Quick links: Content - sections - sub sections
EN FR
Quick Search Advanced search
 
Page

  [Opened] [jTpl] Nouveau modifier

Posted by isepman on 12/01/2008 16:14

Bonjour tout le monde et encore une fois merci pour ce frameworks à tous les contributeurs.

J'ai essayé de poster un ticket sur la forge mais je n'ai pas compris comment on faisait pour contribuer au projet jelix.

Voila, j'aimerais moi aussi apporter ma pierre a l'édifice en postant ce modifier : truncatehtml qui permet de couper un texte html en refermant les balises ouvertes. C'est "l'adaptation" du bout de code très utile qui se trouve ici Voilà donc ce que j'aimerais ajouter a jelix.

 <?php
 /**
 * Plugin from sniplr (original sources can be found here: http://snipplr.com/view.php?codeview&id=3618 )
 * @package    jelix
 * @subpackage jtpl_plugin
 * @author		
 * @contributor Didier Huguet (jtpl adaptation)
 * @copyright 2008 Didier Huguet
 * @link http://snipplr.com/view.php?codeview&id=3618
 * @link http://jelix.org/
 * @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
 */ 
 
 /**
 * modifier plugin : cut a html formated string and close all opened tags so that it doesn't inpact on the rest of the page
 * You should use this modifier in a zone so that the return value is cached
 * <pre>{$mytext|truncatehtml}
 * {$mytext|truncatehtml:150:"\n<a href="...">read full article</a>"}
 * {$mytext|truncatehtml:45}
 * </pre>
 * @param string
 * @param integer (warning html tags included )
 * @param string
 * @return string
 */
 function jtpl_modifier_common_truncatehtml($string,$nbChar=200,$etcPattern='...')
 {
	$html = substr ( $string, 0, $nbChar );
 
	$html = strrpos ( $html, "<" ) > strrpos ( $html, ">" ) ? rtrim ( substr ( $string, 0, strrpos ( $html, "<" ) ) ) . $etcPattern : rtrim ( $html ) . $etcPattern;
 	
    #put all opened tags into an array
    preg_match_all ( "#<([a-z]+)( .*)?(?!/)>#iU", $html, $result );
    $openedtags = $result[1];
 
    #put all closed tags into an array
    preg_match_all ( "#</([a-z]+)>#iU", $html, $result );
    $closedtags = $result[1];
    $len_opened = count ( $openedtags );
    # all tags are closed
    if( count ( $closedtags ) == $len_opened )
    {
        return $html;
    }
    $openedtags = array_reverse ( $openedtags );
    # close tags
    for( $i = 0; $i < $len_opened; $i++ )
    {
        if ( !in_array ( $openedtags[$i], $closedtags ) )
        {
            $html .= "</" . $openedtags[$i] . ">";
        }
        else
        {
            unset ( $closedtags[array_search ( $openedtags[$i], $closedtags)] );
        }
    }
    return $html;
 }

  [Opened] Re: [jTpl] Nouveau modifier

Reply #1 Posted by bobi on 12/02/2008 21:14

Bonjour tout le monde et encore une fois merci pour ce frameworks à tous les contributeurs.

:-)

J'ai essayé de poster un ticket sur la forge mais je n'ai pas compris comment on faisait pour contribuer au projet jelix.

Ce n'est pas sur la forge que tu peux contribuer à Jelix mais sur http://developer.jelix.org/register. Tu t'inscris et puis tu ouvres un ticket et tu proposes ton patch en suivant les étapes décrites sur http://developer.jelix.org/wiki/fr/contr(..).

Sinon, ta proposition de template truncatehtml est intéressante. Ton patch sera le bienvenue.

A+ bibo PS : la forge est un dépôt de projets basés sur/relatifs à Jelix

  [Opened] Re: [jTpl] Nouveau modifier

Reply #2 Posted by isepman on 12/04/2008 16:53

Merci beaucoup, j'ai déja développé quelques tests et mis la fonction à jour. Merci pour ton aide,

@+

 
Page
  1. Re: [jTpl] Nouveau modifier