Settings options, database-derived social records
authorLaury GvR <laury@gaslightmedia.com>
Mon, 29 Feb 2016 19:38:19 +0000 (14:38 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Mon, 29 Feb 2016 19:38:19 +0000 (14:38 -0500)
css/admin.css
models/admin/member/social.php
models/admin/settings/social.php [new file with mode: 0644]
setup/adminTabs.php
setup/databaseScripts/create_database_V0.0.1.sql
setup/validActions.php
views/admin/member/social.html
views/admin/settings/social.html [new file with mode: 0644]

index 4c16334..837cfe8 100644 (file)
@@ -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
index 2dc8ccf..e898656 100644 (file)
@@ -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 (file)
index 0000000..1276e59
--- /dev/null
@@ -0,0 +1,223 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Member User Profile
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Gaslight Media <dev@gaslightmedia.com>
+ * @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 "<hr />$name<table>";
+        $i = 0;
+        foreach($array as $key=>$socialRecord) {
+            foreach($socialRecord as $recordKey=>$recordValue)
+            echo("<tr><td>$recordKey</td><td>$recordValue</td></tr>");
+            $i++;
+        }
+        echo "</table><hr>";
+    }
+    
+    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 "<hr />Request:<table>";
+        foreach($_REQUEST as $socialRecord=>$value) {
+            echo("<tr><td>$socialRecord</td><td>$value</td></tr>");
+        }
+        echo "</table>";
+        
+        switch ($option) {
+            case "submit":
+                if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+                    glmMembersAdmin::addNotice("<b>&nbsp;&nbsp;Social Update:</b>", '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<hr>";
+                            $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 "<hr><div>".$statusMessage."</div>";
+                            echo "<div>Social:".$socialRecord."</div>";
+                            echo "<div>Social url:".$value."</div>";
+                            echo "<div>statement:".$sql."</div>";
+                        } 
+                    }               
+                }            
+                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
+        );
+    }
+}
index cfa1ca1..60e25a6 100644 (file)
@@ -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;
+    }
+);
index 241d872..090600e 100644 (file)
@@ -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
index 30d3eb1..e8626e8 100644 (file)
@@ -55,6 +55,9 @@ $glmMembersSocialAddOnValidActions = array(
         ),
         'info' => array(
             'index' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG
+        ),
+        'settings' => array(
+            'social' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG
         )
     ),
     'frontActions' => array(
index ecdc32e..a97192f 100644 (file)
@@ -9,18 +9,20 @@
             <input type="hidden" name="option" value="submit">
             <div class="button glm-button right">Update</div>
             <table class="glm-admin-table">
-            {foreach from=$socialArray key=k item=socialItem}
-                {$socialField = $socialItem.name|lower}
-                <tr>
-                    <th>
-                        <div id="glm-member-db-admin-social-{$socialItem.name|lower}" title="{$socialItem.name}" class="glm-member-db-social-icon" style="background: url('{$assetsUrl}/social-few-full-sprite.jpg') repeat scroll {$socialItem.xpos}px {$socialItem.ypos}px;height:33px;width:33px;display:block;">
-                        </div>
-                        {$socialItem.name}
-                    </th>
-                    <td>
-                        <input type="text" placeholder="{$socialItem.name} URL" name="socialname-{$socialItem.name|lower}" class="glm-form-text-input" value="{$existingUrls.$socialField}">
-                    </td>
-                </tr>
+            {foreach from=$existingSocials key=k item=socialItem}
+                {if $socialItem.active}
+                    {$socialField = $socialItem.social_name|lower}
+                    <tr>
+                        <th>
+                            <div id="glm-member-db-admin-social-{$socialItem.social_name|lower}" title="{$socialItem.social_name}" class="glm-member-db-social-icon" style="background: url('{$assetsUrl}/social-few-full-sprite.jpg') repeat scroll {$socialItem.social_xpos}px {$socialItem.social_ypos}px;height:33px;width:33px;display:block;">
+                            </div>
+                            {$socialItem.social_name}
+                        </th>
+                        <td>
+                            <input type="text" placeholder="{$socialItem.social_name} URL" name="socialname-{$socialItem.social_name|lower}" class="glm-form-text-input" value="{$existingUrls.$socialField}">
+                        </td>
+                    </tr>
+                {/if}
             {/foreach}
             </table>
             <input type="submit" class="button glm-button submit" value="submit" name='submit'>
diff --git a/views/admin/settings/social.html b/views/admin/settings/social.html
new file mode 100644 (file)
index 0000000..a5c662f
--- /dev/null
@@ -0,0 +1,60 @@
+{include file='admin/members/header.html'}
+<h2>{if $socialUpdated}<span class="glm-notice glm-flash-updated glm-right">{$statusMessage}</span>{/if}</h2>
+    <h3>Member Social Tab</h3>
+    <p>{$displayData}</p>
+    <div id="glm-admin-content-container">
+        <a href="{$thisURL}?page={$thisPage}&glm_action=more">Click me to see more!</a>
+        <form id="glm-member-db-social-management" action="{$thisURL}?page={$thisPage}&glm_action=social&member=1" method="post" enctype="multipart/form-data">
+            <input type="submit" class="button glm-button submit" value="submit" name='submit'>
+            <input type="hidden" name="option" value="submit">
+            <div class="button glm-button right">Update</div>
+            <table class="glm-admin-table">
+            {foreach from=$existingSocials key=k item=socialItem}
+                {$socialField = $socialItem.social_name|lower}
+                <tr>
+                    <th class="glm-member-db-social-management-checkbox">
+                        <input type="checkbox" name="checkname-{$socialItem.social_name|lower}" class="glm-form-text-input" value="{$socialField}" {if $socialItem.active}checked{/if}>
+                    </th>
+                    <td class="glm-member-db-social-management-icon">
+                        <div id="glm-member-db-admin-social-{$socialItem.social_name|lower}" title="{$socialItem.social_name}" class="glm-member-db-social-icon" style="background: url('{$assetsUrl}/social-few-full-sprite.jpg') repeat scroll {$socialItem.social_xpos}px {$socialItem.social_ypos}px;height:33px;width:33px;display:block;">
+                        </div>
+                    </td>
+                    <td class="glm-member-db-social-management-name">
+                        {$socialItem.social_name}
+                    </td>
+<!--                    <td>
+                        <input type="button" class="button glm-button submit" value="Change Icon" name="newSocialIcon">
+                    </td>
+                    <td>
+                        <div class="glm-galleryImage" data-id="logo">
+                            <img src="{$glmPluginMediaURL}/images/small/{$member.fieldData.logo}">
+                        </div>
+                        <div id="glm-galleryImageLarger_logo" class="glm-imageDialog">
+                            <div id="glm-member-db-admin-social-{$socialItem.name|lower}" title="{$socialItem.name}" class="glm-member-db-social-icon" style="background: url('{$assetsUrl}/social-few-full-sprite.jpg') repeat scroll {$socialItem.xpos}px {$socialItem.ypos}px;height:33px;width:33px;display:block;">
+                            </div>  
+                        </div>
+                    </td>
+
+                    <td class="glm-admin-image-edit-table">
+                        <div class="glm-galleryImage" data-id="logo">
+                            <div id="glm-member-db-admin-social-{$socialItem.name|lower}" title="{$socialItem.name}" class="glm-member-db-social-icon" style="background: url('{$assetsUrl}/social-few-full-sprite.jpg') repeat scroll {$socialItem.xpos}px {$socialItem.ypos}px;height:33px;width:33px;display:block;">
+                            </div> 
+                        </div>
+                    </td>
+                    <td colspan="2"><b>New image:</b> <input type="file" name="logo_new"></td>
+                    <td><div id="glm-galleryImageLarger_logo" class="glm-imageDialog"></div></td>-->
+                </tr>
+            {/foreach}
+            </table>
+            <input type="submit" class="button glm-button submit" value="submit" name='submit'>
+        </form>
+    </div>
+    
+
+    <script type="text/javascript">
+        jQuery(document).ready(function($) {
+            // Flash certain elements for a short time after display      
+            $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+        });
+</script>
+{include file='admin/footer.html'}
\ No newline at end of file