@@ -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; |
@@ -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'); |
@@ -149,7 +170,9 @@ discard block |
||
| 149 | 170 | GlobalAutoLinkSettings::$encoding |
| 150 | 171 | ); |
| 151 | 172 | |
| 152 | - if (!$content) return false; |
|
| 173 | + if (!$content) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 153 | 176 | |
| 154 | 177 | if( class_exists( 'HTML5_Parser' ) ){ |
| 155 | 178 | $html5 = HTML5_Parser::parse( $content ); |
@@ -158,7 +181,7 @@ discard block |
||
| 158 | 181 | while($html5->length > 0) { |
| 159 | 182 | $dom->appendChild($html5->item(0)); |
| 160 | 183 | } |
| 161 | - }else{ |
|
| 184 | + } else{ |
|
| 162 | 185 | $dom = $html5; |
| 163 | 186 | } |
| 164 | 187 | } else{ |
@@ -178,9 +201,10 @@ discard block |
||
| 178 | 201 | * @return Boolean |
| 179 | 202 | */ |
| 180 | 203 | private function checkForPossibleLinks(SiteTree $page, array $includeIn) { |
| 181 | - foreach ($this->Links as $link) |
|
| 182 | - foreach ($includeIn as $possibleField) |
|
| 204 | + foreach ($this->Links as $link) { |
|
| 205 | + foreach ($includeIn as $possibleField) |
|
| 183 | 206 | if (isset($page->$possibleField) && preg_match("/\b{$link->Phrase}\b/i", $page->$possibleField)) return true; |
| 207 | + } |
|
| 184 | 208 | |
| 185 | 209 | return false; |
| 186 | 210 | } |
@@ -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,45 +90,45 @@ 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 | |
| 110 | - if( class_exists( 'HTML5_Parser' ) ){ |
|
| 111 | - $html5 = HTML5_Parser::parse( $content ); |
|
| 112 | - if($html5 instanceof DOMNodeList){ |
|
| 110 | + if (class_exists('HTML5_Parser')) { |
|
| 111 | + $html5 = HTML5_Parser::parse($content); |
|
| 112 | + if ($html5 instanceof DOMNodeList) { |
|
| 113 | 113 | $dom = new DOMDocument(); |
| 114 | - while($html5->length > 0) { |
|
| 114 | + while ($html5->length > 0) { |
|
| 115 | 115 | $dom->appendChild($html5->item(0)); |
| 116 | 116 | } |
| 117 | - }else{ |
|
| 117 | + }else { |
|
| 118 | 118 | $dom = $html5; |
| 119 | 119 | } |
| 120 | - } else{ |
|
| 120 | + }else { |
|
| 121 | 121 | $dom = new DOMDocument(); |
| 122 | - $dom->loadHTML( $content ); |
|
| 122 | + $dom->loadHTML($content); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Check current link count and if it's already exceeded do nothing |
| 126 | - $this->linkCount += (int) $dom->getElementsByTagName( 'a' )->length; |
|
| 127 | - if( $this->linkCount >= $this->maxLinks ) { |
|
| 126 | + $this->linkCount += (int) $dom->getElementsByTagName('a')->length; |
|
| 127 | + if ($this->linkCount >= $this->maxLinks) { |
|
| 128 | 128 | return; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $parsed = $this->parseField( $dom, $field ); |
|
| 131 | + $parsed = $this->parseField($dom, $field); |
|
| 132 | 132 | $this->owner->data()->$field = $parsed; |
| 133 | 133 | $this->owner->$field = $parsed; |
| 134 | 134 | } |
@@ -143,71 +143,71 @@ discard block |
||
| 143 | 143 | * @param String $field |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - private function parseField( DOMDocument $html, $field ){ |
|
| 147 | - $this->owner->extend( 'beforeParseField', $html, $field ); |
|
| 146 | + private function parseField(DOMDocument $html, $field) { |
|
| 147 | + $this->owner->extend('beforeParseField', $html, $field); |
|
| 148 | 148 | |
| 149 | 149 | // Remove Tags from Content we wown't be using |
| 150 | 150 | $excluded = array(); |
| 151 | - foreach( $this->excludeTags as $eTag ){ |
|
| 152 | - while( $tags = $html->getElementsByTagName( $eTag ) ){ |
|
| 153 | - if( !$tags->length ) break 1; |
|
| 154 | - $tag = $tags->item(0); |
|
| 155 | - $value = $html->saveHTML( $tag ); |
|
| 156 | - $key = (string) crc32( $value ); |
|
| 151 | + foreach ($this->excludeTags as $eTag) { |
|
| 152 | + while ($tags = $html->getElementsByTagName($eTag)) { |
|
| 153 | + if (!$tags->length) break 1; |
|
| 154 | + $tag = $tags->item(0); |
|
| 155 | + $value = $html->saveHTML($tag); |
|
| 156 | + $key = (string) crc32($value); |
|
| 157 | 157 | |
| 158 | 158 | // Convert back children nodes of this node if they were already hashed |
| 159 | - $excluded[$key] = str_replace( array_keys( $excluded ), array_values( $excluded ), $value ); |
|
| 159 | + $excluded[$key] = str_replace(array_keys($excluded), array_values($excluded), $value); |
|
| 160 | 160 | |
| 161 | - $tag->parentNode->replaceChild( $html->createTextNode( $key ), $tag ); |
|
| 161 | + $tag->parentNode->replaceChild($html->createTextNode($key), $tag); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - $body = (string)$html->saveHTML( $html->getElementsByTagName('body')->item(0) ); |
|
| 166 | - $content = preg_replace( array( '/\<body\>/is', '/\<\/body\>/is' ), '', $body, 1 ); |
|
| 165 | + $body = (string) $html->saveHTML($html->getElementsByTagName('body')->item(0)); |
|
| 166 | + $content = preg_replace(array('/\<body\>/is', '/\<\/body\>/is'), '', $body, 1); |
|
| 167 | 167 | |
| 168 | 168 | // Create the links |
| 169 | 169 | $links = AutomatedLink::get()->sort('Priority'); |
| 170 | - foreach( $links as $link ){ |
|
| 170 | + foreach ($links as $link) { |
|
| 171 | 171 | // Check if self-linking is allowed and if current pagetype is allowed |
| 172 | - if( !$link->canBeAdded( $this->owner, $field ) ) continue; |
|
| 172 | + if (!$link->canBeAdded($this->owner, $field)) continue; |
|
| 173 | 173 | |
| 174 | - $max = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
|
| 175 | - $escape = (string) preg_quote( $link->Phrase, '/' ); |
|
| 176 | - $regex = (string) ( $link->CaseSensitive ) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i"; |
|
| 174 | + $max = (int) ($link->MaxLinksPerPage > 0) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
|
| 175 | + $escape = (string) preg_quote($link->Phrase, '/'); |
|
| 176 | + $regex = (string) ($link->CaseSensitive) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i"; |
|
| 177 | 177 | |
| 178 | 178 | // Count the matches |
| 179 | - preg_match_all( $regex, $content, $count ); |
|
| 180 | - $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0; |
|
| 181 | - if( $count < 1 ) continue; |
|
| 179 | + preg_match_all($regex, $content, $count); |
|
| 180 | + $count = (is_array($count) && isset($count[0])) ? count($count[0]) : 0; |
|
| 181 | + if ($count < 1) continue; |
|
| 182 | 182 | |
| 183 | - if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) |
|
| 184 | - $max -= $this->maxLinksPerPage[ $link->ID ]; |
|
| 183 | + if (isset($this->maxLinksPerPage[$link->ID])) |
|
| 184 | + $max -= $this->maxLinksPerPage[$link->ID]; |
|
| 185 | 185 | else |
| 186 | - $this->maxLinksPerPage[ $link->ID ] = 0; |
|
| 186 | + $this->maxLinksPerPage[$link->ID] = 0; |
|
| 187 | 187 | |
| 188 | - for( $x = 0; $x < $count; $x++ ){ |
|
| 188 | + for ($x = 0; $x < $count; $x++) { |
|
| 189 | 189 | // Stop adding links if we reached the link or page limit |
| 190 | - if( $x >= $max || $this->linkCount >= $this->maxLinks ) break; |
|
| 190 | + if ($x >= $max || $this->linkCount >= $this->maxLinks) break; |
|
| 191 | 191 | |
| 192 | 192 | // Check if there is anything else to replace else stop |
| 193 | - preg_match( $regex, $content, $match ); |
|
| 194 | - if( !is_array( $match ) || !count( $match ) ) break; |
|
| 193 | + preg_match($regex, $content, $match); |
|
| 194 | + if (!is_array($match) || !count($match)) break; |
|
| 195 | 195 | |
| 196 | - if( !$html = (string) $link->getHTML( $match[0] ) ) continue; |
|
| 197 | - $key = (string) crc32( $html ); |
|
| 198 | - $excluded[ $key ] = (string) $html; |
|
| 196 | + if (!$html = (string) $link->getHTML($match[0])) continue; |
|
| 197 | + $key = (string) crc32($html); |
|
| 198 | + $excluded[$key] = (string) $html; |
|
| 199 | 199 | |
| 200 | - $content = preg_replace( $regex, $key, $content, 1 ); |
|
| 200 | + $content = preg_replace($regex, $key, $content, 1); |
|
| 201 | 201 | $this->linkCount++; |
| 202 | - $this->maxLinksPerPage[ $link->ID ]++; |
|
| 202 | + $this->maxLinksPerPage[$link->ID]++; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // Stop Adding links if we reached the page limit |
| 206 | - if( $this->linkCount >= $this->maxLinks ) break; |
|
| 206 | + if ($this->linkCount >= $this->maxLinks) break; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | // Re-add the excluded Tags |
| 210 | - $content = str_replace( array_keys( $excluded ), array_values( $excluded ), $content ); |
|
| 210 | + $content = str_replace(array_keys($excluded), array_values($excluded), $content); |
|
| 211 | 211 | |
| 212 | 212 | return $content; |
| 213 | 213 | } |
@@ -73,12 +73,16 @@ discard block |
||
| 73 | 73 | private function getSettings() { |
| 74 | 74 | if ($this->settings === null) { |
| 75 | 75 | $this->settings = GlobalAutoLinkSettings::get_current(); |
| 76 | - if (!$this->settings) return $this->addLinks = false; |
|
| 76 | + if (!$this->settings) { |
|
| 77 | + return $this->addLinks = false; |
|
| 78 | + } |
|
| 77 | 79 | |
| 78 | 80 | $this->excludeTags = (array) $this->settings->ExcludeTags(); |
| 79 | 81 | $this->maxLinks = (int) ($this->settings->MaxLinksPerPage) ? $this->settings->MaxLinksPerPage : PHP_INT_MAX; |
| 80 | 82 | |
| 81 | - if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) $this->addLinks = false; |
|
| 83 | + if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) { |
|
| 84 | + $this->addLinks = false; |
|
| 85 | + } |
|
| 82 | 86 | } |
| 83 | 87 | |
| 84 | 88 | return $this->settings; |
@@ -114,7 +118,7 @@ discard block |
||
| 114 | 118 | while($html5->length > 0) { |
| 115 | 119 | $dom->appendChild($html5->item(0)); |
| 116 | 120 | } |
| 117 | - }else{ |
|
| 121 | + } else{ |
|
| 118 | 122 | $dom = $html5; |
| 119 | 123 | } |
| 120 | 124 | } else{ |
@@ -150,7 +154,9 @@ discard block |
||
| 150 | 154 | $excluded = array(); |
| 151 | 155 | foreach( $this->excludeTags as $eTag ){ |
| 152 | 156 | while( $tags = $html->getElementsByTagName( $eTag ) ){ |
| 153 | - if( !$tags->length ) break 1; |
|
| 157 | + if( !$tags->length ) { |
|
| 158 | + break 1; |
|
| 159 | + } |
|
| 154 | 160 | $tag = $tags->item(0); |
| 155 | 161 | $value = $html->saveHTML( $tag ); |
| 156 | 162 | $key = (string) crc32( $value ); |
@@ -169,7 +175,9 @@ discard block |
||
| 169 | 175 | $links = AutomatedLink::get()->sort('Priority'); |
| 170 | 176 | foreach( $links as $link ){ |
| 171 | 177 | // Check if self-linking is allowed and if current pagetype is allowed |
| 172 | - if( !$link->canBeAdded( $this->owner, $field ) ) continue; |
|
| 178 | + if( !$link->canBeAdded( $this->owner, $field ) ) { |
|
| 179 | + continue; |
|
| 180 | + } |
|
| 173 | 181 | |
| 174 | 182 | $max = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
| 175 | 183 | $escape = (string) preg_quote( $link->Phrase, '/' ); |
@@ -178,22 +186,31 @@ discard block |
||
| 178 | 186 | // Count the matches |
| 179 | 187 | preg_match_all( $regex, $content, $count ); |
| 180 | 188 | $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0; |
| 181 | - if( $count < 1 ) continue; |
|
| 189 | + if( $count < 1 ) { |
|
| 190 | + continue; |
|
| 191 | + } |
|
| 182 | 192 | |
| 183 | - if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) |
|
| 184 | - $max -= $this->maxLinksPerPage[ $link->ID ]; |
|
| 185 | - else |
|
| 186 | - $this->maxLinksPerPage[ $link->ID ] = 0; |
|
| 193 | + if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) { |
|
| 194 | + $max -= $this->maxLinksPerPage[ $link->ID ]; |
|
| 195 | + } else { |
|
| 196 | + $this->maxLinksPerPage[ $link->ID ] = 0; |
|
| 197 | + } |
|
| 187 | 198 | |
| 188 | 199 | for( $x = 0; $x < $count; $x++ ){ |
| 189 | 200 | // Stop adding links if we reached the link or page limit |
| 190 | - if( $x >= $max || $this->linkCount >= $this->maxLinks ) break; |
|
| 201 | + if( $x >= $max || $this->linkCount >= $this->maxLinks ) { |
|
| 202 | + break; |
|
| 203 | + } |
|
| 191 | 204 | |
| 192 | 205 | // Check if there is anything else to replace else stop |
| 193 | 206 | preg_match( $regex, $content, $match ); |
| 194 | - if( !is_array( $match ) || !count( $match ) ) break; |
|
| 207 | + if( !is_array( $match ) || !count( $match ) ) { |
|
| 208 | + break; |
|
| 209 | + } |
|
| 195 | 210 | |
| 196 | - if( !$html = (string) $link->getHTML( $match[0] ) ) continue; |
|
| 211 | + if( !$html = (string) $link->getHTML( $match[0] ) ) { |
|
| 212 | + continue; |
|
| 213 | + } |
|
| 197 | 214 | $key = (string) crc32( $html ); |
| 198 | 215 | $excluded[ $key ] = (string) $html; |
| 199 | 216 | |
@@ -203,7 +220,9 @@ discard block |
||
| 203 | 220 | } |
| 204 | 221 | |
| 205 | 222 | // Stop Adding links if we reached the page limit |
| 206 | - if( $this->linkCount >= $this->maxLinks ) break; |
|
| 223 | + if( $this->linkCount >= $this->maxLinks ) { |
|
| 224 | + break; |
|
| 225 | + } |
|
| 207 | 226 | } |
| 208 | 227 | |
| 209 | 228 | // Re-add the excluded Tags |