Commit dc0e7a45 authored by Sara Arjona's avatar Sara Arjona
Browse files

Merge branch 'MDL-70721-master' of git://github.com/rezaies/moodle

parents 4f76d406 7ba7920a
......@@ -48,6 +48,6 @@
</div>
<input type="text" name="{{name}}" id="{{id}}" value="{{value}}" size="12" class="form-control text-ltr" {{#readonly}}disabled{{/readonly}}>
{{#haspreviewconfig}}
<input type="button" id="{{id}}_preview" value={{#quote}}{{#str}}preview{{/str}}{{/quote}} class="admin_colourpicker_preview">
<input type="button" id="{{id}}_preview" value="{{#cleanstr}}preview{{/cleanstr}}" class="admin_colourpicker_preview">
{{/haspreviewconfig}}
</div>
......@@ -134,9 +134,9 @@
{{# str }}somefieldsrequired, form, <i class="icon fa fa-exclamation-circle text-danger fa-fw" title="{{# str }} required {{/ str }}" ></i>{{/ str }}
<hr>
<input type="submit" class="btn btn-primary" name="submit" value={{#quote}}{{#str}} next {{/str}}{{/quote}}>
<input type="submit" class="btn btn-primary" name="submit" value="{{#cleanstr}} next {{/cleanstr}}">
{{#cancancel}}
<input type="submit" class="btn btn-secondary" name="cancel" value={{#quote}}{{#str}} cancel {{/str}}{{/quote}}>
<input type="submit" class="btn btn-secondary" name="cancel" value="{{#cleanstr}} cancel {{/cleanstr}}">
{{/cancancel}}
</form>
......
......@@ -57,8 +57,8 @@
<div class="event-name-container flex-grow-1 text-truncate line-height-3">
<h6 class="event-name text-truncate mb-0">
<a href="{{url}}"
title={{#quote}}{{{name}}}{{/quote}}
aria-label='{{#str}} ariaeventlistitem, block_timeline, { "name": {{#quote}}{{{activityname}}}{{/quote}}, "course": {{#quote}}{{{course.fullnamedisplay}}}{{/quote}}, "date": "{{#userdate}} {{timesort}}, {{#str}} strftimedatetime, core_langconfig {{/str}} {{/userdate}}" } {{/str}}'>
title="{{name}}"
aria-label='{{#cleanstr}} ariaeventlistitem, block_timeline, { "name": {{#quote}}{{{activityname}}}{{/quote}}, "course": {{#quote}}{{{course.fullnamedisplay}}}{{/quote}}, "date": "{{#userdate}} {{timesort}}, {{#str}} strftimedatetime, core_langconfig {{/str}} {{/userdate}}" } {{/cleanstr}}'>
{{{activityname}}}</a>
{{#overdue}}<span class="badge badge-pill badge-danger ml-1">{{#str}} overdue, block_timeline {{/str}}</span>{{/overdue}}
</h6>
......
......@@ -74,7 +74,6 @@ class activity_navigation implements renderable, templatable {
$attributes = [
'class' => 'btn btn-link',
'id' => 'prev-activity-link',
'title' => $linkname,
];
$this->prevlink = new \action_link($linkurl, $OUTPUT->larrow() . ' ' . $linkname, null, $attributes);
}
......@@ -90,7 +89,6 @@ class activity_navigation implements renderable, templatable {
$attributes = [
'class' => 'btn btn-link',
'id' => 'next-activity-link',
'title' => $linkname,
];
$this->nextlink = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow(), null, $attributes);
}
......
......@@ -67,7 +67,7 @@
data-itemid="{{instanceid}}"
data-cost="{{cost}}"
data-successurl="{{successurl}}"
data-description={{# quote }}{{description}}{{/ quote }}
data-description="{{description}}"
>
{{# str }} sendpaymentbutton, enrol_fee {{/ str }}
</button>
......
......@@ -49,7 +49,7 @@
{{#rows}}
<div>
<label style="display: inline-block; width: 5em"
{{#id}}for={{#quote}}{{{id}}}-{{{uniqid}}}{{/quote}}{{/id}} {{#hidelabel}}
{{#id}}for="{{id}}-{{uniqid}}"{{/id}} {{#hidelabel}}
class="accesshide"{{/hidelabel}}>{{label}}</label>
<div style="display: inline-block">{{> core/copy_box }}</div>
</div>
......
......@@ -47,8 +47,8 @@
{{/params}}
<input type="button" class="btn btn-secondary selectortrigger"
id="{{id}}"
title={{#quote}}{{tooltip}}{{/quote}}
value={{#quote}}{{label}}{{/quote}}
title="{{tooltip}}"
value="{{label}}"
{{#disabled}}disabled{{/disabled}}>
</div>
</div>
......
......@@ -25,4 +25,4 @@
"value": "Save"
}
}}
<input type="{{type}}" value={{#quote}}{{value}}{{/quote}} class="btn btn-secondary">
<input type="{{type}}" value="{{value}}" class="btn btn-secondary">
......@@ -51,7 +51,7 @@
{{{table}}}
<div id="gradetreesubmit">
{{#showsave}}
<input class="advanced btn btn-primary" type="submit" value={{#quote}}{{#str}}savechanges{{/str}}{{/quote}}>
<input class="advanced btn btn-primary" type="submit" value="{{#cleanstr}}savechanges{{/cleanstr}}">
{{/showsave}}
{{#showbulkmove}}
<div class="form-inline mt-3">
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -572,6 +572,25 @@ function(
return '[[_s' + index + ']]';
};
/**
* String helper to render {{#cleanstr}}abd component { a : 'fish'}{{/cleanstr}}
* into a get_string following by an HTML escape.
*
* @method cleanStringHelper
* @private
* @param {object} context The current mustache context.
* @param {string} sectionText The text to parse the arguments from.
* @param {function} helper Used to render subsections of the text.
* @return {string}
*/
Renderer.prototype.cleanStringHelper = function(context, sectionText, helper) {
var str = this.stringHelper(context, sectionText, helper);
// We're going to use [[_cx]] format for clean strings, where x is a number.
// Hence, replacing 's' with 'c' in the placeholder that stringHelper returns.
return str.replace('s', 'c');
};
/**
* Quote helper used to wrap content in quotes, and escape all quotes present in the content.
*
......@@ -718,6 +737,7 @@ function(
this.requiredJS = [];
context.uniqid = (uniqInstances++);
context.str = this.addHelperFunction(this.stringHelper, context);
context.cleanstr = this.addHelperFunction(this.cleanStringHelper, context);
context.pix = this.addHelperFunction(this.pixHelper, context);
context.js = this.addHelperFunction(this.jsHelper, context);
context.quote = this.addHelperFunction(this.quoteHelper, context);
......@@ -761,13 +781,14 @@ function(
* @return {String} The treated content.
*/
Renderer.prototype.treatStringsInContent = function(content, strings) {
var pattern = /\[\[_s\d+\]\]/,
var pattern = /\[\[_(s|c)\d+\]\]/,
treated,
index,
strIndex,
walker,
char,
strFinal;
strFinal,
isClean;
do {
treated = '';
......@@ -777,8 +798,9 @@ function(
// Copy the part prior to the placeholder to the treated string.
treated += content.substring(0, index);
content = content.substr(index);
isClean = content[3] == 'c';
strIndex = '';
walker = 4; // 4 is the length of '[[_s'.
walker = 4; // 4 is the length of either '[[_s' or '[[_c'.
// Walk the characters to manually extract the index of the string from the placeholder.
char = content.substr(walker, 1);
......@@ -791,11 +813,15 @@ function(
// Get the string, add it to the treated result, and remove the placeholder from the content to treat.
strFinal = strings[parseInt(strIndex, 10)];
if (typeof strFinal === 'undefined') {
Log.debug('Could not find string for pattern [[_s' + strIndex + ']].');
Log.debug('Could not find string for pattern [[_' + (isClean ? 'c' : 's') + strIndex + ']].');
strFinal = '';
}
if (isClean) {
strFinal = mustache.escape(strFinal);
}
treated += strFinal;
content = content.substr(6 + strIndex.length); // 6 is the length of the placeholder without the index: '[[_s]]'.
content = content.substr(6 + strIndex.length); // 6 is the length of the placeholder without the index.
// That's either '[[_s]]' or '[[_c]]'.
// Find the next placeholder.
index = content.search(pattern);
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mustache helper to load strings from string_manager and perform HTML escaping on them.
*
* @package core
* @category output
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\output;
use Mustache_LambdaHelper;
/**
* This class will load language strings in a template.
*
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 4.0
*/
class mustache_clean_string_helper {
/** @var mustache_string_helper A string helper instance that is being used internally for fetching strings */
private $stringhelper;
/**
* Create new instance of mustache clean string helper.
*/
public function __construct() {
$this->stringhelper = new \core\output\mustache_string_helper();
}
/**
* Read a lang string from a template and get it from get_string.
*
* Some examples for calling this from a template are:
*
* {{#cleanstr}}activity{{/cleanstr}}
* {{#cleanstr}}actionchoice, core, {{#str}}delete{{/str}}{{/cleanstr}} (Together with the str helper)
* {{#cleanstr}}addinganewto, core, {"what":"This", "to":"That"}{{/cleanstr}} (Complex $a)
*
* The args are comma separated and only the first is required.
* The last is a $a argument for get string. For complex data here, use JSON.
*
* @param string $text The text to parse for arguments.
* @param Mustache_LambdaHelper $helper Used to render nested mustache variables.
* @return string
*/
public function cleanstr($text, Mustache_LambdaHelper $helper) {
return s($this->stringhelper->str($text, $helper));
}
}
......@@ -105,6 +105,7 @@ class renderer_base {
$loader = new \core\output\mustache_filesystem_loader();
$stringhelper = new \core\output\mustache_string_helper();
$cleanstringhelper = new \core\output\mustache_clean_string_helper();
$quotehelper = new \core\output\mustache_quote_helper();
$jshelper = new \core\output\mustache_javascript_helper($this->page);
$pixhelper = new \core\output\mustache_pix_helper($this);
......@@ -116,6 +117,7 @@ class renderer_base {
$helpers = array('config' => $safeconfig,
'str' => array($stringhelper, 'str'),
'cleanstr' => array($cleanstringhelper, 'cleanstr'),
'quote' => array($quotehelper, 'quote'),
'js' => array($jshelper, 'help'),
'pix' => array($pixhelper, 'pix'),
......
......@@ -52,11 +52,11 @@
}
}}
{{^disabled}}
<a href="{{{url}}}" id="{{id}}" class="{{classes}}" {{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}} {{/attributes}}>{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{{text}}}</a>
<a href="{{{url}}}" id="{{id}}" class="{{classes}}" {{#attributes}} {{name}}="{{value}}" {{/attributes}}>{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{{text}}}</a>
{{#hasactions}}
{{> core/actions }}
{{/hasactions}}
{{/disabled}}
{{#disabled}}
<span class="currentlink {{classes}}" {{#attributes}} {{name}}={{#quote}}{{value}}{{/quote}} {{/attributes}}>{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{{text}}}</span>
<span class="currentlink {{classes}}" {{#attributes}} {{name}}="{{value}}" {{/attributes}}>{{#icon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/icon}}{{text}}</span>
{{/disabled}}
......@@ -27,7 +27,7 @@
}
}}
{{^disabled}}
<a href="{{url}}" class="{{$actionmenulinkclasses}}aabtn {{classes}}{{/actionmenulinkclasses}}" {{#attributes}}{{name}}={{#quote}}{{value}}{{/quote}} {{/attributes}}{{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>
<a href="{{url}}" class="{{$actionmenulinkclasses}}aabtn {{classes}}{{/actionmenulinkclasses}}" {{#attributes}}{{name}}="{{value}}" {{/attributes}}{{#showtext}}aria-labelledby="actionmenuaction-{{instance}}"{{/showtext}}>
{{#icon}}
{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}
{{/icon}}
......
......@@ -26,7 +26,7 @@
data-block="{{type}}"
data-instance-id="{{blockinstanceid}}"
{{#arialabel}}
aria-label={{#quote}}{{{arialabel}}}{{/quote}}
aria-label="{{arialabel}}"
{{/arialabel}}
{{^arialabel}}
{{#title}}
......
......@@ -68,8 +68,8 @@
</div>
<div class="submitbuttons">
<input type="submit" name="submitbutton" class="submitbutton btn btn-primary" value={{#quote}}{{#str}}add{{/str}}{{/quote}}>
<input type="submit" name="addcancel" class="addcancel btn btn-secondary" value={{#quote}}{{#str}}cancel{{/str}}{{/quote}}>
<input type="submit" name="submitbutton" class="submitbutton btn btn-primary" value="{{#cleanstr}}add{{/cleanstr}}">
<input type="submit" name="addcancel" class="addcancel btn btn-secondary" value="{{#cleanstr}}cancel{{/cleanstr}}">
</div>
</form>
......
......@@ -31,7 +31,7 @@
Example context (json):
{ "text": "Copyable text"}
}}
<input type="text" class="copy_box" value="{{{ text }}}" readonly="readonly" size="48" {{#id}}id={{#quote}}{{{id}}}-{{{uniqid}}}{{/quote}}{{/id}}/>
<input type="text" class="copy_box" value="{{{ text }}}" readonly="readonly" size="48" {{#id}}id="{{id}}-{{uniqid}}"{{/id}}/>
{{# js }}
require(['jquery'], function($) {
$('.copy_box').on('click', function() {
......
......@@ -137,15 +137,15 @@
<input type="text" name="username" id="username" {{!
!}}class="form-control" {{!
!}}value="{{username}}" {{!
!}}placeholder={{#quote}}{{^canloginbyemail}}{{#str}}username{{/str}}{{/canloginbyemail}}{{!
!}}{{#canloginbyemail}}{{#str}}usernameemail{{/str}}{{/canloginbyemail}}{{/quote}} {{!
!}}placeholder="{{^canloginbyemail}}{{#cleanstr}}username{{/cleanstr}}{{/canloginbyemail}}{{!
!}}{{#canloginbyemail}}{{#cleanstr}}usernameemail{{/cleanstr}}{{/canloginbyemail}}" {{!
!}}autocomplete="username">
</div>
<div class="login-form-password form-group">
<label for="password" class="sr-only">{{#str}} password {{/str}}</label>
<input type="password" name="password" id="password" value="" {{!
!}}class="form-control" {{!
!}}placeholder={{#quote}}{{#str}}password{{/str}}{{/quote}} {{!
!}}placeholder="{{#cleanstr}}password{{/cleanstr}}" {{!
!}}autocomplete="current-password">
</div>
{{#rememberusername}}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment