# 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
{
$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()
--- /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'));