Skip to content

Commit

Permalink
Dev: added a list of broken themes
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jul 3, 2018
1 parent b70c66b commit e24f618
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 7 deletions.
54 changes: 50 additions & 4 deletions application/controllers/admin/themes.php
Expand Up @@ -75,7 +75,6 @@ public function templatezip($templatename)
}
}


/**
* Exports a deprecated template
*
Expand All @@ -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');
Expand All @@ -116,8 +144,8 @@ public function deprecatedtemplatezip($templatename)
// Delete the temporary file
unlink($zipfile);
}
}

}

/**
* Retrieves a temporary template file from disk
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -1185,7 +1231,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma

$thissurvey['include_content'] = $sContentFile;


try {
$myoutput = Yii::app()->twigRenderer->renderTemplateForTemplateEditor(
$sLayoutFile,
Expand Down
28 changes: 27 additions & 1 deletion application/models/Template.php
Expand Up @@ -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(
Expand Down Expand Up @@ -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!
Expand Down
4 changes: 2 additions & 2 deletions application/models/TemplateConfig.php
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
58 changes: 58 additions & 0 deletions application/views/admin/themeoptions/index.php
Expand Up @@ -35,6 +35,7 @@
<?php $this->renderPartial('themeoptions/surveythememenu',['canImport'=>$canImport,'importErrorMessage'=>$importErrorMessage]); ?>
<?php $this->renderPartial('themeoptions/surveythemelist', array( 'oSurveyTheme'=> $oSurveyTheme )); ?>

<!-- Available Themes -->
<?php if (count($oSurveyTheme->templatesWithNoDb) > 0 ):?>
<h3><?php eT('Available survey themes:'); ?></h3>
<div class="row">
Expand Down Expand Up @@ -69,6 +70,63 @@
</div>
<?php endif;?>

<!-- Broken Themes -->
<?php $aBrokenThemes = Template::getBrokenThemes(); if (count($aBrokenThemes) > 0 ):?>

<div class="alert alert-danger" role="alert">
<?php eT('Broken survey themes:'); ?>
</div>

<div class="row" >
<div class="col-sm-12 content-right">

<div id="thembes_broken" class="grid-view">
<table class="items table">
<thead>
<tr>
<th><?php eT('Name'); ?></th><th><?php eT('Error message'); ?></th><th></th>
</tr>
</thead>

<tbody>
<?php foreach ($aBrokenThemes as $sName => $oBrokenTheme):?>
<?php // echo $oTemplate; ?>
<tr class="odd">
<td class="col-md-1 text-danger"><?php echo $sName; ?></td>
<td class="col-md-10 "><blockquote><?php echo $oBrokenTheme->getMessage(); ?></blockquote></td>
<td class="col-md-1">

<!-- Export -->
<?php if(Permission::model()->hasGlobalPermission('templates','export') && function_exists("zip_open")):?>
<a class="btn btn-default btn-block" id="button-export" href="<?php echo $this->createUrl('admin/themes/sa/brokentemplatezip/templatename/' . $sName) ?>" role="button">
<span class="icon-export text-success"></span>
<?php eT("Export"); ?>
</a>
<?php endif;?>

<!-- Delete -->
<?php if(Permission::model()->hasGlobalPermission('templates','delete')):?>
<a class="btn btn-default btn-block" id="button-delete" href="#" role="button" onclick='if (confirm("<?php eT("Are you sure you want to delete this broken theme?", "js"); ?>")) window.open("<?php echo $this->createUrl('admin/themes/sa/deleteBrokenTheme/templatename/'.$sName); ?>", "_top")'>
<span class="fa fa-trash text-warning"></span>
<?php eT("Delete"); ?>
</a>
<?php endif;?>

</td>
</tr>
<?php endforeach;?>
</tbody>
</table>

</div>

</div>
</div>
<?php endif;?>


<!-- Broken Themes -->

<!-- Deprecated Themes -->
<?php $aDeprecatedThemes = Template::getDeprecatedTemplates(); ?>
<?php if (count( $aDeprecatedThemes ) > 0 ):?>
Expand Down

0 comments on commit e24f618

Please sign in to comment.