# PLUGIN PREVIEW BY TEXTPATTERN.INFO
/*
adi_title - Abbreviate Titles
Written by Adi Gilbert
Released under the GNU General Public License
Version history:
0.2 - TXP 4.6 tag registration
- new attributes: wraptag, class & html_id
- fix to ignore appended string if title not changed
0.1 - initial release
*/
// TXP 4.6 tag registration
if (class_exists('\Textpattern\Tag\Registry')) {
Txp::get('\Textpattern\Tag\Registry')
->register('adi_title')
;
}
function adi_title($atts) {
global $thisarticle;
extract(lAtts(array(
'length' => '', // number of chunks
'separator' => ' ', // chunk separator
'offset' => '0', // chunk offset
'append' => ' ...', // string to append to truncated title
'wraptag' => '', // the wraptag
'class' => '', // class for wraptag
'html_id' => '', // HTML id for wraptag
'debug' => '',
),$atts));
empty($debug) ?
$title = $thisarticle['title'] :
$title = $debug;
$array = explode($separator,$title);
empty($length) ?
$array = array_slice($array,$offset) :
$array = array_slice($array,$offset,$length);
$new_title = implode($separator,$array);
if ($new_title == $title)
$append = '';
return doTag(trim($new_title."$append"),$wraptag,$class,'',$html_id);
}