First Commit master
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 24 Aug 2016 13:12:14 +0000 (09:12 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 24 Aug 2016 13:12:14 +0000 (09:12 -0400)
This is a basic copy from the petoskey area plugin created for fetching
the hubspot blog entry.

controllers/Admin.php [new file with mode: 0644]
controllers/Front.php [new file with mode: 0644]
index.php [new file with mode: 0644]
models/database.php [new file with mode: 0644]
other/fetchProps.php [new file with mode: 0644]
views/deniedAccess.php [new file with mode: 0644]
views/frontPage.php [new file with mode: 0644]
views/optionsPage.php [new file with mode: 0644]
views/text.php [new file with mode: 0644]
views/textArea.php [new file with mode: 0644]

diff --git a/controllers/Admin.php b/controllers/Admin.php
new file mode 100644 (file)
index 0000000..ce45fc8
--- /dev/null
@@ -0,0 +1,194 @@
+<?php
+
+/**
+ * Admin.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.1)
+ * @link      <>
+ */
+
+/**
+ * Toolkit_Package_Admin
+ *
+ * Description of Admin
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.1)
+ * @link      <>
+ */
+class GlmHomeAway_Admin_Controller
+{
+    public $path;
+
+    public function __construct($path)
+    {
+        $this->path = $path;
+        add_action('admin_menu', array($this, 'glm_homeaway_add_admin_menu'));
+        add_action('admin_init', array($this, 'glm_homeaway_settings_init'));
+    }
+
+    static public function activate_plugin()
+    {
+        GlmHomeAway_Admin_Controller::add_capability();
+    }
+
+    static public function deactivate_plugin()
+    {
+        GlmHomeAway_Admin_Controller::remove_capability();
+    }
+
+    static public function add_capability()
+    {
+        $roles = get_editable_roles();
+        foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+            if (isset($roles[$key]) && $role->has_cap(GLM_HOMEAWAY_BUILT_IN_CAPABILITY)) {
+                $role->add_cap(GLM_HOMEAWAY_NEW_CAPABILITY);
+            }
+        }
+    }
+
+    static public function remove_capability()
+    {
+        $roles = get_editable_roles();
+        foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+            if (isset($roles[$key]) && $role->has_cap(GLM_HOMEAWAY_NEW_CAPABILITY)) {
+                $role->remove_cap(GLM_HOMEAWAY_NEW_CAPABILITY);
+            }
+        }
+    }
+
+    static public function glm_homeaway_uninstall()
+    {
+        delete_option(GLM_HOMEAWAY_SETTINGS);
+    }
+
+    public function glm_homeaway_add_admin_menu()
+    {
+        add_options_page(
+            'HomeAway',
+            'HomeAway',
+            GLM_HOMEAWAY_NEW_CAPABILITY,
+            'glm_homeaway',
+            array($this, 'glm_homeaway_options_page'),
+            'dashicons-admin-network'
+        );
+    }
+
+    public function glm_homeaway_settings_exist()
+    {
+        if (false == get_option(GLM_HOMEAWAY_SETTINGS)) {
+            add_option(GLM_HOMEAWAY_SETTINGS);
+        }
+    }
+
+    public function glm_homeawayAddSettingTextField($name, $label, $type)
+    {
+        switch ($type) {
+            case 'text':
+                $callback = 'glm_homeawayRenderText';
+                break;
+            case 'textarea':
+                $callback = 'glm_homeawayRenderTextArea';
+                break;
+            default:
+                return false;
+                break;
+        }
+        add_settings_field(
+            $name,
+            __($label, 'wordpress'),
+            array($this, $callback),
+            GLM_HOMEAWAY_OPTION_GROUP,
+            'glm_homeaway_' . GLM_HOMEAWAY_OPTION_GROUP . '_section',
+            $name
+        );
+    }
+
+    public function glm_homeaway_settings_init()
+    {
+        register_setting(GLM_HOMEAWAY_OPTION_GROUP, GLM_HOMEAWAY_SETTINGS);
+        add_filter(
+            'option_page_capability_' . GLM_HOMEAWAY_OPTION_GROUP,
+            array($this, 'glm_homeaway_option_page_capability')
+        );
+        add_settings_section(
+            'glm_homeaway_' . GLM_HOMEAWAY_OPTION_GROUP . '_section',
+            __('Edit Setting', 'wordpress'),
+            array($this, 'glm_homeaway_settings_section_callback'),
+            GLM_HOMEAWAY_OPTION_GROUP
+        );
+
+        $fieldNames = array(
+            array(
+                'name'  => 'user_id',
+                'label' => 'User Id',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'password',
+                'label' => 'Password',
+                'type'  => 'text'
+            ),
+            array(
+                'name'  => 'coid',
+                'label' => 'COID',
+                'type'  => 'text'
+            ),
+        );
+
+        foreach ($fieldNames as $field) {
+            $this->glm_homeawayAddSettingTextField(
+                $field['name'],
+                $field['label'],
+                $field['type']
+            );
+        }
+    }
+
+    public function glm_homeawayRenderText($fieldName)
+    {
+        static $options;
+        if (!$options) {
+            $options = get_option(GLM_HOMEAWAY_SETTINGS);
+        }
+        include $this->path . 'views/text.php';
+    }
+
+    public function glm_homeawayRenderTextArea($fieldName)
+    {
+        static $options;
+        $options = get_option(GLM_HOMEAWAY_SETTINGS);
+        include $this->path . 'views/textArea.php';
+    }
+
+    public function glm_homeaway_settings_section_callback()
+    {
+        echo __('HomeAway Creds', 'wordpress');
+    }
+
+    public function glm_homeaway_option_page_capability($capability)
+    {
+        return GLM_HOMEAWAY_NEW_CAPABILITY;
+    }
+
+    public function glm_homeaway_options_page()
+    {
+        if (current_user_can(GLM_HOMEAWAY_NEW_CAPABILITY)) {
+            include $this->path . 'views/optionsPage.php';
+        } else {
+            include $this->path . 'views/deniedAccess.php';
+        }
+    }
+
+}
diff --git a/controllers/Front.php b/controllers/Front.php
new file mode 100644 (file)
index 0000000..a8f4293
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * Front.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.1)
+ * @link      <>
+ */
+
+/**
+ * Toolkit_Package_Front
+ *
+ * Description of Front
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.1)
+ * @link      <>
+ */
+class GlmHomeAway_Front_controller
+{
+
+    /**
+     * Plugin Path
+     *
+     * @var type String
+     */
+    public $path;
+
+    /**
+     * Initializes Front Controller class
+     *
+     * @param type $path Plugin path
+     */
+    function __construct($path)
+    {
+        $this->path = $path;
+    }
+
+
+}
diff --git a/index.php b/index.php
new file mode 100644 (file)
index 0000000..7ca8f6a
--- /dev/null
+++ b/index.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Plugin Name: Homeaway Prop List Cache
+ * Description: Cache the list of properties from homeaway
+ * Version: 0.0.1
+ * Author: Steve Sutton
+ * Author URI: http://www.gaslightmedia.com
+ * License: All right reserved
+ */
+define('GLM_HOMEAWAY_PLUGIN_PATH_FILE', __FILE__);
+define('GLM_HOMEAWAY_PLUGIN_DIR', plugin_dir_path(__FILE__));
+define('GLM_HOMEAWAY_DB_VERSION', '0.0.1');
+define('GLM_HOMEAWAY_DB_VERSION_OPTION_NAME', 'glm_homeaway_db_version');
+define('GLM_HOMEAWAY_TABLE', 'glm_homeaway_feed');
+define('GLM_HOMEAWAY_SETTINGS', 'glm_homeaway_settings');
+define('GLM_HOMEAWAY_OPTION_GROUP', 'glm_homeaway_section');
+define('GLM_HOMEAWAY_NEW_CAPABILITY', 'glm_homeaway_edit_client');
+define('GLM_HOMEAWAY_BUILT_IN_CAPABILITY', 'edit_posts');
+
+register_activation_hook(__FILE__, array('GlmHomeAway_Admin_Controller', 'activate_plugin'));
+register_deactivation_hook(__FILE__, array('GlmHomeAway_Admin_Controller', 'deactivate_plugin'));
+register_uninstall_hook(__FILE__, array('GlmHomeAway_Admin_Controller', 'glm_homeaway_uninstall'));
+
+if (is_admin()) {
+    // call the Admin Controller to setup the Admin of the plugin
+    require_once 'controllers/Admin.php';
+    $adminController = new GlmHomeAway_Admin_Controller(
+        plugin_dir_path(__FILE__)
+    );
+}
+
+// call the Front Controller to setup the widget
+require_once 'controllers/Front.php';
+$frontController = new GlmHomeAway_Front_controller(
+    plugin_dir_path(__FILE__)
+);
+
+/*
+ * Lead the database class
+ */
+require_once 'models/database.php';
+$homeaway_db = new glm_homeaway_models_database($GLOBALS['wpdb']);
diff --git a/models/database.php b/models/database.php
new file mode 100644 (file)
index 0000000..54c44fe
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * database.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.1)
+ * @link      <>
+ */
+
+/**
+ * Toolkit_Package_database
+ *
+ * Description of database
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.1)
+ * @link      <>
+ */
+class glm_homeaway_models_database
+{
+    public $wpdb;
+    public $homeaway_table;
+
+    /**
+     * Class constructor for the database
+     *
+     * @param type $wpdb Wordpress db object
+     */
+    public function __construct($wpdb)
+    {
+        $this->wpdb = $wpdb;
+        register_activation_hook(
+            GLM_HUBSPOT_PLUGIN_PATH_FILE,
+            array($this, 'install')
+        );
+        add_action('plugins_loaded', array($this, 'glm_update_db_check'));
+
+        $this->homeaway_table = $this->wpdb->prefix . GLM_HUBSPOT_TABLE;
+    }
+
+    /**
+     * Install the database tables needed for jobs
+     */
+    public function install()
+    {
+        $charset_collate = $this->wpdb->get_charset_collate();
+
+        $sql = "CREATE TABLE {$this->homeaway_table} (
+            id BIGINT(20) NOT NULL AUTO_INCREMENT,
+            created DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL,
+            updated DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL,
+            prop_id TEXT NOT NULL,
+            prop_name TEXT NOT NULL,
+            UNIQUE KEY id (id)
+            ) {$charset_collate}";
+        include ABSPATH . 'wp-admin/includes/upgrade.php';
+        dbDelta($sql);
+
+        update_option(GLM_HUBSPOT_DB_VERSION_OPTION_NAME, GLM_HUBSPOT_DB_VERSION);
+    }
+
+    /**
+     * DB Version update check to update the database tables
+     */
+    public function glm_update_db_check()
+    {
+        if (GLM_HUBSPOT_DB_VERSION != get_option(GLM_HUBSPOT_DB_VERSION_OPTION_NAME)) {
+            $this->install();
+        }
+    }
+
+}
diff --git a/other/fetchProps.php b/other/fetchProps.php
new file mode 100644 (file)
index 0000000..9c0dff5
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+$url = 'https://secure.instantsoftwareonline.com/StayUSA/ChannelPartners/wsWeblinkPlusAPI.asmx?wsdl';
+$client = new SoapClient( $url );
+$params = array(
+    'strUserId'   => 'P1429',
+    'strPassword' => 'IqM3Dh9E',
+    'strCOID'     => '1134'
+);
+$result = $client->__soapCall(
+    'getPropertyIndexes', array('parameters' => $params)
+);
+$indexArray = $result->getPropertyIndexesResult->clsPropIndex;
+//echo '<pre>$indexArray: ' . print_r( $indexArray, true ) . '</pre>';
+$propListings = array();
+if (is_array($indexArray) && !empty($indexArray)) {
+    foreach ($indexArray as $propertyObject) {
+        $propListings["{$propertyObject->strId}"] = "{$propertyObject->strId} {$propertyObject->strName}";
+    }
+}
+echo '<pre>$propListings: ' . print_r( $propListings, true ) . '</pre>';
diff --git a/views/deniedAccess.php b/views/deniedAccess.php
new file mode 100644 (file)
index 0000000..597bac8
--- /dev/null
@@ -0,0 +1 @@
+<div class="wrap"><p>You do not have permission!</p></div>
diff --git a/views/frontPage.php b/views/frontPage.php
new file mode 100644 (file)
index 0000000..50d697d
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+echo '<div class="homeaway-container">'
+
+        . '<a class="image-link" href="' .$url .'">'
+            . '<div class="homeaway-featured-image" style="background: url('. $image_url . ') no-repeat center center;">'
+            . '</div>'
+        . '</a>'
+         . '<div class="homeaway-title">'
+            . '<a href="' .$url .'">'
+                . '<h1>' . $title. '</h1>'
+            . '</a>'
+        . '</div>'
+        . '<div class="homeaway-blog-content">'. $content . '</div>'
+        . '<a href="' .$url .'"> Read More </a>'
+  . '</div>';
+        ?>
+
+<script type="text/javascript">
+
+     var blog = jQuery('.homeaway-blog-content');
+     var image_link = jQuery(".image-link");
+     var image = jQuery(".homeaway-featured-image");
+     var blog_characters = blog.text().length;
+     var title = jQuery(".homeaway-title");
+
+     image.css("margin-bottom", "20px").css("background-size", "contain").css("width", "200px").css("height","200px");;
+     image_link.css("display", "block").css("width", "200px").css("margin", "0 auto");
+     blog.find('img').remove();
+     title.find("h1").css("margin-bottom", "15px").css("font-size", "25px");
+
+     if(blog_characters > 400){
+         blog.text(blog.text().substring(0,400) + '...');
+     }
+
+</script>
diff --git a/views/optionsPage.php b/views/optionsPage.php
new file mode 100644 (file)
index 0000000..afd28d8
--- /dev/null
@@ -0,0 +1,14 @@
+<div class="wrap">
+    <form action="options.php" method="post">
+        <h1>HomeAway Creds</h1>
+        <div id="glm-client-info-wrapper" class="row">
+            <?php
+                settings_fields(GLM_HOMEAWAY_OPTION_GROUP);
+                do_settings_sections(GLM_HOMEAWAY_OPTION_GROUP);
+            ?>
+            <div style="clear: both; text-align: center;">
+                <?php submit_button();?>
+            </div>
+        </div>
+    </form>
+</div>
diff --git a/views/text.php b/views/text.php
new file mode 100644 (file)
index 0000000..fbd1552
--- /dev/null
@@ -0,0 +1,2 @@
+<input type="text" name="<?php echo GLM_HOMEAWAY_SETTINGS;?>[<?php echo $fieldName;?>]"
+           value="<?php echo str_replace('"', '&quote;', $options[$fieldName]); ?>">
diff --git a/views/textArea.php b/views/textArea.php
new file mode 100644 (file)
index 0000000..5107f04
--- /dev/null
@@ -0,0 +1 @@
+<textarea cols="40" rows="5" name="<?php echo GLM_HUBSPOT_SETTINGS;?>[<?php echo $fieldName;?>]"><?php echo htmlspecialchars($options[$fieldName]); ?></textarea>