From: Chuck Scott Date: Thu, 2 Jun 2016 20:17:32 +0000 (-0400) Subject: Touched index to force an update X-Git-Tag: v1.0.1^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=eabdfc287e77821aebc3895d89c5b0092acfacfd;p=WP-Plugins%2Fglm-member-db-social.git Touched index to force an update --- diff --git a/models/admin/member/social.php b/models/admin/member/social.php index d0a18f1..08a2383 100644 --- a/models/admin/member/social.php +++ b/models/admin/member/social.php @@ -10,12 +10,13 @@ * @author Gaslight Media * @license http://www.gaslightmedia.com Gaslightmedia * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ - * @link http://dev.gaslightmedia.com/ */ +// Inform the social code that we're working from the member area +define('GLM_SOCIAL_MEMBER_MENU', true); -// Load Management Social data abstract -require_once GLM_MEMBERS_SOCIAL_PLUGIN_CLASS_PATH.'/data/dataSocialUrls.php'; +// Load the events index +require GLM_MEMBERS_SOCIAL_PLUGIN_PATH."/models/admin/social/index.php"; /** * GlmMembersAdmin_member_social @@ -26,10 +27,9 @@ require_once GLM_MEMBERS_SOCIAL_PLUGIN_CLASS_PATH.'/data/dataSocialUrls.php'; * @package GLM Member DB * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott - * Exp $ + * @release social.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ */ -class GlmMembersAdmin_member_social extends GlmDataSocialUrls +class GlmMembersAdmin_member_social extends GlmMembersAdmin_social_index { /** * WordPress Database Object @@ -72,206 +72,8 @@ class GlmMembersAdmin_member_social extends GlmDataSocialUrls $this->config = $config; // Run constructor for social data class - parent::__construct(false, false); + parent::__construct($wpdb, $config); } - public function modelAction($actionData = false) - { - - $success = true; - $urlUpdated = false; - $haveMember = true; - $socialError = false; - $option = false; - $debug = false; - $statusMessage = "Update complete"; - $urlList = $socialList = array(); - - // Get the Member ID - $memberID = '0'; - if (isset($_REQUEST['member']) && ($_REQUEST['member']-0) > 0) { - $memberID = $_REQUEST['member'] - 0; - } - if ($memberID == 0) { - // There should have been a member ID - So failure - return array( - 'status' => false, - 'menuItemRedirect' => 'error', - 'modelRedirect' => 'index', - 'view' => 'admin/error/index.html', - 'data' => false - ); - } - - // Get the base member data - require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'); - $Members = new GlmDataMembers($this->wpdb, $this->config); - $memberData = $Members->getEntry($memberID); - $memberName = $memberData['name']; - - $urlList = $this->getList("ref_dest = " . $memberID); - if ($urlList) { - $haveURls = true; - } - - require_once(GLM_MEMBERS_SOCIAL_PLUGIN_CLASS_PATH.'/data/dataSocials.php'); - $Socials = new GlmDataSocials($this->wpdb, $this->config); - $socialList = $Socials->getList(); - - // Get the option or set to default - if (isset($_REQUEST['option'])) { - $option = trim(filter_var($_REQUEST['option'],FILTER_SANITIZE_STRING)); - } else { - $option = "default"; - } - - - switch ($option) { - case "submit": - // loop thru the socialList to see if there's a new value for that media - // if there no value then see if there's a record and delete it - // if there's no record then add it - // if there's a record then update it - - // If we have a list of social media types - if ($socialList) { - - $memberSocialUrlList = array(); - - // Scan the urlList to see if any of them are now blank - if (!empty($urlList)) { - foreach ($urlList as $url) { - - // If there's no input for an existing url record - if ( !isset($_REQUEST['socialUrl'][$url['social']]) - || trim($_REQUEST['socialUrl'][$url['social']]) == '' - ) { - - // delete record here - $this->wpdb->delete( - $this->table, - array( 'id' => $url['id']), - array( '%d' ) - ); - - } else { - $memberSocialUrlList[$url['social']] = $url['id']; - } - } - } - - // Scan the Social List to see if there's any that do have data - foreach ($socialList as $socialData) { - - // Was there any input for this social media type - if ( isset($_REQUEST['socialUrl'][$socialData['id']]) - && trim($_REQUEST['socialUrl'][$socialData['id']]) != '' - ) { - - $url = $_REQUEST['socialUrl'][$socialData['id']]; - - // See if there's a record for it - if (isset($memberSocialUrlList[$socialData['id']])) { - - // There is, so just update record here - $this->wpdb->update( - $this->table, - array('url' => $url), - array( - 'ref_type' => $this->config['ref_type_numb']['MemberInfo'], - 'ref_dest' => $memberID, - 'social' => $socialData['id'] - ), - array('%s'), - array('%d', '%d', '%s' ) - ); - - // There is no record for it, so insert one - } else { - - // add record here - $newId = $this->wpdb->insert( - $this->table, - array( - 'url' => $url, - 'ref_type' => $this->config['ref_type_numb']['MemberInfo'], - 'ref_dest' => $memberID, - 'social' => $socialData['id'] - ), - array( '%s', '%d', '%d', '%s' ) - ); - } - } - } - } - - $statusMessage = "Social Media URLs Updated"; - - // Get our updated list - $urlList = $this->getList("ref_dest = " . $memberID); - - $urlUpdated = true; - - break; - - case "social": - default: - break; - } - - // If we had a fatal error, redirect to the error page - if ($socialError) { - return array( - 'status' => $success, - 'option' => $option, - 'menuItemRedirect' => 'error', - 'modelRedirect' => 'index', - 'view' => 'admin/error/index.html', - 'data' => false - ); - } - - // Refresh the Url list before returning it - if (!empty($urlList)) { - foreach ($urlList as $url) { - $socialList[$url['social']]['url'] = $url['url']; - } - } - - - if ($debug) { - echo '
$urlList: ' . print_r($urlList, true) . '
'; - echo "
Request:"; - foreach($_REQUEST as $key=>$value) { - echo(""); - } - echo "
$key$value
"; - echo "
UrlList:"; - echo "
".print_r($urlList[$memberID], true)."
"; - echo "
sociallist:
"; - echo "
".print_r($socialList, true)."
"; - echo "
"; - } - - $templateData = array( - 'memberName' => $memberName, - 'socials' => $socialList, - 'assetsUrl' => GLM_MEMBERS_SOCIAL_PLUGIN_ASSETS_URL, - 'urlUpdated' => $urlUpdated, - 'socialError' => $socialError, - 'haveMember' => $haveMember, - 'memberID' => $memberID, - 'option' => $option, - 'statusMessage' => $statusMessage - ); - - // Return status, any suggested view, and any data to controller - return array( - 'status' => true, - 'modelRedirect' => false, - 'view' => 'admin/member/social.html', - 'data' => $templateData - ); - } } diff --git a/models/admin/social/index.php b/models/admin/social/index.php new file mode 100644 index 0000000..d0f4bf4 --- /dev/null +++ b/models/admin/social/index.php @@ -0,0 +1,280 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Management Social data abstract +require_once GLM_MEMBERS_SOCIAL_PLUGIN_CLASS_PATH.'/data/dataSocialUrls.php'; + +/** + * GlmMembersAdmin_member_social + * + * PHP version 5 + * + * @category Model + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmMembersAdmin_social_index extends GlmDataSocialUrls +{ + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Member ID + * + * @var $memberID + * @access public + */ + public $memberID = false; + + /* + * Constructor + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for social data class + parent::__construct($wpdb, $config); + + } + + public function modelAction($actionData = false) + { + + $lockedToMember = false; + $socialWhereT = 'true'; + $socialWhere = 'true'; + $success = true; + $urlUpdated = false; + $haveMember = true; + $socialError = false; + $option = false; + $statusMessage = "Update complete"; + $urlList = $socialsList = array(); + + // 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; + $lockedToMember = $memberID; + } else { + + // Get the Member ID + $memberID = '0'; + if (isset($_REQUEST['member']) && ($_REQUEST['member']-0) > 0) { + $memberID = $_REQUEST['member'] - 0; + } + + if ($memberID == 0) { + // There should have been a member ID - So failure + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => false + ); + } + + } + + // *** Note that ref_type should be Member (10) rather than MemberInfo(20), but this works *** + $socialWhereT = 'T.ref_type = '.$this->config['ref_type_numb']['MemberInfo'].' AND T.ref_dest = '.$memberID; + $socialWhere = 'ref_type = '.$this->config['ref_type_numb']['MemberInfo'].' AND ref_dest = '.$memberID; + + // Get the base member data + require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'); + $Members = new GlmDataMembers($this->wpdb, $this->config); + $memberData = $Members->getEntry($memberID); + $memberName = $memberData['name']; + + // Get a list of currently selected social media types for this member + $urlList = $this->getList($socialWhere); + if ($urlList) { + $haveURls = true; + } + + // Get list of all available social media types + require_once(GLM_MEMBERS_SOCIAL_PLUGIN_CLASS_PATH.'/data/dataSocials.php'); + $Socials = new GlmDataSocials($this->wpdb, $this->config); + $socialsList = $Socials->getList(); + + // Get the option or set to default + if (isset($_REQUEST['option'])) { + $option = trim(filter_var($_REQUEST['option'],FILTER_SANITIZE_STRING)); + } else { + $option = "default"; + } + + + switch ($option) { + case "submit": + // loop thru the socialsList to see if there's a new value for that media + // if there no value then see if there's a record and delete it + // if there's no record then add it + // if there's a record then update it + + // If we have a list of social media types + if ($socialsList) { + + $memberSocialUrlList = array(); + + // Scan the urlList to see if any of them are now blank + if (!empty($urlList)) { + foreach ($urlList as $url) { + + // If there's no input for an existing url record + if ( !isset($_REQUEST['socialUrl'][$url['social']]) + || trim($_REQUEST['socialUrl'][$url['social']]) == '' + ) { + + // delete record here + $this->wpdb->delete( + $this->table, + array( 'id' => $url['id']), + array( '%d' ) + ); + + } else { + $memberSocialUrlList[$url['social']] = $url['id']; + } + } + } + + // Scan the Social List to see if there's any that do have data + foreach ($socialsList as $socialData) { + + // Was there any input for this social media type + if ( isset($_REQUEST['socialUrl'][$socialData['id']]) + && trim($_REQUEST['socialUrl'][$socialData['id']]) != '' + ) { + + $url = $_REQUEST['socialUrl'][$socialData['id']]; + + // See if there's a record for it + if (isset($memberSocialUrlList[$socialData['id']])) { + + // There is, so just update record here + $this->wpdb->update( + $this->table, + array('url' => $url), + array( + 'ref_type' => $this->config['ref_type_numb']['MemberInfo'], + 'ref_dest' => $memberID, + 'social' => $socialData['id'] + ), + array('%s'), + array('%d', '%d', '%s' ) + ); + + // There is no record for it, so insert one + } else { + + // add record here + $newId = $this->wpdb->insert( + $this->table, + array( + 'url' => $url, + 'ref_type' => $this->config['ref_type_numb']['MemberInfo'], + 'ref_dest' => $memberID, + 'social' => $socialData['id'] + ), + array( '%s', '%d', '%d', '%s' ) + ); + } + } + } + } + + $statusMessage = "Social Media URLs Updated"; + + // Get our updated list + $urlList = $this->getList("ref_dest = " . $memberID); + + $urlUpdated = true; + + break; + + case "social": + default: + break; + } + + // If we had a fatal error, redirect to the error page + if ($socialError) { + return array( + 'status' => $success, + 'option' => $option, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => false + ); + } + + // Refresh the Url list before returning it + if (!empty($urlList)) { + foreach ($urlList as $url) { + $socialsList[$url['social']]['url'] = $url['url']; + } + } + + $templateData = array( + 'lockedToMember' => $lockedToMember, + 'memberName' => $memberName, + 'socials' => $socialsList, + 'assetsUrl' => GLM_MEMBERS_SOCIAL_PLUGIN_ASSETS_URL, + 'urlUpdated' => $urlUpdated, + 'socialError' => $socialError, + 'haveMember' => $haveMember, + 'memberID' => $memberID, + 'option' => $option, + 'statusMessage' => $statusMessage + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'admin/social/index.html', + 'data' => $templateData + ); + } +} diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 7a5e3e2..6e91272 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -70,31 +70,17 @@ * */ -// Add a main menu item -//add_menu_page( -// 'GLM Social', // Page Title -// 'GLM Social', // Menu Title -// 'glm-members-members', // Capability -// 'glm-members-admin-menu-social', // Menu Slug -// function() {$this->controller('social');}, // Called function -// false, // Icon URL -// '92' // Menu Position -//); -// -//add_submenu_page( -// 'glm-members-admin-menu-social', // Parent slug -// 'Social', // Page title -// 'Social', // Menu Title -// 'glm_members_members', // Capability required -// 'glm-members-admin-menu-social-social', // Menu slug -// function() {$this->controller('social');} -//); -// -//add_submenu_page( -// 'glm-members-admin-menu-social', // Parent slug -// 'Info', // Page title -// 'Info', // Menu Title -// 'glm_members_members', // Capability required -// 'glm-members-admin-menu-social-info', // Menu slug -// function() {$this->controller('info');} -//); + +// If a contact is logged in (ownEntity isn't false), add Contact Profile menu item +if ($this->config['loggedInUser']['contactUser']) { + + add_submenu_page( + $mainMenuSlug, + 'Social Media', + 'Social Media', + 'glm_members_edit_my_entity', + 'glm-members-admin-menu-social-index', + function() {$this->controller('social');} + ); + +} diff --git a/setup/adminTabs.php b/setup/adminTabs.php index 087500c..2caf00d 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -46,24 +46,28 @@ * */ -add_filter('glm-member-db-add-tab-for-member', - function($addOnTabs) { - $newTabs = array( - array( - 'text' => 'Social', - 'menu' => 'member', - 'action' => 'social' - ) - ); - $addOnTabs = array_merge($addOnTabs, $newTabs); - return $addOnTabs; - } -); +// If user can manage all members +if (current_user_can('glm_members_members')) { + add_filter('glm-member-db-add-tab-for-member', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Social Media', + 'menu' => 'member', + 'action' => 'social' + ) + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } + ); +} + add_filter('glm-member-db-add-tab-for-management', function($addOnTabs) { $newTabs = array( array( - 'text' => 'Social', + 'text' => 'Social Media', 'menu' => 'settings', 'action' => 'social' ) diff --git a/setup/permissions.php b/setup/permissions.php index e66d3d7..940ac7d 100644 --- a/setup/permissions.php +++ b/setup/permissions.php @@ -13,20 +13,6 @@ * @link http://dev.gaslightmedia.com/ */ - -/********************************************************************** - * NOTE: THIS IS A SOCIAL FILE - DO NOT USE UNMODIFIED - * - * Please change all references to social, Social, or SOCIAL to a name - * appropriate for your new Add-On. - * - * This file is used to add permission checks that can be used throught - * the main plugin and add-ons. If no such permissions are needed by - * this add-on, this file should be omitted. - * - * Remove this message before using this file in production! - **********************************************************************/ - /* * Below are permission checks for various specific things in this add-on and * elsewhere in the Member DB main plugin and add-ons. @@ -54,3 +40,20 @@ * * Of course any of these may test more than one capability if that's desired. */ + +// Logged in all members manager user may edit Social media for all members +add_filter('glm_members_permit_admin_members_social', + function($permit) { + if (!$permit) { return false; } + return current_user_can('glm_members_edit_any_member'); + } +); + +// Logged in member user may edit an social media only for their own entity +add_filter('glm_members_permit_admin_member_social', + function($permit) { + if (!$permit) { return false; } + return current_user_can('glm_members_edit_my_member'); + } +); + diff --git a/setup/validActions.php b/setup/validActions.php index 92d210b..0c5e3ee 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -49,6 +49,9 @@ $glmMembersSocialAddOnValidActions = array( 'member' => array( 'social' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG, ), + 'social' => array( + 'index' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG, + ), 'management' => array( 'social' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG ) @@ -56,7 +59,6 @@ $glmMembersSocialAddOnValidActions = array( 'frontActions' => array( 'social' => array( 'list' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG, - // 'detail' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG ) ) ); diff --git a/views/admin/management/social.html b/views/admin/management/social.html index 9bc2ed4..969ab52 100644 --- a/views/admin/management/social.html +++ b/views/admin/management/social.html @@ -89,36 +89,40 @@
- - - - - - - + + + + + + + + + + {foreach $socials as $s} - - - - - - - + + + + + + + {/foreach} +
NameActiveImageBase URL 
NameActiveImageBase URL 
- {$s.name} - - {$s.active.name} - - {if $s.b64icon} - Embedded Image - {else} - (no image) - {/if} - - {$s.baseurl} - -
Delete
-
+ {$s.name} + + {$s.active.name} + + {if $s.b64icon} + Embedded Image + {else} + (no image) + {/if} + + {$s.baseurl} + +
Delete
+
diff --git a/views/admin/member/social.html b/views/admin/member/social.html deleted file mode 100644 index 4af11b3..0000000 --- a/views/admin/member/social.html +++ /dev/null @@ -1,70 +0,0 @@ -{include file='admin/member/header.html'} -

