I'm having some difficulty getting this script to execute properly.
The create_rss function does not create the RSS file when the remote function updateStatus is called.
<?php
define("DB_HOST", "localhost");
define("DB_USER", "user");
define("DB_PASS", "pass");
define("DB_NAME", "db_test");
class updateService
{
function updateService()
{
$this->methodTable = array(
"updateStatus" => array(
"description" => "Retrieve RSS Info",
"arguments" => array("info"),
"access" => "remote"
),
"create_rss" => array(
"description" => "Create RSS",
"arguments" => array("id"),
"access" => "private"
)
);
//Connect to MySQL and select database
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
$db = mysql_select_db(DB_NAME);
}
/**
* Update Status
* @access remote
*/
//$info contains the integer site id...
function updateStatus($info)
{
create_rss(4);
}
function create_rss($id)
{
$xml = '<?xml version="1.0" encoding="ISO-8859-1" ?><rss version="2.0">' . "\r\n";
$xml .= "\t\t" . "<channel>" . "\n\r";
$xml .= "\t\t\t" . "<title>Website Feed</title>" . "\n\r";
$xml .= "\t\t\t" . "<link>http://website.com</link>" . "\n\r";
$xml .= "\t\t\t" . "<description>Website Design</description>" . "\n\r";
switch ($id)
{
case 1:
$site_name = 'MyTestWebsite';
$site_link = 'http://www.website.com';
break;
case 2:
$site_name = 'TestWebsite';
$link = 'http://website.com/?q=1&g=2';
$site_link = htmlspecialchars($link);
break;
default:
break;
}
$sql = "SELECT * FROM table1 WHERE site_id = '$id'
LIMIT 30";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$timestamp = $row['timestamp'];
$xml .= "\t\t" . "<item>" . "\n\r";
$xml .= "\t\t\t" . "<title>" . $site_name . " Activity</title>" . "\n\r";
$xml .= "\t\t\t" . "<link>" . $site_link . "</link>" . "\n\r";
$xml .= "\t\t\t" . '<description><![CDATA[<p><b>Timestamp: ' . $timestamp . '</b></p>]]>' . "\n\r";
$xml .= "\t\t" . "</item>" . "\n\r";
}
$xml .= "\t" . "</channel>" . "\n\r" . "</rss>";
//create xml file
$rssfile_path = 'feed/' . $site_name . '.xml';
chmod($rssfile_path, 0777);
$file = $_SERVER['DOCUMENT_ROOT'] . $rssfile_path;
if (!$file_handle = fopen($file, "w"))
{
//print "<br>Cannot open XML document:<br>";
}
elseif (!fwrite($file_handle, $xml))
{
//print "<br>Cannot write to XML document:<br>";
}
else
{
//print "<br>Successfully created XML document:<br>";
}
fclose($file_handle);
}
}
?>