Putting this code into a branch for Laury. Video ember code transfer.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 19 Jul 2016 14:50:55 +0000 (10:50 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 19 Jul 2016 14:50:55 +0000 (10:50 -0400)
This code will transfer the embed youtube code from the descr field in
the member_info table to the video_url field and delete the iframe code
from the descr.
So far it is finding the code and parsing out the youtube embed id.

models/admin/management/videos.php [new file with mode: 0644]
setup/validActions.php
views/admin/management/header.html
views/admin/management/videos.html [new file with mode: 0644]

diff --git a/models/admin/management/videos.php b/models/admin/management/videos.php
new file mode 100644 (file)
index 0000000..1e71a4a
--- /dev/null
@@ -0,0 +1,177 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Development
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+/*
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_management_videos
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * '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.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        $resultMessage         = '';
+        $success               = false;
+        $haveMembers           = false;
+        $import                = false;
+        $importNotice          = '';
+        $haveDatabaseTableList = false;
+        $databaseList          = false;
+
+        // Get current database version
+        $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION;
+        settype($dbVersion, 'string');
+
+        // Load database activation class to get access to database version information
+        require_once (GLM_MEMBERS_PLUGIN_PATH . '/activate.php');
+        $activate = new glmMembersPluginActivate($this->wpdb, $this->config, true);
+
+        $option = '';
+        if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') {
+            $option = $_REQUEST['option'];
+        }
+
+        switch($option) {
+        case 'transfer_videos':
+            $resultMessage = '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
+            $sql = "
+            SELECT id,descr,video_url
+              FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+             WHERE descr like '%youtube.com/embed%'
+            ORDER BY id";
+            $results = $this->wpdb->get_results( $sql, ARRAY_A );
+            //echo '<pre>$results: ' . print_r($results, true) . '</pre>';
+            if ( $results ) {
+                foreach ( $results as $member ) {
+                    // parse out the iframe code
+                    $descr = $member['descr'];
+                    //$resultMessage .= '<pre>' . htmlspecialchars( $descr ) . '</pre>';
+                    if ( preg_match( '%<iframe ?(.*)>(.*)</iframe>%', $descr, $matches ) ) {
+                        // match 0 is the whole iframe
+                        $iframeCode = $matches[0];
+                        // from the first matched element get the src attribute
+                        if ( preg_match( '%youtube.com/embed/([^?"]*)%', $matches[1], $srcMatches ) ) {
+                            echo '<pre>$srcMatches: ' . print_r($srcMatches, true) . '</pre>';
+                        }
+                        //$resultMessage .= '<pre>$matches: ' . print_r($matches, true) . '</pre>';
+                    }
+                }
+            }
+            break;
+
+        default:
+            // do a search for members with video embed code in descr field.
+            $sql = "
+            SELECT count(id)
+              FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+             WHERE descr like '%youtube.com/embed%'
+            ORDER BY id";
+            $count = $this->wpdb->get_var( $sql );
+            //echo '<pre>$count: ' . print_r($count, true) . '</pre>';
+            $resultMessage = "There are {$count} Members with embed code in their descr field.";
+            break;
+        }
+
+        $templateData['resultMessage']         = $resultMessage;
+        $templateData['success']               = $success;
+        $templateData['haveMembers']           = $haveMembers;
+        $templateData['importNotice']          = $importNotice;
+        $templateData['haveDatabaseTableList'] = $haveDatabaseTableList;
+        $templateData['databaseList']          = $databaseList;
+
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => true,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/management/videos.html',
+            'data'             => $templateData
+        );
+
+    }
+
+}
index be7b0f0..549a70b 100644 (file)
@@ -63,6 +63,7 @@ $glmMembersValidActions = array(
             'index'       => 'glm-member-db',            // General Options
             'terms'       => 'glm-member-db',
             'development' => 'glm-member-db',
+            'videos'      => 'glm-member-db',
             'theme'       => 'glm-member-db',
             'import'      => 'glm-member-db',
             'addons'      => 'glm-member-db',
index 2bda60f..99b0aec 100644 (file)
@@ -1,7 +1,7 @@
 <div class="wrap">
 
     <h2>{$glmPluginName} Configuration</h2>
-       
+
     <h2 class="nav-tab-wrapper">
         <a href="{$thisUrl}?page={$thisPage}&glm_action=index" class="nav-tab{if $thisAction==index} nav-tab-active{/if}">General Settings</a>
         <a href="{$thisUrl}?page={$thisPage}&glm_action=terms" class="nav-tab{if $thisAction==terms} nav-tab-active{/if}">Terms and Phrases</a>
         <a href="{$thisUrl}?page={$thisPage}&glm_action=import" class="nav-tab{if $thisAction==import} nav-tab-active{/if}">Members</a>
         <a href="{$thisUrl}?page={$thisPage}&glm_action=addons" class="nav-tab{if $thisAction==addons} nav-tab-active{/if}">Add-Ons</a>
         <a href="{$thisUrl}?page={$thisPage}&glm_action=hooks" class="nav-tab{if $thisAction==hooks} nav-tab-active{/if}">Hooks</a>
+        <a href="{$thisUrl}?page={$thisPage}&glm_action=videos" class="nav-tab{if $thisAction==videos} nav-tab-active{/if}">Videos</a>
 {foreach $addOnTabs as $a}
         <a href="{$thisUrl}?page={$thisPage}&glm_action={$a.action}" class="nav-tab{if $thisAction==$a.action} nav-tab-active{/if}">{$a.text}</a>
-{/foreach}        
+{/foreach}
     </h2>
     <div id="glm-admin-content-container">
-    
\ No newline at end of file
+
diff --git a/views/admin/management/videos.html b/views/admin/management/videos.html
new file mode 100644 (file)
index 0000000..720f5b5
--- /dev/null
@@ -0,0 +1,14 @@
+{include file='admin/management/header.html'}
+
+<h2>Videos</h2>
+
+{if $resultMessage}
+    <div>
+        <hr>
+        {$resultMessage}
+    </div>
+{/if}
+
+<a href="{$thisUrl}?page={$thisPage}&glm_action=videos&option=transfer_videos">Transfer embed scripts to video_url</a>
+
+{include file='admin/footer.html'}