• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisionfd148a94f34566cd8df35b36f3cdd77c18b191b9 (tree)
Time2022-01-24 01:55:11
Authorhai-fun <haifun129@gmai...>
Commiterhai-fun

Log Message

PHP8

Change Summary

Incremental Difference

--- a/tag/tag.inc.php
+++ b/tag/tag.inc.php
@@ -8,1328 +8,1337 @@
88 * @version $Id: tag.inc.php,v 1.30 2008-03-19 07:23:17Z sonots $
99 * @package plugin
1010 */
11-
11+ // v1.31 PHP8.0対応 2021-12-15 byはいふん
12+
1213 class PluginTag extends Tag
1314 {
14- function PluginTag()
15- {
16- parent::Tag();
17- static $conf = array();
18- if (empty($conf)) {
19- $conf['listcmd'] = get_script_uri() . '?cmd=taglist&amp;tag=';
20- $conf['use_session'] = TRUE;
21- $conf['through_if_admin'] = TRUE;
22- }
23- $this->conf = & $conf;
24- }
15+ function __construct()
16+ {
17+ parent::__construct();
18+ static $conf = array();
19+ if (empty($conf)) {
20+ $conf['listcmd'] = get_script_uri() . '?cmd=taglist&amp;tag=';
21+ $conf['use_session'] = TRUE;
22+ $conf['through_if_admin'] = TRUE;
23+ }
24+ $this->conf = & $conf;
25+ }
26+
27+ function PluginTag() {
28+ $this->__construct();
29+ }
2530
26- var $conf;
27- var $plugin = 'tag';
31+ var $conf;
32+ var $plugin = 'tag';
2833
29- function action() // clean cache
30- {
31- global $vars;
32- if (is_admin($vars['pass'], $this->conf['use_session'], $this->conf['through_if_admin'])) {
33- $body = $this->clean_cache();
34- } else {
35- $body = $this->display_password_form();
36- }
37- return array('msg'=>'Clean Tag Caches', 'body'=>$body);
38- }
39-
40- /**
41- * Clean Tag Caches
42- *
43- * @return string HTML
44- */
45- function clean_cache()
46- {
47- set_time_limit(0);
48- global $vars;
49-
50- // remove all files
51- $files = $this->get_items_filenames();
52- $files = array_merge($files, $this->get_tags_filenames());
53- $files = array_merge($files, (array)$this->get_tagcloud_filename());
54- foreach ($files as $file) {
55- unlink($file);
56- }
57- // execute all pages
58- $exec_pages = exec_existpages('/&tag\([^;]*\);/');
59- if (empty($exec_pages)) {
60- $html = '';
61- } else {
62- $links = array_map('make_pagelink', $exec_pages);
63- $html = '<p>Following pages were executed to assure:</p>'
64- . '<p>' . implode("<br />\n", $links) . '</p>';
65- }
66- $html .= $this->display_tagcloud(NULL);
67- return $html;
68- }
34+ function action() // clean cache
35+ {
36+ global $vars;
37+ if (is_admin($vars['pass'], $this->conf['use_session'], $this->conf['through_if_admin'])) {
38+ $body = $this->clean_cache();
39+ } else {
40+ $body = $this->display_password_form();
41+ }
42+ return array('msg'=>'Clean Tag Caches', 'body'=>$body);
43+ }
44+
45+ /**
46+ * Clean Tag Caches
47+ *
48+ * @return string HTML
49+ */
50+ function clean_cache()
51+ {
52+ set_time_limit(0);
53+ global $vars;
54+
55+ // remove all files
56+ $files = $this->get_items_filenames();
57+ $files = array_merge($files, $this->get_tags_filenames());
58+ $files = array_merge($files, (array)$this->get_tagcloud_filename());
59+ foreach ($files as $file) {
60+ unlink($file);
61+ }
62+ // execute all pages
63+ $exec_pages = exec_existpages('/&tag\([^;]*\);/');
64+ if (empty($exec_pages)) {
65+ $html = '';
66+ } else {
67+ $links = array_map('make_pagelink', $exec_pages);
68+ $html = '<p>Following pages were executed to assure:</p>'
69+ . '<p>' . implode("<br />\n", $links) . '</p>';
70+ }
71+ $html .= $this->display_tagcloud(NULL);
72+ return $html;
73+ }
6974
70- /**
71- * Display a password form
72- *
73- * @param $msg error message or some messages
74- * @return string form html
75- */
76- function display_password_form($message = "")
77- {
78- $cmd = $this->plugin;
79- $pcmd = 'clean';
80- $form = array();
81- $form[] = '<form action="' . get_script_uri() . '?cmd=' . $cmd . '" method="post">';
82- $form[] = '<div>';
83- $form[] = ' <input type="hidden" name="pcmd" value="' . $pcmd . '" />';
84- if (! is_admin(null, $this->conf['use_session'], $this->conf['through_if_admin'])) {
85- $form[] = ' <input type="password" name="pass" size="24" value="" /> ' . _('Admin Password') . '<br />';
86- }
87- $form[] = ' <input type="submit" name="submit" value="Submit" /><br />';
88- $form[] = '</div>';
89- $form[] = '</form>';
90- $form = implode("\n", $form);
91-
92- if ($message != '') {
93- $message = '<p><b>' . htmlspecialchars($message) . '</b></p>';
94- }
95- return $message . $form;
96- }
75+ /**
76+ * Display a password form
77+ *
78+ * @param $msg error message or some messages
79+ * @return string form html
80+ */
81+ function display_password_form($message = "")
82+ {
83+ $cmd = $this->plugin;
84+ $pcmd = 'clean';
85+ $form = array();
86+ $form[] = '<form action="' . get_script_uri() . '?cmd=' . $cmd . '" method="post">';
87+ $form[] = '<div>';
88+ $form[] = ' <input type="hidden" name="pcmd" value="' . $pcmd . '" />';
89+ if (! is_admin(null, $this->conf['use_session'], $this->conf['through_if_admin'])) {
90+ $form[] = ' <input type="password" name="pass" size="24" value="" /> ' . _('Admin Password') . '<br />';
91+ }
92+ $form[] = ' <input type="submit" name="submit" value="Submit" /><br />';
93+ $form[] = '</div>';
94+ $form[] = '</form>';
95+ $form = implode("\n", $form);
96+
97+ if ($message != '') {
98+ $message = '<p><b>' . htmlsc($message) . '</b></p>';
99+ }
100+ return $message . $form;
101+ }
97102
98- function inline() // tagging
99- {
100- static $tagging = FALSE;
101- if (func_num_args() == 0){
102- return 'tag(): no argument(s). ';
103- }
104- global $vars, $defaultpage;
105- $page = isset($vars['page']) ? $vars['page'] : $defaultpage;
106- $args = func_get_args();
107- array_pop($args); // drop {}
108- $tags = $args;
109-
110- if ($tagging) { // 2nd call
111- $this->add_tags($page, $tags);
112- } elseif (isset($vars['preview']) || isset($vars['realview']) ||
113- is_page_newer($page, $this->get_tags_filename($page))) {
114- $this->save_tags($page, $tags);
115- $tagging = TRUE;
116- }
117- return $this->display_tags($tags);
118- }
103+ function inline() // tagging
104+ {
105+ static $tagging = FALSE;
106+ if (func_num_args() == 0){
107+ return 'tag(): no argument(s). ';
108+ }
109+ global $vars, $defaultpage;
110+ $page = isset($vars['page']) ? $vars['page'] : $defaultpage;
111+ $args = func_get_args();
112+ array_pop($args); // drop {}
113+ $tags = $args;
114+
115+ if ($tagging) { // 2nd call
116+ $this->add_tags($page, $tags);
117+ } elseif (isset($vars['preview']) || isset($vars['realview']) ||
118+ is_page_newer($page, $this->get_tags_filename($page))) {
119+ $this->save_tags($page, $tags);
120+ $tagging = TRUE;
121+ }
122+ return $this->display_tags($tags);
123+ }
119124
120- /**
121- * Experimental: Write After Plugin Main Function
122- *
123- * @param string &$page
124- * @param string &$postdata
125- * @param boolean &$notimestamp
126- * @return void or exit
127- */
128- function write_after()
129- {
130- $args = func_get_args();
131- $page = $args[0];
132- $postdata = $args[1];
133- if ($postdata == "") { // if page is deleted
134- $this->save_tags($page, array()); // remove tags
135- }
136- // ToDo: renew tag cache on write_after, not on read
137- // Since the whole text must be parsed to find '&tag();',
138- // it is not realistic.
139- // Must create a separated form for Tags to avoid this load.
140- }
125+ /**
126+ * Experimental: Write After Plugin Main Function
127+ *
128+ * @param string &$page
129+ * @param string &$postdata
130+ * @param boolean &$notimestamp
131+ * @return void or exit
132+ */
133+ function write_after()
134+ {
135+ $args = func_get_args();
136+ $page = $args[0];
137+ $postdata = $args[1];
138+ if ($postdata == "") { // if page is deleted
139+ $this->save_tags($page, array()); // remove tags
140+ }
141+ // ToDo: renew tag cache on write_after, not on read
142+ // Since the whole text must be parsed to find '&tag();',
143+ // it is not realistic.
144+ // Must create a separated form for Tags to avoid this load.
145+ }
141146
142- /**
143- * Experimental: Plugin for Rename Plugin Main Function
144- *
145- * @param array $pages $oldpage => $newpage
146- * @return void or exit
147- */
148- function rename_plugin()
149- {
150- $args = func_get_args();
151- $pages = $args[0];
152- foreach ($pages as $oldpage => $newpage) {
153- $this->rename_item($oldpage, $newpage);
154- }
155- }
147+ /**
148+ * Experimental: Plugin for Rename Plugin Main Function
149+ *
150+ * @param array $pages $oldpage => $newpage
151+ * @return void or exit
152+ */
153+ function rename_plugin()
154+ {
155+ $args = func_get_args();
156+ $pages = $args[0];
157+ foreach ($pages as $oldpage => $newpage) {
158+ $this->rename_item($oldpage, $newpage);
159+ }
160+ }
156161
157- /**
158- * Get tag link
159- *
160- * @param string $tag
161- * @return string url
162- */
163- function get_taglink($tag)
164- {
165- $href = $this->conf['listcmd'] . rawurlencode($tag);
166- return '<a href="' . $href . '">' . htmlspecialchars($tag) . '</a> ';
167- }
162+ /**
163+ * Get tag link
164+ *
165+ * @param string $tag
166+ * @return string url
167+ */
168+ function get_taglink($tag)
169+ {
170+ $href = $this->conf['listcmd'] . rawurlencode($tag);
171+ return '<a href="' . $href . '">' . htmlsc($tag) . '</a> ';
172+ }
168173
169- /**
170- * Display tags
171- *
172- * @param array $tags
173- * @return string HTML
174- */
175- function display_tags($tags)
176- {
177- $ret = '<span class="tag">';
178- $ret .= 'Tag: ';
179- foreach ($tags as $tag) {
180- $ret .= $this->get_taglink($tag);
181- }
182- $ret .= '</span>';
174+ /**
175+ * Display tags
176+ *
177+ * @param array $tags
178+ * @return string HTML
179+ */
180+ function display_tags($tags)
181+ {
182+ $ret = '<span class="tag">';
183+ $ret .= 'Tag: ';
184+ foreach ($tags as $tag) {
185+ $ret .= $this->get_taglink($tag);
186+ }
187+ $ret .= '</span>';
183188
184- global $head_tags;
185- $head_tags[] = ' <meta name="keywords" content="' .
186- htmlspecialchars(implode(', ', $tags)) . '" />';
189+ global $head_tags;
190+ $head_tags[] = ' <meta name="keywords" content="' .
191+ htmlsc(implode(', ', $tags)) . '" />';
187192
188- return $ret;
189- }
193+ return $ret;
194+ }
190195
191- /**
192- * Display tags list
193- *
194- * @param integer $limit Number to show
195- * @param string $relate_tag Show only related tags of this
196- * @param string $cssclass
197- * @return string HTML
198- */
199- function display_taglist($limit = NULL, $relate_tag = NULL, $cssclass = 'taglist tags')
200- {
201- $html = '<ul class="' . $cssclass . '">';
202- $tagcloud = $this->get_tagcloud($limit, $relate_tag);
203- foreach ($tagcloud as $tag => $count) {
204- $html .= '<li>' . $this->get_taglink($tag) . '</li>';
205- }
206- $html .= '</ul>';
207- return $html;
208- }
196+ /**
197+ * Display tags list
198+ *
199+ * @param integer $limit Number to show
200+ * @param string $relate_tag Show only related tags of this
201+ * @param string $cssclass
202+ * @return string HTML
203+ */
204+ function display_taglist($limit = NULL, $relate_tag = NULL, $cssclass = 'taglist tags')
205+ {
206+ $html = '<ul class="' . $cssclass . '">';
207+ $tagcloud = $this->get_tagcloud($limit, $relate_tag);
208+ foreach ($tagcloud as $tag => $count) {
209+ $html .= '<li>' . $this->get_taglink($tag) . '</li>';
210+ }
211+ $html .= '</ul>';
212+ return $html;
213+ }
209214
210- /**
211- * Display tagcloud
212- *
213- * @param integer $limit Number to show
214- * @param string $relate_tag Show only related tags of this
215- * @return string HTML
216- */
217- function display_tagcloud($limit = null, $relate_tag = null)
218- {
219- $view = new TagCloud();
220- $tagcloud = $this->get_tagcloud($limit, $relate_tag);
221- foreach ($tagcloud as $tag => $count) {
222- $url = $this->conf['listcmd'] . rawurlencode($tag);
223- $view->add(htmlspecialchars($tag), $url, $count);
224- }
225- return $view->html();
226- }
215+ /**
216+ * Display tagcloud
217+ *
218+ * @param integer $limit Number to show
219+ * @param string $relate_tag Show only related tags of this
220+ * @return string HTML
221+ */
222+ function display_tagcloud($limit = null, $relate_tag = null)
223+ {
224+ $view = new TagCloud();
225+ $tagcloud = $this->get_tagcloud($limit, $relate_tag);
226+ foreach ($tagcloud as $tag => $count) {
227+ $url = $this->conf['listcmd'] . rawurlencode($tag);
228+ $view->add(htmlsc($tag), $url, $count);
229+ }
230+ return $view->html();
231+ }
227232
228- function get_items_filename($tag)
229- {
230- $tag = $this->normalize_tags($tag);
231- return CACHE_DIR . encode($tag) . '_tag.tag';
232- }
233- function get_items_filenames()
234- {
235- return get_existfiles(CACHE_DIR, '_tag.tag');
236- }
237- function get_tags_filename($page)
238- {
239- return CACHE_DIR . encode($page) . '_page.tag';
240- }
241- function get_tags_filenames()
242- {
243- return get_existfiles(CACHE_DIR, '_page.tag');
244- }
245- function get_tagcloud_filename()
246- {
247- return CACHE_DIR . 'tagcloud.tag';
248- }
249- /**
250- * Get tagged pages
251- *
252- * Syntax Sugar for get_items_by_tagtok
253- *
254- * @uses get_items_by_tagtok
255- */
256- function get_taggedpages($tagtok)
257- {
258- return $this->get_items_by_tagtok($tagtok);
259- }
233+ function get_items_filename($tag)
234+ {
235+ $tag = $this->normalize_tags($tag);
236+ return CACHE_DIR . encode($tag) . '_tag.tag';
237+ }
238+ function get_items_filenames()
239+ {
240+ return get_existfiles(CACHE_DIR, '_tag.tag');
241+ }
242+ function get_tags_filename($page)
243+ {
244+ return CACHE_DIR . encode($page) . '_page.tag';
245+ }
246+ function get_tags_filenames()
247+ {
248+ return get_existfiles(CACHE_DIR, '_page.tag');
249+ }
250+ function get_tagcloud_filename()
251+ {
252+ return CACHE_DIR . 'tagcloud.tag';
253+ }
254+ /**
255+ * Get tagged pages
256+ *
257+ * Syntax Sugar for get_items_by_tagtok
258+ *
259+ * @uses get_items_by_tagtok
260+ */
261+ function get_taggedpages($tagtok)
262+ {
263+ return $this->get_items_by_tagtok($tagtok);
264+ }
260265 }
261266
262267 //////////////// PukiWiki API Extension
263268 if (! function_exists('parse_options')) {
264- /**
265- * Parse plugin arguments for options
266- *
267- * @param array &$args
268- * @param array &$options
269- * @param string $sep key/val separator
270- * @return void
271- */
272- function parse_options(&$args, &$options, $sep = '=')
273- {
274- foreach ($args as $arg) {
275- list($key, $val) = array_pad(explode($sep, $arg, 2), 2, TRUE);
276- if (array_key_exists($key, $options)) {
277- $options[$key] = $val;
278- }
279- }
280- }
269+ /**
270+ * Parse plugin arguments for options
271+ *
272+ * @param array &$args
273+ * @param array &$options
274+ * @param string $sep key/val separator
275+ * @return void
276+ */
277+ function parse_options(&$args, &$options, $sep = '=')
278+ {
279+ foreach ($args as $arg) {
280+ list($key, $val) = array_pad(explode($sep, $arg, 2), 2, TRUE);
281+ if (array_key_exists($key, $options)) {
282+ $options[$key] = $val;
283+ }
284+ }
285+ }
281286 }
282287
283288 if (! function_exists('is_admin')) {
284- /**
285- * PukiWiki admin login with session
286- *
287- * @param string $pass
288- * @param boolean $use_session Use Session log
289- * @param boolean $use_basicauth Use BasicAuth log
290- * @return boolean
291- */
292- function is_admin($pass = null, $use_session = false, $use_basicauth = false)
293- {
294- $is_admin = FALSE;
295- if ($use_basicauth) {
296- if (is_callable(array('auth', 'check_role'))) { // Plus!
297- $is_admin = ! auth::check_role('role_adm_contents');
298- }
299- }
300- if (! $is_admin && isset($pass)) {
301- $is_admin = function_exists('pkwk_login') ? pkwk_login($pass) :
302- md5($pass) === $GLOBALS['adminpass']; // 1.4.3
303- }
304- if ($use_session) {
305- session_start();
306- if ($is_admin) $_SESSION['is_admin'] = TRUE;
307- return isset($_SESSION['is_admin']) && $_SESSION['is_admin'];
308- } else {
309- return $is_admin;
310- }
311- }
289+ /**
290+ * PukiWiki admin login with session
291+ *
292+ * @param string $pass
293+ * @param boolean $use_session Use Session log
294+ * @param boolean $use_basicauth Use BasicAuth log
295+ * @return boolean
296+ */
297+ function is_admin($pass = null, $use_session = false, $use_basicauth = false)
298+ {
299+ $is_admin = FALSE;
300+ if ($use_basicauth) {
301+ if (is_callable(array('auth', 'check_role'))) { // Plus!
302+ $is_admin = ! auth::check_role('role_adm_contents');
303+ }
304+ }
305+ if (! $is_admin && isset($pass)) {
306+ $is_admin = function_exists('pkwk_login') ? pkwk_login($pass) :
307+ md5($pass) === $GLOBALS['adminpass']; // 1.4.3
308+ }
309+ if ($use_session) {
310+ session_start();
311+ if ($is_admin) $_SESSION['is_admin'] = TRUE;
312+ return isset($_SESSION['is_admin']) && $_SESSION['is_admin'];
313+ } else {
314+ return $is_admin;
315+ }
316+ }
312317 }
313318
314319 if (! function_exists('make_pagelink_nopg')) {
315- /**
316- * Make a hyperlink to the page without passage
317- *
318- * @param string $page pagename
319- * @param string $alias string to be displayed on the link
320- * @param string $anchor anchor
321- * @param string $refer reference pagename. query '&amp;refer=' is added.
322- * @param bool $isautolink flag if this link is created via autolink or not
323- * @return string link html
324- * @uses make_pagelink
325- */
326- function make_pagelink_nopg($page, $alias = '', $anchor = '', $refer = '', $isautolink = FALSE)
327- {
328- // no passage
329- global $show_passage;
330- $tmp = $show_passage; $show_passage = 0;
331- $link = make_pagelink($page, $alias, $anchor, $refer, $isautolink);
332- $show_passage = $tmp;
333- return $link;
334- }
320+ /**
321+ * Make a hyperlink to the page without passage
322+ *
323+ * @param string $page pagename
324+ * @param string $alias string to be displayed on the link
325+ * @param string $anchor anchor
326+ * @param string $refer reference pagename. query '&amp;refer=' is added.
327+ * @param bool $isautolink flag if this link is created via autolink or not
328+ * @return string link html
329+ * @uses make_pagelink
330+ */
331+ function make_pagelink_nopg($page, $alias = '', $anchor = '', $refer = '', $isautolink = FALSE)
332+ {
333+ // no passage
334+ global $show_passage;
335+ $tmp = $show_passage; $show_passage = 0;
336+ $link = make_pagelink($page, $alias, $anchor, $refer, $isautolink);
337+ $show_passage = $tmp;
338+ return $link;
339+ }
335340 }
336341
337342 if (! function_exists('is_page_newer')) {
338- /**
339- * Check if the page timestamp is newer than the file timestamp
340- *
341- * PukiWiki API Extension
342- *
343- * @param string $page pagename
344- * @param string $file filename
345- * @param bool $ignore_notimestamp Ignore notimestamp edit and see the real time editted
346- * @return boolean
347- */
348- function is_page_newer($page, $file, $ignore_notimestamp = TRUE)
349- {
350- $filestamp = file_exists($file) ? filemtime($file) : 0;
351- if ($ignore_notimestamp) { // See the diff file. PukiWiki Trick.
352- $pagestamp = is_page($page) ? filemtime(DIFF_DIR . encode($page) . '.txt') : 0;
353- } else {
354- $pagestamp = is_page($page) ? filemtime(get_filename($page)) : 0;
355- }
356- return $pagestamp > $filestamp;
357- }
343+ /**
344+ * Check if the page timestamp is newer than the file timestamp
345+ *
346+ * PukiWiki API Extension
347+ *
348+ * @param string $page pagename
349+ * @param string $file filename
350+ * @param bool $ignore_notimestamp Ignore notimestamp edit and see the real time editted
351+ * @return boolean
352+ */
353+ function is_page_newer($page, $file, $ignore_notimestamp = TRUE)
354+ {
355+ $filestamp = file_exists($file) ? filemtime($file) : 0;
356+ if ($ignore_notimestamp) { // See the diff file. PukiWiki Trick.
357+ $pagestamp = is_page($page) ? filemtime(DIFF_DIR . encode($page) . '.txt') : 0;
358+ } else {
359+ $pagestamp = is_page($page) ? filemtime(get_filename($page)) : 0;
360+ }
361+ return $pagestamp > $filestamp;
362+ }
358363 }
359364
360365 if (! function_exists('exec_page')) {
361- /**
362- * Execute (convert_html) this page
363- *
364- * PukiWiki API Extension
365- *
366- * @param string $page
367- * @param string $regexp execute only matched lines (preg_grep)
368- * @return boolean executed
369- */
370- function exec_page($page, $regexp = null)
371- {
372- global $vars, $get, $post;
373- $lines = get_source($page);
374- if (isset($regexp)) {
375- $lines = preg_grep($regexp, $lines);
376- }
377- if (empty($lines)) return FALSE;
378- $tmp_page = $vars['page'];
379- $tmp_cmd = $vars['cmd'];
380- $vars['cmd'] = $get['cmd'] = $post['cmd'] = 'read';
381- $vars['page'] = $get['page'] = $post['page'] = $page;
382- convert_html($lines);
383- $vars['page'] = $get['page'] = $post['page'] = $tmp_page;
384- $vars['cmd'] = $get['cmd'] = $post['cmd'] = $tmp_cmd;
385- return TRUE;
386- }
366+ /**
367+ * Execute (convert_html) this page
368+ *
369+ * PukiWiki API Extension
370+ *
371+ * @param string $page
372+ * @param string $regexp execute only matched lines (preg_grep)
373+ * @return boolean executed
374+ */
375+ function exec_page($page, $regexp = null)
376+ {
377+ global $vars, $get, $post;
378+ $lines = get_source($page);
379+ if (isset($regexp)) {
380+ $lines = preg_grep($regexp, $lines);
381+ }
382+ if (empty($lines)) return FALSE;
383+ $tmp_page = $vars['page'];
384+ $tmp_cmd = $vars['cmd'];
385+ $vars['cmd'] = $get['cmd'] = $post['cmd'] = 'read';
386+ $vars['page'] = $get['page'] = $post['page'] = $page;
387+ convert_html($lines);
388+ $vars['page'] = $get['page'] = $post['page'] = $tmp_page;
389+ $vars['cmd'] = $get['cmd'] = $post['cmd'] = $tmp_cmd;
390+ return TRUE;
391+ }
387392 }
388393
389394 if (! function_exists('exec_existpages')) {
390- /**
391- * Execute (convert_html) all pages
392- *
393- * PukiWiki API Extension
394- *
395- * @param string $regexp execute only matched lines (preg_grep)
396- * @return array executed pages
397- */
398- function exec_existpages($regexp = null)
399- {
400- global $vars, $get, $post;
401- $pages = get_existpages();
402- $exec_pages = array();
403- $tmp_page = $vars['page'];
404- $tmp_cmd = $vars['cmd'];
405- $vars['cmd'] = $get['cmd'] = $post['cmd'] = 'read';
406- foreach ($pages as $page) {
407- $vars['page'] = $get['page'] = $post['page'] = $page;
408- $lines = get_source($page);
409- if (isset($regexp)) {
410- $lines = preg_grep($regexp, $lines);
411- }
412- if (empty($lines)) continue;
413- convert_html($lines);
414- $exec_pages[] = $page;
415- }
416- $vars['page'] = $get['page'] = $post['page'] = $tmp_page;
417- $vars['cmd'] = $get['cmd'] = $post['cmd'] = $tmp_cmd;
418- return $exec_pages;
419- }
395+ /**
396+ * Execute (convert_html) all pages
397+ *
398+ * PukiWiki API Extension
399+ *
400+ * @param string $regexp execute only matched lines (preg_grep)
401+ * @return array executed pages
402+ */
403+ function exec_existpages($regexp = null)
404+ {
405+ global $vars, $get, $post;
406+ $pages = get_existpages();
407+ $exec_pages = array();
408+ $tmp_page = $vars['page'];
409+ $tmp_cmd = $vars['cmd'];
410+ $vars['cmd'] = $get['cmd'] = $post['cmd'] = 'read';
411+ foreach ($pages as $page) {
412+ $vars['page'] = $get['page'] = $post['page'] = $page;
413+ $lines = get_source($page);
414+ if (isset($regexp)) {
415+ $lines = preg_grep($regexp, $lines);
416+ }
417+ if (empty($lines)) continue;
418+ convert_html($lines);
419+ $exec_pages[] = $page;
420+ }
421+ $vars['page'] = $get['page'] = $post['page'] = $tmp_page;
422+ $vars['cmd'] = $get['cmd'] = $post['cmd'] = $tmp_cmd;
423+ return $exec_pages;
424+ }
420425 }
421426
422427 /////////////// PHP API Extension ///////////////////////
423428 if (! function_exists('ya_array_diff')) {
424- /**
425- * Get array diff
426- *
427- * @param array $oldarray
428- * @param array $newarray
429- * @return array array((array)$minus, (array)$plus)
430- */
431- function ya_array_diff($oldarray, $newarray)
432- {
433- $common = array_intersect($oldarray, $newarray);
434- $minus = array_diff($oldarray, $common);
435- $plus = array_diff($newarray, $common);
436- return array($minus, $plus);
437- }
429+ /**
430+ * Get array diff
431+ *
432+ * @param array $oldarray
433+ * @param array $newarray
434+ * @return array array((array)$minus, (array)$plus)
435+ */
436+ function ya_array_diff($oldarray, $newarray)
437+ {
438+ $common = array_intersect($oldarray, $newarray);
439+ $minus = array_diff($oldarray, $common);
440+ $plus = array_diff($newarray, $common);
441+ return array($minus, $plus);
442+ }
438443 }
439444
440445 if (! function_exists('file_put_contents')) {
441- if (! defined('FILE_APPEND')) define('FILE_APPEND', 8);
442- if (! defined('FILE_USE_INCLUDE_PATH')) define('FILE_USE_INCLUDE_PATH', 1);
443- /**
444- * Write a string to a file (PHP5 has this function)
445- *
446- * PHP Compat
447- *
448- * @param string $filename
449- * @param string $data
450- * @param int $flags
451- * @return int the amount of bytes that were written to the file, or FALSE if failure
452- */
453- function file_put_contents($filename, $data, $flags = 0)
454- {
455- $mode = ($flags & FILE_APPEND) ? 'a' : 'w';
456- $fp = fopen($filename, $mode);
457- if ($fp === false) {
458- return false;
459- }
460- if (is_array($data)) $data = implode('', $data);
461- if ($flags & LOCK_EX) flock($fp, LOCK_EX);
462- $bytes = fwrite($fp, $data);
463- if ($flags & LOCK_EX) flock($fp, LOCK_UN);
464- fclose($fp);
465- return $bytes;
466- }
446+ if (! defined('FILE_APPEND')) define('FILE_APPEND', 8);
447+ if (! defined('FILE_USE_INCLUDE_PATH')) define('FILE_USE_INCLUDE_PATH', 1);
448+ /**
449+ * Write a string to a file (PHP5 has this function)
450+ *
451+ * PHP Compat
452+ *
453+ * @param string $filename
454+ * @param string $data
455+ * @param int $flags
456+ * @return int the amount of bytes that were written to the file, or FALSE if failure
457+ */
458+ function file_put_contents($filename, $data, $flags = 0)
459+ {
460+ $mode = ($flags & FILE_APPEND) ? 'a' : 'w';
461+ $fp = fopen($filename, $mode);
462+ if ($fp === false) {
463+ return false;
464+ }
465+ if (is_array($data)) $data = implode('', $data);
466+ if ($flags & LOCK_EX) flock($fp, LOCK_EX);
467+ $bytes = fwrite($fp, $data);
468+ if ($flags & LOCK_EX) flock($fp, LOCK_UN);
469+ fclose($fp);
470+ return $bytes;
471+ }
467472 }
468473
469474 if (! function_exists('r_strpos')) {
470- /**
471- * Find positions of occurrence of a string
472- *
473- * PHP Extension
474- *
475- * @param string $str
476- * @param string $substr
477- * @return array positions
478- */
479- function r_strpos($str, $substr)
480- {
481- $r_pos = array();
482- while(true) {
483- $pos = strpos($str, $substr);
484- if ($pos === false) break;
485- array_push($r_pos, $pos);
486- $str = substr($str, $pos + 1);
487- }
488- return $r_pos;
489- }
475+ /**
476+ * Find positions of occurrence of a string
477+ *
478+ * PHP Extension
479+ *
480+ * @param string $str
481+ * @param string $substr
482+ * @return array positions
483+ */
484+ function r_strpos($str, $substr)
485+ {
486+ $r_pos = array();
487+ while(true) {
488+ $pos = strpos($str, $substr);
489+ if ($pos === false) break;
490+ array_push($r_pos, $pos);
491+ $str = substr($str, $pos + 1);
492+ }
493+ return $r_pos;
494+ }
490495 }
491496
492497 if (! function_exists('get_existfiles')) {
493- /**
494- * Get list of files in a directory
495- *
496- * PHP Extension
497- *
498- * @access public
499- * @param string $dir Directory Name
500- * @param string $ext File Extension
501- * @param bool $recursive Traverse Recursively
502- * @return array array of filenames
503- * @uses is_dir()
504- * @uses opendir()
505- * @uses readdir()
506- */
507- function &get_existfiles($dir, $ext = '', $recursive = FALSE)
508- {
509- if (($dp = @opendir($dir)) == FALSE)
510- return FALSE;
511- $pattern = '/' . preg_quote($ext, '/') . '$/';
512- $dir = ($dir[strlen($dir)-1] == '/') ? $dir : $dir . '/';
513- $dir = ($dir == '.' . '/') ? '' : $dir;
514- $files = array();
515- while (($file = readdir($dp)) !== false ) {
516- if($file != '.' && $file != '..' && is_dir($dir . $file) && $recursive) {
517- $files = array_merge($files, get_existfiles($dir . $file, $ext, $recursive));
518- } else {
519- $matches = array();
520- if (preg_match($pattern, $file, $matches)) {
521- $files[] = $dir . $file;
522- }
523- }
524- }
525- closedir($dp);
526- return $files;
527- }
498+ /**
499+ * Get list of files in a directory
500+ *
501+ * PHP Extension
502+ *
503+ * @access public
504+ * @param string $dir Directory Name
505+ * @param string $ext File Extension
506+ * @param bool $recursive Traverse Recursively
507+ * @return array array of filenames
508+ * @uses is_dir()
509+ * @uses opendir()
510+ * @uses readdir()
511+ */
512+ function &get_existfiles($dir, $ext = '', $recursive = FALSE)
513+ {
514+ if (($dp = @opendir($dir)) == FALSE)
515+ return FALSE;
516+ $pattern = '/' . preg_quote($ext, '/') . '$/';
517+ $dir = ($dir[strlen($dir)-1] == '/') ? $dir : $dir . '/';
518+ $dir = ($dir == '.' . '/') ? '' : $dir;
519+ $files = array();
520+ while (($file = readdir($dp)) !== false ) {
521+ if($file != '.' && $file != '..' && is_dir($dir . $file) && $recursive) {
522+ $files = array_merge($files, get_existfiles($dir . $file, $ext, $recursive));
523+ } else {
524+ $matches = array();
525+ if (preg_match($pattern, $file, $matches)) {
526+ $files[] = $dir . $file;
527+ }
528+ }
529+ }
530+ closedir($dp);
531+ return $files;
532+ }
528533 }
529534
530535 if (! function_exists('_')) {
531- /**
532- * i18n gettext
533- *
534- * PHP Compat
535- *
536- * @param string $str
537- * @return string
538- */
539- function _($str)
540- {
541- return $str;
542- }
536+ /**
537+ * i18n gettext
538+ *
539+ * PHP Compat
540+ *
541+ * @param string $str
542+ * @return string
543+ */
544+ function _($str)
545+ {
546+ return $str;
547+ }
543548 }
544549
545550 ////////////////////////////////
546551 function plugin_tag_init()
547552 {
548- global $plugin_tag_name;
549- if (class_exists('PluginTagUnitTest')) {
550- $plugin_tag_name = 'PluginTagUnitTest';
551- } elseif (class_exists('PluginTagUser')) {
552- $plugin_tag_name = 'PluginTagUser';
553- } else {
554- $plugin_tag_name = 'PluginTag';
555- }
553+ global $plugin_tag_name;
554+ if (class_exists('PluginTagUnitTest')) {
555+ $plugin_tag_name = 'PluginTagUnitTest';
556+ } elseif (class_exists('PluginTagUser')) {
557+ $plugin_tag_name = 'PluginTagUser';
558+ } else {
559+ $plugin_tag_name = 'PluginTag';
560+ }
556561 }
557562
558563 function plugin_tag_inline()
559564 {
560- global $plugin_tag, $plugin_tag_name;
561- $plugin_tag = new $plugin_tag_name();
562- $args = func_get_args();
563- return call_user_func_array(array(&$plugin_tag, 'inline'), $args);
565+ global $plugin_tag, $plugin_tag_name;
566+ $plugin_tag = new $plugin_tag_name();
567+ $args = func_get_args();
568+ return call_user_func_array(array(&$plugin_tag, 'inline'), $args);
564569 }
565570
566571 function plugin_tag_convert()
567572 {
568- global $plugin_tag, $plugin_tag_name;
569- $plugin_tag = new $plugin_tag_name();
570- $args = func_get_args();
571- return call_user_func_array(array(&$plugin_tag, 'convert'), $args);
573+ global $plugin_tag, $plugin_tag_name;
574+ $plugin_tag = new $plugin_tag_name();
575+ $args = func_get_args();
576+ return call_user_func_array(array(&$plugin_tag, 'convert'), $args);
572577 }
573578
574579 function plugin_tag_action()
575580 {
576- global $plugin_tag, $plugin_tag_name;
577- $plugin_tag = new $plugin_tag_name();
578- return call_user_func(array(&$plugin_tag, 'action'));
581+ global $plugin_tag, $plugin_tag_name;
582+ $plugin_tag = new $plugin_tag_name();
583+ return call_user_func(array(&$plugin_tag, 'action'));
579584 }
580585
581586 function plugin_tag_write_after()
582587 {
583- global $plugin_tag_name;
584- $plugin_tag = new $plugin_tag_name();
585- $args = func_get_args();
586- return call_user_func_array(array(&$plugin_tag, 'write_after'), $args);
588+ global $plugin_tag_name;
589+ $plugin_tag = new $plugin_tag_name();
590+ $args = func_get_args();
591+ return call_user_func_array(array(&$plugin_tag, 'write_after'), $args);
587592 }
588593
589594 function plugin_tag_rename_plugin()
590595 {
591- global $plugin_tag_name;
592- $plugin_tag = new $plugin_tag_name();
593- $args = func_get_args();
594- return call_user_func_array(array(&$plugin_tag, 'rename_plugin'), $args);
596+ global $plugin_tag_name;
597+ $plugin_tag = new $plugin_tag_name();
598+ $args = func_get_args();
599+ return call_user_func_array(array(&$plugin_tag, 'rename_plugin'), $args);
595600 }
596601
597602 /**
598603 * Tag Class
599604 *
600- * @author sonots
601- * @license http://www.gnu.org/licenses/gpl.html GPL2
602- * @link http://lsx.sourceforge.jp/?Plugin%2Ftag.inc.php
605+ * @author sonots
606+ * @license http://www.gnu.org/licenses/gpl.html GPL2
607+ * @link http://lsx.sourceforge.jp/?Plugin%2Ftag.inc.php
603608 */
604609 class Tag
605610 {
606- /**
607- * Items of a tag
608- *
609- * Associative array of items whose key is a tag
610- * and values are an array of items
611- *
612- * @var array
613- *
614- * [tag] = array(item1, item2, item3, ...)
615- */
616- var $items;
617- /**
618- * Tags of an item
619- *
620- * Associative array of tags whose key is an item
621- * and values are an array of keys
622- *
623- * @var array
624- *
625- * [item] = array(tag1, tag2, tag3, ...)
626- */
627- var $tags;
628- /**
629- * Tagcloud
630- *
631- * Associative array whose key is a tag
632- * and values are the number of items
633- *
634- * @var array
635- */
636- var $tagcloud;
637- /**
638- * Reserved keys
639- *
640- * Strings which have special meanings.
641- * They can not be used for tag strings
642- *
643- * @static array
644- */
645- var $reserved_keys = array('prod' => '^', 'diff' => '-');
611+ /**
612+ * Items of a tag
613+ *
614+ * Associative array of items whose key is a tag
615+ * and values are an array of items
616+ *
617+ * @var array
618+ *
619+ * [tag] = array(item1, item2, item3, ...)
620+ */
621+ var $items;
622+ /**
623+ * Tags of an item
624+ *
625+ * Associative array of tags whose key is an item
626+ * and values are an array of keys
627+ *
628+ * @var array
629+ *
630+ * [item] = array(tag1, tag2, tag3, ...)
631+ */
632+ var $tags;
633+ /**
634+ * Tagcloud
635+ *
636+ * Associative array whose key is a tag
637+ * and values are the number of items
638+ *
639+ * @var array
640+ */
641+ var $tagcloud;
642+ /**
643+ * Reserved keys
644+ *
645+ * Strings which have special meanings.
646+ * They can not be used for tag strings
647+ *
648+ * @static array
649+ */
650+ var $reserved_keys = array('prod' => '^', 'diff' => '-');
646651
647- function Tag($items = array(), $tags = array(), $tagcloud = null)
648- {
649- $this->items = $items;
650- $this->tags = $tags;
651- $this->tagcloud = $tagcloud;
652- }
652+ function __construct($items = array(), $tags = array(), $tagcloud = null)
653+ {
654+ $this->items = $items;
655+ $this->tags = $tags;
656+ $this->tagcloud = $tagcloud;
657+ }
658+
659+ function Tag() {
660+ $this->__construct();
661+ }
653662
654- /**
655- * Get filename which stores items by a tag
656- *
657- * Overwrite Me!
658- *
659- * @param string $tag
660- * @return string
661- * @access protected
662- */
663- function get_items_filename($tag)
664- {
665- $tag = $this->normalize_tags($tag);
666- return str_replace('%', '', rawurlencode($tag)) . '_items.tag';
667- }
668- /**
669- * Get all items_filename
670- *
671- * Overwrite Me!
672- *
673- * @return array
674- * @access protected
675- */
676- function get_items_filenames()
677- {
678- return get_existfiles('.', '_items.tag');
679- }
680- /**
681- * Get filename which stores tags of an item
682- *
683- * Overwrite Me!
684- *
685- * @param string $item
686- * @return string
687- * @access protected
688- */
689- function get_tags_filename($item)
690- {
691- return str_replace('%', '', rawurlencode($item)) . '_tags.tag';
692- }
693- /**
694- * Get all tags_filename
695- *
696- * Overwrite Me!
697- *
698- * @return array
699- * @access protected
700- */
701- function get_tags_filenames()
702- {
703- return get_existfiles('.', '_tags.tag');
704- }
705- /**
706- * Get filename which stores tagcloud
707- *
708- * Overwrite Me!
709- *
710- * @return string
711- * @access protected
712- */
713- function get_tagcloud_filename()
714- {
715- return 'tagcloud.tag';
716- }
663+ /**
664+ * Get filename which stores items by a tag
665+ *
666+ * Overwrite Me!
667+ *
668+ * @param string $tag
669+ * @return string
670+ * @access protected
671+ */
672+ function get_items_filename($tag)
673+ {
674+ $tag = $this->normalize_tags($tag);
675+ return str_replace('%', '', rawurlencode($tag)) . '_items.tag';
676+ }
677+ /**
678+ * Get all items_filename
679+ *
680+ * Overwrite Me!
681+ *
682+ * @return array
683+ * @access protected
684+ */
685+ function get_items_filenames()
686+ {
687+ return get_existfiles('.', '_items.tag');
688+ }
689+ /**
690+ * Get filename which stores tags of an item
691+ *
692+ * Overwrite Me!
693+ *
694+ * @param string $item
695+ * @return string
696+ * @access protected
697+ */
698+ function get_tags_filename($item)
699+ {
700+ return str_replace('%', '', rawurlencode($item)) . '_tags.tag';
701+ }
702+ /**
703+ * Get all tags_filename
704+ *
705+ * Overwrite Me!
706+ *
707+ * @return array
708+ * @access protected
709+ */
710+ function get_tags_filenames()
711+ {
712+ return get_existfiles('.', '_tags.tag');
713+ }
714+ /**
715+ * Get filename which stores tagcloud
716+ *
717+ * Overwrite Me!
718+ *
719+ * @return string
720+ * @access protected
721+ */
722+ function get_tagcloud_filename()
723+ {
724+ return 'tagcloud.tag';
725+ }
717726
718- /**
719- * Get tags of an item from a storage (file or db)
720- *
721- * Overwrite Me if you don't like the file format
722- *
723- * @param string $item
724- * @param string $filename
725- * @return array
726- * @access protected
727- */
728- function get_tags_from_storage($item, $filename = null)
729- {
730- if ($item === null) return false;
731- if ($filename === null) $filename = $this->get_tags_filename($item);
732- if (! file_exists($filename)) return array();
733- $tags = array_map('rtrim', file($filename));
734- return $tags;
735- }
727+ /**
728+ * Get tags of an item from a storage (file or db)
729+ *
730+ * Overwrite Me if you don't like the file format
731+ *
732+ * @param string $item
733+ * @param string $filename
734+ * @return array
735+ * @access protected
736+ */
737+ function get_tags_from_storage($item, $filename = null)
738+ {
739+ if ($item === null) return false;
740+ if ($filename === null) $filename = $this->get_tags_filename($item);
741+ if (! file_exists($filename)) return array();
742+ $tags = array_map('rtrim', file($filename));
743+ return $tags;
744+ }
736745
737- /**
738- * Get items by a tag from a storage (file or db)
739- *
740- * Overwrite Me if you don't like the file format
741- *
742- * @param string $tag
743- * @param string $filename
744- * @return array
745- * @access protected
746- */
747- function get_items_from_storage($tag, $filename = null)
748- {
749- if ($filename === null) $filename = $this->get_items_filename($tag);
750- if (! file_exists($filename)) return array();
751- $items = array_map('rtrim', file($filename));
752- return $items;
753- }
746+ /**
747+ * Get items by a tag from a storage (file or db)
748+ *
749+ * Overwrite Me if you don't like the file format
750+ *
751+ * @param string $tag
752+ * @param string $filename
753+ * @return array
754+ * @access protected
755+ */
756+ function get_items_from_storage($tag, $filename = null)
757+ {
758+ if ($filename === null) $filename = $this->get_items_filename($tag);
759+ if (! file_exists($filename)) return array();
760+ $items = array_map('rtrim', file($filename));
761+ return $items;
762+ }
754763
755- /**
756- * Get tagcloud from a storage (file or db)
757- *
758- * Overwrite Me if you don't like the file format
759- *
760- * @return array
761- * @access protected
762- */
763- function get_tagcloud_from_storage()
764- {
765- $filename = $this->get_tagcloud_filename();
766- $tagcloud = array();
767- if (file_exists($filename)) {
768- $lines = file($filename);
769- if (empty($lines)) return array();
770- $lines = array_map('rtrim', $lines);
771- foreach ($lines as $line) {
772- list($tag, $count) = explode("\t", $line);
773- $tagcloud[$tag] = $count;
774- }
775- }
776- return $tagcloud;
777- }
764+ /**
765+ * Get tagcloud from a storage (file or db)
766+ *
767+ * Overwrite Me if you don't like the file format
768+ *
769+ * @return array
770+ * @access protected
771+ */
772+ function get_tagcloud_from_storage()
773+ {
774+ $filename = $this->get_tagcloud_filename();
775+ $tagcloud = array();
776+ if (file_exists($filename)) {
777+ $lines = file($filename);
778+ if (empty($lines)) return array();
779+ $lines = array_map('rtrim', $lines);
780+ foreach ($lines as $line) {
781+ list($tag, $count) = explode("\t", $line);
782+ $tagcloud[$tag] = $count;
783+ }
784+ }
785+ return $tagcloud;
786+ }
778787
779- /**
780- * Set tags into an item, and store into a storage (file or db)
781- *
782- * Overwrite Me if you don't like the file format
783- *
784- * @param string $item
785- * @param array $tags
786- * @param string $filename
787- * @return boolean
788- * @access protected
789- */
790- function set_tags_into_storage($item, $tags, $filename = null)
791- {
792- if ($filename === null) $filename = $this->get_tags_filename($item);
793- if (empty($tags) && file_exists($filename)) {
794- return unlink($filename);
795- }
796- $contents = implode("\n", $tags) . "\n";
797- return file_put_contents($filename, $contents);
798- }
788+ /**
789+ * Set tags into an item, and store into a storage (file or db)
790+ *
791+ * Overwrite Me if you don't like the file format
792+ *
793+ * @param string $item
794+ * @param array $tags
795+ * @param string $filename
796+ * @return boolean
797+ * @access protected
798+ */
799+ function set_tags_into_storage($item, $tags, $filename = null)
800+ {
801+ if ($filename === null) $filename = $this->get_tags_filename($item);
802+ if (empty($tags) && file_exists($filename)) {
803+ return unlink($filename);
804+ }
805+ $contents = implode("\n", $tags) . "\n";
806+ return file_put_contents($filename, $contents);
807+ }
799808
800- /**
801- * Set items into a tag, and store into a storage (file or db)
802- *
803- * Overwrite Me if you don't like the file format
804- *
805- * @param string $tag
806- * @param array $items
807- * @param string $filename
808- * @return boolean
809- * @access protected
810- */
811- function set_items_into_storage($tag, $items, $filename = null)
812- {
813- if ($filename === null) $filename = $this->get_items_filename($tag);
814- if (empty($items) && file_exists($filename)) {
815- return unlink($filename);
816- }
817- $contents = implode("\n", $items) . "\n";
818- return file_put_contents($filename, $contents);
819- }
809+ /**
810+ * Set items into a tag, and store into a storage (file or db)
811+ *
812+ * Overwrite Me if you don't like the file format
813+ *
814+ * @param string $tag
815+ * @param array $items
816+ * @param string $filename
817+ * @return boolean
818+ * @access protected
819+ */
820+ function set_items_into_storage($tag, $items, $filename = null)
821+ {
822+ if ($filename === null) $filename = $this->get_items_filename($tag);
823+ if (empty($items) && file_exists($filename)) {
824+ return unlink($filename);
825+ }
826+ $contents = implode("\n", $items) . "\n";
827+ return file_put_contents($filename, $contents);
828+ }
820829
821- /**
822- * Store tagcloud into a storage (file or db)
823- *
824- * Overwrite Me if you don't like the file format
825- *
826- * @param array $tagcloud
827- * @param string filename
828- * @return boolean
829- * @access protected
830- */
831- function set_tagcloud_into_storage($tagcloud, $filename = null)
832- {
833- if ($filename === null) $filename = $this->get_tagcloud_filename();
834- $contents = '';
835- ksort($tagcloud);
836- foreach ($tagcloud as $tag => $count) {
837- if ($count === 0) continue;
838- $contents .= $tag . "\t" . $count . "\n";
839- }
840- return file_put_contents($filename, $contents);
841- }
830+ /**
831+ * Store tagcloud into a storage (file or db)
832+ *
833+ * Overwrite Me if you don't like the file format
834+ *
835+ * @param array $tagcloud
836+ * @param string filename
837+ * @return boolean
838+ * @access protected
839+ */
840+ function set_tagcloud_into_storage($tagcloud, $filename = null)
841+ {
842+ if ($filename === null) $filename = $this->get_tagcloud_filename();
843+ $contents = '';
844+ ksort($tagcloud);
845+ foreach ($tagcloud as $tag => $count) {
846+ if ($count === 0) continue;
847+ $contents .= $tag . "\t" . $count . "\n";
848+ }
849+ return file_put_contents($filename, $contents);
850+ }
842851
843- /**
844- * Get tags of an item
845- *
846- * @param string $item
847- * @param boolean $cache use memory cache
848- * @return array
849- * @uses get_tags_from_storage
850- * @access public
851- */
852- function get_tags($item, $cache = true)
853- {
854- if (isset($this->tags[$item]) & $cache) {
855- return $this->tags[$item];
856- }
857- $tags = $this->get_tags_from_storage($item);
858- if ($cache) $this->tags[$item] = $tags;
859- return $tags;
860- }
852+ /**
853+ * Get tags of an item
854+ *
855+ * @param string $item
856+ * @param boolean $cache use memory cache
857+ * @return array
858+ * @uses get_tags_from_storage
859+ * @access public
860+ */
861+ function get_tags($item, $cache = true)
862+ {
863+ if (isset($this->tags[$item]) & $cache) {
864+ return $this->tags[$item];
865+ }
866+ $tags = $this->get_tags_from_storage($item);
867+ if ($cache) $this->tags[$item] = $tags;
868+ return $tags;
869+ }
861870
862- /**
863- * Get items by a tag
864- *
865- * @param string $tag
866- * @param boolean $cache use memory cache
867- * @return array
868- * @uses get_items_from_storage
869- * @access public
870- */
871- function get_items($tag, $cache = true)
872- {
873- if (isset($this->items[$tag]) & $cache) {
874- return $this->items[$tag];
875- }
876- $items = $this->get_items_from_storage($tag);
877- if ($cache) $this->items[$tag] = $items;
878- return $items;
879- }
871+ /**
872+ * Get items by a tag
873+ *
874+ * @param string $tag
875+ * @param boolean $cache use memory cache
876+ * @return array
877+ * @uses get_items_from_storage
878+ * @access public
879+ */
880+ function get_items($tag, $cache = true)
881+ {
882+ if (isset($this->items[$tag]) & $cache) {
883+ return $this->items[$tag];
884+ }
885+ $items = $this->get_items_from_storage($tag);
886+ if ($cache) $this->items[$tag] = $items;
887+ return $items;
888+ }
880889
881- /**
882- * Set tags into an item
883- *
884- * @param string $item
885- * @param array $tags
886- * @param boolean $storage write to storage
887- * @return boolean
888- * @uses normalize_tags
889- * @uses set_tags_into_storage
890- * @access public
891- */
892- function set_tags($item, $tags, $storage = true)
893- {
894- $tags = $this->normalize_tags($tags);
895- // $tags == $this->tags[$item] // key/val pair
896- list($minus, $plus) = ya_array_diff($this->get_tags($item), $tags);
897- if (empty($minus) & empty($plus)) {
898- return true;
899- }
900- $this->tags[$item] = $tags;
901- if ($storage) {
902- return $this->set_tags_into_storage($item, $tags);
903- }
904- return true;
905- }
890+ /**
891+ * Set tags into an item
892+ *
893+ * @param string $item
894+ * @param array $tags
895+ * @param boolean $storage write to storage
896+ * @return boolean
897+ * @uses normalize_tags
898+ * @uses set_tags_into_storage
899+ * @access public
900+ */
901+ function set_tags($item, $tags, $storage = true)
902+ {
903+ $tags = $this->normalize_tags($tags);
904+ // $tags == $this->tags[$item] // key/val pair
905+ list($minus, $plus) = ya_array_diff($this->get_tags($item), $tags);
906+ if (empty($minus) & empty($plus)) {
907+ return true;
908+ }
909+ $this->tags[$item] = $tags;
910+ if ($storage) {
911+ return $this->set_tags_into_storage($item, $tags);
912+ }
913+ return true;
914+ }
906915
907- /**
908- * Set items into a tag
909- *
910- * @param string $tag
911- * @param array $items
912- * @param boolean $storage write to storage
913- * @return boolean
914- * @uses set_items_into_storage
915- * @access public
916- */
917- function set_items($tag, $items, $storage = true)
918- {
919- // $items == $this->items[$tag] // key/val pair
920- list($minus, $plus) = ya_array_diff($this->get_items($tag), $items);
921- if (empty($minus) & empty($plus)) {
922- return true;
923- }
924- $this->items[$tag] = $items;
925- if ($storage) {
926- return $this->set_items_into_storage($tag, $items);
927- }
928- return true;
929- }
916+ /**
917+ * Set items into a tag
918+ *
919+ * @param string $tag
920+ * @param array $items
921+ * @param boolean $storage write to storage
922+ * @return boolean
923+ * @uses set_items_into_storage
924+ * @access public
925+ */
926+ function set_items($tag, $items, $storage = true)
927+ {
928+ // $items == $this->items[$tag] // key/val pair
929+ list($minus, $plus) = ya_array_diff($this->get_items($tag), $items);
930+ if (empty($minus) & empty($plus)) {
931+ return true;
932+ }
933+ $this->items[$tag] = $items;
934+ if ($storage) {
935+ return $this->set_items_into_storage($tag, $items);
936+ }
937+ return true;
938+ }
930939
931- /**
932- * Save tags into an item (This does more than set_tags)
933- *
934- * @param string $item
935- * @param mixed $tags string or array of tag(s)
936- * @return boolean Success or Failure
937- * @uses normalize_tags
938- * @uses get_tags
939- * @uses set_tags
940- * @uses get_items
941- * @uses set_items
942- * @uses update_tagcloud
943- * @access public
944- */
945- function save_tags($item, $new_tags)
946- {
947- $new_tags = (array)$new_tags;
948- $old_tags = $this->get_tags($item);
949- $new_tags = $this->normalize_tags($new_tags);
950- $ret = true;
951- $ret &= $this->set_tags($item, $new_tags);
952- list($minus, $plus) = ya_array_diff($old_tags, $new_tags);
953- foreach ($minus as $tag) {
954- $old_items = $this->get_items($tag);
955- $new_items = array_diff($old_items, (array)$item);
956- $ret &= $this->set_items($tag, $new_items);
957- }
958- foreach ($plus as $tag) {
959- $old_items = $this->get_items($tag);
960- $new_items = array_unique(array_merge($old_items, (array)$item));
961- $ret &= $this->set_items($tag, $new_items);
962- }
963- $ret &= $this->update_tagcloud();
964- return $ret;
965- }
966- /**
967- * Add tags into an item
968- *
969- * @param string $item
970- * @param mixed $tags string or array of tag(s)
971- * @return boolean Success or Failure
972- * @uses normalize_tags
973- * @uses get_tags
974- * @uses set_tags
975- * @uses get_items
976- * @uses set_items
977- * @uses update_tagcloud
978- * @access public
979- */
980- function add_tags($item, $tags)
981- {
982- $tags = (array)$tags;
983- $tags = $this->normalize_tags($tags);
984- $new_tags = array_unique(array_merge($this->get_tags($item), $tags));
985- // return $this->save_tags($item, $new_tags);
986- $ret = true;
987- $ret &= $this->set_tags($item, $new_tags);
988- foreach ($tags as $tag) {
989- $old_items = $this->get_items($tag);
990- $new_items = array_unique(array_merge($old_items, (array)$item));
991- $ret &= $this->set_items($tag, $new_items);
992- }
993- $ret &= $this->update_tagcloud();
994- return $ret;
995- }
996- /**
997- * Remove tags from an item
998- *
999- * @param string $item
1000- * @param mixed $tags string or array of tag(s)
1001- * @return boolean Success or Failure
1002- * @uses normalize_tags
1003- * @uses get_tags
1004- * @uses set_tags
1005- * @uses get_items
1006- * @uses set_items
1007- * @uses update_tagcloud
1008- * @access public
1009- */
1010- function remove_tags($item, $tags)
1011- {
1012- $tags = (array)$tags;
1013- $tags = $this->normalize_tags($tags);
1014- $new_tags = array_diff($this->get_tags($item), $tags);
1015- // return $this->save_tags($item, $new_tags);
1016- $ret = true;
1017- $ret &= $this->set_tags($item, $new_tags);
1018- foreach ($tags as $tag) {
1019- $old_items = $this->get_items($tag);
1020- $new_items = array_diff($old_items, (array)$item);
1021- $ret &= $this->set_items($tag, $new_items);
1022- }
1023- $ret &= $this->update_tagcloud();
1024- return $ret;
1025- }
1026- /**
1027- * Remove tags from the system
1028- *
1029- * @uses Tag::remove_tags()
1030- *
1031- * @param mixed $tags string or array of tag(s)
1032- * @return boolean Success or Failure
1033- * @uses normalize_tags
1034- * @uses get_items
1035- * @uses remove_tags
1036- * @uses set_items
1037- * @uses update_tagcloud
1038- * @access public
1039- */
1040- function remove_system_tags($tags)
1041- {
1042- $tags = (array)$tags;
1043- $tags = $this->normalize_tags($tags);
1044- $ret = true;
1045- foreach ($tags as $tag) {
1046- foreach ($this->get_items($tag) as $item) {
1047- $ret &= $this->remove_tags($item, $tag);
1048- }
1049- $ret &= $this->set_items($tag, array());
1050- }
1051- $ret &= $this->update_tagcloud();
1052- return $ret;
1053- }
1054- /**
1055- * Rename a tag
1056- *
1057- * @param string $old_tag
1058- * @param string $new_tag
1059- * @return boolean Success or Failure
1060- * @uses normalize_tags
1061- * @uses get_items
1062- * @uses set_items
1063- * @uses remove_tags
1064- * @uses add_tags
1065- * @access public
1066- */
1067- function rename_tag($old_tag, $new_tag)
1068- {
1069- $old_tag = $this->normalize_tags($old_tag);
1070- $new_tag = $this->normalize_tags($new_tag);
1071- $items = $this->get_items($old_tag);
1072- if (empty($items)) return false;
1073- $ret = true;
1074- $ret &= $this->set_items($old_tag, array());
1075- $ret &= $this->set_items($new_tag, $items);
1076- foreach ($items as $item) {
1077- $ret &= $this->remove_tags($item, $old_tag);
1078- $ret &= $this->add_tags($item, $new_tag);
1079- }
1080- // $ret &= $this->update_tagcloud();
1081- return $ret;
1082- }
940+ /**
941+ * Save tags into an item (This does more than set_tags)
942+ *
943+ * @param string $item
944+ * @param mixed $tags string or array of tag(s)
945+ * @return boolean Success or Failure
946+ * @uses normalize_tags
947+ * @uses get_tags
948+ * @uses set_tags
949+ * @uses get_items
950+ * @uses set_items
951+ * @uses update_tagcloud
952+ * @access public
953+ */
954+ function save_tags($item, $new_tags)
955+ {
956+ $new_tags = (array)$new_tags;
957+ $old_tags = $this->get_tags($item);
958+ $new_tags = $this->normalize_tags($new_tags);
959+ $ret = true;
960+ $ret &= $this->set_tags($item, $new_tags);
961+ list($minus, $plus) = ya_array_diff($old_tags, $new_tags);
962+ foreach ($minus as $tag) {
963+ $old_items = $this->get_items($tag);
964+ $new_items = array_diff($old_items, (array)$item);
965+ $ret &= $this->set_items($tag, $new_items);
966+ }
967+ foreach ($plus as $tag) {
968+ $old_items = $this->get_items($tag);
969+ $new_items = array_unique(array_merge($old_items, (array)$item));
970+ $ret &= $this->set_items($tag, $new_items);
971+ }
972+ $ret &= $this->update_tagcloud();
973+ return $ret;
974+ }
975+ /**
976+ * Add tags into an item
977+ *
978+ * @param string $item
979+ * @param mixed $tags string or array of tag(s)
980+ * @return boolean Success or Failure
981+ * @uses normalize_tags
982+ * @uses get_tags
983+ * @uses set_tags
984+ * @uses get_items
985+ * @uses set_items
986+ * @uses update_tagcloud
987+ * @access public
988+ */
989+ function add_tags($item, $tags)
990+ {
991+ $tags = (array)$tags;
992+ $tags = $this->normalize_tags($tags);
993+ $new_tags = array_unique(array_merge($this->get_tags($item), $tags));
994+ // return $this->save_tags($item, $new_tags);
995+ $ret = true;
996+ $ret &= $this->set_tags($item, $new_tags);
997+ foreach ($tags as $tag) {
998+ $old_items = $this->get_items($tag);
999+ $new_items = array_unique(array_merge($old_items, (array)$item));
1000+ $ret &= $this->set_items($tag, $new_items);
1001+ }
1002+ $ret &= $this->update_tagcloud();
1003+ return $ret;
1004+ }
1005+ /**
1006+ * Remove tags from an item
1007+ *
1008+ * @param string $item
1009+ * @param mixed $tags string or array of tag(s)
1010+ * @return boolean Success or Failure
1011+ * @uses normalize_tags
1012+ * @uses get_tags
1013+ * @uses set_tags
1014+ * @uses get_items
1015+ * @uses set_items
1016+ * @uses update_tagcloud
1017+ * @access public
1018+ */
1019+ function remove_tags($item, $tags)
1020+ {
1021+ $tags = (array)$tags;
1022+ $tags = $this->normalize_tags($tags);
1023+ $new_tags = array_diff($this->get_tags($item), $tags);
1024+ // return $this->save_tags($item, $new_tags);
1025+ $ret = true;
1026+ $ret &= $this->set_tags($item, $new_tags);
1027+ foreach ($tags as $tag) {
1028+ $old_items = $this->get_items($tag);
1029+ $new_items = array_diff($old_items, (array)$item);
1030+ $ret &= $this->set_items($tag, $new_items);
1031+ }
1032+ $ret &= $this->update_tagcloud();
1033+ return $ret;
1034+ }
1035+ /**
1036+ * Remove tags from the system
1037+ *
1038+ * @uses Tag::remove_tags()
1039+ *
1040+ * @param mixed $tags string or array of tag(s)
1041+ * @return boolean Success or Failure
1042+ * @uses normalize_tags
1043+ * @uses get_items
1044+ * @uses remove_tags
1045+ * @uses set_items
1046+ * @uses update_tagcloud
1047+ * @access public
1048+ */
1049+ function remove_system_tags($tags)
1050+ {
1051+ $tags = (array)$tags;
1052+ $tags = $this->normalize_tags($tags);
1053+ $ret = true;
1054+ foreach ($tags as $tag) {
1055+ foreach ($this->get_items($tag) as $item) {
1056+ $ret &= $this->remove_tags($item, $tag);
1057+ }
1058+ $ret &= $this->set_items($tag, array());
1059+ }
1060+ $ret &= $this->update_tagcloud();
1061+ return $ret;
1062+ }
1063+ /**
1064+ * Rename a tag
1065+ *
1066+ * @param string $old_tag
1067+ * @param string $new_tag
1068+ * @return boolean Success or Failure
1069+ * @uses normalize_tags
1070+ * @uses get_items
1071+ * @uses set_items
1072+ * @uses remove_tags
1073+ * @uses add_tags
1074+ * @access public
1075+ */
1076+ function rename_tag($old_tag, $new_tag)
1077+ {
1078+ $old_tag = $this->normalize_tags($old_tag);
1079+ $new_tag = $this->normalize_tags($new_tag);
1080+ $items = $this->get_items($old_tag);
1081+ if (empty($items)) return false;
1082+ $ret = true;
1083+ $ret &= $this->set_items($old_tag, array());
1084+ $ret &= $this->set_items($new_tag, $items);
1085+ foreach ($items as $item) {
1086+ $ret &= $this->remove_tags($item, $old_tag);
1087+ $ret &= $this->add_tags($item, $new_tag);
1088+ }
1089+ // $ret &= $this->update_tagcloud();
1090+ return $ret;
1091+ }
10831092
1084- /**
1085- * Rename an item
1086- *
1087- * @param string $old_item
1088- * @param string $new_item
1089- * @return boolean Success or Failure
1090- * @uses get_tags
1091- * @uses save_tags
1092- * @access public
1093- */
1094- function rename_item($old_item, $new_item)
1095- {
1096- $tags = $this->get_tags($old_item);
1097- if (empty($tags)) return false;
1098- $ret = true;
1099- $ret &= $this->save_tags($old_item, array());
1100- $ret &= $this->save_tags($new_item, $tags);
1101- // $ret &= $this->update_tagcloud();
1102- return $ret;
1103- }
1093+ /**
1094+ * Rename an item
1095+ *
1096+ * @param string $old_item
1097+ * @param string $new_item
1098+ * @return boolean Success or Failure
1099+ * @uses get_tags
1100+ * @uses save_tags
1101+ * @access public
1102+ */
1103+ function rename_item($old_item, $new_item)
1104+ {
1105+ $tags = $this->get_tags($old_item);
1106+ if (empty($tags)) return false;
1107+ $ret = true;
1108+ $ret &= $this->save_tags($old_item, array());
1109+ $ret &= $this->save_tags($new_item, $tags);
1110+ // $ret &= $this->update_tagcloud();
1111+ return $ret;
1112+ }
11041113
1105- /**
1106- * Check if a tag exists in a certain item
1107- *
1108- * @param string $tag
1109- * @return boolean
1110- * @access public
1111- */
1112- function has_tag($item, $tag)
1113- {
1114- return in_array($tag, $this->get_tags($item));
1115- }
1116- /**
1117- * Check if a tag exists in the system
1118- *
1119- * @param string $tag
1120- * @return boolean
1121- * @access public
1122- */
1123- function has_system_tag($tag)
1124- {
1125- $items = $this->get_items($tag);
1126- return ! empty($items);
1127- }
1128- /**
1129- * Normalize tags
1130- *
1131- * @param string or array $tags
1132- * @return string or array normalized tags
1133- * @access public
1134- */
1135- function normalize_tags($tags)
1136- {
1137- $isarray = is_array($tags);
1138- $tags = (array)$tags;
1139- // if (extension_loaded('mbstring'))
1140- //if (function_exists('mb_strtolower')) {
1141- //foreach ($tags as $i => $tag) {
1142- //$tags[$i] = mb_strtolower($tag, SOURCE_ENCODING);
1143- //}
1144- //}
1114+ /**
1115+ * Check if a tag exists in a certain item
1116+ *
1117+ * @param string $tag
1118+ * @return boolean
1119+ * @access public
1120+ */
1121+ function has_tag($item, $tag)
1122+ {
1123+ return in_array($tag, $this->get_tags($item));
1124+ }
1125+ /**
1126+ * Check if a tag exists in the system
1127+ *
1128+ * @param string $tag
1129+ * @return boolean
1130+ * @access public
1131+ */
1132+ function has_system_tag($tag)
1133+ {
1134+ $items = $this->get_items($tag);
1135+ return ! empty($items);
1136+ }
1137+ /**
1138+ * Normalize tags
1139+ *
1140+ * @param string or array $tags
1141+ * @return string or array normalized tags
1142+ * @access public
1143+ */
1144+ function normalize_tags($tags)
1145+ {
1146+ $isarray = is_array($tags);
1147+ $tags = (array)$tags;
1148+ // if (extension_loaded('mbstring'))
1149+ //if (function_exists('mb_strtolower')) {
1150+ //foreach ($tags as $i => $tag) {
1151+ //$tags[$i] = mb_strtolower($tag, SOURCE_ENCODING);
1152+ //}
1153+ //}
11451154
1146- // Reserved keys can not be used for tag strings
1147- foreach ($tags as $i => $tag) {
1148- $tags[$i] = str_replace($this->reserved_keys, '', $tag);
1149- }
1150- $tags = array_unique($tags);
1151- if ($isarray) return $tags;
1152- else return $tags[0];
1153- }
1155+ // Reserved keys can not be used for tag strings
1156+ foreach ($tags as $i => $tag) {
1157+ $tags[$i] = str_replace($this->reserved_keys, '', $tag);
1158+ }
1159+ $tags = array_unique($tags);
1160+ if ($isarray) return $tags;
1161+ else return $tags[0];
1162+ }
11541163
1155- /**
1156- * Get tagcloud
1157- *
1158- * @param integer $limit
1159- * @param string $relate_tag
1160- * @param boolean $cache use memory cache
1161- * @return array
1162- * @access public
1163- */
1164- function get_tagcloud($limit = null, $relate_tag = null, $cache = true)
1165- {
1166- if (isset($this->tagcloud) & $cache) {
1167- $tagcloud = $this->tagcloud;
1168- } else {
1169- $tagcloud = $this->get_tagcloud_from_storage();
1170- }
1171- if (isset($relate_tag)) {
1172- $related_tags = $this->get_related_tags($relate_tag);
1173- $r_tagcloud = array();
1174- foreach ($related_tags as $tag) {
1175- $r_tagcloud[$tag] = $tagcloud[$tag];
1176- }
1177- $tagcloud = $r_tagcloud;
1178- }
1179- if (isset($limit)) {
1180- arsort($tagcloud);
1181- $tagcloud = array_slice($tagcloud, 0, $limit);
1182- ksort($tagcloud);
1183- }
1184- return $tagcloud;
1185- }
1164+ /**
1165+ * Get tagcloud
1166+ *
1167+ * @param integer $limit
1168+ * @param string $relate_tag
1169+ * @param boolean $cache use memory cache
1170+ * @return array
1171+ * @access public
1172+ */
1173+ function get_tagcloud($limit = null, $relate_tag = null, $cache = true)
1174+ {
1175+ if (isset($this->tagcloud) & $cache) {
1176+ $tagcloud = $this->tagcloud;
1177+ } else {
1178+ $tagcloud = $this->get_tagcloud_from_storage();
1179+ }
1180+ if (isset($relate_tag)) {
1181+ $related_tags = $this->get_related_tags($relate_tag);
1182+ $r_tagcloud = array();
1183+ foreach ($related_tags as $tag) {
1184+ $r_tagcloud[$tag] = $tagcloud[$tag];
1185+ }
1186+ $tagcloud = $r_tagcloud;
1187+ }
1188+ if (isset($limit)) {
1189+ arsort($tagcloud);
1190+ $tagcloud = array_slice($tagcloud, 0, $limit);
1191+ ksort($tagcloud);
1192+ }
1193+ return $tagcloud;
1194+ }
11861195
1187- /**
1188- * Update tagcloud
1189- *
1190- * Excute after set_tags and set_items
1191- *
1192- * @param boolean $cache use memory cache
1193- * @return boolean
1194- * @access public
1195- */
1196- function update_tagcloud($cache = true)
1197- {
1198- if (isset($this->tagcloud) & $cache) {
1199- $tagcloud = $this->tagcloud; // read cache
1200- } else {
1201- $tagcloud = $this->get_tagcloud();
1202- }
1203- $ret = true;
1204- if (! empty($this->items)) { // update
1205- foreach ($this->items as $tag => $items) {
1206- $count = count($items);
1207- if ($count === 0) {
1208- unset($tagcloud[$tag]);
1209- } else {
1210- $tagcloud[$tag] = $count;
1211- }
1212- }
1213- ksort($tagcloud);
1214- $ret &= $this->set_tagcloud_into_storage($tagcloud);
1215- }
1216- if ($cache) $this->tagcloud = $tagcloud;
1217- return $ret;
1218- }
1196+ /**
1197+ * Update tagcloud
1198+ *
1199+ * Excute after set_tags and set_items
1200+ *
1201+ * @param boolean $cache use memory cache
1202+ * @return boolean
1203+ * @access public
1204+ */
1205+ function update_tagcloud($cache = true)
1206+ {
1207+ if (isset($this->tagcloud) & $cache) {
1208+ $tagcloud = $this->tagcloud; // read cache
1209+ } else {
1210+ $tagcloud = $this->get_tagcloud();
1211+ }
1212+ $ret = true;
1213+ if (! empty($this->items)) { // update
1214+ foreach ($this->items as $tag => $items) {
1215+ $count = count($items);
1216+ if ($count === 0) {
1217+ unset($tagcloud[$tag]);
1218+ } else {
1219+ $tagcloud[$tag] = $count;
1220+ }
1221+ }
1222+ ksort($tagcloud);
1223+ $ret &= $this->set_tagcloud_into_storage($tagcloud);
1224+ }
1225+ if ($cache) $this->tagcloud = $tagcloud;
1226+ return $ret;
1227+ }
12191228
1220- /**
1221- * Get related tags
1222- *
1223- * @param string $tag
1224- * @return array
1225- * @access public
1226- */
1227- function get_related_tags($tag = null)
1228- {
1229- if ($tag === null) return false;
1230- $items = $this->get_items($tag);
1231- $tags = array();
1232- foreach ($items as $item) {
1233- $tags = array_merge($tags, (array)$this->get_tags($item));
1234- }
1235- $tags = array_unique($tags);
1236- return $tags;
1237- }
1229+ /**
1230+ * Get related tags
1231+ *
1232+ * @param string $tag
1233+ * @return array
1234+ * @access public
1235+ */
1236+ function get_related_tags($tag = null)
1237+ {
1238+ if ($tag === null) return false;
1239+ $items = $this->get_items($tag);
1240+ $tags = array();
1241+ foreach ($items as $item) {
1242+ $tags = array_merge($tags, (array)$this->get_tags($item));
1243+ }
1244+ $tags = array_unique($tags);
1245+ return $tags;
1246+ }
12381247
1239- /**
1240- * Get items by a tag token
1241- *
1242- * TagA^TagB => intersection
1243- * TagA-TagB => subtraction
1244- *
1245- * @param string $tagtok
1246- * @return array items
1247- * @access public
1248- */
1249- function get_items_by_tagtok($tagtok)
1250- {
1251- // token analysis
1252- $tags = array();
1253- $operands = array();
1254- $tokpos = -1;
1248+ /**
1249+ * Get items by a tag token
1250+ *
1251+ * TagA^TagB => intersection
1252+ * TagA-TagB => subtraction
1253+ *
1254+ * @param string $tagtok
1255+ * @return array items
1256+ * @access public
1257+ */
1258+ function get_items_by_tagtok($tagtok)
1259+ {
1260+ // token analysis
1261+ $tags = array();
1262+ $operands = array();
1263+ $tokpos = -1;
12551264
1256- $token = implode('', $this->reserved_keys);
1257- $substr = strtok($tagtok, $token);
1258- array_push($tags, $substr);
1259- $tokpos = $tokpos + strlen($substr) + 1;
1260- $substr = strtok($token);
1261- while ($substr !== false) {
1262- switch ($tagtok[$tokpos]) {
1263- case $this->reserved_keys['diff']:
1264- array_push($operands, $this->reserved_keys['diff']);
1265- break;
1266- case $this->reserved_keys['prod']:
1267- default:
1268- array_push($operands, $this->reserved_keys['prod']);
1269- break;
1270- }
1271- array_push($tags, $substr);
1272- $tokpos = $tokpos + strlen($substr) + 1;
1273- $substr = strtok($token);
1274- }
1265+ $token = implode('', $this->reserved_keys);
1266+ $substr = strtok($tagtok, $token);
1267+ array_push($tags, $substr);
1268+ $tokpos = $tokpos + strlen($substr) + 1;
1269+ $substr = strtok($token);
1270+ while ($substr !== false) {
1271+ switch ($tagtok[$tokpos]) {
1272+ case $this->reserved_keys['diff']:
1273+ array_push($operands, $this->reserved_keys['diff']);
1274+ break;
1275+ case $this->reserved_keys['prod']:
1276+ default:
1277+ array_push($operands, $this->reserved_keys['prod']);
1278+ break;
1279+ }
1280+ array_push($tags, $substr);
1281+ $tokpos = $tokpos + strlen($substr) + 1;
1282+ $substr = strtok($token);
1283+ }
12751284
1276- // narrow items
1277- $items = $this->get_items(array_shift($tags));
1278- foreach ($tags as $i => $tag) {
1279- switch ($operands[$i]) {
1280- case $this->reserved_keys['diff']:
1281- $items = array_diff($items, $this->get_items($tag));
1282- break;
1283- case $this->reserved_keys['prod']:
1284- default:
1285- $items = array_intersect($items, $this->get_items($tag));
1286- break;
1287- }
1288- }
1289- return $items;
1290- }
1285+ // narrow items
1286+ $items = $this->get_items(array_shift($tags));
1287+ foreach ($tags as $i => $tag) {
1288+ switch ($operands[$i]) {
1289+ case $this->reserved_keys['diff']:
1290+ $items = array_diff($items, $this->get_items($tag));
1291+ break;
1292+ case $this->reserved_keys['prod']:
1293+ default:
1294+ $items = array_intersect($items, $this->get_items($tag));
1295+ break;
1296+ }
1297+ }
1298+ return $items;
1299+ }
12911300
1292- /**
1293- * Display tags
1294- *
1295- * Overwrite Me!
1296- *
1297- * @param string $item
1298- * @access public
1299- */
1300- function display_tags($tags)
1301- {
1302- print_r($tags);
1303- }
1301+ /**
1302+ * Display tags
1303+ *
1304+ * Overwrite Me!
1305+ *
1306+ * @param string $item
1307+ * @access public
1308+ */
1309+ function display_tags($tags)
1310+ {
1311+ print_r($tags);
1312+ }
13041313
1305- /**
1306- * Display items
1307- *
1308- * Overwrite Me!
1309- *
1310- * @param string $tag
1311- * @access public
1312- */
1313- function display_items($items)
1314- {
1315- print_r($items);
1316- }
1314+ /**
1315+ * Display items
1316+ *
1317+ * Overwrite Me!
1318+ *
1319+ * @param string $tag
1320+ * @access public
1321+ */
1322+ function display_items($items)
1323+ {
1324+ print_r($items);
1325+ }
13171326
1318- /**
1319- * Display tagcloud
1320- *
1321- * Overwrite Me!
1322- *
1323- * @param integer $limit
1324- * @param string $relate_tag
1325- * @access public
1326- */
1327- function display_tagcloud($limit = null, $relate_tag = null)
1328- {
1329- $tagcloud = $this->get_tagcloud($limit, $relate_tag);
1330- print '[Tabcloud]';
1331- print_r($tagcloud);
1332- }
1327+ /**
1328+ * Display tagcloud
1329+ *
1330+ * Overwrite Me!
1331+ *
1332+ * @param integer $limit
1333+ * @param string $relate_tag
1334+ * @access public
1335+ */
1336+ function display_tagcloud($limit = null, $relate_tag = null)
1337+ {
1338+ $tagcloud = $this->get_tagcloud($limit, $relate_tag);
1339+ print '[Tabcloud]';
1340+ print_r($tagcloud);
1341+ }
13331342 }
13341343 /*
13351344 $tag = new Tag();
@@ -1353,155 +1362,159 @@ $tag->display_tagcloud(null, 'Plugin');
13531362 * Example
13541363 * <code>
13551364 * $tags = array(
1356- * array('tag' => 'blog', 'count' => 20),
1357- * array('tag' => 'ajax', 'count' => 10),
1358- * array('tag' => 'mysql', 'count' => 5),
1359- * array('tag' => 'hatena', 'count' => 12),
1360- * array('tag' => 'bookmark', 'count' => 30),
1361- * array('tag' => 'rss', 'count' => 1),
1362- * array('tag' => 'atom', 'count' => 2),
1363- * array('tag' => 'misc', 'count' => 10),
1364- * array('tag' => 'javascript', 'count' => 11),
1365- * array('tag' => 'xml', 'count' => 6),
1366- * array('tag' => 'perl', 'count' => 32),
1365+ * array('tag' => 'blog', 'count' => 20),
1366+ * array('tag' => 'ajax', 'count' => 10),
1367+ * array('tag' => 'mysql', 'count' => 5),
1368+ * array('tag' => 'hatena', 'count' => 12),
1369+ * array('tag' => 'bookmark', 'count' => 30),
1370+ * array('tag' => 'rss', 'count' => 1),
1371+ * array('tag' => 'atom', 'count' => 2),
1372+ * array('tag' => 'misc', 'count' => 10),
1373+ * array('tag' => 'javascript', 'count' => 11),
1374+ * array('tag' => 'xml', 'count' => 6),
1375+ * array('tag' => 'perl', 'count' => 32),
13671376 * );
13681377 * $cloud = new TagCloud();
13691378 * foreach ($tags as $t) {
1370- * $cloud->add($t['tag'], "http://<your.domain>/{$t['tag']}/", $t['count']);
1379+ * $cloud->add($t['tag'], "http://<your.domain>/{$t['tag']}/", $t['count']);
13711380 * }
13721381 * print "<html><body>";
13731382 * print $cloud->htmlAndCSS(20);
13741383 * print "</body></html>";
13751384 * </code>
13761385 *
1377- * @author astronote
1378- * @license http://www.gnu.org/licenses/gpl.html GPL2
1379- * @link http://astronote.jp/
1386+ * @author astronote
1387+ * @license http://www.gnu.org/licenses/gpl.html GPL2
1388+ * @link http://astronote.jp/
13801389 */
13811390 class TagCloud
13821391 {
1383- /**
1384- * Counts of tags
1385- *
1386- * Associative array of integers whose key is a tag and value
1387- * is its count (number of items associated with the tag)
1388- *
1389- * @var array
1390- *
1391- * [tag] = count
1392- */
1393- var $counts;
1394- /**
1395- * Urls of tags
1396- *
1397- * Associative array of strings whose key is a tag
1398- * and value is its link to be displayed in tagcloud
1399- *
1400- * @var array
1401- *
1402- * [tag] = url
1403- */
1404- var $urls;
1405-
1406- function TagCloud()
1407- {
1408- $this->counts = array();
1409- $this->urls = array();
1410- }
1392+ /**
1393+ * Counts of tags
1394+ *
1395+ * Associative array of integers whose key is a tag and value
1396+ * is its count (number of items associated with the tag)
1397+ *
1398+ * @var array
1399+ *
1400+ * [tag] = count
1401+ */
1402+ var $counts;
1403+ /**
1404+ * Urls of tags
1405+ *
1406+ * Associative array of strings whose key is a tag
1407+ * and value is its link to be displayed in tagcloud
1408+ *
1409+ * @var array
1410+ *
1411+ * [tag] = url
1412+ */
1413+ var $urls;
1414+
1415+ function __construct()
1416+ {
1417+ $this->counts = array();
1418+ $this->urls = array();
1419+ }
1420+
1421+ function TagCloud() {
1422+ $this->__construct();
1423+ }
14111424
1412- /**
1413- * Add a tag
1414- *
1415- * @param $tag tag
1416- * @param $url associated url to be displayed in tagcloud
1417- * @param $count number of items associated with tag.
1418- * @return void
1419- * @access public
1420- */
1421- function add($tag, $url, $count)
1422- {
1423- $this->counts[$tag] = $count;
1424- $this->urls[$tag] = $url;
1425- }
1425+ /**
1426+ * Add a tag
1427+ *
1428+ * @param $tag tag
1429+ * @param $url associated url to be displayed in tagcloud
1430+ * @param $count number of items associated with tag.
1431+ * @return void
1432+ * @access public
1433+ */
1434+ function add($tag, $url, $count)
1435+ {
1436+ $this->counts[$tag] = $count;
1437+ $this->urls[$tag] = $url;
1438+ }
14261439
1427- /**
1428- * Generate embedded CSS HTML
1429- *
1430- * You may create a .css file instead of using this function everytime
1431- *
1432- * @return string CSS
1433- */
1434- function css()
1435- {
1436- $css = '#htmltagcloud { text-align: center; line-height: 16px; }';
1437- for ($level = 0; $level <= 24; $level++) {
1438- $font = 12 + $level;
1439- $css .= "span.tagcloud$level { font-size: ${font}px;}\n";
1440- $css .= "span.tagcloud$level a {text-decoration: none;}\n";
1441- }
1442- return $css;
1443- }
1440+ /**
1441+ * Generate embedded CSS HTML
1442+ *
1443+ * You may create a .css file instead of using this function everytime
1444+ *
1445+ * @return string CSS
1446+ */
1447+ function css()
1448+ {
1449+ $css = '#htmltagcloud { text-align: center; line-height: 16px; }';
1450+ for ($level = 0; $level <= 24; $level++) {
1451+ $font = 12 + $level;
1452+ $css .= "span.tagcloud$level { font-size: ${font}px;}\n";
1453+ $css .= "span.tagcloud$level a {text-decoration: none;}\n";
1454+ }
1455+ return $css;
1456+ }
14441457
1445- /**
1446- * Generate tagcloud HTML
1447- *
1448- * @param $limit number of limits to be displayed
1449- * @return string HTML
1450- * @access public
1451- */
1452- function html($limit = NULL)
1453- {
1454- $a = $this->counts;
1455- arsort($a);
1456- $tags = array_keys($a);
1457- if (isset($limit)) {
1458- $tags = array_slice($tags, 0, $limit);
1459- }
1460- $n = count($tags);
1461- if ($n == 0) {
1462- return '';
1463- } elseif ($n == 1) {
1464- $tag = $tags[0];
1465- $url = $this->urls[$tag];
1466- return "<div class=\"htmltagcloud\"><span class=\"tagcloud1\"><a href=\"$url\">$tag</a></span></div>\n";
1467- }
1468-
1469- $min = sqrt($this->counts[$tags[$n - 1]]);
1470- $max = sqrt($this->counts[$tags[0]]);
1471- $factor = 0;
1472-
1473- // specal case all tags having the same count
1474- if (($max - $min) == 0) {
1475- $min -= 24;
1476- $factor = 1;
1477- } else {
1478- $factor = 24 / ($max - $min);
1479- }
1480- $html = '';
1481- sort($tags);
1482- foreach($tags as $tag) {
1483- $count = $this->counts[$tag];
1484- $url = $this->urls[$tag];
1485- $level = (int)((sqrt($count) - $min) * $factor);
1486- $html .= "<span class=\"tagcloud$level\"><a href=\"$url\">$tag</a></span>\n";
1487- }
1488- $html = "<div class=\"htmltagcloud\">$html</div>";
1489- return $html;
1490- }
1458+ /**
1459+ * Generate tagcloud HTML
1460+ *
1461+ * @param $limit number of limits to be displayed
1462+ * @return string HTML
1463+ * @access public
1464+ */
1465+ function html($limit = NULL)
1466+ {
1467+ $a = $this->counts;
1468+ arsort($a);
1469+ $tags = array_keys($a);
1470+ if (isset($limit)) {
1471+ $tags = array_slice($tags, 0, $limit);
1472+ }
1473+ $n = count($tags);
1474+ if ($n == 0) {
1475+ return '';
1476+ } elseif ($n == 1) {
1477+ $tag = $tags[0];
1478+ $url = $this->urls[$tag];
1479+ return "<div class=\"htmltagcloud\"><span class=\"tagcloud1\"><a href=\"$url\">$tag</a></span></div>\n";
1480+ }
1481+
1482+ $min = sqrt($this->counts[$tags[$n - 1]]);
1483+ $max = sqrt($this->counts[$tags[0]]);
1484+ $factor = 0;
1485+
1486+ // specal case all tags having the same count
1487+ if (($max - $min) == 0) {
1488+ $min -= 24;
1489+ $factor = 1;
1490+ } else {
1491+ $factor = 24 / ($max - $min);
1492+ }
1493+ $html = '';
1494+ sort($tags);
1495+ foreach($tags as $tag) {
1496+ $count = $this->counts[$tag];
1497+ $url = $this->urls[$tag];
1498+ $level = (int)((sqrt($count) - $min) * $factor);
1499+ $html .= "<span class=\"tagcloud$level\"><a href=\"$url\">$tag</a></span>\n";
1500+ }
1501+ $html = "<div class=\"htmltagcloud\">$html</div>";
1502+ return $html;
1503+ }
14911504
1492- /**
1493- * Generate tagcloud HTML and embedded CSS HTML concurrently
1494- *
1495- * @param $limit number of limits to be displayed in tagcloud
1496- * @return string HTML
1497- * @access public
1498- */
1499- function htmlAndCSS($limit = NULL)
1500- {
1501- $html = "<style type=\"text/css\">\n" . $this->css() . "</style>"
1502- . $this->html($limit);
1503- return $html;
1504- }
1505+ /**
1506+ * Generate tagcloud HTML and embedded CSS HTML concurrently
1507+ *
1508+ * @param $limit number of limits to be displayed in tagcloud
1509+ * @return string HTML
1510+ * @access public
1511+ */
1512+ function htmlAndCSS($limit = NULL)
1513+ {
1514+ $html = "<style type=\"text/css\">\n" . $this->css() . "</style>"
1515+ . $this->html($limit);
1516+ return $html;
1517+ }
15051518 }
15061519
15071520 ?>
--- a/tag/tagcloud.inc.php
+++ b/tag/tagcloud.inc.php
@@ -9,67 +9,115 @@
99 * @uses tag.inc.php
1010 * @package plugin
1111 */
12+ // v1.11 PHP8.0対応 2021-12-15 byはいふん
1213
1314 exist_plugin('tag') or die_message('tag.inc.php does not exist.');
1415 class PluginTagcloud
1516 {
16- var $plugin_tag;
17+ var $plugin_tag;
1718
18- function PluginTagcloud()
19- {
20- static $default_options = array();
21- if (empty($default_options)) {
22- $default_options['limit'] = NULL;
23- $default_options['related'] = NULL;
24- $default_options['cloud'] = TRUE;
25- }
26- // static
27- $this->default_options = & $default_options;
28- // init
29- $this->options = $default_options;
30- global $plugin_tag_name;
31- $this->plugin_tag = new $plugin_tag_name();
32- }
19+ function __construct()
20+ {
21+ static $default_options = array();
22+ if (empty($default_options)) {
23+ $default_options['limit'] = NULL;
24+ $default_options['related'] = NULL;
25+ $default_options['cloud'] = TRUE;
26+ }
27+ // static
28+ $this->default_options = & $default_options;
29+ // init
30+ $this->options = $default_options;
31+ global $plugin_tag_name;
32+ $this->plugin_tag = new $plugin_tag_name();
33+ }
34+
35+ function PluginTagcloud() {
36+ $this->__construct();
37+ }
3338
34- function convert() // tagcloud
35- {
36- $args = func_get_args();
37- parse_options($args, $this->options);
38- if ($this->options['limit'] === "0") {
39- $this->options['limit'] = NULL;
40- }
41- if ($this->options['cloud'] === 'off' ||
42- $this->options['cloud'] === 'false' ) {
43- $this->options['cloud'] = FALSE;
44- }
45- //print_r($this->options);
46- if ($this->options['cloud']) {
47- $html = $this->plugin_tag->display_tagcloud($this->options['limit'], $this->options['related']);
48- } else {
49- $html = $this->plugin_tag->display_taglist($this->options['limit'], $this->options['related']);
50- }
51- return $html;
52- }
39+ function convert() // tagcloud
40+ {
41+ $args = func_get_args();
42+ parse_options($args, $this->options);
43+ if ($this->options['limit'] === "0") {
44+ $this->options['limit'] = NULL;
45+ }
46+ if ($this->options['cloud'] === 'off' ||
47+ $this->options['cloud'] === 'false' ) {
48+ $this->options['cloud'] = FALSE;
49+ }
50+ //print_r($this->options);
51+ if ($this->options['cloud']) {
52+ $html = $this->plugin_tag->display_tagcloud($this->options['limit'], $this->options['related']);
53+ } else {
54+ $html = $this->plugin_tag->display_taglist($this->options['limit'], $this->options['related']);
55+ }
56+ return $html;
57+ }
5358 }
5459
60+define('PLUGIN_TAGCLOUD_CSS', <<<EOD
61+#body .htmltagcloud{
62+ font-size: 12px;
63+ line-height:340%;
64+}
65+.menubar .htmltagcloud{
66+ font-size: 6px;
67+ line-height:340%;
68+}
69+
70+.menubar .htmltagcloud span{
71+ display: block;
72+}
73+
74+.tagcloud0 { font-size: 100%;}
75+.tagcloud1 { font-size: 110%;}
76+.tagcloud2 { font-size: 120%;}
77+.tagcloud3 { font-size: 130%;}
78+.tagcloud4 { font-size: 140%;}
79+.tagcloud5 { font-size: 150%;}
80+.tagcloud6 { font-size: 160%;}
81+.tagcloud7 { font-size: 170%;}
82+.tagcloud8 { font-size: 180%;}
83+.tagcloud9 { font-size: 190%;}
84+.tagcloud10 { font-size: 200%;}
85+.tagcloud11 { font-size: 210%;}
86+.tagcloud12 { font-size: 220%;}
87+.tagcloud13 { font-size: 230%;}
88+.tagcloud14 { font-size: 240%;}
89+.tagcloud15 { font-size: 250%;}
90+.tagcloud16 { font-size: 260%;}
91+.tagcloud17 { font-size: 270%;}
92+.tagcloud18 { font-size: 280%;}
93+.tagcloud19 { font-size: 290%;}
94+.tagcloud20 { font-size: 300%;}
95+.tagcloud21 { font-size: 310%;}
96+.tagcloud22 { font-size: 320%;}
97+.tagcloud23 { font-size: 330%;}
98+.tagcloud24 { font-size: 340%;}
99+EOD
100+);
101+
55102 function plugin_tagcloud_init()
56103 {
57- global $plugin_tagcloud_name;
58- if (class_exists('PluginTagcloudUnitTest')) {
59- $plugin_tagcloud_name = 'PluginTagcloudUnitTest';
60- } elseif (class_exists('PluginTagcloudUser')) {
61- $plugin_tagcloud_name = 'PluginTagcloudUser';
62- } else {
63- $plugin_tagcloud_name = 'PluginTagcloud';
64- }
65- plugin_tag_init();
104+ global $plugin_tagcloud_name, $head_tags;
105+ if (class_exists('PluginTagcloudUnitTest')) {
106+ $plugin_tagcloud_name = 'PluginTagcloudUnitTest';
107+ } elseif (class_exists('PluginTagcloudUser')) {
108+ $plugin_tagcloud_name = 'PluginTagcloudUser';
109+ } else {
110+ $plugin_tagcloud_name = 'PluginTagcloud';
111+ }
112+ $head_tags[] = "<style>" . PLUGIN_TAGCLOUD_CSS . "</style>";
113+ plugin_tag_init();
66114 }
67115
68116 function plugin_tagcloud_convert()
69117 {
70- global $plugin_tagcloud, $plugin_tagcloud_name;
71- $plugin_tagcloud = new $plugin_tagcloud_name();
72- $args = func_get_args();
73- return call_user_func_array(array(&$plugin_tagcloud, 'convert'), $args);
118+ global $plugin_tagcloud, $plugin_tagcloud_name;
119+ $plugin_tagcloud = new $plugin_tagcloud_name();
120+ $args = func_get_args();
121+ return call_user_func_array(array(&$plugin_tagcloud, 'convert'), $args);
74122 }
75123 ?>
--- a/tag/taglist.inc.php
+++ b/tag/taglist.inc.php
@@ -9,187 +9,193 @@
99 * @uses tag.inc.php
1010 * @package plugin
1111 */
12+ // v1.11 PHP8.0対応 2021-12-15 byはいふん
1213
1314 exist_plugin('tag') or die_message('tag.inc.php does not exist.');
1415 class PluginTaglist
1516 {
16- function PluginTaglist()
17- {
18- static $default_options = array();
19- if (empty($default_options)) {
20- $default_options['tag'] = '';
21- $default_options['related'] = NULL;
22- }
23- // static
24- $this->default_options = & $default_options;
25- // init
26- $this->options = $default_options;
27- global $plugin_tag_name;
28- $this->plugin_tag = new $plugin_tag_name();
29- }
17+ function __construct()
18+ {
19+ static $default_options = array();
20+ if (empty($default_options)) {
21+ $default_options['tag'] = '';
22+ $default_options['related'] = NULL;
23+ }
24+ // static
25+ $this->default_options = & $default_options;
26+ // init
27+ $this->options = $default_options;
28+ global $plugin_tag_name;
29+ $this->plugin_tag = new $plugin_tag_name();
30+ }
3031
31- var $plugin_tag;
32- var $default_options;
33- var $options;
34- var $plugin = 'taglist';
32+ function PluginTaglist() {
33+ $this->__construct();
34+ }
3535
36- function action() // taglist
37- {
38- global $vars;
39- if (isset($vars['tag'])) {
40- $this->options['tag'] = $vars['tag'];
41- $msg = htmlspecialchars($this->options['tag']);
42- } elseif (isset($vars['related'])) {
43- $this->options['related'] = $vars['related'];
44- $msg = htmlspecialchars($this->options['related']);
45- } else {
46- $msg = _('Taglist');
47- }
48- $body = $this->taglist($this->options['tag'], $this->options['related']);
49- return array('msg'=>$msg, 'body'=>$body);
50- }
36+ var $plugin_tag;
37+ var $default_options;
38+ var $options;
39+ var $plugin = 'taglist';
5140
52- function convert() // taglist
53- {
54- $args = func_get_args();
55- ///// Support old versions (The 1st arg is tagtok) ///
56- $fisrtIsOption = FALSE;
57- foreach ($this->options as $key => $val) {
58- if (strpos($args[0], $key) === 0) {
59- $firstIsOption = TRUE; break;
60- }
61- }
62- if (func_num_args() >= 1 && ! $firstIsOption) {
63- $this->options['tag'] = array_shift($args);
64- }
65- //////////////////////////////////////////////////////
66- parse_options($args, $this->options);
67- return $this->taglist($this->options['tag'], $this->options['related']);
68- }
41+ function action() // taglist
42+ {
43+ global $vars;
44+ if (isset($vars['tag'])) {
45+ $this->options['tag'] = $vars['tag'];
46+ $msg = htmlsc($this->options['tag']);
47+ } elseif (isset($vars['related'])) {
48+ $this->options['related'] = $vars['related'];
49+ $msg = htmlsc($this->options['related']);
50+ } else {
51+ $msg = _('Taglist');
52+ }
53+ $body = $this->taglist($this->options['tag'], $this->options['related']);
54+ return array('msg'=>$msg, 'body'=>$body);
55+ }
6956
70- /**
71- * Body Function of this plugin
72- */
73- function taglist($tagtok = '', $relate_tag = NULL)
74- {
75- if ($tagtok !== '') {
76- $pages = $this->plugin_tag->get_taggedpages($tagtok);
77- $html = $this->display_pagelist($pages);
78- } else {
79- $html = $this->display_tagpagelist($relate_tag);
80- }
81- return $html;
82- }
57+ function convert() // taglist
58+ {
59+ $args = func_get_args();
60+ ///// Support old versions (The 1st arg is tagtok) ///
61+ $fisrtIsOption = FALSE;
62+ foreach ($this->options as $key => $val) {
63+ if (strpos($args[0], $key) === 0) {
64+ $firstIsOption = TRUE; break;
65+ }
66+ }
67+ if (func_num_args() >= 1 && ! $firstIsOption) {
68+ $this->options['tag'] = array_shift($args);
69+ }
70+ //////////////////////////////////////////////////////
71+ parse_options($args, $this->options);
72+ return $this->taglist($this->options['tag'], $this->options['related']);
73+ }
8374
84- /**
85- * Display tags and tagged pages
86- *
87- * Future Work: Use a common function with lsx.inc.php
88- *
89- * @param array $relate_tag Show only related tags of this
90- * @return string HTML
91- */
92- function display_tagpagelist($relate_tag = NULL, $cssclass = 'taglist tags')
93- {
94- $tagcloud = $this->plugin_tag->get_tagcloud(NULL, $relate_tag);
95- $html = '<ul class="' . $cssclass . '">';
96- foreach ($tagcloud as $tag => $count) {
97- $html .= '<li>' . $this->plugin_tag->get_taglink($tag);
98- $pages = $this->plugin_tag->get_taggedpages($tag);
99- $html .= $this->display_pagelist($pages);
100- $html .= '</li>';
101- }
102- $html .= '</ul>';
103- return $html;
104- }
75+ /**
76+ * Body Function of this plugin
77+ */
78+ function taglist($tagtok = '', $relate_tag = NULL)
79+ {
80+ if ($tagtok !== '') {
81+ $pages = $this->plugin_tag->get_taggedpages($tagtok);
82+ $html = $this->display_pagelist($pages);
83+ } else {
84+ $html = $this->display_tagpagelist($relate_tag);
85+ }
86+ return $html;
87+ }
10588
106- /**
107- * Display pages
108- *
109- * Future Work: Use a common function with lsx.inc.php
110- *
111- * @param array $pages pagenames
112- * @return string HTML
113- */
114- function display_pagelist($pages, $cssclass = 'taglist pages')
115- {
116- /* PukiWiki standard does listing as <ul><li style="padding-left:16*2px;margin-left:16*2px">.
117- Since I do no like it, I do as <ul><li style="list-type:none"><ul><li>
118-
119- <ul> <ul><li>1
120- <li>1</li> </li><li>1
121- <li>1 <ul><li>2
122- <ul> </li></ul></li><li>1
123- <li>2</li> </li><li>1
124- </ul> => <ul><li style="list-type:none"><ul><li>3
125- </li> </li></ul></li></ul></li></ul>
126- <li>1</li>
127- <li>1</li>
128- <ul><li style="list-type:none"><ul>
129- <li>3</li>
130- </ul></li></ul>
131- </li>
132- </ul>
133- */
134- $ul = $pdepth = 0;
135- foreach ($pages as $i => $page) {
136- $exist = is_page($page);
137- $depth = 1;
138- $link = make_pagelink_nopg($page);
139- $info = null;
140- if ($depth > $pdepth) {
141- $diff = $depth - $pdepth;
142- $html .= str_repeat('<ul><li style="list-style:none">', $diff - 1);
143- if ($depth == 1) { // first flag
144- $html .= '<ul' . (isset($cssclass) ? ' class="' . $cssclass . '"' : '') . '><li>';
145- } else {
146- $html .= '<ul><li>';
147- }
148- $ul += $diff;
149- } elseif ($depth == $pdepth) {
150- $html .= '</li><li>';
151- } elseif ($depth < $pdepth) {
152- $diff = $pdepth - $depth;
153- $html .= str_repeat('</li></ul>', $diff);
154- $html .= '</li><li>';
155- $ul -= $diff;
156- }
157- $pdepth = $depth;
89+ /**
90+ * Display tags and tagged pages
91+ *
92+ * Future Work: Use a common function with lsx.inc.php
93+ *
94+ * @param array $relate_tag Show only related tags of this
95+ * @return string HTML
96+ */
97+ function display_tagpagelist($relate_tag = NULL, $cssclass = 'taglist tags')
98+ {
99+ $tagcloud = $this->plugin_tag->get_tagcloud(NULL, $relate_tag);
100+ $html = '<ul class="' . $cssclass . '">';
101+ foreach ($tagcloud as $tag => $count) {
102+ $html .= '<li>' . $this->plugin_tag->get_taglink($tag);
103+ $pages = $this->plugin_tag->get_taggedpages($tag);
104+ $html .= $this->display_pagelist($pages);
105+ $html .= '</li>';
106+ }
107+ $html .= '</ul>';
108+ return $html;
109+ }
158110
159- $html .= $link;
160- $html .= isset($info) ? $info: '';
161- }
162- $html .= str_repeat('</li></ul>', $ul);
163- return $html;
164- }
111+ /**
112+ * Display pages
113+ *
114+ * Future Work: Use a common function with lsx.inc.php
115+ *
116+ * @param array $pages pagenames
117+ * @return string HTML
118+ */
119+ function display_pagelist($pages, $cssclass = 'taglist pages')
120+ {
121+ /* PukiWiki standard does listing as <ul><li style="padding-left:16*2px;margin-left:16*2px">.
122+ Since I do no like it, I do as <ul><li style="list-type:none"><ul><li>
123+
124+ <ul> <ul><li>1
125+ <li>1</li> </li><li>1
126+ <li>1 <ul><li>2
127+ <ul> </li></ul></li><li>1
128+ <li>2</li> </li><li>1
129+ </ul> => <ul><li style="list-type:none"><ul><li>3
130+ </li> </li></ul></li></ul></li></ul>
131+ <li>1</li>
132+ <li>1</li>
133+ <ul><li style="list-type:none"><ul>
134+ <li>3</li>
135+ </ul></li></ul>
136+ </li>
137+ </ul>
138+ */
139+ $html = "";
140+ $ul = $pdepth = 0;
141+ foreach ($pages as $i => $page) {
142+ $exist = is_page($page);
143+ $depth = 1;
144+ $link = make_pagelink_nopg($page);
145+ $info = null;
146+ if ($depth > $pdepth) {
147+ $diff = $depth - $pdepth;
148+ $html .= str_repeat('<ul><li style="list-style:none">', $diff - 1);
149+ if ($depth == 1) { // first flag
150+ $html .= '<ul' . (isset($cssclass) ? ' class="' . $cssclass . '"' : '') . '><li>';
151+ } else {
152+ $html .= '<ul><li>';
153+ }
154+ $ul += $diff;
155+ } elseif ($depth == $pdepth) {
156+ $html .= '</li><li>';
157+ } elseif ($depth < $pdepth) {
158+ $diff = $pdepth - $depth;
159+ $html .= str_repeat('</li></ul>', $diff);
160+ $html .= '</li><li>';
161+ $ul -= $diff;
162+ }
163+ $pdepth = $depth;
164+
165+ $html .= $link;
166+ $html .= isset($info) ? $info: '';
167+ }
168+ $html .= str_repeat('</li></ul>', $ul);
169+ return $html;
170+ }
165171 }
166172
167173 function plugin_taglist_init()
168174 {
169- global $plugin_taglist_name;
170- if (class_exists('PluginTaglistUnitTest')) {
171- $plugin_taglist_name = 'PluginTaglistUnitTest';
172- } elseif (class_exists('PluginTaglistUser')) {
173- $plugin_taglist_name = 'PluginTaglistUser';
174- } else {
175- $plugin_taglist_name = 'PluginTaglist';
176- }
177- plugin_tag_init();
175+ global $plugin_taglist_name;
176+ if (class_exists('PluginTaglistUnitTest')) {
177+ $plugin_taglist_name = 'PluginTaglistUnitTest';
178+ } elseif (class_exists('PluginTaglistUser')) {
179+ $plugin_taglist_name = 'PluginTaglistUser';
180+ } else {
181+ $plugin_taglist_name = 'PluginTaglist';
182+ }
183+ plugin_tag_init();
178184 }
179185
180186 function plugin_taglist_convert()
181187 {
182- global $plugin_taglist, $plugin_taglist_name;
183- $plugin_taglist = new $plugin_taglist_name();
184- $args = func_get_args();
185- return call_user_func_array(array(&$plugin_taglist, 'convert'), $args);
188+ global $plugin_taglist, $plugin_taglist_name;
189+ $plugin_taglist = new $plugin_taglist_name();
190+ $args = func_get_args();
191+ return call_user_func_array(array(&$plugin_taglist, 'convert'), $args);
186192 }
187193
188194 function plugin_taglist_action()
189195 {
190- global $plugin_taglist, $plugin_taglist_name;
191- $plugin_taglist = new $plugin_taglist_name();
192- return $plugin_taglist->action();
196+ global $plugin_taglist, $plugin_taglist_name;
197+ $plugin_taglist = new $plugin_taglist_name();
198+ return $plugin_taglist->action();
193199 }
194200
195201 ?>