OSDN Git Service

とりあえず整形
authorshizuki <shizuki@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Fri, 6 Oct 2006 07:42:55 +0000 (07:42 +0000)
committershizuki <shizuki@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Fri, 6 Oct 2006 07:42:55 +0000 (07:42 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@427 1ca29b6e-896d-4ea0-84a5-967f57386b96

trunk/NP_ChoppedDisc/NP_ChoppedDisc.php

index 20cd0f3..83e6fd5 100644 (file)
@@ -1,22 +1,46 @@
 <?
-// 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. &lt;%ChoppedDisc(250,1)%&gt;';
        }
-       function supportsFeature($what) {
-               switch($what){
+
+       function supportsFeature($what)
+       {
+               switch ($what) {
                        case 'SqlTablePrefix':
                                return 1;
                        default:
@@ -24,7 +48,8 @@ class NP_ChoppedDisc extends NucleusPlugin {
                }
        }
 
-       function parseHighlight($query) {
+       function parseHighlight($query)
+       {
        
                // get rid of quotes
                $query = preg_replace('/\'|"/','',$query);
@@ -45,17 +70,19 @@ class NP_ChoppedDisc extends NucleusPlugin {
                        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)
@@ -66,19 +93,21 @@ class NP_ChoppedDisc extends NucleusPlugin {
                $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;
+                                       }
                                }
                        }
                }
@@ -86,23 +115,24 @@ class NP_ChoppedDisc extends NucleusPlugin {
 
                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];
 
@@ -118,21 +148,21 @@ class NP_ChoppedDisc extends NucleusPlugin {
                                        $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'];
                                }
                        }
@@ -143,15 +173,17 @@ class NP_ChoppedDisc extends NucleusPlugin {
                                 $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);
                        
@@ -164,11 +196,11 @@ class NP_ChoppedDisc extends NucleusPlugin {
 
                        $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;
                        }
@@ -177,10 +209,12 @@ class NP_ChoppedDisc extends NucleusPlugin {
                        $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;
+                       }
 
                }
 
@@ -210,7 +244,8 @@ class NP_ChoppedDisc extends NucleusPlugin {
 */
        }
 
-       function doTemplateVar(&$item, $maxLength = 250, $addHighlight = 0){
+       function doTemplateVar(&$item, $maxLength = 250, $addHighlight = 0)
+       {
                global $CONF, $manager, $member, $catid;
                global $query;
 
@@ -222,7 +257,7 @@ class NP_ChoppedDisc extends NucleusPlugin {
 
                $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);