Skip to content

Commit

Permalink
update db queries used in creation of rss feeds; improve date formatt…
Browse files Browse the repository at this point in the history
…ing; remove some duplication

git-svn-id: https://xerteonlinetoolkits.googlecode.com/svn/trunk@123 912cdd6b-5c7d-d5a7-a2ba-d0f0cdb91641
  • Loading branch information
Dave Goodwin committed Oct 3, 2011
1 parent a5ec7a1 commit 35a916b
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 194 deletions.
261 changes: 123 additions & 138 deletions rss.php
@@ -1,140 +1,125 @@
<?PHP

header("Content-Type: application/xml; charset=ISO-8859-1");

require "config.php";

include $xerte_toolkits_site->php_library_path . "database_library.php";
include $xerte_toolkits_site->php_library_path . "url_library.php";

function normal_date($string){

$temp = explode("-", $string);
return $temp[2] . "/" . $temp[1] . "/" . $temp[0];

}

$database_id = database_connect("rss page.php database connect success worked","rss failed");

$query_modifier = "rss";

$action_modifder = "play";

if(isset($_GET['export'])){

$query_modifier = "export";

$action_modifder = "export";

}

if(!isset($_GET['username'])){

/*
* Change this to reflect site settings
*/

echo "<rss version=\"2.0\"><channel><title>" . $xerte_toolkits_site->name . "</title><link>" . $xerte_toolkits_site->site_url . "</link><description>A feed containing all the public learning objects from " . $xerte_toolkits_site->name . "</description><language>en-gb</language><image><title>" . $xerte_toolkits_site->name . "</title><url>" . $xerte_toolkits_site->site_url . "website_code/images/xerteLogo.jpg</url><link>" . $xerte_toolkits_site->site_url . "</link></image>";

}else{

if(!$database_id){

die("Sorry, the system cannot connect to the database at present. The mysql error is " . mysql_error() );

}

$temp_array = explode("_",mysql_real_escape_string($_GET['username']));

$query_created_by = "select login_id from " . $xerte_toolkits_site->database_table_prefix . "logindetails where (firstname=\"" . $temp_array[0] . "\" AND surname =\"" . $temp_array[1] . "\")";

$query_create = mysql_query($query_created_by);

if(mysql_num_rows($query_create)==0){

header("HTTP/1.0 404 Not Found");

}else{

if(!isset($_GET['folder_name'])){

echo "<rss version=\"2.0\"><channel><title>" . $temp_array[0] . " " . $temp_array[1] . "'s Learning Objects - " . $xerte_toolkits_site->name . "</title><link>" . $xerte_toolkits_site->site_url . "</link><description>A feed containing all of " . $temp_array[0] . " " . $temp_array[1] . "'s public learning objects from the " . $xerte_toolkits_site->name . "</description><language>en-gb</language><image><title>" . $xerte_toolkits_site->rss_title . "</title><url>" . $xerte_toolkits_site->site_url . "website_code/images/xerteLogo.jpg</url><link>" . $xerte_toolkits_site->site_url . "</link></image>";

}else{

echo "<rss version=\"2.0\"><channel><title>" . $temp_array[0] . " " . $temp_array[1] . "'s Learning Objects - " . str_replace("_"," ",$_GET['folder_name']) . " - " . $xerte_toolkits_site->name . "</title><link>" . $xerte_toolkits_site->site_url . "</link><description>A feed containing all of " . $temp_array[0] . " " . $temp_array[1] . "'s learning objects - " . str_replace("_"," ",$_GET['folder_name']) . " from the " . $xerte_toolkits_site->name . "'s site</description><language>en-gb</language><image><title>" . $xerte_toolkits_site->rss_title . "</title><url>" . $xerte_toolkits_site->site_url . "/website_code/images/xerteLogo.jpg</url><link>" . $xerte_toolkits_site->site_url . "</link></image>";

}

$row_create = mysql_fetch_array($query_create);

}


}


