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

Smarty SEO URL Friendly Modifier

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
sangprabv
Smarty Rookie


Joined: 14 Feb 2005
Posts: 13
Location: Jakarta

PostPosted: Wed Aug 21, 2013 2:21 am    Post subject: Smarty SEO URL Friendly Modifier Reply with quote

The modifier:
Code:
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage PluginsModifier
 */

/**
 * Smarty SEO URL Friendly modifier plugin
 *
 * Type:     modifier<br>
 * Name:     seo<br>
 * Purpose:  SEO URL Friendly
 *
 * @link http://smarty.php.net/manual/en/language.modifier.seo.php replace (Smarty online manual)
 * @author Willy Mularto <me at sangprabv dot web dot id>
 * @param string $string  input string
 * @param string $search  text to search for
 * @param string $delimiter replacement text
 * @param string $case uppercase/lowercase/ucfirst
 * @return string
 */
function smarty_modifier_seo($string, $search, $delimiter, $case)
{
   /*Replace any non latin chars*/
   $string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
    /*Remove any non alpha numeric*/
    $string = preg_replace("/[^a-zA-Z 0-9]+/", " ",$string);   
    /*Remove any double delimiter*/
    $string = preg_replace("/[[:blank:]]+/", "$delimiter",$string);
    /*Remove any delimiter at the beginning of string if any*/
    $string = ltrim($string, "$delimiter");
    /*Remove any delimiter at the end of string if any*/
    $string = rtrim($string, "$delimiter");
   
    switch($case) {
       case 'upper':
          return strtoupper($string);
       case 'lower':
          return strtolower($string);
       case 'first':
          return ucfirst($string);
       default:
          return($string);
    }
}

?>

Save as modifier.seo.php and store it in plugins folder
Call it on your template page, here is the example:
{-$title|seo:" ":"-":"first"-}
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
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 -> Plugins 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