@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | Requirements::clear(); |
| 20 | 20 | |
| 21 | - if (!Member::currentUser() || !Permission::check('CMS_ACCESS_SEOToolboxAdmin')){ |
|
| 21 | + if (!Member::currentUser() || !Permission::check('CMS_ACCESS_SEOToolboxAdmin')) { |
|
| 22 | 22 | return $this->redirect(Security::login_url().'?BackURL=/seotest'); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param SS_HTTPRequest $request |
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | - public function getPage(SS_HTTPRequest $request){ |
|
| 79 | + public function getPage(SS_HTTPRequest $request) { |
|
| 80 | 80 | $agent = ($request->getVar('agent') == 'mobile') |
| 81 | 81 | ? $this->config()->get('mobile_user_agent') |
| 82 | 82 | : $this->config()->get('desktop_user_agent'); |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | * @param string $data |
| 179 | 179 | * @return array |
| 180 | 180 | */ |
| 181 | - private function getHTMLFieldsData($data){ |
|
| 181 | + private function getHTMLFieldsData($data) { |
|
| 182 | 182 | preg_match_all('/\[\*\*\[(.*?)\]\*\*\[(.*?)\]\*\*\]/im', $data, $matches); |
| 183 | - foreach( $matches[2] as $key => $field_text ){ |
|
| 183 | + foreach ($matches[2] as $key => $field_text) { |
|
| 184 | 184 | $matches[2][$key] = base64_decode($field_text); |
| 185 | 185 | $matches[3][$key] = preg_replace('/[\s]+/mu', ' ', strip_tags($matches[2][$key])); |
| 186 | 186 | } |
@@ -196,20 +196,20 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @return resource |
| 198 | 198 | */ |
| 199 | - public function setupCurl($url, $agent, $useCrawlID = false){ |
|
| 199 | + public function setupCurl($url, $agent, $useCrawlID = false) { |
|
| 200 | 200 | $ch = curl_init(); |
| 201 | - curl_setopt( $ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url ); |
|
| 202 | - curl_setopt( $ch, CURLOPT_HEADER, true ); |
|
| 203 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
| 204 | - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); |
|
| 205 | - curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 ); |
|
| 206 | - curl_setopt( $ch, CURLOPT_USERAGENT, $agent ); |
|
| 207 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 ); |
|
| 208 | - curl_setopt( $ch, CURLOPT_TIMEOUT, 30 ); |
|
| 209 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); |
|
| 210 | - if( $useCrawlID ){ |
|
| 201 | + curl_setopt($ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url); |
|
| 202 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
| 203 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 204 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
| 205 | + curl_setopt($ch, CURLOPT_MAXREDIRS, 10); |
|
| 206 | + curl_setopt($ch, CURLOPT_USERAGENT, $agent); |
|
| 207 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
| 208 | + curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
|
| 209 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
| 210 | + if ($useCrawlID) { |
|
| 211 | 211 | $crawl_id = GlobalAutoLinkSettings::get_current()->CrawlID; |
| 212 | - curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'X-Crawl-Id: '.$crawl_id ) ); |
|
| 212 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Crawl-Id: '.$crawl_id)); |
|
| 213 | 213 | } |
| 214 | 214 | return $ch; |
| 215 | 215 | } |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @param string $data |
| 222 | 222 | * @return string |
| 223 | 223 | */ |
| 224 | - public function getPageHeaders($ch, $data){ |
|
| 225 | - $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE ); |
|
| 226 | - $header = explode( "\r\n\r\n", substr( $data, 0, $header_size ) ); |
|
| 227 | - array_pop( $header ); // Remove last element as it will always be empty |
|
| 228 | - return array_pop( $header ); |
|
| 224 | + public function getPageHeaders($ch, $data) { |
|
| 225 | + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
|
| 226 | + $header = explode("\r\n\r\n", substr($data, 0, $header_size)); |
|
| 227 | + array_pop($header); // Remove last element as it will always be empty |
|
| 228 | + return array_pop($header); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | * @param string $data |
| 236 | 236 | * @return string |
| 237 | 237 | */ |
| 238 | - public function getPageBody($ch, $data){ |
|
| 239 | - $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE ); |
|
| 240 | - return substr( $data, $header_size ); |
|
| 238 | + public function getPageBody($ch, $data) { |
|
| 239 | + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
|
| 240 | + return substr($data, $header_size); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -248,23 +248,23 @@ discard block |
||
| 248 | 248 | * @param (null|string) $agent |
| 249 | 249 | * @return array |
| 250 | 250 | */ |
| 251 | - public function loadPage($url, $agent=null){ |
|
| 251 | + public function loadPage($url, $agent = null) { |
|
| 252 | 252 | $ch = $this->setupCurl($url, $agent, true); |
| 253 | 253 | $data = curl_exec($ch); |
| 254 | 254 | $fetched = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_PATH); |
| 255 | 255 | $header = $this->getPageHeaders($ch, $data); |
| 256 | 256 | $body = preg_replace('/[\s]+/mu', ' ', $this->getPageBody($ch, $data)); |
| 257 | 257 | |
| 258 | - curl_close( $ch ); |
|
| 258 | + curl_close($ch); |
|
| 259 | 259 | |
| 260 | - if( !strpos( $header, ' 200 ' ) ) { |
|
| 261 | - return array( 'headers' => false, 'body' => false ); |
|
| 260 | + if (!strpos($header, ' 200 ')) { |
|
| 261 | + return array('headers' => false, 'body' => false); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | $field_data = $this->getHTMLFieldsData($body); |
| 265 | 265 | $body = str_replace($field_data[0], $field_data[2], $body); |
| 266 | 266 | |
| 267 | - return array( 'headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched ); |
|
| 267 | + return array('headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |