Dotclear

source: admin/post_media.php @ 3167:9b0e5988c0eb

Revision 3167:9b0e5988c0eb, 2.7 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Cope with sort of "un-attached" media → allows new features as "featured media" plugin. Video and Audio HTML5 element are now used (if possible) rather than Flash object for attachments.

RevLine 
[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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::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;
[3167]19$link_type = !empty($_REQUEST['link_type']) ? $_REQUEST['link_type'] : null;
[0]20
21if (!$post_id) {
22     exit;
23}
24$rs = $core->blog->getPosts(array('post_id' => $post_id,'post_type'=>''));
25if ($rs->isEmpty()) {
26     exit;
27}
28
[1537]29try {
[2320]30     if ($post_id && $media_id && !empty($_REQUEST['attach']))
[1537]31     {
32          $core->media = new dcMedia($core);
[3167]33          $core->media->addPostMedia($post_id,$media_id,$link_type);
[2320]34        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
35            header('Content-type: application/json');
36            echo json_encode(array('url' => $core->getPostAdminURL($rs->post_type,$post_id,false)));
37            exit();
38        } else {
39            http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false));
40        }
[1537]41     }
[0]42
43     $core->media = new dcMedia($core);
[3167]44     $f = $core->media->getPostMedia($post_id,$media_id,$link_type);
[0]45     if (empty($f)) {
46          $post_id = $media_id = null;
47          throw new Exception(__('This attachment does not exist'));
48     }
49     $f = $f[0];
50} catch (Exception $e) {
51     $core->error->add($e->getMessage());
52}
53
54# Remove a media from en
55if (($post_id && $media_id) || $core->error->flag())
56{
57     if (!empty($_POST['remove']))
58     {
[3167]59          $core->media->removePostMedia($post_id,$media_id,$link_type);
[2566]60
[2256]61          dcPage::addSuccessNotice(__('Attachment has been successfully removed.'));
62          http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false));
[0]63     }
64     elseif (isset($_POST['post_id'])) {
65          http::redirect($core->getPostAdminURL($rs->post_type,$post_id,false));
66     }
[2566]67
[0]68     if (!empty($_GET['remove']))
69     {
70          dcPage::open(__('Remove attachment'));
[2566]71
[500]72          echo '<h2>'.__('Attachment').' &rsaquo; <span class="page-title">'.__('confirm removal').'</span></h2>';
[2566]73
[0]74          echo
[2720]75          '<form action="'.$core->adminurl->get("admin.post.media").'" method="post">'.
[0]76          '<p>'.__('Are you sure you want to remove this attachment?').'</p>'.
[557]77          '<p><input type="submit" class="reset" value="'.__('Cancel').'" /> '.
78          ' &nbsp; <input type="submit" class="delete" name="remove" value="'.__('Yes').'" />'.
[0]79          form::hidden('post_id',$post_id).
80          form::hidden('media_id',$media_id).
81          $core->formNonce().'</p>'.
82          '</form>';
[2566]83
[0]84          dcPage::close();
85          exit;
86     }
87}
Note: See TracBrowser for help on using the repository browser.

Sites map