Datasheet

populateChart($watchRow);
populateFinancialNews($watchRow);
populateDelicious($watchRow);
// Send the result
header(“Cache-Control: max-age=60”);
header(“Content-type: text/html”);
print $document->saveXML();
The validation of the document is necessary for libxml2, the XML parser on which PHP5 relies, if you
want to be able to get elements by their identifiers.
Like their JavaScript equivalents, the functions that populate the panels receive their data as XML. They
could get this XML accessing the web server locally through HTTP. However, you can save the server
the extra load of a full HTTP request for each panel when the page is created by exposing the XML
cached document through PHP functions. Following this principle, the function that populates the
quotes panel in
index.php is:
function populateQuotes($watchRow) {
global $document;
if (!$watchRow) {
return;
}
$quote = simplexml_load_string(
get_cached_data(
getUrlQuotes($watchRow[‘symbol’]),
get_quotes_as_xml,
YAHOOFINANCE_QUOTES_LIFETIME
)
);
setValue(‘yahoofinance.quotes.title’, “Quotes ({$quote->name})”);
setValue(‘yahoofinance.quotes.last_price’, $quote->lastTrade->price);
setValue(‘yahoofinance.quotes.last_time’,
“{$quote->lastTrade->time} EST ({$quote->lastTrade->date})” );
setValue(‘yahoofinance.quotes.change’, $quote->change);
setValue(‘yahoofinance.quotes.open’, $quote->open);
setValue(‘yahoofinance.quotes.high’, $quote->high);
setValue(‘yahoofinance.quotes.low’, $quote->low);
setValue(‘yahoofinance.quotes.volume’, $quote->volume);
}
This function is very similar to the JavaScript method that refreshes the panel client side in panel.js:
YAHOO.buzzWatch.panels[“yahoofinance.quotes”].callback[“success”] = function(o) {
if(o.responseText !== undefined){
this.isEmpty = false;
this.setTimeout(getMaxAge(o));
var xotree = new XML.ObjTree();
var tree = xotree.parseDOM( o.responseXML.documentElement );
if (tree.quote.name != undefined) {
setValue(‘yahoofinance.quotes.title’, “Quotes (“+tree.quote.name+”)”);
setValue(‘yahoofinance.quotes.last_price’, tree.quote.lastTrade.price);
setValue(‘yahoofinance.quotes.last_time’,
tree.quote.lastTrade.time + “ EST (“ + tree.quote.lastTrade.date +”)” );
setValue(‘yahoofinance.quotes.change’, tree.quote.change);
27
Hello Web 2.0 World
04_087889 ch01.qxp 5/2/07 12:56 PM Page 27