From: Steve Sutton Date: Thu, 9 Jul 2015 20:30:37 +0000 (-0400) Subject: Moving files around. X-Git-Tag: v0.0.2^2~50 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=f5dde7630dcd6c13d896dfaa07d0a5739e907e08;p=WP-Plugins%2Fglm-wp-importer.git Moving files around. put the Import class into controllers folder --- diff --git a/controllers/Admin.php b/controllers/Admin.php index 22fe5cc..b2597e3 100644 --- a/controllers/Admin.php +++ b/controllers/Admin.php @@ -36,7 +36,7 @@ class GlmWPImporter_Admin_Controller $this->path = $path; add_action('admin_menu', array($this, 'glmwpimporter_add_admin_menu')); add_action('admin_init', array($this, 'glmwpimporter_settings_init')); - + } static public function activate_plugin() @@ -54,7 +54,7 @@ class GlmWPImporter_Admin_Controller public function glmwpimporter_add_admin_menu() { - add_menu_page( + add_options_page( 'Gaslight WP Importer Setup', 'GLM WP Importer', GLM_WP_IMPORT_CAPABILITY, diff --git a/controllers/Import.php b/controllers/Import.php index c771250..d740719 100644 --- a/controllers/Import.php +++ b/controllers/Import.php @@ -27,12 +27,87 @@ * @release Release: (0.0.1) * @link <> */ -class GlmWPImporter_Import_Controller -{ - public $path; - - public function __construct($path) - { - $this->path = $path; - } -} + 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 '
'; + 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=glmwpimporter' + ), + array($toolbox_import, 'dispatch') + ); diff --git a/glm-wp-importer.php b/glm-wp-importer.php deleted file mode 100644 index 23a5cff..0000000 --- a/glm-wp-importer.php +++ /dev/null @@ -1,85 +0,0 @@ -'; - 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 72d5272..db6b44d 100644 --- a/index.php +++ b/index.php @@ -14,7 +14,6 @@ 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'));