PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / 4.0
Advanced Access Manager – Access Governance for WordPress v4.0
6.8.4 6.8.5 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13 6.9.14 6.9.15 6.9.16 6.9.17 6.9.18 6.9.19 6.9.2 6.9.20 6.9.21 6.9.22 6.9.23 6.9.24 6.9.25 6.9.26 6.9.27 6.9.28 6.9.29 6.9.3 6.9.30 6.9.31 6.9.32 6.9.33 6.9.34 6.9.35 6.9.36 6.9.37 6.9.38 6.9.39 6.9.4 6.9.41 6.9.42 6.9.43 6.9.44 6.9.45 6.9.46 6.9.47 6.9.48 6.9.49 6.9.5 6.9.51 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.0-alpha.6 7.0.0-alpha.7 7.0.0-beta.1 7.0.0-rc1 7.0.0-rc2 7.0.0-rc3 7.0.1 7.0.10 7.0.11 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6 7.0.7 7.0.8 7.0.9 7.1.0 7.1.1 trunk 3.0 4.0 4.0.1 4.1 4.2 4.3 4.4 4.4.1 4.5 4.6 4.6.1 4.6.2 4.7 4.7.1 4.7.2 4.7.5 4.7.6 4.8 4.8.1 4.9 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.5.1 4.9.5.2 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1 5.1.1 5.10 5.11 5.2 5.2.1 5.2.5 5.2.6 5.2.7 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.4 5.4.1 5.4.2 5.4.3 5.4.3.1 5.4.3.2 5.5 5.5.1 5.5.2 5.6 5.6.1 5.6.1.1 5.7 5.7.1 5.7.2 5.7.3 5.8 5.8.1 5.8.2 5.8.3 5.9 5.9.1 5.9.1.1 5.9.2 5.9.2.1 5.9.3 5.9.4 5.9.5 5.9.6 5.9.6.1 5.9.6.2 5.9.6.3 5.9.7 5.9.7.1 5.9.7.2 5.9.7.3 5.9.8 5.9.8.1 5.9.9 5.9.9.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.2.0 6.2.1 6.2.2 6.3.0 6.3.1 6.3.2 6.3.3 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.6.0 6.6.1 6.6.2 6.6.3 6.6.4 6.7.0 6.7.1 6.7.2 6.7.3 6.7.4 6.7.5 6.7.6 6.7.7 6.7.8 6.7.9 6.8.0 6.8.1 6.8.2 6.8.3
advanced-access-manager / Application / Backend / Feature / Post.php
advanced-access-manager / Application / Backend / Feature Last commit date
Abstract.php 9 years ago Capability.php 9 years ago Contact.php 9 years ago Extension.php 9 years ago LoginRedirect.php 9 years ago Menu.php 9 years ago Metabox.php 9 years ago Post.php 9 years ago Redirect.php 9 years ago Role.php 9 years ago Security.php 9 years ago Teaser.php 9 years ago User.php 9 years ago Utility.php 9 years ago
Post.php
397 lines
1 <?php
2
3 /**
4 * ======================================================================
5 * LICENSE: This file is subject to the terms and conditions defined in *
6 * file 'license.txt', which is part of this source code package. *
7 * ======================================================================
8 */
9
10 /**
11 * Backend posts & pages manager
12 *
13 * @package AAM
14 * @author Vasyl Martyniuk <vasyl@vasyltech.com>
15 */
16 class AAM_Backend_Feature_Post extends AAM_Backend_Feature_Abstract {
17
18 /**
19 * Get list for the table
20 *
21 * @return string
22 *
23 * @access public
24 */
25 public function getTable() {
26 $type = trim(AAM_Core_Request::request('type'));
27
28 if (empty($type)) {
29 $response = $this->retrieveTypeList();
30 } else {
31 $response = $this->retrieveTypeContent($type);
32 }
33
34 return $this->wrapTable($response);
35 }
36
37 /**
38 * Retrieve list of registered post types
39 *
40 * @return array
41 *
42 * @access protected
43 */
44 protected function retrieveTypeList() {
45 $list = $this->prepareTypeList();
46 $response = array(
47 'data' => array(),
48 'recordsTotal' => $list->total,
49 'recordsFiltered' => $list->filtered
50 );
51
52 foreach ($list->records as $type) {
53 $response['data'][] = array(
54 $type->name,
55 null,
56 'type',
57 $type->labels->name,
58 apply_filters('aam-type-row-actions-filter', 'drilldown,manage', $type)
59 );
60 }
61
62 return $response;
63 }
64
65 /**
66 *
67 * @return type
68 */
69 protected function prepareTypeList() {
70 $list = get_post_types(array(), 'objects');
71 $filtered = array();
72
73 //filters
74 $s = AAM_Core_Request::post('search.value');
75 $length = AAM_Core_Request::post('length');
76 $start = AAM_Core_Request::post('start');
77
78 foreach (get_post_types(array(), 'objects') as $type) {
79 if ($type->public
80 && (empty($s) || stripos($type->labels->name, $s) !== false)) {
81 $filtered[] = $type;
82 }
83 }
84
85 return (object) array(
86 'total' => count($list),
87 'filtered' => count($filtered),
88 'records' => array_slice($filtered, $start, $length)
89 );
90 }
91
92 /**
93 * Get post type children
94 *
95 * Retrieve list of all posts and terms that belong to specified post type
96 *
97 * @param string $type
98 *
99 * @return array
100 *
101 * @access protected
102 */
103 protected function retrieveTypeContent($type) {
104 $list = $this->prepareContentList($type);
105 $response = array(
106 'data' => array(),
107 'recordsTotal' => $list->total,
108 'recordsFiltered' => $list->filtered
109 );
110
111 foreach($list->records as $record) {
112 if (isset($record->ID)) { //this is post
113 $response['data'][] = array(
114 $record->ID,
115 get_edit_post_link($record->ID, 'link'),
116 'post',
117 $record->post_title,
118 apply_filters('aam-post-row-actions-filter', 'manage,edit', $record)
119 );
120 } else { //term
121 $response['data'][] = array(
122 $record->term_id . '|' . $record->taxonomy,
123 get_edit_term_link($record->term_id, $record->taxonomy),
124 'term',
125 $record->name,
126 apply_filters('aam-term-row-actions-filter', 'manage,edit', $record)
127 );
128 }
129 }
130
131
132 return $response;
133 }
134
135 /**
136 *
137 * @return type
138 */
139 protected function prepareContentList($type) {
140 $list = array();
141 $filtered = array();
142
143 //filters
144 $s = AAM_Core_Request::post('search.value');
145 $length = AAM_Core_Request::post('length');
146 $start = AAM_Core_Request::post('start');
147
148 //first retrieve all hierarchical terms that belong to Post Type
149 foreach (get_object_taxonomies($type, 'objects') as $tax) {
150 if (is_taxonomy_hierarchical($tax->name)) {
151 //get all terms that have no parent category
152 $list = array_merge($list, $this->retrieveTermList($tax->name));
153 }
154 }
155
156 //retrieve all posts
157 $list = array_merge(
158 $list,
159 get_posts(array(
160 'post_type' => $type, 'category' => 0,
161 'numberposts' => -1, 'post_status' => 'any'
162 ))
163 );
164
165 foreach($list as $row) {
166 if (!empty($s)) {
167 if (isset($row->term_id) && stripos($row->name, $s) !== false) {
168 $filtered[] = $row;
169 } elseif (isset($row->ID) && stripos($row->post_title, $s) !== false) {
170 $filtered[] = $row;
171 }
172 } else {
173 $filtered[] = $row;
174 }
175 }
176
177 return (object) array(
178 'total' => count($list),
179 'filtered' => count($filtered),
180 'records' => array_slice($filtered, $start, $length)
181 );
182 }
183
184 /**
185 * Retrieve term list
186 *
187 * @param string $taxonomy
188 *
189 * @return array
190 *
191 * @access protected
192 */
193 protected function retrieveTermList($taxonomy) {
194 $response = array();
195
196 foreach (get_terms($taxonomy, array('hide_empty' => false)) as $term) {
197 $term->taxonomy = $taxonomy;
198 $response[] = $term;
199 }
200
201 return $response;
202 }
203
204 /**
205 * Prepare response
206 *
207 * @param array $response
208 *
209 * @return string
210 *
211 * @access protected
212 */
213 protected function wrapTable($response) {
214 $response['draw'] = AAM_Core_Request::request('draw');
215
216 return json_encode($response);
217 }
218
219 /**
220 * Get Post or Term access
221 *
222 * @return string
223 *
224 * @access public
225 */
226 public function getAccess() {
227 $type = trim(AAM_Core_Request::post('type'));
228 $id = AAM_Core_Request::post('id');
229
230 $object = AAM_Backend_View::getSubject()->getObject($type, $id);
231
232 //prepare the response object
233 if ($object instanceof AAM_Core_Object) {
234 $access = $object->getOption();
235 $metadata = array('overwritten' => $object->isOverwritten());
236 } else {
237 $access = $metadata = array();
238 }
239
240 return json_encode(array('access' => $access, 'meta' => $metadata));
241 }
242
243 /**
244 * Save post properties
245 *
246 * @return string
247 *
248 * @access public
249 */
250 public function save() {
251 if ($this->checkLimit()) {
252 $subject = AAM_Backend_View::getSubject();
253
254 $object = trim(AAM_Core_Request::post('object'));
255 $id = AAM_Core_Request::post('objectId', null);
256
257 $param = AAM_Core_Request::post('param');
258 $value = AAM_Core_Request::post('value');
259
260 //clear cache
261 AAM_Core_Cache::clear();
262
263 $result = $subject->save($param, $value, $object, $id);
264 } else {
265 $result = false;
266 $error = __('You reached your limitation.', AAM_KEY);
267 }
268
269 return json_encode(array(
270 'status' => ($result ? 'success' : 'failure'),
271 'error' => (empty($error) ? '' : $error)
272 ));
273 }
274
275 /**
276 * Reset the object settings
277 *
278 * @return string
279 *
280 * @access public
281 */
282 public function reset() {
283 $type = trim(AAM_Core_Request::post('type'));
284 $id = AAM_Core_Request::post('id', 0);
285
286 $object = AAM_Backend_View::getSubject()->getObject($type, $id);
287 if ($object instanceof AAM_Core_Object) {
288 $result = $object->reset();
289 //clear cache
290 AAM_Core_Cache::clear();
291 } else {
292 $result = false;
293 }
294
295 return json_encode(array('status' => ($result ? 'success' : 'failure')));
296 }
297
298 /**
299 *
300 * @global type $wpdb
301 * @return type
302 */
303 public static function checkLimit() {
304 global $wpdb;
305
306 $limit = apply_filters('aam-post-limit', 0);
307
308 if ($limit != -1) {
309 //count number of posts that have access saved
310 $query = "SELECT COUNT(*) as `total` FROM {$wpdb->postmeta} "
311 . "WHERE meta_key LIKE %s";
312
313 $row = $wpdb->get_row($wpdb->prepare($query, 'aam_post_access_%'));
314 $limit = ($row->total < 10 ? -1 : 0);
315 }
316
317 return ($limit == -1);
318 }
319
320 /**
321 * @inheritdoc
322 */
323 public static function getAccessOption() {
324 return 'feature.post.capability';
325 }
326
327 /**
328 * @inheritdoc
329 */
330 public static function getTemplate() {
331 return 'object/post.phtml';
332 }
333
334 /**
335 *
336 * @staticvar type $list
337 * @param type $area
338 * @return type
339 */
340 public function getAccessOptionList($area) {
341 static $list = null;
342
343 if (is_null($list)) {
344 $list = require_once dirname(__FILE__) . '/../View/PostOptionList.php';
345 }
346
347 return apply_filters('aam-post-access-options-filter', $list[$area], $area);
348 }
349
350 /**
351 *
352 * @return type
353 */
354 public function getCurrentObject() {
355 $object = (object) array(
356 'id' => urldecode(AAM_Core_Request::post('oid')),
357 'type' => AAM_Core_Request::post('otype')
358 );
359
360 if ($object->id) {
361 if (strpos($object->id, '|') !== false) { //term
362 $part = explode('|', $object->id);
363 $object->term = get_term($part[0], $part[1]);
364 } else {
365 $object->post = get_post($object->id);
366 }
367 }
368
369 return $object;
370 }
371
372 /**
373 * Register Posts & Pages feature
374 *
375 * @return void
376 *
377 * @access public
378 */
379 public static function register() {
380 $cap = AAM_Core_Config::get(self::getAccessOption(), 'administrator');
381
382 AAM_Backend_Feature::registerFeature((object) array(
383 'uid' => 'post',
384 'position' => 20,
385 'title' => __('Posts & Pages', AAM_KEY),
386 'capability' => $cap,
387 'subjects' => array(
388 'AAM_Core_Subject_Role',
389 'AAM_Core_Subject_User',
390 'AAM_Core_Subject_Visitor',
391 'AAM_Core_Subject_Default'
392 ),
393 'view' => __CLASS__
394 ));
395 }
396
397 }