From LifeType Wiki
Contents |
How to show the user picture
In LifeType it is possible for users to select a picture to represent them, as some kind of "avatar". The picture must be selected from the list of pictures currently available in the "resource center".
The picture can be shown anywhere in our templates, but some of the templates offered by the LifeType project do not make use of this feature so you as a site administrator may choose to configure your templates to use this feature.
Add the following Smarty code anywhere in your favourite template set:
{assign var=blogOwner value=$blog->getOwnerInfo()}
{if $blogOwner->hasPicture()}
{assign var=picture value=$blogOwner->getPicture()}
<img src="{$url->resourcePreviewLink($picture)}" alt="My picture!" />
{/if}
Notes and description of the code above:
- The {if ...}{/if} around the actual display of the picture is necessary, since it will prevent our template from crashing in case we remove the picture, or if our template is used by a user who has no picture set.
- {$url->resourcePreviewLink($picture)} will generate a link to the small thumbnail of the picture (which is usually a 120x120 picture) If we'd like to show a bigger version or even the real size version, please use {$url->resourceMediumSizePreviewLink($picture)} or {$url->resourceDownloadLink($picture)}
- The $picture object is in fact a resource (a GalleryResource object) itself so all the methods that can be used in places like resource.template can be used with this one too. We can for example query the file name and its description via {$picture->getFileName()} and {$picture->getDescription()}
How to display RSS feeds in the sidebar
This is a simple technique which allows displaying the RSS feed contents from a link, in the sidemenu. The code below is added to footer.template, in the standard template. The foreach loop iterates over the links, and then the link is checked for an RSS Feed. If there is an RSS feed, the link is shown with the description and with a link to the RSS feed. Furthermore, the RSS feed can be parsed by the built-in feed reader, and the links in the RSS content displayed right below the feed link. Thus, it is very easy to add a blogroll or linkroll to your LifeType installation, without any hardcoding or additional plugins.
<ul class="rightmenu">
{foreach from=$mylinkscategories item=linkcategory}
<b class="rightmenu">{$linkcategory->getName()}</b>
{foreach from=$linkcategory->getLinks() item=link}
{if $link->getRssFeed()}
<li class="rightmenu">
<a href="{$link->getUrl()}" title="{$link->getDescription()}">{$link->getName()}</a>
<a href="{$link->getRssFeed()}">: [ RSS ]</a>
</li>
{if $rss->parse($link->getRssFeed())}
{foreach from=$rss->getItems() item=rssItem}
{assign var="short_title" value=$rssItem->getTitle()|truncate:45}
<li><a href="{$rssItem->getLink()}" class="rightmenu">{$short_title}</a></li>
{/foreach}
{/if}
{else}
<li class="rightmenu">
<a href="{$link->getUrl(http://news.bbc.co.uk/rss/arabic/sci_tech/rss091.xml)}" title="{$link->getDescription()}" >{$link->getName()}</a>:
{$link->getDescription()}
</li>
{/if}
{/foreach}
{/foreach}
</ul>
- keep in mind that if you display the RSS contents, the request won't finalize until all the RSS feeds have been fetched so that potentially means that the page will take ages to load for some of your visitors. The RSS is then cached so subsequent requests should perform fine.
How to make the comment form remember the poster
NOTE: this trick is taken from http://forums.lifetype.net/viewtopic.php?p=12278#12278, posted by user sganjam
In order for the comment form to remember the poster, we can use the following Javascript code that will set a cookie to remember the user information values. It needs some Javascript code as well as a couple of changes to your commentform.template file.
This is the Javascript code, please add it to your header.template file so that it is always available.
{literal}
<script type="text/javascript" language="javascript">
//You will need to set the following to work with your site
var HOST = 'yourdomain.tld';
function setCookie (name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
document.cookie = curCookie;
}
function getCookie (name) {
var prefix = name + '=';
var c = document.cookie;
var nullstring = '';
var cookieStartIndex = c.indexOf(prefix);
if (cookieStartIndex == -1)
return nullstring;
var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
if (cookieEndIndex == -1)
cookieEndIndex = c.length;
return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}
function deleteCookie (name, path, domain) {
if (getCookie(name))
document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
function fixDate (date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}
function rememberMe (f) {
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
if (f.userName != undefined)
setCookie('plogcmtuserName', f.userName.value, now, '/', '', '');
if (f.userEmail != undefined)
setCookie('plogcmtuserEmail', f.userEmail.value, now, '/', '', '');
if (f.userUrl != undefined)
setCookie('plogcmtuserUrl', f.userUrl.value, now, '/', '', '');
}
</script>
{/literal}
You can also save it as a .js file somewhere in your web server (but remember to remove the {literal} and {/literal} tags as they are not needed by Javascript but by Smarty. Then, replace the script with the following mark up code:
<script type="text/javascript" src="/path/to/your/file.js" />
These are the changes that should be made to commentform.template, somewhere near the end of the file if possible:
{literal}
<script type="text/javascript" language="javascript">
window.document.NewComment.userEmail.value = getCookie("plogcmtuserEmail");
window.document.NewComment.userName.value = getCookie("plogcmtuserName");
window.document.NewComment.userUrl.value = getCookie("plogcmtuserUrl");
</script>
{/literal}
How to use custom fields
Custom fields allow to add extra fields of information to our posts, in addition to the standard ones (post intro, post body, categories, etc) These are the supported types of custom fields in LifeType:
- Text field
- Text box
- Checkbox
- Date chooser
Whenever adding a new field, we will have to provide a descriptive string and an identifer, so that we can refer to our fields from within the templates.
Some plugins (such as the 'karma' plugin) use custom fields to store extra information related to the post. Custom fields added by plugin usually have a name that refers to the plugin so please do not delete those fields or else the plugin would not work.
As an example, we could create a blog completely devoted to movie reviews. We could use custom fields to define extra parts of the post that you want to call out special attention to and are present on every post. So we might add a few custom fields such as:
- Year
- Studio
- Starring
- Directed By
- Rating
These fields will appear automatically in the "New Post" and "Edit Post" pages, each one in a different section depending on the type. For example text fields will appear under the "topic" textbox, text boxes will appear under the post intro text box, and checkboxes and date choosers will appear on the right hand side of the page just to make them look more integrated with the rest of the side.
The only catch to custom fields is that they are not automatically shown in the template until we make a fewc changes. This is done because LifeType cannot really guess where users would like to show these fields in the page, or if they should even be shown at all.
In order to show certain fields, we will have to modify post.template for each of the templates you want to be able to 'use' these custom fields in order to have them show up on your blog with the following code:
{if $post->hasField("year")}
{$post->getFieldDescription("year")}: {$post->getField("year")}
{/if}
{if $post->hasField("Studio")}
{$post->getFieldDescription("Studio")}: {$post->getField("Studio")}
{/if}
{if $post->hasField("Starring")}
{$post->getFieldDescription("Starring")}: {$post->getField("Starring")}
{/if}
{if $post->hasField("Directed")}
{$post->getFieldDescription("Directed")}: {$post->getField("Directed ")}
{/if}
{if $post->hasField("Rating")}
{$post->getFieldDescription("Rating")}: {$post->getField("Rating")}
{/if}
When we call the {$post->hasField("xxx")} method, we are checking whether there is a value defined for that particular field in the current post. This is helpful in cases like for example the year, where we would show the text with the field description even though there was no year typed at all when adding the post.
The key function that we should call to get the value of the field is {$post->getField("XXX")} where XXX is the identifier of the field (hence the importance of using clear identifiers!) This function will return the value of the field, as it was set in the "New Post" or "Edit Post" pages.
Getting advanced with custom fields
At the bottom layer of custom fields, there are a few PHP classes that handle custom fields. These classes provide, for example, more precise control over the values of the fields than just getting its value. For example, if we have a date field and we call {$post->getField("myDateField")} we will get a field formatted in the default date format. If we want a different format, we could use a little more complicated code:
{assign var=dateField value=$post->getFieldObject("myDateField")}
{assign var=dateObject value=$dateField->getDateObject()}
The year is: {$locale->formatDate($dateObject,"%Y"}
The {$post->getFieldObject("...")} method will return an object of type CustomFieldValue, CustomFieldDateValue or CustomFieldCheckboxValue, depending on the type of the field. CustomFieldValue is the main class and CustomFieldCheckboxValue and CustomFieldDateValue extend it providing some additional methods, so we must make sure that we are getting a class of the right type before calling any of the methods added by child classes!
New types of custom fields will be added in future releases of LifeType which will enhance and improve this functionality.
Enabling plugins for new blogs
The BlogSettings class contains the settings assigned to blogs and in the case of new blogs, it is initialized with certain default values. This means that is possible to edit the code in the class so that new blogs have even plugins enabled by default, such as the authimage plugin.
In file class/dao/blogsettings.class.php, the method _setDefaults() contains the default settings for new blogs. If we'd like to get the 'authimage' plugin enabled for new blogs, all we have to do is add the following lines of code before the closing bracket of the method:
$this->setValue( "plugin_authimage_enabled", 1 ); $this->setValue( "plugin_authimage_length", 6 ); $this->setValue( "plugin_authimage_key", LifeType); $this->setValue( "plugin_authimage_expiredtime", 3600 ); $this->setValue( "plugin_authimage_default", "sky.gif" );
Other plugins can be enabled in a similar way. For example:
$this->setValue( "plugin_smileys_enabled", 1 ); $this->setValue( "plugin_smileys_iconset", "default" ); $this->setValue( "plugin_validatetrackback_enabled", 1 ); $this->setValue( "plugin_validatetrackback_dns_enabled", 1 ); $this->setValue( "plugin_validatetrackback_trackback_enabled", 1 );
The only tricky thing is to find the name of the right plugin configuration "keys", but it shouldn't be too difficult after taking a quick look at the plugin code.