if(!isset($_GET['username'])){

$query = "select " . $xerte_toolkits_site->database_table_prefix . "templatedetails.template_id,creator_id,date_created,template_name,description from " . $xerte_toolkits_site->database_table_prefix . "templatedetails, " . $xerte_toolkits_site->database_table_prefix . "templatesyndication where " . $query_modifier . "=\"true\" and " . $xerte_toolkits_site->database_table_prefix . "templatedetails.template_id = " . $xerte_toolkits_site->database_table_prefix . "templatesyndication.template_id";

}else{

if(!isset($_GET['folder_name'])){

$query = "select " . $xerte_toolkits_site->database_table_prefix . "templatedetails.template_id,creator_id,date_created,template_name,description from " . $xerte_toolkits_site->database_table_prefix . "templatedetails, " . $xerte_toolkits_site->database_table_prefix . "templatesyndication where " . $query_modifier . "=\"true\" AND creator_id=\"" . $row_create['login_id'] . "\" and " . $xerte_toolkits_site->database_table_prefix . "templatedetails.template_id = " . $xerte_toolkits_site->database_table_prefix . "templatesyndication.template_id";

}else{

$query_folder = "select folder_id from " . $xerte_toolkits_site->database_table_prefix . "folderdetails where folder_name=\"" . str_replace("_", " ",mysql_real_escape_string($_GET['folder_name'])) . "\"";

$query_folder_response = mysql_query($query_folder);

$row_folder = mysql_fetch_array($query_folder_response);

$query = "select * from " . $xerte_toolkits_site->database_table_prefix . "templaterights, " . $xerte_toolkits_site->database_table_prefix . "templatedetails, " . $xerte_toolkits_site->database_table_prefix . "templatesyndication where folder = \"" . $row_folder['folder_id'] . "\" and " . $xerte_toolkits_site->database_table_prefix . "templaterights.template_id = " . $xerte_toolkits_site->database_table_prefix . "templatedetails.template_id and " . $xerte_toolkits_site->database_table_prefix . "templatesyndication.template_id = " . $xerte_toolkits_site->database_table_prefix . "templaterights.template_id and rss = \"true\"";

//$query = "select " . $xerte_toolkits_site->database_table_prefix . "templatedetails.template_id,creator_id,template_name,folder,description from " . $xerte_toolkits_site->database_table_prefix . "templatedetails," . $xerte_toolkits_site->database_table_prefix . "templaterights," . $xerte_toolkits_site->database_table_prefix . "templatesyndication where " . $query_modifier . "=\"true\" AND creator_id=\"" . $row_create['login_id'] . "\" and " . $xerte_toolkits_site->database_table_prefix . "templaterights.template_id = " . $xerte_toolkits_site->database_table_prefix . "templatedetails.template_id and folder_id=\"" . $row_folder['folder_id'] . "\"";

}

}

$query_response = mysql_query($query);

while($row = mysql_fetch_array($query_response)){

if(!isset($_GET['username'])){

$query_creator = "select firstname,surname from " . $xerte_toolkits_site->database_table_prefix . "logindetails where login_id=\"" . $row['creator_id'] . "\"";

$query_creator_response = mysql_query($query_creator);

$row_creator = mysql_fetch_array($query_creator_response);

$user = $row_creator['firstname'] . " " . $row_creator['surname'];

}else{

$user = $temp_array[0] . " " . $temp_array[1];

}

if(isset($_GET['export'])){

echo "<item><title>" . str_replace("_"," ",$row['template_name']) . "</title><link><![CDATA[" . $xerte_toolkits_site->site_url . url_return("export", $row['template_id']) . "]]></link><description><![CDATA[" . $row['description'] . "<br><br>" . str_replace("_"," ",$row['template_name']) . " was developed by " . $user . "]]></description><pubDate>" . date('D, d M Y', strtotime($row['date_created'])) . " 12:00:00 GMT</pubDate><guid><![CDATA[" . $xerte_toolkits_site->site_url . url_return("export", $row['template_id']) . "]]></guid></item>";

}else{

echo "<item><title>" . str_replace("_"," ",$row['template_name']) . "</title><link><![CDATA[" . $xerte_toolkits_site->site_url . url_return("play", $row['template_id']) . "]]></link><description><![CDATA[" . $row['description'] . "<br><br>" . str_replace("_"," ",$row['template_name']) . " was developed by " . $user . "]]></description><pubDate>" . date('D, d M Y', strtotime($row['date_created'])) . " 12:00:00 GMT</pubDate><guid><![CDATA[" . $xerte_toolkits_site->site_url . url_return("play", $row['template_id']) . "]]></guid></item>";


}

}

echo "</channel></rss>";

mysql_close($database_id);

?>
header("Content-Type: application/xml; charset=ISO-8859-1");

require_once "config.php";

include $xerte_toolkits_site->php_library_path . "database_library.php";
include $xerte_toolkits_site->php_library_path . "url_library.php";

function normal_date($string){
$temp = explode("-", $string);
return $temp[2] . "/" . $temp[1] . "/" . $temp[0];
}

$query_modifier = "rss";
$action_modifder = "play";

