[Fusionforge-commits] r11707 - in trunk/src/plugins/extratabs: common etc www

Franck VILLAUME nerville at libremir.placard.fr.eu.org
Sun Dec 5 17:55:29 CET 2010


Author: nerville
Date: 2010-12-05 17:55:29 +0100 (Sun, 05 Dec 2010)
New Revision: 11707

Modified:
   trunk/src/plugins/extratabs/common/ExtraTabsPlugin.class.php
   trunk/src/plugins/extratabs/etc/extratabs.ini
   trunk/src/plugins/extratabs/www/index.php
Log:
cleanup and validate plugin

Modified: trunk/src/plugins/extratabs/common/ExtraTabsPlugin.class.php
===================================================================
--- trunk/src/plugins/extratabs/common/ExtraTabsPlugin.class.php	2010-12-05 14:15:31 UTC (rev 11706)
+++ trunk/src/plugins/extratabs/common/ExtraTabsPlugin.class.php	2010-12-05 16:55:29 UTC (rev 11707)
@@ -5,6 +5,7 @@
  * Copyright 2005, Raphaël Hertzog
  * Copyright 2009, Roland Mas
  * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
+ * Copyright 2010, Franck Villaume - Capgemini
  * http://fusionforge.org
  *
  * This file is part of FusionForge.
@@ -30,34 +31,42 @@
 		$this->Plugin() ;
 		$this->name = "extratabs" ;
 		$this->text = "Extra tabs";
-		$this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
-		$this->hooks[] = "groupisactivecheckboxpost" ; //
-		$this->hooks[] = "project_admin_plugins" ;
-		$this->hooks[] = "groupmenu" ;  // To put into the project tabs
+		$this->_addHook('groupisactivecheckbox'); // The "use ..." checkbox in editgroupinfo
+		$this->_addHook('groupisactivecheckboxpost');
+		$this->_addHook('project_admin_plugins');
+		$this->_addHook('groupmenu'); // To put into the project tabs
 	}
 
