Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,344 @@
/**
* Priority groups list controller
*/
window.$ = jQuery;
var listController = {
// Node storage
$container: '',
$noPG: '',
$pgInput: '',
// Others objects
groupsObject: {},
init: function (args) {
// this.$variable = args[variable];
var $this = this;
$.each(args, function (k, v) {
$this[k] = v;
});
$this.$groupSample = $this.$container.find('.pg_rule_group').detach();
},
printGroups: function () {
var $this = this;
$this.$container.html('');
$.each($this.groupsObject, function (i, o) {
var n = $this.$groupSample.clone();
var groupID = i + 1;
n.data('groupid', groupID);
$('span.pg_name', n).html(o.name);
var plural = o.rules.length == 1 ? '' : 's';
$('span.pg_info', n).html(o.rules.length + ' rule' + plural + '. Priority: ' + o.priority);
n.appendTo($this.$container);
});
if ($this.groupsObject.length == 0) {
$this.$noPG.removeClass('hiddend');
} else {
$this.$noPG.addClass('hiddend');
}
},
saveGroups: function () {
var $this = this;
$this.$pgInput.val(WD_Helpers.Base64.encode(JSON.stringify($this.groupsObject)));
},
deleteGroup: function (id) {
var $this = this;
this.groupsObject.splice(id, 1);
this.saveGroups();
},
deleteGroups: function () {
var $this = this;
this.groupsObject = [];
this.saveGroups();
}
};
/**
* Modal window Group and Rule editor controller
*/
var mgController = {
$group: {}, // Group node list (except the rule editor)
$rules: '', // Rules container
$ruleEditor: '', // Rule editor container
$selectedTaxTerms: '', // Selected taxonomy terms container
$fields: '', // Fields in Rule editor
$addRuleBTN: '', // Add Rule button
$ruleSample: '',
// Others objects
groupsObject: {},
modalOriginalStates: {},
editorOriginalStates: {},
openedRuleGroup: {},
defaultRule: {},
_taxTermNames: {}, // Temporary storage for taxonomy term names in use
init: function(args) {
var $this = this;
// this.$variable = args[variable];
$.each(args, function(k, v){
$this[k] = v;
});
$('select, input', $this.$group.editor).each(function(){
$this.modalOriginalStates[$(this).attr('name')] = $(this).val();
});
$this.$ruleEditor.find('select, input').each(function(){
$this.editorOriginalStates[$(this).attr('name')] = $(this).val();
});
$this.$ruleSample = $this.$rules.find('p').detach();
},
resetRuleEditor: function() {
var $this = this;
$.each($this.editorOriginalStates, function(k, o){
$('*[name="' + k + '"]', $this.$ruleEditor).val(o);
});
$this.$selectedTaxTerms.html('');
},
openRuleEditor: function(id) {
var $this = this;
$this.resetRuleEditor();
var rules = $this.openedRuleGroup.rules;
// Set the latest rule, if the id is not defined
id = typeof id == 'undefined' ? rules.length - 1 : id;
if ( id < 0 )
return false;
var name = typeof rules[id] != 'undefined' ? rules[id].name : 'New rule';
if ( id > -1 ) {
$this.loadRule(id);
}
$this.$ruleEditor.data('rule-id', id);
$('.re_label', $this.$ruleEditor).html('Editing: ' + name);
$this.$ruleEditor.removeClass('hiddend');
$this.$rules.addClass('hiddend');
$this.$addRuleBTN.addClass('hiddend');
$('>p', $this.$ruleEditor).addClass('hiddend');
},
closeRuleEditor: function () {
var $this = this;
$this.$rules.removeClass('hiddend');
$this.$ruleEditor.addClass('hiddend');
$this.$addRuleBTN.removeClass('hiddend');
$('>p', $this.$ruleEditor).removeClass('hiddend');
},
printRules: function() {
var $this = this;
var rules = $this.openedRuleGroup.rules;
$this.$rules.html('');
$.each(rules, function(i, r){
var $r = $this.$ruleSample.clone();
var id = i + 0;
$r.addClass('pg_rule_' + id);
$r.data('id', id);
$r.find('span').html(r.name);
$r.appendTo($this.$rules);
});
},
maxRulesCheck: function() {
var $this = this;
var maxRules = 4;
if ( $this.openedRuleGroup.rules.length >= maxRules ) {
$this.$addRuleBTN.attr('disabled', 'disabled');
} else {
$this.$addRuleBTN.removeAttr('disabled');
}
},
loadRule: function(id) {
var $this = this;
var rules = $this.openedRuleGroup.rules;
if (
typeof rules[id] != 'undefined'
) {
var rule = rules[id];
if ( rule.rule_field != 0 ) {
$this.toEditor(rule);
$('.pg_rule_'+rule.field, $this.$ruleEditor).removeClass('hiddend');
}
}
},
saveOpenRule: function() {
var $this = this;
if ( !$this.$ruleEditor.hasClass('hiddend') ) {
var id = $this.$ruleEditor.data('rule-id');
return $this.saveRule(id);
}
},
saveRule: function(id) {
var $this = this;
var rules = $this.openedRuleGroup.rules;
if ( id == -1 ) {
// Safe add new rule
rules.push( JSON.parse(JSON.stringify($this.defaultRule)) );
} else {
var rule = $this.fromEditor();
if ( typeof(rules[id]) != 'undefined' )
rules[id] = rule;
else
rules.push(rule);
}
return rules;
},
deleteRule: function(id) {
var $this = this;
var rules = $this.openedRuleGroup.rules;
if ( typeof(rules[id]) != 'undefined' ) {
rules.splice(id, 1);
}
return rules;
},
fromEditor: function() {
var $this = this;
var rule = $.extend({}, $this.defaultRule);
var $f = $this.$fields;
rule.name = $f.name.val();
rule.field = $f.field.val();
switch(rule.field) {
case 'tax':
rule.operator = $f.termOperator.val();
rule.values = {};
$.each($f.termValues.find('li'), function(i, o){
var tax = $(this).data('taxonomy');
var id = $(this).data('id');
rule.values[tax] = rule.values[tax] || [];
if ( $.inArray(id, rule.values[tax]) )
rule.values[tax].push(id);
$this._taxTermNames[tax] = $this._taxTermNames[tax] || {};
$this._taxTermNames[tax][id] = $(this).text();
});
break;
case 'cf':
rule.operator = $f.cfOperator.val();
rule.values = {};
rule.values[$f.cfField.val()] = [];
if ( $f.cfVal1.val() != '' )
rule.values[$f.cfField.val()].push($f.cfVal1.val());
if ( $f.cfVal2.val() != '' )
rule.values[$f.cfField.val()].push($f.cfVal2.val());
break;
case 'title':
rule.operator = $f.titleOperator.val();
rule.values = [];
if ( $f.titleValue.val() != '' )
rule.values.push($f.titleValue.val());
break;
}
return rule;
},
toEditor: function(rule) {
var $this = this;
// Load rule values to editor
var $f = $this.$fields;
$f.name.val(rule.name).trigger('change');
$f.field.val(rule.field).trigger('change');
switch(rule.field) {
case 'tax':
$f.termOperator.val(rule.operator).trigger('change');
$.each(rule.values, function(tax, ids){
$.each(ids, function(kk, id){
var $li = $('<li>');
$li.html($this._findTermName(rule, tax, id));
$li.addClass('t_'+tax+'_'+id);
$li.data('taxonomy', tax);
$li.data('id', id);
$li.appendTo($this.$selectedTaxTerms);
});
});
break;
case 'cf':
$f.cfOperator.val(rule.operator).trigger('change');
$.each(rule.values, function(k, o){
$f.cfField.val(k);
if ( typeof o[0] !== 'undefined' )
$f.cfVal1.val(o[0]);
if ( typeof o[1] !== 'undefined' )
$f.cfVal2.val(o[1]);
return false;
});
break;
case 'title':
$f.titleOperator.val(rule.operator);
if ( typeof rule.values[0] !== 'undefined' )
$f.titleValue.val(rule.values[0]);
break;
}
},
saveRuleGroup: function(id) {
var $this = this;
$this.openedRuleGroup.name = $this.$group.name.val();
$this.openedRuleGroup.instance = $this.$group.instance.val();
$this.openedRuleGroup.priority = $this.$group.priority.val();
$this.openedRuleGroup.phrase_logic = $this.$group.phraseLogic.val();
$this.openedRuleGroup.logic = $this.$group.ruleLogic.val();
if ( $this.openedRuleGroup.phrase_logic != 'disabled' ) {
$this.openedRuleGroup.phrase = $this.$group.phrase.val();
} else {
$this.openedRuleGroup.phrase = '';
}
if ( id == -1 ) {
$this.groupsObject.push($this.openedRuleGroup);
} else {
$this.groupsObject[id] = $this.openedRuleGroup;
}
},
loadRuleGroup: function(g) {
var $this = this;
if ( typeof g != 'undefined' )
$this.openedRuleGroup = g;
$.each($this.modalOriginalStates, function (k, o) {
$('*[name="' + k + '"]', $this.$group.editor).val(o);
});
if ( typeof $this.openedRuleGroup != 'undefined' ) {
// Group editor stuff
$this.$group.name.val($this.openedRuleGroup.name);
$this.$group.instance.val($this.openedRuleGroup.instance);
$this.$group.priority.val($this.openedRuleGroup.priority);
$this.$group.phrase.val($this.openedRuleGroup.phrase);
$this.$group.phraseLogic.val($this.openedRuleGroup.phrase_logic).trigger('change');
$this.$group.ruleLogic.val($this.openedRuleGroup.logic).trigger('change');
// Rule editor stuff
if ( typeof $this.openedRuleGroup.rules != 'undefined' ) {
$this.closeRuleEditor();
//ruleEditorPrintRules(g.rules);
$this.printRules();
$this.maxRulesCheck();
}
}
},
// ----------------- HELPER PRIVATE METHODS ------------------------
_findTermName: function(rule, tax, id) {
var $this = this;
// Look within recent tax term names
if ( typeof $this._taxTermNames[tax] != 'undefined' &&
typeof $this._taxTermNames[tax][id] != 'undefined'
)
return $this._taxTermNames[tax][id];
// Look within the initial printed tax term names
if ( typeof rule._values != 'undefined' &&
typeof rule._values[tax] != 'undefined' &&
typeof rule._values[tax][id] != 'undefined'
)
return rule._values[tax][id];
return '';
}
};

