• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revision1031044091e77e6b23df41619240784650644b2a (tree)
Time2006-10-06 16:42:55
Authorshizuki <shizuki@1ca2...>
Commitershizuki

Log Message

とりあえず整形

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@427 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- a/trunk/NP_ChoppedDisc/NP_ChoppedDisc.php
+++ b/trunk/NP_ChoppedDisc/NP_ChoppedDisc.php
@@ -1,22 +1,46 @@
11 <?
2-// plugin needs to work on Nucleus versions <=2.0 as well
2+/* plugin needs to work on Nucleus versions <=2.0 as well
33 if (!function_exists('sql_table')){
44 function sql_table($name) {
55 return 'nucleus_' . $name;
66 }
7-}
8-
9-class NP_ChoppedDisc extends NucleusPlugin {
10- function getEventList() { return array(); }
11- function getName() { return 'Chopped description'; }
12- function getAuthor() { return 'nakahara21'; }
13- function getURL() { return 'http://nakahara21.com/'; }
14- function getVersion() { return '0.7'; }
15- function getDescription() {
7+}*/
8+
9+class NP_ChoppedDisc extends NucleusPlugin
10+{
11+ function getEventList()
12+ {
13+ return array();
14+ }
15+
16+ function getName()
17+ {
18+ return 'Chopped description';
19+ }
20+
21+ function getAuthor()
22+ {
23+ return 'nakahara21';
24+ }
25+
26+ function getURL()
27+ {
28+ return 'http://nakahara21.com';
29+ }
30+
31+ function getVersion()
32+ {
33+ return '0.7';
34+ }
35+
36+ function getDescription()
37+ {
1638 return 'Chopped description. &lt;%ChoppedDisc(250,1)%&gt;';
1739 }
18- function supportsFeature($what) {
19- switch($what){
40+
41+ function supportsFeature($what)
42+ {
43+ switch ($what) {
2044 case 'SqlTablePrefix':
2145 return 1;
2246 default:
@@ -24,7 +48,8 @@ class NP_ChoppedDisc extends NucleusPlugin {
2448 }
2549 }
2650
27- function parseHighlight($query) {
51+ function parseHighlight($query)
52+ {
2853
2954 // get rid of quotes
3055 $query = preg_replace('/\'|"/','',$query);
@@ -45,17 +70,19 @@ class NP_ChoppedDisc extends NucleusPlugin {
4570 return $aHighlight;
4671 }
4772
48- function splitLastStr($str, $width=5){
73+ function splitLastStr($str, $width=5)
74+ {
4975 $posn = (mb_strwidth($str) > $width)? mb_strwidth($str) - $width: 0;
50- $resArray[0] = ($posn)? mb_strcut($str, 0, $posn, _CHARSET): '';
51- $resArray[1] = ($posn)? mb_strcut($str, $posn, $width + 2, _CHARSET): $str;
76+ $resArray[0] = ($posn) ? mb_strcut($str, 0, $posn, _CHARSET) : '';
77+ $resArray[1] = ($posn) ? mb_strcut($str, $posn, $width + 2, _CHARSET) : $str;
5278 return $resArray;
5379 }
5480
55- function chopStr($str, $query, $maxLength){
81+ function chopStr($str, $query, $maxLength)
82+ {
5683
5784 $searchclass =& new SEARCH($query);
58- $highlight = $searchclass->inclusive;
85+ $highlight = $searchclass->inclusive;
5986 $this->highlights = $this->parseHighlight($highlight);
6087
6188 if(mb_strwidth($str) <= $maxLength)
@@ -66,19 +93,21 @@ class NP_ChoppedDisc extends NucleusPlugin {
6693 $maxLength = $maxLength - $tLength;
6794
6895 $text = highlight($str, $this->highlights, '<\0>');
69- $text = '< >'.$text;
96+ $text = '< >' . $text;
7097 preg_match_all('/(<[^>]+>)([^<>]*)/', $text, $matches);
7198 for($i=0;$i<count($matches[1]);$i++){
72- $matches[1][$i] = ereg_replace("<|>",'',$matches[1][$i]);
99+ $matches[1][$i] = ereg_replace("<|>", '', $matches[1][$i]);
73100 }
74101 /*
75102 print_r($matches);
76103 echo "<hr />";
77104 */
78- for($i=0;$i<count($this->highlights);$i++){
79- for($e=0;$e<count($matches[1]);$e++){
80- if(eregi($this->highlights[$i], $matches[1][$e])){
81- if(!$hitkey[$i]) $hitkey[$i] = $e;
105+ for ($i=0;$i<count($this->highlights);$i++) {
106+ for ($e=0;$e<count($matches[1]);$e++) {
107+ if (eregi($this->highlights[$i], $matches[1][$e])) {
108+ if (!$hitkey[$i]) {
109+ $hitkey[$i] = $e;
110+ }
82111 }
83112 }
84113 }
@@ -86,23 +115,24 @@ class NP_ChoppedDisc extends NucleusPlugin {
86115
87116 if(!$hitkey){
88117 $tt = mb_strcut($matches[2][0], 0, $maxLength, _CHARSET);
89- if(mb_strwidth($matches[2][0]) > $maxLength)
118+ if(mb_strwidth($matches[2][0]) > $maxLength) {
90119 $tt .= $toated;
91- }elseif($hitkey[1]){
120+ }
121+ } elseif($hitkey[1]) {
92122 sort($hitkey);
93- foreach($hitkey as $keyval){
123+ foreach ($hitkey as $keyval) {
94124 $hitWordArray[] = $matches[1][$keyval];
95125 }
96126
97- $list[0] = array("qlen"=>0,"q"=>'');
127+ $list[0] = array("qlen" => 0, "q" => '');
98128 $trimLength = intval(($maxLength - mb_strwidth(join("",$hitWordArray))) / (count($hitWordArray) +1));
99129
100130 $left = $str;
101131 $i=0;
102- while($i <= count($hitWordArray)){
132+ while ($i <= count($hitWordArray)) {
103133 // $hitWord = $hitWordArray[$i];
104- $tempArray = ($hitWord = $hitWordArray[$i])? explode($hitWord, $left, 2): array($left, '');
105- $preStr = ($hitWord)? $this->splitLastStr($tempArray[0], 5): array($left, '');
134+ $tempArray = ($hitWord = $hitWordArray[$i]) ? explode($hitWord, $left, 2) : array($left, '');
135+ $preStr = ($hitWord) ? $this->splitLastStr($tempArray[0], 5) : array($left, '');
106136
107137 $left = $preStr[1].$hitWord.$tempArray[1];
108138
@@ -118,21 +148,21 @@ class NP_ChoppedDisc extends NucleusPlugin {
118148 $list[$i]['trimlen'] = $list[$i]['len'] - $tempTrimLen;
119149 }
120150
121- if(!$hitWord) break;
151+ if (!$hitWord) break;
122152 $i++;
123153 $list[$i]['q'] = $hitWord;
124154 $list[$i]['qlen'] = mb_strwidth($hitWord);
125155 }
126156 // print_r($list);
127157
128- for($i=0;$i<count($list);$i++){
129- if($list[$i]['trimlen'] && ($addsum > 0)){
158+ for ($i=0;$i<count($list);$i++) {
159+ if ($list[$i]['trimlen'] && ($addsum > 0)) {
130160 $list[$i]['trimlen'] = min($list[$i]['trimlen'], $addsum);
131161 $addsum -= $list[$i]['trimlen'];
132162 $list[$i]['trimlen'] = $trimLength + $list[$i]['trimlen'] + $list[$i]['qlen'];
133- }elseif($list[$i]['trimlen']){
163+ } elseif($list[$i]['trimlen']) {
134164 $list[$i]['trimlen'] = $trimLength + $list[$i]['qlen'];
135- }else{
165+ } else {
136166 $list[$i]['trimlen'] = $list[$i]['len'];
137167 }
138168 }
@@ -143,15 +173,17 @@ class NP_ChoppedDisc extends NucleusPlugin {
143173 $list[0]['len'] - $list[0]['trimlen'],
144174 $list[0]['trimlen'] + 2,
145175 _CHARSET);
146- if($list[0]['len'] > $list[0]['trimlen'])
176+ if ($list[0]['len'] > $list[0]['trimlen']) {
147177 $tt = $toated.$tt;
178+ }
148179
149- for($i=1;$i<count($list);$i++){
180+ for ($i=1;$i<count($list);$i++) {
150181 $tt .= mb_strcut($list[$i]['str'], 0, $list[$i]['trimlen'], _CHARSET);
151- if($list[$i]['len'] > $list[$i]['trimlen'])
182+ if ($list[$i]['len'] > $list[$i]['trimlen']) {
152183 $tt .= $toated;
184+ }
153185 }
154- }else{
186+ } else {
155187 $hitWord = $this->highlights[0];
156188 $keyLength = mb_strwidth($hitWord);
157189
@@ -164,11 +196,11 @@ class NP_ChoppedDisc extends NucleusPlugin {
164196
165197 $hTrimLength = $preTrimLength = $halfLength;
166198 $minLength = min($preStrLength, $hStrLength, $halfLength);
167- if($preStrLength == $minLength){
199+ if ($preStrLength == $minLength) {
168200 $hTrimLength = $maxLength - $keyLength - $preStrLength;
169201 $preTrimLength = $preStrLength;
170202 }
171- if($hStrLength == $minLength){
203+ if ($hStrLength == $minLength) {
172204 $preTrimLength = $maxLength - $keyLength - $hStrLength;
173205 $hTrimLength = $hStrLength;
174206 }
@@ -177,10 +209,12 @@ class NP_ChoppedDisc extends NucleusPlugin {
177209 $tt .= $matches[1][1];
178210 $tt .= mb_strcut($hStr, 0, $hTrimLength,_CHARSET);
179211
180- if($preTrimLength < $preStrLength)
212+ if ($preTrimLength < $preStrLength) {
181213 $tt = $toated . $tt;
182- if($hTrimLength < $hStrLength)
214+ }
215+ if ($hTrimLength < $hStrLength) {
183216 $tt .= $toated;
217+ }
184218
185219 }
186220
@@ -210,7 +244,8 @@ class NP_ChoppedDisc extends NucleusPlugin {
210244 */
211245 }
212246
213- function doTemplateVar(&$item, $maxLength = 250, $addHighlight = 0){
247+ function doTemplateVar(&$item, $maxLength = 250, $addHighlight = 0)
248+ {
214249 global $CONF, $manager, $member, $catid;
215250 global $query;
216251
@@ -222,7 +257,7 @@ class NP_ChoppedDisc extends NucleusPlugin {
222257
223258 $syndicated = strip_tags($item->body);
224259 $syndicated .= strip_tags($item->more);
225- $syndicated = preg_replace("/[\r\n]/","",$syndicated);
260+ $syndicated = preg_replace("/[\r\n]/", "", $syndicated);
226261
227262 $syndicated = $this->chopStr($syndicated, $query, $maxLength);
228263
Show on old repository browser