/
AdminPageFramework_Factory.php
406 lines (405 loc) · 18.3 KB
/
AdminPageFramework_Factory.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?php
/**
Admin Page Framework v3.8.29 by Michael Uno
Generated by PHP Class Files Script Generator <https://github.com/michaeluno/PHP-Class-Files-Script-Generator>
<http://en.michaeluno.jp/admin-page-framework>
Copyright (c) 2013-2021, Michael Uno; Licensed under MIT <http://opensource.org/licenses/MIT> */
abstract class AdminPageFramework_Factory_Router {
public $oProp;
public $oDebug;
public $oUtil;
public $oMsg;
public $oForm;
protected $oPageLoadInfo;
protected $oResource;
protected $oHeadTag;
protected $oHelpPane;
protected $oLink;
protected $_aSubClassPrefixes = array('oForm' => 'AdminPageFramework_Form_', 'oPageLoadInfo' => 'AdminPageFramework_PageLoadInfo_', 'oResource' => 'AdminPageFramework_Resource_', 'oHelpPane' => 'AdminPageFramework_HelpPane_', 'oLink' => 'AdminPageFramework_Link_',);
private $_aSubClassNames = array('oProp' => null, 'oDebug' => 'AdminPageFramework_Debug', 'oUtil' => 'AdminPageFramework_FrameworkUtility', 'oMsg' => 'AdminPageFramework_Message', 'oForm' => null, 'oPageLoadInfo' => null, 'oResource' => null, 'oHelpPane' => null, 'oLink' => null,);
public $aSubClassNames = array();
public function __construct($oProp) {
$this->aSubClassNames = $this->___getSubClassNames();
unset($this->oDebug, $this->oUtil, $this->oMsg, $this->oForm, $this->oPageLoadInfo, $this->oResource, $this->oHelpPane, $this->oLink);
$this->oProp = $oProp;
if ($this->oProp->bIsAdmin) {
$this->oUtil->registerAction('current_screen', array($this, '_replyToLoadComponents'));
}
$this->start();
$this->oUtil->addAndDoAction($this, 'start_' . $this->oProp->sClassName, $this);
}
private function ___getSubClassNames() {
foreach ($this->_aSubClassPrefixes as $_sObjectVariableName => $_sPrefix) {
$this->aSubClassNames[$_sObjectVariableName] = $_sPrefix . $this->_sStructureType;
}
return $this->aSubClassNames + $this->_aSubClassNames;
}
public function _replyToLoadComponents() {
if (!$this->_isInThePage()) {
return;
}
if (!isset($this->oResource)) {
$this->oResource = $this->_replyTpSetAndGetInstance_oResource();
}
if (!isset($this->oLink)) {
$this->oLink = $this->_replyTpSetAndGetInstance_oLink();
}
if ($this->oUtil->isDebugMode()) {
$this->oPageLoadInfo = $this->oPageLoadInfo;
}
}
protected function _load($aActions = array()) {
$aActions = empty($aActions) ? array('load_' . $this->oProp->sClassName,) : $aActions;
$this->load();
$this->oUtil->addAndDoActions($this, $aActions, $this);
}
protected function _setUp() {
$aActions = array('set_up_' . $this->oProp->sClassName,);
$this->setUp();
$this->oUtil->addAndDoActions($this, $aActions, $this);
}
protected function _isInstantiatable() {
if ($this->_isWordPressCoreAjaxRequest()) {
return false;
}
return true;
}
protected function _isWordPressCoreAjaxRequest() {
if (!isset($GLOBALS['pagenow'])) {
return false;
}
if ('admin-ajax.php' !== $GLOBALS['pagenow']) {
return false;
}
$_sAction = isset($_POST['action']) ? $_POST['action'] : '';
return in_array($_sAction, array('heartbeat', 'closed-postboxes', 'meta-box-order'), true);
}
protected function _isInThePage() {
return true;
}
protected function _isValidAjaxReferrer() {
if (!$this->oProp->bIsAdminAjax) {
return false;
}
return true;
}
public function _replyToDetermineToLoad() {
if (!$this->_isInThePage()) {
return;
}
$this->_setUp();
}
protected function _getFormObject() {
$this->oProp->setFormProperties();
$_sFormClass = $this->aSubClassNames['oForm'];
return new $_sFormClass($this->oProp->aFormArguments, $this->oProp->aFormCallbacks, $this->oMsg);
}
protected function _getLinkObject() {
return null;
}
protected function _getPageLoadObject() {
return null;
}
public function __get($sPropertyName) {
if (isset($this->aSubClassNames[$sPropertyName])) {
return call_user_func(array($this, "_replyTpSetAndGetInstance_{$sPropertyName}"));
}
}
public function _replyTpSetAndGetInstance_oUtil() {
$_sClassName = $this->aSubClassNames['oUtil'];
$this->oUtil = new $_sClassName;
return $this->oUtil;
}
public function _replyTpSetAndGetInstance_oDebug() {
$_sClassName = $this->aSubClassNames['oDebug'];
$this->oDebug = new $_sClassName;
return $this->oDebug;
}
public function _replyTpSetAndGetInstance_oMsg() {
$this->oMsg = call_user_func_array(array($this->aSubClassNames['oMsg'], 'getInstance'), array($this->oProp->sTextDomain));
return $this->oMsg;
}
public function _replyTpSetAndGetInstance_oForm() {
$this->oForm = $this->_getFormObject();
return $this->oForm;
}
public function _replyTpSetAndGetInstance_oResource() {
if (isset($this->oResource)) {
return $this->oResource;
}
$_sClassName = $this->aSubClassNames['oResource'];
$this->oResource = new $_sClassName($this->oProp);
return $this->oResource;
}
public function _replyTpSetAndGetInstance_oHeadTag() {
$this->oHead = $this->_replyTpSetAndGetInstance_oResource();
return $this->oHead;
}
public function _replyTpSetAndGetInstance_oHelpPane() {
$_sClassName = $this->aSubClassNames['oHelpPane'];
$this->oHelpPane = new $_sClassName($this->oProp);
return $this->oHelpPane;
}
public function _replyTpSetAndGetInstance_oLink() {
$this->oLink = $this->_getLinkObject();
return $this->oLink;
}
public function _replyTpSetAndGetInstance_oPageLoadInfo() {
$this->oPageLoadInfo = $this->_getPageLoadObject();
return $this->oPageLoadInfo;
}
public function __call($sMethodName, $aArguments = null) {
$_mFirstArg = $this->oUtil->getElement($aArguments, 0);
switch ($sMethodName) {
case 'validate':
case 'content':
return $_mFirstArg;
}
if (has_filter($sMethodName)) {
return $this->_getAutoCallback($sMethodName, $aArguments);
}
$this->_triggerUndefinedMethodWarning($sMethodName);
}
private function _getAutoCallback($sMethodName, $aArguments) {
if (false === strpos($sMethodName, "\\")) {
return $this->oUtil->getElement($aArguments, 0);
}
$_sAutoCallbackMethodName = str_replace('\\', '_', $sMethodName);
return method_exists($this, $_sAutoCallbackMethodName) ? call_user_func_array(array($this, $_sAutoCallbackMethodName), $aArguments) : $this->oUtil->getElement($aArguments, 0);
}
private function _triggerUndefinedMethodWarning($sMethodName) {
trigger_error(AdminPageFramework_Registry::NAME . ': ' . sprintf(__('The method is not defined: %1$s', $this->oProp->sTextDomain), $sMethodName), E_USER_WARNING);
}
public function __toString() {
return AdminPageFramework_FrameworkUtility::getObjectInfo($this);
}
public function setFooterInfoRight() {
}
public function setFooterInfoLeft() {
}
}
abstract class AdminPageFramework_Factory_Model extends AdminPageFramework_Factory_Router {
public function __construct($oProp) {
parent::__construct($oProp);
add_filter('field_types_' . $oProp->sClassName, array($this, '_replyToFilterFieldTypeDefinitions'));
}
public function _replyToFieldsetResourceRegistration($aFieldset) {
$aFieldset = $aFieldset + array('help' => null, 'title' => null, 'help_aside' => null,);
if (!$aFieldset['help']) {
return;
}
$this->oHelpPane->_addHelpTextForFormFields($aFieldset['title'], $aFieldset['help'], $aFieldset['help_aside']);
}
public function _replyToFilterFieldTypeDefinitions($aFieldTypeDefinitions) {
if (method_exists($this, 'field_types_' . $this->oProp->sClassName)) {
return call_user_func_array(array($this, 'field_types_' . $this->oProp->sClassName), array($aFieldTypeDefinitions));
}
return $aFieldTypeDefinitions;
}
public function _replyToModifySectionsets($aSectionsets) {
return $this->oUtil->addAndApplyFilter($this, "sections_{$this->oProp->sClassName}", $aSectionsets);
}
public function _replyToModifyFieldsets($aFieldsets, $aSectionsets) {
foreach ($aFieldsets as $_sSectionPath => $_aFields) {
$_aSectionPath = explode('|', $_sSectionPath);
$_sFilterSuffix = implode('_', $_aSectionPath);
$aFieldsets[$_sSectionPath] = $this->oUtil->addAndApplyFilter($this, "fields_{$this->oProp->sClassName}_{$_sFilterSuffix}", $_aFields);
}
$aFieldsets = $this->oUtil->addAndApplyFilter($this, "fields_{$this->oProp->sClassName}", $aFieldsets);
if (count($aFieldsets)) {
$this->oProp->bEnableForm = true;
}
return $aFieldsets;
}
public function _replyToModifyFieldsetsDefinitions($aFieldsets) {
return $this->oUtil->addAndApplyFilter($this, "field_definition_{$this->oProp->sClassName}", $aFieldsets);
}
public function _replyToModifyFieldsetDefinitionAfterFormatting($aFieldset) {
return $this->oUtil->addAndApplyFilter($this, $this->_getHookNameByFieldsetAndPrefix('field_definition_', $aFieldset), $aFieldset, $aFieldset['_subsection_index']);
}
public function _replyToModifyFieldsetDefinitionBeforeFormatting($aFieldset) {
return $this->oUtil->addAndApplyFilter($this, $this->_getHookNameByFieldsetAndPrefix('field_definition_before_formatting_', $aFieldset), $aFieldset);
}
private function _getHookNameByFieldsetAndPrefix($sPrefix, $aFieldset) {
$_sFieldPart = '_' . implode('_', $aFieldset['_field_path_array']);
$_sSectionPart = implode('_', $aFieldset['_section_path_array']);
$_sSectionPart = $this->oUtil->getAOrB('_default' === $_sSectionPart, '', '_' . $_sSectionPart);
return $sPrefix . $this->oProp->sClassName . $_sSectionPart . $_sFieldPart;
}
public function _replyToHandleSubmittedFormData($aSavedData, $aArguments, $aSectionsets, $aFieldsets) {
}
public function _replyToFormatFieldsetDefinition($aFieldset, $aSectionsets) {
return $aFieldset;
}
public function _replyToFormatSectionsetDefinition($aSectionset) {
if (empty($aSectionset)) {
return $aSectionset;
}
$aSectionset = $aSectionset + array('_fields_type' => $this->oProp->_sPropertyType, '_structure_type' => $this->oProp->_sPropertyType,);
return $aSectionset;
}
public function _replyToDetermineWhetherToProcessFormRegistration($bAllowed) {
return $this->_isInThePage();
}
public function _replyToGetCapabilityForForm($sCapability) {
return $this->oProp->sCapability;
}
public function _replyToGetSavedFormData() {
$this->oProp->aOptions = $this->oUtil->addAndApplyFilter($this, 'options_' . $this->oProp->sClassName, $this->oProp->aOptions);
return $this->oProp->aOptions;
}
public function _replyToDetermineWhetherToShowDebugInfo() {
return $this->oProp->bShowDebugInfo;
}
public function getSavedOptions() {
return $this->oForm->aSavedData;
}
public function getFieldErrors() {
return $this->oForm->getFieldErrors();
}
protected function _getFieldErrors() {
return $this->oForm->getFieldErrors();
}
public function setLastInputs(array $aLastInputs) {
return $this->oForm->setLastInputs($aLastInputs);
}
public function _setLastInput($aLastInputs) {
return $this->setLastInputs($aLastInputs);
}
}
abstract class AdminPageFramework_Factory_View extends AdminPageFramework_Factory_Model {
public function __construct($oProp) {
parent::__construct($oProp);
new AdminPageFramework_Factory_View__SettingNotice($this, $this->oProp->sSettingNoticeActionHook);
}
public function _replyToGetSectionName() {
$_aParams = func_get_args() + array(null, null,);
return $_aParams[0];
}
public function _replyToGetInputID() {
$_aParams = func_get_args() + array(null, null, null, null);
return $_aParams[0];
}
public function _replyToGetInputTagIDAttribute() {
$_aParams = func_get_args() + array(null, null, null, null);
return $_aParams[0];
}
public function _replyToGetFieldNameAttribute() {
$_aParams = func_get_args() + array(null, null,);
return $_aParams[0];
}
public function _replyToGetFlatFieldName() {
$_aParams = func_get_args() + array(null, null,);
return $_aParams[0];
}
public function _replyToGetInputNameAttribute() {
$_aParams = func_get_args() + array(null, null, null);
return $_aParams[0];
}
public function _replyToGetFlatInputName() {
$_aParams = func_get_args() + array(null, null, null);
return $_aParams[0];
}
public function _replyToGetInputClassAttribute() {
$_aParams = func_get_args() + array(null, null, null, null);
return $_aParams[0];
}
public function _replyToDetermineSectionsetVisibility($bVisible, $aSectionset) {
return $this->_isElementVisible($aSectionset, $bVisible);
}
public function _replyToDetermineFieldsetVisibility($bVisible, $aFieldset) {
return $this->_isElementVisible($aFieldset, $bVisible);
}
private function _isElementVisible($aElementDefinition, $bDefault) {
$aElementDefinition = $aElementDefinition + array('if' => true, 'capability' => '',);
if (!$aElementDefinition['if']) {
return false;
}
if (!$aElementDefinition['capability']) {
return true;
}
if (!current_user_can($aElementDefinition['capability'])) {
return false;
}
return $bDefault;
}
public function isSectionSet(array $aFieldset) {
$aFieldset = $aFieldset + array('section_id' => null,);
return $aFieldset['section_id'] && '_default' !== $aFieldset['section_id'];
}
public function _replyToGetSectionHeaderOutput($sSectionDescription, $aSectionset) {
return $this->oUtil->addAndApplyFilters($this, array('section_head_' . $this->oProp->sClassName . '_' . $aSectionset['section_id']), $sSectionDescription);
}
public function _replyToGetFieldOutput($sFieldOutput, $aFieldset) {
$_sSectionPart = $this->oUtil->getAOrB(isset($aFieldset['section_id']) && '_default' !== $aFieldset['section_id'], '_' . $aFieldset['section_id'], '');
return $this->oUtil->addAndApplyFilters($this, array('field_' . $this->oProp->sClassName . $_sSectionPart . '_' . $aFieldset['field_id']), $sFieldOutput, $aFieldset);
}
}
abstract class AdminPageFramework_Factory_Controller extends AdminPageFramework_Factory_View {
public function start() {
}
public function setUp() {
}
public function load() {
}
public function isInThePage() {
return $this->_isInThePage();
}
public function setMessage($sKey, $sMessage) {
$this->oMsg->set($sKey, $sMessage);
}
public function getMessage($sKey = '') {
return $this->oMsg->get($sKey);
}
public function enqueueStyles($aSRCs, $_vArg2 = null) {
}
public function enqueueStyle($sSRC, $_vArg2 = null) {
}
public function enqueueScripts($aSRCs, $_vArg2 = null) {
}
public function enqueueScript($sSRC, $_vArg2 = null) {
}
public function addHelpText($sHTMLContent, $sHTMLSidebarContent = "") {
if (method_exists($this->oHelpPane, '_addHelpText')) {
$this->oHelpPane->_addHelpText($sHTMLContent, $sHTMLSidebarContent);
}
}
public function addSettingSections() {
foreach (func_get_args() as $_asSectionset) {
$this->addSettingSection($_asSectionset);
}
$this->_sTargetSectionTabSlug = null;
}
public function addSettingSection($aSectionset) {
if (!is_array($aSectionset)) {
return;
}
$this->_sTargetSectionTabSlug = $this->oUtil->getElement($aSectionset, 'section_tab_slug', $this->_sTargetSectionTabSlug);
$aSectionset['section_tab_slug'] = $this->oUtil->getAOrB($this->_sTargetSectionTabSlug, $this->_sTargetSectionTabSlug, null);
$this->oForm->addSection($aSectionset);
}
public function addSettingFields() {
foreach (func_get_args() as $_aFieldset) {
$this->addSettingField($_aFieldset);
}
}
public function addSettingField($asFieldset) {
if (method_exists($this->oForm, 'addField')) {
$this->oForm->addField($asFieldset);
}
}
public function setFieldErrors($aErrors) {
$this->oForm->setFieldErrors($aErrors);
}
public function hasFieldError() {
return $this->oForm->hasFieldError();
}
public function setSettingNotice($sMessage, $sType = 'error', $asAttributes = array(), $bOverride = true) {
$this->oForm->setSubmitNotice($sMessage, $sType, $asAttributes, $bOverride);
}
public function hasSettingNotice($sType = '') {
return $this->oForm->hasSubmitNotice($sType);
}
}
abstract class AdminPageFramework_Factory extends AdminPageFramework_Factory_Controller {
}