Skip to content

Commit

Permalink
Dev Fully removed old header_includes function.
Browse files Browse the repository at this point in the history
Dev Changed method for rendering scripts work on incorrect script endings
(exit).
  • Loading branch information
SamMousa committed Jul 12, 2013
1 parent 9bb6ad8 commit f26db5a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 100 deletions.
4 changes: 2 additions & 2 deletions application/controllers/Statistics_userController.php
Expand Up @@ -451,8 +451,8 @@ function actionAction($surveyid,$language)

$redata = compact(array_keys(get_defined_vars()));
$data['redata'] = $redata;
header_includes('statistics_user.js');
$this->render('/statistics_user_view',$data);
Yii::app()->getClientScript()->registerScriptFile('statistics_user.js');
$this->render('/statistics_user_view',$data);

//output footer
echo getFooter();
Expand Down
21 changes: 13 additions & 8 deletions application/controllers/survey/index.php
Expand Up @@ -15,13 +15,19 @@ class index extends CAction {

public function run()
{
ob_start();
/*
* Instead of manually rendering scripts after this function returns we
* use the callback. This ensures that scripts are always rendered, even
* if we call exit at some point in the code. (Which we shouldn't, but
* it happens.)
*/
ob_start(function($buffer, $phase) {
App()->getClientScript()->render($buffer);
return $buffer;
});
ob_implicit_flush(false);
$this->action();
$out = ob_get_clean();
App()->getClientScript()->render($out);
echo $out;

ob_flush();
}

function action()
Expand Down Expand Up @@ -323,7 +329,7 @@ function sendreq(surveyid)

$this->_printTemplateContent(getTemplatePath(Yii::app()->getConfig("defaulttemplate"))."/endpage.pstpl", $data, __LINE__);
doFooter();
exit;
return;
}

// Get token
Expand Down Expand Up @@ -770,8 +776,7 @@ function _niceExit(&$redata, $iDebugLine, $sTemplateDir = null, $asMessage = arr
$this->_printTemplateContent($sTemplateDir.'/endpage.pstpl', $redata, $iDebugLine);

doFooter();

exit;
exit;
}

function _createNewUserSessionAndRedirect($surveyid, &$redata, $iDebugLine, $asMessage = array())
Expand Down
31 changes: 7 additions & 24 deletions application/helpers/common_helper.php
Expand Up @@ -6101,12 +6101,13 @@ function isNumericInt($mStr)
function includeKeypad()
{
$clang = Yii::app()->lang;
header_includes(Yii::app()->getConfig('generalscripts').'jquery/jquery.keypad.min.js');

Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts').'jquery/jquery.keypad.min.js');
if ($clang->langcode != 'en')
{
header_includes(Yii::app()->getConfig('generalscripts').'jquery/locale/jquery.ui.keypad-'.$clang->langcode.'.js');
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts').'jquery/locale/jquery.ui.keypad-'.$clang->langcode.'.js');
}
header_includes('jquery.keypad.alt.css','css');
Yii::app()->getClientScript()->registerCssFile('jquery.keypad.alt.css');
}

/**
Expand Down Expand Up @@ -7366,7 +7367,8 @@ function getHeader($meta = false)
if ($meta)
$header .= $meta;

if ( !$embedded )

if ( !$embedded )
{
return $header;
}
Expand All @@ -7380,7 +7382,7 @@ function getHeader($meta = false)

function doHeader()
{
echo getHeader();
echo getHeader();
}

/**
Expand Down Expand Up @@ -7872,25 +7874,6 @@ function getBrowserLanguage()
return $sLanguage;
}

/**
* This function add string to css or js header for public surevy
* @param string string to ellipsize
* @param string max length of string
* @return array array of string for js or css to be included
*
*/

function header_includes($includes = false, $method = "js" )
{
$header_includes = (array) Yii::app()->getConfig("{$method}_header_includes");
$header_includes[] = $includes;
$header_includes = array_filter($header_includes);
$header_includes = array_unique($header_includes);
Yii::app()->setConfig("{$method}_header_includes", $header_includes);
return $header_includes;
}


