PluginProbe
User Access Manager / 2.1.10
User Access Manager v2.1.10
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Controller / Backend / PostObjectController.php

PostObjectController.php in User Access Manager 2.1.10, at src/Controller/Backend/PostObjectController.php

195 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PostObjectController.php
4 *
5 * The PostObjectController class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15 namespace UserAccessManager\Controller\Backend;
16
17 use UserAccessManager\Object\ObjectHandler;
18
19 /**
20 * Class PostObjectController
21 *
22 * @package UserAccessManager\Controller\Backend
23 */
24 class PostObjectController extends ObjectController
25 {
26 /**
27 * The function for the manage_posts_columns and
28 * the manage_pages_columns filter.
29 *
30 * @param array $defaults The table headers.
31 *
32 * @return array
33 */
34 public function addPostColumnsHeader($defaults)
35 {
36 $defaults[self::COLUMN_NAME] = TXT_UAM_COLUMN_ACCESS;
37 return $defaults;
38 }
39
40 /**
41 * The function for the manage_users_custom_column action.
42 *
43 * @param string $columnName The column name.
44 * @param integer $id The id.
45 */
46 public function addPostColumn($columnName, $id)
47 {
48 if ($columnName === self::COLUMN_NAME) {
49 $post = $this->objectHandler->getPost($id);
50 echo $this->getGroupColumn($post->post_type, $post->ID);
51 }
52 }
53
54 /**
55 * The function for the uam_post_access meta box.
56 *
57 * @param object $post The post.
58 */
59 public function editPostContent($post)
60 {
61 if ($post instanceof \WP_Post) {
62 $this->setObjectInformation($post->post_type, $post->ID);
63 }
64
65 echo $this->getIncludeContents('PostEditForm.php');
66 }
67
68 /**
69 * Adds the bulk edit form.
70 *
71 * @param $columnName
72 */
73 public function addBulkAction($columnName)
74 {
75 if ($columnName === self::COLUMN_NAME) {
76 echo $this->getIncludeContents('BulkEditForm.php');
77 }
78 }
79
80 /**
81 * The function for the save_post action.
82 *
83 * @param mixed $postParam The post id or a array of a post.
84 */
85 public function savePostData($postParam)
86 {
87 $postId = (is_array($postParam) === true) ? $postParam['ID'] : $postParam;
88 $post = $this->objectHandler->getPost($postId);
89 $postType = $post->post_type;
90 $postId = $post->ID;
91
92 if ($postType === 'revision') {
93 $postId = $post->post_parent;
94 $parentPost = $this->objectHandler->getPost($postId);
95 $postType = $parentPost->post_type;
96 }
97
98 $this->saveObjectData($postType, $postId);
99 }
100
101 /**
102 * The function for the add_attachment action.
103 *
104 * @param int $postId
105 */
106 public function addAttachment($postId)
107 {
108 $post = $this->objectHandler->getPost($postId);
109 $postType = $post->post_type;
110 $postId = $post->ID;
111 $defaultGroups = [];
112
113 foreach ($this->userGroupHandler->getFullUserGroups() as $userGroup) {
114 if ($userGroup->isDefaultGroupForObjectType($postType) === true) {
115 $defaultGroups[$userGroup->getId()] = ['id' => $userGroup->getId()];
116 }
117 }
118
119 $this->saveObjectData($postType, $postId, $defaultGroups, true);
120 }
121
122 /**
123 * The function for the attachment_fields_to_save filter.
124 * We have to use this because the attachment actions work
125 * not in the way we need.
126 *
127 * @param array $attachment The attachment id.
128 *
129 * @return array
130 */
131 public function saveAttachmentData($attachment)
132 {
133 $this->savePostData($attachment['ID']);
134
135 return $attachment;
136 }
137
138 /**
139 * The function for the wp_ajax_save_attachment_compat filter.
140 */
141 public function saveAjaxAttachmentData()
142 {
143 $attachmentId = $this->getRequestParameter('id');
144 $userGroups = $this->getRequestParameter(self::DEFAULT_GROUPS_FORM_NAME);
145
146 $this->saveObjectData(
147 ObjectHandler::GENERAL_POST_OBJECT_TYPE,
148 $attachmentId,
149 $userGroups
150 );
151 }
152
153 /**
154 * The function for the delete_post action.
155 *
156 * @param integer $postId The post id.
157 */
158 public function removePostData($postId)
159 {
160 $post = $this->objectHandler->getPost($postId);
161 $this->removeObjectData($post->post_type, $postId);
162 }
163
164 /**
165 * The function for the media_meta action.
166 *
167 * @param array $formFields The meta.
168 * @param \WP_Post $post The post.
169 *
170 * @return array
171 */
172 public function showMediaFile(array $formFields, $post = null)
173 {
174 if ($this->getRequestParameter('action') !== 'edit') {
175 $attachmentId = $this->getRequestParameter('attachment_id');
176
177 if ($attachmentId !== null) {
178 $post = $this->objectHandler->getPost($attachmentId);
179 }
180
181 if ($post instanceof \WP_Post) {
182 $this->setObjectInformation($post->post_type, $post->ID);
183 }
184
185 $formFields[self::DEFAULT_GROUPS_FORM_NAME] = [
186 'label' => TXT_UAM_SET_UP_USER_GROUPS,
187 'input' => 'editFrom',
188 'editFrom' => $this->getIncludeContents('MediaAjaxEditForm.php')
189 ];
190 }
191
192 return $formFields;
193 }
194 }
195