1 <?php rcs_id('$Id: PageType.php,v 1.4 2002-02-18 23:17:47 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);
52 // PageType currently only works with InterWikiMap.
53 // Once a contentType field has been implemented in the
54 // database then that can be used instead of this pagename check.
55 $i = _("InterWikiMap");
58 $ContentTemplateName = 'interwikimap';
61 $ContentTemplateName = 'wikitext';
64 $_ContentTemplates = array('wikitext' => new PageType($text, $markup),
65 'interwikimap' => new interWikiMapPageType($text, $markup));
67 // Start making the actual content
68 $content_template = $_ContentTemplates[$ContentTemplateName];
69 return $content_template->getContent();
78 * This is a simple WikiPage
84 function PageType (&$content, $markup) {
85 $this->_content = $content;
86 $this->_markup = $markup;
87 $this->_html = HTML();
89 $this->_defineSections();
90 $this->_populateSections();
93 function _defineSections() {
94 // section_id => ('css_class', $this->_section_function)
95 $this->_divs = array('wikitext' => array('wikitext', $this->_extractText()));
98 function _populateSections() {
99 foreach ($this->_divs as $section => $data) {
100 list($class, $function) = $data;
101 $this->_html->pushContent(HTML::div(array('class' => $class), $function));
106 function _extractText() {
107 return TransformText($this->_content, $this->_markup);
110 function getContent() {
116 class interWikiMapPageType extends PageType {
118 function _defineSections() {
119 // section_id => ('css_class', $this->_section_function)
120 $this->_divs = array('interwikimap-header' => array('wikitext', $this->_extractStartText()),
121 'interwikimap' => array('wikitext', $this->_getMap()),
122 'interwikimap-footer' => array('wikitext', $this->_extractEndText()));
127 // return TransformText("<verbatim>" . $this->_extractMap() . "</verbatim>", $this->markup);
130 //return $this->_arrayToTable($this->_extractMap(), $request);
132 // let interwiki.php get the map
133 include_once("lib/interwiki.php");
134 $map = InterWikiMap::GetMap($request);
135 return $this->_arrayToTable($map->_map, $request);
138 function _arrayToTable ($array, &$request) {
139 $dbi = $request->getDbh();
140 $table = HTML::table();
141 foreach ($array as $moniker => $url) {
142 if ($dbi->isWikiPage($moniker)) {
143 $moniker = WikiLink($moniker);
145 $table->pushContent(HTML::tr(HTML::td($moniker), HTML::td(HTML::pre($url))));
150 function _extractStartText() {
151 // cut the map out of the text
152 $v = strpos($this->_content, "<verbatim>");
154 list($wikitext, $cruft) = explode("<verbatim>", $this->_content);
156 $wikitext = $this->_content;
158 return TransformText($wikitext, $this->_markup);
161 function _extractEndText() {
162 // cut the map out of the text
163 $v = strpos($this->_content, "</verbatim>");
165 list($cruft, $endtext) = explode("</verbatim>", $this->_content);
166 return TransformText($endtext, $this->_markup);
173 function _extractMap() {
174 if (preg_match('|^<verbatim>\n(.*)^</verbatim>|ms',
175 $this->_content['rawmarkup'], $m)) {
179 global $AllowedProtocols;
180 if (!preg_match_all("/^\s*(\S+)\s+(\S+)/m",
181 $maptext, $matches, PREG_SET_ORDER))
183 foreach ($matches as $m) {
196 // c-hanging-comment-ender-p: nil
197 // indent-tabs-mode: nil