-
Notifications
You must be signed in to change notification settings - Fork 988
/
TemplateConfiguration.php
648 lines (536 loc) · 28.3 KB
/
TemplateConfiguration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2015 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
/**
* Template Configuration Model
*
* This model retrieves all the data of template configuration from the configuration file
*
* @package LimeSurvey
* @subpackage Backend
*/
class TemplateConfiguration extends CFormModel
{
/** @var string $sTemplateName The template name */
public $sTemplateName='';
/** @var string $sPackageName Name of the asset package of this template*/
public $sPackageName;
/** @var string $siteLogo Name of the logo file (like: logo.png) */
public $siteLogo;
/** @var string $path Path of this template */
public $path;
/** @var string[] $sTemplateurl Url to reach the framework */
public $sTemplateurl;
/** @var string $viewPath Path of the views files (twig template) */
public $viewPath;
/** @var string $filesPath Path of the tmeplate's files */
public $filesPath;
/** @var string[] $cssFramework What framework css is used */
public $cssFramework;
/** @var boolean $isStandard Is this template a core one? */
public $isStandard;
/** @var SimpleXMLElement $config Will contain the config.xml */
public $config;
/** @var TemplateConfiguration $oMotherTemplate The template name */
public $oMotherTemplate;
public $templateEditor;
/** @var string $iSurveyId The current Survey Id. It can be void. It's use only to retreive the current template of a given survey */
private $iSurveyId='';
/** @var string $hasConfigFile Does it has a config.xml file? */
private $hasConfigFile='';//
/** @var stdClass[] $packages Array of package dependencies defined in config.xml*/
private $packages;
/** @var string[] $depends List of all dependencies (could be more that just the config.xml packages) */
private $depends = array();
/** @var string $xmlFile What xml config file does it use? (config/minimal) */
private $xmlFile;
/** @var integer $apiVersion: Version of the LS API when created. Must be private : disallow update */
private $apiVersion;
/**
* Constructs a template configuration object
* If any problem (like template doesn't exist), it will load the default template configuration
*
* @param string $sTemplateName the name of the template to load. The string comes from the template selector in survey settings
* @param string $iSurveyId the id of the survey. If
* @return $this
*/
public function setTemplateConfiguration($sTemplateName='', $iSurveyId='')
{
$this->setTemplateName($sTemplateName, $iSurveyId); // Check and set template name
$this->setIsStandard(); // Check if it is a CORE template
$this->setPath(); // Check and set path
$this->readManifest(); // Check and read the manifest to set local params
$this->setMotherTemplates(); // Recursive mother templates configuration
$this->setThisTemplate(); // Set the main config values of this template
$this->createTemplatePackage($this); // Create an asset package ready to be loaded
return $this;
}
/**
* Update the configuration file "last update" node.
* For now, it is called only from template editor
*/
public function actualizeLastUpdate()
{
$date = date("Y-m-d H:i:s");
$config = simplexml_load_file(realpath ($this->xmlFile));
$config->metadatas->last_update = $date;
$config->asXML( realpath ($this->xmlFile) ); // Belt
touch ( $this->path ); // & Suspenders ;-)
}
/**
* get the template API version
* @return integer
*/
public function getApiVersion()
{
return $this->apiVersion;
}
/**
* This function returns the complete URL path to a given template name
*
* @param string $sTemplateName
* @return string template url
*/
public function getTemplateURL()
{
if(!isset($this->sTemplateurl)){
$this->sTemplateurl = Template::getTemplateURL($this->sTemplateName);
}
return $this->sTemplateurl;
}
/**
* Used from the template editor.
* It returns an array of editable files by screen for a given file type
*
* @param string $sType the type of files (view/css/js)
* @param string $sScreen the screen you want to retreive the files from. If null: all screens
* @return array array ( [screen name] => array([files]) )
*/
public function getValidScreenFiles($sType = "view", $sScreen=null)
{
$aScreenFiles = array();
$filesFromXML = (is_null($sScreen)) ? (array) $this->templateEditor->screens->xpath('//file') : $this->templateEditor->screens->xpath('//'.$sScreen.'/file');
foreach( $filesFromXML as $file){
if ( $file->attributes()->type == $sType ){
$aScreenFiles[] = (string) $file;
}
}
$aScreenFiles = array_unique($aScreenFiles);
return $aScreenFiles;
}
/**
* Returns the layout file name for a given screen
*
* @param string $sScreen the screen you want to retreive the files from. If null: all screens
* @return string the file name
*/
public function getLayoutForScreen($sScreen)
{
$filesFromXML = $this->templateEditor->screens->xpath('//'.$sScreen.'/file');
foreach( $filesFromXML as $file){
if ( $file->attributes()->role == "layout" ){
return (string) $file;
}
}
return false;
}
/**
* Retreives the absolute path for a file to edit (current template, mother template, etc)
* Also perform few checks (permission to edit? etc)
*
* @param string $sfile relative path to the file to edit
*/
public function getFilePathForEdition($sFile, $aAllowedFiles=null)
{
// Check if the file is allowed for edition ($aAllowedFiles is produced via getValidScreenFiles() )
if (is_array($aAllowedFiles)){
if (!in_array($sFile, $aAllowedFiles)){
return false;
}
}
return $this->getFilePath($sFile, $this);
}
public function extendsFile($sFile)
{
if( !file_exists($this->path.'/'.$sFile) && !file_exists($this->viewPath.$sFile) ){
// Copy file from mother template to local directory
$sRfilePath = $this->getFilePath($sFile, $this);
$sLfilePath = (pathinfo($sFile, PATHINFO_EXTENSION) == 'twig')?$this->viewPath.$sFile:$this->path.'/'.$sFile;
copy ( $sRfilePath, $sLfilePath );
}
return $this->getFilePath($sFile, $this);
}
/**
* This function will update the config file of a given template so that it extends another one
*
* It will:
* 1. Delete files and engine nodes
* 2. Update the name of the template
* 3. Change the creation/modification date to the current date
* 4. Change the autor name to the current logged in user
* 5. Change the author email to the admin email
*
* Used in template editor
* Both templates and configuration files must exist before using this function
*
* It's used when extending a template from template editor
* @param string $sToExtends the name of the template to extend
* @param string $sNewName the name of the new template
*/
static public function extendsConfig($sToExtends, $sNewName)
{
$sConfigPath = Yii::app()->getConfig('usertemplaterootdir') . "/" . $sNewName;
// First we get the XML file
libxml_disable_entity_loader(false);
$oNewManifest = new DOMDocument();
$oNewManifest->load($sConfigPath."/config.xml");
$oConfig = $oNewManifest->getElementsByTagName('config')->item(0);
// Then we delete the nodes that should be inherit
$aNodesToDelete = array();
$aNodesToDelete[] = $oConfig->getElementsByTagName('files')->item(0);
$aNodesToDelete[] = $oConfig->getElementsByTagName('engine')->item(0);
foreach($aNodesToDelete as $node){
$oConfig->removeChild($node);
}
// We replace the name by the new name
$oMetadatas = $oConfig->getElementsByTagName('metadatas')->item(0);
$oOldNameNode = $oMetadatas->getElementsByTagName('name')->item(0);
$oNvNameNode = $oNewManifest->createElement('name', $sNewName);
$oMetadatas->replaceChild($oNvNameNode, $oOldNameNode);
// We change the date
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$oOldDateNode = $oMetadatas->getElementsByTagName('creationDate')->item(0);
$oNvDateNode = $oNewManifest->createElement('creationDate', $today);
$oMetadatas->replaceChild($oNvDateNode, $oOldDateNode);
$oOldUpdateNode = $oMetadatas->getElementsByTagName('last_update')->item(0);
$oNvDateNode = $oNewManifest->createElement('last_update', $today);
$oMetadatas->replaceChild($oNvDateNode, $oOldUpdateNode);
// We change the author name
$oOldAuthorNode = $oMetadatas->getElementsByTagName('author')->item(0);
$oNvAuthorNode = $oNewManifest->createElement('author', Yii::app()->user->name);
$oMetadatas->replaceChild($oNvAuthorNode, $oOldAuthorNode);
// We change the author email
$oOldMailNode = $oMetadatas->getElementsByTagName('authorEmail')->item(0);
$oNvMailNode = $oNewManifest->createElement('authorEmail', htmlspecialchars(getGlobalSetting('siteadminemail')));
$oMetadatas->replaceChild($oNvMailNode, $oOldMailNode);
// TODO: provide more datas in the post variable such as description, url, copyright, etc
// We add the extend parameter
$oExtendsNode = $oNewManifest->createElement('extends', $sToExtends);
// We test if mother template already extends another template
if(!empty($oMetadatas->getElementsByTagName('extends')->item(0))){
$oMetadatas->replaceChild($oExtendsNode, $oMetadatas->getElementsByTagName('extends')->item(0));
}else{
$oMetadatas->appendChild($oExtendsNode);
}
$oNewManifest->save($sConfigPath."/config.xml");
libxml_disable_entity_loader(true);
}
/**
* Create a package for the asset manager.
* The asset manager will push to tmp/assets/xyxyxy/ the whole template directory (with css, js, files, etc.)
* And it will publish the CSS and the JS defined in config.xml. So CSS can use relative path for pictures.
* The publication of the package itself is in LSETwigViewRenderer::renderTemplateFromString()
*
*/
private function createTemplatePackage($oTemplate)
{
// Each template in the inheritance tree needs a specific alias
$sPathName = 'survey.template-'.$oTemplate->sTemplateName.'.path';
$sViewName = 'survey.template-'.$oTemplate->sTemplateName.'.viewpath';
Yii::setPathOfAlias($sPathName, $oTemplate->path);
Yii::setPathOfAlias($sViewName, $oTemplate->viewPath);
$aCssFiles = isset($oTemplate->config->files->css->filename)?(array) $oTemplate->config->files->css->filename:array(); // The CSS files of this template
$aJsFiles = isset($oTemplate->config->files->js->filename)? (array) $oTemplate->config->files->js->filename:array(); // The JS files of this template
$dir = getLanguageRTL(App()->language) ? 'rtl' : 'ltr';
// Remove/Replace mother files
$aCssFiles = $this->changeMotherConfiguration('css', $aCssFiles);
$aJsFiles = $this->changeMotherConfiguration('js', $aJsFiles);
if (isset($oTemplate->config->files->$dir)) {
$aCssFilesDir = isset($oTemplate->config->files->$dir->css->filename) ? (array) $oTemplate->config->files->$dir->css->filename : array();
$aJsFilesDir = isset($oTemplate->config->files->$dir->js->filename) ? (array) $oTemplate->config->files->$dir->js->filename : array();
$aCssFiles = array_merge($aCssFiles,$aCssFilesDir);
$aJsFiles = array_merge($aJsFiles,$aJsFilesDir);
}
if (Yii::app()->getConfig('debug') == 0) {
Yii::app()->clientScript->registerScriptFile( Yii::app()->getConfig("generalscripts"). 'deactivatedebug.js', CClientScript::POS_END);
}
$this->sPackageName = 'survey-template-'.$this->sTemplateName;
$sTemplateurl = $oTemplate->getTemplateURL();
// The package "survey-template-{sTemplateName}" will be available from anywhere in the app now.
// To publish it : Yii::app()->clientScript->registerPackage( 'survey-template-{sTemplateName}' );
// Depending on settings, it will create the asset directory, and publish the css and js files
Yii::app()->clientScript->addPackage( $this->sPackageName, array(
'devBaseUrl' => $sTemplateurl, // Used when asset manager is off
'basePath' => $sPathName, // Used when asset manager is on
'css' => $aCssFiles,
'js' => $aJsFiles,
'depends' => $oTemplate->depends,
) );
}
/**
* Change the mother template configuration depending on template settings
* @var $sType string the type of settings to change (css or js)
* @var $aSettings array array of local setting
* @return array
*/
private function changeMotherConfiguration( $sType, $aSettings )
{
foreach( $aSettings as $key => $aSetting){
if (!empty($aSetting['replace']) || !empty($aSetting['remove'])){
Yii::app()->clientScript->removeFileFromPackage($this->oMotherTemplate->sPackageName, $sType, $aSetting['replace'] );
unset($aSettings[$key]);
}
}
return $aSettings;
}
/**
* Read the config.xml file of the template and push its contents to $this->config
*/
private function readManifest()
{
$this->xmlFile = $this->path.DIRECTORY_SEPARATOR.'config.xml';
$bOldEntityLoaderState = libxml_disable_entity_loader(true); // @see: http://phpsecurity.readthedocs.io/en/latest/Injection-Attacks.html#xml-external-entity-injection
$sXMLConfigFile = file_get_contents( realpath ($this->xmlFile)); // @see: Now that entity loader is disabled, we can't use simplexml_load_file; so we must read the file with file_get_contents and convert it as a string
$this->config = simplexml_load_string($sXMLConfigFile); // Using PHP >= 5.4 then no need to decode encode + need attributes : then other function if needed :https://secure.php.net/manual/en/book.simplexml.php#108688 for example
libxml_disable_entity_loader($bOldEntityLoaderState); // Put back entity loader to its original state, to avoid contagion to other applications on the server
}
/**
* Configure the mother template (and its mother templates)
* This is an object recursive call to TemplateConfiguration::setTemplateConfiguration()
*/
private function setMotherTemplates()
{
if (isset($this->config->metadatas->extends)){
$sMotherTemplateName = (string) $this->config->metadatas->extends;
$this->oMotherTemplate = new TemplateConfiguration;
$this->oMotherTemplate->setTemplateConfiguration($sMotherTemplateName); // Object Recursion
}
}
/**
* Set the path of the current template
* It checks if it's a core or a user template, if it exists, and if it has a config file
*/
private function setPath()
{
// If the template is standard, its root is based on standardtemplaterootdir, else, it is a user template, its root is based on usertemplaterootdir
$this->path = ($this->isStandard)?Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName:Yii::app()->getConfig("usertemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;
// If the template directory doesn't exist, we just set Default as the template to use
// TODO: create a method "setToDefault"
if (!is_dir($this->path)) {
$this->sTemplateName = 'default';
$this->isStandard = true;
$this->path = Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;
if(!$this->iSurveyId){
setGlobalSetting('defaulttemplate', 'default');
}
}
// If the template doesn't have a config file (maybe it has been deleted, or whatever),
// then, we load the default template
$this->hasConfigFile = (string) is_file($this->path.DIRECTORY_SEPARATOR.'config.xml');
if (!$this->hasConfigFile) {
$this->path = Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.$this->sTemplateName;
}
}
/**
* Set the template name.
* If no templateName provided, then a survey id should be given (it will then load the template related to the survey)
*
* @var $sTemplateName string the name of the template
* @var $iSurveyId int the id of the survey
*/
private function setTemplateName($sTemplateName='', $iSurveyId='')
{
// If it is called from the template editor, a template name will be provided.
// If it is called for survey taking, a survey id will be provided
if ($sTemplateName == '' && $iSurveyId == '') {
/* Some controller didn't test completely survey id (PrintAnswersController for example), then set to default here */
$sTemplateName = Template::templateNameFilter(Yii::app()->getConfig('defaulttemplate','default'));
}
$this->sTemplateName = $sTemplateName;
$this->iSurveyId = (int) $iSurveyId;
if ($sTemplateName == '') {
$oSurvey = Survey::model()->findByPk($iSurveyId);
if($oSurvey) {
$this->sTemplateName = $oSurvey->template;
} else {
$this->sTemplateName = Template::templateNameFilter(App()->getConfig('defaulttemplate','default'));
}
}
}
/**
* Set the default configuration values for the template, and use the motherTemplate value if needed
*/
private function setThisTemplate()
{
// Mandtory setting in config XML (can be not set in inheritance tree, but must be set in mother template (void value is still a setting))
$this->apiVersion = (isset($this->config->metadatas->apiVersion)) ? $this->config->metadatas->apiVersion : $this->oMotherTemplate->apiVersion;
$this->viewPath = (!empty($this->config->xpath("//viewdirectory"))) ? $this->path.DIRECTORY_SEPARATOR.$this->config->engine->viewdirectory.DIRECTORY_SEPARATOR : $this->path.DIRECTORY_SEPARATOR.$this->oMotherTemplate->config->engine->viewdirectory.DIRECTORY_SEPARATOR;
$this->filesPath = (!empty($this->config->xpath("//filesdirectory"))) ? $this->path.DIRECTORY_SEPARATOR.$this->config->engine->filesdirectory.DIRECTORY_SEPARATOR : $this->path.DIRECTORY_SEPARATOR.$this->oMotherTemplate->config->engine->filesdirectory.DIRECTORY_SEPARATOR;
$this->templateEditor = (!empty($this->config->xpath("//template_editor"))) ? $this->config->engine->template_editor : $this->oMotherTemplate->templateEditor;
$this->siteLogo = (!empty($this->config->xpath("//logo"))) ? $this->config->files->logo->filename : $this->oMotherTemplate->siteLogo;
// Not mandatory (use package dependances)
$this->cssFramework = (!empty($this->config->xpath("//cssframework"))) ? $this->config->engine->cssframework : '';
$this->packages = (!empty($this->config->xpath("//packages"))) ? $this->config->engine->packages : array();
// Add depend package according to packages
$this->depends = array_merge($this->depends, $this->getDependsPackages($this));
}
/**
* @return bool
*/
private function setIsStandard()
{
$this->isStandard = Template::isStandardTemplate($this->sTemplateName);
}
/**
* Get the depends package
* @uses self::@package
* @return string[]
*/
private function getDependsPackages($oTemplate)
{
/* Start by adding cssFramework package */
$packages = $this->getFrameworkPackages($oTemplate);
if (!getLanguageRTL(App()->getLanguage())) {
$packages = array_merge ($packages, $this->getFrameworkPackages($oTemplate, 'ltr'));
} else {
$packages = array_merge ($packages, $this->getFrameworkPackages($oTemplate, 'rtl'));
}
/* Core package */
$packages[]='limesurvey-public';
/* template packages */
if (!empty($this->packages->package)) {
$packages = array_merge ($packages, (array)$this->packages->package);
}
/* Adding rtl/tl specific package (see https://bugs.limesurvey.org/view.php?id=11970#c42317 ) */
$dir = getLanguageRTL(App()->language) ? 'rtl' : 'ltr';
if (!empty($this->packages->$dir->package)) {
$packages = array_merge ($packages, (array)$this->packages->$dir->package);
}
if (isset($this->config->metadatas->extends)){
$sMotherTemplateName = (string) $this->config->metadatas->extends;
$packages[] = 'survey-template-'.$sMotherTemplateName;
}
return $packages;
}
/**
* Set the framework package
* @param string $dir (rtl|ltr|)
* @use self::@cssFramework
* @return string[] depends for framework
*/
private function getFrameworkPackages($oTemplate, $dir="")
{
// If current template doesn't have a name for the framework package, we use the mother's one
$framework = isset($oTemplate->cssFramework->name) ? (string) $oTemplate->cssFramework->name : (string) $oTemplate->oMotherTemplate->cssFramework;
$framework = $dir ? $framework."-".$dir : $framework;
if ( isset(Yii::app()->clientScript->packages[$framework]) ) {
$frameworkPackages = array();
/* Theming */
if ($dir) {
$cssFrameworkCsss = isset ( $oTemplate->cssFramework->$dir->css ) ? $oTemplate->cssFramework->$dir->css : array();
$cssFrameworkJss = isset ( $oTemplate->cssFramework->$dir->js ) ? $oTemplate->cssFramework->$dir->js : array();
} else {
$cssFrameworkCsss = isset ( $oTemplate->cssFramework->css ) ? $oTemplate->cssFramework->css : array();
$cssFrameworkJss = isset ( $oTemplate->cssFramework->js ) ? $oTemplate->cssFramework->js : array();
}
if (empty($cssFrameworkCsss) && empty($cssFrameworkJss)) {
$frameworkPackages[] = $framework;
} else {
$cssFrameworkPackage = Yii::app()->clientScript->packages[$framework]; // Need to create an adapted core framework
$packageCss = array(); // Need to create an adapted template/theme framework */
$packageJs = array(); // css file to replace from default package */
$cssDelete = array();
foreach($cssFrameworkCsss as $cssFrameworkCss) {
if(isset($cssFrameworkCss['replace'])) {
$cssDelete[] = $cssFrameworkCss['replace'];
}
if((string)$cssFrameworkCss) {
$packageCss[] = (string) $cssFrameworkCss;
}
}
if(isset($cssFrameworkPackage['css'])) {
$cssFrameworkPackage['css']=array_diff($cssFrameworkPackage['css'],$cssDelete);
}
$jsDelete=array();
foreach($cssFrameworkJss as $cssFrameworkJs) {
if(isset($cssFrameworkJs['replace'])) {
$jsDelete[] = $cssFrameworkJs['replace'];
}
if((string)$cssFrameworkJs) {
$packageJs[] = (string)$cssFrameworkJs;
}
}
if(isset($cssFrameworkPackage['js'])) {
$cssFrameworkPackage['js'] = array_diff($cssFrameworkPackage['js'],$cssDelete);
}
/* And now : we add : core package fixed + template/theme package */
Yii::app()->clientScript->packages[$framework] = $cssFrameworkPackage; /* @todo : test if empty css and js : just add depends if yes */
$aDepends=array(
$framework,
);
$sTemplateurl = $oTemplate->getTemplateURL();
$sPathName = 'survey.template-'.$oTemplate->sTemplateName.'.path';
Yii::app()->clientScript->addPackage(
$framework.'-template', array(
'devBaseUrl' => $sTemplateurl, // Don't use asset manager
'basePath' => $sPathName, // basePath: the asset manager will be used
'css' => $packageCss,
'js' => $packageJs,
'depends' => $aDepends,
)
);
$frameworkPackages[]=$framework.'-template';
}
return $frameworkPackages;
}/*elseif($framework){
throw error ? Only for admin template editor ? disable and reset to default ?
}*/
return array();
}
private function getTemplateForFile($sFile, $oRTemplate)
{
while (!file_exists($oRTemplate->path.'/'.$sFile) && !file_exists($oRTemplate->viewPath.$sFile)){
$oMotherTemplate = $oRTemplate->oMotherTemplate;
if(!($oMotherTemplate instanceof TemplateConfiguration)){
return false;
break;
}
$oRTemplate = $oMotherTemplate;
}
return $oRTemplate;
}
/**
* Get the file path for a given template.
* It will check if css/js (relative to path), or view (view path)
* It will search for current template and mother templates
*
* @param string $sFile relative path to the file
* @param string $oTemplate the template where to look for (and its mother templates)
*/
private function getFilePath($sFile, $oTemplate)
{
// Remove relative path
$sFile = trim($sFile, '.');
$sFile = trim($sFile, '/');
// Retreive the correct template for this file (can be a mother template)
$oTemplate = $this->getTemplateForFile($sFile, $oTemplate);
if($oTemplate instanceof TemplateConfiguration){
if(file_exists($oTemplate->path.'/'.$sFile)){
return $oTemplate->path.'/'.$sFile;
}elseif(file_exists($oTemplate->viewPath.$sFile)){
return $oTemplate->viewPath.$sFile;
}
}
return false;
}
}