Completed
Branch dev (1ad2e5)
by
unknown
04:33
created

AdminPageFramework_Property_Base::_setGlobals()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
/**
3
 * Admin Page Framework
4
 * 
5
 * http://en.michaeluno.jp/admin-page-framework/
6
 * Copyright (c) 2013-2016 Michael Uno; Licensed MIT
7
 * 
8
 */
9
10
/**
11
 * The base class for Property classes.
12
 * 
13
 * Stores necessary data to render pages and its elements such as forms, including callback functions, resource (asset) localtions (paths and urls), inline script and stylesheet etc.
14
 * 
15
 * Provides the common methods  and properties for the property classes that are used by the main class, the meta box class, and the post type class.
16
 * @since       2.1.0
17
 * @package     AdminPageFramework
18
 * @subpackage  Common/Factory/Property
19
 * @internal
20
 * @extends     AdminPageFramework_FrameworkUtility
21
 */ 
22
abstract class AdminPageFramework_Property_Base extends AdminPageFramework_FrameworkUtility {
23
24
    /**
25
     * Represents the structure of the script info array.
26
     * @internal
27
     * @since       2.0.0
28
     * @since       3.0.0     Moved from the link class.
29
     */ 
30
    private static $_aStructure_CallerInfo = array(
31
        'sPath'         => null,
32
        'sType'         => null,
33
        'sName'         => null,     
34
        'sURI'          => null,
35
        'sVersion'      => null,
36
        'sThemeURI'     => null,
37
        'sScriptURI'    => null,
38
        'sAuthorURI'    => null,
39
        'sAuthor'       => null,
40
        'sDescription'  => null,
41
    );    
42
    
43
    /**
44
     * Stores the library information.
45
     * 
46
     * @remark Do not assign anything here because it is checked whether it is set.
47
     * @since 3.0.0
48
     */
49
    static public $_aLibraryData;
50
51
    /**
52
     * Defines the property type.
53
     * 
54
     * @since       3.3.1   This was defined in each extended classes.
55
     * @internal
56
     */
57
    public $_sPropertyType = '';    
58
    
59
    /**
60
     * Stores the main (caller) object.
61
     * 
62
     * @since       2.1.5
63
     * @since       3.7.10      Changed the visibility scope to public as accessing the property directly rather than using _getCallerObject() is faster..
64
     */
65
    public $oCaller;    
66
    
67
    /**
68
     * Stores the caller script file path.
69
     * 
70
     * @since 3.0.0
71
     */
72
    public $sCallerPath;
73
    
74
    /**
75
     * Stores the caller script data
76
     * 
77
     * @remark  This will be set with the `__get()` method.
78
     * @since   unknown
79
     */
80
    public $aScriptInfo;
81
    
82
    /**
83
     * Stores form data.
84
     * @remark  This will be set with the `__get()` method.
85
     * @since   unknwon
86
     */
87
    public $aOptions;
88
    
89
    /**
90
     * Stores the extended class name that instantiated the property object.
91
     * 
92
     * @since     
93
     */
94
    public $sClassName;
95
    
96
    /**
97
     * The MD5 hash string of the extended class name.
98
     * @since     
99
     */
100
    public $sClassHash;
101
    
102
    /**
103
     * Stores the script to be embedded in the head tag.
104
     * 
105
     * @remark This should be an empty string by default since the related methods uses the append operator.
106
     * @since 2.0.0
107
     * @since 2.1.5 Moved from each extended property class.
108
     * @internal
109
     */             
110
    public $sScript = '';    
111
112
    /**
113
     * Stores the CSS rules to be embedded in the head tag.
114
     * 
115
     * @remark This should be an empty string by default since the related methods uses the append operator.
116
     * @since 2.0.0
117
     * @since 2.1.5 Moved from each extended property class.
118
     * @internal
119
     */         
120
    public $sStyle = '';
121
    
122
    /**
123
     * Stores the CSS rules for IE to be embedded in the head tag.
124
     * 
125
     * @remark This should be an empty string by default since the related methods uses the append operator.
126
     * @since 2.0.0 to 2.1.4
127
     * @internal
128
     */ 
129
    public $sStyleIE = '';    
130
131
    /**
132
     * Stores the field type definitions.
133
     * 
134
     * @since 2.1.5
135
     * @internal
136
     */
137
    public $aFieldTypeDefinitions = array();
138
    
139
    /**
140
     * The default JavaScript script loaded in the head tag of the created admin pages.
141
     * 
142
     * @since 3.0.0
143
     * @internal
144
     */
145
    public static $_sDefaultScript = "";
146
    
147
    /**
148
     * The default CSS rules loaded in the head tag of the created admin pages.
149
     * 
150
     * @since       2.0.0
151
     * @var         string
152
     * @static
153
     * @remark      It is accessed from the main class and meta box class.
154
     * @access      public    
155
     * @deprecated  3.2.0
156
     * @internal    
157
     */
158
    public static $_sDefaultStyle ="";    
159
        
160
    /**
161
     * The default CSS rules for IE loaded in the head tag of the created admin pages.
162
     * @since       2.1.1
163
     * @since       2.1.5       Moved the contents to the taxonomy field definition so it become an empty string.
164
     * @deprecated  3.2.0
165
     * @internal
166
     */
167
    public static $_sDefaultStyleIE = '';
168
        
169
    /**
170
     * Stores enqueuing script URLs and their criteria by md5 hash of the source url.
171
     * @since       2.1.2
172
     * @since       2.1.5       Moved to the base class.
173
     */
174
    public $aEnqueuingScripts = array();
175
    /**    
176
     * Stores enqueuing style URLs and their criteria by md5 hash of the source url.
177
     * @since       2.1.2
178
     * @since       2.1.5       Moved to the base class.
179
     */    
180
    public $aEnqueuingStyles = array();
181
182
183
    /**
184
     * Stores enqueued script/style argument array by its url.
185
     * @since       3.3.0
186
     */
187
    public $aResourceAttributes = array();
188
189
    
190
    /**
191
     * Stores the index of enqueued scripts.
192
     * 
193
     * @since       2.1.2
194
     * @since       2.1.5       Moved to the base class.
195
     */
196
    public $iEnqueuedScriptIndex = 0;
197
    /**
198
     * Stores the index of enqueued styles.
199
     * 
200
     * The index number will be incremented as a script is enqueued regardless a previously added enqueue item has been removed or not.
201
     * This is because this index number will be used for the script handle ID which is automatically generated.
202
     * 
203
     * @since       2.1.2
204
     * @since       2.1.5     Moved to the base class.
205
     */    
206
    public $iEnqueuedStyleIndex = 0;     
207
    
208
    /**
209
     * Stores is_admin() value to be reused. 
210
     * 
211
     * @since       3.0.0
212
     */
213
    public $bIsAdmin;
214
    
215
    /**
216
     * Stores the flag that indicates whether the library is minified or not.
217
     * @since       3.0.0
218
     * @deprecated  3.1.3   Use AdminPageFramework_Registry::$bIsMinifiedVersion
219
     */
220
    public $bIsMinifiedVersion;
221
        
222
    /**
223
     * Stores the capability for displayable elements.
224
     * 
225
     * @since       2.0.0
226
     */     
227
    public $sCapability;
228
    
229
    /**
230
     * Defines the fields type.
231
     * 
232
     * Can be either 'admin_page', 'network_admin_page', 'post_meta_box', 'page_meta_box', 'post_type', 'taxonomy_field'
233
     * 
234
     * @since       3.0.4
235
     * @internal
236
     */
237
    public $sStructureType;
238
        
239
    /**
240
     * Stores the text domain.
241
     * 
242
     * @since       3.0.4
243
     * @internal
244
     */ 
245
    public $sTextDomain;
246
    
247
    /**
248
     * Stores the current page's base name.
249
     * 
250
     * @since       3.0.5
251
     * @internal
252
     */
253
    public $sPageNow;
254
    
255
    /**
256
     * Indicates whether the setUp() method is loaded.
257
     *  
258
     * @since       3.1.0
259
     * @internal
260
     * @deprecated  3.7.0      To check if the `setUp()` is called, perform did_action( 'set_up_' . {instantiated class name} )
261
     */
262
    public $_bSetupLoaded;
263
    
264
    /**
265
     * Indicates whether the current page is in admin-ajax.php
266
     * 
267
     * @since       3.1.3
268
     * @internal
269
     */
270
    public $bIsAdminAjax;
271
        
272
    /**
273
     * Stores the label of the settings link embedded to the plugin listing table cell of the plugin title.
274
     * 
275
     * @since       3.1.0
276
     * @since       3.5.5       Moved from `AdminPageFramework_Property_admin_page` as the post type class also access it.
277
     * @remark      The default value should be `null` as the user may explicitly set an empty value.
278
     * The `null` value will be replaced with the system default text 'Settings' while an empty string '' will remove the link.
279
     */     
280
    public $sLabelPluginSettingsLink = null;
281
    
282
    /**
283
     * Stores the information to insert into the page footer.
284
     * 
285
     * The initially assigned text strings, `__SCRIPT_CREDIT__` and `__FRAMEWORK_CREDIT__` are reserved for the default values which will be replaced when the footer is being rendered.
286
     * 
287
     * @since       2.0.0
288
     * @since       3.5.5       Moved from `AdminpageFramework_Property_Page` as this is used by the post type link class and admin page link class.
289
     */             
290
    public $aFooterInfo = array(
291
        'sLeft'     => '__SCRIPT_CREDIT__',
292
        'sRight'    => '__FRAMEWORK_CREDIT__',
293
    );    
294
295
    /**
296
     * The utility object.
297
     * @since       3.5.3
298
     * @deprecated  3.7.0       Not declaring it here to trigger the `__get()` overload method.
299
     */
300
    /* public $oUtil; */
301
              
302
    /**
303
     * Stores the action hook name that gets triggered when the form registration is performed.
304
     * 'admin_page' and 'network_admin_page' will use a custom hook for it.
305
     * @since       3.7.0
306
     * @access      public
307
     */
308
    public $_sFormRegistrationHook = 'current_screen';
309
              
310
    /**
311
     * Stores arguments for the form object.
312
     * @since       3.7.0
313
     */
314
    public $aFormArguments = array(
315
        'caller_id'                         => '',
316
        'structure_type'                    => '',
317
        'action_hook_form_registration'     => '',
318
    );
319
    
320
    /**
321
     * Stores callbacks for the form object.
322
     * @since       3.7.0
323
     */
324
    public $aFormCallbacks = array(
325
        'hfID'              => null,    // the input id attribute
326
        'hfTagID'           => null,    // the field container id attribute
327
        'hfName'            => null,    // the field name attribute
328
        'hfNameFlat'        => null,    // the flat field name attribute
329
        // @todo Document the differences between `hfName` and `hfInputName`
330
        'hfInputName'       => null,    // 3.6.0+   the field input name attribute
331
        'hfInputNameFlat'   => null,    // 3.6.0+   the flat field input name 
332
        'hfClass'           => null,    // the class attribute       
333
    );
334
            
335
    /**
336
     * Indicates the caller script type.
337
     * 
338
     * This can be either 'unknown', 'plugin', or 'theme'.
339
     * @since       3.7.6
340
     */
341
    public $sScriptType = 'unknown';
342
            
343
    /**
344
     * Indicates the action hook to display setting notices.
345
     * 
346
     * @since       3.7.9
347
     */
348
    public $sSettingNoticeActionHook = 'admin_notices';
349
                  
350
    /**
351
     * Stores text to insert into the contextual help tab.
352
     * @since       2.1.0
353
     * @since       3.7.10      Moved from `AdminPageFramework_Property_post_meta_box`
354
     */ 
355
    public $aHelpTabText = array();
356
    
357
    /**
358
     * Stores text to insert into the sidebar of a contextual help tab.
359
     * @since       2.1.0
360
     * @since       3.7.10      Moved from `AdminPageFramework_Property_post_meta_box`
361
     */ 
362
    public $aHelpTabTextSide = array();                  
363
                  
364
    /**
365
     * Stores the meta box title.
366
     * 
367
     * Used for the help pane and meta box title.
368
     * 
369
     * @since       2.0.0
370
     * @since       2.1.0       Moved from the meta box class.
371
     * @since       3.7.10      Moved from `AdminPageFramework_Property_post_meta_box`
372
     * @var string
373
     */ 
374
    public $sTitle = '';                  
375
                  
376
    /**
377
     * Sets up necessary property values.
378
     * 
379
     * @remark      This class gets instantiated in every factory class so the constructor should be lightest as possible.
380
     */
381
    public function __construct( $oCaller, $sCallerPath, $sClassName, $sCapability, $sTextDomain, $sStructureType ) {
382
                
383
        $this->oCaller          = $oCaller;
384
        $this->sCallerPath      = $sCallerPath;
385
        $this->sClassName       = $sClassName; // sanitize name space path delimiter.
386
        $this->sCapability      = empty( $sCapability )
387
            ? 'manage_options'
388
            : $sCapability;
389
        $this->sTextDomain      = empty( $sTextDomain )
390
            ? 'admin-page-framework'
391
            : $sTextDomain;
392
        $this->sStructureType   = $sStructureType;
393
        $this->sPageNow         = $this->getPageNow();
394
        $this->bIsAdmin         = is_admin();
395
        $this->bIsAdminAjax     = in_array( $this->sPageNow, array( 'admin-ajax.php' ) );
396
               
397
        // Overloading property items - these will be set on demand
398
        unset(
399
            $this->aScriptInfo,
400
            $this->aOptions,
401
            $this->sScriptType,
402
            $this->sClassHash
403
        );           
404
           
405
        $this->_setGlobals();
406
       
407
    }
408
        /**
409
         * Sets up global variables.
410
         * @since       3.7.9
411
         */
412
        private function _setGlobals() {
0 ignored issues
show
Coding Style introduced by
_setGlobals uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
413
            if ( ! isset( $GLOBALS[ 'aAdminPageFramework' ] ) ) {
414
                $GLOBALS[ 'aAdminPageFramework' ] = array( 
415
                    'aFieldFlags' => array() 
416
                );
417
            }
418
        } 
419
        
420
    /**
421
     * Sets up properties related to the form object.
422
     * @remark      Should be called right before the form object gets created.
423
     * @since       3.7.9
424
     */
425
    public function setFormProperties() {
426
        $this->aFormArguments = $this->getFormArguments();
427
        $this->aFormCallbacks = $this->getFormCallbacks();
428
    }
429
    /**
430
     * @remark      The Widget factory class access this method.
431
     * @return      array
432
     * @since       3.7.9
433
     */
434
    public function getFormArguments() {
435
        return array(
436
            'caller_id'                         => $this->sClassName,
437
            'structure_type'                    => $this->_sPropertyType,  // @todo change this to admin_page
438
            'action_hook_form_registration'     => $this->_sFormRegistrationHook,
439
        ) + $this->aFormArguments;
440
    }
441
    /**
442
     * @remark      The widget factory class accesses this method.
443
     * @return      array
444
     * @since       3.7.9
445
     */
446
    public function getFormCallbacks() {
447
        return array(
448
            'is_in_the_page'                    => array( $this->oCaller, '_replyToDetermineWhetherToProcessFormRegistration' ),
449
            'load_fieldset_resource'            => array( $this->oCaller, '_replyToFieldsetResourceRegistration' ),
450
            
451
'is_fieldset_registration_allowed'  => null,
452
453
            'capability'                        => array( $this->oCaller, '_replyToGetCapabilityForForm' ),
454
            'saved_data'                        => array( $this->oCaller, '_replyToGetSavedFormData' ),
455
            
456
            // Outputs
457
            'section_head_output'               => array( $this->oCaller, '_replyToGetSectionHeaderOutput' ),
458
            'fieldset_output'                   => array( $this->oCaller, '_replyToGetFieldOutput' ),
459
             
460
            // 
461
            'sectionset_before_output'          => array( $this->oCaller, '_replyToFormatSectionsetDefinition' ),
462
            'fieldset_before_output'            => array( $this->oCaller, '_replyToFormatFieldsetDefinition' ),
463
            'fieldset_after_formatting'         => array( $this->oCaller, '_replyToModifyFieldsetDefinition' ),
464
            'fieldsets_after_formatting'        => array( $this->oCaller, '_replyToModifyFieldsetsDefinitions' ),
465
            
466
            'is_sectionset_visible'             => array( $this->oCaller, '_replyToDetermineSectionsetVisibility' ),
467
            'is_fieldset_visible'               => array( $this->oCaller, '_replyToDetermineFieldsetVisibility' ),
468
            
469
            'secitonsets_before_registration'   => array( $this->oCaller, '_replyToModifySectionsets' ),
470
            'fieldsets_before_registration'     => array( $this->oCaller, '_replyToModifyFieldsets' ),
471
            
472
            'handle_form_data'                  => array( $this->oCaller, '_replyToHandleSubmittedFormData' ),        
473
            
474
            // legacy callbacks
475
            'hfID'                              => array( $this->oCaller, '_replyToGetInputID' ), // the input id attribute
476
            'hfTagID'                           => array( $this->oCaller, '_replyToGetInputTagIDAttribute' ), // the fields & fieldset & field row container id attribute
477
            'hfName'                            => array( $this->oCaller, '_replyToGetFieldNameAttribute' ), // the input name attribute
478
            'hfNameFlat'                        => array( $this->oCaller, '_replyToGetFlatFieldName' ), // the flat input name attribute
479
            'hfInputName'                       => array( $this->oCaller, '_replyToGetInputNameAttribute' ),    // 3.6.0+   the field input name attribute
480
            'hfInputNameFlat'                   => array( $this->oCaller, '_replyToGetFlatInputName' ),    // 3.6.0+   the flat field input name                 
481
            'hfClass'                           => array( $this->oCaller, '_replyToGetInputClassAttribute' ), // the class attribute
482
            'hfSectionName'                     => array( $this->oCaller, '_replyToGetSectionName' ), // 3.6.0+            
483
        ) + $this->aFormCallbacks;        
484
    }
485
    
486
    /**
487
     * Returns the caller object.
488
     * 
489
     * This is used from other sub classes that need to retrieve the caller object.
490
     * 
491
     * @since       2.1.5
492
     * @access      public    
493
     * @return      object The caller class object.
494
     * @internal
495
     * @deprecated  3.7.10          Directly access the $oCaller object for performance.
496
     */     
497
    // public function _getCallerObject() {
498
        // return $this->oCaller;
499
    // }
500
    
501
    /**
502
     * Sets the library information property array.
503
     * @internal
504
     * @since       3.0.0
505
     */
506
    static public function _setLibraryData() {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
507
508
        self::$_aLibraryData = array(
509
            'sName'         => AdminPageFramework_Registry::NAME,
510
            'sURI'          => AdminPageFramework_Registry::URI,
511
            'sScriptName'   => AdminPageFramework_Registry::NAME,
512
            'sLibraryName'  => AdminPageFramework_Registry::NAME,
513
            'sLibraryURI'   => AdminPageFramework_Registry::URI,
514
            'sPluginName'   => '',
515
            'sPluginURI'    => '',
516
            'sThemeName'    => '',
517
            'sThemeURI'     => '',
518
            'sVersion'      => AdminPageFramework_Registry::getVersion(),
519
            'sDescription'  => AdminPageFramework_Registry::DESCRIPTION,
520
            'sAuthor'       => AdminPageFramework_Registry::AUTHOR,
521
            'sAuthorURI'    => AdminPageFramework_Registry::AUTHOR_URI,
522
            'sTextDomain'   => AdminPageFramework_Registry::TEXT_DOMAIN,
523
            'sDomainPath'   => AdminPageFramework_Registry::TEXT_DOMAIN_PATH,
524
            'sNetwork'      => '',
525
            '_sitewide'     => '',
526
        );
527
        return self::$_aLibraryData;
528
        
529
    }
530
    /**
531
     * Returns the set library data array.
532
     * 
533
     * @internal
534
     * @since       3.0.0
535
     */
536
    static public function _getLibraryData() {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
537
        return isset( self::$_aLibraryData ) 
538
            ? self::$_aLibraryData 
539
            : self::_setLibraryData();     
540
    }
541
    
542
    /*
543
     * Methods for getting script info.
544
     */      
545
    /**
546
     * Retrieves the caller script information whether it's a theme or plugin or something else.
547
     * 
548
     * @since       2.0.0
549
     * @since       3.0.0       Moved from the link class.
550
     * @since       3.7.9       Changed the default value to an empty string. Made it use a cache if set.
551
     * @remark      The information can be used to embed into the footer etc.
552
     * @return      array       The information of the script.
553
     */  
554
    protected function getCallerInfo( $sCallerPath='' ) {
555
556
        if ( isset( self::$_aScriptDataCaches[ $sCallerPath ] ) ) {
557
            return self::$_aScriptDataCaches[ $sCallerPath ];
558
        }
559
    
560
        $_aCallerInfo            = self::$_aStructure_CallerInfo;
561
        $_aCallerInfo[ 'sPath' ] = $sCallerPath;
562
        $_aCallerInfo[ 'sType' ] = $this->_getCallerType( $_aCallerInfo[ 'sPath' ] );
563
564
        if ( 'unknown' == $_aCallerInfo[ 'sType' ] ) {
565
            self::$_aScriptDataCaches[ $sCallerPath ] = $_aCallerInfo;
566
            return $_aCallerInfo;
567
        }
568
        if ( 'plugin' == $_aCallerInfo[ 'sType' ] ) {
569
            self::$_aScriptDataCaches[ $sCallerPath ] = $this->getScriptData( $_aCallerInfo[ 'sPath' ], $_aCallerInfo[ 'sType' ] ) + $_aCallerInfo;
570
            return self::$_aScriptDataCaches[ $sCallerPath ];
571
        }
572
        if ( 'theme' == $_aCallerInfo[ 'sType' ] ) {
573
            $_oTheme = wp_get_theme(); // stores the theme info object
574
            self::$_aScriptDataCaches[ $sCallerPath ] = array(
575
                'sName'         => $_oTheme->Name,
576
                'sVersion'      => $_oTheme->Version,
577
                'sThemeURI'     => $_oTheme->get( 'ThemeURI' ),
578
                'sURI'          => $_oTheme->get( 'ThemeURI' ),
579
                'sAuthorURI'    => $_oTheme->get( 'AuthorURI' ),
580
                'sAuthor'       => $_oTheme->get( 'Author' ),     
581
            ) + $_aCallerInfo;    
582
            return self::$_aScriptDataCaches[ $sCallerPath ];
583
        }
584
        self::$_aScriptDataCaches[ $sCallerPath ] = array();
585
        return self::$_aScriptDataCaches[ $sCallerPath ];
586
        
587
    }    
588
        /** 
589
         * @since       3.7.9
590
         */
591
        static private $_aScriptDataCaches = array();
592
    
593
    /**
594
     * Determines the script type.
595
     * 
596
     * It tries to find what kind of script this is, theme, plugin or something else from the given path.
597
     * 
598
     * @since       2.0.0
599
     * @since       3.0.0       Moved from the link class.
600
     * @since       3.1.5       Changed the scope to protected as the post type property class access it.
601
     * @return      string      Returns either 'theme', 'plugin', or 'unknown'
602
     */ 
603
    protected function _getCallerType( $sScriptPath ) {
604
                
605
        if ( isset( self::$_aCallerTypeCache[ $sScriptPath ] ) ) {
606
            return self::$_aCallerTypeCache[ $sScriptPath ];
607
        }
608
        
609
        $sScriptPath = str_replace( '\\', '/', $sScriptPath );
610
        if ( false !== strpos( $sScriptPath, '/themes/' ) ) {
611
            self::$_aCallerTypeCache[ $sScriptPath ] = 'theme';
612
            return 'theme';            
613
        }
614
        // if ( preg_match( '/[\/\\\\]themes[\/\\\\]/', $sScriptPath, $m ) ) {
615
            // self::$_aCallerTypeCache[ $sScriptPath ] = 'theme';
616
            // return 'theme';
617
        // }
618
        if ( false !== strpos( $sScriptPath, '/plugins/' ) ) {
619
            self::$_aCallerTypeCache[ $sScriptPath ] = 'plugin';
620
            return 'plugin';
621
        }        
622
        // if ( preg_match( '/[\/\\\\]plugins[\/\\\\]/', $sScriptPath, $m ) ) {
623
            // self::$_aCallerTypeCache[ $sScriptPath ] = 'plugin';
624
            // return 'plugin';
625
        // }
626
        self::$_aCallerTypeCache[ $sScriptPath ] = 'unknown';
627
        return 'unknown';
628
    
629
    }    
630
        static private $_aCallerTypeCache = array();
631
            
632
    /**
633
     * Retrieves the option array.
634
     * 
635
     * This method should be extended in the extended class.
636
     * 
637
     * @remark      This method is triggered from the __get() overload magic method to set the $aOptions property.
638
     * @since       3.1.0
639
     * @internal
640
     */
641
    protected function _getOptions() {
642
        return array();
643
    }
644
    
645
    /*
646
     * Magic methods
647
     * */
648
    /**
649
     * 
650
     * @since 3.1.3
651
     */
652
    public function __get( $sName ) {
653
        
654
        if ( 'aScriptInfo' === $sName ) {
655
            $this->sCallerPath = $this->sCallerPath 
656
                ? $this->sCallerPath 
657
                : $this->getCallerScriptPath( __FILE__ );
658
            $this->aScriptInfo = $this->getCallerInfo( $this->sCallerPath );
659
            return $this->aScriptInfo;    
660
        }
661
        
662
        // 3.4.1+ Moved from `AdminPageFramework_Property_admin_page` as meta box classes also access it.
663
        // If $this->aOptions is called for the first time, retrieve the option data from the database and assign them to the property.
664
        // Once this is done, calling $this->aOptions will not trigger the __get() magic method any more.
665
        if ( 'aOptions' === $sName ) {
666
            $this->aOptions = $this->_getOptions();
667
            return $this->aOptions;    
668
        }     
669
670
        // 3.7.9 Moved from the constructor to make it lighter.
671
        if ( 'sClassHash' === $sName ) {
672
            $this->sClassHash       = md5( $this->sClassName );    
673
            return $this->sClassHash;
674
        }
675
        if ( 'sScriptType' === $sName ) {
676
            $this->sScriptType      = $this->_getCallerType( $this->sCallerPath );    // 3.7.6+        
677
            return $this->sScriptType;
678
        }
679
        if ( 'oUtil' === $sName ) {
680
            $this->oUtil = new AdminPageFramework_WPUtility;
0 ignored issues
show
Bug introduced by
The property oUtil does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
681
            return $this->oUtil;
682
        }
683
        
684
    }
685
    
686
}
687