]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/FrameInclude.php
Code cleanup:
[SourceForge/phpwiki.git] / lib / plugin / FrameInclude.php
1 <?php // -*-php-*-
2 rcs_id('$Id: FrameInclude.php,v 1.6 2003-01-18 21:41:01 carstenklapp Exp $');
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
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  * FrameInclude:  Displays a url or page in a seperate frame inside our body.
25  *
26  * Usage:
27  *  <?plugin-head FrameInclude src=http://www.internet-technology.de/fourwins_de.htm ?>
28  *  <?plugin-head FrameInclude page=OtherPage ?>
29  *  at the VERY BEGINNING in the content! Otherwise it will be ignored.
30  *
31  * Author:  Reini Urban <rurban@x-ray.at>
32  *
33  * KNOWN ISSUES:
34  *
35  * This is a dirty hack into the whole system. To display the page as
36  * frameset we must know in advance about the plugin existence.
37  *
38  *  1. Check the page content for the start string '<?plugin-head '
39  *     which we currently do.
40  *
41  * 2. We can buffer the output stream (which in certain cases is not
42       doable).
43  *
44  *  3. Redirect to a new page with the frameset only. ?frameset=pagename
45  *      $request->setArg('framesrc', $src);
46  *      $request->redirect('frameset', $request->getName());
47  *
48  *  In any cases we can now serve only specific templates with the new
49  *  frame argument. The whole page is now ?frame=html (before it was
50  *  named "top") For the Sidebar theme (or derived from it) we provide
51  *  a left frame also, otherwise only top, content and bottom.
52  *
53  *  This plugin doesn't return a typical html stream inside a <body>,
54  *  only a <frameset> which has to go before <body>, right after
55  *  <head>.
56  *
57  */
58 class WikiPlugin_FrameInclude
59 extends WikiPlugin
60 {
61     function getName() {
62         return _("FrameInclude");
63     }
64
65     function getDescription() {
66         return _("Displays a url in a seperate frame inside our body. Only one frame allowed.");
67     }
68
69     function getVersion() {
70         return preg_replace("/[Revision: $]/", '',
71                             "\$Revision: 1.6 $");
72     }
73
74     function getDefaultArguments() {
75         return array( 'src'         => false,       // the src url to include
76                       'page'        => false,
77                       'name'        => 'content',   // name of our frame
78                       'title'       => false,
79                       'rows'        => '10%,*,10%', // names: top, $name, bottom
80                       'cols'        => '10%,*',     // names: left, $name
81                                                     // only useful on Theme "Sidebar"
82                       'frameborder' => 0,
83                       'marginwidth'  => false,
84                       'marginheight' => false,
85                       'noresize'    => false,
86                       'scrolling'   => 'auto',  // '[ yes | no | auto ]'
87                     );
88     }
89
90     function run($dbi, $argstr, $request) {
91         global $Theme;
92
93         $args = ($this->getArgs($argstr, $request));
94         extract($args);
95
96         if (!$src) {
97             if (!$page) {
98                 return
99                     $this->error(sprintf(_("%s or %s parameter missing"),
100                                          'src', 'page'));
101             } else {
102                 if ($page == $request->get('pagename')) {
103                     return
104                         $this->error(sprintf(_("recursive inclusion of page %s"),
105                                              $page));
106                 }
107                 $src = WikiURL($page);
108             }
109         }
110
111         // How to normalize url's to compare against recursion?
112         if ($src == $request->getURLtoSelf() ) {
113             return $this->error(sprintf(_("recursive inclusion of url %s"),
114                                         $src));
115         }
116
117         // pass FRAMEPARAMS directly to the Template call in Template.php:214
118         // which goes right after <HEAD>
119         $topuri = $request->getURLtoSelf(array('frame' => 'top'));
120         $bottomuri = $request->getURLtoSelf(array('frame' => 'bottom'));
121         $top = HTML::frame(array('name' => "top", "src" => $topuri));
122         $bottom = HTML::frame(array('name' => "bottom", "src" => $bottomuri));
123         //$bottom = "<frame name=\"bottom\" src=\"$bottomuri\" />";
124
125         $content_opts = array('name' => $name, "src" => $src,
126                               'frameborder' => $frameborder);
127         //        $content = "<frame name=\"$name\" src=\"$src\" frameborder=\"$frameborder\" ";
128         if ($marginwidth)
129             $content_opts['marginwidth'] = $marginwidth;
130         if ($marginheight)
131             $content_opts['marginheight'] = $marginheight;
132         if ($noresize)
133             $content_opts['noresize'] = "noresize";
134         $content_opts['scrolling'] = $scrolling;
135         $content = HTML::frame($content_opts);
136
137         // include this into top.tmpl instead
138         //$memo = HTML(HTML::p(array('class' => 'transclusion-title'),
139         //                     fmt("Included frame from %s", $src)));
140         if (isa($Theme, 'Theme_Sidebar')) {
141             // left also.
142             $lefturi = $request->getURLtoSelf(array('frame' => 'navbar'));
143             $frameset = HTML::frameset(array('rows' => $rows));
144             $frameset->pushContent($top);
145             $colframeset = HTML::frameset(array('cols' => $cols));
146             $colframeset->pushContent(HTML::frame(array('name' => "left",
147                                                         "src" => $lefturi)));
148             $colframeset->pushContent($content);
149             $frameset->pushContent($colframeset);
150             $frameset->pushContent($bottom);
151         } else {
152             unset($args['cols']);
153             // only top, body, bottom
154             $frameset = HTML::frameset(array('rows' => $rows));
155             $frameset->pushContent($top);
156             $frameset->pushContent($content);
157             $frameset->pushContent($bottom);
158         }
159         $args['FRAMESET'] = $frameset;
160         return printXML(new Template('frameset', $request, $args));
161     }
162 };
163
164 // $Log: not supported by cvs2svn $
165
166 // For emacs users
167 // Local Variables:
168 // mode: php
169 // tab-width: 8
170 // c-basic-offset: 4
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil
173 // End:
174 ?>