Changeset 516
- Timestamp:
- 10/13/08 01:12:27 (15 years ago)
- google:author:
- tbouron
- Location:
- plugins/publicMedia
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/publicMedia/_define.php
r515 r516 25 25 /* Name */ "Public Media", 26 26 /* Description*/ "Display media on a public page or in a widget", 27 /* Author */ "Moe (http://gniark.net/) and Osku ",28 /* Version */ '1. 0.1',27 /* Author */ "Moe (http://gniark.net/) and Osku and Tomtom (http://blog.zenstyle.fr)", 28 /* Version */ '1.1', 29 29 /* Permissions */ 'admin' 30 30 ); -
plugins/publicMedia/_prepend.php
r513 r516 26 26 $core->url->register('media','media', 27 27 '^media(/.+)?$',array('publicMediaPageDocument','page')); 28 $core->url->register('download','download', 29 '^download/([0-9]+)$',array('publicMediaPageDocument','wrapper')); 28 30 29 31 ?> -
plugins/publicMedia/_public.php
r513 r516 154 154 self::serveDocument('media.html','text/html'); 155 155 } 156 157 /** 158 serve downlaod headers 159 @param args <b>string</b> Argument 160 */ 161 public function wrapper($args) 162 { 163 global $core; 164 165 if (empty($args) || $core->blog->settings->publicmedia_page_active == '0') { 166 self::p404(); 167 } 168 169 $core->media = new dcMedia($core); 170 171 $core->media->chdir($core->blog->settings->publicmedia_page_root); 172 $core->media->getDir(); 173 174 $items = $core->media->dir['files']; 175 176 foreach ($items as $media_item) { 177 if ($media_item->media_id == $args) { 178 $file_id = $media_item->media_id; 179 $file_ext = $media_item->extension; 180 $file_mime = $media_item->type; 181 $file_name = $media_item->media_title; 182 $file = $media_item->file; 183 break; 184 } 185 } 186 unset($items); 187 188 if ($file && is_readable($file)) { 189 $count = unserialize($core->blog->settings->publicmedia_count_dl); 190 $count[$file_id] = array_key_exists($file_id,$count) ? $count[$file_id]+1 : 1; 191 $settings = new dcSettings($core,$core->blog->id); 192 $settings->setNamespace('system'); 193 $settings->put('publicmedia_count_dl',serialize($count),'string','Download counter'); 194 //$core->callBehavior('publicDownloadedFile',(integer)$args); 195 header('Content-type: '.$file_mime); 196 header('Content-Disposition: attachment; filename="'.$file_name.'"'); 197 readfile($file); 198 exit; 199 } 200 201 self::p404(); 202 } 156 203 } 157 204 … … 212 259 'itemMediaType')); 213 260 $core->tpl->addValue('MediaItemMTime',array('publicMediaPageTpl','itemMTime')); 261 $core->tpl->addValue('MediaItemDlCount',array('publicMediaPageTpl','itemDlCount')); 214 262 $core->tpl->addValue('MediaItemImageThumbPath',array('publicMediaPageTpl', 215 263 'itemImageThumbPath')); … … 519 567 $f = $GLOBALS['core']->tpl->getFilters($attr); 520 568 521 return('<?php echo '.sprintf($f,'$_ctx->media_item->file_url').'; ?>'); 569 $link = $GLOBALS['core']->blog->url.'download/'; 570 571 return($link.'<?php echo '.sprintf($f,'$_ctx->media_item->media_id').'; ?>'); 522 572 } 523 573 /** … … 577 627 578 628 return('<?php echo '.sprintf($f,'$_ctx->media_item->media_dtstr').'; ?>'); 629 } 630 631 /** 632 Item download counter 633 @param attr <b>array</b> Attribute 634 @return <b>string</b> PHP block 635 */ 636 public static function itemDlCount($attr) 637 { 638 $f = $GLOBALS['core']->tpl->getFilters($attr); 639 640 return 641 '<?php $count = unserialize($core->blog->settings->publicmedia_count_dl); '. 642 'echo '.sprintf($f,'array_key_exists($_ctx->media_item->media_id,$count) ? $count[$_ctx->media_item->media_id] : "0"'). 643 '; ?>'; 579 644 } 580 645 … … 641 706 642 707 foreach ($items as $media_item) { 643 $items_str .= sprintf($w->item,$ media_item->file_url,708 $items_str .= sprintf($w->item,$core->blog->url.'download/'.$media_item->media_id, 644 709 $media_item->media_title,$media_item->basename); 645 710 }
Note: See TracChangeset
for help on using the changeset viewer.