Skip to content

Commit

Permalink
Dev: added relative path logic for template inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jun 28, 2017
1 parent 77c2dc9 commit 335092f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
47 changes: 28 additions & 19 deletions application/controllers/admin/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,32 +623,40 @@ public function templatesavechanges()
}
}

$action = returnGlobal('action');
$editfile = returnGlobal('editfile');
$sTemplateName = Template::templateNameFilter(App()->request->getPost('templatename'));
$screenname = returnGlobal('screenname');
$oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName);
$aScreenFiles = $oEditedTemplate->getValidScreenFiles("view");
$cssfiles = $oEditedTemplate->getValidScreenFiles("css");
$jsfiles = $oEditedTemplate->getValidScreenFiles("js");
$action = returnGlobal('action');
$editfile = returnGlobal('editfile');
$relativePathEditfile = returnGlobal('relativePathEditfile');
$sTemplateName = Template::templateNameFilter(App()->request->getPost('templatename'));
$screenname = returnGlobal('screenname');
$oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName);
$aScreenFiles = $oEditedTemplate->getValidScreenFiles("view");
$cssfiles = $oEditedTemplate->getValidScreenFiles("css");
$jsfiles = $oEditedTemplate->getValidScreenFiles("js");


if ($action == "templatesavechanges" && $changedtext){
Yii::app()->loadHelper('admin/template');
$changedtext = str_replace("\r\n", "\n", $changedtext);

if ($editfile){

if ($relativePathEditfile){
// Check if someone tries to submit a file other than one of the allowed filenames
if (
in_array($editfile,$aScreenFiles)===false &&
in_array($editfile,$cssfiles)===false &&
in_array($editfile,$jsfiles)===false
in_array($relativePathEditfile,$aScreenFiles)===false &&
in_array($relativePathEditfile,$cssfiles)===false &&
in_array($relativePathEditfile,$jsfiles)===false
){
Yii::app()->user->setFlash('error',gT('Invalid template name'));
$this->getController()->redirect(array("admin/templates/sa/upload"));
}

$savefilename = gettemplatefilename($sTemplateName, $editfile);

//$savefilename = $oEditedTemplate
if( !file_exists($oEditedTemplate->path.'/'.$relativePathEditfile) && !file_exists($oEditedTemplate->viewPath.$relativePathEditfile) ){
$oEditedTemplate->extendsFile($relativePathEditfile);
}

$savefilename = $oEditedTemplate->extendsFile($relativePathEditfile);

if (is_writable($savefilename)){

Expand Down Expand Up @@ -715,7 +723,7 @@ protected function _templatebar($screenname, $editfile, $screens, $tempdir, $tem
* @param array $myoutput
* @return void
*/
protected function _templatesummary($templatename, $screenname, $editfile, $templates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput)
protected function _templatesummary($templatename, $screenname, $editfile, $relativePathEditfile, $templates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput)
{
$tempdir = Yii::app()->getConfig("tempdir");
$tempurl = Yii::app()->getConfig("tempurl");
Expand Down Expand Up @@ -784,6 +792,7 @@ protected function _templatesummary($templatename, $screenname, $editfile, $temp
$filesdir = $oEditedTemplate->filesPath;
$aData['screenname'] = $screenname;
$aData['editfile'] = $editfile;
$aData['relativePathEditfile'] = $relativePathEditfile;
$aData['tempdir'] = $tempdir;
$aData['templatename'] = $templatename;
$aData['templates'] = $templates;
Expand Down Expand Up @@ -1106,7 +1115,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma

$myoutput = Yii::app()->twigRenderer->renderTemplateForTemplateEditor( $sLayoutFile,array('aSurveyInfo'=>$thissurvey), $oEditedTemplate);

$jsfiles = $oEditedTemplate->getValidScreenFiles("js");
$jsfiles = $oEditedTemplate->getValidScreenFiles("js");
$aCssAndJsfiles = array_merge($cssfiles,$jsfiles ) ;

// XML Behaviour: if only one file, then $files is just a string
Expand Down Expand Up @@ -1135,9 +1144,9 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
}

$editfile = (empty($editfile))?$sLayoutFile:$editfile;
$editfile = $oEditedTemplate->getFilePathForEdition($editfile, array_merge($files, $aCssAndJsfiles));
$sEditfile = $oEditedTemplate->getFilePathForEdition($editfile, array_merge($files, $aCssAndJsfiles));

$extension = substr(strrchr($editfile, "."), 1);
$extension = substr(strrchr($sEditfile, "."), 1);
$highlighter = 'html';
if ($extension == 'css' || $extension == 'js'){
$highlighter = $extension;
Expand All @@ -1149,7 +1158,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$aData['templatename'] = $templatename;
$aData['templateapiversion'] = $oEditedTemplate->getApiVersion();
$aData['templates'] = $aAllTemplates;
$aData['editfile'] = $editfile;
$aData['editfile'] = $sEditfile;
$aData['screenname'] = $screenname;
$aData['tempdir'] = Yii::app()->getConfig('tempdir');
$aData['usertemplaterootdir'] = Yii::app()->getConfig('usertemplaterootdir');
Expand All @@ -1158,7 +1167,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
if ($showsummary)
{
//$aCssfileseditable = (array) $oEditedTemplate->config->files_editable->css->filename;
$aViewUrls = array_merge($aViewUrls, $this->_templatesummary($templatename, $screenname, $editfile, $aAllTemplates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput));
$aViewUrls = array_merge($aViewUrls, $this->_templatesummary($templatename, $screenname, $sEditfile, $editfile, $aAllTemplates, $files, $cssfiles, $jsfiles, $otherfiles, $myoutput));
}

App()->getClientScript()->registerScriptFile( App()->getConfig('adminscripts') . 'admin_core.js');
Expand Down
1 change: 1 addition & 0 deletions application/views/admin/templates/templatesummary_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<?php echo CHtml::hiddenField('templatename', $templatename, array('class'=>'templatename'));
echo CHtml::hiddenField('screenname', $screenname, array('class'=>'screenname'));
echo CHtml::hiddenField('editfile', $editfile);
echo CHtml::hiddenField('relativePathEditfile', $relativePathEditfile);
echo CHtml::hiddenField('action', 'templatesavechanges');

echo CHtml::textArea('changes', (!empty($editfile))?file_get_contents($editfile):'',array('rows'=>'20',
Expand Down

0 comments on commit 335092f

Please sign in to comment.