cvs: pecl /sdo/scenarios/ajax-rss README rss.xsd sdoajax.php welcome.php

From: Date: Mon, 02 Oct 2006 13:06:44 +0000
Subject: cvs: pecl /sdo/scenarios/ajax-rss README rss.xsd sdoajax.php welcome.php
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-6443@lists.php.net to get a copy of this message
slaws Mon Oct 2 13:06:44 2006 UTC Added files: /pecl/sdo/scenarios/ajax-rss sdoajax.php README rss.xsd welcome.php Log: A sample that shows how SDO can be used, along with JSON formatted messages, in an AJAX style application. This makes use of the very simple JSON DAS implementation the PECL JSON extension.

http://cvs.php.net/viewvc.cgi/pecl/sdo/scenarios/ajax-rss/sdoajax.php?view=markup&rev=1.1 Index: pecl/sdo/scenarios/ajax-rss/sdoajax.php +++ pecl/sdo/scenarios/ajax-rss/sdoajax.php <?php /* +----------------------------------------------------------------------+ | (c) Copyright IBM Corporation 2006. | | All Rights Reserved. | +----------------------------------------------------------------------+ | | | Licensed under the Apache License, Version 2.0 (the "License"); you | | may not use this file except in compliance with the License. You may | | obtain a copy of the License at | | http://www.apache.org/licenses/LICENSE-2.0 | | | | Unless required by applicable law or agreed to in writing, software | | distributed under the License is distributed on an "AS IS" BASIS, | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ | Author: SL | +----------------------------------------------------------------------+ $Id: sdoajax.php,v 1.1 2006/10/02 13:06:44 slaws Exp $ */ require_once "SDO/DAS/json.php"; try { // create a json das, we'll need one later $jsonDas = new SDO_DAS_Json(); // get the rss feed as an SDO object $feedurl = $_POST['feedurl']; $xmldas = SDO_DAS_XML::create('./rss.xsd'); $xmldoc = $xmldas->loadFile($feedurl); $rss = $xmldoc->getRootDataObject(); // get the object representing the contents of the <div/> element // in the browser $objectString = $_POST['object']; $item = null; // do something special if this is the first time through here if ( $objectString == "NoItem" ) { // this is the first request so read the first item try { $item = $rss["channel/item[1]"]; } catch ( Exception $e ) { // there are no items so $item will remain null. } } else { // and item has already been read and passed back into us // reconstitute the object sent from the browser $currentItem = $jsonDas->decode($objectString); // get the title from the object $title = $currentItem["title"]; // find the next sibling of the item that matches the title $matchfound = false; foreach ( $rss->channel->item as $rssitem ) { if ( $matchfound == true ) { $item = $rssitem; break; } if ( $rssitem->title == $title ) { $matchfound = true; } } } if ( $item == null ) { $item = "No items in feed"; } echo $jsonDas->encode($item); } catch ( Exception $e ) { echo "Caught exception: \n"; print_r($e); } ?> http://cvs.php.net/viewvc.cgi/pecl/sdo/scenarios/ajax-rss/rss.xsd?view=markup&rev=1.1 Index: pecl/sdo/scenarios/ajax-rss/rss.xsd +++ pecl/sdo/scenarios/ajax-rss/rss.xsd <?xml version="1.0" encoding="utf-8" ?> <xs:schema version="1.1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="rss"> <xs:complexType> <xs:attribute name="version" default="2.0" /> <xs:sequence> <xs:element name="channel" type="channel" /> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="channel"> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="link" type="xs:string"/> <xs:element name="description" type="xs:string"/> <xs:element name="copyright" type="xs:string"/> <xs:element name="language" type="xs:string"/> <xs:element name="webMaster" type="xs:string"/> <xs:element name="lastBuildDate" type="xs:string"/> <xs:element name="pubDate" type="xs:string"/> <xs:element name="ttl" type="xs:string"/> <xs:element name="item" type="item" minOccurs="0" maxOccurs="unbounded" /> <xs:any namespace="##any"/> </xs:sequence> </xs:complexType> <xs:complexType name="item"> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="link" type="xs:string"/> <xs:element name="description" type="xs:string"/> <xs:element name="guid" type="guid"/> <xs:element name="pubDate" type="xs:string"/> <xs:element name="enclosure" type="enclosure"/> </xs:sequence> </xs:complexType> <xs:complexType name="guid"> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="isPermaLink" use="optional" type="xs:boolean"/> </xs:extension> </xs:simpleContent> </xs:complexType> <xs:complexType name="enclosure"> <xs:attribute name="url" type="xs:string"/> <xs:attribute name="length" type="xs:positiveInteger"/> <xs:attribute name="type" type="xs:string"/> </xs:complexType> </xs:schema> http://cvs.php.net/viewvc.cgi/pecl/sdo/scenarios/ajax-rss/welcome.php?view=markup&rev=1.1 Index: pecl/sdo/scenarios/ajax-rss/welcome.php +++ pecl/sdo/scenarios/ajax-rss/welcome.php <html> <!-- +----------------------------------------------------------------------+ | (c) Copyright IBM Corporation 2006. | | All Rights Reserved. | +----------------------------------------------------------------------+ | | | Licensed under the Apache License, Version 2.0 (the "License"); you | | may not use this file except in compliance with the License. You may | | obtain a copy of the License at | | http://www.apache.org/licenses/LICENSE-2.0 | | | | Unless required by applicable law or agreed to in writing, software | | distributed under the License is distributed on an "AS IS" BASIS, | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | | implied. See the License for the specific language governing | | permissions and limitations under the License. | +----------------------------------------------------------------------+ | Author: SL | +----------------------------------------------------------------------+ $Id: welcome.php,v 1.1 2006/10/02 13:06:44 slaws Exp $ --> <head> <title>The SDO AJAX Sample</title> </head> <body BGCOLOR="#EFEFEF"> <?php define('AJAX_SERVER', 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '/ajax-rss/sdoajax.php'); ?> <script type="text/javascript"> var request; var object; /** * Called when the response from XMLHttpRequest.send * is ready for processing */ function handleResponse () { if ( request.readyState == 4 ) { if ( request.status == 200 ) { var responseText = request.responseText; document.getElementById('jsonString').innerHTML=responseText; } else { alert("The request didn't work " + request.status); } } } /** * Called when the "Get Item" button is pressed. * Makes a call to the server to retrieve the next * item from the RSS feed */ function getItem () { var inputfield = document.getElementById("feedurl").value; var objectString = document.getElementById("jsonString").innerHTML; request = new XMLHttpRequest (); request.onreadystatechange = handleResponse; request.open("POST", "<?php echo AJAX_SERVER ?>", true); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); request.send("feedurl=" + inputfield + "&object=" + objectString); } </script> URL of RSS feed: <input type="text" id="feedurl" size="80" value="http://www.mail-archive.com/tuscany-dev%40ws.apache.org/maillist.xml"/> <p/> <input type="button" value="Get Item" onclick="getItem()"/> <p/> RSS Item: <div id="jsonString">NoItem</div> </body> </html>
« previous php.pecl.cvs (#6443) next »