OSDN Git Service

Added related-action plugin for backlinks, instead of search via GET method
[pukiwiki/pukiwiki.git] / plugin / related.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: related.inc.php,v 1.1 2005/01/12 14:02:05 henoheno Exp $
4 //
5 // Related plugin: Show Backlinks for the page
6
7 // TODO: move '#related' here
8 //function plugin_related_convert()
9 //{
10 //      global $related_link;
11 //      $related_link = 0;
12 //      // Do
13 //}
14
15 // Show Backlinks: via related caches for the page
16 function plugin_related_action()
17 {
18         global $vars, $script, $non_list, $defaultpage, $whatsnew;
19
20         $_page = isset($vars['page']) ? $vars['page'] : '';
21         if ($_page == '') $_page = $defaultpage;
22
23         // Get related from cache
24         $data = links_get_related_db($_page);
25         $non_list_pattern = '/' . $non_list . '/';
26         foreach(array_keys($data) as $page)
27                 if ($page == $whatsnew || preg_match($non_list_pattern, $page))
28                         unset($data[$page]);
29
30         // Result
31         $s_word = htmlspecialchars($_page);
32         $msg = '<a href="' . $script . '?' . $s_word . '">' .
33                 'Backlinks for: ' . $s_word . '</a>';
34
35         if (empty($data)) {
36                 return array('msg'=>$msg, 'body'=>'No related pages found.');
37         } else {
38                 // Show count($data)?
39                 ksort($data);
40                 $retval = '<ul>' . "\n";
41                 foreach ($data as $page=>$time) {
42                         $r_page  = rawurlencode($page);
43                         $s_page  = htmlspecialchars($page);
44                         $passage = get_passage($time);
45                         $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page .
46                                 '</a> ' . $passage . '</li>' . "\n";
47                 }
48                 $retval .= '</ul>' . "\n";
49                 return array('msg'=>$msg, 'body'=>$retval);
50         }
51 }
52 ?>