@@ -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 | |
@@ -40,7 +40,9 @@ |
||
| 40 | 40 | |
| 41 | 41 | // Define which ratio will be used, depending on which is the biggest side |
| 42 | 42 | $ratio = $wRatio < $hRatio ? $wRatio : $hRatio; |
| 43 | - if ($ratio < 1) $ratio = 1; |
|
| 43 | + if ($ratio < 1) { |
|
| 44 | + $ratio = 1; |
|
| 45 | + } |
|
| 44 | 46 | |
| 45 | 47 | // Calculate the destination width, height, x and y |
| 46 | 48 | $this->_destWidth = $originalWidth / $ratio; |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | $output = ''; |
| 50 | 50 | for ($i = 0; $i < $count; $i += 16) { |
| 51 | 51 | $random_state = |
| 52 | - md5(microtime() . $random_state); |
|
| 52 | + md5(microtime().$random_state); |
|
| 53 | 53 | $output .= |
| 54 | 54 | pack('H*', md5($random_state)); |
| 55 | 55 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | spl_autoload_extensions('.php'); |
| 3 | 3 | spl_autoload_register("autoloader"); |
| 4 | 4 | |
| 5 | -$rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)) . '/../../') . '/'); |
|
| 5 | +$rootPath = str_replace('\\', '/', realpath(str_replace('\\', '/', dirname(__FILE__)).'/../../').'/'); |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * The function to be registered as the default autoload functino |
@@ -32,14 +32,14 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | global $rootPath; |
| 35 | - $file = $rootPath . str_replace('\\', '/', $class) . ".php"; |
|
| 35 | + $file = $rootPath.str_replace('\\', '/', $class).".php"; |
|
| 36 | 36 | $debug_backtrace = debug_backtrace(); |
| 37 | 37 | |
| 38 | 38 | if (file_exists($file)) { |
| 39 | 39 | require_once($file); |
| 40 | 40 | if ($throwException) { |
| 41 | 41 | if (class_exists($class, false) == false && interface_exists($class, false) == false) { |
| 42 | - throw new \Exception('Could not load class "' . $class . '" in file ' . $file); |
|
| 42 | + throw new \Exception('Could not load class "'.$class.'" in file '.$file); |
|
| 43 | 43 | } else { |
| 44 | 44 | return true; |
| 45 | 45 | } |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | } else { |
| 49 | 49 | if (isset($debug_backtrace[2]) && isset($debug_backtrace[2]['file']) && isset($debug_backtrace[2]['line'])) { |
| 50 | 50 | if ($throwException) { |
| 51 | - errorHandler(0, 'Could not load class \'' . $class . '\' in file ' . $rootPath . $file, $debug_backtrace[2]['file'], $debug_backtrace[2]['line']); |
|
| 51 | + errorHandler(0, 'Could not load class \''.$class.'\' in file '.$rootPath.$file, $debug_backtrace[2]['file'], $debug_backtrace[2]['line']); |
|
| 52 | 52 | } else { |
| 53 | 53 | return false; |
| 54 | 54 | } |
| 55 | 55 | } else { |
| 56 | 56 | if ($throwException) { |
| 57 | - throw new \Exception('Could not load class "' . $class . '" in file ' . $file . "\n" . 'Called from unknown origin.'); |
|
| 57 | + throw new \Exception('Could not load class "'.$class.'" in file '.$file."\n".'Called from unknown origin.'); |
|
| 58 | 58 | } else { |
| 59 | 59 | return false; |
| 60 | 60 | } |
@@ -61,12 +61,15 @@ |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | function humanFileSize($size,$unit="") { |
| 64 | - if( (!$unit && $size >= 1<<30) || $unit == "GB") |
|
| 65 | - return number_format($size/(1<<30),2)."GB"; |
|
| 66 | - if( (!$unit && $size >= 1<<20) || $unit == "MB") |
|
| 67 | - return number_format($size/(1<<20),2)."MB"; |
|
| 68 | - if( (!$unit && $size >= 1<<10) || $unit == "KB") |
|
| 69 | - return number_format($size/(1<<10),2)."KB"; |
|
| 64 | + if( (!$unit && $size >= 1<<30) || $unit == "GB") { |
|
| 65 | + return number_format($size/(1<<30),2)."GB"; |
|
| 66 | + } |
|
| 67 | + if( (!$unit && $size >= 1<<20) || $unit == "MB") { |
|
| 68 | + return number_format($size/(1<<20),2)."MB"; |
|
| 69 | + } |
|
| 70 | + if( (!$unit && $size >= 1<<10) || $unit == "KB") { |
|
| 71 | + return number_format($size/(1<<10),2)."KB"; |
|
| 72 | + } |
|
| 70 | 73 | return number_format($size)." bytes"; |
| 71 | 74 | } |
| 72 | 75 | |
@@ -116,7 +116,7 @@ |
||
| 116 | 116 | * @param array $replace |
| 117 | 117 | * @param string $delimiter |
| 118 | 118 | * |
| 119 | - * @return mixed|string |
|
| 119 | + * @return string |
|
| 120 | 120 | */ |
| 121 | 121 | function slugify($str, $replace=array(), $delimiter='-') { |
| 122 | 122 | if( !empty($replace) ) { |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | return '0 seconds'; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - $a = array( 365 * 24 * 60 * 60 => 'year', |
|
| 41 | + $a = array(365 * 24 * 60 * 60 => 'year', |
|
| 42 | 42 | 30 * 24 * 60 * 60 => 'month', |
| 43 | 43 | 24 * 60 * 60 => 'day', |
| 44 | 44 | 60 * 60 => 'hour', |
| 45 | 45 | 60 => 'minute', |
| 46 | 46 | 1 => 'second' |
| 47 | 47 | ); |
| 48 | - $a_plural = array( 'year' => 'years', |
|
| 48 | + $a_plural = array('year' => 'years', |
|
| 49 | 49 | 'month' => 'months', |
| 50 | 50 | 'day' => 'days', |
| 51 | 51 | 'hour' => 'hours', |
@@ -59,19 +59,19 @@ discard block |
||
| 59 | 59 | if ($d >= 1) |
| 60 | 60 | { |
| 61 | 61 | $r = round($d); |
| 62 | - return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago'; |
|
| 62 | + return $r.' '.($r > 1 ? $a_plural[$str] : $str).' ago'; |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | return 0; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | -function humanFileSize($size,$unit="") { |
|
| 69 | - if( (!$unit && $size >= 1<<30) || $unit == "GB") |
|
| 70 | - return number_format($size/(1<<30),2)."GB"; |
|
| 71 | - if( (!$unit && $size >= 1<<20) || $unit == "MB") |
|
| 72 | - return number_format($size/(1<<20),2)."MB"; |
|
| 73 | - if( (!$unit && $size >= 1<<10) || $unit == "KB") |
|
| 74 | - return number_format($size/(1<<10),2)."KB"; |
|
| 68 | +function humanFileSize($size, $unit = "") { |
|
| 69 | + if ((!$unit && $size >= 1 << 30) || $unit == "GB") |
|
| 70 | + return number_format($size / (1 << 30), 2)."GB"; |
|
| 71 | + if ((!$unit && $size >= 1 << 20) || $unit == "MB") |
|
| 72 | + return number_format($size / (1 << 20), 2)."MB"; |
|
| 73 | + if ((!$unit && $size >= 1 << 10) || $unit == "KB") |
|
| 74 | + return number_format($size / (1 << 10), 2)."KB"; |
|
| 75 | 75 | return number_format($size)." bytes"; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return mixed|string |
| 120 | 120 | */ |
| 121 | -function slugify($str, $replace=array(), $delimiter='-') { |
|
| 122 | - if( !empty($replace) ) { |
|
| 123 | - $str = str_replace((array)$replace, ' ', $str); |
|
| 121 | +function slugify($str, $replace = array(), $delimiter = '-') { |
|
| 122 | + if (!empty($replace)) { |
|
| 123 | + $str = str_replace((array) $replace, ' ', $str); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | $debug_backtrace = current(debug_backtrace()); |
| 145 | 145 | if (PHP_SAPI == 'cli') { |
| 146 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 146 | + echo 'Dump: '.$debug_backtrace['file'].':'.$debug_backtrace['line']."\n"; |
|
| 147 | 147 | foreach (func_get_args() as $data) { |
| 148 | 148 | var_dump($data); |
| 149 | 149 | } |
| 150 | 150 | } else { |
| 151 | 151 | ob_clean(); |
| 152 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 152 | + echo '<div>Dump: '.$debug_backtrace['file'].':<b>'.$debug_backtrace['line']."</b></div>"; |
|
| 153 | 153 | echo '<pre>'; |
| 154 | 154 | foreach (func_get_args() as $data) { |
| 155 | 155 | echo "<code>"; |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | function utf8Convert($array) |
| 192 | 192 | { |
| 193 | - array_walk_recursive($array, function(&$item, $key){ |
|
| 194 | - if(!mb_detect_encoding($item, 'utf-8', true)){ |
|
| 193 | + array_walk_recursive($array, function(&$item, $key) { |
|
| 194 | + if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
| 195 | 195 | $item = utf8_encode($item); |
| 196 | 196 | } |
| 197 | 197 | }); |
@@ -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 | |
@@ -6,12 +6,12 @@ discard block |
||
| 6 | 6 | } |
| 7 | 7 | ?> |
| 8 | 8 | <div class="rte"> |
| 9 | - <div id="summernote_<?=str_replace(']', '-', str_replace('[','-', $fieldPrefix)) . $field->slug?>_rte_<?=$summernoteInstances?>" class="summernote"><?=isset($value) ? $value : '' ?></div> |
|
| 9 | + <div id="summernote_<?=str_replace(']', '-', str_replace('[', '-', $fieldPrefix)).$field->slug?>_rte_<?=$summernoteInstances?>" class="summernote"><?=isset($value) ? $value : '' ?></div> |
|
| 10 | 10 | </div> |
| 11 | 11 | <textarea style="display:none;" id="summernote_<?=$field->slug?>_container_<?=$summernoteInstances?>" name="<?=$fieldPrefix?>[<?=$field->slug?>][]"></textarea> |
| 12 | 12 | <script> |
| 13 | 13 | $(document).ready(function () { |
| 14 | - $('#summernote_<?=str_replace(']', '-', str_replace('[','-', $fieldPrefix)) . $field->slug?>_rte_<?=$summernoteInstances?>').summernote({ |
|
| 14 | + $('#summernote_<?=str_replace(']', '-', str_replace('[', '-', $fieldPrefix)).$field->slug?>_rte_<?=$summernoteInstances?>').summernote({ |
|
| 15 | 15 | height: 300, |
| 16 | 16 | toolbar: [ |
| 17 | 17 | //[groupname, [button list]] |
@@ -29,4 +29,4 @@ discard block |
||
| 29 | 29 | if (!isset($GLOBALS['rteList'])) { |
| 30 | 30 | $GLOBALS['rteList'] = array(); |
| 31 | 31 | } |
| 32 | -$GLOBALS['rteList'][] = 'summernote_' . str_replace(']', '-', str_replace('[','-', $fieldPrefix)) . $field->slug . '_rte_' . $summernoteInstances ?> |
|
| 32 | +$GLOBALS['rteList'][] = 'summernote_'.str_replace(']', '-', str_replace('[', '-', $fieldPrefix)).$field->slug.'_rte_'.$summernoteInstances ?> |
|
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param array $parameters |
| 42 | 42 | * @param $matchedSitemapItem |
| 43 | 43 | */ |
| 44 | - public function __construct($template='', Request $request, $parameters=array(), $matchedSitemapItem) |
|
| 44 | + public function __construct($template = '', Request $request, $parameters = array(), $matchedSitemapItem) |
|
| 45 | 45 | { |
| 46 | 46 | $this->template = $template; |
| 47 | 47 | $this->request = $request; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @throws \Exception |
| 69 | 69 | */ |
| 70 | - public function render($application=null) |
|
| 70 | + public function render($application = null) |
|
| 71 | 71 | { |
| 72 | 72 | $this->renderedContent = $this->renderTemplate($this->template, true, $application); |
| 73 | 73 | } |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | * @return string |
| 94 | 94 | * @throws \Exception |
| 95 | 95 | */ |
| 96 | - public function renderTemplate($template='', $obClean = true, $application=null) |
|
| 96 | + public function renderTemplate($template = '', $obClean = true, $application = null) |
|
| 97 | 97 | { |
| 98 | - $templatePath = __DIR__ . '/../../templates/' . $template . '.php'; |
|
| 98 | + $templatePath = __DIR__.'/../../templates/'.$template.'.php'; |
|
| 99 | 99 | if (realpath($templatePath) !== false) { |
| 100 | 100 | if ($obClean) { |
| 101 | 101 | ob_clean(); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | return ob_get_contents(); |
| 113 | 113 | } else { |
| 114 | 114 | if ($template !== null) { // If template is null, its a application component, which doesnt have a template |
| 115 | - throw new \Exception('Couldnt find template ' . $templatePath); |
|
| 115 | + throw new \Exception('Couldnt find template '.$templatePath); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @return string |
| 128 | 128 | * @throws \Exception |
| 129 | 129 | */ |
| 130 | - public function includeTemplate($template='', $parameters = array()) |
|
| 130 | + public function includeTemplate($template = '', $parameters = array()) |
|
| 131 | 131 | { |
| 132 | 132 | if (is_array($parameters)) { |
| 133 | 133 | foreach ($parameters as $name => $value) { |
@@ -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 | { |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | |
| 97 | 97 | if ($this->forceRedirect === true) { |
| 98 | 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); |
|
| 99 | + header('Location: '.$request::$subfolders.$lang.'/'.$request::$relativeUri); |
|
| 100 | 100 | exit; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -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 | - public function run(Storage $storage) {} |
|
| 122 | - public function render() {} |
|
| 123 | - public function get() {} |
|
| 121 | + public function run(Storage $storage) {} |
|
| 122 | + public function render() {} |
|
| 123 | + public function get() {} |
|
| 124 | 124 | } |
| 125 | 125 | \ No newline at end of file |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | if (isset($this->parameters['document'])) { |
| 84 | 84 | $this->runByDocumentParameter(); |
| 85 | 85 | } else { |
| 86 | - throw new \Exception('When not using a regex, you need to set the parameter `document` with the path to the document in this sitemap item: ' . $this->matchedSitemapItem->title); |
|
| 86 | + throw new \Exception('When not using a regex, you need to set the parameter `document` with the path to the document in this sitemap item: '.$this->matchedSitemapItem->title); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | $relativeDocumentUri = current($this->matchedSitemapItem->matches[1]); |
| 101 | 101 | if (isset($this->parameters['folder'])) { |
| 102 | 102 | if (substr($this->parameters['folder'], -1) !== '/') { |
| 103 | - $this->parameters['folder'] = $this->parameters['folder'] . '/'; |
|
| 103 | + $this->parameters['folder'] = $this->parameters['folder'].'/'; |
|
| 104 | 104 | } |
| 105 | - $relativeDocumentUri = $this->parameters['folder'] . $relativeDocumentUri; |
|
| 105 | + $relativeDocumentUri = $this->parameters['folder'].$relativeDocumentUri; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | $document = $this->storage->getDocumentBySlug($relativeDocumentUri); |