Skip to content

Commit

Permalink
Merge pull request #158 from Shnoulle/master_betterDisplaySurveyLogic
Browse files Browse the repository at this point in the history
Fixed issue #08470: Script are hard to debug in Survey Logic File
  • Loading branch information
Shnoulle committed Dec 19, 2013
2 parents 33fbe97 + dc948b8 commit 5795dc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
15 changes: 7 additions & 8 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -8787,12 +8787,12 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
$sgqas = explode('|',$q['sgqa']);
if (count($sgqas) == 1 && !is_null($q['info']['default']))
{
$LEM->ProcessString($q['info']['default'], $qid,NULL,false,1,1,false,false);
$LEM->ProcessString(htmlspecialchars($q['info']['default']), $qid,NULL,false,1,1,false,false);// Default value is Y or answer code or go to input/textarea, then we can filter it
$_default = $LEM->GetLastPrettyPrintExpression();
if ($LEM->em->HasErrors()) {
++$errorCount;
}
$default = '<br />(' . $LEM->gT('Default:') . ' ' . htmlspecialchars($_default) . ')';
$default = '<br />(' . $LEM->gT('Default:') . ' ' . viewHelper::filterScript($_default) . ')';
}
else
{
Expand Down Expand Up @@ -8886,7 +8886,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
}

$LEM->ProcessString($qtext . $help . $prettyValidTip . $attrTable, $qid,NULL,false,1,1,false,false);
$qdetails = $LEM->GetLastPrettyPrintExpression();
$qdetails = viewHelper::filterScript($LEM->GetLastPrettyPrintExpression());
if ($LEM->em->HasErrors()) {
++$errorCount;
}
Expand Down Expand Up @@ -9034,11 +9034,10 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL

$sgqaInfo = $LEM->knownVars[$sgqa];
$subqText = $sgqaInfo['subqtext'];

if (isset($sgqaInfo['default']) && $sgqaInfo['default'] !== '')
{
$LEM->ProcessString($sgqaInfo['default'], $qid,NULL,false,1,1,false,false);
$_default = $LEM->GetLastPrettyPrintExpression();
$LEM->ProcessString(htmlspecialchars($sgqaInfo['default']), $qid,NULL,false,1,1,false,false);
$_default = viewHelper::filterScript($LEM->GetLastPrettyPrintExpression());
if ($LEM->em->HasErrors()) {
++$errorCount;
}
Expand All @@ -9053,7 +9052,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
. "</tr>";
}
$LEM->ProcessString($sqRows, $qid,NULL,false,1,1,false,false);
$sqRows = $LEM->GetLastPrettyPrintExpression();
$sqRows = viewHelper::filterScript($LEM->GetLastPrettyPrintExpression());
if ($LEM->em->HasErrors()) {
++$errorCount;
}
Expand Down Expand Up @@ -9105,7 +9104,7 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
. "</tr>\n";
}
$LEM->ProcessString($answerRows, $qid,NULL,false,1,1,false,false);
$answerRows = $LEM->GetLastPrettyPrintExpression();
$answerRows = viewHelper::filterScript($LEM->GetLastPrettyPrintExpression());
if ($LEM->em->HasErrors()) {
++$errorCount;
}
Expand Down
13 changes: 13 additions & 0 deletions application/helpers/viewHelper.php
Expand Up @@ -170,4 +170,17 @@ public static function disableHtmlLogging(){
$route->enabled = $route->enabled && !($route instanceOf CWebLogRoute);
}
}

/**
* Deactivate script but show it for debuging
* This only filter script tag
* @todo : filter inline javascript (onclick etc ..., but don't filter EM javascript)
* Maybe doing it directly in LEM->GetLastPrettyPrintExpression();
* @param string : Html to filter
* @return string
* @author Denis Chenu
*/
public static function filterScript($sHtml){
return preg_replace('#<script(.*?)>(.*?)</script>#is', '<pre>&lt;script&gt;${2}&lt;/script&gt;</pre>', $sHtml);
}
}

0 comments on commit 5795dc6

Please sign in to comment.