diff --git a/e107_plugins/linkwords/admin_config.php b/e107_plugins/linkwords/admin_config.php
index ce40ff9b1..0f7baa8ea 100644
--- a/e107_plugins/linkwords/admin_config.php
+++ b/e107_plugins/linkwords/admin_config.php
@@ -19,9 +19,10 @@ if (!getperms('P') || !e107::isInstalled('linkwords'))
}
e107::lan('linkwords', true);
-
-define('LW_CACHE_TAG', 'nomd5_linkwords');
-
+if(!defined('LW_CACHE_TAG'))
+{
+ define('LW_CACHE_TAG', 'nomd5_linkwords');
+}
class linkwords_admin extends e_admin_dispatcher
{
@@ -40,7 +41,7 @@ class linkwords_admin extends e_admin_dispatcher
'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'),
'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'),
'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'),
- // 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P')
+ 'main/test' => array('caption'=> LAN_TEST, 'perm' => 'P')
);
protected $adminMenuAliases = array(
@@ -79,6 +80,8 @@ class linkwords_ui extends e_admin_ui
'linkword_limit' => array ( 'title' => LWLAN_67, 'type' => 'number', 'data' => 'int', 'width' => '10%', 'help' => LAN_LW_HELP_15, 'readParms' => '', 'writeParms' => array('default'=>3), 'class' => 'right', 'thclass' => 'right', ),
'linkword_tip_id' => array ( 'title' => LAN_ID, 'type' => 'number', 'data' => 'int', 'width' => '5%', 'help' => LAN_LW_HELP_16, 'readParms' => '', 'writeParms' => '', 'class' => 'right', 'thclass' => 'right', ),
'linkword_newwindow' => array ( 'title' => LWLAN_55, 'type' => 'boolean', 'data' => 'int', 'width' => 'auto', 'inline' => true, 'help' => LAN_LW_HELP_17, 'filter'=>true, 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center', ),
+ 'linkword_rel' => array ( 'title' => LAN_RELATIONSHIP, 'type' => 'tags', 'data' => 'str', 'width' => 'auto', 'inline' => true, 'help' => LAN_RELATIONSHIP_HELP, 'filter'=>false, 'readParms' => '', 'writeParms'=>array('placeholder'=>'eg.nofollow,noreferrer','size'=>'xlarge'), 'class' => 'center', 'thclass' => 'center', ),
+
'options' => array ( 'title' => LAN_OPTIONS, 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1', ),
);
@@ -176,6 +179,35 @@ class linkwords_ui extends e_admin_ui
}
+ public function testPage()
+ {
+ $text = '';
+
+ if(!empty($_POST['runLinkwordTest']))
+ {
+ // $text .= "Result:
";
+ $result = e107::getParser()->toHTML($_POST['test_body'], false, 'BODY');
+
+ $text .= "
".$result."
";
+ $text .= "".htmlentities($result)."
";
+ }
+
+ $frm = $this->getUI();
+ $text .= $frm->open('linkwordsTest');
+ $text .= "";
+ $text .= $frm->textarea('test_body', varset($_POST['test_body']), 10, 80, ['class'=>'form-control','placeholder'=>'Start writing...']);
+
+ $text .= "
";
+ $text .= "
";
+ $text .= $frm->close();
+
+ return $text;
+
+
+ }
+
}
diff --git a/e107_plugins/linkwords/e_header.php b/e107_plugins/linkwords/e_header.php
index a92655e4d..a49d8b9c4 100644
--- a/e107_plugins/linkwords/e_header.php
+++ b/e107_plugins/linkwords/e_header.php
@@ -1,6 +1,6 @@
lw_enabled = true;
+ }
+
+ public function setWordData($arr = array())
+ {
+ foreach($arr as $val)
+ {
+ $this->word_list[] = $val['word'];
+ $this->link_list[] = $val['link'];
+ $this->ext_list[] = $val['ext'];
+ $this->tip_list[] = $val['tip'];
+ $this->word_limit[] = $val['limit'];
+ }
+ }
+
+ public function setAreaOpts($arr = array())
+ {
+ $this->area_opts = $arr;
+ }
+
+
+ public function setLink($arr)
+ {
+ $this->word_list = $arr;
+ }
+
+
+ /* constructor */
+ function __construct()
+ {
+
+ $tp = e107::getParser();
+ $pref = e107::pref('linkwords');
+ $frm = e107::getForm();
+
+ // $this->maxPerWord = vartrue($pref['lw_max_per_word'], 25);
+ $this->customClass = vartrue($pref['lw_custom_class']);
+ $this->area_opts = (array) varset($pref['lw_context_visibility']);
+ $this->utfMode = (strtolower(CHARSET) == 'utf-8') ? 'u' : ''; // Flag to enable utf-8 on regex //@TODO utfMode probably obsolete
+ $this->lwAjaxEnabled = varset($pref['lw_ajax_enable'],0);
+
+ // See whether they should be active on this page - if not, no point doing anything!
+ if(e_ADMIN_AREA === true && empty($_POST['runLinkwordTest'])) { return; }
+
+ // Now see if disabled on specific pages
+ $check_url = e_SELF.(defined('e_QUERY') ? "?".e_QUERY : '');
+ $this->block_list = explode("|",substr(varset($pref['lw_page_visibility']),2)); // Knock off the 'show/hide' flag
+
+ foreach($this->block_list as $p)
+ {
+ if($p=trim($p))
+ {
+ if(substr($p, -1) == '!')
+ {
+ $p = substr($p, 0, -1);
+ if(substr($check_url, strlen($p)*-1) == $p) return;
+ }
+ else
+ {
+ if(strpos($check_url, $p) !== FALSE) return;
+ }
+ }
+ }
+
+ // Will probably need linkwords on this page - so get the info
+ if(!defined('LW_CACHE_TAG'))
+ {
+ define('LW_CACHE_TAG', 'nomd5_linkwords'); // Put it here to avoid conflict on admin pages
+ }
+
+ if(LW_CACHE_ENABLE && ($temp = e107::getCache()->retrieve_sys(LW_CACHE_TAG)))
+ {
+ $ret = eval($temp);
+ if ($ret)
+ {
+ echo "Error reading linkwords cache: {$ret}
";
+ $temp = '';
+ }
+ else
+ {
+ $this->lw_enabled = TRUE;
+ }
+ }
+
+ if(!vartrue($temp)) // Either cache disabled, or no info in cache (or error reading/processing cache)
+ {
+ $link_sql = e107::getDb('link_sql');
+
+ if($link_sql->select("linkwords", "*", "linkword_active!=1"))
+ {
+ $this->lw_enabled = true;
+
+ while($row = $link_sql->fetch())
+ {
+
+ $lw = $tp->ustrtolower($row['linkword_word']); // It was trimmed when saved *utf
+
+ if($row['linkword_active'] == 2)
+ {
+ $row['linkword_link'] = ''; // Make sure linkword disabled
+ }
+
+ if($row['linkword_active'] < 2)
+ {
+ $row['linkword_tooltip'] = ''; // Make sure tooltip disabled
+ }
+
+
+ if(strpos($lw,',')) // Several words to same link
+ {
+ $lwlist = explode(',',$lw);
+ foreach ($lwlist as $lw)
+ {
+ $this->loadRow($lw,$row);
+ }
+ }
+ else
+ {
+ $this->loadRow($lw,$row);
+ }
+ }
+
+ if(deftrue('LW_CACHE_ENABLE')) // Write to file for next time
+ {
+ $temp = '';
+ foreach (array('word_list', 'link_list', 'tip_list', 'ext_list', 'LinkID') as $var)
+ {
+ $temp .= '$this->'.$var.'='.var_export($this->$var, TRUE).";\n";
+ }
+
+ e107::getCache()->set_sys(LW_CACHE_TAG,$temp);
+ }
+ }
+ }
+
+
+
+ }
+
+ private function loadRow($lw, $row)
+ {
+ $lw = trim($lw);
+
+ if(empty($lw))
+ {
+ return;
+ }
+
+ $frm = e107::getForm();
+
+ $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->rel_list[] = str_replace(",", ' ', $row['linkword_rel']);
+ $this->LinkID[] = max($row['linkword_tip_id'], $row['linkword_id']); // If no specific ID defined, use the DB record ID
+
+ }
+
+
+ public function toHTML($text,$area = 'olddefault')
+ {
+
+ if(is_string($this->area_opts))
+ {
+ $this->area_opts = e107::unserialize($this->area_opts);
+ }
+
+ if($this->area_opts === null)
+ {
+ $this->area_opts = array();
+ }
+
+ if (!$this->lw_enabled || empty($this->area_opts) || !array_key_exists($area,$this->area_opts) || !$this->area_opts[$area])
+ {
+ // e107::getDebug()->log("Link words skipped on ".substr($text, 0, 50));
+ return $text; // No linkwords in disabled areas
+ }
+
+ // Split up by HTML tags and process the odd bits here
+ $ptext = "";
+ $lflag = FALSE;
+
+ // Shouldn't need utf-8 on next line - just looking for HTML tags
+ $content = preg_split('#(<.*?>)#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
+
+ foreach($content as $cont)
+ {
+
+
+ if ($cont[0] == "<")
+ { // Its some HTML
+ $ptext .= $cont;
+ if (substr($cont,0,2) == "linksproc($cont,0,count($this->word_list));
+ // echo "Check linkwords: ".count($this->word_list).'
';
+ }
+ else
+ {
+ $ptext .= $cont;
+ }
+ }
+ }
+ }
+
+ // print_a($this->wordCount);
+ return $ptext;
+ }
+
+
+ /**
+ * This function is called recursively - it splits the text up into blocks - some containing a particular linkword
+ * @param $text
+ * @param $first
+ * @param $limit
+ * @return string
+ */
+ function linksproc($text,$first,$limit)
+ {
+ $tp = e107::getParser();
+ $doSamePage = !e107::getPref('lw_notsamepage');
+
+
+ for (; $first < $limit; $first ++)
+ {
+ if (empty($this->word_list[$first])) continue;
+ if (strpos($tp->ustrtolower($text), $this->word_list[$first]) !== false) break;
+ }
+
+ 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
+ // If supporting Ajax, use the following:
+ //
+ // linkwordId::122 is a unique ID
+
+ $ret = '';
+ $linkwd = '';
+ $linkrel = array();
+ // $linkwd = "href='#' "; // Not relevant for Prototype, but needed with 'pure' JS to make tooltip stuff work - doesn't find link elements without href
+ $lwClass = array();
+ $lw = $this->word_list[$first]; // This is the word we're matching - in lower case in our 'master' list
+ $tooltip = '';
+
+ if ($this->tip_list[$first])
+ { // Got tooltip
+ if ($this->lwAjaxEnabled)
+ {
+ $linkrel[] = 'linkwordID::'.$this->LinkID[$first];
+ $lwClass[] = 'lw-ajax '.$this->customClass;
+ }
+ else
+ {
+ $tooltip = " title=\"{$this->tip_list[$first]}\" ";
+ $lwClass[] = 'lw-tip '.$this->customClass;
+ }
+ }
+
+ if ($this->link_list[$first]) // Got link
+ {
+ $newLink = $tp->replaceConstants($this->link_list[$first], 'full');
+ if ($doSamePage || ($newLink != e_SELF.'?'.e_QUERY))
+ {
+ $linkwd = " href=\"".$newLink."\" ";
+
+ if(!empty($this->rel_list[$first]))
+ {
+ $linkrel[] = $this->rel_list[$first];
+ }
+ elseif($this->ext_list[$first]) // Determine external links
+ {
+ $linkrel[] = 'noopener external';
+ }
+
+ $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)
+ // }
+
+ if (count($linkrel))
+ {
+ $linkwd .= " rel='".implode(' ',$linkrel)."'";
+ }
+
+ // This splits the text into blocks, some of which will precisely contain a linkword
+ $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);
+
+ if(!isset($this->wordCount[$hash]))
+ {
+ $this->wordCount[$hash] = 0;
+ }
+
+ foreach ($split_line as $count=>$sl)
+ {
+ if ($tp->ustrtolower($sl) == $lw && $this->wordCount[$hash] < (int) $this->word_limit[$first]) // Do linkword replace // We know the linkword is already lower case // *utf
+ {
+ $this->wordCount[$hash]++;
+
+ $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
+ {
+ $ret .= $this->linksproc($sl,$first+1,$limit);
+ }
+ else
+ {
+ $ret .= $sl; // Probably just some white space
+ }
+ }
+
+ return $ret;
+ }
+
+
+}
+
+
+
+
diff --git a/e107_plugins/linkwords/e_tohtml.php b/e107_plugins/linkwords/e_tohtml.php
index ec75a8e13..ddfe063ce 100755
--- a/e107_plugins/linkwords/e_tohtml.php
+++ b/e107_plugins/linkwords/e_tohtml.php
@@ -9,387 +9,7 @@
*/
/**
- * e107 Linkword plugin
- *
- * 'Hook' page
- * The class is 'hooked' by the parser, to add linkword capability to any context where its enabled.
- *
- * @todo Link to capability for clever display options on tooltips
+ * @deprecated see linkwords/e_parse.php
*/
if (!defined('e107_INIT')) { exit; }
-// if (!e107::isInstalled('linkwords')) exit; // This will completely break a site during upgrades.
-
-define('LW_CACHE_ENABLE', FALSE);
-
-class e_tohtml_linkwords
-{
- 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
-
- 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
- var $LinkID = array(); // Unique ID for each linkword
- 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 $word_limit = array();
-// protected $maxPerWord = 3;
-
- public function enable()
- {
- $this->lw_enabled = true;
- }
-
- public function setWordData($arr = array())
- {
- foreach($arr as $val)
- {
- $this->word_list[] = $val['word'];
- $this->link_list[] = $val['link'];
- $this->ext_list[] = $val['ext'];
- $this->tip_list[] = $val['tip'];
- $this->word_limit[] = $val['limit'];
- }
- }
-
- public function setAreaOpts($arr = array())
- {
- $this->area_opts = $arr;
- }
-
-
- public function setLink($arr)
- {
- $this->word_list = $arr;
- }
-
-
- /* constructor */
- function __construct()
- {
- $tp = e107::getParser();
- $pref = e107::pref('core');
- $frm = e107::getForm();
-
- // $this->maxPerWord = vartrue($pref['lw_max_per_word'], 25);
- $this->customClass = vartrue($pref['lw_custom_class'],'');
- $this->area_opts = varset($pref['lw_context_visibility']);
- $this->utfMode = (strtolower(CHARSET) == 'utf-8') ? 'u' : ''; // Flag to enable utf-8 on regex //@TODO utfMode probably obsolete
- $this->lwAjaxEnabled = varset($pref['lw_ajax_enable'],0);
-
- // See whether they should be active on this page - if not, no point doing anything!
- if(e_ADMIN_AREA === true) { return; }
- // if ((strpos(e_SELF, ADMINDIR) !== FALSE) || (strpos(e_PAGE, "admin_") !== FALSE)) return; // No linkwords on admin directories
-
- // Now see if disabled on specific pages
- $check_url = e_SELF.(defined('e_QUERY') ? "?".e_QUERY : '');
- $this->block_list = explode("|",substr(varset($pref['lw_page_visibility'],''),2)); // Knock off the 'show/hide' flag
-
- foreach($this->block_list as $p)
- {
- if($p=trim($p))
- {
- if(substr($p, -1) == '!')
- {
- $p = substr($p, 0, -1);
- if(substr($check_url, strlen($p)*-1) == $p) return;
- }
- else
- {
- if(strpos($check_url, $p) !== FALSE) return;
- }
- }
- }
-
- // Will probably need linkwords on this page - so get the info
- define('LW_CACHE_TAG', 'nomd5_linkwords'); // Put it here to avoid conflict on admin pages
-
- if(LW_CACHE_ENABLE && ($temp = e107::getCache()->retrieve_sys(LW_CACHE_TAG)))
- {
- $ret = eval($temp);
- if ($ret)
- {
- echo "Error reading linkwords cache: {$ret}
";
- $temp = '';
- }
- else
- {
- $this->lw_enabled = TRUE;
- }
- }
-
- if(!vartrue($temp)) // Either cache disabled, or no info in cache (or error reading/processing cache)
- {
- $link_sql = e107::getDb('link_sql');
-
- if($link_sql->select("linkwords", "*", "linkword_active!=1"))
- {
- $this->lw_enabled = true;
-
- while($row = $link_sql->fetch())
- {
-
- $lw = $tp->ustrtolower($row['linkword_word']); // It was trimmed when saved *utf
-
- if($row['linkword_active'] == 2)
- {
- $row['linkword_link'] = ''; // Make sure linkword disabled
- }
-
- if($row['linkword_active'] < 2)
- {
- $row['linkword_tooltip'] = ''; // Make sure tooltip disabled
- }
-
- $lwID = max($row['linkword_tip_id'], $row['linkword_id']); // If no specific ID defined, use the DB record ID
-
-
- if(strpos($lw,',')) // Several words to same link
- {
- $lwlist = explode(',',$lw);
- foreach ($lwlist as $lw)
- {
- $lw = trim($lw);
-
- if(empty($lw))
- {
- continue;
- }
-
- $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;
- }
- }
- else
- {
-
- $lw = trim($lw);
-
- if(empty($lw))
- {
- continue;
- }
-
- $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;
- }
- }
-
- if(LW_CACHE_ENABLE) // Write to file for next time
- {
- $temp = '';
- foreach (array('word_list', 'link_list', 'tip_list', 'ext_list', 'LinkID') as $var)
- {
- $temp .= '$this->'.$var.'='.var_export($this->$var, TRUE).";\n";
- }
-
- e107::getCache()->set_sys(LW_CACHE_TAG,$temp);
- }
- }
- }
-
-
- }
-
-
- function to_html($text,$area = 'olddefault')
- {
-
- if(is_string($this->area_opts))
- {
- $this->area_opts = e107::unserialize($this->area_opts);
- }
-
- if($this->area_opts === null)
- {
- $this->area_opts = array();
- }
-
- if (!$this->lw_enabled || empty($this->area_opts) || !array_key_exists($area,$this->area_opts) || !$this->area_opts[$area])
- {
- // e107::getDebug()->log("Link words skipped on ".substr($text, 0, 50));
- return $text; // No linkwords in disabled areas
- }
-
- // Split up by HTML tags and process the odd bits here
- $ptext = "";
- $lflag = FALSE;
-
- // Shouldn't need utf-8 on next line - just looking for HTML tags
- $content = preg_split('#(<.*?>)#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
-
- foreach($content as $cont)
- {
- if ($cont[0] == "<")
- { // Its some HTML
- $ptext .= $cont;
- if (substr($cont,0,2) == "linksproc($cont,0,count($this->word_list));
- // echo "Check linkwords: ".count($this->word_list).'
';
- }
- else
- {
- $ptext .= $cont;
- }
- }
- }
- }
-
- // print_a($this->wordCount);
- return $ptext;
- }
-
-
- /**
- * This function is called recursively - it splits the text up into blocks - some containing a particular linkword
- * @param $text
- * @param $first
- * @param $limit
- * @return string
- */
- function linksproc($text,$first,$limit)
- {
- $tp = e107::getParser();
- $doSamePage = !e107::getPref('lw_notsamepage');
-
- for (; $first < $limit; $first ++)
- {
- if (empty($this->word_list[$first])) continue;
- if (strpos($tp->ustrtolower($text), $this->word_list[$first]) !== false) break;
- }
-
- 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
- // If supporting Ajax, use the following:
- //
- // linkwordId::122 is a unique ID
-
- $ret = '';
- $linkwd = '';
- $linkrel = array();
- // $linkwd = "href='#' "; // Not relevant for Prototype, but needed with 'pure' JS to make tooltip stuff work - doesn't find link elements without href
- $lwClass = array();
- $lw = $this->word_list[$first]; // This is the word we're matching - in lower case in our 'master' list
- $tooltip = '';
-
- if ($this->tip_list[$first])
- { // Got tooltip
- if ($this->lwAjaxEnabled)
- {
- $linkrel[] = 'linkwordID::'.$this->LinkID[$first];
- $lwClass[] = 'lw-ajax '.$this->customClass;
- }
- else
- {
- $tooltip = " title=\"{$this->tip_list[$first]}\" ";
- $lwClass[] = 'lw-tip '.$this->customClass;
- }
- }
-
- if ($this->link_list[$first]) // Got link
- {
- $newLink = $tp->replaceConstants($this->link_list[$first], 'full');
- if ($doSamePage || ($newLink != e_SELF.'?'.e_QUERY))
- {
- $linkwd = " href=\"".$newLink."\" ";
- if ($this->ext_list[$first]) { $linkrel[] = 'noopener external'; } // Determine external links
- $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)
- // }
-
- if (count($linkrel))
- {
- $linkwd .= " rel='".implode(' ',$linkrel)."'";
- }
-
- // This splits the text into blocks, some of which will precisely contain a linkword
- $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);
-
- if(!isset($this->wordCount[$hash]))
- {
- $this->wordCount[$hash] = 0;
- }
-
- foreach ($split_line as $count=>$sl)
- {
- if ($tp->ustrtolower($sl) == $lw && $this->wordCount[$hash] < (int) $this->word_limit[$first]) // Do linkword replace // We know the linkword is already lower case // *utf
- {
- $this->wordCount[$hash]++;
-
- $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
- {
- $ret .= $this->linksproc($sl,$first+1,$limit);
- }
- else
- {
- $ret .= $sl; // Probably just some white space
- }
- }
- return $ret;
- }
-}
-
diff --git a/e107_plugins/linkwords/linkwords.php b/e107_plugins/linkwords/linkwords.php
index 52199604c..663a14297 100644
--- a/e107_plugins/linkwords/linkwords.php
+++ b/e107_plugins/linkwords/linkwords.php
@@ -1,73 +1,13 @@
add('LINKWD_05',LWLAN_58.'[!br!]'.$pref['tohtml_hook'],''); // Log that the update was done
- return;
- }
-
-
- // This avoids confusing the parser!
- function to_html($text,$area = 'olddefault')
- {
- return $text;
- }
-
-
- function linkwords($text,$area = 'olddefault')
- {
- return $text;
- }
-
- function linksproc($text,$first,$limit)
- {
- return $text; // Shouldn't get called - but just in case
- }
-}
-
diff --git a/e107_plugins/linkwords/linkwords_setup.php b/e107_plugins/linkwords/linkwords_setup.php
new file mode 100644
index 000000000..ea1978c53
--- /dev/null
+++ b/e107_plugins/linkwords/linkwords_setup.php
@@ -0,0 +1,82 @@
+addDebug("Prefs need to be migrated out of core prefs and into linkwords prefs.");
+ return true;
+ }
+
+ return false;
+ }
+
+
+ function upgrade_post($var)
+ {
+
+ $plugPrefs = array(
+ 'lw_context_visibility' => 'lw_context_visibility',
+ 'lw_ajax_enable' => 'lw_ajax_enable',
+ 'lw_notsamepage' => 'lw_notsamepage',
+ 'linkword_omit_pages' => 'linkword_omit_pages',
+ 'lw_custom_class' => 'lw_custom_class',
+ );
+
+ if($saveData = e107::getConfig()->migrateData($plugPrefs, true))
+ {
+ e107::getPlugConfig('linkwords')->setPref($saveData)->save(true,true,true);
+ }
+
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/e107_plugins/linkwords/linkwords_sql.php b/e107_plugins/linkwords/linkwords_sql.php
index 3aa15daea..37b5869d0 100644
--- a/e107_plugins/linkwords/linkwords_sql.php
+++ b/e107_plugins/linkwords/linkwords_sql.php
@@ -7,5 +7,6 @@ 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',
+linkword_rel varchar(250) NOT NULL default '',
PRIMARY KEY (linkword_id)
) ENGINE=MyISAM AUTO_INCREMENT=1;
\ No newline at end of file
diff --git a/e107_plugins/linkwords/plugin.xml b/e107_plugins/linkwords/plugin.xml
index 0686d9371..4788eb8bc 100644
--- a/e107_plugins/linkwords/plugin.xml
+++ b/e107_plugins/linkwords/plugin.xml
@@ -1,12 +1,12 @@
-
+
This plugin will link specified words with a defined link and/or tooltip.
content
Configure LinkWords
-
+
0
2
@@ -23,5 +23,5 @@
'RAWTEXT' => ''
)
-
+
\ No newline at end of file
diff --git a/e107_tests/tests/unit/plugins/linkwords/e_tohtml_linkwordsTest.php b/e107_tests/tests/unit/plugins/linkwords/e_tohtml_linkwordsTest.php
index 550552f34..cf78b41fd 100644
--- a/e107_tests/tests/unit/plugins/linkwords/e_tohtml_linkwordsTest.php
+++ b/e107_tests/tests/unit/plugins/linkwords/e_tohtml_linkwordsTest.php
@@ -17,10 +17,10 @@
protected function _before()
{
- require_once(e_PLUGIN."linkwords/e_tohtml.php");
+ require_once(e_PLUGIN."linkwords/e_parse.php");
try
{
- $this->lw = $this->make('e_tohtml_linkwords');
+ $this->lw = $this->make('linkwords_parse');
} catch(Exception $e)
{
$this->assertTrue(false, "Couldn't load e_tohtml_linkwords object");
@@ -65,7 +65,7 @@
foreach($tests as $val)
{
- $result = $this->lw->to_html($val['text'], 'BODY');
+ $result = $this->lw->toHTML($val['text'], 'BODY');
$this->assertEquals($val['expected'],$result);
}
diff --git a/e107_tests/tests/unit/pluginsTest.php b/e107_tests/tests/unit/pluginsTest.php
index 13a2c202e..58b8de013 100644
--- a/e107_tests/tests/unit/pluginsTest.php
+++ b/e107_tests/tests/unit/pluginsTest.php
@@ -308,15 +308,15 @@
{
$this->pluginInstall('linkwords');
- $pref1 = e107::pref('core', 'lw_custom_class');
+ $pref1 = e107::pref('linkwords', 'lw_custom_class');
$this->assertNotEmpty($pref1);
- $pref2 = e107::pref('core', 'lw_context_visibility');
+ $pref2 = e107::pref('linkwords', 'lw_context_visibility');
$this->assertNotEmpty($pref2['SUMMARY']);
$this->pluginUninstall('linkwords');
- $pref2 = e107::pref('core', 'lw_context_visibility');
+ $pref2 = e107::pref('linkwords', 'lw_context_visibility');
$this->assertEmpty($pref2);
}