Changeset 2646:d055bf88fa80 for inc/public/class.dc.template.php
- Timestamp:
- 01/29/14 13:32:04 (12 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/public/class.dc.template.php
r2610 r2646 385 385 } 386 386 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 } 387 416 /* TEMPLATE FUNCTIONS 388 417 ------------------------------------------------------- */ … … 545 574 { 546 575 $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 ); 548 586 } 549 587 … … 1021 1059 { 1022 1060 $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 ); 1024 1071 } 1025 1072 … … 1720 1767 } 1721 1768 1769 1770 1771 1722 1772 /*dtd 1723 1773 <!ELEMENT tpl:EntryCommentCount - O -- Number of comments for entry --> … … 1731 1781 public function EntryCommentCount($attr) 1732 1782 { 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 1747 1783 if (empty($attr['count_all'])) { 1748 1784 $operation = '$_ctx->posts->nb_comment'; … … 1751 1787 } 1752 1788 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 ); 1761 1799 } 1762 1800 … … 1771 1809 public function EntryPingCount($attr) 1772 1810 { 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 ); 1795 1821 } 1796 1822
Note: See TracChangeset
for help on using the changeset viewer.