| @@ -15,7 +15,7 @@ discard block | ||
| 15 | 15 | |
| 16 | 16 | Requirements::clear(); | 
| 17 | 17 | |
| 18 | -        if (!Member::currentUser()  || !Permission::check('CMS_ACCESS_SEOToolboxAdmin')){ | |
| 18 | +        if (!Member::currentUser() || !Permission::check('CMS_ACCESS_SEOToolboxAdmin')) { | |
| 19 | 19 | return $this->redirect(Security::login_url().'?BackURL=/seotest'); | 
| 20 | 20 | } | 
| 21 | 21 | |
| @@ -151,9 +151,9 @@ discard block | ||
| 151 | 151 | * @param string $data | 
| 152 | 152 | * @return array | 
| 153 | 153 | */ | 
| 154 | -    private function getHTMLFieldsData($data){ | |
| 154 | +    private function getHTMLFieldsData($data) { | |
| 155 | 155 |          preg_match_all('/\[\*\*\[(.*?)\]\*\*\[(.*?)\]\*\*\]/im', $data, $matches); | 
| 156 | -        foreach( $matches[2] as $key => $field_text ){ | |
| 156 | +        foreach ($matches[2] as $key => $field_text) { | |
| 157 | 157 | $matches[2][$key] = base64_decode($field_text); | 
| 158 | 158 |              $matches[3][$key] = preg_replace('/[\s]+/mu', ' ', strip_tags($matches[2][$key])); | 
| 159 | 159 | } | 
| @@ -168,38 +168,38 @@ discard block | ||
| 168 | 168 | * @param (null|string) $agent | 
| 169 | 169 | * @return array | 
| 170 | 170 | */ | 
| 171 | -    public function loadPage($url, $agent=null){ | |
| 171 | +    public function loadPage($url, $agent = null) { | |
| 172 | 172 | $crawl_id = GlobalAutoLinkSettings::get_current()->CrawlID; | 
| 173 | 173 | $ch = curl_init(); | 
| 174 | - curl_setopt( $ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url ); | |
| 175 | - curl_setopt( $ch, CURLOPT_HEADER, true ); | |
| 176 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); | |
| 177 | - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); | |
| 178 | - curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 ); | |
| 179 | - curl_setopt( $ch, CURLOPT_USERAGENT, $agent ); | |
| 180 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 ); | |
| 181 | - curl_setopt( $ch, CURLOPT_TIMEOUT, 30 ); | |
| 182 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); | |
| 183 | - curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'X-Crawl-Id: '.$crawl_id ) ); | |
| 184 | - $data = curl_exec( $ch ); | |
| 174 | + curl_setopt($ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url); | |
| 175 | + curl_setopt($ch, CURLOPT_HEADER, true); | |
| 176 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| 177 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| 178 | + curl_setopt($ch, CURLOPT_MAXREDIRS, 10); | |
| 179 | + curl_setopt($ch, CURLOPT_USERAGENT, $agent); | |
| 180 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | |
| 181 | + curl_setopt($ch, CURLOPT_TIMEOUT, 30); | |
| 182 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
| 183 | +        curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Crawl-Id: '.$crawl_id)); | |
| 184 | + $data = curl_exec($ch); | |
| 185 | 185 | |
| 186 | 186 | $fetched = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_PATH); | 
| 187 | - $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE ); | |
| 188 | - $header = explode( "\r\n\r\n", substr( $data, 0, $header_size ) ); | |
| 189 | - array_pop( $header ); // Remove last element as it will always be empty | |
| 190 | - $header = array_pop( $header ); | |
| 191 | -        $body   = preg_replace('/[\s]+/mu', ' ', substr( $data, $header_size )); | |
| 187 | + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); | |
| 188 | +        $header = explode("\r\n\r\n", substr($data, 0, $header_size)); | |
| 189 | + array_pop($header); // Remove last element as it will always be empty | |
| 190 | + $header = array_pop($header); | |
| 191 | +        $body   = preg_replace('/[\s]+/mu', ' ', substr($data, $header_size)); | |
| 192 | 192 | |
| 193 | - curl_close( $ch ); | |
| 193 | + curl_close($ch); | |
| 194 | 194 | |
| 195 | -        if( !strpos( $header, ' 200 ' ) ) { | |
| 196 | - return array( 'headers' => false, 'body' => false ); | |
| 195 | +        if (!strpos($header, ' 200 ')) { | |
| 196 | +            return array('headers' => false, 'body' => false); | |
| 197 | 197 | } | 
| 198 | 198 | |
| 199 | 199 | $field_data = $this->getHTMLFieldsData($body); | 
| 200 | 200 | $body = str_replace($field_data[0], $field_data[2], $body); | 
| 201 | 201 | |
| 202 | - return array( 'headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched ); | |
| 202 | +        return array('headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched); | |
| 203 | 203 | } | 
| 204 | 204 | |
| 205 | 205 | /** | 
| @@ -113,8 +113,9 @@ | ||
| 113 | 113 | $phrases = array_merge($phrases, $matches[$commands['find_pos']]); | 
| 114 | 114 | } | 
| 115 | 115 | |
| 116 | - if (isset($commands['replace'])) | |
| 117 | - $html = preg_replace($commands['replace'], ' ', $html); | |
| 116 | +            if (isset($commands['replace'])) { | |
| 117 | + $html = preg_replace($commands['replace'], ' ', $html); | |
| 118 | + } | |
| 118 | 119 | } | 
| 119 | 120 | |
| 120 | 121 | // Remove the empty elements |