Initial import of the plugin v0.0.1
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 8 Jul 2015 20:52:39 +0000 (16:52 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 8 Jul 2015 20:52:39 +0000 (16:52 -0400)
NOTES.md [new file with mode: 0644]
README.md [new file with mode: 0644]
controllers/Admin.php [new file with mode: 0644]
controllers/Import.php [new file with mode: 0644]
index.php [new file with mode: 0644]
views/deniedAccess.php [new file with mode: 0644]
views/optionsPage.php [new file with mode: 0644]
views/text.php [new file with mode: 0644]

diff --git a/NOTES.md b/NOTES.md
new file mode 100644 (file)
index 0000000..a3e1c6b
--- /dev/null
+++ b/NOTES.md
@@ -0,0 +1,12 @@
+Resources for the image importing:
+
+Plugins that work well with importing the images into the Media Library.
+Currently the Html Import 2 Plugin does a nice job of parsing out a list of images and files from the page content (post and pages)
+and fetches a list of images and files that then is added to the Media Library. Pages or Post are then updated with the media information.
+
+I'm planning on using the same thing here. 
+
+1. Store db options in settings.
+2. Fetch all pages from the database and add pages.
+3. Fetch list of all images, files and import them into Media Library
+4. Update all pages with new references of the images.
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..243114f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,14 @@
+# 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
+1. Database Host: The database host name
+2. Database Name: The database name
+3. Database User: The database user name
+4. Database Password: The database password (if set)
+5. Toolbox Schema: The schema used for the Toolbox (blank for no schema or public)
+6. Toolbox Page Table: Table name of the Toolbox Pages
+7. Toolbox Paragraph Table: Table name of the Toolbox Paragraphs
+8. CKEditor Schema: Schema name for the CKEditor
+9. CKEditor Images Table: Table name for the CKEditor Images
diff --git a/controllers/Admin.php b/controllers/Admin.php
new file mode 100644 (file)
index 0000000..4071142
--- /dev/null
@@ -0,0 +1,200 @@
+<?php
+
+/**
+ * Admin.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Importer
+ * @package   GLM WP Importer
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.0.1)
+ * @link      <>
+ */
+
+/**
+ * GlmWPImporter_Admin_Controller
+ *
+ * Main Controller for the Gaslight WP Importer Plugin
+ *
+ * @category  Importer
+ * @package   GLM WP Importer
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.0.1)
+ * @link      <>
+ */
+class GlmWPImporter_Admin_Controller
+{
+    public $path;
+
+    public function __construct($path)
+    {
+        $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()
+    {
+    }
+
+    static public function deactivate_plugin()
+    {
+    }
+
+
+    static public function glmwpimporter_uninstall()
+    {
+        delete_option(GLM_WP_IMPORT_SETTINGS);
+    }
+
+    public function glmwpimporter_add_admin_menu()
+    {
+        add_menu_page(
+            'Gaslight WP Importer Setup',
+            'GLM WP Importer',
+            GLM_WP_IMPORT_CAPABILITY,
+            'glmwpimporter',
+            array($this, 'glmwpimporter_options_page'),
+            'dashicons-download'
+        );
+    }
+
+    public function glmwpimporter_settings_exist()
+    {
+        if (false == get_option(GLM_WP_IMPORT_SETTINGS)) {
+            add_option(GLM_WP_IMPORT_SETTINGS);
+        }
+    }
+
+    public function glmwpimporter_settings_init()
+    {
+        register_setting(GLM_WP_IMPORT_OPTION_GROUP, GLM_WP_IMPORT_SETTINGS);
+        add_filter(
+            'option_page_capability_' . GLM_WP_IMPORT_OPTION_GROUP,
+            array($this, 'glmwpimporter_option_page_capability')
+        );
+
+        add_settings_section(
+            'glmwpimporter_' . GLM_WP_IMPORT_OPTION_GROUP . '_section',
+            __('Edit your Import Setting', 'wordpress'),
+            array($this, 'glmwpimporter_settings_section_callback'),
+            GLM_WP_IMPORT_OPTION_GROUP
+        );
+
+        $fieldNames = array(
+            array(
+                'name'  => 'db_host',
+                'label' => 'Database Host',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'db_name',
+                'label' => 'Database Name',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'db_user',
+                'label' => 'Database User',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'db_password',
+                'label' => 'Database Password',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'toolbox_schema',
+                'label' => 'Toolbox Schema',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'toolbox_page_table',
+                'label' => 'Toolbox Page Table',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'toolbox_paragraphs_table',
+                'label' => 'Toolbox Paragraph Table',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'toolbox_files_table',
+                'label' => 'Toolbox Files Table',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'ckeditor_schema',
+                'label' => 'CKEditor Schema',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'ckeditor_images_table',
+                'label' => 'CKEditor Images Table',
+                'type'  => 'text'
+            ),
+        );
+
+        foreach ($fieldNames as $field) {
+            $this->glmwpimporterAddSettingTextField(
+                $field['name'],
+                $field['label'],
+                $field['type']
+            );
+        }
+    }
+
+    public function glmwpimporterAddSettingTextField($name, $label, $type)
+    {
+        switch ($type) {
+            case 'text':
+                $callback = 'glmwpimporterRenderText';
+                break;
+            default:
+                return false;
+                break;
+        }
+        add_settings_field(
+            $name,
+            __($label, 'wordpress'),
+            array($this, $callback),
+            GLM_WP_IMPORT_OPTION_GROUP,
+            'glmwpimporter_' . GLM_WP_IMPORT_OPTION_GROUP. '_section',
+            $name
+        );
+    }
+
+    public function glmwpimporterRenderText($fieldName)
+    {
+        static $options;
+        if (!$options) {
+            $options = get_option(GLM_WP_IMPORT_SETTINGS);
+        }
+        include $this->path . 'views/text.php';
+    }
+
+    public function glmwpimporter_settings_section_callback()
+    {
+        echo __('Database Options', 'wordpress');
+    }
+
+    public function glmwpimporter_option_page_capability($capability)
+    {
+        return GLM_WP_IMPORT_CAPABILITY;
+    }
+
+    public function glmwpimporter_options_page()
+    {
+        if (current_user_can(GLM_WP_IMPORT_CAPABILITY)) {
+            include $this->path . 'views/optionsPage.php';
+        } else {
+            include $this->path . 'views/deniedAccess.php';
+        }
+    }
+
+}
diff --git a/controllers/Import.php b/controllers/Import.php
new file mode 100644 (file)
index 0000000..c771250
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Import.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Importer
+ * @package   GLM WP Importer
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.0.1)
+ * @link      <>
+ */
+
+/**
+ * GlmWPImporter_Import_Controller
+ *
+ * Main Controller for the Gaslight WP Importer Plugin
+ *
+ * @category  Importer
+ * @package   GLM WP Importer
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.0.1)
+ * @link      <>
+ */
+class GlmWPImporter_Import_Controller
+{
+    public $path;
+
+    public function __construct($path)
+    {
+        $this->path = $path;
+    }
+}
diff --git a/index.php b/index.php
new file mode 100644 (file)
index 0000000..690c9d3
--- /dev/null
+++ b/index.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Plugin Name: GLM WP Importer
+ * Description: Import Gaslight Media Toolbox Content Into WordPress
+ * Version: 0.0.1
+ * Author: Steve Sutton
+ * Author URI: http://www.gaslightmedia.com
+ * License: All right reserved
+ */
+define('GLM_WP_IMPORT_SETTINGS', 'glm_wp_import_settings');
+define('GLM_WP_IMPORT_CAPABILITY', 'manage_options');
+define('GLM_WP_IMPORT_OPTION_GROUP', 'glmwp_import_group');
+
+if (is_admin()) {
+    require_once 'controllers/Admin.php';
+    require_once 'controllers/Import.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'));
+
+
+    if ($action = filter_var($_REQUEST['glm_action'], FILTER_SANITIZE_STRING)) {
+        $importController = new GlmWPImporter_Import_Controller(plugin_dir_path(__FILE__));
+    } else {
+        $adminController = new GlmWPImporter_Admin_Controller(plugin_dir_path(__FILE__));
+    }
+}
diff --git a/views/deniedAccess.php b/views/deniedAccess.php
new file mode 100644 (file)
index 0000000..effa1fc
--- /dev/null
@@ -0,0 +1 @@
+<div class="wrap"><p>You do not have permission to edit Gaslight Media WP Importer Settings</p></div>
diff --git a/views/optionsPage.php b/views/optionsPage.php
new file mode 100644 (file)
index 0000000..f3bfda6
--- /dev/null
@@ -0,0 +1,14 @@
+<div class="wrap">
+    <form action="options.php" method="post">
+        <h2>Gaslight WP Importer Settings</h2>
+        <?php
+            settings_fields(GLM_WP_IMPORT_OPTION_GROUP);
+            do_settings_sections(GLM_WP_IMPORT_OPTION_GROUP);
+            submit_button();
+        ?>
+    </form>
+    <form action="admin.php?page=glmwpimporter">
+        <input type="hidden" name="glm_action" value="Import">
+        <input class="button" type="submit" value="Import Pages">
+    </form>
+</div>
diff --git a/views/text.php b/views/text.php
new file mode 100644 (file)
index 0000000..e62126b
--- /dev/null
@@ -0,0 +1,2 @@
+<input type="text" name="<?php echo GLM_WP_IMPORT_SETTINGS;?>[<?php echo $fieldName;?>]"
+           value="<?php echo str_replace('"', '&quote;', $options[$fieldName]); ?>">