Dotclear


Ignore:
Timestamp:
06/23/11 13:00:59 (14 years ago)
Author:
Dsls <dsls@…>
Branch:
default
Message:
  • Re-enabled blank post_type required by media.php in class dcBlog
  • Attachments are now handled by a plugins/attachments/_admin.php
  • Added core dcPostMedia multi-purpose class, and 'link_type' in post_media table
  • Added new behavior : tplIfConditions, to enable to add new attributes to tpl:XXXIf tags
  • Moved tpl:SysIf has_tag attribute to Tags plugin
File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/public/class.dc.template.php

    r406 r407  
    5454          $this->addValue('ArchiveEntriesCount',array($this,'ArchiveEntriesCount')); 
    5555          $this->addValue('ArchiveURL',array($this,'ArchiveURL')); 
    56            
    57           # Attachments 
    58           $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')); 
    7056           
    7157          # Blog 
     
    141127          $this->addBlock('EntriesHeader',array($this,'EntriesHeader')); 
    142128          $this->addValue('EntryExcerpt',array($this,'EntryExcerpt')); 
    143           $this->addValue('EntryAttachmentCount',array($this,'EntryAttachmentCount')); 
    144129          $this->addValue('EntryAuthorCommonName',array($this,'EntryAuthorCommonName')); 
    145130          $this->addValue('EntryAuthorDisplayName',array($this,'EntryAuthorDisplayName')); 
     
    749734     } 
    750735      
    751      /* Attachments ---------------------------------------- */ 
    752      /*dtd 
    753      <!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      /*dtd 
    775      <!ELEMENT tpl:AttachmentsHeader - - -- First attachments result container --> 
    776      */ 
    777      public function AttachmentsHeader($attr,$content) 
    778      { 
    779           return 
    780           "<?php if (\$attach_i == 0) : ?>". 
    781           $content. 
    782           "<?php endif; ?>"; 
    783      } 
    784       
    785      /*dtd 
    786      <!ELEMENT tpl:AttachmentsFooter - - -- Last attachments result container --> 
    787      */ 
    788      public function AttachmentsFooter($attr,$content) 
    789      { 
    790           return 
    791           "<?php if (\$attach_i+1 == count(\$_ctx->attachments)) : ?>". 
    792           $content. 
    793           "<?php endif; ?>"; 
    794      } 
    795       
    796      /*dtd 
    797      <!ELEMENT tpl:AttachmentsIf - - -- Test on attachment fields --> 
    798      <!ATTLIST tpl:AttachmentIf 
    799      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      /*dtd 
    842      <!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      /*dtd 
    851      <!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      /*dtd 
    860      <!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      /*dtd 
    869      <!ELEMENT tpl:AttachmentSize - O -- Attachment size --> 
    870      <!ATTLIST tpl:AttachmentSize 
    871      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      /*dtd 
    884      <!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      /*dtd 
    893      <!ELEMENT tpl:AttachmentThumbnailURL - O -- Attachment square thumbnail URL --> 
    894      */ 
    895      public function AttachmentThumbnailURL($attr) 
    896      { 
    897           $f = $this->getFilters($attr); 
    898           return 
    899           '<?php '. 
    900           'if (isset($attach_f->media_thumb[\'sq\'])) {'. 
    901                'echo '.sprintf($f,'$attach_f->media_thumb[\'sq\']').';'. 
    902           '}'. 
    903           '?>'; 
    904      } 
    905       
    906      /*dtd 
    907      <!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      } 
    920736      
    921737     /* Blog ----------------------------------------------- */ 
     
    1160976     public function CategoryIf($attr,$content) 
    1161977     { 
    1162           $if = array(); 
     978          $if = new ArrayObject(); 
    1163979          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; 
    1164980           
     
    1182998               $if[] = '$_ctx->categories->cat_desc '.$sign.' ""';  
    1183999          }  
     1000           
     1001          $this->core->callBehavior('tplIfConditions','CategoryIf',$attr,$content,$if); 
    11841002           
    11851003          if (!empty($if)) { 
     
    14311249     selected  (0|1)     #IMPLIED  -- post is selected (value : 1) or not (value : 0) 
    14321250     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) 
    14341252     comments_active     (0|1)     #IMPLIED  -- comments are active for this post (value : 1) or not (value : 0) 
    14351253     pings_active   (0|1)     #IMPLIED  -- trackbacks are active for this post (value : 1) or not (value : 0) 
     
    14421260     public function EntryIf($attr,$content) 
    14431261     { 
    1444           $if = array(); 
     1262          $if = new ArrayObject(); 
    14451263          $extended = null; 
    14461264          $hascategory = null; 
     
    14991317          } 
    15001318           
    1501           if (isset($attr['has_attachment'])) { 
    1502                $sign = (boolean) $attr['has_attachment'] ? '' : '!'; 
    1503                $if[] = $sign.'$_ctx->posts->countMedia()'; 
    1504           } 
    1505            
    15061319          if (isset($attr['comments_active'])) { 
    15071320               $sign = (boolean) $attr['comments_active'] ? '' : '!'; 
     
    15401353          } 
    15411354           
     1355          $this->core->callBehavior('tplIfConditions','EntryIf',$attr,$content,$if); 
     1356           
    15421357          if (!empty($if)) { 
    1543                return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>'; 
     1358               return '<?php if('.implode(' '.$operator.' ',(array)$if).') : ?>'.$content.'<?php endif; ?>'; 
    15441359          } else { 
    15451360               return $content; 
     
    16361451     } 
    16371452      
    1638      /*dtd 
    1639      <!ELEMENT tpl:EntryAttachmentCount - O -- Number of attachments for entry --> 
    1640      <!ATTLIST tpl:EntryAttachmentCount 
    1641      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           return 
    1663           "<?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      } 
    16711453      
    16721454     /*dtd 
     
    22232005               $if[] = $sign.'context::PaginationEnd()'; 
    22242006          } 
     2007           
     2008          $this->core->callBehavior('tplIfConditions','PaginationIf',$attr,$content,$if); 
    22252009           
    22262010          if (!empty($if)) { 
     
    24972281          } 
    24982282           
     2283          $this->core->callBehavior('tplIfConditions','CommentIf',$attr,$content,$if); 
     2284           
    24992285          if (!empty($if)) { 
    25002286               return '<?php if('.implode(' && ',$if).') : ?>'.$content.'<?php endif; ?>'; 
     
    29882774     current_mode        CDATA     #IMPLIED  -- tests if current URL mode is the one given in parameter 
    29892775     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) 
    29912777     blog_id             CDATA     #IMPLIED  -- tests if current blog ID is the one given in parameter 
    29922778     comments_active     (0|1)     #IMPLIED  -- test if comments are enabled blog-wide  
     
    29982784     public function SysIf($attr,$content) 
    29992785     { 
    3000           $if = array(); 
     2786          $if = new ArrayObject(); 
    30012787          $is_ping = null; 
    30022788           
     
    30442830          } 
    30452831           
    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            
    30552832          if (isset($attr['blog_id'])) { 
    30562833               $sign = ''; 
     
    30812858               $if[] = '(isset($_search_count) && $_search_count '.html::decodeEntities($attr['search_count']).')'; 
    30822859          } 
     2860           
     2861          $this->core->callBehavior('tplIfConditions','SysIf',$attr,$content,$if); 
    30832862           
    30842863          if (!empty($if)) { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map