]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/FrameInclude.php
Add missing return
[SourceForge/phpwiki.git] / lib / plugin / FrameInclude.php
1 <?php
2
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:  Display a url or page in a separate 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     {
53         return _("FrameInclude");
54     }
55
56     function getDescription()
57     {
58         return _("Display a url in a separate frame inside our body. Only one frame allowed.");
59     }
60
61     function getDefaultArguments()
62     {
63         return array('src' => false, // the src url to include
64             'page' => false,
65             'name' => 'content', // name of our frame
66             'title' => false,
67             'rows' => '18%,*,15%', // names: top, $name, bottom
68             'cols' => '20%,*', // names: left, $name
69             // only useful on WikiTheme "Sidebar"
70             'frameborder' => 1,
71             'marginwidth' => false,
72             'marginheight' => false,
73             'noresize' => false,
74             'scrolling' => 'auto', // '[ yes | no | auto ]'
75         );
76     }
77
78     function run($dbi, $argstr, &$request, $basepage)
79     {
80
81         $args = ($this->getArgs($argstr, $request));
82         extract($args);
83
84         if ($request->getArg('action') != 'browse') {
85             return $this->disabled(_("Plugin not run: not in browse mode"));
86         }
87         if (!$request->isGetOrHead()) {
88             return $this->disabled("(method != 'GET')");
89         }
90
91         if (!$src and $page) {
92             if ($page == $request->get('pagename')) {
93                 return $this->error(sprintf(_("Recursive inclusion of page %s"),
94                     $page));
95             }
96             $src = WikiURL($page);
97         }
98         if (!$src) {
99             return $this->error(sprintf(_("%s or %s parameter missing"),
100                 'src', 'page'));
101         }
102
103         // FIXME: How to normalize url's to compare against recursion?
104         if ($src == $request->getURLtoSelf()) {
105             return $this->error(sprintf(_("Recursive inclusion of url %s"),
106                 $src));
107         }
108
109         static $noframes = false;
110         if ($noframes) {
111             // Content for noframes version of page.
112             return HTML::p(fmt("See %s",
113                 HTML::a(array('href' => $src), $src)));
114         }
115         $noframes = true;
116
117         if (($which = $request->getArg('frame'))) {
118             // Generate specialized frame output (header, footer, etc...)
119             $request->discardOutput();
120             displayPage($request, new Template("frame-$which", $request));
121             $request->finish(); //noreturn
122         }
123
124         // Generate the outer frameset
125         $frame = HTML::frame(array('name' => $name,
126             'src' => $src,
127             'title' => $title,
128             'frameborder' => (int)$frameborder,
129             'scrolling' => (string)$scrolling,
130             'noresize' => (bool)$noresize,
131         ));
132
133         if ($marginwidth)
134             $frame->setArg('marginwidth', $marginwidth);
135         if ($marginheight)
136             $frame->setArg('marginheight', $marginheight);
137
138         $tokens = array('CONTENT_FRAME' => $frame,
139             'ROWS' => $rows,
140             'COLS' => $cols,
141             'FRAMEARGS' => sprintf('frameborder="%d"', $frameborder),
142         );
143
144         // Produce the frameset.
145         $request->discardOutput();
146         displayPage($request, new Template('frameset', $request, $tokens));
147         $request->finish(); //noreturn
148         return '';
149     }
150 }
151
152 // Local Variables:
153 // mode: php
154 // tab-width: 8
155 // c-basic-offset: 4
156 // c-hanging-comment-ender-p: nil
157 // indent-tabs-mode: nil
158 // End: