| [ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 +---------------------------------------------------------------+ 4 | e107 website system 5 | /sitelinks_class.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_handlers/sitelinks_class.php,v $ 15 | $Revision: 1.114 $ 16 | $Date: 2007/02/13 23:23:22 $ 17 | $Author: e107coders $ 18 +---------------------------------------------------------------+ 19 */ 20 21 if (!defined('e107_INIT')) { exit; } 22 23 @include_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_sitelinks.php"); 24 @include_once(e_LANGUAGEDIR."English/lan_sitelinks.php"); 25 26 /** 27 * @return void 28 * @desc Outputs sitelinks 29 */ 30 31 class sitelinks 32 { 33 34 var $eLinkList; 35 36 function getlinks($cat=1) 37 { 38 39 global $sql; 40 if ($sql->db_Select('links', '*', "link_category = ".intval($cat)." and link_class IN (".USERCLASS_LIST.") ORDER BY link_order ASC")){ 41 while ($row = $sql->db_Fetch()) 42 { 43 // if (substr($row['link_name'], 0, 8) == 'submenu.'){ 44 // $tmp=explode('.', $row['link_name'], 3); 45 // $this->eLinkList[$tmp[1]][]=$row; 46 if (isset($row['link_parent']) && $row['link_parent'] != 0){ 47 $this->eLinkList['sub_'.$row['link_parent']][]=$row; 48 }else{ 49 $this->eLinkList['head_menu'][] = $row; 50 } 51 } 52 } 53 54 } 55 56 function get($cat=1, $style='', $css_class = false) 57 { 58 global $pref, $ns, $e107cache, $linkstyle; 59 $usecache = ((trim(defset('LINKSTART_HILITE')) != "" || trim(defset('LINKCLASS_HILITE')) != "") ? false : true); 60 61 if ($usecache && !strpos(e_SELF, e_ADMIN) & ($data = $e107cache->retrieve('sitelinks_'.$cat.md5($linkstyle.e_PAGE.e_QUERY)))) { 62 return $data; 63 } 64 65 if (LINKDISPLAY == 4) { 66 require_once(e_PLUGIN.'ypslide_menu/ypslide_menu.php'); 67 return; 68 } 69 70 $this->getlinks($cat); 71 72 // are these defines used at all ? 73 74 if(!defined('PRELINKTITLE')){ 75 define('PRELINKTITLE', ''); 76 } 77 if(!defined('PRELINKTITLE')){ 78 define('POSTLINKTITLE', ''); 79 } 80 // ----------------------------- 81 82 // where did link alignment go? 83 if (!defined('LINKALIGN')) { define(LINKALIGN, ''); } 84 85 if(!$style){ 86 $style['prelink'] = defined('PRELINK') ? PRELINK : ''; 87 $style['postlink'] = defined('POSTLINK') ? POSTLINK : ''; 88 $style['linkclass'] = defined('LINKCLASS') ? LINKCLASS : ""; 89 $style['linkclass_hilite'] = defined('LINKCLASS_HILITE') ? LINKCLASS_HILITE : ""; 90 $style['linkstart_hilite'] = defined('LINKSTART_HILITE') ? LINKSTART_HILITE : ""; 91 $style['linkstart'] = defined('LINKSTART') ? LINKSTART : ''; 92 $style['linkdisplay'] = defined('LINKDISPLAY') ? LINKDISPLAY : ''; 93 $style['linkend'] = defined('LINKEND') ? LINKEND : ''; 94 $style['linkseparator'] = defined('LINKSEPARATOR') ? LINKSEPARATOR : ''; 95 } 96 97 // Sublink styles.- replacing the tree-menu. 98 if(isset($style['sublinkdisplay']) || isset($style['subindent']) || isset($style['sublinkclass']) || isset($style['sublinkstart']) || isset($style['sublinkend']) || isset($style['subpostlink'])){ 99 foreach($style as $key=>$val){ 100 $aSubStyle[$key] = ($style["sub".$key]) ? $style["sub".$key] : $style[$key]; 101 } 102 }else{ 103 $style['subindent'] = " "; 104 $aSubStyle = $style; 105 } 106 107 $text = "\n\n\n<!-- Sitelinks ($cat) -->\n\n\n".$style['prelink']; 108 109 if ($style['linkdisplay'] != 3) { 110 foreach ($this->eLinkList['head_menu'] as $key => $link){ 111 $main_linkid = "sub_".$link['link_id']; 112 113 $link['link_expand'] = ((isset($pref['sitelinks_expandsub']) && $pref['sitelinks_expandsub']) && !$style['linkmainonly'] && !defined("LINKSRENDERONLYMAIN") && isset($this->eLinkList[$main_linkid]) && is_array($this->eLinkList[$main_linkid])) ? TRUE : FALSE; 114 115 $render_link[$key] = $this->makeLink($link,'', $style, $css_class); 116 117 if(!defined("LINKSRENDERONLYMAIN") && !varset($style['linkmainonly'])) /* if this is defined in theme.php only main links will be rendered */ 118 { 119 120 // if there's a submenu. : 121 if (isset($this->eLinkList[$main_linkid]) && is_array($this->eLinkList[$main_linkid])){ 122 $substyle = (strpos(e_SELF, $link['link_url']) !== FALSE || strpos(e_SELF, $link['link_name']) !== FALSE || $link['link_expand'] == FALSE) ? "compact" : "none"; // expanding sub-menus. 123 $render_link[$key] .= "\n\n<div id='{$main_linkid}' style='display:$substyle' class='d_sublink'>\n"; 124 foreach ($this->eLinkList[$main_linkid] as $sub){ 125 $render_link[$key] .= $this->makeLink($sub, TRUE, $aSubStyle, $css_class); 126 } 127 $render_link[$key] .= "\n</div>\n\n"; 128 } 129 } 130 } 131 $text .= implode($style['linkseparator'], $render_link); 132 $text .= $style['postlink']; 133 if ($style['linkdisplay'] == 2) { 134 $text = $ns->tablerender(LAN_SITELINKS_183, $text, 'sitelinks', TRUE); 135 } 136 } 137 else 138 { 139 foreach($this->eLinkList['head_menu'] as $link) 140 { 141 if (!count($this->eLinkList['sub_'.$link['link_id']])) 142 { 143 $text .= $this->makeLink($link,'', $style, $css_class); 144 } 145 $text .= $style['postlink']; 146 } 147 $text = $ns->tablerender(LAN_SITELINKS_183, $text, 'sitelinks_main', TRUE); 148 foreach(array_keys($this->eLinkList) as $k) 149 { 150 $mnu = $style['prelink']; 151 foreach($this->eLinkList[$k] as $link) 152 { 153 if ($k != 'head_menu') 154 { 155 $mnu .= $this->makeLink($link, TRUE, $style, $css_class); 156 } 157 } 158 $mnu .= $style['postlink']; 159 $text .= $ns->tablerender($k, $mnu, 'sitelinks_sub', TRUE); 160 } 161 } 162 $text .= "\n\n\n<!--- end Site Links -->\n\n\n"; 163 if($usecache) 164 { 165 $e107cache->set('sitelinks_'.$cat.md5($linkstyle.e_PAGE.e_QUERY), $text); 166 } 167 return $text; 168 } 169 170 function makeLink($linkInfo, $submenu = FALSE, $style='', $css_class = false) 171 { 172 global $pref,$tp; 173 174 // Start with an empty link 175 $linkstart = $indent = $linkadd = $screentip = $href = $link_append = ''; 176 177 // If submenu: Fix Name, Add Indentation. 178 if ($submenu == TRUE) { 179 if(substr($linkInfo['link_name'],0,8) == "submenu."){ 180 $tmp = explode('.', $linkInfo['link_name'], 3); 181 $linkInfo['link_name'] = $tmp[2]; 182 } 183 $indent = ($style['linkdisplay'] != 3) ? $style['subindent'] : ""; 184 } 185 186 $linkInfo['link_url'] = $tp -> replaceConstants($linkInfo['link_url'],TRUE); // replace {e_xxxx} 187 188 if(strpos($linkInfo['link_url'],"{") !== FALSE){ 189 $linkInfo['link_url'] = $tp->parseTemplate($linkInfo['link_url'], TRUE); // shortcode in URL support - dynamic urls for multilanguage. 190 } 191 // By default links are not highlighted. 192 $linkstart = $style['linkstart']; 193 $linkadd = ($style['linkclass']) ? " class='".$style['linkclass']."'" : ""; 194 $linkadd = ($css_class) ? " class='".$css_class."'" : $linkadd; 195 196 // Check for screentip regardless of URL. 197 if (isset($pref['linkpage_screentip']) && $pref['linkpage_screentip'] && $linkInfo['link_description']){ 198 $screentip = " title = \"".$tp->toHTML($linkInfo['link_description'],"","value, emotes_off, defs, no_hook")."\""; 199 } 200 201 // Check if its expandable first. It should override its URL. 202 if (isset($linkInfo['link_expand']) && $linkInfo['link_expand']){ 203 $href = " href=\"javascript:expandit('sub_".$linkInfo['link_id']."')\""; 204 } elseif ($linkInfo['link_url']){ 205 206 // Only add the e_BASE if it actually has an URL. 207 $linkInfo['link_url'] = (strpos($linkInfo['link_url'], '://') === FALSE && strpos($linkInfo['link_url'], 'mailto:') !== 0 ? e_HTTP.$linkInfo['link_url'] : $linkInfo['link_url']); 208 209 // Only check if its highlighted if it has an URL 210 if ($this->hilite($linkInfo['link_url'], $style['linkstart_hilite'])== TRUE) { 211 $linkstart = (isset($style['linkstart_hilite'])) ? $style['linkstart_hilite'] : ""; 212 $highlighted = TRUE; 213 } 214 if ($this->hilite($linkInfo['link_url'], $style['linkclass_hilite'])== TRUE) { 215 $linkadd = (isset($style['linkclass_hilite'])) ? " class='".$style['linkclass_hilite']."'" : ""; 216 $highlighted = TRUE; 217 } 218 219 if ($linkInfo['link_open'] == 4 || $linkInfo['link_open'] == 5){ 220 $dimen = ($linkInfo['link_open'] == 4) ? "600,400" : "800,600"; 221 $href = " href=\"javascript:open_window('".$linkInfo['link_url']."',{$dimen})\""; 222 } else { 223 $href = " href='".$linkInfo['link_url']."'"; 224 } 225 226 // Open link in a new window. (equivalent of target='_blank' ) 227 $link_append = ($linkInfo['link_open'] == 1) ? " rel='external'" : ""; 228 } 229 230 // Remove default images if its a button and add new image at the start. 231 if ($linkInfo['link_button']){ 232 $linkstart = preg_replace('/\<img.*\>/si', '', $linkstart); 233 $linkstart .= "<img src='".e_IMAGE_ABS."icons/".$linkInfo['link_button']."' alt='' style='vertical-align:middle' />"; 234 } 235 236 // mobile phone support. 237 $accesskey = (isset($style['accesskey']) && $style['accesskey']==TRUE) ? " accesskey='".$linkInfo['link_order']."' " : ""; 238 $accessdigit = (isset($style['accessdigit'],$style['accesskey']) && $style['accessdigit']==TRUE && $style['accesskey']==TRUE) ? $linkInfo['link_order'].". " : ""; 239 240 // If its a link.. make a link 241 $_link = ""; 242 $_link .= $accessdigit; 243 if (!empty($href) && ((varset($style['hilite_nolink']) && $highlighted)!=TRUE)){ 244 $_link .= "<a".$linkadd.$screentip.$href.$link_append.$accesskey.">".$tp->toHTML($linkInfo['link_name'],"","emotes_off, defs, no_hook")."</a>"; 245 // If its not a link, but has a class or screentip do span: 246 }elseif (!empty($linkadd) || !empty($screentip)){ 247 $_link .= "<span".$linkadd.$screentip.">".$tp->toHTML($linkInfo['link_name'],"","emotes_off, defs, no_hook")."</span>"; 248 // Else just the name: 249 }else { 250 $_link .= $tp->toHTML($linkInfo['link_name'],"","emotes_off, defs, no_hook"); 251 } 252 253 $_link = $linkstart.$indent.$_link; 254 255 return $_link.$style['linkend']."\n"; 256 } 257 258 259 260 261 262 function hilite($link,$enabled=''){ 263 global $PLUGINS_DIRECTORY,$tp,$pref; 264 if(!$enabled){ return FALSE; } 265 266 $link = $tp->replaceConstants($link,TRUE); 267 $tmp = explode("?",$link); 268 $link_qry = (isset($tmp[1])) ? $tmp[1] : ""; 269 $link_slf = (isset($tmp[0])) ? $tmp[0] : ""; 270 $link_pge = basename($link_slf); 271 $link_match = strpos(e_SELF,$tmp[0]); 272 273 if(e_MENU == "debug" && getperms('0')) 274 { 275 echo "<br />link= ".$link; 276 echo "<br />link_q= ".$link_qry; 277 echo "<br />url= ".e_PAGE; 278 echo "<br />url_query= ".e_QUERY."<br />"; 279 280 } 281 282 // ----------- highlight overriding - set the link matching in the page itself. 283 284 if(defined("HILITE")){ 285 if(strpos($link,HILITE)){ 286 return TRUE; 287 } 288 } 289 290 291 // --------------- highlighting for 'HOME'. ---------------- 292 global $pref; 293 list($fp,$fp_q) = explode("?",$pref['frontpage']['all']."?"); 294 if(strpos(e_SELF,"/".$pref['frontpage']['all'])!== FALSE && $fp_q == $tmp[1] && $link == e_HTTP."index.php"){ 295 return TRUE; 296 } 297 298 // --------------- highlighting for plugins. ---------------- 299 if(stristr($link, $PLUGINS_DIRECTORY) !== FALSE && stristr($link, "custompages") === FALSE){ 300 301 if($link_qry) 302 { // plugin links with queries 303 $subq = explode("?",$link); 304 if(strpos(e_SELF,$subq[0]) && e_QUERY == $subq[1]){ 305 return TRUE; 306 }else{ 307 return FALSE; 308 } 309 } 310 else 311 { // plugin links without queries 312 $link = str_replace("../", "", $link); 313 if(stristr(dirname(e_SELF), dirname($link)) !== FALSE){ 314 return TRUE; 315 } 316 } 317 return FALSE; 318 } 319 320 // --------------- highlight for news items.---------------- 321 // eg. news.php, news.php?list.1 or news.php?cat.2 etc 322 if(substr(basename($link),0,8) == "news.php") 323 { 324 325 if (strpos($link, "news.php?") !== FALSE && strpos(e_SELF,"/news.php")!==FALSE) { 326 327 $lnk = explode(".",$link_qry); // link queries. 328 $qry = explode(".",e_QUERY); // current page queries. 329 330 if($qry[0] == "item") 331 { 332 return ($qry[2] == $lnk[1]) ? TRUE : FALSE; 333 } 334 335 if($qry[0] == "all" && $lnk[0] == "all") 336 { 337 return TRUE; 338 } 339 340 if($lnk[0] == $qry[0] && $lnk[1] == $qry[1]) 341 { 342 return TRUE; 343 } 344 345 if($qry[1] == "list" && $lnk[0] == "list" && $lnk[1] == $qry[2]) 346 { 347 return TRUE; 348 } 349 350 } 351 elseif (!e_QUERY && e_PAGE == "news.php") 352 { 353 354 return TRUE; 355 } 356 return FALSE; 357 358 } 359 // --------------- highlight for Custom Pages.---------------- 360 // eg. page.php?1 361 362 if (strpos($link, "page.php?") !== FALSE && strpos(e_SELF,"/page.php")) { 363 list($custom,$page) = explode(".",$link_qry); 364 list($q_custom,$q_page) = explode(".",e_QUERY); 365 if($custom == $q_custom){ 366 return TRUE; 367 }else{ 368 return FALSE; 369 } 370 } 371 372 // --------------- highlight default ---------------- 373 if(strpos($link, "?") !== FALSE){ 374 375 $thelink = str_replace("../", "", $link); 376 if((strpos(e_SELF,$thelink) !== false) && (strpos(e_QUERY,$link_qry) !== false)){ 377 return true; 378 } 379 } 380 if(!preg_match("/all|item|cat|list/", e_QUERY) && (strpos(e_SELF, str_replace("../", "",$link)) !== false)){ 381 return true; 382 } 383 384 if((!$link_qry && !e_QUERY) && (strpos(e_SELF,$link) !== FALSE)){ 385 return TRUE; 386 } 387 388 if(($link_slf == e_SELF && !link_qry) || (e_QUERY && strpos(e_SELF."?".e_QUERY,$link)!== FALSE) ){ 389 return TRUE; 390 } 391 392 return FALSE; 393 } 394 } 395 ?>
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 |