provide a custom jsmart because friendica delimters diddn't work with the original

This commit is contained in:
rabuzarus 2016-05-05 18:39:15 +02:00
parent 75c76775a5
commit 462a942df2
2 changed files with 3520 additions and 41 deletions

File diff suppressed because it is too large Load diff

View file

@ -692,7 +692,11 @@
{ {
var params = getActualParamValues(node.params, data); var params = getActualParamValues(node.params, data);
var a = params.from; var a = params.from;
if (!(a instanceof Object)) if (typeof a == 'undefined')
{
a = [];
}
if (typeof a != 'object')
{ {
a = [a]; a = [a];
} }
@ -1794,11 +1798,14 @@
{ {
s = s ? '1' : ''; s = s ? '1' : '';
} }
if (s == null) {
s = '';
}
if (tree.length == 1) if (tree.length == 1)
{ {
return s; return s;
} }
res += s; res += s!==null ? s : '';
if (data.smarty['continue'] || data.smarty['break']) if (data.smarty['continue'] || data.smarty['break'])
{ {
@ -2885,11 +2892,13 @@
aEncoded += address.substr(i,1); aEncoded += address.substr(i,1);
} }
} }
aEncoded = aEncoded.toLowerCase();
var tEncoded = ''; var tEncoded = '';
for (var i=0; i<text.length; ++i) for (var i=0; i<text.length; ++i)
{ {
tEncoded += '&#x' + jSmart.prototype.PHPJS('bin2hex','mailto').bin2hex(text.substr(i,1)) + ';'; tEncoded += '&#x' + jSmart.prototype.PHPJS('bin2hex','mailto').bin2hex(text.substr(i,1)) + ';';
} }
tEncoded = tEncoded.toLowerCase();
return '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' + aEncoded + '" ' + extra + '>' + tEncoded + '</a>'; return '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;' + aEncoded + '" ' + extra + '>' + tEncoded + '</a>';
} }
return s; return s;
@ -2941,6 +2950,8 @@
return ''; return '';
} }
content = new String(content);
var wrap = params.__get('wrap',80); var wrap = params.__get('wrap',80);
var wrap_char = params.__get('wrap_char','\n'); var wrap_char = params.__get('wrap_char','\n');
var wrap_cut = params.__get('wrap_cut',false); var wrap_cut = params.__get('wrap_cut',false);
@ -2990,6 +3001,9 @@
'modifier', 'modifier',
'capitalize', 'capitalize',
function(s, upDigits, lcRest) { function(s, upDigits, lcRest) {
if (typeof s != 'string') {
return s;
}
var re = new RegExp(upDigits ? '[^a-zA-Z_\u00E0-\u00FC]+' : '[^a-zA-Z0-9_\u00E0-\u00FC]'); var re = new RegExp(upDigits ? '[^a-zA-Z_\u00E0-\u00FC]+' : '[^a-zA-Z0-9_\u00E0-\u00FC]');
var found = null; var found = null;
var res = ''; var res = '';
@ -3024,7 +3038,7 @@
function(s, value) function(s, value)
{ {
value = value ? value : ''; value = value ? value : '';
return s + value; return new String(s) + value;
} }
); );
@ -3060,6 +3074,7 @@
'count_characters', 'count_characters',
function(s, includeWhitespaces) function(s, includeWhitespaces)
{ {
s = new String(s);
return includeWhitespaces ? s.length : s.replace(/\s/g,'').length; return includeWhitespaces ? s.length : s.replace(/\s/g,'').length;
} }
); );
@ -3069,7 +3084,7 @@
'count_paragraphs', 'count_paragraphs',
function(s) function(s)
{ {
var found = s.match(/\n+/g); var found = (new String(s)).match(/\n+/g);
if (found) if (found)
{ {
return found.length+1; return found.length+1;
@ -3083,10 +3098,13 @@
'count_sentences', 'count_sentences',
function(s) function(s)
{ {
var found = s.match(/[^\s]\.(?!\w)/g); if (typeof s == 'string')
if (found)
{ {
return found.length; var found = s.match(/[^\s]\.(?!\w)/g);
if (found)
{
return found.length;
}
} }
return 0; return 0;
} }
@ -3097,10 +3115,13 @@
'count_words', 'count_words',
function(s) function(s)
{ {
var found = s.match(/\w+/g); if (typeof s == 'string')
if (found)
{ {
return found.length; var found = s.match(/\w+/g);
if (found)
{
return found.length;
}
} }
return 0; return 0;
} }
@ -3139,7 +3160,7 @@
return s.replace(/&lt;/g, '<').replace(/&gt;/g,'>').replace(/&#039;/g,"'").replace(/&quot;/g,'"'); return s.replace(/&lt;/g, '<').replace(/&gt;/g,'>').replace(/&#039;/g,"'").replace(/&quot;/g,'"');
case 'entity': case 'entity':
case 'htmlall': case 'htmlall':
return jSmart.prototype.PHPJS('html_entity_decode','unescape').html_entity_decode(s, 0); return jSmart.prototype.PHPJS('html_entity_decode','unescape').html_entity_decode(s, 1);
case 'url': case 'url':
return jSmart.prototype.PHPJS('rawurldecode','unescape').rawurldecode(s); return jSmart.prototype.PHPJS('rawurldecode','unescape').rawurldecode(s);
}; };
@ -3176,13 +3197,13 @@
var res = ''; var res = '';
for (var i=0; i<s.length; ++i) for (var i=0; i<s.length; ++i)
{ {
res += '%' + jSmart.prototype.PHPJS('bin2hex','escape').bin2hex(s.substr(i,1)); res += '%' + jSmart.prototype.PHPJS('bin2hex','escape').bin2hex(s.substr(i,1)).toLowerCase();
} }
return res; return res;
case 'hexentity': case 'hexentity':
var res = ''; var res = '';
for (var i=0; i<s.length; ++i) { for (var i=0; i<s.length; ++i) {
res += '&#x' + jSmart.prototype.PHPJS('bin2hex','escape').bin2hex(s.substr(i,1)).toLowerCase() + ';'; res += '&#x' + jSmart.prototype.PHPJS('bin2hex','escape').bin2hex(s.substr(i,1)) + ';';
} }
return res; return res;
case 'decentity': case 'decentity':
@ -3218,6 +3239,7 @@
'indent', 'indent',
function(s, repeat, indentWith) function(s, repeat, indentWith)
{ {
s = new String(s);
repeat = repeat ? repeat : 4; repeat = repeat ? repeat : 4;
indentWith = indentWith ? indentWith : ' '; indentWith = indentWith ? indentWith : ' ';
@ -3237,7 +3259,7 @@
'lower', 'lower',
function(s) function(s)
{ {
return s.toLowerCase(); return new String(s).toLowerCase();
} }
); );
@ -3246,7 +3268,7 @@
'nl2br', 'nl2br',
function(s) function(s)
{ {
return s.replace(/\n/g,'<br />\n'); return new String(s).replace(/\n/g,'<br />\n');
} }
); );
@ -3297,7 +3319,7 @@
{ {
space = ' '; space = ' ';
} }
return s.replace(/(\n|.)(?!$)/g,'$1'+space); return (new String(s)).replace(/(\n|.)(?!$)/g,'$1'+space);
} }
); );
@ -3344,6 +3366,7 @@
'truncate', 'truncate',
function(s, length, etc, breakWords, middle) function(s, length, etc, breakWords, middle)
{ {
s = new String(s);
length = length ? length : 80; length = length ? length : 80;
etc = (etc!=null) ? etc : '...'; etc = (etc!=null) ? etc : '...';
@ -3373,7 +3396,7 @@
'upper', 'upper',
function(s) function(s)
{ {
return s.toUpperCase(); return (new String(s)).toUpperCase();
} }
); );
@ -3382,33 +3405,33 @@
'wordwrap', 'wordwrap',
function(s, width, wrapWith, breakWords) function(s, width, wrapWith, breakWords)
{ {
width = width || 80; width = width || 80;
wrapWith = wrapWith || '\n'; wrapWith = wrapWith || '\n';
var lines = s.split('\n'); var lines = (new String(s)).split('\n');
for (var i=0; i<lines.length; ++i) for (var i=0; i<lines.length; ++i)
{ {
var line = lines[i]; var line = lines[i];
var parts = '' var parts = ''
while (line.length > width) while (line.length > width)
{ {
var pos = 0; var pos = 0;
var found = line.slice(pos).match(/\s+/); var found = line.slice(pos).match(/\s+/);
for (;found && (pos+found.index)<=width; found=line.slice(pos).match(/\s+/)) for (;found && (pos+found.index)<=width; found=line.slice(pos).match(/\s+/))
{ {
pos += found.index + found[0].length; pos += found.index + found[0].length;
} }
pos = pos || (breakWords ? width : (found ? found.index+found[0].length : line.length)); pos = pos || (breakWords ? width : (found ? found.index+found[0].length : line.length));
parts += line.slice(0,pos).replace(/\s+$/,'');// + wrapWith; parts += line.slice(0,pos).replace(/\s+$/,'');// + wrapWith;
if (pos < line.length) if (pos < line.length)
{ {
parts += wrapWith; parts += wrapWith;
} }
line = line.slice(pos); line = line.slice(pos);
} }
lines[i] = parts + line; lines[i] = parts + line;
} }
return lines.join('\n'); return lines.join('\n');
} }
); );