Skip to content

Commit

Permalink
Fixed issue #6599 : Old custom templates incompatibility : replace te…
Browse files Browse the repository at this point in the history
…mplate.js by {TEMPLATEJS} when upload

Dev: add a private function _templateFixes($templatename)
Dev : update release_notes.txt , to do : update docs.limesurvey.org
  • Loading branch information
Shnoulle committed Oct 2, 2012
1 parent 76a7c59 commit e07579c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 4 deletions.
64 changes: 60 additions & 4 deletions application/controllers/admin/templates.php
Expand Up @@ -144,19 +144,26 @@ public function upload()
// Delete temporary folder
rmdir($extractdir);

if (count($aErrorFilesInfo) == 0 && count($aImportedFilesInfo) == 0)
$this->getController()->error($clang->gT("This ZIP archive contains no valid template files. Import failed."));
if (count($aErrorFilesInfo) == 0 && count($aImportedFilesInfo) == 0)
$this->getController()->error($clang->gT("This ZIP archive contains no valid template files. Import failed."));
}
else
$this->getController()->error(sprintf($clang->gT("An error occurred uploading your file. This may be caused by incorrect permissions in your %s folder."), $basedestdir));


if (count($aImportedFilesInfo) > 0)
{
$templateFixes= $this->_templateFixes($newdir);
}
else
{
$templateFixes= array();
}
$aViewUrls = 'importuploaded_view';
$aData = array(
'aImportedFilesInfo' => $aImportedFilesInfo,
'aErrorFilesInfo' => $aErrorFilesInfo,
'lid' => $lid,
'newdir' => $newdir,
'templateFixes' => $templateFixes,
);
}
else
Expand All @@ -167,6 +174,53 @@ public function upload()

$this->_renderWrappedTemplate('templates', $aViewUrls, $aData);
}
/**
* Try to correct a template with new funcyionnality.
*
* @access private
* @param string $templatename
* @return array $correction ($success,$number,array($information))
*/

private function _templateFixes($templatename)
{
$clang = $this->getController()->lang;
$usertemplaterootdir=Yii::app()->getConfig("usertemplaterootdir");
$templateFixes=array();
$templateFixes['success']=true;
$templateFixes['details']=array();
// TEMPLATEJS control
$fname="$usertemplaterootdir/$templatename/startpage.pstpl";
if(is_file($fname))
{

$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));
if(strpos($content, "{TEMPLATEJS}")===false)
{
$content = str_replace("<script type=\"text/javascript\" src=\"{TEMPLATEURL}template.js\"></script>", "{TEMPLATEJS}", $content);
$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
fclose($fhandle);
if(strpos($content, "{TEMPLATEJS}")===false)
{
$templateFixes['success']=false;
$templateFixes['details']['templatejs']="Unable to adding {TEMPLATEJS} placeholder, please control your startpage.pstpl.";
}
else
{
$templateFixes['details']['templatejs']="Placeholder {TEMPLATEJS} added to your startpage.pstpl.";
}
}
}
else
{
$templateFixes['success']=false;
$templateFixes['details']['templatejs']="Unable to find startpage.pstpl to add {TEMPLATEJS} placeholder, please control your template.";
}
return $templateFixes;
}

/**
* Responsible to import a template file.
*
Expand Down Expand Up @@ -218,6 +272,7 @@ public function uploadfile()
}
$this->getController()->redirect(array("admin/templates/view/editfile/" . $editfile . "/screenname/" . $screenname . "/templatename/" . $templatename));
}

/**
* Generates a random temp directory
*
Expand Down Expand Up @@ -867,6 +922,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$aData['notanswered'] = $notanswered;
$aData['privacy'] = $privacy;
$aData['surveyid'] = $surveyid;
$aData['sid'] = $surveyid;
$aData['token'] = $token;
$aData['assessments'] = $assessments;
$aData['printoutput'] = $printoutput;
Expand Down
32 changes: 32 additions & 0 deletions application/views/admin/templates/importuploaded_view.php
Expand Up @@ -61,5 +61,37 @@
}
?>
</ul>
<?php
if(count($templateFixes['details'])>0)
{
?>
<br />
<div class="header"><?php $clang->eT("Template fixes summary") ?></div>
<?php
if(!$templateFixes['success'])
{
$status = $clang->gT("Error");
$statusClass = 'warningheader';
}
else
{
$status = $clang->gT("Success");
$statusClass = 'successheader';
}
?>
<div class="<?php echo $statusClass ?>"><?php echo $status ?></div>
<ul>
<?php
foreach ($templateFixes['details'] as $detail)
{
?>
<li><?php echo $detail ?></li>
<?php
}
?>
</ul>
<?php
}
?>
<input type='submit' value='<?php $clang->eT("Open imported template") ?>' onclick="window.open('<?php echo $this->createUrl('admin/templates/view/editfile/startpage.pstpl/screenname/welcome/templatename/' . $newdir) ?>', '_top')" />
</div>
6 changes: 6 additions & 0 deletions docs/release_notes.txt
Expand Up @@ -45,6 +45,12 @@ HOW TO UPGRADE from LimeSurvey 1.50 or later (<=1.70)
It is usually easier to customize a default templates, again, instead of fixing your old template!
8. Done.

TEMPLATE modification between LimeSurvey 1.8
------------------------------------------------------
LimeSurvey 2 use a new placeholder for javascript inclusion: {TEMPLATEJS}.
Old template can be incompatible with the new javascript inclusion system. LimeSurvey need a placeholder to include js file for public survey.
The update process and the template upload process try to update your template. If there are javascript issue with your custom template, control you have the placeholder {TEMPLACEJS} in your starpage.pstpl.

Thank you to everyone who helped with this new release!


Expand Down

0 comments on commit e07579c

Please sign in to comment.