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