Mercurial > SimpleWebPresenter
comparison Options.inc @ 47:66382989353f
Extract baseDir only once.
Function for generating cacheset.
Added logger functionality.
Removed hardcoded location for flagScript.
BUGFIX: masterdocument was not added to the cacheset.
BUGFIX: When two options existed next to eachother, the last was not
read.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Mon, 08 Oct 2012 17:35:08 +0200 |
| parents | bd82b719a0de |
| children | c6d0892f81ff |
comparison
equal
deleted
inserted
replaced
| 46:15879e2aab65 | 47:66382989353f |
|---|---|
| 7 private $acceptedLanguages = array(); | 7 private $acceptedLanguages = array(); |
| 8 private $inputDefaults = array(); | 8 private $inputDefaults = array(); |
| 9 private $cache; | 9 private $cache; |
| 10 private $urlParams = array(); | 10 private $urlParams = array(); |
| 11 private $basePath; | 11 private $basePath; |
| 12 private $flagUrl; | |
| 13 private $baseUrl; | |
| 12 | 14 |
| 13 function getDefaultLang() | 15 function getDefaultLang() |
| 14 { | 16 { |
| 15 return $this->defaultLang; | 17 return $this->defaultLang; |
| 16 } | 18 } |
| 17 | 19 |
| 18 function getLang() | 20 function getLang() |
| 19 { | 21 { |
| 20 return $this->lang; | 22 return $this->lang; |
| 23 } | |
| 24 | |
| 25 function getBaseUrl() | |
| 26 { | |
| 27 if ($this->baseUrl) | |
| 28 return $this->baseUrl; | |
| 29 | |
| 30 $request = $_SERVER['REQUEST_URI']; | |
| 31 $l = strpos($request, '?'); | |
| 32 $base = ($l) ? substr($request, 0 , $l) : $request; | |
| 33 | |
| 34 return "http://" . $_SERVER['HTTP_HOST'] . $base; | |
| 35 } | |
| 36 | |
| 37 function replacePlaceholders($value) | |
| 38 { | |
| 39 $value = preg_replace('/%HOST%/', $_SERVER['HTTP_HOST'], $value); | |
| 40 return $value; | |
| 41 } | |
| 42 | |
| 43 function setBaseUrl($baseUrl) | |
| 44 { | |
| 45 $baseUrl = self::replacePlaceholders($baseUrl); | |
| 46 $this->baseUrl = $baseUrl; | |
| 47 } | |
| 48 | |
| 49 function setFlagUrl($flagUrl) | |
| 50 { | |
| 51 $flagUrl = self::replacePlaceholders($flagUrl); | |
| 52 $this->flagUrl = $flagUrl; | |
| 53 } | |
| 54 | |
| 55 function getFlagUrl() | |
| 56 { | |
| 57 if ($this->flagUrl) | |
| 58 return $this->flagUrl; | |
| 59 | |
| 60 return $this->getBaseUrl() . "/flag.php"; | |
| 21 } | 61 } |
| 22 | 62 |
| 23 function setLang($lang) | 63 function setLang($lang) |
| 24 { | 64 { |
| 25 $this->lang = $lang; | 65 $this->lang = $lang; |
| 79 } | 119 } |
| 80 | 120 |
| 81 function __construct($baseDocument) | 121 function __construct($baseDocument) |
| 82 { | 122 { |
| 83 $params = $baseDocument->getElementsByTagName("param"); | 123 $params = $baseDocument->getElementsByTagName("param"); |
| 124 $toRemove = array(); | |
| 84 foreach ($params as $param) { | 125 foreach ($params as $param) { |
| 85 if ($param->getAttribute("type") == "option") { | 126 if ($param->getAttribute("type") == "option") { |
| 86 $id = $param->getAttribute("id"); | 127 $id = $param->getAttribute("id"); |
| 87 if ($id == "lang") { | 128 if ($id == "lang") { |
| 88 $this->defaultLang = $param->getAttribute("default"); | 129 $this->defaultLang = $param->getAttribute("default"); |
| 91 foreach($accept->childNodes as $child) { | 132 foreach($accept->childNodes as $child) { |
| 92 array_push($this->acceptedLanguages, $child->nodeValue); | 133 array_push($this->acceptedLanguages, $child->nodeValue); |
| 93 } | 134 } |
| 94 } | 135 } |
| 95 } | 136 } |
| 137 elseif ($id == "baseUrl") { | |
| 138 $value = $param->getAttribute("value"); | |
| 139 if($value) | |
| 140 $this->setBaseUrl($value); | |
| 141 } | |
| 142 elseif ($id == "flagUrl") { | |
| 143 $value = $param->getAttribute("value"); | |
| 144 if($value) | |
| 145 $this->setFlagUrl($value); | |
| 146 } | |
| 96 else { | 147 else { |
| 97 die("Invalid option : $id"); | 148 warn("Invalid option: ${id}"); |
| 98 } | 149 } |
| 99 $parent = $param->parentNode; | 150 //We need to iterate in the opposite direction when removing, |
| 100 $parent->removeChild($param); | 151 //so best shifting. |
| 152 array_unshift($toRemove, $param); | |
| 101 } | 153 } |
| 102 elseif ($param->getAttribute("type") == "input") { | 154 elseif ($param->getAttribute("type") == "input") { |
| 103 $id = $param->getAttribute("id"); | 155 $id = $param->getAttribute("id"); |
| 104 $default = $param->getAttribute("default"); | 156 $default = $param->getAttribute("default"); |
| 105 $this->inputDefaults[$id] = $default; | 157 $this->inputDefaults[$id] = $default; |
| 106 } | 158 } |
| 107 } | 159 } |
| 160 foreach($toRemove as $param) { | |
| 161 $parent = $param->parentNode; | |
| 162 $parent->removeChild($param); | |
| 163 } | |
| 108 } | 164 } |
| 109 } | 165 } |
| 110 ?> | 166 ?> |
