]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
fix lib/display.php:159: Warning[2]: Argument to array_reverse() should be an array
[SourceForge/phpwiki.git] / lib / display.php
1 <?php
2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.56 2004-10-14 13:44:14 rurban Exp $');
4
5 require_once('lib/Template.php');
6
7 /**
8  * Extract keywords from Category* links on page. 
9  */
10 function GleanKeywords ($page) {
11     global $KeywordLinkRegexp;
12
13     $links = $page->getLinks(false);
14
15     $keywords[] = SplitPagename($page->getName());
16     
17     while ($link = $links->next())
18         if (preg_match("/${KeywordLinkRegexp}/x", $link->getName(), $m))
19             $keywords[] = SplitPagename($m[0]);
20
21     $keywords[] = WIKI_NAME;
22     
23     return join(', ', $keywords);
24 }
25
26 /** Make a link back to redirecting page.
27  *
28  * @param $pagename string  Name of redirecting page.
29  * @return XmlContent Link to the redirecting page.
30  */
31 function RedirectorLink($pagename) {
32     $url = WikiURL($pagename, array('redirectfrom' => ''));
33     return HTML::a(array('class' => 'redirectfrom wiki',
34                          'href' => $url),
35                    $pagename);
36 }
37
38     
39 function actionPage(&$request, $action) {
40     global $WikiTheme;
41
42     $pagename = $request->getArg('pagename');
43     $version = $request->getArg('version');
44
45     $page = $request->getPage();
46     $revision = $page->getCurrentRevision();
47
48     $dbi = $request->getDbh();
49     $actionpage = $dbi->getPage($action);
50     $actionrev = $actionpage->getCurrentRevision();
51
52     $pagetitle = HTML(fmt("%s: %s", 
53                           $actionpage->getName(),
54                           $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
55
56     $validators = new HTTP_ValidatorSet(array('pageversion' => $revision->getVersion(),
57                                               '%mtime' => $revision->get('mtime')));
58                                         
59     $request->appendValidators(array('pagerev' => $revision->getVersion(),
60                                      '%mtime' => $revision->get('mtime')));
61     $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
62                                      '%mtime' => $actionrev->get('mtime')));
63
64     $transformedContent = $actionrev->getTransformedContent();
65     $template = Template('browse', array('CONTENT' => $transformedContent));
66 /*
67     if (!headers_sent()) {
68         //FIXME: does not work yet. document.write not supported (signout button)
69         // http://www.w3.org/People/mimasa/test/xhtml/media-types/results
70         if (ENABLE_XHTML_XML 
71             and (!isBrowserIE() and
72                  strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
73             header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
74         else
75             header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
76     }
77 */    
78     GeneratePage($template, $pagetitle, $revision);
79     $request->checkValidators();
80     flush();
81 }
82
83 function displayPage(&$request, $template=false) {
84     $pagename = $request->getArg('pagename');
85     $version = $request->getArg('version');
86     $page = $request->getPage();
87     if ($version) {
88         $revision = $page->getRevision($version);
89         if (!$revision)
90             NoSuchRevision($request, $page, $version);
91     }
92     else {
93         $revision = $page->getCurrentRevision();
94     }
95
96     if (isSubPage($pagename)) {
97         $pages = explode(SUBPAGE_SEPARATOR, $pagename);
98         $last_page = array_pop($pages); // deletes last element from array as side-effect
99         $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
100                                               'class' => 'pagetitle'
101                                               ),
102                                         SplitPagename($pages[0] . SUBPAGE_SEPARATOR)));
103         $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
104         array_shift($pages);
105         foreach ($pages as $p)  {
106             $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
107                                                   'class' => 'backlinks'),
108                                        SplitPagename($p . SUBPAGE_SEPARATOR)));
109             $first_pages .= $p . SUBPAGE_SEPARATOR;
110         }
111         $backlink = HTML::a(array('href' => WikiURL($pagename,
112                                                     array('action' => _("BackLinks"))),
113                                   'class' => 'backlinks'),
114                             SplitPagename($last_page));
115         $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
116         $pagetitle->pushContent($backlink);
117     } else {
118         $pagetitle = HTML::a(array('href' => WikiURL($pagename,
119                                                      array('action' => _("BackLinks"))),
120                                    'class' => 'backlinks'),
121                              SplitPagename($pagename));
122         $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
123         if ($request->getArg('frame'))
124             $pagetitle->setAttr('target', '_top');
125     }
126
127     $pageheader = $pagetitle;
128     if (($redirect_from = $request->getArg('redirectfrom'))) {
129         $redirect_message = HTML::span(array('class' => 'redirectfrom'),
130                                        fmt("(Redirected from %s)",
131                                            RedirectorLink($redirect_from)));
132     }
133
134     $request->appendValidators(array('pagerev' => $revision->getVersion(),
135                                      '%mtime' => $revision->get('mtime')));
136 /*
137     // FIXME: This is also in the template...
138     if ($request->getArg('action') != 'pdf' and !headers_sent()) {
139       // FIXME: enable MathML/SVG/... support
140       if (ENABLE_XHTML_XML
141              and (!isBrowserIE()
142                   and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
143             header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
144         else
145             header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
146     }
147 */
148     $page_content = $revision->getTransformedContent();
149
150     // if external searchengine (google) referrer, highlight the searchterm
151     // FIXME: move that to the transformer?
152     // OR: add the searchhightplugin line to the content?
153     if ($result = isExternalReferrer($request)) {
154         if (DEBUG and !empty($result['query'])) {
155             include_once('lib/WikiPlugin.php');
156             $loader = new WikiPluginLoader;
157             $xml = $loader->expandPI('<'.'?plugin SearchHighLight s="'.$result['query'].'"?'.'>', $request, $markup);
158             if ($xml and is_array($xml)) {
159               foreach (array_reverse($xml) as $line) {
160                 array_unshift($page_content->_content, $line);
161               }
162               array_unshift($page_content->_content, 
163                             HTML::div(_("You searched for: "), HTML::strong($result['query'])));
164             }
165             if (0) {
166             require_once("lib/TextSearchQuery.php");
167             $query = new TextSearchQuery($result['query']);
168             $hilight_re = $query->getHighlightRegexp();
169             $matches = preg_grep("/$hilight_re/i", $revision->getContent());
170             // FIXME!
171             foreach ($page_content->_content as $line) {
172                 if (is_string($line)) {
173                   $html = array();
174                   while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) {
175                     $line = substr($line, strlen($m[0]));
176                     $html[] = $m[1];    // prematch
177                     $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match
178                   }
179                 }
180                 $html[] = $line;  // postmatch
181                 //$html = HTML::dd(HTML::small(array('class' => 'search-context'),
182                 //                             $html));
183             }
184             }
185         }
186     }
187    
188     $toks['CONTENT'] = new Template('browse', $request, $page_content);
189     
190     $toks['TITLE'] = $pagetitle;
191     $toks['HEADER'] = $pageheader;
192     $toks['revision'] = $revision;
193     if (!empty($redirect_message))
194         $toks['redirected'] = $redirect_message;
195     $toks['ROBOTS_META'] = 'index,follow';
196     $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
197     $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
198     if (!$template)
199         $template = new Template('html', $request);
200     
201     $template->printExpansion($toks);
202     $page->increaseHitCount();
203
204     if ($request->getArg('action') != 'pdf')
205         $request->checkValidators();
206     flush();
207 }
208
209 // $Log: not supported by cvs2svn $
210 // Revision 1.55  2004/09/26 14:58:35  rurban
211 // naive SearchHighLight implementation
212 //
213 // Revision 1.54  2004/09/17 14:19:41  rurban
214 // disable Content-Type header for now, until it is fixed
215 //
216 // Revision 1.53  2004/06/25 14:29:20  rurban
217 // WikiGroup refactoring:
218 //   global group attached to user, code for not_current user.
219 //   improved helpers for special groups (avoid double invocations)
220 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
221 // fixed a XHTML validation error on userprefs.tmpl
222 //
223 // Revision 1.52  2004/06/14 11:31:37  rurban
224 // renamed global $Theme to $WikiTheme (gforge nameclash)
225 // inherit PageList default options from PageList
226 //   default sortby=pagename
227 // use options in PageList_Selectable (limit, sortby, ...)
228 // added action revert, with button at action=diff
229 // added option regex to WikiAdminSearchReplace
230 //
231 // Revision 1.51  2004/05/18 16:23:39  rurban
232 // rename split_pagename to SplitPagename
233 //
234 // Revision 1.50  2004/05/04 22:34:25  rurban
235 // more pdf support
236 //
237 // Revision 1.49  2004/04/18 01:11:52  rurban
238 // more numeric pagename fixes.
239 // fixed action=upload with merge conflict warnings.
240 // charset changed from constant to global (dynamic utf-8 switching)
241 //
242
243 // For emacs users
244 // Local Variables:
245 // mode: php
246 // tab-width: 8
247 // c-basic-offset: 4
248 // c-hanging-comment-ender-p: nil
249 // indent-tabs-mode: nil
250 // End:
251 ?>