{if $urlUpdated}{$statusMessage}{/if}

-

Member Social Tab

- -
-
- - - {foreach from=$socials key=k item=socialItem} - {if !$socialItem.active.value} - - {/if} - {/foreach} - - - {foreach from=$socials key=k item=socialItem} - {if $socialItem.active.value} - {$socialField = $socialItem.name|lower} - - - - - - {/if} - {/foreach} -
Social Media TypeIconURL
-
-
- {$socialItem.name} -
- Embedded Image - - -
- -
-
- - - -{include file='admin/footer.html'} diff --git a/views/admin/social/index.html b/views/admin/social/index.html new file mode 100644 index 0000000..a2fb00a --- /dev/null +++ b/views/admin/social/index.html @@ -0,0 +1,77 @@ +{if $lockedToMember} +
+ +

+ {if $haveMember} + {$terms.term_member_cap}: {$memberName} + {else} + New {$terms.term_member_cap} + {/if} +

+ +
+ +{else} + {include file='admin/member/header.html'} +{/if} +

{if $urlUpdated}{$statusMessage}{/if}

+

Social Media URLs

+ +
+{if $lockedToMember} +
+{else} + +{/if} + + {foreach from=$socials key=k item=socialItem} + {if !$socialItem.active.value} + + {/if} + {/foreach} + + + + + + + + + + {foreach from=$socials key=k item=socialItem} + {if $socialItem.active.value} + {$socialField = $socialItem.name|lower} + + + + + + {/if} + {/foreach} + +
Social Media TypeIconURL
+ {$socialItem.name} + + Embedded Image + + +
+ +
+
+ + + +{include file='admin/footer.html'}