@@ -148,47 +148,47 @@ |
||
| 148 | 148 | /** |
| 149 | 149 | * @param string $data |
| 150 | 150 | */ |
| 151 | - private function getHTMLFieldsData($data){ |
|
| 151 | + private function getHTMLFieldsData($data) { |
|
| 152 | 152 | preg_match_all('/\[\*\*\[(.*?)\]\*\*\[(.*?)\]\*\*\]/im', $data, $matches); |
| 153 | - foreach( $matches[2] as $key => $field_text ){ |
|
| 153 | + foreach ($matches[2] as $key => $field_text) { |
|
| 154 | 154 | $matches[2][$key] = base64_decode($field_text); |
| 155 | 155 | $matches[3][$key] = preg_replace('/[\s]+/mu', ' ', strip_tags($matches[2][$key])); |
| 156 | 156 | } |
| 157 | 157 | return $matches; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public function loadPage($url, $agent=null){ |
|
| 160 | + public function loadPage($url, $agent = null) { |
|
| 161 | 161 | $crawl_id = GlobalAutoLinkSettings::get_current()->CrawlID; |
| 162 | 162 | $ch = curl_init(); |
| 163 | - curl_setopt( $ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url ); |
|
| 164 | - curl_setopt( $ch, CURLOPT_HEADER, true ); |
|
| 165 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
| 166 | - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); |
|
| 167 | - curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 ); |
|
| 168 | - curl_setopt( $ch, CURLOPT_USERAGENT, $agent ); |
|
| 169 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 ); |
|
| 170 | - curl_setopt( $ch, CURLOPT_TIMEOUT, 30 ); |
|
| 171 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); |
|
| 172 | - curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'X-Crawl-Id: '.$crawl_id ) ); |
|
| 173 | - $data = curl_exec( $ch ); |
|
| 163 | + curl_setopt($ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url); |
|
| 164 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
| 165 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 166 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
| 167 | + curl_setopt($ch, CURLOPT_MAXREDIRS, 10); |
|
| 168 | + curl_setopt($ch, CURLOPT_USERAGENT, $agent); |
|
| 169 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
| 170 | + curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
|
| 171 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
| 172 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Crawl-Id: '.$crawl_id)); |
|
| 173 | + $data = curl_exec($ch); |
|
| 174 | 174 | |
| 175 | 175 | $fetched = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_PATH); |
| 176 | - $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE ); |
|
| 177 | - $header = explode( "\r\n\r\n", substr( $data, 0, $header_size ) ); |
|
| 178 | - array_pop( $header ); // Remove last element as it will always be empty |
|
| 179 | - $header = array_pop( $header ); |
|
| 180 | - $body = preg_replace('/[\s]+/mu', ' ', substr( $data, $header_size )); |
|
| 176 | + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
|
| 177 | + $header = explode("\r\n\r\n", substr($data, 0, $header_size)); |
|
| 178 | + array_pop($header); // Remove last element as it will always be empty |
|
| 179 | + $header = array_pop($header); |
|
| 180 | + $body = preg_replace('/[\s]+/mu', ' ', substr($data, $header_size)); |
|
| 181 | 181 | |
| 182 | - curl_close( $ch ); |
|
| 182 | + curl_close($ch); |
|
| 183 | 183 | |
| 184 | - if( !strpos( $header, ' 200 ' ) ) { |
|
| 185 | - return array( 'headers' => false, 'body' => false ); |
|
| 184 | + if (!strpos($header, ' 200 ')) { |
|
| 185 | + return array('headers' => false, 'body' => false); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | $field_data = $this->getHTMLFieldsData($body); |
| 189 | 189 | $body = str_replace($field_data[0], $field_data[2], $body); |
| 190 | 190 | |
| 191 | - return array( 'headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched ); |
|
| 191 | + return array('headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -17,21 +17,29 @@ discard block |
||
| 17 | 17 | parent::init(); |
| 18 | 18 | |
| 19 | 19 | // Check user is logged in and has permission to access to SEO Toolbox Admin |
| 20 | - if (!Member::currentUser()) return $this->redirect(Security::login_url().'?BackURL=/seotest'); |
|
| 21 | - if (!Permission::check('CMS_ACCESS_SEOToolboxAdmin')) return $this->redirect(self::getPermissionDeniedPage()->Link()); |
|
| 20 | + if (!Member::currentUser()) { |
|
| 21 | + return $this->redirect(Security::login_url().'?BackURL=/seotest'); |
|
| 22 | + } |
|
| 23 | + if (!Permission::check('CMS_ACCESS_SEOToolboxAdmin')) { |
|
| 24 | + return $this->redirect(self::getPermissionDeniedPage()->Link()); |
|
| 25 | + } |
|
| 22 | 26 | |
| 23 | 27 | Requirements::clear(); |
| 24 | 28 | |
| 25 | 29 | // Sprite Location needs to be dynamic as devs can install module in different locations |
| 26 | 30 | $sprite_path = $this->config()->get('sprite_path'); |
| 27 | - if ($sprite_path === null) $sprite_path = SEOTOOLBOX_DIR.'/css/icons/icon_sprite.png'; |
|
| 31 | + if ($sprite_path === null) { |
|
| 32 | + $sprite_path = SEOTOOLBOX_DIR.'/css/icons/icon_sprite.png'; |
|
| 33 | + } |
|
| 28 | 34 | Requirements::customCSS(".icon{width:16px;height: 16px;cursor:pointer;background: url(/{$sprite_path});}"); |
| 29 | 35 | |
| 30 | 36 | // CSS can be replaced by devs if they desire to change styling |
| 31 | 37 | Requirements::css(SEOTOOLBOX_DIR.'/third-party/bootstrap/css/bootstrap.min.css'); |
| 32 | 38 | Requirements::css(SEOTOOLBOX_DIR.'/third-party/bootstrap/css/bootstrap-theme.min.css'); |
| 33 | 39 | $css = $this->config()->get('css'); |
| 34 | - if ($css === null) $css = array(SEOTOOLBOX_DIR.'/fonts/lato/lato.css', SEOTOOLBOX_DIR.'/css/seotest.css'); |
|
| 40 | + if ($css === null) { |
|
| 41 | + $css = array(SEOTOOLBOX_DIR.'/fonts/lato/lato.css', SEOTOOLBOX_DIR.'/css/seotest.css'); |
|
| 42 | + } |
|
| 35 | 43 | Requirements::combine_files('seotest.css', $css); |
| 36 | 44 | |
| 37 | 45 | Requirements::combine_files('seotest.js', array( |
@@ -120,8 +128,9 @@ discard block |
||
| 120 | 128 | $phrases = array_merge($phrases, $matches[$commands['find_pos']]); |
| 121 | 129 | } |
| 122 | 130 | |
| 123 | - if (isset($commands['replace'])) |
|
| 124 | - $html = preg_replace($commands['replace'], ' ', $html); |
|
| 131 | + if (isset($commands['replace'])) { |
|
| 132 | + $html = preg_replace($commands['replace'], ' ', $html); |
|
| 133 | + } |
|
| 125 | 134 | } |
| 126 | 135 | |
| 127 | 136 | // Remove the empty elements |