PluginProbe
User Access Manager / 2.2.6
User Access Manager v2.2.6
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.2.6, at src/Controller/Backend/PostObjectController.php

195 lines 5.6 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
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Controller\Backend;
19
20 use UserAccessManager\Object\ObjectHandler;
21 use UserAccessManager\UserGroup\UserGroupTypeException;
22 use WP_Post;
23
24 /**
25 * Class PostObjectController
26 *
27 * @package UserAccessManager\Controller\Backend
28 */
29 class PostObjectController extends ObjectController
30 {
31 /**
32 * The function for the manage_posts_columns and
33 * the manage_pages_columns filter.
34 * @param array $defaults The table headers.
35 * @return array
36 */
37 public function addPostColumnsHeader(array $defaults): array
38 {
39 $defaults[self::COLUMN_NAME] = TXT_UAM_COLUMN_ACCESS;
40 return $defaults;
41 }
42
43 /**
44 * The function for the manage_users_custom_column action.
45 * @param string $columnName The column name.
46 * @param int|string $id The id.
47 * @throws UserGroupTypeException
48 */
49 public function addPostColumn(string $columnName, $id)
50 {
51 if ($columnName === self::COLUMN_NAME) {
52 $post = $this->objectHandler->getPost($id);
53 echo $this->getGroupColumn($post->post_type, $post->ID);
54 }
55 }
56
57 /**
58 * The function for the uam_post_access meta box.
59 * @param mixed $post The post.
60 * @throws UserGroupTypeException
61 */
62 public function editPostContent($post)
63 {
64 if ($post instanceof WP_Post) {
65 $this->setObjectInformation($post->post_type, $post->ID);
66 }
67
68 echo $this->getIncludeContents('PostEditForm.php');
69 }
70
71 /**
72 * Adds the bulk edit form.
73 * @param $columnName
74 */
75 public function addBulkAction($columnName)
76 {
77 if ($columnName === self::COLUMN_NAME) {
78 echo $this->getIncludeContents('BulkEditForm.php');
79 }
80 }
81
82 /**
83 * The function for the save_post action.
84 * @param mixed $postParam The post id or a array of a post.
85 * @throws UserGroupTypeException
86 */
87 public function savePostData($postParam)
88 {
89 $postId = (is_array($postParam) === true) ? $postParam['ID'] : $postParam;
90 $post = $this->objectHandler->getPost($postId);
91 $postType = $post->post_type;
92 $postId = $post->ID;
93
94 if ($postType === 'revision') {
95 $postId = $post->post_parent;
96 $parentPost = $this->objectHandler->getPost($postId);
97 $postType = $parentPost->post_type;
98 }
99
100 $this->saveObjectData($postType, $postId);
101 }
102
103 /**
104 * The function for the add_attachment action.
105 * @param int $postId
106 * @throws UserGroupTypeException
107 */
108 public function addAttachment(int $postId)
109 {
110 $post = $this->objectHandler->getPost($postId);
111 $postType = $post->post_type;
112 $postId = $post->ID;
113 $defaultGroups = [];
114
115 foreach ($this->userGroupHandler->getFullUserGroups() as $userGroup) {
116 if ($userGroup->isDefaultGroupForObjectType($postType) === true) {
117 $defaultGroups[$userGroup->getId()] = ['id' => $userGroup->getId()];
118 }
119 }
120
121 $this->saveObjectData($postType, $postId, $defaultGroups, true);
122 }
123
124 /**
125 * The function for the attachment_fields_to_save filter.
126 * We have to use this because the attachment actions work
127 * not in the way we need.
128 * @param array $attachment The attachment id.
129 * @return array
130 * @throws UserGroupTypeException
131 */
132 public function saveAttachmentData(array $attachment): array
133 {
134 $this->savePostData($attachment['ID']);
135
136 return $attachment;
137 }
138
139 /**
140 * The function for the wp_ajax_save_attachment_compat filter.
141 * @throws UserGroupTypeException
142 */
143 public function saveAjaxAttachmentData()
144 {
145 $attachmentId = $this->getRequestParameter('id');
146 $userGroups = $this->getRequestParameter(self::DEFAULT_GROUPS_FORM_NAME);
147
148 $this->saveObjectData(
149 ObjectHandler::GENERAL_POST_OBJECT_TYPE,
150 $attachmentId,
151 $userGroups
152 );
153 }
154
155 /**
156 * The function for the delete_post action.
157 * @param int|string $postId The post id.
158 */
159 public function removePostData($postId)
160 {
161 $post = $this->objectHandler->getPost($postId);
162 $this->removeObjectData($post->post_type, $postId);
163 }
164
165 /**
166 * The function for the media_meta action.
167 * @param array $formFields The meta.
168 * @param WP_Post $post The post.
169 * @return array
170 * @throws UserGroupTypeException
171 */
172 public function showMediaFile(array $formFields, $post = null): array
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