Skip to content
Snippets Groups Projects
Commit 26187f0d authored by hahn's avatar hahn
Browse files

replace array_key_exists()

parent 850e166c
No related branches found
No related tags found
1 merge request!195534 add docker
...@@ -45,7 +45,7 @@ class Actionlog { ...@@ -45,7 +45,7 @@ class Actionlog {
*/ */
public function __construct($sProject = false) { public function __construct($sProject = false) {
global $aConfig; global $aConfig;
if (!is_array($aConfig) || !array_key_exists("appRootDir", $aConfig)) { if (!isset($aConfig["appRootDir"])) {
die(__CLASS__ . "::".__FUNCTION__." ERROR: configuration with \$aConfig was not loaded."); die(__CLASS__ . "::".__FUNCTION__." ERROR: configuration with \$aConfig was not loaded.");
} }
$this->_dbfile = $aConfig['dataDir'] . '/database/logs.db'; $this->_dbfile = $aConfig['dataDir'] . '/database/logs.db';
...@@ -164,24 +164,24 @@ class Actionlog { ...@@ -164,24 +164,24 @@ class Actionlog {
$sWhere = false; $sWhere = false;
$aWhere=array(); $aWhere=array();
if (array_key_exists("project", $aFilter) && $aFilter["project"]) { if (isset($aFilter["project"]) && $aFilter["project"]) {
$aWhere[]='`project`="' . $this->_filterAllowedChars($aFilter["project"], '[a-z0-9\-\_]') . '"'; $aWhere[]='`project`="' . $this->_filterAllowedChars($aFilter["project"], '[a-z0-9\-\_]') . '"';
} }
if (array_key_exists("from", $aFilter) && $aFilter["from"]) { if (isset($aFilter["from"])) {
$aWhere[]='`time`>="' . $this->_filterAllowedChars($aFilter["from"], '[0-9\-\ \:]') . '"'; $aWhere[]='`time`>="' . $this->_filterAllowedChars($aFilter["from"], '[0-9\-\ \:]') . '"';
} }
if (array_key_exists("to", $aFilter) && $aFilter["to"]) { if (isset($aFilter["to"])) {
$aWhere[]='`time`<="' . $this->_filterAllowedChars($aFilter["to"], '[0-9\-\ \:]') . '"'; $aWhere[]='`time`<="' . $this->_filterAllowedChars($aFilter["to"], '[0-9\-\ \:]') . '"';
} }
$sSql.=(count($aWhere) ? 'WHERE '. implode(' AND ', $aWhere) : ''); $sSql.=(count($aWhere) ? 'WHERE '. implode(' AND ', $aWhere) : '');
if (array_key_exists("order", $aFilter) && $aFilter["order"]) { if (isset($aFilter["order"])) {
$sSql.=' ORDER BY ' . $this->_filterAllowedChars($aFilter["order"], '[a-z\`0-9\,\ ]'); $sSql.=' ORDER BY ' . $this->_filterAllowedChars($aFilter["order"], '[a-z\`0-9\,\ ]');
} else { } else {
$sSql.=' ORDER BY id DESC '; $sSql.=' ORDER BY id DESC ';
} }
if (array_key_exists("limit", $aFilter) && $aFilter["limit"]) { if (isset($aFilter["limit"])) {
$sSql.=' LIMIT ' . $this->_filterAllowedChars($aFilter["limit"], '[0-9\,\ ]'); $sSql.=' LIMIT ' . $this->_filterAllowedChars($aFilter["limit"], '[0-9\,\ ]');
} }
...@@ -293,13 +293,13 @@ class Actionlog { ...@@ -293,13 +293,13 @@ class Actionlog {
} else { } else {
// write filters as hidden fields // write filters as hidden fields
if (array_key_exists("project", $aFilter)){ if (isset($aFilter["project"])){
$aForms["filter"]["form"]['selectproject'] = array( $aForms["filter"]["form"]['selectproject'] = array(
'type' => 'hidden', 'type' => 'hidden',
'value' => $aFilter["project"] 'value' => $aFilter["project"]
); );
} }
if (array_key_exists("limit", $aFilter)){ if (isset($aFilter["limit"])){
$aForms["filter"]["form"]['selectlimit'] = array( $aForms["filter"]["form"]['selectlimit'] = array(
'type' => 'hidden', 'type' => 'hidden',
'value' => $aFilter["limit"] 'value' => $aFilter["limit"]
......
...@@ -50,7 +50,7 @@ class configreplacement { ...@@ -50,7 +50,7 @@ class configreplacement {
$aBuildfiles=$this->_oProject->getBuildfilesByPlace($this->_sPhase, 'ready2install'); $aBuildfiles=$this->_oProject->getBuildfilesByPlace($this->_sPhase, 'ready2install');
} }
if (!$aBuildfiles || !array_key_exists('types', $aBuildfiles) || !array_key_exists('templates', $aBuildfiles['types'])){ if (!isset($aBuildfiles['types']['templates'])){
return false; return false;
} }
foreach ($aBuildfiles['types']['templates'] as $sFile){ foreach ($aBuildfiles['types']['templates'] as $sFile){
...@@ -110,7 +110,7 @@ class configreplacement { ...@@ -110,7 +110,7 @@ class configreplacement {
} }
// abort if no foreman connection was configured // abort if no foreman connection was configured
if (!array_key_exists('foreman', $aConfig)) { if (!isset($aConfig['foreman'])) {
return false; return false;
} }
...@@ -147,7 +147,7 @@ class configreplacement { ...@@ -147,7 +147,7 @@ class configreplacement {
// HACK: phases are part of the hostname .. but not "live" ... and special handling for demo // HACK: phases are part of the hostname .. but not "live" ... and special handling for demo
$aPrjConfig=$this->_oProject->getConfig(); $aPrjConfig=$this->_oProject->getConfig();
$bIsDemo=(array_key_exists('fileprefix', $aPrjConfig) $bIsDemo=(isset($aPrjConfig['fileprefix'])
&& !strpos($aPrjConfig['fileprefix'], 'demo')===false); && !strpos($aPrjConfig['fileprefix'], 'demo')===false);
$sPhase=$bIsDemo ? 'demo' : $this->_sPhase; $sPhase=$bIsDemo ? 'demo' : $this->_sPhase;
foreach($aHosts as $aName){ foreach($aHosts as $aName){
...@@ -216,14 +216,14 @@ class configreplacement { ...@@ -216,14 +216,14 @@ class configreplacement {
$aReturn=array(); $aReturn=array();
foreach ($aProject as $sFile=>$aParams){ foreach ($aProject as $sFile=>$aParams){
$aReturn[$sFile]=array(); $aReturn[$sFile]=array();
if (array_key_exists('target', $aParams)){ if (isset($aParams['target'])){
$aReturn[$sFile]['target']=$aParams['target']; $aReturn[$sFile]['target']=$aParams['target'];
} }
if (array_key_exists('replace', $aParams)){ if (isset($aParams['replace'])){
$aReplace=json_decode($aParams['replace'], 1); $aReplace=json_decode($aParams['replace'], 1);
$aReturn[$sFile]['replace_source']=$aReplace; $aReturn[$sFile]['replace_source']=$aReplace;
foreach ($aReplace as $sVarname=>$value){ foreach ($aReplace as $sVarname=>$value){
if (is_array($value) && array_key_exists('_'.$this->_sPhase.'_', $value)){ if (isset($value['_'.$this->_sPhase.'_'])){
$value=$value['_'.$this->_sPhase.'_']; $value=$value['_'.$this->_sPhase.'_'];
} }
$aReturn[$sFile]['replace'][$sVarname]=$value; $aReturn[$sFile]['replace'][$sVarname]=$value;
...@@ -252,13 +252,10 @@ class configreplacement { ...@@ -252,13 +252,10 @@ class configreplacement {
*/ */
private function _getForemanBaseUrl(){ private function _getForemanBaseUrl(){
global $aConfig; global $aConfig;
if (!array_key_exists('foreman', $aConfig) return (isset($aConfig['foreman']['api']))
|| !array_key_exists('api', $aConfig['foreman']) ? $aConfig['foreman']['api']
|| !$aConfig['foreman']['api'] : false
){ ;
return false;
}
return $aConfig['foreman']['api'];
} }
/** /**
...@@ -272,7 +269,7 @@ class configreplacement { ...@@ -272,7 +269,7 @@ class configreplacement {
return false; return false;
} }
$aTmp=$this->_getForemanReplacement(); $aTmp=$this->_getForemanReplacement();
if (!array_key_exists('hostsphase', $aTmp)){ if (!isset($aTmp['hostsphase'])){
return false; return false;
} }
require_once 'htmlguielements.class.php'; require_once 'htmlguielements.class.php';
......
...@@ -123,7 +123,7 @@ class deployForeman { ...@@ -123,7 +123,7 @@ class deployForeman {
public function __construct($aCfg) { public function __construct($aCfg) {
if(!is_array($aCfg) || !count($aCfg) || !array_key_exists('api', $aCfg)){ if(!isset($aCfg['api'])){
die("ERROR: class ".__CLASS__." must be initialized with an array containing api config for foreman."); die("ERROR: class ".__CLASS__." must be initialized with an array containing api config for foreman.");
return false; return false;
} }
...@@ -173,7 +173,7 @@ class deployForeman { ...@@ -173,7 +173,7 @@ class deployForeman {
* @return string * @return string
*/ */
protected function _generateUrl(){ protected function _generateUrl(){
if(!array_key_exists('request', $this->_aRequest)){ if(!isset($this->_aRequest['request'])){
die('ERROR: missing key [request]'); die('ERROR: missing key [request]');
} }
$sReturn=$this->_aCfg['api']; $sReturn=$this->_aCfg['api'];
...@@ -182,7 +182,7 @@ class deployForeman { ...@@ -182,7 +182,7 @@ class deployForeman {
$sReturn.=$sPrefix; $sReturn.=$sPrefix;
foreach($this->_aRequest['request'] as $aReqItem){ foreach($this->_aRequest['request'] as $aReqItem){
if (!array_key_exists($aReqItem[0], $this->_aAllowedUrls[$sPrefix])){ if (!isset($this->_aAllowedUrls[$sPrefix][$aReqItem[0]])){
echo 'WARNING: wrong item: [' . $aReqItem[0]."]<br>\n"; echo 'WARNING: wrong item: [' . $aReqItem[0]."]<br>\n";
} }
$sReturn.=$aReqItem[0] ? $aReqItem[0].'/' : ''; $sReturn.=$aReqItem[0] ? $aReqItem[0].'/' : '';
...@@ -199,14 +199,14 @@ class deployForeman { ...@@ -199,14 +199,14 @@ class deployForeman {
* @return string * @return string
*/ */
protected function _generateParams(){ protected function _generateParams(){
if (!array_key_exists('filter', $this->_aRequest)){ if (!isset($this->_aRequest['filter'])){
return ''; return '';
} }
$sReturn='?'; $sReturn='?';
// TODO: "sort by" and "sort order" ... need to be added here ... somehow // TODO: "sort by" and "sort order" ... need to be added here ... somehow
foreach(array('page', 'per_page', 'search') as $sParam){ foreach(array('page', 'per_page', 'search') as $sParam){
if (array_key_exists($sParam, $this->_aRequest['filter'])){ if (isset($this->_aRequest['filter'][$sParam])){
$sReturn.='&'.$sParam.'='.urlencode($this->_aRequest['filter'][$sParam]); $sReturn.='&'.$sParam.'='.urlencode($this->_aRequest['filter'][$sParam]);
} }
} }
...@@ -233,10 +233,11 @@ class deployForeman { ...@@ -233,10 +233,11 @@ class deployForeman {
die("ERROR: PHP CURL module is not installed."); die("ERROR: PHP CURL module is not installed.");
} }
$sApiUser=array_key_exists('user', $this->_aCfg) ? $this->_aCfg['user'] : false; $sApiUser=isset($this->_aCfg['user']) ? $this->_aCfg['user'] : false;
$sApiPassword=array_key_exists('password', $this->_aCfg) ? $this->_aCfg['password'] : false; $sApiPassword=isset($this->_aCfg['password']) ? $this->_aCfg['password'] : false;
$sFullUrl=$sApiUrl.$this->_aRequest['url']; // $sFullUrl=$sApiUrl.$this->_aRequest['url'];
$sFullUrl=$this->_aRequest['url'];
$this->log(__FUNCTION__ . " ".$this->_aRequest['method']." " . $this->_aRequest['url']); $this->log(__FUNCTION__ . " ".$this->_aRequest['method']." " . $this->_aRequest['url']);
$ch = curl_init($this->_aRequest['url']); $ch = curl_init($this->_aRequest['url']);
...@@ -309,11 +310,16 @@ class deployForeman { ...@@ -309,11 +310,16 @@ class deployForeman {
// prevent missing data because of paging // prevent missing data because of paging
if ($this->_aRequest['method']==='GET' && !array_key_exists('per_page', $this->_aRequest['filter'])){ if ($this->_aRequest['method']==='GET' && !isset($this->_aRequest['filter']['per_page'])){
$this->_aRequest['filter']['per_page']=1000; $this->_aRequest['filter']['per_page']=1000;
} }
// TODO check postdata // TODO check postdata
if ($this->_aRequest['method']==='POST' && (!array_key_exists('postdata',$this->_aRequest) || !count($this->_aRequest['postdata']))){ if ($this->_aRequest['method']==='POST' && (
!isset($this->_aRequest['postdata'])
|| !is_array($this->_aRequest['postdata'])
|| !count($this->_aRequest['postdata'])
)
){
die("ERROR in ".__CLASS__."::".__FUNCTION__.": missing data to make a POST request"); die("ERROR in ".__CLASS__."::".__FUNCTION__.": missing data to make a POST request");
} }
...@@ -344,7 +350,7 @@ class deployForeman { ...@@ -344,7 +350,7 @@ class deployForeman {
if($bOk){ if($bOk){
$aJson=json_decode($aReturn['body'], 1); $aJson=json_decode($aReturn['body'], 1);
if (is_array($aJson)){ if (is_array($aJson)){
if (array_key_exists('total', $aJson) && $aJson['total'] > $aJson['per_page']){ if (isset($aJson['total']) && $aJson['total'] > $aJson['per_page']){
$bOk=false; $bOk=false;
$sStatus='Http OK, but incomplete results (paging)'; $sStatus='Http OK, but incomplete results (paging)';
} }
...@@ -367,10 +373,10 @@ class deployForeman { ...@@ -367,10 +373,10 @@ class deployForeman {
* @return array * @return array
*/ */
protected function _filterOutput($aData){ protected function _filterOutput($aData){
if(!array_key_exists('response', $this->_aRequest)){ if(!isset($this->_aRequest['response'])){
return $aData; return $aData;
} }
$aTmp=array_key_exists('results', $aData['_json']) ? $aData['_json']['results'] : array($aData['_json']); $aTmp=isset($aData['_json']['results']) ? $aData['_json']['results'] : array($aData['_json']);
if(!count($aTmp)){ if(!count($aTmp)){
return array(); return array();
} }
......
...@@ -133,7 +133,7 @@ class ForemanApi { ...@@ -133,7 +133,7 @@ class ForemanApi {
public function __construct($aCfg) { public function __construct($aCfg) {
if(!is_array($aCfg) || !count($aCfg) || !array_key_exists('api', $aCfg)){ if(!isset($aCfg['api'])){
die("ERROR: class ".__CLASS__." must be initialized with an array containing api config for foreman."); die("ERROR: class ".__CLASS__." must be initialized with an array containing api config for foreman.");
return false; return false;
} }
...@@ -154,10 +154,8 @@ class ForemanApi { ...@@ -154,10 +154,8 @@ class ForemanApi {
*/ */
protected function log($sMessage, $sLevel = "info") { protected function log($sMessage, $sLevel = "info") {
global $oCLog; global $oCLog;
if(is_object($oCLog) && method_exists($oCLog, 'add')){
return $oCLog->add(basename(__FILE__) . " class " . __CLASS__ . " - " . $sMessage, $sLevel); return $oCLog->add(basename(__FILE__) . " class " . __CLASS__ . " - " . $sMessage, $sLevel);
} }
}
/** /**
* search url prefix in $this->_aAllowedUrls by given key * search url prefix in $this->_aAllowedUrls by given key
...@@ -188,7 +186,7 @@ class ForemanApi { ...@@ -188,7 +186,7 @@ class ForemanApi {
* @return string * @return string
*/ */
protected function _generateUrl(){ protected function _generateUrl(){
if(!array_key_exists('request', $this->_aRequest)){ if(!isset($this->_aRequest['request'])){
die('ERROR: missing key [request]'); die('ERROR: missing key [request]');
} }
$sReturn=$this->_aCfg['api']; $sReturn=$this->_aCfg['api'];
...@@ -197,7 +195,7 @@ class ForemanApi { ...@@ -197,7 +195,7 @@ class ForemanApi {
$sReturn.=$sPrefix.'/'; $sReturn.=$sPrefix.'/';
foreach($this->_aRequest['request'] as $aReqItem){ foreach($this->_aRequest['request'] as $aReqItem){
if (!array_key_exists($aReqItem[0], $this->_aAllowedUrls[$sPrefix])){ if (!isset($this->_aAllowedUrls[$sPrefix][$aReqItem[0]])){
echo 'WARNING: wrong item: [' . $aReqItem[0]."]<br>\n"; echo 'WARNING: wrong item: [' . $aReqItem[0]."]<br>\n";
} }
$sReturn.=$aReqItem[0] ? $aReqItem[0].'/' : ''; $sReturn.=$aReqItem[0] ? $aReqItem[0].'/' : '';
...@@ -214,7 +212,7 @@ class ForemanApi { ...@@ -214,7 +212,7 @@ class ForemanApi {
* @return string * @return string
*/ */
protected function _generateParams(){ protected function _generateParams(){
if (!array_key_exists('filter', $this->_aRequest)){ if (!isset($this->_aRequest['filter'])){
return ''; return '';
} }
$sReturn='?'; $sReturn='?';
...@@ -246,10 +244,11 @@ class ForemanApi { ...@@ -246,10 +244,11 @@ class ForemanApi {
die("ERROR: PHP CURL module is not installed."); die("ERROR: PHP CURL module is not installed.");
} }
$sApiUser=array_key_exists('user', $this->_aCfg) ? $this->_aCfg['user'] : false; $sApiUser=isset($this->_aCfg['user']) ? $this->_aCfg['user'] : false;
$sApiPassword=array_key_exists('password', $this->_aCfg) ? $this->_aCfg['password'] : false; $sApiPassword=isset($this->_aCfg['password']) ? $this->_aCfg['password'] : false;
$sFullUrl=$sApiUrl.$this->_aRequest['url']; // $sFullUrl=$sApiUrl.$this->_aRequest['url'];
$sFullUrl=$this->_aRequest['url'];
$this->log(__FUNCTION__ . " ".$this->_aRequest['method']." " . $this->_aRequest['url']); $this->log(__FUNCTION__ . " ".$this->_aRequest['method']." " . $this->_aRequest['url']);
$ch = curl_init($this->_aRequest['url']); $ch = curl_init($this->_aRequest['url']);
...@@ -330,12 +329,19 @@ class ForemanApi { ...@@ -330,12 +329,19 @@ class ForemanApi {
$this->_aRequest['filter']['per_page']=1000; $this->_aRequest['filter']['per_page']=1000;
} }
// TODO check postdata // TODO check postdata
if ($this->_aRequest['method']==='POST' && (!array_key_exists('postdata',$this->_aRequest) || !count($this->_aRequest['postdata']))){ if ($this->_aRequest['method']==='POST' && (
!isset($this->_aRequest['postdata'])
|| !is_array($this->_aRequest['postdata'])
|| !count($this->_aRequest['postdata'])
)
){
die("ERROR in ".__CLASS__."::".__FUNCTION__.": missing data to make a POST request"); die("ERROR in ".__CLASS__."::".__FUNCTION__.": missing data to make a POST request");
} }
if (!array_key_exists('url', $this->_aRequest)){
$this->_aRequest['url']=$this->_generateUrl().$this->_generateParams(); $this->_aRequest['url']=isset($this->_aRequest['url'])
} ? $this->_aRequest['url']
: $this->_generateUrl().$this->_generateParams()
;
// ----- request // ----- request
$this->_writeDebug(__FUNCTION__ . ' start request <pre>'.print_r($this->_aRequest,1).'</pre>'); $this->_writeDebug(__FUNCTION__ . ' start request <pre>'.print_r($this->_aRequest,1).'</pre>');
...@@ -362,7 +368,7 @@ class ForemanApi { ...@@ -362,7 +368,7 @@ class ForemanApi {
if($bOk){ if($bOk){
$aJson=json_decode($aReturn['body'], 1); $aJson=json_decode($aReturn['body'], 1);
if (is_array($aJson)){ if (is_array($aJson)){
if (array_key_exists('total', $aJson) && $aJson['total'] > $aJson['per_page']){ if (isset($aJson['total']) && $aJson['total'] > $aJson['per_page']){
$bOk=false; $bOk=false;
$sStatus='Http OK, but incomplete results (paging)'; $sStatus='Http OK, but incomplete results (paging)';
} }
...@@ -386,11 +392,10 @@ class ForemanApi { ...@@ -386,11 +392,10 @@ class ForemanApi {
* @return array * @return array
*/ */
protected function _filterOutput($aData){ protected function _filterOutput($aData){
if(!array_key_exists('response', $this->_aRequest)){ if(!isset($this->_aRequest['response'])){
return $aData; return $aData;
} }
$bIsList=array_key_exists('results', $aData['_json']); $aTmp=isset($aData['_json']['results']) ? $aData['_json']['results'] : array($aData['_json']);
$aTmp=$bIsList ? $aData['_json']['results'] : array($aData['_json']);
if(!count($aTmp)){ if(!count($aTmp)){
return array(); return array();
} }
...@@ -404,9 +409,12 @@ class ForemanApi { ...@@ -404,9 +409,12 @@ class ForemanApi {
} }
$aReturn[] = $aReturnitem; $aReturn[] = $aReturnitem;
} }
/*
return ($bIsList==1) return ($bIsList==1)
? $aReturn ? $aReturn
: (count($aReturn) ? $aReturn[0] : array()); : (count($aReturn) ? $aReturn[0] : array());
*/
return $aReturn;
} }
......
...@@ -48,14 +48,14 @@ class formgen { ...@@ -48,14 +48,14 @@ class formgen {
*/ */
public function renderHtml($sFormId) { public function renderHtml($sFormId) {
$sReturn = false; $sReturn = false;
if (!array_key_exists($sFormId, $this->aForm)) { if (!isset($this->aForm[$sFormId])) {
die("ERROR: " . __CLASS__ . ":" . __FUNCTION__ . " - form id " . $sFormId . " does not exist."); die("ERROR: " . __CLASS__ . ":" . __FUNCTION__ . " - form id " . $sFormId . " does not exist.");
} }
// FORM tag // FORM tag
$sReturn.='<form '; $sReturn.='<form ';
if (array_key_exists("meta", $this->aForm[$sFormId])) { if (isset($this->aForm[$sFormId]["meta"])) {
foreach (array("method", "action", "target", "accept-charset", "class", "id", "name") as $sAttr) { foreach (array("method", "action", "target", "accept-charset", "class", "id", "name") as $sAttr) {
if (array_key_exists($sAttr, $this->aForm[$sFormId]["meta"])) { if (isset($this->aForm[$sFormId]["meta"][$sAttr])) {
$sReturn.=$sAttr . '="' . $this->aForm[$sFormId]["meta"][$sAttr] . '" '; $sReturn.=$sAttr . '="' . $this->aForm[$sFormId]["meta"][$sAttr] . '" ';
} }
} }
...@@ -80,10 +80,10 @@ class formgen { ...@@ -80,10 +80,10 @@ class formgen {
private function _addHtmlAtrributes($aAttributes, $elementData) { private function _addHtmlAtrributes($aAttributes, $elementData) {
$sReturn = false; $sReturn = false;
foreach ($aAttributes as $sAtrr) { foreach ($aAttributes as $sAtrr) {
if (array_key_exists($sAtrr, $elementData) && $elementData[$sAtrr]) { if (isset($elementData[$sAtrr]) && $elementData[$sAtrr]) {
if ($sReturn) $sReturn.=($sReturn ? ' ' : '')
$sReturn.=' '; .$sAtrr . '="' . $elementData[$sAtrr] . '"'
$sReturn.=$sAtrr . '="' . $elementData[$sAtrr] . '"'; ;
} }
} }
return $sReturn; return $sReturn;
...@@ -102,7 +102,7 @@ class formgen { ...@@ -102,7 +102,7 @@ class formgen {
private function _checkReqiredKeys($aArray, $aRequiredKeys, $sLabel = false) { private function _checkReqiredKeys($aArray, $aRequiredKeys, $sLabel = false) {
$bReturn = true; $bReturn = true;
foreach ($aRequiredKeys as $sKey) { foreach ($aRequiredKeys as $sKey) {
if (!array_key_exists($sKey, $aArray)) { if (!isset($aArray[$sKey])) {
die("ERROR: $sLabel<br>Missing key \"$sKey\" in the array of a form element:<pre>" . print_r($aArray, true) . "</pre>"); die("ERROR: $sLabel<br>Missing key \"$sKey\" in the array of a form element:<pre>" . print_r($aArray, true) . "</pre>");
$bReturn = false; $bReturn = false;
} }
...@@ -130,7 +130,7 @@ class formgen { ...@@ -130,7 +130,7 @@ class formgen {
. "title" . "title"
; ;
if (!array_key_exists("type", $elementData)) { if (!isset($elementData["type"])) {
print_r($elementData); print_r($elementData);
die("ERROR: " . __CLASS__ . ":" . __FUNCTION__ . " - key &quot;type&quot; does not exist."); die("ERROR: " . __CLASS__ . ":" . __FUNCTION__ . " - key &quot;type&quot; does not exist.");
} }
...@@ -142,9 +142,9 @@ class formgen { ...@@ -142,9 +142,9 @@ class formgen {
$sHtmlDefault = ''; $sHtmlDefault = '';
$sHtmlTable = ''; $sHtmlTable = '';
if (array_key_exists("label", $elementData)) { if (isset($elementData["label"])) {
$sLabelText = $elementData["label"]; $sLabelText = $elementData["label"];
$sLabelText.=(array_key_exists("required", $elementData) && $elementData["required"]) ? $this->sRequired : ''; $sLabelText.=(isset($elementData["required"]) && $elementData["required"]) ? $this->sRequired : '';
} }
switch ($elementData["type"]) { switch ($elementData["type"]) {
...@@ -190,7 +190,7 @@ class formgen { ...@@ -190,7 +190,7 @@ class formgen {
break; break;
case "markup": case "markup":
if (array_key_exists("value", $elementData)) if (isset($elementData["value"]))
$sHtmlDefault = $elementData["value"] . "\n"; $sHtmlDefault = $elementData["value"] . "\n";
break; break;
...@@ -224,7 +224,7 @@ class formgen { ...@@ -224,7 +224,7 @@ class formgen {
case "select": case "select":
// HINWEIS optgroups werden nicht unterstuezt - nur einfache Listen // HINWEIS optgroups werden nicht unterstuezt - nur einfache Listen
$this->_checkReqiredKeys($elementData, array("name")); $this->_checkReqiredKeys($elementData, array("name"));
$sDivClass=(array_key_exists("inline", $elementData) && $elementData["inline"])?"form-group":"col-sm-10"; $sDivClass=(isset($elementData["inline"]) && $elementData["inline"])?"form-group":"col-sm-10";
$sFormElement.='<div class="'.$sDivClass.'"><select id="' . $sId . '" class="form-control" '; $sFormElement.='<div class="'.$sDivClass.'"><select id="' . $sId . '" class="form-control" ';
$sFormElement.=$this->_addHtmlAtrributes(explode(",", "$sDefaultAttributes,name,onchange"), $elementData); $sFormElement.=$this->_addHtmlAtrributes(explode(",", "$sDefaultAttributes,name,onchange"), $elementData);
$sFormElement.=">\n"; $sFormElement.=">\n";
...@@ -239,7 +239,7 @@ class formgen { ...@@ -239,7 +239,7 @@ class formgen {
if ($sLabelText) { if ($sLabelText) {
// $sLabelElement.='<span class="help-block">' . $sLabelText . '</span>' . "\n"; // $sLabelElement.='<span class="help-block">' . $sLabelText . '</span>' . "\n";
$sLabelClass=(array_key_exists("inline", $elementData) && $elementData["inline"])?"":"col-sm-2"; $sLabelClass=(isset($elementData["inline"]) && $elementData["inline"])?"":"col-sm-2";
$sLabelElement = $this->_addLabel($sLabelText, $sId, $sLabelClass); $sLabelElement = $this->_addLabel($sLabelText, $sId, $sLabelClass);
} }
...@@ -252,7 +252,7 @@ class formgen { ...@@ -252,7 +252,7 @@ class formgen {
case "submit": case "submit":
$this->_checkReqiredKeys($elementData, array("value")); $this->_checkReqiredKeys($elementData, array("value"));
$sClass="btn btn-primary "; $sClass="btn btn-primary ";
if (array_key_exists("class", $elementData)){ if (isset($elementData["class"])){
$sClass.=$elementData["class"]; $sClass.=$elementData["class"];
} }
$elementData["class"]=$sClass; $elementData["class"]=$sClass;
...@@ -276,7 +276,7 @@ class formgen { ...@@ -276,7 +276,7 @@ class formgen {
$sFormElement.=' />'; $sFormElement.=' />';
$sFormElement.="\n"; $sFormElement.="\n";
if (array_key_exists("inline", $elementData) && $elementData["inline"]){ if (isset($elementData["class"]) && $elementData["inline"]){
$sLabelElement = $this->_addLabel($sLabelText, $sId, "col-sm-2"); $sLabelElement = $this->_addLabel($sLabelText, $sId, "col-sm-2");
// $sHtmlDefault = $sLabelElement . "\n" . $sFormElement . "\n"; // $sHtmlDefault = $sLabelElement . "\n" . $sFormElement . "\n";
$sHtmlDefault = $sLabelElement . '<div class="col-sm-3">' . "\n" . $sFormElement . '</div>' . "\n"; $sHtmlDefault = $sLabelElement . '<div class="col-sm-3">' . "\n" . $sFormElement . '</div>' . "\n";
...@@ -313,11 +313,11 @@ class formgen { ...@@ -313,11 +313,11 @@ class formgen {
} }
// Default or table mode? // Default or table mode?
if (array_key_exists("mode", $elementData) && $elementData["mode"] == 'table' && $sHtmlTable) { if (isset($elementData["mode"]) && $elementData["mode"] == 'table' && $sHtmlTable) {
$sHtmlDefault = $sHtmlTable; $sHtmlDefault = $sHtmlTable;
} else { } else {
if ($elementData["type"] != "button" && $elementData["type"] != "fieldset" && $elementData["type"] != "markup") { if ($elementData["type"] != "button" && $elementData["type"] != "fieldset" && $elementData["type"] != "markup") {
if (!array_key_exists("inline", $elementData) || !$elementData["inline"]){ if (!isset($elementData["inline"]) || !$elementData["inline"]){
// $sHtmlDefault = "<fieldset>" . $sHtmlDefault . "</fieldset>\n"; // $sHtmlDefault = "<fieldset>" . $sHtmlDefault . "</fieldset>\n";
$sHtmlDefault = '<div class="form-group">' . $sHtmlDefault . '</div>'."\n"; $sHtmlDefault = '<div class="form-group">' . $sHtmlDefault . '</div>'."\n";
} }
......
...@@ -220,7 +220,7 @@ class htmlguielements{ ...@@ -220,7 +220,7 @@ class htmlguielements{
* @return string * @return string
*/ */
public function addAttributeFromKey($sAttribute, $aData, $sDefault=''){ public function addAttributeFromKey($sAttribute, $aData, $sDefault=''){
return (array_key_exists($sAttribute, $aData) return (isset($aData[$sAttribute])
? $this->addAttribute($sAttribute, $aData[$sAttribute]) ? $this->addAttribute($sAttribute, $aData[$sAttribute])
: $this->addAttribute($sAttribute, $sDefault) : $this->addAttribute($sAttribute, $sDefault)
); );
...@@ -281,7 +281,7 @@ class htmlguielements{ ...@@ -281,7 +281,7 @@ class htmlguielements{
* @return array * @return array
*/ */
public function getIconByType($sType){ public function getIconByType($sType){
return (array_key_exists($sType, $this->aCfg['icons']) return (isset($this->aCfg['icons'][$sType])
? $this->getIcon($this->aCfg['icons'][$sType]) ? $this->getIcon($this->aCfg['icons'][$sType])
: '' : ''
); );
...@@ -296,11 +296,11 @@ class htmlguielements{ ...@@ -296,11 +296,11 @@ class htmlguielements{
public function getLink($aItem){ public function getLink($aItem){
$sHref=$this->addAttributeFromKey('href', $aItem, '#'); $sHref=$this->addAttributeFromKey('href', $aItem, '#');
$sLabel=(array_key_exists('icon', $aItem) ? $this->getIcon($aItem['icon']): '') $sLabel=(isset($aItem['icon']) ? $this->getIcon($aItem['icon']): '')
.(array_key_exists('label', $aItem) ? $aItem['label'] : ''); .(isset($aItem['label']) ? $aItem['label'] : '');
foreach(array('href', 'icon', 'label') as $sKey){ foreach(array('href', 'icon', 'label') as $sKey){
if (array_key_exists($sKey, $aItem)){ if (isset($aItem[$sKey])){
unset($aItem[$sKey]); unset($aItem[$sKey]);
} }
} }
...@@ -322,7 +322,7 @@ class htmlguielements{ ...@@ -322,7 +322,7 @@ class htmlguielements{
*/ */
protected function _getButtonattributesByType($aItem){ protected function _getButtonattributesByType($aItem){
$aReturn=$aItem; $aReturn=$aItem;
if (array_key_exists($aItem['type'], $this->aCfg['buttons'])){ if (isset($this->aCfg['buttons'][$aItem['type']])){
$sClass=$this->aCfg['buttons'][$aItem['type']]['class']; $sClass=$this->aCfg['buttons'][$aItem['type']]['class'];
$aReturn['class'].=$sClass ? ' '.$sClass : ''; $aReturn['class'].=$sClass ? ' '.$sClass : '';
...@@ -331,7 +331,11 @@ class htmlguielements{ ...@@ -331,7 +331,11 @@ class htmlguielements{
$aReturn['icon']=$aReturn['icon'] ? $aReturn['icon'] : $aReturn['icon']=$aReturn['icon'] ? $aReturn['icon'] :
( $this->aCfg['buttons'][$aItem['type']]['icon'] ( $this->aCfg['buttons'][$aItem['type']]['icon']
? $this->aCfg['buttons'][$aItem['type']]['icon'] ? $this->aCfg['buttons'][$aItem['type']]['icon']
: ( array_key_exists($aItem['type'], $this->aCfg['icons']) ? $this->aCfg['icons'][$aItem['type']] : '') : (
isset($this->aCfg['icons'][$aItem['type']])
? $this->aCfg['icons'][$aItem['type']]
: ''
)
); );
} }
return $aReturn; return $aReturn;
...@@ -346,13 +350,13 @@ class htmlguielements{ ...@@ -346,13 +350,13 @@ class htmlguielements{
*/ */
public function getLinkButton($aItem){ public function getLinkButton($aItem){
foreach(array('class', 'icon') as $sKey){ foreach(array('class', 'icon') as $sKey){
if (!array_key_exists($sKey, $aItem)){ if (!isset($aItem[$sKey])){
$aItem[$sKey]=''; $aItem[$sKey]='';
} }
} }
$aItem['class'].='btn btn-default'; $aItem['class'].='btn btn-default';
if (array_key_exists('type', $aItem)){ if (isset($aItem['type'])){
$aItem=$this->_getButtonattributesByType($aItem); $aItem=$this->_getButtonattributesByType($aItem);
unset($aItem['type']); unset($aItem['type']);
} }
...@@ -379,7 +383,7 @@ class htmlguielements{ ...@@ -379,7 +383,7 @@ class htmlguielements{
); );
$sClass = ""; $sClass = "";
$sPrefix = ""; $sPrefix = "";
if (array_key_exists($sWarnlevel, $aCfg)) { if (isset($aCfg[$sWarnlevel])) {
$sClass = $aCfg[$sWarnlevel]["class"]; $sClass = $aCfg[$sWarnlevel]["class"];
$sPrefix = $aCfg[$sWarnlevel]["prefix"]; $sPrefix = $aCfg[$sWarnlevel]["prefix"];
$sMessage = '<strong>' . $aCfg[$sWarnlevel]["prefix"] . '</strong> ' . $sMessage; $sMessage = '<strong>' . $aCfg[$sWarnlevel]["prefix"] . '</strong> ' . $sMessage;
...@@ -406,10 +410,10 @@ class htmlguielements{ ...@@ -406,10 +410,10 @@ class htmlguielements{
} }
$sNavType=$aTabData['options']['type']; // "tabs" or "pills" $sNavType=$aTabData['options']['type']; // "tabs" or "pills"
$sNavCss='nav nav-'.$sNavType; $sNavCss='nav nav-'.$sNavType;
if (array_key_exists('stacked', $aTabData['options']) && $aTabData['options']['stacked']){ if (isset($aTabData['options']['stacked']) && $aTabData['options']['stacked']){
$sNavCss.=' nav-stacked'; $sNavCss.=' nav-stacked';
} }
if (array_key_exists('justified', $aTabData['options']) && $aTabData['options']['justified']){ if (isset($aTabData['options']['justified']) && $aTabData['options']['justified']){
$sNavCss.=' nav-justified'; $sNavCss.=' nav-justified';
} }
$sNavType=$aTabData['options']['justified']; $sNavType=$aTabData['options']['justified'];
...@@ -443,7 +447,7 @@ class htmlguielements{ ...@@ -443,7 +447,7 @@ class htmlguielements{
public function getTable($aTabledata) { public function getTable($aTabledata) {
$sTHead=''; $sTHead='';
$sTBody=''; $sTBody='';
if (array_key_exists('body', $aTabledata)){ if (isset($aTabledata['body'])){
foreach ($aTabledata['body'] as $aRow){ foreach ($aTabledata['body'] as $aRow){
$sTBody.='<tr>'; $sTBody.='<tr>';
foreach ($aRow as $sItem){ foreach ($aRow as $sItem){
...@@ -452,7 +456,7 @@ class htmlguielements{ ...@@ -452,7 +456,7 @@ class htmlguielements{
$sTBody.='</tr>'; $sTBody.='</tr>';
} }
} }
if (array_key_exists('header', $aTabledata)){ if (isset($aTabledata['header'])){
foreach ($aTabledata['header'] as $sItem){ foreach ($aTabledata['header'] as $sItem){
$sTHead.='<th>'.$sItem.'</th>'; $sTHead.='<th>'.$sItem.'</th>';
} }
......
...@@ -138,11 +138,11 @@ class user { ...@@ -138,11 +138,11 @@ class user {
public function authenticate(){ public function authenticate(){
global $aConfig, $aParams; global $aConfig, $aParams;
//print_r($aConfig); //print_r($aConfig);
if(!array_key_exists('auth', $aConfig) || !count($aConfig['auth']) || !array_key_exists('user', $aParams)){ if(!isset($aConfig['auth']) || !is_array($aConfig['auth']) || !count($aConfig['auth']) || !isset($aParams['user'])){
return false; return false;
} }
$sUser=$aParams['user']; $sUser=$aParams['user'];
$sPassword=array_key_exists('password', $aParams)?$aParams['password']:false; $sPassword=isset($aParams['password']) ? $aParams['password'] : false;
foreach (array_keys($aConfig['auth']) as $sAuthMethod){ foreach (array_keys($aConfig['auth']) as $sAuthMethod){
$oUserAuth=false; $oUserAuth=false;
......
...@@ -46,7 +46,7 @@ class vcs implements iVcs { ...@@ -46,7 +46,7 @@ class vcs implements iVcs {
/** /**
* name of the default remote branch to access * name of the default remote branch to access
* @var type * @var string
*/ */
private $_sCurrentBranch = "origin/master"; private $_sCurrentBranch = "origin/master";
...@@ -80,7 +80,7 @@ class vcs implements iVcs { ...@@ -80,7 +80,7 @@ class vcs implements iVcs {
// checks // checks
// foreach (array("type", "url") as $key) { // foreach (array("type", "url") as $key) {
foreach (array("type") as $key) { foreach (array("type") as $key) {
if (!array_key_exists($key, $aRepoConfig)) { if (!isset($aRepoConfig[$key])) {
die("ERROR: key $key does not exist in config <pre>" . print_r($aRepoConfig, true) . "</pre>"); die("ERROR: key $key does not exist in config <pre>" . print_r($aRepoConfig, true) . "</pre>");
} }
if (!$aRepoConfig[$key]) { if (!$aRepoConfig[$key]) {
...@@ -346,9 +346,9 @@ class vcs implements iVcs { ...@@ -346,9 +346,9 @@ class vcs implements iVcs {
if ( if (
is_array($this->_aRemoteBranches) is_array($this->_aRemoteBranches)
&& ( && (
array_key_exists($sBranch, $this->_aRemoteBranches) && $sVerifyRevision && $this->_aRemoteBranches[$sBranch]['revision'] == $sVerifyRevision isset($this->_aRemoteBranches[$sBranch]) && $sVerifyRevision && $this->_aRemoteBranches[$sBranch]['revision'] == $sVerifyRevision
|| ||
array_key_exists($sBranch, $this->_aRemoteBranches) && !$sVerifyRevision isset($this->_aRemoteBranches[$sBranch]) && !$sVerifyRevision
) )
) { ) {
// it is up to date - doing nothing // it is up to date - doing nothing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment