From: Laury GvR Date: Mon, 29 Feb 2016 19:38:19 +0000 (-0500) Subject: Settings options, database-derived social records X-Git-Tag: v1.0.0^2~15 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=652c4fd2d4fb9407342edf6ee257bc3d86cce8ce;p=WP-Plugins%2Fglm-member-db-social.git Settings options, database-derived social records --- diff --git a/css/admin.css b/css/admin.css index 4c16334..837cfe8 100644 --- a/css/admin.css +++ b/css/admin.css @@ -11,4 +11,13 @@ and open the template in the editor. .glm-member-db-social-icon { border-radius: 20px; margin-bottom: 5px; +} +#glm-member-db-social-management .glm-admin-table { + max-width: 250px; +} +#glm-member-db-social-management .glm-member-db-social-management-checkbox > * { + margin-top: 8px; +} +#glm-member-db-social-management .glm-member-db-social-management-name { + padding-top: 7px; } \ No newline at end of file diff --git a/models/admin/member/social.php b/models/admin/member/social.php index 2dc8ccf..e898656 100644 --- a/models/admin/member/social.php +++ b/models/admin/member/social.php @@ -133,82 +133,12 @@ class GlmMembersAdmin_member_social extends GlmDataSocial $option = false; $debug = true; - $socialArray = array( - 'facebook' => array( - 'name' => 'Facebook', - 'xpos' => -5, - 'ypos' => -5, - 'baseurl' => 'www.facebook.com' - ), - 'twitter' => array( - 'name' => 'Twitter', - 'xpos' => -44, - 'ypos' => -5, - 'baseurl' => 'www.twitter.com' - ), - 'pinterest' => array( - 'name' => 'Pinterest', - 'xpos' => -84, - 'ypos' => -5, - 'baseurl' => 'www.pinterest.com' - ), - 'googleplus' => array( - 'name' => 'GooglePlus', - 'xpos' => -124, - 'ypos' => -5, - 'baseurl' => 'www.google.com' - ), - 'digg' => array( - 'name' => 'Digg', - 'xpos' => -163, - 'ypos' => -5, - 'baseurl' => 'www.digg.com' - ), - 'linkedin' => array( - 'name' => 'LinkedIn', - 'xpos' => -203, - 'ypos' => -5, - 'baseurl' => 'www.linkedin.com' - ), - 'instagram' => array( - 'name' => 'Instagram', - 'xpos' => -242, - 'ypos' => -5, - 'baseurl' => 'www.instagram.com' - ), - 'youtube' => array( - 'name' => 'YouTube', - 'xpos' => -322, - 'ypos' => -5, - 'baseurl' => 'www.youtube.com' - ), - 'flickr' => array( - 'name' => 'Flickr', - 'xpos' => -44, - 'ypos' => -44, - 'baseurl' => 'www.flickr.com' - ), - 'blog' => array( - 'name' => 'blog', - 'xpos' => -124, - 'ypos' => -45, - 'baseurl' => '#' - ), - 'photobucket' => array( - 'name' => 'Photobucket', - 'xpos' => -282, - 'ypos' => -45, - 'baseurl' => 'www.photobucket.com' - ), - 'rss' => array( - 'name' => 'RSS', - 'xpos' => -282, - 'ypos' => -5, - 'baseurl' => '#' - ) - ); // The above array needs to be inserted into the Database - + $getExistingSocials = " + SELECT * + FROM ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."media_record + ;"; + $existingSocials = $this->wpdb->get_results($getExistingSocials, ARRAY_A); $getExistingUrls = " SELECT * FROM ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."media_urls @@ -332,7 +262,7 @@ class GlmMembersAdmin_member_social extends GlmDataSocial // Compile template data $templateData = array( 'displayData' => $displayData, - 'socialArray' => $socialArray, + 'existingSocials' => $existingSocials, 'assetsUrl' => GLM_MEMBERS_SOCIAL_PLUGIN_ASSETS_URL, 'socials' => $socials, 'socialUpdated' => $socialUpdated, diff --git a/models/admin/settings/social.php b/models/admin/settings/social.php new file mode 100644 index 0000000..1276e59 --- /dev/null +++ b/models/admin/settings/social.php @@ -0,0 +1,223 @@ + + * @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 Contacts data abstract +//require_once(GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php'); + +class GlmMembersAdmin_settings_social // extends GlmDataContacts +{ + + + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + + /* + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * '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. + * + * @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 the Contacts data class + * + * Note, the third parameter is a flag that indicates to the Contacts + * data class that it should flag a group of fields as 'view_only'. + */ +// parent::__construct(false, false, true); + + + } + + + + public function updateSocialList(&$existingSocials) { + $getExistingSocials = " + SELECT * + FROM ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."media_record + ;"; + $existingSocials = $this->wpdb->get_results($getExistingSocials, ARRAY_A); + } + + public function printSocialList($array,$name="Array list") { + echo "
$name"; + $i = 0; + foreach($array as $key=>$socialRecord) { + foreach($socialRecord as $recordKey=>$recordValue) + echo(""); + $i++; + } + echo "
$recordKey$recordValue

"; + } + + public function modelAction($actionData = false) + { + $displayData = 'Hello, World! This is the Social Add-On "settings" model talking to you from inside WordPress.'; + $success = true; + $socials = false; + $socialUpdated = false; + $socialError = false; + $option = false; + $debug = true; + $statusMessage = 'Social Updated'; + $getExistingSocials = " + SELECT * + FROM ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."media_record + ;"; + $existingSocials = $this->wpdb->get_results($getExistingSocials, ARRAY_A); + // If there's an action option + if (isset($_REQUEST['option'])) { + $option = trim(filter_var($_REQUEST['option'],FILTER_SANITIZE_STRING)); + } else { + $option = "default"; + } + + echo "
Request:"; + foreach($_REQUEST as $socialRecord=>$value) { + echo(""); + } + echo "
$socialRecord$value
"; + + switch ($option) { + case "submit": + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice("  Social Update:", 'Process'); + } + + foreach($existingSocials as $key => $socialRecord) { + $socialUpdated = false; + $sql = ""; + + $recordBool = $socialRecord['active']; + if(isset($_REQUEST['checkname-'.strtolower($socialRecord['social_name'])])){ + $socialBool = 1; + } else { + $socialBool = 0; + } +// echo " | checkname-".strtolower($socialRecord['social_name'])." | "; +// $socialChecked = $_REQUEST['checkname-'.strtolower($socialRecord['social_name'])]; + if ($socialBool != $recordBool) { + echo " - Unequal, rec:$recordBool and soc:$socialBool
"; + $sql = " + UPDATE ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."media_record + SET active = $socialBool + WHERE social_id = ".$socialRecord['social_id']." + ;"; + $socialUpdated = true; + $this->wpdb->query($sql); + } + if ($socialUpdated) { + if ($debug){ + echo "
".$statusMessage."
"; + echo "
Social:".$socialRecord."
"; + echo "
Social url:".$value."
"; + echo "
statement:".$sql."
"; + } + } + } + if ($debug) { + $this->updateSocialList($existingSocials); + $this->printSocialList($existingSocials,"Existing Socials Post Submit"); + } + break; + case "social"; + default: + $this->updateSocialList($existingSocials); + + if ($debug) { + $this->printSocialList($existingSocials,"Existing Socials 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 + ); + } + +// if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { +// glmMembersAdmin::addNotice($memberTypes, 'DataBlock', 'Member Types Data'); +// } + // Refresh the URL list before sending it to the front + $this->updateSocialList($existingSocials); + // Compile template data + $templateData = array( + 'displayData' => $displayData, + 'assetsUrl' => GLM_MEMBERS_SOCIAL_PLUGIN_ASSETS_URL, + 'socials' => $socials, + 'socialUpdated' => $socialUpdated, + 'socialError' => $socialError, + 'option' => $option, + 'existingSocials' => $existingSocials, + 'statusMessage' => $statusMessage + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'admin/settings/social.html', + 'data' => $templateData + ); + } +} diff --git a/setup/adminTabs.php b/setup/adminTabs.php index cfa1ca1..60e25a6 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -59,3 +59,16 @@ add_filter('glm-member-db-add-tab-for-member', return $addOnTabs; } ); +add_filter('glm-member-db-add-tab-for-settings', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Social', + 'menu' => 'settings', + 'action' => 'social' + ) + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } +); diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql index 241d872..090600e 100644 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -32,10 +32,30 @@ CREATE TABLE {prefix}media_urls ( ---- CREATE TABLE {prefix}media_record ( - id INT NOT NULL AUTO_INCREMENT, + social_id INT NOT NULL AUTO_INCREMENT, social_name TINYTEXT NULL, social_xpos int NULL, social_ypos int NULL, social_baseurl TINYTEXT NULL, - PRIMARY KEY (id) + active BOOLEAN NOT NULL DEFAULT '1', + PRIMARY KEY (social_id), + INDEX(social_id) ); + +---- + +INSERT INTO {prefix}media_record + (social_name, social_xpos, social_ypos, social_baseurl, active) + VALUES ('Facebook',-5,-5,'www.facebook.com',true), + ('Twitter',-44,-5,'www.twitter.com',true), + ('Pinterest',-84,-5,'www.pinterest.com',true), + ('GooglePlus',-124,-5,'www.google.com',true), + ('Digg',-163,-5,'www.digg.com',true), + ('LinkedIn',-203,-5,'www.linkedin.com',true), + ('Instagram',-242,-5,'www.instagram.com',true), + ('YouTube',-322,-5,'www.youtube.com',true), + ('Flickr',-44,-44,'www.flickr.com',true), + ('blog',-124,-45, '#',true), + ('Photobucket',-282,-45,'www.photobucket.com',true), + ('RSS',-282,-5,'#',false) +; \ No newline at end of file diff --git a/setup/validActions.php b/setup/validActions.php index 30d3eb1..e8626e8 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -55,6 +55,9 @@ $glmMembersSocialAddOnValidActions = array( ), 'info' => array( 'index' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG + ), + 'settings' => array( + 'social' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG ) ), 'frontActions' => array( diff --git a/views/admin/member/social.html b/views/admin/member/social.html index ecdc32e..a97192f 100644 --- a/views/admin/member/social.html +++ b/views/admin/member/social.html @@ -9,18 +9,20 @@
Update
- {foreach from=$socialArray key=k item=socialItem} - {$socialField = $socialItem.name|lower} - - - - + {foreach from=$existingSocials key=k item=socialItem} + {if $socialItem.active} + {$socialField = $socialItem.social_name|lower} + + + + + {/if} {/foreach}
-
-
- {$socialItem.name} -
- -
+
+
+ {$socialItem.social_name} +
+ +
diff --git a/views/admin/settings/social.html b/views/admin/settings/social.html new file mode 100644 index 0000000..a5c662f --- /dev/null +++ b/views/admin/settings/social.html @@ -0,0 +1,60 @@ +{include file='admin/members/header.html'} +

{if $socialUpdated}{$statusMessage}{/if}

+

Member Social Tab

+

{$displayData}

+
+ Click me to see more! +
+ + +
Update
+ + {foreach from=$existingSocials key=k item=socialItem} + {$socialField = $socialItem.social_name|lower} + + + + + + + {/foreach} +
+ + +
+
+
+ {$socialItem.social_name} +
+ +
+
+ + + +{include file='admin/footer.html'} \ No newline at end of file