$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()
public function glmwpimporter_add_admin_menu()
{
- add_menu_page(
+ add_options_page(
'Gaslight WP Importer Setup',
'GLM WP Importer',
GLM_WP_IMPORT_CAPABILITY,
* @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 '<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=glmwpimporter'
+ ),
+ array($toolbox_import, 'dispatch')
+ );
+++ /dev/null
-<?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')
-);
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'));