Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed May 29, 2017
2 parents ea3ccb3 + 1cab15f commit 6784ecd
Show file tree
Hide file tree
Showing 111 changed files with 19,017 additions and 744 deletions.
9 changes: 5 additions & 4 deletions application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
'isset' => 'isset',
'str_replace' => 'str_replace',
'assetPublish' => 'LS_Twig_Extension::assetPublish',
'image' => 'LS_Twig_Extension::image',
'sprintf' => 'sprintf',
'gT' => 'gT',
),
Expand All @@ -239,15 +240,15 @@
'tags' => array('if', 'for', 'set', 'autoescape'),
'filters' => array('escape', 'raw', 't', 'merge', 'length', 'gT', 'keys'),
'methods' => array(
'ETwigViewRendererStaticClassProxy' => array("textfield", "form", "link", "emailField", "beginForm", "endForm", "dropDownList", "htmlButton", "passwordfield" ),
'ETwigViewRendererStaticClassProxy' => array("encode", "textfield", "form", "link", "emailField", "beginForm", "endForm", "dropDownList", "htmlButton", "passwordfield" ),
'Survey' => array("getAllLanguages"),
'LSHttpRequest' => array("getParam"),
),
'properties' => array(
'ETwigViewRendererYiiCoreStaticClassesProxy'=>array("Html"),
'LSYii_Application' => array("request"),
'ETwigViewRendererYiiCoreStaticClassesProxy' => array("Html"),
'LSYii_Application' => array("request"),
),
'functions' => array('include', 'dump', 'flatEllipsizeText', 'getLanguageData', 'array_flip', 'array_intersect_key', 'registerPublicCssFile', 'registerTemplateCssFile', 'registerGeneralScript', 'registerTemplateScript', 'registerScript', 'getAllQuestionClasses','intval', 'count', 'empty', 'reset', 'renderCaptcha', 'getPost','getParam', 'getQuery', 'isset', 'str_replace', 'assetPublish', 'sprintf', 'gT' ),
'functions' => array('include', 'dump', 'flatEllipsizeText', 'getLanguageData', 'array_flip', 'array_intersect_key', 'registerPublicCssFile', 'registerTemplateCssFile', 'registerGeneralScript', 'registerTemplateScript', 'registerScript', 'getAllQuestionClasses','intval', 'count', 'empty', 'reset', 'renderCaptcha', 'getPost','getParam', 'getQuery', 'isset', 'str_replace', 'assetPublish', 'image', 'sprintf', 'gT' ),
),

),
Expand Down
12 changes: 6 additions & 6 deletions application/controllers/SurveysController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public function actionPublicList($lang = null)


$oTemplate = Template::model()->getInstance(Yii::app()->getConfig("defaulttemplate"));
$oTemplate->registerAssets();
//$oTemplate->registerAssets();


$this->sTemplate = $oTemplate->name;
Yii::app()->clientScript->registerPackage( 'survey-template' );
// $this->aGlobalData['languagechanger'] = makeLanguageChanger(App()->language);
//Yii::app()->clientScript->registerPackage( 'survey-template' );
//Yii::app()->clientScript->registerPackage( 'survey-template-'.$oTemplate->sTemplateName );
//var_dump('survey-template-'.$oTemplate->sTemplateName);


