}
}
+/**
+ * getFilteredIntFromRequest - get an int from REQUEST
+ *
+ * @param string $key of the wanted value
+ * @param string $pattern Regular expression of allowed values.
+ * @param integer $defaultValue if we can't find the wanted value, it returns the default value
+ * @return integer the value or false if not valid.
+ */
+function getFilteredIntFromRequest($key, $pattern, $defaultValue = 0) {
+ $value = getIntFromRequest($key, $defaultValue);
+ if (preg_match($pattern, $value)) {
+ return $value;
+ } else {
+ return $defaultValue;
+ }
+}
+
/**
* existInRequest - check if a var exists in REQUEST
*
<?php
/**
* Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
- * Copyright 2016, Franck Villaume - TrivialDev
+ * Copyright 2016,2021, Franck Villaume - TrivialDev
*
* This file is a part of Codendi.
*
var $content = '';
function __construct($owner_type, $owner_id) {
- $request =& HTTPRequest::instance();
if ($owner_type == WidgetLayoutManager::OWNER_TYPE_HOME) {
$this->widget_id = 'plugin_blocks_home_summary';
$this->group_id = $owner_id;
function getInstallPreferences() {
return $this->getPartialPreferencesForm(_('Enter title of block'), '');
}
- function updatePreferences(&$request) {
+ function updatePreferences() {
$done = false;
- $vContentId = new Valid_UInt('content_id');
- $vContentId->required();
- if ($request->valid($vContentId)) {
- $vTitle = new Valid_String('title');
- if($request->valid($vTitle)) {
- $title = htmlspecialchars($request->get('title'));
- } else {
- $title = '';
- }
+ if (existInRequest('content_id')) {
+ $title = htmlspecialchars(getStringFromRequest('title', ''));
- $vContent = new Valid_Text('body');
- $vContent->required();
- if($request->valid($vContent)) {
- $content = $request->get('body');
+ if(existInRequest('body')) {
+ $content = getStringFromRequest('body');
if (getStringFromRequest('_body_content_type') == 'html') {
$content = TextSanitizer::purify($content);
} else {
if ($content) {
$sql = "UPDATE plugin_blocks SET title=$1, content=$2 WHERE group_id =$3 AND id = $4";
- $res = db_query_params($sql,array($title,$content,$this->group_id,(int)$request->get('content_id')));
+ $res = db_query_params($sql, array($title, $content, $this->group_id, getIntFromRequest('content_id')));
$done = true;
}
}
$this->content_id = $id;
}
- function create(&$request) {
+ function create() {
$title = getStringFromRequest('title');
$content = getStringFromRequest('body');
$res = db_query_params('INSERT INTO plugin_blocks (group_id, name, status, title, content)
function __construct($owner_type, $owner_id) {
$request =& HTTPRequest::instance();
if ($owner_type == WidgetLayoutManager::OWNER_TYPE_USER) {
- $this->widget_id = 'plugin_hudson_my_jobbuildhistory';
+ $this->widget_id = 'plugin_blocks_user_summary';
$this->group_id = $owner_id;
} else {
$this->widget_id = 'plugin_blocks_project_summary';
return $this->getPartialPreferencesForm(_("Enter title of block"), '');
}
- function updatePreferences(&$request) {
+ function updatePreferences() {
$done = false;
- $vContentId = new Valid_UInt('content_id');
- $vContentId->required();
- if ($request->valid($vContentId)) {
- $vTitle = new Valid_String('title');
- if($request->valid($vTitle)) {
- $title = htmlspecialchars($request->get('title'));
- } else {
- $title = '';
- }
+ if (existInRequest('content_id')) {
+ $title = htmlspecialchars(getStringFromRequest('title', ''));
- $vContent = new Valid_Text('body');
- $vContent->required();
- if($request->valid($vContent)) {
- $content = $request->get('body');
+ if(existInRequest('body')) {
+ $content = getStringFromRequest('body');
if (getStringFromRequest('_body_content_type') == 'html') {
$content = TextSanitizer::purify($content);
} else {
if ($content) {
$sql = "UPDATE plugin_blocks SET title=$1, content=$2 WHERE group_id =$3 AND id = $4";
- $res = db_query_params($sql,array($title,$content,$this->group_id,(int)$request->get('content_id')));
+ $res = db_query_params($sql,array($title,$content,$this->group_id, getIntFromRequest('content_id')));
$done = true;
}
}
}
}
- function create(&$request) {
+ function create() {
$title = getStringFromRequest('title');
$content = getStringFromRequest('body');
$res = db_query_params('INSERT INTO plugin_blocks (group_id, name, status, title, content)
return false;
}
- function create(&$request) {
+ function create() {
$content_id = false;
- $vId = new Valid_Uint('job_id');
- $vId->setErrorMessage(_("Cannot add empty job id"));
- $vId->required();
- if ($request->valid($vId)) {
- $job_id = $request->get('job_id');
+ $job_id = getIntFromRequest('job_id');
+ if ($job_id) {
$sql = 'INSERT INTO plugin_hudson_widget (widget_name, owner_id, owner_type, job_id) VALUES ($1,$2,$3,$4)';
$res = db_query_params($sql,array($this->id,$this->owner_id,$this->owner_type,$job_id));
$content_id = db_insertid($res,'plugin_hudson_widget','id');
return $prefs;
}
- function updatePreferences(&$request) {
- $request->valid(new Valid_String('cancel'));
- if (!$request->exist('cancel')) {
- $job_id = $request->get($this->id);
+ function updatePreferences() {
+ if (!existInRequest('cancel')) {
+ $job_id = getIntFromRequest($this->id);
$sql = "UPDATE plugin_hudson_widget SET job_id=$1 WHERE owner_id = $2 AND owner_type = $3 AND id = $4";
- $res = db_query_params($sql,array($job_id,$this->owner_id,$this->owner_type,(int)$request->get('content_id')));
+ $res = db_query_params($sql, array($job_id, $this->owner_id, $this->owner_type, getIntFromRequest('content_id')));
}
return true;
}
<?php
/**
* Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
- * Copyright 2013-2014, Franck Villaume - TrivialDev
+ * Copyright 2013-2014,2021, Franck Villaume - TrivialDev
*
* This file is a part of Fusionforge.
*
function request() {
global $feedback, $error_msg;
- $request =& HTTPRequest::instance();
- $vgi = new Valid_GroupId();
- $vgi->required();
- if ($request->valid($vgi)) {
- $group_id = $request->get('group_id');
- $project = group_get_object($group_id);
- if ($project->usesService('hudson')) {
- $user = UserManager::instance()->getCurrentUser();
- if (forge_check_perm('plugin_hudson_read', $group_id, 'read')) {
- switch($request->get('action')) {
+ $group_id = getFilteredIntFromRequest('group_id', '\d');
+ $project = group_get_object($group_id);
+ if ($project->usesService('hudson')) {
+ $user = session_get_user();
+ if (forge_check_perm('plugin_hudson_read', $group_id, 'read')) {
+ $action = getStringFromRequest('action');
+ switch($action) {
case 'add_job':
if ($user->isMember($group_id, 'A')) {
- if ( $request->exist('hudson_job_url') && trim($request->get('hudson_job_url') != '') ) {
+ if (existInRequest('hudson_job_url') && (getStringFromRequest('hudson_job_url') != '')) {
$this->action = 'addJob';
} else {
$error_msg .= _('Missing Hudson job url (eg: http://myCIserver:8080/hudson/job/MyJob)');
break;
case 'edit_job':
if ($user->isMember($group_id,'A')) {
- if ($request->exist('job_id')) {
+ if (existInRequest('job_id')) {
$this->view = 'editJob';
} else {
$error_msg .= _('Missing Hudson job ID');
break;
case 'update_job':
if ($user->isMember($group_id, 'A')) {
- if ($request->exist('job_id')) {
- if ($request->exist('new_hudson_job_url') && $request->get('new_hudson_job_url') != '') {
+ if (existInRequest('job_id')) {
+ if (existInRequest('new_hudson_job_url') && (getStringFromRequest('new_hudson_job_url') != '')) {
$this->action = 'updateJob';
} else {
$error_msg .= _('Missing Hudson job url (eg: http://myCIserver:8080/hudson/job/MyJob)');
break;
case 'delete_job':
if ($user->isMember($group_id, 'A')) {
- if ($request->exist('job_id')) {
+ if (existInRequest('job_id')) {
$this->action = 'deleteJob';
} else {
$error_msg .= _('Missing Hudson job ID');
function __construct($plugin) {
parent::__construct('plugin_hudson_my_jobs');
$this->plugin = $plugin;
- $user=UserManager::instance()->getCurrentUser();
+ $user = session_get_user();
$this->_not_monitored_jobs = $user->getPreference('plugin_hudson_my_not_monitored_jobs');
if ($this->_not_monitored_jobs === false) {
$this->_not_monitored_jobs = array();
}
function updatePreferences(&$request) {
- $request->valid(new Valid_String('cancel'));
- if (!$request->exist('cancel')) {
+ if (existInRequest('cancel')) {
$monitored_jobs = $request->get('myhudsonjobs');
- $user = UserManager::instance()->getCurrentUser();
+ $user = session_get_user();
$job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance());
$dar = $job_dao->searchByUserID($user->getId());
$not_monitored_jobs = array();
$prefs = '';
// Monitored jobs
$prefs .= '<strong>'._("Monitored jobs:").'</strong><br />';
- $user = UserManager::instance()->getCurrentUser();
+ $user = session_get_user();
$job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance());
$dar = $job_dao->searchByUserID($user->getId());
while ($dar->valid()) {
}
function _getMonitoredJobsByUser() {
- $user = UserManager::instance()->getCurrentUser();
+ $user = session_get_user();
$job_dao = new PluginHudsonJobDao(CodendiDataAccess::instance());
$dar = $job_dao->searchByUserID($user->getId());
$monitored_jobs = array();
<?php
/**
* Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
- * Copyright 2014,2016,2019, Franck Villaume - TrivialDev
+ * Copyright 2014,2016,2019,2021, Franck Villaume - TrivialDev
*
* This file is a part of Fusionforge.
*
parent::__construct('plugin_hudson_project_jobsoverview');
$this->plugin = $plugin;
- $request =& HTTPRequest::instance();
- $this->group_id = $request->get('group_id');
+ $this->group_id = getIntFromRequest('group_id');
if ($this->_use_global_status === true) {
$this->_all_status = array(