|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ube Smarty n00b
Joined: 01 Jul 2003 Posts: 2
|
Posted: Wed Sep 24, 2003 10:56 pm Post subject: Wordlist block |
|
|
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 |
|
|
|
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
|