]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/DynamicIncludePage.php
Remove rcs_id
[SourceForge/phpwiki.git] / lib / plugin / DynamicIncludePage.php
1 <?php // -*-php-*-
2 // $Id$
3 /*
4  * Copyright 2009 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * DynamicIncludePage - Include wikipage asynchronously. Icon to show/hide.
25  * Usage:   <<DynamicIncludePage page=OtherPage state=true ...>>
26  * Author:  Reini Urban
27  */
28
29 require_once('lib/plugin/IncludePage.php');
30
31 class WikiPlugin_DynamicIncludePage
32 extends WikiPlugin_IncludePage
33 {
34     function getName() {
35         return _("DynamicIncludePage");
36     }
37
38     function getDescription() {
39         return _("Dynamically include the content from another wiki page.");
40     }
41
42     function getDefaultArguments() {
43             return array_merge
44             (WikiPlugin_IncludePage::getDefaultArguments(),
45              array(
46                    'state'   => false, // initial state: false <=> [+], true <=> [-]
47                   ));
48     }
49
50     function run($dbi, $argstr, &$request, $basepage) {
51             global $WikiTheme;
52         $args = $this->getArgs($argstr, $request, false);
53         $page =& $args['page'];
54         if (ENABLE_AJAX) {
55             if ($args['state'])
56                 $html = WikiPlugin_IncludePage::run($dbi, $argstr, $request, $basepage);
57             else
58                 $html = HTML(HTML::p(array('class' => 'transclusion-title'),
59                                  fmt(" %s :", WikiLink($page))),
60                              HTML::div(array('class' => 'transclusion'), ''));
61             $ajaxuri = WikiURL($page, array('format' => 'xml'));
62         } else {
63             $html = WikiPlugin_IncludePage::run($dbi, $argstr, $request, $basepage);
64         }
65         $header = $html->_content[0];
66         $body   = $html->_content[1];
67         $id = 'DynInc-'.MangleXmlIdentifier($page);
68         $body->setAttr('id', $id.'-body');
69         $png = $WikiTheme->_findData('images/folderArrow'.
70                                     ($args['state'] ? 'Open' : 'Closed').
71                                     '.png');
72         $icon = HTML::img(array('id'  => $id.'-img',
73                                 'src' => $png,
74                                 'onclick' => ENABLE_AJAX
75                                   ? "showHideAsync('".$ajaxuri."','$id')"
76                                   : "showHideFolder('$id')",
77                                 'alt' => _("Click to hide/show"),
78                                 'title'  => _("Click to hide/show")));
79         $header = HTML::p(array('class' => 'transclusion-title',
80                                 'style' => "text-decoration: none;"),
81                           $icon,
82                           fmt(" %s :", WikiLink($page)));
83         if ($args['state']) { // show base
84             $body->setAttr('style', 'display:block');
85             return HTML($header, $body);
86         } else { // do not show base
87             $body->setAttr('style', 'display:none');
88             if (ENABLE_AJAX)
89                 return HTML($header, $body); // async (load in background and insert)
90             else
91                 return HTML($header, $body); // sync (load but display:none)
92         }
93     }
94 };
95
96 // Local Variables:
97 // mode: php
98 // tab-width: 8
99 // c-basic-offset: 4
100 // c-hanging-comment-ender-p: nil
101 // indent-tabs-mode: nil
102 // End:
103 ?>