OSDN Git Service

BugTrack/585: Added anchor_explode() into lib/html.php and plugin_edit_inline() into...
authorhenoheno <henoheno>
Sat, 20 Nov 2004 04:32:49 +0000 (13:32 +0900)
committerhenoheno <henoheno>
Sat, 20 Nov 2004 04:32:49 +0000 (13:32 +0900)
lib/html.php
plugin/edit.inc.php

index d251ac6..57af7fe 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: html.php,v 1.13 2004/11/07 13:09:37 henoheno Exp $
+// $Id: html.php,v 1.14 2004/11/20 04:32:49 henoheno Exp $
 //
 
 // ËÜʸ¤ò½ÐÎÏ
@@ -351,4 +351,27 @@ function make_heading(& $str, $strip = TRUE)
 
        return $id;
 }
+
+// Separate a page-name(or URL or null string) and an anchor
+// (last one standing) without sharp
+function anchor_explode($page, $strict_editable = FALSE)
+{
+       $pos = strrpos($page, '#');
+       if ($pos === FALSE) return array($page, '', FALSE);
+
+       // Ignore the last sharp letter
+       if ($pos + 1 == strlen($page)) {
+               $pos = strpos(substr($page, $pos + 1), '#');
+               if ($pos === FALSE) return array($page, '', FALSE);
+       }
+
+       $s_page = substr($page, 0, $pos);
+       $anchor = substr($page, $pos + 1);
+
+       if($strict_editable === TRUE &&  preg_match('/^[a-z][a-f0-9]{7}$/', $anchor)) {
+               return array ($s_page, $anchor, TRUE); // Seems fixed-anchor
+       } else {
+               return array ($s_page, $anchor, FALSE);
+       }
+}
 ?>
index 61daece..ad067f6 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: edit.inc.php,v 1.19 2004/10/11 02:05:12 henoheno Exp $
+// $Id: edit.inc.php,v 1.20 2004/11/20 04:32:49 henoheno Exp $
 //
 
 // Edit plugin
@@ -76,6 +76,89 @@ function plugin_edit_preview()
        return array('msg'=>$_title_preview, 'body'=>$body);
 }
 
+// Inline: Show edit (or unfreeze text) link
+function plugin_edit_inline()
+{
+       static $usage = '&edit(pagename#anchor[[,noicon],nolabel])[{label}];';
+
+       global $script, $vars;
+       global $_symbol_paraedit, $fixed_heading_anchor_edit;
+
+       // Arguments
+       $args = func_get_args();
+       $s_label = array_pop($args); // {label}
+       $page    = array_shift($args);
+       if($page == NULL) $page = '';
+       $_noicon = $_nolabel = FALSE;
+       foreach($args as $arg){
+               switch($arg){
+               case '': break;
+               case 'noicon':  $_noicon  = TRUE; break;
+               case 'nolabel': $_nolabel = TRUE; break;
+               default: return $usage;
+               }
+       }
+
+       // Separate a page-name and a fixed anchor
+       list($s_page, $id, $editable) = anchor_explode($page, TRUE);
+       // Default: This one
+       if ($s_page == '') $s_page = isset($vars['page']) ? $vars['page'] : '';
+       // $s_page fixed
+       $isfreeze = is_freeze($s_page);
+
+       // Paragraph edit or not
+       $short = htmlspecialchars('Edit');
+       if ($fixed_heading_anchor_edit && $editable === TRUE) {
+               $title = htmlspecialchars(sprintf('Edit %s', $page));
+               $id    = rawurlencode($id);
+               $icon = '<img src="' . IMAGE_DIR . 'paraedit.png' .
+                       '" width="9" height="9" alt="' .
+                       $short . '" title="' . $title . '" /> ';
+               $class = 'anchor_super';
+       } else {
+               $title = htmlspecialchars(sprintf('Edit %s', $s_page));
+               $id    = '';
+               $icon = '<img src="' . IMAGE_DIR . 'edit.png' .
+                       '" width="20" height="20" alt="' .
+                       $short . '" title="' . $title . '" />';
+               $class = '';
+       }
+       if ($_noicon || $isfreeze) $icon = ''; // No more icon
+       if ($_nolabel) {
+               if (!$_noicon) {
+                       $s_label = '';     // No label with an icon
+               } else {
+                       $s_label = $short; // Short label without an icon
+               }
+       } else {
+               if ($s_label == '') $s_label = $title; // Rich label with an icon
+       }
+
+       // Anchor tag
+       if ($isfreeze) {
+               $title = htmlspecialchars(sprintf('Unfreeze %s', $page));
+               $url   = $script . '?cmd=unfreeze&amp;page=' . rawurlencode($s_page);
+       } else {
+               if ($id != '') {
+                       $s_id = '&amp;id=' . $id;
+               } else {
+                       $s_id = '';
+               }
+               $url  = $script . '?cmd=edit&amp;page=' . rawurlencode($s_page) . $s_id;
+       }
+       $atag  = '<a class="' . $class . '" href="' . $url . '" title="' . $title . '">';
+       static $atags = '</a>';
+
+       if (is_page($s_page)) {
+               // Normal edit link
+               return $atag . $icon . $s_label . $atags;
+       } else {
+               // Dangling edit link
+               return $atag . $icon . $atags . '<span class="noexists">' .
+                       $s_label . $atag . '?' . $atags . '</span>';
+       }
+}
+
 // Write, add, or insert new comment
 function plugin_edit_write()
 {