1 <?php rcs_id('$Id: PageType.php,v 1.1 2002-02-18 08:58:10 carstenklapp Exp $');
3 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5 This file is part of PhpWiki.
7 PhpWiki is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 PhpWiki is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with PhpWiki; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 include_once('lib/BlockParser.php');
31 * require_once('lib/PageType.php');
32 * $transformedContent = PageType($pagerevisionhandle, $pagename, $markup);
34 * See http://phpwiki.sourceforge.net/phpwiki/PageType
36 function PageType(&$rev, $pagename = false, $markup = false) {
38 if (isa($rev, 'WikiDB_PageRevision')) {
39 $text = $rev->getPackedContent();
40 $pagename = $rev->_pagename; //is this _ok?
41 $markup = $rev->get('markup');
44 // Hopefully only an edit preview gets us here, else we might be screwed.
45 if ($pagename == false || $markup = false) {
46 $error_text = "DEBUG: \$rev was not a 'WikiDB_PageRevision'. (Are you not previewing a page edit?)"; //debugging message only
47 trigger_error($error_text, E_USER_NOTICE);
51 //echo $ContentTemplateName; //debugging
52 //echo $text; //debugging
55 // PageType currently only works with InterWikiMap.
56 // Once a contentType field has been implemented in the
57 // database then that can be used instead of this pagename check.
58 switch( _($pagename) ) {
60 $ContentTemplateName = 'interwikimap';
63 $ContentTemplateName = 'wikitext';
66 $_ContentTemplates = array('wikitext' => new PageType($text, $markup),
67 'interwikimap' => new interWikiMapPageType($text, $markup));
69 // Start making the actual content
70 $content_template = $_ContentTemplates[$ContentTemplateName];
71 return $content_template->getContent();
80 * This is a simple WikiPage
84 function PageType (&$content, $markup) {
85 $this->_html = TransformText($content, $markup);
88 function getContent() {
94 class interWikiMapPageType extends PageType {
97 function interWikiMapPageType($content, $markup) {
98 //echo $content; //debugging
99 $this->_content = $content;
100 $this->markup = $markup;
101 $this->_html = HTML();
103 // $this->_html->pushContent($this->_extractText());
104 // $this->_html->pushContent($this->_getMap());
106 $divs = array('interwikimap-header' => $this->_extractStartText(),
107 'interwikimap' => $this->_getMap(),
108 'interwikimap-footer' => $this->_extractEndText());
110 foreach ($divs as $class => $function)
111 $this->_html->pushContent(HTML::div(array('class' => $class), $function));
115 function getContent() {
121 // return TransformText("<verbatim>" . $this->_extractMap() . "</verbatim>", $this->markup);
124 //return $this->_arrayToTable($this->_extractMap(), $request);
126 // let interwiki.php get the map
127 include_once("lib/interwiki.php");
128 $map = InterWikiMap::GetMap($request);
129 return $this->_arrayToTable($map->_map, $request);
132 function _arrayToTable ($array, &$request) {
133 $dbi = $request->getDbh();
134 $table = HTML::table();
135 foreach ($array as $moniker => $url) {
136 if ($dbi->isWikiPage($moniker)) {
137 $moniker = WikiLink($moniker);
139 $table->pushContent(HTML::tr(HTML::td($moniker), HTML::td(HTML::pre($url))));
144 function _extractStartText() {
145 // cut the map out of the text
146 $v = strpos($this->_content, "<verbatim>");
148 list($wikitext, $cruft) = explode("<verbatim>", $this->_content);
149 //echo $cruft; //debugging
151 $wikitext = $this->_content;
153 return TransformText($wikitext, $this->markup);
156 function _extractEndText() {
157 // cut the map out of the text
158 $v = strpos($this->_content, "</verbatim>");
160 list($cruft, $endtext) = explode("</verbatim>", $this->_content);
161 //echo $cruft; //debugging
162 return TransformText($endtext, $this->markup);
169 function _extractMap() {
170 if (preg_match('|^<verbatim>\n(.*)^</verbatim>|ms',
171 $this->_content['rawmarkup'], $m)) {
175 global $AllowedProtocols;
176 if (!preg_match_all("/^\s*(\S+)\s+(\S+)/m",
177 $maptext, $matches, PREG_SET_ORDER))
179 foreach ($matches as $m) {
192 // c-hanging-comment-ender-p: nil
193 // indent-tabs-mode: nil