@@ -11,18 +11,18 @@ |
||
11 | 11 | */ |
12 | 12 | class SEOToolboxAdmin extends ModelAdmin{ |
13 | 13 | |
14 | - private static $menu_title = 'SEO Tool box'; |
|
15 | - private static $url_segment = 'seo-tool-box'; |
|
16 | - private static $managed_models = array( 'AutomatedLink' ); |
|
14 | + private static $menu_title = 'SEO Tool box'; |
|
15 | + private static $url_segment = 'seo-tool-box'; |
|
16 | + private static $managed_models = array( 'AutomatedLink' ); |
|
17 | 17 | private static $menu_priority = 10; |
18 | 18 | |
19 | 19 | |
20 | - public function getEditForm($id = null, $fields = null) { |
|
21 | - $form = parent::getEditForm( $id, $fields ); |
|
22 | - $class = $this->sanitiseClassName($this->modelClass); |
|
23 | - $grid = $form->Fields()->fieldByName($class); |
|
24 | - $grid->getConfig()->addComponent( new GridFieldSortableRows( 'Priority' ) ); |
|
20 | + public function getEditForm($id = null, $fields = null) { |
|
21 | + $form = parent::getEditForm( $id, $fields ); |
|
22 | + $class = $this->sanitiseClassName($this->modelClass); |
|
23 | + $grid = $form->Fields()->fieldByName($class); |
|
24 | + $grid->getConfig()->addComponent( new GridFieldSortableRows( 'Priority' ) ); |
|
25 | 25 | |
26 | - return $form; |
|
27 | - } |
|
26 | + return $form; |
|
27 | + } |
|
28 | 28 | } |
@@ -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 | } |
@@ -66,133 +66,133 @@ |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | function providePermissions() { |
69 | - return array( |
|
70 | - 'AUTOMATEDLINK_VIEW' => 'View Automated Links', |
|
71 | - 'AUTOMATEDLINK_EDIT' => 'Edit Automated Links', |
|
72 | - 'AUTOMATEDLINK_DELETE' => 'Delete Automated Links', |
|
73 | - 'AUTOMATEDLINK_CREATE' => 'Create Automated Links', |
|
74 | - ); |
|
75 | - } |
|
76 | - |
|
77 | - public function requireDefaultRecords(){ |
|
78 | - parent::requireDefaultRecords(); |
|
79 | - |
|
80 | - // Update all links to redirector pages during dev/build |
|
81 | - foreach( self::get() as $link ) { |
|
82 | - $link->CheckAndUpdateDestination( true ); |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Returns the HTML Representation of this object |
|
88 | - * |
|
69 | + return array( |
|
70 | + 'AUTOMATEDLINK_VIEW' => 'View Automated Links', |
|
71 | + 'AUTOMATEDLINK_EDIT' => 'Edit Automated Links', |
|
72 | + 'AUTOMATEDLINK_DELETE' => 'Delete Automated Links', |
|
73 | + 'AUTOMATEDLINK_CREATE' => 'Create Automated Links', |
|
74 | + ); |
|
75 | + } |
|
76 | + |
|
77 | + public function requireDefaultRecords(){ |
|
78 | + parent::requireDefaultRecords(); |
|
79 | + |
|
80 | + // Update all links to redirector pages during dev/build |
|
81 | + foreach( self::get() as $link ) { |
|
82 | + $link->CheckAndUpdateDestination( true ); |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Returns the HTML Representation of this object |
|
88 | + * |
|
89 | 89 | * @param String $originalPhrase |
90 | - * @return String |
|
91 | - */ |
|
92 | - public function getHTML($originalPhrase = NULL) { |
|
93 | - $link = ($this->PageID) ? $this->Page()->Link() : '#'; |
|
94 | - $title = ($this->TitleTag) ? "title='{$this->TitleTag}'" : ''; |
|
95 | - $nofollow = ($this->NoFollow) ? 'rel="nofollow"' : ''; |
|
96 | - $newtab = ($this->NewWindow) ? 'target="_blank"' : ''; |
|
90 | + * @return String |
|
91 | + */ |
|
92 | + public function getHTML($originalPhrase = NULL) { |
|
93 | + $link = ($this->PageID) ? $this->Page()->Link() : '#'; |
|
94 | + $title = ($this->TitleTag) ? "title='{$this->TitleTag}'" : ''; |
|
95 | + $nofollow = ($this->NoFollow) ? 'rel="nofollow"' : ''; |
|
96 | + $newtab = ($this->NewWindow) ? 'target="_blank"' : ''; |
|
97 | 97 | $anchor = ($originalPhrase) ? $originalPhrase : $this->Phrase; |
98 | - $link = ($this->AnchorTag) ? rtrim($link, '#').'#'.$this->AnchorTag : $link; |
|
99 | - return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>"; |
|
100 | - } |
|
101 | - |
|
102 | - public function getCMSFields() { |
|
103 | - $fields = FieldList::create(TabSet::create('Root')); |
|
104 | - |
|
105 | - $fields->addFieldsToTab('Root.LinkSettings', array( |
|
106 | - TextField::create('Phrase', 'Phrase to search for', $this->Phrase, 255), |
|
107 | - TextField::create('TitleTag', 'Title Tag', $this->TitleTag, 255), |
|
108 | - TextField::create('AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255), |
|
109 | - FieldGroup::create( |
|
110 | - CheckboxField::create('NoFollow'), |
|
111 | - CheckboxField::create('NewWindow'), |
|
112 | - CheckboxField::create('SelfLinking', 'Allow page to link to itself'), |
|
113 | - CheckboxField::create('CaseSensitive', 'Match the case of the phrase') |
|
114 | - ), |
|
115 | - NumericField::create('MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )'), |
|
116 | - TreeDropdownField::create('PageID', 'Page to link to', 'SiteTree') |
|
117 | - )); |
|
118 | - |
|
119 | - $settings = GlobalAutoLinkSettings::get_current(); |
|
120 | - if ($settings) { |
|
121 | - $fields->addFieldsToTab('Root.Global', array( |
|
122 | - NumericField::create( |
|
123 | - 'Global_MaxLinksPerPage', |
|
124 | - 'Maximum amount of links a single page can have ( 0 = unlimited )', |
|
125 | - $settings->MaxLinksPerPage |
|
126 | - ), |
|
127 | - TextField::create( |
|
128 | - 'Global_ExcludeTags', |
|
129 | - 'Do not include links into these HTML Tags ( comma seperated )', |
|
130 | - $settings->ExcludeTags |
|
131 | - ), |
|
132 | - TextField::create( |
|
133 | - 'Global_AddTo', |
|
134 | - 'Page types where links should be created in ( leave blank for all page types )', |
|
135 | - $settings->AddTo ), |
|
136 | - TextField::create( |
|
137 | - 'Global_IncludeIn', |
|
138 | - 'Include Links into these fields ( comma seperated & field must support html injection )', |
|
139 | - $settings->IncludeIn |
|
140 | - ) |
|
141 | - )); |
|
142 | - } |
|
143 | - |
|
144 | - return $fields; |
|
145 | - } |
|
98 | + $link = ($this->AnchorTag) ? rtrim($link, '#').'#'.$this->AnchorTag : $link; |
|
99 | + return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>"; |
|
100 | + } |
|
101 | + |
|
102 | + public function getCMSFields() { |
|
103 | + $fields = FieldList::create(TabSet::create('Root')); |
|
104 | + |
|
105 | + $fields->addFieldsToTab('Root.LinkSettings', array( |
|
106 | + TextField::create('Phrase', 'Phrase to search for', $this->Phrase, 255), |
|
107 | + TextField::create('TitleTag', 'Title Tag', $this->TitleTag, 255), |
|
108 | + TextField::create('AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255), |
|
109 | + FieldGroup::create( |
|
110 | + CheckboxField::create('NoFollow'), |
|
111 | + CheckboxField::create('NewWindow'), |
|
112 | + CheckboxField::create('SelfLinking', 'Allow page to link to itself'), |
|
113 | + CheckboxField::create('CaseSensitive', 'Match the case of the phrase') |
|
114 | + ), |
|
115 | + NumericField::create('MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )'), |
|
116 | + TreeDropdownField::create('PageID', 'Page to link to', 'SiteTree') |
|
117 | + )); |
|
118 | + |
|
119 | + $settings = GlobalAutoLinkSettings::get_current(); |
|
120 | + if ($settings) { |
|
121 | + $fields->addFieldsToTab('Root.Global', array( |
|
122 | + NumericField::create( |
|
123 | + 'Global_MaxLinksPerPage', |
|
124 | + 'Maximum amount of links a single page can have ( 0 = unlimited )', |
|
125 | + $settings->MaxLinksPerPage |
|
126 | + ), |
|
127 | + TextField::create( |
|
128 | + 'Global_ExcludeTags', |
|
129 | + 'Do not include links into these HTML Tags ( comma seperated )', |
|
130 | + $settings->ExcludeTags |
|
131 | + ), |
|
132 | + TextField::create( |
|
133 | + 'Global_AddTo', |
|
134 | + 'Page types where links should be created in ( leave blank for all page types )', |
|
135 | + $settings->AddTo ), |
|
136 | + TextField::create( |
|
137 | + 'Global_IncludeIn', |
|
138 | + 'Include Links into these fields ( comma seperated & field must support html injection )', |
|
139 | + $settings->IncludeIn |
|
140 | + ) |
|
141 | + )); |
|
142 | + } |
|
143 | + |
|
144 | + return $fields; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | public function getCMSValidator() { |
148 | 148 | return new RequiredFields(array('Phrase', 'PageID')); |
149 | 149 | } |
150 | 150 | |
151 | - /** |
|
152 | - * Save the Global Settings into the |
|
153 | - * Global Auto Link Settings Object |
|
154 | - * |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function onBeforeWrite() { |
|
158 | - parent::onBeforeWrite(); |
|
159 | - |
|
160 | - $settings = GlobalAutoLinkSettings::get_current(); |
|
161 | - if ($settings) { |
|
162 | - |
|
163 | - foreach ($this->getChangedFields() as $field => $value) { |
|
164 | - if (strpos($field, 'Global_') === 0 && isset($value['after'])) { |
|
165 | - $field = str_replace('Global_', '', $field); |
|
166 | - $settings->$field = $value['after']; |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - $settings->write(); |
|
171 | - } |
|
172 | - |
|
173 | - $this->CheckAndUpdateDestination(); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Checks if the destination is a redirector page if so |
|
178 | - * it updates it to the destination of the redirector page |
|
179 | - * |
|
180 | - * @Boolean $write - Write the changes if any |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - public function CheckAndUpdateDestination( $write = false ){ |
|
184 | - $this->extend('beforeCheckAndUpdateDestination', $write); |
|
185 | - |
|
186 | - if( $this->PageID && $this->Page() && |
|
187 | - $this->Page()->ClassName == 'RedirectorPage' && |
|
188 | - $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' ) |
|
189 | - { |
|
190 | - $this->PageID = $this->Page()->LinkToID; |
|
191 | - if( $write ) { |
|
192 | - $this->write(); |
|
193 | - } |
|
194 | - } |
|
195 | - } |
|
151 | + /** |
|
152 | + * Save the Global Settings into the |
|
153 | + * Global Auto Link Settings Object |
|
154 | + * |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function onBeforeWrite() { |
|
158 | + parent::onBeforeWrite(); |
|
159 | + |
|
160 | + $settings = GlobalAutoLinkSettings::get_current(); |
|
161 | + if ($settings) { |
|
162 | + |
|
163 | + foreach ($this->getChangedFields() as $field => $value) { |
|
164 | + if (strpos($field, 'Global_') === 0 && isset($value['after'])) { |
|
165 | + $field = str_replace('Global_', '', $field); |
|
166 | + $settings->$field = $value['after']; |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + $settings->write(); |
|
171 | + } |
|
172 | + |
|
173 | + $this->CheckAndUpdateDestination(); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Checks if the destination is a redirector page if so |
|
178 | + * it updates it to the destination of the redirector page |
|
179 | + * |
|
180 | + * @Boolean $write - Write the changes if any |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + public function CheckAndUpdateDestination( $write = false ){ |
|
184 | + $this->extend('beforeCheckAndUpdateDestination', $write); |
|
185 | + |
|
186 | + if( $this->PageID && $this->Page() && |
|
187 | + $this->Page()->ClassName == 'RedirectorPage' && |
|
188 | + $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' ) |
|
189 | + { |
|
190 | + $this->PageID = $this->Page()->LinkToID; |
|
191 | + if( $write ) { |
|
192 | + $this->write(); |
|
193 | + } |
|
194 | + } |
|
195 | + } |
|
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Checks if the field is parable |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | 'Page' => 'SiteTree' |
44 | 44 | ); |
45 | 45 | |
46 | - private static $summary_fields = array( 'Phrase', 'PointsTo' ); |
|
47 | - private static $searchable_fields = array( 'Phrase' ); |
|
48 | - private static $singular_name = 'Automated Link'; |
|
46 | + private static $summary_fields = array('Phrase', 'PointsTo'); |
|
47 | + private static $searchable_fields = array('Phrase'); |
|
48 | + private static $singular_name = 'Automated Link'; |
|
49 | 49 | private static $plural_name = 'Automated Links'; |
50 | 50 | private static $parsableFields = array(); |
51 | 51 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public function PointsTo(){ |
|
57 | + public function PointsTo() { |
|
58 | 58 | return $this->Page()->Link(); |
59 | 59 | } |
60 | 60 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return string |
65 | 65 | */ |
66 | - public function Title(){ |
|
66 | + public function Title() { |
|
67 | 67 | return $this->Phrase; |
68 | 68 | } |
69 | 69 | |
@@ -72,23 +72,23 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return String |
74 | 74 | */ |
75 | - public function forTemplate(){ |
|
75 | + public function forTemplate() { |
|
76 | 76 | return $this->getHTML(); |
77 | 77 | } |
78 | 78 | |
79 | - public function canView( $member = false ){ |
|
79 | + public function canView($member = false) { |
|
80 | 80 | return Permission::check('AUTOMATEDLINK_VIEW'); |
81 | 81 | } |
82 | 82 | |
83 | - public function canEdit( $member = false ){ |
|
83 | + public function canEdit($member = false) { |
|
84 | 84 | return Permission::check('AUTOMATEDLINK_EDIT'); |
85 | 85 | } |
86 | 86 | |
87 | - public function canDelete( $member = false ){ |
|
87 | + public function canDelete($member = false) { |
|
88 | 88 | return Permission::check('AUTOMATEDLINK_DELETE'); |
89 | 89 | } |
90 | 90 | |
91 | - public function canCreate( $member = false ){ |
|
91 | + public function canCreate($member = false) { |
|
92 | 92 | return Permission::check('AUTOMATEDLINK_CREATE'); |
93 | 93 | } |
94 | 94 | |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | ); |
102 | 102 | } |
103 | 103 | |
104 | - public function requireDefaultRecords(){ |
|
104 | + public function requireDefaultRecords() { |
|
105 | 105 | parent::requireDefaultRecords(); |
106 | 106 | |
107 | 107 | // Update all links to redirector pages during dev/build |
108 | - foreach( self::get() as $link ) { |
|
109 | - $link->CheckAndUpdateDestination( true ); |
|
108 | + foreach (self::get() as $link) { |
|
109 | + $link->CheckAndUpdateDestination(true); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -207,15 +207,15 @@ discard block |
||
207 | 207 | * @Boolean $write - Write the changes if any |
208 | 208 | * @return void |
209 | 209 | */ |
210 | - public function CheckAndUpdateDestination( $write = false ){ |
|
210 | + public function CheckAndUpdateDestination($write = false) { |
|
211 | 211 | $this->extend('beforeCheckAndUpdateDestination', $write); |
212 | 212 | |
213 | - if( $this->PageID && $this->Page() && |
|
213 | + if ($this->PageID && $this->Page() && |
|
214 | 214 | $this->Page()->ClassName == 'RedirectorPage' && |
215 | - $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' ) |
|
215 | + $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal') |
|
216 | 216 | { |
217 | 217 | $this->PageID = $this->Page()->LinkToID; |
218 | - if( $write ) { |
|
218 | + if ($write) { |
|
219 | 219 | $this->write(); |
220 | 220 | } |
221 | 221 | } |
@@ -245,8 +245,8 @@ discard block |
||
245 | 245 | * @param ContentController $controller |
246 | 246 | * @return Boolean |
247 | 247 | */ |
248 | - public function canBeAdded( ContentController $controller ){ |
|
249 | - return ( $this->SelfLinking || $controller->ID != $this->PageID ); |
|
248 | + public function canBeAdded(ContentController $controller) { |
|
249 | + return ($this->SelfLinking || $controller->ID != $this->PageID); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -255,20 +255,20 @@ discard block |
||
255 | 255 | * @param string $html |
256 | 256 | * @return DOMDocument |
257 | 257 | */ |
258 | - public static function constructDOMDocument($html){ |
|
259 | - if( class_exists( 'HTML5_Parser' ) ){ |
|
260 | - $html5 = HTML5_Parser::parse( $html ); |
|
261 | - if($html5 instanceof DOMNodeList){ |
|
258 | + public static function constructDOMDocument($html) { |
|
259 | + if (class_exists('HTML5_Parser')) { |
|
260 | + $html5 = HTML5_Parser::parse($html); |
|
261 | + if ($html5 instanceof DOMNodeList) { |
|
262 | 262 | $dom = new DOMDocument(); |
263 | - while($html5->length > 0) { |
|
263 | + while ($html5->length > 0) { |
|
264 | 264 | $dom->appendChild($html5->item(0)); |
265 | 265 | } |
266 | - }else{ |
|
266 | + }else { |
|
267 | 267 | $dom = $html5; |
268 | 268 | } |
269 | - } else{ |
|
269 | + }else { |
|
270 | 270 | $dom = new DOMDocument(); |
271 | - $dom->loadHTML( $html ); |
|
271 | + $dom->loadHTML($html); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | return $dom; |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | * @param string $class |
281 | 281 | * @return array |
282 | 282 | */ |
283 | - public static function getAllDatabaseFields($class){ |
|
283 | + public static function getAllDatabaseFields($class) { |
|
284 | 284 | $fields = array(); |
285 | - foreach (ClassInfo::ancestry($class, true) as $ancestor){ |
|
285 | + foreach (ClassInfo::ancestry($class, true) as $ancestor) { |
|
286 | 286 | $fields = array_merge($fields, (array) DataObject::database_fields($ancestor)); |
287 | 287 | } |
288 | 288 | return $fields; |
@@ -263,7 +263,7 @@ |
||
263 | 263 | while($html5->length > 0) { |
264 | 264 | $dom->appendChild($html5->item(0)); |
265 | 265 | } |
266 | - }else{ |
|
266 | + } else{ |
|
267 | 267 | $dom = $html5; |
268 | 268 | } |
269 | 269 | } else{ |
@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public static function add_or_update(SiteTree $page) { |
54 | 54 | $obj = self::get()->find('PageID', $page->ID); |
55 | - if (!$obj) $obj = self::create(array('PageID' => $page->ID)); |
|
55 | + if (!$obj) { |
|
56 | + $obj = self::create(array('PageID' => $page->ID)); |
|
57 | + } |
|
56 | 58 | |
57 | 59 | $obj->OriginalLinkCount = $page->OriginalLinkCount; |
58 | 60 | $obj->LinksCreatedCount = $page->LinkCount; |
@@ -68,6 +70,8 @@ discard block |
||
68 | 70 | * @return void |
69 | 71 | */ |
70 | 72 | public static function remove_old_data() { |
71 | - foreach (self::get() as $obj) if (!SiteTree::get()->byID($obj->PageID)) $obj->delete(); |
|
73 | + foreach (self::get() as $obj) { |
|
74 | + if (!SiteTree::get()->byID($obj->PageID)) $obj->delete(); |
|
75 | + } |
|
72 | 76 | } |
73 | 77 | } |
@@ -10,20 +10,20 @@ discard block |
||
10 | 10 | */ |
11 | 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 | - private static $db = array( |
|
17 | - 'MaxLinksPerPage' => 'INT', |
|
18 | - 'ExcludeTags' => 'VARCHAR(255)', |
|
19 | - 'IncludeIn' => 'Text', |
|
20 | - 'AddTo' => 'Text', |
|
16 | + private static $db = array( |
|
17 | + 'MaxLinksPerPage' => 'INT', |
|
18 | + 'ExcludeTags' => 'VARCHAR(255)', |
|
19 | + 'IncludeIn' => 'Text', |
|
20 | + 'AddTo' => 'Text', |
|
21 | 21 | 'CrawlID' => 'VARCHAR(15)' |
22 | - ); |
|
22 | + ); |
|
23 | 23 | |
24 | - private static $defaults = array( |
|
25 | - 'IncludeIn' => 'Content' |
|
26 | - ); |
|
24 | + private static $defaults = array( |
|
25 | + 'IncludeIn' => 'Content' |
|
26 | + ); |
|
27 | 27 | |
28 | 28 | public static $default_create_config = array( |
29 | 29 | 'MaxLinksPerPage' => 0, |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | 'IncludeIn' => 'Content' |
32 | 32 | ); |
33 | 33 | |
34 | - public function ExcludeTags(){ |
|
35 | - return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) ); |
|
36 | - } |
|
34 | + public function ExcludeTags(){ |
|
35 | + return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) ); |
|
36 | + } |
|
37 | 37 | |
38 | - public function IncludeInFields(){ |
|
39 | - return explode( ',', str_replace( ' ', '', $this->IncludeIn ) ); |
|
40 | - } |
|
38 | + public function IncludeInFields(){ |
|
39 | + return explode( ',', str_replace( ' ', '', $this->IncludeIn ) ); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | public function requireDefaultRecords() { |
43 | 43 | $hasData = self::get()->first(); |
@@ -61,8 +61,9 @@ discard block |
||
61 | 61 | $alpha = 'abcdefghijklm[)0123456789(]nopqrstuvwxyz'; |
62 | 62 | $alpha_len = strlen($alpha); |
63 | 63 | |
64 | - while (strlen($ret) < 14) |
|
65 | - $ret .= (rand(0, 1) == 0) ? strtoupper($alpha[rand(0, $alpha_len-1)]) : $alpha[rand(0, $alpha_len-1)]; |
|
64 | + while (strlen($ret) < 14) { |
|
65 | + $ret .= (rand(0, 1) == 0) ? strtoupper($alpha[rand(0, $alpha_len-1)]) : $alpha[rand(0, $alpha_len-1)]; |
|
66 | + } |
|
66 | 67 | |
67 | 68 | return $ret; |
68 | 69 | } |
@@ -77,7 +78,9 @@ discard block |
||
77 | 78 | */ |
78 | 79 | public function AllowedIn(){ |
79 | 80 | $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) ); |
80 | - if( !$this->AddTo ) return $classes; |
|
81 | + if( !$this->AddTo ) { |
|
82 | + return $classes; |
|
83 | + } |
|
81 | 84 | |
82 | 85 | $sanitized = explode( ',', str_replace( ' ', '', strtolower( $this->AddTo ) ) ); |
83 | 86 | |
@@ -92,7 +95,9 @@ discard block |
||
92 | 95 | } |
93 | 96 | } |
94 | 97 | |
95 | - if( !$found ) unset( $sanitized[$x] ); |
|
98 | + if( !$found ) { |
|
99 | + unset( $sanitized[$x] ); |
|
100 | + } |
|
96 | 101 | } |
97 | 102 | |
98 | 103 | return (array) $sanitized; |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @property string AddTo |
15 | 15 | * @property string CrawlID |
16 | 16 | */ |
17 | -class GlobalAutoLinkSettings extends DataObject{ |
|
17 | +class GlobalAutoLinkSettings extends DataObject { |
|
18 | 18 | |
19 | - public static $enabled = true; |
|
19 | + public static $enabled = true; |
|
20 | 20 | public static $encoding = 'UTF-8'; |
21 | 21 | |
22 | 22 | private static $db = array( |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - public function ExcludeTags(){ |
|
46 | - return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) ); |
|
45 | + public function ExcludeTags() { |
|
46 | + return array_unique(explode(',', str_replace(' ', '', $this->ExcludeTags).',a,img,iframe,video,object')); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,19 +51,19 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public function IncludeInFields(){ |
|
55 | - return explode( ',', str_replace( ' ', '', $this->IncludeIn ) ); |
|
54 | + public function IncludeInFields() { |
|
55 | + return explode(',', str_replace(' ', '', $this->IncludeIn)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | public function requireDefaultRecords() { |
59 | 59 | $hasData = self::get()->first(); |
60 | - if(!$hasData) { |
|
60 | + if (!$hasData) { |
|
61 | 61 | $obj = self::create(self::$default_create_config); |
62 | 62 | $obj->CrawlID = $this->createCrawlID(); |
63 | 63 | $obj->write(); |
64 | - DB::alteration_message("Added default Global Auto Link Settings","created"); |
|
65 | - } else{ |
|
66 | - if(!$hasData->CrawlID){ |
|
64 | + DB::alteration_message("Added default Global Auto Link Settings", "created"); |
|
65 | + }else { |
|
66 | + if (!$hasData->CrawlID) { |
|
67 | 67 | $hasData->CrawlID = $this->createCrawlID(); |
68 | 68 | $hasData->write(); |
69 | 69 | } |
@@ -96,25 +96,25 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return array |
98 | 98 | */ |
99 | - public function AllowedIn(){ |
|
100 | - $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) ); |
|
101 | - if( !$this->AddTo ) return $classes; |
|
99 | + public function AllowedIn() { |
|
100 | + $classes = array_values(ClassInfo::subclassesFor('SiteTree')); |
|
101 | + if (!$this->AddTo) return $classes; |
|
102 | 102 | |
103 | - $sanitized = explode( ',', str_replace( ' ', '', strtolower( $this->AddTo ) ) ); |
|
103 | + $sanitized = explode(',', str_replace(' ', '', strtolower($this->AddTo))); |
|
104 | 104 | $len = count($sanitized); |
105 | 105 | |
106 | - for( $x = 0; $x < $len; $x++ ){ |
|
106 | + for ($x = 0; $x < $len; $x++) { |
|
107 | 107 | $found = false; |
108 | 108 | |
109 | - foreach( $classes as $class ){ |
|
110 | - if( strtolower( $class ) === $sanitized[$x] ){ |
|
109 | + foreach ($classes as $class) { |
|
110 | + if (strtolower($class) === $sanitized[$x]) { |
|
111 | 111 | $sanitized[$x] = $class; |
112 | 112 | $found = true; |
113 | 113 | break 1; |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | - if( !$found ) unset( $sanitized[$x] ); |
|
117 | + if (!$found) unset($sanitized[$x]); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | return (array) $sanitized; |
@@ -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, |
@@ -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(){ |
|
37 | - if( !Config::inst()->get( $this->class, 'run_in_realtime' ) ) { |
|
36 | + public function sourceRecords() { |
|
37 | + if (!Config::inst()->get($this->class, 'run_in_realtime')) { |
|
38 | 38 | return AutomatedLinkPageResult::get(); |
39 | 39 | } |
40 | 40 |
@@ -16,7 +16,9 @@ discard block |
||
16 | 16 | private static $exclude_classes = array('RedirectorPage', 'VirtualPage'); |
17 | 17 | |
18 | 18 | public function index() { |
19 | - if (!Director::is_cli()) return 'Please run this controller in CLI'; |
|
19 | + if (!Director::is_cli()) { |
|
20 | + return 'Please run this controller in CLI'; |
|
21 | + } |
|
20 | 22 | |
21 | 23 | libxml_use_internal_errors(true); |
22 | 24 | set_time_limit(600); |
@@ -52,15 +54,23 @@ discard block |
||
52 | 54 | $exclude = Config::inst()->get($this->class, 'exclude_classes'); |
53 | 55 | $exclude = ($exclude) ? "'".implode("','", $exclude)."'" : ''; |
54 | 56 | foreach (SiteTree::get()->where("ClassName NOT IN($exclude)") as $page) { |
55 | - if (!$this->checkForPossibleLinks($page, $includeInFields)) continue; |
|
57 | + if (!$this->checkForPossibleLinks($page, $includeInFields)) { |
|
58 | + continue; |
|
59 | + } |
|
56 | 60 | $page = $this->getLinkData($page, $includeInFields); |
57 | - if (!$page) continue; |
|
61 | + if (!$page) { |
|
62 | + continue; |
|
63 | + } |
|
58 | 64 | |
59 | - if (!$run_in_realtime) AutomatedLinkPageResult::add_or_update($page); |
|
65 | + if (!$run_in_realtime) { |
|
66 | + AutomatedLinkPageResult::add_or_update($page); |
|
67 | + } |
|
60 | 68 | $data->push($page); |
61 | 69 | } |
62 | 70 | |
63 | - if (!$run_in_realtime) AutomatedLinkPageResult::remove_old_data(); |
|
71 | + if (!$run_in_realtime) { |
|
72 | + AutomatedLinkPageResult::remove_old_data(); |
|
73 | + } |
|
64 | 74 | |
65 | 75 | return $data; |
66 | 76 | } |
@@ -78,15 +88,18 @@ discard block |
||
78 | 88 | // Set a list of all fields that can have autolinks created in them |
79 | 89 | $page->AutomateableFields = ArrayList::create(); |
80 | 90 | |
81 | - foreach (AutomatedLink::getAllDatabaseFields($page->class) as $field => $type) |
|
82 | - if (in_array($field, $includeIn) && |
|
91 | + foreach (AutomatedLink::getAllDatabaseFields($page->class) as $field => $type) { |
|
92 | + if (in_array($field, $includeIn) && |
|
83 | 93 | !$page->AutomateableFields->find('DataField', $field) && |
84 | 94 | AutomatedLink::isFieldParsable($page, $field) |
85 | 95 | ) $page->AutomateableFields->push(DataObject::create(array('DataField' => $field))); |
96 | + } |
|
86 | 97 | |
87 | 98 | // Get data Pre-Automated Links creation |
88 | 99 | $withLinks = $this->getPageDOM($page); |
89 | - if (!$withLinks) return false; |
|
100 | + if (!$withLinks) { |
|
101 | + return false; |
|
102 | + } |
|
90 | 103 | |
91 | 104 | $links = $withLinks->getElementsByTagName('a'); |
92 | 105 | |
@@ -96,10 +109,11 @@ discard block |
||
96 | 109 | |
97 | 110 | // List all automated links that were created in this $page |
98 | 111 | $linksUsed = array(); |
99 | - foreach ($this->Links as $autolink) |
|
100 | - foreach ($links as $link) { |
|
112 | + foreach ($this->Links as $autolink) { |
|
113 | + foreach ($links as $link) { |
|
101 | 114 | if ($link->getAttribute('data-id') == $autolink->ID) { |
102 | 115 | $linksUsed[$autolink->ID] = $autolink->Phrase; |
116 | + } |
|
103 | 117 | $page->OriginalLinkCount--; |
104 | 118 | $page->LinkCount++; |
105 | 119 | } |
@@ -107,7 +121,9 @@ discard block |
||
107 | 121 | |
108 | 122 | $page->Links = implode(', ', $linksUsed); |
109 | 123 | |
110 | - if ($page->LinkCount < 1) return false; |
|
124 | + if ($page->LinkCount < 1) { |
|
125 | + return false; |
|
126 | + } |
|
111 | 127 | |
112 | 128 | return $page; |
113 | 129 | } |
@@ -122,8 +138,12 @@ discard block |
||
122 | 138 | */ |
123 | 139 | private function getPageDOM(SiteTree $page) { |
124 | 140 | $controllerClass = $page->class.'_Controller'; |
125 | - if (!class_exists($controllerClass)) $controllerClass = $page->class.'Controller'; |
|
126 | - if (!class_exists($controllerClass)) return false; |
|
141 | + if (!class_exists($controllerClass)) { |
|
142 | + $controllerClass = $page->class.'Controller'; |
|
143 | + } |
|
144 | + if (!class_exists($controllerClass)) { |
|
145 | + return false; |
|
146 | + } |
|
127 | 147 | |
128 | 148 | $controller = $controllerClass::create($page); |
129 | 149 | $controller->invokeWithExtensions('addAutomatedLinks'); |
@@ -154,9 +174,10 @@ discard block |
||
154 | 174 | * @return Boolean |
155 | 175 | */ |
156 | 176 | private function checkForPossibleLinks(SiteTree $page, array $includeIn) { |
157 | - foreach ($this->Links as $link) |
|
158 | - foreach ($includeIn as $possibleField) |
|
177 | + foreach ($this->Links as $link) { |
|
178 | + foreach ($includeIn as $possibleField) |
|
159 | 179 | if (isset($page->$possibleField) && preg_match("/\b{$link->Phrase}\b/i", $page->$possibleField)) return true; |
180 | + } |
|
160 | 181 | |
161 | 182 | return false; |
162 | 183 | } |
@@ -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 | } |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | * @param array $hash_tags |
131 | 131 | * @return array |
132 | 132 | */ |
133 | - private function hashTags( DOMDocument $html, $hash_tags ){ |
|
133 | + private function hashTags(DOMDocument $html, $hash_tags) { |
|
134 | 134 | $excluded = array(); |
135 | - foreach( $hash_tags as $eTag ){ |
|
136 | - while( $tags = $html->getElementsByTagName( $eTag ) ){ |
|
137 | - if( !$tags->length ) break 1; |
|
138 | - $tag = $tags->item(0); |
|
139 | - $value = $html->saveHTML( $tag ); |
|
140 | - $key = (string) crc32( $value ); |
|
135 | + foreach ($hash_tags as $eTag) { |
|
136 | + while ($tags = $html->getElementsByTagName($eTag)) { |
|
137 | + if (!$tags->length) break 1; |
|
138 | + $tag = $tags->item(0); |
|
139 | + $value = $html->saveHTML($tag); |
|
140 | + $key = (string) crc32($value); |
|
141 | 141 | |
142 | 142 | // Convert back children nodes of this node if they were already hashed |
143 | - $excluded[$key] = str_replace( array_keys( $excluded ), array_values( $excluded ), $value ); |
|
143 | + $excluded[$key] = str_replace(array_keys($excluded), array_values($excluded), $value); |
|
144 | 144 | |
145 | - $tag->parentNode->replaceChild( $html->createTextNode( $key ), $tag ); |
|
145 | + $tag->parentNode->replaceChild($html->createTextNode($key), $tag); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
@@ -157,38 +157,38 @@ discard block |
||
157 | 157 | * @param string $content |
158 | 158 | * @return array |
159 | 159 | */ |
160 | - public function addLinkToContent(AutomatedLink $link, &$content){ |
|
160 | + public function addLinkToContent(AutomatedLink $link, &$content) { |
|
161 | 161 | $links = array(); |
162 | - $max = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
|
163 | - $escape = (string) preg_quote( $link->Phrase, '/' ); |
|
164 | - $regex = (string) ( $link->CaseSensitive ) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i"; |
|
162 | + $max = (int) ($link->MaxLinksPerPage > 0) ? $link->MaxLinksPerPage : PHP_INT_MAX; |
|
163 | + $escape = (string) preg_quote($link->Phrase, '/'); |
|
164 | + $regex = (string) ($link->CaseSensitive) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i"; |
|
165 | 165 | |
166 | 166 | // Count the matches |
167 | - preg_match_all( $regex, $content, $count ); |
|
168 | - $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0; |
|
169 | - if( $count < 1 ) $links; |
|
167 | + preg_match_all($regex, $content, $count); |
|
168 | + $count = (is_array($count) && isset($count[0])) ? count($count[0]) : 0; |
|
169 | + if ($count < 1) $links; |
|
170 | 170 | |
171 | - if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) { |
|
171 | + if (isset($this->maxLinksPerPage[$link->ID])) { |
|
172 | 172 | $max -= $this->maxLinksPerPage[$link->ID]; |
173 | - } else { |
|
173 | + }else { |
|
174 | 174 | $this->maxLinksPerPage[$link->ID] = 0; |
175 | 175 | } |
176 | 176 | |
177 | - for( $x = 0; $x < $count; $x++ ){ |
|
177 | + for ($x = 0; $x < $count; $x++) { |
|
178 | 178 | // Stop adding links if we reached the link or page limit |
179 | - if( $x >= $max || $this->linkCount >= $this->maxLinks ) break; |
|
179 | + if ($x >= $max || $this->linkCount >= $this->maxLinks) break; |
|
180 | 180 | |
181 | 181 | // Check if there is anything else to replace else stop |
182 | - preg_match( $regex, $content, $match ); |
|
183 | - if( !is_array( $match ) || !count( $match ) ) break; |
|
182 | + preg_match($regex, $content, $match); |
|
183 | + if (!is_array($match) || !count($match)) break; |
|
184 | 184 | |
185 | - if( !$html = (string) $link->getHTML( $match[0] ) ) continue; |
|
186 | - $key = (string) crc32( $html ); |
|
187 | - $links[ $key ] = (string) $html; |
|
185 | + if (!$html = (string) $link->getHTML($match[0])) continue; |
|
186 | + $key = (string) crc32($html); |
|
187 | + $links[$key] = (string) $html; |
|
188 | 188 | |
189 | - $content = preg_replace( $regex, $key, $content, 1 ); |
|
189 | + $content = preg_replace($regex, $key, $content, 1); |
|
190 | 190 | $this->linkCount++; |
191 | - $this->maxLinksPerPage[ $link->ID ]++; |
|
191 | + $this->maxLinksPerPage[$link->ID]++; |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | return $links; |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | * @param String $field |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - private function parseField( DOMDocument $html, $field ){ |
|
205 | - $this->owner->extend( 'beforeParseField', $html, $field ); |
|
204 | + private function parseField(DOMDocument $html, $field) { |
|
205 | + $this->owner->extend('beforeParseField', $html, $field); |
|
206 | 206 | |
207 | 207 | // Remove Tags from Content we wown't be using |
208 | 208 | $excluded = $this->hashTags($html, $this->excludeTags); |
209 | - $body = (string)$html->saveHTML( $html->getElementsByTagName('body')->item(0) ); |
|
210 | - $content = preg_replace( array( '/\<body\>/is', '/\<\/body\>/is' ), '', $body, 1 ); |
|
209 | + $body = (string) $html->saveHTML($html->getElementsByTagName('body')->item(0)); |
|
210 | + $content = preg_replace(array('/\<body\>/is', '/\<\/body\>/is'), '', $body, 1); |
|
211 | 211 | |
212 | - foreach( AutomatedLink::get()->sort('Priority') as $link){ |
|
213 | - if( $this->linkCount < $this->maxLinks && $link->canBeAdded( $this->owner, $field ) ) { |
|
212 | + foreach (AutomatedLink::get()->sort('Priority') as $link) { |
|
213 | + if ($this->linkCount < $this->maxLinks && $link->canBeAdded($this->owner, $field)) { |
|
214 | 214 | $links = $this->addLinkToContent($link, $content); |
215 | - if( is_array($links) && count($links) > 0 ) { |
|
216 | - $excluded = $excluded + $links; |
|
215 | + if (is_array($links) && count($links) > 0) { |
|
216 | + $excluded = $excluded+$links; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | 221 | // Re-add the excluded Tags |
222 | - return str_replace( array_keys( $excluded ), array_values( $excluded ), $content ); |
|
222 | + return str_replace(array_keys($excluded), array_values($excluded), $content); |
|
223 | 223 | } |
224 | 224 | } |
@@ -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; |
@@ -134,7 +138,9 @@ discard block |
||
134 | 138 | $excluded = array(); |
135 | 139 | foreach( $hash_tags as $eTag ){ |
136 | 140 | while( $tags = $html->getElementsByTagName( $eTag ) ){ |
137 | - if( !$tags->length ) break 1; |
|
141 | + if( !$tags->length ) { |
|
142 | + break 1; |
|
143 | + } |
|
138 | 144 | $tag = $tags->item(0); |
139 | 145 | $value = $html->saveHTML( $tag ); |
140 | 146 | $key = (string) crc32( $value ); |
@@ -166,7 +172,9 @@ discard block |
||
166 | 172 | // Count the matches |
167 | 173 | preg_match_all( $regex, $content, $count ); |
168 | 174 | $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0; |
169 | - if( $count < 1 ) $links; |
|
175 | + if( $count < 1 ) { |
|
176 | + $links; |
|
177 | + } |
|
170 | 178 | |
171 | 179 | if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) { |
172 | 180 | $max -= $this->maxLinksPerPage[$link->ID]; |
@@ -176,13 +184,19 @@ discard block |
||
176 | 184 | |
177 | 185 | for( $x = 0; $x < $count; $x++ ){ |
178 | 186 | // Stop adding links if we reached the link or page limit |
179 | - if( $x >= $max || $this->linkCount >= $this->maxLinks ) break; |
|
187 | + if( $x >= $max || $this->linkCount >= $this->maxLinks ) { |
|
188 | + break; |
|
189 | + } |
|
180 | 190 | |
181 | 191 | // Check if there is anything else to replace else stop |
182 | 192 | preg_match( $regex, $content, $match ); |
183 | - if( !is_array( $match ) || !count( $match ) ) break; |
|
193 | + if( !is_array( $match ) || !count( $match ) ) { |
|
194 | + break; |
|
195 | + } |
|
184 | 196 | |
185 | - if( !$html = (string) $link->getHTML( $match[0] ) ) continue; |
|
197 | + if( !$html = (string) $link->getHTML( $match[0] ) ) { |
|
198 | + continue; |
|
199 | + } |
|
186 | 200 | $key = (string) crc32( $html ); |
187 | 201 | $links[ $key ] = (string) $html; |
188 | 202 |