View File

@@ -0,0 +1,302 @@
jQuery(function($){
// --------------------------------------- INIT VARIABLES --------------------------------------------------------------
var $pgEditor = $('#asp_pg_editor').detach();
var openedRuleGroupDef = {
priority: 100,
name: 'Priority Group',
phrase: '',
phrase_logic: 'disabled',
instance: 0,
logic: 'and',
rules: []
};
var openedRuleGroup = JSON.parse(JSON.stringify(openedRuleGroupDef)); // Reference to the currently opened group
// Reference to the whole groups array - this is gettings saved
var groupsObject = JSON.parse(WD_Helpers.Base64.decode($('#priority_groups').val()));
var initialValue = $('#priority_groups').val(); // Used to check whenever the user leaves the page
var submit_clicked = false; // Used to check whenever the user leaves the page
listController.init({
// Node storage
$container: $('#pg_container'),
$noPG: $('#pg_no_pg'),
$pgInput: $('#priority_groups'),
// Others objects
groupsObject: groupsObject
});
mgController.init({
$group: {
editor: $pgEditor,
name: $('#ruleset_name', $pgEditor), // Group name input
priority: $('#pg_priority', $pgEditor), // Group priority input
instance: $('#pg_instance', $pgEditor), // Search instance to affect
phrase: $('#pg_phrase', $pgEditor), // Group Phrase
phraseLogic: $('#pg_phrase_logic', $pgEditor), // Group Phrase Logic
ruleLogic: $('#pg_rule_logic', $pgEditor) // Group Rules Logic
},
$rules: $('#pg_rules_container', $pgEditor),
$ruleEditor: $('#pg_rule_editor', $pgEditor),
$selectedTaxTerms: $('#pg_selected_tax_terms', $pgEditor),
$addRuleBTN: $('#pg_add_rule', $pgEditor),
$fields: {
name: $('#pg_rule_editor', $pgEditor).find('input[name=rule_name]'),
field: $('#pg_rule_editor', $pgEditor).find('select[name=rule_field]'),
termOperator: $('#pg_rule_editor', $pgEditor).find('select[name=term_operator]'),
cfOperator: $('#pg_rule_editor', $pgEditor).find('select[name=cf_operator]'),
titleOperator: $('#pg_rule_editor', $pgEditor).find('select[name=title_operator]'),
termValues: $('#pg_rule_editor', $pgEditor).find('#pg_selected_tax_terms'),
cfField: $('#pg_rule_editor', $pgEditor).find('input[name=pg_search_cf]'),
cfVal1: $('#pg_rule_editor', $pgEditor).find('input[name=cf_val1]'),
cfVal2: $('#pg_rule_editor', $pgEditor).find('input[name=cf_val2]'),
titleValue: $('#pg_rule_editor', $pgEditor).find('input[name=title_value]')
},
groupsObject: groupsObject,
openedRuleGroup: openedRuleGroup,
defaultRule: {
'name' : 'Rule name',
'field' : 'tax', // 'tax', 'cf', 'title'
'operator' : 'in', // in, not in, like, not like, elike, =, <>, >, <, >=, <=, BETWEEN
'values' : []
}
});
listController.printGroups();
// Modal controller shorthand reference
var mw = window.WPD_Modal;
// Set the modal content only once, to prevent event detaching
// ..use it later with the 'leaveContent: true' param
mw.options({
'content': $pgEditor
});
mw.layout({
'max-width': '640px',
'width': '640px'
});
// ---------------------------------------------------------------------------------------------------------------------
// -------------------------------------- GROUP LISTING & BUTTONS ------------------------------------------------------
// Add new group
$('#pg_add_new').on('click', function(){
$pgEditor.removeClass('hiddend');
mw.options({
'type': 'info',
'header': msg('msg_npg'),
'leaveContent': true,
'buttons': {
'okay': {
'text': msg('msg_sav'),
'type': 'okay',
'click': function(e, button){
mgController.saveOpenRule();
mgController.closeRuleEditor();
mgController.saveRuleGroup(-1);
listController.printGroups();
listController.saveGroups();
}
},
'cancel': {
'text': msg('msg_can'),
'type': 'cancel',
'click': function(e, button){}
}
}
});
openedRuleGroup = JSON.parse(JSON.stringify(openedRuleGroupDef));
mgController.loadRuleGroup(openedRuleGroup);
mw.show();
});
// Edit existing group
$('#pg_container').on('click', '.pg_rg_edit', function(){
var id = $(this).closest('.pg_rule_group').data('groupid') - 1;
if ( typeof groupsObject[id] == 'undefined' )
return false;
openedRuleGroup = JSON.parse(JSON.stringify(groupsObject[id]));
$pgEditor.removeClass('hiddend');
mw.options({
'type': 'info',
'header': msg('msg_epg') + ' ' + openedRuleGroup.name,
'leaveContent': true,
'buttons': {
'okay': {
'text': msg('msg_sav'),
'type': 'okay',
'click': function(e, button){
mgController.saveOpenRule();
mgController.closeRuleEditor();
mgController.saveRuleGroup(id);
listController.printGroups();
$('#priority_groups').val(WD_Helpers.Base64.encode(JSON.stringify(groupsObject)));
}
},
'cancel': {
'text': msg('msg_can'),
'type': 'cancel',
'click': function(e, button){}
}
}
});
mgController.loadRuleGroup(openedRuleGroup);
mw.show();
});
// Delete a group
$('#pg_container').on('click', '.pg_rg_delete', function(){
var id = $(this).closest('.pg_rule_group').data('groupid') - 1;
if ( typeof groupsObject[id] == 'undefined' )
return false;
var sure = confirm( sprintf(msg('msg_del'), groupsObject[id].name) );
if ( sure ) {
listController.deleteGroup(id);
listController.printGroups();
}
});
// Save all groups
$('#pg_save').on('click', function(){
submit_clicked = true;
$(this).closest('form').submit();
});
// Delete all groups
$('#pg_remove_all').on('click', function(e){
e.preventDefault();
if ( confirm( msg('msg_dal') ) ) {
listController.deleteGroups();
submit_clicked = true;
$(this).closest('form').submit();
}
});
// ---------------------------------------------------------------------------------------------------------------------
// -------------------------------------- GROUP EDITOR INTERACTIONS ----------------------------------------------------
// Phrase logic change
$('#pg_phrase_logic').on('change', function(){
if ( $(this).val() == 'disabled' ) {
$('#pg_phrase').attr('disabled', 'disabled');
$('label[for=pg_phrase]').attr('disabled', 'disabled');
} else {
$('#pg_phrase').removeAttr('disabled');
$('label[for=pg_phrase]').removeAttr('disabled');
}
});
$('#pg_phrase_logic').trigger('change');
// Chose rule type
$('#wpd_modal_inner').on('change', 'select[name=rule_field]', function(){
$('#pg_rule_editor').find('.pg_rule_tax, .pg_rule_cf, .pg_rule_title').addClass('hiddend');
if ( $(this).val() != 0 ) {
$('#pg_rule_editor').find('.pg_rule_' + $(this).val()).removeClass('hiddend');
}
});
// Priority input
$('#wpd_modal_inner').on('input', '#pg_priority', function(e){
var val = $(this).val();
if ( val == '' ) {
$(this).val(0);
} else {
val = parseInt($(this).val());
var fval = Math.min(5000, Math.max(0, val));
if (val != fval)
$(this).val(fval);
}
});
// ---------------------------------------------------------------------------------------------------------------------
// -------------------------------------- RULE EDITOR BUTTONS ----------------------------------------------------------
// New rule button
$('#wpd_modal_inner').on('click', '#pg_add_rule', function(){
mgController.saveRule(-1);
mgController.printRules();
mgController.closeRuleEditor();
mgController.maxRulesCheck();
mgController.openRuleEditor();
});
// Edit rule icon
$('#wpd_modal_inner').on('click', '.pg_edit_rule', function(){
mgController.openRuleEditor($(this).closest('p').data('id'));
});
// Delete rule icon
$('#wpd_modal_inner').on('click', '.pg_delete_rule', function(){
if ( confirm( msg('msg_dru') ) ) {
mgController.closeRuleEditor();
mgController.deleteRule($(this).closest('p').data('id'));
mgController.printRules();
mgController.maxRulesCheck();
}
});
// Save rule button
$('#wpd_modal_inner').on('click', '#pg_editor_save_rule', function(){
mgController.saveOpenRule();
mgController.closeRuleEditor();
mgController.printRules();
mgController.maxRulesCheck();
});
// Delete rule button
$('#wpd_modal_inner').on('click', '#pg_editor_delete_rule', function(){
if ( confirm( msg('msg_dru') ) ) {
var id = $('#pg_rule_editor').data('rule-id');
mgController.deleteRule(id);
mgController.printRules();
mgController.maxRulesCheck();
mgController.closeRuleEditor();
}
});
// ---------------------------------------------------------------------------------------------------------------------
// -------------------------------------- RULE EDITOR OTHER INTERACTIONS -----------------------------------------------
// Taxonomy search interactions
$('#asp_pg_editor')
.on('wd_taxterm_search_end wd_taxterm_open_results', '.wd_taxterm_search', function(e, input, results){
e.stopPropagation(); // Prevent multiple fire
$('#asp_pg_editor .wd_taxterm_search_res li').removeClass('wtsr_selected');
$('#pg_selected_tax_terms li').each(function(i, o){
var iclass = $(this).attr('class');
$('#asp_pg_editor .wd_taxterm_search_res li.' + iclass).addClass('wtsr_selected');
});
});
// Taxonomy search adding new elements
$('#asp_pg_editor .wd_taxterm_search_res').on('click', 'li:not(.wtsr_selected)', function(e){
if ( $('#pg_selected_tax_terms li').length < 11 ) {
$(this).clone().appendTo('#pg_selected_tax_terms');
$('#asp_pg_editor .wd_taxterm_search').trigger('wd_taxterm_open_results');
} else {
alert( msg('msg_cru') );
}
});
// Taxonomy search removing elements
$('#pg_selected_tax_terms').on('click', 'li', function(e){
$(this).remove();
$('#asp_pg_editor .wd_taxterm_search').trigger('wd_taxterm_open_results');
});
// Change custom field operator type
$('#wpd_modal_inner').on('change', 'select[name=cf_operator]', function(){
if ( $(this).val() == 'between' ) {
$('input[name=cf_val2]').css('display', 'inline');
} else {
$('input[name=cf_val2]').css('display', 'none');
}
});
// ---------------------------------------------------------------------------------------------------------------------
// --------------------------------------- ETC -------------------------------------------------------------------------
function msg(k) {
return typeof ASP_EVTS[k] != 'undefined' ? ASP_EVTS[k] : '';
}
function sprintf(s) {
var i = 1, r = '';
while ( s.indexOf('%s') !== false ) {
r = typeof arguments[i] !== 'undefined' ? arguments[i] : '';
s = s.replace('%s', r);
i++;
if ( i > 40 )
break;
}
return s;
}
});