| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Admin Page Framework Loader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Demonstrates the usage of Admin Page Framework. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * http://admin-page-framework.michaeluno.jp/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Copyright (c) 2013-2022, Michael Uno; Licensed GPLv2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * A base class that provides methods to display readme file contents. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @sicne       3.5.3       Extends `AdminPageFrameworkLoader_AdminPage_Tab_Base`. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @extends     AdminPageFrameworkLoader_AdminPage_Tab_Base | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | abstract class AdminPageFrameworkLoader_AdminPage_Tab_ReadMeBase extends AdminPageFrameworkLoader_AdminPage_Tab_Base { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @since       3.5.3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     protected function _getReadmeContents( $sFilePath, $sTOCTitle, $asSections=array() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $_oWPReadmeParser = new AdminPageFramework_WPReadmeParser( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             $sFilePath, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             array( // replacements | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 '%PLUGIN_DIR_URL%'  => AdminPageFrameworkLoader_Registry::getPluginURL(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 '%WP_ADMIN_URL%'    => admin_url(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             array( // callbacks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 'content_before_parsing' => array( $this, '_replyToProcessShortcodes' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $_sContent = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         foreach( ( array ) $asSections as $_sSection  ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             $_sContent .= $_oWPReadmeParser->getSection( $_sSection ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         if ( $sTOCTitle ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $_oTOC = new AdminPageFramework_TableOfContents( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 $_sContent, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 4, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 $sTOCTitle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             return $_oTOC->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return '' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |          . $_sContent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |          * @return      string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |          * @return      3.6.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         public function _replyToProcessShortcodes( $sContent ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             // Register the 'embed' shortcode. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             add_shortcode( 'embed', array( $this, '_replyToProcessShortcode_embed' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             return do_shortcode( $sContent ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |              * @since       3.6.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |              * @return      string      The generate HTML output. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |              */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             public function _replyToProcessShortcode_embed( $aAttributes, $sURL, $sShortcode='' ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 $sURL   = isset( $aAttributes[ 'src' ] ) ? $aAttributes[ 'src' ] : $sURL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                 $_sHTML = wp_oembed_get( $sURL ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 // If there was a result, return it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 if ( $_sHTML ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                     // This filter is documented in wp-includes/class-wp-embed.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                     return "<div class='video oembed'>" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                                 . apply_filters( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                                     'embed_oembed_html', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                                     $_sHTML, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                                     $sURL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                                     $aAttributes, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                                     0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                         . "</div>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 // If not found, return the link. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 $_oWPEmbed = new WP_Embed; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 return "<div class='video oembed'>" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                         . $_oWPEmbed->maybe_make_link( $sURL ) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                     . "</div>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * Returns HTML contents divided by heading. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * For example, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * <h3>First Heading</h3> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * Some text. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * <h3>Second Heading</h3> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * Another text. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * Will be | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      *  array( 'First Heading' => 'Some text', ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      *  array( 'Second Heading' => 'Another text', ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * ) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 110 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |     public function getContentsByHeader( $sContents, $iHeaderNumber=2 ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |         $_aContents = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |         $_aSplitContents = preg_split( | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |             // '/^[\s]*==[\s]*(.+?)[\s]*==/m', | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |             '/(<h[' . $iHeaderNumber . ']*[^>]*>.*?<\/h[' . $iHeaderNumber . ']>)/i', | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |             $sContents, | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |             -1, | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |             PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |         foreach( $_aSplitContents as $_iIndex => $_sSplitContent ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |             if ( ! preg_match( '/<h[' . $iHeaderNumber . ']*[^>]*>(.*?)<\/h[' . $iHeaderNumber . ']>/i', $_sSplitContent , $_aMatches ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |                 continue; | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |             if ( ! isset( $_aMatches[ 1 ] ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |                 continue; | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |             if ( isset( $_aSplitContents[ $_iIndex + 1 ] ) )  { | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |                 $_aContents[] = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |                     $_aMatches[ 1 ], | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |                     $_aSplitContents[ $_iIndex + 1 ] | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |                 ); | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |         return empty( $_aContents ) | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |             ? array( array( '', $sContents ) ) | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |             : $_aContents; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 144 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 145 |  |  |  | 
            
                        
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.