[407] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[407] | 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 | |
---|
[2359] | 14 | $core->addBehavior('adminPostFormItems',array('attachmentAdmin','adminPostFormItems')); |
---|
| 15 | $core->addBehavior('adminPostAfterForm',array('attachmentAdmin','adminPostAfterForm')); |
---|
[1392] | 16 | $core->addBehavior('adminPostHeaders',array('attachmentAdmin','postHeaders')); |
---|
[2359] | 17 | $core->addBehavior('adminPageFormItems',array('attachmentAdmin','adminPostFormItems')); |
---|
| 18 | $core->addBehavior('adminPageAfterForm',array('attachmentAdmin','adminPostAfterForm')); |
---|
[1617] | 19 | $core->addBehavior('adminPageHeaders',array('attachmentAdmin','postHeaders')); |
---|
[2359] | 20 | $core->addBehavior('adminPageHelpBlock',array('attachmentAdmin','adminPageHelpBlock')); |
---|
[407] | 21 | |
---|
| 22 | class attachmentAdmin |
---|
| 23 | { |
---|
[2360] | 24 | public static function adminPageHelpBlock($blocks) |
---|
[2359] | 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 | } |
---|
[1392] | 38 | public static function postHeaders() |
---|
| 39 | { |
---|
[2823] | 40 | $core =& $GLOBALS['core']; |
---|
[2566] | 41 | return |
---|
[2849] | 42 | '<script type="text/javascript" src="'.dcPage::getPF('attachments/js/post.js').'"></script>'; |
---|
[1392] | 43 | } |
---|
[2566] | 44 | public static function adminPostFormItems($main,$sidebar,$post) |
---|
[407] | 45 | { |
---|
| 46 | if ($post !== null) |
---|
| 47 | { |
---|
| 48 | $core =& $GLOBALS['core']; |
---|
[1467] | 49 | $post_media = $core->media->getPostMedia($post->post_id); |
---|
[1501] | 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>'; |
---|
[1467] | 53 | foreach ($post_media as $f) |
---|
| 54 | { |
---|
| 55 | $ftitle = $f->media_title; |
---|
| 56 | if (strlen($ftitle) > 18) { |
---|
| 57 | $ftitle = substr($ftitle,0,16).'...'; |
---|
[407] | 58 | } |
---|
[1392] | 59 | $item .= |
---|
| 60 | '<div class="media-item s-attachments">'. |
---|
[2823] | 61 | '<a class="media-icon" href="'.$core->adminurl->get('admin.media.item',array('id' => $f->media_id)).'">'. |
---|
[1467] | 62 | '<img src="'.$f->media_icon.'" alt="" title="'.$f->basename.'" /></a>'. |
---|
| 63 | '<ul>'. |
---|
[2823] | 64 | '<li><a class="media-link" href="'.$core->adminurl->get('admin.media.item',array('id' => $f->media_id)).'" '. |
---|
[1467] | 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>'. |
---|
[2566] | 69 | |
---|
[1467] | 70 | '<li class="media-action"><a class="attachment-remove" id="attachment-'.$f->media_id.'" '. |
---|
[2823] | 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 | )).'">'. |
---|
[2351] | 76 | '<img src="images/trash.png" alt="'.__('remove').'" /></a>'. |
---|
[1467] | 77 | '</li>'. |
---|
[2566] | 78 | |
---|
[1467] | 79 | '</ul>'. |
---|
| 80 | '</div>'; |
---|
[407] | 81 | } |
---|
[1467] | 82 | unset($f); |
---|
[2566] | 83 | |
---|
[407] | 84 | if (empty($post_media)) { |
---|
[1392] | 85 | $item .= '<p class="form-note s-attachments">'.__('No attachment.').'</p>'; |
---|
[2566] | 86 | } |
---|
[2823] | 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>'; |
---|
[1398] | 90 | $sidebar['metas-box']['items']['attachments']= $item; |
---|
[407] | 91 | } |
---|
| 92 | } |
---|
[2566] | 93 | |
---|
[416] | 94 | public static function adminPostAfterForm($post) { |
---|
[407] | 95 | if ($post !== null) |
---|
| 96 | { |
---|
| 97 | $core =& $GLOBALS['core']; |
---|
| 98 | echo |
---|
[2823] | 99 | '<form action="'.$core->adminurl->get('admin.post.media').'" id="attachment-remove-hide" method="post">'. |
---|
[407] | 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 | } |
---|