# HG changeset patch # User Tom Fredrik "BFG" Klaussen # Date 1349378522 -7200 # Node ID c3a61615a39c6292f970d0b8451f4ff536bdad66 # Parent aec57ed6f5f60c20c4133682a7e095da6757f621# Parent f37be50a70cf201b2c8b280913c3c6e97dc1b66a Branch merge. diff -r f37be50a70cf -r c3a61615a39c Options.inc --- a/Options.inc Sun Sep 30 17:06:07 2012 +0200 +++ b/Options.inc Thu Oct 04 21:22:02 2012 +0200 @@ -6,6 +6,8 @@ private $name; private $acceptedLanguages = array(); private $inputDefaults = array(); + private $cache; + private $urlParams = array(); function getDefaultLang() { @@ -22,6 +24,21 @@ $this->lang = $lang; } + function setUrlParams($urlParams) + { + foreach($urlParams as $key) { + $value = $_GET[$key]; + if (!$value) + $value = ''; + $this->urlParams[$key] = $value; + } + } + + function getUrlParams() + { + return $this->urlParams; + } + function setName($name) { $this->name = $name; @@ -32,6 +49,16 @@ return $this->name; } + function setCache($cache) + { + $this->cache = $cache; + } + + function getCache() + { + return $this->cache; + } + function getAcceptedLanguages() { return $this->acceptedLanguages; diff -r f37be50a70cf -r c3a61615a39c cache_check.inc --- a/cache_check.inc Sun Sep 30 17:06:07 2012 +0200 +++ b/cache_check.inc Thu Oct 04 21:22:02 2012 +0200 @@ -1,35 +1,47 @@ files, $filename); + $this->newest = $minTime; + $this->cache_time(__FILE__); + } - $gmdate_mod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT'; + function CheckHttpModified() + { + if (DEBUG) + var_dump($_SERVER); + + $HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE']; + $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE); - if ($if_modified_since == $gmdate_mod) { - header("HTTP/1.0 304 Not Modified"); - exit; + $gmdate_mod = gmdate('D, d M Y H:i:s', $this->newest) . ' GMT'; + + if ($if_modified_since == $gmdate_mod) { + header("HTTP/1.0 304 Not Modified"); + exit; + } + header("Last-Modified: $gmdate_mod"); } - header("Last-Modified: $gmdate_mod"); -} -function cache_time($path) -{ - global $newest; - $mtime = filemtime($path); - if ($mtime > $newest) { - $newest = $mtime; + function cache_time($path) + { + array_push($this->files, $path); + $mtime = filemtime($path); + if ($mtime > $this->newest) { + $this->newest = $mtime; + } + } + + function includeOnce($path) + { + $this->cache_time($path); + include_once($path); } } - -function include_with_mtime($path) -{ - cache_time($path); - include_once($path); -} - -cache_time(__FILE__); ?> \ No newline at end of file diff -r f37be50a70cf -r c3a61615a39c common-functions.inc --- a/common-functions.inc Sun Sep 30 17:06:07 2012 +0200 +++ b/common-functions.inc Thu Oct 04 21:22:02 2012 +0200 @@ -3,71 +3,71 @@ function loadFile($sFilename, $sCharset = 'UTF-8') { - if (floatval(phpversion()) >= 4.3) { - if (!file_exists($sFilename)) return -3; - $sData = file_get_contents($sFilename); - } else { - if (!file_exists($sFilename)) return -3; - $rHandle = fopen($sFilename, 'r'); - if (!$rHandle) return -2; + if (floatval(phpversion()) >= 4.3) { + if (!file_exists($sFilename)) + return -3; + $sData = file_get_contents($sFilename); + } + else { + if (!file_exists($sFilename)) + return -3; + $rHandle = fopen($sFilename, 'r'); + if (!$rHandle) + return -2; - $sData = ''; - while(!feof($rHandle)) - $sData .= fread($rHandle, filesize($sFilename)); - fclose($rHandle); + $sData = ''; + while(!feof($rHandle)) + $sData .= fread($rHandle, filesize($sFilename)); + fclose($rHandle); + } + if ($sEncoding = mb_detect_encoding($sData, 'auto', true) != $sCharset) { + if ($sEncoding != 1) { + $sData = mb_convert_encoding($sData, $sCharset, $sEncoding); } - if ($sEncoding = mb_detect_encoding($sData, 'auto', true) != $sCharset) { - if ($sEncoding != 1) { - $sData = mb_convert_encoding($sData, $sCharset, $sEncoding); - } - } - return $sData; + } + return $sData; } -function errorPage($errorText, $errorCode=403) +function errorPage($errorText, $errorCode = 403) { header(StatusCodes::httpHeaderFor($errorCode)); print "

