OSDN Git Service

BugTrack2/55: Added two functions.
[pukiwiki/pukiwiki.git] / plugin / img.inc.php
1 <?php
2 // 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
5 // License: GPL v2 or (at your option) any later version
6 //
7 // Inline-image plugin (Output inline-image tag from a URI)
8
9 define('PLUGIN_IMG_USAGE', '#img(): Usage: (URI-to-image[,right[,clear]])<br />' . "\n");
10 define('PLUGIN_IMG_CLEAR', '<div style="clear:both"></div>' . "\n"); // Stop word-wrapping
11
12 function plugin_img_convert()
13 {
14         if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI)
15                 return '#img(): PKWK_DISABLE_INLINE_IMAGE_FROM_URI prohibits this' .
16                         '<br />' . "\n";
17
18         $args = func_get_args();
19
20         // Check the 2nd argument first, for compatibility
21         $arg = isset($args[1]) ? strtoupper($args[1]) : '';
22         if ($arg == '' || $arg == 'L' || $arg == 'LEFT') {
23                 $align = 'left';
24         } else if ($arg == 'R' || $arg == 'RIGHT') {
25                 $align = 'right';
26         } else {
27                 // Stop word-wrapping only (Ugly but compatible)
28                 // Short usage: #img(,clear)
29                 return PLUGIN_IMG_CLEAR;
30         }
31
32         $url = isset($args[0]) ? $args[0] : '';
33         if (! is_url($url) || ! preg_match('/\.(jpe?g|gif|png)$/i', $url))
34                 return PLUGIN_IMG_USAGE;
35
36         $arg = isset($args[2]) ? strtoupper($args[2]) : '';
37         $clear = ($arg == 'C' || $arg == 'CLEAR') ? PLUGIN_IMG_CLEAR : '';
38
39         return <<<EOD
40 <div style="float:$align;padding:.5em 1.5em .5em 1.5em">
41  <img src="$url" alt="" />
42 </div>$clear
43 EOD;
44 }
45 ?>