Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Wordlist block

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
ube
Smarty n00b


Joined: 01 Jul 2003
Posts: 2

PostPosted: Wed Sep 24, 2003 10:56 pm    Post subject: Wordlist block Reply with quote

There I was, with a nice wordlist and a FAQ page. I needed some way to link certain words and phrases to a wordlist page, so I came up with this plug in. Hope someone finds it useful.. Input wanted.

Code:
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File:     block.wordlist.php
* Type:     block
* Name:     wordlist
* Purpose:  rewrite block and add links to wordlist page
* Parameters: wordlist [required] - array ("id" => "word") oderd by longest word
*             href [required] - href string
*             attr [optional] - attributes to <a>-tag
*             assign [optional] - variable to collect output
* Author:   Urban Jonsson <urban@solace.mh.se>
* -------------------------------------------------------------
* example
* {wordlist href="wordlist.php?id=%id" wordlist=$wordlist attr="class=faq target=_blank"}
*       {$text}
* {/wordlist}
*/
function smarty_block_wordlist($params, $content, &$this)
{
extract($params);
        if ( $wordlist && $content && $href) {
                foreach ( $wordlist as $key => $val ) {
                        if ( ereg($val, $content) ) {
if ( substr(strtolower($content), (strpos(strtolower($content), strtolower($val))+strlen($val)), 4) != "</a>" ) {
                                        $content = eregi_replace("$val", "<a $attr href=\"$href\">\\0</a>", $content);
                                        $content = ereg_replace("%id", "$key", $content);
                                }
                        }
                }
                if (!empty($params['assign'])) {
                        $this->assign($params['assign'], $content);
                } else {
                        echo $content;
                }
        }
}
?>
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP