| Server IP : 46.105.57.169 / Your IP : 216.73.217.8 Web Server : Apache System : Linux webd003.cluster120.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : maitricfuz ( 93378) PHP Version : 8.4.22 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/m/a/i/maitricfuz/www/saint-martin-lg/media/sourcerer/js/ |
Upload File : |
/**
* @package Sourcerer
* @version 13.0.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2026 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
(function() {
'use strict';
window.RegularLabs = window.RegularLabs || {};
window.RegularLabs.SourcererPopup = window.RegularLabs.SourcererPopup || {
form : null,
options: {},
init: function(editor_name) {
if ( ! parent.RegularLabs.SourcererButton) {
document.querySelector('body').innerHTML = '<div class="alert alert-error">This page cannot function on its own.</div>';
return;
}
if ( ! RegularLabs.Scripts.isEditorReady('code')) {
setTimeout(() => {
RegularLabs.SourcererPopup.init(editor_name);
}, 100);
return;
}
this.options = parent.Joomla.getOptions ? parent.Joomla.getOptions('rl_sourcerer_button', {}) : parent.Joomla.optionsStorage.rl_sourcerer_button || {};
const form = document.getElementById('sourcererForm');
form.editors = RegularLabs.Scripts.getEditors();
parent.RegularLabs.SourcererButton.setForm(form);
if ( ! parent.RegularLabs.Scripts.getEditor(editor_name)) {
return;
}
const source_mode = parent.RegularLabs.Scripts.isEditorSourceMode(editor_name);
let string = parent.RegularLabs.Scripts.getEditorSelection(editor_name, true);
if ( ! source_mode) {
string = this.prepareHtml(string);
}
string = this.prepareText(string);
this.setAttributes(string);
string = this.removeSourceTags(string);
RegularLabs.Scripts.setEditorValue('code', string);
document.getElementById('sourcerer-insert-button').disabled = false;
},
prepareHtml: function(string) {
let regex;
string = this.prepareText(string);
// remove newlines / returns
regex = new RegExp('[\n\r]', 'gim');
string = string.replace(regex, '');
// replace html breaks/paragraphs with newlines
regex = new RegExp('(</p><p>|</?p>|<br ?/?>)', 'gim');
string = string.replace(regex, '\n');
string = string.trim();
// replace tab images with normal tabs
regex = new RegExp('<img[^>]*src="[^"]*/tab.(svg|png)"[^>]*>', 'gim');
string = string.replace(regex, '\t');
// remove remaining html tags
regex = new RegExp('</?[a-z][^>]*>', 'gim');
string = string.replace(regex, '');
// replace html entities with normal characters
string = string.replace(/( | )/gi, ' ');
string = string.replace(/</gi, '<');
string = string.replace(/>/gi, '>');
string = string.replace(/&/gi, '&');
return string;
},
prepareText: function(string) {
// handle non-breaking spaces
const regex = new RegExp(String.fromCharCode(160), 'gim');
string = string.replace(regex, ' ');
// Handle tabs
string = string.replace(/ /g, '\t');
return string;
},
setAttributes: function(string) {
const tag_word = this.options.syntax_word;
const tag_start = this.options.tag_characters[0];
const tag_end = this.options.tag_characters[1];
const start_tag = this.preg_quote(tag_start + tag_word) + '( .*?)' + this.preg_quote(tag_end);
const regex = new RegExp(start_tag, 'gim');
if ( ! string.match(regex)) {
return;
}
const attributes = this.getAttributes(regex.exec(string)[1].trim());
if ('raw' in attributes) {
this.setField('raw', attributes.raw.toBooleanNumber());
}
if ('trim' in attributes) {
this.setField('trim', attributes.trim.toBooleanNumber());
}
},
setPhpField: function(value, method) {
this.setField('php_file', value);
this.setField('php_include_method', method);
},
getAttributes: function(string) {
const attributes = {};
let regex = new RegExp('^0 ?');
if (string.match(regex)) {
attributes.raw = true;
string = string.replace(/^0/, '').trim();
}
regex = new RegExp('([a-z_-]+)="([^"]*)"', 'gim');
if ( ! string.match(regex)) {
return attributes;
}
let match = regex.exec(string);
while (match) {
attributes[match[1]] = match[2];
match = regex.exec(string);
}
return attributes;
},
removeSourceTags: function(string) {
const tag_word = this.options.syntax_word;
const tag_start = this.options.tag_characters[0];
const tag_end = this.options.tag_characters[1];
const start_tag = this.preg_quote(tag_start + tag_word) + '.*?' + this.preg_quote(tag_end);
const end_tag = this.preg_quote(tag_start + '/' + tag_word + tag_end);
let regex = new RegExp('(' + start_tag + ')\\s*', 'gim');
if (string.match(regex)) {
string = string.replace(regex, '');
}
regex = new RegExp('\\s*' + end_tag, 'gim');
string = string.replace(regex, '');
return string.trim();
},
preg_quote: function(str) {
return (str + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, '\\$1');
},
setField: function(name, value) {
const field = document.querySelector('input[name="' + name + '"],select[name="' + name + '"]');
if ( ! field) {
return;
}
if (field.getAttribute('type') === 'radio') {
this.setRadioOption(name, value);
return;
}
field.value = value;
},
setRadioOption: function(name, value) {
const field = document.querySelector('input[name="' + name + '"][value="' + value + '"]');
if ( ! field) {
return;
}
field.checked = true;
},
};
String.prototype.trim = function() {
// fix linebreaks
this.replace(/\r/, "");
// Left trim
this.replace(/^[\n ]*/, "");
// Right trim
this.replace(/[\n ]*$/, "");
return this;
};
String.prototype.toBooleanNumber = function() {
const string = this.toString().valueOf();
return string === '1' || string === 'true' ? 1 : 0;
};
})();