From 96e46b4b94998bc0f98192a9fd6d1ac352749ebc Mon Sep 17 00:00:00 2001 From: Christian Bayle Date: Mon, 29 Mar 2010 08:00:44 +0000 Subject: [PATCH] Add codendi glue --- .gitattributes | 5 + .../common/include/Codendi_Request.class.php | 108 ++++++++++++++ gforge/common/include/HTTPRequest.class.php | 138 ++++++++++++++++++ .../common/include/ProjectManager.class.php | 67 +++++++++ gforge/common/include/UserManager.class.php | 59 ++++++++ gforge/common/include/plugins_utils.php | 33 +++++ 6 files changed, 410 insertions(+) create mode 100644 gforge/common/include/Codendi_Request.class.php create mode 100644 gforge/common/include/HTTPRequest.class.php create mode 100644 gforge/common/include/ProjectManager.class.php create mode 100644 gforge/common/include/UserManager.class.php create mode 100644 gforge/common/include/plugins_utils.php diff --git a/.gitattributes b/.gitattributes index ff4a852d68..24c62dedf1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -28,11 +28,16 @@ gforge/common/docman/engine/parser_oo.php -text gforge/common/docman/engine/parser_pdf.php -text gforge/common/docman/engine/parser_text.inc.php -text gforge/common/docman/engine/parser_text.php -text +gforge/common/include/Codendi_Request.class.php -text +gforge/common/include/HTTPRequest.class.php -text gforge/common/include/Navigation.class.php -text +gforge/common/include/ProjectManager.class.php -text gforge/common/include/TextSanitizer.class.php -text +gforge/common/include/UserManager.class.php -text gforge/common/include/config.php -text gforge/common/include/database-mysql.php -text gforge/common/include/group_section_texts.php -text +gforge/common/include/plugins_utils.php -text gforge/common/include/rbac_texts.php -text gforge/common/include/tag_cloud.php -text gforge/common/include/utils_crossref.php -text diff --git a/gforge/common/include/Codendi_Request.class.php b/gforge/common/include/Codendi_Request.class.php new file mode 100644 index 0000000000..3a80251b98 --- /dev/null +++ b/gforge/common/include/Codendi_Request.class.php @@ -0,0 +1,108 @@ +. + */ + +/* 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]); + } + + +} +?> diff --git a/gforge/common/include/HTTPRequest.class.php b/gforge/common/include/HTTPRequest.class.php new file mode 100644 index 0000000000..84fc0f3d7f --- /dev/null +++ b/gforge/common/include/HTTPRequest.class.php @@ -0,0 +1,138 @@ +. + */ + + +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; + } + } + +} + +?> diff --git a/gforge/common/include/ProjectManager.class.php b/gforge/common/include/ProjectManager.class.php new file mode 100644 index 0000000000..44e0d0a926 --- /dev/null +++ b/gforge/common/include/ProjectManager.class.php @@ -0,0 +1,67 @@ +. + */ + + +/** + * 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); + } + + +} +?> diff --git a/gforge/common/include/UserManager.class.php b/gforge/common/include/UserManager.class.php new file mode 100644 index 0000000000..cdd27c7998 --- /dev/null +++ b/gforge/common/include/UserManager.class.php @@ -0,0 +1,59 @@ +. + */ + +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); + } + +} + +?> diff --git a/gforge/common/include/plugins_utils.php b/gforge/common/include/plugins_utils.php new file mode 100644 index 0000000000..32a24337f2 --- /dev/null +++ b/gforge/common/include/plugins_utils.php @@ -0,0 +1,33 @@ +'); +} + + +function helpButton($help) { + +} +function getIcon() { + echo html_image("ic/mail16b.png","20","20",array("border"=>"0")); +} +?> -- 2.30.2