developer.jelix.org is not used any more and exists only for
history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.
Opened 13 years ago
Closed 13 years ago
#511 closed bug (fixed)
truncate modifier modification
Reported by: | Torgan | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | Jelix 1.0.5 |
Component: | jelix:plugins | Version: | 1.0.2 |
Severity: | minor | Keywords: | template modifier truncate |
Cc: | Blocked By: | ||
Blocking: | Documentation needed: | no | |
Hosting Provider: | Php version: |
Description
the truncate modifier uses the iconv functions that sometimes hangs and generate "memory exhausted errors" when addressing UTF8 texts. mb_ seems more stable, though less universally present on php server.
This patch makes the template modifier truncate use mb_ functions if available, or iconv functions if not:
<?php /* comments & extra-whitespaces have been removed by jBuildTools*/ /** * Plugin from smarty project and adapted for jtpl * @package jelix * @subpackage jtpl_plugin * @author * @contributor Laurent Jouanneau (utf8 compliance) * @copyright 2001-2003 ispi of Lincoln, Inc., 2007 Laurent Jouanneau * @link http://smarty.php.net/ * @link http://jelix.org/ * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html */ function jtpl_modifier_common_truncate($string, $length = 80, $etc = '...', $break_words = false) { if (function_exists ('mb_strlen')) { $f_strlen = 'mb_strlen'; } else { $f_strlen = 'iconv_strlen'; } if (function_exists ('mb_substr')) { $f_substr = 'mb_substr'; } else { $f_substr = 'iconv_substr'; } if($length == 0) return ''; $charset = jTpl::getEncoding(); if($f_strlen ($string,$charset) > $length){ $length -= $f_strlen($etc,$charset); if(!$break_words) $string = preg_replace('/\s+?(\S+)?$/', '', $f_substr($string, 0, $length+1,$charset)); return $f_substr($string, 0, $length,$charset).$etc; } else return $string; } ?>
Attachments (1)
Change History (7)
comment:1 Changed 13 years ago by laurentj
- Component changed from jelix to jelix:plugins
- Severity changed from normal to minor
comment:2 Changed 13 years ago by bballizlife
Also don't forget to update the @contributor tag in the header of the file
comment:3 Changed 13 years ago by laurentj
- Milestone set to Jelix 1.1
Changed 13 years ago by bastnic
comment:4 Changed 13 years ago by bastnic
- review set to review?
Stupid to have some ticket like that still open, so there's the same patch with header changed and in the good format.
comment:5 Changed 13 years ago by laurentj
- Milestone changed from Jelix 1.1 beta 1 to Jelix 1.0.5
- review changed from review? to review+
ok.
Should be landed in the 1.0.x branch and the trunk.
comment:6 Changed 13 years ago by bastnic
- Resolution set to fixed
- Status changed from new to closed
done.
Note: See
TracTickets for help on using
tickets.
Please provide a diff file for the trunk.