if(isset($_GET['export'])){
$query_modifier = "export";
$action_modifder = "export";
}

if(!isset($_GET['username'])){

/*
* Change this to reflect site settings
*/

echo "<rss version=\"2.0\">
<channel><title>{$xerte_toolkits_site->name}</title>
<link>{$xerte_toolkits_site->site_url}</link>
<description>A feed containing all the public learning objects from {$xerte_toolkits_site->name}</description>
<language>en-gb</language>
<image><title>{$xerte_toolkits_site->name}</title>
<url>{$xerte_toolkits_site->site_url}website_code/images/xerteLogo.jpg</url>
<link>{$xerte_toolkits_site->site_url}</link></image>";

}else{
$temp_array = explode("_",$_GET['username']);

$query_created_by = "select login_id from {$xerte_toolkits_site->database_table_prefix}logindetails where (firstname=? AND surname = ?)";
$rows = db_query($query_created_by, array($temp_array[0], $temp_array[1]));

if(sizeof($rows) == 0) {
header("HTTP/1.0 404 Not Found");
exit(0);
}else{
$folder_string = 'public';
if(isset($_GET['folder_name'])){
$folder_string = " - " . _html_escape(str_replace("_", " ", $_GET['folder_name']));
}
echo "<rss version=\"2.0\"><channel>
<title>" . _html_escape($temp_array[0]) . " " . _html_escape($temp_array[1]) . "'s Learning Objects - {$xerte_toolkits_site->name}</title>
<link>{$xerte_toolkits_site->site_url}</link>
<description>A feed containing all of " . _html_escape($temp_array[0]) . " " . _html_escape($temp_array[1]) . "'s {$folder_string} learning objects learning objects from the {$xerte_toolkits_site->name}</description>
<language>en-gb</language>
<image>
<title>{$xerte_toolkits_site->rss_title}</title>
<url>{$xerte_toolkits_site->site_url}website_code/images/xerteLogo.jpg</url>
<link>{$xerte_toolkits_site->site_url}</link></image>";
$row_create = $rows[1];
}
}

$params = array();

if(!isset($_GET['username'])){
$query = "select {$xerte_toolkits_site->database_table_prefix}templatedetails.template_id,creator_id,date_created,template_name,description
FROM {$xerte_toolkits_site->database_table_prefix}templatedetails, {$xerte_toolkits_site->database_table_prefix}templatesyndication
WHERE $query_modifier='true' AND {$xerte_toolkits_site->database_table_prefix}templatedetails.template_id = {$xerte_toolkits_site->database_table_prefix}templatesyndication.template_id";

}else{
if(!isset($_GET['folder_name'])){
$query = "select {$xerte_toolkits_site->database_table_prefix}templatedetails.template_id,creator_id,date_created,template_name,description
FROM {$xerte_toolkits_site->database_table_prefix}templatedetails, {$xerte_toolkits_site->database_table_prefix}templatesyndication
WHERE $query_modifier='true' AND creator_id=? AND {$xerte_toolkits_site->database_table_prefix}templatedetails.template_id = {$xerte_toolkits_site->database_table_prefix}templatesyndication.template_id";
$params[] = $row_create['login_id'];
}else{
$row_folder = db_query_one("SELECT folder_id FROM {$xerte_toolkits_site->database_table_prefix}folderdetails WHERE folder_name = ?", array(str_replace("_", " ", $_GET['folder_name'])));

if(empty($row_folder)) {
die("Invalid folder name");
}

$query = "select * from {$xerte_toolkits_site->database_table_prefix}templaterights, {$xerte_toolkits_site->database_table_prefix}templatedetails, {$xerte_toolkits_site->database_table_prefix}templatesyndication
WHERE folder = ?
AND {$xerte_toolkits_site->database_table_prefix}templaterights.template_id = {$xerte_toolkits_site->database_table_prefix}templatedetails.template_id
AND {$xerte_toolkits_site->database_table_prefix}templatesyndication.template_id = {$xerte_toolkits_site->database_table_prefix}templaterights.template_id and rss = 'true'";
$params[] = $row_folder['folder_id'];
}

}

$rows = db_query($query, $params);

