NEW Introduce function dolGetFirstLineOfText

This commit is contained in:
Laurent Destailleur 2015-05-19 00:44:05 +02:00
parent 03acb1a8c9
commit 62e1c55c97
3 changed files with 24 additions and 5 deletions

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
*
@ -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'=>'<table class="nobordernopadding centpercent"><tr><td>'.$li.
'</td><td width="50%">'.
' '.$val['description'].'</td>'.
'</td><td width="50%">'.dolGetFirstLineOfText($val['description']).'</td>'.
'<td align="right" width="20px;"><a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.'">'.img_view().'</a></td>'.
'</tr></table>'
);
@ -160,7 +160,7 @@ foreach($fulltree as $key => $val)
print '<table class="liste" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td>'.$langs->trans("Description").'</td><td align="right">';
print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td align="right">';
if (! empty($conf->use_javascript_ajax))
{
print '<div id="iddivjstreecontrol"><a href="#">'.img_picto('','object_category').' '.$langs->trans("UndoExpandAll").'</a> | <a href="#">'.img_picto('','object_category-expanded').' '.$langs->trans("ExpandAll").'</a></div>';

View File

@ -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')
{

View File

@ -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('/<br[^>]*>.*$/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.