diff --git a/public_html/deployment/classes/projectlist.class.php b/public_html/deployment/classes/projectlist.class.php index e2e1d0f44ec3c318e74d051c3a20c00bd889b8ff..577c98ffc9d6fd2d280887bc1c576f1483e9652a 100644 --- a/public_html/deployment/classes/projectlist.class.php +++ b/public_html/deployment/classes/projectlist.class.php @@ -9,7 +9,7 @@ --------------------------------------------------------------------- Axel <axel.hahn@unibe.ch> 2013-11-08 Axel - 2024-08-28 Axel php8 only; added variable types; short array syntax + 2024-08-29 Axel php8 only; added variable types; short array syntax ###################################################################### */ require_once 'base.class.php'; @@ -93,7 +93,7 @@ class projectlist extends base $oPrj = new projectgui(); $aProjectByLabel = $oPrj->getProjects("label"); foreach ($aProjectByLabel as $aProject) { - $sPrj=$aProject['id']; + $sPrj = $aProject['id']; $oPrj = new projectgui($sPrj); $sPrjFilter .= '<option value="' . $sPrj . '">' . $aProject['label'] . '</option>'; @@ -149,8 +149,8 @@ class projectlist extends base // render output $sOut .= ' <tr class="' . $sClasses . '" ' - . 'ondblclick="location.href=\'/deployment/' . $sPrj . '/\'" ' - . 'title="' . sprintf(t("overview-hint-dblclick"), $sPrj) + . 'ondblclick="location.href=\'/deployment/' . $sPrj . '/\'" ' + . 'title="' . sprintf(t("overview-hint-dblclick"), $sPrj) . '"> <td class="prj"> <span class="float-right"><i class="fa-solid fa-tag"></i> ' . $sPrjGroup . '</span> @@ -316,7 +316,7 @@ class projectlist extends base </thead> <tbody> ' . $sOut . '</tbody></table>' - ; + ; } else { $sOut = t("class-pl-error-no-project") . '<br><br>' . $oPrj1->renderLink("new"); diff --git a/public_html/deployment/classes/queryparam.class.php b/public_html/deployment/classes/queryparam.class.php index f4dd62ceabc92f29da08ebdb1a16759fc6d9bcbf..3379bc5b36e229d8c036bb3f09670e852044b80d 100644 --- a/public_html/deployment/classes/queryparam.class.php +++ b/public_html/deployment/classes/queryparam.class.php @@ -1,35 +1,49 @@ <?php +/** + * Wrapping class to access $_GET|$_POST|$_SESSION variables with validation + * of a value + * + * @example + * Ensure that https://example.com/?page=<VALUE> will be accepted only if + * <VALUE> matches /^[a-z]*$/ + * <code>queryparam::get('page', '/^[a-z]*$/');</code> + * + * Axel <axel.hahn@unibe.ch> + * 2024-08-29 Axel php8 only; added variable types; short array syntax + */ -class queryparam{ - +class queryparam +{ /** - * return value of a a given scope variable (e.g. $_GET|$_POST|$_SESSION) if it exists. + * Get value of a a given scope variable (e.g. $_GET|$_POST|$_SESSION) if it exists. * It will return NULLL if the value does not match an optional regex or type. * + * @param array $aScope array of scope variables * @param string $sVarname name of post or get variable (POST has priority) * @param string $sRegexMatch set a regex that must match * @param string $sType force type: false|int * @return mixed NULL|value */ - static public function getvar($aScope, $sVarname, $sRegexMatch=false, $sType=false){ + static public function getvar(array $aScope, string $sVarname, string $sRegexMatch = '', string $sType = ''): mixed + { // check if it exist - if(!isset($aScope[$sVarname])){ + if (!isset($aScope[$sVarname])) { return NULL; } - + $return = $aScope[$sVarname]; - + // verify regex - if ($sRegexMatch && !preg_match($sRegexMatch,$return)){ + if ($sRegexMatch && !preg_match($sRegexMatch, $return)) { return NULL; } - + // force given type - switch ($sType){ - case 'int': - $return=(int)$return; + switch ($sType) { + case 'int': + $return = (int) $return; break; } return $return; @@ -44,7 +58,8 @@ class queryparam{ * @param string $sType force type: false|int * @return mixed NULL|value */ - static function get($sVarname, $sRegexMatch=false, $sType=false) { + static function get(string $sVarname, string $sRegexMatch = '', string $sType = ''): mixed + { return self::getvar($_GET, $sVarname, $sRegexMatch, $sType); } @@ -56,23 +71,24 @@ class queryparam{ * @param string $sType force type: false|int * @return mixed NULL|value */ - static function getorpost($sVarname, $sRegexMatch=false, $sType=false) { + static function getorpost(string $sVarname, string $sRegexMatch = '', string $sType = ''): mixed + { // $this->logAdd(__METHOD__."($sVarname, $sRegexMatch, $sType) start"); - + // check if it exist - if(!isset($_POST[$sVarname]) && !isset($_GET[$sVarname])){ + if (!isset($_POST[$sVarname]) && !isset($_GET[$sVarname])) { // $this->logAdd(__METHOD__."($sVarname) $sVarname does not exist"); return false; } - + // set it to POST or GET variable $aScope = isset($_POST[$sVarname]) && $_POST[$sVarname] - ? $_POST[$sVarname] - : ((isset($_GET[$sVarname]) && $_GET[$sVarname]) - ? $_GET[$sVarname] - : false - ) - ; + ? $_POST[$sVarname] + : ((isset($_GET[$sVarname]) && $_GET[$sVarname]) + ? $_GET[$sVarname] + : false + ) + ; return self::getvar($aScope, $sVarname, $sRegexMatch, $sType); } @@ -84,7 +100,8 @@ class queryparam{ * @param string $sType force type: false|int * @return mixed NULL|value */ - static function post($sVarname, $sRegexMatch=false, $sType=false) { + static function post(string $sVarname, string $sRegexMatch = '', string $sType = ''): mixed + { return self::getvar($_POST, $sVarname, $sRegexMatch, $sType); }