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

196 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 $this->getObjectInformation()->setObjectId(null);
79 echo $this->getIncludeContents('BulkEditForm.php');
80 }
81 }
82
83 /**
84 * The function for the save_post action.
85 * @param mixed $postParam The post id or a array of a post.
86 * @throws UserGroupTypeException
87 */
88 public function savePostData($postParam)
89 {
90 $postId = (is_array($postParam) === true) ? $postParam['ID'] : $postParam;
91 $post = $this->objectHandler->getPost($postId);
92 $postType = $post->post_type;
93 $postId = $post->ID;
94
95 if ($postType === 'revision') {
96 $postId = $post->post_parent;
97 $parentPost = $this->objectHandler->getPost($postId);
98 $postType = $parentPost->post_type;
99 }
100
101 $this->saveObjectData($postType, $postId);
102 }
103
104 /**
105 * The function for the add_attachment action.
106 * @param int $postId
107 * @throws UserGroupTypeException
108 */
109 public function addAttachment(int $postId)
110 {
111 $post = $this->objectHandler->getPost($postId);
112 $postType = $post->post_type;
113 $postId = $post->ID;
114 $defaultGroups = [];
115
116 foreach ($this->userGroupHandler->getFullUserGroups() as $userGroup) {
117 if ($userGroup->isDefaultGroupForObjectType($postType) === true) {
118 $defaultGroups[$userGroup->getId()] = ['id' => $userGroup->getId()];
119 }
120 }
121
122 $this->saveObjectData($postType, $postId, $defaultGroups, true);
123 }
124
125 /**
126 * The function for the attachment_fields_to_save filter.
127 * We have to use this because the attachment actions work
128 * not in the way we need.
129 * @param array $attachment The attachment id.
130 * @return array
131 * @throws UserGroupTypeException
132 */
133 public function saveAttachmentData(array $attachment): array
134 {
135 $this->savePostData($attachment['ID']);
136
137 return $attachment;
138 }
139
140 /**
141 * The function for the wp_ajax_save_attachment_compat filter.
142 * @throws UserGroupTypeException
143 */
144 public function saveAjaxAttachmentData()
145 {
146 $attachmentId = $this->getRequestParameter('id');
147 $userGroups = $this->getRequestParameter(self::DEFAULT_GROUPS_FORM_NAME);
148
149 $this->saveObjectData(
150 ObjectHandler::GENERAL_POST_OBJECT_TYPE,
151 $attachmentId,
152 $userGroups
153 );
154 }
155
156 /**
157 * The function for the delete_post action.
158 * @param int|string $postId The post id.
159 */
160 public function removePostData($postId)
161 {
162 $post = $this->objectHandler->getPost($postId);
163 $this->removeObjectData($post->post_type, $postId);
164 }
165
166 /**
167 * The function for the media_meta action.
168 * @param array $formFields The meta.
169 * @param WP_Post $post The post.
170 * @return array
171 * @throws UserGroupTypeException
172 */
173 public function showMediaFile(array $formFields, $post = null): array
174 {
175 if ($this->getRequestParameter('action') !== 'edit') {
176 $attachmentId = $this->getRequestParameter('attachment_id');
177
178 if ($attachmentId !== null) {
179 $post = $this->objectHandler->getPost($attachmentId);
180 }
181
182 if ($post instanceof WP_Post) {
183 $this->setObjectInformation($post->post_type, $post->ID);
184 }
185
186 $formFields[self::DEFAULT_GROUPS_FORM_NAME] = [
187 'label' => TXT_UAM_SET_UP_USER_GROUPS,
188 'input' => 'editFrom',
189 'editFrom' => $this->getIncludeContents('MediaAjaxEditForm.php')
190 ];
191 }
192
193 return $formFields;
194 }
195 }
196