Dotclear

source: plugins/attachments/_admin.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 4.3 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

Line 
1<?php
2/**
3 * @brief attachments, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
11
12if (!defined('DC_CONTEXT_ADMIN')) {return;}
13
14$core->addBehavior('adminPostFormItems', ['attachmentAdmin', 'adminPostFormItems']);
15$core->addBehavior('adminPostAfterForm', ['attachmentAdmin', 'adminPostAfterForm']);
16$core->addBehavior('adminPostHeaders', ['attachmentAdmin', 'postHeaders']);
17$core->addBehavior('adminPageFormItems', ['attachmentAdmin', 'adminPostFormItems']);
18$core->addBehavior('adminPageAfterForm', ['attachmentAdmin', 'adminPostAfterForm']);
19$core->addBehavior('adminPageHeaders', ['attachmentAdmin', 'postHeaders']);
20$core->addBehavior('adminPageHelpBlock', ['attachmentAdmin', 'adminPageHelpBlock']);
21
22class attachmentAdmin
23{
24    public static function adminPageHelpBlock($blocks)
25    {
26        $found = false;
27        foreach ($blocks as $block) {
28            if ($block == 'core_post') {
29                $found = true;
30                break;
31            }
32        }
33        if (!$found) {
34            return;
35        }
36        $blocks[] = 'attachments';
37    }
38    public static function postHeaders()
39    {
40        $core = &$GLOBALS['core'];
41        return dcPage::jsLoad(dcPage::getPF('attachments/js/post.js'));
42    }
43    public static function adminPostFormItems($main, $sidebar, $post)
44    {
45        if ($post !== null) {
46            $core       = &$GLOBALS['core'];
47            $post_media = $core->media->getPostMedia($post->post_id, null, 'attachment');
48            $nb_media   = count($post_media);
49            $title      = !$nb_media ? __('Attachments') : sprintf(__('Attachments (%d)'), $nb_media);
50            $item       = '<h5 class="clear s-attachments">' . $title . '</h5>';
51            foreach ($post_media as $f) {
52                $ftitle = $f->media_title;
53                if (strlen($ftitle) > 18) {
54                    $ftitle = substr($ftitle, 0, 16) . '...';
55                }
56                $item .=
57                '<div class="media-item s-attachments">' .
58                '<a class="media-icon" href="' . $core->adminurl->get('admin.media.item', ['id' => $f->media_id]) . '">' .
59                '<img src="' . $f->media_icon . '" alt="" title="' . $f->basename . '" /></a>' .
60                '<ul>' .
61                '<li><a class="media-link" href="' . $core->adminurl->get('admin.media.item', ['id' => $f->media_id]) . '" ' .
62                'title="' . $f->basename . '">' . $ftitle . '</a></li>' .
63                '<li>' . $f->media_dtstr . '</li>' .
64                '<li>' . files::size($f->size) . ' - ' .
65                '<a href="' . $f->file_url . '">' . __('open') . '</a>' . '</li>' .
66
67                '<li class="media-action"><a class="attachment-remove" id="attachment-' . $f->media_id . '" ' .
68                'href="' . $core->adminurl->get('admin.post.media', [
69                    'post_id'   => $post->post_id,
70                    'media_id'  => $f->media_id,
71                    'link_type' => 'attachment',
72                    'remove'    => '1'
73                ]) . '">' .
74                '<img src="images/trash.png" alt="' . __('remove') . '" /></a>' .
75                    '</li>' .
76
77                    '</ul>' .
78                    '</div>';
79            }
80            unset($f);
81
82            if (empty($post_media)) {
83                $item .= '<p class="form-note s-attachments">' . __('No attachment.') . '</p>';
84            }
85            $item .=
86            '<p class="s-attachments"><a class="button" href="' . $core->adminurl->get('admin.media', ['post_id' => $post->post_id, 'link_type' => 'attachment']) . '">' .
87            __('Add files to this entry') . '</a></p>';
88            $sidebar['metas-box']['items']['attachments'] = $item;
89        }
90    }
91
92    public static function adminPostAfterForm($post)
93    {
94        if ($post !== null) {
95            $core = &$GLOBALS['core'];
96            echo
97            '<form action="' . $core->adminurl->get('admin.post.media') . '" id="attachment-remove-hide" method="post">' .
98            '<div>' . form::hidden(['post_id'], $post->post_id) .
99            form::hidden(['media_id'], '') .
100            form::hidden(['link_type'], 'attachment') .
101            form::hidden(['remove'], 1) .
102            $core->formNonce() . '</div></form>';
103        }
104    }
105}
Note: See TracBrowser for help on using the repository browser.

Sites map