Setting up the member db social add on for use in shortcode and filters
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 17 May 2016 15:21:05 +0000 (11:21 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 17 May 2016 15:21:05 +0000 (11:21 -0400)
Created setup for shortcode
Created model to handle the shortcode
Created a hook in setup fronthooks

models/admin/member/social.php
models/front/social/list.php [new file with mode: 0644]
setup/frontHooks.php
setup/shortcodes.php
setup/validActions.php
views/admin/member/social.html
views/front/social/list.html [new file with mode: 0644]

index cb5d1ad..d0a18f1 100644 (file)
@@ -144,7 +144,9 @@ class GlmMembersAdmin_member_social extends GlmDataSocialUrls
                         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']]) == '') {
+                            if (   !isset($_REQUEST['socialUrl'][$url['social']]) 
+                                || trim($_REQUEST['socialUrl'][$url['social']]) == ''
+                            ) {
 
                                 // delete record here
                                 $this->wpdb->delete(
@@ -163,7 +165,9 @@ class GlmMembersAdmin_member_social extends GlmDataSocialUrls
                     foreach ($socialList as $socialData) {
 
                         // Was there any input for this social media type
-                        if (isset($_REQUEST['socialUrl'][$socialData['id']]) && trim($_REQUEST['socialUrl'][$socialData['id']]) != '') {
+                        if (   isset($_REQUEST['socialUrl'][$socialData['id']]) 
+                            && trim($_REQUEST['socialUrl'][$socialData['id']]) != ''
+                        ) {
 
                             $url = $_REQUEST['socialUrl'][$socialData['id']];
 
@@ -174,7 +178,11 @@ class GlmMembersAdmin_member_social extends GlmDataSocialUrls
                                 $this->wpdb->update(
                                     $this->table,
                                     array('url' => $url),
-                                    array( 'ref_type' => $this->config['ref_type_numb']['MemberInfo'], 'ref_dest' => $memberID, 'social' => $socialData['id']),
+                                    array(
+                                        'ref_type' => $this->config['ref_type_numb']['MemberInfo'], 
+                                        'ref_dest' => $memberID, 
+                                        'social'   => $socialData['id']
+                                    ),
                                     array('%s'),
                                     array('%d', '%d', '%s' )
                                 );
diff --git a/models/front/social/list.php b/models/front/social/list.php
new file mode 100644 (file)
index 0000000..af0e7ee
--- /dev/null
@@ -0,0 +1,66 @@
+<?php 
+/**
+ * list.php
+ *
+ * This the Member Social plugin model for front end output of members social urls
+ */
+require_once(GLM_MEMBERS_SOCIAL_PLUGIN_CLASS_PATH.'/data/dataSocialUrls.php');
+class GlmMembersFront_social_list extends GlmDataSocialUrls
+{
+    public $wpdb;
+    public $config;
+
+    /**
+     * __construct
+     *
+     * @param mixed $wpdb   The main Word Press DB Object
+     * @param mixed $config The main Config
+     *
+     * @access public
+     * @return void
+     */
+    public function __construct($wpdb, $config)
+    {
+        $this->wpdb = $wpdb;
+        $this->config = $config;
+
+        parent::__construct(false, false);
+    }
+
+    /**
+     * modelAction
+     *
+     * @param bool $actionData Action Data passed to the modelAction
+     *
+     * @access public
+     * @return void
+     */
+    public function modelAction($actionData = false)
+    {
+        $status = null;
+        $action = '';
+        $settings = $urlList = array();
+        $view = 'list.html';
+
+        $memberID = filter_var( $actionData['request']['id'], FILTER_VALIDATE_INT);
+        if ($memberID) {
+            $urlList = $this->getList("ref_dest = " . $memberID);
+        }
+
+        // Compile template data
+        $templateData = array(
+            'socials'  => $urlList,
+            'memberID' => $memberID,
+        );
+
+        error_reporting(E_ALL ^ E_NOTICE);
+        return array(
+            'status'           => $status,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'front/social/' . $view,
+            'data'             => $templateData,
+            'settings'         => $settings
+        );
+    }
+}
index 3ed55df..ad9160b 100644 (file)
  *
  *  *** Also note that parameters will be in the context of the main front controller constructor. ***
  */
+if (isset($this->config['addOns']['glm-member-db'])) {
+    // Add internal page content links to member detail page
+    add_filter('glm-member-db-front-members-social-list', function($content, $id) {
+            $socialData = do_shortcode('[glm-members-social-list id='.$id.']');
+            $content .= $socialData;
+            return $content;
+        },
+        10,
+        2
+    );
+}
index 97a1a0a..170f74d 100644 (file)
  */
 
 $glmMembersSocialShortcodes = array(
+    'glm-members-social-list' => array(
+        'plugin'     => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG,
+        'menu'       => 'social',
+        'action'     => 'list',
+        'table'      => false,
+        'attributes' => array(
+            'id' => false
+        )
+
+    ),
 );
 
-$glmMembersSocialShortcodesDescription = '';
+$glmMembersSocialShortcodesDescription = '<tr>
+        <th>[glm-members-social-list]</th>
+        <td>&nbsp;</td>
+        <td width="50%">
+            Displays a list of social url\'s.
+        </td>
+    </tr>';
 
index 62f1bd9..92d210b 100644 (file)
@@ -54,13 +54,11 @@ $glmMembersSocialAddOnValidActions = array(
         )
     ),
     'frontActions' => array(
-/*
         'social' => array(
             'list' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG,
-            'detail' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG
+    //        'detail' => GLM_MEMBERS_SOCIAL_PLUGIN_SLUG
         )
-*/
     )
 );
 
-?>
\ No newline at end of file
+?>
index abff50a..4af11b3 100644 (file)
@@ -6,10 +6,15 @@
         <form action="{$thisUrl}?page={$thisPage}&glm_action=social&member={$memberID}" 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">
+            {foreach from=$socials key=k item=socialItem}
+                {if !$socialItem.active.value}
+                <input type="hidden" name="socialUrl[{$socialItem.id}]" value="{if isset($socialItem.url)}{$socialItem.url}{/if}">
+                {/if}
+            {/foreach}
             <table class="wp-list-table striped glm-admin-table">
                 <tr><th>Social Media Type</th><th>Icon</th><th>URL</th></tr>
             {foreach from=$socials key=k item=socialItem}
-                {if $socialItem.active}
+                {if $socialItem.active.value}
                     {$socialField = $socialItem.name|lower}
                     <tr>
                         <th>
diff --git a/views/front/social/list.html b/views/front/social/list.html
new file mode 100644 (file)
index 0000000..ce8abe8
--- /dev/null
@@ -0,0 +1,7 @@
+{if $memberID}
+    {foreach $socials as $social}
+    <a href="{$social.url}" target="_blank" title="{$social.social_name}">
+          <img alt="{$social.social_name}" src="data:image/png;base64,{$social.social_b64icon}">
+      </a>
+    {/foreach}
+{/if}