--- /dev/null
+<?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 GlmHubSpot_Admin_Controller
+{
+ public $path;
+
+ public function __construct($path)
+ {
+ $this->path = $path;
+ add_action('admin_menu', array($this, 'glm_hubspot_add_admin_menu'));
+ add_action('admin_init', array($this, 'glm_hubspot_settings_init'));
+ //add_action('wp_enqueue_scripts', array($this, 'load_stylesheet'));
+ //add_action('wp_enqueue_scripts', array($this, 'load_script'));
+
+ }
+
+ static public function activate_plugin()
+ {
+ GlmHubSpot_Admin_Controller::add_capability();
+ }
+
+ static public function deactivate_plugin()
+ {
+ GlmHubSpot_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_HUBSPOT_BUILT_IN_CAPABILITY)) {
+ $role->add_cap(GLM_HUBSPOT_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_HUBSPOT_NEW_CAPABILITY)) {
+ $role->remove_cap(GLM_HUBSPOT_NEW_CAPABILITY);
+ }
+ }
+ }
+
+ static public function glm_hubspot_uninstall()
+ {
+ delete_option(GLM_HUBSPOT_SETTINGS);
+ }
+
+ public function glm_hubspot_add_admin_menu()
+ {
+ add_options_page(
+ 'HubSpot Blog',
+ 'Hubspot Blog',
+ GLM_HUBSPOT_NEW_CAPABILITY,
+ 'glm_hubspot',
+ array($this, 'glm_hubspot_options_page'),
+ 'dashicons-admin-network'
+ );
+ }
+
+ public function glm_hubspot_settings_exist()
+ {
+ if (false == get_option(GLM_HUBSPOT_SETTINGS)) {
+ add_option(GLM_HUBSPOT_SETTINGS);
+ }
+ }
+
+ public function glm_hubspotAddSettingTextField($name, $label, $type)
+ {
+ switch ($type) {
+ case 'text':
+ $callback = 'glm_hubspotRenderText';
+ break;
+ case 'textarea':
+ $callback = 'glm_hubspotRenderTextArea';
+ break;
+ default:
+ return false;
+ break;
+ }
+ add_settings_field(
+ $name,
+ __($label, 'wordpress'),
+ array($this, $callback),
+ GLM_HUBSPOT_OPTION_GROUP,
+ 'glm_hubspot_' . GLM_HUBSPOT_OPTION_GROUP . '_section',
+ $name
+ );
+ }
+
+ public function glm_hubspot_settings_init()
+ {
+ register_setting(GLM_HUBSPOT_OPTION_GROUP, GLM_HUBSPOT_SETTINGS);
+ add_filter(
+ 'option_page_capability_' . GLM_HUBSPOT_OPTION_GROUP,
+ array($this, 'glm_hubspot_option_page_capability')
+ );
+ add_settings_section(
+ 'glm_hubspot_' . GLM_HUBSPOT_OPTION_GROUP . '_section',
+ __('Edit Setting', 'wordpress'),
+ array($this, 'glm_hubspot_settings_section_callback'),
+ GLM_HUBSPOT_OPTION_GROUP
+ );
+
+ $fieldNames = array(
+ array(
+ 'name' => 'hapikey',
+ 'label' => 'Hubspot API Key',
+ 'type' => 'text'
+ ),
+ array(
+ 'name' => 'refresh_interval',
+ 'label' => 'Refresh Interval',
+ 'type' => 'text'
+ ),
+ array(
+ 'name' => 'refresh_interval_count',
+ 'label' => 'Refresh Interval Count',
+ 'type' => 'text'
+ ),
+ );
+
+ foreach ($fieldNames as $field) {
+ $this->glm_hubspotAddSettingTextField(
+ $field['name'],
+ $field['label'],
+ $field['type']
+ );
+ }
+ }
+
+ public function glm_hubspotRenderText($fieldName)
+ {
+ static $options;
+ if (!$options) {
+ $options = get_option(GLM_HUBSPOT_SETTINGS);
+ }
+ include $this->path . 'views/text.php';
+ }
+
+ public function glm_hubspotRenderTextArea($fieldName)
+ {
+ static $options;
+ $options = get_option(GLM_HUBSPOT_SETTINGS);
+ include $this->path . 'views/textArea.php';
+ }
+
+ public function glm_hubspot_settings_section_callback()
+ {
+ echo __('HubSpot API Key', 'wordpress');
+ }
+
+ public function glm_hubspot_option_page_capability($capability)
+ {
+ return GLM_HUBSPOT_NEW_CAPABILITY;
+ }
+
+ public function glm_hubspot_options_page()
+ {
+ if (current_user_can(GLM_HUBSPOT_NEW_CAPABILITY)) {
+ include $this->path . 'views/optionsPage.php';
+ } else {
+ include $this->path . 'views/deniedAccess.php';
+ }
+ }
+
+ public function load_stylesheet()
+ {
+ //wp_enqueue_style('client-admin-css',plugins_url('glm-client-info/css/admin/admin.css' , $this->pluginDirName));
+ }
+ public function load_script()
+ {
+ /*
+ wp_register_script(
+ 'client-info-admin-js',
+ plugins_url('glm-client-info/js/admin/admin.js' , $this->pluginDirName),
+ array(),
+ '0.0.1',
+ 'all'
+ );
+ wp_enqueue_script('client-info-admin-js');
+ */
+ }
+}
--- /dev/null
+<?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 GlmHubSpot_Front_controller
+{
+
+ /**
+ * Plugin Path
+ *
+ * @var type String
+ */
+ public $path;
+
+ /**
+ * Initializes Front Controller class
+ *
+ * @param type $path Plugin path
+ */
+ function __construct($path)
+ {
+ $this->path = $path;
+ add_action('widgets_init', array($this, 'glm_hubspot_blog_register_widget'));
+ }
+
+ /**
+ * Register the Client Info Widget with WordPress
+ */
+ function glm_hubspot_blog_register_widget()
+ {
+ include $this->path . 'models/GlmHubSpotBlog_Widget.php';
+ register_widget('GlmHubSpotBlog_Widget');
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Plugin Name: HubSpot Blog
+ * Description: Option Setting for the name address and phone numbers. Includes Widget
+ * Version: 0.0.1
+ * Author: Steve Sutton
+ * Author URI: http://www.gaslightmedia.com
+ * License: All right reserved
+ */
+define('GLM_HUBSPOT_PLUGIN_PATH_FILE', __FILE__);
+define('GLM_HUBSPOT_DB_VERSION', '0.0.1');
+define('GLM_HUBSPOT_DB_VERSION_OPTION_NAME', 'glm_hubspot_db_version');
+define('GLM_HUBSPOT_TABLE', 'glm_hubspot_feed');
+define('GLM_HUBSPOT_SETTINGS', 'glm_hubspot_settings');
+define('GLM_HUBSPOT_OPTION_GROUP', 'glm_hubspot_section');
+define('GLM_HUBSPOT_NEW_CAPABILITY', 'glm_hubspot_edit_client');
+define('GLM_HUBSPOT_BUILT_IN_CAPABILITY', 'edit_posts');
+
+register_activation_hook(__FILE__, array('GlmHubSpot_Admin_Controller', 'activate_plugin'));
+register_deactivation_hook(__FILE__, array('GlmHubSpot_Admin_Controller', 'deactivate_plugin'));
+register_uninstall_hook(__FILE__, array('GlmHubSpot_Admin_Controller', 'glm_hubspot_uninstall'));
+
+if (is_admin()) {
+ // call the Admin Controller to setup the Admin of the plugin
+ require_once 'controllers/Admin.php';
+ $adminController = new GlmHubSpot_Admin_Controller(
+ plugin_dir_path(__FILE__)
+ );
+}
+
+// call the Front Controller to setup the widget
+require_once 'controllers/Front.php';
+$frontController = new GlmHubSpot_Front_controller(
+ plugin_dir_path(__FILE__)
+);
+
+/*
+ * Lead the database class
+ */
+require_once 'models/database.php';
+$hubspot_db = new glm_hubspot_models_database($GLOBALS['wpdb']);
--- /dev/null
+<?php
+
+/**
+ * Glmclientinfo_Widget.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_QuickSite_Widget
+ *
+ * Description of QuickSite_Widget
+ *
+ * @category Toolkit
+ * @package Package
+ * @author Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license Gaslight Media
+ * @release Release: (0.1)
+ * @link <>
+ */
+class GlmHubSpotBlog_Widget
+ extends WP_widget
+{
+
+ private $pluginDirPath;
+ private $hapikey;
+ private $refresh_interval;
+ private $refresh_interval_count;
+
+ /**
+ * Class Initializer
+ */
+ public function __construct()
+ {
+ parent::__construct(
+ 'GlmHubSpotBlog_Widget',
+ __('HubSpot Widget', 'text_domain'),
+ array('description' => __('HubSpot Widget', 'text_domain'))
+ );
+ }
+
+ /**
+ * Output widget
+ *
+ * Includes the template file for the widget.
+ * Template file is plain old php for your fastest template engine yet!
+ *
+ * @param type $args Widget Args
+ * @param type $instance Widget Instance
+ *
+ * @return string
+ */
+ public function widget($args, $instance)
+ {
+ $path = plugin_dir_path(__FILE__);
+ $this->check_for_updates();
+ }
+
+ /**
+ * check_for_updates
+ *
+ * Check to see if we need to refresh the feed from hubspot.
+ * If no settings then do nothing.
+ * If nothing is in the feed table then try to refresh.
+ *
+ * @access public
+ * @return void
+ */
+ public function check_for_updates()
+ {
+ $options = get_option( GLM_HUBSPOT_SETTINGS );
+ if ( !$options ) {
+ return false;
+ }
+ $this->hapikey = $options['hapikey'];
+ $this->refresh_interval = $options['refresh_interval'];
+ $this->refresh_interval_count = $options['refresh_interval_count'];
+
+ echo '<pre>$options: ' . print_r( $options, true ) . '</pre>';
+ //$this->fetch_feed();
+ }
+
+ /**
+ * fetch_feed
+ *
+ * Fetch the hubspot json feed for the latest post.
+ *
+ * @access public
+ * @return void
+ */
+ public function fetch_feed()
+ {
+ // https://api.hubapi.com/content/api/v2/blog-posts?hapikey=demo&limit=1&offset=0&order_by=-publish_date&state=PUBLISHED
+ $feed_url = "https://api.hubapi.com/content/api/v2/blog-posts?hapikey={$this->hapikey}"
+ . '&limit=1&offset=0&order_by=-publish_date&state=PUBLISHED';
+ $response = wp_remote_get( esc_url_raw( $feed_url ) );
+ //echo '<pre>$response: ' . print_r( $response, true ) . '</pre>';
+ $response_code = wp_remote_retrieve_response_code( $response );
+ echo '<pre>$response_code: ' . print_r( $response_code, true ) . '</pre>';
+ if ( $response_code === 200 ) {
+ $api_response = json_decode( wp_remote_retrieve_body( $response) );
+ echo '<pre>$api_response: ' . print_r( $api_response, true ) . '</pre>';
+ }
+ }
+
+ /**
+ * update_feed_data
+ *
+ * Store the feed data
+ *
+ * @param mixed JSON data from hubspot
+ *
+ * @access public
+ * @return void
+ */
+ public function update_feed_data( $feedData )
+ {
+ }
+
+ /**
+ * Return the quicksite option for the given key
+ *
+ * @param type $name Name of the quicksite option to return
+ *
+ * @return string Option
+ */
+ function glm_get_clientinfo_option($name)
+ {
+ $settings = get_option('glmclientinfo_settings');
+ $states = get_option('glmclientinfo_states');
+ if ($name == 'stateFull' && $settings['state']) {
+ return $states[$settings['state']];
+ }
+ if ($name == 'state2Full' && $settings['state2']) {
+ return $states[$settings['state2']];
+ }
+ return ($settings && $settings[$name])
+ ? $settings[$name]
+ : null;
+ }
+
+}
--- /dev/null
+<?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_hubspot_models_database
+{
+ public $wpdb;
+ public $applicationTable;
+ public $appFormTable;
+
+ /**
+ * Clas 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->hubspot_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->hubspot_table} (
+ id BIGINT(20) NOT NULL AUTO_INCREMENT,
+ create_time DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL,
+ feed_data 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();
+ }
+ }
+
+}
--- /dev/null
+<div class="wrap"><p>You do not have permission!</p></div>
--- /dev/null
+<div class="wrap">
+ <form action="options.php" method="post">
+ <h1>HubSpot API Key</h1>
+ <div id="glm-client-info-wrapper" class="row">
+ <?php
+ settings_fields(GLM_HUBSPOT_OPTION_GROUP);
+ do_settings_sections(GLM_HUBSPOT_OPTION_GROUP);
+ ?>
+ <div style="clear: both; text-align: center;">
+ <?php submit_button();?>
+ </div>
+ </div>
+ </form>
+</div>
--- /dev/null
+<input type="text" name="<?php echo GLM_HUBSPOT_SETTINGS;?>[<?php echo $fieldName;?>]"
+ value="<?php echo str_replace('"', '"e;', $options[$fieldName]); ?>">
--- /dev/null
+<textarea cols="40" rows="5" name="<?php echo GLM_HUBSPOT_SETTINGS;?>[<?php echo $fieldName;?>]"><?php echo htmlspecialchars($options[$fieldName]); ?></textarea>