_printClassSpecificScripts()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 34
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 34
rs 9.3222
c 0
b 0
f 0
cc 5
nc 5
nop 1
1
<?php
2
/**
3
 * Admin Page Framework
4
 *
5
 * http://admin-page-framework.michaeluno.jp/
6
 * Copyright (c) 2013-2022, Michael Uno; Licensed MIT
7
 *
8
 */
9
10
/**
11
 * {@inheritdoc}
12
 *
13
 * {@inheritdoc}
14
 *
15
 * This is for generic pages the framework creates.
16
 *
17
 * @since       2.1.5
18
 * @since       3.3.0       Changed the name from AdminPageFramework_HeadTag_Page.
19
 * @package     AdminPageFramework/Factory/AdminPage/Resource
20
 * @extends     AdminPageFramework_Resource_Base
21
 * @internal
22
 */
23
class AdminPageFramework_Resource_admin_page extends AdminPageFramework_Resource_Base {
24
25
    /**
26
     * Applies page and tab specific filters to inline CSS rules.
27
     *
28
     * @since       3.5.0
29
     * @return      void
30
     */
31
    protected function _printClassSpecificStyles( $sIDPrefix ) {
32
33
        // This method can be called two times in a page to support embedding in the footer.
34
        static $_bLoaded = false;
35
        if ( $_bLoaded ) {
36
            parent::_printClassSpecificStyles( $sIDPrefix );
37
            return;
38
        }
39
        $_bLoaded   = true;
40
41
        $_oCaller   = $this->oProp->oCaller;
42
        $_sPageSlug = $this->_getCurrentPageSlugForFilter();
43
        $_sTabSlug  = $this->_getCurrentTabSlugForFilter( $_sPageSlug );
44
45
        // tab
46
        if ( $_sPageSlug && $_sTabSlug ) {
47
            $this->oProp->sStyle     = $this->addAndApplyFilters(
48
                $_oCaller,
49
                "style_{$_sPageSlug}_{$_sTabSlug}",
50
                $this->oProp->sStyle
51
            );
52
        }
53
54
        // page
55
        if ( $_sPageSlug ) {
56
            $this->oProp->sStyle     = $this->addAndApplyFilters(
57
                $_oCaller,
58
                "style_{$_sPageSlug}",
59
                $this->oProp->sStyle
60
            );
61
        }
62
63
        // The parent method should be called after updating the $this->oProp->sStyle property above.
64
        parent::_printClassSpecificStyles( $sIDPrefix );
65
66
    }
67
        /**
68
         * Returns the currently loaded page slug to apply resource filters.
69
         *
70
         * If the page has not been added, an empty value will be returned.
71
         *
72
         * @since       3.5.3
73
         * @return      string      The page slug if the page has been added.
74
         */
75
        private function _getCurrentPageSlugForFilter() {
76
            $_sPageSlug = $this->oProp->getCurrentPageSlug();
0 ignored issues
show
Bug introduced by
The method getCurrentPageSlug() does not exist on AdminPageFramework_Property_Base. Did you maybe mean getCurrentPostType()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
            /** @scrutinizer ignore-call */ 
77
            $_sPageSlug = $this->oProp->getCurrentPageSlug();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
            return $this->oProp->isPageAdded( $_sPageSlug )
0 ignored issues
show
Bug introduced by
The method isPageAdded() does not exist on AdminPageFramework_Property_Base. It seems like you code against a sub-type of AdminPageFramework_Property_Base such as AdminPageFramework_Property_admin_page or AdminPageFramework_Property_page_meta_box. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
            return $this->oProp->/** @scrutinizer ignore-call */ isPageAdded( $_sPageSlug )
Loading history...
78
                ? $_sPageSlug
79
                : '';
80
        }
81
        /**
82
         * Returns the currently loaded tab slug to apply resource filters.
83
         *
84
         * If the tab has not been added, an empty value will be returned.
85
         *
86
         * @since       3.5.3
87
         * @return      string      The tab slug if the tab has been added.
88
         */
89
        private function _getCurrentTabSlugForFilter( $sPageSlug ) {
90
            $_sTabSlug  = $this->oProp->getCurrentTabSlug( $sPageSlug );
0 ignored issues
show
Bug introduced by
The method getCurrentTabSlug() does not exist on AdminPageFramework_Property_Base. Did you maybe mean getCurrentURL()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
            /** @scrutinizer ignore-call */ 
91
            $_sTabSlug  = $this->oProp->getCurrentTabSlug( $sPageSlug );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
            return isset( $this->oProp->aInPageTabs[ $sPageSlug ][ $_sTabSlug ] )
0 ignored issues
show
Bug Best Practice introduced by
The property aInPageTabs does not exist on AdminPageFramework_Property_Base. Since you implemented __get, consider adding a @property annotation.
Loading history...
92
                ? $_sTabSlug
93
                : '';
94
        }
95
96
    /**
97
     * Applies page and tab specific filters to inline JaveScript scirpts.
98
     *
99
     * @since       3.5.0
100
     * @return      void
101
     */
102
    protected function _printClassSpecificScripts( $sIDPrefix ) {
103
104
        // This method can be called two times in a page to support embedding in the footer.
105
        static $_bLoaded = false;
106
        if ( $_bLoaded ) {
107
            parent::_printClassSpecificScripts( $sIDPrefix );
108
            return;
109
        }
110
        $_bLoaded   = true;
111
112
        $_oCaller   = $this->oProp->oCaller;
113
        $_sPageSlug = $this->_getCurrentPageSlugForFilter();
114
        $_sTabSlug  = $this->_getCurrentTabSlugForFilter( $_sPageSlug );
115
116
        // tab
117
        if ( $_sPageSlug && $_sTabSlug ) {
118
            $this->oProp->sScript     = $this->addAndApplyFilters(
119
                $_oCaller,
120
                "script_{$_sPageSlug}_{$_sTabSlug}",
121
                $this->oProp->sScript
122
            );
123
        }
124
125
        // page
126
        if ( $_sPageSlug ) {
127
            $this->oProp->sScript     = $this->addAndApplyFilters(
128
                $_oCaller,
129
                "script_{$_sPageSlug}",
130
                $this->oProp->sScript
131
            );
132
        }
133
134
        // The parent method should be called after updating the $this->oProp->sScript property above.
135
        parent::_printClassSpecificScripts( $sIDPrefix );
136
137
    }
138
139
    /**
140
     * A helper function for the _replyToEnqueueScripts() and _replyToEnqueueStyle() methods.
141
     *
142
     * @since       2.1.2
143
     * @since       2.1.5       Moved from the main class. Changed the name from enqueueSRCByPageConditoin.
144
     * @since       3.7.0      Fixed a typo in the method name.
145
     * @internal
146
     */
147
    protected function _enqueueSRCByCondition( $aEnqueueItem ) {
148
149
        $sCurrentPageSlug   = $this->oProp->getCurrentPageSlug();
150
        $sCurrentTabSlug    = $this->oProp->getCurrentTabSlug( $sCurrentPageSlug );
151
        $sPageSlug          = $aEnqueueItem['sPageSlug'];
152
        $sTabSlug           = $aEnqueueItem['sTabSlug'];
153
154
        // If the page slug is not specified and the currently loading page is one of the pages that is added by the framework,
155
        if ( ! $sPageSlug && $this->oProp->isPageAdded( $sCurrentPageSlug ) ) { // means script-global(among pages added by the framework)
156
            $this->_enqueueSRC( $aEnqueueItem );
157
        }
158
159
        // If both tab and page slugs are specified,
160
        if (
161
            ( $sPageSlug && $sCurrentPageSlug == $sPageSlug )
162
            && ( $sTabSlug && $sCurrentTabSlug == $sTabSlug )
163
        ) {
164
            $this->_enqueueSRC( $aEnqueueItem );
165
        }
166
167
        // If the tab slug is not specified and the page slug is specified,
168
        // and if the current loading page slug and the specified one matches,
169
        if (
170
            ( $sPageSlug && ! $sTabSlug )
171
            && ( $sCurrentPageSlug == $sPageSlug )
172
        ) {
173
            $this->_enqueueSRC( $aEnqueueItem );
174
        }
175
176
    }
177
}