@@ -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 | } |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | $imageContent = file_get_contents($imageContainer); |
| 33 | 33 | $this->_imageResource = imagecreatefromstring($imageContent); |
| 34 | 34 | } |
| 35 | - } elseif(is_string($imageContainer)) { |
|
| 35 | + } elseif (is_string($imageContainer)) { |
|
| 36 | 36 | $this->_imageResource = imagecreatefromstring($imageContainer); |
| 37 | 37 | } else { |
| 38 | - throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>' . var_export($imageContainer, true) . '</pre>'); |
|
| 38 | + throw new \Exception('Could not create image resource, accepted inputs are: "resource of type (gd)", path_to_image and "string". <br /><pre>'.var_export($imageContainer, true).'</pre>'); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | if ($mimeTypeConstantValue == IMAGETYPE_GIF) { |
| 57 | 57 | return imagegif($imageResource, $path); |
| 58 | - } elseif ($mimeTypeConstantValue == IMAGETYPE_JPEG) { |
|
| 58 | + } elseif ($mimeTypeConstantValue == IMAGETYPE_JPEG) { |
|
| 59 | 59 | return imagejpeg($imageResource, $path, $quality); |
| 60 | 60 | } elseif ($mimeTypeConstantValue == IMAGETYPE_PNG) { |
| 61 | - return imagepng($imageResource, $path, (intval($quality / 10) -1)); |
|
| 61 | + return imagepng($imageResource, $path, (intval($quality / 10) - 1)); |
|
| 62 | 62 | } |
| 63 | 63 | else { |
| 64 | 64 | throw new \Exception('Not a valid mimetypeconstant given see function documentation'); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | if (function_exists('exif_imagetype')) { |
| 80 | 80 | $exif = exif_imagetype($imagePath); |
| 81 | 81 | } else { |
| 82 | - if ((list($width, $height, $type, $attr) = getimagesize($imagePath)) !== false ) { |
|
| 82 | + if ((list($width, $height, $type, $attr) = getimagesize($imagePath)) !== false) { |
|
| 83 | 83 | $exif = $type; |
| 84 | 84 | } else { |
| 85 | 85 | $exif = false; |
@@ -99,86 +99,86 @@ discard block |
||
| 99 | 99 | public function CreateImageFromBmp($p_sFile) |
| 100 | 100 | { |
| 101 | 101 | // Load the image into a string |
| 102 | - $file = fopen($p_sFile,"rb"); |
|
| 103 | - $read = fread($file,10); |
|
| 104 | - while(!feof($file)&&($read<>"")) |
|
| 105 | - $read .= fread($file,1024); |
|
| 102 | + $file = fopen($p_sFile, "rb"); |
|
| 103 | + $read = fread($file, 10); |
|
| 104 | + while (!feof($file) && ($read <> "")) |
|
| 105 | + $read .= fread($file, 1024); |
|
| 106 | 106 | |
| 107 | - $temp = unpack("H*",$read); |
|
| 108 | - $hex = $temp[1]; |
|
| 109 | - $header = substr($hex,0,108); |
|
| 110 | - $width=null; |
|
| 111 | - $height=null; |
|
| 107 | + $temp = unpack("H*", $read); |
|
| 108 | + $hex = $temp[1]; |
|
| 109 | + $header = substr($hex, 0, 108); |
|
| 110 | + $width = null; |
|
| 111 | + $height = null; |
|
| 112 | 112 | |
| 113 | 113 | // Process the header |
| 114 | 114 | // Structure: http://www.fastgraph.com/help/bmp_header_format.html |
| 115 | - if (substr($header,0,4)=="424d") |
|
| 115 | + if (substr($header, 0, 4) == "424d") |
|
| 116 | 116 | { |
| 117 | 117 | // Cut it in parts of 2 bytes |
| 118 | - $header_parts = str_split($header,2); |
|
| 118 | + $header_parts = str_split($header, 2); |
|
| 119 | 119 | |
| 120 | 120 | // Get the width 4 bytes |
| 121 | - $width = hexdec($header_parts[19].$header_parts[18]); |
|
| 121 | + $width = hexdec($header_parts[19].$header_parts[18]); |
|
| 122 | 122 | |
| 123 | 123 | // Get the height 4 bytes |
| 124 | - $height = hexdec($header_parts[23].$header_parts[22]); |
|
| 124 | + $height = hexdec($header_parts[23].$header_parts[22]); |
|
| 125 | 125 | |
| 126 | 126 | // Unset the header params |
| 127 | 127 | unset($header_parts); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Define starting X and Y |
| 131 | - $x = 0; |
|
| 132 | - $y = 1; |
|
| 131 | + $x = 0; |
|
| 132 | + $y = 1; |
|
| 133 | 133 | |
| 134 | 134 | // Create newimage |
| 135 | - $image = imagecreatetruecolor($width,$height); |
|
| 135 | + $image = imagecreatetruecolor($width, $height); |
|
| 136 | 136 | |
| 137 | 137 | // Grab the body from the image |
| 138 | - $body = substr($hex,108); |
|
| 138 | + $body = substr($hex, 108); |
|
| 139 | 139 | |
| 140 | 140 | // Calculate if padding at the end-line is needed |
| 141 | 141 | // Divided by two to keep overview. |
| 142 | 142 | // 1 byte = 2 HEX-chars |
| 143 | - $body_size = (strlen($body)/2); |
|
| 144 | - $header_size = ($width*$height); |
|
| 143 | + $body_size = (strlen($body) / 2); |
|
| 144 | + $header_size = ($width * $height); |
|
| 145 | 145 | |
| 146 | 146 | // Use end-line padding? Only when needed |
| 147 | - $usePadding = ($body_size>($header_size*3)+4); |
|
| 147 | + $usePadding = ($body_size > ($header_size * 3) + 4); |
|
| 148 | 148 | |
| 149 | 149 | // Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption |
| 150 | 150 | // Calculate the next DWORD-position in the body |
| 151 | - for ($i=0;$i<$body_size;$i+=3) |
|
| 151 | + for ($i = 0; $i < $body_size; $i += 3) |
|
| 152 | 152 | { |
| 153 | 153 | // Calculate line-ending and padding |
| 154 | - if ($x>=$width) |
|
| 154 | + if ($x >= $width) |
|
| 155 | 155 | { |
| 156 | 156 | // If padding needed, ignore image-padding |
| 157 | 157 | // Shift i to the ending of the current 32-bit-block |
| 158 | 158 | if ($usePadding) |
| 159 | - $i += $width%4; |
|
| 159 | + $i += $width % 4; |
|
| 160 | 160 | |
| 161 | 161 | // Reset horizontal position |
| 162 | - $x = 0; |
|
| 162 | + $x = 0; |
|
| 163 | 163 | |
| 164 | 164 | // Raise the height-position (bottom-up) |
| 165 | 165 | $y++; |
| 166 | 166 | |
| 167 | 167 | // Reached the image-height? Break the for-loop |
| 168 | - if ($y>$height) |
|
| 168 | + if ($y > $height) |
|
| 169 | 169 | break; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // Calculation of the RGB-pixel (defined as BGR in image-data) |
| 173 | 173 | // Define $i_pos as absolute position in the body |
| 174 | - $i_pos = $i*2; |
|
| 175 | - $r = hexdec($body[$i_pos+4].$body[$i_pos+5]); |
|
| 176 | - $g = hexdec($body[$i_pos+2].$body[$i_pos+3]); |
|
| 177 | - $b = hexdec($body[$i_pos].$body[$i_pos+1]); |
|
| 174 | + $i_pos = $i * 2; |
|
| 175 | + $r = hexdec($body[$i_pos + 4].$body[$i_pos + 5]); |
|
| 176 | + $g = hexdec($body[$i_pos + 2].$body[$i_pos + 3]); |
|
| 177 | + $b = hexdec($body[$i_pos].$body[$i_pos + 1]); |
|
| 178 | 178 | |
| 179 | 179 | // Calculate and draw the pixel |
| 180 | - $color = imagecolorallocate($image,$r,$g,$b); |
|
| 181 | - imagesetpixel($image,$x,$height-$y,$color); |
|
| 180 | + $color = imagecolorallocate($image, $r, $g, $b); |
|
| 181 | + imagesetpixel($image, $x, $height - $y, $color); |
|
| 182 | 182 | |
| 183 | 183 | // Raise the horizontal position |
| 184 | 184 | $x++; |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | return imagejpeg($imageResource, $path, $quality); |
| 62 | 62 | } elseif ($mimeTypeConstantValue == IMAGETYPE_PNG) { |
| 63 | 63 | return imagepng($imageResource, $path, (intval($quality / 10) -1)); |
| 64 | - } |
|
| 65 | - else { |
|
| 64 | + } else { |
|
| 66 | 65 | throw new \Exception('Not a valid mimetypeconstant given see function documentation'); |
| 67 | 66 | } |
| 68 | 67 | } |
@@ -103,8 +102,9 @@ discard block |
||
| 103 | 102 | // Load the image into a string |
| 104 | 103 | $file = fopen($p_sFile,"rb"); |
| 105 | 104 | $read = fread($file,10); |
| 106 | - while(!feof($file)&&($read<>"")) |
|
| 107 | - $read .= fread($file,1024); |
|
| 105 | + while(!feof($file)&&($read<>"")) { |
|
| 106 | + $read .= fread($file,1024); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | $temp = unpack("H*",$read); |
| 110 | 110 | $hex = $temp[1]; |
@@ -157,8 +157,9 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | // If padding needed, ignore image-padding |
| 159 | 159 | // Shift i to the ending of the current 32-bit-block |
| 160 | - if ($usePadding) |
|
| 161 | - $i += $width%4; |
|
| 160 | + if ($usePadding) { |
|
| 161 | + $i += $width%4; |
|
| 162 | + } |
|
| 162 | 163 | |
| 163 | 164 | // Reset horizontal position |
| 164 | 165 | $x = 0; |
@@ -167,8 +168,9 @@ discard block |
||
| 167 | 168 | $y++; |
| 168 | 169 | |
| 169 | 170 | // Reached the image-height? Break the for-loop |
| 170 | - if ($y>$height) |
|
| 171 | - break; |
|
| 171 | + if ($y>$height) { |
|
| 172 | + break; |
|
| 173 | + } |
|
| 172 | 174 | } |
| 173 | 175 | |
| 174 | 176 | // Calculation of the RGB-pixel (defined as BGR in image-data) |
@@ -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 | { |
@@ -7,124 +7,124 @@ |
||
| 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 | - } else { |
|
| 40 | - if ($this->forceRedirect === true) { |
|
| 41 | - $this->detectLanguage($_SESSION['LanguageComponent'][$this->languageParameterName], $request); |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName]; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Checks to see if any parameters are given from the configuration in the CMS |
|
| 50 | - */ |
|
| 51 | - private function checkParameters() |
|
| 52 | - { |
|
| 53 | - if (isset($this->parameters['defaultLanguage'])) { |
|
| 54 | - $this->defaultLanguage = $this->parameters['defaultLanguage']; |
|
| 55 | - unset($this->parameters['defaultLanguage']); |
|
| 56 | - } |
|
| 57 | - if (isset($this->parameters['acceptedLanguages'])) { |
|
| 58 | - $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']); |
|
| 59 | - unset($this->parameters['acceptedLanguages']); |
|
| 60 | - } |
|
| 61 | - if (isset($this->parameters['languageParameterName'])) { |
|
| 62 | - $this->languageParameterName = $this->parameters['languageParameterName']; |
|
| 63 | - unset($this->parameters['languageParameterName']); |
|
| 64 | - } |
|
| 65 | - if (isset($this->parameters['forceRedirect'])) { |
|
| 66 | - $this->forceRedirect = (bool) $this->parameters['forceRedirect']; |
|
| 67 | - unset($this->parameters['forceRedirect']); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - public function getParameters() |
|
| 75 | - { |
|
| 76 | - return $this->parameters; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Check if the found language is allowed and |
|
| 82 | - * if an action is to be taken. |
|
| 83 | - * |
|
| 84 | - * @param $lang |
|
| 85 | - * @param $request |
|
| 86 | - */ |
|
| 87 | - private function detectLanguage($lang, $request) |
|
| 88 | - { |
|
| 89 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage; |
|
| 90 | - |
|
| 91 | - if ($this->acceptedLanguages === null) { |
|
| 92 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
| 93 | - } else if (in_array($lang, $this->acceptedLanguages)) { |
|
| 94 | - $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
| 95 | - } else { |
|
| 96 | - $lang = $this->defaultLanguage; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $this->sessionValues = $_SESSION['LanguageComponent']; |
|
| 100 | - |
|
| 101 | - if ($this->forceRedirect === true) { |
|
| 102 | - if (substr($request::$relativeUri, 0, 2) !== $lang ) { |
|
| 103 | - if ($lang !== $this->defaultLanguage) { |
|
| 104 | - header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
| 105 | - exit; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Detect if the language is switched manually |
|
| 113 | - * |
|
| 114 | - * @param $request |
|
| 115 | - */ |
|
| 116 | - private function checkLanguageSwitch($request) |
|
| 117 | - { |
|
| 118 | - if (isset($request::$get['langSwitch'])) { |
|
| 119 | - $this->forceRedirect = true; |
|
| 120 | - $this->detectLanguage($request::$get['langSwitch'], $request); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /* |
|
| 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 | + } else { |
|
| 40 | + if ($this->forceRedirect === true) { |
|
| 41 | + $this->detectLanguage($_SESSION['LanguageComponent'][$this->languageParameterName], $request); |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName]; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Checks to see if any parameters are given from the configuration in the CMS |
|
| 50 | + */ |
|
| 51 | + private function checkParameters() |
|
| 52 | + { |
|
| 53 | + if (isset($this->parameters['defaultLanguage'])) { |
|
| 54 | + $this->defaultLanguage = $this->parameters['defaultLanguage']; |
|
| 55 | + unset($this->parameters['defaultLanguage']); |
|
| 56 | + } |
|
| 57 | + if (isset($this->parameters['acceptedLanguages'])) { |
|
| 58 | + $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']); |
|
| 59 | + unset($this->parameters['acceptedLanguages']); |
|
| 60 | + } |
|
| 61 | + if (isset($this->parameters['languageParameterName'])) { |
|
| 62 | + $this->languageParameterName = $this->parameters['languageParameterName']; |
|
| 63 | + unset($this->parameters['languageParameterName']); |
|
| 64 | + } |
|
| 65 | + if (isset($this->parameters['forceRedirect'])) { |
|
| 66 | + $this->forceRedirect = (bool) $this->parameters['forceRedirect']; |
|
| 67 | + unset($this->parameters['forceRedirect']); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + public function getParameters() |
|
| 75 | + { |
|
| 76 | + return $this->parameters; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Check if the found language is allowed and |
|
| 82 | + * if an action is to be taken. |
|
| 83 | + * |
|
| 84 | + * @param $lang |
|
| 85 | + * @param $request |
|
| 86 | + */ |
|
| 87 | + private function detectLanguage($lang, $request) |
|
| 88 | + { |
|
| 89 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage; |
|
| 90 | + |
|
| 91 | + if ($this->acceptedLanguages === null) { |
|
| 92 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
| 93 | + } else if (in_array($lang, $this->acceptedLanguages)) { |
|
| 94 | + $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang; |
|
| 95 | + } else { |
|
| 96 | + $lang = $this->defaultLanguage; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $this->sessionValues = $_SESSION['LanguageComponent']; |
|
| 100 | + |
|
| 101 | + if ($this->forceRedirect === true) { |
|
| 102 | + if (substr($request::$relativeUri, 0, 2) !== $lang ) { |
|
| 103 | + if ($lang !== $this->defaultLanguage) { |
|
| 104 | + header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
| 105 | + exit; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Detect if the language is switched manually |
|
| 113 | + * |
|
| 114 | + * @param $request |
|
| 115 | + */ |
|
| 116 | + private function checkLanguageSwitch($request) |
|
| 117 | + { |
|
| 118 | + if (isset($request::$get['langSwitch'])) { |
|
| 119 | + $this->forceRedirect = true; |
|
| 120 | + $this->detectLanguage($request::$get['langSwitch'], $request); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /* |
|
| 125 | 125 | * These functions are required by the interface, but not for the functionality |
| 126 | 126 | */ |
| 127 | - public function run(Storage $storage) {} |
|
| 128 | - public function render() {} |
|
| 129 | - public function get() {} |
|
| 127 | + public function run(Storage $storage) {} |
|
| 128 | + public function render() {} |
|
| 129 | + public function get() {} |
|
| 130 | 130 | } |
| 131 | 131 | \ No newline at end of file |
@@ -99,9 +99,9 @@ |
||
| 99 | 99 | $this->sessionValues = $_SESSION['LanguageComponent']; |
| 100 | 100 | |
| 101 | 101 | if ($this->forceRedirect === true) { |
| 102 | - if (substr($request::$relativeUri, 0, 2) !== $lang ) { |
|
| 102 | + if (substr($request::$relativeUri, 0, 2) !== $lang) { |
|
| 103 | 103 | if ($lang !== $this->defaultLanguage) { |
| 104 | - header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri); |
|
| 104 | + header('Location: '.$request::$subfolders.$lang.'/'.$request::$relativeUri); |
|
| 105 | 105 | exit; |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -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); |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.1/js/bootstrap.min.js"></script> |
| 4 | 4 | <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> |
| 5 | 5 | <script>var smallestImage = '<?=$smallestImage?>';</script> |
| 6 | -<?$copyable=''?> |
|
| 6 | +<?$copyable = ''?> |
|
| 7 | 7 | <section class="documents"> |
| 8 | 8 | <h2><i class="fa fa-file-text-o"></i> Documents</h2> |
| 9 | 9 | <nav class="actions"> |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | </div> |
| 24 | 24 | </li> |
| 25 | 25 | </ul> |
| 26 | - <?include('document-form-form.php');?> |
|
| 26 | + <?include('document-form-form.php'); ?> |
|
| 27 | 27 | </section> |
| 28 | 28 | |
| 29 | 29 | <script> |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | return $returnFileNames; |
| 45 | 45 | } else { |
| 46 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 46 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | * @return string |
| 55 | 55 | * @throws \Exception |
| 56 | 56 | */ |
| 57 | - public function resize($imagePath='', $width='',$height='') |
|
| 57 | + public function resize($imagePath = '', $width = '', $height = '') |
|
| 58 | 58 | { |
| 59 | - $modifier = '-r' . $width . 'x' . $height; |
|
| 60 | - return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
| 59 | + $modifier = '-r'.$width.'x'.$height; |
|
| 60 | + return $this->applyMethod('Resize', $imagePath, $width, $height, $modifier); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | * @return string |
| 68 | 68 | * @throws \Exception |
| 69 | 69 | */ |
| 70 | - public function smartcrop($imagePath='', $width='',$height='') |
|
| 70 | + public function smartcrop($imagePath = '', $width = '', $height = '') |
|
| 71 | 71 | { |
| 72 | - $modifier = '-s' . $width . 'x' . $height; |
|
| 73 | - return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
| 72 | + $modifier = '-s'.$width.'x'.$height; |
|
| 73 | + return $this->applyMethod('SmartCrop', $imagePath, $width, $height, $modifier); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | * @throws \Exception |
| 82 | 82 | */ |
| 83 | - public function boxcrop($imagePath='', $width='',$height='') |
|
| 83 | + public function boxcrop($imagePath = '', $width = '', $height = '') |
|
| 84 | 84 | { |
| 85 | - $modifier = '-b' . $width . 'x' . $height; |
|
| 86 | - return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
| 85 | + $modifier = '-b'.$width.'x'.$height; |
|
| 86 | + return $this->applyMethod('BoxCrop', $imagePath, $width, $height, $modifier); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return string |
| 94 | 94 | */ |
| 95 | - private function modifyName($imagePath, $modifier='') |
|
| 95 | + private function modifyName($imagePath, $modifier = '') |
|
| 96 | 96 | { |
| 97 | 97 | $filename = basename($imagePath); |
| 98 | 98 | $path = dirname($imagePath); |
@@ -102,30 +102,30 @@ discard block |
||
| 102 | 102 | array_pop($fileParts); |
| 103 | 103 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 104 | 104 | $fileNameWithoutExtension = slugify($fileNameWithoutExtension); |
| 105 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
| 105 | + $filename = $fileNameWithoutExtension.$modifier.'.'.$extension; |
|
| 106 | 106 | } else { |
| 107 | 107 | $filename = slugify($filename); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if (file_exists($path . '/' . $filename)) { |
|
| 110 | + if (file_exists($path.'/'.$filename)) { |
|
| 111 | 111 | $fileParts = explode('.', $filename); |
| 112 | 112 | if (count($fileParts) > 1) { |
| 113 | 113 | $extension = end($fileParts); |
| 114 | 114 | array_pop($fileParts); |
| 115 | 115 | $fileNameWithoutExtension = implode('-', $fileParts); |
| 116 | 116 | $fileNameWithoutExtension .= '-copy'; |
| 117 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
| 117 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
| 118 | 118 | } else { |
| 119 | 119 | $filename .= '-copy'; |
| 120 | 120 | } |
| 121 | - return $this->modifyName($path . '/' . $filename); |
|
| 121 | + return $this->modifyName($path.'/'.$filename); |
|
| 122 | 122 | } |
| 123 | - return $path . '/' . $filename; |
|
| 123 | + return $path.'/'.$filename; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | private function applyMethod($method, $imagePath, $width, $height, $modifier) |
| 127 | 127 | { |
| 128 | - $method = 'library\\images\\methods\\' . $method; |
|
| 128 | + $method = 'library\\images\\methods\\'.$method; |
|
| 129 | 129 | $destination = $this->modifyName($imagePath, $modifier); |
| 130 | 130 | if (file_exists($imagePath)) { |
| 131 | 131 | $image = new Image(); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $resizedImage->SaveImage($destination, $resizedImage->GetImageMimeType($imagePath), 80); |
| 140 | 140 | return basename($destination); |
| 141 | 141 | } else { |
| 142 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
| 142 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -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,7 +59,7 @@ 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; |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | * @param string $unit |
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | -function humanFileSize($size,$unit="") { |
|
| 77 | - if( (!$unit && $size >= 1<<30) || $unit == "GB") |
|
| 78 | - return number_format($size/(1<<30),2)."GB"; |
|
| 79 | - if( (!$unit && $size >= 1<<20) || $unit == "MB") |
|
| 80 | - return number_format($size/(1<<20),2)."MB"; |
|
| 81 | - if( (!$unit && $size >= 1<<10) || $unit == "KB") |
|
| 82 | - return number_format($size/(1<<10),2)."KB"; |
|
| 76 | +function humanFileSize($size, $unit = "") { |
|
| 77 | + if ((!$unit && $size >= 1 << 30) || $unit == "GB") |
|
| 78 | + return number_format($size / (1 << 30), 2)."GB"; |
|
| 79 | + if ((!$unit && $size >= 1 << 20) || $unit == "MB") |
|
| 80 | + return number_format($size / (1 << 20), 2)."MB"; |
|
| 81 | + if ((!$unit && $size >= 1 << 10) || $unit == "KB") |
|
| 82 | + return number_format($size / (1 << 10), 2)."KB"; |
|
| 83 | 83 | return number_format($size)." bytes"; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @return mixed|string |
| 135 | 135 | */ |
| 136 | -function slugify($str, $replace=array(), $delimiter='-') { |
|
| 137 | - if( !empty($replace) ) { |
|
| 138 | - $str = str_replace((array)$replace, ' ', $str); |
|
| 136 | +function slugify($str, $replace = array(), $delimiter = '-') { |
|
| 137 | + if (!empty($replace)) { |
|
| 138 | + $str = str_replace((array) $replace, ' ', $str); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); |
@@ -158,13 +158,13 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | $debug_backtrace = current(debug_backtrace()); |
| 160 | 160 | if (PHP_SAPI == 'cli') { |
| 161 | - echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n"; |
|
| 161 | + echo 'Dump: '.$debug_backtrace['file'].':'.$debug_backtrace['line']."\n"; |
|
| 162 | 162 | foreach (func_get_args() as $data) { |
| 163 | 163 | var_dump($data); |
| 164 | 164 | } |
| 165 | 165 | } else { |
| 166 | 166 | ob_clean(); |
| 167 | - echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>"; |
|
| 167 | + echo '<div>Dump: '.$debug_backtrace['file'].':<b>'.$debug_backtrace['line']."</b></div>"; |
|
| 168 | 168 | echo '<pre>'; |
| 169 | 169 | foreach (func_get_args() as $data) { |
| 170 | 170 | echo "<code>"; |
@@ -214,8 +214,8 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | function utf8Convert($array) |
| 216 | 216 | { |
| 217 | - array_walk_recursive($array, function(&$item, $key){ |
|
| 218 | - if(!mb_detect_encoding($item, 'utf-8', true)){ |
|
| 217 | + array_walk_recursive($array, function(&$item, $key) { |
|
| 218 | + if (!mb_detect_encoding($item, 'utf-8', true)) { |
|
| 219 | 219 | $item = utf8_encode($item); |
| 220 | 220 | } |
| 221 | 221 | }); |
@@ -74,12 +74,15 @@ |
||
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | 76 | function humanFileSize($size,$unit="") { |
| 77 | - if( (!$unit && $size >= 1<<30) || $unit == "GB") |
|
| 78 | - return number_format($size/(1<<30),2)."GB"; |
|
| 79 | - if( (!$unit && $size >= 1<<20) || $unit == "MB") |
|
| 80 | - return number_format($size/(1<<20),2)."MB"; |
|
| 81 | - if( (!$unit && $size >= 1<<10) || $unit == "KB") |
|
| 82 | - return number_format($size/(1<<10),2)."KB"; |
|
| 77 | + if( (!$unit && $size >= 1<<30) || $unit == "GB") { |
|
| 78 | + return number_format($size/(1<<30),2)."GB"; |
|
| 79 | + } |
|
| 80 | + if( (!$unit && $size >= 1<<20) || $unit == "MB") { |
|
| 81 | + return number_format($size/(1<<20),2)."MB"; |
|
| 82 | + } |
|
| 83 | + if( (!$unit && $size >= 1<<10) || $unit == "KB") { |
|
| 84 | + return number_format($size/(1<<10),2)."KB"; |
|
| 85 | + } |
|
| 83 | 86 | return number_format($size)." bytes"; |
| 84 | 87 | } |
| 85 | 88 | |