What else can you do with bemokoLive?
From bemoko developer wiki
Mobilising your PHP Site
Step 1 : Copy the PHP application in to the default UI directory for your site. If this already an existing PC website, then the UI configurations can be set to allow for PC access as default, and you are then free to start creaking any mobile customisations.
Step 2 : (optional) : Add your php.ini configuration file in the conf directory in the site folder (if you wish to apply any PHP settings).
Step 3 : Create any required mobile variations of the PHP pages in the corresponding UI directory. For example if a page is installed in phpsite/ui/pc/templates/index.php, then to create a version of the page that will be run for all iPhones, copy the page to phpsite/ui/iphone/templates/index.php and modify accordingly. Device-specific versions of scripts can apply to both the pages and application scripts.
Step 4 : Access the PHP script using the default resource intent for the site, for example http:// mysite.com/phpsite/r/path/to/script.php
So what's happened here?
- Device-specific versions of scripts are only chosen as an alternative to the default during PHP include, include_once, require and require_once expressions. In this way you can override each page only when needed for a given device.
- After the bemokoLive PHP engine has rendered the output form the PHP page, the live output tweakers are applied and then the response delivered to the calling device.
- To access any content made available by bemoko live plugins, the PHP script can use the same notation as described above, e.g. ${content.countries}
During the running of a PHP page, the UI folder in the site directory will be set as the working directory. Scripts may change the working directory so a subdirectory, or include scripts in the current UI directory or a subdirectory of it, but care should be taken to avoid changing to a working directory or executing a outside of the UI directory if the script needs to take advantages of the device capabilities, user context and other benefits of running inside the Live platform.
The Default Site
Sites within the platform, by default, inherit from the default site. This means that you don't have to worry about the intricate details of site configuration if you don't need to. This need-to-know basis allows you to rapidly get started, but gives you full control if you do find you need it. All the configuration elements of the default site can be overridden in your custom site if desired. For this reason it's useful to take a look at some of the default site elements to see what it gives you.
The sample below is an extract from the default site site-config.xml:
<?xml version="1.0" encoding="UTF-8"?> <site> <headers> <header name="Cache-Control" value="no-transform"/> <header name="Cache-Control" value="no-cache"/> </headers> <uigroup default="mobile" index="r/index-test.html"> <!-- PC browser --> <ui name="pc" expr="!device.value('is_wireless_device')" fallback="ajax" /> <!-- iPhone --> <ui name="iphone" expr="device.value('brand_name')=='Apple'" fallback="ajax"/> <!-- WML --> <ui name="wml" expr="device.value('xhtml_support_level')==-1" /> <!-- Simple HTML with no CSS --> <ui name="nocss" expr="device.value('xhtml_support_level')==0" fallback="mobile"/> <!-- Basic CSS capabilities --> <ui name="basiccss" expr="device.value('xhtml_support_level')==1" fallback="nocss"/> <!-- Good CSS capabilities --> <ui name="goodcss" expr="device.value('xhtml_support_level')==2" fallback="basiccss"/> <!-- Excellent CSS capabilities --> <ui name="mobile" expr="device.value('xhtml_support_level')==3"/> <!-- AJAX with excellent CSS capabilities --> <ui name="ajax" expr="device.value('xhtml_support_level')==4" fallback="mobile"/> </uigroup> <intents> <intent name="r" type="resource" /> <intent name="t" type="transcode" /> <intent name="i" type="template" view="index.html"/> </intents> <tweaks> <tweaker plugin="AbsoluteUrlRewriter" /> </tweaks> </site>
- headers → HTTP headers to set in the HTTP response.
- uigroup → definitions of UIs available to the site developer along with a context expression indicating when a UI should be selected.
- intents → intents from the user or any other system.
- tweaks → tweaks that are made to the mark-up before delivery to device, for example URL rewriting or dealing with device deficiencies.
Plugins
The bemoko live platform allows the use of scripting languages to rapidly pull data into your applications. For example the Groovy script below, which comes out-of-the-box and is ready for use in any site you create, demonstrates how you can load data from YAML file which your views can render.
import com.bemoko.live.platform.mwc.plugins.AbstractPlugin import org.ho.yaml.Yaml class readyaml extends AbstractPlugin { def root def filename void initialise( Map parameters){ filename = parameters.get("filepath") } void execute(Map parameters){ root =Yaml.load(new File(this.findResource(filename))) } Object get(String key){ return root[key] } }
PHP can also be used as your scripting language if you prefer.
Tweakers
Tweakers allow you to control how the page is changed before delivery to the user. In most cases the set of standard tweakers provided by the platform is sufficient and you may never have to create a tweaker, however this feature is made available to site developers to give the control if desired. This can be used for functionality such as URL rewriting or dealing with device deficiencies. The example below is the out-of-the box URL rewriter which you are free to use and / or customise to your needs.
import com.bemoko.live.platform.mwc.plugins.tweakers.AbstractTweakerPlugin import groovy.util.slurpersupport.GPathResult /* * Rewrite all URLs in the document */ class AbsoluteUrlRewriter extends AbstractTweakerPlugin { void tweakMarkup(GPathResult node){ def site=platformContext.site.name def context=platformContext.deploymentContext def intent=platformContext.site.getIntentByType("resource").name /* * closure to rewrite url */ def rewrite = { url,clazz -> def urlOut if (url =~ '^\\/') { if (clazz == "site") { // url is an absolute link to another site urlOut="$context" + url } else { // url is an absolute link urlOut="$context/$site" + url } } else { // url is a relative link urlOut = "$context/$site/$intent/" + url } return urlOut } /* * a tags - rewrite if href do not contain a ":" eg, javascript: http: ftp: etc */ node.'**'.grep{it.@href !=null && it.@href =~ '^[^:]+$'}.each { tag-> tag.@href=rewrite(tag.@href,tag.@class) } /* * img tags - rewrite conditions as with "a" tag */ node.'**'.grep{it.@src !=null && it.@src =~ '^[^:]+$'}.each { tag -> tag.@src = rewrite (tag.@src,tag.@class) } } }
Tweakers can be selected on a per-context basis, for example used only for a selection of devices. They can be configured in the site-config.xml as follows:
<tweaks> <tweaker plugin="AbsoluteUrlRewriter" /> <tweaker plugin="MyTweak" expr="device.value('xhtml_support_level')==0"/> </tweaks>
