[Fusionforge-commits] r9264 - trunk/gforge/common/include

Christian Bayle cbayle at libremir.placard.fr.eu.org
Mon Mar 29 10:00:45 CEST 2010


Author: cbayle
Date: 2010-03-29 10:00:44 +0200 (Mon, 29 Mar 2010)
New Revision: 9264

Added:
   trunk/gforge/common/include/Codendi_Request.class.php
   trunk/gforge/common/include/HTTPRequest.class.php
   trunk/gforge/common/include/ProjectManager.class.php
   trunk/gforge/common/include/UserManager.class.php
   trunk/gforge/common/include/plugins_utils.php
Log:
Add codendi glue


Added: trunk/gforge/common/include/Codendi_Request.class.php
===================================================================
--- trunk/gforge/common/include/Codendi_Request.class.php	                        (rev 0)
+++ trunk/gforge/common/include/Codendi_Request.class.php	2010-03-29 08:00:44 UTC (rev 9264)
@@ -0,0 +1,108 @@
+<?php
+/**
+ * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
+ *
+ * This file is a part of Codendi.
+ *
+ * Codendi 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 License, or
+ * (at your option) any later version.
+ *
+ * Codendi 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 Codendi. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* abstract */ class Codendi_Request {
+    /**
+     * @var array
+     * @access private
+     */
+    var $_validated_input;
+    
+    /**
+     * @var array
+     * @access private
+     */
+    var $_last_access_to_input;
+    
+    /**
+     * @var array
+     */
+    var $params;
+    
+    /**
+     * Constructor
+     */
+    function Codendi_Request($params) {
+        $this->params                = $params;
+        $this->_validated_input      = array();
+        $this->_last_access_to_input = array();
+    }
+    
+   
+    /**
+     * Get the value of $variable in $this->params (user submitted values).
+     *
+     * @param string $variable Name of the parameter to get.
+     * @return mixed If the variable exist, the value is returned (string)
+     * otherwise return false;
+     */
+    function get($variable) {
+      
+        return $this->_get($variable, $this->params);
+    }
+
+    /**
+     * Add a param and/or set its value
+     *
+     */
+    function set($name, $value) {
+        $this->params[$name] = $value;
+    }
+
+    
+    /**
+     * Get the value of $variable in $array. 
+     *
+     * @access private
+     * @param string $variable Name of the parameter to get.
+     * @param array $array Name of the parameter to get.
+     */
+    function _get($variable, $array) {
+        if ($this->_exist($variable, $array)) {
+            return $array[$variable];
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Check if $variable exists in user submitted parameters.
+     *
+     * @param string $variable Name of the parameter.
+     * @return boolean
+     */
+    function exist($variable) {
+        return $this->_exist($variable, $this->params);
+    }
+    
+    /**
+     * Check if $variable exists in $array.
+     *
+     * @access private
+     * @param string $variable Name of the parameter.
+     * @return boolean
+     */
+    function _exist($variable, $array) {
+        return isset($array[$variable]);
+    }
+    
+
+}
+?>

Added: trunk/gforge/common/include/HTTPRequest.class.php
===================================================================
--- trunk/gforge/common/include/HTTPRequest.class.php	                        (rev 0)
+++ trunk/gforge/common/include/HTTPRequest.class.php	2010-03-29 08:00:44 UTC (rev 9264)
@@ -0,0 +1,138 @@
+<?php
+/**
+ * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
+ *
+ * This file is a part of Codendi.
+ *
+ * Codendi 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 License, or
+ * (at your option) any later version.
+ *
+ * Codendi 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 Codendi. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+require_once('common/include/Codendi_Request.class.php');
+
+
+/**
+ * @package Codendi
+ */
+class HTTPRequest extends Codendi_Request {
+
+    /**
+     * Constructor
+     */
+    function HTTPRequest() {
+        parent::Codendi_Request($_REQUEST);
+    }
+    
+
+    /**
+     * Get the value of $variable in $this->params (server side values).
+     *
+     * @param string $variable Name of the parameter to get.
+     * @return mixed If the variable exist, the value is returned (string)
+     * otherwise return false;
+     */
+    function getFromServer($variable) {
+        return $this->_get($variable, $_SERVER);
+    }
+
+    /**
+     * Check if current request is send via 'post' method.
+     *
+     * This method is useful to test if the current request comes from a form.
+     *
+     * @return boolean
+     */
+    function isPost() {
+        if($_SERVER['REQUEST_METHOD'] == 'POST') {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Return true if browser used to submit the request is netscape 4.
+     *
+     * @return boolean
+     */
+    function browserIsNetscape4() {
+        return browser_is_netscape4();
+    }
+
+    /**
+     * Singleton method for the class.
+     *
+     * @return mixed HTTPRequest Object.
+     */
+    function &instance() {
+        static $_httprequest_instance;
+        if (!$_httprequest_instance) {
+            $_httprequest_instance = new HTTPRequest();
+        }
+        return $_httprequest_instance;
+    }
+
+    /**
+     * Validate file upload.
+     *
+     * @param  Valid_File Validator for files.
+     * @return Boolean
+     */
+    function validFile(&$validator) {
+        if(is_a($validator, 'Valid_File')) {
+            $this->_validated_input[$validator->getKey()] = true;
+            return $validator->validate($_FILES, $validator->getKey());
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Remove slashes in $value. If $value is an array, remove slashes for each
+     * element.
+     *
+     * @access private
+     * @param mixed $value
+     * @return mixed
+     */
+    function _stripslashes($value) {
+        if (is_string($value)) {
+            $value = stripslashes($value);
+        } else if (is_array($value)) {
+            foreach($value as $key => $val) {
+                $value[$key] = $this->_stripslashes($val);
+            }
+        }
+        return $value;
+    }
+
+    /**
+     * Get the value of $variable in $array. If magic_quotes are enabled, the
+     * value is escaped.
+     *
+     * @access private
+     * @param string $variable Name of the parameter to get.
+     * @param array $array Name of the parameter to get.
+     */
+    function _get($variable, $array) {
+        if ($this->_exist($variable, $array)) {
+            return (get_magic_quotes_gpc()?$this->_stripslashes($array[$variable]):$array[$variable]);
+        } else {
+            return false;
+        }
+    }
+
+}
+
+?>

Added: trunk/gforge/common/include/ProjectManager.class.php
===================================================================
--- trunk/gforge/common/include/ProjectManager.class.php	                        (rev 0)
+++ trunk/gforge/common/include/ProjectManager.class.php	2010-03-29 08:00:44 UTC (rev 9264)
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
+ *
+ * This file is a part of Codendi.
+ *
+ * Codendi 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 License, or
+ * (at your option) any later version.
+ *
+ * Codendi 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 Codendi. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+/**
+ * Provide access to projects
+ */
+class ProjectManager {
+    
+    /**
+   
+    
+    /**
+     * Hold an instance of the class
+     */
+    private static $_instance;
+    
+    /**
+     * A private constructor; prevents direct creation of object
+     */
+    private function __construct() {
+    
+    }
+    
+    /**
+     * ProjectManager is a singleton
+     * @return ProjectManager
+     */
+    public static function instance() {
+        if (!isset(self::$_instance)) {
+            $c = __CLASS__;
+            self::$_instance = new $c;
+        }
+        return self::$_instance;
+    }
+    
+  
+    
+    /**
+     * @param $group_id int The id of the project to look for
+     * @return Project
+     */
+    public function & getProject($group_id) {
+      
+        return  group_get_object($group_id);
+    }
+    
+ 
+}
+?>

Added: trunk/gforge/common/include/UserManager.class.php
===================================================================
--- trunk/gforge/common/include/UserManager.class.php	                        (rev 0)
+++ trunk/gforge/common/include/UserManager.class.php	2010-03-29 08:00:44 UTC (rev 9264)
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
+ *
+ * This file is a part of Codendi.
+ *
+ * Codendi 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 License, or
+ * (at your option) any later version.
+ *
+ * Codendi 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 Codendi. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+require_once('User.class.php');
+
+
+class UserManager {
+   
+    
+    protected function __construct() {
+    }
+    
+    protected static $_instance;
+    public static function instance() {
+        if (!isset(self::$_instance)) {
+            $c = __CLASS__;
+            self::$_instance = new $c();
+        }
+        return self::$_instance;
+    }
+    
+    
+    /**
+     * @param $session_hash string Optional parameter. If given, this will force 
+     *                             the load of the user with the given session_hash. 
+     *                             else it will check from the user cookies & ip
+     * @return User the user currently logged in (who made the request)
+     */
+    function getCurrentUser($session_hash = false) {
+    	if (!session_get_user()) {
+    		return new GFUser();
+    	}
+    	return session_get_user();
+    }
+    
+    function getUserById($user_id) {
+    	return user_get_object($user_id);
+    }
+   
+}
+
+?>

Added: trunk/gforge/common/include/plugins_utils.php
===================================================================
--- trunk/gforge/common/include/plugins_utils.php	                        (rev 0)
+++ trunk/gforge/common/include/plugins_utils.php	2010-03-29 08:00:44 UTC (rev 9264)
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Portions Copyright 2010 (c) Mélanie Le Bail
+ */
+
+
+
+ 
+$GLOBALS['mailman_bin_dir'] =  $GLOBALS['sys_path_to_mailman'].'/bin';
+$GLOBALS['mailman_list_dir'] = '/var/lib/mailman/lists';
+global $html;
+require_once 'common/include/Plugin.class.php';
+
+function isLogged(){
+	
+	return session_loggedin();
+}
+
+function htmlRedirect($url) {
+	session_redirect('plugins/mailman/'.$url);
+}
+function htmlIframe($url,$poub) {
+	echo ('<iframe src= "'.$url.'" width=100% height=500px></iframe>');
+}
+
+
+function helpButton($help) {
+	
+}
+function getIcon() {
+	echo html_image("ic/mail16b.png","20","20",array("border"=>"0"));
+}
+?>




More information about the Fusionforge-commits mailing list