mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
+ added rss feed of task changes (New/Updated/Completed)
This commit is contained in:
parent
f035fa3464
commit
afc95dba32
3 changed files with 92 additions and 39 deletions
|
|
@ -125,7 +125,11 @@
|
|||
"feed_title": "%s",
|
||||
"feed_completed_tasks": "Completed tasks",
|
||||
"feed_modified_tasks": "Modified tasks",
|
||||
"feed_new_tasks": "New tasks",
|
||||
"feed_new_tasks": "New tasks",
|
||||
"feed_tasks": "Tasks",
|
||||
"feed_status_new": "New",
|
||||
"feed_status_updated": "Updated",
|
||||
"feed_status_completed": "Completed",
|
||||
"alltasks": "All tasks",
|
||||
"set_header": "Settings",
|
||||
"set_title": "Title",
|
||||
|
|
|
|||
|
|
@ -125,7 +125,11 @@
|
|||
"feed_title": "%s",
|
||||
"feed_completed_tasks": "Завершенные задачи",
|
||||
"feed_modified_tasks": "Изменившиеся задачи",
|
||||
"feed_new_tasks": "Новые задачи",
|
||||
"feed_new_tasks": "Новые задачи",
|
||||
"feed_status_new": "Задача создана",
|
||||
"feed_status_updated": "Задача обновлена",
|
||||
"feed_status_completed": "Задача завершена",
|
||||
"feed_tasks": "Задачи",
|
||||
"alltasks": "Все задачи",
|
||||
"set_header": "Настройки",
|
||||
"set_title": "Заголовок страницы",
|
||||
|
|
|
|||
119
src/feed.php
119
src/feed.php
|
|
@ -18,75 +18,120 @@ if (need_auth() && (!$listData || !$listData['published'])) {
|
|||
die("Access denied!<br> List is not published.");
|
||||
}
|
||||
if(!$listData) {
|
||||
die("No such list");
|
||||
die("No list found");
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$feedType = _get('feed');
|
||||
$sqlWhere = '';
|
||||
|
||||
if($feedType == 'completed') {
|
||||
$listData['_uid_field'] = 'd_completed';
|
||||
$listData['_feed_descr'] = $lang->get('feed_completed_tasks');
|
||||
$sqlWhere = 'AND compl=1';
|
||||
fillData( $data, $listId, 'd_completed', 'AND compl=1' );
|
||||
}
|
||||
elseif($feedType == 'modified') {
|
||||
$listData['_uid_field'] = 'd_edited';
|
||||
$listData['_feed_descr'] = $lang->get('feed_modified_tasks');
|
||||
$listData['_feed_descr'] = $lang->get('feed_modified_tasks');
|
||||
fillData( $data, $listId, 'd_edited', '' );
|
||||
}
|
||||
elseif($feedType == 'current') {
|
||||
$listData['_uid_field'] = 'd_created';
|
||||
$listData['_feed_descr'] = $lang->get('feed_new_tasks');
|
||||
$sqlWhere = 'AND compl=0';
|
||||
fillData( $data, $listId, 'd_created', 'AND compl=0' );
|
||||
}
|
||||
elseif($feedType == 'status') {
|
||||
$listData['_feed_descr'] = $lang->get('feed_tasks');
|
||||
fillData( $data, $listId, 'd_created', '' );
|
||||
fillData( $data, $listId, 'd_edited', 'AND compl=0 AND d_edited > d_created' );
|
||||
fillData( $data, $listId, 'd_completed', 'AND compl=1' );
|
||||
}
|
||||
else {
|
||||
$listData['_uid_field'] = 'd_created';
|
||||
$listData['_feed_descr'] = $lang->get('feed_new_tasks');
|
||||
$listData['_feed_descr'] = $lang->get('feed_new_tasks');
|
||||
$feedType = 'tasks';
|
||||
fillData( $data, $listId, 'd_created', '' );
|
||||
}
|
||||
|
||||
$listData['_feed_title'] = sprintf($lang->get('feed_title'), $listData['name']) . ' - '. $listData['_feed_descr'];
|
||||
$listData['_feed_link'] = get_mttinfo('mtt_url'). "feed.php?list=". (int)$listData['id'] . ($feedType != '' ? "&feed=". $feedType : '');
|
||||
$listData['_feed_type'] = $feedType;
|
||||
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))
|
||||
printRss($data, $listData);
|
||||
|
||||
|
||||
function fillData(&$data, $listId, $field, $sqlWhere )
|
||||
{
|
||||
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);
|
||||
$lang = Lang::instance();
|
||||
$db = DBConnection::instance();
|
||||
$q = $db->dq("SELECT * FROM {$db->prefix}todolist WHERE list_id=$listId $sqlWhere ORDER BY $field DESC LIMIT 100");
|
||||
while ($r = $q->fetch_assoc($q))
|
||||
{
|
||||
if ($r['prio'] > 0) {
|
||||
$r['prio'] = '+'.$r['prio'];
|
||||
}
|
||||
$a = array();
|
||||
$a[] = $lang->get('task'). ": ". $r['title'];
|
||||
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);
|
||||
}
|
||||
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'] = implode("<br/>", htmlarray($a)). "<br/><br/>". $r['note'];
|
||||
$r['_title'] = "#". (int)$r['id']. ": ". $r['title'];
|
||||
$r['_d'] = gmdate('r', $r[$field]);
|
||||
$r['_field'] = $field;
|
||||
$data[] = $r;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
printRss($listData, $data);
|
||||
|
||||
|
||||
function printRss($listData, $data)
|
||||
function printRss($data, $listData)
|
||||
{
|
||||
$lang = Lang::instance();
|
||||
$link = get_mttinfo('url'). "?list=". (int)$listData['id'];
|
||||
$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".
|
||||
$s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
|
||||
"<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n".
|
||||
"<channel>\n".
|
||||
"<title>$listData[_feed_title]</title>\n".
|
||||
"<link>$link</link>\n".
|
||||
"<atom:link href=\"${listData['_feed_link']}\" rel=\"self\" type=\"application/rss+xml\"/>\n".
|
||||
"<description>$listData[_feed_descr]</description>\n".
|
||||
"<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']];
|
||||
$guid = $listData['_feed_type']. '-'. $listData['id']. '-'. $v['id']. '-'. $v[$v['_field']];
|
||||
$itemLink = $link. "&task=". (int)$v['id'];
|
||||
|
||||
$s .= "<item>\n<title>${v['title']}</title>\n".
|
||||
"<link>$link</link>\n".
|
||||
"<pubDate>$d</pubDate>\n".
|
||||
$status = '';
|
||||
if ( $listData['_feed_type'] == 'status' ) {
|
||||
if ( $v['_field'] == 'd_created' ) {
|
||||
$status = $lang->get('feed_status_new');
|
||||
}
|
||||
elseif ( $v['_field'] == 'd_edited' ) {
|
||||
$status = $lang->get('feed_status_updated');
|
||||
}
|
||||
elseif ( $v['_field'] == 'd_completed' ) {
|
||||
$status = $lang->get('feed_status_completed');
|
||||
}
|
||||
}
|
||||
if ( $status !='' ) $status = "[$status] ";
|
||||
|
||||
$s .= "<item>\n".
|
||||
"<title>". $status. $v['title']. "</title>\n".
|
||||
"<link>". $itemLink. "</link>\n".
|
||||
"<pubDate>". $v['_d']. "</pubDate>\n".
|
||||
"<description><![CDATA[". $v['_descr']. "]]></description>\n".
|
||||
"<guid isPermaLink=\"false\">$guid</guid>\n".
|
||||
"</item>\n";
|
||||
"</item>\n\n";
|
||||
}
|
||||
|
||||
$s .= "</channel>\n</rss>";
|
||||
|
|
|
|||
Loading…
Reference in a new issue