Dotclear


Ignore:
Timestamp:
01/29/14 13:32:04 (12 years ago)
Author:
Dsls
Branch:
default
Message:

Added "none", "one","more" attributes to all *Count template tags, fixes #1147

File:
1 edited

Legend:

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

    r2610 r2646  
    385385     } 
    386386 
     387     public function displayCounter($variable,$values,$attr,$count_only_by_default=false) { 
     388          if (isset($attr['count_only'])) { 
     389               $count_only=($attr['count_only']==1); 
     390          } else { 
     391               $count_only = $count_only_by_default; 
     392          } 
     393          if ($count_only) { 
     394               return "<?php echo ".$variable."; ?>"; 
     395          } else { 
     396               $v=$values; 
     397               if (isset($attr['none'])) { 
     398                    $v['none'] = addslashes($attr['none']); 
     399               } 
     400               if (isset($attr['one'])) { 
     401                    $v['one'] = addslashes($attr['one']); 
     402               } 
     403               if (isset($attr['more'])) { 
     404                    $v['more'] = addslashes($attr['more']); 
     405               } 
     406               return 
     407                    "<?php if (".$variable." == 0) {\n". 
     408                    "  printf(__('".$v['none']."'),".$variable.");\n". 
     409                    "} elseif (".$variable." == 1) {\n". 
     410                    "  printf(__('".$v['one']."'),".$variable.");\n". 
     411                    "} else {\n". 
     412                    "  printf(__('".$v['more']."'),".$variable.");\n". 
     413                    "} ?>"; 
     414          } 
     415     } 
    387416     /* TEMPLATE FUNCTIONS 
    388417     ------------------------------------------------------- */ 
     
    545574     { 
    546575          $f = $this->getFilters($attr); 
    547           return '<?php echo '.sprintf($f,'$_ctx->archives->nb_post').'; ?>'; 
     576          return $this->displayCounter( 
     577               sprintf($f,'$_ctx->archives->nb_post'), 
     578               array( 
     579                    'none' => 'no archive', 
     580                    'one'  => 'one archive', 
     581                    'more' => '%d archives' 
     582               ), 
     583               $attr, 
     584               true 
     585          ); 
    548586     } 
    549587 
     
    10211059     { 
    10221060          $f = $this->getFilters($attr); 
    1023           return '<?php echo '.sprintf($f,'$_ctx->categories->nb_post').'; ?>'; 
     1061          return $this->displayCounter( 
     1062               sprintf($f,'$_ctx->categories->nb_post'), 
     1063               array( 
     1064                    'none' => 'No post', 
     1065                    'one'  => 'One post', 
     1066                    'more' => '%d posts' 
     1067               ), 
     1068               $attr, 
     1069               true 
     1070          ); 
    10241071     } 
    10251072 
     
    17201767     } 
    17211768 
     1769 
     1770 
     1771 
    17221772     /*dtd 
    17231773     <!ELEMENT tpl:EntryCommentCount - O -- Number of comments for entry --> 
     
    17311781     public function EntryCommentCount($attr) 
    17321782     { 
    1733           $none = 'no comment'; 
    1734           $one = 'one comment'; 
    1735           $more = '%d comments'; 
    1736  
    1737           if (isset($attr['none'])) { 
    1738                $none = addslashes($attr['none']); 
    1739           } 
    1740           if (isset($attr['one'])) { 
    1741                $one = addslashes($attr['one']); 
    1742           } 
    1743           if (isset($attr['more'])) { 
    1744                $more = addslashes($attr['more']); 
    1745           } 
    1746  
    17471783          if (empty($attr['count_all'])) { 
    17481784               $operation = '$_ctx->posts->nb_comment'; 
     
    17511787          } 
    17521788 
    1753           return 
    1754           "<?php if (".$operation." == 0) {\n". 
    1755           "  printf(__('".$none."'),".$operation.");\n". 
    1756           "} elseif (".$operation." == 1) {\n". 
    1757           "  printf(__('".$one."'),".$operation.");\n". 
    1758           "} else {\n". 
    1759           "  printf(__('".$more."'),".$operation.");\n". 
    1760           "} ?>"; 
     1789          return $this->displayCounter( 
     1790               $operation, 
     1791               array( 
     1792                    'none' => 'no comment', 
     1793                    'one'  => 'one comment', 
     1794                    'more' => '%d comments' 
     1795                    ), 
     1796               $attr, 
     1797               false 
     1798          ); 
    17611799     } 
    17621800 
     
    17711809     public function EntryPingCount($attr) 
    17721810     { 
    1773           $none = 'no trackback'; 
    1774           $one = 'one trackback'; 
    1775           $more = '%d trackbacks'; 
    1776  
    1777           if (isset($attr['none'])) { 
    1778                $none = addslashes($attr['none']); 
    1779           } 
    1780           if (isset($attr['one'])) { 
    1781                $one = addslashes($attr['one']); 
    1782           } 
    1783           if (isset($attr['more'])) { 
    1784                $more = addslashes($attr['more']); 
    1785           } 
    1786  
    1787           return 
    1788           "<?php if (\$_ctx->posts->nb_trackback == 0) {\n". 
    1789           "  printf(__('".$none."'),(integer) \$_ctx->posts->nb_trackback);\n". 
    1790           "} elseif (\$_ctx->posts->nb_trackback == 1) {\n". 
    1791           "  printf(__('".$one."'),(integer) \$_ctx->posts->nb_trackback);\n". 
    1792           "} else {\n". 
    1793           "  printf(__('".$more."'),(integer) \$_ctx->posts->nb_trackback);\n". 
    1794           "} ?>"; 
     1811          return $this->displayCounter( 
     1812               '$_ctx->posts->nb_trackback', 
     1813               array( 
     1814                    'none' => 'no trackback', 
     1815                    'one'  => 'one trackback', 
     1816                    'more' => '%d trackbacks' 
     1817                    ), 
     1818               $attr, 
     1819               false 
     1820          ); 
    17951821     } 
    17961822 
Note: See TracChangeset for help on using the changeset viewer.

Sites map