Skip to content

Instantly share code, notes, and snippets.

@iso100
Created December 11, 2012 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iso100/4260171 to your computer and use it in GitHub Desktop.
Save iso100/4260171 to your computer and use it in GitHub Desktop.
Plugin to create href links from delimited text
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* List Linker Plugin
*
* @package ExpressionEngine
* @subpackage Addons
* @category Plugin
* @author Adam Wiggall
* @link http://turnandface.com
*/
$plugin_info = array(
'pi_name' => 'List Linker',
'pi_version' => '1.0',
'pi_author' => 'Adam Wiggall',
'pi_author_url' => 'http://turnandface.com',
'pi_description'=> 'Takes input from a P&T List and splits it into a link around a known delimiter',
'pi_usage' => List_linker::usage()
);
class List_linker {
public $return_data = "";
/**
* Constructor
*/
public function __construct()
{
$this->EE =& get_instance();
$link_data = ($this->EE->TMPL->fetch_param('item')) ? ($this->EE->TMPL->fetch_param('item')) : 'Item Required';
$item_class = ($this->EE->TMPL->fetch_param('class')) ? ($this->EE->TMPL->fetch_param('class')) : '';
if ($item_class != "")
{
$item_class = ' class="' . $item_class . '"';
}
$link_array = explode('|', $link_data);
if (count($link_array) > 1)
{
$full_link = '<a href="' . trim($link_array[1]) . '"' . $item_class . '>' . trim($link_array[0]) . '</a>';
}
else
{
$full_link = trim($link_array[0]);
}
$this->return_data = $full_link;
}
public function List_linker()
{
}
// ----------------------------------------------------------------
/**
* Plugin Usage
*/
public static function usage()
{
ob_start();
?>
Designed to take a P&T list item and turn it into an anchor element.
Splits the input around a delimiter of | (pipe)
So, in the list enter "the text of a link | the location of the link", like so
My Link|http://example.com
or
My Link | /directory/template
(spaces around the delimiter are optional to enhance legibility in the CP)
Plugin returns
<a href="http://example.com" title="My Link">My Link</a>
or
<a href="/directory/template" title="My Link">My Link</a>
In you template code
{p&t_list_field_name}
{exp:list_linker item="{item}"}
{/p&t_list_field_name}
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
}
/* End of file pi.list_linker.php */
/* Location: /system/expressionengine/third_party/list_linker/pi.list_linker.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment