Mercurial > SimpleWebPresenter
changeset 52:3898353ed1d8
Include fixes.
sitemap don't print before everything has been processed.
Make a class of accept-language.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 11 Oct 2012 00:48:46 +0200 |
| parents | 2d0cda52f43f |
| children | 2e6ba7259281 |
| files | CacheTimeCheck.inc accept-language.inc common-functions.inc sitemap.php |
| diffstat | 4 files changed, 54 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/CacheTimeCheck.inc Tue Oct 09 20:15:20 2012 +0200 +++ b/CacheTimeCheck.inc Thu Oct 11 00:48:46 2012 +0200 @@ -1,4 +1,12 @@ <?php +$baseDir = dirname(__FILE__); + +include_once 'logger.inc'; +include_once 'common-functions.inc'; +$cache = CacheTimeCheck::instance(__FILE__); +$cache->cache_time("${baseDir}/logger.inc"); +$cache->cache_time("${baseDir}/common-functions.inc"); + /** * CacheTimeCheck provides a set of functions to enable generating a * correct time for the latest update for a given file. @@ -88,7 +96,7 @@ { if (!file_exists($path)) { warn("${path} does not exist"); - errorPage("Resource not available"); + errorPage("Resource is not available"); } array_push($this->files, $path);
--- a/accept-language.inc Tue Oct 09 20:15:20 2012 +0200 +++ b/accept-language.inc Thu Oct 11 00:48:46 2012 +0200 @@ -1,39 +1,41 @@ <?php -function acceptedLanguages() { - $langs = array(); +class Language { + function acceptedLanguages() { + $langs = array(); - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - // break up string into pieces (languages and q factors) - preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + // break up string into pieces (languages and q factors) + preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); - if (count($lang_parse[1])) { + if (count($lang_parse[1])) { // create a list like "en" => 0.8 $langs = array_combine($lang_parse[1], $lang_parse[4]); // set default to 1 for any without q factor foreach ($langs as $lang => $val) { - if ($val === '') $langs[$lang] = 1; + if ($val === '') $langs[$lang] = 1; } // sort list based on value arsort($langs, SORT_NUMERIC); - } - } - return $langs; -} - -function preferLanguage($prefer) -{ - $language = $prefer; - $langs = acceptedLanguages(); - if ($langs) { - foreach ($langs as $l => $val) { - if (file_exists($l)) { - $language = $l; - break; } } + return $langs; } - return $language; + + function preferLanguage($prefer) + { + $language = $prefer; + $langs = acceptedLanguages(); + if ($langs) { + foreach ($langs as $l => $val) { + if (file_exists($l)) { + $language = $l; + break; + } + } + } + return $language; + } } ?> \ No newline at end of file
--- a/common-functions.inc Tue Oct 09 20:15:20 2012 +0200 +++ b/common-functions.inc Thu Oct 11 00:48:46 2012 +0200 @@ -1,8 +1,10 @@ <?php include_once 'CacheTimeCheck.inc'; +$baseDir = dirname(__FILE__); + $cache = CacheTimeCheck::instance(__FILE__); -$cache->includeOnce('http-response-status-codes.inc', dirname(__FILE__)); +$cache->includeOnce('http-response-status-codes.inc', $baseDir); function repMapString($map) {
--- a/sitemap.php Tue Oct 09 20:15:20 2012 +0200 +++ b/sitemap.php Thu Oct 11 00:48:46 2012 +0200 @@ -1,16 +1,19 @@ <? -header('Content-type: application/xml'); -print '<?xml version="1.0" encoding="UTF-8"?>'; -print "\n"; -?> -<urlset +$out = '<?xml version="1.0" encoding="UTF-8"?>'; +$out .= "\n"; +$out .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> -<? +'; include_once 'CacheTimeCheck.inc'; +$baseDir = dirname(__FILE__); +$cache = CacheTimeCheck::instance(__FILE__); +$cache->includeOnce('common-functions.inc', $baseDir); + + $cache = CacheTimeCheck::instance(__FILE__); $cache->includeOnce('Options.inc', dirname(__FILE__)); @@ -59,10 +62,10 @@ $lastmod = strtotime($lastmod); $lastmod = date(DateTime::W3C, $lastmod); - print "<url>\n"; - print "<loc>${location}</loc>\n"; - print "<lastmod>${lastmod}</lastmod>\n"; - print "</url>\n"; + $out .= "<url>\n"; + $out .= "<loc>${location}</loc>\n"; + $out .= "<lastmod>${lastmod}</lastmod>\n"; + $out .= "</url>\n"; } } } @@ -71,5 +74,8 @@ } } -?> -</urlset> \ No newline at end of file +$out .= '</urlset>'; + +header('Content-type: application/xml'); +print $out; +?> \ No newline at end of file
