A Service
Default values are stored in liveInfo.xml
-
<?xml version="1.0" encoding="UTF-8"?>
-
<liveInfo>
-
<liveInfoDir>/liveInfo</liveInfoDir>
-
<cssLink>http://yourdomain.com/liveInfo/css/liveInfo.css</cssLink>
-
<cacheTTL>3600</cacheTTL>
-
<liveInfoContainer>
-
<![CDATA[
-
<div id="[<infoName>][<opName>]_liveInfo" class="liveInfo">
-
<div id="[<infoName>][<opName>]_liveInfoStatus" class="liveInfoStatus">
-
<a href="javascript:void(0)" id="[<infoName>][<opName>]_liveInfoClose" class="liveInfoClose" onclick="[<infoName>][<opName>].hideLiveInfo();" title="Close">X</a>
-
<div id="[<infoName>][<opName>]_liveInfoPageControls" class="liveInfoPageControls">
-
<a id="[<infoName>][<opName>]_liveInfoNext" class="liveInfoNext" onclick="[<infoName>][<opName>].next()" title="Next results">»</a>
-
<a id="[<infoName>][<opName>]_liveInfoPrev" class="liveInfoPrev" onclick="[<infoName>][<opName>].previous();" title="Previous results">«</a>
-
</div>
-
<div id="[<infoName>][<opName>]_liveInfoTitle" class="liveInfoTitle">[<infoName>]</div><div id="[<infoName>][<opName>]_liveInfoStatusText" class="liveInfoStatusText"></div>
-
</div>
-
<div id="[<infoName>][<opName>]_liveInfoResults" class="liveInfoResults"></div>
-
</div>]]>
-
</liveInfoContainer>
-
</liveInfo>
The liveInfoDir points to the install directory of liveInfo. This is used by the js liveInfo object. The cacheTTL node defines the default time in seconds to cache the service. This can be overridden by a service. The cssLink points to the location of the default css stylesheet. This can also be overridden by a service. Also overrideable by a service is the liveInfoContainer node. This defines the HTML that is displayed when results are shown. The [<infoname>][<opname>] is used as placeholders and is replaced by the serviceName and opName in the final output on a page eg googleSearch. The structure of this node can change but note that the event handlers, id and class names should be the same. You should be able to add new elements also.
The google service xml looks like this:
-
<?xml version="1.0" encoding="UTF-8"?>
-
<liveInfoProvider>
-
<name>Google</name>
-
<description>you need a description?!</description>
-
<link>http://www.google.com</link>
-
<cacheTTL>3600</cacheTTL>
-
<key>Use your own google key</key>
-
<q></q>
-
<start></start>
-
<maxResults>10</maxResults>
-
<filter>true</filter>
-
<safeSearch>false</safeSearch>
-
<restrict></restrict>
-
<lr></lr>
-
<liveInfoOperations>
-
<liveInfoOperation>
-
<liveInfoOperationName>Search</liveInfoOperationName>
-
<liveInfoDescription>Get Search Results</liveInfoDescription>
-
<client>
-
<liveInfoForm>
-
<![CDATA[<form onsubmit="return [<infoName>][<opName>].submit()" id="[<infoName>][<opName>]_liveInfoForm" class="[<infoName>][<opName>]_liveInfoForm" method="get" action="./">
-
<input type="text" id="googlesearch" size="15" onkeypress="[<infoName>][<opName>].execute()" />
-
</form>]]>
-
</liveInfoForm>
-
<liveInfoJS>
-
<![CDATA[
-
[<infoName>][<opName>]= new liveInfo("[<liveInfoURL>]","[<infoName>]","[<opName>]","googlesearch");
-
[<infoName>][<opName>].init();
-
]]>
-
</liveInfoJS>
-
<cssLink>http://yourdomain.com/css/googleLiveInfo.css</cssLink>
-
</client>
-
</liveInfoOperation>
-
</liveInfoOperations>
-
</liveInfoProvider>
The name, description and link nodes are there for informational purposes about the service. On line 6 we can see that this service is set to cache for only 15 mins. The key, q, lr, start, maxresults, filter, safesearch and restrict nodes are google webservice parameters. If a service needs service specific config values, they can be defined here in the xml and the service will pick it up.
Now every service has at least one operation. Here we define one called search. Google's webservice also provides a spelling operation. If we wanted to, we would have another liveOperation node which defines the information needed for that operation. The important nodes here are the liveInfoOperationName and the client nodes. The liveInfoOperationName identifies the operation and is used by the liveInfoManager to load up the correct service operation. The client node has a liveInfoForm node which is where the form for the service is defined. To note here is the keypress event handler event for the element that is to trigger the liveInfo. This event can be used on other elements if the form has more than one element. The liveInfoJS node contains the javascript code to create the liveInfo js object. Any parameters or customisation is set here. See the Javascript section for more information. Finally the cssLink node defines the link to the stylesheet for this service.
It's possible that a form element is dynamic. For instance, a select element's options are loaded from the database. In this case, we can specify a method to call which will output the element. To do this we put the following in the relevant place. An example
-
<opCall>getDays</opCall>
When the service encounters the node, it calls the getDays method and inserts the return value in the form
The PHP
An abstract class called liveInfo defines the interface which any service must implement. It also provides some helper methods for outputting xml, debug info and caching methods. The constructor looks like this.
-
class googleLiveInfo extends soapLiveInfo {
-
var $serviceName = "google";
-
-
function googleLiveInfo($opName=null) {
-
parent::soapLiveInfo();
-
$this->opName = $opName;
-
parent::initialise();
-
}
The Google webservice is a soap service. Besides the liveInfo abstract class, the liveInfo framework is supplied with two subclasses called rpcLiveInfo and soapLiveInfo. These subclasses include the required library for using XMLRPC or SOAP. So if your service uses XMLRPC or SOAP you should subclass one of these methods. If not, then you should just subclass the liveInfo class. Its important that you do this and call the parent constuctor (see line 5). Calling the parent constructor, loads the default liveInfo.xml then calling the initialise() method, loads the service's xml file initialising the object with the data in the xml file
-
function getLiveInfo($query) {
-
if ($this->debug)
-
$this->dumpVariable('RECEIVED QUERY PARAMS: ',$query);
-
# Set google parameters
-
'key'=>$this->key,
-
'q' => $query['googlesearch'],
-
'start' => '0',
-
'maxResults' => '10',
-
'filter' => $this->filter,
-
-
'restrict' => $this->restrict,
-
'safeSearch' => $this->safeSearch,
-
'lr' => $this->lr,
-
);
-
$cache = $this->getCache($this->serviceName.$this->opName);
-
switch($this->opName) {
-
case "Search":
-
//if not using a cache use this line
-
// $result = $this->getSearch($parameters);
-
break;
-
}
-
if ($this->debug) {
-
$this->dumpVariable('LIVEINFO RESULT (XML) : ',$result);
-
}
-
if($this->debug)
-
return $this->packageResult($this->packageDebug($this->debugStr).$result);
-
else return $this->packageResult($result);
-
}
When a request from a liveInfo page element, its the getLiveInfo that is called. If cache is needed we get a cache object by calling the getCache method, then we call the getSearch method via the cache object' call method. If a cache is not needed, then we would just call the getSearch method directly. Then the results are packaged for return. Note also debug data is also added if debug mode is on. The getSearch method sets up the SOAP call, contacts the webservice and passes the results to the renderResults method which returns them nicely formated into an unordered list.
-
function renderResults($results) {
-
if ($this->debug)
-
$this->dumpVariable('LIVEINFO RESULTS (RAW) : ',$results);
-
$channels = $results;
-
$html ='<ul class="liveResults">';
-
foreach ( $results['resultElements'] as $result ) {
-
$title = $result['title'] ? $result['title'] : 'no title';
-
//opera 7 has problems with brs in snippet field (??)
-
$html .='<li class="liveInfoItem"><a href="'.$result["URL"].'" target="_blank" title="'.$url.'"><strong>'.$title.'</strong><br />'.$snippet.'</a></li>';
-
}
-
$html.="</ul>";
-
return $html;
-
}
The resulting document for a search for "news" looks like this : (debug mode turned off)
-
<?xml version="1.0" encoding="UTF-8"?>
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
-
<liveInfo>
-
<liveInfoResult id="liveInfoResult">
-
<ul class="liveResults"><li class="liveInfoItem"><a href="http://www.cnn.com/" target="_blank" title="http://www.cnn.com/"><strong>CNN.com</strong><br /><b>...</b> MORE <b>NEWS</b>, Most Popular. <b>...</b> BUSINESS at CNN/Money, Business <b>News</b>. STOCK/FUND QUOTES: enter symbol. MARKETS: 5:16pm ET, 02/03. DJIA, -3.69, 10,593.10, -0.03. <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://news.bbc.co.uk/" target="_blank" title="http://news.bbc.co.uk/"><strong>BBC <b>NEWS</b> | <b>News</b> Front Page</strong><br />Visit BBC <b>News</b> for up-to-the-minute <b>news</b>, breaking <b>news</b>, video, audio and feature stories. BBC <b>News</b> provides trusted World and UK <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://www.foxnews.com/" target="_blank" title="http://www.foxnews.com/"><strong>FOXNews.com</strong><br /><b>...</b> Jacko Talks Neverland. Michael Jackson tells FOX <b>News</b> about the 'bliss' of his home, says he's a target. LATEST HEADLINES. ONLY ON FOX. <b>...</b> FOX <b>NEWS</b> 24/7. <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://abcnews.go.com/" target="_blank" title="http://abcnews.go.com/"><strong>ABC <b>News</b>: Online <b>news</b>, breaking <b>news</b>, feature stories and more</strong><br />ABC <b>News</b> HomeABC <b>News</b> Home. February 3, 2005 | Get Your Local <b>News</b> and Weather. Search ABC <b>News</b> Search the Web. <b>...</b> ABC <b>News</b> Now. View Schedule. Subscribe Now <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://news.google.com/" target="_blank" title="http://news.google.com/"><strong>Google <b>News</b></strong><br />Google <b>News</b>. <b>...</b> Rudy T Runs Himself Out of LA WOAI Los Angeles Daily <b>News</b> - Xinhua - WTNH - People's Daily Online - all 1,228 related ? BBC Sport. <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://www.cbsnews.com/" target="_blank" title="http://www.cbsnews.com/"><strong>CBSNews.com</strong><br />Home US Iraq World Politics SciTech HealthWatch Entertainment New: Business Opinion FREE CBS <b>News</b> Video. CBSNews.com, <b>...</b> All Evening <b>News</b>, All Early Show. <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://news.yahoo.com/" target="_blank" title="http://news.yahoo.com/"><strong>Yahoo! <b>News</b> - Front Page</strong><br />Personalize <b>News</b> Home Page. Yahoo! <b>News</b> Thu, Feb 03, 2005, <b>...</b> Reuters Video, Stocks Edge Lower; Amazon Weighs (Reuters Video). <b>News</b> via RSS. Top <b>News</b>. Top Stories. <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://www.wired.com/" target="_blank" title="http://www.wired.com/"><strong>Wired <b>News</b></strong><br />Read our design notes for details. Welcome to Wired <b>News</b>. Skip <b>...</b> Advertisement. updated 2:00 am Feb. 3, 2005 PT <b>News</b> Archive. Peekaboo <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://www.msnbc.msn.com/" target="_blank" title="http://www.msnbc.msn.com/"><strong>MSNBC - MSNBC Front Page</strong><br /><b>...</b> MSNBC <b>News</b>, Alerts | Newsletters | RSS | Help, MSNBC Home. MSNBC TV. <b>News</b>. Business. Sports. Entertainment. Tech / Science. Weather. Health. Travel. Blogs Etc. <b>...</b> </a></li>
-
<li class="liveInfoItem"><a href="http://www.usnews.com/usnews/home.htm" target="_blank" title="http://www.usnews.com/usnews/home.htm"><strong>USNews.com: Home</strong><br /><b>...</b> dietary guidelines Best Hospitals: Top medical centers Honor Roll: 14 excellent hospitals Find a hospital: Comprehensive directory Heart Guide: <b>News</b> and tools <b>...</b> </a></li>
-
</ul>
-
</liveInfoResult>
-
</liveInfo>
-
</html>
If there were no results, the liveInfoResult would be replaced by a liveInfoNoResult node. If there was a fault of some sort, then the liveInfoResult node would be replaced by a liveInfoFault node.
Debugging
If debugging is turned on, then liveInfo outputs the debug output that is received form the server to an element that is identified by the id of serviceName+opName+_liveInfoDebug giving (for wordpress search) wordpressSearch_liveInfoDebug. You can also do some direct checking by inserting the liveInfo url into your browser with the required parameters. For example, for wordpress, the url would be [path to liveInfo]/liveInfo/liveInfo.php?liveInfo=wordpress&opName=Search&s=rpc
Todo:
Streamline debug
Make install easier with less or ideally no editing of xml files needed