${errorText}

"; exit; } -function genUrl($keys=array()) { - $out="?"; - $first=1; - $URL_PARAMS=$GLOBALS['URL_PARAMS']; - $new_params=array(); - foreach($URL_PARAMS as $param) { - $new_params[$param]=$GLOBALS[$param]; - } - foreach($keys as $param => $val) { - $new_params[$param]=$val; - } - foreach($new_params as $param => $val) { - if($first) - $first=0; - else - $out.="&"; - $out.=urlencode($param).'='.urlencode($val); - } - return $out; +function genUrl($urlParams, $keys = array()) { + $out = "?"; + $first = 1; + $new_params = $urlParams; + foreach($keys as $param => $val) { + $new_params[$param] = $val; + } + foreach($new_params as $param => $val) { + if($first) + $first = 0; + else + $out .= "&"; + $out .= urlencode($param) . '=' . urlencode($val); + } + return $out; } function getElementByTagName($obj, $name) { - $elems=$obj->getElementsByTagName($name); + $elems = $obj->getElementsByTagName($name); if ($elems->length != 1) { exit; } - $elem=$elems->item(0); + $elem = $elems->item(0); return $elem; } function getXmlContent($node) { - $text=$node->ownerDocument->saveXml($node); - $pattern="/^<".$node->tagName."[^>]*>/is"; - $text=preg_replace($pattern, '' , $text); - $pattern='/<\/'.$node->tagName.'[^>]*>$/is'; - $text=preg_replace($pattern, '' , $text); + $text = $node->ownerDocument->saveXml($node); + $pattern = "/^<" . $node->tagName."[^>]*>/is"; + $text = preg_replace($pattern, '' , $text); + $pattern = '/<\/' . $node->tagName . '[^>]*>$/is'; + $text = preg_replace($pattern, '' , $text); return $text; } diff -r f37be50a70cf -r c3a61615a39c filters.inc --- a/filters.inc Sun Sep 30 17:06:07 2012 +0200 +++ b/filters.inc Thu Oct 04 21:22:02 2012 +0200 @@ -1,52 +1,68 @@ ]*)>/is"; - $replacement = "
  • "; - $output= preg_replace($pattern, $replacement, $input); + $name = $options->getName(); + $lang = $options->getLang(); + $pattern = "/
  • ]*)>/is"; + $replacement = "
  • "; + $output = preg_replace($pattern, $replacement, $input); + + $pattern = '/
  • ]*)>(.*?)<\/li>/is'; + $replacement = "
  • \$3
  • "; + + $opt = 'array('; + $start = True; - $pattern = '/
  • ]*)>(.*?)<\/li>/is'; - $replacement = "
  • \$3
  • "; - $output=preg_replace_callback($pattern, + foreach($options->getUrlParams() as $param => $value) { + if ($start) { + $start = False; + $opt .= "\"${param}\" => \"${value}\""; + } + else { + $opt .= ", \"${param}\" => \"${value}\""; + } + } + $opt .= ')'; + + $output = preg_replace_callback($pattern, create_function( '$matches', - 'return "
  • $matches[1]))."\">$matches[3]
  • ";' + 'return "
  • $matches[1])) . "\">$matches[3]
  • ";' ), $output); - return $output; + return $output; } -function addLangBar($input, $languages) { - $name=$GLOBALS['name']; - $lang=$GLOBALS['lang']; -// $languages = array("no","en"); - $langbar='