| [ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | /tree_menu.php 6 | 7 | ©Steve Dunstan 2001-2002 8 | http://e107.org 9 | jalist@e107.org 10 | 11 | Released under the terms and conditions of the 12 | GNU General Public License (http://gnu.org). 13 | 14 | $Source: /cvsroot/e107/e107_0.7/e107_plugins/tree_menu/tree_menu.php,v $ 15 | $Revision: 1.26 $ 16 | $Date: 2006/11/25 15:39:55 $ 17 | $Author: lisa_ $ 18 +----------------------------------------------------------------------------+ 19 */ 20 21 if (!defined('e107_INIT')) { exit; } 22 23 /* Modification to keep menu status during navigation on the site 24 - Call the language file (only used for title !!! Maybe this title can be included in the default language file) 25 - Add a HTML id to the span tags (menus) : span_$link_name 26 - Add a javascript function to write a cookie when menu is opened (updatecook) 27 - Add a javascript function if menu is closed or no subitem (clearcook) 28 - Add event onclick for div without subitem, and modify the existing events for items WITH subitems 29 - Add a PHP function to read cookie (if existing) when page is loaded and restore menu status (writing or not window.onload js function) 30 */ 31 32 /* changes by jalist 33 26/01/2005 34 + complete rewrite 35 + now uses single db query, links and sublinks are built into array 36 */ 37 38 39 global $tp; 40 include_lan(e_LANGUAGEDIR.e_LANGUAGE."/lan_sitelinks.php"); 41 42 // Many thanks to Lolo Irie for fixing the javascript that drives this menu item 43 unset($text); 44 45 $query = "SELECT * FROM #links WHERE link_class IN (".USERCLASS_LIST.") ORDER BY link_order ASC"; 46 $sql -> db_Select_gen($query); 47 $linkArray = $sql->db_getList(); 48 49 // all main links now held in array, we now need to loop through them and assign the sublinks to the correct parent links ... 50 51 $mainLinkArray = array(); 52 foreach($linkArray as $links) { 53 54 // Updated to stop using the deprecated method of splitting the link-name in 3. 55 // Now uses uses the link parent to determine the 'tree'. 56 57 extract ($links); 58 if ($link_parent == 0) 59 { 60 // main link - add to main array ... 61 $mainLinkArray[$link_id]['id'] = $link_id; 62 $mainLinkArray[$link_id]['name'] = $tp->toHtml(strip_tags($link_name),"","defs"); 63 $mainLinkArray[$link_id]['url'] = $link_url; 64 $mainLinkArray[$link_id]['description'] = $link_description; 65 $mainLinkArray[$link_id]['image'] = $link_button; 66 $mainLinkArray[$link_id]['openMethod'] = $link_open; 67 $mainLinkArray[$link_id]['class'] = $link_class; 68 } 69 else 70 { 71 // submenu - add to parent's array entry ... 72 $tmp = explode(".", $link_name); 73 $submenu_name = ($tmp[2]) ? $tmp[2] : $link_name; 74 75 $mainLinkArray[$link_parent]['sublink'][$link_id]['parent_name'] = $link_parent; 76 $mainLinkArray[$link_parent]['sublink'][$link_id]['id'] = $link_id; 77 $mainLinkArray[$link_parent]['sublink'][$link_id]['name'] = $tp->toHtml(strip_tags($submenu_name)); 78 $mainLinkArray[$link_parent]['sublink'][$link_id]['url'] = $link_url; 79 $mainLinkArray[$link_parent]['sublink'][$link_id]['description'] = $links['link_description']; 80 $mainLinkArray[$link_parent]['sublink'][$link_id]['image'] = $link_button; 81 $mainLinkArray[$link_parent]['sublink'][$link_id]['openMethod'] = $link_open; 82 $mainLinkArray[$link_parent]['sublink'][$link_id]['class'] = $link_class; 83 } 84 85 } 86 87 // ok, now all mainlinks and sublinks are held in the array, now we have to loop through and build the text to send to screen ... 88 89 $text = ""; 90 foreach($mainLinkArray as $links) { 91 extract ($links); 92 if (array_key_exists("sublink", $links) && $links['name'] != "") { 93 // sublinks found ... 94 95 $url = "javascript:void(0);"; 96 $spanName = $id; 97 $image = ($image ? "<img src='".e_IMAGE."icons/".$image."' alt='' style='vertical-align:middle;' />" : "»"); 98 $plink = "<div".($menu_pref['tm_class2'] ? " class='{$menu_pref['tm_class2']}'" : "")." style='width:100%; cursor: pointer;' onclick='expandit(\"span_".$spanName."\");updatecook(\"".$spanName."\");'>".$image.setLink($name, $url, $openMethod, $description)."</div>\n"; 99 $text .= ($menu_pref['tm_spacer'] ? "<div class='spacer'>\n".$plink."\n</div>\n" : $plink); 100 } else { 101 // no sublinks found ... 102 if($links['name']) 103 { 104 $linkName = $url; 105 $spanName = ""; 106 $image = ($image ? "<img src='".e_IMAGE."icons/".$image."' alt='' style='vertical-align:middle;' />" : "·"); 107 $plink = "<div".($menu_pref['tm_class1'] ? " class='{$menu_pref['tm_class1']}'" : "")." style='width:100%; cursor: pointer;'>".$image.setLink($name, $url, $openMethod, $description)."</div>"; 108 $text .= ($menu_pref['tm_spacer'] ? "<div class='spacer'>\n".$plink."\n</div>\n" : $plink); 109 } 110 } 111 112 $c = 0; 113 if (array_key_exists("sublink", $links) && $links['name'] != "" ) { 114 115 $text .= "\n<span style=\"display:none\" id=\"span_".$spanName."\">\n"; 116 foreach($sublink as $link) { 117 extract($link); 118 $image = ($image ? "<img src='".e_IMAGE."icons/".$image."' alt='' style='vertical-align:middle' /> " : "· "); 119 $spanName = $parent_name; 120 121 $plink = $image.setLink($name, $url, $openMethod, $description)."<br />\n"; 122 $text .=($menu_pref['tm_class3'] ? "<span".($menu_pref['tm_class3'] ? " class='{$menu_pref['tm_class3']}'" : "").">".$plink."</span>\n\n" : $plink); 123 } 124 $text .= "</span>\n"; 125 } 126 127 } 128 129 function setlink($link_name, $link_url, $link_open, $link_description) { 130 global $tp; 131 switch ($link_open) { 132 case 1: 133 $link_append = "rel='external'"; 134 break; 135 case 2: 136 $link_append = ""; 137 break; 138 case 3: 139 $link_append = ""; 140 break; 141 default: 142 $link_append = ''; 143 } 144 145 if (!strstr($link_url, "http:") && !strstr($link_url, "void") && strpos($link_url, "mailto:") !== 0) { 146 $link_url = e_BASE.$link_url; 147 } 148 $link_url = $tp->replaceConstants($link_url, $nonrelative = TRUE, $all = false); 149 150 if ($link_open == 4) { 151 $link = "<a style='text-decoration:none' title='".$link_description."' href=\"javascript:open_window('".$link_url."')\">".$link_name."</a>\n"; 152 } else { 153 $link = "<a style='text-decoration:none' title='".$link_description."' href=\"".$link_url."\" ".$link_append.">".$link_name."</a>\n"; 154 } 155 return $link; 156 } 157 158 (isset($_COOKIE["treemenustatus"]) && $_COOKIE["treemenustatus"]) ? $treemenustatus = $_COOKIE["treemenustatus"] : $treemenustatus = "0"; 159 $text .= " 160 <script type='text/javascript'> 161 <!-- 162 function updatecook(itemmenu){ 163 cookitem='span_'+itemmenu; 164 if (document.getElementById(cookitem).style.display!='none'){ 165 var expireDate = new Date; 166 expireDate.setMinutes(expireDate.getMinutes()+10); 167 document.cookie = \"treemenustatus=\" + itemmenu + \"; expires=\" + expireDate.toGMTString()+\";path=/\"; 168 } 169 else{ 170 clearcook(); 171 } 172 }\n 173 174 function clearcook(){ 175 var expireDate = new Date; 176 expireDate.setMinutes(expireDate.getMinutes()+10); 177 document.cookie = \"treemenustatus=\" + \"0\" + \"; expires=\" + expireDate.toGMTString(); 178 }\n 179 //-->\n 180 "; 181 182 (($treemenustatus != "0" && isset($treemenustatus))?$text .= "window.onload=document.getElementById('span_".$treemenustatus."').style.display=''":""); 183 184 $text .= "</script> 185 "; 186 $ns->tablerender(LAN_SITELINKS_183, $text, 'tree_menu'); 187 188 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |