From 93a6b52924fa3579937358516fc1a2b357370e7e Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Tue, 12 Jan 2016 15:14:22 -0500 Subject: [PATCH] Various updates including fixes to the use of "Member" submenu and packaging support. --- classes/data/dataMembers.php | 4 +- classes/glmPluginSupport.php | 3 +- controllers/admin.php | 31 +++++++++- controllers/front.php | 62 ++++++------------- css/admin.css | 27 +++----- glm-member-db.php | 18 +++++- models/admin/member/index.php | 49 ++++++++++----- setup/adminHooks.php | 29 +++++++++ setup/frontHooks.php | 51 +++++++++++++++ views/admin/configure/accommodationTypes.html | 14 ++--- views/admin/configure/amenities.html | 14 ++--- views/admin/configure/categories.html | 14 ++--- views/admin/configure/cities.html | 14 ++--- views/admin/configure/header.html | 14 ++--- views/admin/configure/index.html | 14 ++--- views/admin/configure/regions.html | 14 ++--- views/admin/management/development.html | 4 +- views/admin/management/header.html | 14 ++--- views/admin/management/import.html | 2 +- .../admin/management/import/readDatabase.html | 2 +- views/admin/management/index.html | 2 +- views/admin/management/terms.html | 2 +- views/admin/member/header.html | 14 ++--- views/admin/member/index.html | 44 +++++++------ views/admin/member/memberInfo.html | 18 +++--- views/admin/members/header.html | 8 +-- views/admin/members/index.html | 4 +- views/admin/members/list.html | 2 +- views/front/members/list.html | 1 - 29 files changed, 299 insertions(+), 190 deletions(-) create mode 100644 setup/adminHooks.php create mode 100644 setup/frontHooks.php diff --git a/classes/data/dataMembers.php b/classes/data/dataMembers.php index 601b64a7..3b779c26 100644 --- a/classes/data/dataMembers.php +++ b/classes/data/dataMembers.php @@ -162,7 +162,7 @@ class GlmDataMembers extends GlmDataAbstract { 'member_slug' => array( 'field' => 'member_slug', 'type' => 'text', - 'use' => 'gl' + 'use' => 'gle' ), // Date created @@ -245,7 +245,7 @@ class GlmDataMembers extends GlmDataAbstract { return $slug; -} + } /* * Get a simple members list - Name and ID only diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 0fcb27d8..b8039ae3 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -318,9 +318,8 @@ class GlmPluginSupport // Check for PHP script to update database $phpScript = $a['database']['dbScriptPath'].'/update_database_V'.$ver.'.php'; - if (is_file($phpScript)) { - include ($phpScript); + require_once ($phpScript); } // If there were no errors diff --git a/controllers/admin.php b/controllers/admin.php index 451d3b4c..905423af 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -186,6 +186,29 @@ class glmMembersAdmin extends GlmPluginSupport // Create hook for add-ons to create menus do_action('glm-member-db-add-menu'); + /* + * Include any misc add-on hooks and filters in add-on setup folder adminMisc.php file. + * + * Note that filter and hook callback functions must be included in-line as shown below... + * + * add_filter( 'filter_title', function( $parameter ) { + * // Function code + * }); + * + * Also note that parameters will be in the context of this class. + * + */ + foreach ($this->config['addOns'] as $a) { + + // If setup/frontMisc.php exists include that now - Can be used for additional filters and hooks + $miscFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/setup/adminHooks.php'; + if (is_file($miscFile)) { + require_once($miscFile); + } + + } + + } /** @@ -339,7 +362,7 @@ class glmMembersAdmin extends GlmPluginSupport public function configureMenus () { - // Add a new main menu item for management and display of Members + // If user can manage all members, then show "Members" menu item if (apply_filters('glm_members_menu_members', true)) { $mainMenuSlug = 'glm-members-admin-menu-members'; @@ -366,6 +389,7 @@ class glmMembersAdmin extends GlmPluginSupport ); } + // Otherwise just display "Member" menu item } else { $mainMenuSlug = 'glm-members-admin-menu-member'; @@ -504,8 +528,8 @@ class glmMembersAdmin extends GlmPluginSupport * * Controller parameters * - * @param string $menuItem - * Name of the menu item that is being processed + * @param string $menuItem Name of the menu item that is being processed + * @param string $action Specified Action to take or false * * @return void * @access public @@ -788,6 +812,7 @@ class glmMembersAdmin extends GlmPluginSupport $smarty->templateAssign ( 'thisPage', (isset($_REQUEST['page']) ? $_REQUEST['page']: '') ); $smarty->templateAssign ( 'glmPluginName', GLM_MEMBERS_PLUGIN_NAME ); $smarty->templateAssign ( 'glmPluginMediaURL', GLM_MEMBERS_PLUGIN_MEDIA_URL ); + $smarty->templateAssign ( 'glmWordpresBasePluginPath', GLM_MEMBERS_WORDPRESS_PLUGIN_PATH ); $smarty->templateAssign ( 'thisYear', date ( 'Y' ) ); $smarty->templateAssign ( 'ref_type_numb', $this->config['ref_type_numb']); $smarty->templateAssign ( 'settings', $this->config['settings']); diff --git a/controllers/front.php b/controllers/front.php index 5c8986a3..0f6daed4 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -57,26 +57,6 @@ class glmMembersFront extends GlmPluginSupport die('Database check failure'); } - // Setup rewrite for member detail pages - add_filter( 'rewrite_rules_array', - array( - $this, - 'glm_members_insert_rewrite_rules' - ) - ); - add_filter('query_vars', - array( - $this, - 'glm_members_RewriteQueryVars' - ) - ); - add_filter( 'init', - array( - $this, - 'glm_members_flush_rules' - ) - ); - // Add front-end scripts and css add_action('wp_enqueue_scripts', array( @@ -97,33 +77,30 @@ class glmMembersFront extends GlmPluginSupport } - } + /* + * Include any misc add-on hooks and filters in add-on setup folder frontMisc.php file. + * + * Note that filter and hook callback functions must be included in-line as shown below... + * + * add_filter( 'filter_title', function( $parameter ) { + * // Function code + * }); + * + * Also note that parameters will be in the context of this class. + * + */ + foreach ($this->config['addOns'] as $a) { - // Flush rules if the member detail rewrite hasn't been included - function glm_members_flush_rules(){ - $rules = get_option( 'rewrite_rules' ); - if ( ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] ) ) { - global $wp_rewrite; - $wp_rewrite->flush_rules(); - } - } + // If setup/frontMisc.php exists include that now - Can be used for additional filters and hooks + $miscFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/setup/frontHooks.php'; + if (is_file($miscFile)) { + require_once($miscFile); + } - // Add the rewrite rule for the member detail page - function glm_members_insert_rewrite_rules( $rules ) - { - $newrules = array(); - $newrules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] = 'index.php?pagename=$matches[1]&memberslug=$matches[2]'; - return $newrules + $rules; - } + } - // Have WP store memberid value so we can read it after rewrites - function glm_members_RewriteQueryVars($vars) - { - array_push($vars, 'memberslug'); - return $vars; } - /** * Setup inclusion of front-end scripts and css * @@ -144,7 +121,6 @@ class glmMembersFront extends GlmPluginSupport wp_enqueue_style("wp-jquery-ui-dialog"); // Register any front.js files in the js directory of any glm members plugin - reset($this->config['addOns']); foreach ($this->config['addOns'] as $a) { $jsFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/js/front.js'; if (is_file($jsFile)) { diff --git a/css/admin.css b/css/admin.css index bc96525f..d6c690fe 100644 --- a/css/admin.css +++ b/css/admin.css @@ -45,9 +45,17 @@ margin-left: 4px !important; margin-right: 4px !important; } +.glm-button-small { + font-size: 0.9em !important; + padding: .0em .3em 0em .3em !important; + margin-right: 2px !important; + line-height: 1.8em !important; + height: 1.8em !important; +} /* Admin Area - General */ #glm-admin-content-container { + margin-top: 1em; border: 1px #ccc solid; padding: 1em; background-color: #fff; @@ -59,25 +67,6 @@ } /* Admin Tabs */ -.nav-tab-wrapper { - white-space: nowrap; - height: 1.5em; -} -.nav-tab { - font-size: 1.1vw !important; - font-weight: bold; - padding: 0px 8px 4px 8px !important; -} -.nav-tab-active { - font-weight: bold; - font-size: 1.1vw !important; - text-decoration: none; - border: 2px #ccc solid; - border-bottom: 0px; - padding: 8px 8px 10px 8px !important; - margin-bottom: 10px; - background-color: #f8f8f8; -} .disabled { pointer-events: none; cursor: default; diff --git a/glm-member-db.php b/glm-member-db.php index ab533a25..5837e722 100644 --- a/glm-member-db.php +++ b/glm-member-db.php @@ -217,6 +217,7 @@ add_option('glmMembersDatabaseDbVersion', false); * 'name' => {text name for add-on}, * 'short_name' => {an abreviated name for the add-on}, * 'slug' => {slug for add-on}, + * 'config' => {optional array of config data to be merged into $config}, * 'actions' => array( * 'adminActions => array( * '{menu name}' => array( @@ -232,6 +233,16 @@ add_option('glmMembersDatabaseDbVersion', false); * ... additional pages ... * ) * ), + * 'shortcodes' => array( + * '{shortcode} => array( + * 'plugin' => {plugin slug}, + * 'menu' => '{menu}, + * 'action' => '{action}', + * 'table' => {table name where default values for 'attributes' are stored}, + * 'adttributes' => array({array of attributes that might be in the shortcode}) + * ), + * ... additional shortcodes ... + * ), * // if the add-on is adding database tables use this, otherwise FALSE * 'database' => array( * 'dbPrefix' => '{database prefix to use}', @@ -295,7 +306,12 @@ if (count($config['addOns']) > 0) { $config['shortcodes'] = array_merge_recursive($config['shortcodes'], $a['shortcodes']); } - // If the add-on has additional config parameters + // If the add-on has supplied additional config parameters when registering + if (isset($a['config'])) { + $config = array_merge_recursive($config, $a['config']); + } + + // If the add-on has additional config parameters in a plugin.ini file $iniFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.'/'.$a['slug'].'/config/plugin.ini'; if (isset($iniFile)) { diff --git a/models/admin/member/index.php b/models/admin/member/index.php index 9521948b..70486a8e 100644 --- a/models/admin/member/index.php +++ b/models/admin/member/index.php @@ -101,6 +101,7 @@ class GlmMembersAdmin_member_index extends GlmDataMembers $success = true; $haveMember = false; + $addingMember = false; $memberData = false; $memberName = false; $memberID = 0; @@ -117,20 +118,32 @@ class GlmMembersAdmin_member_index extends GlmDataMembers // Check if there's a logged in user who is locked to their own entity $lockedToMember = apply_filters('glm_members_locked_to_member_id', false); if ($lockedToMember) { + $memberID = $lockedToMember; - $memberID = $lockedToMember; + // Otherwise Check for other member selection options + } else { + + if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'add') { + + delete_option('glmMembersDatabaseMemberID'); + $memberID = 0; - // Check if a redirecting model supplied the member ID - } elseif (isset($actionData['memberID'])) { + // Check if a redirecting model supplied the member ID + } elseif (isset($actionData['memberID'])) { - $memberID = $actionData['memberID']; + $memberID = $actionData['memberID']; - // Otherwise check if one was supplied by the user or passed from somewhere else - } elseif (isset($_REQUEST['member'])) { + // Otherwise check if one was supplied by the user or passed from somewhere else + } elseif (isset($_REQUEST['member'])) { - // Make sure it's a number - $memberID = $_REQUEST['member']-0; + // Make sure it's a number + $memberID = $_REQUEST['member']-0; + + } else { + $memberID = get_option('glmMembersDatabaseMemberID'); + + } } /* @@ -138,7 +151,7 @@ class GlmMembersAdmin_member_index extends GlmDataMembers * Setup to add a new member * */ - if ($memberID <= 0) { + if ($memberID <= 0 && isset($_REQUEST['option']) && ($_REQUEST['option'] == 'add' || $_REQUEST['option'] == 'addNew')) { // If this is a new member submission if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'addNew') { @@ -146,8 +159,8 @@ class GlmMembersAdmin_member_index extends GlmDataMembers // Attempt to add the new member $memberData = $this->insertEntry(); if($memberData['status']) { + $memberID = $memberData['fieldData']['id']; - $haveMember = true; // Update the member slug then get member data again $this->updateSlug($memberID); @@ -155,6 +168,8 @@ class GlmMembersAdmin_member_index extends GlmDataMembers // Now get the updated entry with the slug $memberData = $this->editEntry($memberID); + $haveMember = true; + } if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { @@ -171,6 +186,7 @@ class GlmMembersAdmin_member_index extends GlmDataMembers // Setup to add a new member $memberData = $this->newEntry(); + $addingMember = true; } @@ -212,7 +228,7 @@ class GlmMembersAdmin_member_index extends GlmDataMembers * Get existing base member data * */ - } else { + } elseif ($memberID > 0) { if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { glmMembersAdmin::addNotice("  Member ID specified: $memberID", 'Process'); @@ -220,7 +236,9 @@ class GlmMembersAdmin_member_index extends GlmDataMembers // Try to get existing member data $memberData = $this->editEntry($memberID); - $haveMember = true; + if ($memberData) { + $haveMember = true; + } } @@ -233,7 +251,6 @@ class GlmMembersAdmin_member_index extends GlmDataMembers * Other actions that may be required * */ - // Check if there's a request to delete a specific member information record if (isset($_REQUEST['deleteID']) && $_REQUEST['deleteID'] != '') { @@ -334,13 +351,15 @@ class GlmMembersAdmin_member_index extends GlmDataMembers $noActive = true; } - } - + // Also save the mmeber ID in a WordPress "option" in case someone clicks the "Member" sub-menu + update_option('glmMembersDatabaseMemberID', $memberID); + } // Compile template data $templateData = array( 'haveMemberTypes' => $haveMemberTypes, 'haveMember' => $haveMember, + 'addingMember' => $addingMember, 'memberID' => $memberID, 'member' => $memberData, 'memberName' => $memberName, diff --git a/setup/adminHooks.php b/setup/adminHooks.php new file mode 100644 index 00000000..1c005073 --- /dev/null +++ b/setup/adminHooks.php @@ -0,0 +1,29 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release adminHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * Place Misc Hooks and Filters here. If this file exists, it will be included + * by the add-on main plugin script. + * + * Note that filter and hook callback functions must be included in-line as shown below... + * + * add_filter( 'filter_title', function( $parameter ) { + * // Function code + * }); + * + * Also note that parameters will be in the context of the main admin controller constructor. + */ + +?> \ No newline at end of file diff --git a/setup/frontHooks.php b/setup/frontHooks.php new file mode 100644 index 00000000..f93f1249 --- /dev/null +++ b/setup/frontHooks.php @@ -0,0 +1,51 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release frontHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * Place Misc Hooks and Filters here. If this file exists, it will be included + * by the add-on main plugin script. + * + * Note that filter and hook callback functions must be included in-line as shown below... + * + * add_filter( 'filter_title', function( $parameter ) { + * // Function code + * }); + * + * Also note that parameters will be in the context of the main front controller constructor. + */ + +// Setup rewrite for member detail pages +add_filter('rewrite_rules_array', function($rules) { + $newrules = array(); + $newrules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] = 'index.php?pagename=$matches[1]&memberslug=$matches[2]'; + return $newrules + $rules; +}); + +// Add memberslug query var +add_filter('query_vars', function($vars) { + array_push($vars, 'memberslug'); + return $vars; +}); + +// On init, check if we need to flush the rewrite rules to pickup the new ones +add_filter('init', function() { + $rules = get_option( 'rewrite_rules' ); + if ( ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/([^/]*)$'] ) ) { + global $wp_rewrite; + $wp_rewrite->flush_rules(); + } +}); + +?> \ No newline at end of file diff --git a/views/admin/configure/accommodationTypes.html b/views/admin/configure/accommodationTypes.html index 0f1839db..a57c7e64 100644 --- a/views/admin/configure/accommodationTypes.html +++ b/views/admin/configure/accommodationTypes.html @@ -1,7 +1,7 @@ {include file='admin/configure/header.html'} -
Add a Accommodation Type
+
Add a Accommodation Type
@@ -27,8 +27,8 @@

* Required

- Cancel - + Cancel +
@@ -36,8 +36,8 @@

Are you sure you want to delete this accommodation type?

-

Yes, delete this accommodation type

-

Cancel

+

Yes, delete this accommodation type

+

Cancel

@@ -68,7 +68,7 @@

* Required

- Cancel + Cancel @@ -103,7 +103,7 @@ {$t.short_descr} -
Delete
+
Delete
{/foreach} diff --git a/views/admin/configure/amenities.html b/views/admin/configure/amenities.html index b1b9a68f..7115bef3 100644 --- a/views/admin/configure/amenities.html +++ b/views/admin/configure/amenities.html @@ -1,7 +1,7 @@ {include file='admin/configure/header.html'} -
Add an Amenity
+
Add an Amenity
@@ -42,8 +42,8 @@

* Required

- Cancel - + Cancel +
@@ -52,8 +52,8 @@

Are you sure you want to delete this accommodation type?

-

Yes, delete this accommodation type

-

Cancel

+

Yes, delete this accommodation type

+

Cancel

@@ -99,7 +99,7 @@

* Required

- Cancel + Cancel @@ -144,7 +144,7 @@ {$t.short_descr} -
Delete
+
Delete
{/foreach} diff --git a/views/admin/configure/categories.html b/views/admin/configure/categories.html index 7ede7f0b..42a7bfdc 100644 --- a/views/admin/configure/categories.html +++ b/views/admin/configure/categories.html @@ -1,7 +1,7 @@ {include file='admin/configure/header.html'} -
Add a Category
+
Add a Category
@@ -43,8 +43,8 @@

* Required

- Cancel - + Cancel +
@@ -52,8 +52,8 @@

Are you sure you want to delete this category?

-

Yes, delete this category

-

Cancel

+

Yes, delete this category

+

Cancel

@@ -99,7 +99,7 @@

* Required

- Cancel + Cancel @@ -138,7 +138,7 @@ {$t.short_descr} -
Delete
+
Delete
{/foreach} diff --git a/views/admin/configure/cities.html b/views/admin/configure/cities.html index 892fca5e..8615f065 100644 --- a/views/admin/configure/cities.html +++ b/views/admin/configure/cities.html @@ -1,7 +1,7 @@ {include file='admin/configure/header.html'} -
Add a City
+
Add a City
@@ -15,7 +15,7 @@

* Required

- Cancel + Cancel
@@ -24,8 +24,8 @@

Are you sure you want to delete this city?

-

Yes, delete this city

-

Cancel

+

Yes, delete this city

+

Cancel

@@ -44,8 +44,8 @@

* Required

- Cancel - + Cancel + @@ -71,7 +71,7 @@ {$t.name} -
Delete
+
Delete
{/foreach} diff --git a/views/admin/configure/header.html b/views/admin/configure/header.html index cd9ee47f..cb224eed 100644 --- a/views/admin/configure/header.html +++ b/views/admin/configure/header.html @@ -3,14 +3,14 @@

{$glmPluginName} Configuration

diff --git a/views/admin/configure/index.html b/views/admin/configure/index.html index b188b6d2..46369abc 100644 --- a/views/admin/configure/index.html +++ b/views/admin/configure/index.html @@ -1,7 +1,7 @@ {include file='admin/configure/header.html'} -
Add a Member Type
+
Add a Member Type
@@ -22,8 +22,8 @@

* Required

- Cancel - + Cancel +
@@ -31,8 +31,8 @@

Are you sure you want to delete this member type?

-

Yes, delete this member type

-

Cancel

+

Yes, delete this member type

+

Cancel

@@ -57,7 +57,7 @@

* Required

- Cancel + Cancel
@@ -88,7 +88,7 @@ {$t.descr} -
Delete
+
Delete
{/foreach} diff --git a/views/admin/configure/regions.html b/views/admin/configure/regions.html index 0475d072..cacbfb44 100644 --- a/views/admin/configure/regions.html +++ b/views/admin/configure/regions.html @@ -1,7 +1,7 @@ {include file='admin/configure/header.html'} -
Add a Region
+
Add a Region
@@ -27,8 +27,8 @@

* Required

- Cancel - + Cancel +
@@ -36,8 +36,8 @@

Are you sure you want to delete this region?

-

Yes, delete this region

-

Cancel

+

Yes, delete this region

+

Cancel

@@ -68,7 +68,7 @@

* Required

- Cancel + Cancel @@ -103,7 +103,7 @@ {$t.short_descr} -
Delete
+
Delete
{/foreach} diff --git a/views/admin/management/development.html b/views/admin/management/development.html index 7d2ad628..b69636be 100644 --- a/views/admin/management/development.html +++ b/views/admin/management/development.html @@ -33,8 +33,8 @@

- Skip All   - Import All + Skip All   + Import All