Commit dce9887f authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Converting feeds over to a pure smarty template system

- Some code cleanup
parent bccedd30
......@@ -19,11 +19,15 @@
// Define phpTodo (to allow access to files)
define('phpTodo', 1);
// Define usesmarty (to indicate that config needs to load smarty)
define('usesmarty', 1);
// Load the global config
require_once('config.php');
// Load the generator
require_once('libs/feedcreator.class.php');
// Connect to the database server
$sqlhdlr = new mysqli($phpTodo_dbHost, $phpTodo_dbUser, $phpTodo_dbPass,
$phpTodo_dbName);
// Set and validate the the request variables
if (ctype_digit($_REQUEST['user_id'])) {
......@@ -36,151 +40,139 @@
$secret = $_REQUEST['secret'];
}
// Create the feed object;
$feed = new UniversalFeedCreator();
// Connect to the database server
$sqlhdlr = ($GLOBALS["___mysqli_ston"] = mysqli_connect($phpTodo_dbHost, $phpTodo_dbUser, $phpTodo_dbPass))
or die( 'Error: Database Connect: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) );
// Select the database
((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE $phpTodo_dbName"))
or die( 'Error: Choose Database: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) );
if (! $feed_param = feed_authenticate($user_id, $feed_id, $secret)) {
// Set up the channel with info indicating an invalid feed
$feed->title = 'Invalid RSS Feed';
$feed->link = $phpTodo_serveruri . $phpTodo_serverpath .
$_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING'];
$feed->description = 'phpTodo Version ' . $phpTodo_version . "\n" .
'Auto-generated RSS feed' . "\n" . $phpTodo_homepage;
// Display the necessary headers
header('content-type: text/xml');
header('Content-Disposition: inline; filename=rss_' .
str_replace(' ', '' ,$feed_param->name .
' - phpTodo RSS Feed.xml'));
// Display the RSS Feed
$feeddata = $feed->createFeed($feed_param->version);
print "$feeddata";
// Exit
((is_null($___mysqli_res = mysqli_close($sqlhdlr))) ? false : $___mysqli_res);
exit;
}
// Set up the channel
$feed->title = $feed_param->name . ' - phpTodo RSS Feed';
$feed->link = $phpTodo_serveruri . $_SERVER['REQUEST_URI'];
$feed->description = 'phpTodo Version ' . $phpTodo_version . "\n" .
'Auto-generated RSS feed' . "\n" . $phpTodo_homepage;
// Get the GMT offset
$itemTZOffset = date('O');
// Get all of the todo items from the database
$query = sprintf('SELECT l.id, l.subject, p.name, d.description, ' .
's.status, c.category, DATE_FORMAT(l.start_date, "%s"), ' .
'DATE_FORMAT(l.due_date, "%s"), ' .
'DATE_FORMAT(l.create_date, "%s"), u.email, u.full_name ' .
'FROM listentries AS l LEFT JOIN priority AS p ON p.id = ' .
'l.priority_id LEFT JOIN status AS s ON s.id = ' .
'l.status_id LEFT JOIN category AS c ON c.id = ' .
'l.category_id LEFT JOIN description AS d ON d.list_id = ' .
'l.id LEFT JOIN users AS u ON u.id = l.user_id WHERE ' .
'l.user_id = %d AND l.status_id != %d', '%m-%d-%Y',
'%m-%d-%Y', '%a, %d %b %Y %h:%i:%s', $user_id,
$phpTodo_cancelled);
# If the priority is specified, filter for it
if ($feed_param->priority != 0) {
$query = $query . sprintf(' AND l.priority_id = %d',
$feed_param->priority);
}
# If the status is specified, filter for it
if ($feed_param->status != 0) {
$query = $query . sprintf(' AND l.status_id = %d', $feed_param->status);
}
# If the category is specified, filter for it
if ($feed_param->category != 0) {
$query = $query . sprintf(' AND l.category_id = %d',
$feed_param->category);
}
# If we don't want to show the completed items, filter them out
if (($feed_param->show_completed == 0) &&
($feed_param->status != $phpTodo_completed)) {
$query = $query . sprintf(' AND l.status_id != %d', $phpTodo_completed);
}
# If specified, filter by the specified field(s)
if ($feed_param->field_name != '') {
$query = $query . sprintf(' ORDER BY %s', $feed_param->field_name);
}
# If a limit is specified, use it
if ($feed_param->max_limit != 0) {
$query = $query . sprintf(' LIMIT %d', $feed_param->max_limit);
}
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die ( 'Error: Query: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) );
# Take the items and place them into the RSS object
while (list($id, $subject, $priority, $desc, $status, $category, $start_date,
$due_date, $create_date, $email,
$user) = mysqli_fetch_array($result)) {
$feedDesc = "Priority : $priority\n";
$feedDesc .= "Status : $status\n";
$feedDesc .= "Category : $category\n";
$builddate = new DateTime();
// Set up the default channel with info indicating an invalid feed
$feed_output['title'] = 'Invalid RSS Feed';
$feed_output['link'] = $phpTodo_serveruri . $phpTodo_serverpath .
$_SERVER['REQUEST_URI'] .
$_SERVER['QUERY_STRING'];
$feed_output['description'] = 'phpTodo Version ' . $phpTodo_version .
"\n" . 'Auto-generated RSS feed' . "\n" .
$phpTodo_homepage;
$feed_output['lastbuild'] = $builddate->format(DATE_RFC822);
$feed_output['generator'] = 'phpTodo Version ' . $phpTodo_version;
// Check authentication
if ($auth_array = feed_authenticate($user_id, $feed_id, $secret)) {
$feed = $auth_array[0];
$user_obj = $auth_array[1];
// Set up the channel
$feed_output['title'] = $feed->name() . ' - phpTodo RSS Feed';
// Query to retrieve the list entries
$query = sprintf('SELECT l.id, count(l.id) AS numid FROM listentries ' .
'AS l LEFT JOIN tag2entry AS te ON te.entry_id = ' .
'l.id, status AS s WHERE l.status_id = s.id AND ' .
'l.user_id = %d', $user_id);
// If the status is specified, filter for it
if ($feed->status_id() != 0) {
$query = $query . sprintf(' AND l.status_id = %d', $feed->status_id());
}
# Split apart the date and build the way *we* want it
$date_match = '/^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})\z/';
$time_match = '/^[0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})\z/';
// Ignore completed/cancelled entries if the user doesn't want to see them
if (! $feed->show_completed()) {
$query = $query . sprintf(' AND l.status_id NOT IN (%d,%d)',
$phpTodo_completed, $phpTodo_cancelled);
}
if (isset($start_date) && ($start_date != '00-00-0000')) {
$feedDesc .= "Start Date : $start_date\n";
// If the priority is specified, filter for it
if ($feed->priority_min() != 0) {
$query = $query . sprintf(' AND l.priority >= %d',
$feed->priority_min());
}
if (isset($due_date) && ($due_date != '00-00-0000')) {
$feedDesc .= "Due Date : $due_date\n";
// If the priority is specified, filter for it
if ($feed->priority_max() != 0) {
$query = $query . sprintf(' AND l.priority <= %d',
$feed->priority_max());
}
if (get_magic_quotes_gpc()) {
$feedDesc .= stripslashes(urldecode("$desc"));
$feedSubject = stripslashes(urldecode($subject));
// Filter tags
if ($feed->tag_filter_id()) {
$query = $query . sprintf(' AND te.tag_id IN (%s) GROUP BY l.id ' .
'HAVING numid = %d', $feed->tag_filter_id(),
count(explode(',', $feed->tag_filter_id())));
} else {
$feedDesc .= urldecode("$desc");
$feedSubject = urldecode($subject);
$query = $query . ' GROUP BY l.id';
}
if ($feed->max_limit() > 0) {
$query = $query . sprintf(' LIMIT %d', $feed->max_limit());
}
# Take the data and put it into the rss object
$item = new FeedItem();
$item->title = "$feedSubject ($priority)";
$item->link = $phpTodo_serveruri . $phpTodo_serverpath .
"taskmodify.php?edit=Edit&task_id=$id";
$item->description = nl2br("$feedDesc");
$item->date = "$create_date $itemTZOffset";
$item->source = '';
$item->author = "$email ($user)";
// If specified, order by the specified field
//if ($feed->order_by() != '') {
// $query = $query . sprintf(' ORDER BY %s', $feed->order_by());
//}
// Execute the query
if ($result = $sqlhdlr->query($query)) {
// Place the results into a two dimensional array
$loop = 0;
while ($line = $result->fetch_array()) {
$todoitem = new TodoItem($phpTodo_dbHost, $phpTodo_dbUser,
$phpTodo_dbPass, $phpTodo_dbName,
$user_id, false, $line[0]);
// Create the description
$feedDesc = 'Priority : ' . $todoitem->priority_name() . '(' .
$todoitem->priority() . ')' . "\n";
$feedDesc .= 'Status : ' . $todoitem->status() . "\n";
//$feedDesc .= 'Category : ' . implode(',', $todoitem->tags()) . "\n";
if ($todoitem->start_date() != '00-00-0000') {
$feedDesc .= 'Start Date : ' . $todoitem->start_date() . "\n";
}
if ($todoitem->due_date() != '00-00-0000') {
$feedDesc .= 'Due Date : ' . $todoitem->due_date() . "\n";
}
$feedDesc .= $todoitem->description();
$entries[$loop]['title'] = $todoitem->subject() . ' (' .
$todoitem->priority_name() . ')';
$entries[$loop]['link'] = $phpTodo_serveruri .
$phpTodo_serverpath .
'taskmodify.php?edit=Edit&' .
'task_id=' .
$todoitem->task_id();
$entries[$loop]['description'] = nl2br("$feedDesc");
$createdate = DateTime::createFromFormat('m-d-Y',
$todoitem->create_date());
$entries[$loop]['createdate'] = $createdate->format(DATE_RFC822);
$entries[$loop]['source'] = '';
$entries[$loop]['author'] = $user_obj->email() . ' (' .
$user_obj->username() . ')';
$loop++;
}
// Free the result
$result->close();
} else {
die( 'Error: ' . $sqlhdlr->error );
}
}
$feed->addItem($item);
}
// Assign the array to a template variable (if there is an array)
if (! empty($entries)) {
$smarty->assign('entries', $entries);
}
// Free the result
((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
$smarty->assign('feed', $feed_output);
// Close the MySQL handler
((is_null($___mysqli_res = mysqli_close($sqlhdlr))) ? false : $___mysqli_res);
$sqlhdlr->close();
// Display the necessary headers
header('content-type: text/xml');
header('Content-Disposition: inline; filename=rss_' .
str_replace(' ', '' ,$feed_param->name . ' - phpTodo RSS Feed.xml'));
str_replace(' ', '' , $feed->name() . ' - phpTodo RSS Feed.xml'));
// Display the Feed
$feeddata = $feed->createFeed($feed_param->version);
print "$feeddata";
$smarty->display('feed-rss091.tpl');
?>
......@@ -311,7 +311,7 @@ class phpTodoFeed {
*
* @return string Returns a comma separated list of tag filter IDs
*/
private function tag_filter_id() {
public function tag_filter_id() {
$tag_filter_id = array();
foreach ($this->tag_filter as $tag) {
array_push($tag_filter_id, $tag->id());
......
......@@ -117,30 +117,21 @@ function feed_authenticate($user_id, $feed_id, $secret) {
global $phpTodo_dbHost, $phpTodo_dbUser, $phpTodo_dbPass, $phpTodo_dbName,
$phpTodo_sessTime, $sqlhdlr;
// Get the rss feed information and pass it back to the rss generator
$query = sprintf('SELECT r.name, r.priority, r.status, r.category, ' .
'o.field_name, r.max_limit, r.show_completed, ' .
'r.version FROM feeds AS r LEFT JOIN order_by ' .
'AS o ON o.id = r.order_by WHERE r.user_id = %d AND r.id ' .
'= %d AND r.secret = "%s"', $user_id, $feed_id,
$sqlhdlr->real_escape_string($secret));
// Create the phpTodoFeed object
$feed = new phpTodoFeed($phpTodo_dbHost, $phpTodo_dbUser, $phpTodo_dbPass,
$phpTodo_dbName, $user_id, $feed_id);
if ($result = $sqlhdlr->query($query)) {
if ($result->num_rows == 1) {
$feed_param = $result->fetch_object();
$result->close();
if ($feed->secret() == $secret) {
// Create the user object
$user_obj = new phpTodoUser($phpTodo_dbHost, $phpTodo_dbUser,
$phpTodo_dbPass, $phpTodo_dbName, $user_id);
return $feed_param;
} else {
// Return a 0 to indicate that authentication was not successful
return 0;
}
return Array($feed, $user_obj);
} else {
die( 'Error: ' . $sqlhdlr->error );
// Return a 0 to indicate that authentication was not successful
return 0;
}
// This code should never be executed
return 0;
}
......
{* phpTodo - Web based todo lists *}
{* Copyright (C) 2005-12 Jason Frisvold <friz@godshell.com> *}
{* *}
{* This program is free software; you can redistribute it and/or modify *}
{* it under the terms of the GNU General Public License as published by *}
{* the Free Software Foundation; either version 2 of the License, or *}
{* (at your option) any later version. *}
{* *}
{* This program is distributed in the hope that it will be useful, *}
{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
{* GNU General Public License for more details. *}
{* *}
{* You should have received a copy of the GNU General Public License *}
{* along with this program; if not, write to the Free Software *}
{* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *}
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="0.91">
<channel>
<title>{$feed.title|escape:'html'}</title>
<link>{$feed.link|escape:'html'}</link>
<description>{$feed.description|escape:'html'}</description>
<lastBuildDate>{$feed.lastbuild}</lastBuildDate>
<generator>{$feed.generator}</generator>
<!-- <language>en-us</language>
<copyright>Copyright 2000, WriteTheWeb team.</copyright>
<managingEditor>editor@writetheweb.com</managingEditor>
<webMaster>webmaster@writetheweb.com</webMaster>
-->
<!-- <image>
<title>WriteTheWeb</title>
<url>http://writetheweb.com/images/mynetscape88.gif</url>
<link>http://writetheweb.com</link>
<width>88</width>
<height>31</height>
<description>News for web users that write back</description>
</image>
-->
{foreach from=$entries item=entry}
<item>
<title>{$entry.title|escape:'html'}</title>
<link>{$entry.link|escape:'html'}</link>
<description>{$entry.description|escape:'html'}</description>
<author>{$entry.author|escape:'html'}</author>
<pubDate>{$entry.createdate}</pubDate>
</item>
{/foreach}
</channel>
</rss>
\ No newline at end of file
......@@ -199,8 +199,6 @@
$smarty->assign('duedate_val', $user_obj->duedate_sort());
// Query to retrieve the list entries
$query_head = 'SELECT l.id, count(l.id) AS numid ';
$query = sprintf('SELECT l.id, count(l.id) AS numid FROM listentries AS l ' .
'LEFT JOIN tag2entry AS te ON te.entry_id = l.id, status ' .
'AS s WHERE l.status_id = s.id AND l.user_id = %d',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment