Completed
Branch master (163d15)
by
unknown
18:49 queued 09:51
created

AdminPageFramework_NetworkAdmin::__construct()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 29
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 29
rs 8.8571
cc 3
eloc 8
nc 3
nop 4
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 factory class that creates network admin pages.
12
 *
13
 * @abstract
14
 * @since       3.1.0
15
 * @remark      This class stems from several abstract classes.
16
 * @extends     AdminPageFramework
17
 * @package     AdminPageFramework
18
 * @subpackage  NetworkAdmin
19
 */
20
abstract class AdminPageFramework_NetworkAdmin extends AdminPageFramework {
21
       
22
    /**
23
     * Defines the class object structure type.
24
     * 
25
     * @since       3.7.12      
26
     * @internal
27
     */
28
    protected $_sStructureType = 'network_admin_page';
29
       
30
    /**
31
     * Used to refer the built-in root menu slugs.
32
     * 
33
     * @since       3.1.0
34
     * @remark      Not for the user.
35
     * @var         array Holds the built-in root menu slugs.
36
     * @internal
37
     */ 
38
    protected $_aBuiltInRootMenuSlugs = array(
39
        // All keys must be lower case to support case insensitive look-ups.
40
        'dashboard'     => 'index.php',
41
        'sites'         => 'sites.php',         // not work
42
        'themes'        => 'themes.php',        // not work
43
        'plugins'       => 'plugins.php',
44
        'users'         => 'users.php',
45
        'settings'      => 'settings.php',
46
        'updates'       => 'update-core.php',   // does not work
47
    );     
48
        
49
    /**
50
     * Registers necessary callbacks ans sets up internal components including properties.
51
     * 
52
     * <h4>Example</h4>
53
     * <code>if ( is_admin() )
54
     *     new MyAdminPageClass( 'my_custom_option_key', __FILE__ );</code>
55
     * 
56
     * @access      public
57
     * @since       3.1.0
58
     * @see         http://codex.wordpress.org/Roles_and_Capabilities
59
     * @see         http://codex.wordpress.org/I18n_for_WordPress_Developers#Text_Domains
60
     * @param       string      $sOptionKey         (optional) specifies the option key name to store in the options table. If this is not set, the instantiated class name will be used.
61
     * @param       string      $sCallerPath        (optional) used to retrieve the plugin/theme details to auto-insert the information into the page footer.
62
     * @param       string      $sCapability        (optional) sets the overall access level to the admin pages created by the framework. The used capabilities are listed <a href="http://codex.wordpress.org/Roles_and_Capabilities">here</a>. The capability can be set per page, tab, setting section, setting field. Default: `manage_options.`
63
     * @param       string      $sTextDomain        (optional) the <a href="http://codex.wordpress.org/I18n_for_WordPress_Developers#Text_Domains" target="_blank">text domain</a> used for the framework's system messages. Default: `admin-page-framework`.
64
     * @return      void        returns nothing.
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
65
     */
66
    public function __construct( $sOptionKey=null, $sCallerPath=null, $sCapability='manage_network', $sTextDomain='admin-page-framework' ){
67
            
68
        if ( ! $this->_isInstantiatable() ) {
69
            return;
70
        }
71
                    
72
        $sCallerPath = $sCallerPath 
73
            ? $sCallerPath 
74
            : AdminPageFramework_Utility::getCallerScriptPath( __FILE__ );     // this is important to attempt to find the caller script path here when separating the library into multiple files.
75
     
76
        // $_sProprtyClassName = $this->aSubClassNames[ 'oProp' ] 
77
            // ? $this->aSubClassNames[ 'oProp' ] 
78
            // : 'AdminPageFramework_Property_' . $this->_sStructureType;
79
            
80
        // $this->oProp = new $_sProprtyClassName( 
81
            // $this, 
82
            // $sCallerPath, 
83
            // get_class( $this ), 
84
            // $sOptionKey, 
85
            // $sCapability,
86
            // $sTextDomain,
87
            // $this->_sStructureType
88
        // );
89
        
90
        parent::__construct( $sOptionKey, $sCallerPath, $sCapability, $sTextDomain );
91
        
92
        new AdminPageFramework_Model_Menu__RegisterMenu( $this, 'network_admin_menu' );
93
        
94
    }    
95
    
96
    /**
97
     * Instantiates a link object based on the type.
98
     * 
99
     * @since       3.7.10
100
     * @internal
101
     * @return      null|object
102
     */
103
    protected function _getLinkObject() {
104
        $_sClassName = $this->aSubClassNames[ 'oLink' ];
105
        return new $_sClassName( $this->oProp, $this->oMsg );        
106
    }
107
    
108
    /**
109
     * Instantiates a link object based on the type.
110
     * 
111
     * @since       3.7.10
112
     * @internal
113
     * @return      null|object
114
     */    
115
    protected function _getPageLoadObject() {
116
        $_sClassName = $this->aSubClassNames[ 'oPageLoadInfo' ];
117
        return new $_sClassName( $this->oProp, $this->oMsg );
118
    }    
119
120
    /**
121
     * Checks whether the class should be instantiated.
122
     * 
123
     * @since       3.1.0
124
     * @internal
125
     */
126
    protected function _isInstantiatable() {
0 ignored issues
show
Coding Style introduced by
_isInstantiatable 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...
127
        
128
        if ( isset( $GLOBALS['pagenow'] ) && 'admin-ajax.php' === $GLOBALS['pagenow'] ) {
129
            return false;
130
        }     
131
        
132
        // Nothing to do in the non-network admin area.
133
        if ( is_network_admin() ) {
134
            return true;
135
        }
136
        
137
        return false;
138
        
139
    }
140
    
141
    
142
    /**
143
     * Retrieves the saved option value from the given option key and the dimensional array key representation.
144
     * 
145
     * <h4>Example</h4>
146
     * <code>
147
     * $aData       = AdminPageFramework::getOption( 'APF' );
148
     * $aSection    = AdminPageFramework::getOption( 'APF', 'my_section' );
149
     * $sText       = AdminPageFramework::getOption( 'APF', array( 'my_section', 'my_text_field' ), 'foo' );
150
     * $sColor      = AdminPageFramework::getOption( 'APF', 'my_color_field', '#FFF' );
151
     * </code>
152
     * 
153
     * @since       3.1.0
154
     * @param       string      $sOptionKey     the option key of the options table.
155
     * @param       string      $asKey          the representation of dimensional array keys. If the returning option structure is like the following,
156
     * <code>
157
     * array(
158
     *     'a' => array(
159
     *         'b' => array(
160
     *             'c' => 'ccc',
161
     *         ),
162
     *     ),
163
     * )
164
     * </code>
165
     * then the value 'ccc' can be retrieved with the key representation array of 
166
     * <code>
167
     * array( 'a', 'b', 'c' )
168
     * </code>
169
     * @param       mixed       $vDefault     the default value that will be returned if nothing is stored.
170
     * @return      mixed       If the field ID is not specified.
171
     */
172
    static public function getOption( $sOptionKey, $asKey=null , $vDefault=null ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
173
        return AdminPageFramework_WPUtility::getSiteOption( $sOptionKey, $asKey, $vDefault );
174
    }
175
    
176
}
177