From cc9cb0b1d1d1cf267d305370865781e923095534 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Thu, 16 Jun 2016 13:11:35 -0400 Subject: [PATCH] adding shortcode builder functionality --- classes/glmPluginSupport.php | 52 ++++++++++---------------------- js/shortcodeBuilder.js | 56 ++++++++++++++++++++++++----------- models/admin/member/index.php | 2 +- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 461a67d2..5a1ee356 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -347,7 +347,7 @@ return; // Off for now ** Need to make this switchable in management public function get_post_id_by_slug($postName) { - $value = $this->wpdb->get_var("SELECT ID FROM ".$this->wpdb->posts." WHERE post_name = '".$postName."'"); + $value = $this->wpdb->get_var("SELECT ID FROM ". $this->wpdb->posts." WHERE post_name = '" . $postName."'"); return $value; } @@ -407,9 +407,9 @@ return; // Off for now ** Need to make this switchable in management public function shortcode_builder_markup_template($shortCodes, $list) { //dropdown for shortcode names $this->increase_shortcode_count(); - echo '
'; + echo '
'; echo '
'; - echo ' '; foreach($shortCodes as $code){ if (false !== strpos($code, 'members-list') || false !== strpos($code, 'packaging-list')){ @@ -438,16 +438,6 @@ return; // Off for now ** Need to make this switchable in management } } echo ''; - - echo '
'; - foreach($list as $key=>$value){ - if( ! empty($value['parent']['name'])){ - echo ''; - } else { - echo ''; - } - } - echo '
'; // dropdown for blank start echo ''; - // show list options 'scb' = shortcode builder acronym -// echo '
'; -// echo ''; -// echo ''; -// foreach($listAttr as $key=>$value){ -// if($value != ''){ -// echo ''; -// } -// } -// echo '
'; - - // show detail options -// echo '
'; -// echo ''; -// echo ''; -// foreach($detailAttr as $key=>$value){ -// if($value != ''){ -// echo ''; -// } -// } - // packaging addOn mark up if(file_exists(GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php")){ include GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php"; @@ -539,13 +508,24 @@ return; // Off for now ** Need to make this switchable in management // This function when called will auto-increment the shortcode ID $this->shortcode_builder_markup_template($shortCodes, $list); - + ?> + + + + shortcode_builder_markup_template($shortCodes, $list); +// $this->shortcode_builder_markup_template($shortCodes, $list); // This button will add another shortcode editor + echo ''; } } diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index 7bd02eee..219d3882 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -6,9 +6,10 @@ jQuery(document).ready(function ($) { 'use strict'; - + var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, boxTarget, shortcodeString, editor_shortcodes, category_id, shortcodeValues = {}; + $("#showDetail").hide(); $("#categoryBox").hide(); $("#showCategory").hide(); @@ -18,23 +19,33 @@ jQuery(document).ready(function ($) { $(".scCategories").hide(); // reset checkboxes after page load - function uncheckAll() { - var w = document.getElementsByTagName('input'); - for (var i = 0; i < w.length; i++){ - if(w[i].type === 'checkbox'){ - w[i].checked = false; - } - } - } - - +// function uncheckAll() { +// var w = document.getElementsByTagName('input'); +// for (var i = 0; i < w.length; i++){ +// if(w[i].type === 'checkbox'){ +// w[i].checked = false; +// } +// } +// } + var shortcode = $("#shortcode_container").not('.glm-dynSelect-item'), clone, id_count; + id_count = 0; +// $("#additionalShortcode").on( "click", function () { +// id_count++; +// clone = shortcode.clone(true); +// clone.find("#shortcodeDropdown").attr("id", "shortcodeDropdown" + "_" + id_count); +// clone.find(".glm-dynSelect-item").remove(); +// clone.find("#generate").attr("id", "generate" + "_" + id_count); +// clone.insertAfter("#shortcode_container:last"); +// +// }); + ///////////////////////////////////////////////////////////////////////////////////////// // CHANGE MAIN SHORTCODE ///////////////////////////////////////////////////////////////////////////////////////// // fire core events and reset settings when switching between shortcodes - $("#shortcodeDropdown").on("change", function () { + $("[id$=shortcodeDropdown]").on("change", function () { // reset the dropdowns and checkbox if when switching shortcodes document.getElementById('category-scDropdown').options[0].selected = 'selected'; if($('#blank-start-scDropdown').length) @@ -42,7 +53,7 @@ jQuery(document).ready(function ($) { if($('#id-scDropdown').length) document.getElementById('id-scDropdown').options[0].selected = 'selected'; - uncheckAll(); +// uncheckAll(); // delete the object properties to reset the object shortcodeString = ""; @@ -51,7 +62,7 @@ jQuery(document).ready(function ($) { } // get the shortcode option name and hide / show necessary elements - shortcodeDropdown = $("#shortcodeDropdown option:selected").val(); + shortcodeDropdown = $(".shortcodeDropdown option:selected").val(); if(shortcodeDropdown === "glm-members-list"){ $("#showCategory").show(); @@ -129,14 +140,23 @@ jQuery(document).ready(function ($) { } editor_shortcodes = get_tinymce_content(); + if(editor_shortcodes){ var number_of_categories = (editor_shortcodes.match(/category="(.*?)"/g) || []).length; } console.debug(number_of_categories); + console.debug(editor_shortcodes); if(editor_shortcodes){ if(editor_shortcodes.match(/category="(.*?)"/) !== null){ category_id = editor_shortcodes.match(/category="(.*?)"/)[1]; +// console.debug(category_id); +// var cat_id_array = []; +// $.each(category_id, function (key, value) { +// cat_id_array.push(value.match(/"(.*?)"/)[1]); +// }); + category_id = category_id.split(','); + } else if (editor_shortcodes.match(/category=""/) !== null){ category_id = editor_shortcodes.match(/category="(.*?)"/)[1]; } @@ -273,7 +293,7 @@ jQuery(document).ready(function ($) { // INSERT SHORTCODE FUNCTION ///////////////////////////////////////////////////////////////////////////////////////////////// // generate the shortcode into a string and insert into the content upon clicking - $("#generate").on("click", function () { + $("[id$=generate]").on("click", function () { count = 0; if(number_of_categories){ count = number_of_categories; @@ -318,7 +338,7 @@ jQuery(document).ready(function ($) { } } // start the shortcode string that will be added to the tinymce editor - shortcodeString = '
[' + shortcodeDropdown; + shortcodeString = '
[' + shortcodeDropdown; // populate the shortcode object for (var key in shortcodeValues) { @@ -368,7 +388,7 @@ jQuery(document).ready(function ($) { editor_shortcodes = get_tinymce_content(); - if(editor_shortcodes.match(/category="(.*?)"/) !== null){ + if(editor_shortcodes && editor_shortcodes.match(/category="(.*?)"/) !== null){ category_id = editor_shortcodes.match(/category="(.*?)"/)[1]; category_id = category_id.split(','); ids = category_id.join(','); @@ -434,6 +454,6 @@ jQuery(document).ready(function ($) { if(view){ window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected'; } - window.onload = uncheckAll(); +// window.onload = uncheckAll(); }); diff --git a/models/admin/member/index.php b/models/admin/member/index.php index 70486a8e..d5eed2c5 100644 --- a/models/admin/member/index.php +++ b/models/admin/member/index.php @@ -98,7 +98,7 @@ class GlmMembersAdmin_member_index extends GlmDataMembers */ public function modelAction ($actionData = false) { - + echo current_user_can('edit_pages'); $success = true; $haveMember = false; $addingMember = false; -- 2.17.1