• R/O
  • HTTP
  • SSH
  • HTTPS

pukiwiki: Commit


Commit MetaInfo

Revisionce74cd7aafbd0200cab2aebd5e920181f6edb2b4 (tree)
Time2018-04-17 07:25:11
Authorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2465 img plugin: +Inline style, Show image of any extention

Change Summary

Incremental Difference

--- a/plugin/img.inc.php
+++ b/plugin/img.inc.php
@@ -1,45 +1,99 @@
11 <?php
22 // PukiWiki - Yet another WikiWikiWeb clone.
3-// $Id: img.inc.php,v 1.15 2007/04/08 10:22:18 henoheno Exp $
4-// Copyright (C) 2002-2005, 2007 PukiWiki Developers Team
3+// img.inc.php
4+// Copyright 2002-2018 PukiWiki Development Team
55 // License: GPL v2 or (at your option) any later version
66 //
77 // Inline-image plugin (Output inline-image tag from a URI)
88
99 define('PLUGIN_IMG_USAGE', '#img(): Usage: (URI-to-image[,right[,clear]])<br />' . "\n");
1010 define('PLUGIN_IMG_CLEAR', '<div style="clear:both"></div>' . "\n"); // Stop word-wrapping
11+if (defined('PKWK_DISABLE_INLINE_IMAGE_FROM_URI') && PKWK_DISABLE_INLINE_IMAGE_FROM_URI) {
12+ define('PLUGIN_IMG_SHOW_IMAGE', 0); // 1: Show image, 0: Don't show image
13+} else {
14+ define('PLUGIN_IMG_SHOW_IMAGE', 1); // 1: Show image, 0: Don't show image
15+}
1116
12-function plugin_img_convert()
17+function plugin_img_get_style($args)
1318 {
14- if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI)
15- return '#img(): PKWK_DISABLE_INLINE_IMAGE_FROM_URI prohibits this' .
16- '<br />' . "\n";
19+ $style = '';
20+ for ($i = 1; $i <= 3; $i++) {
21+ if (isset($args[$i])) {
22+ $arg = $args[$i];
23+ $m = null;
24+ if (preg_match('#^(\d+)x(\d+)$#', $arg, $m)) {
25+ $style = 'max-width:' . $m[1] . 'px;max-height:' . $m[2] . 'px;';
26+ break;
27+ } else if (preg_match('#^(\d+)px$#', $arg, $m)) {
28+ $style = 'max-width:' . $m[1] . 'px;max-height:' . $m[1] . 'px;';
29+ break;
30+ } else if (preg_match('#^(\d+)%$#', $arg, $m)) {
31+ // Note: zoom is not standard. Recommend using MAXpx or WIDTHxHEIGHT
32+ $style = 'zoom:' . $m[1] . '%;';
33+ break;
34+ }
35+ }
36+ }
37+ return $style;
38+}
1739
40+function plugin_img_inline()
41+{
1842 $args = func_get_args();
43+ $url = isset($args[0]) ? $args[0] : '';
44+ if (!PLUGIN_IMG_SHOW_IMAGE) {
45+ if (is_url($url)) {
46+ $h_url = htmlsc($url);
47+ $title = '#img(): PLUGIN_IMG_SHOW_IMAGE prohibits this';
48+ return "<a href=\"$h_url\" title=\"$title\">$h_url</a>";
49+ }
50+ return '&amp;img(): PLUGIN_IMG_SHOW_IMAGE prohibits this' . "\n";
51+ }
52+ $size = isset($args[2]) ? strtolower($args[2]) : '';
53+ if (is_url($url)) {
54+ $h_url = htmlsc($url);
55+ $style = plugin_img_get_style($args);
56+ return <<<EOD
57+<img class="plugin-img-inline" src="$h_url" style="$style" alt="" />
58+EOD;
59+ }
60+}
1961
62+function plugin_img_convert()
63+{
64+ $args = func_get_args();
65+ $url = isset($args[0]) ? $args[0] : '';
66+ $h_url = htmlsc($url);
67+ if (!PLUGIN_IMG_SHOW_IMAGE) {
68+ if (is_url($url)) {
69+ $title = '#img(): PLUGIN_IMG_SHOW_IMAGE prohibits this';
70+ return "<div><a href=\"$h_url\" title=\"$title\">$h_url</a></div>";
71+ }
72+ return '#img(): PLUGIN_IMG_SHOW_IMAGE prohibits this' .
73+ '<br />' . "\n";
74+ }
2075 // Check the 2nd argument first, for compatibility
2176 $arg = isset($args[1]) ? strtoupper($args[1]) : '';
2277 if ($arg == '' || $arg == 'L' || $arg == 'LEFT') {
2378 $align = 'left';
2479 } else if ($arg == 'R' || $arg == 'RIGHT') {
2580 $align = 'right';
26- } else {
81+ } else if ($url === '' && $arg == 'CLEAR') {
2782 // Stop word-wrapping only (Ugly but compatible)
2883 // Short usage: #img(,clear)
2984 return PLUGIN_IMG_CLEAR;
3085 }
31-
3286 $url = isset($args[0]) ? $args[0] : '';
33- if (! is_url($url) || ! preg_match('/\.(jpe?g|gif|png)$/i', $url))
87+ if (! is_url($url)) {
3488 return PLUGIN_IMG_USAGE;
35-
89+ }
90+ $h_url = htmlsc($url);
3691 $arg = isset($args[2]) ? strtoupper($args[2]) : '';
3792 $clear = ($arg == 'C' || $arg == 'CLEAR') ? PLUGIN_IMG_CLEAR : '';
38-
93+ $style = plugin_img_get_style($args);
3994 return <<<EOD
40-<div style="float:$align;padding:.5em 1.5em .5em 1.5em">
41- <img src="$url" alt="" />
95+<div style="float:$align;padding:.5em 1.5em .5em 1.5em;">
96+ <img class="plugin-img-block" src="$h_url" style="$style" alt="" />
4297 </div>$clear
4398 EOD;
4499 }
45-?>
Show on old repository browser