foreach($rows as $row) {

if(!isset($_GET['username'])){
$row_creator = db_query_one("SELECT firstname,surname from {$xerte_toolkits_site->database_table_prefix}logindetails where login_id=?", array($row['creator_id']));
$user = $row_creator['firstname'] . " " . $row_creator['surname'];
}else{
// revert back to $_GET['usenrame'] parsed value(s)
$user = $temp_array[0] . " " . $temp_array[1];
}

$action = 'play';
if(isset($_GET['export'])){
$action = 'export';
}
echo "<item>
<title>" . str_replace("_"," ",$row['template_name']) . "</title>
<link><![CDATA[" . $xerte_toolkits_site->site_url . url_return($action, $row['template_id']) . "]]></link>
<description><![CDATA[" . $row['description'] . "<br><br>" . str_replace("_"," ",$row['template_name']) . " was developed by " . $user . "]]></description>
<pubDate>" . date(DATE_RSS, strtotime($row['date_created'])) . "</pubDate>
<guid><![CDATA[" . $xerte_toolkits_site->site_url . url_return($action, $row['template_id']) . "]]></guid>
</item>\n";
}

echo "
</channel>
</rss>";

function _html_escape($string) {
return htmlentities($string, ENT_QUOTES, null, false);
}
10 changes: 7 additions & 3 deletions syndicate.php
Expand Up @@ -17,21 +17,25 @@ function normal_date($string){
license, category, export, {$xerte_toolkits_site->database_table_prefix}templatesyndication.description, firstname, surname
FROM {$xerte_toolkits_site->database_table_prefix}templatedetails, {$xerte_toolkits_site->database_table_prefix}templatesyndication, {$xerte_toolkits_site->database_table_prefix}logindetails,
{$xerte_toolkits_site->database_table_prefix}originaltemplatesdetails
WHERE syndication="true"
WHERE syndication='true'
AND login_id = creator_id
AND {$xerte_toolkits_site->database_table_prefix}templatedetails.template_id = {$xerte_toolkits_site->database_table_prefix}templatesyndication.template_id
AND {$xerte_toolkits_site->database_table_prefix}templatedetails.template_type_id = {$xerte_toolkits_site->database_table_prefix}originaltemplatesdetails.template_type_id";

$rows = db_query($query);

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://web.resource.org/cc/\"><channel><title>" .$xerte_toolkits_site->rss_title . "</title><link>" . $xerte_toolkits_site->site_url . "</link><description>This RSS feed contains a list of all the syndicated content from the Xerte Online Toolkits installation at " . $xerte_toolkits_site->synd_publisher . "</description><generator>Xerte Online Toolkits</generator><language>en-gb</language><copyright>http://creativecommons.org/licenses/by-nc-sa/2.0/uk/ </copyright><lastBuildDate>" . date("D, d M Y H:i:s", time()-20000) . " GMT</lastBuildDate><pubDate>" . date("D, d M Y H:i:s", time()-20000) . " GMT</pubDate><dc:publisher>" . $xerte_toolkits_site->synd_publisher . "</dc:publisher><cc:license>" . $xerte_toolkits_site->synd_license . "</cc:license>";
echo "<" . "?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://web.resource.org/cc/\">
<channel>
<title>" .$xerte_toolkits_site->rss_title . "</title>
<link>" . $xerte_toolkits_site->site_url . "</link><description>This RSS feed contains a list of all the syndicated content from the Xerte Online Toolkits installation at " . $xerte_toolkits_site->synd_publisher . "</description><generator>Xerte Online Toolkits</generator><language>en-gb</language><copyright>http://creativecommons.org/licenses/by-nc-sa/2.0/uk/ </copyright><lastBuildDate>" . date(DATE_RSS, time()-20000) ."</lastBuildDate><pubDate>" . date(DATE_RSS, time()-20000) . "</pubDate><dc:publisher>" . $xerte_toolkits_site->synd_publisher . "</dc:publisher><cc:license>" . $xerte_toolkits_site->synd_license . "</cc:license>";

foreach($rows as $row) {
$_dataxml = $xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . $row['template_id'] . '-' . $row['username'] . '-' . $row['origname'] . '/data.xml';

echo "<item><title>" . str_replace("_"," ",$row['template_name']) . "</title>
<link>" . $xerte_toolkits_site->site_url . url_return("play" , $row['template_id']) . "</link>
<dc:date>" . date("D, d M y H:i:s O ", filemtime($_dataxml) . "</dc:date>
<dc:date>" . date(DATE_RSS, filemtime($_dataxml)) . "</dc:date>
<description><![CDATA[" . $row['description'] . "<br>" . str_replace("_"," ",$row['template_name']) . " was developed by " . $row['firstname'] . " " . $row['surname'] . " <br/> This content has the following license - " . $row['license'];

if($row['export']=="true"){
Expand Down

0 comments on commit 35a916b

Please sign in to comment.