[Fusionforge-commits] r13090 - in branches/Branch_5_1/src: common/forum www/news www/news/admin

Roland Mas lolando at fusionforge.org
Tue Apr 12 19:01:10 CEST 2011


Author: lolando
Date: 2011-04-12 19:01:10 +0200 (Tue, 12 Apr 2011)
New Revision: 13090

Modified:
   branches/Branch_5_1/src/common/forum/ForumHTML.class.php
   branches/Branch_5_1/src/www/news/admin/index.php
   branches/Branch_5_1/src/www/news/submit.php
Log:
Newsbyte-related forums need to belong to newsadmin only when approved for front page, for RBAC to be effective

Modified: branches/Branch_5_1/src/common/forum/ForumHTML.class.php
===================================================================
--- branches/Branch_5_1/src/common/forum/ForumHTML.class.php	2011-04-12 16:11:48 UTC (rev 13089)
+++ branches/Branch_5_1/src/common/forum/ForumHTML.class.php	2011-04-12 17:01:10 UTC (rev 13090)
@@ -43,94 +43,88 @@
 	$params['group']=$group_id;
 	$params['toptab']='forums';
 
-	/*
-		bastardization for news
-		Show icon bar unless it's a news forum
-	*/
-	if ($group_id == forge_get_config('news_group')) {
-		//this is a news item, not a regular forum
-		if ($forum_id) {
-			// Show this news item at the top of the page
-			$result = db_query_params ('SELECT submitted_by, post_date, group_id, forum_id, summary, details FROM news_bytes WHERE forum_id=$1',
-						   array ($forum_id));
-
+	if ($forum_id) {
+		// Check if this is a news item, to display it at the top of the page
+		$result = db_query_params ('SELECT submitted_by, post_date, group_id, forum_id, summary, details FROM news_bytes WHERE forum_id=$1',
+					   array ($forum_id));
+		
+		if (db_numrows($result) == 1) {
+			
 			// checks which group the news item belongs to
 			$params['group']=db_result($result,0,'group_id');
 			$params['toptab']='news';
 			$params['title']= _('Forum: ') . db_result($result,0,'summary');
 			$HTML->header($params);
-
+		
 			echo '<table><tr><td valign="top">';
-			if (!$result || db_numrows($result) < 1) {
-				echo '<p class="error">'._('Error - this news item was not found').'</p>';
-			} else {
-				$user = user_get_object(db_result($result,0,'submitted_by'));
-				$group = group_get_object($params['group']);
-				if (!$group || !is_object($group) || $group->isError()) {
-					exit_no_group();
-				}
-				echo '<p>
+			$user = user_get_object(db_result($result,0,'submitted_by'));
+			$group = group_get_object($params['group']);
+			if (!$group || !is_object($group) || $group->isError()) {
+				exit_no_group();
+			}
+			echo '<p>
 				<strong>'._('Posted by').':</strong> '.$user->getRealName().'<br />
 				<strong>'._('Date').':</strong> '. date(_('Y-m-d H:i'),db_result($result,0,'post_date')).'<br />
 				<strong>'._('Summary').':</strong>'.
-					util_make_link ('/forum/forum.php?forum_id='.db_result($result,0,'forum_id').'&group_id='.$group_id,
-							db_result($result,0,'summary')).'<br/>
+				util_make_link ('/forum/forum.php?forum_id='.db_result($result,0,'forum_id').'&group_id='.$group_id,
+						db_result($result,0,'summary')).'<br/>
 				<strong>'._('Project').':</strong>'.
-					util_make_link_g ($group->getUnixName(),db_result($result,0,'group_id'),$group->getPublicName()).'<br />
+				util_make_link_g ($group->getUnixName(),db_result($result,0,'group_id'),$group->getPublicName()).'<br />
 				</p>
 				';
-				$body = db_result($result,0,'details');
-				$body = TextSanitizer::purify($body);
-				if (!strstr($body,'<')) {
-					//backwards compatibility for non html messages
-					echo util_make_links(nl2br($body)); 
-				} else {
-					echo util_make_links($body);
-				}
-
-				// display classification
-				if ($params['group'] == forge_get_config('news_group')) { 
-				   print stripslashes(trove_news_getcatlisting(db_result($result,0,'forum_id'),0,1));
-				} elseif (forge_get_config('use_trove')) {
-				   print stripslashes(trove_getcatlisting($params['group'],0,1));
-				}
+			$body = db_result($result,0,'details');
+			$body = TextSanitizer::purify($body);
+			if (!strstr($body,'<')) {
+				//backwards compatibility for non html messages
+				echo util_make_links(nl2br($body)); 
+			} else {
+				echo util_make_links($body);
 			}
+			
+			// display classification
+			if ($params['group'] == forge_get_config('news_group')) { 
+				print stripslashes(trove_news_getcatlisting(db_result($result,0,'forum_id'),0,1));
+			} elseif (forge_get_config('use_trove')) {
+				print stripslashes(trove_getcatlisting($params['group'],0,1));
+			}
 			echo '</td><td valign="top" width="35%">';
 			echo $HTML->boxTop(_('Latest News'));
 			echo news_show_latest($params['group'],5,false);
 			echo $HTML->boxBottom();
 			echo '</td></tr></table>';
+		} else {
+			$HTML->header($params);
 		}
-	}
-
-	$menu_text=array();
-	$menu_links=array();
-
-	$menu_text[]=_('View Forums');
-	$menu_links[]='/forum/?group_id='.$group_id;
-
-	if ($f){
-		if ($forum_id) {
-			$menu_text[]=_('Discussion Forums:') .' '. $f->getName();
-			$menu_links[]='/forum/forum.php?forum_id='.$forum_id;
-		}
-		if (forge_check_perm ('forum_admin', $f->Group->getID())) {
-			$menu_text[]=_('Administration');
-			$menu_links[]='/forum/admin/?group_id='.$group_id;
-		} 
 	} else {
+		$menu_text=array();
+		$menu_links=array();
+		
+		$menu_text[]=_('View Forums');
+		$menu_links[]='/forum/?group_id='.$group_id;
+		
+		if ($f){
+			if ($forum_id) {
+				$menu_text[]=_('Discussion Forums:') .' '. $f->getName();
+				$menu_links[]='/forum/forum.php?forum_id='.$forum_id;
+			}
+			if (forge_check_perm ('forum_admin', $f->Group->getID())) {
+				$menu_text[]=_('Administration');
+				$menu_links[]='/forum/admin/?group_id='.$group_id;
+			} 
+		} else {
 			$gg=group_get_object($group_id);
 			if (forge_check_perm ('forum_admin', $group_id)) {
 				$menu_text[]=_('Administration');
 				$menu_links[]='/forum/admin/?group_id='.$group_id;
 			}
+		}
+		if (count($menu_text) > 0) {
+			$params['submenu'] =$HTML->subMenu($menu_text,$menu_links);
+		}
+		
+		site_project_header($params);
 	}
-	if (count($menu_text) > 0) {
-		$params['submenu'] =$HTML->subMenu($menu_text,$menu_links);
-	}
 
-	site_project_header($params);
-
 	$pluginManager = plugin_manager_get_object();
 	if ($f && $pluginManager->PluginIsInstalled('blocks') && plugin_hook ("blocks", "forum_".$f->getName()))
 		echo '<br />';

Modified: branches/Branch_5_1/src/www/news/admin/index.php
===================================================================
--- branches/Branch_5_1/src/www/news/admin/index.php	2011-04-12 16:11:48 UTC (rev 13089)
+++ branches/Branch_5_1/src/www/news/admin/index.php	2011-04-12 17:01:10 UTC (rev 13090)
@@ -40,6 +40,7 @@
 $summary = getStringFromRequest('summary');
 $details = getStringFromRequest('details');
 $id = getIntFromRequest('id');
+$for_group = getIntFromRequest('for_group');
 
 $feedback = htmlspecialchars(getStringFromRequest('feedback'));
 
@@ -61,6 +62,14 @@
 
 	*/
 	if ($post_changes) {
+		$result = db_query_params("SELECT nb.forum_id, fgl.group_id FROM news_bytes nb, forum_group_list fgl WHERE nb.id=$1 AND nb.group_id=$2 AND nb.forum_id=fgl.group_forum_id", array($id, $group_id));
+		if (db_numrows($result) < 1) {
+			exit_error(_('Newsbyte not found'),'news');
+		}
+		
+		$forum_id = db_result($result,0,'forum_id');
+		$old_group_id = db_result($result,0,'group_id');
+	
 		if ($approve) {
 			/*
 				Update the db so the item shows on the home page
@@ -77,22 +86,38 @@
 				$details='(none)';
 			}
 			
-				if (getStringFromRequest('_details_content_type') == 'html') {
-					$details = TextSanitizer::purify($details);
-				} else {
-					$details = htmlspecialchars($details);
-				}
+			if (getStringFromRequest('_details_content_type') == 'html') {
+				$details = TextSanitizer::purify($details);
+			} else {
+				$details = htmlspecialchars($details);
+			}
+
+			db_begin(); 
 			$result = db_query_params("UPDATE news_bytes SET is_approved=$1, summary=$2, 
 details=$3 WHERE id=$4 AND group_id=$5", array($status, htmlspecialchars($summary), $details, $id, $group_id));
-
+			
 			if (!$result || db_affected_rows($result) < 1) {
 				$error_msg .= _('Error On Update:');
 				$error_msg .= db_error();
+				db_rollback();
 			} else {
+				// If the forum has been moved to the newsadmin project
+				// (because the newsbyte has been approved),
+				// reassign it back to its original project
+				if ($group_id != $old_group_id) {
+					$result = db_query_params("UPDATE forum_group_list SET group_id=$1 WHERE group_forum_id=$2", array($group_id, $forum_id));
+					
+					$for_group = group_get_object($group_id);
+					$for_group->normalizeAllRoles();
+					$sitenews_group = group_get_object(forge_get_config('news_group'));
+					$sitenews_group->normalizeAllRoles();
+				}
+
 				$feedback .= _('Newsbyte Updated.');
 				// No notification if news is deleted.
 //				if ($status != 4)
 //					send_news_notification_email($id);
+				db_commit();
 			}
 			/*
 				Show the list_queue
@@ -196,6 +221,14 @@
 
 	if ($post_changes) {
 		if ($approve) {
+
+			$result=db_query_params("SELECT * FROM news_bytes WHERE id=$1 AND group_id=$2", array($id, $for_group));
+			if (db_numrows($result) < 1) {
+				exit_error(_('Newsbyte not found'),'news');
+			}
+			
+			$forum_id = db_result($result,0,'forum_id');
+
 			if ($status==1) {
 				/*
 					Update the db so the item shows on the home page
@@ -205,22 +238,45 @@
 				} else {
 					$details = htmlspecialchars($details);
 				}
-				$result=db_query_params("UPDATE news_bytes SET is_approved='1', post_date=$1, 
-summary=$2, details=$3 WHERE id=$4", array(time(), htmlspecialchars($summary), $details, $id));
+				db_begin();
+				$result=db_query_params('UPDATE news_bytes SET is_approved=1, post_date=$1, summary=$2, details=$3 WHERE id=$4',
+							array(time(),
+							      htmlspecialchars($summary),
+							      $details,
+							      $id));
 				if (!$result || db_affected_rows($result) < 1) {
 					$error_msg .= _('Error On Update:');
+					db_rollback();
 				} else {
+					db_query_params('UPDATE forum_group_list SET group_id=$1 WHERE group_forum_id=$2',
+							array(forge_get_config('news_group'),
+							      $forum_id));
+					$for_group = group_get_object($for_group);
+					$for_group->normalizeAllRoles();
+					$sitenews_group = group_get_object(forge_get_config('news_group'));
+					$sitenews_group->normalizeAllRoles();
+					db_commit();
 					$feedback .= _('Newsbyte Updated.');
 				}
 			} else if ($status==2) {
 				/*
 					Move msg to deleted status
 				*/
+				db_begin();
 				$result=db_query_params("UPDATE news_bytes SET is_approved='2' WHERE id=$1", array($id));
 				if (!$result || db_affected_rows($result) < 1) {
 					$error_msg .= _('Error On Update:');
 					$error_msg .= db_error();
+					db_rollback();
 				} else {
+					db_query_params('UPDATE forum_group_list SET group_id=$1 WHERE group_forum_id=$2',
+							array($for_group,
+							      $forum_id));
+					$for_group = group_get_object($for_group);
+					$for_group->normalizeAllRoles();
+					$sitenews_group = group_get_object(forge_get_config('news_group'));
+					$sitenews_group->normalizeAllRoles();
+					db_commit();
 					$feedback .= _('Newsbyte Deleted.');
 				}
 			}

Modified: branches/Branch_5_1/src/www/news/submit.php
===================================================================
--- branches/Branch_5_1/src/www/news/submit.php	2011-04-12 16:11:48 UTC (rev 13089)
+++ branches/Branch_5_1/src/www/news/submit.php	2011-04-12 17:01:10 UTC (rev 13090)
@@ -97,13 +97,12 @@
 			*/
 			
 			db_begin();
-			$g=group_get_object(forge_get_config('news_group'));
-			$f=new Forum($g);
+			$f = new Forum($group);
 			if (!$f->create(preg_replace('/[^_\.0-9a-z-]/','-', strtolower($summary)),$details,1,'',0,0)) {
 				db_rollback();
 				exit_error($f->getErrorMessage(),'news');
 			}
-			$g->normalizeAllRoles();
+			$group->normalizeAllRoles();
 			$new_id=$f->getID();
 			$sql='INSERT INTO news_bytes (group_id,submitted_by,is_approved,post_date,forum_id,summary,details) 
  VALUES ($1, $2, $3, $4, $5, $6, $7)';




More information about the Fusionforge-commits mailing list