Admin Page Framework Documentation
  • Package
  • Class
  • Tree

Packages

  • AdminPageFramework
    • FieldType
    • MetaBox
    • NetworkAdmin
      • Page
    • Page
    • PageMetaBox
    • PostType
    • TaxonomyField
  • None

Classes

  • AdminPageFramework_PostType
  • AdminPageFramework_PostType_Controller
  • AdminPageFramework_PostType_Model
  • AdminPageFramework_PostType_Router
  • AdminPageFramework_PostType_View
  1 <?php
  2 /**
  3  * Admin Page Framework
  4  * 
  5  * http://en.michaeluno.jp/admin-page-framework/
  6  * Copyright (c) 2013-2014 Michael Uno; Licensed MIT
  7  * 
  8  */
  9 if ( ! class_exists( 'AdminPageFramework_PostType_View' ) ) :
 10 /**
 11  * Provides methods of views for the post type factory class.
 12  * 
 13  * Those methods are internal and deal with printing outputs.
 14  * 
 15  * @abstract
 16  * @since 3.0.4
 17  * @package AdminPageFramework
 18  * @subpackage PostType
 19  */
 20 abstract class AdminPageFramework_PostType_View extends AdminPageFramework_PostType_Model {    
 21 
 22     function __construct( $oProp ) {
 23         
 24         parent::__construct( $oProp );
 25                         
 26         if ( $this->_isInThePage() ) {     
 27     
 28             // Table filters
 29             add_action( 'restrict_manage_posts', array( $this, '_replyToAddAuthorTableFilter' ) );
 30             add_action( 'restrict_manage_posts', array( $this, '_replyToAddTaxonomyTableFilter' ) );
 31             add_filter( 'parse_query', array( $this, '_replyToGetTableFilterQueryForTaxonomies' ) );
 32             
 33             // Style
 34             add_action( 'admin_head', array( $this, '_replyToPrintStyle' ) );
 35             
 36         }     
 37                 
 38     }
 39         
 40     /**
 41      * Adds a drop-down list to filter posts by author, placed above the post type listing table.
 42      * 
 43      * @internal
 44      */ 
 45     public function _replyToAddAuthorTableFilter() {
 46         
 47         if ( ! $this->oProp->bEnableAuthorTableFileter ) { return; }
 48         
 49         if ( 
 50             ! ( isset( $_GET['post_type'] ) && post_type_exists( $_GET['post_type'] ) 
 51             && in_array( strtolower( $_GET['post_type'] ), array( $this->oProp->sPostType ) ) ) 
 52         ) {
 53             return;
 54         }
 55         
 56         wp_dropdown_users( array(
 57             'show_option_all' => 'Show all Authors',
 58             'show_option_none' => false,
 59             'name' => 'author',
 60             'selected' => ! empty( $_GET['author'] ) ? $_GET['author'] : 0,
 61             'include_selected' => false
 62         ));
 63             
 64     }
 65     
 66     /**
 67      * Adds drop-down lists to filter posts by added taxonomies, placed above the post type listing table.
 68      * 
 69      * @internal
 70      */ 
 71     public function _replyToAddTaxonomyTableFilter() {
 72         
 73         if ( $GLOBALS['typenow'] != $this->oProp->sPostType ) return;
 74         
 75         // If there is no post added to the post type, do nothing.
 76         $oPostCount = wp_count_posts( $this->oProp->sPostType );
 77         if ( $oPostCount->publish + $oPostCount->future + $oPostCount->draft + $oPostCount->pending + $oPostCount->private + $oPostCount->trash == 0 )
 78             return;
 79         
 80         foreach ( get_object_taxonomies( $GLOBALS['typenow'] ) as $sTaxonomySulg ) {
 81             
 82             if ( ! in_array( $sTaxonomySulg, $this->oProp->aTaxonomyTableFilters ) ) continue;
 83             
 84             $oTaxonomy = get_taxonomy( $sTaxonomySulg );
 85  
 86             // If there is no added term, skip.
 87             if ( wp_count_terms( $oTaxonomy->name ) == 0 ) continue;             
 88 
 89             // This function will echo the drop down list based on the passed array argument.
 90             wp_dropdown_categories( array(
 91                 'show_option_all' => $this->oMsg->__( 'show_all' ) . ' ' . $oTaxonomy->label,
 92                 'taxonomy'       => $sTaxonomySulg,
 93                 'name'           => $oTaxonomy->name,
 94                 'orderby'       => 'name',
 95                 'selected'       => intval( isset( $_GET[ $sTaxonomySulg ] ) ),
 96                 'hierarchical'       => $oTaxonomy->hierarchical,
 97                 'show_count'       => true,
 98                 'hide_empty'       => false,
 99                 'hide_if_empty' => false,
100                 'echo' => true, // this make the function print the output
101             ) );
102             
103         }
104     }
105     /**
106      * Returns a query object based on the taxonomies belongs to the post type.
107      * 
108      * @internal
109      */
110     public function _replyToGetTableFilterQueryForTaxonomies( $oQuery=null ) {
111         
112         if ( 'edit.php' != $this->oProp->sPageNow ) return $oQuery;
113         
114         if ( ! isset( $GLOBALS['typenow'] ) ) return $oQuery;
115 
116         foreach ( get_object_taxonomies( $GLOBALS['typenow'] ) as $sTaxonomySlug ) {
117             
118             if ( ! in_array( $sTaxonomySlug, $this->oProp->aTaxonomyTableFilters ) ) continue;
119             
120             $sVar = &$oQuery->query_vars[ $sTaxonomySlug ];
121             if ( ! isset( $sVar ) ) continue;
122             
123             $oTerm = get_term_by( 'id', $sVar, $sTaxonomySlug );
124             if ( is_object( $oTerm ) )
125                 $sVar = $oTerm->slug;
126 
127         }
128         
129         return $oQuery;
130         
131     }
132     
133     
134     /**
135      * Prints the script.
136      * @internal
137      */
138     public function _replyToPrintStyle() {
139         
140         if ( $this->oUtil->getCurrentPostType() !== $this->oProp->sPostType ) {
141             return;
142         }
143 
144         // If the screen icon url is specified
145         if ( isset( $this->oProp->aPostTypeArgs['screen_icon'] ) && $this->oProp->aPostTypeArgs['screen_icon'] ) {
146             $this->oProp->sStyle .= $this->_getStylesForPostTypeScreenIcon( $this->oProp->aPostTypeArgs['screen_icon'] );
147         }
148             
149         $this->oProp->sStyle = $this->oUtil->addAndApplyFilters( $this, "style_{$this->oProp->sClassName}", $this->oProp->sStyle );
150         
151         // Print out the filtered styles.
152         if ( ! empty( $this->oProp->sStyle ) ) {
153             echo "<style type='text/css' id='admin-page-framework-style-post-type'>" 
154                 . $this->oProp->sStyle
155                 . "</style>";     
156         }
157         
158     }
159         /**
160          * Sets the given screen icon to the post type screen icon.
161          * 
162          * @since 2.1.3
163          * @since 2.1.6 The $sSRC parameter can accept file path.
164          */
165         private function _getStylesForPostTypeScreenIcon( $sSRC ) {
166             
167             $sNone = 'none';
168             
169             $sSRC = $this->oUtil->resolveSRC( $sSRC );
170             
171             return "#post-body-content {
172                     margin-bottom: 10px;
173                 }
174                 #edit-slug-box {
175                     display: {$sNone};
176                 }
177                 #icon-edit.icon32.icon32-posts-" . $this->oProp->sPostType . " {
178                     background: url('" . $sSRC . "') no-repeat;
179                     background-size: 32px 32px;
180                 }     
181             ";     
182             
183         }    
184     
185 }
186 endif;
Admin Page Framework Documentation API documentation generated by ApiGen 2.8.0