project = $project;
}
function filter($item) {
return $item['project_id'] == $this->project;
}
}
/**
* Decrypt data.
* @param auth authentification data.
* @return decrypted data.
*/
function decrypt($auth) {
$auth = base64_decode(strtr($auth, '-_', '+/'));
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, variable_get('origo_feed_key', ''), $auth, MCRYPT_MODE_ECB, $iv);
}
/**
* Generate a feed for workitems
*/
function origo_feed_page($auth, $project) {
$rss = new UniversalFeedCreator();
$user = $auth_data['name'];
$project = intval($project);
$cache_file = variable_get('origo_feed_cache_dir', '') . $user . $project .'.xml';
// check if the feed is cached
// If so, the call will return immediately
$rss->useCached(variable_get('origo_feed_type', ''), $cache_file, variable_get('origo_feed_cache_ttl', ''));
// Otherwise, we'll continue building the feed
$auth_data = unserialize(decrypt($auth));
$pass = $auth_data['pass'];
$session = xmlrpc(variable_get('origo_api_internal', ''), 'internal_user.login', $user, $pass);
$workitems = array();
$wid_list = get_workitem_ids($project, $user);
if (count($wid_list) > 0) {
$workitems = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'workitem.retrieve', $wid_list);
usort($workitems, "_cmp_workitem");
}
if ((int)xmlrpc_errno() == 0) {
if ($project > 0) {
// retrieve project name from backend
$project_information = origo_auth_xml_rpc(variable_get('origo_api_internal', ''), 'internal_project.retrieve', (int)$project);
if ((int)xmlrpc_errno() == 0) {
$title = drupal_ucfirst($project_information['name']);
}
else {
// fallback
$title = "Your ";
}
}
else {
$title = "All Subscribed Projects";
}
}
else {
// error
// $foo = xmlrpc_error_msg();
}
// Setup rss channel
$rss->title = $title .' '. variable_get('origo_feed_title', '');
$rss->description = variable_get('origo_feed_description', '');
$rss->link = variable_get('origo_feed_link', '');
$rss->ttl = variable_get('origo_feed_cache_ttl', '');
$origo_web_domain = variable_get('origo_web_domain', '');
foreach ($workitems as $workitem) {
$item = new FeedItem();
$item->descriptionHtmlSyndicated = True;
$workitem_base_url = get_origo_project_link($workitem['project_name']) .'/origo_home/workitem/'. $workitem['id'];
$description = "";
switch ($workitem['type_id']) {
case 1:
// issue
if ($workitem['is_new'] == True) {
$item->title = $workitem['project_name'] .': New Issue #'. $workitem['project_issue_id'] .': '. $workitem['title'];
}
else {
$item->title = $workitem['project_name'] .': Issue Reply #'. $workitem['project_issue_id'] .': '. $workitem['title'];
}
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['reference']);
$description .= "Tags: ". implode(", ", $workitem['tags']) ."
";
$description .= "Visibility: ";
$description .= ($workitem['is_private']) ? "Private
" : "Public
";
if (isset($workitem['work_amount']) && $workitem['work_amount'] != 0) {
$description .= "Work Amount: ". $workitem['work_amount'] ."
";
}
if (isset($workitem['deadline']) && $workitem['deadline'] != 0) {
$description .= "Deadline: ". gmdate('Y-m-d', $workitem['timestamp']) ."
";
}
$description .= "Description: ". nl2br($workitem['description']) ."
";
break;
case 2:
// release
$item->title = $workitem['project_name'] .': Release '. $workitem['release_version'] .' '. $workitem['release_name'];
$item->description = $workitem['release_description'];
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['reference']);
if (isset($workitem['release_version']) && $workitem['release_version'] != 0) {
$description .= "Version: ". $workitem['release_version'] ."
";
}
$description .= "Description: ". nl2br($workitem['release_description']) ."
";
break;
case 3:
// commit
$item->title = $workitem['project_name'] .': Commit Revision '. $workitem['revision'];
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['reference']);
$item->description = $workitem['log'];
$description .= "Revision: ". $workitem['revision'] ."
";
$description .= "Log Message: ". nl2br($workitem['log']) ."
";
$description .= "Diff: ". nl2br($workitem['diff']) ."
";
break;
case 4:
// wiki
if ($workitem['is_new'] == True) {
$item->title = $workitem['project_name'] .': Created Page \''. $workitem['title'] .'\'';
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['reference']);
}
else {
$item->title = $workitem['project_name'] .': Changed Page \''. $workitem['title'] .'\'';
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['diffurl']);
}
$description .= "Revision: ". $workitem['revision'] ."
";
$description .= "Previous Revision: ". $workitem['previous_revision'] ."
";
$description .= "Visibility: ";
$description .= ($workitem['is_private']) ? "Private
" : "Public
";
$description .= "Diff: ". nl2br($workitem['diff']) ."
";
break;
case 5:
// blog
if ($workitem['is_new'] == True) {
$item->title = $workitem['project_name'] .': Created Blog \''. $workitem['title'] .'\'';
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['reference']);
}
else {
$item->title = $workitem['project_name'] .': Changed Blog \''. $workitem['title'] .'\'';
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['diffurl']);
}
$description .= "Revision: ". $workitem['revision'] ."
";
$description .= "Previous Revision: ". $workitem['previous_revision'] ."
";
$description .= "Visibility: ";
$description .= ($workitem['is_private']) ? "Private
" : "Public
";
$description .= "Diff: ". nl2br($workitem['diff']) ."
";
break;
case 6:
// comment
if ($workitem['is_new'] == True) {
$item->title = $workitem['project_name'] .': Created Comment \''. $workitem['title'] .'\'';
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['reference']);
}
else {
$item->title = $workitem['project_name'] .': Changed Comment \''. $workitem['title'] .'\'';
$item->link = $workitem_base_url .'/?target='. base64_encode($workitem['reference']);
}
$comment_type = '';
switch ($workitem['comment_type']) {
case 1:
$comment_type = 'Undefined';
break;
case 2:
$comment_type = 'General';
break;
case 3:
default:
$comment_type = 'Forum';
break;
}
$description .= "Comment Type: ". $comment_type ."
";
$description .= "Text: ". $workitem['comment_text'] ."
";
break;
}
$item->description = $description;
// add feed logo
$image = new FeedImage();
$image->title = $rss->title;
$image->url = get_origo_project_link($workitem['project_name']) .'/'. drupal_get_path('theme', variable_get('theme_default', 'oxymoron')) .'/favicon.ico';
$image->link = $rss->link;
$rss->image = $image;
$item->author = $workitem['user_name'];
$item->date = $workitem['timestamp'];
$rss->addItem($item);
}
$rss->saveFeed(variable_get('origo_feed_type', ''), $cache_file);
}
/**
* Retrieve the latest work item ID's from `$project_id'.
*/
function get_workitem_ids($project_id = NULL, $username) {
$project_id_list = array();
if (!isset($project_id) || $project_id == 0) {
// get project-id's of user
$project_id_list = get_projects_of_user($username);
}
else {
$project_id_list[] = $project_id;
}
// hashtable => array
$project_id_list = array_values($project_id_list);
// Check if any project IDs were returned at all.
$pid_list = array();
foreach ($project_id_list as $pid) {
if (is_int($pid) && $pid != 0) {
$pid_list[] = $pid;
}
}
if (count($pid_list) == 0) {
return array();
}
$wid_list = array();
$user_feed_show_unread = get_origo_setting(ORIGO_FEED_SHOW_UNREAD, True, $user->name);
// Note:
// The setting is misnamed.. use the inverted value!
$user_feed_show_unread = !(bool)$user_feed_show_unread;
$workitems = origo_auth_xmlrpc_session(
variable_get('origo_api', ''),
'workitem.list',
$pid_list, // project_id_list
$user_feed_show_unread, // unread only
0, // filter type
0, // start
100, // limit
'', // sort column
'' // sort order
);
if (xmlrpc_errno() == 0) {
foreach ($workitems as $w) {
$wid_list[] = $w['id'];
}
}
return $wid_list;
}
/**
* Retrieve a list of project ID's of $user.
*/
function get_projects_of_user($username) {
$project_id_list = array();
// projects where $username is owner or member
$projects = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'project.list_of_user', $username);
if (xmlrpc_errno() == 0) {
foreach ($projects as $p) {
$project_id_list["" . $p['project_id']] = $p['project_id'];
}
}
// projects where $username is bookmarker
$bookmarked = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.list_bookmark', $username);
if ((int)xmlrpc_errno() == 0) {
foreach ($bookmarked as $b) {
$project_id_list["". $p['project_id']] = $p['project_id'];
}
}
return $project_id_list;
}
function _cmp_workitem($a, $b) {
if ($a['timestamp'] == $b['timestamp']) {
return 0;
}
return ($a['timestamp'] > $b['timestamp']) ? -1 : 1;
}