@@ -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 |
@@ -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, |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | private $excludeTags = array(); |
| 19 | 19 | private $maxLinks = 0; |
| 20 | 20 | |
| 21 | - public function index(){ |
|
| 21 | + public function index() { |
|
| 22 | 22 | $this->addAutomatedLinks(); |
| 23 | 23 | |
| 24 | 24 | // If we have a crawl request check the CrawlID so we're sure we didn't hit another SS site running our module |
| 25 | - if( $crawl_id = $this->owner->request->getHeader('X-Crawl-Id') ){ |
|
| 26 | - return( $crawl_id == GlobalAutoLinkSettings::get_current()->CrawlID ) |
|
| 25 | + if ($crawl_id = $this->owner->request->getHeader('X-Crawl-Id')) { |
|
| 26 | + return($crawl_id == GlobalAutoLinkSettings::get_current()->CrawlID) |
|
| 27 | 27 | ? $this->crawl_response() |
| 28 | 28 | : $this->owner->redirect(SEOTestSiteTreeController::getPermissionDeniedPage()->Link()); |
| 29 | 29 | } |
@@ -31,13 +31,13 @@ discard block |
||
| 31 | 31 | return array(); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - private function crawl_response(){ |
|
| 34 | + private function crawl_response() { |
|
| 35 | 35 | // Encoded version to detect which fields are being used |
| 36 | 36 | $customize = array(); |
| 37 | - foreach( Config::inst()->get($this->owner->ClassName, 'db') as $field => $type ){ |
|
| 38 | - if( strtolower( $type ) == 'htmltext' ){ |
|
| 37 | + foreach (Config::inst()->get($this->owner->ClassName, 'db') as $field => $type) { |
|
| 38 | + if (strtolower($type) == 'htmltext') { |
|
| 39 | 39 | $data = ($this->owner->hasMethod($field)) ? $this->owner->$field() : $this->owner->$field; |
| 40 | - if( !$data ) { |
|
| 40 | + if (!$data) { |
|
| 41 | 41 | continue; |
| 42 | 42 | } |
| 43 | 43 | $tmp = new HTMLText('tmp'); |
@@ -88,37 +88,37 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return void |
| 90 | 90 | */ |
| 91 | - public function addAutomatedLinks(){ |
|
| 92 | - if( GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage' ) { |
|
| 91 | + public function addAutomatedLinks() { |
|
| 92 | + if (GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage') { |
|
| 93 | 93 | $this->getSettings(); |
| 94 | - if( !$this->addLinks ) { |
|
| 94 | + if (!$this->addLinks) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - foreach( $this->getSettings()->IncludeInFields() as $field ){ |
|
| 98 | + foreach ($this->getSettings()->IncludeInFields() as $field) { |
|
| 99 | 99 | // Check that the field provided by user exists in this object, is of type HTMLText and has content |
| 100 | - if( AutomatedLink::isFieldParsable( $this->owner->data(), $field ) ){ |
|
| 100 | + if (AutomatedLink::isFieldParsable($this->owner->data(), $field)) { |
|
| 101 | 101 | |
| 102 | 102 | // Create dummy object so we can parse the HTML |
| 103 | - $dummy = new HTMLText( $field ); |
|
| 104 | - $dummy->setValue( $this->owner->$field ); |
|
| 103 | + $dummy = new HTMLText($field); |
|
| 104 | + $dummy->setValue($this->owner->$field); |
|
| 105 | 105 | // Create DOMDocument Object |
| 106 | - $content = mb_convert_encoding( $dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding ); |
|
| 106 | + $content = mb_convert_encoding($dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding); |
|
| 107 | 107 | |
| 108 | - if( class_exists( 'HTML5_Parser' ) ){ |
|
| 109 | - $dom = HTML5_Parser::parse( $content ); |
|
| 110 | - } else{ |
|
| 108 | + if (class_exists('HTML5_Parser')) { |
|
| 109 | + $dom = HTML5_Parser::parse($content); |
|
| 110 | + }else { |
|
| 111 | 111 | $dom = new DOMDocument(); |
| 112 | - $dom->loadHTML( $content ); |
|
| 112 | + $dom->loadHTML($content); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Check current link count and if it's already exceeded do nothing |
| 116 | - $this->linkCount += (int) $dom->getElementsByTagName( 'a' )->length; |
|
| 117 | - if( $this->linkCount >= $this->maxLinks ) { |
|
| 116 | + $this->linkCount += (int) $dom->getElementsByTagName('a')->length; |
|
| 117 | + if ($this->linkCount >= $this->maxLinks) { |
|
| 118 | 118 | return; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $parsed = $this->parseField( $dom, $field ); |
|
| 121 | + $parsed = $this->parseField($dom, $field); |
|
| 122 | 122 | $this->owner->data()->$field = $parsed; |
| 123 | 123 | $this->owner->$field = $parsed; |
| 124 | 124 | } |
@@ -133,71 +133,71 @@ discard block |
||
| 133 | 133 | * @param String $field |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - private function parseField( DOMDocument $html, $field ){ |
|
| 137 | - $this->owner->extend( 'beforeParseField', $html, $field ); |
|
| 136 | + private function parseField(DOMDocument $html, $field) { |
|
| 137 | + $this->owner->extend('beforeParseField', $html, $field); |
|
| 138 | 138 | |
| 139 | 139 | // Remove Tags from Content we wown't be using |
| 140 | 140 | $excluded = array(); |
| 141 | - foreach( $this->excludeTags as $eTag ){ |
|
| 142 | - while( $tags = $html->getElementsByTagName( $eTag ) ){ |
|
| 143 | - if( !$tags->length ) break 1; |
|
| 144 | - $tag = $tags->item(0); |
|
| 145 | - $value = $html->saveHTML( $tag ); |
|
| 146 | - $key = (string) crc32( $value ); |
|
| 141 | + foreach ($this->excludeTags as $eTag) { |
|
| 142 | + while ($tags = $html->getElementsByTagName($eTag)) { |
|
| 143 | + if (!$tags->length) break 1; |
|
| 144 | + $tag = $tags->item(0); |
|
| 145 | + $value = $html->saveHTML($tag); |
|
| 146 | + $key = (string) crc32($value); |
|
| 147 | 147 | |
| 148 | 148 | // Convert back children nodes of this node if they were already hashed |
| 149 | - $excluded[$key] = str_replace( array_keys( $excluded ), array_values( $excluded ), $value ); |
|
| 149 | + $excluded[$key] = str_replace(array_keys($excluded), array_values($excluded), $value); |
|
| 150 | 150 | |
| 151 | - $tag->parentNode->replaceChild( $html->createTextNode( $key ), $tag ); |
|
| 151 | + $tag->parentNode->replaceChild($html->createTextNode($key), $tag); |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $body = (string)$html->saveHTML( $html->getElementsByTagName('body')->item(0) ); |
|
| 156 | - $content = preg_replace( array( '/\<body\>/is', '/\<\/body\>/is' ), '', $body, 1 ); |
|
| 155 | + $body = (string) $html->saveHTML($html->getElementsByTagName('body')->item(0)); |
|
| 156 | + $content = preg_replace(array('/\<body\>/is', '/\<\/body\>/is'), '', $body, 1); |
|
| 157 | 157 | |
| 158 | 158 | // Create the links |
| 159 | 159 | $links = AutomatedLink::get()->sort('Priority'); |
| 160 | - foreach( $links as $link ){ |
|
| 160 | + foreach ($links as $link) { |
|
| 161 | 161 | // Check if self-linking is allowed and if current pagetype is allowed |
| 162 | - if( !$link->canBeAdded( $this->owner, $field ) ) continue; |
|
| 162 | + if (!$link->canBeAdded($this->owner, $field)) continue; |
|
| 163 | 163 | |
| 164 | - $max = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
|
| 165 | - $escape = (string) preg_quote( $link->Phrase, '/' ); |
|
| 166 | - $regex = (string) ( $link->CaseSensitive ) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i"; |
|
| 164 | + $max = (int) ($link->MaxLinksPerPage > 0) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
|
| 165 | + $escape = (string) preg_quote($link->Phrase, '/'); |
|
| 166 | + $regex = (string) ($link->CaseSensitive) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i"; |
|
| 167 | 167 | |
| 168 | 168 | // Count the matches |
| 169 | - preg_match_all( $regex, $content, $count ); |
|
| 170 | - $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0; |
|
| 171 | - if( $count < 1 ) continue; |
|
| 169 | + preg_match_all($regex, $content, $count); |
|
| 170 | + $count = (is_array($count) && isset($count[0])) ? count($count[0]) : 0; |
|
| 171 | + if ($count < 1) continue; |
|
| 172 | 172 | |
| 173 | - if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) |
|
| 174 | - $max -= $this->maxLinksPerPage[ $link->ID ]; |
|
| 173 | + if (isset($this->maxLinksPerPage[$link->ID])) |
|
| 174 | + $max -= $this->maxLinksPerPage[$link->ID]; |
|
| 175 | 175 | else |
| 176 | - $this->maxLinksPerPage[ $link->ID ] = 0; |
|
| 176 | + $this->maxLinksPerPage[$link->ID] = 0; |
|
| 177 | 177 | |
| 178 | - for( $x = 0; $x < $count; $x++ ){ |
|
| 178 | + for ($x = 0; $x < $count; $x++) { |
|
| 179 | 179 | // Stop adding links if we reached the link or page limit |
| 180 | - if( $x >= $max || $this->linkCount >= $this->maxLinks ) break; |
|
| 180 | + if ($x >= $max || $this->linkCount >= $this->maxLinks) break; |
|
| 181 | 181 | |
| 182 | 182 | // Check if there is anything else to replace else stop |
| 183 | - preg_match( $regex, $content, $match ); |
|
| 184 | - if( !is_array( $match ) || !count( $match ) ) break; |
|
| 183 | + preg_match($regex, $content, $match); |
|
| 184 | + if (!is_array($match) || !count($match)) break; |
|
| 185 | 185 | |
| 186 | - if( !$html = (string) $link->getHTML( $match[0] ) ) continue; |
|
| 187 | - $key = (string) crc32( $html ); |
|
| 188 | - $excluded[ $key ] = (string) $html; |
|
| 186 | + if (!$html = (string) $link->getHTML($match[0])) continue; |
|
| 187 | + $key = (string) crc32($html); |
|
| 188 | + $excluded[$key] = (string) $html; |
|
| 189 | 189 | |
| 190 | - $content = preg_replace( $regex, $key, $content, 1 ); |
|
| 190 | + $content = preg_replace($regex, $key, $content, 1); |
|
| 191 | 191 | $this->linkCount++; |
| 192 | - $this->maxLinksPerPage[ $link->ID ]++; |
|
| 192 | + $this->maxLinksPerPage[$link->ID]++; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // Stop Adding links if we reached the page limit |
| 196 | - if( $this->linkCount >= $this->maxLinks ) break; |
|
| 196 | + if ($this->linkCount >= $this->maxLinks) break; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | // Re-add the excluded Tags |
| 200 | - $content = str_replace( array_keys( $excluded ), array_values( $excluded ), $content ); |
|
| 200 | + $content = str_replace(array_keys($excluded), array_values($excluded), $content); |
|
| 201 | 201 | |
| 202 | 202 | return $content; |
| 203 | 203 | } |
@@ -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; |