Dotclear

source: plugins/attachments/_admin.php @ 1501:6885aa3f7dc2

Revision 1501:6885aa3f7dc2, 2.8 KB checked in by Denis Jean-Christian <contact@…>, 12 years ago (diff)

Add count on title for attachments on entry sidebar, fixes #1560

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
18class attachmentAdmin
19{
20     public static function postHeaders()
21     {
22          return 
23          '<script type="text/javascript" src="index.php?pf=attachments/js/post.js"></script>';
24     }
25     public static function adminPostFormItems($main,$sidebar,$post) 
26     {
27          if ($post !== null)
28          {
29               $core =& $GLOBALS['core'];
30               $post_media = $core->media->getPostMedia($post->post_id);
31               $nb_media = count($post_media);
32               $title = !$nb_media ? __('Attachments') : sprintf(__('Attachments (%d)'),$nb_media);
33               $item = '<h5 class="clear s-attachments">'.$title.'</h5>';
34               foreach ($post_media as $f)
35               {
36                    $ftitle = $f->media_title;
37                    if (strlen($ftitle) > 18) {
38                         $ftitle = substr($ftitle,0,16).'...';
39                    }
40                    $item .=
41                    '<div class="media-item s-attachments">'.
42                    '<a class="media-icon" href="media_item.php?id='.$f->media_id.'">'.
43                    '<img src="'.$f->media_icon.'" alt="" title="'.$f->basename.'" /></a>'.
44                    '<ul>'.
45                    '<li><a class="media-link" href="media_item.php?id='.$f->media_id.'" '.
46                    'title="'.$f->basename.'">'.$ftitle.'</a></li>'.
47                    '<li>'.$f->media_dtstr.'</li>'.
48                    '<li>'.files::size($f->size).' - '.
49                    '<a href="'.$f->file_url.'">'.__('open').'</a>'.'</li>'.
50                   
51                    '<li class="media-action"><a class="attachment-remove" id="attachment-'.$f->media_id.'" '.
52                    'href="post_media.php?post_id='.$post->post_id.'&amp;media_id='.$f->media_id.'&amp;remove=1">'.
53                    '<img src="images/check-off.png" alt="'.__('remove').'" /></a>'.
54                    '</li>'.
55                   
56                    '</ul>'.
57                    '</div>';
58               }
59               unset($f);
60               
61               if (empty($post_media)) {
62                    $item .= '<p class="form-note s-attachments">'.__('No attachment.').'</p>';
63               } 
64               $item .= '<p class="s-attachments"><a class="button" href="media.php?post_id='.$post->post_id.'">'.__('Add files to this entry').'</a></p>';
65               $sidebar['metas-box']['items']['attachments']= $item;
66          }
67     }
68     
69     public static function adminPostAfterForm($post) {
70          if ($post !== null)
71          {
72               $core =& $GLOBALS['core'];
73               echo
74                    '<form action="post_media.php" id="attachment-remove-hide" method="post">'.
75                    '<div>'.form::hidden(array('post_id'),$post->post_id).
76                    form::hidden(array('media_id'),'').
77                    form::hidden(array('remove'),1).
78                    $core->formNonce().'</div></form>';
79          }
80     }
81}
82?>
Note: See TracBrowser for help on using the repository browser.

Sites map