1 <?php
2 3 4 5 6 7
8 class WebylonSiteConfig extends SiteConfigDecorator {
9
10 11 12
13 static $hidden_fields = array('LinkVK', 'LinkFB', 'LinkGP', 'LinkTW', 'LinkLJ', 'Theme', 'Tagline');
14
15 16 17
18 static $block_oversized = true;
19
20 21 22
23 static $cms_disabled = '';
24
25 26 27
28 static $use_site_agreement = false;
29
30 31 32
33 static $site_agreement_field = 'AgreeWithSiteRules';
34
35 36 37
38 static $max_file_upload_size = 94371840;
39
40 41 42
43 static $max_image_upload_size = 8388608;
44
45 46 47
48 static $map_base_url = "https://api-maps.yandex.ru/2.0.48/?load=package.full&lang=ru-RU&apikey=";
49
50 function () {
51 return array(
52 'db' => array(
53 'AdminEmail' => 'Varchar',
54 'Copyrights' => 'HTMLText',
55
56 'Address' => 'HTMLText',
57 'WorkingHours' => 'HTMLText',
58 'Phone' => 'HTMLText',
59 'Fax' => 'HTMLText',
60 'ContactEmail' => 'Varchar',
61
62 'LinkVK' => 'Varchar(255)',
63 'LinkFB' => 'Varchar(255)',
64 'LinkGP' => 'Varchar(255)',
65 'LinkTW' => 'Varchar(255)',
66 'LinkLJ' => 'Varchar(255)',
67
68 'HtmlLeftBlock' => 'HTMLText',
69 'HtmlRightBlock' => 'HTMLText',
70 'HtmlFooterBlock' => 'HTMLText',
71 'HtmlShare' => 'HTMLText',
72
73 'MetaKeywords' => 'Text',
74 'MetaDescription' => 'Text',
75 'MetaTags' => 'Text',
76
77 'SiteAgreementText' => 'Text',
78
79
80 'MapApiKey' => 'Varchar(250)',
81 ),
82
83 'defaults' => array(
84 'MetaKeywords' => '',
85 'MetaDescription' => '',
86 'MetaTags' => ''
87 ),
88 'has_one' => array(
89 'SiteAgreementPage' => 'SiteTree',
90 )
91 );
92 }
93
94 static function set_map_base_url($url) {
95 self::$map_base_url = $url;
96 }
97
98 public function updateCMSFields(FieldSet &$fields) {
99 $tab = self::get_config_tab($fields);
100
101 if (method_exists('LeftAndMainQuota', 'sizeStatus')) {
102 $sizeInfo = LeftAndMainQuota::sizeStatus();
103
104 if ($sizeInfo->Blocked) {
105 $fields->insertBefore(new LiteralField('oversize', '<div id="oversizeMessage">' . sprintf(_t('SiteConfig.SITEBLOCKEDOVERSIZED', 'Site oversized used %d Mb from %d'), $sizeInfo->Used, $sizeInfo->Quota) . '</div>'), 'Title');
106 } elseif ($sizeInfo->State == 'over') {
107 $fields->insertBefore(new LiteralField('oversize', '<div id="oversizeMessage">' . sprintf(_t('SiteConfig.SITEOVERSIZED', 'Site oversized used %d Mb from %d'), $sizeInfo->Used, $sizeInfo->Quota) . '</div>'), 'Title');
108 }
109 }
110
111 $tab->push(new EmailField('AdminEmail', $this->owner->fieldLabel('AdminEmail').sprintf(' (%s)', Email::getAdminEmail())));
112 $tab->push(new TextAreaField('Copyrights', $this->owner->fieldLabel('Copyrights')));
113
114 if (self::$use_site_agreement) {
115 $tab->push(new TreeDropdownField('SiteAgreementPageID', $this->owner->fieldLabel('SiteAgreementPage'), 'SiteTree'));
116 $tab->push(new TextAreaField('SiteAgreementText', $this->owner->fieldLabel('SiteAgreementText')));
117 }
118
119 $tab = self::get_config_tab($fields, 'Contacts');
120 $tab->push(new TextAreaField('Address', $this->owner->fieldLabel('Address')));
121 $tab->push(new TextAreaField('WorkingHours', $this->owner->fieldLabel('WorkingHours')));
122 $tab->push(new TextAreaField('Phone', $this->owner->fieldLabel('Phone')));
123 $tab->push(new TextAreaField('Fax', $this->owner->fieldLabel('Fax')));
124 $tab->push(new EmailField('ContactEmail', $this->owner->fieldLabel('ContactEmail')));
125 $tab->push(new TextField('LinkVK', $this->owner->fieldLabel('LinkVK')));
126 $tab->push(new TextField('LinkFB', $this->owner->fieldLabel('LinkFB')));
127 $tab->push(new TextField('LinkGP', $this->owner->fieldLabel('LinkGP')));
128 $tab->push(new TextField('LinkTW', $this->owner->fieldLabel('LinkTW')));
129 $tab->push(new TextField('LinkLJ', $this->owner->fieldLabel('LinkLJ')));
130
131 $tab = self::get_config_tab($fields, 'HtmlBlocks');
132 $tab->push(new TextAreaField('HtmlLeftBlock', $this->owner->fieldLabel('HtmlLeftBlock')));
133 $tab->push(new TextAreaField('HtmlRightBlock', $this->owner->fieldLabel('HtmlRightBlock')));
134 $tab->push(new TextAreaField('HtmlFooterBlock', $this->owner->fieldLabel('HtmlFooterBlock')));
135 $tab->push($htmlShare = new TextAreaField('HtmlShare', $this->owner->fieldLabel('HtmlShare') . ' (<a target="_blank" href="http://api.yandex.ru/share/">http://api.yandex.ru/share/</a>)'));
136 $tab->push(new TextField('MapApiKey', $this->owner->fieldLabel('MapApiKey') . _t("SiteConfig.GetMapApiKeyLink")));
137
138 $tab = self::get_config_tab($fields, 'SEO');
139 $tab->push(new TextField('MetaKeywords', $this->owner->fieldLabel('MetaKeywords')));
140 $tab->push(new TextAreaField('MetaDescription', $this->owner->fieldLabel('MetaDescription')));
141 $tab->push(new TextAreaField('MetaTags', $this->owner->fieldLabel('MetaTags')));
142
143
144 $robots = null;
145 $error = null;
146 if (!is_file(BASE_PATH . '/robots.txt')) {
147 if (SSViewer::hasTemplate('robots')) {
148 $baseRobots = $this->owner->renderWith('robots');
149 $robots = @file_put_contents(BASE_PATH . '/robots.txt', $baseRobots);
150 }
151 if (!$robots) {
152 $error = _t('SiteConfig.CANNOTCREATEFILE');
153 }
154 }
155 if (!$error && !is_writable(BASE_PATH . '/robots.txt')) {
156 $error = _t('SiteConfig.CANNOTWRITETOFILE');
157 }
158 if ($robots = @file_get_contents(BASE_PATH . '/robots.txt')) {
159 $this->owner->RobotsFile = $robots;
160 }
161 if ($error) {
162 $tab->push(new LiteralField('BadRobotsFile', '<p>' . _t('SiteConfig.RobotsFile') . '</p>'));
163 $tab->push(new LiteralField('BadRobotsFile', $error . '<p> </p>'));
164 } else {
165 $tab->push($f = new TextAreaField('RobotsFile', _t('SiteConfig.RobotsFile'), 20));
166 }
167
168 $this->hideUnselectedFields($fields);
169
170
171 Requirements::customScript("
172 Behaviour.register({
173 '#Form_EditForm' : {
174 initialize : function() {
175 this.observeMethod('PageLoaded', this.MediawebPageHandler);
176 this.MediawebPageHandler();
177 },
178 MediawebPageHandler : function() {
179 (function($) {
180 if (($('#Form_EditForm_folder_id').length) && ($('input#Form_EditForm_folder_id').attr('folder_updated') != '1')) {
181 if ($('#TreeDropdownField_Form_EditorToolbarImageForm_FolderID')) {
182 $('#TreeDropdownField_Form_EditorToolbarImageForm_FolderID')[0].setValue($('#Form_EditForm_folder_id').val());
183 $('#TreeDropdownField_Form_EditorToolbarImageForm_FolderID')[0].refresh();
184 }
185 if ($('#TreeDropdownField_Form_EditorToolbarFlashForm_FolderID')) {
186 $('#TreeDropdownField_Form_EditorToolbarFlashForm_FolderID')[0].setValue($('#Form_EditForm_folder_id').val());
187 $('#TreeDropdownField_Form_EditorToolbarFlashForm_FolderID')[0].refresh();
188 }
189 if ($('#TreeDropdownField_Form_EditorToolbarLinkForm_file')) {
190 $('#TreeDropdownField_Form_EditorToolbarLinkForm_file')[0].setValue($('#Form_EditForm_folder_path').val());
191 $('#TreeDropdownField_Form_EditorToolbarLinkForm_file')[0].refresh();
192 }
193 $('input#Form_EditForm_folder_id').attr('folder_updated','1');
194 }
195 })(jQuery);
196 }
197 }
198 });
199 ");
200
201
202 }
203
204 function populateDefaults() {
205 $this->owner->SiteAgreementText = _t('SiteConfig.default_SiteAgreementText', 'Default Site Agreement Text');
206 }
207
208 function requireDefaultRecords() {
209
210 if (!is_file(BASE_PATH . '/robots.txt') && SSViewer::hasTemplate('robots')) {
211 $baseRobots = $this->owner->renderWith('robots');
212 $robots = @file_put_contents(BASE_PATH . '/robots.txt', $baseRobots);
213 }
214 }
215
216 function onBeforeWrite() {
217 if ($this->owner->isChanged('RobotsFile') && is_file(BASE_PATH . '/robots.txt')) {
218 @file_put_contents(BASE_PATH . '/robots.txt', $this->owner->RobotsFile);
219 }
220 }
221
222 223 224 225 226
227 static function set_block_oversized($state = true) {
228 self::$block_oversized = $state;
229 }
230
231 232 233 234 235
236 static function disable_cms($message) {
237 self::$cms_disabled = $message;
238 }
239
240 241 242 243
244 function canCreateTopLevel(& $member = null) {
245 $sizeInfo = LeftAndMainQuota::sizeStatus();
246 if ($sizeInfo->Blocked) {
247 return false;
248 }
249 return true;
250 }
251
252 253 254 255
256 function setupAdminEmail() {
257 if ($this->owner->AdminEmail) {
258 Email::setAdminEmail($this->owner->AdminEmail);
259 }
260 }
261
262 263 264 265 266
267 function AdminEmail() {
268 return ($this->owner->AdminEmail) ? $this->owner->AdminEmail : Email::getAdminEmail();
269 }
270
271 272 273 274 275
276 function SenderEmail() {
277 if ($this->owner->AdminEmail) return $this->owner->AdminEmail;
278 return (strpos(Email::getAdminEmail(), 'mediaweb.ru') > 0) ? 'noreply@mediaweb.ru' : Email::getAdminEmail();
279 }
280
281 282 283 284 285 286
287 function hasLinkFields() {
288 if ($allConfigFields = DataObject::database_fields('SiteConfig')) {
289 foreach($allConfigFields as $name=>$type) {
290 if ((strpos($name, 'Link') === 0) && ($this->owner->hasValue($name))) {
291 return true;
292 }
293 }
294 }
295 return false;
296 }
297
298 299 300 301 302 303
304 function SiteAgreementField() {
305 if (self::$use_site_agreement && $this->owner->SiteAgreementText && $this->owner->SiteAgreementPageID && ($rulesPage = $this->owner->SiteAgreementPage())) {
306 $title = str_replace('$link', $rulesPage->Link(), $this->owner->SiteAgreementText);
307 $title = str_replace('$full_link', sprintf(_t("SiteConfig.SiteAgreementFullLink"), $rulesPage->Link(), $rulesPage->MenuTitle), $title);
308 $fields = new CheckboxField(self::$site_agreement_field, $title);
309 return $fields;
310 }
311 }
312
313 314 315 316 317 318 319
320 function FirstPhone($field = 'Phone') {
321 $phone = $this->owner->$field;
322 $phone = preg_replace('/^[^\d(]+/s', '', $phone);
323 $phone = preg_replace('/(\d)(\s+|\s?[()-]\s?)(\d)/s', '$1$3', $phone);
324 $phone = preg_replace('/^(\d+).*$/s', '$1', $phone);
325 return $phone;
326 }
327
328 329 330 331 332 333 334 335
336 function Phone2Links($field = 'Phone') {
337 $phone = $this->owner->$field;
338 $phone = preg_replace('/(\+?([\d-]|\s?\(|\)\s?)+)([^\d()-]|$)/', '<a href="tel:$1">$1</a>$3', $phone);
339 return $phone;
340 }
341
342 343 344 345 346 347
348 function RequireMapApi($url = false) {
349 if (!$url) {
350 $url = self::$map_base_url;
351 }
352 if ($this->owner->MapApiKey) {
353 $url .= $this->owner->MapApiKey;
354 }
355 Requirements::javascript($url);
356 }
357
358 function isNeedMapApiKey() {
359 return ($this->owner->MapApiKey) ? 1 : 0;
360 }
361 }
362
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-