OSDN Git Service

BugTrack/791: Fix typo 0,91 => 0.91
[pukiwiki/pukiwiki.git] / plugin / related.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: related.inc.php,v 1.3 2005/01/15 14:25:58 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         if (! empty($data)) {
26                 // Hide by array keys (not values)
27                 $non_list_pattern = '/' . $non_list . '/';
28                 foreach(array_keys($data) as $page)
29                         if ($page == $whatsnew ||
30                             preg_match($non_list_pattern, $page))
31                                 unset($data[$page]);
32         }
33
34         // Result
35         $s_word = htmlspecialchars($_page);
36         $msg = 'Backlinks for: ' . $s_word;
37         $retval  = '<a href="' . $script . '?' . $s_word . '">' .
38                 'Return ' . $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 ?>