[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 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 | |
---|
| 28 | if ($post_id && $media_id && !empty($_POST['attach'])) |
---|
| 29 | { |
---|
| 30 | $core->media = new dcMedia($core); |
---|
| 31 | $core->media->addPostMedia($post_id,$media_id); |
---|
| 32 | http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false)); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | try { |
---|
| 36 | $core->media = new dcMedia($core); |
---|
| 37 | $f = $core->media->getPostMedia($post_id,$media_id); |
---|
| 38 | if (empty($f)) { |
---|
| 39 | $post_id = $media_id = null; |
---|
| 40 | throw new Exception(__('This attachment does not exist')); |
---|
| 41 | } |
---|
| 42 | $f = $f[0]; |
---|
| 43 | } catch (Exception $e) { |
---|
| 44 | $core->error->add($e->getMessage()); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | # Remove a media from en |
---|
| 48 | if (($post_id && $media_id) || $core->error->flag()) |
---|
| 49 | { |
---|
| 50 | if (!empty($_POST['remove'])) |
---|
| 51 | { |
---|
| 52 | $core->media->removePostMedia($post_id,$media_id); |
---|
| 53 | http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false).'&rmattach=1'); |
---|
| 54 | } |
---|
| 55 | elseif (isset($_POST['post_id'])) { |
---|
| 56 | http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false)); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if (!empty($_GET['remove'])) |
---|
| 60 | { |
---|
| 61 | dcPage::open(__('Remove attachment')); |
---|
| 62 | |
---|
[500] | 63 | echo '<h2>'.__('Attachment').' › <span class="page-title">'.__('confirm removal').'</span></h2>'; |
---|
[0] | 64 | |
---|
| 65 | echo |
---|
| 66 | '<form action="post_media.php" method="post">'. |
---|
| 67 | '<p>'.__('Are you sure you want to remove this attachment?').'</p>'. |
---|
[70] | 68 | '<p><input type="submit" class="reset" value="'.__('cancel').'" /> '. |
---|
| 69 | ' <input type="submit" class="delete" name="remove" value="'.__('yes').'" />'. |
---|
[0] | 70 | form::hidden('post_id',$post_id). |
---|
| 71 | form::hidden('media_id',$media_id). |
---|
| 72 | $core->formNonce().'</p>'. |
---|
| 73 | '</form>'; |
---|
| 74 | |
---|
| 75 | dcPage::close(); |
---|
| 76 | exit; |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | ?> |
---|