Skip to content

Commit

Permalink
New feature #11808: add template apiVersion and fix old template
Browse files Browse the repository at this point in the history
Dev: Start with api version 3 : follow LS version.
Dev: fix template according to API : for old : add needed pstpl file
Dev: add survey +fontawesome to template package (and add it if api < 3)
Dev: Todo : add an alert / log for admin user
  • Loading branch information
Shnoulle committed Nov 10, 2016
1 parent 40eb07d commit 1888b37
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
1 change: 0 additions & 1 deletion application/helpers/common_helper.php
Expand Up @@ -5636,7 +5636,6 @@ function getHeader($meta = false)
{
$languagecode = Yii::app()->getConfig('defaultlang');
}
App()->getClientScript()->registerPackage('fontawesome');
$header = "<!DOCTYPE html>\n";
$class = "no-js $languagecode";
$header .= "<html lang=\"{$languagecode}\"";
Expand Down
40 changes: 38 additions & 2 deletions application/models/TemplateConfiguration.php
Expand Up @@ -25,6 +25,7 @@ class TemplateConfiguration extends CFormModel
public $sTemplateName=''; // The template name
public $iSurveyId=''; // The current Survey Id. It can be void. It's use only to retreive the current template of a given survey
public $config; // Will contain the config.xml
public $apiVersion; // Version of the LS API when created

public $pstplPath; // Path of the pstpl files
public $viewPath; // Path of the views files (php files to replace existing core views)
Expand Down Expand Up @@ -93,7 +94,9 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')
$this->sTemplateName = 'default';
$this->isStandard = true;
$this->path = Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;
setGlobalSetting('defaulttemplate', 'default');
if(!$this->iSurveyId){
setGlobalSetting('defaulttemplate', 'default');
}
}

// If the template don't have a config file (maybe it has been deleted, or whatever),
Expand All @@ -120,6 +123,7 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')
}



//////////////////////
// Config file loading

Expand All @@ -132,13 +136,18 @@ public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')

// Template configuration
// Ternary operators test if configuration entry exists in the config file (to avoid PHP notice in user custom templates)
$this->apiVersion = (isset($this->config->metadatas->apiVersion)) ? $this->config->metadatas->apiVersion:0;

$this->pstplPath = (isset($this->config->engine->pstpldirectory)) ? $this->path.DIRECTORY_SEPARATOR.$this->config->engine->pstpldirectory.DIRECTORY_SEPARATOR : $this->path;
$this->viewPath = (isset($this->config->engine->viewdirectory)) ? $this->path.DIRECTORY_SEPARATOR.$this->config->engine->viewdirectory.DIRECTORY_SEPARATOR : '';

$this->siteLogo = (isset($this->config->files->logo)) ? $this->config->files->logo->filename : '';
$this->filesPath = (isset($this->config->engine->filesdirectory)) ? $this->path.DIRECTORY_SEPARATOR.$this->config->engine->filesdirectory.DIRECTORY_SEPARATOR : $this->path . '/files/';
$this->cssFramework = (isset($this->config->engine->cssframework)) ? $this->config->engine->cssframework : '';
$this->packages = (isset($this->config->engine->packages->package)) ? $this->config->engine->packages->package : array();
$this->packages = (isset($this->config->engine->packages->package)) ? (array) $this->config->engine->packages->package : array();

/* Add options/package according to apiVersion */
$this->fixTemplateByApi();

// overwrite_question_views accept different values : "true" or "yes"
$this->overwrite_question_views = (isset($this->config->engine->overwrite_question_views)) ? ($this->config->engine->overwrite_question_views=='true' || $this->config->engine->overwrite_question_views=='yes' ) : false;
Expand Down Expand Up @@ -261,4 +270,31 @@ private function setIsStandard()
return Template::isStandardTemplate($this->sTemplateName);
}

/**
* Fix template accorfing to apiVersion
*/
private function fixTemplateByApi()
{
if($this->apiVersion<3){
$this->packages[]= 'fontawesome';
$this->packages[]= 'limesurvey-public';
if(!is_file($this->pstplPath.DIRECTORY_SEPARATOR."message.pstpl")){
$messagePstpl = "<div id='{MESSAGEID}-wrapper'>\n"
. " {ERROR}\n"
. " <div class='{MESSAGEID}-text'>{MESSAGE}</div>\n"
. " {URL}"
. "</div>";
file_put_contents($this->pstplPath.DIRECTORY_SEPARATOR."message.pstpl",$messagePstpl);
}
if(!is_file($this->pstplPath.DIRECTORY_SEPARATOR."form.pstpl")){
$formTemplate = "<div class='{FORMID}-page'>\n"
. " <div class='form-heading'>{FORMHEADING}</div>\n"
. " {FORMMESSAGE}\n"
. " {FORMERROR}\n"
. " <div class='form-{FORMID}'>{FORM}</div>\n"
. "</div>";
file_put_contents($this->pstplPath.DIRECTORY_SEPARATOR."form.pstpl",$formTemplate);
}
}
}
}
1 change: 0 additions & 1 deletion application/views/layouts/public.php
Expand Up @@ -31,7 +31,6 @@
<?php
App()->clientScript->registerScript("nojsReplace","(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement);",CClientScript::POS_HEAD);
$oTemplate = Template::model()->getInstance($this->sTemplate);
App()->getClientScript()->registerPackage('fontawesome');
if($oTemplate->cssFramework == 'bootstrap')
{
Yii::app()->getClientScript()->registerMetaTag('width=device-width, initial-scale=1.0', 'viewport');
Expand Down
5 changes: 3 additions & 2 deletions templates/default/config.xml
Expand Up @@ -15,7 +15,8 @@
<authorUrl>http://www.limesurvey.org</authorUrl>
<copyright>Copyright (C) 2005 - 2016 LimeSurvey Gmbh, Inc. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later</license>
<version>1.0</version>
<version>2.0</version>
<apiVersion>3</apiVersion>
<description>Default LimeSurvey Template.</description>
<last_update>2016-11-07 23:59:00</last_update>
</metadatas>
Expand Down Expand Up @@ -110,7 +111,7 @@
<packages>
<package>jqueryui</package>
<package>jquery-touch-punch</package>
<!-- Add the limesurvey needed package. Without : no backwards-compatible for minor version -->
<package>fontawesome</package>
<package>limesurvey-public</package>
</packages>
</engine>
Expand Down
3 changes: 2 additions & 1 deletion templates/minimal-config.xml
Expand Up @@ -2,6 +2,7 @@
<config>
<metadatas>
<description>A pre 2.5 template.</description>
<apiVersion>0</apiVersion>
</metadatas>
<files>
<!-- Css used in different template from 2.05/06 -->
Expand All @@ -11,7 +12,7 @@
<filename>template.css</filename>
</css>
<js>
<filename>template.js</filename>
<filename>template.js</filename>
</js>
<rtl>
<css>
Expand Down

0 comments on commit 1888b37

Please sign in to comment.