1 <?php
2 3 4 5 6 7 8
9 if ( ! class_exists( 'AdminPageFramework_PostType_View' ) ) :
10 11 12 13 14 15 16 17 18 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
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
34 add_action( 'admin_head', array( $this, '_replyToPrintStyle' ) );
35
36 }
37
38 }
39
40 41 42 43 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 68 69 70
71 public function _replyToAddTaxonomyTableFilter() {
72
73 if ( $GLOBALS['typenow'] != $this->oProp->sPostType ) return;
74
75
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
87 if ( wp_count_terms( $oTaxonomy->name ) == 0 ) continue;
88
89
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,
101 ) );
102
103 }
104 }
105 106 107 108 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 136 137
138 public function _replyToPrintStyle() {
139
140 if ( $this->oUtil->getCurrentPostType() !== $this->oProp->sPostType ) {
141 return;
142 }
143
144
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
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 161 162 163 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;