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 ----------------------------------------- |
---|
12 | if (!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 | |
---|
22 | class 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 dcPage::jsLoad(dcPage::getPF('attachments/js/post.js')); |
---|
42 | } |
---|
43 | public static function adminPostFormItems($main,$sidebar,$post) |
---|
44 | { |
---|
45 | if ($post !== null) |
---|
46 | { |
---|
47 | $core =& $GLOBALS['core']; |
---|
48 | $post_media = $core->media->getPostMedia($post->post_id); |
---|
49 | $nb_media = count($post_media); |
---|
50 | $title = !$nb_media ? __('Attachments') : sprintf(__('Attachments (%d)'),$nb_media); |
---|
51 | $item = '<h5 class="clear s-attachments">'.$title.'</h5>'; |
---|
52 | foreach ($post_media as $f) |
---|
53 | { |
---|
54 | $ftitle = $f->media_title; |
---|
55 | if (strlen($ftitle) > 18) { |
---|
56 | $ftitle = substr($ftitle,0,16).'...'; |
---|
57 | } |
---|
58 | $item .= |
---|
59 | '<div class="media-item s-attachments">'. |
---|
60 | '<a class="media-icon" href="'.$core->adminurl->get('admin.media.item',array('id' => $f->media_id)).'">'. |
---|
61 | '<img src="'.$f->media_icon.'" alt="" title="'.$f->basename.'" /></a>'. |
---|
62 | '<ul>'. |
---|
63 | '<li><a class="media-link" href="'.$core->adminurl->get('admin.media.item',array('id' => $f->media_id)).'" '. |
---|
64 | 'title="'.$f->basename.'">'.$ftitle.'</a></li>'. |
---|
65 | '<li>'.$f->media_dtstr.'</li>'. |
---|
66 | '<li>'.files::size($f->size).' - '. |
---|
67 | '<a href="'.$f->file_url.'">'.__('open').'</a>'.'</li>'. |
---|
68 | |
---|
69 | '<li class="media-action"><a class="attachment-remove" id="attachment-'.$f->media_id.'" '. |
---|
70 | 'href="'.$core->adminurl->get('admin.post.media',array( |
---|
71 | 'post_id' => $post->post_id, |
---|
72 | 'media_id' => $f->media_id, |
---|
73 | 'remove' => '1' |
---|
74 | )).'">'. |
---|
75 | '<img src="images/trash.png" alt="'.__('remove').'" /></a>'. |
---|
76 | '</li>'. |
---|
77 | |
---|
78 | '</ul>'. |
---|
79 | '</div>'; |
---|
80 | } |
---|
81 | unset($f); |
---|
82 | |
---|
83 | if (empty($post_media)) { |
---|
84 | $item .= '<p class="form-note s-attachments">'.__('No attachment.').'</p>'; |
---|
85 | } |
---|
86 | $item .= |
---|
87 | '<p class="s-attachments"><a class="button" href="'.$core->adminurl->get('admin.media',array('post_id' => $post->post_id)).'">'. |
---|
88 | __('Add files to this entry').'</a></p>'; |
---|
89 | $sidebar['metas-box']['items']['attachments']= $item; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | public static function adminPostAfterForm($post) { |
---|
94 | if ($post !== null) |
---|
95 | { |
---|
96 | $core =& $GLOBALS['core']; |
---|
97 | echo |
---|
98 | '<form action="'.$core->adminurl->get('admin.post.media').'" id="attachment-remove-hide" method="post">'. |
---|
99 | '<div>'.form::hidden(array('post_id'),$post->post_id). |
---|
100 | form::hidden(array('media_id'),''). |
---|
101 | form::hidden(array('remove'),1). |
---|
102 | $core->formNonce().'</div></form>'; |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|