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