aliroPage404.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*******************************************************************************
00004  * Aliro - the modern, accessible content management system
00005  *
00006  * Aliro is open source software, free to use, and licensed under GPL.
00007  * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL
00008  *
00009  * The author freely draws attention to the fact that Aliro derives from Mambo,
00010  * software that is controlled by the Mambo Foundation.  However, this section
00011  * of code is totally new.  If it should contain any fragments that are similar
00012  * to Mambo, please bear in mind (1) there are only so many ways to do things
00013  * and (2) the author of Aliro is also the author and copyright owner for large
00014  * parts of Mambo 4.6.
00015  *
00016  * Tribute should be paid to all the developers who took Mambo to the stage
00017  * it had reached at the time Aliro was created.  It is a feature rich system
00018  * that contains a good deal of innovation.
00019  *
00020  * Your attention is also drawn to the fact that Aliro relies on other items of
00021  * open source software, which is very much in the spirit of open source.  Aliro
00022  * wishes to give credit to those items of code.  Please refer to
00023  * http://aliro.org/credits for details.  The credits are not included within
00024  * the Aliro package simply to avoid providing a marker that allows hackers to
00025  * identify the system.
00026  *
00027  * Copyright in this code is strictly reserved by its author, Martin Brampton.
00028  * If it seems appropriate, the copyright will be vested in the Aliro Organisation
00029  * at a suitable time.
00030  *
00031  * Copyright (c) 2007 Martin Brampton
00032  *
00033  * http://aliro.org
00034  *
00035  * counterpoint@aliro.org
00036  *
00037  * aliroPage404 should be developed to be much more user friendly.  At present
00038  * it simply provides some basic diagnostics when a page link does not work out.
00039  *
00040  */
00041 
00042 
00043 class aliroPage404 {
00044 
00045     public function __construct () {
00046         if (aliroComponentHandler::getInstance()->componentCount() AND aliroMenuHandler::getInstance()->getMenuCount('mainmenu')) {
00047             header ('HTTP/1.1 404 Not Found');
00048             $this->record404();
00049             $searchtext = $this->searchuri();
00050             aliroRequest::getInstance()->setPageTitle(T_('404 Error - page not found'));
00051             echo <<<PAGE_404
00052             <h3>Sorry! Page not found</h3>
00053             <p>
00054             This may be a problem with our system, and the issue 
00055             has been logged for investigation. Or it could be that 
00056             you have an outdated link.
00057             </p>
00058             <p>
00059             This page is also presented for an item that exists 
00060             but is not available to you.  If you are not logged in, 
00061             you might like to log in and try again.
00062             </p>
00063             <p>
00064             If you have any query you would like us to deal with, 
00065             please use the CONTACT US facility from the main menu.  
00066             </p>
00067             <p>
00068             The following items have some connection with the URI 
00069             you used to come here, so maybe they are what you were 
00070             looking for?
00071             </p>
00072 PAGE_404;
00073 
00074             echo $searchtext;
00075         }
00076         else echo T_('This Aliro based web site is not yet configured with user data, please call back later');
00077     }
00078 
00079     private function record404 () {
00080         $uri = $_SERVER['REQUEST_URI'];
00081         $timestamp = date ('Y-m-d H:i:s');
00082         $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
00083         $post = base64_encode(serialize($_POST));
00084         $trace = aliroRequest::trace();
00085         aliroCoreDatabase::getInstance()->doSQL("INSERT INTO #__error_404 (uri, timestamp, referer, post, trace) VALUES ('$uri', '$timestamp', '$referer', '$post', '$trace') ON DUPLICATE KEY UPDATE timestamp = '$timestamp', referer='$referer', post='$post', trace='$trace'");
00086     }
00087 
00088     private function searchuri () {
00089         $uri = $_SERVER['REQUEST_URI'];
00090         $bits = explode ('/', $uri);
00091         for ($i=count($bits); $i>0; $i--) {
00092             $bit = $bits[$i-1];
00093             if ($bit) break;
00094         }
00095         $bit = str_replace(array('!', '%21'), array('',''), $bit);
00096         $searchword = preg_replace('/[^A-Za-z]/', ' ', $bit);
00097         $results = aliroMambotHandler::getInstance()->trigger('onSearch', array($searchword, 'all', 'popular'));
00098         $lines = array();
00099         $purifier = new HTMLPurifier;
00100         foreach ($results as $result) {
00101             if ($result) foreach ($result as $item) {
00102                 if (empty($item->text)) continue;
00103                 $item->text = $purifier->purify($item->text);
00104                 $item->text = strip_tags($item->text);
00105                 if (strlen($item->text) > 200) $item->text = substr($item->text,0,200).'...';
00106                 if (!isset($item->section)) $item->section = '';
00107                 $lines[] = $item;
00108             }
00109         }
00110         $html = '';
00111         $sef = aliroSEF::getInstance();
00112         if (count($lines)) foreach ($lines as $line) {
00113             $section = isset($line->section) ? $line->section : '';
00114             $html .= <<<SEARCH_LINE
00115 
00116             <p>
00117             <a href="{$sef->sefRelToAbs($line->href)}">$line->title</a>
00118             $section
00119             $line->text
00120             </p>
00121 
00122 SEARCH_LINE;
00123 
00124         }
00125         else $html = '<p>'.T_('Sorry, none found').'</p>';
00126         return $html;
00127     }
00128 
00129 }

Generated on Wed May 14 13:01:56 2008 for ALIRO by  doxygen 1.5.5