-	function CallHook ($hookname, &$params) {
+	function CallHook($hookname, &$params) {
 		global $HTML;
-		
-		if ($hookname == "project_admin_plugins") {
-			$group_id=$params['group_id'];
-			echo '<p>'.util_make_link ('/plugins/extratabs/index.php?group_id='.$group_id,
-					     _('Extra Tabs Admin')) . '</p>';	       
-		} elseif ($hookname == "groupmenu") {
-			$group_id=$params['group'];
-			$project = group_get_object($group_id);
-			if (!$project || !is_object($project))
-				return;
-			if ($project->isError())
-				return;
-			if (!$project->isProject())
-				return;
-			$res_tabs = db_query_params ('SELECT tab_name, tab_url FROM plugin_extratabs_main WHERE group_id=$1 ORDER BY index',
-						     array ($group_id)) ;
-			while ($row_tab = db_fetch_array($res_tabs)) {
-				$params['DIRS'][] = $row_tab['tab_url'];
-				$params['TITLES'][] = $row_tab['tab_name'];
+
+		switch ($hookname) {
+			case "project_admin_plugins": {
+				$group_id = $params['group_id'];
+				$project = group_get_object($group_id);
+				if ($project->usesPlugin($this->name)) {
+					echo '<p>'.util_make_link('/plugins/extratabs/index.php?group_id='.$group_id,
+					     _('Extra Tabs Admin')) . '</p>';
+				}
+				break;
 			}
+			case "groupmenu": {
+				$group_id = $params['group'];
+				$project = group_get_object($group_id);
+				if (!$project || !is_object($project))
+					return;
+				if ($project->isError())
+					return;
+				if (!$project->isProject())
+					return;
+				$res_tabs = db_query_params('SELECT tab_name, tab_url FROM plugin_extratabs_main WHERE group_id=$1 ORDER BY index',
+							    array($group_id));
+				while ($row_tab = db_fetch_array($res_tabs)) {
+					$params['DIRS'][] = $row_tab['tab_url'];
+					$params['TITLES'][] = $row_tab['tab_name'];
+				}
+				break;
+			}
 		}
 	}
 }

Modified: trunk/src/plugins/extratabs/etc/extratabs.ini
===================================================================
--- trunk/src/plugins/extratabs/etc/extratabs.ini	2010-12-05 14:15:31 UTC (rev 11706)
+++ trunk/src/plugins/extratabs/etc/extratabs.ini	2010-12-05 16:55:29 UTC (rev 11707)
@@ -1,8 +1,8 @@
 [extratabs]
 
-; Current extratabs is to be validate by developers
+; Current extratabs is production ready
 ; plugin_status is a string.
 ; valid means : production ready.
 ; Any other strings means it's under work or broken and plugin 
 ; is available in installation_environment = development only.
-plugin_status = 'to be validate by developers'
\ No newline at end of file
+plugin_status = valid
\ No newline at end of file

Modified: trunk/src/plugins/extratabs/www/index.php
===================================================================
--- trunk/src/plugins/extratabs/www/index.php	2010-12-05 14:15:31 UTC (rev 11706)
+++ trunk/src/plugins/extratabs/www/index.php	2010-12-05 16:55:29 UTC (rev 11707)
@@ -5,7 +5,7 @@
  * Copyright 2005, Raphaël Hertzog
  * Copyright 2006-2009, Roland Mas
  * Copyright 2009-2010, Alain Peyrat
- * Copyright 2010, Franck Villaume
+ * Copyright 2010, Franck Villaume - Capgemini
  * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
  * http://fusionforge.org/
  *
@@ -30,52 +30,52 @@
 require_once $gfcommon.'include/pre.php';
 require_once $gfwww.'project/admin/project_admin_utils.php';
 
-$group_id = getIntFromRequest ('group_id') ;
-$index = getIntFromRequest ('index') ;
+$group_id = getIntFromRequest('group_id');
+$index = getIntFromRequest('index');
 
-$tab_name = htmlspecialchars(trim(getStringFromRequest ('tab_name')));
-$tab_url = htmlspecialchars(trim(getStringFromRequest ('tab_url', 'http://')));
+$tab_name = htmlspecialchars(trim(getStringFromRequest('tab_name')));
+$tab_url = htmlspecialchars(trim(getStringFromRequest('tab_url', 'http://')));
 
-session_require_perm ('project_admin', $group_id) ;
+session_require_perm('project_admin', $group_id);
 
 // get current information
 $group = group_get_object($group_id);
 if (!$group || !is_object($group)) {
 	exit_no_group();
 } elseif ($group->isError()) {
-	exit_error($group->getErrorMessage(),'home');
+	exit_error($group->getErrorMessage(), 'home');
 }
 
 db_begin();
 
 // Calculate new index field
-$res = db_query_params ('SELECT COUNT(*) as c FROM plugin_extratabs_main WHERE group_id = $1',
-			array ($group_id)) ;
+$res = db_query_params('SELECT COUNT(*) as c FROM plugin_extratabs_main WHERE group_id = $1',
+			array ($group_id));
 $row = db_fetch_array($res);
 $newid = $row['c'] + 1;
 
 $selected = 0; // No item selected by default
 
 // Do work before displaying so that the result is immediately visible
-if (getStringFromRequest ('addtab') != '') {
+if (getStringFromRequest('addtab') != '') {
 	if ($tab_name == '' || $tab_url == '' || $tab_url == 'http://') {
 		$error_msg = _('ERROR: Missing Name or URL for the new tab');
 	} else if (!util_check_url($tab_url)) {
 		$error_msg = _('ERROR: Malformed URL (only http, https and ftp allowed)');
 	} else {
 		$res = db_query_params('SELECT * FROM plugin_extratabs_main WHERE group_id=$1 AND tab_name=$2',
-			array($group_id, $tab_name));
+					array($group_id, $tab_name));
 		if ($res && db_numrows($res) > 0) {
 			$error_msg = _('ERROR: Name for tab is already used.');
 		} else {
-			$res = db_query_params ('INSERT INTO plugin_extratabs_main (group_id, index, tab_name, tab_url) VALUES ($1,$2,$3,$4)',
-						array ($group_id,
-						       $newid,
-						       $tab_name,
-						       $tab_url)) ;
+			$res = db_query_params('INSERT INTO plugin_extratabs_main (group_id, index, tab_name, tab_url) VALUES ($1,$2,$3,$4)',
+						array($group_id,
+						      $newid,
+						      $tab_name,
+						      $tab_url));
 			if (!$res || db_affected_rows($res) < 1) {
-				$error_msg = sprintf (_('Cannot insert new tab entry: %s'),
-						      db_error());
+				$error_msg = sprintf(_('Cannot insert new tab entry: %s'),
+						     db_error());
 			} else {
 				$tab_name = '';
 				$tab_url = 'http://';
@@ -83,46 +83,42 @@
 			}
 		}
 	}
-} elseif (getStringFromRequest ('delete') != '') {
-	$res = db_query_params ('DELETE FROM plugin_extratabs_main WHERE group_id=$1 AND index=$2',
-				array ($group_id,
-				       $index)) ;
+} elseif (getStringFromRequest('delete') != '') {
+	$res = db_query_params('DELETE FROM plugin_extratabs_main WHERE group_id=$1 AND index=$2',
+				array($group_id, $index));
 	if (!$res || db_affected_rows($res) < 1) {
-		$error_msg = sprintf (_('Cannot delete tab entry: %s'), db_error());
+		$error_msg = sprintf(_('Cannot delete tab entry: %s'), db_error());
 	} else {
-		$res = db_query_params ('SELECT index FROM plugin_extratabs_main WHERE group_id=$1 AND index > $2 ORDER BY index ASC',
-					array ($group_id,
-					       $index)) ;
+		$res = db_query_params('SELECT index FROM plugin_extratabs_main WHERE group_id=$1 AND index > $2 ORDER BY index ASC',
+					array($group_id, $index));
 		if (db_numrows($res) > 0) {
-			$todo = array () ;
+			$todo = array();
 			while ($row = db_fetch_array($res)) {
-				$todo[] = $row['index'] ;
+				$todo[] = $row['index'];
 			}
 			foreach ($todo as $i) {
-				$res = db_query_params ('UPDATE plugin_extratabs_main SET index = index - 1 WHERE group_id = $1 AND index = $2',
-							array ($group_id,
-							       $i)) ;
+				$res = db_query_params('UPDATE plugin_extratabs_main SET index = index - 1 WHERE group_id = $1 AND index = $2',
+							array($group_id, $i));
 			}
 		}
 		if ($res) {
 			$feedback = _('Tab successfully deleted');
 		} else {
-			$error_msg = sprintf (_('Cannot delete tab entry: %s'), db_error());
+			$error_msg = sprintf(_('Cannot delete tab entry: %s'), db_error());
 		}
 	}
 } elseif (getStringFromRequest ('up') != '') {
 	if ($index > 1) {
 		$previous = $index - 1;
 		$res = db_query_params('UPDATE plugin_extratabs_main SET index=0 WHERE group_id=$1 AND index=$2',
-				       array ($group_id,
-					      $index)) ;
+					array ($group_id, $index));
 		$res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=$3',
-				       array ($index,
+					array($index,
 					      $group_id,
-					      $previous)) ;
+					      $previous));
 		$res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=0',
-				       array ($previous,
-					      $group_id)) ;
+					array($previous,
+					      $group_id));
 		$selected = $previous;
 		$feedback = _('Tab successfully moved');
 	} else {
@@ -133,15 +129,15 @@
 	if ($index < $newid - 1) {
 		$next = $index + 1;
 		$res = db_query_params('UPDATE plugin_extratabs_main SET index=0 WHERE group_id=$1 AND index=$2',
-				       array ($group_id,
-					      $index)) ;
+					array($group_id,
+					      $index));
 		$res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=$3',
-				       array ($index,
+					array($index,
 					      $group_id,
-					      $next)) ;
+					      $next));
 		$res = db_query_params('UPDATE plugin_extratabs_main SET index=$1 WHERE group_id=$2 AND index=0',
-				       array ($next,
-					      $group_id)) ;
+					array($next,
+					      $group_id));
 		$feedback = _('Tab successfully moved');
 		$selected = $next;
 	} else {
@@ -151,13 +147,12 @@
 }
 if (!$res) {
 	db_rollback();
-} else  {
+} else {
 	db_commit();
 }
 
-$adminheadertitle=sprintf(_('Manage extra tabs for project %1$s'), $group->getPublicName() );
+$adminheadertitle = sprintf(_('Manage extra tabs for project %1$s'), $group->getPublicName());
 project_admin_header(array('title'=>$adminheadertitle, 'group'=>$group->getID()));
-
 ?>
 
 <h1><?php echo _('Manage extra tabs') ;?></h1>
@@ -186,10 +181,10 @@
 </form>
 
 <?php
-	$res = db_query_params ('SELECT * FROM plugin_extratabs_main WHERE group_id=$1 ORDER BY index ASC', array ($group_id)) ;
-$nbtabs = db_numrows($res) ;
+	$res = db_query_params('SELECT * FROM plugin_extratabs_main WHERE group_id=$1 ORDER BY index ASC', array($group_id));
+$nbtabs = db_numrows($res);
 if ($nbtabs > 0) {
-	
+
 ?>
 
 <h2><?php echo _('Move or delete extra tabs') ;?></h2>
@@ -210,26 +205,26 @@
 <select name="index">
 <?php
 while ($row = db_fetch_array($res)) {
-    if ($row['index'] == $selected) {
-	echo "<option selected=\"selected\" value='" . $row['index'] . "'>" . $row['tab_name'] .  "</option>";
-    } else {
-	echo "<option value='" . $row['index'] . "'>" . $row['tab_name'] .  "</option>";
-    }
+	if ($row['index'] == $selected) {
+		echo "<option selected=\"selected\" value='" . $row['index'] . "'>" . $row['tab_name'] .  "</option>";
+	} else {
+		echo "<option value='" . $row['index'] . "'>" . $row['tab_name'] .  "</option>";
+	}
 } ?>
 </select>
 </p>
 <p>
-	  <?php if ($nbtabs > 1) { ?>
+<?php if ($nbtabs > 1) { ?>
 <input type="submit" name="up" value="<?php echo _('Move tab before') ?>" />
 <input type="submit" name="down" value="<?php echo _('Move tab after') ?>" />
-		  <?php } ?>
+	<?php } ?>
 <input type="submit" name="delete" value="<?php echo _('Delete tab') ?>" />
 </p>
 </fieldset>
 </form>
 
 <?php
-	  }
+}
 project_admin_footer(array());
 
 // Local Variables:




More information about the Fusionforge-commits mailing list