Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update db queries used in creation of rss feeds; improve date formatt…
…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
Showing
3 changed files
with
176 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.