2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: include.inc.php,v 1.21 2004/12/30 13:26:43 henoheno Exp $
10 // | // #include(PageB)
14 // | // #include(PageC)
18 // --------- // PageC end
20 // | // #include(PageD)
24 // --------- // PageD end
26 // --------- // PageB end
28 // | #include(): Included already: PageC
30 // | // #include(PageE)
34 // --------- // PageE end
36 // | #include(): Limit exceeded: PageF
37 // | // When PLUGIN_INCLUDE_MAX == 4
40 //-------- // PageA end
44 // Default value of 'title|notitle' option
45 define('PLUGIN_INCLUDE_WITH_TITLE', TRUE); // Default: TRUE(title)
47 // Max pages allowed to be included at a time
48 define('PLUGIN_INCLUDE_MAX', 4);
51 define('PLUGIN_INCLUDE_USAGE', '#include(): Usage: (a-page-name-you-want-to-include[,title|,notitle])');
53 function plugin_include_convert()
55 global $script, $vars, $get, $post, $menubar, $_msg_include_restrict;
56 static $included = array();
59 if (func_num_args() == 0) return PLUGIN_INCLUDE_USAGE . '<br />' . "\n";;
61 // $menubar will already be shown via menu plugin
62 if (! isset($included[$menubar])) $included[$menubar] = TRUE;
65 $root = isset($vars['page']) ? $vars['page'] : '';
66 $included[$root] = TRUE;
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;
80 $s_page = htmlspecialchars($page);
81 $r_page = rawurlencode($page);
82 $link = '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>'; // Read link
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";
95 // One page, only one time, at a time
96 $included[$page] = TRUE;
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));
103 $body = str_replace('$1', $page, $_msg_include_restrict);
105 $get['page'] = $post['page'] = $vars['page'] = $root;
107 // Put a title-with-edit-link, before including document
109 $link = '<a href="' . $script . '?cmd=edit&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>';
115 $body = '<h1>' . $link . '</h1>' . "\n" . $body . "\n";