• R/O
  • HTTP
  • SSH
  • HTTPS

pukiwiki: Commit


Commit MetaInfo

Revisionebb80be5a3d3a15e87b3cae8fd9d1579aa56406c (tree)
Time2018-04-25 23:18:49
Authorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2467 img plugin: Show page-attached image

Change Summary

Incremental Difference

--- a/plugin/img.inc.php
+++ b/plugin/img.inc.php
@@ -52,75 +52,118 @@ function plugin_img_get_islink($args)
5252 return true;
5353 }
5454
55+/**
56+ * @param[in] $args func_get_args() of xxx_inline() and xxx_convert()
57+ * @return array(url, is_url, file_path, page, style, a_begin, a_end)
58+ */
59+function plugin_img_get_props($args)
60+{
61+ global $vars;
62+ $is_file = false;
63+ $is_url = false;
64+ $file_path = isset($args[0]) ? $args[0] : '';
65+ $page = isset($vars['page']) ? $vars['page'] : '';
66+ if (is_url($file_path)) {
67+ $url = $file_path;
68+ $is_url = true;
69+ } else if (isset($file_path)) {
70+ // $file_path s not an URL. It should be attached-file path
71+ $matches = null;
72+ if (preg_match('#^(.+)/([^/]+)$#', $file_path, $matches)) {
73+ // (Page_name/maybe-separated-with/slashes/ATTACHED_FILENAME)
74+ if ($matches[1] == '.' || $matches[1] == '..') {
75+ $matches[1] .= '/'; // Restore relative paths
76+ }
77+ $attach_name = $matches[2];
78+ $attach_page = get_fullname($matches[1], $page);
79+ } else {
80+ // Simple single argument
81+ $attach_name = $file_path;
82+ $attach_page = $page;
83+ }
84+ $file = UPLOAD_DIR . encode($attach_page) . '_' . encode($attach_name);
85+ $is_file = is_file($file);
86+ if ($is_file) {
87+ $url = get_base_uri() . '?plugin=attach' .
88+ '&refer=' . rawurlencode($attach_page) .
89+ '&openfile=' . rawurlencode($attach_name);
90+ $is_url = true;
91+ }
92+ }
93+ $h_url = htmlsc($url);
94+ $style = plugin_img_get_style($args);
95+ $a_begin = '';
96+ $a_end = '';
97+ if (plugin_img_get_islink($args)) {
98+ $a_begin = "<a href=\"$h_url\" class=\"image-link\">";
99+ $a_end = '</a>';
100+ }
101+ return (object)array('url' => $url, 'is_url' => $is_url,
102+ 'file_path' => $file_path, 'is_file' => $is_file,
103+ 'style' => $style,
104+ 'a_begin' => $a_begin, 'a_end' => $a_end,);
105+}
106+
55107 function plugin_img_inline()
56108 {
57109 $args = func_get_args();
58- $url = isset($args[0]) ? $args[0] : '';
110+ $p = plugin_img_get_props($args);
59111 if (!PLUGIN_IMG_SHOW_IMAGE) {
60- if (is_url($url)) {
61- $h_url = htmlsc($url);
62- $title = '#img(): PLUGIN_IMG_SHOW_IMAGE prohibits this';
112+ if ($p->is_url) {
113+ $h_url = htmlsc($p->url);
114+ $title = '&amp;img(): PLUGIN_IMG_SHOW_IMAGE prohibits this';
63115 return "<a href=\"$h_url\" title=\"$title\">$h_url</a>";
64116 }
65- return '&amp;img(): PLUGIN_IMG_SHOW_IMAGE prohibits this' . "\n";
117+ return '&amp;img(): File not found: ' . htmlsc($p->file_path) . "\n";
66118 }
67- $size = isset($args[2]) ? strtolower($args[2]) : '';
68- if (is_url($url)) {
69- $h_url = htmlsc($url);
70- $style = plugin_img_get_style($args);
71- $a_begin = '';
72- $a_end = '';
73- if (plugin_img_get_islink($args)) {
74- $a_begin = "<a href=\"$h_url\" class=\"image-link\">";
75- $a_end = '</a>';
76- }
119+ if ($p->is_url) {
120+ $h_url = htmlsc($p->url);
121+ $style = $p->style;
122+ $a_begin = $p->a_begin;
123+ $a_end = $p->a_end;
77124 return <<<EOD
78125 $a_begin<img class="plugin-img-inline" src="$h_url" style="$style" alt="" />$a_end
79126 EOD;
80127 }
128+ return '&amp;img(): File not found: ' . htmlsc($p->file_path) . "\n";
81129 }
82130
83131 function plugin_img_convert()
84132 {
85133 $args = func_get_args();
86- $url = isset($args[0]) ? $args[0] : '';
87- $h_url = htmlsc($url);
88- if (!PLUGIN_IMG_SHOW_IMAGE) {
89- if (is_url($url)) {
90- $title = '#img(): PLUGIN_IMG_SHOW_IMAGE prohibits this';
91- return "<div><a href=\"$h_url\" title=\"$title\">$h_url</a></div>";
92- }
93- return '#img(): PLUGIN_IMG_SHOW_IMAGE prohibits this' .
94- '<br />' . "\n";
95- }
134+ $p = plugin_img_get_props($args);
96135 // Check the 2nd argument first, for compatibility
97136 $arg = isset($args[1]) ? strtoupper($args[1]) : '';
98- if ($arg == '' || $arg == 'L' || $arg == 'LEFT') {
99- $align = 'left';
100- } else if ($arg == 'R' || $arg == 'RIGHT') {
101- $align = 'right';
102- } else if ($url === '' && $arg == 'CLEAR') {
137+ if ($a->file_path === '' && $arg == 'CLEAR') {
103138 // Stop word-wrapping only (Ugly but compatible)
104139 // Short usage: #img(,clear)
105140 return PLUGIN_IMG_CLEAR;
106141 }
107- $url = isset($args[0]) ? $args[0] : '';
108- if (! is_url($url)) {
109- return PLUGIN_IMG_USAGE;
142+ if ($arg === '' || $arg === 'L' || $arg === 'LEFT') {
143+ $align = 'left';
144+ } else if ($arg === 'R' || $arg === 'RIGHT') {
145+ $align = 'right';
110146 }
111- $h_url = htmlsc($url);
112- $arg = isset($args[2]) ? strtoupper($args[2]) : '';
113- $clear = ($arg == 'C' || $arg == 'CLEAR') ? PLUGIN_IMG_CLEAR : '';
114- $style = plugin_img_get_style($args);
115- $a_begin = '';
116- $a_end = '';
117- if (plugin_img_get_islink($args)) {
118- $a_begin = "<a href=\"$h_url\" class=\"image-link\">";
119- $a_end = '</a>';
147+ $arg2 = isset($args[2]) ? strtoupper($args[2]) : '';
148+ $clear = ($arg2 === 'C' || $arg2 === 'CLEAR') ? PLUGIN_IMG_CLEAR : '';
149+ if (!PLUGIN_IMG_SHOW_IMAGE) {
150+ if ($p->is_url) {
151+ $h_url = htmlsc($p->url);
152+ $title = '#img(): PLUGIN_IMG_SHOW_IMAGE prohibits this';
153+ return "<div><a href=\"$h_url\" title=\"$title\">$h_url</a></div>";
154+ }
155+ return '#img(): File not found: ' . htmlsc($p->file_path) . "\n";
120156 }
121- return <<<EOD
157+ if ($p->is_url) {
158+ $h_url = htmlsc($p->url);
159+ $style = $p->style;
160+ $a_begin = $p->a_begin;
161+ $a_end = $p->a_end;
162+ return <<<EOD
122163 <div style="float:$align;padding:.5em 1.5em .5em 1.5em;">
123164 $a_begin<img class="plugin-img-block" src="$h_url" style="$style" alt="" />$a_end
124165 </div>$clear
125166 EOD;
167+ }
168+ return '#img(): File not found: ' . htmlsc($p->file_path) . "\n";
126169 }
Show on old repository browser