[Fusionforge-commits] r9586 - trunk/gforge/www/export

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Apr 23 11:28:13 CEST 2010


Author: lolando
Date: 2010-04-23 11:28:13 +0200 (Fri, 23 Apr 2010)
New Revision: 9586

Added:
   trunk/gforge/www/export/rss20_docman.php
   trunk/gforge/www/export/rss20_forum.php
   trunk/gforge/www/export/rss20_tasks.php
   trunk/gforge/www/export/rss20_tracker.php
Log:
Added new RSS?\194?\160feeds for docman, forum, tasks and trackers

Added: trunk/gforge/www/export/rss20_docman.php
===================================================================
--- trunk/gforge/www/export/rss20_docman.php	                        (rev 0)
+++ trunk/gforge/www/export/rss20_docman.php	2010-04-23 09:28:13 UTC (rev 9586)
@@ -0,0 +1,165 @@
+<?php
+
+// $Id$
+
+// export a group's tracker bugs per artifact in RSS 2.0
+// Author: Jutta Horstmann, data in transit <jh at dataintransit.com>
+// Created: 01.10.07
+// Based on: export/rss20_tracker.php (by JH), docman/index.php
+// Changes:
+// Date         Author      Comment
+// 07.11.07     JH          show only public group feeds
+//
+//TO DO: Translations for error messages
+//Notes:
+// Keep in mind to write "&" in URLs as &amp; in RSS feeds
+
+
+include "pre.php";
+include "rss_utils.inc";
+require_once('common/docman/DocumentFactory.class');
+require_once('common/docman/DocumentGroupFactory.class');
+
+
+if (isset($_GET['group_id'])&&!empty($_GET['group_id'])&&is_numeric($_GET['group_id'])) {
+	$group_id = $_GET['group_id'];
+
+	$group =& group_get_object($group_id);
+
+	
+	//does group exist? do we get an object?
+	if (!$group || !is_object($group)) {
+		beginFeed();
+		endOnError('Could not get the Group object');
+	} elseif ($group->isError()) {
+	        beginFeed();
+		endOnError($group->getErrorMessage());
+	}
+    elseif (!$group->isPublic()){
+		beginFeed();
+		endOnError('No RSS feed available as group status is set to private.');
+	}
+	$groupname = $group->getPublicName();
+	$link = "/docman/index.php?group_id=$group_id";
+
+    beginFeed($groupname,$link);
+
+	//does documentation exist? do we get a factory?
+	$df = new DocumentFactory($group);
+	if ($df->isError()) {
+		endOnError($df->getErrorMessage());
+	}
+
+	$dgf = new DocumentGroupFactory($group);
+	if ($dgf->isError()) {
+		endOnError($dgf->getErrorMessage());
+	}
+	// Get the document groups info
+	$nested_groups =& $dgf->getNested();
+	
+	$d_arr =& $df->getDocuments();
+	
+	writeFeed($d_arr,$group_id, $nested_groups);
+	endFeed();
+	
+}//no group_id in GET
+else {
+	beginFeed();
+	displayError('Please supply a Group ID with the request.');
+	endFeed();
+}
+
+//**************************************************************++
+function beginFeed($groupname = "", $link = "") {
+	global $sys_default_domain, $sys_name, $sys_admin_email;
+	header("Content-Type: text/xml");
+	print '<?xml version="1.0" encoding="UTF-8"?>
+			<rss version="2.0">
+			';
+	print " <channel>\n";
+	print "  <title>".$sys_name." Project \"".$groupname."\" Documents</title>\n";
+	print "  <link>http://".$sys_default_domain.$link."</link>\n";
+	print "  <description>".$sys_name." Documents of \"".$groupname."\"</description>\n";
+	print "  <language>en-us</language>\n";
+	print "  <copyright>Copyright 2000-".date("Y")." ".$sys_name."</copyright>\n";
+	print "  <webMaster>".$sys_admin_email."</webMaster>\n";
+	print "  <lastBuildDate>".gmdate('D, d M Y G:i:s',time())." GMT</lastBuildDate>\n";
+	print "  <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
+	print "  <image>\n";
+	print "    <url>http://".$sys_default_domain."/images/bflogo-88.png</url>\n";
+	print "    <title>".$sys_name." Developer</title>\n";
+	print "    <link>http://".$sys_default_domain."/</link>\n";
+	print "    <width>124</width>\n";
+	print "    <heigth>32</heigth>\n";
+	print "  </image>\n";
+}
+
+function writeFeed($d_arr, $group_id){
+	global $sys_default_domain;
+	// ## default limit
+	//if (isset($limit) ||empty($limit)) $limit = 10;
+	//if ($limit > 100) $limit = 100;
+
+	/*
+	if (!is_array($nested_groups["$parent_group"])) {
+		return;
+	}
+	$child_count = count($nested_groups["$parent_group"]);
+	*/	
+	if (!$d_arr || count($d_arr) < 1) {
+		endOnError($Language->getText('docman','error_no_docs'));
+
+	} else {
+		//	Put the result set (list of documents for this group) into feed items
+
+		// ## item outputs
+		//$outputtotal = 0;
+		//loop through the documents
+		for ($j = 0; $j < count($d_arr); $j++) {
+			$link = (( $d_arr[$j]->isURL() ) ? $d_arr[$j]->getFileName() : "docman/view.php/".$d_arr[$j]->Group->getID()."/".$d_arr[$j]->getID()."/".$d_arr[$j]->getFileName() );
+			
+			print "  <item>\n";			
+			if (!is_object($d_arr[$j])) {
+                        	//just skip it
+			} elseif ($d_arr[$j]->isError()) {
+				print " <title>Error</title>".
+						"<description>".rss_description($d_arr[$j]->getErrorMessage())."</decription>";
+			} else {				
+				print "   <title>".$d_arr[$j]->getName()."</title>\n"; 
+				print "   <link>http://".$sys_default_domain."/".$link."</link>\n";
+				print "   <category>".$d_arr[$j]->getDocGroupName()."</category>\n";
+				
+				print "   <description>".
+						rss_description($d_arr[$j]->getDescription()).
+						" - Language: ". $d_arr[$j]->getLanguageName().
+						"</description>\n";
+				
+				print "   <author>".$d_arr[$j]->getCreatorRealName()."</author>\n";
+				//print "   <comment></comment>\n";
+				//print "   <pubDate>".gmdate('D, d M Y G:i:s',time())." GMT</pubDate>\n";
+				//print "   <guid></guid>\n";
+			}//else (everything ok)			
+			print "  </item>\n";
+			
+			//$outputtotal++;
+			//if ($outputtotal >= $limit) break;
+		}//for loop
+	}//else (there are documents)	
+}
+
+
+function displayError($errorMessage) {
+	print " <title>Error</title>".
+			"<description>".rss_description($errorMessage)."</description>";
+}
+
+function endFeed() {
+			print '</channel></rss>';
+			exit();
+		}
+
+function endOnError($errorMessage) {
+	displayError($errorMessage);
+	endFeed();
+}
+?>

