Completed
Branch master (69b4cd)
by Michael
05:07
created

_shouldSetPluginActionLinks()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 6
c 1
b 1
f 0
nc 3
nop 0
dl 0
loc 13
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
 * Provides methods for HTML link elements.
12
 *
13
 * @abstract
14
 * @since       2.0.0
15
 * @extends     AdminPageFramework_FrameworkUtility
16
 * @package     AdminPageFramework
17
 * @subpackage  Link
18
 * @internal
19
 */
20
abstract class AdminPageFramework_Link_Base extends AdminPageFramework_FrameworkUtility {
21
     
22
    public $oProp;
23
24
    public $oMsg;
25
     
26
    /**
27
     * Sets up hooks and properties.
28
     */ 
29
    public function __construct( $oProp, $oMsg=null ) {
30
        
31
        if ( ! $this->_isLoadable( $oProp ) ) {
32
            return;
33
        }
34
                
35
        $this->oProp    = $oProp;
36
        $this->oMsg     = $oMsg;        
37
        
38
        add_action( 'in_admin_footer', array( $this, '_replyToSetFooterInfo' ) );
39
        
40
        // Add an action link in the plugin listing page
41
        if ( $this->_shouldSetPluginActionLinks() ) {
42
            add_filter( 
43
                'plugin_action_links_' . plugin_basename( $this->oProp->aScriptInfo[ 'sPath' ] ),
44
                array( $this, '_replyToAddSettingsLinkInPluginListingPage' ), 
45
                20     // set a lower priority so that the link will be embedded at the beginning ( the most left hand side ).
46
            );     
47
        }        
48
        
49
    }
50
        /**
51
         * Determines if construction the object should be performed or not.
52
         * 
53
         * @since       3.5.5
54
         * @return      boolean
55
         */
56
        private function _isLoadable( $oProp ) {
57
            if ( ! $oProp->bIsAdmin ) { 
58
                return false;
59
            }
60
            if ( $oProp->bIsAdminAjax ) {
61
                return false;
62
            }
63
            return ! $this->hasBeenCalled( 'links_' . $oProp->sClassName );
64
        }
65
        
66
    /**
67
     * Checks whether it is okay to set up action links in the plugin listing page (plugins.php).
68
     * @since       3.7.15
69
     * @return      boolean
70
     */
71
    protected function _shouldSetPluginActionLinks() {
72
        
73
        // It is possible that the sub-objects are not set when the class is considered not loadable.
74
        if ( ! isset( $this->oProp ) ) {
75
            return false;
76
        }
77
        
78
        if ( ! in_array( $this->oProp->sPageNow, array( 'plugins.php' ) ) ) {
79
            return false;
80
        }
81
        return 'plugin' === $this->oProp->aScriptInfo[ 'sType' ];
82
        
83
    }
84
        
85
    /**
86
     * Sets up footer information.
87
     * 
88
     * @since           3.5.5
89
     * @callback        action      in_admin_footer
90
     */
91
    public function _replyToSetFooterInfo() {
92
93
        $this->_setDefaultFooterText();
94
        $this->_setFooterHooks();
95
           
96
    }              
97
       
98
        /**
99
         * Set the default footer text values.
100
         * @internal        
101
         * @since       3.5.5
102
         * @return      void
103
         */
104
        protected function _setDefaultFooterText() {
105
        
106
            $this->oProp->aFooterInfo[ 'sLeft' ] = str_replace( 
107
                '__SCRIPT_CREDIT__', 
108
                $this->_getFooterInfoLeft( $this->oProp->aScriptInfo ),
109
                $this->oProp->aFooterInfo[ 'sLeft' ]
110
            );
111
            $this->oProp->aFooterInfo[ 'sRight' ] = str_replace(
112
                '__FRAMEWORK_CREDIT__',
113
                $this->_getFooterInfoRight( $this->oProp->_getLibraryData() ),
114
                $this->oProp->aFooterInfo[ 'sRight' ]
115
            );
116
            
117
        }
118
            /**
119
             * Sets the default footer text on the left hand side.
120
             * 
121
             * @since       2.1.1
122
             * @since       3.5.5       Changed the name from `_setFooterInfoLeft()` and dropped the second parameter.
123
             * @return      string
124
             */
125
            private function _getFooterInfoLeft( $aScriptInfo ) {
126
127
                $_sDescription = $this->getAOrB(
128
                    empty( $aScriptInfo[ 'sDescription' ] ),
129
                    '',
130
                    "&#13;{$aScriptInfo[ 'sDescription' ]}"
131
                );
132
                $_sVersion = $this->getAOrB(
133
                    empty( $aScriptInfo[ 'sVersion' ] ),
134
                    '',
135
                    "&nbsp;{$aScriptInfo[ 'sVersion' ]}"
136
                );
137
                $_sPluginInfo = $this->getAOrB(
138
                    empty( $aScriptInfo[ 'sURI' ] ),
139
                    $aScriptInfo[ 'sName' ],
140
                    $this->getHTMLTag( 
141
                        'a', 
142
                        array(
143
                            'href'      => $aScriptInfo[ 'sURI' ],
144
                            'target'    => '_blank',
145
                            'title'     => $aScriptInfo[ 'sName' ] . $_sVersion . $_sDescription 
146
                        ), 
147
                        $aScriptInfo[ 'sName' ] 
148
                    )    
149
                );
150
151
                $_sAuthorInfo = $this->getAOrB(
152
                    empty( $aScriptInfo[ 'sAuthorURI' ] ),
153
                    '',
154
                    $this->getHTMLTag( 
155
                        'a', 
156
                        array(
157
                            'href'      => $aScriptInfo[ 'sAuthorURI' ],
158
                            'target'    => '_blank',
159
                            'title'     => $aScriptInfo[ 'sAuthor' ],
160
                        ), 
161
                        $aScriptInfo[ 'sAuthor' ]
162
                    )                
163
                );
164
                $_sAuthorInfo = $this->getAOrB(
165
                    empty( $aScriptInfo[ 'sAuthor' ] ),
166
                    $_sAuthorInfo,
167
                    ' by ' . $_sAuthorInfo
168
                );
169
                
170
                // Enclosing the output in a span tag as the outer element is a '<p>' tag. So this cannot be div.
171
                // 3.5.7+ Added the class attribute for acceptance testing
172
                return "<span class='apf-script-info'>"  
173
                        . $_sPluginInfo . $_sAuthorInfo
174
                    . "</span>";
175
          
176
            }
177
            /**
178
             * Sets the default footer text on the right hand side.
179
             * 
180
             * @since       2.1.1
181
             * @since       3.5.5       Changed the name from `_setFooterInfoRight()` and dropped the second parameter.
182
             * @return      string
183
             */    
184
            private function _getFooterInfoRight( $aScriptInfo ) {
0 ignored issues
show
Coding Style introduced by
_getFooterInfoRight 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...
185
186
                $_sDescription = $this->getAOrB(
187
                    empty( $aScriptInfo[ 'sDescription' ] ),
188
                    '',
189
                    "&#13;{$aScriptInfo[ 'sDescription' ]}"
190
                );
191
                $_sVersion = $this->getAOrB(
192
                    empty( $aScriptInfo[ 'sVersion' ] ),
193
                    '',
194
                    "&nbsp;{$aScriptInfo[ 'sVersion' ]}"
195
                );
196
                $_sLibraryInfo = $this->getAOrB(
197
                    empty( $aScriptInfo[ 'sURI' ] ),
198
                    $aScriptInfo[ 'sName' ],
199
                    $this->getHTMLTag( 
200
                        'a', 
201
                        array(
202
                            'href'      => $aScriptInfo[ 'sURI' ],
203
                            'target'    => '_blank',
204
                            'title'     => $aScriptInfo[ 'sName' ] . $_sVersion . $_sDescription,
205
                        ), 
206
                        $aScriptInfo[ 'sName' ]
207
                    )                   
208
                );
209
                
210
                // Update the variable
211
                // 3.5.7+ added the 'apf-credit' class attribute for acceptance testing
212
                // 3.7.0+  added the footer-thankyou id attribute.
213
                return "<span class='apf-credit' id='footer-thankyou'>" 
214
                    . $this->oMsg->get( 'powered_by' ) . '&nbsp;' 
215
                    . $_sLibraryInfo
216
                    . ",&nbsp;"
217
                    . $this->oMsg->get( 'and' ) . '&nbsp;' 
218
                    . $this->getHTMLTag( 
219
                        'a', 
220
                        array(
221
                            'href'      => 'https://wordpress.org',
222
                            'target'    => '_blank',
223
                            'title'     => 'WordPress ' . $GLOBALS[ 'wp_version' ]
224
                        ), 
225
                        'WordPress'
226
                    )
227
                    . "</span>";
228
                    
229
            }        
230
        
231
        /**
232
         * Sets up hooks to insert admin footer text strings.
233
         * @internal
234
         * @since       3.5.5
235
         * @return      void
236
         */
237
        protected function _setFooterHooks() {
238
            
239
            add_filter( 'admin_footer_text' , array( $this, '_replyToAddInfoInFooterLeft' ) );
240
            add_filter( 'update_footer', array( $this, '_replyToAddInfoInFooterRight' ), 11 );
241
            
242
        }             
243
            /**
244
             * Inserts the left footer text.
245
             * @since       2.0.0
246
             * @since       3.5.5       Moved from `AdminPageFramework_Link_post_type`.
247
             * @remark      The page link class will override this method.
248
             * @callback    filter      admin_footer_text
249
             * @internal
250
             */ 
251
            public function _replyToAddInfoInFooterLeft( $sLinkHTML='' ) {
252
253
                $sLinkHTML = empty( $this->oProp->aScriptInfo[ 'sName' ] )
254
                    ? $sLinkHTML
255
                    : $this->oProp->aFooterInfo[ 'sLeft' ];
256
             
257
                return $this->addAndApplyFilters( 
258
                    $this->oProp->oCaller, 
259
                    'footer_left_' . $this->oProp->sClassName, 
260
                    $sLinkHTML
261
                );
262
             
263
            }
264
            /**
265
             * Inserts the right footer text.
266
             * @since       2.0.0
267
             * @since       3.5.5       Moved from `AdminPageFramework_Link_post_type`.
268
             * @remark      The page link class will override this method.
269
             * @callback    filter      admin_footer_text
270
             * @internal
271
             */     
272
            public function _replyToAddInfoInFooterRight( $sLinkHTML='' ) {
273
                return $this->addAndApplyFilters( 
274
                    $this->oProp->oCaller, 
275
                    'footer_right_' . $this->oProp->sClassName, 
276
                    $this->oProp->aFooterInfo[ 'sRight' ]
277
                );                
278
            }       
279
       
280
}
281