Last active
December 22, 2015 00:28
-
-
Save neilbradley/6389449 to your computer and use it in GitHub Desktop.
This is a simple plugin to dash encode a string (and convert to lower case) for ExpressionEngine. Create a folder inside your third_party directory with your sitename (all one word in lower case). Change all references of sitename in the file to your sitename.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* ExpressionEngine - by EllisLab | |
* | |
* @package ExpressionEngine | |
* @author ExpressionEngine Dev Team | |
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc. | |
* @license http://expressionengine.com/user_guide/license.html | |
* @link http://expressionengine.com | |
* @since Version 2.0 | |
* @filesource | |
*/ | |
// ------------------------------------------------------------------------ | |
/** | |
* Energy Cell Client Plugin | |
* | |
* @package ExpressionEngine | |
* @subpackage Addons | |
* @category Plugin | |
* @author Neil Bradley / The Energy Cell | |
* @link http://www.energycell.co.uk | |
*/ | |
$plugin_info = array( | |
'pi_name' => 'Sitename Helper', | |
'pi_version' => '1.0', | |
'pi_author' => 'Neil Bradley / The Energy Cell', | |
'pi_author_url' => 'http://www.energycell.co.uk', | |
'pi_description'=> 'Sitename helper plugin', | |
//Ensure your sitename here is all lower case except the first character | |
'pi_usage' => Sitename::usage() | |
); | |
//Ensure your sitename here is all lower case except the first character | |
class Sitename { | |
public $return_data; | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
$this->EE =& get_instance(); | |
} | |
/** | |
* Just encode a string to lowercase, replacing spaces with dashes | |
* @return Formatted tag is returned | |
*/ | |
public function dash_encode() | |
{ | |
// The Template class variable $this->EE->TMPL->tagdata contains everything between the {exp:sitename:dash_encode} tags in the template | |
$tagdata = $this->EE->TMPL->tagdata; | |
$needles = array(" "); | |
$return_data = strtolower(str_replace($needles, '-', $tagdata)); | |
return $return_data; | |
} | |
// ---------------------------------------------------------------- | |
/** | |
* Plugin Usage | |
*/ | |
public static function usage() | |
{ | |
ob_start(); | |
?> | |
Dash Encoding - converts spaces in a string to a dash and converts to lowercase; | |
{exp:sitename:dash_encode}{title}{/exp:sitename:dash_encode} | |
<?php | |
$buffer = ob_get_contents(); | |
ob_end_clean(); | |
return $buffer; | |
} | |
} | |
/* End of file pi.sitename.php */ | |
/* Location: /third_party/sitename/pi.sitename.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment