[Fusionforge-commits] r15479 - in trunk/src: . plugins plugins/headermenu plugins/headermenu/action plugins/headermenu/common plugins/headermenu/db plugins/headermenu/etc plugins/headermenu/view plugins/headermenu/view/admin plugins/headermenu/www

Franck VILLAUME nerville at fusionforge.org
Mon May 7 11:04:11 CEST 2012


Author: nerville
Date: 2012-05-07 11:04:10 +0200 (Mon, 07 May 2012)
New Revision: 15479

Added:
   trunk/src/plugins/headermenu/
   trunk/src/plugins/headermenu/action/
   trunk/src/plugins/headermenu/action/addLink.php
   trunk/src/plugins/headermenu/common/
   trunk/src/plugins/headermenu/common/headermenu-init.php
   trunk/src/plugins/headermenu/common/headermenuPlugin.class.php
   trunk/src/plugins/headermenu/db/
   trunk/src/plugins/headermenu/db/headermenu-init.sql
   trunk/src/plugins/headermenu/etc/
   trunk/src/plugins/headermenu/etc/headermenu.ini
   trunk/src/plugins/headermenu/view/
   trunk/src/plugins/headermenu/view/admin/
   trunk/src/plugins/headermenu/view/admin/viewGlobalConfiguration.php
   trunk/src/plugins/headermenu/www/
   trunk/src/plugins/headermenu/www/index.php
Modified:
   trunk/src/CHANGES
Log:
new plugin offering capability to add links right to login/logout menu

Modified: trunk/src/CHANGES
===================================================================
--- trunk/src/CHANGES	2012-05-07 09:02:50 UTC (rev 15478)
+++ trunk/src/CHANGES	2012-05-07 09:04:10 UTC (rev 15479)
@@ -3,6 +3,7 @@
 * Trackers: Attachements moved to filesystem to allow larger attachments & reduce DB size (Alcatel-Lucent)
 * Users: notify admins when user has validated his account (TrivialDev)
 * scmgit: add browsing capability for user personal repository (TrivialDev)
+* headermenu: new plugin to add links in login/logout menu link (TrivialDev)
 
 FusionForge-5.2:
 * Docman: inject zip as a tree (Capgemini)

Added: trunk/src/plugins/headermenu/action/addLink.php
===================================================================
--- trunk/src/plugins/headermenu/action/addLink.php	                        (rev 0)
+++ trunk/src/plugins/headermenu/action/addLink.php	2012-05-07 09:04:10 UTC (rev 15479)
@@ -0,0 +1,47 @@
+<?php
+/**
+ * headermenu plugin
+ *
+ * Copyright 2012, Franck Villaume - TrivialDev
+ * http://fusionforge.org
+ *
+ * This file is part of FusionForge. FusionForge 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 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge 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 FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+global $headermenu;
+
+session_require_global_perm('forge_admin');
+$link = getStringFromRequest('link');
+$descripton = getStringFromRequest('description');
+$name = getStringFromRequest('name');
+
+if (!empty($link) && !empty($name)) {
+	if (util_check_url($link)) {
+		if ($headermenu->addLink($link, $name, $description)) {
+			$feedback = _('Task succeeded.');
+			session_redirect('plugins/'.$headermenu->name.'/?type=globaladmin&feedback='.urlencode($feedback));
+		}
+		$error_msg = _('Task failed');
+		session_redirect('plugins/'.$headermenu->name.'/?type=globaladmin&error_msg='.urlencode($error_msg));
+	} else {
+		$error_msg = _('Provided Link is not a valid URL.');
+		session_redirect('plugins/'.$headermenu->name.'/?type=globaladmin&error_msg='.urlencode($error_msg));
+	}
+}
+$warning_msg = _('Missing Link URL or name.');
+session_redirect('plugins/'.$headermenu->name.'/?type=globaladmin&warning_msg='.urlencode($warning_msg));
+
+?>
\ No newline at end of file

Added: trunk/src/plugins/headermenu/common/headermenu-init.php
===================================================================
--- trunk/src/plugins/headermenu/common/headermenu-init.php	                        (rev 0)
+++ trunk/src/plugins/headermenu/common/headermenu-init.php	2012-05-07 09:04:10 UTC (rev 15479)
@@ -0,0 +1,30 @@
+<?php
+/**
+ *
+ * Copyright 2012, Franck Villaume - TrivialDev
+ * http://fusionforge.org
+ *
+ * This file is part of FusionForge. FusionForge 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 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge 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 FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+global $gfplugins;
+require_once $gfplugins.'headermenu/common/headermenuPlugin.class.php';
+
+$headermenuPluginObject = new headermenuPlugin;
+
+register_plugin($headermenuPluginObject);
+
+?>

Added: trunk/src/plugins/headermenu/common/headermenuPlugin.class.php
===================================================================
--- trunk/src/plugins/headermenu/common/headermenuPlugin.class.php	                        (rev 0)
+++ trunk/src/plugins/headermenu/common/headermenuPlugin.class.php	2012-05-07 09:04:10 UTC (rev 15479)
@@ -0,0 +1,129 @@
+<?php
+
+/**
+ * headermenuPlugin Class
+ *
+ * Copyright 2012 Franck Villaume - TrivialDev
+ * http://fusionforge.org
+ *
+ * This file is part of FusionForge. FusionForge 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 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge 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 FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+class headermenuPlugin extends Plugin {
+
+	function __construct() {
+		$this->Plugin() ;
+		$this->name = "headermenu" ;
+		$this->text = "headermenu" ;
+		$this->_addHook('headermenu');
+		$this->_addHook('site_admin_option_hook');
+	}
+
+	function CallHook ($hookname, &$params) {
+		switch ($hookname) {
+			case "headermenu": {
+				$this->getHeaderLink();
+				break;
+			}
+			case "site_admin_option_hook": {
+				echo '<li>'.$this->getAdminOptionLink().'</li>';
+				$returned = true;
+				break;
+			}
+		}
+	}
+
+	function getAdminOptionLink() {
+		return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global HeaderMenu admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
+	}
+
+	function getHeaderLink() {
+		$availableLinks = $this->getAvailableLinks();
+		foreach ($availableLinks as $link) {
+			$ahref = '<a href="'.$link['url'].'">'.$link['name'].'</a>';
+
+			$template = isset($params['template']) ?  $params['template'] : ' | {menu}';
+			echo str_replace('{menu}', $ahref, $template);
+		}
+		return true;
+	}
+
+	function getAvailableLinks() {
+		$links = db_query_params('SELECT * FROM plugin_headermenu', array());
+		$availableLinks = array();
+		while ($arr = db_fetch_array($links)) {
+			$availableLinks[] = $arr;
+		}
+		return $availableLinks;
+	}
+
+	function addLink($url, $name, $description) {
+		if (!empty($url)) {
+			$res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable)
+					values ($1, $2, $3, $4)',
+					array(
+						$url,
+						$name,
+						$description,
+						1,
+					));
+			if (!$res)
+				return false;
+
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * getHeader - initialize header and js
+	 * @param	string	type : user, project (aka group)
+	 * @return	bool	success or not
+	 */
+	function getHeader($type) {
+		global $gfplugins;
+		$returned = false;
+		switch ($type) {
+			case 'globaladmin': {
+				session_require_global_perm('forge_admin');
+				global $gfwww;
+				require_once($gfwww.'admin/admin_utils.php');
+				use_javascript('/js/sortable.js');
+				site_admin_header(array('title'=>_('Site Global headerMenu Admin'), 'toptab' => ''));
+				$returned = true;
+				break;
+			}
+		}
+		return $returned;
+	}
+
+	/**
+	 * getGlobalAdminView - display the Global Admin View
+	 *
+	 * @return	bool	true
+	 */
+	function getGlobalAdminView() {
+		global $gfplugins;
+		$user = session_get_user();
+		include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
+		return true;
+	}
+
+	function getPluginDescription() {
+		return _('Get the ability to set new links next to the login menu.');
+	}
+}
+?>

Added: trunk/src/plugins/headermenu/db/headermenu-init.sql
===================================================================
--- trunk/src/plugins/headermenu/db/headermenu-init.sql	                        (rev 0)
+++ trunk/src/plugins/headermenu/db/headermenu-init.sql	2012-05-07 09:04:10 UTC (rev 15479)
@@ -0,0 +1,7 @@
+CREATE TABLE plugin_headermenu (
+	id_headermenu	serial PRIMARY KEY,
+	url		character varying(255),
+	name		character varying(255),
+	description	character varying(511),
+	is_enable	integer DEFAULT 0
+);

Added: trunk/src/plugins/headermenu/etc/headermenu.ini
===================================================================
--- trunk/src/plugins/headermenu/etc/headermenu.ini	                        (rev 0)
+++ trunk/src/plugins/headermenu/etc/headermenu.ini	2012-05-07 09:04:10 UTC (rev 15479)
@@ -0,0 +1,8 @@
+[headermenu]
+
+; current headermenu status is valid
+; 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 = valid

Added: trunk/src/plugins/headermenu/view/admin/viewGlobalConfiguration.php
===================================================================
--- trunk/src/plugins/headermenu/view/admin/viewGlobalConfiguration.php	                        (rev 0)
+++ trunk/src/plugins/headermenu/view/admin/viewGlobalConfiguration.php	2012-05-07 09:04:10 UTC (rev 15479)
@@ -0,0 +1,69 @@
+<?php
+/**
+ * headermenuPlugin Class
+ *
+ * Copyright 2012 Franck Villaume - TrivialDev
+ * http://fusionforge.org
+ *
+ * This file is part of FusionForge. FusionForge 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 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge 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 FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+global $HTML;
+global $headermenu;
+
+session_require_global_perm('forge_admin');
+
+$linksArray = $headermenu->getAvailableLinks();
+if (sizeof($linksArray)) {
+	echo $HTML->boxTop(_('Manage available links'));
+	$tabletop = array(_('URL'), _('Displayed Name'), _('Description'), _('Status'), _('Actions'));
+	$classth = array('','','','','');
+	echo $HTML->listTableTop($tabletop, false, 'sortable_headermenu_listlinks', 'sortable', $classth);
+	foreach ($linksArray as $link) {
+		echo '<tr>';
+		echo '<td>'.$link['url'].'</td>';
+		echo '<td>'.$link['name'].'</td>';
+		echo '<td>'.$link['description'].'</td>';
+		echo '<td>'.$link['is_enable'].'</td>';
+		if ($link['is_enable']) {
+			$actionsLink = 'disable';
+		} else {
+			$actionsLink = 'enable';
+		}
+		echo '<td>'._('to be implemented').'</td>';
+		echo '</tr>';
+	}
+	echo $HTML->listTableBottom();
+	echo $HTML->boxBottom();
+	echo '</br>';
+}
+
+echo '<form method="POST" name="addLink" action="index.php?type=globaladmin&action=addLink">';
+echo '<table><tr>';
+echo $HTML->boxTop(_('Add a new link'));
+echo '<td>'._('URL').'</td><td><input name="link" type="text" maxsize="255" /></td>';
+echo '</tr><tr>';
+echo '<td>'._('Displayed Name').'</td><td><input name="name" type="text" maxsize="255" /></td>';
+echo '</tr><tr>';
+echo '<td>'._('Description').'</td><td><input name="description" type="text" maxsize="255" /></td>';
+echo '</tr><tr>';
+echo '<td>';
+echo '<input type="submit" value="'. _('Add') .'" />';
+echo '</td>';
+echo $HTML->boxBottom();
+echo '</tr></table>';
+echo '</form>';
+?>

Added: trunk/src/plugins/headermenu/www/index.php
===================================================================
--- trunk/src/plugins/headermenu/www/index.php	                        (rev 0)
+++ trunk/src/plugins/headermenu/www/index.php	2012-05-07 09:04:10 UTC (rev 15479)
@@ -0,0 +1,59 @@
+<?php
+/**
+ * headermenu plugin
+ *
+ * Copyright 2012, Franck Villaume - TrivialDev
+ * http://fusionforge.org
+ *
+ * This file is part of FusionForge. FusionForge 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 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge 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 FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */ 
+
+require_once('../../env.inc.php');
+require_once $gfcommon.'include/pre.php';
+
+$type = getStringFromRequest('type');
+
+if (!$type) {
+	exit_missing_param($_SERVER['HTTP_REFERER'], array('No TYPE specified'), 'headermenu');
+}
+
+global $use_tooltips;
+$headermenu = plugin_get_object('headermenu');
+
+switch ($type) {
+	case 'globaladmin': {
+		if (!session_loggedin()) {
+			exit_not_logged_in();
+		}
+		session_require_global_perm('forge_admin');
+		$action = getStringFromRequest('action');
+		switch ($action) {
+			case 'addLink': {
+				global $gfplugins;
+				include($gfplugins.$headermenu->name.'/action/'.$action.'.php');
+				break;
+			}
+		}
+		$headermenu->getHeader('globaladmin');
+		$headermenu->getGlobalAdminView();
+		break;
+	}
+}
+
+site_project_footer(array());
+
+?>
+




More information about the Fusionforge-commits mailing list