Skip to content

Commit

Permalink
Dev: remove rtl from config.xml (not needed)
Browse files Browse the repository at this point in the history
Dev: rtl and ltr are optionnable
Dev: Old default have issue with rtl (double loading)
  • Loading branch information
Shnoulle committed Dec 20, 2016
1 parent 8b38afd commit 0f3a1d5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 84 deletions.
41 changes: 17 additions & 24 deletions application/helpers/replacements_helper.php
Expand Up @@ -139,43 +139,36 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$aOtherFiles = $oTemplate->otherFiles;

//var_dump($aCssFiles);var_dump($aJsFiles);die();
$aCssFiles = (array) $oTemplate->config->files->css->filename;
$aJsFiles = (array) $oTemplate->config->files->js->filename;

/* RTL CSS & JS */
if (getLanguageRTL(App()->language))
foreach($aCssFiles as $sCssFile)
{
$aCssFiles = (array) $oTemplate->config->files->rtl->css->filename;
$aJsFiles = (array) $oTemplate->config->files->rtl->js->filename;

foreach($aCssFiles as $sCssFile)
if (file_exists($oTemplate->path .DIRECTORY_SEPARATOR. $sCssFile))
{
if (file_exists($oTemplate->path .DIRECTORY_SEPARATOR. $sCssFile))
{
Yii::app()->getClientScript()->registerCssFile("{$templateurl}$sCssFile");
}
Yii::app()->getClientScript()->registerCssFile("{$templateurl}$sCssFile");
}

foreach($aJsFiles as $sJsFile)
}
foreach($aJsFiles as $sJsFile)
{
if (file_exists($oTemplate->path .DIRECTORY_SEPARATOR. $sJsFile))
{
if (file_exists($oTemplate->path .DIRECTORY_SEPARATOR. $sJsFile))
{
Yii::app()->getClientScript()->registerScriptFile("{$templateurl}$sJsFile");
}
Yii::app()->getClientScript()->registerScriptFile("{$templateurl}$sJsFile");
}
}
else
{
$aCssFiles = (array) $oTemplate->config->files->css->filename;
$aJsFiles = (array) $oTemplate->config->files->js->filename;

foreach($aCssFiles as $sCssFile)
/* RTL|LTR CSS & JS */
$dir=getLanguageRTL(App()->language) ? 'rtl' : 'ltr';
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();
foreach($aCssFilesDir as $sCssFile)
{
if (file_exists($oTemplate->path .DIRECTORY_SEPARATOR. $sCssFile))
{
Yii::app()->getClientScript()->registerCssFile("{$templateurl}$sCssFile");
}
}

foreach($aJsFiles as $sJsFile)
foreach($aJsFilesDir as $sJsFile)
{
if (file_exists($oTemplate->path .DIRECTORY_SEPARATOR. $sJsFile))
{
Expand Down
63 changes: 24 additions & 39 deletions application/models/TemplateConfiguration.php
Expand Up @@ -203,41 +203,32 @@ private function createTemplatePackage()
Yii::setPathOfAlias('survey.template.path', $this->path); // The package creation/publication need an alias
Yii::setPathOfAlias('survey.template.viewpath', $this->viewPath);

$oCssFiles = $this->config->files->css->filename; // The CSS files of this template
$oJsFiles = $this->config->files->js->filename; // The JS files of this template

if (getLanguageRTL(App()->language))
{
$oCssFiles = $this->config->files->rtl->css->filename; // In RTL mode, original CSS files should not be loaded, else padding-left could be added to padding-right.)
$oJsFiles = $this->config->files->rtl->js->filename; // In RTL mode,
$aCssFiles = (array)$this->config->files->css->filename; // The CSS files of this template
$aJsFiles = (array)$this->config->files->js->filename; // The JS files of this template
$dir=getLanguageRTL(App()->language) ? 'rtl' : 'ltr';
if (isset($this->config->files->$dir)){
$aCssFilesDir = isset($this->config->files->$dir->css->filename) ? (array)$this->config->files->$dir->css->filename : array();
$aJsFilesDir = isset($this->config->files->$dir->js->filename) ? (array)$this->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()->baseUrl . '/scripts/deactivatedebug.js', CClientScript::POS_END);
}

$aCssFiles = (array) $oCssFiles;
$aJsFiles = (array) $oJsFiles;


// The package "survey-template" will be available from anywhere in the app now.
// To publish it : Yii::app()->clientScript->registerPackage( 'survey-template' );
// It will create the asset directory, and publish the css and js files
/* @todo : excludeFiles to exlude views and pstpl directory : seem not included in package system */
//~ if(trim($this->config->engine->pstpldirectory,".")){/* not needed */
//~ Yii::app()->assetManager->excludeFiles[]="/".$this->config->engine->pstpldirectory;
//~ }
//~ if($this->config->engine->pstpldirectory){/* think asset directory must not get PHP files */
//~ Yii::app()->assetManager->excludeFiles[]="/".$this->config->engine->viewdirectory;
//~ }
/* @todo : using assets directory ? */
Yii::app()->clientScript->addPackage( 'survey-template', array(
'basePath' => 'survey.template.path',
'css' => $aCssFiles,
'js' => $aJsFiles,
'depends' => $this->depends,
) );

tracevar(Yii::app()->clientScript->packages['survey-template']);
}

/**
Expand Down Expand Up @@ -312,7 +303,7 @@ private function fixTemplateByApi()

/**
* Get the depends package
* @uses $this->package
* @uses self::@package
*/
private function getDependsPackages()
{
Expand All @@ -324,34 +315,26 @@ private function getDependsPackages()
}else{
$packages=array_merge ($packages,$this->getFrameworkPackages('rtl'));
}

/* Core package */
$packages[]='limesurvey-public';

/* template packages */
if(!empty($this->packages->package)){
foreach((array)$this->packages->package as $package){
$packages[]=(string)$package;
}
$packages=array_merge ($packages,(array)$this->packages->package);
}
/* Adding rtl/tl specific package (see https://bugs.limesurvey.org/view.php?id=11970#c42317 ) */
/* better to use attribute of a xml file, but we broke attribute due to dumb server (5.3 PHP version ....) */
/* see https://github.com/LimeSurvey/LimeSurvey/commit/e5268c72ade2eee1ac10f1594815686774f6eb86 */
if(!getLanguageRTL(App()->getLanguage())){
if(!empty($this->packages->ltr->package)){
foreach((array)$this->packages->ltr->package as $package){
$packages[]=(string)$package;
}
}
}else{
if(!empty($this->packages->rtl->package)){
foreach((array)$this->packages->rtl->package as $package){
$packages[]=(string)$package;
}
}
$dir=getLanguageRTL(App()->language) ? 'rtl' : 'ltr';
if(!empty($this->packages->$dir->package)){
$packages=array_merge ($packages,(array)$this->packages->$dir->package);
}

return $packages;
}
/**
* Set the framework package
* @param string : dir (rtl|ltr|)
* @use $this->cssFramework
* @use self::@cssFramework
* @return string[] depends for framework
*/
private function getFrameworkPackages($dir="")
Expand Down Expand Up @@ -416,7 +399,9 @@ private function getFrameworkPackages($dir="")
$frameworkPackages[]=$framework.'-template';
}
return $frameworkPackages;
}
}/*elseif($framework){
throw error ? Only for admin template editor ? disable and reset to default ?
}*/
return array();
}
/**
Expand Down
21 changes: 0 additions & 21 deletions templates/default/config.xml
Expand Up @@ -36,27 +36,6 @@
<filename>css/print_template.css</filename>
</print_css>

<!--
Those files will be loaded for right to left languages only
NOTE 1: If for any reason, you need to edit the RTL behaviors, feel free to contact the LimeSurvey team about it.
We'll be always pleased to make the right to left display better.
NOTE 2: those files are generated with the script R2. See: https://github.com/ded/R2
-->
<rtl>
<css>
<!-- include bootstrap-rtl from Morteza Ansarinia (http://github.com/morteza) -->
<!-- Allow updating only boostrap.css : to be tested -->
<filename>css/template.css</filename>
</css>
<js>
<filename>scripts/template.js</filename>
</js>
<print_css>
<filename>css/print_template.css</filename>
</print_css>
</rtl>

<!-- The logo is used for now only for Surveys List -->
<logo>
<filename>files/logo.png</filename>
Expand Down

0 comments on commit 0f3a1d5

Please sign in to comment.