| [ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | ©Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvsroot/e107/e107_0.7/e107_plugins/linkwords/linkwords.php,v $ 14 | $Revision: 1.13 $ 15 | $Date: 2007/02/07 21:48:14 $ 16 | $Author: e107steved $ 17 | 18 +----------------------------------------------------------------------------+ 19 */ 20 21 if (!defined('e107_INIT')) { exit; } 22 23 24 class e_linkwords 25 { 26 var $lw_enabled = FALSE; // Default to disabled to start 27 var $word_list = array(); // List of link words/phrases 28 var $link_list = array(); // Corresponding list of links to apply 29 var $tip_list = array(); 30 var $area_opts = array(); // Process flags for the various contexts 31 var $block_list = array(); // Array of 'blocked' pages 32 33 function e_linkwords() 34 { 35 global $pref; 36 /* constructor */ 37 // See whether they should be active on this page - if not, no point doing anything! 38 if ((strpos(e_SELF, ADMINDIR) !== FALSE) || (strpos(e_PAGE, "admin_") !== FALSE)) return; // No linkwords on admin directories 39 40 // Now see if disabled on specific pages 41 $check_url = e_SELF.(e_QUERY ? "?".e_QUERY : ''); 42 $this->block_list = explode("|",substr($pref['lw_page_visibility'],2)); // Knock off the 'show/hide' flag 43 foreach ($this->block_list as $p) 44 { 45 if(substr($p, -1) == '!') 46 { 47 $p = substr($p, 0, -1); 48 if(substr($check_url, strlen($p)*-1) == $p) return; 49 } 50 else 51 { 52 if(strpos($check_url, $p) !== FALSE) return; 53 } 54 } 55 56 // Will probably need linkwords on this page - so get the info 57 $this->lw_enabled = TRUE; 58 $link_sql = new db; 59 if($link_sql -> db_Select("linkwords", "*", "linkword_active=0")) 60 { 61 while ($row = $link_sql->db_Fetch()) 62 { 63 $lw = trim(strtolower($row['linkword_word'])); 64 if (strpos($lw,',')) 65 { // Several words to same link 66 $lwlist = explode(',',$lw); 67 foreach ($lwlist as $lw) 68 { 69 $this->word_list[] = trim($lw); 70 $this->link_list[] = $row['linkword_link']; 71 } 72 } 73 else 74 { 75 $this->word_list[] = $lw; 76 $this->link_list[] = $row['linkword_link']; 77 } 78 } 79 } 80 $this->area_opts = $pref['lw_context_visibility']; 81 } 82 83 84 function linkwords($text,$area = 'olddefault') 85 { 86 if (!$this->lw_enabled || !array_key_exists($area,$this->area_opts) || !$this->area_opts[$area]) return $text; // No linkwords in disabled areas 87 88 89 // Split up by HTML tags and process the odd bits here 90 $ptext = ""; 91 $lflag = FALSE; 92 93 $content = preg_split('#(<.*?>)#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); 94 foreach($content as $cont) 95 { 96 if (strpos($cont, "<") !== FALSE) 97 { // Its some HTML 98 $ptext .= $cont; 99 if (strpos($cont,"<a") !== FALSE) $lflag = TRUE; 100 if (strpos($cont,"</a") !== FALSE) $lflag = FALSE; 101 } 102 else 103 { // Its the text in between 104 if ($lflag) 105 { // Its probably within a link - leave unchanged 106 $ptext .= $cont; 107 } 108 else 109 { 110 if (trim($cont)) 111 { // Some non-white space - worth word matching 112 $ptext .= $this->linksproc($cont,0,count($this->word_list)); 113 } 114 else 115 { 116 $ptext .= $cont; 117 } 118 } 119 } 120 } 121 return $ptext; 122 } 123 124 function linksproc($text,$first,$limit) 125 { // This function is called recursively - it splits the text up into blocks - some containing a particular linkword 126 while (($first < $limit) && (stripos($text,$this->word_list[$first]) === FALSE)) { $first++; }; 127 if ($first == $limit) return $text; // Return if no linkword found 128 129 // There's at least one occurrence of the linkword in the text 130 $ret = ''; 131 $lw = $this->word_list[$first]; 132 // This splits the text into blocks, some of which will precisely contain a linkword 133 $split_line = preg_split('#\b('.$lw.')\b#i', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); 134 foreach ($split_line AS $sl) 135 { 136 if (strcasecmp($sl,$lw) == 0) 137 { // Do linkword replace 138 $ret .= " <a href='".$this->link_list[$first]."' rel='external'>{$sl}</a>"; 139 } 140 elseif (trim($sl)) 141 { // Something worthwhile left - look for more linkwords in it 142 $ret .= $this->linksproc($sl,$first+1,$limit); 143 } 144 else 145 { 146 $ret .= $sl; // Probably just some white space 147 } 148 } 149 return $ret; 150 } 151 } 152 153 ?>
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 |