Changeset 407:eb5bd0f66932 for inc/public
- Timestamp:
- 06/23/11 13:00:59 (14 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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)) {
Note: See TracChangeset
for help on using the changeset viewer.