diff --git a/application/controllers/admin/themes.php b/application/controllers/admin/themes.php index d7967bbec21..1ef6bfe9698 100755 --- a/application/controllers/admin/themes.php +++ b/application/controllers/admin/themes.php @@ -107,6 +107,7 @@ public function upload() $uploadresult = ""; $success = false; $debug = []; + if ($action == 'templateuploadimagefile') { // $iTemplateConfigurationId = Yii::app()->request->getPost('templateconfig'); // $oTemplateConfiguration = TemplateConfiguration::getInstanceFromConfigurationId($iTemplateConfigurationId); @@ -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; diff --git a/application/core/LS_Twig_Extension.php b/application/core/LS_Twig_Extension.php index 4a4d359f7cc..3db979ba12c 100644 --- a/application/core/LS_Twig_Extension.php +++ b/application/core/LS_Twig_Extension.php @@ -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); } @@ -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; diff --git a/application/models/TemplateConfiguration.php b/application/models/TemplateConfiguration.php index 294787d7fe0..a1b571e0e6a 100755 --- a/application/models/TemplateConfiguration.php +++ b/application/models/TemplateConfiguration.php @@ -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 @@ -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; } }; @@ -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(); diff --git a/upload/themes/survey/generalfiles/index.html b/upload/themes/survey/generalfiles/index.html new file mode 100644 index 00000000000..aa4602772ae --- /dev/null +++ b/upload/themes/survey/generalfiles/index.html @@ -0,0 +1,12 @@ + + + + +LimeSurvey + + + + + + +