initial commit
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 19 Nov 2014 21:49:24 +0000 (16:49 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 19 Nov 2014 21:49:24 +0000 (16:49 -0500)
controllers/Admin.php [new file with mode: 0644]
controllers/Front.php [new file with mode: 0644]
index.php [new file with mode: 0644]
models/PrestonInfoWidget.php [new file with mode: 0644]
views/deniedAccess.php [new file with mode: 0644]
views/hours.php [new file with mode: 0644]
views/optionsPage.php [new file with mode: 0644]
views/stateSelect.php [new file with mode: 0644]
views/text.php [new file with mode: 0644]
views/textArea.php [new file with mode: 0644]
views/vCard.php [new file with mode: 0644]

diff --git a/controllers/Admin.php b/controllers/Admin.php
new file mode 100644 (file)
index 0000000..610d9d0
--- /dev/null
@@ -0,0 +1,345 @@
+<?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 Preston_Info_Admin_Controller
+{
+    public $path;
+
+    public function __construct($path)
+    {
+        $this->path = $path;
+        add_action('admin_menu', array($this, 'prestonclientinfo_add_admin_menu'));
+        add_action('admin_init', array($this, 'prestonclientinfo_settings_init'));
+
+    }
+
+    static public function activate_plugin()
+    {
+        Preston_Info_Admin_Controller::add_capability();
+        Preston_Info_Admin_Controller::glm_add_state_list_option();
+    }
+
+    static public function deactivate_plugin()
+    {
+        Preston_Info_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(PF_BUILT_IN_CAPABILITY)) {
+                $role->add_cap(GLM_PRESTON_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_PRESTON_CAPABILITY)) {
+                $role->remove_cap(GLM_PRESTON_CAPABILITY);
+            }
+        }
+    }
+
+    static public function prestonclientinfo_uninstall()
+    {
+        delete_option(GLM_PRESTONINFO_SETTINGS);
+        delete_option(GLM_PRESTONINFO_STATES);
+    }
+
+    static public function glm_add_state_list_option()
+    {
+        //echo 'called glm_add_state_list_option';
+        if (get_option(GLM_PRESTONINFO_STATES)) {
+            delete_option(GLM_PRESTONINFO_STATES);
+        }
+        // [status_US] array of states and their abbr.
+        $states_US['']   = '-- Select --'; // {{{
+        $states_US['AL'] = 'Alabama';
+        $states_US['AK'] = 'Alaska';
+        $states_US['AZ'] = 'Arizona';
+        $states_US['AR'] = 'Arkansas';
+        $states_US['CA'] = 'California';
+        $states_US['CO'] = 'Colorado';
+        $states_US['CT'] = 'Connecticut';
+        $states_US['DE'] = 'Delaware';
+        $states_US['DC'] = 'District of Columbia';
+        $states_US['FL'] = 'Florida';
+        $states_US['GA'] = 'Georgia';
+        $states_US['HI'] = 'Hawaii';
+        $states_US['ID'] = 'Idaho';
+        $states_US['IL'] = 'Illinois';
+        $states_US['IN'] = 'Indiana';
+        $states_US['IA'] = 'Iowa';
+        $states_US['KS'] = 'Kansas';
+        $states_US['KY'] = 'Kentucky';
+        $states_US['LA'] = 'Louisiana';
+        $states_US['ME'] = 'Maine';
+        $states_US['MD'] = 'Maryland';
+        $states_US['MA'] = 'Massachusetts';
+        $states_US['MI'] = 'Michigan';
+        $states_US['MN'] = 'Minnesota';
+        $states_US['MS'] = 'Mississippi';
+        $states_US['MO'] = 'Missouri';
+        $states_US['MT'] = 'Montana';
+        $states_US['NE'] = 'Nebraska';
+        $states_US['NV'] = 'Nevada';
+        $states_US['NH'] = 'New Hampshire';
+        $states_US['NJ'] = 'New Jersey';
+        $states_US['NM'] = 'New Mexico';
+        $states_US['NY'] = 'New York';
+        $states_US['NC'] = 'North Carolina';
+        $states_US['ND'] = 'North Dakota';
+        $states_US['OH'] = 'Ohio';
+        $states_US['OK'] = 'Oklahoma';
+        $states_US['OR'] = 'Oregon';
+        $states_US['PA'] = 'Pennsylvania';
+        $states_US['RI'] = 'Rhode Island';
+        $states_US['SC'] = 'South Carolina';
+        $states_US['SD'] = 'South Dakota';
+        $states_US['TN'] = 'Tennessee';
+        $states_US['TX'] = 'Texas';
+        $states_US['UT'] = 'Utah';
+        $states_US['VT'] = 'Vermont';
+        $states_US['VA'] = 'Virginia';
+        $states_US['WA'] = 'Washington';
+        $states_US['WV'] = 'West Virginia';
+        $states_US['WI'] = 'Wisconsin';
+        $states_US['WY'] = 'Wyoming'; // }}}
+        // [states] extended states array
+        $states['AB']    = 'Alberta'; // {{{
+        $states['AS']    = 'American Samoa';
+        $states['BC']    = 'British Columbia';
+        $states['DC']    = 'District of Columbia';
+        $states['FM']    = 'Federated States of Micronesia';
+        $states['GU']    = 'Guam';
+        $states['MB']    = 'Manitoba';
+        $states['MH']    = 'Marshall Islands';
+        $states['NB']    = 'New Brunswick';
+        $states['NF']    = 'Newfoundland';
+        $states['MP']    = 'Northern Mariana Islands';
+        $states['NT']    = 'Northwest Territories';
+        $states['NS']    = 'Nova Scotia';
+        $states['ON']    = 'Ontario';
+        $states['PW']    = 'Palau';
+        $states['PE']    = 'Prince Edward Island';
+        $states['PR']    = 'Puerto Rico';
+        $states['QC']    = 'Quebec';
+        $states['SK']    = 'Saskatchewan';
+        $states['VI']    = 'Virgin Islands';
+        $states['YT']    = 'Yukon'; // }}}
+        //  Merge the 50 US states together with some of the extended
+        //  provinces / territories and then sort them on their keys
+        //  Then add the remaining countries and areas at the end
+        //  of the array.
+        $states          = $states_US + $states;
+        ksort($states);
+        add_option(GLM_PRESTONINFO_STATES, $states);
+        //echo 'called add_option';
+    }
+
+    public function prestonclientinfo_add_admin_menu()
+    {
+        add_menu_page(
+            'Locations',
+            'Locations',
+            GLM_PRESTON_CAPABILITY,
+            'prestonclientinfo',
+            array($this, 'prestonclientinfo_options_page'),
+            'dashicons-id'
+        );
+    }
+
+    public function prestonclientinfo_settings_exist()
+    {
+        if (false == get_option(GLM_PRESTONINFO_SETTINGS)) {
+            add_option(GLM_PRESTONINFO_SETTINGS);
+        }
+    }
+
+    public function prestonclientinfoAddSettingTextField($name, $label, $type)
+    {
+        switch ($type) {
+            case 'text':
+                $callback = 'prestonclientinfoRenderText';
+                break;
+            case 'hours':
+                $callback = 'prestonclientinfoRenderHours';
+                break;
+            case 'textarea':
+                $callback = 'prestonclientinfoRenderTextArea';
+                break;
+            case 'state':
+                $callback = 'prestonclientinfoRenderStateSelect';
+                break;
+            default:
+                return false;
+                break;
+        }
+        add_settings_field(
+            $name,
+            __($label, 'wordpress'),
+            array($this, $callback),
+            'pluginPage',
+            'prestonclientinfo_pluginPage_section',
+            $name
+        );
+    }
+
+    public function prestonclientinfo_settings_init()
+    {
+        register_setting('pluginPage', 'prestonclientinfo_settings');
+        add_filter('option_page_capability_pluginPage',
+                   'prestonclientinfo_option_page_capability');
+
+        add_settings_section(
+            'prestonclientinfo_pluginPage_section',
+            __('Edit your Locations', 'wordpress'),
+            array($this, 'prestonclientinfo_settings_section_callback'),
+            'pluginPage'
+        );
+        $fieldNames = array();
+        for ($i = 1; $i <= 4; ++$i) {
+            $fieldNames[] = array(
+                'name'  => 'location' . $i,
+                'label' => 'Location '. $i,
+                'type'  => 'text'
+            );
+            $fieldNames[] = array(
+                'name'  => 'address' . $i,
+                'label' => 'Address',
+                'type'  => 'text'
+            );
+            $fieldNames[] = array(
+                'name'  => 'city' . $i,
+                'label' => 'City',
+                'type'  => 'text'
+            );
+            $fieldNames[] = array(
+                'name'  => 'state' . $i,
+                'label' => 'State',
+                'type'  => 'state'
+            );
+            $fieldNames[] = array(
+                'name'  => 'zip' . $i,
+                'label' => 'Zip',
+                'type'  => 'text'
+            );
+            $fieldNames[] = array(
+                'name'  => 'phone' . $i,
+                'label' => 'Phone',
+                'type'  => 'text'
+            );
+            $fieldNames[] = array(
+                'name'  => 'tfree' . $i,
+                'label' => 'Toll Free',
+                'type'  => 'text'
+            );
+            $fieldNames[] = array(
+                'name'  => 'hours' . $i. 'a',
+                'label' => 'Hours',
+                'type'  => 'hours'
+            );
+            $fieldNames[] = array(
+                'name'  => 'hours' . $i . 'b',
+                'label' => 'Hours',
+                'type'  => 'hours'
+            );
+            $fieldNames[] = array(
+                'name'  => 'hours' . $i . 'c',
+                'label' => 'Hours',
+                'type'  => 'hours'
+            );
+        }
+
+        foreach ($fieldNames as $field) {
+            $this->prestonclientinfoAddSettingTextField(
+                $field['name'],
+                $field['label'],
+                $field['type']
+            );
+        }
+    }
+
+    public function prestonclientinfoRenderText($fieldName)
+    {
+        static $options;
+        if (!$options) {
+            $options = get_option(GLM_PRESTONINFO_SETTINGS);
+        }
+        include $this->path . 'views/text.php';
+    }
+
+    public function prestonclientinfoRenderHours($fieldName)
+    {
+        static $options;
+        if (!$options) {
+            $options = get_option(GLM_PRESTONINFO_SETTINGS);
+        }
+        include $this->path . 'views/hours.php';
+    }
+
+    public function prestonclientinfoRenderTextArea($fieldName)
+    {
+        static $options;
+        $options = get_option(GLM_PRESTONINFO_SETTINGS);
+        include $this->path . 'views/textArea.php';
+    }
+
+    public function prestonclientinfoRenderStateSelect($fieldName)
+    {
+        static $options;
+        $options = get_option(GLM_PRESTONINFO_SETTINGS);
+        $states  = get_option(GLM_PRESTONINFO_STATES);
+        include $this->path . 'views/stateSelect.php';
+    }
+
+    public function prestonclientinfo_settings_section_callback()
+    {
+        echo __('4 Locations', 'wordpress');
+    }
+
+    public function prestonclientinfo_option_page_capability($capability)
+    {
+        return GLM_PRESTON_CAPABILITY;
+    }
+
+    public function prestonclientinfo_options_page()
+    {
+        if (current_user_can(GLM_PRESTON_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..5882177
--- /dev/null
@@ -0,0 +1,60 @@
+<?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 Preston_Info_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, 'prestonclientinfo_register_widget'));
+    }
+
+    /**
+     * Register the Client Info Widget with WordPress
+     */
+    function prestonclientinfo_register_widget()
+    {
+        include $this->path . 'models/PrestonInfoWidget.php';
+        register_widget('PrestonInfoWidget');
+    }
+
+}
diff --git a/index.php b/index.php
new file mode 100644 (file)
index 0000000..151b4c9
--- /dev/null
+++ b/index.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Plugin Name: Preston Feather Locations
+ * Description: Option Setting for the name address and phone numbers. Includes Widget
+ * Version: 1.1
+ * Author: Steve Sutton
+ * Author URI: http://www.gaslightmedia.com
+ * License: All right reserved
+ */
+define('GLM_PRESTONINFO_SETTINGS', 'prestonclientinfo_settings');
+define('GLM_PRESTONINFO_STATES', 'prestonclientinfo_states');
+define('GLM_PRESTON_CAPABILITY', 'prestonclientinfo_edit_client');
+define('PF_BUILT_IN_CAPABILITY', 'edit_posts');
+
+register_activation_hook(__FILE__, array('Preston_Info_Admin_Controller', 'activate_plugin'));
+register_deactivation_hook(__FILE__, array('Preston_Info_Admin_Controller', 'deactivate_plugin'));
+register_uninstall_hook(__FILE__, array('Preston_Info_Admin_Controller', 'prestonclientinfo_uninstall'));
+
+if (is_admin()) {
+    // call the Admin Controller to setup the Admin of the plugin
+    require_once 'controllers/Admin.php';
+    $adminController = new Preston_Info_Admin_Controller(
+        plugin_dir_path(__FILE__)
+    );
+}
+
+// call the Front Controller to setup the widget
+require_once 'controllers/Front.php';
+$frontController = new Preston_Info_Front_controller(
+    plugin_dir_path(__FILE__)
+);
diff --git a/models/PrestonInfoWidget.php b/models/PrestonInfoWidget.php
new file mode 100644 (file)
index 0000000..43b3bc8
--- /dev/null
@@ -0,0 +1,88 @@
+<?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 PrestonInfoWidget
+    extends WP_widget
+{
+
+    private $pluginDirPath;
+
+    /**
+     * Class Initializer
+     */
+    public function __construct()
+    {
+        parent::__construct(
+            'PrestonInfoWidget',
+            __('Locations Info Widget', 'text_domain'),
+            array('description' => __('Locations 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__);
+        include $path . '../views/vCard.php';
+    }
+
+    /**
+     * Return the quicksite option for the given key
+     *
+     * @param type $name Name of the quicksite option to return
+     *
+     * @return string Option
+     */
+    function show_option($name, $key)
+    {
+        $settings = get_option('prestonclientinfo_settings');
+        $states   = get_option('prestonclientinfo_states');
+        if ($key) {
+            return ($settings[$name][$key])
+                ? $settings[$name][$key]
+                : null;
+        } else {
+            return ($settings && $settings[$name])
+                ? $settings[$name]
+                : null;
+        }
+
+    }
+
+}
diff --git a/views/deniedAccess.php b/views/deniedAccess.php
new file mode 100644 (file)
index 0000000..d8b6753
--- /dev/null
@@ -0,0 +1 @@
+<div class="wrap"><p>You do not have permission to edit Client Info</p></div>
\ No newline at end of file
diff --git a/views/hours.php b/views/hours.php
new file mode 100644 (file)
index 0000000..b74633a
--- /dev/null
@@ -0,0 +1,10 @@
+Days:
+<input type="text" name="prestonclientinfo_settings[<?php echo $fieldName;?>][days]"
+           value="<?php echo str_replace('"', '&quote;', $options[$fieldName]['days']); ?>">
+Times:
+<input type="text" size="50" name="prestonclientinfo_settings[<?php echo $fieldName;?>][times]"
+           value="<?php echo str_replace('"', '&quote;', $options[$fieldName]['times']); ?>">
+
+<?php
+//echo '<pre>'.print_r($options, true).'</pre>';
+?>
\ No newline at end of file
diff --git a/views/optionsPage.php b/views/optionsPage.php
new file mode 100644 (file)
index 0000000..87c657f
--- /dev/null
@@ -0,0 +1,10 @@
+<div class="wrap">
+    <form action="options.php" method="post">
+        <h2>Preston Feather Locations</h2>
+        <?php
+            settings_fields('pluginPage');
+            do_settings_sections('pluginPage');
+            submit_button();
+        ?>
+    </form>
+</div>
\ No newline at end of file
diff --git a/views/stateSelect.php b/views/stateSelect.php
new file mode 100644 (file)
index 0000000..7fd6efe
--- /dev/null
@@ -0,0 +1,9 @@
+<select name="prestonclientinfo_settings[<?php echo $fieldName; ?>]">
+    <?php if (!empty($states)) : foreach ($states as $stateAbbr => $stateName) : ?>
+        <option value="<?php echo $stateAbbr; ?>"<?php if ($options[$fieldName] == $stateAbbr) {
+        echo ' selected';
+    }; ?>>
+        <?php echo $stateName; ?>
+        </option>
+<?php endforeach; endif;?>
+</select>
\ No newline at end of file
diff --git a/views/text.php b/views/text.php
new file mode 100644 (file)
index 0000000..2d854aa
--- /dev/null
@@ -0,0 +1,2 @@
+<input type="text" name="prestonclientinfo_settings[<?php echo $fieldName;?>]"
+           value="<?php echo str_replace('"', '&quote;', $options[$fieldName]); ?>">
\ No newline at end of file
diff --git a/views/textArea.php b/views/textArea.php
new file mode 100644 (file)
index 0000000..05059ef
--- /dev/null
@@ -0,0 +1 @@
+<textarea cols="40" rows="5" name="prestonclientinfo_settings[<?php echo $fieldName;?>]"><?php echo htmlspecialchars($options[$fieldName]); ?></textarea>
\ No newline at end of file
diff --git a/views/vCard.php b/views/vCard.php
new file mode 100644 (file)
index 0000000..52f582d
--- /dev/null
@@ -0,0 +1,29 @@
+<?php for ($i = 1; $i <= 4; ++$i):?>
+<div class="small-12 medium-3 columns">
+    <div class="center">
+        <h3><?php echo $this->show_option('location' . $i);?></h3>
+        <p><?php echo $this->show_option('address' . $i);?></p>
+        <p><?php echo $this->show_option('city' . $i);?>, <?php echo $this->show_option('state' . $i);?> <?php echo $this->show_option('zip' . $i);?></p>
+        <p><?php echo $this->show_option('phone' . $i);?>
+            <?php if($this->show_option('tfree' . $i)):?>&sdot; <?php echo $this->show_option('tfree' . $i);?><?php endif;?></p>
+        <?php if ($this->show_option('hours' . $i . 'a', 'days')):?>
+            <p class="day"><?php echo nl2br($this->show_option('hours' . $i . 'a', 'days'));?></p>
+        <?php endif;?>
+        <?php if ($this->show_option('hours' . $i . 'a', 'times')):?>
+            <p class="time"><?php echo nl2br($this->show_option('hours' . $i . 'a', 'times'));?></p>
+        <?php endif;?>
+        <?php if ($this->show_option('hours' . $i . 'b', 'days')):?>
+            <p class="day"><?php echo nl2br($this->show_option('hours' . $i . 'b', 'days'));?></p>
+        <?php endif;?>
+        <?php if ($this->show_option('hours' . $i . 'b', 'times')):?>
+            <p class="time"><?php echo nl2br($this->show_option('hours' . $i . 'b', 'times'));?></p>
+        <?php endif;?>
+        <?php if ($this->show_option('hours' . $i . 'c', 'days')):?>
+            <p class="day"><?php echo nl2br($this->show_option('hours' . $i . 'c', 'days'));?></p>
+        <?php endif;?>
+        <?php if ($this->show_option('hours' . $i . 'c', 'times')):?>
+            <p class="time"><?php echo nl2br($this->show_option('hours' . $i . 'c', 'times'));?></p>
+        <?php endif;?>
+    </div>
+</div>
+<?php endfor;?>