Dotclear

source: admin/post_media.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 2.7 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Simplify licence block at the beginning of each file

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

Sites map