From 231773a97487b5c44d82aa6c8b99aa42e095eec9 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Wed, 22 Nov 2017 14:16:27 +0100 Subject: [PATCH] Dev Scrutinizer indentation and brace fixes --- application/commands/WipeCommand.php | 20 +- application/config/config-sample-dblib.php | 4 +- application/config/config-sample-mysql.php | 4 +- application/config/config-sample-sqlsrv.php | 4 +- application/config/packages.php | 4 +- application/config/third_party.php | 4 +- .../controllers/admin/themeoptions.php | 120 +++--- application/core/Survey_Common_Action.php | 368 +++++++++--------- .../views/publicSurveyList_extended.php | 3 +- application/helpers/admin/ajax_helper.php | 3 +- .../helpers/admin/export/DocWriter.php | 9 +- .../helpers/admin/export/HtmlWriter.php | 3 +- .../helpers/admin/export/JsonWriter.php | 3 +- .../helpers/admin/export/PdfWriter.php | 9 +- .../helpers/admin/export/Translator.php | 3 +- application/helpers/database_helper.php | 10 +- .../helpers/expressions/em_core_helper.php | 6 +- application/helpers/globals.php | 4 +- application/libraries/Date_Time_Converter.php | 4 +- .../libraries/PluginManager/PluginManager.php | 12 +- .../PluginManager/Question/QuestionBase.php | 12 +- .../PluginManager/Storage/DbStorage.php | 33 +- application/libraries/admin/Services_JSON.php | 5 +- application/models/Condition.php | 3 +- application/models/ParticipantAttribute.php | 4 +- application/models/SettingsUser.php | 206 +++++----- application/models/SurveyLink.php | 7 +- application/models/SurveyTimingDynamic.php | 8 +- application/models/TemplateConfiguration.php | 238 +++++------ application/models/TemplateManifest.php | 196 +++++----- 30 files changed, 652 insertions(+), 657 deletions(-) diff --git a/application/commands/WipeCommand.php b/application/commands/WipeCommand.php index 65e7edb32d5..ef9d901d749 100644 --- a/application/commands/WipeCommand.php +++ b/application/commands/WipeCommand.php @@ -109,15 +109,15 @@ public function run($sArgument) $surveyidresult = dbGetTablesLike("survey\_%"); foreach ($surveyidresult as $sv) { - if (strpos($sv, 'survey_links') === false && strpos($sv, 'survey_url_parameters') === false) - Yii::app()->db->createCommand("drop table ".$sv)->execute(); + if (strpos($sv, 'survey_links') === false && strpos($sv, 'survey_url_parameters') === false) { + Yii::app()->db->createCommand("drop table ".$sv)->execute(); + } } $sBaseUploadDir = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'upload'; SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'surveys', false); SureRemoveDir($sBaseUploadDir.DIRECTORY_SEPARATOR.'templates', false); - } - else + } else { // TODO: a valid error process echo 'This CLI command wipes a LimeSurvey installation clean (including all user except for the user ID 1 and user-uploaded content). For security reasons this command can only started if you add the parameter \'yes\' to the command line.'; @@ -130,10 +130,16 @@ public function run($sArgument) function SureRemoveDir($dir, $DeleteMe) { - if (!$dh = @opendir($dir)) return; + if (!$dh = @opendir($dir)) { + return; + } while (false !== ($obj = readdir($dh))) { - if ($obj == '.' || $obj == '..') continue; - if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true); + if ($obj == '.' || $obj == '..') { + continue; + } + if (!@unlink($dir.'/'.$obj)) { + SureRemoveDir($dir.'/'.$obj, true); + } } closedir($dh); if ($DeleteMe) { diff --git a/application/config/config-sample-dblib.php b/application/config/config-sample-dblib.php index 77156bb2b16..a8899db68e3 100755 --- a/application/config/config-sample-dblib.php +++ b/application/config/config-sample-dblib.php @@ -1,4 +1,6 @@ -hasGlobalPermission('templates','read')){ + if (Permission::model()->hasGlobalPermission('templates', 'read')) { $this->_renderWrappedTemplate('themeoptions', 'read', array( 'model'=>$this->loadModel($id), )); - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); $this->getController()->redirect(App()->createUrl("/admin")); } @@ -50,21 +50,21 @@ public function view($id) */ public function create() { - if ( Permission::model()->hasGlobalPermission('templates','update')){ + if (Permission::model()->hasGlobalPermission('templates', 'update')) { $model = new TemplateOptions; - if(isset($_POST['TemplateOptions'])){ - $model->attributes=$_POST['TemplateOptions']; - if($model->save()){ + if (isset($_POST['TemplateOptions'])) { + $model->attributes = $_POST['TemplateOptions']; + if ($model->save()) { $this->getController()->redirect(array('admin/themeoptions/sa/update/id/'.$model->id)); } } - $this->render('create',array( + $this->render('create', array( 'model'=>$model, )); - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); $this->getController()->redirect(array("admin/themeoptions")); } } @@ -77,20 +77,20 @@ public function create() */ public function update($id) { - if ( Permission::model()->hasGlobalPermission('templates', 'update')){ + if (Permission::model()->hasGlobalPermission('templates', 'update')) { $model = $this->loadModel($id); - if(isset($_POST['TemplateConfiguration'])){ - $model->attributes=$_POST['TemplateConfiguration']; - if($model->save()) { + if (isset($_POST['TemplateConfiguration'])) { + $model->attributes = $_POST['TemplateConfiguration']; + if ($model->save()) { Yii::app()->user->setFlash('success', gT('Theme options saved.')); $this->getController()->redirect(array('admin/themeoptions/sa/update/id/'.$model->id)); } } $this->_updateCommon($model); - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/themeoptions")); } } @@ -102,21 +102,21 @@ public function update($id) */ public function updatesurvey($sid) { - if ( Permission::model()->hasGlobalPermission('templates', 'update')){ + if (Permission::model()->hasGlobalPermission('templates', 'update')) { $model = TemplateConfiguration::getInstance(null, null, $sid); - if(isset($_POST['TemplateConfiguration'])){ - $model->attributes=$_POST['TemplateConfiguration']; - if($model->save()) { + if (isset($_POST['TemplateConfiguration'])) { + $model->attributes = $_POST['TemplateConfiguration']; + if ($model->save()) { Yii::app()->user->setFlash('success', gT('Theme options saved.')); - $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/themeoptions/sa/updatesurvey",['surveyid'=>$sid,'sid'=>$sid])); + $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/themeoptions/sa/updatesurvey", ['surveyid'=>$sid, 'sid'=>$sid])); } } $this->_updateCommon($model, $sid); - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); - $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/themeoptions/sa/updatesurvey",['surveyid'=>$sid,'sid'=>$sid])); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); + $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/themeoptions/sa/updatesurvey", ['surveyid'=>$sid, 'sid'=>$sid])); } } @@ -125,25 +125,25 @@ public function updatesurvey($sid) * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ - public function updatesurveygroup($id=null, $gsid) + public function updatesurveygroup($id = null, $gsid) { - if ( Permission::model()->hasGlobalPermission('templates', 'update')){ - $sTemplateName = $id !==null ? TemplateConfiguration::model()->findByPk($id)->template_name : null; + if (Permission::model()->hasGlobalPermission('templates', 'update')) { + $sTemplateName = $id !== null ? TemplateConfiguration::model()->findByPk($id)->template_name : null; $model = TemplateConfiguration::getInstance($sTemplateName, $gsid); - if(isset($_POST['TemplateConfiguration'])){ + if (isset($_POST['TemplateConfiguration'])) { $model = TemplateConfiguration::getInstance($_POST['TemplateConfiguration']['template_name'], $gsid); - $model->attributes=$_POST['TemplateConfiguration']; - if($model->save()) { + $model->attributes = $_POST['TemplateConfiguration']; + if ($model->save()) { Yii::app()->user->setFlash('success', gT('Theme options saved.')); - $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/",['id'=>$gsid])); + $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/", ['id'=>$gsid])); } } $this->_updateCommon($model); - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); - $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/",['id'=>$gsid])); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); + $this->getController()->redirect(Yii::app()->getController()->createUrl("/admin/surveysgroups/sa/update/", ['id'=>$gsid])); } } @@ -152,13 +152,13 @@ public function updatesurveygroup($id=null, $gsid) */ public function index() { - if ( Permission::model()->hasGlobalPermission('templates', 'read') ){ + if (Permission::model()->hasGlobalPermission('templates', 'read')) { $model = new TemplateConfiguration(); $aData = array(); $aData['model'] = $model; $this->_renderWrappedTemplate('themeoptions', 'index', $aData); - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); $this->getController()->redirect(App()->createUrl("/admin")); } } @@ -168,18 +168,18 @@ public function index() */ public function admin() { - if ( Permission::model()->hasGlobalPermission('templates','read')){ - $model=new TemplateOptions('search'); - $model->unsetAttributes(); // clear any default values - if(isset($_GET['TemplateOptions'])){ - $model->attributes=$_GET['TemplateOptions']; + if (Permission::model()->hasGlobalPermission('templates', 'read')) { + $model = new TemplateOptions('search'); + $model->unsetAttributes(); // clear any default values + if (isset($_GET['TemplateOptions'])) { + $model->attributes = $_GET['TemplateOptions']; } - $this->render('admin',array( + $this->render('admin', array( 'model'=>$model, )); - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); $this->getController()->redirect(App()->createUrl("/admin")); } } @@ -193,9 +193,9 @@ public function admin() */ public function loadModel($id) { - $model=TemplateConfiguration::model()->findByPk($id); - if($model===null){ - throw new CHttpException(404,'The requested page does not exist.'); + $model = TemplateConfiguration::model()->findByPk($id); + if ($model === null) { + throw new CHttpException(404, 'The requested page does not exist.'); } return $model; @@ -204,11 +204,11 @@ public function loadModel($id) public function importManifest($templatename) { - if ( Permission::model()->hasGlobalPermission('templates', 'update')){ + if (Permission::model()->hasGlobalPermission('templates', 'update')) { TemplateManifest::importManifest($templatename); $this->getController()->redirect(array("admin/themeoptions")); - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); $this->getController()->redirect(array("admin/themeoptions")); } @@ -216,14 +216,14 @@ public function importManifest($templatename) public function uninstall($templatename) { - if ( Permission::model()->hasGlobalPermission('templates','update')){ - if (!Template::hasInheritance($templatename)){ + if (Permission::model()->hasGlobalPermission('templates', 'update')) { + if (!Template::hasInheritance($templatename)) { TemplateConfiguration::uninstall($templatename); - }else{ + } else { Yii::app()->setFlashMessage(sprintf(gT("You can't uninstall template '%s' because some templates inherit from it."), $templatename), 'error'); } - }else{ - Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."),'error'); + } else { + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); } $this->getController()->redirect(array("admin/themeoptions")); @@ -235,7 +235,7 @@ public function uninstall($templatename) */ protected function performAjaxValidation($model) { - if(isset($_POST['ajax']) && $_POST['ajax']==='template-options-form'){ + if (isset($_POST['ajax']) && $_POST['ajax'] === 'template-options-form') { echo CActiveForm::validate($model); Yii::app()->end(); } @@ -248,7 +248,7 @@ protected function performAjaxValidation($model) * @param int $sid * @return void */ - private function _updateCommon(TemplateConfiguration $model,$sid=null) + private function _updateCommon(TemplateConfiguration $model, $sid = null) { $oModelWithInheritReplacement = TemplateConfiguration::model()->findByPk($model->id); $templateOptionPage = $oModelWithInheritReplacement->optionPage; @@ -259,7 +259,7 @@ private function _updateCommon(TemplateConfiguration $model,$sid=null) 'templateOptionPage' => $templateOptionPage ); - if($sid !== null){ + if ($sid !== null) { $aData['surveybar']['savebutton']['form'] = true; $aData['surveyid'] = $sid; $aData['title_bar']['title'] = gT("Survey template options"); diff --git a/application/core/Survey_Common_Action.php b/application/core/Survey_Common_Action.php index 70e23021934..9a324dbbba4 100644 --- a/application/core/Survey_Common_Action.php +++ b/application/core/Survey_Common_Action.php @@ -24,7 +24,7 @@ */ class Survey_Common_Action extends CAction { - public function __construct($controller=null, $id=null) + public function __construct($controller = null, $id = null) { parent::__construct($controller, $id); Yii::app()->request->updateNavigationStack(); @@ -48,8 +48,7 @@ public function runWithParams($params) if (empty($params['sa'])) { $sSubAction = $sDefault; // default - } - else + } else { $sSubAction = $params['sa']; } @@ -75,7 +74,7 @@ public function runWithParams($params) // Get the action classes from the admin controller as the urls necessarily do not equal the class names. Eg. survey -> surveyaction $aActions = Yii::app()->getController()->getActionClasses(); - if(empty($aActions[$this->getId()]) || strtolower($oMethod->getDeclaringClass()->name) != strtolower($aActions[$this->getId()]) || !$oMethod->isPublic()) + if (empty($aActions[$this->getId()]) || strtolower($oMethod->getDeclaringClass()->name) != strtolower($aActions[$this->getId()]) || !$oMethod->isPublic()) { // Either action doesn't exist in our whitelist, or the method class doesn't equal the action class or the method isn't public // So let us get the last possible default method, ie. index @@ -112,9 +111,9 @@ private function _addPseudoParams($params) 'qid' => 'iQuestionId', /* Unsure we set 'iSurveyId', 'iSurveyID','surveyid' to same final survey id */ /* priority is surveyid,surveyId,sid : surveyId=1&sid=2 set sid surveyid to 1 */ - 'sid' => array('iSurveyId', 'iSurveyID','surveyid'), // Old link use sid - 'surveyId' => array('iSurveyId', 'iSurveyID','surveyid'),// PluginHelper->sidebody : if disable surveyId usage : broke API - 'surveyid' => array('iSurveyId', 'iSurveyID','surveyid'), + 'sid' => array('iSurveyId', 'iSurveyID', 'surveyid'), // Old link use sid + 'surveyId' => array('iSurveyId', 'iSurveyID', 'surveyid'), // PluginHelper->sidebody : if disable surveyId usage : broke API + 'surveyid' => array('iSurveyId', 'iSurveyID', 'surveyid'), 'srid' => 'iSurveyResponseId', 'scid' => 'iSavedControlId', 'uid' => 'iUserId', @@ -147,40 +146,40 @@ private function _addPseudoParams($params) /* Control sid,gid and qid params validity see #12434 */ // Fill param with according existing param, replace existing parameters. // iGroupId/gid can be found with qid/iQuestionId - if(!empty($params['iQuestionId'])) { - if((string)(int)$params['iQuestionId']!==(string)$params['iQuestionId']) { // pgsql need filtering before find - throw new CHttpException(403,gT("Invalid question id")); + if (!empty($params['iQuestionId'])) { + if ((string) (int) $params['iQuestionId'] !== (string) $params['iQuestionId']) { // pgsql need filtering before find + throw new CHttpException(403, gT("Invalid question id")); } - $oQuestion=Question::model()->find("qid=:qid",array(":qid"=>$params['iQuestionId']));//Move this in model to use cache - if(!$oQuestion) { - throw new CHttpException(404,gT("Question not found")); + $oQuestion = Question::model()->find("qid=:qid", array(":qid"=>$params['iQuestionId'])); //Move this in model to use cache + if (!$oQuestion) { + throw new CHttpException(404, gT("Question not found")); } - if(!isset($params['iGroupId'])) { - $params['iGroupId']=$params['gid']=$oQuestion->gid; + if (!isset($params['iGroupId'])) { + $params['iGroupId'] = $params['gid'] = $oQuestion->gid; } } // iSurveyId/iSurveyID/sid can be found with gid/iGroupId - if(!empty($params['iGroupId'])) { - if((string)(int)$params['iGroupId']!==(string)$params['iGroupId']) { // pgsql need filtering before find - throw new CHttpException(403,gT("Invalid group id")); + if (!empty($params['iGroupId'])) { + if ((string) (int) $params['iGroupId'] !== (string) $params['iGroupId']) { // pgsql need filtering before find + throw new CHttpException(403, gT("Invalid group id")); } - $oGroup=QuestionGroup::model()->find("gid=:gid",array(":gid"=>$params['iGroupId']));//Move this in model to use cache - if(!$oGroup) { - throw new CHttpException(404,gT("Group not found")); + $oGroup = QuestionGroup::model()->find("gid=:gid", array(":gid"=>$params['iGroupId'])); //Move this in model to use cache + if (!$oGroup) { + throw new CHttpException(404, gT("Group not found")); } - if(!isset($params['iSurveyId'])) { - $params['iSurveyId']=$params['iSurveyID']=$params['surveyid']=$params['sid']=$oGroup->sid; + if (!isset($params['iSurveyId'])) { + $params['iSurveyId'] = $params['iSurveyID'] = $params['surveyid'] = $params['sid'] = $oGroup->sid; } } // Finally control validity of sid - if(!empty($params['iSurveyId'])) { - if((string)(int)$params['iSurveyId']!==(string)$params['iSurveyId']) { // pgsql need filtering before find + if (!empty($params['iSurveyId'])) { + if ((string) (int) $params['iSurveyId'] !== (string) $params['iSurveyId']) { // pgsql need filtering before find // 403 mean The request was valid, but the server is refusing action. - throw new CHttpException(403,gT("Invalid survey id")); + throw new CHttpException(403, gT("Invalid survey id")); } - $oSurvey=Survey::model()->findByPk($params['iSurveyId']); - if(!$oSurvey) { - throw new CHttpException(404,gT("Survey not found")); + $oSurvey = Survey::model()->findByPk($params['iSurveyId']); + if (!$oSurvey) { + throw new CHttpException(404, gT("Survey not found")); } // Minimal permission needed, extra permission must be tested in each controller if (!Permission::model()->hasSurveyPermission($params['iSurveyId'], 'survey', 'read')) { @@ -188,16 +187,16 @@ private function _addPseudoParams($params) // 401 semantically means "unauthenticated" throw new CHttpException(403); } - $params['iSurveyId']=$params['iSurveyID']=$params['surveyid']=$params['sid']=$oSurvey->sid; + $params['iSurveyId'] = $params['iSurveyID'] = $params['surveyid'] = $params['sid'] = $oSurvey->sid; } // Finally return the populated array return $params; } /** - * Action classes require them to have a run method. We reroute it to index - * if called. - */ + * Action classes require them to have a run method. We reroute it to index + * if called. + */ public function run() { $this->index(); @@ -214,30 +213,31 @@ public function run() protected function route($sa, array $get_vars) { $func_args = array(); - foreach ($get_vars as $k => $var) - $func_args[$k] = Yii::app()->request->getQuery($var); + foreach ($get_vars as $k => $var) { + $func_args[$k] = Yii::app()->request->getQuery($var); + } return call_user_func_array(array($this, $sa), $func_args); } /** - * Renders template(s) wrapped in header and footer - * - * Addition of parameters should be avoided if they can be added to $aData - * - * NOTE FROM LOUIS : We want to remove this function, wich doesn't respect MVC pattern. - * The work it's doing should be handle by layout files, and subviews inside views. - * Eg : for route "admin/survey/sa/listquestiongroups/surveyid/282267" - * the Group controller should use a main layout (with admin menu bar as a widget), then render the list view, in wich the question group bar is called as a subview. - * - * So for now, we try to evacuate all the renderWrappedTemplate logic (if statements, etc.) to subfunctions, then it will be easier to remove. - * Comments starting with //// indicate how it should work in the future - * - * @param string $sAction Current action, the folder to fetch views from - * @param string|array $aViewUrls View url(s) - * @param array $aData Data to be passed on. Optional. - */ + * Renders template(s) wrapped in header and footer + * + * Addition of parameters should be avoided if they can be added to $aData + * + * NOTE FROM LOUIS : We want to remove this function, wich doesn't respect MVC pattern. + * The work it's doing should be handle by layout files, and subviews inside views. + * Eg : for route "admin/survey/sa/listquestiongroups/surveyid/282267" + * the Group controller should use a main layout (with admin menu bar as a widget), then render the list view, in wich the question group bar is called as a subview. + * + * So for now, we try to evacuate all the renderWrappedTemplate logic (if statements, etc.) to subfunctions, then it will be easier to remove. + * Comments starting with //// indicate how it should work in the future + * + * @param string $sAction Current action, the folder to fetch views from + * @param string|array $aViewUrls View url(s) + * @param array $aData Data to be passed on. Optional. + */ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $aData = array()) { // Gather the data @@ -245,8 +245,9 @@ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $ //// This will be handle by subviews inclusions $aViewUrls = (array) $aViewUrls; $sViewPath = '/admin/'; - if (!empty($sAction)) - $sViewPath .= $sAction . '/'; + if (!empty($sAction)) { + $sViewPath .= $sAction . '/'; + } ob_start(); //// That was used before the MVC pattern, in procedural code. Will not be used anymore. @@ -265,7 +266,7 @@ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $ // Needed to evaluate EM expressions in question summary // See bug #11845 - LimeExpressionManager::StartProcessingPage(false,true); + LimeExpressionManager::StartProcessingPage(false, true); $aData['debug'] = $aData; $this->_titlebar($aData); //// TODO : Move this div inside each correct view ASAP ! @@ -293,8 +294,7 @@ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $ $this->_listquestions($aData); $this->_nsurveysummary($aData); - } - else + } else { /// $this->_fullpagebar($aData); @@ -318,8 +318,7 @@ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $ if (is_numeric($sViewKey)) { Yii::app()->getController()->renderPartial($sViewPath . $viewUrl, $aData); - } - elseif (is_array($viewUrl)) + } elseif (is_array($viewUrl)) { foreach ($viewUrl as $aSubData) { @@ -327,8 +326,7 @@ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $ Yii::app()->getController()->renderPartial($sViewPath . $sViewKey, $aSubData); } } - } - else + } else { switch ($sViewKey) { @@ -338,8 +336,7 @@ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $ if (empty($viewUrl['class'])) { Yii::app()->getController()->_showMessageBox($viewUrl['title'], $viewUrl['message']); - } - else + } else { Yii::app()->getController()->_showMessageBox($viewUrl['title'], $viewUrl['message'], $viewUrl['class']); } @@ -351,8 +348,9 @@ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $ echo $viewUrl; - if(isset($aViewUrls['afteroutput'])) - echo $aViewUrls['afteroutput']; + if(isset($aViewUrls['afteroutput'])) { + echo $aViewUrls['afteroutput']; + } break; } @@ -373,15 +371,16 @@ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $ //// THe footer will be called directly from the layout. // Footer - if(!isset($aData['display']['endscripts']) || $aData['display']['endscripts'] !== false) - Yii::app()->getController()->_loadEndScripts(); + if(!isset($aData['display']['endscripts']) || $aData['display']['endscripts'] !== false) { + Yii::app()->getController()->_loadEndScripts(); + } if( !Yii::app()->user->isGuest ) { - if(!isset($aData['display']['footer']) || $aData['display']['footer'] !== false) - Yii::app()->getController()->_getAdminFooter('http://manual.limesurvey.org', gT('LimeSurvey online manual')); - } - else{ + if(!isset($aData['display']['footer']) || $aData['display']['footer'] !== false) { + Yii::app()->getController()->_getAdminFooter('http://manual.limesurvey.org', gT('LimeSurvey online manual')); + } + } else{ echo ''; } @@ -482,7 +481,7 @@ function _nsurveysummary($aData) */ function _showHeaders($aData) { - if(!isset($aData['display']['header']) || $aData['display']['header'] !== false) + if (!isset($aData['display']['header']) || $aData['display']['header'] !== false) { // Send HTTP header header("Content-type: text/html; charset=UTF-8"); // needed for correct UTF-8 encoding @@ -507,7 +506,7 @@ function _showHeaders($aData) public function _showadminmenu($aData) { // We don't wont the admin menu to be shown in login page - if( !Yii::app()->user->isGuest ) + if (!Yii::app()->user->isGuest) { // Default password notification if (Yii::app()->session['pw_notify'] && Yii::app()->getConfig("debug") < 2) @@ -516,7 +515,7 @@ public function _showadminmenu($aData) 'user_id' => App()->user->id, 'importance' => Notification::HIGH_IMPORTANCE, 'title' => 'Password warning', - 'message' => ' ' . + 'message' => ' '. gT("Warning: You are still using the default password ('password'). Please change your password and re-login again.") )); $not->save(); @@ -532,11 +531,10 @@ public function _showadminmenu($aData) $aData['dataForConfigMenu']['userscount'] = User::model()->count(); //Check if have a comfortUpdate key - if(getGlobalSetting('emailsmtpdebug')!=null) + if (getGlobalSetting('emailsmtpdebug') != null) { $aData['dataForConfigMenu']['comfortUpdateKey'] = gT('Activated'); - } - else + } else { $aData['dataForConfigMenu']['comfortUpdateKey'] = gT('None'); } @@ -545,7 +543,7 @@ public function _showadminmenu($aData) $updateModel = new UpdateForm(); $updateNotification = $updateModel->updateNotification; - $aData['showupdate'] = Yii::app()->getConfig('updatable') && $updateNotification->result && ! $updateNotification->unstable_update ; + $aData['showupdate'] = Yii::app()->getConfig('updatable') && $updateNotification->result && !$updateNotification->unstable_update; // Fetch extra menus from plugins, e.g. last visited surveys $aData['extraMenus'] = $this->fetchExtraMenus($aData); @@ -562,19 +560,19 @@ public function _showadminmenu($aData) function _titlebar($aData) { - if( isset($aData['title_bar']) ) { + if (isset($aData['title_bar'])) { $this->getController()->renderPartial("/admin/super/title_bar", $aData); } } function _tokenbar($aData) { - if( isset($aData['token_bar']) ) { + if (isset($aData['token_bar'])) { - if(isset($aData['token_bar']['closebutton']['url'])) + if (isset($aData['token_bar']['closebutton']['url'])) { $sAlternativeUrl = $aData['token_bar']['closebutton']['url']; - $aData['token_bar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer( Yii::app()->createUrl($sAlternativeUrl) ); + $aData['token_bar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl($sAlternativeUrl)); } $this->getController()->renderPartial("/admin/token/token_bar", $aData); @@ -593,10 +591,10 @@ function _organizequestionbar($aData) { if (isset($aData['organizebar'])) { - if(isset($aData['questionbar']['closebutton']['url'])) + if (isset($aData['questionbar']['closebutton']['url'])) { $sAlternativeUrl = $aData['questionbar']['closebutton']['url']; - $aData['questionbar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer( Yii::app()->createUrl($sAlternativeUrl) ); + $aData['questionbar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl($sAlternativeUrl)); } $aData['questionbar'] = $aData['organizebar']; @@ -605,13 +603,13 @@ function _organizequestionbar($aData) } /** - * Shows admin menu for question - * - * @param array $aData - */ + * Shows admin menu for question + * + * @param array $aData + */ public function _questionbar($aData) { - if(isset($aData['questionbar'])) { + if (isset($aData['questionbar'])) { if (is_object($aData['oSurvey'])) { $iSurveyID = $aData['surveyid']; @@ -632,7 +630,9 @@ public function _questionbar($aData) $aData['sqct'] = Question::model()->countByAttributes(array('parent_qid' => $qid, 'language' => $baselang)); $qrrow = Question::model()->findByAttributes(array('qid' => $qid, 'gid' => $gid, 'sid' => $iSurveyID, 'language' => $baselang)); - if (is_null($qrrow)) return; + if (is_null($qrrow)) { + return; + } $questionsummary = ""; // Check if other questions in the Survey are dependent upon this question @@ -640,7 +640,7 @@ public function _questionbar($aData) // $surveyinfo = $oSurvey->attributes; // $surveyinfo = array_map('flattenText', $surveyinfo); - $aData['activated'] = $oSurvey->active; + $aData['activated'] = $oSurvey->active; $qrrow = $qrrow->attributes; $aData['languagelist'] = $oSurvey->getAllLanguages(); @@ -662,8 +662,9 @@ public function _questionbar($aData) { if ($aAttribute['inputtype'] == 'singleselect') { - if(isset($aAttribute['options'][$aAttribute['value']])) - $aAttribute['value'] = $aAttribute['options'][$aAttribute['value']]; + if(isset($aAttribute['options'][$aAttribute['value']])) { + $aAttribute['value'] = $aAttribute['options'][$aAttribute['value']]; + } } $DisplayArray[] = $aAttribute; } @@ -671,16 +672,15 @@ public function _questionbar($aData) $aData['advancedsettings'] = $DisplayArray; $aData['condarray'] = $condarray; - if(isset($aData['questionbar']['closebutton']['url'])) + if (isset($aData['questionbar']['closebutton']['url'])) { $sAlternativeUrl = $aData['questionbar']['closebutton']['url']; - $aData['questionbar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer( Yii::app()->createUrl($sAlternativeUrl) ); + $aData['questionbar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl($sAlternativeUrl)); } $questionsummary .= $this->getController()->renderPartial('/admin/survey/Question/questionbar_view', $aData, true); $finaldata['display'] = $questionsummary; $this->getController()->renderPartial('/survey_view', $finaldata); - } - else + } else { Yii::app()->session['flashmessage'] = gT("Invalid survey ID"); $this->getController()->redirect(array("admin/index")); @@ -695,13 +695,13 @@ public function _questionbar($aData) */ function _nquestiongroupbar($aData) { - if(isset($aData['questiongroupbar'])) + if (isset($aData['questiongroupbar'])) { - if(!isset($aData['gid'])) + if (!isset($aData['gid'])) { - if(isset($_GET['gid'])) + if (isset($_GET['gid'])) { - $aData['gid'] = $_GET['gid']; + $aData['gid'] = $_GET['gid']; } } @@ -710,7 +710,7 @@ function _nquestiongroupbar($aData) $surveyid = $aData['surveyid']; $gid = $aData['gid']; $oSurvey = $aData['oSurvey']; - $baselang =$oSurvey->language; + $baselang = $oSurvey->language; $aData['sumcount4'] = Question::model()->countByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $baselang)); @@ -728,7 +728,7 @@ function _nquestiongroupbar($aData) $aData['languagelist'] = $oSurvey->getAllLanguages(); - if(isset($aData['questiongroupbar']['closebutton']['url'])) + if (isset($aData['questiongroupbar']['closebutton']['url'])) { $sAlternativeUrl = $aData['questiongroupbar']['closebutton']['url']; $aData['questiongroupbar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl($sAlternativeUrl)); @@ -740,12 +740,12 @@ function _nquestiongroupbar($aData) function _fullpagebar($aData) { - if((isset($aData['fullpagebar']))) + if ((isset($aData['fullpagebar']))) { - if(isset($aData['fullpagebar']['closebutton']['url']) && !isset($aData['fullpagebar']['closebutton']['url_keep'])) + if (isset($aData['fullpagebar']['closebutton']['url']) && !isset($aData['fullpagebar']['closebutton']['url_keep'])) { - $sAlternativeUrl = '/admin/index'; - $aData['fullpagebar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer( Yii::app()->createUrl($sAlternativeUrl)); + $sAlternativeUrl = '/admin/index'; + $aData['fullpagebar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl($sAlternativeUrl)); } $this->getController()->renderPartial("/admin/super/fullpagebar_view", $aData); } @@ -757,12 +757,12 @@ function _fullpagebar($aData) */ function _surveybar($aData) { - if((isset($aData['surveybar']))) + if ((isset($aData['surveybar']))) { $iSurveyID = $aData['surveyid']; /** @var Survey $oSurvey */ $oSurvey = $aData['oSurvey']; - $gid = isset($aData['gid'])?$aData['gid']:null; + $gid = isset($aData['gid']) ? $aData['gid'] : null; $aData['baselang'] = $oSurvey->language; App()->getClientScript()->registerPackage('js-cookie'); @@ -787,7 +787,7 @@ function _surveybar($aData) $aData['icontext'] = gT("Execute survey"); } - $aData['onelanguage']=(count($oSurvey->allLanguages)==1); + $aData['onelanguage'] = (count($oSurvey->allLanguages) == 1); $aData['hasadditionallanguages'] = (count($oSurvey->additionalLanguages) > 0); // EDIT SURVEY TEXT ELEMENTS BUTTON @@ -817,7 +817,7 @@ function _surveybar($aData) // Only show survey properties menu if at least one item is permitted $aData['showSurveyPropertiesMenu'] = - $aData['surveylocale'] + $aData['surveylocale'] || $aData['surveysettings'] || $aData['surveysecurity'] || $aData['surveycontentread'] @@ -840,7 +840,7 @@ function _surveybar($aData) // Only show tools menu if at least one item is permitted $aData['showToolsMenu'] = - $aData['surveydelete'] + $aData['surveydelete'] || $aData['surveytranslate'] || Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update') || !is_null($extraToolsMenuItems); @@ -864,8 +864,7 @@ function _surveybar($aData) if (!$oSurvey->hasTokensTable) { $aData['tokenmanagement'] = Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'create'); - } - else { + } else { $aData['tokenmanagement'] = Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'create') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read') @@ -886,7 +885,7 @@ function _surveybar($aData) if (getGroupListLang($gid, $oSurvey->language, $iSurveyID)) { $aData['groups'] = getGroupListLang($gid, $oSurvey->language, $iSurveyID); } else { - $aData['groups'] = ""; + $aData['groups'] = ""; } $aData['GidPrev'] = $GidPrev = getGidPrevious($iSurveyID, $gid); @@ -899,8 +898,9 @@ function _surveybar($aData) $aData['surveybar']['closebutton']['url'] = Yii::app()->request->getUrlReferrer( Yii::app()->createUrl($sAlternativeUrl)); } - if($aData['gid']==null) - $this->getController()->renderPartial("/admin/survey/surveybar_view", $aData); + if($aData['gid']==null) { + $this->getController()->renderPartial("/admin/survey/surveybar_view", $aData); + } } } @@ -913,7 +913,7 @@ function _surveysidemenu($aData) { $iSurveyID = $aData['surveyid']; - $survey=Survey::model()->findByPk($iSurveyID); + $survey = Survey::model()->findByPk($iSurveyID); // TODO : create subfunctions $sumresult1 = Survey::model()->with(array( 'languagesettings' => array('condition'=>'surveyls_language=language')) @@ -922,8 +922,7 @@ function _surveysidemenu($aData) if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'read')) { $aData['permission'] = true; - } - else + } else { $aData['gid'] = $gid = null; $qid = null; @@ -941,8 +940,7 @@ function _surveysidemenu($aData) if (!$bTokenExists) { $aData['tokenmanagement'] = Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'create'); - } - else { + } else { $aData['tokenmanagement'] = Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'create') || Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read') @@ -951,18 +949,18 @@ function _surveysidemenu($aData) } // Question explorer - $aGroups = QuestionGroup::model()->findAllByAttributes(array('sid' => $iSurveyID, "language" => $sumresult1->defaultlanguage->surveyls_language),array('order'=>'group_order ASC')); - if(count($aGroups)) + $aGroups = QuestionGroup::model()->findAllByAttributes(array('sid' => $iSurveyID, "language" => $sumresult1->defaultlanguage->surveyls_language), array('order'=>'group_order ASC')); + if (count($aGroups)) { - foreach($aGroups as $group) + foreach ($aGroups as $group) { - $group->aQuestions = Question::model()->findAllByAttributes(array("sid"=>$iSurveyID, "gid"=>$group['gid'],"language"=>$sumresult1->defaultlanguage->surveyls_language), array('order'=>'question_order ASC')); + $group->aQuestions = Question::model()->findAllByAttributes(array("sid"=>$iSurveyID, "gid"=>$group['gid'], "language"=>$sumresult1->defaultlanguage->surveyls_language), array('order'=>'question_order ASC')); - foreach($group->aQuestions as $question) + foreach ($group->aQuestions as $question) { - if(is_object($question)) + if (is_object($question)) { - $question->question = viewHelper::flatEllipsizeText($question->question,true,60,'[...]',0.5); + $question->question = viewHelper::flatEllipsizeText($question->question, true, 60, '[...]', 0.5); } } } @@ -975,8 +973,7 @@ function _surveysidemenu($aData) $aData['surveycontentupdate'] = Permission::model()->hasSurveyPermission($aData['surveyid'], 'surveycontent', 'update'); $aData['sideMenuBehaviour'] = getGlobalSetting('sideMenuBehaviour'); $this->getController()->renderPartial("/admin/super/sidemenu", $aData); - } - else + } else { Yii::app()->session['flashmessage'] = gT("Invalid survey ID"); $this->getController()->redirect(array("admin/index")); @@ -1040,7 +1037,7 @@ protected function beforeSideMenuRender(array $aData) */ private function _listquestiongroups(array $aData) { - if ( isset($aData['display']['menu_bars']['listquestiongroups']) ) + if (isset($aData['display']['menu_bars']['listquestiongroups'])) { $this->getController()->renderPartial("/admin/survey/QuestionGroups/listquestiongroups", $aData); } @@ -1048,7 +1045,7 @@ private function _listquestiongroups(array $aData) private function _listquestions($aData) { - if ( isset($aData['display']['menu_bars']['listquestions']) ) + if (isset($aData['display']['menu_bars']['listquestions'])) { $iSurveyID = $aData['surveyid']; $oSurvey = $aData['oSurvey']; @@ -1058,16 +1055,19 @@ private function _listquestions($aData) $model = new Question('search'); // Global filter - if (isset($_GET['Question'])) - $model->attributes = $_GET['Question']; + if (isset($_GET['Question'])) { + $model->attributes = $_GET['Question']; + } // Filter group - if (isset($_GET['gid'])) - $model->gid = $_GET['gid']; + if (isset($_GET['gid'])) { + $model->gid = $_GET['gid']; + } // Set number of page - if (isset($_GET['pageSize'])) - Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']); + if (isset($_GET['pageSize'])) { + Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']); + } // We filter the current survey id $model->sid = $iSurveyID; @@ -1080,14 +1080,14 @@ private function _listquestions($aData) } /** - * Show survey summary + * Show survey summary * @param array $aData - */ + */ public function _surveysummary($aData) { $iSurveyID = $aData['surveyid']; - $aSurveyInfo=getSurveyInfo($iSurveyID); + $aSurveyInfo = getSurveyInfo($iSurveyID); /** @var Survey $oSurvey */ $oSurvey = $aData['oSurvey']; $baselang = $aSurveyInfo['language']; @@ -1105,20 +1105,17 @@ public function _surveysummary($aData) if ($aSurveyInfo['anonymized'] != "N") { $surveysummary2 .= gT("Responses to this survey are anonymized.") . "
"; - } - else + } else { $surveysummary2 .= gT("Responses to this survey are NOT anonymized.") . "
"; } if ($aSurveyInfo['format'] == "S") { $surveysummary2 .= gT("It is presented question by question.") . "
"; - } - elseif ($aSurveyInfo['format'] == "G") + } elseif ($aSurveyInfo['format'] == "G") { $surveysummary2 .= gT("It is presented group by group.") . "
"; - } - else + } else { $surveysummary2 .= gT("It is presented on one single page.") . "
"; } @@ -1127,12 +1124,10 @@ public function _surveysummary($aData) if ($aSurveyInfo['format'] == 'A') { $surveysummary2 .= gT("No question index will be shown with this format.") . "
"; - } - elseif ($aSurveyInfo['questionindex'] == 1) + } elseif ($aSurveyInfo['questionindex'] == 1) { $surveysummary2 .= gT("A question index will be shown; participants will be able to jump between viewed questions.") . "
"; - } - elseif ($aSurveyInfo['questionindex'] == 2) + } elseif ($aSurveyInfo['questionindex'] == 2) { $surveysummary2 .= gT("A full question index will be shown; participants will be able to jump between relevant questions.") . "
"; } @@ -1167,8 +1162,7 @@ public function _surveysummary($aData) Yii::import('application.libraries.Date_Time_Converter'); $datetimeobj = new Date_Time_Converter($oSurvey->startdate, 'Y-m-d H:i:s'); $aData['startdate'] = $datetimeobj->convert($dateformatdetails['phpdate'] . ' H:i'); - } - else + } else { $aData['startdate'] = "-"; } @@ -1179,8 +1173,7 @@ public function _surveysummary($aData) $datetimeobj = new Date_Time_Converter($oSurvey->expires, 'Y-m-d H:i:s'); //$datetimeobj = new Date_Time_Converter($surveyinfo['expires'] , "Y-m-d H:i:s"); $aData['expdate'] = $datetimeobj->convert($dateformatdetails['phpdate'] . ' H:i'); - } - else + } else { $aData['expdate'] = "-"; } @@ -1192,7 +1185,7 @@ public function _surveysummary($aData) } if ($oSurvey->currentLanguageSettings->surveyls_url != "") { - $aData['endurl'] = " ".flattenText($oSurvey->currentLanguageSettings->surveyls_url).""; + $aData['endurl'] = " ".flattenText($oSurvey->currentLanguageSettings->surveyls_url).""; } else { $aData['endurl'] = "-"; } @@ -1208,17 +1201,17 @@ public function _surveysummary($aData) $aData['activated'] = $activated; if ($oSurvey->isActive) { - $aData['surveydb'] = Yii::app()->db->tablePrefix . "survey_" . $iSurveyID; + $aData['surveydb'] = Yii::app()->db->tablePrefix."survey_".$iSurveyID; } $aData['warnings'] = ""; if ($activated == "N" && $sumcount3 == 0) { - $aData['warnings'] = gT("Survey cannot be activated yet.") . "
\n"; + $aData['warnings'] = gT("Survey cannot be activated yet.")."
\n"; if ($sumcount2 == 0 && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'create')) { - $aData['warnings'] .= "[" . gT("You need to add question groups") . "]
"; + $aData['warnings'] .= "[".gT("You need to add question groups")."]
"; } if ($sumcount3 == 0 && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'create')) { - $aData['warnings'] .= "[" . gT("You need to add questions") . "]
"; + $aData['warnings'] .= "[".gT("You need to add questions")."]
"; } } $aData['hints'] = $surveysummary2; @@ -1253,7 +1246,7 @@ public function _browsemenubar(array $aData) if (!empty($aData['display']['menu_bars']['browse']) && !empty($aData['surveyid'])) { //BROWSE MENU BAR - $iSurveyID=$aData['surveyid']; + $iSurveyID = $aData['surveyid']; $oSurvey = $aData['oSurvey']; $aData['title'] = $aData['display']['menu_bars']['browse']; $aData['thissurvey'] = getSurveyInfo($iSurveyID); @@ -1265,9 +1258,9 @@ public function _browsemenubar(array $aData) rsort($tmp_survlangs); $aData['tmp_survlangs'] = $tmp_survlangs; - if(!isset($aData['menu']['closeurl'])) + if (!isset($aData['menu']['closeurl'])) { - $aData['menu']['closeurl'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl("/admin/responses/sa/browse/surveyid/".$aData['surveyid']) ); + $aData['menu']['closeurl'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl("/admin/responses/sa/browse/surveyid/".$aData['surveyid'])); } $this->getController()->renderPartial("/admin/responses/browsemenubar_view", $aData); @@ -1281,7 +1274,7 @@ public function _browsemenubar(array $aData) */ public function _userGroupBar(array $aData) { - $ugid = (isset($aData['ugid'])) ? $aData['ugid'] : 0 ; + $ugid = (isset($aData['ugid'])) ? $aData['ugid'] : 0; if (!empty($aData['display']['menu_bars']['user_group'])) { $data = $aData; Yii::app()->loadHelper('database'); @@ -1291,7 +1284,7 @@ public function _userGroupBar(array $aData) $uid = Yii::app()->session['loginID']; if($userGroup && $userGroup->hasUser($uid)){ $data['userGroup'] = $userGroup; - }else{ + } else{ $data['userGroup'] = null; } } @@ -1317,11 +1310,13 @@ protected function _filterImportedResources($extractdir, $destdir) $aErrorFilesInfo = array(); $aImportedFilesInfo = array(); - if (!is_dir($extractdir)) - return array(array(), array()); + if (!is_dir($extractdir)) { + return array(array(), array()); + } - if (!is_dir($destdir)) - mkdir($destdir); + if (!is_dir($destdir)) { + mkdir($destdir); + } $dh = opendir($extractdir); @@ -1329,29 +1324,27 @@ protected function _filterImportedResources($extractdir, $destdir) { if ($direntry != "." && $direntry != "..") { - if (is_file($extractdir . "/" . $direntry)) + if (is_file($extractdir."/".$direntry)) { // is a file $extfile = substr(strrchr($direntry, '.'), 1); - if (!(stripos(',' . Yii::app()->getConfig('allowedresourcesuploads') . ',', ',' . $extfile . ',') === false)) + if (!(stripos(','.Yii::app()->getConfig('allowedresourcesuploads').',', ','.$extfile.',') === false)) { // Extension allowed - if (!copy($extractdir . "/" . $direntry, $destdir . "/" . $direntry)) + if (!copy($extractdir."/".$direntry, $destdir."/".$direntry)) { $aErrorFilesInfo[] = Array( "filename" => $direntry, "status" => gT("Copy failed") ); - } - else + } else { $aImportedFilesInfo[] = Array( "filename" => $direntry, "status" => gT("OK") ); } - } - else + } else { // Extension forbidden $aErrorFilesInfo[] = Array( @@ -1359,7 +1352,7 @@ protected function _filterImportedResources($extractdir, $destdir) "status" => gT("Forbidden Extension") ); } - unlink($extractdir . "/" . $direntry); + unlink($extractdir."/".$direntry); } } } @@ -1369,18 +1362,19 @@ protected function _filterImportedResources($extractdir, $destdir) /** - * Creates a temporary directory - * - * @access protected - * @param string $dir - * @param string $prefix - * @param int $mode - * @return string - */ + * Creates a temporary directory + * + * @access protected + * @param string $dir + * @param string $prefix + * @param int $mode + * @return string + */ protected function _tempdir($dir, $prefix='', $mode=0700) { - if (substr($dir, -1) != DIRECTORY_SEPARATOR) - $dir .= DIRECTORY_SEPARATOR; + if (substr($dir, -1) != DIRECTORY_SEPARATOR) { + $dir .= DIRECTORY_SEPARATOR; + } do { diff --git a/application/core/plugins/extendedStartPage/views/publicSurveyList_extended.php b/application/core/plugins/extendedStartPage/views/publicSurveyList_extended.php index a59163d745e..520e23a2b45 100644 --- a/application/core/plugins/extendedStartPage/views/publicSurveyList_extended.php +++ b/application/core/plugins/extendedStartPage/views/publicSurveyList_extended.php @@ -24,8 +24,7 @@ ); $statistics .= ""; $list .= "
"; - } - else + } else { $statistics = ""; $list .= "
"; diff --git a/application/helpers/admin/ajax_helper.php b/application/helpers/admin/ajax_helper.php index 73bb968a5c2..05fb443c623 100644 --- a/application/helpers/admin/ajax_helper.php +++ b/application/helpers/admin/ajax_helper.php @@ -289,8 +289,7 @@ public function __construct() // This should not be possible here if (isset($result[0]) && $result[0] == 'success') { throw new \CException('Internal error: login form submitted'); - } - else if (isset($result[0]) && $result[0] == 'failed') { + } else if (isset($result[0]) && $result[0] == 'failed') { throw new \CException('Internal error: login form submitted'); } diff --git a/application/helpers/admin/export/DocWriter.php b/application/helpers/admin/export/DocWriter.php index 16313012074..72bd81d226a 100644 --- a/application/helpers/admin/export/DocWriter.php +++ b/application/helpers/admin/export/DocWriter.php @@ -59,15 +59,13 @@ protected function outputRecord($headers, $values, FormattingOptions $oOptions) { //No headers at all, only output values. $this->output .= implode($this->separator, $values).PHP_EOL; - } - elseif ($oOptions->answerFormat == 'long') + } elseif ($oOptions->answerFormat == 'long') { //Output each record, one per page, with a header preceding every value. if ($this->isBeginning) { $this->isBeginning = false; - } - else + } else { $this->output .= "
"; } @@ -86,8 +84,7 @@ protected function outputRecord($headers, $values, FormattingOptions $oOptions) $counter++; } $this->output .= "".PHP_EOL; - } - else + } else { safeDie('An invalid answer format was selected. Only \'short\' and \'long\' are valid.'); } diff --git a/application/helpers/admin/export/HtmlWriter.php b/application/helpers/admin/export/HtmlWriter.php index 5eaac4e2bf5..419a1907c62 100644 --- a/application/helpers/admin/export/HtmlWriter.php +++ b/application/helpers/admin/export/HtmlWriter.php @@ -148,8 +148,7 @@ protected function closeTag() { $this->out(CHtml::closeTag(array_pop($this->stack))); return true; - } - else + } else { return false; } diff --git a/application/helpers/admin/export/JsonWriter.php b/application/helpers/admin/export/JsonWriter.php index e025e1a2ab4..449bdaca763 100644 --- a/application/helpers/admin/export/JsonWriter.php +++ b/application/helpers/admin/export/JsonWriter.php @@ -58,8 +58,7 @@ public function close() if (!$this->file) { echo $sEndOutput; - } - else + } else { $this->output .= $sEndOutput; fwrite($this->file, $this->output); diff --git a/application/helpers/admin/export/PdfWriter.php b/application/helpers/admin/export/PdfWriter.php index b5fac544f77..61fed4da218 100644 --- a/application/helpers/admin/export/PdfWriter.php +++ b/application/helpers/admin/export/PdfWriter.php @@ -48,8 +48,7 @@ public function outputRecord($headers, $values, FormattingOptions $oOptions) $pdfstring .= $value.' | '; } $this->pdf->intopdf($pdfstring); - } - elseif ($oOptions->answerFormat == 'long') + } elseif ($oOptions->answerFormat == 'long') { if ($this->rowCounter != 1) { @@ -70,8 +69,7 @@ public function outputRecord($headers, $values, FormattingOptions $oOptions) } } } - } - else + } else { safeDie('An invalid answer format was encountered: '.$oOptions->answerFormat); } @@ -84,8 +82,7 @@ public function close() { //Save to file on filesystem. $filename = $this->filename; - } - else + } else { //Presuming this else branch is a send to client via HTTP. $filename = $this->translate($this->surveyName, $this->languageCode).'.pdf'; diff --git a/application/helpers/admin/export/Translator.php b/application/helpers/admin/export/Translator.php index 287015f12f0..93842c75d6f 100644 --- a/application/helpers/admin/export/Translator.php +++ b/application/helpers/admin/export/Translator.php @@ -20,8 +20,7 @@ public function getHeaderTranslationKey($column) if (isset($this->headerTranslationKeys[$column])) { return $this->headerTranslationKeys[$column]; - } - else + } else { return false; } diff --git a/application/helpers/database_helper.php b/application/helpers/database_helper.php index b100bd5812d..87d7932221b 100644 --- a/application/helpers/database_helper.php +++ b/application/helpers/database_helper.php @@ -1,5 +1,7 @@ db->createCommand($sql)->bindValues($inputarr)->query(); //Checked - } - else + } else { $dataset = Yii::app()->db->createCommand($sql)->query(); @@ -81,8 +82,7 @@ function dbSelectLimitAssoc($sql, $numrows = 0, $offset = 0, $inputarr = false, } try { $dataset = $query->query(); - } - catch (CDbException $e) { + } catch (CDbException $e) { $dataset = false; } if (!$dataset && $dieonerror) { diff --git a/application/helpers/expressions/em_core_helper.php b/application/helpers/expressions/em_core_helper.php index feb9673449b..fcf0d1a95f8 100644 --- a/application/helpers/expressions/em_core_helper.php +++ b/application/helpers/expressions/em_core_helper.php @@ -2079,7 +2079,7 @@ private function RDP_RunFunction($funcNameToken, $params) break; case 1: if (!$this->RDP_onlyparse) { - switch($funcName) { + switch ($funcName) { case 'acos': case 'asin': case 'atan': @@ -2106,11 +2106,11 @@ private function RDP_RunFunction($funcNameToken, $params) break; case 2: if (!$this->RDP_onlyparse) { - switch($funcName) { + switch ($funcName) { case 'atan2': if (is_numeric($params[0]) && is_numeric($params[1])) { - $result = $funcName(floatval($params[0]),floatval($params[1])); + $result = $funcName(floatval($params[0]), floatval($params[1])); } else { diff --git a/application/helpers/globals.php b/application/helpers/globals.php index 419f04edf68..bb374a80654 100644 --- a/application/helpers/globals.php +++ b/application/helpers/globals.php @@ -1,4 +1,6 @@ -unsubscribe($plugin, $event); } - } - elseif (isset($this->subscriptions[$event])) + } elseif (isset($this->subscriptions[$event])) { foreach ($this->subscriptions[$event] as $index => $subscription) { @@ -299,8 +297,7 @@ public function loadPlugin($pluginName, $id = null) return $plugin; } } - } - else + } else { if ((!isset($this->plugins[$id]) || get_class($this->plugins[$id]) !== $pluginName)) { @@ -342,8 +339,7 @@ public function loadPlugins() { $this->loadPlugin($record->name, $record->id); } - } - else + } else { // Log it ? tracevar ? } diff --git a/application/libraries/PluginManager/Question/QuestionBase.php b/application/libraries/PluginManager/Question/QuestionBase.php index 02e92b27220..2c796588e00 100644 --- a/application/libraries/PluginManager/Question/QuestionBase.php +++ b/application/libraries/PluginManager/Question/QuestionBase.php @@ -145,8 +145,7 @@ protected function get($key = null, $default = null, $language = null, $question { $questionId = $this->questionId; return $this->plugin->getStore()->get($this->plugin, $key, 'Question', $questionId, $default, $language); - } - else + } else { return false; } @@ -178,8 +177,7 @@ public function getAttributes($languages = null) { $metaData['current'][$language] = $this->get($name, null, $language); } - } - else + } else { $metaData['current'] = $this->get($name, null, $languages); } @@ -285,8 +283,7 @@ public function saveAttributes(array $attributeValues, $qid = null) $result = false; } } - } - else + } else { if (!$this->set($key, $value, $qid)) { @@ -314,8 +311,7 @@ protected function set($key, $value, $language = null, $questionId = null) { $questionId = $this->questionId; return $this->plugin->getStore()->set($this->plugin, $key, $value, 'Question', $questionId, $language); - } - else + } else { return false; } diff --git a/application/libraries/PluginManager/Storage/DbStorage.php b/application/libraries/PluginManager/Storage/DbStorage.php index 06d8783c892..c93a452900d 100644 --- a/application/libraries/PluginManager/Storage/DbStorage.php +++ b/application/libraries/PluginManager/Storage/DbStorage.php @@ -24,8 +24,7 @@ public function get(iPlugin $plugin, $key = null, $model = null, $id = null, $de if ($model == null || !method_exists($this, $functionName)) { return $this->getGeneric($plugin, $key, $model, $id, $default); - } - else + } else { return $this->$functionName($plugin, $key, $model, $id, $default, $language); } @@ -59,12 +58,10 @@ protected function getGeneric(iPlugin $plugin, $key, $model, $id, $default) { $result[] = json_decode($record->value, true); } - } - elseif (count($records) == 1) + } elseif (count($records) == 1) { $result = json_decode($records[0]->value, true); - } - else + } else { $result = $default; } @@ -99,8 +96,7 @@ protected function getQuestion(iPlugin $plugin, $key, $model, $id, $default, $la if (in_array($key, $baseAttributes)) { $result = $this->getQuestionBase($id, $key, $default); - } - else + } else { $attributes = array('qid' => $id); // If * is passed we retrieve all languages. @@ -121,16 +117,14 @@ protected function getQuestion(iPlugin $plugin, $key, $model, $id, $default, $la if ($record->serialized) { $value = json_decode($record->value, true); - } - else + } else { $value = $record->value; } if ($record->language != null && ($language == '*' || is_array($language))) { $result[$record->language][] = $value; - } - else + } else { $result[] = $value; } @@ -144,13 +138,11 @@ protected function getQuestion(iPlugin $plugin, $key, $model, $id, $default, $la $item = $item[0]; } } - } - elseif (count($result) == 1) + } elseif (count($result) == 1) { $result = $result[0]; } - } - else + } else { $result = $default; } @@ -193,8 +185,7 @@ public function set(iPlugin $plugin, $key, $data, $model = null, $id = null, $la if ($model == null || !method_exists($this, $functionName)) { return $this->setGeneric($plugin, $key, $data, $model, $id, $language); - } - else + } else { return $this->$functionName($plugin, $key, $data, $model, $id, $language); } @@ -268,8 +259,7 @@ protected function setQuestion(iPlugin $plugin, $key, $data, $model, $id, $langu $data = null; } $result = $this->setQuestionBase($id, $key, $data); - } - else + } else { $attributes = array( 'qid' => $id, @@ -288,8 +278,7 @@ protected function setQuestion(iPlugin $plugin, $key, $data, $model, $id, $langu { $record->value = json_encode($data); $record->serialized = true; - } - else + } else { $record->value = $data; $record->serialized = false; diff --git a/application/libraries/admin/Services_JSON.php b/application/libraries/admin/Services_JSON.php index 1f17898d297..3dedb6eb040 100644 --- a/application/libraries/admin/Services_JSON.php +++ b/application/libraries/admin/Services_JSON.php @@ -739,8 +739,9 @@ function decode($str) array_pop($stk); $c++; - for ($i = $top['where']; $i <= $c; ++$i) - $chrs = substr_replace($chrs, ' ', $i, 1); + for ($i = $top['where']; $i <= $c; ++$i) { + $chrs = substr_replace($chrs, ' ', $i, 1); + } //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); diff --git a/application/models/Condition.php b/application/models/Condition.php index d2beabdcf66..60c6962f03a 100644 --- a/application/models/Condition.php +++ b/application/models/Condition.php @@ -1,7 +1,8 @@ true), - array('entity', 'length', 'max'=>15), - array('entity_id', 'length', 'max'=>31), - array('stg_name', 'length', 'max'=>63), - array('stg_value', 'safe'), - // The following rule is used by search(). - // @todo Please remove those attributes that should not be searched. - array('uid, entity, entity_id, stg_name, stg_value', 'safe', 'on'=>'search'), - ); - } - - /** - * @return array relational rules. - */ - public function relations() - { - // NOTE: you may need to adjust the relation name and the related - // class name for the relations automatically generated below. - return array( + /** + * @return string the associated database table name + */ + public function tableName() + { + return '{{settings_user}}'; + } + + /** + * @return array validation rules for model attributes. + */ + public function rules() + { + // NOTE: you should only define rules for those attributes that + // will receive user inputs. + return array( + array('uid, stg_name', 'required'), + array('uid', 'numerical', 'integerOnly'=>true), + array('entity', 'length', 'max'=>15), + array('entity_id', 'length', 'max'=>31), + array('stg_name', 'length', 'max'=>63), + array('stg_value', 'safe'), + // The following rule is used by search(). + // @todo Please remove those attributes that should not be searched. + array('uid, entity, entity_id, stg_name, stg_value', 'safe', 'on'=>'search'), + ); + } + + /** + * @return array relational rules. + */ + public function relations() + { + // NOTE: you may need to adjust the relation name and the related + // class name for the relations automatically generated below. + return array( 'user' => array(self::HAS_ONE, 'User', 'uid') - ); - } - - /** - * @return array customized attribute labels (name=>label) - */ - public function attributeLabels() - { - return array( - 'uid' => 'Uid', - 'entity' => 'Entity', - 'entity_id' => 'Entity', - 'stg_name' => 'Setting Name', - 'stg_value' => 'Setting Value', - ); - } + ); + } + + /** + * @return array customized attribute labels (name=>label) + */ + public function attributeLabels() + { + return array( + 'uid' => 'Uid', + 'entity' => 'Entity', + 'entity_id' => 'Entity', + 'stg_name' => 'Setting Name', + 'stg_value' => 'Setting Value', + ); + } /** * Changes or creates a user setting * * @param [String] $stg_name - * @param [String] $stg_value + * @param integer $stg_value * @param [Integer] $uid | Can be omitted to just take the currently logged in users id * @param [type] $entity | optional defaults to 'null' * @param [type] $entity_id | optional defaults to 'null' * @return boolean | Saving success/failure */ - public static function setUserSetting($stg_name, $stg_value, $uid = null, $entity = null, $entity_id = null){ - if($uid === null){ $uid = Yii::app()->user->getId(); } + public static function setUserSetting($stg_name, $stg_value, $uid = null, $entity = null, $entity_id = null) { + if ($uid === null) { $uid = Yii::app()->user->getId(); } - $setting = self::getUserSetting($stg_name,$uid,$entity,$entity_id); + $setting = self::getUserSetting($stg_name, $uid, $entity, $entity_id); - if($setting == null){ + if ($setting == null) { $setting = new SettingsUser(); $setting->setAttributes([ 'stg_name' => $stg_name, @@ -92,7 +92,7 @@ public static function setUserSetting($stg_name, $stg_value, $uid = null, $entit 'entity_id' => $entity_id ]); } - $setting->setAttribute('stg_value',$stg_value); + $setting->setAttribute('stg_value', $stg_value); return $setting->save(); } @@ -106,8 +106,8 @@ public static function setUserSetting($stg_name, $stg_value, $uid = null, $entit * @param [type] $entity_id | optional defaults to 'null' * @return SettingsUser | The current settings Object */ - public static function getUserSetting($stg_name, $uid = null, $entity = null, $entity_id = null){ - if($uid === null){ $uid = Yii::app()->user->getId(); } + public static function getUserSetting($stg_name, $uid = null, $entity = null, $entity_id = null) { + if ($uid === null) { $uid = Yii::app()->user->getId(); } $searchCriteria = new CDbCriteria; $searchParams = []; @@ -115,13 +115,13 @@ public static function getUserSetting($stg_name, $uid = null, $entity = null, $e $searchParams[':uid'] = $uid; $searchCriteria->addCondition('stg_name=:stg_name'); $searchParams[':stg_name'] = $stg_name; - if($entity != null){ + if ($entity != null) { $searchCriteria->addCondition('entity=:entity'); $searchParams[':entity'] = $entity; } else { $searchCriteria->addCondition('entity IS NULL'); } - if($entity_id != null){ + if ($entity_id != null) { $searchCriteria->addCondition('entity_id=:entity_id'); $searchParams[':entity_id'] = $entity_id; } else { @@ -139,56 +139,56 @@ public static function getUserSetting($stg_name, $uid = null, $entity = null, $e * Gets a user settings value depending on the given parameters * Shorthand function * - * @param [String] $stg_name + * @param string $stg_name * @param [Integer] $uid | Can be omitted to just take the currently logged in users id * @param [type] $entity | optional defaults to 'null' * @param [type] $entity_id | optional defaults to 'null' * @return String|Null | The current settings value or null id there is no setting */ - public static function getUserSettingValue($stg_name, $uid = null, $entity = null, $entity_id = null){ - $setting = self::getUserSetting($stg_name,$uid,$entity,$entity_id); + public static function getUserSettingValue($stg_name, $uid = null, $entity = null, $entity_id = null) { + $setting = self::getUserSetting($stg_name, $uid, $entity, $entity_id); return $setting != null ? $setting->getAttribute('stg_value') : null; } - /** - * Retrieves a list of models based on the current search/filter conditions. - * - * Typical usecase: - * - Initialize the model fields with values from filter form. - * - Execute this method to get CActiveDataProvider instance which will filter - * models according to data in model fields. - * - Pass data provider to CGridView, CListView or any similar widget. - * - * @return CActiveDataProvider the data provider that can return the models - * based on the search/filter conditions. - */ - public function search() - { - // @todo Please modify the following code to remove attributes that should not be searched. - - $criteria=new CDbCriteria; - - $criteria->compare('uid',$this->uid); - $criteria->compare('entity',$this->entity,true); - $criteria->compare('entity_id',$this->entity_id,true); - $criteria->compare('stg_name',$this->stg_name,true); - $criteria->compare('stg_value',$this->stg_value,true); - - return new CActiveDataProvider($this, array( - 'criteria'=>$criteria, - )); - } - - /** - * Returns the static model of the specified AR class. - * Please note that you should have this exact method in all your CActiveRecord descendants! - * @param string $className active record class name. - * @return SettingsUser the static model class - */ - public static function model($className=__CLASS__) - { + /** + * Retrieves a list of models based on the current search/filter conditions. + * + * Typical usecase: + * - Initialize the model fields with values from filter form. + * - Execute this method to get CActiveDataProvider instance which will filter + * models according to data in model fields. + * - Pass data provider to CGridView, CListView or any similar widget. + * + * @return CActiveDataProvider the data provider that can return the models + * based on the search/filter conditions. + */ + public function search() + { + // @todo Please modify the following code to remove attributes that should not be searched. + + $criteria=new CDbCriteria; + + $criteria->compare('uid',$this->uid); + $criteria->compare('entity',$this->entity,true); + $criteria->compare('entity_id',$this->entity_id,true); + $criteria->compare('stg_name',$this->stg_name,true); + $criteria->compare('stg_value',$this->stg_value,true); + + return new CActiveDataProvider($this, array( + 'criteria'=>$criteria, + )); + } + + /** + * Returns the static model of the specified AR class. + * Please note that you should have this exact method in all your CActiveRecord descendants! + * @param string $className active record class name. + * @return SettingsUser the static model class + */ + public static function model($className=__CLASS__) + { /** @var self $model */ $model =parent::model($className); return $model; - } + } } diff --git a/application/models/SurveyLink.php b/application/models/SurveyLink.php index 6d0a356d5a2..b104b316225 100644 --- a/application/models/SurveyLink.php +++ b/application/models/SurveyLink.php @@ -1,4 +1,6 @@ -isSubmitted); $submittedAt = $date->format($this->dateFormat); return $submittedAt; - } - else { + } else { return '–'; } } diff --git a/application/models/SurveyTimingDynamic.php b/application/models/SurveyTimingDynamic.php index 1c7b6930019..74062f3c1f1 100644 --- a/application/models/SurveyTimingDynamic.php +++ b/application/models/SurveyTimingDynamic.php @@ -1,4 +1,6 @@ -refreshMetaData(); + if ($refresh === true) { + $model->refreshMetaData(); + } return $model; } diff --git a/application/models/TemplateConfiguration.php b/application/models/TemplateConfiguration.php index 05714789532..7dba2296f7c 100644 --- a/application/models/TemplateConfiguration.php +++ b/application/models/TemplateConfiguration.php @@ -1,5 +1,5 @@ findByPk($iTemplateConfigId); $oTemplateConfiguration->setThisTemplate(); return $oTemplateConfiguration; @@ -147,7 +147,7 @@ public static function getInstanceFromConfigurationId($iTemplateConfigId){ * @param [String] $sTemplateName * @return TemplateConfiguration */ - public static function getInstanceFromTemplateName($sTemplateName){ + public static function getInstanceFromTemplateName($sTemplateName) { return self::model()->find( 'template_name=:template_name AND sid IS NULL AND gsid IS NULL', array(':template_name'=>$sTemplateName) @@ -162,7 +162,7 @@ public static function getInstanceFromTemplateName($sTemplateName){ * @param [String] $sTemplateName * @return TemplateConfiguration */ - public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName=null){ + public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName = null) { //if a template name is given also check against that $sTemplateName = $sTemplateName != null ? $sTemplateName : SurveysGroups::model()->findByPk($iSurveyGroupId)->template; @@ -175,7 +175,7 @@ public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateNam // No specific template configuration for this surveygroup => create one // TODO: Move to SurveyGroup creation, right now the 'lazy loading' approach is ok. - if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration') && $sTemplateName != null){ + if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration') && $sTemplateName != null) { $oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName); $oTemplateConfigurationModel->id = null; $oTemplateConfigurationModel->isNewRecord = true; @@ -192,14 +192,14 @@ public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateNam * Returns a TemplateConfiguration Object based on a surveyID * If no instance is existing, it will create one. * - * @param [Integer] $iSurveyId + * @param integer $iSurveyId * @param [String] $sTemplateName * @return TemplateConfiguration */ - public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName=null){ + public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName = null) { //if a template name is given also check against that - $sTemplateName = $sTemplateName!=null ? $sTemplateName : Survey::model()->findByPk($iSurveyId)->template; + $sTemplateName = $sTemplateName != null ? $sTemplateName : Survey::model()->findByPk($iSurveyId)->template; $criteria = new CDbCriteria(); $criteria->addCondition('sid=:sid'); @@ -211,7 +211,7 @@ public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName=null){ // No specific template configuration for this surveygroup => create one // TODO: Move to SurveyGroup creation, right now the 'lazy loading' approach is ok. - if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration') && $sTemplateName != null){ + if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration') && $sTemplateName != null) { $oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName); $oTemplateConfigurationModel->id = null; $oTemplateConfigurationModel->isNewRecord = true; @@ -231,19 +231,19 @@ public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName=null){ * @param integer $iSurveyId * @return TemplateConfiguration */ - public static function getInstance($sTemplateName=null, $iSurveyGroupId=null, $iSurveyId=null){ + public static function getInstance($sTemplateName = null, $iSurveyGroupId = null, $iSurveyId = null) { $oTemplateConfigurationModel = new TemplateConfiguration(); - if ($sTemplateName!=null){ + if ($sTemplateName != null) { $oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName); } - if($iSurveyGroupId!=null && $iSurveyId==null) { + if ($iSurveyGroupId != null && $iSurveyId == null) { $oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName); } - if($iSurveyId!=null) { + if ($iSurveyId != null) { $oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromSurveyId($iSurveyId, $sTemplateName); } @@ -268,7 +268,7 @@ public function search() { // @todo Please modify the following code to remove attributes that should not be searched. - $criteria=new CDbCriteria; + $criteria = new CDbCriteria; $criteria->join = 'INNER JOIN {{templates}} AS template ON t.template_name = template.name'; //Don't show surveyspecifi settings on the overview @@ -276,16 +276,16 @@ public function search() $criteria->addCondition('t.gsid IS NULL'); $criteria->addCondition('template.name IS NOT NULL'); - $criteria->compare('id',$this->id); - $criteria->compare('template_name',$this->template_name,true); - $criteria->compare('files_css',$this->files_css,true); - $criteria->compare('files_js',$this->files_js,true); - $criteria->compare('files_print_css',$this->files_print_css,true); - $criteria->compare('options',$this->options,true); - $criteria->compare('cssframework_name',$this->cssframework_name,true); - $criteria->compare('cssframework_css',$this->cssframework_css,true); - $criteria->compare('cssframework_js',$this->cssframework_js,true); - $criteria->compare('packages_to_load',$this->packages_to_load,true); + $criteria->compare('id', $this->id); + $criteria->compare('template_name', $this->template_name, true); + $criteria->compare('files_css', $this->files_css, true); + $criteria->compare('files_js', $this->files_js, true); + $criteria->compare('files_print_css', $this->files_print_css, true); + $criteria->compare('options', $this->options, true); + $criteria->compare('cssframework_name', $this->cssframework_name, true); + $criteria->compare('cssframework_css', $this->cssframework_css, true); + $criteria->compare('cssframework_js', $this->cssframework_js, true); + $criteria->compare('packages_to_load', $this->packages_to_load, true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, @@ -298,10 +298,10 @@ public function search() * @param string $className active record class name. * @return TemplateConfiguration the static model class */ - public static function model($className=__CLASS__) + public static function model($className = __CLASS__) { /** @var self $model */ - $model =parent::model($className); + $model = parent::model($className); return $model; } @@ -312,9 +312,9 @@ public static function model($className=__CLASS__) * @return boolean true on success | exception * @throws Exception */ - public static function importManifest($sTemplateName, $aDatas=array() ) + public static function importManifest($sTemplateName, $aDatas = array()) { - if ( !empty($aDatas['extends']) ){ + if (!empty($aDatas['extends'])) { $oMotherTemplate = self::getInstanceFromTemplateName($aDatas['extends']); if (is_a($oMotherTemplate, 'TemplateConfiguration')) { @@ -326,14 +326,14 @@ public static function importManifest($sTemplateName, $aDatas=array() ) $aDatas['version'] = $oMotherTemplate->template->version; $aDatas['license'] = $oMotherTemplate->template->license; $aDatas['files_folder'] = $oMotherTemplate->template->files_folder; - $aDatas['aOptions'] = json_decode($oMotherTemplate->options); + $aDatas['aOptions'] = json_decode($oMotherTemplate->options); } } - return parent::importManifest($sTemplateName, $aDatas ); + return parent::importManifest($sTemplateName, $aDatas); } - public function setToInherit(){ + public function setToInherit() { $this->files_css = 'inherit'; $this->files_js = 'inherit'; $this->files_print_css = 'inherit'; @@ -346,9 +346,9 @@ public function setToInherit(){ public function checkTemplate() { - if (empty($this->bTemplateCheckResult)){ + if (empty($this->bTemplateCheckResult)) { $this->bTemplateCheckResult = true; - if (is_object($this->template) && !is_dir(Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$this->template->folder)&& !is_dir(Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$this->template->folder)){ + if (is_object($this->template) && !is_dir(Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$this->template->folder) && !is_dir(Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$this->template->folder)) { $this->bTemplateCheckResult = false; } } @@ -366,20 +366,20 @@ public function checkTemplate() * @param bool $bUseMagicInherit * @return $this */ - public function prepareTemplateRendering($sTemplateName='', $iSurveyId='', $bUseMagicInherit=true) + public function prepareTemplateRendering($sTemplateName = '', $iSurveyId = '', $bUseMagicInherit = true) { $this->bUseMagicInherit = $bUseMagicInherit; $this->setBasics($sTemplateName, $iSurveyId); - $this->setMotherTemplates(); // Recursive mother templates configuration - $this->setThisTemplate(); // Set the main config values of this template - $this->createTemplatePackage($this); // Create an asset package ready to be loaded + $this->setMotherTemplates(); // Recursive mother templates configuration + $this->setThisTemplate(); // Set the main config values of this template + $this->createTemplatePackage($this); // Create an asset package ready to be loaded return $this; } - public function setBasics($sTemplateName='', $iSurveyId='') + public function setBasics($sTemplateName = '', $iSurveyId = '') { $this->sTemplateName = $this->template->name; - $this->setIsStandard(); // Check if it is a CORE template + $this->setIsStandard(); // Check if it is a CORE template $this->path = ($this->isStandard) ? Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$this->template->folder.DIRECTORY_SEPARATOR : Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$this->template->folder.DIRECTORY_SEPARATOR; @@ -404,17 +404,17 @@ public function addFileReplacement($sFile, $sType) $this->$sField = json_encode($oFiles); - if ($this->save()){ + if ($this->save()) { return true; - }else{ + } else { throw new Exception("could not add $sFile to $sField replacements! ".$this->getErrors()); } } public function getTypeIcon() { - if (empty($this->sTypeIcon)){ - $this->sTypeIcon = (Template::isStandardTemplate($this->template->name))?gT("Core theme"):gT("User theme"); + if (empty($this->sTypeIcon)) { + $this->sTypeIcon = (Template::isStandardTemplate($this->template->name)) ?gT("Core theme") : gT("User theme"); } return $this->sTypeIcon; } @@ -422,11 +422,11 @@ public function getTypeIcon() public function getButtons() { - $sEditorUrl = Yii::app()->getController()->createUrl('admin/themes/sa/view', array("templatename"=>$this->template_name)); - if (App()->getController()->action->id == "surveysgroups"){ + $sEditorUrl = Yii::app()->getController()->createUrl('admin/themes/sa/view', array("templatename"=>$this->template_name)); + if (App()->getController()->action->id == "surveysgroups") { $gisd = Yii::app()->request->getQuery('id', null); $sOptionUrl = Yii::app()->getController()->createUrl('admin/themeoptions/sa/updatesurveygroup', array("id"=>$this->id, "gsid"=>$gisd)); - }else{ + } else { $sOptionUrl = Yii::app()->getController()->createUrl('admin/themeoptions/sa/update', array("id"=>$this->id)); } @@ -444,8 +444,8 @@ class='btn btn-default'> $OptionLink = ''; - if ($this->hasOptionPage){ - $OptionLink .= "hasOptionPage) { + $OptionLink .= " @@ -469,12 +469,12 @@ class="btn btn-danger"> '; - if (App()->getController()->action->id == "surveysgroups"){ + if (App()->getController()->action->id == "surveysgroups") { $sButtons = $OptionLink; - }else{ + } else { $sButtons = $sEditorLink.'

'.$OptionLink; - if ($this->template_name != 'default'){ + if ($this->template_name != 'default') { $sButtons .= '

'.$sUninstallLink; } } @@ -491,10 +491,10 @@ public function getHasOptionPage() $this->prepareTemplateRendering(); $oRTemplate = $this; $sOptionFile = 'options'.DIRECTORY_SEPARATOR.'options.twig'; - while (!file_exists($oRTemplate->path.$sOptionFile)){ + while (!file_exists($oRTemplate->path.$sOptionFile)) { $oMotherTemplate = $oRTemplate->oMotherTemplate; - if(!($oMotherTemplate instanceof TemplateConfiguration)){ + if (!($oMotherTemplate instanceof TemplateConfiguration)) { return false; break; } @@ -504,20 +504,20 @@ public function getHasOptionPage() return true; } - private function _filterImages($file){ + private function _filterImages($file) { $checkImage = getimagesize($this->filesPath.$file['name']); - if (!($checkImage === false || !in_array($checkImage[2], [IMAGETYPE_JPEG,IMAGETYPE_PNG,IMAGETYPE_GIF]))) + if (!($checkImage === false || !in_array($checkImage[2], [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF]))) return ['filepath' => './files/'.$file['name'], 'filename'=>$file['name']]; } - protected function getOptionPageAttributes(){ + protected function getOptionPageAttributes() { $aData = $this->attributes; $fileList = Template::getOtherFiles($this->filesPath); $aData['brandlogoFileList'] = []; - foreach($fileList as $file){ + foreach ($fileList as $file) { $isImage = $this->_filterImages($file); - if($isImage) + if ($isImage) $aData['brandlogoFileList'][] = $isImage; }; return $aData; @@ -539,7 +539,7 @@ public function getOptionPage() */ protected function getFilesToLoad($oTemplate, $sType) { - if (empty($this->aFilesToLoad)){ + if (empty($this->aFilesToLoad)) { $this->aFilesToLoad = array(); } @@ -548,7 +548,7 @@ protected function getFilesToLoad($oTemplate, $sType) $this->aFilesToLoad[$sType] = array(); - if(!empty($jFiles)){ + if (!empty($jFiles)) { $oFiles = json_decode($jFiles, true); if ($oFiles === null) { Yii::app()->setFlashMessage( @@ -560,13 +560,13 @@ protected function getFilesToLoad($oTemplate, $sType) 'error' ); } else { - foreach($oFiles as $action => $aFileList){ + foreach ($oFiles as $action => $aFileList) { - if ( is_array( $aFileList ) ){ - if ($action == "add" || $action == "replace"){ + if (is_array($aFileList)) { + if ($action == "add" || $action == "replace") { // Specific inheritance of one of the value of the json array - if ($aFileList[0] == 'inherit'){ + if ($aFileList[0] == 'inherit') { $aParentjFiles = (array) json_decode($oTemplate->getParentConfiguration->$sField); $aFileList = $aParentjFiles[$action]; } @@ -589,22 +589,22 @@ protected function getFilesToLoad($oTemplate, $sType) * @var $aSettings array array of local setting * @return array */ - protected function changeMotherConfiguration( $sType, $aSettings ) + protected function changeMotherConfiguration($sType, $aSettings) { - if (is_a($this->oMotherTemplate, 'TemplateConfiguration')){ + if (is_a($this->oMotherTemplate, 'TemplateConfiguration')) { // Check if each file exist in this template path // If the file exists in local template, we can remove it from mother template package. // Else, we must remove it from current package, and if it doesn't exist in mother template definition, we must add it. // (and leave it in moter template definition if it already exists.) - foreach ($aSettings as $key => $sFileName){ - if (file_exists($this->path.$sFileName)){ - Yii::app()->clientScript->removeFileFromPackage($this->oMotherTemplate->sPackageName, $sType, $sFileName ); + foreach ($aSettings as $key => $sFileName) { + if (file_exists($this->path.$sFileName)) { + Yii::app()->clientScript->removeFileFromPackage($this->oMotherTemplate->sPackageName, $sType, $sFileName); - }else{ + } else { $oTemplate = $this->getTemplateForFile($sFileName, $this); - if (!Yii::app()->clientScript->IsFileInPackage($oTemplate->sPackageName, $sType, $sFileName)){ + if (!Yii::app()->clientScript->IsFileInPackage($oTemplate->sPackageName, $sType, $sFileName)) { Yii::app()->clientScript->addFileToPackage($oTemplate->sPackageName, $sType, $sFileName); unset($aSettings[$key]); } @@ -623,10 +623,10 @@ protected function changeMotherConfiguration( $sType, $aSettings ) * @param $aSettings array array of local setting * @return array */ - protected function removeFileFromPackage( $sPackageName, $sType, $aSettings ) + protected function removeFileFromPackage($sPackageName, $sType, $aSettings) { - foreach( $aSettings as $sFile){ - Yii::app()->clientScript->removeFileFromPackage($sPackageName, $sType, $sFile ); + foreach ($aSettings as $sFile) { + Yii::app()->clientScript->removeFileFromPackage($sPackageName, $sType, $sFile); } } @@ -636,13 +636,13 @@ protected function removeFileFromPackage( $sPackageName, $sType, $aSettings ) */ protected function setMotherTemplates() { - if(!empty($this->template->extends)){ + if (!empty($this->template->extends)) { $sMotherTemplateName = $this->template->extends; $this->oMotherTemplate = TemplateConfiguration::getInstanceFromTemplateName($sMotherTemplateName); $this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName, null); - if ($this->oMotherTemplate->checkTemplate()){ + if ($this->oMotherTemplate->checkTemplate()) { $this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName, null); // Object Recursion - }else{ + } else { // Throw exception? Set to default template? } } @@ -652,11 +652,11 @@ protected function setMotherTemplates() * @param TemplateConfiguration $oRTemplate * @param string $sPath */ - protected function getTemplateForPath($oRTemplate, $sPath ) + protected function getTemplateForPath($oRTemplate, $sPath) { - while (empty($oRTemplate->template->$sPath)){ + while (empty($oRTemplate->template->$sPath)) { $oMotherTemplate = $oRTemplate->oMotherTemplate; - if(!($oMotherTemplate instanceof TemplateConfiguration)){ + if (!($oMotherTemplate instanceof TemplateConfiguration)) { //throw new Exception("can't find a template for template '{$oRTemplate->template_name}' for path '$sPath'."); TemplateConfiguration::uninstall($this->template_name); Yii::app()->setFlashMessage(sprintf(gT("Theme '%s' has been uninstalled because it's not compatible with this LimeSurvey version."), $this->template_name), 'error'); @@ -674,9 +674,9 @@ protected function getTemplateForPath($oRTemplate, $sPath ) protected function setThisTemplate() { - $this->apiVersion = (!empty($this->template->api_version))? $this->template->api_version : null; // Mandtory setting in config XML - $this->viewPath = $this->path.$this->getTemplateForPath($this, 'view_folder')->template->view_folder.DIRECTORY_SEPARATOR; - $this->filesPath = $this->path.$this->getTemplateForPath($this, 'files_folder')->template->files_folder.DIRECTORY_SEPARATOR ; + $this->apiVersion = (!empty($this->template->api_version)) ? $this->template->api_version : null; // Mandtory setting in config XML + $this->viewPath = $this->path.$this->getTemplateForPath($this, 'view_folder')->template->view_folder.DIRECTORY_SEPARATOR; + $this->filesPath = $this->path.$this->getTemplateForPath($this, 'files_folder')->template->files_folder.DIRECTORY_SEPARATOR; // Options are optional $this->setOptions(); @@ -684,25 +684,25 @@ protected function setThisTemplate() // Not mandatory (use package dependances) $this->setCssFramework(); $this->packages = $this->getDependsPackages($this); - if (!empty($this->packages_to_load)){ + if (!empty($this->packages_to_load)) { $templateToLoadPackages = json_decode($this->packages_to_load); - if(is_array($templateToLoadPackages)) - $this->packages = array_merge( $templateToLoadPackages, $this->getDependsPackages($this)); + if (is_array($templateToLoadPackages)) + $this->packages = array_merge($templateToLoadPackages, $this->getDependsPackages($this)); } // Add depend package according to packages - $this->depends = array_merge($this->depends, $this->packages); + $this->depends = array_merge($this->depends, $this->packages); } private function setCssFramework() { - if (!empty($this->cssframework_name)){ + if (!empty($this->cssframework_name)) { $this->cssFramework = new \stdClass(); $this->cssFramework->name = $this->cssframework_name; $this->cssFramework->css = json_decode($this->cssframework_css); $this->cssFramework->js = json_decode($this->cssframework_js); - }else{ + } else { $this->cssFramework = ''; } } @@ -710,7 +710,7 @@ private function setCssFramework() protected function setOptions() { $this->oOptions = array(); - if (!empty($this->options)){ + if (!empty($this->options)) { $this->oOptions = json_decode($this->options); } @@ -721,8 +721,8 @@ protected function setOptionInheritance() { $oOptions = $this->oOptions; - if (!empty($oOptions)){ - foreach($oOptions as $sKey => $sOption){ + if (!empty($oOptions)) { + foreach ($oOptions as $sKey => $sOption) { $oOptions->$sKey = $this->getOptionKey($sKey); } } @@ -748,7 +748,7 @@ protected function getOptionKey($key) protected function addMotherTemplatePackage($packages) { - if (!empty($this->template->extends)){ + if (!empty($this->template->extends)) { $sMotherTemplateName = (string) $this->template->extends; $packages[] = 'survey-template-'.$sMotherTemplateName; } @@ -761,9 +761,9 @@ protected function addMotherTemplatePackage($packages) * @param boolean $bInlcudeRemove also get the files to remove * @return array */ - protected function getFrameworkAssetsToReplace( $sType, $bInlcudeRemove = false) + protected function getFrameworkAssetsToReplace($sType, $bInlcudeRemove = false) { - if (empty($this->aFrameworkAssetsToReplace)){ + if (empty($this->aFrameworkAssetsToReplace)) { $this->aFrameworkAssetsToReplace = array(); } @@ -772,21 +772,21 @@ protected function getFrameworkAssetsToReplace( $sType, $bInlcudeRemove = false) $sFieldName = 'cssframework_'.$sType; $aFieldValue = (array) json_decode($this->$sFieldName); - if (!empty( $aFieldValue ) && !empty($aFieldValue['replace'])){ - $this->aFrameworkAssetsToReplace[$sType] = (array) $aFieldValue['replace'] ; + if (!empty($aFieldValue) && !empty($aFieldValue['replace'])) { + $this->aFrameworkAssetsToReplace[$sType] = (array) $aFieldValue['replace']; // Inner field inheritance - foreach ($this->aFrameworkAssetsToReplace[$sType] as $key => $aFiles){ - foreach($aFiles as $sReplacement){ - if ( $sReplacement == "inherit"){ + foreach ($this->aFrameworkAssetsToReplace[$sType] as $key => $aFiles) { + foreach ($aFiles as $sReplacement) { + if ($sReplacement == "inherit") { $aParentReplacement = $this->getParentConfiguration()->getFrameworkAssetsToReplace($sType); $this->aFrameworkAssetsToReplace[$sType][$key][1] = $aParentReplacement[$key][1]; } } } - if($bInlcudeRemove && isset($aFieldValue['remove'])){ - $this->aFrameworkAssetsToReplace[$sType] = array_merge($this->aFrameworkAssetsToReplace, (array) $aFieldValue['remove'] ); + if ($bInlcudeRemove && isset($aFieldValue['remove'])) { + $this->aFrameworkAssetsToReplace[$sType] = array_merge($this->aFrameworkAssetsToReplace, (array) $aFieldValue['remove']); } } @@ -799,16 +799,16 @@ protected function getFrameworkAssetsToReplace( $sType, $bInlcudeRemove = false) * @param string $sType css|js the type of file * @return array */ - protected function getFrameworkAssetsReplacement( $sType ) + protected function getFrameworkAssetsReplacement($sType) { - if (empty($this->aReplacements)){ + if (empty($this->aReplacements)) { $this->aReplacements = array(); } $this->aReplacements[$sType] = array(); $aFrameworkAssetsToReplace = $this->getFrameworkAssetsToReplace($sType); - foreach($aFrameworkAssetsToReplace as $key => $aAsset ){ + foreach ($aFrameworkAssetsToReplace as $key => $aAsset) { $aReplace = $aAsset[1]; $this->aReplacements[$sType][] = $aReplace; } @@ -818,14 +818,14 @@ protected function getFrameworkAssetsReplacement( $sType ) } - public function getParentConfiguration(){ - if (empty($this->oParentTemplate)){ + public function getParentConfiguration() { + if (empty($this->oParentTemplate)) { //check for surveygroup id if a survey is given - if($this->sid != null ){ + if ($this->sid != null) { $oSurvey = Survey::model()->findByPk($this->sid); - $oParentTemplate = Template::getTemplateConfiguration($this->sTemplateName,null,$oSurvey->gsid); - if (is_a($oParentTemplate, 'TemplateConfiguration')){ + $oParentTemplate = Template::getTemplateConfiguration($this->sTemplateName, null, $oSurvey->gsid); + if (is_a($oParentTemplate, 'TemplateConfiguration')) { $this->oParentTemplate = $oParentTemplate; $this->oParentTemplate->bUseMagicInherit = $this->bUseMagicInherit; return $this->oParentTemplate; @@ -833,12 +833,12 @@ public function getParentConfiguration(){ } //check for surveygroup id if a surveygroup is given - if($this->sid == null && $this->gsid != null ){ + if ($this->sid == null && $this->gsid != null) { $oSurveyGroup = SurveysGroups::model()->findByPk($this->gsid); //Switch if the surveygroup inherits from a parent surveygroup - if($oSurveyGroup != null && $oSurveyGroup->parent_id != 0) { - $oParentTemplate = Template::getTemplateConfiguration($this->sTemplateName,null,$oSurveyGroup->parent_id); - if (is_a($oParentTemplate, 'TemplateConfiguration')){ + if ($oSurveyGroup != null && $oSurveyGroup->parent_id != 0) { + $oParentTemplate = Template::getTemplateConfiguration($this->sTemplateName, null, $oSurveyGroup->parent_id); + if (is_a($oParentTemplate, 'TemplateConfiguration')) { $this->oParentTemplate = $oParentTemplate; $this->oParentTemplate->bUseMagicInherit = $this->bUseMagicInherit; return $this->oParentTemplate; @@ -863,9 +863,9 @@ public function getParentConfiguration(){ * @param string $sOldName The old name of the template * @param string $sNewName The newname of the template */ - public static function rename($sOldName,$sNewName) + public static function rename($sOldName, $sNewName) { - self::model()->updateAll(array( 'template_name' => $sNewName ), "template_name = :oldname", array(':oldname'=>$sOldName)); + self::model()->updateAll(array('template_name' => $sNewName), "template_name = :oldname", array(':oldname'=>$sOldName)); } @@ -881,14 +881,14 @@ public function __get($name) { $aAttributesThatCanBeInherited = array('files_css', 'files_js', 'options', 'cssframework_name', 'cssframework_css', 'cssframework_js', 'packages_to_load'); - if (in_array($name, $aAttributesThatCanBeInherited) && $this->bUseMagicInherit){ + if (in_array($name, $aAttributesThatCanBeInherited) && $this->bUseMagicInherit) { // Full inheritance of the whole field $sAttribute = parent::__get($name); - if($sAttribute === 'inherit'){ + if ($sAttribute === 'inherit') { // NOTE: this is object recursive (if parent configuration field is set to inherit, then it will lead to this method again.) $sAttribute = $this->getParentConfiguration()->$name; } - }else{ + } else { $sAttribute = parent::__get($name); } diff --git a/application/models/TemplateManifest.php b/application/models/TemplateManifest.php index 76fdd9423e6..668458c73d3 100644 --- a/application/models/TemplateManifest.php +++ b/application/models/TemplateManifest.php @@ -1,5 +1,7 @@ xmlFile)); + $config = simplexml_load_file(realpath($this->xmlFile)); $config->metadatas->last_update = date("Y-m-d H:i:s"); - $config->asXML( realpath ($this->xmlFile) ); // Belt - touch ( $this->path ); // & Suspenders ;-) + $config->asXML(realpath($this->xmlFile)); // Belt + touch($this->path); // & Suspenders ;-) libxml_disable_entity_loader(true); } @@ -52,7 +54,7 @@ public function actualizeLastUpdate() * @param string $sScreen the screen you want to retreive the files from. If null: all screens * @return array array ( [screen name] => array([files]) ) */ - public function getValidScreenFiles($sType = "view", $sScreen=null) + public function getValidScreenFiles($sType = "view", $sScreen = null) { $aScreenFiles = array(); @@ -62,8 +64,8 @@ public function getValidScreenFiles($sType = "view", $sScreen=null) $filesFromXML = (is_null($sScreen)) ? (array) $this->templateEditor->screens->xpath('//file') : $this->templateEditor->screens->xpath('//'.$sScreen.'/file'); - foreach( $filesFromXML as $file){ - if ( $file->attributes()->type == $sType ){ + foreach ($filesFromXML as $file) { + if ($file->attributes()->type == $sType) { $aScreenFiles[] = (string) $file; } } @@ -86,9 +88,9 @@ public function getLayoutForScreen($sScreen) $filesFromXML = $this->templateEditor->screens->xpath('//'.$sScreen.'/file'); - foreach( $filesFromXML as $file){ + foreach ($filesFromXML as $file) { - if ( $file->attributes()->role == "layout" ){ + if ($file->attributes()->role == "layout") { return (string) $file; } } @@ -102,12 +104,12 @@ public function getLayoutForScreen($sScreen) * * @param string $sFile relative path to the file to edit */ - public function getFilePathForEdition($sFile, $aAllowedFiles=null) + public function getFilePathForEdition($sFile, $aAllowedFiles = null) { // Check if the file is allowed for edition ($aAllowedFiles is produced via getValidScreenFiles() ) - if (is_array($aAllowedFiles)){ - if (!in_array($sFile, $aAllowedFiles)){ + if (is_array($aAllowedFiles)) { + if (!in_array($sFile, $aAllowedFiles)) { return false; } } @@ -116,29 +118,29 @@ public function getFilePathForEdition($sFile, $aAllowedFiles=null) } /** - * Copy a file from mother template to local directory and edit manifest if needed - * - * @return string template url - */ + * Copy a file from mother template to local directory and edit manifest if needed + * + * @return string template url + */ public function extendsFile($sFile) { - if( !file_exists($this->path.$sFile) && !file_exists($this->viewPath.$sFile) ){ + if (!file_exists($this->path.$sFile) && !file_exists($this->viewPath.$sFile)) { // Copy file from mother template to local directory $sRfilePath = $this->getFilePath($sFile, $this); - $sLfilePath = (pathinfo($sFile, PATHINFO_EXTENSION) == 'twig')?$this->viewPath.$sFile:$this->path.$sFile; - copy ( $sRfilePath, $sLfilePath ); + $sLfilePath = (pathinfo($sFile, PATHINFO_EXTENSION) == 'twig') ? $this->viewPath.$sFile : $this->path.$sFile; + copy($sRfilePath, $sLfilePath); // If it's a css or js file from config... must update DB and XML too.... $sExt = pathinfo($sLfilePath, PATHINFO_EXTENSION); - if ($sExt == "css" || $sExt == "js"){ + if ($sExt == "css" || $sExt == "js") { // Check if that CSS/JS file is in DB/XML $aFiles = $this->getFilesForPackages($sExt, $this); $sFile = str_replace('./', '', $sFile); // The CSS/JS file is a configuration one.... - if(in_array($sFile, $aFiles)){ + if (in_array($sFile, $aFiles)) { $this->addFileReplacement($sFile, $sExt); $this->addFileReplacementInDB($sFile, $sExt); } @@ -148,17 +150,17 @@ public function extendsFile($sFile) } /** - * Get the files (css or js) defined in the manifest of a template and its mother templates - * - * @param string $type css|js - * @param string $oRTemplate template from which the recurrence should start - * @return array - */ + * Get the files (css or js) defined in the manifest of a template and its mother templates + * + * @param string $type css|js + * @param string $oRTemplate template from which the recurrence should start + * @return array + */ public function getFilesForPackages($type, $oRTemplate) { $aFiles = array(); - while(is_a($oRTemplate, 'TemplateManifest')){ - $aTFiles = isset($oRTemplate->config->files->$type->filename)?(array) $oRTemplate->config->files->$type->filename:array(); + while (is_a($oRTemplate, 'TemplateManifest')) { + $aTFiles = isset($oRTemplate->config->files->$type->filename) ? (array) $oRTemplate->config->files->$type->filename : array(); $aFiles = array_merge($aTFiles, $aFiles); $oRTemplate = $oRTemplate->oMotherTemplate; } @@ -177,7 +179,7 @@ public function getFilesForPackages($type, $oRTemplate) public function addFileReplacementInDB($sFile, $sType) { $oTemplateConfigurationModels = TemplateConfiguration::model()->findAllByAttributes(array('template_name'=>$this->sTemplateName)); - foreach($oTemplateConfigurationModels as $oTemplateConfigurationModel){ + foreach ($oTemplateConfigurationModels as $oTemplateConfigurationModel) { $oTemplateConfigurationModel->addFileReplacement($sFile, $sType); } } @@ -190,16 +192,16 @@ public function getOtherFiles() { $otherfiles = array(); - if (!empty($this->oMotherTemplate)){ + if (!empty($this->oMotherTemplate)) { $otherfiles = $this->oMotherTemplate->getOtherFiles(); } - if ( file_exists($this->filesPath) && $handle = opendir($this->filesPath)){ + if (file_exists($this->filesPath) && $handle = opendir($this->filesPath)) { - while (false !== ($file = readdir($handle))){ + while (false !== ($file = readdir($handle))) { if (!array_search($file, array("DUMMYENTRY", ".", "..", "preview.png"))) { - if (!is_dir($this->viewPath . DIRECTORY_SEPARATOR . $file)) { - $otherfiles[$file] = $this->filesPath . DIRECTORY_SEPARATOR . $file; + if (!is_dir($this->viewPath.DIRECTORY_SEPARATOR.$file)) { + $otherfiles[$file] = $this->filesPath.DIRECTORY_SEPARATOR.$file; } } } @@ -238,7 +240,7 @@ class='btn btn-default'> $sLoadLink = ''; - $sLoadLink .= "sTemplateName."' href='".$sLoadUrl."' class='btn btn-default '> @@ -246,7 +248,7 @@ class='btn btn-default '> ".gT('Install')." "; - $sDeleteLink = "sTemplateName."' href='".$sDeleteUrl."' class='btn btn-danger '> @@ -264,13 +266,13 @@ class='btn btn-danger '> * @return boolean true on success | exception * @throws Exception */ - public static function importManifest($sTemplateName, $aDatas=array() ) + public static function importManifest($sTemplateName, $aDatas = array()) { $oTemplate = Template::getTemplateConfiguration($sTemplateName, null, null, true); $aDatas['extends'] = $bExtends = (string) $oTemplate->config->metadatas->extends; - if ($bExtends && !Template::model()->findByPk($bExtends)){ - Yii::app()->setFlashMessage(sprintf(gT("You can't import the theme '%s' because '%s' is not installed."), $sTemplateName, $bExtends ), 'error'); + if ($bExtends && !Template::model()->findByPk($bExtends)) { + Yii::app()->setFlashMessage(sprintf(gT("You can't import the theme '%s' because '%s' is not installed."), $sTemplateName, $bExtends), 'error'); Yii::app()->getController()->redirect(array("admin/themeoptions")); } @@ -284,7 +286,7 @@ public static function importManifest($sTemplateName, $aDatas=array() ) // Engine, files, and options can be inherited from a moter template // It means that the while field should always be inherited, not a subfield (eg: all files, not only css add) - $oREngineTemplate = (!empty($bExtends))? self::getTemplateForXPath($oTemplate, 'engine' ) : $oTemplate; + $oREngineTemplate = (!empty($bExtends)) ? self::getTemplateForXPath($oTemplate, 'engine') : $oTemplate; $aDatas['view_folder'] = (string) $oREngineTemplate->config->engine->viewdirectory; @@ -302,7 +304,7 @@ public static function importManifest($sTemplateName, $aDatas=array() ) $aDatas['files_css'] = self::formatArrayFields($oTemplate, 'files', 'css'); $aDatas['files_js'] = self::formatArrayFields($oTemplate, 'files', 'js'); $aDatas['files_print_css'] = self::formatArrayFields($oTemplate, 'files', 'print_css'); - }else{ + } else{ $aDatas['files_css'] = $aDatas['files_js'] = $aDatas['files_print_css'] = null; } @@ -326,7 +328,7 @@ public static function getTemplateForXPath($oTemplate, $sFieldPath) // Think about what to do.. throw new Exception("Error: Can't find a template for '$oRTemplate->sTemplateName' in xpath '$sFieldPath'."); } - }else{ + } else{ throw new Exception("Error: Can't find a template for '$oRTemplate->sTemplateName' in xpath '$sFieldPath'."); } } @@ -345,7 +347,7 @@ public static function getTemplateForXPath($oTemplate, $sFieldPath) */ public static function formatArrayFields($oTemplate, $sFieldPath, $sFieldName) { - return ( empty($oTemplate->config->$sFieldPath->$sFieldName->value) && empty($oTemplate->config->$sFieldPath->$sFieldName) )?array():$oTemplate->config->$sFieldPath->$sFieldName; + return (empty($oTemplate->config->$sFieldPath->$sFieldName->value) && empty($oTemplate->config->$sFieldPath->$sFieldName)) ? array() : $oTemplate->config->$sFieldPath->$sFieldName; } /** @@ -381,9 +383,9 @@ public static function changeNameInDOM($oNewManifest, $sName) * @param DOMDocument $oNewManifest The DOMDOcument of the manifest * @param string $sDate The wanted date, if empty the current date with config time adjustment will be used */ - public static function changeDateInDOM($oNewManifest, $sDate='') + public static function changeDateInDOM($oNewManifest, $sDate = '') { - $date = (empty($date))?dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust")):$date; + $date = (empty($date)) ?dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust")) : $date; $oConfig = $oNewManifest->getElementsByTagName('config')->item(0); $oMetadatas = $oConfig->getElementsByTagName('metadatas')->item(0); $oOldDateNode = $oMetadatas->getElementsByTagName('creationDate')->item(0); @@ -401,10 +403,10 @@ public static function changeDateInDOM($oNewManifest, $sDate='') * @param string $sOldName The old name of the template * @param string $sNewName The newname of the template */ - public static function rename($sOldName,$sNewName) + public static function rename($sOldName, $sNewName) { libxml_disable_entity_loader(false); - $sConfigPath = Yii::app()->getConfig('userthemerootdir') . "/" . $sNewName; + $sConfigPath = Yii::app()->getConfig('userthemerootdir')."/".$sNewName; $oNewManifest = self::getManifestDOM($sConfigPath); self::changeNameInDOM($oNewManifest, $sNewName); self::changeDateInDOM($oNewManifest); @@ -426,9 +428,9 @@ public static function deleteEngineInDom($oNewManifest) //$aNodesToDelete[] = $oConfig->getElementsByTagName('files')->item(0); $aNodesToDelete[] = $oConfig->getElementsByTagName('engine')->item(0); - foreach($aNodesToDelete as $node){ + foreach ($aNodesToDelete as $node) { // If extended template already extend another template, it will not have those nodes - if (is_a( $node, 'DOMNode')){ + if (is_a($node, 'DOMNode')) { $oConfig->removeChild($node); } } @@ -477,7 +479,7 @@ public static function changeExtendsInDom($oNewManifest, $sToExtends) // We test if mother template already extends another template if(!empty($oMetadatas->getElementsByTagName('extends')->item(0))){ $oMetadatas->replaceChild($oExtendsNode, $oMetadatas->getElementsByTagName('extends')->item(0)); - }else{ + } else{ $oMetadatas->appendChild($oExtendsNode); } } @@ -501,7 +503,7 @@ public static function changeExtendsInDom($oNewManifest, $sToExtends) */ public static function extendsConfig($sToExtends, $sNewName) { - $sConfigPath = Yii::app()->getConfig('userthemerootdir') . "/" . $sNewName; + $sConfigPath = Yii::app()->getConfig('userthemerootdir')."/".$sNewName; // First we get the XML file libxml_disable_entity_loader(false); @@ -525,11 +527,11 @@ public static function extendsConfig($sToExtends, $sNewName) private function readManifest() { $this->xmlFile = $this->path.'config.xml'; - $bOldEntityLoaderState = libxml_disable_entity_loader(true); // @see: http://phpsecurity.readthedocs.io/en/latest/Injection-Attacks.html#xml-external-entity-injection - $sXMLConfigFile = file_get_contents( realpath ($this->xmlFile)); // @see: Now that entity loader is disabled, we can't use simplexml_load_file; so we must read the file with file_get_contents and convert it as a string - $this->config = simplexml_load_string($sXMLConfigFile); // Using PHP >= 5.4 then no need to decode encode + need attributes : then other function if needed :https://secure.php.net/manual/en/book.simplexml.php#108688 for example + $bOldEntityLoaderState = libxml_disable_entity_loader(true); // @see: http://phpsecurity.readthedocs.io/en/latest/Injection-Attacks.html#xml-external-entity-injection + $sXMLConfigFile = file_get_contents(realpath($this->xmlFile)); // @see: Now that entity loader is disabled, we can't use simplexml_load_file; so we must read the file with file_get_contents and convert it as a string + $this->config = simplexml_load_string($sXMLConfigFile); // Using PHP >= 5.4 then no need to decode encode + need attributes : then other function if needed :https://secure.php.net/manual/en/book.simplexml.php#108688 for example - libxml_disable_entity_loader($bOldEntityLoaderState); // Put back entity loader to its original state, to avoid contagion to other applications on the server + libxml_disable_entity_loader($bOldEntityLoaderState); // Put back entity loader to its original state, to avoid contagion to other applications on the server } /** @@ -539,7 +541,7 @@ private function readManifest() private function setPath() { // If the template is standard, its root is based on standardthemerootdir, else, it is a user template, its root is based on userthemerootdir - $this->path = ($this->isStandard)?Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$this->sTemplateName.DIRECTORY_SEPARATOR:Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$this->sTemplateName.DIRECTORY_SEPARATOR; + $this->path = ($this->isStandard) ?Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$this->sTemplateName.DIRECTORY_SEPARATOR : Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$this->sTemplateName.DIRECTORY_SEPARATOR; // If the template directory doesn't exist, we just set Default as the template to use // TODO: create a method "setToDefault" @@ -547,7 +549,7 @@ private function setPath() $this->sTemplateName = 'default'; $this->isStandard = true; $this->path = Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$this->sTemplateName.DIRECTORY_SEPARATOR; - if(!$this->iSurveyId){ + if (!$this->iSurveyId) { setGlobalSetting('defaulttheme', 'default'); } } @@ -567,7 +569,7 @@ private function setPath() * * @var $sTemplateName string the name of the template * @var $iSurveyId int the id of the survey - */ + */ private function setTemplateName($sTemplateName='', $iSurveyId='') { @@ -606,22 +608,22 @@ private function setTemplateName($sTemplateName='', $iSurveyId='') * @param string $iSurveyId the id of the survey. If * @return $this */ - public function prepareTemplateRendering($sTemplateName='', $iSurveyId='', $bUseMagicInherit=true) + public function prepareTemplateRendering($sTemplateName = '', $iSurveyId = '', $bUseMagicInherit = true) { $this->setBasics($sTemplateName, $iSurveyId); - $this->setMotherTemplates(); // Recursive mother templates configuration - $this->setThisTemplate(); // Set the main config values of this template - $this->createTemplatePackage($this); // Create an asset package ready to be loaded + $this->setMotherTemplates(); // Recursive mother templates configuration + $this->setThisTemplate(); // Set the main config values of this template + $this->createTemplatePackage($this); // Create an asset package ready to be loaded return $this; } - public function setBasics($sTemplateName='', $iSurveyId='') + public function setBasics($sTemplateName = '', $iSurveyId = '') { - $this->setTemplateName($sTemplateName, $iSurveyId); // Check and set template name - $this->setIsStandard(); // Check if it is a CORE template - $this->setPath(); // Check and set path - $this->readManifest(); // Check and read the manifest to set local params + $this->setTemplateName($sTemplateName, $iSurveyId); // Check and set template name + $this->setIsStandard(); // Check if it is a CORE template + $this->setPath(); // Check and set path + $this->readManifest(); // Check and read the manifest to set local params } /** @@ -640,15 +642,15 @@ public function addFileReplacement($sFile, $sType) $oConfig = $oNewManifest->getElementsByTagName('config')->item(0); $oFiles = $oNewManifest->getElementsByTagName('files')->item(0); - $oOptions = $oNewManifest->getElementsByTagName('options')->item(0); // Only for the insert before statement + $oOptions = $oNewManifest->getElementsByTagName('options')->item(0); // Only for the insert before statement - if (is_null($oFiles)){ - $oFiles = $oNewManifest->createElement('files'); + if (is_null($oFiles)) { + $oFiles = $oNewManifest->createElement('files'); } $oAssetType = $oFiles->getElementsByTagName($sType)->item(0); - if (is_null($oAssetType)){ - $oAssetType = $oNewManifest->createElement($sType); + if (is_null($oAssetType)) { + $oAssetType = $oNewManifest->createElement($sType); $oFiles->appendChild($oAssetType); } @@ -659,7 +661,7 @@ public function addFileReplacement($sFile, $sType) $replaceAttribute->value = $sFile; $oAssetElem->appendChild($replaceAttribute); $oAssetType->appendChild($oAssetElem); - $oConfig->insertBefore($oFiles,$oOptions); + $oConfig->insertBefore($oFiles, $oOptions); $oNewManifest->save($this->path."config.xml"); libxml_disable_entity_loader(true); } @@ -673,9 +675,9 @@ public function addFileReplacement($sFile, $sType) protected function getFilesToLoad($oTemplate, $sType) { $aFiles = array(); - $oRFilesTemplate = (!empty($bExtends))? self::getTemplateForXPath($oTemplate, 'files' ) : $oTemplate; + $oRFilesTemplate = (!empty($bExtends)) ? self::getTemplateForXPath($oTemplate, 'files') : $oTemplate; - if(isset($oRFilesTemplate->config->files->$sType->add)){ + if (isset($oRFilesTemplate->config->files->$sType->add)) { // TODO: "replace" and "remove" $aFiles = (array) $oTemplate->config->files->$sType->add; } @@ -688,10 +690,10 @@ protected function getFilesToLoad($oTemplate, $sType) * @param $aSettings array array of local setting * @return array */ - protected function changeMotherConfiguration( $sType, $aSettings ) + protected function changeMotherConfiguration($sType, $aSettings) { - foreach( $aSettings as $key => $aSetting){ - if (!empty($aSetting['replace']) || !empty($aSetting['remove'])){ + foreach ($aSettings as $key => $aSetting) { + if (!empty($aSetting['replace']) || !empty($aSetting['remove'])) { $this->removeFileFromPackage($this->oMotherTemplate->sPackageName, $sType, $aSetting['replace']); unset($aSettings[$key]); } @@ -711,9 +713,9 @@ protected function changeMotherConfiguration( $sType, $aSettings ) * @param $aSettings array array of local setting * @return array */ - protected function removeFileFromPackage( $sPackageName, $sType, $aSetting ) + protected function removeFileFromPackage($sPackageName, $sType, $aSetting) { - Yii::app()->clientScript->removeFileFromPackage($sPackageName, $sType, $aSetting ); + Yii::app()->clientScript->removeFileFromPackage($sPackageName, $sType, $aSetting); } /** @@ -722,7 +724,7 @@ protected function removeFileFromPackage( $sPackageName, $sType, $aSetting ) */ protected function setMotherTemplates() { - if (isset($this->config->metadatas->extends)){ + if (isset($this->config->metadatas->extends)) { $sMotherTemplateName = (string) $this->config->metadatas->extends; $this->oMotherTemplate = new TemplateManifest; $this->oMotherTemplate->prepareTemplateRendering($sMotherTemplateName); // Object Recursion @@ -751,7 +753,7 @@ protected function getTemplateForPath($oRTemplate, $sPath) protected function setThisTemplate() { // Mandtory setting in config XML (can be not set in inheritance tree, but must be set in mother template (void value is still a setting)) - $this->apiVersion = (isset($this->config->metadatas->apiVersion)) ? $this->config->metadatas->apiVersion : null; + $this->apiVersion = (isset($this->config->metadatas->apiVersion)) ? $this->config->metadatas->apiVersion : null; $this->viewPath = $this->path.$this->getTemplateForPath($this, '//viewdirectory')->config->engine->viewdirectory.DIRECTORY_SEPARATOR; @@ -762,9 +764,9 @@ protected function setThisTemplate() if (!empty($this->config->xpath("//options"))){ $aOptions = $this->config->xpath("//options"); $this->oOptions = $aOptions[0]; - }elseif(!empty($this->oMotherTemplate->oOptions)){ + } elseif(!empty($this->oMotherTemplate->oOptions)){ $this->oOptions = $this->oMotherTemplate->oOptions; - }else{ + } else{ $this->oOptions = ""; } @@ -779,7 +781,7 @@ protected function setThisTemplate() protected function addMotherTemplatePackage($packages) { - if (isset($this->config->metadatas->extends)){ + if (isset($this->config->metadatas->extends)) { $sMotherTemplateName = (string) $this->config->metadatas->extends; $packages[] = 'survey-template-'.$sMotherTemplateName; } @@ -792,13 +794,13 @@ protected function addMotherTemplatePackage($packages) * @param boolean $bInlcudeRemove also get the files to remove * @return array */ - protected function getFrameworkAssetsToReplace( $sType, $bInlcudeRemove = false) + protected function getFrameworkAssetsToReplace($sType, $bInlcudeRemove = false) { $aAssetsToRemove = array(); - if (!empty($this->cssFramework->$sType) && !empty($this->cssFramework->$sType->attributes()->replace)){ - $aAssetsToRemove = (array) $this->cssFramework->$sType->attributes()->replace ; - if($bInlcudeRemove){ - $aAssetsToRemove = array_merge($aAssetsToRemove, (array) $this->cssFramework->$sType->attributes()->remove ); + if (!empty($this->cssFramework->$sType) && !empty($this->cssFramework->$sType->attributes()->replace)) { + $aAssetsToRemove = (array) $this->cssFramework->$sType->attributes()->replace; + if ($bInlcudeRemove) { + $aAssetsToRemove = array_merge($aAssetsToRemove, (array) $this->cssFramework->$sType->attributes()->remove); } } return $aAssetsToRemove; @@ -809,17 +811,17 @@ protected function getFrameworkAssetsToReplace( $sType, $bInlcudeRemove = false) * @param string $sType css|js the type of file * @return array */ - protected function getFrameworkAssetsReplacement( $sType ) + protected function getFrameworkAssetsReplacement($sType) { $aAssetsToRemove = array(); - if (!empty($this->cssFramework->$sType)){ + if (!empty($this->cssFramework->$sType)) { $nodes = (array) $this->config->xpath('//cssframework/'.$sType.'[@replace]'); - if (!empty($nodes)){ - foreach ($nodes as $key => $node){ - $nodes[$key] = (string) $node[0]; + if (!empty($nodes)) { + foreach ($nodes as $key => $node) { + $nodes[$key] = (string) $node[0]; } - $aAssetsToRemove = $nodes ; + $aAssetsToRemove = $nodes; } } return $aAssetsToRemove;