From 62e1c55c97b583a5e9c8565407c41dae0f995667 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 May 2015 00:44:05 +0200 Subject: [PATCH] NEW Introduce function dolGetFirstLineOfText --- htdocs/categories/index.php | 8 ++++---- htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/lib/functions2.lib.php | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index 76a19c91d7d..590cb4edb49 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2005 Eric Seigne - * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2006-2015 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2005-2012 Regis Houssin * @@ -28,6 +28,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $langs->load("categories"); @@ -151,8 +152,7 @@ foreach($fulltree as $key => $val) 'rowid'=>$val['rowid'], 'fk_menu'=>$val['fk_parent'], 'entry'=>''. + ''. ''. '
'.$li. - ''. - ' '.$val['description'].''.dolGetFirstLineOfText($val['description']).''.img_view().'
' ); @@ -160,7 +160,7 @@ foreach($fulltree as $key => $val) print ''; -print '
'.$langs->trans("Categories").''.$langs->trans("Description").''; +print '
'.$langs->trans("Categories").''; if (! empty($conf->use_javascript_ajax)) { print ''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6d5f1fe7a65..3d756fb8e32 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4020,7 +4020,7 @@ function dol_nboflines($s,$maxchar=0) * @param int $maxlinesize Largeur de ligne en caracteres (ou 0 si pas de limite - defaut) * @param string $charset Give the charset used to encode the $text variable in memory. * @return int Number of lines - * @see dol_nboflines + * @see dol_nboflines, dolGetFirstLineOfText */ function dol_nboflines_bis($text,$maxlinesize=0,$charset='UTF-8') { diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 5fbf3fb9c5e..1a1fd706e0a 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -29,6 +29,25 @@ // Enable this line to trace path when function is called. //print xdebug_print_function_stack('Functions2.lib was called');exit; +/** + * Return first line of text. Cut will depends if content is HTML or not. + * + * @param string $text Input text + * @return string Output text + * @see dol_nboflines_bis + */ +function dolGetFirstLineOfText($text) +{ + if (dol_textishtml($text)) + { + $firstline=preg_replace('/]*>.*$/s','',$text); // The s pattern modifier means the . can match newline characters + } + else + { + $firstline=preg_replace('/[\n\r].*/','',$text); + } + return $firstline.((strlen($firstline) != strlen($text))?'...':''); +} /** * Same function than javascript unescape() function but in PHP.