From 5350385b22c944ab57ea9a4e3f29dbeacdee39bb Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 9 Jul 2015 16:09:23 -0400 Subject: [PATCH] Update to get the import part of the plugin working. Now I'm getting somewhere. Have a registered import plugin for Toolbox. --- README.md | 3 +- controllers/Admin.php | 9 +---- glm-wp-importer.php | 85 +++++++++++++++++++++++++++++++++++++++++++ index.php | 1 + views/optionsPage.php | 5 +-- 5 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 glm-wp-importer.php diff --git a/README.md b/README.md index 243114f..0f62f6b 100644 --- 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 diff --git a/controllers/Admin.php b/controllers/Admin.php index 5fa27f2..22fe5cc 100644 --- a/controllers/Admin.php +++ b/controllers/Admin.php @@ -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 index 0000000..23a5cff --- /dev/null +++ b/glm-wp-importer.php @@ -0,0 +1,85 @@ +'; + echo '

'.__('Toolbox Importer').'

'; + } + + function footer() + { + echo ''; + } + + function greet() + { + echo '

Hello there person!

'; + // read optios for the import and if they aren't set then give a warning. + $options = get_option(GLM_WP_IMPORT_SETTINGS); + echo '
'.print_r($options, true).'
'; + // 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 '
'.print_r($this->_dbh, true).'
'; + $sql = "SELECT * FROM toolbox.pages"; + $data = $this->_dbh->query($sql)->fetchAll(); + echo '
'.print_r($data, true).'
'; + } + + 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 setup first to setup the database options.', + 'import-toolbox-pages'), + 'options-general.php?page=toolbox-html.php' + ), + array($toolbox_import, 'dispatch') +); diff --git a/index.php b/index.php index db6b44d..72d5272 100644 --- 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')); diff --git a/views/optionsPage.php b/views/optionsPage.php index 92cd437..a73a3b7 100644 --- a/views/optionsPage.php +++ b/views/optionsPage.php @@ -7,8 +7,5 @@ submit_button(); ?> -
- - -
+ Get started -- 2.17.1