Update to get the import part of the plugin working.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 9 Jul 2015 20:09:23 +0000 (16:09 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 9 Jul 2015 20:09:23 +0000 (16:09 -0400)
Now I'm getting somewhere. Have a registered import plugin for Toolbox.

README.md
controllers/Admin.php
glm-wp-importer.php [new file with mode: 0644]
index.php
views/optionsPage.php

index 243114f..0f62f6b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,8 +1,7 @@
 # Gaslight Media Word Press Importer Plugin
 The objective of this plugin is to fetch all toolbox page content from the database. This will also fetch all images and files from the pages and import them properly into the Wordpress Pages.
 
-##
-First you'll need to setup the Database Options. GLM WP Importer
+##First you'll need to setup the Database Options. GLM WP Importer
 1. Database Host: The database host name
 2. Database Name: The database name
 3. Database User: The database user name
index 5fa27f2..22fe5cc 100644 (file)
@@ -35,13 +35,8 @@ class GlmWPImporter_Admin_Controller
     {
         $this->path = $path;
         add_action('admin_menu', array($this, 'glmwpimporter_add_admin_menu'));
-
-        if (isset($action) && $action = filter_var($_REQUEST['glm_action'], FILTER_SANITIZE_STRING)) {
-            add_action('admin_init', array($this, 'glmimporter_import_pages'));
-        } else {
-            add_action('admin_init', array($this, 'glmwpimporter_settings_init'));
-        }
-
+        add_action('admin_init', array($this, 'glmwpimporter_settings_init'));
+        
     }
 
     static public function activate_plugin()
diff --git a/glm-wp-importer.php b/glm-wp-importer.php
new file mode 100644 (file)
index 0000000..23a5cff
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+if (!defined('WP_LOAD_IMPORTERS')) {
+  return;
+}
+require_once ABSPATH . 'wp-admin/includes/import.php';
+
+if ( !class_exists( 'WP_Importer' ) ) {
+       $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
+       if ( file_exists( $class_wp_importer ) ) {
+               require_once $class_wp_importer;
+    }
+}
+
+if (class_exists('WP_Importer')) {
+    class Toolbox_Import extends WP_Importer
+    {
+        private $_dbh;
+        function __construct(){}
+
+        function header()
+        {
+            echo '<div class="wrap">';
+            echo '<h2>'.__('Toolbox Importer').'</h2>';
+        }
+
+        function footer()
+        {
+            echo '</div>';
+        }
+
+        function greet()
+        {
+            echo '<h2>Hello there person!</h2>';
+            // read optios for the import and if they aren't set then give a warning.
+            $options = get_option(GLM_WP_IMPORT_SETTINGS);
+            echo '<pre>'.print_r($options, true).'</pre>';
+            // try making a postgres connection to the database
+            $connectionString  = 'dbname=' . $options['db_name'];
+            $connectionString .= ' host=' . $options['db_host'];
+            $connectionString .= ' user=' . $options['db_user'];
+            $driverOptions = array(
+                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
+            );
+            $this->_dbh = new PDO('pgsql:'.$connectionString, null, null, $driverOptions);
+            $this->_dbh->setAttribute(
+                PDO::ATTR_ERRMODE,
+                PDO::ERRMODE_EXCEPTION
+            );
+            echo '<pre>'.print_r($this->_dbh, true).'</pre>';
+            $sql = "SELECT * FROM toolbox.pages";
+            $data = $this->_dbh->query($sql)->fetchAll();
+            echo '<pre>'.print_r($data, true).'</pre>';
+        }
+
+        function dispatch()
+        {
+            if (empty($_GET['step'])) {
+                $step = 0;
+            } else {
+                $step = filter_var($_GET['step'], FILTER_VALIDATE_INT);
+            }
+            switch($step) {
+            case 0:
+                $this->greet();
+                break;
+            case 1:
+                $this->import();
+                break;
+            }
+        }
+    }
+}
+
+$toolbox_import = new Toolbox_Import();
+
+register_importer(
+    'toolbox',
+    __('Toolbox', 'import-toolbox-pages'),
+    sprintf(
+        __('Import the contents of Gaslight Toolbox Pages as pages. Visit <a href="%s">setup</a> first to setup the database options.',
+        'import-toolbox-pages'),
+        'options-general.php?page=toolbox-html.php'
+    ),
+    array($toolbox_import, 'dispatch')
+);
index db6b44d..72d5272 100644 (file)
--- a/index.php
+++ b/index.php
@@ -14,6 +14,7 @@ define('GLM_WP_IMPORT_OPTION_GROUP', 'glmwp_import_group');
 if (is_admin()) {
     require_once 'controllers/Admin.php';
     require_once 'controllers/Import.php';
+    require_once 'glm-wp-importer.php';
     register_activation_hook(__FILE__, array('GlmWPImporter_Admin_Controller', 'activate_plugin'));
     register_deactivation_hook(__FILE__, array('GlmWPImporter_Admin_Controller', 'deactivate_plugin'));
     register_uninstall_hook(__FILE__, array('GlmWPImporter_Admin_Controller', 'uninstall'));
index 92cd437..a73a3b7 100644 (file)
@@ -7,8 +7,5 @@
             submit_button();
         ?>
     </form>
-    <form action="edit.php?page=glmwpimporter">
-        <input type="hidden" name="glm_action" value="Import">
-        <input class="button" type="submit" value="Import Pages">
-    </form>
+    <a href="admin.php?import=toolbox" class="button-secondary">Get started</a>
 </div>