OSDN Git Service

BugTrack/664 Should replace #img(,clear) => #clear
[pukiwiki/pukiwiki.git] / plugin / include.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: include.inc.php,v 1.16 2004/08/19 11:36:08 henoheno Exp $
6 //
7
8 define('INCLUDE_MAX', 4); // °ìÅ٤˥¤¥ó¥¯¥ë¡¼¥É¤Ç¤­¤ë¥Ú¡¼¥¸¤ÎºÇÂç¿ô
9
10 // ¥Ú¡¼¥¸¤ò(²Äǽ¤Ê¤é¤ÐºÆµ¢Åª¤Ë)¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë
11 function plugin_include_convert()
12 {
13         global $script, $vars, $get, $post, $menubar, $_msg_include_restrict;
14         static $included = array();
15         static $count = 1;
16         $usage = "#include(): Usage: (a-page-name-you-want-to-include)<br />\n";
17
18         if (func_num_args() == 0) return $usage;
19
20         // Get an argument
21         list($page) = func_get_args();
22         $page = strip_bracket($page);
23         $s_page = htmlspecialchars($page);
24         $r_page = rawurlencode($page);
25         $link = "<a href=\"$script?$r_page\">$s_page</a>"; // Read link
26
27         // Loop yourself
28         $root = isset($vars['page']) ? $vars['page'] : '';
29         $included[$root] = TRUE;
30
31         // I'm stuffed
32         if (isset($included[$page])) {
33                 return "#include(): Included already: $link<br />\n";
34         } if (! is_page($page)) {
35                 return "#include(): No such page: $s_page<br />\n";
36         } if ($count > INCLUDE_MAX) {
37                 return "#include(): Limit exceeded: $link<br />\n";
38         } else {
39                 ++$count;
40         }
41
42         // One page, only one time, at a time
43         $included[$page] = TRUE;
44
45         // Include A page, that probably includes another pages
46         $get['page'] = $post['page'] = $vars['page'] = $page;
47         if (check_readable($page, false, false)) {
48                 $body = convert_html(get_source($page));
49         } else {
50                 $body = str_replace('$1', $page, $_msg_include_restrict);
51         }
52         $get['page'] = $post['page'] = $vars['page'] = $root;
53
54         // Add a title with edit link, before included document
55         $link = "<a href=\"$script?cmd=edit&amp;page=$r_page\">$s_page</a>";
56
57         if ($page == $menubar) {
58                 $body = "<span align=\"center\"><h5 class=\"side_label\">$link</h5></span>" .
59                         "<small>$body</small>";
60         } else {
61                 $body = "<h1>$link</h1>\n" .
62                         "$body\n";
63         }
64
65         return $body;
66 }
67 ?>