[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/inc/ -> class.error404.php (source)

   1  <?php
   2  /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
   3  /*
   4  # ***** BEGIN LICENSE BLOCK *****
   5  # This file is part of Plume CMS, a website management application.
   6  # Copyright (C) 2001-2005 Loic d'Anterroches and contributors.
   7  #
   8  # Plume CMS 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  # Plume CMS 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 this program; if not, write to the Free Software
  20  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  21  #
  22  # ***** END LICENSE BLOCK ***** */
  23  
  24  
  25  
  26  class Error404
  27  {
  28      /**
  29       * Action to display the 404 error.
  30       *
  31       * @param string Server query string
  32       * @return int Success code
  33       */
  34      function action($query)
  35      {
  36          config::setVar('category_page', 1);
  37          $GLOBALS['_PX_render']['last'] = '';
  38          $last =& $GLOBALS['_PX_render']['last']; 
  39          $GLOBALS['_PX_render']['website'] = '';
  40          $website =& $GLOBALS['_PX_render']['website']; 
  41          $GLOBALS['_PX_render']['res'] = '';
  42          $res =& $GLOBALS['_PX_render']['res']; 
  43  
  44          // Parse query string to find the matching article
  45          $con =& pxDBConnect();
  46  
  47          // Find possible matches in the DB for a category
  48          if ('/' != substr($query, 0, 1)) $query = '/'.$query;
  49          $r = 'SELECT * FROM '.$con->pfx.'categories
  50                  LEFT JOIN '.$con->pfx.'websites ON '.$con->pfx.'websites.website_id = '.$con->pfx.'categories.website_id
  51                  WHERE '.$con->pfx.'categories.website_id=\''.$con->escapeStr($GLOBALS['_PX_website_config']['website_id']).'\'
  52                  AND '.$con->pfx.'categories.category_path=\''.$con->escapeStr($query.'/').'\'';
  53          if (($rs = $con->select($r)) !== false) {
  54              if ($rs->f('category_id')) {
  55                  //bingo the error was a missing / at the end for a category
  56                  $con->close();
  57                  if (config::f('url_format') == 'simple') {
  58                      $query = '/?'.$query;
  59                  }
  60                  $GLOBALS['_PX_redirect'] = $GLOBALS['_PX_website_config']['rel_url'].$query.'/';
  61                  return 301;
  62              }
  63          }
  64          //need to see if a redirection is available.
  65          $r = 'SELECT * FROM '.$con->pfx.'smart404 WHERE
  66                website_id=\''.$con->escapeStr($GLOBALS['_PX_website_config']['website_id']).'\' AND
  67                oldpage=\''.$con->escapeStr($query).'\'';
  68          if (($rs = $con->select($r)) !== false) {
  69              if ($rs->f('newpage')) {
  70                  //bingo
  71                  $page = $rs->f('newpage');
  72                  //try to update the count
  73                  $r = 'UPDATE '.$con->pfx.'smart404 SET
  74                  lastroutingdate=\''.date::stamp().'\', total=total+1
  75                  WHERE website_id=\''.$con->escapeStr($GLOBALS['_PX_website_config']['website_id']).'\' AND
  76                  oldpage=\''.$con->escapeStr($query).'\' LIMIT 1';
  77                  $con->execute($r); //we do not check if errors as we already know the page
  78                  @$con->close();
  79                  $GLOBALS['_PX_redirect'] = $page;
  80                  return 301;
  81              }
  82          } 
  83  
  84          //log the error if log requested
  85          if (config::f('log404errors')) {
  86                  $ref = (!empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '';
  87                  $agent = (!empty($_SERVER['HTTP_USER_AGENT'])) ? substr($_SERVER['HTTP_USER_AGENT'],0, 250) : '';
  88                  $r = 'INSERT INTO '.$con->pfx.'smart404logs SET
  89                  website_id=\''.$con->escapeStr($GLOBALS['_PX_website_config']['website_id']).'\',
  90                  page=\''.$con->escapeStr($query).'\', fromurl=\''.$con->escapeStr($ref).'\',
  91                  date=\''.date::stamp().'\', useragent=\''.$con->escapeStr($agent).'\'';
  92                  $con->execute($r); //we do not check if errors as it is not critical
  93          }
  94  
  95  
  96          $s = new Search($con, config::f('website_id'));
  97  
  98          $query = preg_replace('#^(/error404)#', '', $query);
  99          config::setVar('query_string', Error404::parseQueryString($query));
 100  
 101          $sql = $s->create_search_query_string(config::f('query_string'));
 102          $extra = ' AND '.$con->pfx.'resources.publicationdate <= '
 103              .date::stamp().' AND '.$con->pfx.'resources.enddate >= '
 104              .date::stamp().' AND '.$con->pfx.'resources.status = '
 105              .PX_RESOURCE_STATUS_VALIDE;
 106          $sql = sprintf($sql, $extra);
 107  
 108          if (($res = $con->select($sql, 'ResourceSet')) === false) {
 109              $GLOBALS['_PX_render']['error']->setError('MySQL: '
 110                                                        .$con->error(), 500);
 111              return 404;
 112          }
 113  
 114          $GLOBALS['_PX_render']['res']->autoSave(array('score', 'total'));
 115          $GLOBALS['_PX_render']['website'] = FrontEnd::getWebsite();
 116  
 117          header('Status: 404 Not Found');
 118          header(FrontEnd::getHeader('404.php'));
 119          // Load the template
 120          include config::f('manager_path').'/templates/'
 121              .config::f('theme_id').'/404.php';
 122          return 200;
 123      }
 124  
 125      /**
 126       * Parse query string.
 127       *
 128       * @param string Query string
 129       * @return string Clean query string
 130       */
 131      function parseQueryString($query)
 132      {
 133          $clean = '';
 134          $query = Search::clean_string($query);
 135          $words = Search::explode_in_words($query, true);
 136          foreach ($words as $k => $v) {
 137              $clean .= $k.' ';
 138          }
 139          return trim($clean);
 140      }
 141  
 142  }
 143  
 144  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics