Skip to content

Commit

Permalink
Fixed issue #05992: After upgrade to Version 1.92+ Build 120405 the u…
Browse files Browse the repository at this point in the history
…ploaded file information gets corrupted.

Dev ensures that all json_encode output has spaces added after opening curly braces so that EM doesn't try to parse it.
  • Loading branch information
TMSWhite committed Apr 16, 2012
1 parent 364472e commit 8755a06
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 42 deletions.
20 changes: 10 additions & 10 deletions application/controllers/UploaderController.php
Expand Up @@ -67,7 +67,7 @@ function run()
$iFileIndex++;
}
if ($found==true) unset($aFiles[$iFileIndex]);
$_SESSION[$sFieldname] = str_replace('{','{ ',json_encode($aFiles));
$_SESSION[$sFieldname] = ls_json_encode($aFiles);
}
}
//var_dump($sFileDir.$sFilename);
Expand Down Expand Up @@ -129,7 +129,7 @@ function run()
"success" => false,
"msg" => sprintf($clang->gT("Sorry, this file extension (%s) is not allowed!"),$ext)
);
echo lsJSONEncode($return);
echo ls_json_encode($return);
exit ();
}

Expand All @@ -142,7 +142,7 @@ function run()
"success" => false,
"msg" => sprintf($clang->gT("Sorry, this file is too large. Only files upto %s KB are allowed."), $maxfilesize)
);
echo lsJSONEncode($return);
echo ls_json_encode($return);
exit ();
}

Expand All @@ -158,7 +158,7 @@ function run()
"filename" => $randfilename,
"msg" => $clang->gT("The file has been successfuly uploaded.")
);
echo lsJSONEncode($return);
echo ls_json_encode($return);
// TODO : unlink this file since this is just a preview
// unlink($randfileloc);
exit ();
Expand All @@ -174,7 +174,7 @@ function run()
"success" => false,
"msg" => sprintf($clang->gT("Sorry, this file is too large. Only files up to %s KB are allowed.",'unescaped'), $maxfilesize)
);
echo lsJSONEncode($return);
echo ls_json_encode($return);
exit ();
}
elseif ($iFileUploadTotalSpaceMB>0 && ((calculateTotalFileUploadUsage()+($size/1024/1024))>$iFileUploadTotalSpaceMB))
Expand All @@ -183,7 +183,7 @@ function run()
"success" => false,
"msg" => $clang->gT("We are sorry but there was a system error and your file was not saved. An email has been dispatched to notify the survey administrator.",'unescaped')
);
echo lsJSONEncode($return);
echo ls_json_encode($return);
exit ();
}
elseif (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $randfileloc))
Expand All @@ -199,7 +199,7 @@ function run()
"msg" => $clang->gT("The file has been successfuly uploaded.")
);

echo lsJSONEncode($return);
echo ls_json_encode($return);
exit ();
}
// if there was some error, report error message
Expand All @@ -213,7 +213,7 @@ function run()
"msg" => $clang->gT("Sorry, there was an error uploading your file")
);

echo lsJSONEncode($return);
echo ls_json_encode($return);
exit ();
}
// check to ensure that the file does not cross the maximum file size
Expand All @@ -224,7 +224,7 @@ function run()
"msg" => sprintf($clang->gT("Sorry, this file is too large. Only files upto %s KB are allowed."), $maxfilesize)
);

echo lsJSONEncode($return);
echo ls_json_encode($return);
exit ();
}
else
Expand All @@ -233,7 +233,7 @@ function run()
"success" => false,
"msg" => $clang->gT("Unknown error")
);
echo lsJSONEncode($return);
echo ls_json_encode($return);
exit ();
}
}
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/conditionsaction.php
Expand Up @@ -1092,7 +1092,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null)
{
foreach($canswers as $can)
{
$an = lsJSONEncode(flattenText($can[2]));
$an = ls_json_encode(flattenText($can[2]));
$aViewUrls['output'] .= "Fieldnames[$jn]='$can[0]';\n"
. "Codes[$jn]='$can[1]';\n"
. "Answers[$jn]={$an};\n";
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/dataentry.php
Expand Up @@ -1760,7 +1760,7 @@ public function insert()
}
}

