Dotclear

source: plugins/attachments/_admin.php @ 2849:97e1b334e54b

Revision 2849:97e1b334e54b, 3.6 KB checked in by Dsls, 11 years ago (diff)

Deprecated $core->adminurl->decode, use $core->adminurl->get instead (with urlencode set to false)

Added dcPage::getPF to shortcut plugin file inclusion

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
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 -----------------------------------------
12if (!defined('DC_CONTEXT_ADMIN')) { return; }
13
14$core->addBehavior('adminPostFormItems',array('attachmentAdmin','adminPostFormItems'));
15$core->addBehavior('adminPostAfterForm',array('attachmentAdmin','adminPostAfterForm'));
16$core->addBehavior('adminPostHeaders',array('attachmentAdmin','postHeaders'));
17$core->addBehavior('adminPageFormItems',array('attachmentAdmin','adminPostFormItems'));
18$core->addBehavior('adminPageAfterForm',array('attachmentAdmin','adminPostAfterForm'));
19$core->addBehavior('adminPageHeaders',array('attachmentAdmin','postHeaders'));
20$core->addBehavior('adminPageHelpBlock',array('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 null;
35          }
36          $blocks[] = 'attachments';
37     }
38     public static function postHeaders()
39     {
40          $core =& $GLOBALS['core'];
41          return
42          '<script type="text/javascript" src="'.dcPage::getPF('attachments/js/post.js').'"></script>';
43     }
44     public static function adminPostFormItems($main,$sidebar,$post)
45     {
46          if ($post !== null)
47          {
48               $core =& $GLOBALS['core'];
49               $post_media = $core->media->getPostMedia($post->post_id);
50               $nb_media = count($post_media);
51               $title = !$nb_media ? __('Attachments') : sprintf(__('Attachments (%d)'),$nb_media);
52               $item = '<h5 class="clear s-attachments">'.$title.'</h5>';
53               foreach ($post_media as $f)
54               {
55                    $ftitle = $f->media_title;
56                    if (strlen($ftitle) > 18) {
57                         $ftitle = substr($ftitle,0,16).'...';
58                    }
59                    $item .=
60                    '<div class="media-item s-attachments">'.
61                    '<a class="media-icon" href="'.$core->adminurl->get('admin.media.item',array('id' => $f->media_id)).'">'.
62                    '<img src="'.$f->media_icon.'" alt="" title="'.$f->basename.'" /></a>'.
63                    '<ul>'.
64                    '<li><a class="media-link" href="'.$core->adminurl->get('admin.media.item',array('id' => $f->media_id)).'" '.
65                    'title="'.$f->basename.'">'.$ftitle.'</a></li>'.
66                    '<li>'.$f->media_dtstr.'</li>'.
67                    '<li>'.files::size($f->size).' - '.
68                    '<a href="'.$f->file_url.'">'.__('open').'</a>'.'</li>'.
69
70                    '<li class="media-action"><a class="attachment-remove" id="attachment-'.$f->media_id.'" '.
71                    'href="'.$core->adminurl->get('admin.post.media',array(
72                         'post_id' => $post->post_id,
73                         'media_id' => $f->media_id,
74                         'remove' => '1'
75                         )).'">'.
76                    '<img src="images/trash.png" alt="'.__('remove').'" /></a>'.
77                    '</li>'.
78
79                    '</ul>'.
80                    '</div>';
81               }
82               unset($f);
83
84               if (empty($post_media)) {
85                    $item .= '<p class="form-note s-attachments">'.__('No attachment.').'</p>';
86               }
87               $item .=
88                    '<p class="s-attachments"><a class="button" href="'.$core->adminurl->get('admin.media',array('post_id' => $post->post_id)).'">'.
89                    __('Add files to this entry').'</a></p>';
90               $sidebar['metas-box']['items']['attachments']= $item;
91          }
92     }
93
94     public static function adminPostAfterForm($post) {
95          if ($post !== null)
96          {
97               $core =& $GLOBALS['core'];
98               echo
99                    '<form action="'.$core->adminurl->get('admin.post.media').'" id="attachment-remove-hide" method="post">'.
100                    '<div>'.form::hidden(array('post_id'),$post->post_id).
101                    form::hidden(array('media_id'),'').
102                    form::hidden(array('remove'),1).
103                    $core->formNonce().'</div></form>';
104          }
105     }
106}
Note: See TracBrowser for help on using the repository browser.

Sites map