From: Steve Sutton Date: Thu, 4 Aug 2016 17:30:28 +0000 (-0400) Subject: Refractor the shortcode builder code into model. X-Git-Tag: v2.4.0^2~5^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=ce62dead5804c218bc5188939ecbdc64d6d377d9;p=WP-Plugins%2Fglm-member-db.git Refractor the shortcode builder code into model. Create a model for the shortcode builder. models/admin/pages/shortcode.php and view file views/admin/pages/shortcode.html Which deals with the output of the meta box for the shortcode. Js file moved into the adminHooks.php so it gets setup in time. --- diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 5a50662c..918e655b 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -355,202 +355,6 @@ return; // Off for now ** Need to make this switchable in management echo '
', print_r($array), '
'; } - /** - * - * Shortcode Builder Functions - * - */ - private $shortcodeCounter = 0; - private function get_shortcode_count() { - return $this->shortcodeCounter; - } - private function increase_shortcode_count() { - $this->shortcodeCounter += 1; - } - public function glmMembersShortcode(){ - - // load shortcodeBuilder.js when the shortcode function has been fired if it hasn't been enqueued yet - if( ! wp_script_is( 'jquery-ui-dialog', 'enqueued' ) ){ - wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); - wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true); - } - - function custom_js_css() { - - wp_enqueue_script('your-meta-box', GLM_MEMBERS_PLUGIN_URL. '/js/shortcodeBuilder.js', array('jquery'), null, true); - } - add_action('admin_print_styles-post.php', 'custom_js_css'); - add_action('admin_print_styles-post-new.php', 'custom_js_css'); - reset($this->config['addOns']); - foreach ($this->config['addOns'] as $a) { - $cssFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/css/admin.css'; - if (is_file($cssFile)) { - $cssName = $a['slug'].'-admin-css'; - wp_register_style( - $cssName, - GLM_MEMBERS_WORDPRESS_PLUGIN_URL.'/'.$a['slug'].'/css/admin.css', - false, - GLM_MEMBERS_PLUGIN_VERSION - ); - wp_enqueue_style($cssName); - } - } - - add_meta_box("shortcode_builder", - "Associate Shortcode Builder", - array($this,'shortcode_builder_markup'), - "page", 'normal', 'high' - ); - - } - - public function shortcode_builder_markup_template($shortCodes, $list) { - //dropdown for shortcode names - $this->increase_shortcode_count(); - echo '
'; - echo '
'; - echo ''; - -// echo ''; - /* - * Member DB Shortcode Attributes - */ - - //dropdown for categories - echo ''; - - // dropdown for blank start - echo ''; - - // dropdown for views - echo ''; - - // dropdown for Amenity Groups - $amenGroupSql = " - SELECT id,name - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenity_groups - ORDER BY name"; - $amenGroups = $this->wpdb->get_results( $amenGroupSql, ARRAY_A ); - 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"; - } - - // list and detail buttons to open dialog for member db 'show' attr options - -// echo ''; - - echo ''; - echo ''; - echo '
'; - - - echo '
Categories
'; - - echo '
Amenity Groups
'; - -// echo '
Shortcodes
'; - echo '
'; - } - // metabox content - public function shortcode_builder_markup(){ - - require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php'); - - $listAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-members-list']['attributes']; - $detailAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-member-detail']['attributes']; - $glmcat = new GlmDataCategories($this->wpdb, $this->config); - $list = $glmcat->getListSortedParentChild(); - - // get the each addOn slugs to pass to the config array later - $addOns = $this->config['addOns']; - foreach($addOns as $addOn){ - if(!is_array($addOn['slug'])){ - $addOnSlugs[] = $addOn['slug']; - } - } - - // use the addOn slugs to access each of the shortcodes - foreach($addOnSlugs as $addOn){ - - // Check if the add-on has shortcodes - if (isset($this->config['addOns'][$addOn]['shortcodes'])) { - - // It does, so add them to the list - if ($this->config['addOns'][$addOn]['shortcodes']) { - $shortCodeList[] = $this->config['addOns'][$addOn]['shortcodes']; - } - - } - } - - // loop through the shortcodes to pull out the shortcode names - foreach($shortCodeList as $addonInfo) { - foreach($addonInfo as $shortCode=>$value){ -// echo "
".print_r($value, true)."
"; - if(!is_array($shortCode)){ - $shortCodes[] = $shortCode; - } - } - } - - // This function when called will auto-increment the shortcode ID - $this->shortcode_builder_markup_template($shortCodes, $list); - ?> - - - - shortcode_builder_markup_template($shortCodes, $list); - - // This button will add another shortcode editor - - //echo ''; - } } /* diff --git a/controllers/admin.php b/controllers/admin.php index f0e6fbc5..0930b812 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -170,10 +170,12 @@ class glmMembersAdmin extends GlmPluginSupport ); // add shortcode metabox + /* add_action('add_meta_boxes', array( $this, 'glmMembersShortcode' ) ); + */ // Add AJAX image upload action add_action( 'wp_ajax_glm_members_admin_ajax', diff --git a/models/admin/pages/shortcode.php b/models/admin/pages/shortcode.php new file mode 100644 index 00000000..7806b8a9 --- /dev/null +++ b/models/admin/pages/shortcode.php @@ -0,0 +1,230 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +/** + * Adding content to the GLM Associate Dashboard Widget from an Add-on. + * + * There are three filters in the GLM Associate Dashboard Widget view for adding content into the widget. + * These include short warnings, lists of pending user actions, and other notices. + * + * See "Management" -> "Hooks" then scan down to "Main Dashboard Widget Hooks". + * + * Here's the best method for providing content to the dashboard widget. There is an example of this in the search add-on. + * + * 1. Create a Model/View to build additional content for the dashboard widget + * a. Add a model for generating the warning/notice to the add-on in, for example, "models/admin/dashboardWidget/search/" + * b. Add a view for this model to the add-on in, for example, "views/admin/dashboardWidget/search/" + * (see Main Dashboard Widget Hooks descriptions for suggested format) + * c. Add the model to "setup/validActions.php" in the add-on + * + * 2. Place an add_filter() function in the add-on's "setup/adminHooks.php" file, for example... + * + * // Add content to the main dashboard widget + * add_filter( 'glm-member-db-dashboard-widget-warnings', function( $content ) { + * $content .= $this->controller('dashboardWidget', 'search'); + * return $content; + * }); + */ + +/** + * This class performs the work for the default action of the "Members" menu + * option, which is to display the members dashboard. + * + */ +class GlmMembersAdmin_pages_shortcode +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + private $shortcodeCounter = 0; + + /** + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + } + + /** + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + */ + public function modelAction ($actionData = false) + { + $success = true; + $categories = array(); + + // load shortcodeBuilder.js when the shortcode function has been fired if it hasn't been enqueued yet + if( ! wp_script_is( 'jquery-ui-dialog', 'enqueued' ) ){ + wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); + wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true); + } + + reset($this->config['addOns']); + foreach ($this->config['addOns'] as $a) { + $cssFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/css/admin.css'; + if (is_file($cssFile)) { + $cssName = $a['slug'].'-admin-css'; + wp_register_style( + $cssName, + GLM_MEMBERS_WORDPRESS_PLUGIN_URL.'/'.$a['slug'].'/css/admin.css', + false, + GLM_MEMBERS_PLUGIN_VERSION + ); + wp_enqueue_style($cssName); + } + } + + require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php'); + + $listAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-members-list']['attributes']; + $detailAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-member-detail']['attributes']; + $glmcat = new GlmDataCategories( $this->wpdb, $this->config ); + $categories = $glmcat->getListSortedParentChild(); + + // get the each addOn slugs to pass to the config array later + $addOns = $this->config['addOns']; + foreach($addOns as $addOn){ + if(!is_array($addOn['slug'])){ + $addOnSlugs[] = $addOn['slug']; + } + } + + // use the addOn slugs to access each of the shortcodes + foreach($addOnSlugs as $addOn){ + + // Check if the add-on has shortcodes + if (isset($this->config['addOns'][$addOn]['shortcodes'])) { + + // It does, so add them to the list + if ($this->config['addOns'][$addOn]['shortcodes']) { + $shortCodeList[] = $this->config['addOns'][$addOn]['shortcodes']; + } + + } + } + + // loop through the shortcodes to pull out the shortcode names + foreach($shortCodeList as $addonInfo) { + foreach($addonInfo as $shortCode=>$value){ + if(!is_array($shortCode)){ + $shortCodes[] = $shortCode; + } + } + } + + // This function when called will auto-increment the shortcode ID + $this->increase_shortcode_count(); + // Amenity Groups. + $amenGroupSql = " + SELECT id,name + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenity_groups + ORDER BY name"; + $amenGroups = $this->wpdb->get_results( $amenGroupSql, ARRAY_A ); + + // Compile template data + $templateData = array( + 'categories' => $categories, + 'amenGroups' => $amenGroups, + 'shortCodes' => $shortCodes, + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/pages/shortcode.html', + 'data' => $templateData + ); + + } + + /** + * get_shortcode_count + * + * Return the count of shortcodes. + * + * @access private + * @return void + */ + private function get_shortcode_count() { + return $this->shortcodeCounter; + } + /** + * increase_shortcode_count + * + * Increase the shortcode by one. + * + * @access private + * @return void + */ + private function increase_shortcode_count() { + $this->shortcodeCounter += 1; + } +} diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 1e86d66c..2200cb24 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -43,17 +43,17 @@ add_filter('glm-member-db-admin-management-hooksHelp', function($content) { 10, 2 ); - + $menuName = "Members Only Menu"; $menuSlug = "members-only-menu"; // Does the menu exist already? register_nav_menu($menuSlug, $menuName); - + $menuExists = wp_get_nav_menu_object( $menuName ); // If it doesn't exist, let's create it. if( !$menuExists){ - + $membersOnlyPageID = get_option(GLM_MEMBERS_PLUGIN_MEMBERS_ONLY_ID); // $menu_id = wp_create_nav_menu($menuName); @@ -84,6 +84,23 @@ if(!empty($locations)) $locations[$menuSlug] = $menu->term_id; set_theme_mod('nav_menu_locations', $locations); } + + +add_action( 'add_meta_boxes', function() { + function custom_js_css() { + wp_enqueue_script('your-meta-box', GLM_MEMBERS_PLUGIN_URL. '/js/shortcodeBuilder.js', array('jquery'), null, true); + } + add_action('admin_print_styles-post.php', 'custom_js_css' ); + add_action('admin_print_styles-post-new.php', 'custom_js_css' ); + add_meta_box("shortcode_builder", + "Associate Shortcode Builder", + function() { + $this->controller( 'pages', 'shortcode' ); + }, + "page", 'normal', 'high' + ); +} ); + // This function below needs to be defined in the theme's functions.php // //if ( ! function_exists( 'glm_members_only_menu' ) && class_exists('GLM_Members_Only_Walker')) { @@ -105,5 +122,5 @@ if(!empty($locations)) // } //} - -?> \ No newline at end of file + +?> diff --git a/setup/validActions.php b/setup/validActions.php index 6f71eedc..8f167535 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -51,8 +51,7 @@ $glmMembersValidActions = array( 'memberInfo' => 'glm-member-db', 'memberEdit' => 'glm-member-db', 'locations' => 'glm-member-db', - ) - , + ), 'settings' => array( 'index' => 'glm-member-db', // Member Types 'categories' => 'glm-member-db', @@ -76,6 +75,9 @@ $glmMembersValidActions = array( 'error' => array( 'index' => 'glm-member-db', 'badAction' => 'glm-member-db', + ), + 'pages' => array( + 'shortcode' => 'glm-member-db' ) ), 'frontActions' => array( diff --git a/views/admin/pages/shortcode.html b/views/admin/pages/shortcode.html new file mode 100644 index 00000000..e78221dc --- /dev/null +++ b/views/admin/pages/shortcode.html @@ -0,0 +1,42 @@ +
+
+ + + + + + + +
+
Categories
+
Amenity Groups
+
+ +