<?
-// plugin needs to work on Nucleus versions <=2.0 as well
+/* plugin needs to work on Nucleus versions <=2.0 as well
if (!function_exists('sql_table')){
function sql_table($name) {
return 'nucleus_' . $name;
}
-}
-
-class NP_ChoppedDisc extends NucleusPlugin {
- function getEventList() { return array(); }
- function getName() { return 'Chopped description'; }
- function getAuthor() { return 'nakahara21'; }
- function getURL() { return 'http://nakahara21.com/'; }
- function getVersion() { return '0.7'; }
- function getDescription() {
+}*/
+
+class NP_ChoppedDisc extends NucleusPlugin
+{
+ function getEventList()
+ {
+ return array();
+ }
+
+ function getName()
+ {
+ return 'Chopped description';
+ }
+
+ function getAuthor()
+ {
+ return 'nakahara21';
+ }
+
+ function getURL()
+ {
+ return 'http://nakahara21.com';
+ }
+
+ function getVersion()
+ {
+ return '0.7';
+ }
+
+ function getDescription()
+ {
return 'Chopped description. <%ChoppedDisc(250,1)%>';
}
- function supportsFeature($what) {
- switch($what){
+
+ function supportsFeature($what)
+ {
+ switch ($what) {
case 'SqlTablePrefix':
return 1;
default:
}
}
- function parseHighlight($query) {
+ function parseHighlight($query)
+ {
// get rid of quotes
$query = preg_replace('/\'|"/','',$query);
return $aHighlight;
}
- function splitLastStr($str, $width=5){
+ function splitLastStr($str, $width=5)
+ {
$posn = (mb_strwidth($str) > $width)? mb_strwidth($str) - $width: 0;
- $resArray[0] = ($posn)? mb_strcut($str, 0, $posn, _CHARSET): '';
- $resArray[1] = ($posn)? mb_strcut($str, $posn, $width + 2, _CHARSET): $str;
+ $resArray[0] = ($posn) ? mb_strcut($str, 0, $posn, _CHARSET) : '';
+ $resArray[1] = ($posn) ? mb_strcut($str, $posn, $width + 2, _CHARSET) : $str;
return $resArray;
}
- function chopStr($str, $query, $maxLength){
+ function chopStr($str, $query, $maxLength)
+ {
$searchclass =& new SEARCH($query);
- $highlight = $searchclass->inclusive;
+ $highlight = $searchclass->inclusive;
$this->highlights = $this->parseHighlight($highlight);
if(mb_strwidth($str) <= $maxLength)
$maxLength = $maxLength - $tLength;
$text = highlight($str, $this->highlights, '<\0>');
- $text = '< >'.$text;
+ $text = '< >' . $text;
preg_match_all('/(<[^>]+>)([^<>]*)/', $text, $matches);
for($i=0;$i<count($matches[1]);$i++){
- $matches[1][$i] = ereg_replace("<|>",'',$matches[1][$i]);
+ $matches[1][$i] = ereg_replace("<|>", '', $matches[1][$i]);
}
/*
print_r($matches);
echo "<hr />";
*/
- for($i=0;$i<count($this->highlights);$i++){
- for($e=0;$e<count($matches[1]);$e++){
- if(eregi($this->highlights[$i], $matches[1][$e])){
- if(!$hitkey[$i]) $hitkey[$i] = $e;
+ for ($i=0;$i<count($this->highlights);$i++) {
+ for ($e=0;$e<count($matches[1]);$e++) {
+ if (eregi($this->highlights[$i], $matches[1][$e])) {
+ if (!$hitkey[$i]) {
+ $hitkey[$i] = $e;
+ }
}
}
}
if(!$hitkey){
$tt = mb_strcut($matches[2][0], 0, $maxLength, _CHARSET);
- if(mb_strwidth($matches[2][0]) > $maxLength)
+ if(mb_strwidth($matches[2][0]) > $maxLength) {
$tt .= $toated;
- }elseif($hitkey[1]){
+ }
+ } elseif($hitkey[1]) {
sort($hitkey);
- foreach($hitkey as $keyval){
+ foreach ($hitkey as $keyval) {
$hitWordArray[] = $matches[1][$keyval];
}
- $list[0] = array("qlen"=>0,"q"=>'');
+ $list[0] = array("qlen" => 0, "q" => '');
$trimLength = intval(($maxLength - mb_strwidth(join("",$hitWordArray))) / (count($hitWordArray) +1));
$left = $str;
$i=0;
- while($i <= count($hitWordArray)){
+ while ($i <= count($hitWordArray)) {
// $hitWord = $hitWordArray[$i];
- $tempArray = ($hitWord = $hitWordArray[$i])? explode($hitWord, $left, 2): array($left, '');
- $preStr = ($hitWord)? $this->splitLastStr($tempArray[0], 5): array($left, '');
+ $tempArray = ($hitWord = $hitWordArray[$i]) ? explode($hitWord, $left, 2) : array($left, '');
+ $preStr = ($hitWord) ? $this->splitLastStr($tempArray[0], 5) : array($left, '');
$left = $preStr[1].$hitWord.$tempArray[1];
$list[$i]['trimlen'] = $list[$i]['len'] - $tempTrimLen;
}
- if(!$hitWord) break;
+ if (!$hitWord) break;
$i++;
$list[$i]['q'] = $hitWord;
$list[$i]['qlen'] = mb_strwidth($hitWord);
}
// print_r($list);
- for($i=0;$i<count($list);$i++){
- if($list[$i]['trimlen'] && ($addsum > 0)){
+ for ($i=0;$i<count($list);$i++) {
+ if ($list[$i]['trimlen'] && ($addsum > 0)) {
$list[$i]['trimlen'] = min($list[$i]['trimlen'], $addsum);
$addsum -= $list[$i]['trimlen'];
$list[$i]['trimlen'] = $trimLength + $list[$i]['trimlen'] + $list[$i]['qlen'];
- }elseif($list[$i]['trimlen']){
+ } elseif($list[$i]['trimlen']) {
$list[$i]['trimlen'] = $trimLength + $list[$i]['qlen'];
- }else{
+ } else {
$list[$i]['trimlen'] = $list[$i]['len'];
}
}
$list[0]['len'] - $list[0]['trimlen'],
$list[0]['trimlen'] + 2,
_CHARSET);
- if($list[0]['len'] > $list[0]['trimlen'])
+ if ($list[0]['len'] > $list[0]['trimlen']) {
$tt = $toated.$tt;
+ }
- for($i=1;$i<count($list);$i++){
+ for ($i=1;$i<count($list);$i++) {
$tt .= mb_strcut($list[$i]['str'], 0, $list[$i]['trimlen'], _CHARSET);
- if($list[$i]['len'] > $list[$i]['trimlen'])
+ if ($list[$i]['len'] > $list[$i]['trimlen']) {
$tt .= $toated;
+ }
}
- }else{
+ } else {
$hitWord = $this->highlights[0];
$keyLength = mb_strwidth($hitWord);
$hTrimLength = $preTrimLength = $halfLength;
$minLength = min($preStrLength, $hStrLength, $halfLength);
- if($preStrLength == $minLength){
+ if ($preStrLength == $minLength) {
$hTrimLength = $maxLength - $keyLength - $preStrLength;
$preTrimLength = $preStrLength;
}
- if($hStrLength == $minLength){
+ if ($hStrLength == $minLength) {
$preTrimLength = $maxLength - $keyLength - $hStrLength;
$hTrimLength = $hStrLength;
}
$tt .= $matches[1][1];
$tt .= mb_strcut($hStr, 0, $hTrimLength,_CHARSET);
- if($preTrimLength < $preStrLength)
+ if ($preTrimLength < $preStrLength) {
$tt = $toated . $tt;
- if($hTrimLength < $hStrLength)
+ }
+ if ($hTrimLength < $hStrLength) {
$tt .= $toated;
+ }
}
*/
}
- function doTemplateVar(&$item, $maxLength = 250, $addHighlight = 0){
+ function doTemplateVar(&$item, $maxLength = 250, $addHighlight = 0)
+ {
global $CONF, $manager, $member, $catid;
global $query;
$syndicated = strip_tags($item->body);
$syndicated .= strip_tags($item->more);
- $syndicated = preg_replace("/[\r\n]/","",$syndicated);
+ $syndicated = preg_replace("/[\r\n]/", "", $syndicated);
$syndicated = $this->chopStr($syndicated, $query, $maxLength);