OSDN Git Service

BugTrack/800: 'contents' and 'related' can not operate with same name created.
[pukiwiki/pukiwiki.git] / plugin / related.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: related.inc.php,v 1.6 2005/04/10 18:41:02 teanan Exp $
4 //
5 // Related plugin: Show Backlinks for the page
6
7 function plugin_related_convert()
8 {
9         global $vars;
10
11         return make_related($vars['page'], 'p');
12 }
13
14 // Show Backlinks: via related caches for the page
15 function plugin_related_action()
16 {
17         global $vars, $script, $non_list, $defaultpage, $whatsnew;
18
19         $_page = isset($vars['page']) ? $vars['page'] : '';
20         if ($_page == '') $_page = $defaultpage;
21
22         // Get related from cache
23         $data = links_get_related_db($_page);
24         if (! empty($data)) {
25                 // Hide by array keys (not values)
26                 $non_list_pattern = '/' . $non_list . '/';
27                 foreach(array_keys($data) as $page)
28                         if ($page == $whatsnew ||
29                             preg_match($non_list_pattern, $page))
30                                 unset($data[$page]);
31         }
32
33         // Result
34         $r_word = rawurlencode($_page);
35         $s_word = htmlspecialchars($_page);
36         $msg = 'Backlinks for: ' . $s_word;
37         $retval  = '<a href="' . $script . '?' . $r_word . '">' .
38                 'Return to ' . $s_word .'</a><br />'. "\n";
39
40         if (empty($data)) {
41                 $retval .= '<ul><li>No related pages found.</li></ul>' . "\n";  
42         } else {
43                 // Show count($data)?
44                 ksort($data);
45                 $retval .= '<ul>' . "\n";
46                 foreach ($data as $page=>$time) {
47                         $r_page  = rawurlencode($page);
48                         $s_page  = htmlspecialchars($page);
49                         $passage = get_passage($time);
50                         $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page .
51                                 '</a> ' . $passage . '</li>' . "\n";
52                 }
53                 $retval .= '</ul>' . "\n";
54         }
55         return array('msg'=>$msg, 'body'=>$retval);
56 }
57 ?>