From 5edae9692dd37c1af991c719dd6995a713c8b983 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 19 Jul 2016 10:50:55 -0400 Subject: [PATCH] Putting this code into a branch for Laury. Video ember code transfer. 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 | 177 +++++++++++++++++++++++++++++ setup/validActions.php | 1 + views/admin/management/header.html | 7 +- views/admin/management/videos.html | 14 +++ 4 files changed, 196 insertions(+), 3 deletions(-) create mode 100644 models/admin/management/videos.php create mode 100644 views/admin/management/videos.html diff --git a/models/admin/management/videos.php b/models/admin/management/videos.php new file mode 100644 index 00000000..1e71a4a9 --- /dev/null +++ b/models/admin/management/videos.php @@ -0,0 +1,177 @@ + + * @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 = '
$_REQUEST: ' . print_r($_REQUEST, true) . '
'; + $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 '
$results: ' . print_r($results, true) . '
'; + if ( $results ) { + foreach ( $results as $member ) { + // parse out the iframe code + $descr = $member['descr']; + //$resultMessage .= '
' . htmlspecialchars( $descr ) . '
'; + if ( preg_match( '%%', $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 '
$srcMatches: ' . print_r($srcMatches, true) . '
'; + } + //$resultMessage .= '
$matches: ' . print_r($matches, true) . '
'; + } + } + } + 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 '
$count: ' . print_r($count, true) . '
'; + $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 + ); + + } + +} diff --git a/setup/validActions.php b/setup/validActions.php index be7b0f0d..549a70b4 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -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', diff --git a/views/admin/management/header.html b/views/admin/management/header.html index 2bda60f0..99b0aec0 100644 --- a/views/admin/management/header.html +++ b/views/admin/management/header.html @@ -1,7 +1,7 @@

{$glmPluginName} Configuration

- +
- \ No newline at end of file + diff --git a/views/admin/management/videos.html b/views/admin/management/videos.html new file mode 100644 index 00000000..720f5b54 --- /dev/null +++ b/views/admin/management/videos.html @@ -0,0 +1,14 @@ +{include file='admin/management/header.html'} + +

Videos

+ +{if $resultMessage} +
+
+ {$resultMessage} +
+{/if} + +Transfer embed scripts to video_url + +{include file='admin/footer.html'} -- 2.17.1