OSDN Git Service

f49cd91ccdb4168a55e1e19192c0870fc54e3e2a
[pukiwiki/pukiwiki.git] / plugin / include.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: include.inc.php,v 1.21 2004/12/30 13:26:43 henoheno Exp $
4 //
5 // Include-once plugin
6
7 //--------
8 //      | PageA
9 //      |
10 //      | // #include(PageB)
11 //      ---------
12 //              | PageB
13 //              |
14 //              | // #include(PageC)
15 //              ---------
16 //                      | PageC
17 //                      |
18 //              --------- // PageC end
19 //              |
20 //              | // #include(PageD)
21 //              ---------
22 //                      | PageD
23 //                      |
24 //              --------- // PageD end
25 //              |
26 //      --------- // PageB end
27 //      |
28 //      | #include(): Included already: PageC
29 //      |
30 //      | // #include(PageE)
31 //      ---------
32 //              | PageE
33 //              |
34 //      --------- // PageE end
35 //      |
36 //      | #include(): Limit exceeded: PageF
37 //      | // When PLUGIN_INCLUDE_MAX == 4
38 //      |
39 //      |
40 //-------- // PageA end
41
42 // ----
43
44 // Default value of 'title|notitle' option
45 define('PLUGIN_INCLUDE_WITH_TITLE', TRUE);      // Default: TRUE(title)
46
47 // Max pages allowed to be included at a time
48 define('PLUGIN_INCLUDE_MAX', 4);
49
50 // ----
51 define('PLUGIN_INCLUDE_USAGE', '#include(): Usage: (a-page-name-you-want-to-include[,title|,notitle])');
52
53 function plugin_include_convert()
54 {
55         global $script, $vars, $get, $post, $menubar, $_msg_include_restrict;
56         static $included = array();
57         static $count = 1;
58
59         if (func_num_args() == 0) return PLUGIN_INCLUDE_USAGE . '<br />' . "\n";;
60
61         // $menubar will already be shown via menu plugin
62         if (! isset($included[$menubar])) $included[$menubar] = TRUE;
63
64         // Loop yourself
65         $root = isset($vars['page']) ? $vars['page'] : '';
66         $included[$root] = TRUE;
67
68         // Get arguments
69         $args = func_get_args();
70         // strip_bracket() is not necessary but compatible
71         $page = isset($args[0]) ? get_fullname(strip_bracket(array_shift($args)), $root) : '';
72         $with_title = PLUGIN_INCLUDE_WITH_TITLE;
73         if (isset($args[0])) {
74                 switch(strtolower(array_shift($args))) {
75                 case 'title'  : $with_title = TRUE;  break;
76                 case 'notitle': $with_title = FALSE; break;
77                 }
78         }
79
80         $s_page = htmlspecialchars($page);
81         $r_page = rawurlencode($page);
82         $link = '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>'; // Read link
83
84         // I'm stuffed
85         if (isset($included[$page])) {
86                 return '#include(): Included already: ' . $link . '<br />' . "\n";
87         } if (! is_page($page)) {
88                 return '#include(): No such page: ' . $s_page . '<br />' . "\n";
89         } if ($count > PLUGIN_INCLUDE_MAX) {
90                 return '#include(): Limit exceeded: ' . $link . '<br />' . "\n";
91         } else {
92                 ++$count;
93         }
94
95         // One page, only one time, at a time
96         $included[$page] = TRUE;
97
98         // Include A page, that probably includes another pages
99         $get['page'] = $post['page'] = $vars['page'] = $page;
100         if (check_readable($page, false, false)) {
101                 $body = convert_html(get_source($page));
102         } else {
103                 $body = str_replace('$1', $page, $_msg_include_restrict);
104         }
105         $get['page'] = $post['page'] = $vars['page'] = $root;
106
107         // Put a title-with-edit-link, before including document
108         if ($with_title) {
109                 $link = '<a href="' . $script . '?cmd=edit&amp;page=' . $r_page .
110                         '">' . $s_page . '</a>';
111                 if ($page == $menubar) {
112                         $body = '<span align="center"><h5 class="side_label">' .
113                                 $link . '</h5></span><small>' . $body . '</small>';
114                 } else {
115                         $body = '<h1>' . $link . '</h1>' . "\n" . $body . "\n";
116                 }
117         }
118
119         return $body;
120 }
121 ?>