mytinytodo/src/feed.php

98 lines
3.1 KiB
PHP
Raw Normal View History

2009-11-01 14:42:36 +00:00
<?php
/*
This file is part of myTinyTodo.
(C) Copyright 2009-2010 Max Pozdeev <maxpozdeev@gmail.com>
Licensed under the GNU GPL v2 license. See file COPYRIGHT for details.
2009-11-01 14:42:36 +00:00
*/
$dontStartSession = 1;
require_once('./init.php');
2010-02-06 17:35:39 +00:00
$lang = Lang::instance();
2009-11-01 14:42:36 +00:00
$listId = (int)_get('list');
$listData = $db->sqa("SELECT * FROM {$db->prefix}lists WHERE id=$listId");
if (need_auth() && (!$listData || !$listData['published'])) {
2009-11-22 12:24:36 +00:00
die("Access denied!<br> List is not published.");
}
2009-11-01 14:42:36 +00:00
if(!$listData) {
die("No such list");
}
2009-11-22 12:24:36 +00:00
$feedType = _get('feed');
$sqlWhere = '';
if($feedType == 'completed') {
$listData['_uid_field'] = 'd_completed';
$listData['_feed_descr'] = $lang->get('feed_completed_tasks');
$sqlWhere = 'AND compl=1';
}
elseif($feedType == 'modified') {
$listData['_uid_field'] = 'd_edited';
$listData['_feed_descr'] = $lang->get('feed_modified_tasks');
}
elseif($feedType == 'current') {
$listData['_uid_field'] = 'd_created';
$listData['_feed_descr'] = $lang->get('feed_new_tasks');
$sqlWhere = 'AND compl=0';
}
else {
$listData['_uid_field'] = 'd_created';
$listData['_feed_descr'] = $lang->get('feed_new_tasks');
}
$listData['_feed_title'] = sprintf($lang->get('feed_title'), $listData['name']) . ' - '. $listData['_feed_descr'];
2009-11-01 14:42:36 +00:00
htmlarray_ref($listData);
$data = array();
$q = $db->dq("SELECT * FROM {$db->prefix}todolist WHERE list_id=$listId $sqlWhere ORDER BY ". $listData['_uid_field'] ." DESC LIMIT 100");
while($r = $q->fetch_assoc($q))
2009-11-01 14:42:36 +00:00
{
if($r['prio'] > 0) $r['prio'] = '+'.$r['prio'];
$a = array();
if($r['prio']) $a[] = $lang->get('priority'). ": $r[prio]";
if($r['duedate'] != '') {
$ad = explode('-', $r['duedate']);
$a[] = $lang->get('due'). ": ".formatDate3(Config::get('dateformat'), (int)$ad[0], (int)$ad[1], (int)$ad[2], $lang);
2009-11-01 14:42:36 +00:00
}
if($r['tags'] != '') $a[] = $lang->get('tags'). ": ". str_replace(',', ', ', $r['tags']);
if($r['compl']) $a[] = $lang->get('taskdate_completed'). ": ". timestampToDatetime($r['d_completed']);
$r['title'] = htmlspecialchars( $r['title'] );
$r['note'] = mttMarkup_v1($r['note']);
$r['_descr'] = $r['note']. ($a && $r['note']!='' ? "<br/><br/>" : ""). implode("<br/>", htmlarray($a));
$data[] = $r;
2009-11-01 14:42:36 +00:00
}
printRss($listData, $data);
function printRss($listData, $data)
{
2020-09-12 14:02:15 +00:00
$link = get_mttinfo('url'). "?list=". (int)$listData['id'];
2009-11-01 14:42:36 +00:00
$buildDate = gmdate('r');
$s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n<channel>\n".
"<title>$listData[_feed_title]</title>\n<link>$link</link>\n<description>$listData[_feed_descr]</description>\n".
2009-11-01 14:42:36 +00:00
"<lastBuildDate>$buildDate</lastBuildDate>\n\n";
foreach($data as $v)
{
$d = gmdate('r', $v[$listData['_uid_field']]);
$guid = $listData['id'].'-'.$v['id'].'-'.$v[$listData['_uid_field']];
2009-11-01 14:42:36 +00:00
$s .= "<item>\n<title>${v['title']}</title>\n".
2009-11-01 14:42:36 +00:00
"<link>$link</link>\n".
"<pubDate>$d</pubDate>\n".
"<description><![CDATA[". $v['_descr']. "]]></description>\n".
2009-11-01 14:42:36 +00:00
"<guid isPermaLink=\"false\">$guid</guid>\n".
"</item>\n";
}
$s .= "</channel>\n</rss>";
header("Content-type: text/xml; charset=utf-8");
2009-11-01 14:42:36 +00:00
print $s;
}
?>