function array_diff_assoc_recursive($array1, $array2) {
$difference=array();
foreach($array1 as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/frontend_helper.php
Expand Up @@ -144,7 +144,7 @@ function makegraph($currentstep, $total)
global $thissurvey;

$clang = Yii::app()->lang;
header_includes('lime-progress.css','css');
Yii::app()->getClientScript()->registerCssFile('lime-progress.css');
$size = intval(($currentstep-1)/$total*100);

$graph = '<script type="text/javascript">
Expand Down
34 changes: 17 additions & 17 deletions application/helpers/qanda_helper.php
Expand Up @@ -542,7 +542,7 @@ function return_timer_script($aQuestionAttributes, $ia, $disable=null) {
global $thissurvey;

$clang = Yii::app()->lang;
header_includes(Yii::app()->getConfig("generalscripts").'coookies.js', 'js');
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'coookies.js');

/* The following lines cover for previewing questions, because no $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['fieldarray'] exists.
This just stops error messages occuring */
Expand Down Expand Up @@ -980,8 +980,8 @@ function do_5pointchoice($ia)
$inputnames[]=$ia[1];

if($aQuestionAttributes['slider_rating']==1){
header_includes('star-rating.css','css');
header_includes('star-rating.js','js');
Yii::app()->getClientScript()->registerCssFile('star-rating.css');
Yii::app()->getClientScript()->registerScriptFile('star-rating.js');
$answer .= "<script type='text/javascript'>\n"
. " <!--\n"
." doRatingStar({$ia[0]});\n"
Expand All @@ -990,8 +990,8 @@ function do_5pointchoice($ia)
}

if($aQuestionAttributes['slider_rating']==2){
header_includes('slider-rating.css','css');
header_includes('slider-rating.js','js');
Yii::app()->getClientScript()->registerCssFile('slider-rating.css');
Yii::app()->getClientScript()->registerScriptFile('slider-rating.js');
$answer .= "<script type='text/javascript'>\n"
. " <!--\n"
." doRatingSlider({$ia[0]});\n"
Expand All @@ -1006,7 +1006,7 @@ function do_date($ia)
{
global $thissurvey;

header_includes(Yii::app()->getConfig("generalscripts").'date.js', 'js');
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'date.js');


$clang=Yii::app()->lang;
Expand Down Expand Up @@ -2077,9 +2077,9 @@ function do_ranking($ia)
$answer.="<div id=\"htmlblock-{$ia['0']}-{$ansrow['code']}\">{$ansrow['answer']}</div>";
}
$answer .="</div>";
header_includes("/third_party/jquery.actual/jquery.actual.min.js"); // Needed to with jq1.9 ?
header_includes("ranking.js");
header_includes("ranking.css","css");
Yii::app()->getClientScript()->registerScriptFile("/third_party/jquery.actual/jquery.actual.min.js"); // Needed to with jq1.9 ?
Yii::app()->getClientScript()->registerScriptFile("ranking.js");
Yii::app()->getClientScript()->registerCssFile("ranking.css");

if(trim($aQuestionAttributes['choice_title'][$clang->langcode]) != '')
{
Expand Down Expand Up @@ -2639,7 +2639,7 @@ function do_multiplechoice_withcomments($ia)
$answer .= "<ul class=\"subquestions-list questions-list checkbox-text-list\">\n".$answer_main."</ul>\n";
if($aQuestionAttributes['commented_checkbox']!="allways" && $aQuestionAttributes['commented_checkbox_auto'])
{
header_includes("multiplechoice_withcomments.js");
Yii::app()->getClientScript()->registerScriptFile("multiplechoice_withcomments.js");
# $script= " doMultipleChoiceWithComments({$ia[0]},'{$aQuestionAttributes["commented_checkbox"]}');\n";
# App()->getClientScript()->registerScript("doMultipleChoiceWithComments",$script,CClientScript::POS_HEAD);// Deactivate now: need to be after question, and just after
$answer .= "<script type='text/javascript'>\n"
Expand Down Expand Up @@ -2709,7 +2709,7 @@ function upload_$ia[1]() {
var imageurl = '".Yii::app()->getConfig('imageurl')."';
var uploadurl = '".$scriptloc."';
</script>\n";
header_includes(Yii::app()->getConfig('generalscripts')."modaldialog.js");
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."modaldialog.js");

// Modal dialog
$answer .= $uploadbutton;
Expand Down Expand Up @@ -3207,8 +3207,8 @@ function do_multiplenumeric($ia)

if($aQuestionAttributes['slider_layout']==1)
{
header_includes("numeric-slider.js");
header_includes("numeric-slider.css","css");
Yii::app()->getClientScript()->registerScriptFile("numeric-slider.js");
Yii::app()->getClientScript()->registerCssFile("numeric-slider.css");
if ($slider_default != "")
{
$slider_startvalue = $slider_default;
Expand Down Expand Up @@ -3519,11 +3519,11 @@ class=\"mapservice\" value = \"{$aQuestionAttributes['location_mapservice']}\" >
<div id=\"gmap_canvas_$ia[1]_c\" style=\"width: {$aQuestionAttributes['location_mapwidth']}px; height: {$aQuestionAttributes['location_mapheight']}px\"></div>
</div>";
if ($aQuestionAttributes['location_mapservice']==1 && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off")
header_includes("https://maps.googleapis.com/maps/api/js?sensor=false");
Yii::app()->getClientScript()->registerScriptFile("https://maps.googleapis.com/maps/api/js?sensor=false");
else if ($aQuestionAttributes['location_mapservice']==1)
header_includes("http://maps.googleapis.com/maps/api/js?sensor=false");
Yii::app()->getClientScript()->registerScriptFile("http://maps.googleapis.com/maps/api/js?sensor=false");
elseif ($aQuestionAttributes['location_mapservice']==2)
header_includes("http://www.openlayers.org/api/OpenLayers.js");
Yii::app()->getClientScript()->registerScriptFile("http://www.openlayers.org/api/OpenLayers.js");

if (isset($aQuestionAttributes['hide_tip']) && $aQuestionAttributes['hide_tip']==0)
{
Expand Down Expand Up @@ -6260,7 +6260,7 @@ function do_array_dual($ia)
$answer = "<p class='error'>".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."</p>\n";
$inputnames="";
}
header_includes("dualscale.js");
Yii::app()->getClientScript()->registerScriptFile("dualscale.js");
$answer .= "<script type='text/javascript'>\n"
. " <!--\n"
." {$doDualScaleFunction}({$ia[0]});\n"
Expand Down
54 changes: 7 additions & 47 deletions application/helpers/replacements_helper.php
Expand Up @@ -134,69 +134,29 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$_templatecss="";$_templatejs="";
if(stripos ($line,"{TEMPLATECSS}"))
{
$css_header_includes=Yii::app()->getConfig("css_header_includes");
if (file_exists($templatedir .DIRECTORY_SEPARATOR.'jquery-ui-custom.css'))
{
$template_jqueryui_css= "<link rel='stylesheet' type='text/css' media='all' href='{$templateurl}jquery-ui-custom.css' />\n";
Yii::app()->getClientScript()->registerCssFile("{$templateurl}jquery-ui-custom.css");
}
elseif(file_exists($templatedir.DIRECTORY_SEPARATOR.'jquery-ui.css'))
{
$template_jqueryui_css= "<link rel='stylesheet' type='text/css' media='all' href='{$templateurl}jquery-ui.css' />\n";
Yii::app()->getClientScript()->registerCssFile("{$templateurl}jquery-ui.css");
}
else
{
$_templatecss .="<link rel='stylesheet' type='text/css' media='all' href='".Yii::app()->getConfig('publicstyleurl')."jquery-ui.css' />\n"; // Remove it after corrected slider
$template_jqueryui_css="";
Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl')."jquery-ui.css");
}
if($css_header_includes){
foreach ($css_header_includes as $cssinclude)
{
if (substr($cssinclude,0,4) == 'http' || substr($cssinclude,0,strlen(Yii::app()->getConfig('publicurl'))) == Yii::app()->getConfig('publicurl'))
{
$_templatecss .= "<link rel='stylesheet' type='text/css' media='all' href='".$cssinclude."' />\n";
}
else
{
if(file_exists($templatedir.DIRECTORY_SEPARATOR.$cssinclude))
{
$_templatecss .= "<link rel='stylesheet' type='text/css' media='all' href='{$templateurl}{$cssinclude}' />\n";
}
else
{
$_templatecss .= "<link rel='stylesheet' type='text/css' media='all' href='".Yii::app()->getConfig('publicstyleurl').$cssinclude."' />\n";
}
}
}
}
$_templatecss.= $template_jqueryui_css; // Template jquery ui after default css
$_templatecss.= "<link rel='stylesheet' type='text/css' media='all' href='{$templateurl}template.css' />\n";
if (getLanguageRTL($clang->langcode))

Yii::app()->getClientScript()->registerCssFile("{$templateurl}template.css");
if (getLanguageRTL($clang->langcode))
{
$_templatecss.="<link rel='stylesheet' type='text/css' media='all' href='{$templateurl}template-rtl.css' />\n";
Yii::app()->getClientScript()->registerCssFile("{$templateurl}template-rtl.css");
}
}
if(stripos ($line,"{TEMPLATEJS}"))
{

$js_header_includes =header_includes(false,'js');
App()->getClientScript()->registerPackage('jqueryui');
if($js_header_includes){
foreach ($js_header_includes as $jsinclude)
{
if (substr($jsinclude,0,4) == 'http' || substr($jsinclude,0,strlen(Yii::app()->getConfig('publicurl'))) == Yii::app()->getConfig('publicurl'))
{
App()->getClientScript()->registerScriptFile($jsinclude);
}
else
{
if(file_exists($templatedir.DIRECTORY_SEPARATOR.$jsinclude)){
App()->getClientScript()->registerScriptFile($templateurl.$jsinclude);
}else{
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts').$jsinclude);
}
}
}
}
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");
App()->getClientScript()->registerScriptFile($templateurl . 'template.js',CClientScript::POS_END);
useFirebug();
Expand Down
2 changes: 1 addition & 1 deletion application/models/SurveyDynamic.php
Expand Up @@ -172,7 +172,7 @@ public function addTokenCriteria($condition)
foreach($aSelectFields as $sField)
$aSelect[]="$alias.".Yii::app()->db->schema->quoteColumnName($sField);
$aSelectFields=$aSelect;
$aSelectFields[]='$alias.token';
$aSelectFields[]="$alias.token";

if ($criteria->select == '*')
{
Expand Down

0 comments on commit f26db5a

Please sign in to comment.