From LifeType Wiki
Name: mobile
Download link: http://sourceforge.net/projects/lifetype/files/
License: GPL
Author: The LifeType Project
Description
This plugin generates a mobile an PDA-friendly version of LifeType pages, with the advantage that new devices can be added as they become necessary. All is needed to do is to provide some information about the new platform and create the necessary templates for it. Please see the Notes section for more information.
The plugin currently offers a very simplified view of a blog, where it is only possible to view the list of posts and browse the comments. There is no calendar, list of categories, links, resources or trackbacks, and it is not possible to add new comments either.
It is not possible to define different templates for different blogs, so all blogs will use the same mobile template.
Both the main blog view and the article view offer pagination of the contents so that pages are smaller.
Configuration
First of all, move mobile.php from the plugin folder into the root folder of LifeType, so that it can be used as an entry point to the application.
There is no need to activate the plugin, it will be working as soon as mobile.php can be reached.
All the URLs relative to the mobile version of a blog or article have mobile.php as the entry point, which is a completely independent entity from index.php, admin.php and summary.php.
There are two kind of URLs that this plugin will generate:
- Links to the mobile version of a blog: http://www.yoursite.com/mobile.php?blogId=X, where X is the blog identifier.
- Links to the mobile version of an article: http://www.yoursite.com/mobile.php?op=ViewArticle&blogId=X&articleId=YY, where X is the blog identifier and YY is the article identifier.
It is also possible to use any of the functions below provided by the $mobile object at the template level. They will calculate the right URLs for us:
- {$mobile->blogLink()}: Use this method to obtain the link to the mobile version of any given blog. (should look like http://www.yoursite.com/mobile.php?blogId=X)
- {$mobile->postLink($post)}: Use this method to obtain the link to the mobile version of any post in a blog. Links to the mobile version of a post should look like http://www.yoursite.com/mobile.php?op=ViewArticle&blogId=1&articleId=44
It is also important to keep in mind that currently, plugins are not supported when accessing a blog via mobile.php.
Notes
How to add new platforms
Platforms are defined in the terminal.properties.php file that can be found in the plugin's own config/ folder (plugins/mobile/config/) For each new platform, we have to add a new array to the global array $config.
Each platform is defined using the following properties:
- regexp: The regular expression that will be applied agains the User-Agent string of the device, which can be as easy or complex as neeed. However, make sure that it does not collide with any of the other regexps already defined.
- content: The name of the template folder where terminal-specific templates can be found. The folder must exist and be readable in the plugins/mobile/templates/ folder.
- content-type: The "Content-Type" header that will be sent to the device when sending a response
- id: The unique identifier assigned to this definition.
- itemsPerPage: The number of items per page that will be displayed (number of posts, number of comments, etc) This can be configured on a per-platform basis so that we can reduce the amount of items for WAP platforms, which usually have less memory available for pages.
- desc: A generic string describing this platform.
There should always be a generic platform identified by the id default, as the plugin will try to load this one when there is no other platform matching.
The following is an example of a device definition, specifically created for the Nokia 9500 Communicator which features a bigger screen and a reacher browser:
$config["terminals"] = Array (
...
Array( "regexp" => "/.*Nokia 9500.*/",
"content" => "html-nokia-9500",
"content-type" => "text/html",
"id" => "nokia",
"itemsPerPage" => 5,
"desc" => "Nokia 9500 Communicator" )
);
Template files required
Before a new platform can be used, the following template files must be created:
- main.template: Renders the main page of the blog. Use the object $posts, which is an array of articles, to display the information.
- postandcomments.template: Displays one post and its comments. The object containing the current post is called $post and the array containing the comments is called $comments. Please keep in mind that this array does not contain all the comments but only the comments that should be shown in the current page (since pagination is enabled)
- error.template: This template is used when an error message needs to be displayed. The $viewErrorMessage variable contains the error message itself.
Additionally, most template sets use the following files. They are not mandatory but help not to repeat the same content in each single page.
- header.template: Contains the common header that is repeated in all pages.
- footer.template: Contains the common footer that is repeated in all pages.
- post.template: Displays one single post. In the 'html-light' template that is included in the package, this template file is used both in main.template and post.template when showing a post.
- pager.template: This file contains the display logic behind the pager. The logic is a bit complex, so please just copy the file as it is if you don't know how it works but wish to create a new template set for a new platform.
In the next section you will find more objects that are available for all templates.
Objects available in mobile templates
The following objects are always available in the mobile templates. They include things like information about the terminal making the request, a request generator and the blog which we are currently displaying:
- $murl: This object is the mobile equivalent of $url which is used in the normal templates to generate URLs. It is a much simplified version of the normal request generators and is only able to generate ULRs pointing to the mobile version of a blog and to the mobile version of a post.
- $murl->blogLink(): Generates the link to the mobile version of the current blog.
- $murl->postPermalink($post): Generates a link to the mobile version of the given article.
- $terminal: This is a special object that contains information about the terminal/platform that made the current request. It supports the following methods:
- $terminal->getRegexp(): Returns the regular expression that was used to match this terminal. The regular expression is the same one that can be found in the terminal.properties.php file.
- $terminal->getContent(): Returns the name of the folder where platform-specific templates can be found. This is the same information described by the content key in the terminal.properties.php file.
- $terminal->getContentType(): Returns the HTTP content type that should be sent to this kind of platform. It could for example be text/html for devices that support HTML content and text/xml for devices that only support WAP.
- $terminal->getId(): Returns the identifier assigned to this platform, as defined in the platform.properties.php file.
- $terminal->getDesc(): Returns the description assigned to this platform/terminal.
- $terminal->getUserAgent(): Returns the User-Agent HTTP header as it was sent by this terminal.
- $terminal->getAcceptTypes(): Returns which MIME types this terminal accepts. This information is fetched from the Accept-Types HTTP header that the terminal sent when making the request.
- $terminal->getNumItemsPerPage(): The amount of items per page is a value configurable on a per-platform basis. It is possible to check at the template level how many items we are showing per page via this method.
- $blog: This is an object of type BlogInfo type and contains information about the current blog.
Tips
Useful tips when creating templates for mobile platforms:
- When targetting mobile Opera browsers, make sure to include a handheld stylesheet so that Opera does not enable its small-screen rendering technology:
<STYLE TYPE="text/css" media="handheld"> ... </STYLE>
- Try to avoid horizontal scroll bars.
