| @@ -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 | |
| @@ -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 | -    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 | 
| @@ -18,7 +18,7 @@ discard block | ||
| 18 | 18 | |
| 19 | 19 | /** | 
| 20 | 20 | * @var null | 
| 21 | - */ | |
| 21 | + */ | |
| 22 | 22 | protected $subTemplate = null; | 
| 23 | 23 | |
| 24 | 24 | /** | 
| @@ -139,7 +139,7 @@ discard block | ||
| 139 | 139 | /** | 
| 140 | 140 | * @param $remoteAddress | 
| 141 | 141 | * @throws \Exception | 
| 142 | - */ | |
| 142 | + */ | |
| 143 | 143 | private function checkWhiteList($remoteAddress) | 
| 144 | 144 |  		{ | 
| 145 | 145 |  			if (isset($this->parameters['whitelistIps'])) { | 
| @@ -154,7 +154,7 @@ discard block | ||
| 154 | 154 | /** | 
| 155 | 155 | * @param $remoteAddress | 
| 156 | 156 | * @throws \Exception | 
| 157 | - */ | |
| 157 | + */ | |
| 158 | 158 | private function checkBlackList($remoteAddress) | 
| 159 | 159 |  		{ | 
| 160 | 160 |  			if (isset($this->parameters['blacklistIps'])) { | 
| @@ -169,7 +169,7 @@ discard block | ||
| 169 | 169 | /** | 
| 170 | 170 | * @param $request | 
| 171 | 171 | * @return mixed|string | 
| 172 | - */ | |
| 172 | + */ | |
| 173 | 173 | private function getRelativeCmsUri($request) | 
| 174 | 174 |  		{ | 
| 175 | 175 | // TODO Use regex match parameter instead of calculating relative uri | 
| @@ -184,7 +184,7 @@ discard block | ||
| 184 | 184 | /** | 
| 185 | 185 | * @param $request | 
| 186 | 186 | * @param $relativeCmsUri | 
| 187 | - */ | |
| 187 | + */ | |
| 188 | 188 | private function documentsRouting($request, $relativeCmsUri) | 
| 189 | 189 |  		{ | 
| 190 | 190 |  			if ($relativeCmsUri == '/documents') { | 
| @@ -199,7 +199,7 @@ discard block | ||
| 199 | 199 | /** | 
| 200 | 200 | * @param $request | 
| 201 | 201 | * @param $relativeCmsUri | 
| 202 | - */ | |
| 202 | + */ | |
| 203 | 203 | private function sitemapRouting($request, $relativeCmsUri) | 
| 204 | 204 |  		{ | 
| 205 | 205 |  			if ($relativeCmsUri == '/sitemap') { | 
| @@ -237,7 +237,7 @@ discard block | ||
| 237 | 237 | /** | 
| 238 | 238 | * @param $request | 
| 239 | 239 | * @param $relativeCmsUri | 
| 240 | - */ | |
| 240 | + */ | |
| 241 | 241 | private function imagesRouting($request, $relativeCmsUri) | 
| 242 | 242 |  		{ | 
| 243 | 243 |  			if ($relativeCmsUri == '/images') { | 
| @@ -269,7 +269,7 @@ discard block | ||
| 269 | 269 | |
| 270 | 270 | /** | 
| 271 | 271 | * @param $relativeCmsUri | 
| 272 | - */ | |
| 272 | + */ | |
| 273 | 273 | private function apiRouting($relativeCmsUri) | 
| 274 | 274 |  		{ | 
| 275 | 275 |  			if ($relativeCmsUri == '/images.json') { | 
| @@ -287,7 +287,7 @@ discard block | ||
| 287 | 287 | /** | 
| 288 | 288 | * @param $request | 
| 289 | 289 | * @param $relativeCmsUri | 
| 290 | - */ | |
| 290 | + */ | |
| 291 | 291 | private function filesRouting($request, $relativeCmsUri) | 
| 292 | 292 |  		{ | 
| 293 | 293 |  			if ($relativeCmsUri == '/files') { | 
| @@ -313,7 +313,7 @@ discard block | ||
| 313 | 313 | |
| 314 | 314 | /** | 
| 315 | 315 | * @param $slug | 
| 316 | - */ | |
| 316 | + */ | |
| 317 | 317 | private function downloadFile($slug) | 
| 318 | 318 |  		{ | 
| 319 | 319 | $file = $this->storage->getFileByName($slug); | 
| @@ -338,7 +338,7 @@ discard block | ||
| 338 | 338 | /** | 
| 339 | 339 | * @param $request | 
| 340 | 340 | * @param $relativeCmsUri | 
| 341 | - */ | |
| 341 | + */ | |
| 342 | 342 | private function configurationRouting($request, $relativeCmsUri) | 
| 343 | 343 |  		{ | 
| 344 | 344 |  			if ($relativeCmsUri == '/configuration') { | 
| @@ -357,7 +357,7 @@ discard block | ||
| 357 | 357 | * @param $request | 
| 358 | 358 | * @param $relativeCmsUri | 
| 359 | 359 | * @throws \Exception | 
| 360 | - */ | |
| 360 | + */ | |
| 361 | 361 | private function documentRouting($request, $relativeCmsUri) | 
| 362 | 362 |  		{ | 
| 363 | 363 |  			if ($relativeCmsUri == '/documents/new-document' && isset($request::$get['path'])) { | 
| @@ -412,7 +412,7 @@ discard block | ||
| 412 | 412 | /** | 
| 413 | 413 | * @param $request | 
| 414 | 414 | * @param $relativeCmsUri | 
| 415 | - */ | |
| 415 | + */ | |
| 416 | 416 | private function folderRouting($request, $relativeCmsUri) | 
| 417 | 417 |  		{ | 
| 418 | 418 |  			if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get['path'])) { | 
| @@ -453,7 +453,7 @@ discard block | ||
| 453 | 453 | /** | 
| 454 | 454 | * @param $request | 
| 455 | 455 | * @param $relativeCmsUri | 
| 456 | - */ | |
| 456 | + */ | |
| 457 | 457 | private function usersRouting($request, $relativeCmsUri) | 
| 458 | 458 |  		{ | 
| 459 | 459 |  			if ($relativeCmsUri == '/configuration/users') { | 
| @@ -487,7 +487,7 @@ discard block | ||
| 487 | 487 | /** | 
| 488 | 488 | * @param $request | 
| 489 | 489 | * @param $relativeCmsUri | 
| 490 | - */ | |
| 490 | + */ | |
| 491 | 491 | private function documentTypesRouting($request, $relativeCmsUri) | 
| 492 | 492 |  		{ | 
| 493 | 493 |  			if ($relativeCmsUri == '/configuration/document-types') { | 
| @@ -526,7 +526,7 @@ discard block | ||
| 526 | 526 | /** | 
| 527 | 527 | * @param $request | 
| 528 | 528 | * @param $relativeCmsUri | 
| 529 | - */ | |
| 529 | + */ | |
| 530 | 530 | private function bricksRouting($request, $relativeCmsUri) | 
| 531 | 531 |  		{ | 
| 532 | 532 |  			if ($relativeCmsUri == '/configuration/bricks') { | 
| @@ -565,7 +565,7 @@ discard block | ||
| 565 | 565 | /** | 
| 566 | 566 | * @param $request | 
| 567 | 567 | * @param $relativeCmsUri | 
| 568 | - */ | |
| 568 | + */ | |
| 569 | 569 | private function imageSetRouting($request, $relativeCmsUri) | 
| 570 | 570 |  		{ | 
| 571 | 571 |  			if ($relativeCmsUri == '/configuration/image-set') { | 
| @@ -600,7 +600,7 @@ discard block | ||
| 600 | 600 | /** | 
| 601 | 601 | * @param $request | 
| 602 | 602 | * @param $relativeCmsUri | 
| 603 | - */ | |
| 603 | + */ | |
| 604 | 604 | private function applicationComponentRouting($request, $relativeCmsUri) | 
| 605 | 605 |  		{ | 
| 606 | 606 |  			if ($relativeCmsUri == '/configuration/application-components') { | 
| @@ -132,7 +132,7 @@ discard block | ||
| 132 | 132 | |
| 133 | 133 | /** | 
| 134 | 134 | * Sets variables needed for rendering the form template | 
| 135 | - * @param $storage | |
| 135 | + * @param Storage $storage | |
| 136 | 136 | */ | 
| 137 | 137 | private function initialize($storage) | 
| 138 | 138 |      { | 
| @@ -168,7 +168,7 @@ discard block | ||
| 168 | 168 | * submitting the form | 
| 169 | 169 | * | 
| 170 | 170 | * @param $postValues | 
| 171 | - * @param $storage | |
| 171 | + * @param Storage $storage | |
| 172 | 172 | */ | 
| 173 | 173 | protected function postSubmit($postValues, $storage) | 
| 174 | 174 |      {} | 
| @@ -191,7 +191,7 @@ discard block | ||
| 191 | 191 | /** | 
| 192 | 192 | * Checks if this form has been submitted | 
| 193 | 193 | * | 
| 194 | - * @param $request | |
| 194 | + * @param \library\cc\Request $request | |
| 195 | 195 | * @return bool | 
| 196 | 196 | */ | 
| 197 | 197 | private function isFormSubmitted($request) | 
| @@ -202,7 +202,7 @@ discard block | ||
| 202 | 202 | /** | 
| 203 | 203 | * | 
| 204 | 204 | * | 
| 205 | - * @param $request | |
| 205 | + * @param \library\cc\Request $request | |
| 206 | 206 | */ | 
| 207 | 207 | private function getPostValues($request) | 
| 208 | 208 |      { | 
| @@ -7,248 +7,248 @@ | ||
| 7 | 7 | |
| 8 | 8 | class FormComponent Extends BaseComponent | 
| 9 | 9 |  { | 
| 10 | - /** | |
| 11 | - * @var null|string | |
| 12 | - */ | |
| 13 | - protected $documentType = null; | |
| 14 | - /** | |
| 15 | - * @var null|string | |
| 16 | - */ | |
| 17 | - protected $responseFolder = null; | |
| 18 | - /** | |
| 19 | - * @var string | |
| 20 | - */ | |
| 21 | - protected $subTemplate = 'cms/documents/document-form-form'; | |
| 22 | - /** | |
| 23 | - * @var string | |
| 24 | - */ | |
| 25 | - protected $formParameterName = 'form'; | |
| 26 | - /** | |
| 27 | - * @var string | |
| 28 | - */ | |
| 29 | - protected $thankYouMessage = 'Thank you for sending us your response.'; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * @var bool | |
| 33 | - */ | |
| 34 | - protected $submitOncePerSession = false; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * @var string | |
| 38 | - */ | |
| 39 | - private $formId; | |
| 40 | - /** | |
| 41 | - * @var null|string | |
| 42 | - */ | |
| 43 | - private $getPathBackup = null; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * @var null|\stdClass | |
| 47 | - */ | |
| 48 | - private $userSessionBackup = null; | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * @param Storage $storage | |
| 52 | - * @return void | |
| 53 | - * @throws \Exception | |
| 54 | - */ | |
| 55 | - public function run(Storage $storage) | |
| 56 | -    { | |
| 57 | - parent::run($storage); | |
| 58 | - | |
| 59 | - $this->checkParameters(); | |
| 60 | - | |
| 61 | -        if ($this->documentType === null || $this->responseFolder === null) { | |
| 62 | -            throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form'); | |
| 63 | - } | |
| 64 | - | |
| 65 | - $this->setFormId(); | |
| 66 | - $this->initialize($storage); | |
| 67 | - $this->checkSubmit($storage); | |
| 68 | - } | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * @param null|Application $application | |
| 72 | - * @throws \Exception | |
| 73 | - */ | |
| 74 | - public function render($application = null) | |
| 75 | -    { | |
| 76 | - $request = $this->request; | |
| 77 | -        if (isset($request::$get['path'])) { | |
| 78 | - $this->getPathBackup = $request::$get['path']; | |
| 79 | - } | |
| 80 | - $request::$get['path'] = $this->responseFolder; | |
| 81 | - $form = $this->renderTemplate($this->subTemplate); | |
| 82 | -        if ($this->getPathBackup !== null) { | |
| 83 | - $request::$get['path'] = $this->getPathBackup; | |
| 84 | -        } else { | |
| 85 | - unset($request::$get['path']); | |
| 86 | - } | |
| 87 | -        if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) { | |
| 88 | - $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage; | |
| 89 | -        } else { | |
| 90 | - $this->parameters[$this->formParameterName] = $form; | |
| 91 | - } | |
| 92 | - | |
| 93 | - parent::render($application); | |
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * Checks if parameters were given in the CMS configuration and | |
| 98 | - * sets them to their respective fields | |
| 99 | - */ | |
| 100 | - private function checkParameters() | |
| 101 | -    { | |
| 102 | -        if (isset($this->parameters['documentType'])) { | |
| 103 | - $this->documentType = $this->parameters['documentType']; | |
| 104 | - unset($this->parameters['documentType']); | |
| 105 | - } | |
| 106 | - | |
| 107 | -        if (isset($this->parameters['responseFolder'])) { | |
| 108 | - $this->responseFolder = $this->parameters['responseFolder']; | |
| 109 | - unset($this->parameters['responseFolder']); | |
| 110 | - } | |
| 111 | - | |
| 112 | -        if (isset($this->parameters['subTemplate'])) { | |
| 113 | - $this->subTemplate = $this->parameters['subTemplate']; | |
| 114 | - unset($this->parameters['subTemplate']); | |
| 115 | - } | |
| 116 | - | |
| 117 | -        if (isset($this->parameters['formParameterName'])) { | |
| 118 | - $this->formParameterName = $this->parameters['formParameterName']; | |
| 119 | - unset($this->parameters['formParameterName']); | |
| 120 | - } | |
| 121 | - | |
| 122 | -        if (isset($this->parameters['thankYouMessage'])) { | |
| 123 | - $this->thankYouMessage = $this->parameters['thankYouMessage']; | |
| 124 | - unset($this->parameters['thankYouMessage']); | |
| 125 | - } | |
| 126 | - | |
| 127 | -        if (isset($this->parameters['submitOncePerSession'])) { | |
| 128 | - $this->submitOncePerSession = $this->parameters['submitOncePerSession'] === 'true' ? true : false; | |
| 129 | - unset($this->parameters['submitOncePerSession']); | |
| 130 | - } | |
| 131 | - } | |
| 132 | - | |
| 133 | - /** | |
| 134 | - * Sets variables needed for rendering the form template | |
| 135 | - * @param $storage | |
| 136 | - */ | |
| 137 | - private function initialize($storage) | |
| 138 | -    { | |
| 139 | - $this->parameters['smallestImage'] = $storage->getSmallestImageSet()->slug; | |
| 140 | - $this->parameters['cmsPrefix'] = ''; | |
| 141 | - | |
| 142 | - $this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->documentType, true); | |
| 143 | - $this->parameters['documentTypes'] = $this->storage->getDocumentTypes(); | |
| 144 | - $this->parameters['hideTitleAndState'] = true; | |
| 145 | - $this->parameters['formId'] = $this->formId; | |
| 146 | - } | |
| 147 | - | |
| 148 | - /** | |
| 149 | - * If the form has been submitted, save the document | |
| 150 | - * Calls $this->postSubmit() afterwards | |
| 151 | - * | |
| 152 | - * @param Storage $storage | |
| 153 | - */ | |
| 154 | - private function checkSubmit($storage) | |
| 155 | -    { | |
| 156 | -        if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) { | |
| 157 | - $postValues = $this->getPostValues($this->request); | |
| 158 | - $this->setUserSessionBackup(); | |
| 159 | - $storage->addDocument($postValues); | |
| 160 | - $this->restoreUserSessionBackup(); | |
| 161 | - $this->setSubmitToSession(); | |
| 162 | - $this->postSubmit($postValues, $storage); | |
| 163 | - } | |
| 164 | - } | |
| 165 | - | |
| 166 | - /** | |
| 167 | - * Hook for derived classes to take actions after | |
| 168 | - * submitting the form | |
| 169 | - * | |
| 170 | - * @param $postValues | |
| 171 | - * @param $storage | |
| 172 | - */ | |
| 173 | - protected function postSubmit($postValues, $storage) | |
| 174 | -    {} | |
| 175 | - | |
| 176 | - /** | |
| 177 | - * Sets a unique id for this particular form, so it can recognize | |
| 178 | - * it when a submit occurs | |
| 179 | - */ | |
| 180 | - private function setFormId() | |
| 181 | -    { | |
| 182 | -        if (isset($_SESSION['FormComponent'][$this->formParameterName]['formId'])) { | |
| 183 | - $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId']; | |
| 184 | -        } else { | |
| 185 | - $_SESSION['FormComponent'][$this->formParameterName]['formId'] = (string) microtime(true); | |
| 186 | - $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = false; | |
| 187 | - $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId']; | |
| 188 | - } | |
| 189 | - } | |
| 190 | - | |
| 191 | - /** | |
| 192 | - * Checks if this form has been submitted | |
| 193 | - * | |
| 194 | - * @param $request | |
| 195 | - * @return bool | |
| 196 | - */ | |
| 197 | - private function isFormSubmitted($request) | |
| 198 | -    { | |
| 199 | - return !empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]['formId']) && $_SESSION['FormComponent'][$this->formParameterName]['formId'] === $this->formId; | |
| 200 | - } | |
| 201 | - | |
| 202 | - /** | |
| 203 | - * | |
| 204 | - * | |
| 205 | - * @param $request | |
| 206 | - */ | |
| 207 | - private function getPostValues($request) | |
| 208 | -    { | |
| 209 | - $postValues = $request::$post; | |
| 210 | - $postValues['documentType'] = $this->documentType; | |
| 211 | - $postValues['path'] = $this->responseFolder; | |
| 212 | -        $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; | |
| 213 | - return $postValues; | |
| 214 | - } | |
| 215 | - | |
| 216 | - /** | |
| 217 | - * Temporarily stores the current user session in a backup variable | |
| 218 | - * and sets a fake user instead | |
| 219 | - */ | |
| 220 | - private function setUserSessionBackup() | |
| 221 | -    { | |
| 222 | - $this->userSessionBackup = isset($_SESSION['cloudcontrol']) ? $_SESSION['cloudcontrol'] : null; | |
| 223 | - $fakeUser = new \stdClass(); | |
| 224 | - $fakeUser->username = 'FormComponent'; | |
| 225 | - $_SESSION['cloudcontrol'] = $fakeUser; | |
| 226 | - } | |
| 227 | - | |
| 228 | - /** | |
| 229 | - * Removes the fake user and restores the existing user | |
| 230 | - * session if it was there | |
| 231 | - */ | |
| 232 | - private function restoreUserSessionBackup() | |
| 233 | -    { | |
| 234 | -        if ($this->userSessionBackup === null) { | |
| 235 | - unset($_SESSION['cloudcontrol']); | |
| 236 | -        } else { | |
| 237 | - $_SESSION['cloudcontrol'] = $this->userSessionBackup; | |
| 238 | - } | |
| 239 | - } | |
| 240 | - | |
| 241 | - private function setSubmitToSession() | |
| 242 | -    { | |
| 243 | - $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = true; | |
| 244 | - } | |
| 245 | - | |
| 246 | - private function isSubmitAllowed() | |
| 247 | -    { | |
| 248 | -        if ($this->submitOncePerSession === true && $_SESSION['FormComponent'][$this->formParameterName]['submitted'] === true) { | |
| 249 | - return false; | |
| 250 | -        } else { | |
| 251 | - return true; | |
| 252 | - } | |
| 253 | - } | |
| 10 | + /** | |
| 11 | + * @var null|string | |
| 12 | + */ | |
| 13 | + protected $documentType = null; | |
| 14 | + /** | |
| 15 | + * @var null|string | |
| 16 | + */ | |
| 17 | + protected $responseFolder = null; | |
| 18 | + /** | |
| 19 | + * @var string | |
| 20 | + */ | |
| 21 | + protected $subTemplate = 'cms/documents/document-form-form'; | |
| 22 | + /** | |
| 23 | + * @var string | |
| 24 | + */ | |
| 25 | + protected $formParameterName = 'form'; | |
| 26 | + /** | |
| 27 | + * @var string | |
| 28 | + */ | |
| 29 | + protected $thankYouMessage = 'Thank you for sending us your response.'; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @var bool | |
| 33 | + */ | |
| 34 | + protected $submitOncePerSession = false; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * @var string | |
| 38 | + */ | |
| 39 | + private $formId; | |
| 40 | + /** | |
| 41 | + * @var null|string | |
| 42 | + */ | |
| 43 | + private $getPathBackup = null; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @var null|\stdClass | |
| 47 | + */ | |
| 48 | + private $userSessionBackup = null; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * @param Storage $storage | |
| 52 | + * @return void | |
| 53 | + * @throws \Exception | |
| 54 | + */ | |
| 55 | + public function run(Storage $storage) | |
| 56 | +	{ | |
| 57 | + parent::run($storage); | |
| 58 | + | |
| 59 | + $this->checkParameters(); | |
| 60 | + | |
| 61 | +		if ($this->documentType === null || $this->responseFolder === null) { | |
| 62 | +			throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form'); | |
| 63 | + } | |
| 64 | + | |
| 65 | + $this->setFormId(); | |
| 66 | + $this->initialize($storage); | |
| 67 | + $this->checkSubmit($storage); | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * @param null|Application $application | |
| 72 | + * @throws \Exception | |
| 73 | + */ | |
| 74 | + public function render($application = null) | |
| 75 | +	{ | |
| 76 | + $request = $this->request; | |
| 77 | +		if (isset($request::$get['path'])) { | |
| 78 | + $this->getPathBackup = $request::$get['path']; | |
| 79 | + } | |
| 80 | + $request::$get['path'] = $this->responseFolder; | |
| 81 | + $form = $this->renderTemplate($this->subTemplate); | |
| 82 | +		if ($this->getPathBackup !== null) { | |
| 83 | + $request::$get['path'] = $this->getPathBackup; | |
| 84 | +		} else { | |
| 85 | + unset($request::$get['path']); | |
| 86 | + } | |
| 87 | +		if ($this->isFormSubmitted($this->request) || $this->isSubmitAllowed() === false) { | |
| 88 | + $this->parameters[$this->formParameterName] = '<a name="' . $this->formId . '"></a>' . $this->thankYouMessage; | |
| 89 | +		} else { | |
| 90 | + $this->parameters[$this->formParameterName] = $form; | |
| 91 | + } | |
| 92 | + | |
| 93 | + parent::render($application); | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * Checks if parameters were given in the CMS configuration and | |
| 98 | + * sets them to their respective fields | |
| 99 | + */ | |
| 100 | + private function checkParameters() | |
| 101 | +	{ | |
| 102 | +		if (isset($this->parameters['documentType'])) { | |
| 103 | + $this->documentType = $this->parameters['documentType']; | |
| 104 | + unset($this->parameters['documentType']); | |
| 105 | + } | |
| 106 | + | |
| 107 | +		if (isset($this->parameters['responseFolder'])) { | |
| 108 | + $this->responseFolder = $this->parameters['responseFolder']; | |
| 109 | + unset($this->parameters['responseFolder']); | |
| 110 | + } | |
| 111 | + | |
| 112 | +		if (isset($this->parameters['subTemplate'])) { | |
| 113 | + $this->subTemplate = $this->parameters['subTemplate']; | |
| 114 | + unset($this->parameters['subTemplate']); | |
| 115 | + } | |
| 116 | + | |
| 117 | +		if (isset($this->parameters['formParameterName'])) { | |
| 118 | + $this->formParameterName = $this->parameters['formParameterName']; | |
| 119 | + unset($this->parameters['formParameterName']); | |
| 120 | + } | |
| 121 | + | |
| 122 | +		if (isset($this->parameters['thankYouMessage'])) { | |
| 123 | + $this->thankYouMessage = $this->parameters['thankYouMessage']; | |
| 124 | + unset($this->parameters['thankYouMessage']); | |
| 125 | + } | |
| 126 | + | |
| 127 | +		if (isset($this->parameters['submitOncePerSession'])) { | |
| 128 | + $this->submitOncePerSession = $this->parameters['submitOncePerSession'] === 'true' ? true : false; | |
| 129 | + unset($this->parameters['submitOncePerSession']); | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * Sets variables needed for rendering the form template | |
| 135 | + * @param $storage | |
| 136 | + */ | |
| 137 | + private function initialize($storage) | |
| 138 | +	{ | |
| 139 | + $this->parameters['smallestImage'] = $storage->getSmallestImageSet()->slug; | |
| 140 | + $this->parameters['cmsPrefix'] = ''; | |
| 141 | + | |
| 142 | + $this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->documentType, true); | |
| 143 | + $this->parameters['documentTypes'] = $this->storage->getDocumentTypes(); | |
| 144 | + $this->parameters['hideTitleAndState'] = true; | |
| 145 | + $this->parameters['formId'] = $this->formId; | |
| 146 | + } | |
| 147 | + | |
| 148 | + /** | |
| 149 | + * If the form has been submitted, save the document | |
| 150 | + * Calls $this->postSubmit() afterwards | |
| 151 | + * | |
| 152 | + * @param Storage $storage | |
| 153 | + */ | |
| 154 | + private function checkSubmit($storage) | |
| 155 | +	{ | |
| 156 | +		if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) { | |
| 157 | + $postValues = $this->getPostValues($this->request); | |
| 158 | + $this->setUserSessionBackup(); | |
| 159 | + $storage->addDocument($postValues); | |
| 160 | + $this->restoreUserSessionBackup(); | |
| 161 | + $this->setSubmitToSession(); | |
| 162 | + $this->postSubmit($postValues, $storage); | |
| 163 | + } | |
| 164 | + } | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * Hook for derived classes to take actions after | |
| 168 | + * submitting the form | |
| 169 | + * | |
| 170 | + * @param $postValues | |
| 171 | + * @param $storage | |
| 172 | + */ | |
| 173 | + protected function postSubmit($postValues, $storage) | |
| 174 | +	{} | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Sets a unique id for this particular form, so it can recognize | |
| 178 | + * it when a submit occurs | |
| 179 | + */ | |
| 180 | + private function setFormId() | |
| 181 | +	{ | |
| 182 | +		if (isset($_SESSION['FormComponent'][$this->formParameterName]['formId'])) { | |
| 183 | + $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId']; | |
| 184 | +		} else { | |
| 185 | + $_SESSION['FormComponent'][$this->formParameterName]['formId'] = (string) microtime(true); | |
| 186 | + $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = false; | |
| 187 | + $this->formId = $_SESSION['FormComponent'][$this->formParameterName]['formId']; | |
| 188 | + } | |
| 189 | + } | |
| 190 | + | |
| 191 | + /** | |
| 192 | + * Checks if this form has been submitted | |
| 193 | + * | |
| 194 | + * @param $request | |
| 195 | + * @return bool | |
| 196 | + */ | |
| 197 | + private function isFormSubmitted($request) | |
| 198 | +	{ | |
| 199 | + return !empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]['formId']) && $_SESSION['FormComponent'][$this->formParameterName]['formId'] === $this->formId; | |
| 200 | + } | |
| 201 | + | |
| 202 | + /** | |
| 203 | + * | |
| 204 | + * | |
| 205 | + * @param $request | |
| 206 | + */ | |
| 207 | + private function getPostValues($request) | |
| 208 | +	{ | |
| 209 | + $postValues = $request::$post; | |
| 210 | + $postValues['documentType'] = $this->documentType; | |
| 211 | + $postValues['path'] = $this->responseFolder; | |
| 212 | +		$postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; | |
| 213 | + return $postValues; | |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * Temporarily stores the current user session in a backup variable | |
| 218 | + * and sets a fake user instead | |
| 219 | + */ | |
| 220 | + private function setUserSessionBackup() | |
| 221 | +	{ | |
| 222 | + $this->userSessionBackup = isset($_SESSION['cloudcontrol']) ? $_SESSION['cloudcontrol'] : null; | |
| 223 | + $fakeUser = new \stdClass(); | |
| 224 | + $fakeUser->username = 'FormComponent'; | |
| 225 | + $_SESSION['cloudcontrol'] = $fakeUser; | |
| 226 | + } | |
| 227 | + | |
| 228 | + /** | |
| 229 | + * Removes the fake user and restores the existing user | |
| 230 | + * session if it was there | |
| 231 | + */ | |
| 232 | + private function restoreUserSessionBackup() | |
| 233 | +	{ | |
| 234 | +		if ($this->userSessionBackup === null) { | |
| 235 | + unset($_SESSION['cloudcontrol']); | |
| 236 | +		} else { | |
| 237 | + $_SESSION['cloudcontrol'] = $this->userSessionBackup; | |
| 238 | + } | |
| 239 | + } | |
| 240 | + | |
| 241 | + private function setSubmitToSession() | |
| 242 | +	{ | |
| 243 | + $_SESSION['FormComponent'][$this->formParameterName]['submitted'] = true; | |
| 244 | + } | |
| 245 | + | |
| 246 | + private function isSubmitAllowed() | |
| 247 | +	{ | |
| 248 | +		if ($this->submitOncePerSession === true && $_SESSION['FormComponent'][$this->formParameterName]['submitted'] === true) { | |
| 249 | + return false; | |
| 250 | +		} else { | |
| 251 | + return true; | |
| 252 | + } | |
| 253 | + } | |
| 254 | 254 | } | 
| 255 | 255 | \ No newline at end of file | 
| @@ -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) ) { |