Changeset 407:eb5bd0f66932
- Timestamp:
- 06/23/11 13:00:59 (14 years ago)
- Branch:
- default
- Files:
-
- 4 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/media.php
r270 r407 60 60 $post_id = !empty($_GET['post_id']) ? (integer) $_GET['post_id'] : null; 61 61 if ($post_id) { 62 $post = $core->blog->getPosts(array('post_id'=>$post_id ,'post_type'=>''));62 $post = $core->blog->getPosts(array('post_id'=>$post_id)); 63 63 if ($post->isEmpty()) { 64 64 $post_id = null; … … 68 68 unset($post); 69 69 } 70 71 70 $d = isset($_REQUEST['d']) ? $_REQUEST['d'] : null; 72 71 $dir = null; -
admin/post.php
r322 r407 32 32 $post_open_comment = $core->blog->settings->system->allow_comments; 33 33 $post_open_tb = $core->blog->settings->system->allow_trackbacks; 34 35 $post_media = array();36 34 37 35 $page_title = __('New entry'); … … 146 144 try { 147 145 $core->media = new dcMedia($core); 148 $post_media = $core->media->getPostMedia($post_id);149 146 } catch (Exception $e) {} 150 147 } … … 408 405 '</div>'; 409 406 410 if ($post_id)411 {412 echo413 '<h3 class="clear">'.__('Attachments').'</h3>';414 foreach ($post_media as $f)415 {416 $ftitle = $f->media_title;417 if (strlen($ftitle) > 18) {418 $ftitle = substr($ftitle,0,16).'...';419 }420 echo421 '<div class="media-item">'.422 '<a class="media-icon" href="media_item.php?id='.$f->media_id.'">'.423 '<img src="'.$f->media_icon.'" alt="" title="'.$f->basename.'" /></a>'.424 '<ul>'.425 '<li><a class="media-link" href="media_item.php?id='.$f->media_id.'"'.426 'title="'.$f->basename.'">'.$ftitle.'</a></li>'.427 '<li>'.$f->media_dtstr.'</li>'.428 '<li>'.files::size($f->size).' - '.429 '<a href="'.$f->file_url.'">'.__('open').'</a>'.'</li>'.430 431 '<li class="media-action"><a class="attachment-remove" id="attachment-'.$f->media_id.'" '.432 'href="post_media.php?post_id='.$post_id.'&media_id='.$f->media_id.'&remove=1">'.433 '<img src="images/check-off.png" alt="'.__('remove').'" /></a>'.434 '</li>'.435 436 '</ul>'.437 '</div>';438 }439 unset($f);440 441 if (empty($post_media)) {442 echo '<p>'.__('No attachment.').'</p>';443 }444 echo '<p><a class="button" href="media.php?post_id='.$post_id.'">'.__('Add files to this entry').'</a></p>';445 }446 447 407 # --BEHAVIOR-- adminPostFormSidebar 448 408 $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null); … … 491 451 } 492 452 493 if ($post_id && !empty($post_media))494 {495 echo496 '<form action="post_media.php" id="attachment-remove-hide" method="post">'.497 '<div>'.form::hidden(array('post_id'),$post_id).498 form::hidden(array('media_id'),'').499 form::hidden(array('remove'),1).500 $core->formNonce().'</div></form>';501 }502 453 } 503 454 -
inc/core/class.dc.blog.php
r340 r407 727 727 if (isset($params['post_type'])) 728 728 { 729 $strReq .= 'AND post_type '.$this->con->in($params['post_type']); 729 if (is_array($params['post_type']) || $params['post_type'] != '') { 730 $strReq .= 'AND post_type '.$this->con->in($params['post_type']); 731 } 730 732 } 731 733 else -
inc/core/class.dc.core.php
r331 r407 27 27 { 28 28 public $con; ///< <b>connection</b> Database connection object 29 public $prefix; ///< <b>string</b> Database tables prefix29 public $prefix; ///< <b>string</b> Database tables prefix 30 30 public $blog; ///< <b>dcBlog</b> dcBlog object 31 31 public $error; ///< <b>dcError</b> dcError object … … 36 36 public $plugins; ///< <b>dcModules</b> dcModules object 37 37 public $media; ///< <b>dcMedia</b> dcMedia object 38 public $rest; ///< <b>dcRestServer</b> dcRestServer object 38 public $postmedia; ///< <b>dcPostMedia</b> dcPostMedia object 39 public $rest; ///< <b>dcRestServer</b> dcRestServer object 39 40 public $log; ///< <b>dcLog</b> dcLog object 40 41 -
inc/core/class.dc.media.php
r270 r407 23 23 protected $con; ///< <b>connection</b> Database connection 24 24 protected $table; ///< <b>string</b> Media table name 25 protected $table_ref; ///< <b>string</b> Post-media relation table name26 25 protected $type; ///< <b>string</b> Media type filter 26 protected $postmedia; 27 27 protected $file_sort = 'name-asc'; 28 28 … … 57 57 $this->core =& $core; 58 58 $this->con =& $core->con; 59 $this->postmedia = new dcPostMedia($core); 59 60 60 61 if ($this->core->blog == null) { … … 63 64 64 65 $this->table = $this->core->prefix.'media'; 65 $this->table_ref = $this->core->prefix.'post_media';66 66 $root = $this->core->blog->public_path; 67 67 … … 494 494 public function getPostMedia($post_id,$media_id=null) 495 495 { 496 $post_id = (integer) $post_id; 497 498 $strReq = 499 'SELECT media_file, M.media_id, media_path, media_title, media_meta, media_dt, '. 500 'media_creadt, media_upddt, media_private, user_id '. 501 'FROM '.$this->table.' M '. 502 'INNER JOIN '.$this->table_ref.' PM ON (M.media_id = PM.media_id) '. 503 "WHERE media_path = '".$this->path."' ". 504 'AND post_id = '.$post_id.' '; 505 496 $params = array( 497 'post_id' => $post_id, 498 'media_path' => $this->path 499 ); 506 500 if ($media_id) { 507 $strReq .= 'AND M.media_id = '.(integer) $media_id.' '; 508 } 509 510 $rs = $this->con->select($strReq); 501 $params['media_id'] = (integer) $media_id; 502 } 503 $rs = $this->postmedia->getPostMedia($params); 511 504 512 505 $res = array(); … … 523 516 524 517 /** 525 Attaches a media to a post. 526 527 @param post_id <b>integer</b> Post ID 528 @param media_id <b>integer</b> Optionnal media ID 518 @deprecated since version 2.4 519 @see dcPostMedia::addPostMedia 529 520 */ 530 521 public function addPostMedia($post_id,$media_id) 531 522 { 532 $post_id = (integer) $post_id; 533 $media_id = (integer) $media_id; 534 535 $f = $this->getPostMedia($post_id,$media_id); 536 537 if (!empty($f)) { 538 return; 539 } 540 541 $cur = $this->con->openCursor($this->table_ref); 542 $cur->post_id = $post_id; 543 $cur->media_id = $media_id; 544 545 $cur->insert(); 546 $this->core->blog->triggerBlog(); 547 } 548 549 /** 550 Detaches a media from a post. 551 552 @param post_id <b>integer</b> Post ID 553 @param media_id <b>integer</b> Optionnal media ID 523 $this->postmedia->addPostMedia($post_id,$media_id); 524 } 525 526 /** 527 @deprecated since version 2.4 528 @see dcPostMedia::removePostMedia 554 529 */ 555 530 public function removePostMedia($post_id,$media_id) 556 531 { 557 $post_id = (integer) $post_id; 558 $media_id = (integer) $media_id; 559 560 $strReq = 'DELETE FROM '.$this->table_ref.' '. 561 'WHERE post_id = '.$post_id.' '. 562 'AND media_id = '.$media_id.' '; 563 564 $this->con->execute($strReq); 565 $this->core->blog->triggerBlog(); 532 $this->postmedia->removePostMedia($post_id,$media_id,"attachment"); 566 533 } 567 534 -
inc/dbschema/db-schema.php
r270 r407 152 152 ->media_id ('bigint', 0, false) 153 153 ->post_id ('bigint', 0, false) 154 155 ->primary('pk_post_media','media_id','post_id') 154 ->link_type ('varchar', 32, false, "'attachment'") 155 156 ->primary('pk_post_media','media_id','post_id','link_type') 156 157 ; 157 158 … … 235 236 $_s->media->index ('idx_media_user_id', 'btree', 'user_id'); 236 237 $_s->post_media->index ('idx_post_media_post_id', 'btree', 'post_id'); 238 $_s->post_media->index ('idx_post_media_media_id', 'btree', 'media_id'); 237 239 $_s->log->index ('idx_log_user_id', 'btree', 'user_id'); 238 240 $_s->comment->index ('idx_comment_post_id', 'btree', 'post_id'); -
inc/prepend.php
r372 r407 43 43 $__autoload['dcMeta'] = dirname(__FILE__).'/core/class.dc.meta.php'; 44 44 $__autoload['dcMedia'] = dirname(__FILE__).'/core/class.dc.media.php'; 45 $__autoload['dcPostMedia'] = dirname(__FILE__).'/core/class.dc.postmedia.php'; 45 46 $__autoload['dcModules'] = dirname(__FILE__).'/core/class.dc.modules.php'; 46 47 $__autoload['dcThemes'] = dirname(__FILE__).'/core/class.dc.themes.php'; -
inc/public/class.dc.template.php
r406 r407 54 54 $this->addValue('ArchiveEntriesCount',array($this,'ArchiveEntriesCount')); 55 55 $this->addValue('ArchiveURL',array($this,'ArchiveURL')); 56 57 # Attachments58 $this->addBlock('Attachments',array($this,'Attachments'));59 $this->addBlock('AttachmentsHeader',array($this,'AttachmentsHeader'));60 $this->addBlock('AttachmentsFooter',array($this,'AttachmentsFooter'));61 $this->addValue('AttachmentMimeType',array($this,'AttachmentMimeType'));62 $this->addValue('AttachmentType',array($this,'AttachmentType'));63 $this->addValue('AttachmentFileName',array($this,'AttachmentFileName'));64 $this->addValue('AttachmentSize',array($this,'AttachmentSize'));65 $this->addValue('AttachmentTitle',array($this,'AttachmentTitle'));66 $this->addValue('AttachmentThumbnailURL',array($this,'AttachmentThumbnailURL'));67 $this->addValue('AttachmentURL',array($this,'AttachmentURL'));68 $this->addBlock('AttachmentIf',array($this,'AttachmentIf'));69 $this->addValue('MediaURL',array($this,'MediaURL'));70 56 71 57 # Blog … … 141 127 $this->addBlock('EntriesHeader',array($this,'EntriesHeader')); 142 128 $this->addValue('EntryExcerpt',array($this,'EntryExcerpt')); 143 $this->addValue('EntryAttachmentCount',array($this,'EntryAttachmentCount'));144 129 $this->addValue('EntryAuthorCommonName',array($this,'EntryAuthorCommonName')); 145 130 $this->addValue('EntryAuthorDisplayName',array($this,'EntryAuthorDisplayName')); … … 749 734 } 750 735 751 /* Attachments ---------------------------------------- */752 /*dtd753 <!ELEMENT tpl:Attachments - - -- Post Attachments loop -->754 */755 public function Attachments($attr,$content)756 {757 $res =758 "<?php\n".759 'if ($_ctx->posts !== null && $core->media) {'."\n".760 '$_ctx->attachments = new ArrayObject($core->media->getPostMedia($_ctx->posts->post_id));'."\n".761 "?>\n".762 763 '<?php foreach ($_ctx->attachments as $attach_i => $attach_f) : '.764 '$GLOBALS[\'attach_i\'] = $attach_i; $GLOBALS[\'attach_f\'] = $attach_f;'.765 '$_ctx->file_url = $attach_f->file_url; ?>'.766 $content.767 '<?php endforeach; $_ctx->attachments = null; unset($attach_i,$attach_f,$_ctx->file_url); ?>'.768 769 "<?php } ?>\n";770 771 return $res;772 }773 774 /*dtd775 <!ELEMENT tpl:AttachmentsHeader - - -- First attachments result container -->776 */777 public function AttachmentsHeader($attr,$content)778 {779 return780 "<?php if (\$attach_i == 0) : ?>".781 $content.782 "<?php endif; ?>";783 }784 785 /*dtd786 <!ELEMENT tpl:AttachmentsFooter - - -- Last attachments result container -->787 */788 public function AttachmentsFooter($attr,$content)789 {790 return791 "<?php if (\$attach_i+1 == count(\$_ctx->attachments)) : ?>".792 $content.793 "<?php endif; ?>";794 }795 796 /*dtd797 <!ELEMENT tpl:AttachmentsIf - - -- Test on attachment fields -->798 <!ATTLIST tpl:AttachmentIf799 is_image (0|1) #IMPLIED -- test if attachment is an image (value : 1) or not (value : 0)800 has_thumb (0|1) #IMPLIED -- test if attachment has a square thumnail (value : 1) or not (value : 0)801 is_mp3 (0|1) #IMPLIED -- test if attachment is a mp3 file (value : 1) or not (value : 0)802 is_flv (0|1) #IMPLIED -- test if attachment is a flv file (value : 1) or not (value : 0)803 >804 */805 public function AttachmentIf($attr,$content)806 {807 $if = array();808 809 $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';810 811 if (isset($attr['is_image'])) {812 $sign = (boolean) $attr['is_image'] ? '' : '!';813 $if[] = $sign.'$attach_f->media_image';814 }815 816 if (isset($attr['has_thumb'])) {817 $sign = (boolean) $attr['has_thumb'] ? '' : '!';818 $if[] = $sign.'isset($attach_f->media_thumb[\'sq\'])';819 }820 821 if (isset($attr['is_mp3'])) {822 $sign = (boolean) $attr['is_mp3'] ? '==' : '!=';823 $if[] = '$attach_f->type '.$sign.' "audio/mpeg3"';824 }825 826 if (isset($attr['is_flv'])) {827 $sign = (boolean) $attr['is_flv'] ? '' : '!';828 $if[] = $sign.829 '($attach_f->type == "video/x-flv" || '.830 '$attach_f->type == "video/mp4" || '.831 '$attach_f->type == "video/x-m4v")';832 }833 834 if (!empty($if)) {835 return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';836 } else {837 return $content;838 }839 }840 841 /*dtd842 <!ELEMENT tpl:AttachmentMimeType - O -- Attachment MIME Type -->843 */844 public function AttachmentMimeType($attr)845 {846 $f = $this->getFilters($attr);847 return '<?php echo '.sprintf($f,'$attach_f->type').'; ?>';848 }849 850 /*dtd851 <!ELEMENT tpl:AttachmentType - O -- Attachment type -->852 */853 public function AttachmentType($attr)854 {855 $f = $this->getFilters($attr);856 return '<?php echo '.sprintf($f,'$attach_f->media_type').'; ?>';857 }858 859 /*dtd860 <!ELEMENT tpl:AttachmentFileName - O -- Attachment file name -->861 */862 public function AttachmentFileName($attr)863 {864 $f = $this->getFilters($attr);865 return '<?php echo '.sprintf($f,'$attach_f->basename').'; ?>';866 }867 868 /*dtd869 <!ELEMENT tpl:AttachmentSize - O -- Attachment size -->870 <!ATTLIST tpl:AttachmentSize871 full CDATA #IMPLIED -- if set, size is rounded to a human-readable value (in KB, MB, GB, TB)872 >873 */874 public function AttachmentSize($attr)875 {876 $f = $this->getFilters($attr);877 if (!empty($attr['full'])) {878 return '<?php echo '.sprintf($f,'$attach_f->size').'; ?>';879 }880 return '<?php echo '.sprintf($f,'files::size($attach_f->size)').'; ?>';881 }882 883 /*dtd884 <!ELEMENT tpl:AttachmentTitle - O -- Attachment title -->885 */886 public function AttachmentTitle($attr)887 {888 $f = $this->getFilters($attr);889 return '<?php echo '.sprintf($f,'$attach_f->media_title').'; ?>';890 }891 892 /*dtd893 <!ELEMENT tpl:AttachmentThumbnailURL - O -- Attachment square thumbnail URL -->894 */895 public function AttachmentThumbnailURL($attr)896 {897 $f = $this->getFilters($attr);898 return899 '<?php '.900 'if (isset($attach_f->media_thumb[\'sq\'])) {'.901 'echo '.sprintf($f,'$attach_f->media_thumb[\'sq\']').';'.902 '}'.903 '?>';904 }905 906 /*dtd907 <!ELEMENT tpl:AttachmentURL - O -- Attachment URL -->908 */909 public function AttachmentURL($attr)910 {911 $f = $this->getFilters($attr);912 return '<?php echo '.sprintf($f,'$attach_f->file_url').'; ?>';913 }914 915 public function MediaURL($attr)916 {917 $f = $this->getFilters($attr);918 return '<?php echo '.sprintf($f,'$_ctx->file_url').'; ?>';919 }920 736 921 737 /* Blog ----------------------------------------------- */ … … 1160 976 public function CategoryIf($attr,$content) 1161 977 { 1162 $if = array();978 $if = new ArrayObject(); 1163 979 $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; 1164 980 … … 1182 998 $if[] = '$_ctx->categories->cat_desc '.$sign.' ""'; 1183 999 } 1000 1001 $this->core->callBehavior('tplIfConditions','CategoryIf',$attr,$content,$if); 1184 1002 1185 1003 if (!empty($if)) { … … 1431 1249 selected (0|1) #IMPLIED -- post is selected (value : 1) or not (value : 0) 1432 1250 has_category (0|1) #IMPLIED -- post has a category (value : 1) or not (value : 0) 1433 has_attachment (0|1) #IMPLIED -- post has attachments (value : 1) or not (value : 0) 1251 has_attachment (0|1) #IMPLIED -- post has attachments (value : 1) or not (value : 0) (see Attachment plugin for code) 1434 1252 comments_active (0|1) #IMPLIED -- comments are active for this post (value : 1) or not (value : 0) 1435 1253 pings_active (0|1) #IMPLIED -- trackbacks are active for this post (value : 1) or not (value : 0) … … 1442 1260 public function EntryIf($attr,$content) 1443 1261 { 1444 $if = array();1262 $if = new ArrayObject(); 1445 1263 $extended = null; 1446 1264 $hascategory = null; … … 1499 1317 } 1500 1318 1501 if (isset($attr['has_attachment'])) {1502 $sign = (boolean) $attr['has_attachment'] ? '' : '!';1503 $if[] = $sign.'$_ctx->posts->countMedia()';1504 }1505 1506 1319 if (isset($attr['comments_active'])) { 1507 1320 $sign = (boolean) $attr['comments_active'] ? '' : '!'; … … 1540 1353 } 1541 1354 1355 $this->core->callBehavior('tplIfConditions','EntryIf',$attr,$content,$if); 1356 1542 1357 if (!empty($if)) { 1543 return '<?php if('.implode(' '.$operator.' ', $if).') : ?>'.$content.'<?php endif; ?>';1358 return '<?php if('.implode(' '.$operator.' ',(array)$if).') : ?>'.$content.'<?php endif; ?>'; 1544 1359 } else { 1545 1360 return $content; … … 1636 1451 } 1637 1452 1638 /*dtd1639 <!ELEMENT tpl:EntryAttachmentCount - O -- Number of attachments for entry -->1640 <!ATTLIST tpl:EntryAttachmentCount1641 none CDATA #IMPLIED -- text to display for "no attachment" (default: no attachment)1642 one CDATA #IMPLIED -- text to display for "one attachment" (default: one attachment)1643 more CDATA #IMPLIED -- text to display for "more attachment" (default: %s attachment, %s is replaced by the number of attachments)1644 >1645 */1646 public function EntryAttachmentCount($attr)1647 {1648 $none = 'no attachment';1649 $one = 'one attachment';1650 $more = '%d attachments';1651 1652 if (isset($attr['none'])) {1653 $none = addslashes($attr['none']);1654 }1655 if (isset($attr['one'])) {1656 $one = addslashes($attr['one']);1657 }1658 if (isset($attr['more'])) {1659 $more = addslashes($attr['more']);1660 }1661 1662 return1663 "<?php if (\$_ctx->posts->countMedia() == 0) {\n".1664 " printf(__('".$none."'),(integer) \$_ctx->posts->countMedia());\n".1665 "} elseif (\$_ctx->posts->countMedia() == 1) {\n".1666 " printf(__('".$one."'),(integer) \$_ctx->posts->countMedia());\n".1667 "} else {\n".1668 " printf(__('".$more."'),(integer) \$_ctx->posts->countMedia());\n".1669 "} ?>";1670 }1671 1453 1672 1454 /*dtd … … 2223 2005 $if[] = $sign.'context::PaginationEnd()'; 2224 2006 } 2007 2008 $this->core->callBehavior('tplIfConditions','PaginationIf',$attr,$content,$if); 2225 2009 2226 2010 if (!empty($if)) { … … 2497 2281 } 2498 2282 2283 $this->core->callBehavior('tplIfConditions','CommentIf',$attr,$content,$if); 2284 2499 2285 if (!empty($if)) { 2500 2286 return '<?php if('.implode(' && ',$if).') : ?>'.$content.'<?php endif; ?>'; … … 2988 2774 current_mode CDATA #IMPLIED -- tests if current URL mode is the one given in parameter 2989 2775 has_tpl CDATA #IMPLIED -- tests if a named template exists 2990 has_tag CDATA #IMPLIED -- tests if a named template tag exists 2776 has_tag CDATA #IMPLIED -- tests if a named template tag exists (see Tag plugin for code) 2991 2777 blog_id CDATA #IMPLIED -- tests if current blog ID is the one given in parameter 2992 2778 comments_active (0|1) #IMPLIED -- test if comments are enabled blog-wide … … 2998 2784 public function SysIf($attr,$content) 2999 2785 { 3000 $if = array();2786 $if = new ArrayObject(); 3001 2787 $is_ping = null; 3002 2788 … … 3044 2830 } 3045 2831 3046 if (isset($attr['has_tag'])) {3047 $sign = '';3048 if (substr($attr['has_tag'],0,1) == '!') {3049 $sign = '!';3050 $attr['has_tag'] = substr($attr['has_tag'],1);3051 }3052 $if[] = $sign."(\$core->tpl->tagExists('".addslashes($attr['has_tag'])."') )";3053 }3054 3055 2832 if (isset($attr['blog_id'])) { 3056 2833 $sign = ''; … … 3081 2858 $if[] = '(isset($_search_count) && $_search_count '.html::decodeEntities($attr['search_count']).')'; 3082 2859 } 2860 2861 $this->core->callBehavior('tplIfConditions','SysIf',$attr,$content,$if); 3083 2862 3084 2863 if (!empty($if)) { -
plugins/tags/_public.php
r270 r407 44 44 45 45 $core->addBehavior('templateBeforeBlock',array('behaviorsTags','templateBeforeBlock')); 46 $core->addBehavior('tplSysIfConditions',array('behaviorsTags','tplSysIfConditions')); 46 47 47 48 class behaviorsTags … … 68 69 "\$params['sql'] .= \"AND META.meta_id = '\".\$core->con->escape(\$_ctx->meta->meta_id).\"' \";\n". 69 70 "} ?>\n"; 71 } 72 } 73 74 public static function tplIfConditions($tag, $attr,$content,$if) 75 { 76 if ($tag == 'Sys' && isset($attr['has_tag'])) { 77 $sign = ''; 78 if (substr($attr['has_tag'],0,1) == '!') { 79 $sign = '!'; 80 $attr['has_tag'] = substr($attr['has_tag'],1); 81 } 82 $if[] = $sign."(\$core->tpl->tagExists('".addslashes($attr['has_tag'])."') )"; 70 83 } 71 84 }
Note: See TracChangeset
for help on using the changeset viewer.