Skip to content

Commit

Permalink
Fixed issue: Simply uploading an image in a standard theme wasn't wor…
Browse files Browse the repository at this point in the history
…king
  • Loading branch information
lacrioque committed Mar 14, 2018
1 parent 1429369 commit a3d9f34
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
5 changes: 5 additions & 0 deletions application/controllers/admin/themes.php
Expand Up @@ -107,6 +107,7 @@ public function upload()
$uploadresult = "";
$success = false;
$debug = [];

if ($action == 'templateuploadimagefile') {
// $iTemplateConfigurationId = Yii::app()->request->getPost('templateconfig');
// $oTemplateConfiguration = TemplateConfiguration::getInstanceFromConfigurationId($iTemplateConfigurationId);
Expand Down Expand Up @@ -147,6 +148,10 @@ public function upload()
}

$destdir = $oTemplateConfiguration->filesPath;
if(Template::isStandardTemplate($oTemplateConfiguration->sTemplateName)){
$destdir = $oTemplateConfiguration->generalFilesPath;
}

$filename = sanitize_filename($_FILES['file']['name'], false, false, false); // Don't force lowercase or alphanumeric
$fullfilepath = $destdir.$filename;
$debug[] = $destdir;
Expand Down
20 changes: 13 additions & 7 deletions application/core/LS_Twig_Extension.php
Expand Up @@ -247,14 +247,17 @@ public static function image($sImagePath, $alt = '', $htmlOptions = array( ))
{
// Reccurence on templates to find the file
$oTemplate = self::getTemplateForRessource($sImagePath);
$sUrlImgAsset = '';

if ($oTemplate) {
$sUrlImgAsset = self::assetPublish($oTemplate->path.$sImagePath);
} else {
$sUrlImgAsset = '';
// TODO: publish a default image "not found"
}

if (@is_array(getimagesize(Yii::app()->getConfig('rootdir').$sImagePath))) {
$sUrlImgAsset = $sImagePath;
}


return CHtml::image($sUrlImgAsset, $alt, $htmlOptions);
}

Expand All @@ -268,12 +271,15 @@ public static function imageSrc($sImagePath, $default = './files/pattern.png')
{
// Reccurence on templates to find the file
$oTemplate = self::getTemplateForRessource($sImagePath);
$sUrlImgAsset = '';

$sUrlImgAsset = '';$sImagePath;


if ($oTemplate) {
$sUrlImgAsset = self::assetPublish($oTemplate->path.$sImagePath);
} else {
// TODO: publish a default image "not found"
}

if (@is_array(getimagesize(Yii::app()->getConfig('rootdir').$sImagePath))) {
$sUrlImgAsset = $sImagePath;
}

return $sUrlImgAsset;
Expand Down
26 changes: 18 additions & 8 deletions application/models/TemplateConfiguration.php
Expand Up @@ -83,6 +83,7 @@ class TemplateConfiguration extends TemplateConfig
/** @var array $aReplacements cache for the method getFrameworkAssetsReplacement */
private $aReplacements;

public $generalFilesPath; //Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.'generalfiles'.DIRECTORY_SEPARATOR;

/**
* @return string the associated database table name
Expand Down Expand Up @@ -601,23 +602,32 @@ public function getHasOptionPage()

private function _filterImages($file)
{
$checkImage = getimagesize($this->filesPath.$file['name']);
if(file_exists($this->filesPath.$file['name'])) {
$imagePath = $this->filesPath.$file['name'];
$fileRoot = './files';
} else {
$imagePath = $this->generalFilesPath.$file['name'] ;
$fileRoot = Yii::app()->getConfig("userthemerooturl").'/generalfiles/';
}


$checkImage = getimagesize($imagePath);
if (!($checkImage === false || !in_array($checkImage[2], [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF]))) {
return ['filepath' => './files/'.$file['name'], 'filename'=>$file['name']];
return ['filepath' => $fileRoot.$file['name'], 'filename'=>$file['name']];
}
}

protected function getOptionPageAttributes()
{
$aData = $this->attributes;
$fileList = Template::getOtherFiles($this->filesPath);
$fileList = array_merge(Template::getOtherFiles($this->filesPath), Template::getOtherFiles($this->generalFilesPath));
$aData['maxFileSize'] = getMaximumFileUploadSize();
$aData['imageFileList'] = [];
foreach ($fileList as $file) {
$isImage = $this->_filterImages($file);

if ($isImage) {
$aData['imageFileList'][] = $isImage;
$aData['imageFileList'][] = $isImage;
}
};

Expand Down Expand Up @@ -797,10 +807,10 @@ protected function uninstallIncorectTheme($sTemplateName)
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;
$this->generalFilesPath = Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.'generalfiles'.DIRECTORY_SEPARATOR;
// Options are optional
$this->setOptions();

Expand Down
12 changes: 12 additions & 0 deletions upload/themes/survey/generalfiles/index.html
@@ -0,0 +1,12 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>LimeSurvey</title>
</head>
<body>
</body>
</html>



0 comments on commit a3d9f34

Please sign in to comment.