$insert_data[$fieldname] = json_encode($phparray);
$insert_data[$fieldname] = ls_json_encode($phparray);

}
else
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/labels.php
Expand Up @@ -381,7 +381,7 @@ public function getAllSets()
$output[$row->lid] = $row->getAttribute('label_name');
}

echo json_encode($output);
echo ls_json_encode($output);
}

public function ajaxSets()
Expand Down Expand Up @@ -422,7 +422,7 @@ public function ajaxSets()
$res = 'fail';
}
}
echo json_encode($res);
echo ls_json_encode($res);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -198,7 +198,7 @@ function getShareInfo_json()
$i++;
}

echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}
// otherwise only the shared participants by that user
else
Expand All @@ -216,7 +216,7 @@ function getShareInfo_json()
$i++;
}

echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}
}

Expand Down Expand Up @@ -282,7 +282,7 @@ function getAttributeInfo_json()
$i++;
}

echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}

/**
Expand Down Expand Up @@ -473,7 +473,7 @@ function getSurveyInfo_json()
$i++;
}

echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}

/**
Expand Down Expand Up @@ -907,7 +907,7 @@ function subval_sort($a, $subkey, $order)
$i++;
}
}
echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}
// Only the owned and shared participants will be visible
else
Expand Down Expand Up @@ -991,7 +991,7 @@ function subval_sort($a, $subkey, $order)
$i++;
}
}
echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}
}

Expand Down Expand Up @@ -1078,7 +1078,7 @@ function subval_sort($a, $subkey, $order)
$i++;
}
}
echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}
// Only the owned and shared participants will be visible
else
Expand Down Expand Up @@ -1128,7 +1128,7 @@ function subval_sort($a, $subkey, $order)
$i++;
}
}
echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}
}

Expand Down Expand Up @@ -1220,7 +1220,7 @@ function getAttribute_json()
$i++;
}
}
echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}

/*
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/admin/question.php
Expand Up @@ -732,7 +732,7 @@ public function index($sa, $surveyid, $gid, $qid=null)
foreach ($qtypelist as $qtype => $qdesc)
{
$qDescToCode .= " '{$qdesc['description']}' : '{$qtype}', \n";
$qCodeToInfo .= " '{$qtype}' : '" . lsJSONEncode($qdesc) . "', \n";
$qCodeToInfo .= " '{$qtype}' : '" . ls_json_encode($qdesc) . "', \n";
}
$aData['qTypeOutput'] = "$qDescToCode 'null':'null' }; \n $qCodeToInfo 'null':'null' };";

Expand Down Expand Up @@ -978,7 +978,7 @@ public function ajaxlabelsetdetails()
$resultdata[]=array($language=>array($labels,getLanguageNameFromCode($language,false)));
}

echo json_encode($resultdata);
echo ls_json_encode($resultdata);
}

/**
Expand All @@ -1000,7 +1000,7 @@ public function ajaxlabelsetpicker()
$language=null;
}
$resultdata=getlabelsets($language);
echo json_encode($resultdata);
echo ls_json_encode($resultdata);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -427,7 +427,7 @@ public function ajaxgetusers()
foreach ($result as $rows)
$aUsers[] = array($rows['uid'], $rows['users_name']);
}
$ajaxoutput = json_encode($aUsers) . "\n";
$ajaxoutput = ls_json_encode($aUsers) . "\n";
echo $ajaxoutput;
}

Expand Down Expand Up @@ -468,7 +468,7 @@ public function ajaxowneredit($newowner, $surveyid)
foreach ($result as $row)
$aUsers['newowner'] = $row->owner->users_name;

$ajaxoutput = json_encode($aUsers) . "\n";
$ajaxoutput = ls_json_encode($aUsers) . "\n";

echo $ajaxoutput;
}
Expand Down Expand Up @@ -601,7 +601,7 @@ public function getSurveys_json()
$aSurveyEntries->rows[] = array('id' => $rows['sid'], 'cell' => $aSurveyEntry);
}

echo lsJSONEncode($aSurveyEntries);
echo ls_json_encode($aSurveyEntries);
}

/**
Expand Down Expand Up @@ -1380,7 +1380,7 @@ function getUrlParamsJSON($iSurveyId)
$aData->records = $oResult->getRowCount();
$aData->total = 1;

echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/admin/tokens.php
Expand Up @@ -392,7 +392,7 @@ function getTokens_json($iSurveyId)
}
}

echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}

function editToken($iSurveyId)
Expand Down Expand Up @@ -482,7 +482,7 @@ function editToken($iSurveyId)
$this->getController()->error(sprintf($clang->gT('%s cannot be empty'), $desc['description']));
$aData[$attr_name] = Yii::app()->request->getPost($attr_name);
}
echo lsJSONEncode(var_export($aData));
echo ls_json_encode(var_export($aData));
$token = new Tokens_dynamic;
foreach ($aData as $k => $v)
$token->$k = $v;
Expand Down Expand Up @@ -2178,7 +2178,7 @@ function subval_sort($a, $subkey, $order)
$i++;
}
}
echo lsJSONEncode($aData);
echo ls_json_encode($aData);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/translate.php
Expand Up @@ -1074,7 +1074,7 @@ private function translate_google_api()
'converted' => $sOutput
);

return lsJSONEncode($aOutput) . "\n";
return ls_json_encode($aOutput) . "\n";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/admin/statistics_helper.php
Expand Up @@ -3415,7 +3415,7 @@ function generate_statistics($surveyid, $allfields, $q2show='all', $usegraph=0,
break;
case 'html':
$statisticsoutput .= "<script type=\"text/javascript\" src=\"http://maps.googleapis.com/maps/api/js?sensor=false\"></script>"
."<script type=\"text/javascript\">var site_url='".Yii::app()->baseUrl."';var temppath='$tempurl';var imgpath='".Yii::app()->getConfig('imageurl')."';var aGMapData=".json_encode($agmapdata) .";var aStatData=".json_encode($astatdata)."</script>";
."<script type=\"text/javascript\">var site_url='".Yii::app()->baseUrl."';var temppath='$tempurl';var imgpath='".Yii::app()->getConfig('imageurl')."';var aGMapData=".ls_json_encode($agmapdata) .";var aStatData=".ls_json_encode($astatdata)."</script>";
return $statisticsoutput;

break;
Expand Down
8 changes: 5 additions & 3 deletions application/helpers/common_helper.php
Expand Up @@ -7455,11 +7455,13 @@ function fixSubquestions()
}

/**
* Must use lsJSONEncode to json_encode content, otherwise LimeExpressionManager will think that the associative arrays are expressions and try to parse them.
* Must use ls_json_encode to json_encode content, otherwise LimeExpressionManager will think that the associative arrays are expressions and try to parse them.
*/
function lsJSONEncode($content)
function ls_json_encode($content)
{
return preg_replace('/\{\"/','{ "',json_encode($content));
$ans = json_encode($content);
$ans = str_replace(array('{','}'),array('{ ',' }'), $ans);
return $ans;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/expressions/em_manager_helper.php
Expand Up @@ -6119,7 +6119,7 @@ static function ProcessCurrentResponses()
$phparray[$i]->filename = $sDestinationFileName;
}
}
$value = str_replace('{','{ ',json_encode($phparray)); // so that EM doesn't try to parse it.
$value = ls_json_encode($phparray); // so that EM doesn't try to parse it.
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/qanda_helper.php
Expand Up @@ -2494,7 +2494,7 @@ function do_multiplechoice($ia)
}
}
if ($exclude_all_others_auto==1){
$answer .= "<script type='text/javascript'>autoArray = ".json_encode($autoArray).";</script>";
$answer .= "<script type='text/javascript'>autoArray = ".ls_json_encode($autoArray).";</script>";
}
if ($other == 'Y')
{
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/export/statistics_graph_view.php
Expand Up @@ -3,13 +3,13 @@

<?php
if (isset($mapdata)) {
echo ",\"mapdata\":".json_encode($mapdata);
echo ",\"mapdata\":".ls_json_encode($mapdata);
}
?>

<?php
if (isset($chartdata)) {
echo ",\"chartdata\":".json_encode($chartdata);
echo ",\"chartdata\":".ls_json_encode($chartdata);
}
?>
}

0 comments on commit 8755a06

Please sign in to comment.