Commit d199477e authored by Evan Goldenberg's avatar Evan Goldenberg Committed by Richard Mansfield

atom feeds for group forums

Signed-off-by: default avatarEvan Goldenberg <evang@catalyst.net.nz>
parent b5096a58
......@@ -50,10 +50,16 @@ if (is_logged_in()) {
$view = group_get_homepage_view($group->id);
$viewcontent = $view->build_columns();
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');
$headers = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');
if ($group->public) {
$feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=g&id=' . $group->id;
$headers[] = '<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '" />';
}
$smarty = smarty(
array(),
$stylesheets,
$headers,
array(),
array('stylesheets' => array('style/views.css'))
);
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage interaction-forum
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2010 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('PUBLIC', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
function atom_date($date) {
$date = str_replace(' ', 'T', $date);
$date .= date('P');
return $date;
}
function generate_feed($feed, $posts) {
$smarty = smarty();
$smarty->assign('feed', $feed);
$smarty->assign('posts', $posts);
header("Content-Type: application/atom+xml");
$smarty->display('interaction:forum:atom.xml.tpl');
}
function error_feed() {
return array(
'title' => get_string('accessdenied', 'error'),
'link' => '',
'selflink' => '',
'id' => '',
'description' => '',
'ownername' => '',
'updated' => '',
'logo' => '',
);
}
function error_post($message) {
return array(
0 => array(
'title' => get_string('accessdenied', 'error'),
'link' => '',
'id' => '',
'description' => $message,
'mtime' => '',
));
}
$feedtype = param_alpha('type'); //g = group, f = forum, t = topic
$id = param_integer('id');
if ($feedtype == 'g') {
if (!record_exists('group', 'id', $id, 'deleted', 0)) {
generate_feed(error_feed(), error_post(get_string('groupnotfound', 'group', $id)));
exit();
}
$groupid = $id;
$sql = "
SELECT u.firstname, u.lastname, p.id, p.parent, p.topic, p.subject, p.body, p.ctime
FROM {interaction_forum_post} p
INNER JOIN (
SELECT t.id
FROM {interaction_forum_topic} t
INNER JOIN {interaction_instance} f ON t.forum = f.id
WHERE f.group = ?
) gt ON p.topic = gt.id
INNER JOIN {usr} u ON p.poster = u.id
WHERE p.deleted = 0";
$link = get_config('wwwroot') . 'interaction/forum/index.php?group=' . $id;
$title = implode(' - ', array(get_field('group', 'name', 'id', $id),
get_string('allposts', 'interaction.forum')));
}
elseif ($feedtype == 'f') {
if (!($groupid = get_field('interaction_instance', '"group"', 'id', $id, 'deleted', 0))) {
generate_feed(error_feed(), error_post(get_string('cantfindforum', 'interaction.forum', $id)));
exit();
}
$sql = "
SELECT u.firstname, u.lastname, p.id, p.parent, p.topic, p.subject, p.body, p.ctime
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON p.topic = t.id
INNER JOIN {usr} u ON p.poster = u.id
WHERE t.forum = ?
AND p.deleted = 0";
$link = get_config('wwwroot') . 'interaction/forum/view.php?id=' . $id;
$title = implode(' - ', array(get_field('group', 'name', 'id', $groupid),
get_field('interaction_instance', 'title', 'id', $id),
get_string('allposts', 'interaction.forum')));
}
elseif ($feedtype == 't') {
if (!($forumid = get_field('interaction_forum_topic', 'forum', 'id', $id, 'deleted', 0))) {
generate_feed(error_feed(), error_post(get_string('cantfindtopic', 'interaction.forum', $id)));
exit();
}
$groupid = get_field('interaction_instance', '"group"', 'id', $forumid, 'deleted', 0);
$sql = "
SELECT u.firstname, u.lastname, p.id, p.parent, p.topic, p.subject, p.body, p.ctime
FROM {interaction_forum_post} p, {usr} u
WHERE p.deleted = 0
AND p.topic = ?
AND p.poster = u.id";
$link = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $id;
$title = implode(' - ', array(get_field('group', 'name', 'id', $groupid),
get_field('interaction_instance', 'title', 'id', $forumid),
get_field_sql("
SELECT p.subject
FROM {interaction_forum_post} p
WHERE p.topic = ?
AND p.parent IS NULL", array($id)),
get_string('allposts', 'interaction.forum')));
}
if (!get_field('"group"', 'public', 'id', $groupid)) {
generate_feed(error_feed(), error_post(get_string('notpublic', 'group')));
exit();
}
$sql .= "
ORDER BY p.ctime DESC
LIMIT ?;";
$selflink = get_config('wwwroot') . 'interaction/forum/atom.php?type=' . $feedtype . '&id=' . $id;
$postcount = 20;
$postrecords = get_records_sql_array($sql, array($id, $postcount));
$image = get_config('wwwroot') . 'theme/raw/static/images/site-logo.png';
$updated = $postrecords[0]->ctime;
$generator = array(
'uri' => 'http://mahara.org',
'version' => get_config('release'),
'text' => 'Mahara',
);
$feed = array(
'title' => $title,
'link' => $link,
'selflink' => $selflink,
'id' => implode(',', array(get_config('wwwroot'), $feedtype, $id)),
'updated' => atom_date($updated),
'logo' => $image,
'icon' => get_config('wwwroot') . 'favicon.ico',
'generator' => $generator,
);
$posts = array();
if($postrecords) {
foreach($postrecords as &$post) {
$parent = $post->parent;
while(!$post->subject) {
$post->subject = get_field('interaction_forum_post', 'subject', 'id', $parent);
$parent = get_field('interaction_forum_post', 'parent', 'id', $parent);
}
if ($parent != $post->parent) {
$post->subject = get_string('re', 'interaction.forum', $post->subject);
}
$posts[] = array(
'title' => $post->subject,
'link' => get_config('wwwroot') . 'interaction/forum/topic.php?id=' .
$post->topic . '#post' . $post->id,
'id' => implode(',', array(get_config('wwwroot'), $post->topic, $post->id)),
'description' => $post->body,
'mtime' => atom_date($post->ctime),
'author' => implode(' ', array($post->firstname, $post->lastname)),
);
}
}
generate_feed($feed, $posts);
?>
......@@ -86,6 +86,10 @@ if ($forums) {
}
}
foreach($forums as $forum) {
$forum->feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=f&id=' . $forum->id;
}
$i = 0;
if ($forums && $membership) {
foreach ($forums as $forum) {
......@@ -125,8 +129,16 @@ if ($forums && $membership) {
}
}
$smarty = smarty();
$feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=g&id=' . $group->id;
$headers = array();
if ($publicgroup) {
$headers[] ='<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '" />';
}
$smarty = smarty(array(), $headers, array(), array());
$smarty->assign('groupid', $groupid);
$smarty->assign('publicgroup', $group->public);
$smarty->assign('feedlink', $feedlink);
$smarty->assign('heading', $group->name);
$smarty->assign('admin', $membership == 'admin');
$smarty->assign('groupadmins', group_get_admin_ids($groupid));
......
......@@ -122,6 +122,7 @@ $string['postedin'] = '%s posted in %s';
$string['Poster'] = 'Poster';
$string['postreply'] = 'Post reply';
$string['Posts'] = 'Posts';
$string['allposts'] = 'All posts';
$string['postsvariable'] = 'Posts: %s';
$string['potentialmoderators'] = 'Potential Moderators';
$string['re'] ='Re: %s';
......
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>{$feed.title}</title>
<id>{$feed.id}</id>
<link href="{$feed.link|escape}" />
<link rel="self" type="application/atom+xml" href="{$feed.selflink|escape}" />
<logo>{$feed.logo|escape}</logo>
<icon>{$feed.icon|escape}</icon>
<generator uri="{$feed.generator.uri|escape}" version="{$feed.generator.version}">
{$feed.generator.text}
</generator>
<updated>{$feed.updated}</updated>
{foreach from=$posts item=post}
<entry>
<title>{$post.title}</title>
<id>{$post.id}</id>
<link href="{$post.link|escape}" />
<content type="html"><![CDATA[ {$post.description} ]]></content>
<author>
<name>{$post.author}</name>
</author>
<updated>{$post.mtime}</updated>
</entry>
{/foreach}
</feed>
{include file="header.tpl"}
<h2>{str tag="nameplural" section=interaction.forum}</h2>
<h2>{str tag="nameplural" section=interaction.forum}{if $publicgroup}<a href="{$feedlink}"><img class="feedicon" src="{theme_url filename='images/rss.gif'}"></a>{/if}</h2>
{if $admin}
<div id="forumbtns" class="rbuttons">
<a href="{$WWWROOT}interaction/edit.php?group={$groupid}&amp;plugin=forum" class="btn btn-add">{str tag="newforum" section=interaction.forum}</a>
......@@ -23,7 +23,7 @@
</div>
{/if}
<div class="nowrap">
<strong><a href="{$WWWROOT}interaction/forum/view.php?id={$forum->id}">{$forum->title}</a></strong>
<strong><a href="{$WWWROOT}interaction/forum/view.php?id={$forum->id}">{$forum->title}</a>{if $publicgroup}<a href="{$forum->feedlink}"><img class="feedicon" src="{theme_url filename='images/rss_small.gif'}"></a>{/if}</strong>
</div>
<div class="s">{$forum->description|str_shorten_html:1000:true|safe}</div>
{if $forum->moderators}
......
......@@ -20,7 +20,7 @@
<a href="{$WWWROOT}interaction/forum/deletetopic.php?id={$topic->id}&amp;returnto=view" class="btn-del">{str tag="delete"}</a>
</div>
{/if}
<div><a href="{$WWWROOT}interaction/forum/topic.php?id={$topic->id}">{$topic->subject}</a></div>
<div><a href="{$WWWROOT}interaction/forum/topic.php?id={$topic->id}">{$topic->subject}</a>{if $publicgroup}<a href="{$topic->feedlink}"><img class="feedicon" src="{theme_url filename='images/rss_small.gif'}"></a>{/if}</div>
<div class="s">{$topic->body|str_shorten_html:50:true:false|safe}</div>
</td>
<td class="s">
......
{include file="header.tpl"}
<h3>{$subheading}</h3>
<h3>{$subheading}{if $publicgroup}<a href="{$feedlink}"><img class="feedicon" src="{theme_url filename='images/rss.gif'}"></a>{/if}</h3>
<div id="forumbtns" class="rbuttons">
{if $admin}
<a href="{$WWWROOT}interaction/edit.php?id={$forum->id}" class="btn btn-editforum">{str tag="edittitle" section="interaction.forum"}</a>
......@@ -28,10 +28,10 @@
<th class="lastpost" width="25%">{str tag="lastpost" section="interaction.forum"}</th>
</tr>
{if $stickytopics}
{include file="interaction:forum:topics.tpl" topics=$stickytopics moderator=$moderator forum=$forum sticky=true}
{include file="interaction:forum:topics.tpl" topics=$stickytopics moderator=$moderator forum=$forum publicgroup=$publicgroup sticky=true}
{/if}
{if $regulartopics}
{include file="interaction:forum:topics.tpl" topics=$regulartopics moderator=$moderator forum=$forum sticky=false}
{include file="interaction:forum:topics.tpl" topics=$regulartopics moderator=$moderator forum=$forum publicgroup=$publicgroup sticky=false}
{/if}
</table>
{if $regulartopics}
......
......@@ -59,6 +59,9 @@ if (!$topic) {
define('GROUP', $topic->groupid);
$publicgroup = get_field('group', 'public', 'id', $topic->groupid);
$feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=t&id=' . $topic->id;
$membership = user_can_access_forum((int)$topic->forumid);
$moderator = (bool)($membership & INTERACTION_FORUM_MOD);
......@@ -170,7 +173,12 @@ execute_sql('
// builds the first post (with index 0) which has as children all the posts in the topic
$posts = buildpostlist($posts, $indentmode, $maxindentdepth);
$smarty = smarty();
$headers = array();
if ($publicgroup) {
$headers[] = '<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '" />';
}
$smarty = smarty(array(), $headers, array(), array());
$smarty->assign('topic', $topic);
$smarty->assign('membership', $membership);
$smarty->assign('moderator', $moderator);
......
......@@ -68,14 +68,15 @@ if (!$forum) {
$membership = user_can_access_forum((int)$forumid);
$admin = (bool)($membership & INTERACTION_FORUM_ADMIN);
$moderator = (bool)($membership & INTERACTION_FORUM_MOD);
if (!$membership
&& !get_field('group', 'public', 'id', $forum->groupid)) {
$publicgroup = get_field('group', 'public', 'id', $forum->groupid);
if (!$membership && !$publicgroup) {
throw new GroupAccessDeniedException(get_string('cantviewforums', 'interaction.forum'));
}
define('TITLE', $forum->groupname . ' - ' . $forum->title);
$feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=f&id=' . $forum->id;
$moderators = get_column_sql(
'SELECT gm.user FROM {interaction_forum_moderator} gm
INNER JOIN {usr} u ON (u.id = gm.user AND u.deleted = 0)
......@@ -244,10 +245,17 @@ addLoadEvent(function() {
});
EOF;
$smarty = smarty();
$headers = array();
if ($publicgroup) {
$headers[] = '<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '" />';
}
$smarty = smarty(array(), $headers, array(), array());
$smarty->assign('heading', $forum->groupname);
$smarty->assign('subheading', $forum->title);
$smarty->assign('forum', $forum);
$smarty->assign('publicgroup', $publicgroup);
$smarty->assign('feedlink', $feedlink);
$smarty->assign('membership', $membership);
$smarty->assign('moderator', $moderator);
$smarty->assign('admin', $admin);
......@@ -269,6 +277,7 @@ function setup_topics(&$topics) {
if ($topics) {
foreach ($topics as $topic) {
$topic->lastposttime = relative_date(get_string('strftimerecentrelative', 'interaction.forum'), get_string('strftimerecent'), $topic->lastposttime);
$topic->feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=t&id=' . $topic->id;
}
}
}
......
......@@ -178,6 +178,7 @@ $string['groups'] = 'groups';
$string['notamember'] = 'You are not a member of this group';
$string['notmembermayjoin'] = 'You must join the group \'%s\' to see this page.';
$string['declinerequestsuccess'] = 'Group membership request has been declined sucessfully.';
$string['notpublic'] = 'This group is not public.';
// Bulk add, invite
$string['addmembers'] = 'Add members';
......
......@@ -1705,4 +1705,8 @@ ul.viewlist li:first-child {
}
ul.viewlist li {
margin: 0.75em 0 0;
/* Feed icons */
img.feedicon {
margin-left: 10px;
}
......@@ -208,7 +208,3 @@ input.addcolumn, input.removecolumn {
border: none;
}
/* Feed icons */
img.feedicon {
margin-left: 10px;
}
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