Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの
Revision | 1031044091e77e6b23df41619240784650644b2a (tree) |
---|---|
Time | 2006-10-06 16:42:55 |
Author | shizuki <shizuki@1ca2...> |
Commiter | shizuki |
とりあえず整形
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@427 1ca29b6e-896d-4ea0-84a5-967f57386b96
@@ -1,22 +1,46 @@ | ||
1 | 1 | <? |
2 | -// plugin needs to work on Nucleus versions <=2.0 as well | |
2 | +/* plugin needs to work on Nucleus versions <=2.0 as well | |
3 | 3 | if (!function_exists('sql_table')){ |
4 | 4 | function sql_table($name) { |
5 | 5 | return 'nucleus_' . $name; |
6 | 6 | } |
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 | + { | |
16 | 38 | return 'Chopped description. <%ChoppedDisc(250,1)%>'; |
17 | 39 | } |
18 | - function supportsFeature($what) { | |
19 | - switch($what){ | |
40 | + | |
41 | + function supportsFeature($what) | |
42 | + { | |
43 | + switch ($what) { | |
20 | 44 | case 'SqlTablePrefix': |
21 | 45 | return 1; |
22 | 46 | default: |
@@ -24,7 +48,8 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
24 | 48 | } |
25 | 49 | } |
26 | 50 | |
27 | - function parseHighlight($query) { | |
51 | + function parseHighlight($query) | |
52 | + { | |
28 | 53 | |
29 | 54 | // get rid of quotes |
30 | 55 | $query = preg_replace('/\'|"/','',$query); |
@@ -45,17 +70,19 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
45 | 70 | return $aHighlight; |
46 | 71 | } |
47 | 72 | |
48 | - function splitLastStr($str, $width=5){ | |
73 | + function splitLastStr($str, $width=5) | |
74 | + { | |
49 | 75 | $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; | |
52 | 78 | return $resArray; |
53 | 79 | } |
54 | 80 | |
55 | - function chopStr($str, $query, $maxLength){ | |
81 | + function chopStr($str, $query, $maxLength) | |
82 | + { | |
56 | 83 | |
57 | 84 | $searchclass =& new SEARCH($query); |
58 | - $highlight = $searchclass->inclusive; | |
85 | + $highlight = $searchclass->inclusive; | |
59 | 86 | $this->highlights = $this->parseHighlight($highlight); |
60 | 87 | |
61 | 88 | if(mb_strwidth($str) <= $maxLength) |
@@ -66,19 +93,21 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
66 | 93 | $maxLength = $maxLength - $tLength; |
67 | 94 | |
68 | 95 | $text = highlight($str, $this->highlights, '<\0>'); |
69 | - $text = '< >'.$text; | |
96 | + $text = '< >' . $text; | |
70 | 97 | preg_match_all('/(<[^>]+>)([^<>]*)/', $text, $matches); |
71 | 98 | 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]); | |
73 | 100 | } |
74 | 101 | /* |
75 | 102 | print_r($matches); |
76 | 103 | echo "<hr />"; |
77 | 104 | */ |
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 | + } | |
82 | 111 | } |
83 | 112 | } |
84 | 113 | } |
@@ -86,23 +115,24 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
86 | 115 | |
87 | 116 | if(!$hitkey){ |
88 | 117 | $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) { | |
90 | 119 | $tt .= $toated; |
91 | - }elseif($hitkey[1]){ | |
120 | + } | |
121 | + } elseif($hitkey[1]) { | |
92 | 122 | sort($hitkey); |
93 | - foreach($hitkey as $keyval){ | |
123 | + foreach ($hitkey as $keyval) { | |
94 | 124 | $hitWordArray[] = $matches[1][$keyval]; |
95 | 125 | } |
96 | 126 | |
97 | - $list[0] = array("qlen"=>0,"q"=>''); | |
127 | + $list[0] = array("qlen" => 0, "q" => ''); | |
98 | 128 | $trimLength = intval(($maxLength - mb_strwidth(join("",$hitWordArray))) / (count($hitWordArray) +1)); |
99 | 129 | |
100 | 130 | $left = $str; |
101 | 131 | $i=0; |
102 | - while($i <= count($hitWordArray)){ | |
132 | + while ($i <= count($hitWordArray)) { | |
103 | 133 | // $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, ''); | |
106 | 136 | |
107 | 137 | $left = $preStr[1].$hitWord.$tempArray[1]; |
108 | 138 |
@@ -118,21 +148,21 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
118 | 148 | $list[$i]['trimlen'] = $list[$i]['len'] - $tempTrimLen; |
119 | 149 | } |
120 | 150 | |
121 | - if(!$hitWord) break; | |
151 | + if (!$hitWord) break; | |
122 | 152 | $i++; |
123 | 153 | $list[$i]['q'] = $hitWord; |
124 | 154 | $list[$i]['qlen'] = mb_strwidth($hitWord); |
125 | 155 | } |
126 | 156 | // print_r($list); |
127 | 157 | |
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)) { | |
130 | 160 | $list[$i]['trimlen'] = min($list[$i]['trimlen'], $addsum); |
131 | 161 | $addsum -= $list[$i]['trimlen']; |
132 | 162 | $list[$i]['trimlen'] = $trimLength + $list[$i]['trimlen'] + $list[$i]['qlen']; |
133 | - }elseif($list[$i]['trimlen']){ | |
163 | + } elseif($list[$i]['trimlen']) { | |
134 | 164 | $list[$i]['trimlen'] = $trimLength + $list[$i]['qlen']; |
135 | - }else{ | |
165 | + } else { | |
136 | 166 | $list[$i]['trimlen'] = $list[$i]['len']; |
137 | 167 | } |
138 | 168 | } |
@@ -143,15 +173,17 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
143 | 173 | $list[0]['len'] - $list[0]['trimlen'], |
144 | 174 | $list[0]['trimlen'] + 2, |
145 | 175 | _CHARSET); |
146 | - if($list[0]['len'] > $list[0]['trimlen']) | |
176 | + if ($list[0]['len'] > $list[0]['trimlen']) { | |
147 | 177 | $tt = $toated.$tt; |
178 | + } | |
148 | 179 | |
149 | - for($i=1;$i<count($list);$i++){ | |
180 | + for ($i=1;$i<count($list);$i++) { | |
150 | 181 | $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']) { | |
152 | 183 | $tt .= $toated; |
184 | + } | |
153 | 185 | } |
154 | - }else{ | |
186 | + } else { | |
155 | 187 | $hitWord = $this->highlights[0]; |
156 | 188 | $keyLength = mb_strwidth($hitWord); |
157 | 189 |
@@ -164,11 +196,11 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
164 | 196 | |
165 | 197 | $hTrimLength = $preTrimLength = $halfLength; |
166 | 198 | $minLength = min($preStrLength, $hStrLength, $halfLength); |
167 | - if($preStrLength == $minLength){ | |
199 | + if ($preStrLength == $minLength) { | |
168 | 200 | $hTrimLength = $maxLength - $keyLength - $preStrLength; |
169 | 201 | $preTrimLength = $preStrLength; |
170 | 202 | } |
171 | - if($hStrLength == $minLength){ | |
203 | + if ($hStrLength == $minLength) { | |
172 | 204 | $preTrimLength = $maxLength - $keyLength - $hStrLength; |
173 | 205 | $hTrimLength = $hStrLength; |
174 | 206 | } |
@@ -177,10 +209,12 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
177 | 209 | $tt .= $matches[1][1]; |
178 | 210 | $tt .= mb_strcut($hStr, 0, $hTrimLength,_CHARSET); |
179 | 211 | |
180 | - if($preTrimLength < $preStrLength) | |
212 | + if ($preTrimLength < $preStrLength) { | |
181 | 213 | $tt = $toated . $tt; |
182 | - if($hTrimLength < $hStrLength) | |
214 | + } | |
215 | + if ($hTrimLength < $hStrLength) { | |
183 | 216 | $tt .= $toated; |
217 | + } | |
184 | 218 | |
185 | 219 | } |
186 | 220 |
@@ -210,7 +244,8 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
210 | 244 | */ |
211 | 245 | } |
212 | 246 | |
213 | - function doTemplateVar(&$item, $maxLength = 250, $addHighlight = 0){ | |
247 | + function doTemplateVar(&$item, $maxLength = 250, $addHighlight = 0) | |
248 | + { | |
214 | 249 | global $CONF, $manager, $member, $catid; |
215 | 250 | global $query; |
216 | 251 |
@@ -222,7 +257,7 @@ class NP_ChoppedDisc extends NucleusPlugin { | ||
222 | 257 | |
223 | 258 | $syndicated = strip_tags($item->body); |
224 | 259 | $syndicated .= strip_tags($item->more); |
225 | - $syndicated = preg_replace("/[\r\n]/","",$syndicated); | |
260 | + $syndicated = preg_replace("/[\r\n]/", "", $syndicated); | |
226 | 261 | |
227 | 262 | $syndicated = $this->chopStr($syndicated, $query, $maxLength); |
228 | 263 |