Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	application/controllers/admin/questions.php
  • Loading branch information
olleharstedt committed May 25, 2018
2 parents 42d8df4 + 0abd142 commit 4caa8b8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/questions.php
Expand Up @@ -1219,7 +1219,7 @@ public function index($sa, $surveyid, $gid, $qid = null)
$aData['surveyid'] = $surveyid;
$aData['gid'] = $gid;
$questionTemplateAttributes = Question::model()->getAdvancedSettingsWithValues($qid, $eqrow['type'], $surveyid);
$aData['aQuestionTemplateAttributes'] = \QuestionTemplate::getQuestionTemplateList($eqrow['type']);
$aData['aQuestionTemplateAttributes'] = $questionTemplateAttributes['question_template'];
} else {
$aData['aQuestionTemplateAttributes']['core'] = array('title'=>'Default', 'preview'=>\LimeSurvey\Helpers\questionHelper::getQuestionThemePreviewUrl($eqrow['type']));
}
Expand Down
12 changes: 8 additions & 4 deletions application/models/TemplateManifest.php
Expand Up @@ -162,12 +162,16 @@ public function extendsFile($sFile)
if (!file_exists($this->path.$sFile) && !file_exists($this->viewPath.$sFile)) {

// Copy file from mother template to local directory
$sRfilePath = $this->getFilePath($sFile, $this);
$sLfilePath = (pathinfo($sFile, PATHINFO_EXTENSION) == 'twig') ? $this->viewPath.$sFile : $this->path.$sFile;
copy($sRfilePath, $sLfilePath);
$sSourceFilePath = $this->getFilePath($sFile, $this);
$sDestinationFilePath = (pathinfo($sFile, PATHINFO_EXTENSION) == 'twig') ? $this->viewPath.$sFile : $this->path.$sFile;

//PHP 7 seems not to create the folder on copy automatically.
@mkdir(dirname($sDestinationFilePath), 0775, true);

copy($sSourceFilePath, $sDestinationFilePath);

// If it's a css or js file from config... must update DB and XML too....
$sExt = pathinfo($sLfilePath, PATHINFO_EXTENSION);
$sExt = pathinfo($sDestinationFilePath, PATHINFO_EXTENSION);
if ($sExt == "css" || $sExt == "js") {

// Check if that CSS/JS file is in DB/XML
Expand Down
47 changes: 21 additions & 26 deletions application/third_party/gtranslate-api/GTranslate.php
Expand Up @@ -61,14 +61,14 @@ class GTranslate
* @access private
* @var String
*/
private $url = "http://ajax.googleapis.com/ajax/services/language/translate";
private $url = "https://www.googleapis.com/language/translate/v2";

/**
* Google Translate (TM) Api Version
* @access private
* @var String
*/
private $api_version = "1.0";
private $api_version = "2";

/**
* Comunication Transport Method
Expand Down Expand Up @@ -163,26 +163,20 @@ private function parseLanguageFile()
private function urlFormat($lang_pair,$string)
{
$parameters = array(
"v" => $this->api_version,
"q" => $string,
"langpair"=> implode("|",$lang_pair)
"source" => $lang_pair[0],
"target" => $lang_pair[1],
);

if(!empty($this->api_key))
{
$parameters["key"] = $this->api_key;
}

if( empty($this->user_ip) )
{
if( !empty($_SERVER["REMOTE_ADDR"]) )
{
$parameters["userip"] = $_SERVER["REMOTE_ADDR"];
}
} else
{
$parameters["userip"] = $this->user_ip;
}
else
{
$parameters["key"] = getGlobalSetting('googletranslateapikey');
}

$url = "";

Expand Down Expand Up @@ -274,8 +268,11 @@ public function query($lang_pair,$string)

private function requestHttp($url)
{

return GTranslate::evalResponse(json_decode(file_get_contents($this->url."?".$url)));
$fullurl = $this->url."?".$url;
$return = file_get_contents($fullurl);
$json = json_decode($return);
return GTranslate::evalResponse($json);

}

/**
Expand Down Expand Up @@ -308,16 +305,14 @@ private function requestCurl($url)

private function evalResponse($json_response)
{

switch($json_response->responseStatus)
{
case 200:
return $json_response->responseData->translatedText;
break;
default:
throw new GTranslateException("Unable to perform Translation:".$json_response->responseDetails);
break;
}
if (isset($json_response->data->translations))
{
return $json_response->data->translations[0]->translatedText;
}
else
{
throw new GTranslateException("Unable to perform Translation:".$json_response->data);
}
}


Expand Down
9 changes: 6 additions & 3 deletions application/views/admin/survey/Question/editQuestion_view.php
Expand Up @@ -17,6 +17,7 @@
$aQuestionTypeGroups = array();
$aQuestionTypeList = Question::typeList();
$question_template_preview = \LimeSurvey\Helpers\questionHelper::getQuestionThemePreviewUrl($eqrow['type']);
$selected = null;

foreach ( $aQuestionTypeList as $key=> $questionType)
{
Expand Down Expand Up @@ -245,10 +246,12 @@
<label class=" control-label" for='gid' title="<?php eT("Use a customized question theme for this question");?>"><?php eT("Question theme:"); ?></label>
<div class="">
<select id="question_template" name="question_template" class="form-control">
<?php
<?php
foreach ($aQuestionTemplateList as $code => $value) {
$selected = $aQuestionTemplateAttributes[$code] == $code ? 'selected' : '';
$question_template_preview = $aQuestionTemplateAttributes[$code] == $code ? $value['preview'] : $question_template_preview;
if (!empty($aQuestionTemplateAttributes)){
$question_template_preview = $aQuestionTemplateAttributes['value'] == $code ? $value['preview'] : $question_template_preview;
$selected = $aQuestionTemplateAttributes['value'] == $code ? 'selected' : '';
}
if(YII_DEBUG) {
echo sprintf("<option value='%s' %s>%s (code: %s)</option>", $code, $selected, $value['title'], $code);
} else {
Expand Down

0 comments on commit 4caa8b8

Please sign in to comment.