Completed
Branch dev (a3767f)
by Michael
40:38
created

replyToLoadTab()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12
Metric Value
dl 0
loc 23
rs 9.0857
ccs 0
cts 20
cp 0
cc 3
eloc 15
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * Admin Page Framework Loader
4
 * 
5
 * Demonstrates the usage of Admin Page Framework.
6
 * 
7
 * http://en.michaeluno.jp/admin-page-framework/
8
 * Copyright (c) 2013-2015 Michael Uno; Licensed GPLv2
9
 * 
10
 */
11
12
/**
13
 * Adds a tab of the set page to the loader plugin.
14
 * 
15
 * @since       3.5.0    
16
 */
17
class AdminPageFrameworkLoader_AdminPage_Help_FAQ extends AdminPageFrameworkLoader_AdminPage_Tab_ReadMeBase {
2 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
18
    
19
    /**
20
     * Triggered when the tab is loaded.
21
     */
22
    public function replyToLoadTab( $oAdminPage ) {
23
24
        $_aSections  = $this->getContentsByHeader( $this->getFAQContents(), 4 );
25
        foreach( $_aSections as $_iIndex => $_aContent ) {
26
            
27
            $_sTitle   = $_aContent[ 0 ];
28
            $_sContent = $this->_getFAQSubSections( $_aContent[ 1 ] );
29
            if ( in_array( $_sTitle, array( 'Tutorials' ) ) ) {
30
                continue;
31
            }
32
            $oAdminPage->addSettingSections(    
33
                $this->sPageSlug, // the target page slug  
34
                array(
35
                    'section_id'        => 'faq_sections_' . $_iIndex,
36
                    'tab_slug'          => $this->sTabSlug,                
37
                    'section_tab_slug'  => 'apf_faq',
38
                    'title'             => $_sTitle,
39
                    'content'           => $_sContent,
40
                )
41
            );            
42
        }
43
44
    }
45
        /**
46
         * @return      array|string        If sections exits, an array holding sections. If no, a string content of the item.
47
         */
48
        private function _getFAQSubSections( $asItems ) {
1 ignored issue
show
Coding Style introduced by
Method name "_getFAQSubSections" should not be prefixed with an underscore to indicate visibility
Loading history...
49
            
50
            if ( empty( $asItems ) ) {
51
                return array();
52
            }
53
            $aItems = $this->getContentsByHeader( $asItems, 5 );
54
            
55
            $_aNestedSections = array();
56
            $_iLastIndex = count( $aItems ) - 1;
57
            foreach( $aItems as $_iIndex => $_aContent ) {
58
                
59
                $_oParser   = new AdminPageFramework_WPReadmeParser( $_aContent[ 1 ] );
60
                
61
                // If no sections, return the contents of the first item.
62
                if ( ! $_aContent[ 0 ] ) {
63
                    return $_oParser->get();
64
                }
65
                
66
                $_aNestedSections[] = array(
67
                    'section_id'        => 'faq_item_' . $_iIndex,
68
                    'title'             => $_aContent[ 0 ],
69
                    'collapsible'       => array(
70
                        'toggle_all_button' => $_iLastIndex === $_iIndex 
71
                            ? array( 'bottom-right' )
72
                            : ( 0 === $_iIndex
73
                                ? array( 'top-right' )
74
                                : false
75
                            ),
76
                    ),
77
                    'content'           => $_oParser->get(),
78
                );
79
            }
80
            return $_aNestedSections;
81
            
82
        }
83
        private function getFAQContents()  {
84
            
85
            $_aReplacements   = array(
86
                '%PLUGIN_DIR_URL%'  => AdminPageFrameworkLoader_Registry::getPluginURL(),
87
                '%WP_ADMIN_URL%'    => admin_url(),
88
            );
89
            $_oWPReadmeParser = new AdminPageFramework_WPReadmeParser( 
90
                AdminPageFrameworkLoader_Registry::$sDirPath . '/readme.txt',
91
                $_aReplacements
92
            );    
93
            return $_oWPReadmeParser->getRawSection( 'Frequently asked questions' );                        
94
            
95
        }
96
    
97
}
1 ignored issue
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...