From e24f618a11e1dffa734e445be9e6664353de43d3 Mon Sep 17 00:00:00 2001 From: LouisGac Date: Tue, 3 Jul 2018 13:32:18 +0200 Subject: [PATCH] Dev: added a list of broken themes --- application/controllers/admin/themes.php | 54 +++++++++++++++-- application/models/Template.php | 28 ++++++++- application/models/TemplateConfig.php | 4 +- .../views/admin/themeoptions/index.php | 58 +++++++++++++++++++ 4 files changed, 137 insertions(+), 7 deletions(-) diff --git a/application/controllers/admin/themes.php b/application/controllers/admin/themes.php index 435747a0165..74ae40cec02 100755 --- a/application/controllers/admin/themes.php +++ b/application/controllers/admin/themes.php @@ -75,7 +75,6 @@ public function templatezip($templatename) } } - /** * Exports a deprecated template * @@ -89,10 +88,39 @@ public function deprecatedtemplatezip($templatename) $templatename = sanitize_dirname($templatename); $usertemplaterootdir = Yii::app()->getConfig("uploaddir").DIRECTORY_SEPARATOR."templates"; $templatePath = $usertemplaterootdir.DIRECTORY_SEPARATOR.$templatename; + $this->folderzip($templatename, $templatePath); + } + /** + * Exports a broken theme + * + * @access public + * @param string $templatename + * @return void + */ + public function brokentemplatezip($templatename) + { + //$oEditedTemplate = Template::model()->getTemplateConfiguration($templatename); + $templatename = sanitize_dirname($templatename); + $templatePath = Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$templatename; + $this->folderzip($templatename, $templatePath); + } + + /** + * Exports a theme folder + * NOTE: This function must remain private !!! it doesn't sanitize the $templatePath + * This should be done by the proxy function (eg: deprecatedtemplatezip(), brokentemplatezip() ) + * + * @access public + * @param string $templatename + * @return void + */ + private function folderzip($templatename, $templatePath) + { if (!Permission::model()->hasGlobalPermission('templates','export')){ - die('No permission'); + Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); + $this->getController()->redirect(array("admin/themeoptions")); } $tempdir = Yii::app()->getConfig('tempdir'); @@ -116,8 +144,8 @@ public function deprecatedtemplatezip($templatename) // Delete the temporary file unlink($zipfile); } - } + } /** * Retrieves a temporary template file from disk @@ -616,10 +644,28 @@ public function delete($templatename) } else { Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error'); } + + // Redirect with default templatename, editfile and screenname $this->getController()->redirect(array("admin/themeoptions")); } + public function deleteBrokenTheme($templatename) + { + // First we check that the theme is really broken + $aBrokenThemes = Template::getBrokenThemes(); + $templatename = sanitize_dirname($templatename); + if (array_key_exists($templatename, $aBrokenThemes)) { + if (rmdirr(Yii::app()->getConfig('userthemerootdir')."/".$templatename)){ + Yii::app()->setFlashMessage(sprintf(gT("Theme '%s' was successfully deleted."), $templatename)); + } + }else{ + Yii::app()->setFlashMessage(gT("Not a broken theme!"), 'error'); + } + + $this->getController()->redirect(array("admin/themeoptions")); + } + /** * Function responsible to save the changes made in CodemMirror editor. * @@ -1185,7 +1231,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma $thissurvey['include_content'] = $sContentFile; - + try { $myoutput = Yii::app()->twigRenderer->renderTemplateForTemplateEditor( $sLayoutFile, diff --git a/application/models/Template.php b/application/models/Template.php index 87789d96400..6c267c64e5f 100755 --- a/application/models/Template.php +++ b/application/models/Template.php @@ -221,7 +221,7 @@ public function checkTemplateExtends() if (empty($oRTemplate)) { // Why? it blocks the user at login screen.... - // It should return false and show a nice warning message. + // It should return false and show a nice warning message. /*throw new Exception( sprintf( @@ -677,6 +677,32 @@ static public function getDeprecatedTemplates() return $aTemplateList; } + /** + * Retrieves a list of broken themes + */ + public static function getBrokenThemes($sFolder=null) + { + $aBrokenTemplateList = array(); + $sFolder = (empty($sFolder))?Yii::app()->getConfig("userthemerootdir"):$sFolder; + + if ($sFolder && $handle = opendir($sFolder)) { + while (false !== ($sFileName = readdir($handle))) { + if (!is_file("$sFolder/$sFileName") && $sFileName != "." && $sFileName != ".." && $sFileName != ".svn" && $sFileName != 'generalfiles' ) { + + try { + $oTheme = Template::getTemplateConfiguration($sFileName, null, null, true); // Get the manifest; + }catch (Exception $e) { + $aBrokenTemplateList[$sFileName] = $e; + } + } + } + closedir($handle); + } + ksort($aBrokenTemplateList); + return $aBrokenTemplateList; + } + + /** * Returns the static model of the specified AR class. * Please note that you should have this exact method in all your CActiveRecord descendants! diff --git a/application/models/TemplateConfig.php b/application/models/TemplateConfig.php index 56d4c8efadf..62456a5cb32 100644 --- a/application/models/TemplateConfig.php +++ b/application/models/TemplateConfig.php @@ -112,7 +112,7 @@ public function getTemplateURL() /** * Get the template for a given file. It checks if a file exist in the current template or in one of its mother templates * Can return a 302 redirect (this is not really a throw … - * + * * @param string $sFile the file to look for (must contain relative path, unless it's a view file) * @param TemplateConfig $oRTemplate template from which the recurrence should start * @param boolean $force file to be in template or mother template @@ -730,7 +730,7 @@ public function getClassAndAttributes() $aClassAndAttributes['attr']['clearalllinks'] = $aClassAndAttributes['attr']['clearalllink'] = ' '; // Clearall Buttons $aClassAndAttributes['class']['clearallwrapper'] = $aClassAndAttributes['class']['clearallconfirm'] = ""; // No need, adding it if need something after - $aClassAndAttributes['class']['clearalllabel'] = "ls-js-hidden"; + $aClassAndAttributes['class']['clearalllabel'] = "ls-js-hidden"; $aClassAndAttributes['attr']['clearallconfirm'] = 'value="confirm" name="confirm-clearall" type="checkbox"'; $aClassAndAttributes['attr']['clearallbutton'] = 'type="submit" value="clearall" name="move" data-confirmedby="confirm-clearall"'; $aClassAndAttributes['class']['clearallbutton'] = "ls-clearaction ls-clearall"; // Not needed, keep it (and adding to twig to be most compatible in future) diff --git a/application/views/admin/themeoptions/index.php b/application/views/admin/themeoptions/index.php index 4336e8c7ac7..aeab45bbfa2 100644 --- a/application/views/admin/themeoptions/index.php +++ b/application/views/admin/themeoptions/index.php @@ -35,6 +35,7 @@ renderPartial('themeoptions/surveythememenu',['canImport'=>$canImport,'importErrorMessage'=>$importErrorMessage]); ?> renderPartial('themeoptions/surveythemelist', array( 'oSurveyTheme'=> $oSurveyTheme )); ?> + templatesWithNoDb) > 0 ):?>

@@ -69,6 +70,63 @@
+ + 0 ):?> + + + +
+
+ +
+ + + + + + + + + $oBrokenTheme):?> + + + + + + + + +
getMessage(); ?>
+ + + hasGlobalPermission('templates','export') && function_exists("zip_open")):?> + + + + + + + + hasGlobalPermission('templates','delete')):?> + ", "_top")'> + + + + + +
+ +
+ +
+
+ + + + + 0 ):?>