[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 | { |
---|
| 40 | return |
---|
| 41 | '<script type="text/javascript" src="index.php?pf=attachments/js/post.js"></script>'; |
---|
| 42 | } |
---|
[1398] | 43 | public static function adminPostFormItems($main,$sidebar,$post) |
---|
[407] | 44 | { |
---|
| 45 | if ($post !== null) |
---|
| 46 | { |
---|
| 47 | $core =& $GLOBALS['core']; |
---|
[1467] | 48 | $post_media = $core->media->getPostMedia($post->post_id); |
---|
[1501] | 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>'; |
---|
[1467] | 52 | foreach ($post_media as $f) |
---|
| 53 | { |
---|
| 54 | $ftitle = $f->media_title; |
---|
| 55 | if (strlen($ftitle) > 18) { |
---|
| 56 | $ftitle = substr($ftitle,0,16).'...'; |
---|
[407] | 57 | } |
---|
[1392] | 58 | $item .= |
---|
| 59 | '<div class="media-item s-attachments">'. |
---|
[1467] | 60 | '<a class="media-icon" href="media_item.php?id='.$f->media_id.'">'. |
---|
| 61 | '<img src="'.$f->media_icon.'" alt="" title="'.$f->basename.'" /></a>'. |
---|
| 62 | '<ul>'. |
---|
| 63 | '<li><a class="media-link" href="media_item.php?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="post_media.php?post_id='.$post->post_id.'&media_id='.$f->media_id.'&remove=1">'. |
---|
[2351] | 71 | '<img src="images/trash.png" alt="'.__('remove').'" /></a>'. |
---|
[1467] | 72 | '</li>'. |
---|
| 73 | |
---|
| 74 | '</ul>'. |
---|
| 75 | '</div>'; |
---|
[407] | 76 | } |
---|
[1467] | 77 | unset($f); |
---|
[407] | 78 | |
---|
| 79 | if (empty($post_media)) { |
---|
[1392] | 80 | $item .= '<p class="form-note s-attachments">'.__('No attachment.').'</p>'; |
---|
| 81 | } |
---|
| 82 | $item .= '<p class="s-attachments"><a class="button" href="media.php?post_id='.$post->post_id.'">'.__('Add files to this entry').'</a></p>'; |
---|
[1398] | 83 | $sidebar['metas-box']['items']['attachments']= $item; |
---|
[407] | 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
[416] | 87 | public static function adminPostAfterForm($post) { |
---|
[407] | 88 | if ($post !== null) |
---|
| 89 | { |
---|
| 90 | $core =& $GLOBALS['core']; |
---|
| 91 | echo |
---|
| 92 | '<form action="post_media.php" id="attachment-remove-hide" method="post">'. |
---|
| 93 | '<div>'.form::hidden(array('post_id'),$post->post_id). |
---|
| 94 | form::hidden(array('media_id'),''). |
---|
| 95 | form::hidden(array('remove'),1). |
---|
| 96 | $core->formNonce().'</div></form>'; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | } |
---|
[1620] | 100 | ?> |
---|