| 
<?php
/*--------------------------------------------------------------*\
 * Copyright (C) 2006-2007 Anthony K Rogers [email protected]    *
 *--------------------------------------------------------------*
 * This file is part of RSSread. It gives an example of        *
 * implementing RSSread using both methods            *
 *--------------------------------------------------------------*
 * version 1.2                            *
 * copyright 2006                        *
 \*--------------------------------------------------------------*/
 
 require_once("rss_read.class.php");
 ?>
 <html>
 <head>
 <title>rssRead Test Page</title>
 <style type="text/css">
 <!--
 div.form{ text-align: center; }
 div.line{ padding: 2px 0px 3px 0px; }
 div.line div{ display: inline;}
 div.line div textarea{ vertical-align: text-top; }
 -->
 </style>
 <script type="text/javascript">
 <!--
 <?php
 /* Javascript for the form */
 ?>
 var exampleConfig = new Array();
 //Roganty's RSS feed - the one codded in the script
 exampleConfig[0] = new Array();
 exampleConfig[0][0] = "http://roganty.jubiiblog.co.uk/syndication.php?action=article"; //rssFeed
 exampleConfig[0][1] = 3; //numPosts
 exampleConfig[0][2] = "s"; //whichOne
 exampleConfig[0][3] = 3; //num[Sentences|Words|Chars]
 exampleConfig[0][4] = false; //stripLinks
 exampleConfig[0][5] = "_blank"; //postLinkTarget
 exampleConfig[0][6] = "<b>[title]<\/b>\r\n<p>[post]\r\n<font class=\"LinkReadMore\">[[link,target=_blank]read more[/link]]<\/font><\/p>\r\n"; //outputFormat
 exampleConfig[0][7] = "<hr width=\"65%\" />"; //joinOutputBy
 //BBC UK News RSS feed
 exampleConfig[1] = new Array();
 exampleConfig[1][0] = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/uk/rss.xml"; //rssFeed
 exampleConfig[1][1] = 5; //numPosts
 exampleConfig[1][2] = "n"; //whichOne
 exampleConfig[1][3] = -1; //num[Sentences|Words|Chars]
 exampleConfig[1][4] = true; //stripLinks
 exampleConfig[1][5] = "_blank"; //postLinkTarget
 exampleConfig[1][6] = "<div class=\"rssfeed\">[link,target=_blank][title][/link]\r\n<br />[post]<\/div>\r\n"; //outputFormat
 exampleConfig[1][7] = "<hr width=\"65%\" />"; //joinOutputBy
 
 function populateForm(whichEg){
 var egNum = ( whichEg == "roganty" ) ? 0 : 1; //roganty or bbc
 //alert(whichEg +":"+ egNum);
 for( var i = 1; i <= 7; i++ ){
 //loop through the thingy adding the data to the appropriate form element
 var elementType = document.confForm.elements[i].type;
 var elementName = document.confForm.elements[i].name;
 //alert(document.confForm.elements[i].value);
 //alert(document.confForm.elements[i].type);
 if( elementType == "select-one" ){
 if( elementName == "whichone" ){
 switch( exampleConfig[egNum][2] ){
 case "s" : document.confForm.elements[i].options[0].selected = true; break;
 case "w" : document.confForm.elements[i].options[1].selected = true; break;
 case "c" : document.confForm.elements[i].options[2].selected = true; break;
 case "n" : document.confForm.elements[i].options[3].selected = true; break;
 }
 }else
 if( elementName == "striplinks" ){
 if( exampleConfig[egNum][4] ) document.confForm.elements[i].options[0].selected = true;
 else
 if(! exampleConfig[egNum][4] ) document.confForm.elements[i].options[1].selected = true;
 }
 }else
 if( elementType == "text" || elementType == "textarea" ){
 document.confForm.elements[i].value = exampleConfig[egNum][i - 1];
 }
 }
 //now we need to submit the form
 document.confForm.submit();
 }
 
 //-->
 </script>
 </head>
 <body>
 <?php
 /* This is where we configure the output
 */
 
 //Configure? true or false
 $configure = ( isset($_POST["configure"]) ) ? $_POST["configure"]: false;
 $arrForm = array(); //array used for the form values
 
 //Call the class
 $RSSread = new RSSread($configure);
 /* If we didn't want the script to be configured we would type:
 * $RSSread = new RSSread(); -or-
 * $RSSread = new RSSread(false);
 * But if we did want to configure the script, type:
 * $RSSread = new RSSread(true);
 */
 
 if( $configure ){
 /* If true get the variables from the $_POST variable
 * This will be used for both setting the values in
 * the form and for configuring the script output
 */
 $RSSconf = array(); //The array used to configure the output
 $arrForm[0] = $_POST["rssfeed"];
 $arrForm[1] = $_POST["numposts"];
 $arrForm[2] = $_POST["whichone"];
 $arrForm[3] = $_POST["numlength"];
 $arrForm[4] = $_POST["striplinks"];
 $arrForm[5] = $_POST["postlinktarget"];
 $RSSconf["outputFormat"] = $_POST["outputformat"]; //script output variable
 $arrForm[6] = htmlspecialchars(stripslashes($_POST["outputformat"]));
 $RSSconf["joinOutputBy"] = $_POST["joinoutputby"]; //script output variable
 $arrForm[7] = htmlspecialchars(stripslashes($_POST["joinoutputby"]));
 }else
 if(! $configure ){
 /* If false grab the variables from the sript
 * This is used in displaying the appropriate
 * values in the form
 */
 $arrForm[0] = $RSSread->rssFeed;
 $arrForm[1] = $RSSread->numPosts;
 $arrForm[2] = $RSSread->whichOne;
 switch( $arrForm[2] ){
 case "s" : $arrForm[3] = $RSSread->numSentences; break;
 case "w" : $arrForm[3] = $RSSread->numWords; break;
 case "c" : $arrForm[3] = $RSSread->numChars; break;
 case "n" : $arrForm[3] = -1; break;
 }
 $arrForm[4] = ( $RSSread->stripLinks ) ? "y" : "n";
 $arrForm[5] = $RSSread->postLinkTarget;
 $arrForm[6] = htmlspecialchars(stripslashes($RSSread->outputFormat));
 $arrForm[7] = htmlspecialchars(stripslashes($RSSread->joinOutputBy));
 }
 
 
 if( $configure ){
 //This is where we configure the script output
 
 $RSSconf["rssFeed"] = $arrForm[0];
 $RSSconf["numPosts"] = $arrForm[1];
 $RSSconf["whichOne"] = $arrForm[2];
 $RSSconf["postLinkTarget"] = $arrForm[5];
 
 //which variable to change?
 switch( $arrForm[2] ){
 case "s" : $RSSconf["numSentences"] = $arrForm[3]; break;
 case "w" : $RSSconf["numWords"] = $arrForm[3]; break;
 case "c" : $RSSconf["numChars"] = $arrForm[3]; break;
 }
 $RSSconf["stripLinks"] = ( $arrForm[4] == "y" ) ? true : false;
 
 /* This is where we call the ScriptConfig function
 * passing it the array we have just built up
 * from the variables posted from the form
 */
 $RSSread->ScriptConfig($RSSconf);
 }
 
 /* The rest of the page below is just HTML
 * code and PHP code setting the form values
 */
 
 ?>
 <div id="main">
 <div id="mainTitle" style="text-align: center"><h1>rssRead<?=" v". $RSSread->RSSreadVersion; ?> Test Page</h1></div>
 <hr width="80%" />
 <div id="configTitle" style="text-align: center"><b>rssRead Configuration</b></div>
 <hr width="50%" />
 <div class="form">
 <form name="confForm" action="index.php" method="post">
 <input type="hidden" name="configure" value="true" />
 <div class="line" style="background-color: #cccccc">
 <div>The RSS Feed URL:<input type="text" size="35" name="rssfeed" value="<?=$arrForm[0]; ?>" /></div>
 <div>Number of posts to display:<input type="text" size="5" name="numposts" value="<?=$arrForm[1]; ?>" /></div>
 </div><div class="line" style="background-color: #999999">
 <div>How to shorten the posts:<select name="whichone">
 <option value="s"<?=( $arrForm[2] == "s" ) ? " selected=\"true\"" : "";?>>By Sentences</option>
 <option value="w"<?=( $arrForm[2] == "w" ) ? " selected=\"true\"" : "";?>>By Words</option>
 <option value="c"<?=( $arrForm[2] == "c" ) ? " selected=\"true\"" : "";?>>By Characters</option>
 <option value="n"<?=( $arrForm[2] == "n" ) ? " selected=\"true\"" : "";?>>No Shortening</option>
 </select></div>
 <div>Number of Sentences/Words/Characters to shorten to:<input type="text" size="5" name="numlength" value="<?=$arrForm[3]; ?>" /></div>
 </div><div class="line" style="background-color: #cccccc">
 <div>Remove links from RSS:<select name="striplinks">
 <option value="y"<?=( $arrForm[4] == "y" ) ? " selected=\"true\"" : "";?>>Yes</option>
 <option value="n"<?=( $arrForm[4] == "n" ) ? " selected=\"true\"" : "";?>>No</option>
 </select></div>
 <div>Target to open RSS post links in:<input type="text" size="25" name="postlinktarget" value="<?=$arrForm[5]; ?>" /></div>
 </div><div class="line" style="background-color: #999999">
 <div>The format to output the RSS posts in:<textarea cols="40" rows="3" name="outputformat"><?=$arrForm[6]; ?></textarea></div>
 </div><div class="line" style="background-color: #cccccc">
 <div>How to join the posts:<input type="text" size="30" name="joinoutputby" value="<?=$arrForm[7]; ?>" /></div>
 </div>
 <div><input type="submit" value="Submit" /><input type="reset" value="Reset" /></div>
 <hr width="50%" />
 <div>
 <input type="button" value="Roganty's RSS Feed" onclick="populateForm('roganty')" />
 <input type="button" value="BBC UK News RSS Feed" onclick="populateForm('bbc')" />
 </div>
 </form>
 </div>
 <hr width="80%" />
 <div id="outputTitle" style="text-align: center"><b>rssRead Output</b></div>
 <hr width="50%" />
 <div id="rssFeed"><?php
 /* This is where the magic happens!
 * we have now configured the output
 *
 * now we can print out the RSS feed
 */
 print $RSSread->RSSoutput();
 
 ?></div>
 <hr width="80%" />
 </div>
 </body>
 </html>
 |