OSDN Git Service

BugTrack/2426 topicpath plugin - Use CSS layout for slashes
[pukiwiki/pukiwiki.git] / plugin / related.inc.php
index 19b271a..9b56ca4 100644 (file)
@@ -1,52 +1,58 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: related.inc.php,v 1.1 2005/01/12 14:02:05 henoheno Exp $
+// $Id: related.inc.php,v 1.11 2011/01/25 15:01:01 henoheno Exp $
+// Copyright (C) 2005, 2007 PukiWiki Developers Team
+// License: GPL v2 or (at your option) any later version
 //
 // Related plugin: Show Backlinks for the page
 
-// TODO: move '#related' here
-//function plugin_related_convert()
-//{
-//     global $related_link;
-//     $related_link = 0;
-//     // Do
-//}
+function plugin_related_convert()
+{
+       global $vars;
+
+       return make_related($vars['page'], 'p');
+}
 
 // Show Backlinks: via related caches for the page
 function plugin_related_action()
 {
-       global $vars, $script, $non_list, $defaultpage, $whatsnew;
+       global $vars, $script, $defaultpage, $whatsnew;
 
        $_page = isset($vars['page']) ? $vars['page'] : '';
        if ($_page == '') $_page = $defaultpage;
 
        // Get related from cache
        $data = links_get_related_db($_page);
-       $non_list_pattern = '/' . $non_list . '/';
-       foreach(array_keys($data) as $page)
-               if ($page == $whatsnew || preg_match($non_list_pattern, $page))
-                       unset($data[$page]);
+       if (! empty($data)) {
+               // Hide by array keys (not values)
+               foreach(array_keys($data) as $page)
+                       if ($page == $whatsnew ||
+                           check_non_list($page))
+                               unset($data[$page]);
+       }
 
        // Result
-       $s_word = htmlspecialchars($_page);
-       $msg = '<a href="' . $script . '?' . $s_word . '">' .
-               'Backlinks for: ' . $s_word . '</a>';
+       $r_word = pagename_urlencode($_page);
+       $s_word = htmlsc($_page);
+       $msg = 'Backlinks for: ' . $s_word;
+       $retval  = '<a href="' . $script . '?' . $r_word . '">' .
+               'Return to ' . $s_word .'</a><br />'. "\n";
 
        if (empty($data)) {
-               return array('msg'=>$msg, 'body'=>'No related pages found.');
+               $retval .= '<ul><li>No related pages found.</li></ul>' . "\n";  
        } else {
                // Show count($data)?
-               ksort($data);
-               $retval = '<ul>' . "\n";
+               ksort($data, SORT_STRING);
+               $retval .= '<ul>' . "\n";
                foreach ($data as $page=>$time) {
-                       $r_page  = rawurlencode($page);
-                       $s_page  = htmlspecialchars($page);
+                       $r_page  = pagename_urlencode($page);
+                       $s_page  = htmlsc($page);
                        $passage = get_passage($time);
                        $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page .
                                '</a> ' . $passage . '</li>' . "\n";
                }
                $retval .= '</ul>' . "\n";
-               return array('msg'=>$msg, 'body'=>$retval);
        }
+       return array('msg'=>$msg, 'body'=>$retval);
 }
-?>
+