| @@ -128,7 +128,7 @@ discard block | ||
| 128 | 128 | $this->setHeaders(); | 
| 129 | 129 | |
| 130 | 130 | // Check security token | 
| 131 | -		if(self::config()->enable_security_token && !SecurityToken::inst()->checkRequest($this->request)) { | |
| 131 | +		if (self::config()->enable_security_token && !SecurityToken::inst()->checkRequest($this->request)) { | |
| 132 | 132 | return $this->error( | 
| 133 | 133 | _t( | 
| 134 | 134 | 'SpellController.SecurityMissing', | 
| @@ -140,31 +140,31 @@ discard block | ||
| 140 | 140 | |
| 141 | 141 | // Check permission | 
| 142 | 142 | $permission = self::config()->required_permission; | 
| 143 | -		if($permission && !Permission::check($permission)) { | |
| 143 | +		if ($permission && !Permission::check($permission)) { | |
| 144 | 144 |  			return $this->error(_t('SpellController.SecurityDenied', 'Permission Denied'), 403); | 
| 145 | 145 | } | 
| 146 | 146 | |
| 147 | 147 | // Check data | 
| 148 | 148 | $data = $this->getRequestData(); | 
| 149 | -		if(empty($data)) { | |
| 149 | +		if (empty($data)) { | |
| 150 | 150 |  			return $this->error(_t('SpellController.MissingData', "Could not get raw post data"), 400); | 
| 151 | 151 | } | 
| 152 | 152 | |
| 153 | 153 | // Check params and request type | 
| 154 | -		if(!Director::is_ajax() || empty($data['method']) || empty($data['params']) || count($data['params']) < 2) { | |
| 154 | +		if (!Director::is_ajax() || empty($data['method']) || empty($data['params']) || count($data['params']) < 2) { | |
| 155 | 155 |  			return $this->error(_t('SpellController.InvalidRequest', 'Invalid request'), 400); | 
| 156 | 156 | } | 
| 157 | 157 | |
| 158 | 158 | // Check locale | 
| 159 | 159 | $params = $data['params']; | 
| 160 | 160 | $locale = $params[0]; | 
| 161 | -		if(!in_array($locale, self::get_locales())) { | |
| 161 | +		if (!in_array($locale, self::get_locales())) { | |
| 162 | 162 |  			return $this->error(_t('SpellController.InvalidLocale', 'Not supported locale'), 400); | 
| 163 | 163 | } | 
| 164 | 164 | |
| 165 | 165 | // Check provider | 
| 166 | 166 | $provider = $this->getProvider(); | 
| 167 | -		if(empty($provider)) { | |
| 167 | +		if (empty($provider)) { | |
| 168 | 168 |  			return $this->error(_t('SpellController.MissingProviders', "No spellcheck module installed"), 500); | 
| 169 | 169 | } | 
| 170 | 170 | |
| @@ -172,7 +172,7 @@ discard block | ||
| 172 | 172 |  		try { | 
| 173 | 173 | $method = $data['method']; | 
| 174 | 174 | $words = $params[1]; | 
| 175 | -			switch($method) { | |
| 175 | +			switch ($method) { | |
| 176 | 176 | case 'checkWords': | 
| 177 | 177 | return $this->success($provider->checkWords($locale, $words)); | 
| 178 | 178 | case 'getSuggestions': | 
| @@ -187,7 +187,7 @@ discard block | ||
| 187 | 187 | 400 | 
| 188 | 188 | ); | 
| 189 | 189 | } | 
| 190 | -		} catch(SpellException $ex) { | |
| 190 | +		} catch (SpellException $ex) { | |
| 191 | 191 | return $this->error($ex->getMessage(), $ex->getCode()); | 
| 192 | 192 | } | 
| 193 | 193 | } | 
| @@ -212,7 +212,7 @@ discard block | ||
| 212 | 212 | */ | 
| 213 | 213 |  	protected function getRequestData() { | 
| 214 | 214 | // Check if data needs to be parsed | 
| 215 | -		if($this->data === null) { | |
| 215 | +		if ($this->data === null) { | |
| 216 | 216 | // Parse data from input | 
| 217 | 217 |  			$result = $this->request->requestVar('json_data') | 
| 218 | 218 |  				?: file_get_contents("php://input"); | 
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 |  	public function preRequest(\SS_HTTPRequest $request, \Session $session, \DataModel $model) { | 
| 14 | 14 | // Check languages to set | 
| 15 | 15 | $languages = array(); | 
| 16 | -		foreach(SpellController::get_locales() as $locale) { | |
| 16 | +		foreach (SpellController::get_locales() as $locale) { | |
| 17 | 17 | $languages[] = i18n::get_locale_name($locale).'='.$locale; | 
| 18 | 18 | } | 
| 19 | 19 | |
| @@ -25,14 +25,14 @@ discard block | ||
| 25 | 25 | */ | 
| 26 | 26 |  	protected function invoke($locale, $input, &$stdout, &$stderr) { | 
| 27 | 27 | // Prepare arguments | 
| 28 | - $command = 'hunspell -d ' . escapeshellarg($locale); | |
| 28 | + $command = 'hunspell -d '.escapeshellarg($locale); | |
| 29 | 29 | $descriptorSpecs = array( | 
| 30 | 30 |  			0 => array("pipe", "r"), | 
| 31 | 31 |  			1 => array("pipe", "w"), | 
| 32 | 32 |  			2 => array("pipe", "w") | 
| 33 | 33 | ); | 
| 34 | 34 | $env = array( | 
| 35 | - 'LANG' => $locale . '.utf-8' | |
| 35 | + 'LANG' => $locale.'.utf-8' | |
| 36 | 36 | ); | 
| 37 | 37 | // Invoke command | 
| 38 | 38 | $proc = proc_open($command, $descriptorSpecs, $pipes, null, $env); | 
| @@ -64,17 +64,17 @@ discard block | ||
| 64 | 64 | // Invoke HunSpell | 
| 65 | 65 |  		$input = implode(' ', $words); | 
| 66 | 66 | $return = $this->invoke($locale, $input, $stdout, $stderr); | 
| 67 | -		if($stderr) { | |
| 67 | +		if ($stderr) { | |
| 68 | 68 | throw new SpellException($stderr, 500); | 
| 69 | -		} elseif($return) { | |
| 69 | +		} elseif ($return) { | |
| 70 | 70 |  			throw new SpellException("An unidentified error has occurred", 500); | 
| 71 | 71 | } | 
| 72 | 72 | |
| 73 | 73 | // Parse results | 
| 74 | 74 | $pattern = Config::inst()->get(__CLASS__, 'pattern'); | 
| 75 | 75 | $results = array(); | 
| 76 | -		foreach(preg_split('/$\R?^/m', $stdout) as $line) { | |
| 77 | -			if(preg_match($pattern, $line, $matches)) { | |
| 76 | +		foreach (preg_split('/$\R?^/m', $stdout) as $line) { | |
| 77 | +			if (preg_match($pattern, $line, $matches)) { | |
| 78 | 78 |  				$results[$matches['original']] = explode(', ', $matches['misses']); | 
| 79 | 79 | } | 
| 80 | 80 | } | 
| @@ -88,6 +88,6 @@ discard block | ||
| 88 | 88 | |
| 89 | 89 |  	public function getSuggestions($locale, $word) { | 
| 90 | 90 | $results = $this->getResults($locale, array($word)); | 
| 91 | - if(isset($results[$word])) return $results[$word]; | |
| 91 | + if (isset($results[$word])) return $results[$word]; | |
| 92 | 92 | } | 
| 93 | 93 | } | 
| @@ -36,7 +36,9 @@ discard block | ||
| 36 | 36 | ); | 
| 37 | 37 | // Invoke command | 
| 38 | 38 | $proc = proc_open($command, $descriptorSpecs, $pipes, null, $env); | 
| 39 | - if (!is_resource($proc)) return 255; | |
| 39 | +		if (!is_resource($proc)) { | |
| 40 | + return 255; | |
| 41 | + } | |
| 40 | 42 | |
| 41 | 43 | // Send content as input | 
| 42 | 44 | fwrite($pipes[0], $input); | 
| @@ -88,6 +90,8 @@ discard block | ||
| 88 | 90 | |
| 89 | 91 |  	public function getSuggestions($locale, $word) { | 
| 90 | 92 | $results = $this->getResults($locale, array($word)); | 
| 91 | - if(isset($results[$word])) return $results[$word]; | |
| 93 | +		if(isset($results[$word])) { | |
| 94 | + return $results[$word]; | |
| 95 | + } | |
| 92 | 96 | } | 
| 93 | 97 | } |