@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * Loop through sitemap items and see if one matches the requestUri. |
| 89 | 89 | * If it does, add it tot the matchedSitemapItems array |
| 90 | 90 | * |
| 91 | - * @param $request |
|
| 91 | + * @param Request $request |
|
| 92 | 92 | */ |
| 93 | 93 | private function sitemapMatching($request) |
| 94 | 94 | { |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param string $template |
| 151 | 151 | * @param array $parameters |
| 152 | 152 | * |
| 153 | - * @return mixed |
|
| 153 | + * @return Component |
|
| 154 | 154 | * @throws \Exception |
| 155 | 155 | */ |
| 156 | 156 | private function getComponentObject($class='', $template='', $parameters=array(), $matchedSitemapItem) |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @param array $replace |
| 112 | 112 | * @param string $delimiter |
| 113 | 113 | * |
| 114 | - * @return mixed|string |
|
| 114 | + * @return string |
|
| 115 | 115 | */ |
| 116 | 116 | function slugify($str, $replace=array(), $delimiter='-') { |
| 117 | 117 | if( !empty($replace) ) { |
@@ -130,7 +130,6 @@ discard block |
||
| 130 | 130 | * Dumps a var_dump of the passed arguments with <pre> tags surrounding it. |
| 131 | 131 | * Dies afterwards |
| 132 | 132 | * |
| 133 | - * @param mixed $data The data to be displayed |
|
| 134 | 133 | */ |
| 135 | 134 | function dump() |
| 136 | 135 | { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * JsonStorage constructor. |
| 19 | 19 | * |
| 20 | - * @param $storagePath |
|
| 20 | + * @param string $storagePath |
|
| 21 | 21 | */ |
| 22 | 22 | public function __construct($storagePath) |
| 23 | 23 | { |
@@ -837,6 +837,9 @@ discard block |
||
| 837 | 837 | } |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | + /** |
|
| 841 | + * @param string $path |
|
| 842 | + */ |
|
| 840 | 843 | private function validateFilename($filename, $path) |
| 841 | 844 | { |
| 842 | 845 | $fileParts = explode('.', $filename); |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | /** |
| 787 | 787 | * @param $filename |
| 788 | 788 | * @return null |
| 789 | - */ |
|
| 789 | + */ |
|
| 790 | 790 | public function getImageByName($filename) |
| 791 | 791 | { |
| 792 | 792 | $images = $this->getImages(); |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | /** |
| 877 | 877 | * @param $filename |
| 878 | 878 | * @return null |
| 879 | - */ |
|
| 879 | + */ |
|
| 880 | 880 | public function getFileByName($filename) |
| 881 | 881 | { |
| 882 | 882 | $files = $this->getFiles(); |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | /** |
| 892 | 892 | * @param $filename |
| 893 | 893 | * @throws \Exception |
| 894 | - */ |
|
| 894 | + */ |
|
| 895 | 895 | public function deleteFileByName($filename) |
| 896 | 896 | { |
| 897 | 897 | $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
@@ -62,8 +62,8 @@ |
||
| 62 | 62 | |
| 63 | 63 | // Preserve transparency |
| 64 | 64 | imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
| 65 | - imagealphablending($new, false); |
|
| 66 | - imagesavealpha($new, true); |
|
| 65 | + imagealphablending($new, false); |
|
| 66 | + imagesavealpha($new, true); |
|
| 67 | 67 | |
| 68 | 68 | imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $originalWidth, $originalHeight); |
| 69 | 69 | |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function shutdownHandler () { |
| 33 | 33 | $error = error_get_last(); |
| 34 | - if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { |
|
| 35 | - errorHandler($error['type'],$error['message'],$error['file'],$error['line']); |
|
| 36 | - }elseif ($error['type'] == 1) { |
|
| 37 | - dump($error); |
|
| 38 | - } |
|
| 34 | + if (isset($error['type'], $error['message'], $error['file'], $error['line'])) { |
|
| 35 | + errorHandler($error['type'],$error['message'],$error['file'],$error['line']); |
|
| 36 | + }elseif ($error['type'] == 1) { |
|
| 37 | + dump($error); |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -49,28 +49,28 @@ discard block |
||
| 49 | 49 | $jsonErrorNr = json_last_error(); |
| 50 | 50 | $errstr = ''; |
| 51 | 51 | switch ($jsonErrorNr) { |
| 52 | - case JSON_ERROR_NONE: |
|
| 53 | - $errstr .= ' - No errors' . PHP_EOL; |
|
| 54 | - break; |
|
| 55 | - case JSON_ERROR_DEPTH: |
|
| 56 | - $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL; |
|
| 57 | - break; |
|
| 58 | - case JSON_ERROR_STATE_MISMATCH: |
|
| 59 | - $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL; |
|
| 60 | - break; |
|
| 61 | - case JSON_ERROR_CTRL_CHAR: |
|
| 62 | - $errstr .= ' - Unexpected control character found' . PHP_EOL; |
|
| 63 | - break; |
|
| 64 | - case JSON_ERROR_SYNTAX: |
|
| 65 | - $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL; |
|
| 66 | - break; |
|
| 67 | - case JSON_ERROR_UTF8: |
|
| 68 | - $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL; |
|
| 69 | - break; |
|
| 70 | - default: |
|
| 71 | - $errstr = ' - Unknown error' . PHP_EOL; |
|
| 72 | - break; |
|
| 73 | - } |
|
| 52 | + case JSON_ERROR_NONE: |
|
| 53 | + $errstr .= ' - No errors' . PHP_EOL; |
|
| 54 | + break; |
|
| 55 | + case JSON_ERROR_DEPTH: |
|
| 56 | + $errstr .= ' - Maximum stack depth exceeded' . PHP_EOL; |
|
| 57 | + break; |
|
| 58 | + case JSON_ERROR_STATE_MISMATCH: |
|
| 59 | + $errstr .= ' - Underflow or the modes mismatch' . PHP_EOL; |
|
| 60 | + break; |
|
| 61 | + case JSON_ERROR_CTRL_CHAR: |
|
| 62 | + $errstr .= ' - Unexpected control character found' . PHP_EOL; |
|
| 63 | + break; |
|
| 64 | + case JSON_ERROR_SYNTAX: |
|
| 65 | + $errstr .= ' - Syntax error, malformed JSON' . PHP_EOL; |
|
| 66 | + break; |
|
| 67 | + case JSON_ERROR_UTF8: |
|
| 68 | + $errstr .= ' - Malformed UTF-8 characters, possibly incorrectly encoded' . PHP_EOL; |
|
| 69 | + break; |
|
| 70 | + default: |
|
| 71 | + $errstr = ' - Unknown error' . PHP_EOL; |
|
| 72 | + break; |
|
| 73 | + } |
|
| 74 | 74 | errorHandler ($jsonErrorNr, $errstr, $file, $line); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -86,14 +86,14 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function renderError ($message='', $file='', $line='', $code=0, $trace=array(), $httpHeader = 'HTTP/1.0 500 Internal Server Error') { |
| 88 | 88 | $file_lines = file_exists($file) ? file($file) : array(); |
| 89 | - $range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15); |
|
| 90 | - $lines = array(); |
|
| 89 | + $range = ($line - 15) < 0 ? range(1, 30) : range($line - 15, $line + 15); |
|
| 90 | + $lines = array(); |
|
| 91 | 91 | |
| 92 | - foreach ($range as $line_number) { |
|
| 93 | - if(isset($file_lines[$line_number-1])) { |
|
| 94 | - $lines[$line_number] = $file_lines[$line_number-1]; |
|
| 95 | - } |
|
| 96 | - } |
|
| 92 | + foreach ($range as $line_number) { |
|
| 93 | + if(isset($file_lines[$line_number-1])) { |
|
| 94 | + $lines[$line_number] = $file_lines[$line_number-1]; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | if (ob_get_contents()) ob_end_clean(); |
| 98 | 98 | $error = array( |
| 99 | 99 | 'message' => $message, |
@@ -62,8 +62,8 @@ |
||
| 62 | 62 | |
| 63 | 63 | // Preserve transparency |
| 64 | 64 | imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); |
| 65 | - imagealphablending($new, false); |
|
| 66 | - imagesavealpha($new, true); |
|
| 65 | + imagealphablending($new, false); |
|
| 66 | + imagesavealpha($new, true); |
|
| 67 | 67 | |
| 68 | 68 | imagecopyresampled($new, $imageResource, $this->_destX, $this->_destY, $this->_x, $this->_y, $this->_destWidth, $this->_destHeight, $originalWidth, $originalHeight); |
| 69 | 69 | |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | * @see http://www.php.net/manual/en/function.image-type-to-mime-type.php |
| 75 | 75 | * @param string $imagePath |
| 76 | 76 | * @param bool $getExtension |
| 77 | - * @return bool|int|string |
|
| 77 | + * @return integer |
|
| 78 | 78 | */ |
| 79 | 79 | public function GetImageMimeType($imagePath, $getExtension = false) |
| 80 | 80 | { |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | /** |
| 18 | 18 | * @param resource $imageResource |
| 19 | 19 | * @return resource |
| 20 | - */ |
|
| 20 | + */ |
|
| 21 | 21 | public function Execute($imageResource) |
| 22 | 22 | { |
| 23 | 23 | // Define the origial width and height |
@@ -105,7 +105,7 @@ |
||
| 105 | 105 | /** |
| 106 | 106 | * Detect if the language is switched manually |
| 107 | 107 | * |
| 108 | - * @param $request |
|
| 108 | + * @param Request $request |
|
| 109 | 109 | */ |
| 110 | 110 | private function checkLanguageSwitch($request) |
| 111 | 111 | { |
@@ -7,118 +7,118 @@ |
||
| 7 | 7 | |
| 8 | 8 | class LanguageComponent implements Component |
| 9 | 9 | { |
| 10 | - protected $request; |
|
| 11 | - protected $parameters; |
|
| 12 | - |
|
| 13 | - protected $defaultLanguage = 'en'; |
|
| 14 | - protected $acceptedLanguages = null; |
|
| 15 | - protected $languageParameterName = 'language'; |
|
| 16 | - protected $forceRedirect = false; |
|
| 17 | - protected $sessionValues; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Component constructor. |
|
| 21 | - * |
|
| 22 | - * @param $template |
|
| 23 | - * @param Request $request |
|
| 24 | - * @param $parameters |
|
| 25 | - * @param $matchedSitemapItem |
|
| 26 | - */ |
|
| 27 | - public function __construct($template, Request $request, $parameters, $matchedSitemapItem) |
|
| 28 | - { |
|
| 29 | - $this->parameters = (array) $parameters; |
|
| 30 | - $this->checkParameters(); |
|
| 31 | - |
|
| 32 | - $lang = substr(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $this->defaultLanguage, 0, 2); |
|
| 33 | - $_SESSION['LanguageComponent']['detectedLanguage'] = $lang; |
|
| 34 | - |
|
| 35 | - $this->checkLanguageSwitch($request); |
|
| 36 | - |
|
| 37 | - if (!isset($_SESSION['LanguageComponent'][$this->languageParameterName])) { |
|
| 38 | - $this->detectLanguage($lang, $request); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName]; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Checks to see if any parameters are given from the configuration in the CMS |
|
| 46 | - */ |
|
| 47 | - private function checkParameters() |
|
| 48 | - { |
|
| 49 | - if (isset($this->parameters['defaultLanguage'])) { |
|
| 50 | - $this->defaultLanguage = $this->parameters['defaultLanguage']; |
|
| 51 | - unset($this->parameters['defaultLanguage']); |
|
| 52 | - } |
|
| 53 | - if (isset($this->parameters['acceptedLanguages'])) { |
|
| 54 | - $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']); |
|
| 55 | - unset($this->parameters['acceptedLanguages']); |
|
| 56 | - } |
|
| 57 | - if (isset($this->parameters['languageParameterName'])) { |
|
| 58 | - $this->languageParameterName = $this->parameters['languageParameterName']; |
|
| 59 | - unset($this->parameters['languageParameterName']); |
|
| 60 | - } |
|
| 61 | - if (isset($this->parameters['forceRedirect'])) { |
|
| 62 | - $this->forceRedirect = (bool) $this->parameters['forceRedirect']; |
|
| 63 | - unset($this->parameters['forceRedirect']); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return array |
|
| 69 | - */ |
|
| 70 | - public function getParameters() |
|
| 71 | - { |
|
| 72 | - return $this->parameters; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Check if the found language is allowed and |
|
| 78 | - * if an action is to be taken. |
|
| 79 | - * |
|
| 80 | - * @param $lang |
|
| 81 | - * @param $request |
|
| 82 | - */ |
|
| 83 | - private function detectLanguage($lang, $request) |
|
| 84 | - { |
|
| 85 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage; |
|
| 86 | - |
|
| 87 | - if ($this->acceptedLanguages === null) { |
|
| 88 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
| 89 | - } else if (in_array($lang, $this->acceptedLanguages)) { |
|
| 90 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
| 91 | - } else { |
|
| 92 | - $lang = $this->defaultLanguage; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $this->sessionValues = $_SESSION['LanguageComponent']; |
|
| 96 | - |
|
| 97 | - if ($this->forceRedirect === true) { |
|
| 98 | - if (substr($request::$relativeUri, 0, 2) !== $lang && $lang !== $this->defaultLanguage) { // if default language detected, no redirect |
|
| 99 | - header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
| 100 | - exit; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Detect if the language is switched manually |
|
| 107 | - * |
|
| 108 | - * @param $request |
|
| 109 | - */ |
|
| 110 | - private function checkLanguageSwitch($request) |
|
| 111 | - { |
|
| 112 | - if (isset($request::$get['langSwitch'])) { |
|
| 113 | - $this->forceRedirect = true; |
|
| 114 | - $this->detectLanguage($request::$get['langSwitch'], $request); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /* |
|
| 10 | + protected $request; |
|
| 11 | + protected $parameters; |
|
| 12 | + |
|
| 13 | + protected $defaultLanguage = 'en'; |
|
| 14 | + protected $acceptedLanguages = null; |
|
| 15 | + protected $languageParameterName = 'language'; |
|
| 16 | + protected $forceRedirect = false; |
|
| 17 | + protected $sessionValues; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Component constructor. |
|
| 21 | + * |
|
| 22 | + * @param $template |
|
| 23 | + * @param Request $request |
|
| 24 | + * @param $parameters |
|
| 25 | + * @param $matchedSitemapItem |
|
| 26 | + */ |
|
| 27 | + public function __construct($template, Request $request, $parameters, $matchedSitemapItem) |
|
| 28 | + { |
|
| 29 | + $this->parameters = (array) $parameters; |
|
| 30 | + $this->checkParameters(); |
|
| 31 | + |
|
| 32 | + $lang = substr(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $this->defaultLanguage, 0, 2); |
|
| 33 | + $_SESSION['LanguageComponent']['detectedLanguage'] = $lang; |
|
| 34 | + |
|
| 35 | + $this->checkLanguageSwitch($request); |
|
| 36 | + |
|
| 37 | + if (!isset($_SESSION['LanguageComponent'][$this->languageParameterName])) { |
|
| 38 | + $this->detectLanguage($lang, $request); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName]; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Checks to see if any parameters are given from the configuration in the CMS |
|
| 46 | + */ |
|
| 47 | + private function checkParameters() |
|
| 48 | + { |
|
| 49 | + if (isset($this->parameters['defaultLanguage'])) { |
|
| 50 | + $this->defaultLanguage = $this->parameters['defaultLanguage']; |
|
| 51 | + unset($this->parameters['defaultLanguage']); |
|
| 52 | + } |
|
| 53 | + if (isset($this->parameters['acceptedLanguages'])) { |
|
| 54 | + $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']); |
|
| 55 | + unset($this->parameters['acceptedLanguages']); |
|
| 56 | + } |
|
| 57 | + if (isset($this->parameters['languageParameterName'])) { |
|
| 58 | + $this->languageParameterName = $this->parameters['languageParameterName']; |
|
| 59 | + unset($this->parameters['languageParameterName']); |
|
| 60 | + } |
|
| 61 | + if (isset($this->parameters['forceRedirect'])) { |
|
| 62 | + $this->forceRedirect = (bool) $this->parameters['forceRedirect']; |
|
| 63 | + unset($this->parameters['forceRedirect']); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return array |
|
| 69 | + */ |
|
| 70 | + public function getParameters() |
|
| 71 | + { |
|
| 72 | + return $this->parameters; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Check if the found language is allowed and |
|
| 78 | + * if an action is to be taken. |
|
| 79 | + * |
|
| 80 | + * @param $lang |
|
| 81 | + * @param $request |
|
| 82 | + */ |
|
| 83 | + private function detectLanguage($lang, $request) |
|
| 84 | + { |
|
| 85 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage; |
|
| 86 | + |
|
| 87 | + if ($this->acceptedLanguages === null) { |
|
| 88 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
| 89 | + } else if (in_array($lang, $this->acceptedLanguages)) { |
|
| 90 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
| 91 | + } else { |
|
| 92 | + $lang = $this->defaultLanguage; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $this->sessionValues = $_SESSION['LanguageComponent']; |
|
| 96 | + |
|
| 97 | + if ($this->forceRedirect === true) { |
|
| 98 | + if (substr($request::$relativeUri, 0, 2) !== $lang && $lang !== $this->defaultLanguage) { // if default language detected, no redirect |
|
| 99 | + header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
| 100 | + exit; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Detect if the language is switched manually |
|
| 107 | + * |
|
| 108 | + * @param $request |
|
| 109 | + */ |
|
| 110 | + private function checkLanguageSwitch($request) |
|
| 111 | + { |
|
| 112 | + if (isset($request::$get['langSwitch'])) { |
|
| 113 | + $this->forceRedirect = true; |
|
| 114 | + $this->detectLanguage($request::$get['langSwitch'], $request); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /* |
|
| 119 | 119 | * These functions are required by the interface, but not for the functionality |
| 120 | 120 | */ |
| 121 | - function run(Storage $storage) {} |
|
| 122 | - function render() {} |
|
| 123 | - function get() {} |
|
| 121 | + function run(Storage $storage) {} |
|
| 122 | + function render() {} |
|
| 123 | + function get() {} |
|
| 124 | 124 | } |
| 125 | 125 | \ No newline at end of file |