[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | |
---|
| 13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
| 14 | |
---|
| 15 | dcPage::check('usage,contentadmin'); |
---|
| 16 | |
---|
| 17 | $post_id = !empty($_REQUEST['post_id']) ? (integer) $_REQUEST['post_id'] : null; |
---|
| 18 | $media_id = !empty($_REQUEST['media_id']) ? (integer) $_REQUEST['media_id'] : null; |
---|
| 19 | |
---|
| 20 | if (!$post_id) { |
---|
| 21 | exit; |
---|
| 22 | } |
---|
| 23 | $rs = $core->blog->getPosts(array('post_id' => $post_id,'post_type'=>'')); |
---|
| 24 | if ($rs->isEmpty()) { |
---|
| 25 | exit; |
---|
| 26 | } |
---|
| 27 | |
---|
[1537] | 28 | try { |
---|
[2320] | 29 | if ($post_id && $media_id && !empty($_REQUEST['attach'])) |
---|
[1537] | 30 | { |
---|
| 31 | $core->media = new dcMedia($core); |
---|
| 32 | $core->media->addPostMedia($post_id,$media_id); |
---|
[2320] | 33 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { |
---|
| 34 | header('Content-type: application/json'); |
---|
| 35 | echo json_encode(array('url' => $core->getPostAdminURL($rs->post_type,$post_id,false))); |
---|
| 36 | exit(); |
---|
| 37 | } else { |
---|
| 38 | http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false)); |
---|
| 39 | } |
---|
[1537] | 40 | } |
---|
[0] | 41 | |
---|
| 42 | $core->media = new dcMedia($core); |
---|
| 43 | $f = $core->media->getPostMedia($post_id,$media_id); |
---|
| 44 | if (empty($f)) { |
---|
| 45 | $post_id = $media_id = null; |
---|
| 46 | throw new Exception(__('This attachment does not exist')); |
---|
| 47 | } |
---|
| 48 | $f = $f[0]; |
---|
| 49 | } catch (Exception $e) { |
---|
| 50 | $core->error->add($e->getMessage()); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | # Remove a media from en |
---|
| 54 | if (($post_id && $media_id) || $core->error->flag()) |
---|
| 55 | { |
---|
| 56 | if (!empty($_POST['remove'])) |
---|
| 57 | { |
---|
| 58 | $core->media->removePostMedia($post_id,$media_id); |
---|
[2566] | 59 | |
---|
[2256] | 60 | dcPage::addSuccessNotice(__('Attachment has been successfully removed.')); |
---|
| 61 | http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false)); |
---|
[0] | 62 | } |
---|
| 63 | elseif (isset($_POST['post_id'])) { |
---|
| 64 | http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false)); |
---|
| 65 | } |
---|
[2566] | 66 | |
---|
[0] | 67 | if (!empty($_GET['remove'])) |
---|
| 68 | { |
---|
| 69 | dcPage::open(__('Remove attachment')); |
---|
[2566] | 70 | |
---|
[500] | 71 | echo '<h2>'.__('Attachment').' › <span class="page-title">'.__('confirm removal').'</span></h2>'; |
---|
[2566] | 72 | |
---|
[0] | 73 | echo |
---|
[2720] | 74 | '<form action="'.$core->adminurl->get("admin.post.media").'" method="post">'. |
---|
[0] | 75 | '<p>'.__('Are you sure you want to remove this attachment?').'</p>'. |
---|
[557] | 76 | '<p><input type="submit" class="reset" value="'.__('Cancel').'" /> '. |
---|
| 77 | ' <input type="submit" class="delete" name="remove" value="'.__('Yes').'" />'. |
---|
[0] | 78 | form::hidden('post_id',$post_id). |
---|
| 79 | form::hidden('media_id',$media_id). |
---|
| 80 | $core->formNonce().'</p>'. |
---|
| 81 | '</form>'; |
---|
[2566] | 82 | |
---|
[0] | 83 | dcPage::close(); |
---|
| 84 | exit; |
---|
| 85 | } |
---|
| 86 | } |
---|