]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/FrameInclude.php
New FSF address
[SourceForge/phpwiki.git] / lib / plugin / FrameInclude.php
1 <?php // -*-php-*-
2 // $Id$
3 /*
4  * Copyright 2002 $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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /**
24  * FrameInclude:  Displays a url or page in a seperate frame inside our body.
25  *
26  * Usage:
27  *  <<FrameInclude src=http://www.internet-technology.de/fourwins_de.htm >>
28  *  <<FrameInclude page=OtherPage >>
29  *  at the VERY BEGINNING in the content!
30  *
31  * Author:  Reini Urban <rurban@x-ray.at>, rewrite by Jeff Dairiki <dairiki@dairiki.org>
32  *
33  * KNOWN ISSUES:
34  *
35  * This is a dirty hack into the whole system. To display the page as
36  * frameset we:
37  *
38  *  1. Discard any output buffered so far.
39  *  2. Recursively call displayPage with magic arguments to generate
40  *     the frameset (or individual frame contents.)
41  *  3. Exit early.  (So this plugin is usually a no-return.)
42  *
43  *  In any cases we can now serve only specific templates with the new
44  *  frame argument. The whole page is now ?frame=html (before it was
45  *  named "top") For the Sidebar theme (or derived from it) we provide
46  *  a left frame also, otherwise only top, content and bottom.
47  */
48 class WikiPlugin_FrameInclude
49 extends WikiPlugin
50 {
51     function getName() {
52         return _("FrameInclude");
53     }
54
55     function getDescription() {
56         return _("Displays a url in a seperate frame inside our body. Only one frame allowed.");
57     }
58
59     function getDefaultArguments() {
60         return array( 'src'         => false,       // the src url to include
61                       'page'        => false,
62                       'name'        => 'content',   // name of our frame
63                       'title'       => false,
64                       'rows'        => '18%,*,15%', // names: top, $name, bottom
65                       'cols'        => '20%,*',     // names: left, $name
66                                                     // only useful on WikiTheme "Sidebar"
67                       'frameborder' => 1,
68                       'marginwidth'  => false,
69                       'marginheight' => false,
70                       'noresize'    => false,
71                       'scrolling'   => 'auto',  // '[ yes | no | auto ]'
72                     );
73     }
74
75     function run($dbi, $argstr, &$request, $basepage) {
76
77         $args = ($this->getArgs($argstr, $request));
78         extract($args);
79
80         if ($request->getArg('action') != 'browse') {
81             return $this->disabled(_("Plugin not run: not in browse mode"));
82         }
83         if (! $request->isGetOrHead()) {
84             return $this->disabled("(method != 'GET')");
85         }
86
87         if (!$src and $page) {
88             if ($page == $request->get('pagename')) {
89                 return $this->error(sprintf(_("Recursive inclusion of page %s"),
90                                             $page));
91             }
92             $src = WikiURL($page);
93         }
94         if (!$src) {
95             return $this->error(sprintf(_("%s or %s parameter missing"),
96                                         'src', 'page'));
97         }
98
99         // FIXME: How to normalize url's to compare against recursion?
100         if ($src == $request->getURLtoSelf() ) {
101             return $this->error(sprintf(_("Recursive inclusion of url %s"),
102                                         $src));
103         }
104
105         static $noframes = false;
106         if ($noframes) {
107             // Content for noframes version of page.
108             return HTML::p(fmt("See %s",
109                                HTML::a(array('href' => $src), $src)));
110         }
111         $noframes = true;
112
113         if (($which = $request->getArg('frame'))) {
114             // Generate specialized frame output (header, footer, etc...)
115             $request->discardOutput();
116             displayPage($request, new Template("frame-$which", $request));
117             $request->finish(); //noreturn
118         }
119
120         // Generate the outer frameset
121         $frame = HTML::frame(array('name' => $name,
122                                    'src' => $src,
123                                    'title' => $title,
124                                    'frameborder' => (int)$frameborder,
125                                    'scrolling' => (string)$scrolling,
126                                    'noresize' => (bool)$noresize,
127                                    ));
128
129         if ($marginwidth)
130             $frame->setArg('marginwidth', $marginwidth);
131         if ($marginheight)
132             $frame->setArg('marginheight', $marginheight);
133
134         $tokens = array('CONTENT_FRAME' => $frame,
135                         'ROWS' => $rows,
136                         'COLS' => $cols,
137                         'FRAMEARGS' => sprintf('frameborder="%d"', $frameborder),
138                         );
139
140         // Produce the frameset.
141         $request->discardOutput();
142         displayPage($request, new Template('frameset', $request, $tokens));
143         $request->finish(); //noreturn
144     }
145 };
146
147 // Local Variables:
148 // mode: php
149 // tab-width: 8
150 // c-basic-offset: 4
151 // c-hanging-comment-ender-p: nil
152 // indent-tabs-mode: nil
153 // End:
154 ?>