Dotclear

source: admin/post_media.php @ 3730:5c45a5df9a59

Revision 3730:5c45a5df9a59, 2.9 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Code formatting (PSR-2)

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

Sites map