...
 
Commits (3)
......@@ -2,17 +2,39 @@
Add for your admin user a question setting to put javascript snipet added when loading this question.
- **Compatibility** : Need [LS-SondagesPro](https://github.com/SondagesPro/LimeSurvey-SondagesPro) release 1.1.0 and up or with [LimeSurvey](https://www.limesurvey.org/) 2.50_plus_160731 and up.
- **filterxsshtml** : [filterxsshtml](https://manual.limesurvey.org/Optional_settings#Security) is not taken in account when loading attribute.
This add a new advanced setting in all question where user can just put javascript. Usage of {QID} and {SGQ} is allowed.
- **Compatibility** : Need [LS-SondagesPro](https://github.com/SondagesPro/LimeSurvey-SondagesPro) release 1.1.0 and up or with [LimeSurvey](https://www.limesurvey.org/) 2.50_plus_160731 and up.
- With LimeSurvey 2.63 version : you must use 1.0.2
- **filterxsshtml** : [filterxsshtml](https://manual.limesurvey.org/Optional_settings#Security) if it's activated, admin user see it like a readonly attribute (since 2.1.0)
## Installation
### Via GIT
- Go to your LimeSurvey Directory
- Clone in plugins/addScriptToQuestion directory : `git clone https://git.framasoft.org/SondagePro-LimeSurvey-plugin/addScriptToQuestion.git addScriptToQuestion`
- Clone in plugins/addScriptToQuestion directory : `git clone https://gitlab.com/SondagesPro/addScriptToQuestion.git addScriptToQuestion`
### Via ZIP dowload
- Get the file [addScriptToQuestion.zip](https://extensions.sondages.pro/IMG/auto/addScriptToQuestion.zip)
- Extract : `unzip addScriptToQuestion.zip`
- Move the directory to plugins/ directory inside LimeSurvey
## Contribute
Contribution are welcome, for patch and issue : use [gitlab](https://gitlab.com/SondagesPro/addScriptToQuestion) still the preferred solution.
Translation can be done at [translate.sondages.pro](https://translate.sondages.pro/projects/addscripttoquestion/).
If there are issue with english string : it's a PHP issue, not a language issue.
## Home page & Copyright
- HomePage <http://extensions.sondages.pro/>
- Copyright © 2016 Denis Chenu <http://sondages.pro>
- Licence : GNU Affero General Public License <https://www.gnu.org/licenses/agpl-3.0.html>
## Changelog
- 2018-03-09 [2.2.0] Translation
- 2018-03-09 [2.1.0] Usage of XSS security
- 2018-03-08 [2.0.0] LimeSurvey 3.X version (tested on 3.4.4)
- 2017-06-27 [1.0.2] Fix {SGQ} replacement
- 2017-02-20 [1.0.0] Some fix, and compatibility
- 2016-11-17 [0.1.0] Release
<?php
/**
* Allow to add script to question.
* @todo Show (and update/add) the settings according to XSS
*
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2016 Denis Chenu <http://www.sondages.pro>
* @copyright 2016-2018 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 1.0.2
* @version 2.2.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
......@@ -18,7 +17,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
class addScriptToQuestion extends \ls\pluginmanager\PluginBase
class addScriptToQuestion extends PluginBase
{
static protected $name = 'addScriptToQuestion';
......@@ -67,7 +66,11 @@ class addScriptToQuestion extends \ls\pluginmanager\PluginBase
'QID'=>$oEvent->get('qid'),
'SGQ'=>$oEvent->get('surveyId')."X".$oEvent->get('gid')."X".$oEvent->get('qid'),
);
$script=LimeExpressionManager::ProcessString($aAttributes['javascript'], $oEvent->get('qid'), $aReplacement, false, 1, 1, false, false, true);
if(intval(Yii::app()->getConfig('version')) >=3) {
$script=LimeExpressionManager::ProcessString($aAttributes['javascript'], $oEvent->get('qid'), $aReplacement, 2, 0, false, false, true);
} else {
$script=LimeExpressionManager::ProcessString($aAttributes['javascript'], $oEvent->get('qid'), $aReplacement, false, 2, 0, false, false, true);
}
$aAttributes['scriptPosition']=isset($aAttributes['scriptPosition']) ? $aAttributes['scriptPosition'] : CClientScript::POS_END;
App()->getClientScript()->registerScript("scriptAttribute{$oEvent->get('qid')}",$script,$aAttributes['scriptPosition']);
}
......@@ -78,6 +81,7 @@ class addScriptToQuestion extends \ls\pluginmanager\PluginBase
*/
public function addScriptAttribute()
{
$readonly = Yii::app()->getConfig('filterxsshtml') && !Permission::model()->hasGlobalPermission('superadmin', 'read');
$scriptAttributes = array(
'javascript'=>array(
'types'=>'15ABCDEFGHIKLMNOPQRSTUWXYZ!:;|*', /* Whole question type */
......@@ -86,26 +90,28 @@ class addScriptToQuestion extends \ls\pluginmanager\PluginBase
'inputtype'=>'textarea',
'default'=>'', /* not needed (it's already the default) */
'expression'=>1,/* As static */
'help'=>gT('You don\'t have to add script tag, script is register by LimeSurvey. You can use Expression, this expression is static (no update during runtime).'),
'caption'=>gT('Javascript for this question'),
'readonly'=>$readonly,
'help'=>$this->gT("You don't have to add script tag, script is register by LimeSurvey. You can use expressions, this one is static (no update during run-time)."),
'caption'=>$this->gT('Javascript for this question'),
),
);
if($this->get('scriptPositionAvailable',null,null,$this->settings['scriptPositionAvailable']['default'])){
if($this->get('scriptPositionAvailable',null,null,$this->settings['scriptPositionAvailable']['default']) && !$readonly){
$scriptAttributes['scriptPosition']=array(
'types'=>'15ABCDEFGHIKLMNOPQRSTUWXYZ!:;|*', /* Whole question type */
'category'=>gT('Script'),
'sortorder'=>1,
'inputtype'=>'singleselect',
'options'=>array(
CClientScript::POS_HEAD=>"The script is inserted in the head section right before the title element (POS_HEAD).",
CClientScript::POS_BEGIN=>"The script is inserted at the beginning of the body section (POS_BEGIN).",
CClientScript::POS_END=>"The script is inserted at the end of the body section (POS_END).",
CClientScript::POS_LOAD=>"the script is inserted in the window.onload() function (POS_LOAD).",
CClientScript::POS_READY=>"the script is inserted in the jQuery's ready function (POS_READY).",
CClientScript::POS_HEAD=>$this->gT("The script is inserted in the head section right before the title element (POS_HEAD)."),
CClientScript::POS_BEGIN=>$this->gT("The script is inserted at the beginning of the body section (POS_BEGIN)."),
CClientScript::POS_END=>$this->gT("The script is inserted at the end of the body section (POS_END)."),
CClientScript::POS_LOAD=>$this->gT("The script is inserted in the window.onload() function (POS_LOAD)."),
CClientScript::POS_READY=>$this->gT("The script is inserted in the jQuery's ready function (POS_READY)."),
),
'default'=>$this->get('scriptPositionDefault',null,null,$this->settings['scriptPositionDefault']['default']),
'help'=>gT('Set the position of the script, see http://www.yiiframework.com/doc/api/1.1/CClientScript#registerScript-detail .'),
'caption'=>gT('Position for the script'),
'readonly'=>Yii::app()->getConfig('filterxsshtml') && !Permission::model()->hasGlobalPermission('superadmin', 'read'),
'help'=>sprintf($this->gT('Set the position of the script, see <a href="%s">Yii manual</a>.'),'http://www.yiiframework.com/doc/api/1.1/CClientScript#registerScript-detail'),
'caption'=>$this->gT('Position for the script'),
);
}
......
File added
msgid ""
msgstr ""
"Project-Id-Version: addScriptToQuestion\n"
"POT-Creation-Date: 2018-03-09 16:07+0100\n"
"PO-Revision-Date: 2018-03-09 16:17+0100\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.6\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: gT\n"
"Last-Translator: Denis Chenu <contact@sondages.pro>\n"
"Language: fr\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: locale\n"
#: addScriptToQuestion.php:88 addScriptToQuestion.php:101
msgid "Script"
msgstr "Script"
#: addScriptToQuestion.php:94
msgid ""
"You don't have to add script tag, script is register by LimeSurvey. You can "
"use expressions, this one is static (no update during run-time)."
msgstr ""
"Vous n‘avez pas à ajouter la balise script, celle-ci est gérée par "
"LimeSurvey. Vous pouvez utiliser les expressions, celles-ci sont statiques "
"(pas de mise à jour en réel)."
#: addScriptToQuestion.php:95
msgid "Javascript for this question"
msgstr "Java-script pour cette question"
#: addScriptToQuestion.php:105
msgid ""
"The script is inserted in the head section right before the title element "
"(POS_HEAD)."
msgstr ""
"Le script est inséré dans la partie head juste avant la balise title "
"(POS_HEAD)."
#: addScriptToQuestion.php:106
msgid ""
"The script is inserted at the beginning of the body section (POS_BEGIN)."
msgstr "Le script est inséré au début de la partie body (POS_BEGIN)."
#: addScriptToQuestion.php:107
msgid "The script is inserted at the end of the body section (POS_END)."
msgstr "Le script est inséré à la fin de la partie body (POS_END)."
#: addScriptToQuestion.php:108
msgid "The script is inserted in the window.onload() function (POS_LOAD)."
msgstr "Le script est inséré dans la fonction windows.onload() (POS_LOAD)."
#: addScriptToQuestion.php:109
msgid "The script is inserted in the jQuery's ready function (POS_READY)."
msgstr "Le script est inséré dans la fonction de jQuery ready (POS_READY)."
#: addScriptToQuestion.php:113
#, php-format
msgid "Set the position of the script, see <a href=\"%s\">Yii manual</a>."
msgstr ""
"Décider de la position du script, voir <a href=\"%s\">la manuel de Yii</a>."
#: addScriptToQuestion.php:114
msgid "Position for the script"
msgstr "Position du script"
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: addScriptToQuestion\n"
"POT-Creation-Date: 2018-03-09 16:07+0100\n"
"PO-Revision-Date: 2018-03-09 08:54+0100\n"
"Last-Translator: Denis Chenu <contact@sondages.pro>\n"
"Language-Team: \n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.6\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: gT\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: locale\n"
#: addScriptToQuestion.php:88 addScriptToQuestion.php:101
msgid "Script"
msgstr ""
#: addScriptToQuestion.php:94
msgid ""
"You don't have to add script tag, script is register by LimeSurvey. You can "
"use expressions, this one is static (no update during run-time)."
msgstr ""
#: addScriptToQuestion.php:95
msgid "Javascript for this question"
msgstr ""
#: addScriptToQuestion.php:105
msgid ""
"The script is inserted in the head section right before the title element "
"(POS_HEAD)."
msgstr ""
#: addScriptToQuestion.php:106
msgid ""
"The script is inserted at the beginning of the body section (POS_BEGIN)."
msgstr ""
#: addScriptToQuestion.php:107
msgid "The script is inserted at the end of the body section (POS_END)."
msgstr ""
#: addScriptToQuestion.php:108
msgid "The script is inserted in the window.onload() function (POS_LOAD)."
msgstr ""
#: addScriptToQuestion.php:109
msgid "The script is inserted in the jQuery's ready function (POS_READY)."
msgstr ""
#: addScriptToQuestion.php:113
#, php-format
msgid "Set the position of the script, see <a href=\"%s\">Yii manual</a>."
msgstr ""
#: addScriptToQuestion.php:114
msgid "Position for the script"
msgstr ""