@@ -9,19 +9,19 @@ |
||
| 9 | 9 | * all the automated links and automated link global settings |
| 10 | 10 | * for this site |
| 11 | 11 | */ |
| 12 | -class SEOToolboxAdmin extends ModelAdmin{ |
|
| 12 | +class SEOToolboxAdmin extends ModelAdmin { |
|
| 13 | 13 | |
| 14 | 14 | private static $menu_title = 'SEO Tool box'; |
| 15 | 15 | private static $url_segment = 'seo-tool-box'; |
| 16 | - private static $managed_models = array( 'AutomatedLink' ); |
|
| 17 | - private static $menu_priority = 10; |
|
| 16 | + private static $managed_models = array('AutomatedLink'); |
|
| 17 | + private static $menu_priority = 10; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | public function getEditForm($id = null, $fields = null) { |
| 21 | - $form = parent::getEditForm( $id, $fields ); |
|
| 21 | + $form = parent::getEditForm($id, $fields); |
|
| 22 | 22 | $class = $this->sanitiseClassName($this->modelClass); |
| 23 | - $grid = $form->Fields()->fieldByName($class); |
|
| 24 | - $grid->getConfig()->addComponent( new GridFieldSortableRows( 'Priority' ) ); |
|
| 23 | + $grid = $form->Fields()->fieldByName($class); |
|
| 24 | + $grid->getConfig()->addComponent(new GridFieldSortableRows('Priority')); |
|
| 25 | 25 | |
| 26 | 26 | return $form; |
| 27 | 27 | } |
@@ -33,11 +33,11 @@ |
||
| 33 | 33 | * to view this report. |
| 34 | 34 | */ |
| 35 | 35 | |
| 36 | -define( 'SEOTOOLBOX_DIR', str_replace( Director::baseFolder().'/', '', __DIR__ ) ); |
|
| 36 | +define('SEOTOOLBOX_DIR', str_replace(Director::baseFolder().'/', '', __DIR__)); |
|
| 37 | 37 | |
| 38 | 38 | Config::inst()->update('SEOToolboxAdmin', 'menu_icon', SEOTOOLBOX_DIR.'/code/admin/icon/seotoolbox-icon.png'); |
| 39 | -Config::inst()->update('LeftAndMain','extra_requirements_javascript', array(SEOTOOLBOX_DIR.'/js/seo_page_analyzer.js')); |
|
| 40 | -Config::inst()->update('LeftAndMain','extra_requirements_css', array(SEOTOOLBOX_DIR.'/css/seo_page_analyzer.css')); |
|
| 39 | +Config::inst()->update('LeftAndMain', 'extra_requirements_javascript', array(SEOTOOLBOX_DIR.'/js/seo_page_analyzer.js')); |
|
| 40 | +Config::inst()->update('LeftAndMain', 'extra_requirements_css', array(SEOTOOLBOX_DIR.'/css/seo_page_analyzer.css')); |
|
| 41 | 41 | |
| 42 | 42 | CMSMenu::add_link('seotest', 'Run Crawler', '/seotest', 9, array('target' => '_blank')); |
| 43 | 43 | Requirements::customCSS('.icon.icon-16.icon-seotest{background:url('.SEOTOOLBOX_DIR.'/code/admin/icon/crawl-icon.png)}'); |
@@ -31,37 +31,37 @@ discard block |
||
| 31 | 31 | 'Page' => 'SiteTree' |
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | - private static $summary_fields = array( 'Phrase', 'PointsTo' ); |
|
| 35 | - private static $searchable_fields = array( 'Phrase' ); |
|
| 36 | - private static $singular_name = 'Automated Link'; |
|
| 34 | + private static $summary_fields = array('Phrase', 'PointsTo'); |
|
| 35 | + private static $searchable_fields = array('Phrase'); |
|
| 36 | + private static $singular_name = 'Automated Link'; |
|
| 37 | 37 | private static $plural_name = 'Automated Links'; |
| 38 | 38 | private static $parsableFields = array(); |
| 39 | 39 | |
| 40 | - public function PointsTo(){ |
|
| 40 | + public function PointsTo() { |
|
| 41 | 41 | return $this->Page()->Link(); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function Title(){ |
|
| 44 | + public function Title() { |
|
| 45 | 45 | return $this->Phrase; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function forTemplate(){ |
|
| 48 | + public function forTemplate() { |
|
| 49 | 49 | return $this->getHTML(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - function canView( $member = false ){ |
|
| 52 | + function canView($member = false) { |
|
| 53 | 53 | return Permission::check('AUTOMATEDLINK_VIEW'); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - function canEdit( $member = false ){ |
|
| 56 | + function canEdit($member = false) { |
|
| 57 | 57 | return Permission::check('AUTOMATEDLINK_EDIT'); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - function canDelete( $member = false ){ |
|
| 60 | + function canDelete($member = false) { |
|
| 61 | 61 | return Permission::check('AUTOMATEDLINK_DELETE'); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - function canCreate( $member = false ){ |
|
| 64 | + function canCreate($member = false) { |
|
| 65 | 65 | return Permission::check('AUTOMATEDLINK_CREATE'); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function requireDefaultRecords(){ |
|
| 77 | + public function requireDefaultRecords() { |
|
| 78 | 78 | parent::requireDefaultRecords(); |
| 79 | 79 | |
| 80 | 80 | // Update all links to redirector pages during dev/build |
| 81 | - foreach( self::get() as $link ) { |
|
| 82 | - $link->CheckAndUpdateDestination( true ); |
|
| 81 | + foreach (self::get() as $link) { |
|
| 82 | + $link->CheckAndUpdateDestination(true); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
@@ -180,15 +180,15 @@ discard block |
||
| 180 | 180 | * @Boolean $write - Write the changes if any |
| 181 | 181 | * @return void |
| 182 | 182 | */ |
| 183 | - public function CheckAndUpdateDestination( $write = false ){ |
|
| 183 | + public function CheckAndUpdateDestination($write = false) { |
|
| 184 | 184 | $this->extend('beforeCheckAndUpdateDestination', $write); |
| 185 | 185 | |
| 186 | - if( $this->PageID && $this->Page() && |
|
| 186 | + if ($this->PageID && $this->Page() && |
|
| 187 | 187 | $this->Page()->ClassName == 'RedirectorPage' && |
| 188 | - $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' ) |
|
| 188 | + $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal') |
|
| 189 | 189 | { |
| 190 | 190 | $this->PageID = $this->Page()->LinkToID; |
| 191 | - if( $write ) { |
|
| 191 | + if ($write) { |
|
| 192 | 192 | $this->write(); |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * |
| 225 | 225 | * @return Boolean |
| 226 | 226 | */ |
| 227 | - public function canBeAdded( ContentController $controller ){ |
|
| 228 | - return ( $this->SelfLinking || $controller->ID != $this->PageID ); |
|
| 227 | + public function canBeAdded(ContentController $controller) { |
|
| 228 | + return ($this->SelfLinking || $controller->ID != $this->PageID); |
|
| 229 | 229 | } |
| 230 | 230 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * Automated Link Report is a report that lists all automated |
| 8 | 8 | * links and how they affect the website |
| 9 | 9 | */ |
| 10 | -class AutomatedLinkReport extends SS_Report{ |
|
| 10 | +class AutomatedLinkReport extends SS_Report { |
|
| 11 | 11 | |
| 12 | 12 | protected $title = 'Automated Link Report'; |
| 13 | 13 | protected $description = 'Shows a list of all automated links and how they affect the site'; |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | ); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function sourceRecords( $params, $sort, $limit ){ |
|
| 37 | - if( !Config::inst()->get( $this->class, 'run_in_realtime' ) ) { |
|
| 36 | + public function sourceRecords($params, $sort, $limit) { |
|
| 37 | + if (!Config::inst()->get($this->class, 'run_in_realtime')) { |
|
| 38 | 38 | return AutomatedLinkPageResult::get(); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -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 | /** |
@@ -3,29 +3,29 @@ |
||
| 3 | 3 | class GridFieldExportAllAutomatedLinksButton extends GridFieldExportButton { |
| 4 | 4 | public function generateExportFileData($gridField) { |
| 5 | 5 | $separator = $this->csvSeparator; |
| 6 | - $csvColumns =$gridField->getColumns(); |
|
| 6 | + $csvColumns = $gridField->getColumns(); |
|
| 7 | 7 | $fileData = ''; |
| 8 | - if($this->csvHasHeader) { |
|
| 8 | + if ($this->csvHasHeader) { |
|
| 9 | 9 | $headers = array(); |
| 10 | - foreach($csvColumns as $columnSource => $columnHeader) { |
|
| 10 | + foreach ($csvColumns as $columnSource => $columnHeader) { |
|
| 11 | 11 | $headers[] = (!is_string($columnHeader) && is_callable($columnHeader)) ? $columnSource : $columnHeader; |
| 12 | 12 | } |
| 13 | - $fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\""; |
|
| 13 | + $fileData .= "\"".implode("\"{$separator}\"", array_values($headers))."\""; |
|
| 14 | 14 | $fileData .= "\n"; |
| 15 | 15 | } |
| 16 | 16 | $items = $gridField->getList(); |
| 17 | 17 | |
| 18 | - foreach($gridField->getConfig()->getComponents() as $component){ |
|
| 19 | - if($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) { |
|
| 18 | + foreach ($gridField->getConfig()->getComponents() as $component) { |
|
| 19 | + if ($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) { |
|
| 20 | 20 | $items = $component->getManipulatedData($gridField, $items); |
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | - foreach($items->limit(null) as $item) { |
|
| 23 | + foreach ($items->limit(null) as $item) { |
|
| 24 | 24 | $columnData = array(); |
| 25 | - foreach($csvColumns as $columnSource => $columnHeader) { |
|
| 26 | - $value = ( $item->hasMethod( $columnHeader ) ) ? $item->$columnHeader() : $item->$columnHeader; |
|
| 25 | + foreach ($csvColumns as $columnSource => $columnHeader) { |
|
| 26 | + $value = ($item->hasMethod($columnHeader)) ? $item->$columnHeader() : $item->$columnHeader; |
|
| 27 | 27 | $value = str_replace(array("\r", "\n"), "\n", $value); |
| 28 | - $columnData[] = '"' . str_replace('"', '\"', $value) . '"'; |
|
| 28 | + $columnData[] = '"'.str_replace('"', '\"', $value).'"'; |
|
| 29 | 29 | } |
| 30 | 30 | $fileData .= implode($separator, $columnData); |
| 31 | 31 | $fileData .= "\n"; |
@@ -4,9 +4,9 @@ discard block |
||
| 4 | 4 | public function generatePrintData(GridField $gridField) { |
| 5 | 5 | $printColumns = $this->getPrintColumnsForGridField($gridField); |
| 6 | 6 | $header = null; |
| 7 | - if($this->printHasHeader) { |
|
| 7 | + if ($this->printHasHeader) { |
|
| 8 | 8 | $header = new ArrayList(); |
| 9 | - foreach($printColumns as $field => $label){ |
|
| 9 | + foreach ($printColumns as $field => $label) { |
|
| 10 | 10 | $header->push(new ArrayData(array( |
| 11 | 11 | "CellString" => $label, |
| 12 | 12 | ))); |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | $items = $gridField->getList(); |
| 17 | 17 | $itemRows = new ArrayList(); |
| 18 | - foreach($items as $item) { |
|
| 18 | + foreach ($items as $item) { |
|
| 19 | 19 | $itemRow = new ArrayList(); |
| 20 | - foreach($printColumns as $field => $label) { |
|
| 20 | + foreach ($printColumns as $field => $label) { |
|
| 21 | 21 | $value = $gridField->getDataFieldValue($item, $field); |
| 22 | 22 | $itemRow->push(new ArrayData(array( |
| 23 | 23 | "CellString" => $value, |
@@ -8,9 +8,9 @@ discard block |
||
| 8 | 8 | * on dev/build and contains all the global settings for the |
| 9 | 9 | * automated links |
| 10 | 10 | */ |
| 11 | -class GlobalAutoLinkSettings extends DataObject{ |
|
| 11 | +class GlobalAutoLinkSettings extends DataObject { |
|
| 12 | 12 | |
| 13 | - public static $enabled = true; |
|
| 13 | + public static $enabled = true; |
|
| 14 | 14 | public static $encoding = 'UTF-8'; |
| 15 | 15 | |
| 16 | 16 | private static $db = array( |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return array |
| 38 | 38 | */ |
| 39 | - public function ExcludeTags(){ |
|
| 40 | - return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) ); |
|
| 39 | + public function ExcludeTags() { |
|
| 40 | + return array_unique(explode(',', str_replace(' ', '', $this->ExcludeTags).',a,img,iframe,video,object')); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -45,19 +45,19 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return array |
| 47 | 47 | */ |
| 48 | - public function IncludeInFields(){ |
|
| 49 | - return explode( ',', str_replace( ' ', '', $this->IncludeIn ) ); |
|
| 48 | + public function IncludeInFields() { |
|
| 49 | + return explode(',', str_replace(' ', '', $this->IncludeIn)); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function requireDefaultRecords() { |
| 53 | 53 | $hasData = self::get()->first(); |
| 54 | - if(!$hasData) { |
|
| 54 | + if (!$hasData) { |
|
| 55 | 55 | $obj = self::create(self::$default_create_config); |
| 56 | 56 | $obj->CrawlID = $this->createCrawlID(); |
| 57 | 57 | $obj->write(); |
| 58 | - DB::alteration_message("Added default Global Auto Link Settings","created"); |
|
| 59 | - } else{ |
|
| 60 | - if(!$hasData->CrawlID){ |
|
| 58 | + DB::alteration_message("Added default Global Auto Link Settings", "created"); |
|
| 59 | + }else { |
|
| 60 | + if (!$hasData->CrawlID) { |
|
| 61 | 61 | $hasData->CrawlID = $this->createCrawlID(); |
| 62 | 62 | $hasData->write(); |
| 63 | 63 | } |
@@ -90,24 +90,24 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | - public function AllowedIn(){ |
|
| 94 | - $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) ); |
|
| 95 | - if( !$this->AddTo ) return $classes; |
|
| 93 | + public function AllowedIn() { |
|
| 94 | + $classes = array_values(ClassInfo::subclassesFor('SiteTree')); |
|
| 95 | + if (!$this->AddTo) return $classes; |
|
| 96 | 96 | |
| 97 | - $sanitized = explode( ',', str_replace( ' ', '', strtolower( $this->AddTo ) ) ); |
|
| 97 | + $sanitized = explode(',', str_replace(' ', '', strtolower($this->AddTo))); |
|
| 98 | 98 | |
| 99 | - for( $x = 0; $x < count( $sanitized ); $x++ ){ |
|
| 99 | + for ($x = 0; $x < count($sanitized); $x++) { |
|
| 100 | 100 | $found = false; |
| 101 | 101 | |
| 102 | - foreach( $classes as $class ){ |
|
| 103 | - if( strtolower( $class ) === $sanitized[$x] ){ |
|
| 102 | + foreach ($classes as $class) { |
|
| 103 | + if (strtolower($class) === $sanitized[$x]) { |
|
| 104 | 104 | $sanitized[$x] = $class; |
| 105 | 105 | $found = true; |
| 106 | 106 | break 1; |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if( !$found ) unset( $sanitized[$x] ); |
|
| 110 | + if (!$found) unset($sanitized[$x]); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return (array) $sanitized; |
@@ -151,19 +151,19 @@ |
||
| 151 | 151 | |
| 152 | 152 | if (!$content) return false; |
| 153 | 153 | |
| 154 | - if( class_exists( 'HTML5_Parser' ) ){ |
|
| 155 | - $html5 = HTML5_Parser::parse( $content ); |
|
| 156 | - if($html5 instanceof DOMNodeList){ |
|
| 154 | + if (class_exists('HTML5_Parser')) { |
|
| 155 | + $html5 = HTML5_Parser::parse($content); |
|
| 156 | + if ($html5 instanceof DOMNodeList) { |
|
| 157 | 157 | $dom = new DOMDocument(); |
| 158 | - while($html5->length > 0) { |
|
| 158 | + while ($html5->length > 0) { |
|
| 159 | 159 | $dom->appendChild($html5->item(0)); |
| 160 | 160 | } |
| 161 | - }else{ |
|
| 161 | + }else { |
|
| 162 | 162 | $dom = $html5; |
| 163 | 163 | } |
| 164 | - } else{ |
|
| 164 | + }else { |
|
| 165 | 165 | $dom = new DOMDocument(); |
| 166 | - $dom->loadHTML( $content ); |
|
| 166 | + $dom->loadHTML($content); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | return $dom; |