Added: trunk/gforge/www/export/rss20_forum.php
===================================================================
--- trunk/gforge/www/export/rss20_forum.php	                        (rev 0)
+++ trunk/gforge/www/export/rss20_forum.php	2010-04-23 09:28:13 UTC (rev 9586)
@@ -0,0 +1,359 @@
+<?php
+
+// $Id$
+
+// export forum posts in RSS 2.0
+// Author: Jutta Horstmann, data in transit <jh at dataintransit.com>
+// Created: 14.01.08
+// Based on: export/rss20_tracker.php (by JH), docman/index.php, export/forum.php, forum/forum.php
+// Changes:
+// Date         Author      Comment
+// 31.01.08     JH          error handling & display for valid groups with no forums
+//                          and invalid group_ids /forum_ids parameters (see mail CP 30.01.08)
+//
+// TO DO: Translations for error messages
+// Notes:
+// Keep in mind to write "&" in URLs as &amp; in RSS feeds
+
+// Doc: 
+// Params in calling URL: 
+// group_ids (0 - x group ids, separated by "+"), optional, default: not set
+// forum_ids (0 - x forum ids, separated by "+"), optional, default: not set
+// number (no. of feed items), optional, default: 10
+// item (feed variant, items should be thread headings or postings), optional, default:thread
+// none: 10 last threads of evolvis as a whole
+//
+
+include "pre.php";
+include "rss_utils.inc";
+require_once('common/forum/Forum.class');
+require_once('common/forum/ForumFactory.class');
+require_once('common/forum/ForumMessage.class');
+require_once('common/forum/ForumMessageFactory.class');
+
+global $sys_name, $sys_default_domain;
+
+//Initialize
+$groups = array();
+$forums = array();
+$farr = array();
+$group_ids = array();
+$forum_ids = array();
+$n_forums=0;
+$n_groups=0;
+$n_forum_ids=0;
+$n_group_ids=0;
+
+$where_group = "";
+$where_forum = "";
+$where_threads = "";
+$where_start_or = "";
+$where_end_or = "";
+
+//Defaults
+$number_items = 10;
+$max_number_items = 100;
+$show_threads = true;
+
+//Debug?
+$debug = false;
+
+// ----------------------- check and extract params in GET ----------------------------
+
+//--- filter by group_ids - resolve them to forums ---
+if (isset($_GET['group_ids'])&&!empty($_GET['group_ids'])) {
+    //explode: http changes "+" to " "
+    $group_ids = array_unique(array_merge($group_ids, explode(" ",$_GET['group_ids'])));
+    
+    //loop through group_ids
+    for ($i=0; $i<count($group_ids);$i++){
+        if (is_numeric($group_ids[$i])) {
+            $group =& group_get_object($group_ids[$i]);
+            //does group exist? do we get an object? is group public? does it use forums?
+            if ($group && is_object($group) && !$group->isError() 
+                        && $group->isPublic() && $group->usesForum()){
+                $groups[] = $group;
+                //valid forums from forum_ids param (needed for feed title)
+                $n_group_ids++;
+                                
+                //this groups' forums in array (code based on forum/index.php)
+                $ff=new ForumFactory($group);
+                if ($ff &&is_object($ff) && !$ff->isError()) {
+                    $farr = array_merge($farr, $ff->getForums());
+                    if (count($farr) < 1) {
+                            error_log("Forum RSS: ".$Language->getText('forum','error_no_forums_found', array($group->getPublicName())),0);
+                    }
+                }
+                else error_log("Forum RSS: ForumFactory error: ".$ff->getErrorMessage()." - No forums for group ".$group->getPublicName(),0);
+            }
+	    else error_log("Forum RSS: group object error",0);
+        }
+	else error_log("Forum RSS: invalid group_ids param: ".$group_ids[$i],0);
+    }
+}
+
+// ----------- add forums called by forum_ids param, if any ------------
+if (isset($_GET['forum_ids']) && !empty($_GET['forum_ids'])) {
+    //explode: http changes "+" to " "
+    $forum_ids = array_unique(explode(' ',$_GET['forum_ids']));
+    
+    foreach ($forum_ids as $fid){
+        //we got strings from explode(), cast them to int (if possible)
+        $fid= (int) $fid;
+
+        if (is_numeric($fid)) {
+            //based on code from forum/forum.php: Get the group_id based on this forum_id
+            $result=db_query("SELECT group_id FROM forum_group_list
+                              WHERE group_forum_id='".$fid."'");
+            if ($result && db_numrows($result) >= 1) {
+                $forum_group_id=db_result($result,0,'group_id');
+    
+                $g =& group_get_object($forum_group_id);
+                if ($g && is_object($g) && !$g->isError() && $g->isPublic() && $g->usesForum()) {
+                    $f=new Forum($g,$fid);
+                    
+                    if ($f && is_object($f) && !$f->isError() && $f->isPublic()) {
+                        //add group to group array, forum to forum array
+                        $groups[] = $g;
+                        $farr[] = $f;
+                        //valid forums from forum_ids param (needed for feed title)
+                        $n_forum_ids++;
+                    }
+		    else error_log("Forum RSS: forum object error",0);
+                }
+		else error_log("Forum RSS: forum group oject error",0);
+            }//there is a db result
+	    else error_log("Forum RSS: no forum group in DB",0);
+        }//url param is valid (numeric)
+	else error_log("Forum RSS: invalid forum_ids param",0);
+    }//for loop
+
+}
+
+//if forum_ids specifies forums contained also in group_ids: drop duplicates
+//does not filter groups by forums!
+
+//merge $forums and $farr
+$forums = array_merge($farr, $forums);
+//unique for objects
+$forums = object_array_unique($forums);
+$groups = object_array_unique($groups);
+
+$n_forums = count($forums);
+$n_groups = count($groups);
+
+// ----------------------- error cases ---------------------
+$error_no_messages = false;
+//there were filter parameters but they were invalid or
+//there were valid group_ids, but they contained no forums
+
+if (($n_groups == 0 && count($_GET['group_ids'])>0) || 
+    ($n_forums == 0 && count($_GET['forum_ids'])>0) ||
+    ($n_groups > 0 && $n_forums == 0)){
+    $error_no_messages = "No forum messages found. Please check for invalid parameters and if the project(s) contain public forums.";
+}
+
+
+
+//-------------------- other parameters --------------------
+//number
+if (isset($_GET['number']) && !empty($_GET['number']) &&
+    is_numeric($_GET['number']) && $_GET['number']>0) {
+    $number_items = $_GET['number'];
+    if ($number_items > $max_number_items) $number_items = $max_number_items;
+}
+
+//item
+if (isset($_GET['item']) && !empty($_GET['item']) && ($_GET['item'] == "posting")) {
+    $show_threads = false;    
+} 
+else $where_threads = " AND is_followup_to=0";
+
+
+// ------------- general settings and defaults for filtered and non-filtered feeds -------------
+$feed_title_desc = $show_threads ? "Current threads" : "Recent postings";
+$feed_title = $sys_name." Forums: ".$feed_title_desc; //all site's forums
+$feed_link = "http://".$sys_default_domain;
+$feed_desc = $sys_name." Forums";
+
+
+// -------------for filtered feeds - set feed title, link and description-------------
+
+//more than one group and/or multiple forums -> title is "Selected Evolvis Forums..."; link is default
+if ($n_groups>1 || $n_forums>0) {
+    $feed_title = "Selected ".$feed_title;
+    if ($debug) error_log ("Forum RSS: g: ".$n_groups." f: ".$n_forums,0);
+}
+//one group and no forum param -> Groupname in feed title; link to group
+if ($n_groups == 1 && $n_forum_ids == 0){
+    $feed_title = $groups[0]->getPublicName()." Forums: ".$feed_title_desc;
+    $feed_link = $feed_link . "/forum/?group_id=".$groups[0]->getID();
+    $feed_desc = $groups[0]->getDescription(); //Feed desc = project desc
+}
+//one forum and no (valid) group param 
+//-> forum's group name and forum name in feed title; link to forum
+if ($n_forum_ids == 1 && $n_group_ids == 0){
+    $forum_group = $forums[0]->getGroup();
+    
+    $feed_title = $forum_group->getPublicName().' - "' .$forums[0]->getName().'" forum: '.
+                $feed_title_desc;
+    $feed_link = $feed_link . "/forum/forum.php?forum_id=".$forums[0]->getID();
+    $feed_desc = $forums[0]->getDescription();
+}
+
+// --------------------------- build the feed -------------------------------
+
+beginForumFeed($feed_title, $feed_link, $feed_desc);
+
+// ----------------- collect the messages -----------
+
+//only if no $error_no_messages
+if (!$error_no_messages){
+    //messages to be displayed
+    $rss_messages = array();
+
+    //assemble SQL statement to get messages from selected forums
+    if ($n_forums>0){
+        $where_start_or = " AND (";
+        $where_end_or = ") ";
+    }
+    
+    $cnt = 0;
+    foreach ($forums as $f){
+        $where_forum .= " f.group_forum_id = ". $f->getID();
+        $cnt++;
+        $where_forum .= $cnt < $n_forums ? " OR " : "";
+    }
+    //get forum messages 
+    $msg_sql = 
+        "SELECT f.group_forum_id AS group_forum_id, 
+                f.msg_id AS msg_id, f.subject AS subject, f.most_recent_date AS most_recent_date,
+                f.has_followups, f.thread_id,
+                u.realname AS user_realname,
+                g.group_id AS group_id, g.group_name as group_name,
+                fg.forum_name as forum_name, fg.description AS forum_desc
+        FROM forum f,users u, groups g,forum_group_list fg
+        WHERE f.posted_by=u.user_id
+        AND g.group_id = fg.group_id
+        AND f.group_forum_id = fg.group_forum_id 
+        AND g.is_public=1
+        AND g.status='A'
+        AND g.use_forum=1
+        AND fg.is_public=1 ".
+        $where_start_or . $where_forum . $where_end_or. $where_threads. 
+        " ORDER BY f.most_recent_date DESC
+        LIMIT ". $number_items;
+    
+    $res_msg = db_query($msg_sql);
+    if (!$res_msg || db_numrows($res_msg) < 1) {
+            error_log("Forum RSS: ".$Language->getText('forum','error_forum_not_found').' '.db_error(),0);
+    }
+    if ($debug) error_log("Forum RSS: ". $msg_sql,0);
+
+
+    while ($row_msg = db_fetch_array($res_msg)) {
+        //get thread name for posting
+        $res_thread = db_query("
+            SELECT subject  
+            FROM forum
+            WHERE is_followup_to=0 AND thread_id = ".$row_msg['thread_id']);
+        $row_thread = db_fetch_array($res_thread);
+        if (!$res_thread || db_numrows($res_thread) != 1) {
+                error_log("Forum RSS: Could not get thread subject to thread-ID ".$row_msg['thread_id'],0);
+        }    
+        //category: Project name - Forum Name - Thread Name
+        $item_cat = $row_msg['group_name']." - ".$row_msg['forum_name']." -- ".$row_thread['subject'];
+        writeForumFeed($row_msg, $item_cat);
+    }
+}//end no $error_no_messages
+else {
+    displayError($error_no_messages);
+}
+endFeed(); 	
+	
+
+
+//*********************** HELPER FUNCTIONS ***************************************
+function beginForumFeed($feed_title, $feed_link, $feed_desc) {
+	global $sys_default_domain, $sys_name, $sys_admin_email;
+	header("Content-Type: text/xml");
+	print '<?xml version="1.0" encoding="UTF-8"?>
+			<rss version="2.0">
+			';
+	print " <channel>\n";
+	print "  <title>".$feed_title."</title>\n";
+	print "  <link>".$feed_link."</link>\n";
+	print "  <description>".$feed_desc."</description>\n";
+	print "  <language>en-us</language>\n";
+	print "  <copyright>Copyright 2000-".date("Y")." ".$sys_name."</copyright>\n";
+	print "  <webMaster>".$sys_admin_email."</webMaster>\n";
+	print "  <lastBuildDate>".gmdate('D, d M Y G:i:s',time())." GMT</lastBuildDate>\n";
+	print "  <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
+	print "  <image>\n";
+	print "    <url>http://".$sys_default_domain."/images/bflogo-88.png</url>\n";
+	print "    <title>".$sys_name." Developer</title>\n";
+	print "    <link>http://".$sys_default_domain."/</link>\n";
+	print "    <width>124</width>\n";
+	print "    <heigth>32</heigth>\n";
+	print "  </image>\n";
+}
+
+function writeForumFeed($msg, $item_cat){
+    global $sys_default_domain, $show_threads;
+            
+    $link = "forum/message.php?msg_id=".$msg['msg_id'];
+
+    //------------ build one feed item ------------
+    print "  <item>\n";					
+        print "   <title>".$msg['subject']."</title>\n"; 
+        print "   <link>http://".$sys_default_domain."/".$link."</link>\n";
+        print "   <category>".$item_cat."</category>\n";
+                //print "   <description>".rss_description($item_desc)."</description>\n";
+        print "   <author>".$msg['user_realname']."</author>\n";
+                //print "   <comment></comment>\n";
+        print "   <pubDate>".gmdate('D, d M Y G:i:s',$msg['most_recent_date'])." GMT</pubDate>\n";
+                //print "   <guid></guid>\n";			
+    print "  </item>\n";
+
+}
+
+
+function displayError($errorMessage) {
+	print " <title>Error</title>".
+		"<description>".rss_description($errorMessage)."</description>";
+}
+
+function endFeed() {
+    print '</channel></rss>';
+    exit();
+}
+
+function endOnError($errorMessage) {
+	displayError($errorMessage);
+	endFeed();
+}
+
+//function taken from here http://de3.php.net/manual/de/function.array-unique.php#75307
+function object_array_unique($array, $keep_key_assoc = false)
+{
+    $duplicate_keys = array();
+    $tmp         = array();       
+
+    foreach ($array as $key=>$val)
+    {
+        // convert objects to arrays, in_array() does not support objects
+        if (is_object($val))
+            $val = (array)$val;
+
+        if (!in_array($val, $tmp))
+            $tmp[] = $val;
+        else
+            $duplicate_keys[] = $key;
+    }
+
+    foreach ($duplicate_keys as $key)
+        unset($array[$key]);
+       
+    return $keep_key_assoc ? $array : array_values($array);
+}
+?>
\ No newline at end of file

Added: trunk/gforge/www/export/rss20_tasks.php
===================================================================
--- trunk/gforge/www/export/rss20_tasks.php	                        (rev 0)
+++ trunk/gforge/www/export/rss20_tasks.php	2010-04-23 09:28:13 UTC (rev 9586)
@@ -0,0 +1,280 @@
+<?php
+include "../include/pre.php";
+include "rss_utils.inc";
+
+global $sys_name, $sys_default_domain;
+
+//Default Vars
+$number_items = 10;
+$max_number_items = 100;
+$show_threads = true;
+$number=10;
+$max_number=100;
+$additive=' AND ';
+$btwg='';
+$btwp='';
+$project='';
+$us='';
+
+//group and project and user, or group or project or user?
+//take care: status means AND to all (user or group, but AND status)
+if (isset($_GET['OR']))
+{
+	$additive=' OR ';
+}
+
+$user_arr=handle_getvar('user_ids');
+if(isset($user_arr[0]))
+{
+	foreach($user_arr AS $single_user_id)
+	{
+		$user.=" OR (a.assigned_to_id = '".$single_user_id."')";
+	}
+	$user='('.substr($user,4).')';
+}
+//group_ids
+$projects=array();
+$groups = handle_getvar('group_ids');
+if(isset($groups[0])) //die projekte der gruppen werden in $projects gespeichert
+{
+	foreach($groups AS $group)
+	{
+		$sql="SELECT group_project_id FROM project_group_list WHERE group_id='".$group."'";
+		$res=pg_query($sql);
+		while($row=db_fetch_array($res))
+		{
+			$projects[]=$row['group_project_id'];
+		}
+	}
+}
+$p=handle_getvar('group_project_ids');
+$projects = array_unique(array_merge($projects,$p)); //die projekte der getvars kommen dazu
+if(isset($projects[0]))
+{
+	foreach($projects AS $project)
+	{
+		$project_sq.=" OR (group_project_id = '".$project."')";
+		/*$sql="SELECT project_name,group_id FROM project_group_list WHERE group_project_id='".$project."'";
+		$res=pg_query($sql);
+		if(pg_num_rows($res)==0)
+		{
+			$project_c[$project]['project_name']='Wrong or deleted project';
+			$project_c[$project]['group_id']='0';
+		} else
+		{
+			$project_c[$project]=db_fetch_array($res);
+		}
+		if(!isset($group_c[$project_c[$project]['group_id']]))
+		{
+			$sql="SELECT group_name FROM groups WHERE group_id='".$project_c[$project]['group_id']."'";
+			$res2=pg_query($sql);
+			if(pg_num_rows($res2)==0)
+			{
+				$group_c[$project_c[$project]['group_id']]='Wrong or deleted group';
+			} else
+			{
+				$a=db_fetch_array($res2);
+				$group_c[$project_c[$project]['group_id']]=$a['group_name'];
+			}
+		}*/
+		
+	}
+$project_sq='('.substr($project_sq,4).')';
+}
+
+foreach(handle_getvar('status_ids') AS $status_id)
+{
+	$status.=" OR (status_id = '".$status_id."')";
+}
+if(isset($status))
+{
+	$status='('.substr($status,4).')';
+}
+
+//important for correct sql-syntax
+if(!empty($status))
+{
+	$status=' AND '.$status;
+}
+if(!empty($project_sq) OR !empty($user) OR !empty($status))
+{
+	$us="AND ";
+}
+if(!empty($project_sq) AND !empty($user))
+{
+	$btwp=$additive;
+}
+
+//calculates number of shown 
+if (isset($_GET['number']) AND ctype_digit($_GET['number']))
+{
+	if($_GET['number']<=$max_number AND $_GET['number']>0)
+	{
+		$number=$_GET['number'];
+	} elseif($_GET['number']>$max_number)
+	{
+		$number=$max_number;
+	}
+}
+
+//creating, sending, and using the query
+
+$sql="
+	SELECT DISTINCT
+		pt.*,u.realname AS user_realname
+	FROM
+		project_task pt,users u,project_assigned_to a
+	WHERE
+		".is_needed('(').$project_sq." ".$btwp."
+		".$user." 
+		".$status.is_needed(')')."
+		".$us."u.user_id=pt.created_by
+		AND pt.project_task_id=a.project_task_id
+	ORDER BY
+		last_modified_date
+	LIMIT
+		".$number.";";
+$res=pg_query($sql);
+$i=0;
+
+beginTaskFeed('evolvis: Current Tasks',$sys_default_domain,'See all the tasks you want to see!');
+if(0<pg_num_rows($res))
+{
+	while($i<pg_num_rows($res))
+	{
+		$sql1="SELECT group_id,project_name FROM project_group_list WHERE group_project_id='".pg_fetch_result($res,$i,'group_project_id')."'";// AND is_public";
+		$res1=pg_query($sql1);
+		if(pg_num_rows($res1)==1)
+		{
+			$row1=db_fetch_array($res1);
+			$project_c[pg_fetch_result($res,$i,'group_project_id')]['group_id']=$row1['group_id'];
+			if(isset($row1['project_name']))
+			{
+				$project_c[pg_fetch_result($res,$i,'group_project_id')]['project_name']=$row1['project_name'];
+			} else
+			{
+				$project_c[pg_fetch_result($res,$i,'group_project_id')]['project_name']='Wrong or deleted project';
+			}
+			$sql2="SELECT group_name FROM groups WHERE group_id='".$row1['group_id']."'";
+			$res2=pg_query($sql2);
+			$row2=db_fetch_array($res2);
+			if(isset($row2['group_name']))
+			{
+				$group_c[$row1['group_id']]=$row2['group_name'];
+			} else
+			{
+				$group_c[$row1['group_id']]='Wrong or deleted group';
+			}
+	
+	
+	
+			$item_cat = $group_c[$project_c[pg_fetch_result($res,$i,'group_project_id')]['group_id']]." - ".$project_c[pg_fetch_result($res,$i,'group_project_id')]['project_name']." -- ".pg_fetch_result($res,$i,'summary');
+			$ar['project_task_id']=pg_fetch_result($res,$i,'project_task_id');
+			$ar['group_project_id']=pg_fetch_result($res,$i,'group_project_id');
+			$ar['group_id']=$project_c[pg_fetch_result($res,$i,'group_project_id')]['group_id'];
+			$ar['most_recent_date']=pg_fetch_result($res,$i,'last_modified_date');
+			$ar['subject']=pg_fetch_result($res,$i,'summary');
+			$ar['user_realname']=pg_fetch_result($res,$i,'user_realname');
+			$ar['details']=pg_fetch_result($res,$i,'details');
+			writeTaskFeed($ar,$item_cat);
+		}
+		$i++;
+	}
+} else
+{
+	displayError('No tasks found! Please check for invalid params.');
+}
+endFeed();
+
+
+
+
+//*********************** HELPER FUNCTIONS ***************************************
+
+function is_needed($str)
+{
+	global $project_sq,$user,$status;
+	if(!empty($project_sq) OR !empty($user) OR !empty($status))
+	{
+		return $str;
+	} else
+	{
+		return '';
+	}
+}
+function handle_getvar($name)
+{
+	$return = array();
+	if(isset($_GET[$name]))
+	{
+		$vars = array_unique(explode(" ",$_GET[$name]));
+		foreach ($vars as $var)
+		{
+			if(ctype_digit($var))
+			{
+				$return[]=$var;
+			}
+		}
+	}
+	return $return;
+}
+
+
+function beginTaskFeed($feed_title, $feed_link, $feed_desc) {
+	global $sys_default_domain, $sys_name, $sys_admin_email;
+	header("Content-Type: text/xml");
+	print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+	print "<rss version=\"2.0\">\n";
+	print " <channel>\n";
+	print "  <title>".$feed_title."</title>\n";
+	print "  <link>".$feed_link."</link>\n";
+	print "  <description>".$feed_desc."</description>\n";
+	print "  <language>en-us</language>\n";
+	print "  <copyright>Copyright 2000-".date("Y")." ".$sys_name."</copyright>\n";
+	print "  <webMaster>".$sys_admin_email."</webMaster>\n";
+	print "  <lastBuildDate>".gmdate('D, d M Y G:i:s',time())." GMT</lastBuildDate>\n";
+	print "  <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
+	print "  <image>\n";
+	print "    <url>http://".$sys_default_domain."/images/bflogo-88.png</url>\n";
+	print "    <title>".$sys_name." Developer</title>\n";
+	print "    <link>http://".$sys_default_domain."/</link>\n";
+	print "    <width>124</width>\n";
+	print "    <heigth>32</heigth>\n";
+	print "  </image>\n";
+}
+
+function writeTaskFeed($msg, $item_cat){
+    global $sys_default_domain, $show_threads;
+            
+  $link = "pm/task.php?func=detailtask&amp;project_task_id=".$msg['project_task_id']."&amp;group_project_id=".$msg['group_project_id']."&amp;group_id=".$msg['group_id'];//group_id missing
+
+    //------------ build one feed item ------------
+    print "  <item>\n";					
+        print "   <title>".$msg['subject']."</title>\n"; 
+        print "   <link>http://".$sys_default_domain."/".$link."</link>\n";
+        print "   <category>".$item_cat."</category>\n";
+        print "   <description>".$msg['details']."</description>\n";
+        print "   <author>".$msg['user_realname']."</author>\n";
+                //print "   <comment></comment>\n";
+        print "   <pubDate>".gmdate('D, d M Y G:i:s',$msg['most_recent_date'])." GMT</pubDate>\n";
+                //print "   <guid></guid>\n";			
+    print "  </item>\n";
+
+}
+
+
+function displayError($errorMessage) {
+	print "  <title>Error</title>\n".
+		"  <description>".$errorMessage."</description>";
+}
+
+function endFeed() {
+    print "\n </channel>\n</rss>";
+    exit();
+}
+
+function endOnError($errorMessage) {
+	displayError($errorMessage);
+	endFeed();
+}
+?>

Added: trunk/gforge/www/export/rss20_tracker.php
===================================================================
--- trunk/gforge/www/export/rss20_tracker.php	                        (rev 0)
+++ trunk/gforge/www/export/rss20_tracker.php	2010-04-23 09:28:13 UTC (rev 9586)
@@ -0,0 +1,147 @@
+<?php
+
+// $Id$
+
+// export a group's tracker bugs per artifact in RSS 2.0
+// Author: Jutta Horstmann, data in transit <jh at dataintransit.com>
+// Created: 01.10.07
+// Based on: export/tracker.php, export/rss20_newreleases.php, tracker/ind.php
+// Changes:
+// Date         Author      Comment
+// 07.11.07     JH          show only public group feeds
+//
+//TO DO: Translations for error messages
+//Notes:
+// Keep in mind to write "&" in URLs as &amp; in RSS feeds
+
+
+include "pre.php";
+include "rss_utils.inc";
+
+
+if (isset($_GET['group_id'])&&!empty($_GET['group_id'])&&is_numeric($_GET['group_id'])) {
+	$group_id = $_GET['group_id'];
+
+	$group =& group_get_object($group_id);
+
+	
+	//does group exist? do we get an object?
+	if (!$group || !is_object($group)) {
+		beginFeed();
+		endOnError('Could not get the Group object');
+	} elseif ($group->isError()) {
+	        beginFeed();
+		endOnError($group->getErrorMessage());
+	}
+    elseif (!$group->isPublic()){
+		beginFeed();
+		endOnError('No RSS feed available as group status is set to private.');
+	}
+	$groupname = $group->getPublicName();
+	$link = "/tracker/?group_id=$group_id";
+
+        beginFeed($groupname,$link);
+
+	//does tracker exist? do we get a factory?
+	$atf = new ArtifactTypeFactory($group);
+	if (!$atf || !is_object($atf) || $atf->isError()) {
+		endOnError('Could Not Get ArtifactTypeFactory');
+	}
+
+	$at_arr =& $atf->getArtifactTypes();
+	
+	writeFeed($at_arr,$group_id);
+	endFeed();
+	
+}//no group_id in GET
+else {
+	beginFeed();
+	displayError('Please supply a Group ID with the request.');
+	endFeed();
+}
+
+//**************************************************************++
+function beginFeed($groupname = "", $link = "") {
+	global $sys_default_domain, $sys_name, $sys_admin_email;
+	header("Content-Type: text/xml");
+	print '<?xml version="1.0" encoding="UTF-8"?>
+			<rss version="2.0">
+			';
+	print " <channel>\n";
+	print "  <title>".$sys_name." Project \"".$groupname."\" Bug Trackers</title>\n";
+	print "  <link>http://".$sys_default_domain.$link."</link>\n";
+	print "  <description>".$sys_name." Bug Trackers of \"".$groupname."\"</description>\n";
+	print "  <language>en-us</language>\n";
+	print "  <copyright>Copyright 2000-".date("Y")." ".$sys_name."</copyright>\n";
+	print "  <webMaster>".$sys_admin_email."</webMaster>\n";
+	print "  <lastBuildDate>".gmdate('D, d M Y G:i:s',time())." GMT</lastBuildDate>\n";
+	print "  <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
+	print "  <image>\n";
+	print "    <url>http://".$sys_default_domain."/images/bflogo-88.png</url>\n";
+	print "    <title>".$sys_name." Developer</title>\n";
+	print "    <link>http://".$sys_default_domain."/</link>\n";
+	print "    <width>124</width>\n";
+	print "    <heigth>32</heigth>\n";
+	print "  </image>\n";
+}
+
+function writeFeed($at_arr, $group_id){
+	global $sys_default_domain;
+	// ## default limit
+	//if (isset($limit) ||empty($limit)) $limit = 10;
+	//if ($limit > 100) $limit = 100;
+
+	if (!$at_arr || count($at_arr) < 1) {
+		endOnError($Language->getText('tracker','no_trackers_text'));
+
+	} else {
+		//	Put the result set (list of trackers for this group) into feed items
+
+		// ## item outputs
+		//$outputtotal = 0;
+		//loop through the bug trackers
+		for ($j = 0; $j < count($at_arr); $j++) {
+			print "  <item>\n";			
+			if (!is_object($at_arr[$j])) {
+                        	//just skip it
+			} elseif ($at_arr[$j]->isError()) {
+				print " <title>Error</title>".
+						"<description>".rss_description($at_arr[$j]->getErrorMessage())."</decription>";
+			} else {				
+				print "   <title>".$at_arr[$j]->getName()."</title>\n";
+				print "   <link>http://".$sys_default_domain."/tracker?atid=".$at_arr[$j]->getID()."&amp;group_id=".$group_id."&amp;func=browse</link>\n";
+				print "   <description>".
+						rss_description($at_arr[$j]->getDescription()).
+						" - Open Bugs: ".(int) $at_arr[$j]->getOpenCount() .
+						", Total Count: ". (int) $at_arr[$j]->getTotalCount() .
+						"</description>\n";
+				print "   <author></author>\n";
+				//print "   <comment></comment>\n";
+				//print "   <pubDate>".gmdate('D, d M Y G:i:s',time())." GMT</pubDate>\n";
+				//print "   <guid></guid>\n";
+			}//else (everything ok)			
+			print "  </item>\n";
+			
+			//$outputtotal++;
+			//if ($outputtotal >= $limit) break;
+		}//for loop
+	}//else (there are trackers)	
+}
+
+
+function displayError($errorMessage) {
+	print " <title>Error</title>".
+			"<description>".rss_description($errorMessage)."</description>";
+}
+
+function endFeed() {
+			print '</channel></rss>';
+			exit();
+		}
+
+function endOnError($errorMessage) {
+	displayError($errorMessage);
+	endFeed();
+}
+
+?>




More information about the Fusionforge-commits mailing list