-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.settings.php
130 lines (114 loc) · 3.42 KB
/
class.settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php if (!defined('APPLICATION')) exit();
/**
* @@ WorkerDomainSettingsDomain @@
*
* Links Settings Worker to the worker collection
* and retrieves it. Auto initialising.
*
* Provides a simple way for other workers, or
* the plugin file to call it method and access its
* properties.
*
* A worker will reference the Settings work like so:
* $this->Plgn->Settings()
*
* The plugin file can access it like so:
* $this->Settings()
*
* @abstract
*/
abstract class WorkerDomainSettingsDomain extends WorkerDomainAPIDomain {
/**
* The unique identifier to look up Worker
* @var string $WorkerName
*/
private $WorkerName = 'Settings';
/**
* @@ Settings @@
*
* Settings Worker Domain address,
* links and retrieves
*
* @return void
*/
public function Settings(){
$WorkerName = $this->WorkerName;
$WorkerClass = $this->GetPluginIndex().$WorkerName;
return $this->LinkWorker($WorkerName,$WorkerClass);
}
}
/**
* @@ WorkerDomainSettings @@
*
* The worker used to handle the backend
* settings interactions.
*
*/
class WorkerDomainSettings {
/**
* @@ WorkerDomainLink @@
*
* Basic settings menu item and link
*
* @param Gdn_Controller $Sender
*
* @return void
*/
public function Settings_MenuItems($Sender) {
$Menu = $Sender->EventArguments['SideMenu'];
$Menu->AddItem('WorkerDomain', T('Worker Domain'));
$Menu->AddLink('WorkerDomain', T('Settings'), 'settings/workerdomain', 'Garden.Settings.Manage');
}
/**
* @@ Settings_Controller @@
*
* Used to load shared resources,
* then dispatched to method using:
* $this->Plgn->Utility()->MiniDispatcher($Sender,'Settings',...);
*
* @param Gdn_Controller $Sender
*
* @return void
*/
public function Settings_Controller($Sender){
// general requirement across all settings/workerdomain/* pages
$Sender->Permission('Garden.Settings.Manage');
$Sender->AddCssFile('workerdomain.css','plugins/WorkerDomain');
$Sender->AddSideMenu();
// dispatch to specific settings page
$this->Plgn->Utility()->MiniDispatcher($Sender,'Settings');
}
/**
* @@ SettingsController_Index @@
*
* Represents the index page of the settings, served by mini-dispatcher
*
* @param Gdn_Controller $Sender
*
* @return void
*/
public function SettingsController_Index($Sender){
if($Sender->Form->IsPostBack() != False){
// basic validation
$Validation = new Gdn_Validation();
$Validation->ApplyRule('URI', 'Required');
$Validation->ApplyRule('URI', 'UrlString', 'You must enter a valid URI');
$Validation->ApplyRule('LinkName', 'Required');
$Validation->AddRule('LinkName','regex:`^[\w ]+$`i');
$Validation->ApplyRule('LinkName', 'LinkName', 'Name contains invalid characters');
$FormValues = $Sender->Form->FormValues();
$Validation->Validate($FormValues);
$Sender->Form->SetValidationResults($Validation->Results());
if(!$Sender->Form->ErrorCount()){
// save date using API
$this->Plgn->API()->SetProperties($FormValues);
}
}
$Sender->SetData('Title', T($this->Plgn->PluginInfo['Name']));
$Sender->SetData('Description', T($this->Plgn->PluginInfo['Description']));
// set data for forum
$Sender->Form->SetData($this->Plgn->API()->GetProperties());
$Sender->View = $this->Plgn->Utility()->ThemeView('settings');
$Sender->Render();
}
}