Changeset 3730:5c45a5df9a59 for plugins/attachments
- Timestamp:
- 03/08/18 17:58:39 (7 years ago)
- Branch:
- default
- Location:
- plugins/attachments
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/attachments/_admin.php
r3167 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_CONTEXT_ADMIN')) { return;}12 if (!defined('DC_CONTEXT_ADMIN')) {return;} 13 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'));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 21 22 22 class attachmentAdmin 23 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,null,'attachment'); 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>'. 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; 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 $core = &$GLOBALS['core']; 47 $post_media = $core->media->getPostMedia($post->post_id, null, 'attachment'); 48 $nb_media = count($post_media); 49 $title = !$nb_media ? __('Attachments') : sprintf(__('Attachments (%d)'), $nb_media); 50 $item = '<h5 class="clear s-attachments">' . $title . '</h5>'; 51 foreach ($post_media as $f) { 52 $ftitle = $f->media_title; 53 if (strlen($ftitle) > 18) { 54 $ftitle = substr($ftitle, 0, 16) . '...'; 55 } 56 $item .= 57 '<div class="media-item s-attachments">' . 58 '<a class="media-icon" href="' . $core->adminurl->get('admin.media.item', array('id' => $f->media_id)) . '">' . 59 '<img src="' . $f->media_icon . '" alt="" title="' . $f->basename . '" /></a>' . 60 '<ul>' . 61 '<li><a class="media-link" href="' . $core->adminurl->get('admin.media.item', array('id' => $f->media_id)) . '" ' . 62 'title="' . $f->basename . '">' . $ftitle . '</a></li>' . 63 '<li>' . $f->media_dtstr . '</li>' . 64 '<li>' . files::size($f->size) . ' - ' . 65 '<a href="' . $f->file_url . '">' . __('open') . '</a>' . '</li>' . 68 66 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 74 'remove'=> '1'75 )).'">'.76 '<img src="images/trash.png" alt="'.__('remove').'" /></a>'.77 '</li>'.67 '<li class="media-action"><a class="attachment-remove" id="attachment-' . $f->media_id . '" ' . 68 'href="' . $core->adminurl->get('admin.post.media', array( 69 'post_id' => $post->post_id, 70 'media_id' => $f->media_id, 71 'link_type' => 'attachment', 72 'remove' => '1' 73 )) . '">' . 74 '<img src="images/trash.png" alt="' . __('remove') . '" /></a>' . 75 '</li>' . 78 76 79 '</ul>'.80 81 82 77 '</ul>' . 78 '</div>'; 79 } 80 unset($f); 83 81 84 85 $item .= '<p class="form-note s-attachments">'.__('No attachment.').'</p>';86 87 88 '<p class="s-attachments"><a class="button" href="'.$core->adminurl->get('admin.media',array('post_id' => $post->post_id, 'link_type' => 'attachment')).'">'.89 __('Add files to this entry').'</a></p>';90 $sidebar['metas-box']['items']['attachments']= $item;91 92 82 if (empty($post_media)) { 83 $item .= '<p class="form-note s-attachments">' . __('No attachment.') . '</p>'; 84 } 85 $item .= 86 '<p class="s-attachments"><a class="button" href="' . $core->adminurl->get('admin.media', array('post_id' => $post->post_id, 'link_type' => 'attachment')) . '">' . 87 __('Add files to this entry') . '</a></p>'; 88 $sidebar['metas-box']['items']['attachments'] = $item; 89 } 90 } 93 91 94 public static function adminPostAfterForm($post) { 95 if ($post !== null) 96 97 $core =&$GLOBALS['core'];98 99 '<form action="'.$core->adminurl->get('admin.post.media').'" id="attachment-remove-hide" method="post">'.100 '<div>'.form::hidden(array('post_id'),$post->post_id).101 form::hidden(array('media_id'),'').102 form::hidden(array('link_type'),'attachment').103 form::hidden(array('remove'),1).104 $core->formNonce().'</div></form>';105 106 92 public static function adminPostAfterForm($post) 93 { 94 if ($post !== null) { 95 $core = &$GLOBALS['core']; 96 echo 97 '<form action="' . $core->adminurl->get('admin.post.media') . '" id="attachment-remove-hide" method="post">' . 98 '<div>' . form::hidden(array('post_id'), $post->post_id) . 99 form::hidden(array('media_id'), '') . 100 form::hidden(array('link_type'), 'attachment') . 101 form::hidden(array('remove'), 1) . 102 $core->formNonce() . '</div></form>'; 103 } 104 } 107 105 } -
plugins/attachments/_define.php
r2566 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 $this->registerModule( 15 /* Name */ "attachments", 16 /* Description*/ "Manage post attachments", 17 /* Author */ "Dotclear Team", 18 /* Version */ '1.1', 19 20 'permissions' =>'usage,contentadmin,pages',21 'priority' =>999,22 'type' =>'plugin'23 15 "attachments", // Name 16 "Manage post attachments", // Description 17 "Dotclear Team", // Author 18 '1.1', // Version 19 array( 20 'permissions' => 'usage,contentadmin,pages', 21 'priority' => 999, 22 'type' => 'plugin' 23 ) 24 24 ); -
plugins/attachments/_public.php
r3167 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 # Attachments 15 $core->tpl->addBlock('Attachments',array('attachmentTpl','Attachments')); 16 $core->tpl->addBlock('AttachmentsHeader',array('attachmentTpl','AttachmentsHeader')); 17 $core->tpl->addBlock('AttachmentsFooter',array('attachmentTpl','AttachmentsFooter')); 18 $core->tpl->addValue('AttachmentMimeType',array('attachmentTpl','AttachmentMimeType')); 19 $core->tpl->addValue('AttachmentType',array('attachmentTpl','AttachmentType')); 20 $core->tpl->addValue('AttachmentFileName',array('attachmentTpl','AttachmentFileName')); 21 $core->tpl->addValue('AttachmentSize',array('attachmentTpl','AttachmentSize')); 22 $core->tpl->addValue('AttachmentTitle',array('attachmentTpl','AttachmentTitle')); 23 $core->tpl->addValue('AttachmentThumbnailURL',array('attachmentTpl','AttachmentThumbnailURL')); 24 $core->tpl->addValue('AttachmentURL',array('attachmentTpl','AttachmentURL')); 25 $core->tpl->addValue('MediaURL',array('attachmentTpl','MediaURL')); 26 $core->tpl->addBlock('AttachmentIf',array('attachmentTpl','AttachmentIf')); 27 28 $core->tpl->addValue('EntryAttachmentCount',array('attachmentTpl','EntryAttachmentCount')); 29 30 $core->addBehavior('tplIfConditions',array('attachmentBehavior','tplIfConditions')); 31 32 class attachmentTpl { 33 34 /*dtd 35 <!ELEMENT tpl:Attachments - - -- Post Attachments loop --> 36 */ 37 public static function Attachments($attr,$content) 38 { 39 $res = 40 "<?php\n". 41 'if ($_ctx->posts !== null && $core->media) {'."\n". 42 '$_ctx->attachments = new ArrayObject($core->media->getPostMedia($_ctx->posts->post_id,null,"attachment"));'."\n". 43 "?>\n". 44 45 '<?php foreach ($_ctx->attachments as $attach_i => $attach_f) : '. 46 '$GLOBALS[\'attach_i\'] = $attach_i; $GLOBALS[\'attach_f\'] = $attach_f;'. 47 '$_ctx->file_url = $attach_f->file_url; ?>'. 48 $content. 49 '<?php endforeach; $_ctx->attachments = null; unset($attach_i,$attach_f,$_ctx->file_url); ?>'. 50 51 "<?php } ?>\n"; 52 53 return $res; 54 } 55 56 /*dtd 57 <!ELEMENT tpl:AttachmentsHeader - - -- First attachments result container --> 58 */ 59 public static function AttachmentsHeader($attr,$content) 60 { 61 return 62 "<?php if (\$attach_i == 0) : ?>". 63 $content. 64 "<?php endif; ?>"; 65 } 66 67 /*dtd 68 <!ELEMENT tpl:AttachmentsFooter - - -- Last attachments result container --> 69 */ 70 public static function AttachmentsFooter($attr,$content) 71 { 72 return 73 "<?php if (\$attach_i+1 == count(\$_ctx->attachments)) : ?>". 74 $content. 75 "<?php endif; ?>"; 76 } 77 78 /*dtd 79 <!ELEMENT tpl:AttachmentsIf - - -- Test on attachment fields --> 80 <!ATTLIST tpl:AttachmentIf 81 is_image (0|1) #IMPLIED -- test if attachment is an image (value : 1) or not (value : 0) 82 has_thumb (0|1) #IMPLIED -- test if attachment has a square thumnail (value : 1) or not (value : 0) 83 is_mp3 (0|1) #IMPLIED -- test if attachment is a mp3 file (value : 1) or not (value : 0) 84 is_flv (0|1) #IMPLIED -- test if attachment is a flv file (value : 1) or not (value : 0) 85 is_audio (0|1) #IMPLIED -- test if attachment is an audio file (value : 1) or not (value : 0) 86 is_video (0|1) #IMPLIED -- test if attachment is a video file (value : 1) or not (value : 0) 87 > 88 */ 89 public static function AttachmentIf($attr,$content) 90 { 91 $if = array(); 92 93 $operator = isset($attr['operator']) ? dcTemplate::getOperator($attr['operator']) : '&&'; 94 95 if (isset($attr['is_image'])) { 96 $sign = (boolean) $attr['is_image'] ? '' : '!'; 97 $if[] = $sign.'$attach_f->media_image'; 98 } 99 100 if (isset($attr['has_thumb'])) { 101 $sign = (boolean) $attr['has_thumb'] ? '' : '!'; 102 $if[] = $sign.'isset($attach_f->media_thumb[\'sq\'])'; 103 } 104 105 if (isset($attr['is_mp3'])) { 106 $sign = (boolean) $attr['is_mp3'] ? '==' : '!='; 107 $if[] = '$attach_f->type '.$sign.' "audio/mpeg3"'; 108 } 109 110 if (isset($attr['is_flv'])) { 111 $sign = (boolean) $attr['is_flv'] ? '==' : '!='; 112 $if[] = '$attach_f->type '.$sign.' "video/x-flv"'; 113 } 114 115 if (isset($attr['is_audio'])) { 116 $sign = (boolean) $attr['is_audio'] ? '==' : '!='; 117 $if[] = '$attach_f->type_prefix '.$sign.' "audio"'; 118 } 119 120 if (isset($attr['is_video'])) { 121 $sign = (boolean) $attr['is_video'] ? '==' : '!='; 122 $if[] = '$attach_f->type_prefix '.$sign.' "video"'; 123 } 124 125 if (count($if) != 0) { 126 return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>'; 127 } else { 128 return $content; 129 } 130 } 131 132 /*dtd 133 <!ELEMENT tpl:AttachmentMimeType - O -- Attachment MIME Type --> 134 */ 135 public static function AttachmentMimeType($attr) 136 { 137 $f = $GLOBALS['core']->tpl->getFilters($attr); 138 return '<?php echo '.sprintf($f,'$attach_f->type').'; ?>'; 139 } 140 141 /*dtd 142 <!ELEMENT tpl:AttachmentType - O -- Attachment type --> 143 */ 144 public static function AttachmentType($attr) 145 { 146 $f = $GLOBALS['core']->tpl->getFilters($attr); 147 return '<?php echo '.sprintf($f,'$attach_f->media_type').'; ?>'; 148 } 149 150 /*dtd 151 <!ELEMENT tpl:AttachmentFileName - O -- Attachment file name --> 152 */ 153 public static function AttachmentFileName($attr) 154 { 155 $f = $GLOBALS['core']->tpl->getFilters($attr); 156 return '<?php echo '.sprintf($f,'$attach_f->basename').'; ?>'; 157 } 158 159 /*dtd 160 <!ELEMENT tpl:AttachmentSize - O -- Attachment size --> 161 <!ATTLIST tpl:AttachmentSize 162 full CDATA #IMPLIED -- if set, size is rounded to a human-readable value (in KB, MB, GB, TB) 163 > 164 */ 165 public static function AttachmentSize($attr) 166 { 167 $f = $GLOBALS['core']->tpl->getFilters($attr); 168 if (!empty($attr['full'])) { 169 return '<?php echo '.sprintf($f,'$attach_f->size').'; ?>'; 170 } 171 return '<?php echo '.sprintf($f,'files::size($attach_f->size)').'; ?>'; 172 } 173 174 /*dtd 175 <!ELEMENT tpl:AttachmentTitle - O -- Attachment title --> 176 */ 177 public static function AttachmentTitle($attr) 178 { 179 $f = $GLOBALS['core']->tpl->getFilters($attr); 180 return '<?php echo '.sprintf($f,'$attach_f->media_title').'; ?>'; 181 } 182 183 /*dtd 184 <!ELEMENT tpl:AttachmentThumbnailURL - O -- Attachment square thumbnail URL --> 185 */ 186 public static function AttachmentThumbnailURL($attr) 187 { 188 $f = $GLOBALS['core']->tpl->getFilters($attr); 189 return 190 '<?php '. 191 'if (isset($attach_f->media_thumb[\'sq\'])) {'. 192 'echo '.sprintf($f,'$attach_f->media_thumb[\'sq\']').';'. 193 '}'. 194 '?>'; 195 } 196 197 /*dtd 198 <!ELEMENT tpl:AttachmentURL - O -- Attachment URL --> 199 */ 200 public static function AttachmentURL($attr) 201 { 202 $f = $GLOBALS['core']->tpl->getFilters($attr); 203 return '<?php echo '.sprintf($f,'$attach_f->file_url').'; ?>'; 204 } 205 206 public static function MediaURL($attr) 207 { 208 $f = $GLOBALS['core']->tpl->getFilters($attr); 209 return '<?php echo '.sprintf($f,'$_ctx->file_url').'; ?>'; 210 } 211 212 /*dtd 213 <!ELEMENT tpl:EntryAttachmentCount - O -- Number of attachments for entry --> 214 <!ATTLIST tpl:EntryAttachmentCount 215 none CDATA #IMPLIED -- text to display for "no attachments" (default: no attachments) 216 one CDATA #IMPLIED -- text to display for "one attachment" (default: one attachment) 217 more CDATA #IMPLIED -- text to display for "more attachment" (default: %s attachment, %s is replaced by the number of attachments) 218 > 219 */ 220 public static function EntryAttachmentCount($attr) 221 { 222 global $core; 223 return $core->tpl->displayCounter( 224 '$_ctx->posts->countMedia(\'attachment\')', 225 array( 226 'none' => 'no attachments', 227 'one' => 'one attachment', 228 'more' => '%d attachments' 229 ), 230 $attr, 231 false 232 ); 233 } 15 $core->tpl->addBlock('Attachments', array('attachmentTpl', 'Attachments')); 16 $core->tpl->addBlock('AttachmentsHeader', array('attachmentTpl', 'AttachmentsHeader')); 17 $core->tpl->addBlock('AttachmentsFooter', array('attachmentTpl', 'AttachmentsFooter')); 18 $core->tpl->addValue('AttachmentMimeType', array('attachmentTpl', 'AttachmentMimeType')); 19 $core->tpl->addValue('AttachmentType', array('attachmentTpl', 'AttachmentType')); 20 $core->tpl->addValue('AttachmentFileName', array('attachmentTpl', 'AttachmentFileName')); 21 $core->tpl->addValue('AttachmentSize', array('attachmentTpl', 'AttachmentSize')); 22 $core->tpl->addValue('AttachmentTitle', array('attachmentTpl', 'AttachmentTitle')); 23 $core->tpl->addValue('AttachmentThumbnailURL', array('attachmentTpl', 'AttachmentThumbnailURL')); 24 $core->tpl->addValue('AttachmentURL', array('attachmentTpl', 'AttachmentURL')); 25 $core->tpl->addValue('MediaURL', array('attachmentTpl', 'MediaURL')); 26 $core->tpl->addBlock('AttachmentIf', array('attachmentTpl', 'AttachmentIf')); 27 28 $core->tpl->addValue('EntryAttachmentCount', array('attachmentTpl', 'EntryAttachmentCount')); 29 30 $core->addBehavior('tplIfConditions', array('attachmentBehavior', 'tplIfConditions')); 31 32 class attachmentTpl 33 { 34 35 /*dtd 36 <!ELEMENT tpl:Attachments - - -- Post Attachments loop --> 37 */ 38 public static function Attachments($attr, $content) 39 { 40 $res = 41 "<?php\n" . 42 'if ($_ctx->posts !== null && $core->media) {' . "\n" . 43 '$_ctx->attachments = new ArrayObject($core->media->getPostMedia($_ctx->posts->post_id,null,"attachment"));' . "\n" . 44 "?>\n" . 45 46 '<?php foreach ($_ctx->attachments as $attach_i => $attach_f) : ' . 47 '$GLOBALS[\'attach_i\'] = $attach_i; $GLOBALS[\'attach_f\'] = $attach_f;' . 48 '$_ctx->file_url = $attach_f->file_url; ?>' . 49 $content . 50 '<?php endforeach; $_ctx->attachments = null; unset($attach_i,$attach_f,$_ctx->file_url); ?>' . 51 52 "<?php } ?>\n"; 53 54 return $res; 55 } 56 57 /*dtd 58 <!ELEMENT tpl:AttachmentsHeader - - -- First attachments result container --> 59 */ 60 public static function AttachmentsHeader($attr, $content) 61 { 62 return 63 "<?php if (\$attach_i == 0) : ?>" . 64 $content . 65 "<?php endif; ?>"; 66 } 67 68 /*dtd 69 <!ELEMENT tpl:AttachmentsFooter - - -- Last attachments result container --> 70 */ 71 public static function AttachmentsFooter($attr, $content) 72 { 73 return 74 "<?php if (\$attach_i+1 == count(\$_ctx->attachments)) : ?>" . 75 $content . 76 "<?php endif; ?>"; 77 } 78 79 /*dtd 80 <!ELEMENT tpl:AttachmentsIf - - -- Test on attachment fields --> 81 <!ATTLIST tpl:AttachmentIf 82 is_image (0|1) #IMPLIED -- test if attachment is an image (value : 1) or not (value : 0) 83 has_thumb (0|1) #IMPLIED -- test if attachment has a square thumnail (value : 1) or not (value : 0) 84 is_mp3 (0|1) #IMPLIED -- test if attachment is a mp3 file (value : 1) or not (value : 0) 85 is_flv (0|1) #IMPLIED -- test if attachment is a flv file (value : 1) or not (value : 0) 86 is_audio (0|1) #IMPLIED -- test if attachment is an audio file (value : 1) or not (value : 0) 87 is_video (0|1) #IMPLIED -- test if attachment is a video file (value : 1) or not (value : 0) 88 > 89 */ 90 public static function AttachmentIf($attr, $content) 91 { 92 $if = array(); 93 94 $operator = isset($attr['operator']) ? dcTemplate::getOperator($attr['operator']) : '&&'; 95 96 if (isset($attr['is_image'])) { 97 $sign = (boolean) $attr['is_image'] ? '' : '!'; 98 $if[] = $sign . '$attach_f->media_image'; 99 } 100 101 if (isset($attr['has_thumb'])) { 102 $sign = (boolean) $attr['has_thumb'] ? '' : '!'; 103 $if[] = $sign . 'isset($attach_f->media_thumb[\'sq\'])'; 104 } 105 106 if (isset($attr['is_mp3'])) { 107 $sign = (boolean) $attr['is_mp3'] ? '==' : '!='; 108 $if[] = '$attach_f->type ' . $sign . ' "audio/mpeg3"'; 109 } 110 111 if (isset($attr['is_flv'])) { 112 $sign = (boolean) $attr['is_flv'] ? '==' : '!='; 113 $if[] = '$attach_f->type ' . $sign . ' "video/x-flv"'; 114 } 115 116 if (isset($attr['is_audio'])) { 117 $sign = (boolean) $attr['is_audio'] ? '==' : '!='; 118 $if[] = '$attach_f->type_prefix ' . $sign . ' "audio"'; 119 } 120 121 if (isset($attr['is_video'])) { 122 $sign = (boolean) $attr['is_video'] ? '==' : '!='; 123 $if[] = '$attach_f->type_prefix ' . $sign . ' "video"'; 124 } 125 126 if (count($if) != 0) { 127 return '<?php if(' . implode(' ' . $operator . ' ', (array) $if) . ') : ?>' . $content . '<?php endif; ?>'; 128 } else { 129 return $content; 130 } 131 } 132 133 /*dtd 134 <!ELEMENT tpl:AttachmentMimeType - O -- Attachment MIME Type --> 135 */ 136 public static function AttachmentMimeType($attr) 137 { 138 $f = $GLOBALS['core']->tpl->getFilters($attr); 139 return '<?php echo ' . sprintf($f, '$attach_f->type') . '; ?>'; 140 } 141 142 /*dtd 143 <!ELEMENT tpl:AttachmentType - O -- Attachment type --> 144 */ 145 public static function AttachmentType($attr) 146 { 147 $f = $GLOBALS['core']->tpl->getFilters($attr); 148 return '<?php echo ' . sprintf($f, '$attach_f->media_type') . '; ?>'; 149 } 150 151 /*dtd 152 <!ELEMENT tpl:AttachmentFileName - O -- Attachment file name --> 153 */ 154 public static function AttachmentFileName($attr) 155 { 156 $f = $GLOBALS['core']->tpl->getFilters($attr); 157 return '<?php echo ' . sprintf($f, '$attach_f->basename') . '; ?>'; 158 } 159 160 /*dtd 161 <!ELEMENT tpl:AttachmentSize - O -- Attachment size --> 162 <!ATTLIST tpl:AttachmentSize 163 full CDATA #IMPLIED -- if set, size is rounded to a human-readable value (in KB, MB, GB, TB) 164 > 165 */ 166 public static function AttachmentSize($attr) 167 { 168 $f = $GLOBALS['core']->tpl->getFilters($attr); 169 if (!empty($attr['full'])) { 170 return '<?php echo ' . sprintf($f, '$attach_f->size') . '; ?>'; 171 } 172 return '<?php echo ' . sprintf($f, 'files::size($attach_f->size)') . '; ?>'; 173 } 174 175 /*dtd 176 <!ELEMENT tpl:AttachmentTitle - O -- Attachment title --> 177 */ 178 public static function AttachmentTitle($attr) 179 { 180 $f = $GLOBALS['core']->tpl->getFilters($attr); 181 return '<?php echo ' . sprintf($f, '$attach_f->media_title') . '; ?>'; 182 } 183 184 /*dtd 185 <!ELEMENT tpl:AttachmentThumbnailURL - O -- Attachment square thumbnail URL --> 186 */ 187 public static function AttachmentThumbnailURL($attr) 188 { 189 $f = $GLOBALS['core']->tpl->getFilters($attr); 190 return 191 '<?php ' . 192 'if (isset($attach_f->media_thumb[\'sq\'])) {' . 193 'echo ' . sprintf($f, '$attach_f->media_thumb[\'sq\']') . ';' . 194 '}' . 195 '?>'; 196 } 197 198 /*dtd 199 <!ELEMENT tpl:AttachmentURL - O -- Attachment URL --> 200 */ 201 public static function AttachmentURL($attr) 202 { 203 $f = $GLOBALS['core']->tpl->getFilters($attr); 204 return '<?php echo ' . sprintf($f, '$attach_f->file_url') . '; ?>'; 205 } 206 207 public static function MediaURL($attr) 208 { 209 $f = $GLOBALS['core']->tpl->getFilters($attr); 210 return '<?php echo ' . sprintf($f, '$_ctx->file_url') . '; ?>'; 211 } 212 213 /*dtd 214 <!ELEMENT tpl:EntryAttachmentCount - O -- Number of attachments for entry --> 215 <!ATTLIST tpl:EntryAttachmentCount 216 none CDATA #IMPLIED -- text to display for "no attachments" (default: no attachments) 217 one CDATA #IMPLIED -- text to display for "one attachment" (default: one attachment) 218 more CDATA #IMPLIED -- text to display for "more attachment" (default: %s attachment, %s is replaced by the number of attachments) 219 > 220 */ 221 public static function EntryAttachmentCount($attr) 222 { 223 global $core; 224 return $core->tpl->displayCounter( 225 '$_ctx->posts->countMedia(\'attachment\')', 226 array( 227 'none' => 'no attachments', 228 'one' => 'one attachment', 229 'more' => '%d attachments' 230 ), 231 $attr, 232 false 233 ); 234 } 234 235 } 235 236 236 237 class attachmentBehavior 237 238 { 238 public static function tplIfConditions($tag,$attr,$content,$if)239 240 241 242 $if[] = $sign.'$_ctx->posts->countMedia(\'attachment\')';243 244 239 public static function tplIfConditions($tag, $attr, $content, $if) 240 { 241 if ($tag == "EntryIf" && isset($attr['has_attachment'])) { 242 $sign = (boolean) $attr['has_attachment'] ? '' : '!'; 243 $if[] = $sign . '$_ctx->posts->countMedia(\'attachment\')'; 244 } 245 } 245 246 }
Note: See TracChangeset
for help on using the changeset viewer.