From 07d000c6b3036c6f4d15402bb1f6bf47631b7805 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 3 Jun 2015 13:07:30 -0400 Subject: [PATCH] Create client info plugin for toski sands --- controllers/Admin.php | 325 +++++++++++++++++++++++++++++++++++++++++ controllers/Front.php | 60 ++++++++ index.php | 38 +++++ views/deniedAccess.php | 1 + views/optionsPage.php | 10 ++ views/stateSelect.php | 9 ++ views/text.php | 2 + views/textArea.php | 1 + 8 files changed, 446 insertions(+) create mode 100644 controllers/Admin.php create mode 100644 controllers/Front.php create mode 100644 index.php create mode 100644 views/deniedAccess.php create mode 100644 views/optionsPage.php create mode 100644 views/stateSelect.php create mode 100644 views/text.php create mode 100644 views/textArea.php diff --git a/controllers/Admin.php b/controllers/Admin.php new file mode 100644 index 0000000..9a9f441 --- /dev/null +++ b/controllers/Admin.php @@ -0,0 +1,325 @@ + + * @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 + * @copyright 2013 Gaslight Media + * @license Gaslight Media + * @release Release: (0.1) + * @link <> + */ +class Toskiclientinfo_Admin_Controller +{ + public $path; + + public function __construct($path) + { + $this->path = $path; + add_action('admin_menu', array($this, 'toskiclientinfo_add_admin_menu')); + add_action('admin_init', array($this, 'toskiclientinfo_settings_init')); + + } + + static public function activate_plugin() + { + Toskiclientinfo_Admin_Controller::add_capability(); + Toskiclientinfo_Admin_Controller::glm_add_state_list_option(); + } + + static public function deactivate_plugin() + { + Toskiclientinfo_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(BUILT_IN_CAPABILITY)) { + $role->add_cap(TOSKI_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(TOSKI_NEW_CAPABILITY)) { + $role->remove_cap(TOSKI_NEW_CAPABILITY); + } + } + } + + static public function toskiclientinfo_uninstall() + { + delete_option(TOSKI_CLIENTINFO_SETTINGS); + delete_option(TOSKI_CLEINTINFO_STATES); + } + + static public function glm_add_state_list_option() + { + //echo 'called glm_add_state_list_option'; + if (get_option(TOSKI_CLEINTINFO_STATES)) { + delete_option(TOSKI_CLEINTINFO_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(TOSKI_CLEINTINFO_STATES, $states); + //echo 'called add_option'; + } + + public function toskiclientinfo_add_admin_menu() + { + add_menu_page( + 'Toski Sands Info', + 'Toski Sands Info', + TOSKI_NEW_CAPABILITY, + 'toskiclientinfo', + array($this, 'toskiclientinfo_options_page'), + 'dashicons-id' + ); + } + + public function toskiclientinfo_settings_exist() + { + if (false == get_option(TOSKI_CLIENTINFO_SETTINGS)) { + add_option(TOSKI_CLIENTINFO_SETTINGS); + } + } + + public function toskiclientinfoAddSettingTextField($name, $label, $type) + { + switch ($type) { + case 'text': + $callback = 'toskiclientinfoRenderText'; + break; + case 'textarea': + $callback = 'toskiclientinfoRenderTextArea'; + break; + case 'state': + $callback = 'toskiclientinfoRenderStateSelect'; + break; + default: + return false; + break; + } + add_settings_field( + $name, + __($label, 'wordpress'), + array($this, $callback), + 'pluginPage', + 'toskiclientinfo_pluginPage_section', + $name + ); + } + + public function toskiclientinfo_settings_init() + { + register_setting('pluginPage', 'toskiclientinfo_settings'); + add_filter( + 'option_page_capability_pluginPage', + array($this, 'toskiclientinfo_option_page_capability') + ); + + add_settings_section( + 'toskiclientinfo_pluginPage_section', + __('Edit your Client Info', 'wordpress'), + array($this, 'toskiclientinfo_settings_section_callback'), + 'pluginPage' + ); + + $fieldNames = array( + array( + 'name' => 'businessName', + 'label' => 'Business Name', + 'type' => 'text' + ), + array( + 'name' => 'address', + 'label' => 'Address', + 'type' => 'text' + ), + array( + 'name' => 'city', + 'label' => 'City', + 'type' => 'text' + ), + array( + 'name' => 'state', + 'label' => 'State', + 'type' => 'state' + ), + array( + 'name' => 'zip', + 'label' => 'Zip', + 'type' => 'text' + ), + array( + 'name' => 'market', + 'label' => 'Market', + 'type' => 'text' + ), + array( + 'name' => 'party_store', + 'label' => 'Party', + 'type' => 'text' + ), + array( + 'name' => 'fax', + 'label' => 'Fax', + 'type' => 'text' + ), + ); + + foreach ($fieldNames as $field) { + $this->toskiclientinfoAddSettingTextField( + $field['name'], + $field['label'], + $field['type'] + ); + } + } + + public function toskiclientinfoRenderText($fieldName) + { + static $options; + if (!$options) { + $options = get_option(TOSKI_CLIENTINFO_SETTINGS); + } + include $this->path . 'views/text.php'; + } + + public function toskiclientinfoRenderTextArea($fieldName) + { + static $options; + $options = get_option(TOSKI_CLIENTINFO_SETTINGS); + include $this->path . 'views/textArea.php'; + } + + public function toskiclientinfoRenderStateSelect($fieldName) + { + static $options; + $options = get_option(TOSKI_CLIENTINFO_SETTINGS); + $states = get_option(TOSKI_CLEINTINFO_STATES); + include $this->path . 'views/stateSelect.php'; + } + + public function toskiclientinfo_settings_section_callback() + { + echo __('Business Name, Address and phone numbers', 'wordpress'); + } + + public function toskiclientinfo_option_page_capability($capability) + { + return TOSKI_NEW_CAPABILITY; + } + + public function toskiclientinfo_options_page() + { + if (current_user_can(TOSKI_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 index 0000000..5cff1a7 --- /dev/null +++ b/controllers/Front.php @@ -0,0 +1,60 @@ + + * @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 + * @copyright 2013 Gaslight Media + * @license Gaslight Media + * @release Release: (0.1) + * @link <> + */ +class Glmclientinfo_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, 'glmclientinfo_register_widget')); + } + + /** + * Register the Client Info Widget with WordPress + */ + function glmclientinfo_register_widget() + { + include $this->path . 'models/Glmclientinfo_Widget.php'; + register_widget('Glmclientinfo_Widget'); + } + +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..068ef35 --- /dev/null +++ b/index.php @@ -0,0 +1,38 @@ +

You do not have permission to edit Client Info

\ No newline at end of file diff --git a/views/optionsPage.php b/views/optionsPage.php new file mode 100644 index 0000000..3a8a97c --- /dev/null +++ b/views/optionsPage.php @@ -0,0 +1,10 @@ +
+
+

Toski Sands Info

+ +
+
diff --git a/views/stateSelect.php b/views/stateSelect.php new file mode 100644 index 0000000..5b534a3 --- /dev/null +++ b/views/stateSelect.php @@ -0,0 +1,9 @@ + diff --git a/views/text.php b/views/text.php new file mode 100644 index 0000000..a47b707 --- /dev/null +++ b/views/text.php @@ -0,0 +1,2 @@ +"> diff --git a/views/textArea.php b/views/textArea.php new file mode 100644 index 0000000..ac98ce4 --- /dev/null +++ b/views/textArea.php @@ -0,0 +1 @@ + -- 2.17.1