1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 12:48:26 +02:00

extra linkword class methods added to enable easy testing.

This commit is contained in:
Cameron
2019-04-25 15:52:05 -07:00
parent 1c168aefa1
commit cc8a4f8cdb

View File

@@ -53,11 +53,45 @@ class e_tohtml_linkwords
protected $word_limit = array(); protected $word_limit = array();
// protected $maxPerWord = 3; // 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 */ /* constructor */
function __construct() function __construct()
{ {
$tp = e107::getParser(); $tp = e107::getParser();
$pref = e107::pref('core'); $pref = e107::pref('core');
$frm = e107::getForm(); $frm = e107::getForm();
@@ -192,12 +226,13 @@ class e_tohtml_linkwords
} }
} }
} }
function to_html($text,$area = 'olddefault') function to_html($text,$area = 'olddefault')
{ {
if(is_string($this->area_opts)) if(is_string($this->area_opts))
{ {
$this->area_opts = e107::unserialize($this->area_opts); $this->area_opts = e107::unserialize($this->area_opts);
@@ -221,6 +256,7 @@ class e_tohtml_linkwords
// Shouldn't need utf-8 on next line - just looking for HTML tags // 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 ); $content = preg_split('#(<.*?>)#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
foreach($content as $cont) foreach($content as $cont)
{ {
if ($cont[0] == "<") if ($cont[0] == "<")
@@ -296,6 +332,8 @@ class e_tohtml_linkwords
$lw = $this->word_list[$first]; // This is the word we're matching - in lower case in our 'master' list $lw = $this->word_list[$first]; // This is the word we're matching - in lower case in our 'master' list
$tooltip = ''; $tooltip = '';
if ($this->tip_list[$first]) if ($this->tip_list[$first])
{ // Got tooltip { // Got tooltip
if ($this->lwAjaxEnabled) if ($this->lwAjaxEnabled)
@@ -305,7 +343,7 @@ class e_tohtml_linkwords
} }
else else
{ {
$tooltip = " title='{$this->tip_list[$first]}' "; $tooltip = " title=\"{$this->tip_list[$first]}\" ";
$lwClass[] = 'lw-tip '.$this->customClass; $lwClass[] = 'lw-tip '.$this->customClass;
} }
} }
@@ -315,7 +353,7 @@ class e_tohtml_linkwords
$newLink = $tp->replaceConstants($this->link_list[$first], 'full'); $newLink = $tp->replaceConstants($this->link_list[$first], 'full');
if ($doSamePage || ($newLink != e_SELF.'?'.e_QUERY)) if ($doSamePage || ($newLink != e_SELF.'?'.e_QUERY))
{ {
$linkwd = " href='".$newLink."' "; $linkwd = " href=\"".$newLink."\" ";
if ($this->ext_list[$first]) { $linkrel[] = 'external'; } // Determine external links if ($this->ext_list[$first]) { $linkrel[] = 'external'; } // Determine external links
$lwClass[] = 'lw-link '.$this->customClass; $lwClass[] = 'lw-link '.$this->customClass;
} }
@@ -323,8 +361,6 @@ class e_tohtml_linkwords
elseif(!empty($this->word_class[$first])) elseif(!empty($this->word_class[$first]))
{ {
$lwClass[] = $this->word_class[$first]; $lwClass[] = $this->word_class[$first];
} }
if (!count($lwClass)) if (!count($lwClass))
@@ -351,19 +387,20 @@ class e_tohtml_linkwords
foreach ($split_line as $count=>$sl) foreach ($split_line as $count=>$sl)
{ {
if ($tp->ustrtolower($sl) == $lw && $this->wordCount[$hash] < $this->word_limit[$first]) // Do linkword replace // We know the linkword is already lower case // *utf 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]++; $this->wordCount[$hash]++;
$classCount = " lw-".$this->wordCount[$hash]; $classCount = " lw-".$this->wordCount[$hash];
if(empty($linkwd)) if(empty($linkwd))
{ {
$ret .= '<span class="'.$class.$classCount.'" '.$tooltip.'>'.$sl.'</span>'; $ret .= "<span class=\"".$class.$classCount."\" ".$tooltip.">".$sl."</span>";
} }
else else
{ {
$ret .= '<a class="'.$class.$classCount.'" '.$linkwd.$tooltip.'>'.$sl.'</a>'; $ret .= "<a class=\"".$class.$classCount."\" ".$linkwd.$tooltip.">".$sl."</a>";
} }
} }