$aData = array(
'publicSurveys' => Survey::model()->active()->open()->public()->with('languagesettings')->findAll(),
Expand All @@ -55,10 +57,8 @@ public function actionPublicList($lang = null)

Yii::app()->clientScript->registerScriptFile(Yii::app()->getConfig("generalscripts").'nojs.js',CClientScript::POS_HEAD);

$sTemplateViewPath = $oTemplate->viewPath;

Yii::app()->twigRenderer->setForcedPath($sTemplateViewPath);
Yii::app()->twigRenderer->renderTemplateFromString( file_get_contents($sTemplateViewPath."layout_survey_list.twig"), array('aSurveyInfo'=>$aData), false);
Yii::app()->twigRenderer->renderTemplateFromFile("layout_survey_list.twig", array('aSurveyInfo'=>$aData), false);

}
/**
Expand Down
42 changes: 21 additions & 21 deletions application/controllers/admin/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function uploadfile()
$editfile = App()->request->getPost('editfile');
$templatename = returnGlobal('templatename');
$oEditedTemplate = Template::model()->getTemplateConfiguration($templatename);
$templatedir = $oEditedTemplate->pstplPath;
$templatedir = $oEditedTemplate->viewPath;
$screenname = returnGlobal('screenname');
$cssfiles = $this->_initcssfiles($oEditedTemplate);
$basedestdir = Yii::app()->getConfig('usertemplaterootdir');
Expand Down Expand Up @@ -387,7 +387,7 @@ public function templatefiledelete()
$sFileToDelete=sanitize_filename(App()->request->getPost('otherfile'),false,false);
$sTemplateName=Template::templateNameFilter(App()->request->getPost('templatename'));
$oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName);
$templatedir = $oEditedTemplate->pstplPath;
$templatedir = $oEditedTemplate->viewPath;
$filesdir = $oEditedTemplate->filesPath;
$the_full_file_path = $filesdir . $sFileToDelete;
if (@unlink($the_full_file_path))
Expand Down Expand Up @@ -973,9 +973,9 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
if (file_exists(Yii::app()->getConfig('usertemplaterootdir') . DIRECTORY_SEPARATOR . $templatename. DIRECTORY_SEPARATOR.$editfile)){
/* the file seems a simple file */
$sEditFile=realpath(Yii::app()->getConfig('usertemplaterootdir') . DIRECTORY_SEPARATOR . $templatename. DIRECTORY_SEPARATOR.$editfile);
}elseif (file_exists($oEditedTemplate->pstplPath. DIRECTORY_SEPARATOR.$editfile)){
}elseif (file_exists($oEditedTemplate->viewPath. DIRECTORY_SEPARATOR.$editfile)){
/* the file seems a view file */
$sEditFile=realpath($oEditedTemplate->pstplPath. DIRECTORY_SEPARATOR.$editfile);
$sEditFile=realpath($oEditedTemplate->viewPath. DIRECTORY_SEPARATOR.$editfile);
}else{
/* the file seems to be invalid */
$sEditFile='';
Expand Down Expand Up @@ -1052,7 +1052,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$surveyid = '1295';
$token = 1234567;

$templatedir = $oEditedTemplate->pstplPath;
$templatedir = $oEditedTemplate->viewPath;
$templateurl = getTemplateURL($templatename);

// Save these variables in an array
Expand Down Expand Up @@ -1121,22 +1121,22 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$files=$SurveyList;
foreach ($files as $qs)
{
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/$qs", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/$qs", $aData, $oEditedTemplate));
}
break;

case 'question':
$files=$Question;
$myoutput[] = $this->getController()->renderPartial('/admin/templates/templateeditor_question_meta_view', array(), true);

$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/startpage.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/survey.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/startpage.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/survey.pstpl", $aData, $oEditedTemplate));

// Normally output by survey_runtime
$myoutput = array_merge($myoutput, array('<div id="group-0">'));

$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/startgroup.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/groupdescription.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/startgroup.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/groupdescription.pstpl", $aData, $oEditedTemplate));

$aReplacements = array(
'QUESTION_TEXT' => gT("How many roads must a man walk down?"),
Expand All @@ -1155,7 +1155,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
);
$aReplacements['ANSWER'] = $this->getController()->renderPartial('/admin/templates/templateeditor_question_answer_view', array(), true);
$aData['aReplacements'] = array_merge($aGlobalReplacements,$aReplacements);
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/question.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/question.pstpl", $aData, $oEditedTemplate));

$aReplacements = array(
'QUESTION_TEXT' => gT('Please explain something in detail:'),
Expand All @@ -1172,9 +1172,9 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
);
$aReplacements['ANSWER'] = $this->getController()->renderPartial('/admin/templates/templateeditor_question_answer_view', array('alt' => true), true);
$aData['aReplacements'] = array_merge($aGlobalReplacements,$aReplacements);
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/question.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/question.pstpl", $aData, $oEditedTemplate));

$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/endgroup.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/endgroup.pstpl", $aData, $oEditedTemplate));

// Normally output by survey_runtime
$myoutput = array_merge($myoutput, array('</div>'));
Expand All @@ -1186,8 +1186,8 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
'MOVENEXTBUTTON' => $sMoveNext,
'NAVIGATOR' => "$sMovePrev $sMoveNext",
));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/navigator.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/endpage.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/navigator.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/endpage.pstpl", $aData, $oEditedTemplate));
break;

case 'welcome':
Expand All @@ -1199,7 +1199,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
));
$files=$Welcome ;
foreach ($files as $qs) {
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/$qs", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/$qs", $aData, $oEditedTemplate));
}
break;

Expand All @@ -1212,7 +1212,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
'SURVEYNAME' => 'Survey name'
))
);
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/survey.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/survey.pstpl", $aData, $oEditedTemplate));

$aData['aReplacements'] = array_merge($aGlobalReplacements,array(
'REGISTERERROR' => 'Example error message',
Expand All @@ -1221,7 +1221,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
'REGISTERFORM' => $this->getController()->renderPartial('/admin/templates/templateeditor_register_view', array('alt' => true), true),
));

