]> git.pld-linux.org Git - packages/Smarty.git/commitdiff
- create mb_truncate modifier, auto/ac/Smarty-2.6.14-4 auto/ac/Smarty-2_6_26-4 auto/th/Smarty-2_6_26-4
authorElan Ruusamäe <glen@pld-linux.org>
Fri, 19 Nov 2010 11:38:36 +0000 (11:38 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
  http://www.guyrutenberg.com/2007/12/04/multibyte-string-truncate-modifier-for-smarty-mb_truncate/
- rel 4

Changed files:
    Smarty.spec -> 1.52
    modifier.mb_truncate.patch -> 1.1

Smarty.spec
modifier.mb_truncate.patch [new file with mode: 0644]

index 3990f78def2613d9915f8c6a9582ab551d7b1409..e409ef977bb90f0b718d51f86e089cc117e1f0b0 100644 (file)
@@ -5,7 +5,7 @@ Summary:        Template engine for PHP
 Summary(pl.UTF-8):     System szablonów dla PHP
 Name:          Smarty
 Version:       2.6.26
-Release:       3
+Release:       4
 License:       LGPL v2.1+
 Group:         Development/Languages/PHP
 Source0:       http://www.smarty.net/distributions/%{name}-%{version}.tar.gz
@@ -15,6 +15,7 @@ Source1:      http://www.smarty.net/distributions/manual/en/%{name}-%{doc_version}-do
 # Source1-md5: 5123152dd248898a84b96b806f551e78
 Source2:       %{name}-function.html_input_image.php
 Patch0:                path.patch
+Patch1:                modifier.mb_truncate.patch
 URL:           http://www.smarty.net/
 BuildRequires: rpm-php-pearprov >= 4.4.2-11
 Requires:      php-common >= 4:%{php_min_version}
@@ -57,6 +58,8 @@ Dokumentacja do systemu szablonów Smarty.
 %prep
 %setup -q -a1
 %patch0 -p1
+cp -a libs/plugins/modifier.{,mb_}truncate.php
+%patch1 -p1
 
 %install
 rm -rf $RPM_BUILD_ROOT
diff --git a/modifier.mb_truncate.patch b/modifier.mb_truncate.patch
new file mode 100644 (file)
index 0000000..bcff995
--- /dev/null
@@ -0,0 +1,46 @@
+--- Smarty-2.6.26/libs/plugins/modifier.mb_truncate.php        2009-06-18 14:46:27.000000000 +0000
++++ Smarty-2.6.26/libs/plugins/modifier.mb_truncate.php        2010-11-19 11:34:18.704932307 +0000
+@@ -10,21 +10,24 @@
+  * Smarty truncate modifier plugin
+  *
+  * Type:     modifier<br>
+- * Name:     truncate<br>
++ * Name:     mb_truncate<br>
+  * Purpose:  Truncate a string to a certain length if necessary,
+  *           optionally splitting in the middle of a word, and
+  *           appending the $etc string or inserting $etc into the middle.
++ *           This version also supports multibyte strings.
+  * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
+  *          truncate (Smarty online manual)
+- * @author   Monte Ohrt <monte at ohrt dot com>
++ * @author   Guy Rutenberg <guyrutenberg@gmail.com> based on the original 
++ *           truncate by Monte Ohrt <monte at ohrt dot com>
+  * @param string
+  * @param integer
+  * @param string
++ * @param string
+  * @param boolean
+  * @param boolean
+  * @return string
+  */
+-function smarty_modifier_truncate($string, $length = 80, $etc = '...',
++function smarty_modifier_mb_truncate($string, $length = 80, $etc = '...', $charset='UTF-8',
+                                   $break_words = false, $middle = false)
+ {
+     if ($length == 0)
+@@ -33,12 +36,12 @@
+     if (strlen($string) > $length) {
+         $length -= min($length, strlen($etc));
+         if (!$break_words && !$middle) {
+-            $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
++            $string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length+1, $charset));
+         }
+         if(!$middle) {
+-            return substr($string, 0, $length) . $etc;
++            return mb_substr($string, 0, $length, $charset) . $etc;
+         } else {
+-            return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
++            return mb_substr($string, 0, $length/2, $charset) . $etc . mb_substr($string, -$length/2, $charset);
+         }
+     } else {
+         return $string;
This page took 0.085702 seconds and 4 git commands to generate.