@@ -84,12 +84,16 @@ discard block |
||
| 84 | 84 | private function getSettings() { |
| 85 | 85 | if ($this->settings === null) { |
| 86 | 86 | $this->settings = GlobalAutoLinkSettings::get_current(); |
| 87 | - if (!$this->settings) return $this->addLinks = false; |
|
| 87 | + if (!$this->settings) { |
|
| 88 | + return $this->addLinks = false; |
|
| 89 | + } |
|
| 88 | 90 | |
| 89 | 91 | $this->excludeTags = (array) $this->settings->ExcludeTags(); |
| 90 | 92 | $this->maxLinks = (int) ($this->settings->MaxLinksPerPage) ? $this->settings->MaxLinksPerPage : PHP_INT_MAX; |
| 91 | 93 | |
| 92 | - if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) $this->addLinks = false; |
|
| 94 | + if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) { |
|
| 95 | + $this->addLinks = false; |
|
| 96 | + } |
|
| 93 | 97 | } |
| 94 | 98 | |
| 95 | 99 | return $this->settings; |
@@ -153,7 +157,9 @@ discard block |
||
| 153 | 157 | $excluded = array(); |
| 154 | 158 | foreach( $this->excludeTags as $eTag ){ |
| 155 | 159 | while( $tags = $html->getElementsByTagName( $eTag ) ){ |
| 156 | - if( !$tags->length ) break 1; |
|
| 160 | + if( !$tags->length ) { |
|
| 161 | + break 1; |
|
| 162 | + } |
|
| 157 | 163 | $tag = $tags->item(0); |
| 158 | 164 | $value = $html->saveHTML( $tag ); |
| 159 | 165 | $key = (string) crc32( $value ); |
@@ -172,7 +178,9 @@ discard block |
||
| 172 | 178 | $links = AutomatedLink::get()->sort('Priority'); |
| 173 | 179 | foreach( $links as $link ){ |
| 174 | 180 | // Check if self-linking is allowed and if current pagetype is allowed |
| 175 | - if( !$link->canBeAdded( $this->owner, $field ) ) continue; |
|
| 181 | + if( !$link->canBeAdded( $this->owner, $field ) ) { |
|
| 182 | + continue; |
|
| 183 | + } |
|
| 176 | 184 | |
| 177 | 185 | $max = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
| 178 | 186 | $escape = (string) preg_quote( $link->Phrase, '/' ); |
@@ -181,22 +189,31 @@ discard block |
||
| 181 | 189 | // Count the matches |
| 182 | 190 | preg_match_all( $regex, $content, $count ); |
| 183 | 191 | $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0; |
| 184 | - if( $count < 1 ) continue; |
|
| 192 | + if( $count < 1 ) { |
|
| 193 | + continue; |
|
| 194 | + } |
|
| 185 | 195 | |
| 186 | - if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) |
|
| 187 | - $max -= $this->maxLinksPerPage[ $link->ID ]; |
|
| 188 | - else |
|
| 189 | - $this->maxLinksPerPage[ $link->ID ] = 0; |
|
| 196 | + if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) { |
|
| 197 | + $max -= $this->maxLinksPerPage[ $link->ID ]; |
|
| 198 | + } else { |
|
| 199 | + $this->maxLinksPerPage[ $link->ID ] = 0; |
|
| 200 | + } |
|
| 190 | 201 | |
| 191 | 202 | for( $x = 0; $x < $count; $x++ ){ |
| 192 | 203 | // Stop adding links if we reached the link or page limit |
| 193 | - if( $x >= $max || $this->linkCount >= $this->maxLinks ) break; |
|
| 204 | + if( $x >= $max || $this->linkCount >= $this->maxLinks ) { |
|
| 205 | + break; |
|
| 206 | + } |
|
| 194 | 207 | |
| 195 | 208 | // Check if there is anything else to replace else stop |
| 196 | 209 | preg_match( $regex, $content, $match ); |
| 197 | - if( !is_array( $match ) || !count( $match ) ) break; |
|
| 210 | + if( !is_array( $match ) || !count( $match ) ) { |
|
| 211 | + break; |
|
| 212 | + } |
|
| 198 | 213 | |
| 199 | - if( !$html = (string) $link->getHTML( $match[0] ) ) continue; |
|
| 214 | + if( !$html = (string) $link->getHTML( $match[0] ) ) { |
|
| 215 | + continue; |
|
| 216 | + } |
|
| 200 | 217 | $key = (string) crc32( $html ); |
| 201 | 218 | $excluded[ $key ] = (string) $html; |
| 202 | 219 | |
@@ -206,7 +223,9 @@ discard block |
||
| 206 | 223 | } |
| 207 | 224 | |
| 208 | 225 | // Stop Adding links if we reached the page limit |
| 209 | - if( $this->linkCount >= $this->maxLinks ) break; |
|
| 226 | + if( $this->linkCount >= $this->maxLinks ) { |
|
| 227 | + break; |
|
| 228 | + } |
|
| 210 | 229 | } |
| 211 | 230 | |
| 212 | 231 | // Re-add the excluded Tags |
@@ -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,15 +31,15 @@ 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 | 37 | $dbFields = Config::inst()->get($this->owner->ClassName, 'db'); |
| 38 | - if(is_array($dbFields)) { |
|
| 39 | - foreach ( $dbFields as $field => $type) { |
|
| 38 | + if (is_array($dbFields)) { |
|
| 39 | + foreach ($dbFields as $field => $type) { |
|
| 40 | 40 | if (strtolower($type) == 'htmltext') { |
| 41 | 41 | $data = ($this->owner->hasMethod($field)) ? $this->owner->$field() : $this->owner->$field; |
| 42 | - if($data){ |
|
| 42 | + if ($data) { |
|
| 43 | 43 | $tmp = new HTMLText('tmp'); |
| 44 | 44 | $tmp->setValue($data); |
| 45 | 45 | $data = base64_encode($tmp->forTemplate()); |
@@ -90,31 +90,31 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return void |
| 92 | 92 | */ |
| 93 | - public function addAutomatedLinks(){ |
|
| 94 | - if( GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage' ) { |
|
| 93 | + public function addAutomatedLinks() { |
|
| 94 | + if (GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage') { |
|
| 95 | 95 | $this->getSettings(); |
| 96 | - if( !$this->addLinks ) { |
|
| 96 | + if (!$this->addLinks) { |
|
| 97 | 97 | return; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - foreach( $this->getSettings()->IncludeInFields() as $field ){ |
|
| 100 | + foreach ($this->getSettings()->IncludeInFields() as $field) { |
|
| 101 | 101 | // Check that the field provided by user exists in this object, is of type HTMLText and has content |
| 102 | - if( AutomatedLink::isFieldParsable( $this->owner->data(), $field ) ){ |
|
| 102 | + if (AutomatedLink::isFieldParsable($this->owner->data(), $field)) { |
|
| 103 | 103 | |
| 104 | 104 | // Create dummy object so we can parse the HTML |
| 105 | - $dummy = new HTMLText( $field ); |
|
| 106 | - $dummy->setValue( $this->owner->$field ); |
|
| 105 | + $dummy = new HTMLText($field); |
|
| 106 | + $dummy->setValue($this->owner->$field); |
|
| 107 | 107 | // Create DOMDocument Object |
| 108 | - $content = mb_convert_encoding( $dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding ); |
|
| 108 | + $content = mb_convert_encoding($dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding); |
|
| 109 | 109 | $dom = AutomatedLink::constructDOMDocument($content); |
| 110 | 110 | |
| 111 | 111 | // Check current link count and if it's already exceeded do nothing |
| 112 | - $this->linkCount += (int) $dom->getElementsByTagName( 'a' )->length; |
|
| 113 | - if( $this->linkCount >= $this->maxLinks ) { |
|
| 112 | + $this->linkCount += (int) $dom->getElementsByTagName('a')->length; |
|
| 113 | + if ($this->linkCount >= $this->maxLinks) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $parsed = $this->parseField( $dom, $field ); |
|
| 117 | + $parsed = $this->parseField($dom, $field); |
|
| 118 | 118 | $this->owner->data()->$field = $parsed; |
| 119 | 119 | $this->owner->$field = $parsed; |
| 120 | 120 | } |
@@ -129,71 +129,71 @@ discard block |
||
| 129 | 129 | * @param String $field |
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | - private function parseField( DOMDocument $html, $field ){ |
|
| 133 | - $this->owner->extend( 'beforeParseField', $html, $field ); |
|
| 132 | + private function parseField(DOMDocument $html, $field) { |
|
| 133 | + $this->owner->extend('beforeParseField', $html, $field); |
|
| 134 | 134 | |
| 135 | 135 | // Remove Tags from Content we wown't be using |
| 136 | 136 | $excluded = array(); |
| 137 | - foreach( $this->excludeTags as $eTag ){ |
|
| 138 | - while( $tags = $html->getElementsByTagName( $eTag ) ){ |
|
| 139 | - if( !$tags->length ) break 1; |
|
| 140 | - $tag = $tags->item(0); |
|
| 141 | - $value = $html->saveHTML( $tag ); |
|
| 142 | - $key = (string) crc32( $value ); |
|
| 137 | + foreach ($this->excludeTags as $eTag) { |
|
| 138 | + while ($tags = $html->getElementsByTagName($eTag)) { |
|
| 139 | + if (!$tags->length) break 1; |
|
| 140 | + $tag = $tags->item(0); |
|
| 141 | + $value = $html->saveHTML($tag); |
|
| 142 | + $key = (string) crc32($value); |
|
| 143 | 143 | |
| 144 | 144 | // Convert back children nodes of this node if they were already hashed |
| 145 | - $excluded[$key] = str_replace( array_keys( $excluded ), array_values( $excluded ), $value ); |
|
| 145 | + $excluded[$key] = str_replace(array_keys($excluded), array_values($excluded), $value); |
|
| 146 | 146 | |
| 147 | - $tag->parentNode->replaceChild( $html->createTextNode( $key ), $tag ); |
|
| 147 | + $tag->parentNode->replaceChild($html->createTextNode($key), $tag); |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - $body = (string)$html->saveHTML( $html->getElementsByTagName('body')->item(0) ); |
|
| 152 | - $content = preg_replace( array( '/\<body\>/is', '/\<\/body\>/is' ), '', $body, 1 ); |
|
| 151 | + $body = (string) $html->saveHTML($html->getElementsByTagName('body')->item(0)); |
|
| 152 | + $content = preg_replace(array('/\<body\>/is', '/\<\/body\>/is'), '', $body, 1); |
|
| 153 | 153 | |
| 154 | 154 | // Create the links |
| 155 | 155 | $links = AutomatedLink::get()->sort('Priority'); |
| 156 | - foreach( $links as $link ){ |
|
| 156 | + foreach ($links as $link) { |
|
| 157 | 157 | // Check if self-linking is allowed and if current pagetype is allowed |
| 158 | - if( !$link->canBeAdded( $this->owner, $field ) ) continue; |
|
| 158 | + if (!$link->canBeAdded($this->owner, $field)) continue; |
|
| 159 | 159 | |
| 160 | - $max = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
|
| 161 | - $escape = (string) preg_quote( $link->Phrase, '/' ); |
|
| 162 | - $regex = (string) ( $link->CaseSensitive ) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i"; |
|
| 160 | + $max = (int) ($link->MaxLinksPerPage > 0) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
|
| 161 | + $escape = (string) preg_quote($link->Phrase, '/'); |
|
| 162 | + $regex = (string) ($link->CaseSensitive) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i"; |
|
| 163 | 163 | |
| 164 | 164 | // Count the matches |
| 165 | - preg_match_all( $regex, $content, $count ); |
|
| 166 | - $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0; |
|
| 167 | - if( $count < 1 ) continue; |
|
| 165 | + preg_match_all($regex, $content, $count); |
|
| 166 | + $count = (is_array($count) && isset($count[0])) ? count($count[0]) : 0; |
|
| 167 | + if ($count < 1) continue; |
|
| 168 | 168 | |
| 169 | - if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) |
|
| 170 | - $max -= $this->maxLinksPerPage[ $link->ID ]; |
|
| 169 | + if (isset($this->maxLinksPerPage[$link->ID])) |
|
| 170 | + $max -= $this->maxLinksPerPage[$link->ID]; |
|
| 171 | 171 | else |
| 172 | - $this->maxLinksPerPage[ $link->ID ] = 0; |
|
| 172 | + $this->maxLinksPerPage[$link->ID] = 0; |
|
| 173 | 173 | |
| 174 | - for( $x = 0; $x < $count; $x++ ){ |
|
| 174 | + for ($x = 0; $x < $count; $x++) { |
|
| 175 | 175 | // Stop adding links if we reached the link or page limit |
| 176 | - if( $x >= $max || $this->linkCount >= $this->maxLinks ) break; |
|
| 176 | + if ($x >= $max || $this->linkCount >= $this->maxLinks) break; |
|
| 177 | 177 | |
| 178 | 178 | // Check if there is anything else to replace else stop |
| 179 | - preg_match( $regex, $content, $match ); |
|
| 180 | - if( !is_array( $match ) || !count( $match ) ) break; |
|
| 179 | + preg_match($regex, $content, $match); |
|
| 180 | + if (!is_array($match) || !count($match)) break; |
|
| 181 | 181 | |
| 182 | - if( !$html = (string) $link->getHTML( $match[0] ) ) continue; |
|
| 183 | - $key = (string) crc32( $html ); |
|
| 184 | - $excluded[ $key ] = (string) $html; |
|
| 182 | + if (!$html = (string) $link->getHTML($match[0])) continue; |
|
| 183 | + $key = (string) crc32($html); |
|
| 184 | + $excluded[$key] = (string) $html; |
|
| 185 | 185 | |
| 186 | - $content = preg_replace( $regex, $key, $content, 1 ); |
|
| 186 | + $content = preg_replace($regex, $key, $content, 1); |
|
| 187 | 187 | $this->linkCount++; |
| 188 | - $this->maxLinksPerPage[ $link->ID ]++; |
|
| 188 | + $this->maxLinksPerPage[$link->ID]++; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // Stop Adding links if we reached the page limit |
| 192 | - if( $this->linkCount >= $this->maxLinks ) break; |
|
| 192 | + if ($this->linkCount >= $this->maxLinks) break; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // Re-add the excluded Tags |
| 196 | - $content = str_replace( array_keys( $excluded ), array_values( $excluded ), $content ); |
|
| 196 | + $content = str_replace(array_keys($excluded), array_values($excluded), $content); |
|
| 197 | 197 | |
| 198 | 198 | return $content; |
| 199 | 199 | } |
@@ -8,7 +8,9 @@ discard block |
||
| 8 | 8 | private static $exclude_classes = array('RedirectorPage', 'VirtualPage'); |
| 9 | 9 | |
| 10 | 10 | public function index() { |
| 11 | - if (!Director::is_cli()) return 'Please run this controller in CLI'; |
|
| 11 | + if (!Director::is_cli()) { |
|
| 12 | + return 'Please run this controller in CLI'; |
|
| 13 | + } |
|
| 12 | 14 | |
| 13 | 15 | libxml_use_internal_errors(true); |
| 14 | 16 | set_time_limit(600); |
@@ -44,15 +46,23 @@ discard block |
||
| 44 | 46 | $exclude = Config::inst()->get($this->class, 'exclude_classes'); |
| 45 | 47 | $exclude = ($exclude) ? "'".implode("','", $exclude)."'" : ''; |
| 46 | 48 | foreach (SiteTree::get()->where("ClassName NOT IN($exclude)") as $page) { |
| 47 | - if (!$this->checkForPossibleLinks($page, $includeInFields)) continue; |
|
| 49 | + if (!$this->checkForPossibleLinks($page, $includeInFields)) { |
|
| 50 | + continue; |
|
| 51 | + } |
|
| 48 | 52 | $page = $this->getLinkData($page, $includeInFields); |
| 49 | - if (!$page) continue; |
|
| 53 | + if (!$page) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 50 | 56 | |
| 51 | - if (!$run_in_realtime) AutomatedLinkPageResult::add_or_update($page); |
|
| 57 | + if (!$run_in_realtime) { |
|
| 58 | + AutomatedLinkPageResult::add_or_update($page); |
|
| 59 | + } |
|
| 52 | 60 | $data->push($page); |
| 53 | 61 | } |
| 54 | 62 | |
| 55 | - if (!$run_in_realtime) AutomatedLinkPageResult::remove_old_data(); |
|
| 63 | + if (!$run_in_realtime) { |
|
| 64 | + AutomatedLinkPageResult::remove_old_data(); |
|
| 65 | + } |
|
| 56 | 66 | |
| 57 | 67 | return $data; |
| 58 | 68 | } |
@@ -70,15 +80,18 @@ discard block |
||
| 70 | 80 | // Set a list of all fields that can have autolinks created in them |
| 71 | 81 | $page->AutomateableFields = ArrayList::create(); |
| 72 | 82 | |
| 73 | - foreach ($this->getAllDatabaseFields($page->class) as $field => $type) |
|
| 74 | - if (in_array($field, $includeIn) && |
|
| 83 | + foreach ($this->getAllDatabaseFields($page->class) as $field => $type) { |
|
| 84 | + if (in_array($field, $includeIn) && |
|
| 75 | 85 | !$page->AutomateableFields->find('DataField', $field) && |
| 76 | 86 | AutomatedLink::isFieldParsable($page, $field) |
| 77 | 87 | ) $page->AutomateableFields->push(DataObject::create(array('DataField' => $field))); |
| 88 | + } |
|
| 78 | 89 | |
| 79 | 90 | // Get data Pre-Automated Links creation |
| 80 | 91 | $withLinks = $this->getPageDOM($page, true); |
| 81 | - if (!$withLinks) return false; |
|
| 92 | + if (!$withLinks) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 82 | 95 | |
| 83 | 96 | $links = $withLinks->getElementsByTagName('a'); |
| 84 | 97 | |
@@ -88,10 +101,11 @@ discard block |
||
| 88 | 101 | |
| 89 | 102 | // List all automated links that were created in this $page |
| 90 | 103 | $linksUsed = array(); |
| 91 | - foreach ($this->Links as $autolink) |
|
| 92 | - foreach ($links as $link) { |
|
| 104 | + foreach ($this->Links as $autolink) { |
|
| 105 | + foreach ($links as $link) { |
|
| 93 | 106 | if ($link->getAttribute('data-id') == $autolink->ID) { |
| 94 | 107 | $linksUsed[$autolink->ID] = $autolink->Phrase; |
| 108 | + } |
|
| 95 | 109 | $page->OriginalLinkCount--; |
| 96 | 110 | $page->LinkCount++; |
| 97 | 111 | } |
@@ -99,7 +113,9 @@ discard block |
||
| 99 | 113 | |
| 100 | 114 | $page->Links = implode(', ', $linksUsed); |
| 101 | 115 | |
| 102 | - if ($page->LinkCount < 1) return false; |
|
| 116 | + if ($page->LinkCount < 1) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 103 | 119 | |
| 104 | 120 | return $page; |
| 105 | 121 | } |
@@ -113,8 +129,9 @@ discard block |
||
| 113 | 129 | */ |
| 114 | 130 | private function getAllDatabaseFields($class) { |
| 115 | 131 | $fields = array(); |
| 116 | - foreach (ClassInfo::ancestry($class, true) as $cls) |
|
| 117 | - $fields = array_merge($fields, (array) DataObject::database_fields($cls)); |
|
| 132 | + foreach (ClassInfo::ancestry($class, true) as $cls) { |
|
| 133 | + $fields = array_merge($fields, (array) DataObject::database_fields($cls)); |
|
| 134 | + } |
|
| 118 | 135 | |
| 119 | 136 | return $fields; |
| 120 | 137 | } |
@@ -129,8 +146,12 @@ discard block |
||
| 129 | 146 | */ |
| 130 | 147 | private function getPageDOM(SiteTree $page) { |
| 131 | 148 | $controllerClass = $page->class.'_Controller'; |
| 132 | - if (!class_exists($controllerClass)) $controller = $page->class.'Controller'; |
|
| 133 | - if (!class_exists($controllerClass)) return false; |
|
| 149 | + if (!class_exists($controllerClass)) { |
|
| 150 | + $controller = $page->class.'Controller'; |
|
| 151 | + } |
|
| 152 | + if (!class_exists($controllerClass)) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 134 | 155 | |
| 135 | 156 | $controller = $controllerClass::create($page); |
| 136 | 157 | $controller->invokeWithExtensions('addAutomatedLinks'); |
@@ -161,9 +182,10 @@ discard block |
||
| 161 | 182 | * @return Boolean |
| 162 | 183 | */ |
| 163 | 184 | private function checkForPossibleLinks(SiteTree $page, array $includeIn) { |
| 164 | - foreach ($this->Links as $link) |
|
| 165 | - foreach ($includeIn as $possibleField) |
|
| 185 | + foreach ($this->Links as $link) { |
|
| 186 | + foreach ($includeIn as $possibleField) |
|
| 166 | 187 | if (isset($page->$possibleField) && preg_match("/\b{$link->Phrase}\b/i", $page->$possibleField)) return true; |
| 188 | + } |
|
| 167 | 189 | |
| 168 | 190 | return false; |
| 169 | 191 | } |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | 'Page' => 'SiteTree' |
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - private static $summary_fields = array( 'Phrase', 'PointsTo' ); |
|
| 37 | - private static $searchable_fields = array( 'Phrase' ); |
|
| 38 | - private static $singular_name = 'Automated Link'; |
|
| 36 | + private static $summary_fields = array('Phrase', 'PointsTo'); |
|
| 37 | + private static $searchable_fields = array('Phrase'); |
|
| 38 | + private static $singular_name = 'Automated Link'; |
|
| 39 | 39 | private static $plural_name = 'Automated Links'; |
| 40 | 40 | private static $parsableFields = array(); |
| 41 | 41 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return string |
| 46 | 46 | */ |
| 47 | - public function PointsTo(){ |
|
| 47 | + public function PointsTo() { |
|
| 48 | 48 | return $this->Page()->Link(); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return string |
| 55 | 55 | */ |
| 56 | - public function Title(){ |
|
| 56 | + public function Title() { |
|
| 57 | 57 | return $this->Phrase; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -62,23 +62,23 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return String |
| 64 | 64 | */ |
| 65 | - public function forTemplate(){ |
|
| 65 | + public function forTemplate() { |
|
| 66 | 66 | return $this->getHTML(); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - function canView( $member = false ){ |
|
| 69 | + function canView($member = false) { |
|
| 70 | 70 | return Permission::check('AUTOMATEDLINK_VIEW'); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - function canEdit( $member = false ){ |
|
| 73 | + function canEdit($member = false) { |
|
| 74 | 74 | return Permission::check('AUTOMATEDLINK_EDIT'); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - function canDelete( $member = false ){ |
|
| 77 | + function canDelete($member = false) { |
|
| 78 | 78 | return Permission::check('AUTOMATEDLINK_DELETE'); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - function canCreate( $member = false ){ |
|
| 81 | + function canCreate($member = false) { |
|
| 82 | 82 | return Permission::check('AUTOMATEDLINK_CREATE'); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | ); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - public function requireDefaultRecords(){ |
|
| 94 | + public function requireDefaultRecords() { |
|
| 95 | 95 | parent::requireDefaultRecords(); |
| 96 | 96 | |
| 97 | 97 | // Update all links to redirector pages during dev/build |
| 98 | - foreach( self::get() as $link ) { |
|
| 99 | - $link->CheckAndUpdateDestination( true ); |
|
| 98 | + foreach (self::get() as $link) { |
|
| 99 | + $link->CheckAndUpdateDestination(true); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
@@ -197,15 +197,15 @@ discard block |
||
| 197 | 197 | * @Boolean $write - Write the changes if any |
| 198 | 198 | * @return void |
| 199 | 199 | */ |
| 200 | - public function CheckAndUpdateDestination( $write = false ){ |
|
| 200 | + public function CheckAndUpdateDestination($write = false) { |
|
| 201 | 201 | $this->extend('beforeCheckAndUpdateDestination', $write); |
| 202 | 202 | |
| 203 | - if( $this->PageID && $this->Page() && |
|
| 203 | + if ($this->PageID && $this->Page() && |
|
| 204 | 204 | $this->Page()->ClassName == 'RedirectorPage' && |
| 205 | - $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' ) |
|
| 205 | + $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal') |
|
| 206 | 206 | { |
| 207 | 207 | $this->PageID = $this->Page()->LinkToID; |
| 208 | - if( $write ) { |
|
| 208 | + if ($write) { |
|
| 209 | 209 | $this->write(); |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * @param ContentController $controller |
| 240 | 240 | * @return Boolean |
| 241 | 241 | */ |
| 242 | - public function canBeAdded( ContentController $controller ){ |
|
| 243 | - return ( $this->SelfLinking || $controller->ID != $this->PageID ); |
|
| 242 | + public function canBeAdded(ContentController $controller) { |
|
| 243 | + return ($this->SelfLinking || $controller->ID != $this->PageID); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -249,20 +249,20 @@ discard block |
||
| 249 | 249 | * @param string $html |
| 250 | 250 | * @return DOMDocument |
| 251 | 251 | */ |
| 252 | - public static function constructDOMDocument($html){ |
|
| 253 | - if( class_exists( 'HTML5_Parser' ) ){ |
|
| 254 | - $html5 = HTML5_Parser::parse( $html ); |
|
| 255 | - if($html5 instanceof DOMNodeList){ |
|
| 252 | + public static function constructDOMDocument($html) { |
|
| 253 | + if (class_exists('HTML5_Parser')) { |
|
| 254 | + $html5 = HTML5_Parser::parse($html); |
|
| 255 | + if ($html5 instanceof DOMNodeList) { |
|
| 256 | 256 | $dom = new DOMDocument(); |
| 257 | - while($html5->length > 0) { |
|
| 257 | + while ($html5->length > 0) { |
|
| 258 | 258 | $dom->appendChild($html5->item(0)); |
| 259 | 259 | } |
| 260 | - }else{ |
|
| 260 | + }else { |
|
| 261 | 261 | $dom = $html5; |
| 262 | 262 | } |
| 263 | - } else{ |
|
| 263 | + }else { |
|
| 264 | 264 | $dom = new DOMDocument(); |
| 265 | - $dom->loadHTML( $html ); |
|
| 265 | + $dom->loadHTML($html); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | return $dom; |
@@ -222,8 +222,9 @@ discard block |
||
| 222 | 222 | if (!isset(self::$parsableFields[$page->ID]) || !isset(self::$parsableFields[$page->ID][$field])) { |
| 223 | 223 | $fields = array(); |
| 224 | 224 | |
| 225 | - foreach (ClassInfo::ancestry($page->ClassName, true) as $class) |
|
| 226 | - $fields = array_merge($fields, (array) DataObject::database_fields($class)); |
|
| 225 | + foreach (ClassInfo::ancestry($page->ClassName, true) as $class) { |
|
| 226 | + $fields = array_merge($fields, (array) DataObject::database_fields($class)); |
|
| 227 | + } |
|
| 227 | 228 | |
| 228 | 229 | self::$parsableFields[$page->ID][$field] = |
| 229 | 230 | (Boolean) array_key_exists($field, $fields) && strtolower($fields[$field]) === 'htmltext' && $page->$field; |
@@ -257,7 +258,7 @@ discard block |
||
| 257 | 258 | while($html5->length > 0) { |
| 258 | 259 | $dom->appendChild($html5->item(0)); |
| 259 | 260 | } |
| 260 | - }else{ |
|
| 261 | + } else{ |
|
| 261 | 262 | $dom = $html5; |
| 262 | 263 | } |
| 263 | 264 | } else{ |