$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/register.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/register.pstpl", $aData, $oEditedTemplate));
$myoutput[] = templatereplace(file_get_contents("$templatedir/endpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate);
$myoutput[] = "\n";
break;
Expand All @@ -1238,7 +1238,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$saveForm .= App()->getController()->renderPartial("/survey/frontpage/saveForm/form",array('captcha'=>false),true);
$saveForm .= CHtml::endForm();
$aData['aReplacements']['SAVEFORM'] = $saveForm;
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/save.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/save.pstpl", $aData, $oEditedTemplate));
$myoutput[] = templatereplace(file_get_contents("$templatedir/endpage.pstpl"), array(), $aData, 'Unspecified', false, NULL, array(), false, $oEditedTemplate);
$myoutput[] = "\n";
break;
Expand All @@ -1254,7 +1254,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$loadForm .= App()->getController()->renderPartial("/survey/frontpage/loadForm/form",array('captcha'=>false),true);
$loadForm .= CHtml::endForm();
$aData['aReplacements']['LOADFORM'] = $loadForm;
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/load.pstpl", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/load.pstpl", $aData, $oEditedTemplate));
$myoutput[] = templatereplace(file_get_contents("$templatedir/endpage.pstpl"), $aData['aReplacements'], $aData['aReplacements'], 'Unspecified', false, NULL, array(), false, $oEditedTemplate);

$myoutput[] = "\n";
Expand All @@ -1275,7 +1275,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
$myoutput[] = "";
foreach ($files as $qs)
{
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->pstplPath . "/$qs", $aData, $oEditedTemplate));
$myoutput = array_merge($myoutput, doreplacement($oEditedTemplate->viewPath . "/$qs", $aData, $oEditedTemplate));
}
break;
case 'printablesurvey':
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/survey/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function action()

Yii::app()->setConfig('surveyID',$surveyid);
Yii::app()->setConfig('move',$move);
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");

if (is_null($thissurvey) && !is_null($surveyid))
$thissurvey = getSurveyInfo($surveyid);
Expand Down Expand Up @@ -407,9 +408,8 @@ function action()

$aLoadForm['aErrors'] = empty($aLoadErrorMsg) ? null : $aLoadErrorMsg; // Set tit to null if empty
$thissurvey['aLoadForm'] = $aLoadForm;
Yii::app()->twigRenderer->setForcedPath($oTemplate->viewPath);
$oTemplate->registerAssets();
Yii::app()->twigRenderer->renderTemplateFromString( file_get_contents($oTemplate->viewPath."layout_load.twig"), array('aSurveyInfo'=>$thissurvey), false);
//$oTemplate->registerAssets();
Yii::app()->twigRenderer->renderTemplateFromFile("layout_load.twig", array('aSurveyInfo'=>$thissurvey), false);
}


Expand Down
46 changes: 31 additions & 15 deletions application/core/LSETwigViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class LSETwigViewRenderer extends ETwigViewRenderer
*/
public $sandboxConfig = array();
private $_twig;
private $forcedPath = null;

/**
* Adds custom extensions
Expand Down Expand Up @@ -137,16 +136,30 @@ public function renderQuestion( $sView, $aData)
}
}

/**
* Only use for renderTemplateFromString for now, to force the path of included twig files (in renderTemplateFromString: the template files)
* It's necessary for the twig include statments: by default, those views would be looked into application/views instead of the template's views directory.
* @param string $sPath the path that will be used to render the views.
*/
public function setForcedPath($sPath)

public function renderTemplateFromFile($sView, $aDatas, $bReturn)
{
$this->forcedPath=$sPath;
$oTemplate = $this->getTemplateForView($sView);
$line = file_get_contents($oTemplate->viewPath.$sView);
$this->renderTemplateFromString( $line, $aDatas, $bReturn);
}

private function getTemplateForView($sView)
{
$oRTemplate = Template::model()->getInstance();

while (!file_exists($oRTemplate->viewPath.$sView)){

$oMotherTemplate = $oRTemplate->oMotherTemplate;
if(!($oMotherTemplate instanceof TemplateConfiguration)){
return false;
break;
}
$oRTemplate = $oMotherTemplate;
}

return $oRTemplate;
}

/**
* Render a string, not a file. It's used from template replace function.
Expand All @@ -157,13 +170,16 @@ public function setForcedPath($sPath)
*/
public function renderTemplateFromString( $line, $aDatas, $bReturn)
{
$this->_twig = $twig = parent::getTwig();

// At this point, forced path should not be nulled.
// It contains the path to the template's view directory for twig include statements
if (!is_null($this->forcedPath)){
$loader = $this->_twig->getLoader();
$loader->setPaths($this->forcedPath);
$this->_twig = $twig = parent::getTwig();
$loader = $this->_twig->getLoader();
$oRTemplate = Template::model()->getInstance();
$loader->addPath($oRTemplate->viewPath);
Yii::app()->clientScript->registerPackage( $oRTemplate->sPackageName );

// Add all mother templates path
while($oRTemplate->oMotherTemplate instanceof TemplateConfiguration){
$oRTemplate = $oRTemplate->oMotherTemplate;
$loader->addPath($oRTemplate->viewPath);
}

// Plugin for blocks replacement
Expand Down

0 comments on commit 6784ecd

Please sign in to comment.