@@ -27,428 +27,428 @@ |
||
27 | 27 | */ |
28 | 28 | class SiteConfig extends DataObject implements PermissionProvider, TemplateGlobalProvider |
29 | 29 | { |
30 | - private static $db = array( |
|
31 | - "Title" => "Varchar(255)", |
|
32 | - "Tagline" => "Varchar(255)", |
|
33 | - "Theme" => "Varchar(255)", |
|
34 | - "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')", |
|
35 | - "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", |
|
36 | - "CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", |
|
37 | - ); |
|
38 | - |
|
39 | - private static $many_many = array( |
|
40 | - "ViewerGroups" => "SilverStripe\\Security\\Group", |
|
41 | - "EditorGroups" => "SilverStripe\\Security\\Group", |
|
42 | - "CreateTopLevelGroups" => "SilverStripe\\Security\\Group" |
|
43 | - ); |
|
44 | - |
|
45 | - private static $defaults = array( |
|
46 | - "CanViewType" => "Anyone", |
|
47 | - "CanEditType" => "LoggedInUsers", |
|
48 | - "CanCreateTopLevelType" => "LoggedInUsers", |
|
49 | - ); |
|
50 | - |
|
51 | - /** |
|
52 | - * @config |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - private static $disabled_themes = array(); |
|
57 | - |
|
58 | - /** |
|
59 | - * Default permission to check for 'LoggedInUsers' to create or edit pages |
|
60 | - * |
|
61 | - * @var array |
|
62 | - * @config |
|
63 | - */ |
|
64 | - private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain'); |
|
65 | - |
|
66 | - |
|
67 | - public function populateDefaults() |
|
68 | - { |
|
69 | - $this->Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name"); |
|
70 | - $this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here"); |
|
71 | - |
|
72 | - // Allow these defaults to be overridden |
|
73 | - parent::populateDefaults(); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Get the fields that are sent to the CMS. |
|
78 | - * |
|
79 | - * In your extensions: updateCMSFields($fields). |
|
80 | - * |
|
81 | - * @return FieldList |
|
82 | - */ |
|
83 | - public function getCMSFields() |
|
84 | - { |
|
85 | - $groupsMap = array(); |
|
86 | - |
|
87 | - foreach (Group::get() as $group) { |
|
88 | - // Listboxfield values are escaped, use ASCII char instead of » |
|
89 | - $groupsMap[$group->ID] = $group->getBreadcrumbs(' > '); |
|
90 | - } |
|
91 | - asort($groupsMap); |
|
92 | - |
|
93 | - $fields = new FieldList( |
|
94 | - new TabSet("Root", |
|
95 | - $tabMain = new Tab('Main', |
|
96 | - $titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")), |
|
97 | - $taglineField = new TextField("Tagline", _t('SiteConfig.SITETAGLINE', "Site Tagline/Slogan")), |
|
98 | - $themeDropdownField = new DropdownField("Theme", _t('SiteConfig.THEME', 'Theme'), $this->getAvailableThemes()) |
|
99 | - ), |
|
100 | - $tabAccess = new Tab('Access', |
|
101 | - $viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")), |
|
102 | - $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups")) |
|
103 | - ->setSource($groupsMap) |
|
104 | - ->setAttribute( |
|
105 | - 'data-placeholder', |
|
106 | - _t('SiteTree.GroupPlaceholder', 'Click to select group') |
|
107 | - ), |
|
108 | - $editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")), |
|
109 | - $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups")) |
|
110 | - ->setSource($groupsMap) |
|
111 | - ->setAttribute( |
|
112 | - 'data-placeholder', |
|
113 | - _t('SiteTree.GroupPlaceholder', 'Click to select group') |
|
114 | - ), |
|
115 | - $topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")), |
|
116 | - $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators")) |
|
117 | - ->setSource($groupsMap) |
|
118 | - ->setAttribute( |
|
119 | - 'data-placeholder', |
|
120 | - _t('SiteTree.GroupPlaceholder', 'Click to select group') |
|
121 | - ) |
|
122 | - ) |
|
123 | - ), |
|
124 | - new HiddenField('ID') |
|
125 | - ); |
|
126 | - |
|
127 | - $themeDropdownField->setEmptyString(_t('SiteConfig.DEFAULTTHEME', '(Use default theme)')); |
|
128 | - |
|
129 | - $viewersOptionsSource = array(); |
|
130 | - $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone"); |
|
131 | - $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users"); |
|
132 | - $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)"); |
|
133 | - $viewersOptionsField->setSource($viewersOptionsSource); |
|
134 | - |
|
135 | - $editorsOptionsSource = array(); |
|
136 | - $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS"); |
|
137 | - $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)"); |
|
138 | - $editorsOptionsField->setSource($editorsOptionsSource); |
|
139 | - |
|
140 | - $topLevelCreatorsOptionsField->setSource($editorsOptionsSource); |
|
141 | - |
|
142 | - if (!Permission::check('EDIT_SITECONFIG')) { |
|
143 | - $fields->makeFieldReadonly($viewersOptionsField); |
|
144 | - $fields->makeFieldReadonly($viewerGroupsField); |
|
145 | - $fields->makeFieldReadonly($editorsOptionsField); |
|
146 | - $fields->makeFieldReadonly($editorGroupsField); |
|
147 | - $fields->makeFieldReadonly($topLevelCreatorsOptionsField); |
|
148 | - $fields->makeFieldReadonly($topLevelCreatorsGroupsField); |
|
149 | - $fields->makeFieldReadonly($taglineField); |
|
150 | - $fields->makeFieldReadonly($titleField); |
|
151 | - } |
|
152 | - |
|
153 | - if (file_exists(BASE_PATH . '/install.php')) { |
|
154 | - $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader", |
|
155 | - "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING", |
|
156 | - "Warning: You should remove install.php from this SilverStripe install for security reasons.") |
|
157 | - . "</p>"), "Title"); |
|
158 | - } |
|
159 | - |
|
160 | - $tabMain->setTitle(_t('SiteConfig.TABMAIN', "Main")); |
|
161 | - $tabAccess->setTitle(_t('SiteConfig.TABACCESS', "Access")); |
|
162 | - $this->extend('updateCMSFields', $fields); |
|
163 | - |
|
164 | - return $fields; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Get all available themes that haven't been marked as disabled. |
|
169 | - * |
|
170 | - * @param string $baseDir Optional alternative theme base directory for testing |
|
171 | - * |
|
172 | - * @return array of theme directory names |
|
173 | - */ |
|
174 | - public function getAvailableThemes($baseDir = null) |
|
175 | - { |
|
176 | - $themes = SSViewer::get_themes($baseDir); |
|
177 | - $disabled = (array)$this->config()->disabled_themes; |
|
178 | - |
|
179 | - foreach ($disabled as $theme) { |
|
180 | - if (isset($themes[$theme])) { |
|
181 | - unset($themes[$theme]); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - return $themes; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Get the actions that are sent to the CMS. |
|
190 | - * |
|
191 | - * In your extensions: updateEditFormActions($actions) |
|
192 | - * |
|
193 | - * @return FieldList |
|
194 | - */ |
|
195 | - public function getCMSActions() |
|
196 | - { |
|
197 | - if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) { |
|
198 | - $actions = new FieldList( |
|
199 | - FormAction::create('save_siteconfig', _t('CMSMain.SAVE', 'Save')) |
|
200 | - ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept') |
|
201 | - ); |
|
202 | - } else { |
|
203 | - $actions = new FieldList(); |
|
204 | - } |
|
205 | - |
|
206 | - $this->extend('updateCMSActions', $actions); |
|
207 | - |
|
208 | - return $actions; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function CMSEditLink() |
|
215 | - { |
|
216 | - return singleton('CMSSettingsController')->Link(); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Get the current sites SiteConfig, and creates a new one through |
|
221 | - * {@link make_site_config()} if none is found. |
|
222 | - * |
|
223 | - * @return SiteConfig |
|
224 | - */ |
|
225 | - public static function current_site_config() |
|
226 | - { |
|
227 | - if ($siteConfig = DataObject::get_one('SiteConfig')) { |
|
228 | - return $siteConfig; |
|
229 | - } |
|
230 | - |
|
231 | - return self::make_site_config(); |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Setup a default SiteConfig record if none exists. |
|
236 | - */ |
|
237 | - public function requireDefaultRecords() |
|
238 | - { |
|
239 | - parent::requireDefaultRecords(); |
|
240 | - |
|
241 | - $config = DataObject::get_one('SiteConfig'); |
|
242 | - |
|
243 | - if (!$config) { |
|
244 | - self::make_site_config(); |
|
245 | - |
|
246 | - DB::alteration_message("Added default site config", "created"); |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Create SiteConfig with defaults from language file. |
|
252 | - * |
|
253 | - * @return SiteConfig |
|
254 | - */ |
|
255 | - public static function make_site_config() |
|
256 | - { |
|
257 | - $config = SiteConfig::create(); |
|
258 | - $config->write(); |
|
259 | - |
|
260 | - return $config; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Can a user view this SiteConfig instance? |
|
265 | - * |
|
266 | - * @param Member $member |
|
267 | - * @return boolean |
|
268 | - */ |
|
269 | - public function canView($member = null) |
|
270 | - { |
|
271 | - if (!$member) { |
|
272 | - $member = Member::currentUserID(); |
|
273 | - } |
|
274 | - if ($member && is_numeric($member)) { |
|
275 | - $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
276 | - } |
|
277 | - |
|
278 | - $extended = $this->extendedCan('canView', $member); |
|
279 | - if ($extended !== null) { |
|
280 | - return $extended; |
|
281 | - } |
|
282 | - |
|
283 | - // Assuming all that can edit this object can also view it |
|
284 | - return $this->canEdit($member); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Can a user view pages on this site? This method is only |
|
289 | - * called if a page is set to Inherit, but there is nothing |
|
290 | - * to inherit from. |
|
291 | - * |
|
292 | - * @param Member $member |
|
293 | - * @return boolean |
|
294 | - */ |
|
295 | - public function canViewPages($member = null) |
|
296 | - { |
|
297 | - if (!$member) { |
|
298 | - $member = Member::currentUserID(); |
|
299 | - } |
|
300 | - if ($member && is_numeric($member)) { |
|
301 | - $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
302 | - } |
|
303 | - |
|
304 | - if ($member && Permission::checkMember($member, "ADMIN")) { |
|
305 | - return true; |
|
306 | - } |
|
307 | - |
|
308 | - $extended = $this->extendedCan('canViewPages', $member); |
|
309 | - if ($extended !== null) { |
|
310 | - return $extended; |
|
311 | - } |
|
312 | - |
|
313 | - if (!$this->CanViewType || $this->CanViewType == 'Anyone') { |
|
314 | - return true; |
|
315 | - } |
|
316 | - |
|
317 | - // check for any logged-in users |
|
318 | - if ($this->CanViewType === 'LoggedInUsers' && $member) { |
|
319 | - return true; |
|
320 | - } |
|
321 | - |
|
322 | - // check for specific groups |
|
323 | - if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) { |
|
324 | - return true; |
|
325 | - } |
|
326 | - |
|
327 | - return false; |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Can a user edit pages on this site? This method is only |
|
332 | - * called if a page is set to Inherit, but there is nothing |
|
333 | - * to inherit from, or on new records without a parent. |
|
334 | - * |
|
335 | - * @param Member $member |
|
336 | - * @return boolean |
|
337 | - */ |
|
338 | - public function canEditPages($member = null) |
|
339 | - { |
|
340 | - if (!$member) { |
|
341 | - $member = Member::currentUserID(); |
|
342 | - } |
|
343 | - if ($member && is_numeric($member)) { |
|
344 | - $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
345 | - } |
|
346 | - |
|
347 | - if ($member && Permission::checkMember($member, "ADMIN")) { |
|
348 | - return true; |
|
349 | - } |
|
350 | - |
|
351 | - $extended = $this->extendedCan('canEditPages', $member); |
|
352 | - if ($extended !== null) { |
|
353 | - return $extended; |
|
354 | - } |
|
355 | - |
|
356 | - // check for any logged-in users with CMS access |
|
357 | - if ($this->CanEditType === 'LoggedInUsers' |
|
358 | - && Permission::checkMember($member, $this->config()->required_permission) |
|
359 | - ) { |
|
360 | - return true; |
|
361 | - } |
|
362 | - |
|
363 | - // check for specific groups |
|
364 | - if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) { |
|
365 | - return true; |
|
366 | - } |
|
367 | - |
|
368 | - return false; |
|
369 | - } |
|
370 | - |
|
371 | - public function canEdit($member = null) |
|
372 | - { |
|
373 | - if (!$member) { |
|
374 | - $member = Member::currentUserID(); |
|
375 | - } |
|
376 | - if ($member && is_numeric($member)) { |
|
377 | - $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
378 | - } |
|
379 | - |
|
380 | - $extended = $this->extendedCan('canEdit', $member); |
|
381 | - if ($extended !== null) { |
|
382 | - return $extended; |
|
383 | - } |
|
384 | - |
|
385 | - return Permission::checkMember($member, "EDIT_SITECONFIG"); |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * @return array |
|
390 | - */ |
|
391 | - public function providePermissions() |
|
392 | - { |
|
393 | - return array( |
|
394 | - 'EDIT_SITECONFIG' => array( |
|
395 | - 'name' => _t('SiteConfig.EDIT_PERMISSION', 'Manage site configuration'), |
|
396 | - 'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'), |
|
397 | - 'help' => _t('SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'), |
|
398 | - 'sort' => 400 |
|
399 | - ) |
|
400 | - ); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Can a user create pages in the root of this site? |
|
405 | - * |
|
406 | - * @param Member $member |
|
407 | - * @return boolean |
|
408 | - */ |
|
409 | - public function canCreateTopLevel($member = null) |
|
410 | - { |
|
411 | - if (!$member) { |
|
412 | - $member = Member::currentUserID(); |
|
413 | - } |
|
414 | - if ($member && is_numeric($member)) { |
|
415 | - $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
416 | - } |
|
417 | - |
|
418 | - if ($member && Permission::checkMember($member, "ADMIN")) { |
|
419 | - return true; |
|
420 | - } |
|
421 | - |
|
422 | - $extended = $this->extendedCan('canCreateTopLevel', $member); |
|
423 | - if ($extended !== null) { |
|
424 | - return $extended; |
|
425 | - } |
|
426 | - |
|
427 | - // check for any logged-in users with CMS permission |
|
428 | - if ($this->CanCreateTopLevelType === 'LoggedInUsers' |
|
429 | - && Permission::checkMember($member, $this->config()->required_permission) |
|
430 | - ) { |
|
431 | - return true; |
|
432 | - } |
|
433 | - |
|
434 | - // check for specific groups |
|
435 | - if ($this->CanCreateTopLevelType === 'OnlyTheseUsers' |
|
436 | - && $member |
|
437 | - && $member->inGroups($this->CreateTopLevelGroups()) |
|
438 | - ) { |
|
439 | - return true; |
|
440 | - } |
|
441 | - |
|
442 | - return false; |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Add $SiteConfig to all SSViewers |
|
447 | - */ |
|
448 | - public static function get_template_global_variables() |
|
449 | - { |
|
450 | - return array( |
|
451 | - 'SiteConfig' => 'current_site_config', |
|
452 | - ); |
|
453 | - } |
|
30 | + private static $db = array( |
|
31 | + "Title" => "Varchar(255)", |
|
32 | + "Tagline" => "Varchar(255)", |
|
33 | + "Theme" => "Varchar(255)", |
|
34 | + "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')", |
|
35 | + "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", |
|
36 | + "CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", |
|
37 | + ); |
|
38 | + |
|
39 | + private static $many_many = array( |
|
40 | + "ViewerGroups" => "SilverStripe\\Security\\Group", |
|
41 | + "EditorGroups" => "SilverStripe\\Security\\Group", |
|
42 | + "CreateTopLevelGroups" => "SilverStripe\\Security\\Group" |
|
43 | + ); |
|
44 | + |
|
45 | + private static $defaults = array( |
|
46 | + "CanViewType" => "Anyone", |
|
47 | + "CanEditType" => "LoggedInUsers", |
|
48 | + "CanCreateTopLevelType" => "LoggedInUsers", |
|
49 | + ); |
|
50 | + |
|
51 | + /** |
|
52 | + * @config |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + private static $disabled_themes = array(); |
|
57 | + |
|
58 | + /** |
|
59 | + * Default permission to check for 'LoggedInUsers' to create or edit pages |
|
60 | + * |
|
61 | + * @var array |
|
62 | + * @config |
|
63 | + */ |
|
64 | + private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain'); |
|
65 | + |
|
66 | + |
|
67 | + public function populateDefaults() |
|
68 | + { |
|
69 | + $this->Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name"); |
|
70 | + $this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here"); |
|
71 | + |
|
72 | + // Allow these defaults to be overridden |
|
73 | + parent::populateDefaults(); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Get the fields that are sent to the CMS. |
|
78 | + * |
|
79 | + * In your extensions: updateCMSFields($fields). |
|
80 | + * |
|
81 | + * @return FieldList |
|
82 | + */ |
|
83 | + public function getCMSFields() |
|
84 | + { |
|
85 | + $groupsMap = array(); |
|
86 | + |
|
87 | + foreach (Group::get() as $group) { |
|
88 | + // Listboxfield values are escaped, use ASCII char instead of » |
|
89 | + $groupsMap[$group->ID] = $group->getBreadcrumbs(' > '); |
|
90 | + } |
|
91 | + asort($groupsMap); |
|
92 | + |
|
93 | + $fields = new FieldList( |
|
94 | + new TabSet("Root", |
|
95 | + $tabMain = new Tab('Main', |
|
96 | + $titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")), |
|
97 | + $taglineField = new TextField("Tagline", _t('SiteConfig.SITETAGLINE', "Site Tagline/Slogan")), |
|
98 | + $themeDropdownField = new DropdownField("Theme", _t('SiteConfig.THEME', 'Theme'), $this->getAvailableThemes()) |
|
99 | + ), |
|
100 | + $tabAccess = new Tab('Access', |
|
101 | + $viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")), |
|
102 | + $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups")) |
|
103 | + ->setSource($groupsMap) |
|
104 | + ->setAttribute( |
|
105 | + 'data-placeholder', |
|
106 | + _t('SiteTree.GroupPlaceholder', 'Click to select group') |
|
107 | + ), |
|
108 | + $editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")), |
|
109 | + $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups")) |
|
110 | + ->setSource($groupsMap) |
|
111 | + ->setAttribute( |
|
112 | + 'data-placeholder', |
|
113 | + _t('SiteTree.GroupPlaceholder', 'Click to select group') |
|
114 | + ), |
|
115 | + $topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")), |
|
116 | + $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators")) |
|
117 | + ->setSource($groupsMap) |
|
118 | + ->setAttribute( |
|
119 | + 'data-placeholder', |
|
120 | + _t('SiteTree.GroupPlaceholder', 'Click to select group') |
|
121 | + ) |
|
122 | + ) |
|
123 | + ), |
|
124 | + new HiddenField('ID') |
|
125 | + ); |
|
126 | + |
|
127 | + $themeDropdownField->setEmptyString(_t('SiteConfig.DEFAULTTHEME', '(Use default theme)')); |
|
128 | + |
|
129 | + $viewersOptionsSource = array(); |
|
130 | + $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone"); |
|
131 | + $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users"); |
|
132 | + $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)"); |
|
133 | + $viewersOptionsField->setSource($viewersOptionsSource); |
|
134 | + |
|
135 | + $editorsOptionsSource = array(); |
|
136 | + $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS"); |
|
137 | + $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)"); |
|
138 | + $editorsOptionsField->setSource($editorsOptionsSource); |
|
139 | + |
|
140 | + $topLevelCreatorsOptionsField->setSource($editorsOptionsSource); |
|
141 | + |
|
142 | + if (!Permission::check('EDIT_SITECONFIG')) { |
|
143 | + $fields->makeFieldReadonly($viewersOptionsField); |
|
144 | + $fields->makeFieldReadonly($viewerGroupsField); |
|
145 | + $fields->makeFieldReadonly($editorsOptionsField); |
|
146 | + $fields->makeFieldReadonly($editorGroupsField); |
|
147 | + $fields->makeFieldReadonly($topLevelCreatorsOptionsField); |
|
148 | + $fields->makeFieldReadonly($topLevelCreatorsGroupsField); |
|
149 | + $fields->makeFieldReadonly($taglineField); |
|
150 | + $fields->makeFieldReadonly($titleField); |
|
151 | + } |
|
152 | + |
|
153 | + if (file_exists(BASE_PATH . '/install.php')) { |
|
154 | + $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader", |
|
155 | + "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING", |
|
156 | + "Warning: You should remove install.php from this SilverStripe install for security reasons.") |
|
157 | + . "</p>"), "Title"); |
|
158 | + } |
|
159 | + |
|
160 | + $tabMain->setTitle(_t('SiteConfig.TABMAIN', "Main")); |
|
161 | + $tabAccess->setTitle(_t('SiteConfig.TABACCESS', "Access")); |
|
162 | + $this->extend('updateCMSFields', $fields); |
|
163 | + |
|
164 | + return $fields; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Get all available themes that haven't been marked as disabled. |
|
169 | + * |
|
170 | + * @param string $baseDir Optional alternative theme base directory for testing |
|
171 | + * |
|
172 | + * @return array of theme directory names |
|
173 | + */ |
|
174 | + public function getAvailableThemes($baseDir = null) |
|
175 | + { |
|
176 | + $themes = SSViewer::get_themes($baseDir); |
|
177 | + $disabled = (array)$this->config()->disabled_themes; |
|
178 | + |
|
179 | + foreach ($disabled as $theme) { |
|
180 | + if (isset($themes[$theme])) { |
|
181 | + unset($themes[$theme]); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + return $themes; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Get the actions that are sent to the CMS. |
|
190 | + * |
|
191 | + * In your extensions: updateEditFormActions($actions) |
|
192 | + * |
|
193 | + * @return FieldList |
|
194 | + */ |
|
195 | + public function getCMSActions() |
|
196 | + { |
|
197 | + if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) { |
|
198 | + $actions = new FieldList( |
|
199 | + FormAction::create('save_siteconfig', _t('CMSMain.SAVE', 'Save')) |
|
200 | + ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept') |
|
201 | + ); |
|
202 | + } else { |
|
203 | + $actions = new FieldList(); |
|
204 | + } |
|
205 | + |
|
206 | + $this->extend('updateCMSActions', $actions); |
|
207 | + |
|
208 | + return $actions; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function CMSEditLink() |
|
215 | + { |
|
216 | + return singleton('CMSSettingsController')->Link(); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Get the current sites SiteConfig, and creates a new one through |
|
221 | + * {@link make_site_config()} if none is found. |
|
222 | + * |
|
223 | + * @return SiteConfig |
|
224 | + */ |
|
225 | + public static function current_site_config() |
|
226 | + { |
|
227 | + if ($siteConfig = DataObject::get_one('SiteConfig')) { |
|
228 | + return $siteConfig; |
|
229 | + } |
|
230 | + |
|
231 | + return self::make_site_config(); |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Setup a default SiteConfig record if none exists. |
|
236 | + */ |
|
237 | + public function requireDefaultRecords() |
|
238 | + { |
|
239 | + parent::requireDefaultRecords(); |
|
240 | + |
|
241 | + $config = DataObject::get_one('SiteConfig'); |
|
242 | + |
|
243 | + if (!$config) { |
|
244 | + self::make_site_config(); |
|
245 | + |
|
246 | + DB::alteration_message("Added default site config", "created"); |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Create SiteConfig with defaults from language file. |
|
252 | + * |
|
253 | + * @return SiteConfig |
|
254 | + */ |
|
255 | + public static function make_site_config() |
|
256 | + { |
|
257 | + $config = SiteConfig::create(); |
|
258 | + $config->write(); |
|
259 | + |
|
260 | + return $config; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Can a user view this SiteConfig instance? |
|
265 | + * |
|
266 | + * @param Member $member |
|
267 | + * @return boolean |
|
268 | + */ |
|
269 | + public function canView($member = null) |
|
270 | + { |
|
271 | + if (!$member) { |
|
272 | + $member = Member::currentUserID(); |
|
273 | + } |
|
274 | + if ($member && is_numeric($member)) { |
|
275 | + $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
276 | + } |
|
277 | + |
|
278 | + $extended = $this->extendedCan('canView', $member); |
|
279 | + if ($extended !== null) { |
|
280 | + return $extended; |
|
281 | + } |
|
282 | + |
|
283 | + // Assuming all that can edit this object can also view it |
|
284 | + return $this->canEdit($member); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Can a user view pages on this site? This method is only |
|
289 | + * called if a page is set to Inherit, but there is nothing |
|
290 | + * to inherit from. |
|
291 | + * |
|
292 | + * @param Member $member |
|
293 | + * @return boolean |
|
294 | + */ |
|
295 | + public function canViewPages($member = null) |
|
296 | + { |
|
297 | + if (!$member) { |
|
298 | + $member = Member::currentUserID(); |
|
299 | + } |
|
300 | + if ($member && is_numeric($member)) { |
|
301 | + $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
302 | + } |
|
303 | + |
|
304 | + if ($member && Permission::checkMember($member, "ADMIN")) { |
|
305 | + return true; |
|
306 | + } |
|
307 | + |
|
308 | + $extended = $this->extendedCan('canViewPages', $member); |
|
309 | + if ($extended !== null) { |
|
310 | + return $extended; |
|
311 | + } |
|
312 | + |
|
313 | + if (!$this->CanViewType || $this->CanViewType == 'Anyone') { |
|
314 | + return true; |
|
315 | + } |
|
316 | + |
|
317 | + // check for any logged-in users |
|
318 | + if ($this->CanViewType === 'LoggedInUsers' && $member) { |
|
319 | + return true; |
|
320 | + } |
|
321 | + |
|
322 | + // check for specific groups |
|
323 | + if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) { |
|
324 | + return true; |
|
325 | + } |
|
326 | + |
|
327 | + return false; |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Can a user edit pages on this site? This method is only |
|
332 | + * called if a page is set to Inherit, but there is nothing |
|
333 | + * to inherit from, or on new records without a parent. |
|
334 | + * |
|
335 | + * @param Member $member |
|
336 | + * @return boolean |
|
337 | + */ |
|
338 | + public function canEditPages($member = null) |
|
339 | + { |
|
340 | + if (!$member) { |
|
341 | + $member = Member::currentUserID(); |
|
342 | + } |
|
343 | + if ($member && is_numeric($member)) { |
|
344 | + $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
345 | + } |
|
346 | + |
|
347 | + if ($member && Permission::checkMember($member, "ADMIN")) { |
|
348 | + return true; |
|
349 | + } |
|
350 | + |
|
351 | + $extended = $this->extendedCan('canEditPages', $member); |
|
352 | + if ($extended !== null) { |
|
353 | + return $extended; |
|
354 | + } |
|
355 | + |
|
356 | + // check for any logged-in users with CMS access |
|
357 | + if ($this->CanEditType === 'LoggedInUsers' |
|
358 | + && Permission::checkMember($member, $this->config()->required_permission) |
|
359 | + ) { |
|
360 | + return true; |
|
361 | + } |
|
362 | + |
|
363 | + // check for specific groups |
|
364 | + if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) { |
|
365 | + return true; |
|
366 | + } |
|
367 | + |
|
368 | + return false; |
|
369 | + } |
|
370 | + |
|
371 | + public function canEdit($member = null) |
|
372 | + { |
|
373 | + if (!$member) { |
|
374 | + $member = Member::currentUserID(); |
|
375 | + } |
|
376 | + if ($member && is_numeric($member)) { |
|
377 | + $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
378 | + } |
|
379 | + |
|
380 | + $extended = $this->extendedCan('canEdit', $member); |
|
381 | + if ($extended !== null) { |
|
382 | + return $extended; |
|
383 | + } |
|
384 | + |
|
385 | + return Permission::checkMember($member, "EDIT_SITECONFIG"); |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * @return array |
|
390 | + */ |
|
391 | + public function providePermissions() |
|
392 | + { |
|
393 | + return array( |
|
394 | + 'EDIT_SITECONFIG' => array( |
|
395 | + 'name' => _t('SiteConfig.EDIT_PERMISSION', 'Manage site configuration'), |
|
396 | + 'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'), |
|
397 | + 'help' => _t('SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'), |
|
398 | + 'sort' => 400 |
|
399 | + ) |
|
400 | + ); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Can a user create pages in the root of this site? |
|
405 | + * |
|
406 | + * @param Member $member |
|
407 | + * @return boolean |
|
408 | + */ |
|
409 | + public function canCreateTopLevel($member = null) |
|
410 | + { |
|
411 | + if (!$member) { |
|
412 | + $member = Member::currentUserID(); |
|
413 | + } |
|
414 | + if ($member && is_numeric($member)) { |
|
415 | + $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member); |
|
416 | + } |
|
417 | + |
|
418 | + if ($member && Permission::checkMember($member, "ADMIN")) { |
|
419 | + return true; |
|
420 | + } |
|
421 | + |
|
422 | + $extended = $this->extendedCan('canCreateTopLevel', $member); |
|
423 | + if ($extended !== null) { |
|
424 | + return $extended; |
|
425 | + } |
|
426 | + |
|
427 | + // check for any logged-in users with CMS permission |
|
428 | + if ($this->CanCreateTopLevelType === 'LoggedInUsers' |
|
429 | + && Permission::checkMember($member, $this->config()->required_permission) |
|
430 | + ) { |
|
431 | + return true; |
|
432 | + } |
|
433 | + |
|
434 | + // check for specific groups |
|
435 | + if ($this->CanCreateTopLevelType === 'OnlyTheseUsers' |
|
436 | + && $member |
|
437 | + && $member->inGroups($this->CreateTopLevelGroups()) |
|
438 | + ) { |
|
439 | + return true; |
|
440 | + } |
|
441 | + |
|
442 | + return false; |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Add $SiteConfig to all SSViewers |
|
447 | + */ |
|
448 | + public static function get_template_global_variables() |
|
449 | + { |
|
450 | + return array( |
|
451 | + 'SiteConfig' => 'current_site_config', |
|
452 | + ); |
|
453 | + } |
|
454 | 454 | } |