Parse HTML in various ways. eg. replace constants, convert bbcode etc.
$tp->toHtml(string, bbcodes, type);
$tp->toHtml("<strong class="bbcode bold bbcode-b bbcode-b-page">Bold print</strong>", true, 'BODY'); // Example
| Name | Description |
|---|---|
| string | text or HTML to be parsed |
| bbcodes | boolean - set to true to parse bbcodes into html |
| type | string - TITLE, SUMMARY, DESCRIPTION, BODY, LINKTEXT, RAWTEXT |
Convert a unix timestamp into a readable format.
$tp->toDate(unixDatestamp, format);
| Format | Description |
|---|---|
| short | Short date format as defined in admin preferences |
| long | Long date format as defined in admin preferences |
| relative | Relative time format. eg. "2 days ago" |
Convert html to plain text.
$tp->toText(string);
Convert e_xxxxx paths to their equivalent shortcodes. eg. e_PLUGIN becomes {e_PLUGIN}
$tp->createConstants(string);
Convert {e_XXXX} shortcode paths to their equivalent constants. eg. {e_PLUGIN} becomes e_PLUGIN
$tp->replaceConstants(string);
Parse an e107 template using core and/or custom shortcodes. ie. replaces all instances of {XXXXX_XXXX} etc.
$tp->parseTemplate(template, use core shortcodes, custom shortcodes);
| Name | Description |
|---|---|
| template | string |
| user core shortcodes | boolean |
| custom shortcodes | object |
Use to convert {e_MEDIA_IMAGE} and other image paths to an auto-sized image path for use inside an img tag.
$url = "{e_MEDIA_IMAGE}2012-04/someimage.jpg";
$image = $tp->thumbUrl($url);
echo "<img src='".$image."' />
Set the width, height and crop of the thumbUrl function.
$tp->setThumbSize($width, $height, $crop);
Convert a glyph name into Html. Just choose an icon from font-awesome and remove the first 'fa'
Templates may also use the following shortcode: which calls the same function.
$tp->toGlyph("fa-anchor");
Advanced settings:
$tp->toGlyph("fa-anchor", array('size'=>'2x'));
Render an icon. If a .glyph extension is found, it will automatically use the toGlyph() function above.
$iconPath = "{e_MEDIA}myicon.png";
$tp->toIcon($iconPath);
Render a user avatar. If empty, the current user's avatar will be displayed if found or a generic avatar image.
echo $tp->toAvatar(); // render avatar of the current user.
$userData = e107::user(5); // Get User data for user-id #5.
echo $tp->toAvatar($userData); // requires as a minimum $userData['user_image'].
Render an image.
$url = "{e_MEDIA_IMAGE}2012-04/someimage.jpg";
$parms = array('w'=>500, 'h'=>200,'crop'=>1, 'alt'=>'my image'); // if not width/height set, the default as set by {SETIMAGE} will be used.
echo $tp->toImage($url,$parms);