@@ -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 | } |
@@ -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 |
@@ -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(); |