| 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 attachment_fields_to_save filter. |
| 103 |
* We have to use this because the attachment actions work |
| 104 |
* not in the way we need. |
| 105 |
* |
| 106 |
* @param array $attachment The attachment id. |
| 107 |
* |
| 108 |
* @return array |
| 109 |
*/ |
| 110 |
public function saveAttachmentData($attachment) |
| 111 |
{ |
| 112 |
$this->savePostData($attachment['ID']); |
| 113 |
|
| 114 |
return $attachment; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* The function for the wp_ajax_save_attachment_compat filter. |
| 119 |
*/ |
| 120 |
public function saveAjaxAttachmentData() |
| 121 |
{ |
| 122 |
$attachmentId = $this->getRequestParameter('id'); |
| 123 |
$userGroups = $this->getRequestParameter(self::DEFAULT_GROUPS_FORM_NAME); |
| 124 |
|
| 125 |
$this->saveObjectData( |
| 126 |
ObjectHandler::GENERAL_POST_OBJECT_TYPE, |
| 127 |
$attachmentId, |
| 128 |
$userGroups |
| 129 |
); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* The function for the delete_post action. |
| 134 |
* |
| 135 |
* @param integer $postId The post id. |
| 136 |
*/ |
| 137 |
public function removePostData($postId) |
| 138 |
{ |
| 139 |
$post = $this->objectHandler->getPost($postId); |
| 140 |
$this->removeObjectData($post->post_type, $postId); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* The function for the media_meta action. |
| 145 |
* |
| 146 |
* @param array $formFields The meta. |
| 147 |
* @param \WP_Post $post The post. |
| 148 |
* |
| 149 |
* @return array |
| 150 |
*/ |
| 151 |
public function showMediaFile(array $formFields, $post = null) |
| 152 |
{ |
| 153 |
$attachmentId = $this->getRequestParameter('attachment_id'); |
| 154 |
|
| 155 |
if ($attachmentId !== null) { |
| 156 |
$post = $this->objectHandler->getPost($attachmentId); |
| 157 |
} |
| 158 |
|
| 159 |
if ($post instanceof \WP_Post) { |
| 160 |
$this->setObjectInformation($post->post_type, $post->ID); |
| 161 |
} |
| 162 |
|
| 163 |
$formFields[self::DEFAULT_GROUPS_FORM_NAME] = [ |
| 164 |
'label' => TXT_UAM_SET_UP_USER_GROUPS, |
| 165 |
'input' => 'editFrom', |
| 166 |
'editFrom' => $this->getIncludeContents('MediaAjaxEditForm.php') |
| 167 |
]; |
| 168 |
|
| 169 |
return $formFields; |
| 170 |
} |
| 171 |
} |
| 172 |
|