cvs: docweb /include init.inc.php lib_general.inc.php /www redirect.php
[email protected] ("Nuno Lopes")
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <cvsnlopess1108646637@cvsserver> |
nlopess Thu Feb 17 08:23:57 2005 EDT
Modified files:
/docweb/include init.inc.php lib_general.inc.php
/docweb/www redirect.php
Log:
half rewrite of redirection system. huge simplification of the code.
remove uneeded function, which seems to belong to old rfc system
nlopess-20050217082357.txt
(text/plain, 12 KB)
http://cvs.php.net/diff.php/docweb/include/init.inc.php?r1=1.9&r2=1.10&ty=u Index: docweb/include/init.inc.php diff -u docweb/include/init.inc.php:1.9 docweb/include/init.inc.php:1.10 --- docweb/include/init.inc.php:1.9 Sun Jan 23 17:29:05 2005 +++ docweb/include/init.inc.php Thu Feb 17 08:23:57 2005 @@ -1,90 +1,82 @@ -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: -+----------------------------------------------------------------------+ -| PHP Documentation Tools Site Source Code | -+----------------------------------------------------------------------+ -| Copyright (c) 1997-2004 The PHP Group | -+----------------------------------------------------------------------+ -| This source file is subject to version 3.0 of the PHP license, | -| that is bundled with this package in the file LICENSE, and is | -| available through the world-wide-web at the following url: | -| http://www.php.net/license/3_0.txt. | -| If you did not receive a copy of the PHP license and are unable to | -| obtain it through the world-wide-web, please send a note to | -| [email protected] so we can mail you a copy immediately. | -+----------------------------------------------------------------------+ -| Authors: Yannick Torres <[email protected]> | -| Mehdi Achour <[email protected]> | -| Gabor Hojtsy <[email protected]> | -| Sean Coates <[email protected]> | -+----------------------------------------------------------------------+ -$Id: init.inc.php,v 1.9 2005/01/23 22:29:05 sean Exp $ -*/ - -error_reporting(E_ALL); - -// get paths -require_once(dirname(realpath(__FILE__)) . '/../build-ops.php'); - -// RSS cache is considered stale after (seconds): -define('RSS_STALE_CACHE_BUGS', 300); // 300 = 5mins - -// project & language config -require_once('lib_proj_lang.inc.php'); - -// get defaults -list($defaultProject) = array_keys($PROJECTS); -list($defaultLanguage) = array_keys($LANGUAGES); -$defaultFallbackProject = 'www'; -$defaultFallbackLanguage = 'en'; - -// Only allow $_SERVER under apache to make cli scripts work -if (!isset($inCli) OR $inCli != true) { - $inCli = false; - - // set up constants (use defaults if necessary) - define('SITE', isset($project) ? $project : $defaultProject); - define('LANGC', isset($language) ? $language : $defaultLanguage); - define('URI', isset($uri) ? $uri : $_SERVER['REQUEST_URI']); - define('LANGD', $LANGUAGES[LANGC]); - - // set up BASE_URL - if (isset($_SERVER['REDIRECT_STATUS']) && - $_SERVER['REDIRECT_STATUS'] == '404') { - // 404 error, revert to /project/language - $baseURL = '/' . SITE . '/' . LANGC . '/'; - - } elseif (substr($_SERVER['REQUEST_URI'], -1, 1) == '/') { - // is a directory, use verbatim - $baseURL = $_SERVER['REQUEST_URI']; - } else { - // not a dir, use the dirname - $baseURL = dirname($_SERVER['REQUEST_URI']); - } - - // this very dirty fix makes /rfc and /dochowto work (@@@ re-work this) - $baseURL = str_replace('/rfc', '', $baseURL); - $baseURL = str_replace('/dochowto', '', $baseURL); - - // actually define the constant (trim off any trailing slashes): - define('BASE_URL', rtrim($baseURL, '/')); - -} - -// general support library -require_once('lib_general.inc.php'); - -if ($inCli != true) { - // language & template constants - define('DOCWEB_ENTITIY_PREFIX', 'docweb'); - define('DOCWEB_PARAM_ENTITIY_PREFIX', 'param'); - - // language engine - require_once('docweb_language.class.php'); - $Language =& new DocWeb_Language(LANGC); - - // template engine - require_once('docweb_template.class.php'); -} - -?> +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: ++----------------------------------------------------------------------+ +| PHP Documentation Tools Site Source Code | ++----------------------------------------------------------------------+ +| Copyright (c) 1997-2004 The PHP Group | ++----------------------------------------------------------------------+ +| This source file is subject to version 3.0 of the PHP license, | +| that is bundled with this package in the file LICENSE, and is | +| available through the world-wide-web at the following url: | +| http://www.php.net/license/3_0.txt. | +| If you did not receive a copy of the PHP license and are unable to | +| obtain it through the world-wide-web, please send a note to | +| [email protected] so we can mail you a copy immediately. | ++----------------------------------------------------------------------+ +| Authors: Yannick Torres <[email protected]> | +| Mehdi Achour <[email protected]> | +| Gabor Hojtsy <[email protected]> | +| Sean Coates <[email protected]> | ++----------------------------------------------------------------------+ +$Id: init.inc.php,v 1.10 2005/02/17 13:23:57 nlopess Exp $ +*/ + +error_reporting(E_ALL); + +// get paths +require_once(dirname(realpath(__FILE__)) . '/../build-ops.php'); + +// RSS cache is considered stale after (seconds): +define('RSS_STALE_CACHE_BUGS', 300); // 300 = 5mins + +// project & language config +require_once('lib_proj_lang.inc.php'); + +// get defaults +list($defaultProject) = array_keys($PROJECTS); +list($defaultLanguage) = array_keys($LANGUAGES); +$defaultFallbackProject = 'www'; +$defaultFallbackLanguage = 'en'; + +// Only allow $_SERVER under apache to make cli scripts work +if (!isset($inCli) OR $inCli != true) { + $inCli = false; + + // set up constants (use defaults if necessary) + define('SITE', isset($project) ? $project : $defaultProject); + define('LANGC', isset($language) ? $language : $defaultLanguage); + define('URI', isset($uri) ? $uri : $_SERVER['REQUEST_URI']); + define('LANGD', $LANGUAGES[LANGC]); + + if (isset($project)) { + $baseURL[] = $project; + } + + if (isset($language) && $language != 'all' && $language != 'en') { + $baseURL[] = $language; + } + + $baseURL = isset($baseURL) ? implode('/', $baseURL) : ''; + + // actually define the constant + define('BASE_URL', '/' . $baseURL); + +} + +// general support library +require_once('lib_general.inc.php'); + +if ($inCli != true) { + // language & template constants + define('DOCWEB_ENTITIY_PREFIX', 'docweb'); + define('DOCWEB_PARAM_ENTITIY_PREFIX', 'param'); + + // language engine + require_once('docweb_language.class.php'); + $Language =& new DocWeb_Language(LANGC); + + // template engine + require_once('docweb_template.class.php'); +} + +?> http://cvs.php.net/diff.php/docweb/include/lib_general.inc.php?r1=1.42&r2=1.43&ty=u Index: docweb/include/lib_general.inc.php diff -u docweb/include/lib_general.inc.php:1.42 docweb/include/lib_general.inc.php:1.43 --- docweb/include/lib_general.inc.php:1.42 Fri Feb 4 06:59:26 2005 +++ docweb/include/lib_general.inc.php Thu Feb 17 08:23:57 2005 @@ -18,7 +18,7 @@ | Gabor Hojtsy <[email protected]> | | Sean Coates <[email protected]> | +----------------------------------------------------------------------+ -$Id: lib_general.inc.php,v 1.42 2005/02/04 11:59:26 nlopess Exp $ +$Id: lib_general.inc.php,v 1.43 2005/02/17 13:23:57 nlopess Exp $ */ function is_translation($project, $language) @@ -123,36 +123,6 @@ return str_replace(array('@', '.'), array(' at ', ' dot '), $email); } -function get_comment($idx, $section, $doc, $file) -{ - $data = array(); - - $sql = 'SELECT - id, file, doc, user, date, note - - FROM - comments - - WHERE - section=\'' . $section . '\' AND - file=\'' . $file . '\' AND - doc=\'' . $doc . '\' - - ORDER BY - date DESC'; - $result = @sqlite_query($idx, $sql); - - $data['nb_rows'] = sqlite_num_rows($result); - - if ($data['nb_rows'] > 0) { - $data['rows'] = array(); - while ($row = sqlite_fetch_array($result)) { - $data['rows'][] = $row; - } - } - - return $data; -} /** * @return string http://cvs.php.net/diff.php/docweb/www/redirect.php?r1=1.2&r2=1.3&ty=u Index: docweb/www/redirect.php diff -u docweb/www/redirect.php:1.2 docweb/www/redirect.php:1.3 --- docweb/www/redirect.php:1.2 Mon Jan 17 14:52:26 2005 +++ docweb/www/redirect.php Thu Feb 17 08:23:57 2005 @@ -15,17 +15,17 @@ +----------------------------------------------------------------------+ | Authors: Sean Coates <[email protected]> | +----------------------------------------------------------------------+ -$Id: redirect.php,v 1.2 2005/01/17 19:52:26 sean Exp $ +$Id: redirect.php,v 1.3 2005/02/17 13:23:57 nlopess Exp $ */ require_once('../include/lib_proj_lang.inc.php'); function part_is_project($part) { - return in_array($part, array_keys($GLOBALS['PROJECTS'])); + return isset($GLOBALS['PROJECTS'][$part]); } function part_is_language($part) { - return in_array($part, array_keys($GLOBALS['LANGUAGES'])); + return isset($GLOBALS['LANGUAGES'][$part]); } function part_get_filename($part) { @@ -49,96 +49,23 @@ } $parts = explode('/', $_SERVER['REQUEST_URI'], 4); +$uri = ''; -if ( - // /proj/lang/URI - count($parts) == 4 && - part_is_project($parts[1]) && - part_is_language($parts[2]) && - part_is_valid_uri($parts[3]) -) { - $project = $parts[1]; - $language = $parts[2]; - $uri = $parts[3]; -} elseif ( - // /lang/proj/URI - count($parts) == 4 && - part_is_language($parts[1]) && - part_is_project($parts[2]) && - part_is_valid_uri($parts[3]) -) { - $language = $parts[1]; - $project = $parts[2]; - $uri = $parts[3]; -} elseif ( - // /lang (no trailing slash) - count($parts) == 2 - && - (part_is_language($parts[1]) || part_is_project($parts[1])) -) { - // redirect (add trailing slash) - // NOTE: we lose get/post data, here - header("Location: /{$parts[1]}/"); - exit(); -} elseif ( - count($parts) == 3 - && - ( - ( - // /lang/proj (no trailing slash) - part_is_language($parts[1]) && - part_is_project($parts[2]) - ) - || - ( - // /proj/lang (no trailing slash) - part_is_project($parts[1]) && - part_is_language($parts[2]) - ) - ) -) { - // redirect (add trailing slash) - // NOTE: we lose get/post data, here - header("Location: /{$parts[1]}/{$parts[2]}/"); - exit(); -} elseif ( - // /proj/URI - part_is_project($parts[1]) && - part_is_valid_uri(implode('/', array_slice($parts, 2))) -) { - $project = $parts[1]; - $uri = implode('/', array_slice($parts, 2)); -} elseif ( - // /lang/URI - part_is_language($parts[1]) && - part_is_valid_uri(implode('/', array_slice($parts, 2))) -) { - $language = $parts[1]; - $uri = implode('/', array_slice($parts, 2)); -} elseif ( - // /proj/lang/404 - part_is_project($parts[1]) && - part_is_language($parts[2]) -) { - $project = $parts[1]; - $language = $parts[2]; -} elseif ( - // /lang/proj/404 - part_is_language($parts[1]) && - part_is_project($parts[2]) -) { - $language = $parts[1]; - $project = $parts[2]; -} elseif ( - // /proj/404 - part_is_project($parts[1]) -) { - $project = $parts[1]; -} elseif ( - // /lang/404 - part_is_language($parts[1]) -) { - $language = $parts[1]; +foreach ($parts as $part) { + + if (part_is_project($part)) { + $project = $part; + + } elseif (part_is_language($part)) { + $language = $part; + + } else { + $uri .= "/$part"; + } +} + +if (!$uri || !part_is_valid_uri($uri)) { + unset($uri); }