OSDN Git Service

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