@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | Requirements::clear(); |
21 | 21 | |
22 | - if (!Member::currentUser() || !Permission::check('CMS_ACCESS_SEOToolboxAdmin')){ |
|
22 | + if (!Member::currentUser() || !Permission::check('CMS_ACCESS_SEOToolboxAdmin')) { |
|
23 | 23 | return $this->redirect(Security::login_url().'?BackURL=/seotest'); |
24 | 24 | } |
25 | 25 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param SS_HTTPRequest $request |
78 | 78 | * @return string |
79 | 79 | */ |
80 | - public function getPage(SS_HTTPRequest $request){ |
|
80 | + public function getPage(SS_HTTPRequest $request) { |
|
81 | 81 | $agent = ($request->getVar('agent') == 'mobile') |
82 | 82 | ? $this->config()->get('mobile_user_agent') |
83 | 83 | : $this->config()->get('desktop_user_agent'); |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * @param string $data |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - private function getHTMLFieldsData($data){ |
|
182 | + private function getHTMLFieldsData($data) { |
|
183 | 183 | preg_match_all('/\[\*\*\[(.*?)\]\*\*\[(.*?)\]\*\*\]/im', $data, $matches); |
184 | - foreach( $matches[2] as $key => $field_text ){ |
|
184 | + foreach ($matches[2] as $key => $field_text) { |
|
185 | 185 | $matches[2][$key] = base64_decode($field_text); |
186 | 186 | $matches[3][$key] = preg_replace('/[\s]+/mu', ' ', strip_tags($matches[2][$key])); |
187 | 187 | } |
@@ -197,20 +197,20 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @return resource |
199 | 199 | */ |
200 | - public function setupCurl($url, $agent, $useCrawlID = false){ |
|
200 | + public function setupCurl($url, $agent, $useCrawlID = false) { |
|
201 | 201 | $ch = curl_init(); |
202 | - curl_setopt( $ch, CURLOPT_URL, $this->getCurlURL($url) ); |
|
203 | - curl_setopt( $ch, CURLOPT_HEADER, true ); |
|
204 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
205 | - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); |
|
206 | - curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 ); |
|
207 | - curl_setopt( $ch, CURLOPT_USERAGENT, $agent ); |
|
208 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 ); |
|
209 | - curl_setopt( $ch, CURLOPT_TIMEOUT, 30 ); |
|
210 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); |
|
211 | - if( $useCrawlID ){ |
|
202 | + curl_setopt($ch, CURLOPT_URL, $this->getCurlURL($url)); |
|
203 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
204 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
205 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
206 | + curl_setopt($ch, CURLOPT_MAXREDIRS, 10); |
|
207 | + curl_setopt($ch, CURLOPT_USERAGENT, $agent); |
|
208 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
209 | + curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
|
210 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
211 | + if ($useCrawlID) { |
|
212 | 212 | $crawl_id = GlobalAutoLinkSettings::get_current()->CrawlID; |
213 | - curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'X-Crawl-Id: '.$crawl_id ) ); |
|
213 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Crawl-Id: '.$crawl_id)); |
|
214 | 214 | } |
215 | 215 | return $ch; |
216 | 216 | } |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return array|scalar|string |
222 | 222 | */ |
223 | - public function getCurlDomain(){ |
|
224 | - return ( self::config()->get('alternate_domain') != null ) |
|
223 | + public function getCurlDomain() { |
|
224 | + return (self::config()->get('alternate_domain') != null) |
|
225 | 225 | ? self::config()->get('alternate_domain') |
226 | 226 | : Director::absoluteBaseURL(); |
227 | 227 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @param string $url |
233 | 233 | * @return string |
234 | 234 | */ |
235 | - public function getCurlURL($url){ |
|
235 | + public function getCurlURL($url) { |
|
236 | 236 | $domain = $this->getCurlDomain(); |
237 | 237 | return "$domain/$url"; |
238 | 238 | } |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | * @param string $data |
245 | 245 | * @return string |
246 | 246 | */ |
247 | - public function getPageHeaders($ch, $data){ |
|
248 | - $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE ); |
|
249 | - $header = explode( "\r\n\r\n", substr( $data, 0, $header_size ) ); |
|
250 | - array_pop( $header ); // Remove last element as it will always be empty |
|
251 | - return array_pop( $header ); |
|
247 | + public function getPageHeaders($ch, $data) { |
|
248 | + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
|
249 | + $header = explode("\r\n\r\n", substr($data, 0, $header_size)); |
|
250 | + array_pop($header); // Remove last element as it will always be empty |
|
251 | + return array_pop($header); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | * @param string $data |
259 | 259 | * @return string |
260 | 260 | */ |
261 | - public function getPageBody($ch, $data){ |
|
262 | - $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE ); |
|
263 | - return substr( $data, $header_size ); |
|
261 | + public function getPageBody($ch, $data) { |
|
262 | + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
|
263 | + return substr($data, $header_size); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -271,23 +271,23 @@ discard block |
||
271 | 271 | * @param (null|string) $agent |
272 | 272 | * @return array |
273 | 273 | */ |
274 | - public function loadPage($url, $agent=null){ |
|
274 | + public function loadPage($url, $agent = null) { |
|
275 | 275 | $ch = $this->setupCurl($url, $agent, true); |
276 | 276 | $data = curl_exec($ch); |
277 | 277 | $fetched = str_replace($this->getCurlDomain(), '', curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); |
278 | 278 | $header = $this->getPageHeaders($ch, $data); |
279 | 279 | $body = preg_replace('/[\s]+/mu', ' ', $this->getPageBody($ch, $data)); |
280 | 280 | |
281 | - curl_close( $ch ); |
|
281 | + curl_close($ch); |
|
282 | 282 | |
283 | - if( !strpos( $header, ' 200 ' ) ) { |
|
284 | - return array( 'headers' => false, 'body' => false ); |
|
283 | + if (!strpos($header, ' 200 ')) { |
|
284 | + return array('headers' => false, 'body' => false); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | $field_data = $this->getHTMLFieldsData($body); |
288 | 288 | $body = str_replace($field_data[0], $field_data[2], $body); |
289 | 289 | |
290 | - return array( 'headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched ); |
|
290 | + return array('headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |