diff --git a/e107_plugins/linkwords/admin_config.php b/e107_plugins/linkwords/admin_config.php index 6fcc76ca4..30b8dc6b3 100644 --- a/e107_plugins/linkwords/admin_config.php +++ b/e107_plugins/linkwords/admin_config.php @@ -88,10 +88,13 @@ 'linkword_link' => array ( 'title' => LWLAN_6, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'inline' => true, 'help' => '', 'readParms' => '', 'writeParms' => 'size=xxlarge', 'class' => 'left', 'thclass' => 'left', ), 'linkword_active' => array ( 'title' => LAN_ACTIVE, 'type' => 'dropdown', 'data' => 'int', 'width' => 'auto', 'batch' => true, 'filter' => true, 'inline' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'left' => 'center', 'thclass' => 'left', ), - 'linkword_tooltip' => array ( 'title' => LWLAN_50, 'type' => 'textarea', 'data' => 'str', 'width' => 'auto', 'inline' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), - 'linkword_tip_id' => array ( 'title' => LAN_ID, 'type' => 'number', 'data' => 'int', 'width' => '5%', 'help' => LWLAN_63, 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ), + 'linkword_tooltip' => array ( 'title' => LWLAN_50, 'type' => 'textarea', 'data' => 'str', 'width' => 'auto', 'inline' => true, 'help' => '', 'readParms' => '', 'writeParms' => array('size'=>'xxlarge'), 'class' => 'left', 'thclass' => 'left', ), + 'linkword_limit' => array ( 'title' => "Max. links/tips", 'type' => 'number', 'data' => 'int', 'width' => '10%', 'help' => LWLAN_63, 'readParms' => '', 'writeParms' => array('default'=>3), 'class' => 'right', 'thclass' => 'right', ), + + 'linkword_tip_id' => array ( 'title' => LAN_ID, 'type' => 'number', 'data' => 'int', 'width' => '5%', 'help' => LWLAN_63, 'readParms' => '', 'writeParms' => '', 'class' => 'right', 'thclass' => 'right', ), 'linkword_newwindow' => array ( 'title' => LWLAN_55, 'type' => 'boolean', 'data' => 'int', 'width' => 'auto', 'inline' => true, 'help' => '', 'filter'=>true, 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ), - 'options' => array ( 'title' => LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1', ), + + 'options' => array ( 'title' => LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1', ), ); protected $fieldpref = array(); @@ -102,7 +105,7 @@ 'lw_ajax_enable' => array('title'=> LWLAN_59, 'type'=>'boolean', 'data' => 'string','help'=>''), 'lw_notsamepage' => array('title'=> LWLAN_64, 'type'=>'boolean', 'data' => 'string','help'=>LWLAN_65), 'linkword_omit_pages' => array('title'=> LWLAN_28, 'type'=>'textarea', 'data' => 'string','help'=>''), - 'lw_max_per_word' => array('title'=> "Maximum links/tips per word", 'type'=>'number', 'data' => 'string','help'=>'If the same word is found multiple times in a piece of text.'), + // 'lw_max_per_word' => array('title'=> "Maximum links/tips per word", 'type'=>'number', 'data' => 'string','help'=>'If the same word is found multiple times in a piece of text.'), 'lw_custom_class' => array('title'=> "Custom CSS Class", 'type'=>'text', 'writeParms'=>array('placeholder'=> LAN_OPTIONAL ), 'data' => 'string','help'=>'Will add this class to all generated links.'), ); diff --git a/e107_plugins/linkwords/e_tohtml.php b/e107_plugins/linkwords/e_tohtml.php index f97d899a3..095d83fd7 100755 --- a/e107_plugins/linkwords/e_tohtml.php +++ b/e107_plugins/linkwords/e_tohtml.php @@ -35,10 +35,10 @@ define('LW_CACHE_ENABLE', FALSE); class e_tohtml_linkwords { - var $lw_enabled = FALSE; // Default to disabled to start + protected $lw_enabled = FALSE; // Default to disabled to start var $lwAjaxEnabled = FALSE; // Adds in Ajax-compatible links var $utfMode = ''; // Flag to enable utf-8 on regex - var $word_list = array(); // List of link words/phrases + protected $word_list = array(); // List of link words/phrases var $link_list = array(); // Corresponding list of links to apply var $ext_list = array(); // Flags to determine 'open in new window' for link var $tip_list = array(); // Store for tooltips @@ -46,9 +46,11 @@ class e_tohtml_linkwords var $area_opts = array(); // Process flags for the various contexts var $block_list = array(); // Array of 'blocked' pages + protected $word_class = array(); + protected $customClass = ''; protected $wordCount = array(); - protected $maxPerWord = 3; +// protected $maxPerWord = 3; /* constructor */ @@ -57,8 +59,9 @@ class e_tohtml_linkwords $tp = e107::getParser(); $pref = e107::pref('core'); + $frm = e107::getForm(); - $this->maxPerWord = vartrue($pref['lw_max_per_word'], 25); + // $this->maxPerWord = vartrue($pref['lw_max_per_word'], 25); $this->customClass = vartrue($pref['lw_custom_class'],''); $this->area_opts = $pref['lw_context_visibility']; $this->utfMode = (strtolower(CHARSET) == 'utf-8') ? 'u' : ''; // Flag to enable utf-8 on regex //@TODO utfMode probably obsolete @@ -110,8 +113,9 @@ class e_tohtml_linkwords if($link_sql->select("linkwords", "*", "linkword_active!=1")) { - $this->lw_enabled = TRUE; - while($row = $link_sql->db_Fetch()) + $this->lw_enabled = true; + + while($row = $link_sql->fetch()) { $lw = $tp->uStrToLower($row['linkword_word']); // It was trimmed when saved *utf @@ -134,19 +138,26 @@ class e_tohtml_linkwords $lwlist = explode(',',$lw); foreach ($lwlist as $lw) { - $this->word_list[] = trim($lw); - $this->link_list[] = $row['linkword_link']; - $this->tip_list[] = $row['linkword_tooltip']; - $this->ext_list[] = $row['linkword_newwindow']; - $this->LinkID[] = $lwID; + $this->word_list[] = trim($lw); + $this->word_class[] = 'lw-'.$frm->name2id($lw); + $this->word_limit[] = vartrue($row['linkword_limit'],3); + + $this->link_list[] = $row['linkword_link']; + $this->tip_list[] = $row['linkword_tooltip']; + $this->ext_list[] = $row['linkword_newwindow']; + + $this->LinkID[] = $lwID; } } else { $this->word_list[] = $lw; + $this->word_class[] = 'lw-'.$frm->name2id($lw); + $this->word_limit[] = vartrue($row['linkword_limit'],3); $this->link_list[] = $row['linkword_link']; $this->tip_list[] = $row['linkword_tooltip']; $this->ext_list[] = $row['linkword_newwindow']; + $this->LinkID[] = $lwID; } } @@ -233,8 +244,15 @@ class e_tohtml_linkwords // Consider next line - stripos is PHP5, and mb_stripos is PHP >= 5.2 - so may well often require handling // while (($first < $limit) && (stripos($text,$this->word_list[$first]) === FALSE)) { $first++; }; // *utf (stripos is PHP5 - compatibility handler implements) - while (($first < $limit) && (strpos($tp->ustrtolower($text),$this->word_list[$first]) === FALSE)) { $first++; }; // *utf - if ($first == $limit) return $text; // Return if no linkword found + while (($first < $limit) && (strpos($tp->ustrtolower($text), $this->word_list[$first]) === false)) + { + $first++; + } // *utf + + if ($first == $limit) + { + return $text; // Return if no linkword found + } // There's at least one occurrence of the linkword in the text // Prepare all info once only @@ -263,6 +281,7 @@ class e_tohtml_linkwords $lwClass[] = 'lw-tip '.$this->customClass; } } + if ($this->link_list[$first]) // Got link { $newLink = $tp->replaceConstants($this->link_list[$first], 'full'); @@ -273,11 +292,16 @@ class e_tohtml_linkwords $lwClass[] = 'lw-link '.$this->customClass; } } + elseif(!empty($this->word_class[$first])) + { + $lwClass[] = $this->word_class[$first]; + } + if (!count($lwClass)) { - return $this->linksproc($sl,$first+1,$limit); // Nothing to do - move on to next word (shouldn't really get here) + // return $this->linksproc($sl,$first+1,$limit); // Nothing to do - move on to next word (shouldn't really get here) } if (count($linkrel)) { @@ -285,8 +309,9 @@ class e_tohtml_linkwords } // This splits the text into blocks, some of which will precisely contain a linkword - $split_line = preg_split('#\b('.$lw.')\b#i'.$this->utfMode, $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); // *utf (selected) - $class = "class='".implode(' ',$lwClass)."' "; + $split_line = preg_split('#\b('.$lw.')(?:\s|\b)#i'.$this->utfMode, $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); // *utf (selected) + // $class = "".implode(' ',$lwClass)."' "; + $class = implode(' ',$lwClass); $hash = md5($lw); @@ -295,14 +320,24 @@ class e_tohtml_linkwords $this->wordCount[$hash] = 0; } - foreach ($split_line as $sl) + foreach ($split_line as $count=>$sl) { - if ($tp->uStrToLower($sl) == $lw && $this->wordCount[$hash] < $this->maxPerWord) // Do linkword replace // We know the linkword is already lower case // *utf + if ($tp->uStrToLower($sl) == $lw && $this->wordCount[$hash] < $this->word_limit[$first]) // Do linkword replace // We know the linkword is already lower case // *utf { $this->wordCount[$hash]++; - $ret .= ''.$sl.''; + $classCount = " lw-".$this->wordCount[$hash]; + + if(empty($linkwd)) + { + $ret .= ''.$sl.''; + } + else + { + $ret .= ''.$sl.''; + } + } elseif (trim($sl)) // Something worthwhile left - look for more linkwords in it { @@ -320,4 +355,3 @@ class e_tohtml_linkwords -?> \ No newline at end of file diff --git a/e107_plugins/linkwords/linkwords.css b/e107_plugins/linkwords/linkwords.css index 5cdf5a32c..e5c8be953 100644 --- a/e107_plugins/linkwords/linkwords.css +++ b/e107_plugins/linkwords/linkwords.css @@ -1,5 +1,5 @@ - - -a.lw-tip { cursor: help; text-decoration-style:dotted } -a.lw-link { cursor: pointer; text-decoration-style:solid } \ No newline at end of file +/* Linkwords */ +a.lw-tip { cursor: help; text-decoration-style:dotted } +span.lw-tip { cursor: help; border-bottom:1px dotted; } +a.lw-link { cursor: pointer; text-decoration-style:solid } \ No newline at end of file diff --git a/e107_plugins/linkwords/linkwords_sql.php b/e107_plugins/linkwords/linkwords_sql.php index 0def55f30..d5825ff68 100644 --- a/e107_plugins/linkwords/linkwords_sql.php +++ b/e107_plugins/linkwords/linkwords_sql.php @@ -6,5 +6,6 @@ linkword_link varchar(250) NOT NULL default '', linkword_tooltip text NOT NULL, linkword_tip_id int(10) UNSIGNED NOT NULL Default '0', linkword_newwindow tinyint(1) unsigned NOT NULL default '1', +linkword_limit int(3) UNSIGNED NOT NULL default '0', PRIMARY KEY (linkword_id) ) ENGINE=MyISAM AUTO_INCREMENT=1; \ No newline at end of file