2 // PukiWiki - Yet another WikiWikiWeb clone.
4 // Copyright 2002-2017 PukiWiki Development Team
5 // License: GPL v2 or (at your option) any later version
12 // | // #include(PageB)
16 // | // #include(PageC)
20 // --------- // PageC end
22 // | // #include(PageD)
26 // --------- // PageD end
28 // --------- // PageB end
30 // | #include(): Included already: PageC
32 // | // #include(PageE)
36 // --------- // PageE end
38 // | #include(): Limit exceeded: PageF
39 // | // When PLUGIN_INCLUDE_MAX == 4
42 //-------- // PageA end
46 // Default value of 'title|notitle' option
47 define('PLUGIN_INCLUDE_WITH_TITLE', TRUE); // Default: TRUE(title)
49 // Max pages allowed to be included at a time
50 define('PLUGIN_INCLUDE_MAX', 4);
53 define('PLUGIN_INCLUDE_USAGE', '#include(): Usage: (a-page-name-you-want-to-include[,title|,notitle])');
55 function plugin_include_convert()
57 global $vars, $get, $post, $menubar, $_msg_include_restrict;
58 static $included = array();
61 $script = get_base_uri();
62 if (func_num_args() == 0) return PLUGIN_INCLUDE_USAGE . '<br />' . "\n";;
64 // $menubar will already be shown via menu plugin
65 if (! isset($included[$menubar])) $included[$menubar] = TRUE;
68 $root = isset($vars['page']) ? $vars['page'] : '';
69 $included[$root] = TRUE;
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;
83 $s_page = htmlsc($page);
84 $r_page = pagename_urlencode($page);
85 $link = '<a href="' . get_page_uri($page) . '">' . $s_page . '</a>'; // Read link
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";
98 // One page, only one time, at a time
99 $included[$page] = TRUE;
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));
106 $body = str_replace('$1', $page, $_msg_include_restrict);
108 $get['page'] = $post['page'] = $vars['page'] = $root;
110 // Put a title-with-edit-link, before including document
112 $link = '<a href="' . $script . '?cmd=edit&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>';
118 $body = '<h1>' . $link . '</h1>' . "\n" . $body . "\n";