From: Chuck Scott Date: Mon, 19 Jan 2015 16:46:20 +0000 (-0500) Subject: Fixed problem with script name missing from base url in some situations. X-Git-Tag: v1.0.0~78 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d78b83f658d085c72f2cb9f456835103f6245fdd;p=WP-Plugins%2Fglm-member-db.git Fixed problem with script name missing from base url in some situations. --- diff --git a/controllers/admin.php b/controllers/admin.php index 56833264..293a282a 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -136,7 +136,6 @@ class glmMembersAdmin extends GlmPluginSupport * @access public */ public $wpdb; - /** * Plugin Configuration Data * @@ -169,8 +168,8 @@ class glmMembersAdmin extends GlmPluginSupport /* * Check if there's a request to bypass the WordPress Dashboard and - * display - * directly to the browser using a specified menuItem/action. + * display directly to the browser using a specified + * menuItem/action. * */ if (isset($_REQUEST['glm_display_direct']) && @@ -361,6 +360,16 @@ class glmMembersAdmin extends GlmPluginSupport $errorMsg = ''; if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + + // Get all defiend constants then if not VERBOSE select out only user contstants + $consts = get_defined_constants(true); + if (!GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + $consts = $consts['user']; + } else { + $this->addNotice("
".print_r($_SERVER,1)."
", "Server Defines"); + } + + $this->addNotice("
".print_r($consts,1)."
", "Defined Parameters"); $this->addNotice("
".print_r($_REQUEST,1)."
", "Request Data"); } diff --git a/controllers/front.php b/controllers/front.php index 73e63059..9dc68e7b 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -10,15 +10,39 @@ * @package glmMembersDatabase * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @release front.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ * @link http://dev.gaslightmedia.com/ */ +/** + * Array of valid menu items and actions. + * + * + * The higher level elements are valid menu items. These correlate to + * actual menu or sub menu items that are hooks back to this controller + * class. + * + * The lower level items below each menu item are actions that may be specified + * by a "glmMembersAction" form field. + */ +$GLOBALS['glmMembersFrontValidActions'] = array( + + 'members' => array( + 'index', // member list + 'list', + 'reports', + 'other' + ) +); + +// Load glmPluginSupport class +require_once (GLM_MEMBERS_PLUGIN_DIR . '/classes/glmPluginSupport.php'); + /* * This class controls which models are use for front-end functionality * of this plugin. */ -class glmMembersFront +class glmMembersFront extends GlmPluginSupport { /** @@ -29,16 +53,335 @@ class glmMembersFront */ public $wpdb; - public function __construct ($wpdb) + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + public function __construct ($wpdb, $config) { // Save WordPress Database object $this->wpdb = $wpdb; + // Save plugin configuration object + $this->config = $config; + + // Add front-end scripts and css + add_action('front_enqueue_scripts', + array( + $this, + 'glmMembersFrontScripts' + )); + + add_shortcode('glm-members', + array( + $this, + 'controller' + )); + } + + /** + * Setup inclusion of front-end scripts and css + * + * This method is called by an add_action() hook setup in the contructor. + * + * (no prameters) + * + * @return void + * @access public + */ + public function glmMembersFrontScripts () + { + /* - * This plugin does not currently have front-end functionality + * + * wp_enqueue_script('jquery'); + * wp_enqueue_script('jquery-style'); + * wp_enqueue_script('jquery-ui-core'); + * wp_enqueue_script('jquery-ui-dialog'); + * + * wp_register_script('glm-members-front-js', + * GLM_MEMBERS_PLUGIN_URL . 'js/front.js', + * array( + * 'jquery' + * )); + * wp_enqueue_script('glm-members-front-js'); */ + + // A simple set of styles for things I haven't found as a WordPress + // default yet + wp_register_style('glmMembersFrontStyle', + GLM_MEMBERS_PLUGIN_URL . 'css/front.css'); + wp_enqueue_style('glmMembersFrontStyle'); } -} + /** + * Front-End controller + * + * This method is called by a plugin menu method. It is responsible for + * executing the approriate model, combining model data with a view, and + * outputing the result. It is therefore the core of the controller. + * + * This controller is supplied a menu item name and then determines if + * there is an additional action related to that menu item that needs to be + * executed rather than the default menu action. + * + * All models should return an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * For a better explanation of how this all works, see the description for + * this class. + * + * Controller parameters + * + * @param object $atts + * Shortcode attributes + * @param string $content + * Content included by an Enclosing format shortcode + * + * @return void + * @access public + */ + public function controller ($atts, $content = null) + { + // Shortcode Attributes defaults + $request = shortcode_atts( + array( + 'action' => 'list', + 'option' => false + ), $atts); + + + + + + + + $errorMsg = ''; + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + + // Get all defiend constants then if not VERBOSE select out only user contstants + $consts = get_defined_constants(true); + if (!GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + $consts = $consts['user']; + } + + $this->addNotice("
".print_r($consts,1)."
", "Defined Parameters"); + $this->addNotice("
".print_r($_REQUEST,1)."
", "Request Data"); + } + + /* + * Determine model to execute + */ + + // Default action is "index" + $action = 'index'; + + // Get any requested "action" from a form submission modify path/name + // accordingly + if (isset($_REQUEST['glm_action']) && $_REQUEST['glm_action'] != '') { + $a = sanitize_text_field($_REQUEST['glm_action']); + if ($a != '') { + $action = $a; + } + } + + // Loop till we have a final action + $loopCheck = 0; + $redirectData = false; + do { + + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) { + $this->addNotice( + "Requested Action: Menu item = $menuItem, Action = $action"); + } + + $modelRedirect = false; + + // Verify that we have the requested menu item in the valid actions + if (! isset($GLOBALS['glmMembersFrontValidActions'][$menuItem])) { + + $modelRedirect = true; + $menuItem = 'error'; + $action = 'index'; + $errorMsg .= "Model doesn't exist: " . $modelName; + } + + // Verify Menu item and action using array at top of this file + if (! isset($GLOBALS['glmMembersFrontValidActions'][$menuItem]) || + ! in_array($action, + $GLOBALS['glmMembersFrontValidActions'][$menuItem])) { + $menuItem = 'error'; + $action = 'badAction'; + } + + /* + * Execute the selected model + */ + + // Build model and path and class names + $modelName = GLM_MEMBERS_PLUGIN_DIR . '/models/front/' . $menuItem . + '/' . $action . '.php'; + $className = 'GlmMembersFront_' . $menuItem . '_' . $action; + + // If model file doesn't exist - we have an error + if (! file_exists($modelName)) { + + $modelRedirect = true; + $menuItem = 'error'; + $action = 'index'; + $errorMsg .= "Model doesn't exist: " . $modelName; + + // Otherwise, load and run the model + } else { + + // Load the model file + require_once ($modelName); + + // check for an invalid model class name + if (! class_exists($className)) { + + $modelRedirect = true; + $menuItem = 'error'; + $action = 'index'; + $errorMsg .= "Model class doesn't exist: " . + $className; + } else { + + // Check if this is a re-direct with parameters + $args = false; + + // Instantiate the model and ask it to perform the work + $model = new $className($this->wpdb, $this->config); + $results = $model->modelAction($redirectData); + + // Check if there's been a model redirect request + if ($results['modelRedirect']) { + + // Set the new model action + $action = $results['modelRedirect']; + + // Check if there's also a menu item change + if ($results['menuItemRedirect']) { + $menuItem = $results['menuItemRedirect']; + } + + // Check if there's data to pass to the new model + if (isset($results['data']) && + count($results['data']) > 0) { + $redirectData = $results['data']; + } + + $modelRedirect = true; + } + + // Get the specified view file + $view = false; + if (isset($results['view'])) { + $view = $results['view']; + } + + // Check for invalid or missing view file + if (! $view || ! is_file( + GLM_MEMBERS_PLUGIN_DIR . '/views/' . $view)) { + $modelRedirect = true; + $menuItem = 'error'; + $action = 'index'; + $errorMsg .= "Bad or missing view file: " . $view; + } + } // model class exists + } + + // This is just a sanity check on this loop to keep it from getting + // out of control + if (++ $loopCheck > 10) { + die( + '

Serious failure looping on model load in "controllers/front.php".

'); + } + + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG && $modelRedirect) { + $this->addNotice('Redirecting...'); + } + + // Loop again if there's a model redirect + } while ($modelRedirect); + + /* + * Check model results + */ + + // Get suggested view + $view = $results['view']; + + // If there's a general model failure use the error view + if (! $results['status']) { + $view = 'front/error/index.html'; + } + + /* + * Merge data returned from the model with the selected view + */ + + // Load Smarty Template support + require (GLM_MEMBERS_PLUGIN_DIR . '/lib/smartyTemplateSupport.php'); + $smarty = new smartyTemplateSupport(); + + // Add data from model to Smarty template + if (is_array($results['data']) && count($results['data']) > 0) { + foreach ($results['data'] as $k => $d) { + $smarty->templateAssign($k, $d); + } + } + + $smarty->templateAssign('thisAction', $action); + + // If there's an error message, add that also + if ($errorMsg != '') { + $smarty->templateAssign('errorMsg', $errorMsg); + } + + // If view debug has been requested + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) { + + glmMembersFront::addNotice("Template Data
$view"); + + $x = $smarty->template->getTemplateVars(); + $templateVars = '
' . print_r($x, 1) . '
'; + glmMembersFront::addNotice($templateVars, 'Template Parameters'); + } + + // Generate output from model data and view + $smarty->template->display($view); + } +} ?> \ No newline at end of file diff --git a/css/front.css b/css/front.css new file mode 100644 index 00000000..7766c467 --- /dev/null +++ b/css/front.css @@ -0,0 +1,5 @@ +/* + + Gaslight Media Members Database Front-End Styles + +*/ diff --git a/index.php b/index.php index 4bfcf0e0..90cf4af0 100644 --- a/index.php +++ b/index.php @@ -49,14 +49,23 @@ // Debug Options define('GLM_MEMBERS_PLUGIN_ADMIN_DEBUG', true); define('GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE', true); +define('GLM_MEMBERS_PLUGIN_FRONT_DEBUG', true); +define('GLM_MEMBERS_PLUGIN_FRONT_DEBUG_VERBOSE', true); // Plugin Versions define('GLM_MEMBERS_PLUGIN_VERSION', 0.1); define('GLM_MEMBERS_PLUGIN_DB_VERSION', 0.1); -// Other standard plugin defines -define('GLM_MEMBERS_PLUGIN_NAME', 'Gaslight Media Members Database'); +// URLs define('GLM_MEMBERS_PLUGIN_URL', plugin_dir_url(__FILE__)); +$pageProtocol = 'http'; +if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') { + $pageProtocol = 'https'; +} +define('GLM_MEMBERS_PLUGIN_CURRENT_BASE_URL', $pageProtocol.'://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']); + +// Directories +define('GLM_MEMBERS_PLUGIN_NAME', 'Gaslight Media Members Database'); define('GLM_MEMBERS_PLUGIN_DIR', dirname(__FILE__)); define('GLM_MEMBERS_PLUGIN_DB_SCRIPTS', dirname(__FILE__).'/misc/databaseScripts'); define('GLM_MEMBERS_PLUGIN_CLASS_DIR', GLM_MEMBERS_PLUGIN_DIR.'/classes'); diff --git a/js/front.js b/js/front.js new file mode 100644 index 00000000..fe7e3d25 --- /dev/null +++ b/js/front.js @@ -0,0 +1,2 @@ + +/* Nothing here yet */ \ No newline at end of file diff --git a/lib/smartyTemplateSupport.php b/lib/smartyTemplateSupport.php index a5dd0f51..c50da953 100644 --- a/lib/smartyTemplateSupport.php +++ b/lib/smartyTemplateSupport.php @@ -57,19 +57,9 @@ class smartyTemplateSupport { $this->template = new Smarty (); - // Get current script URL - $urlParts = explode('?', $_SERVER['HTTP_REFERER']); - $scriptURL = $urlParts[0]; - - // Check for default action - $action = 'index'; - if (isset($_REQUEST['glm_action']) && trim($_REQUEST['glm_action']) != '') { - $action = $_REQUEST['glm_action']; - } - // Add standard parameters $this->templateAssign ( 'adminDebug', GLM_MEMBERS_PLUGIN_ADMIN_DEBUG); - $this->templateAssign ( 'thisURL', $scriptURL ); + $this->templateAssign ( 'thisURL', GLM_MEMBERS_PLUGIN_CURRENT_BASE_URL ); $this->templateAssign ( 'thisPage', $_REQUEST['page']); $this->templateAssign ( 'glmPluginName', GLM_MEMBERS_PLUGIN_NAME ); $this->templateAssign ( 'thisYear', date ( 'Y' ) ); diff --git a/misc/smarty/templates_c/50e78f1400d6db96c588c737669426ab57397d1d.file.footer.html.php b/misc/smarty/templates_c/50e78f1400d6db96c588c737669426ab57397d1d.file.footer.html.php index c174039c..c82ad608 100644 --- a/misc/smarty/templates_c/50e78f1400d6db96c588c737669426ab57397d1d.file.footer.html.php +++ b/misc/smarty/templates_c/50e78f1400d6db96c588c737669426ab57397d1d.file.footer.html.php @@ -1,4 +1,4 @@ - decodeProperties(array ( @@ -7,7 +7,7 @@ $_valid = $_smarty_tpl->decodeProperties(array ( '50e78f1400d6db96c588c737669426ab57397d1d' => array ( 0 => '/var/www/server/wordpress/wp-content/plugins/glm-member-db/views/admin/footer.html', - 1 => 1421287062, + 1 => 1421621593, 2 => 'file', ), ), @@ -37,7 +37,7 @@ $_valid = $_smarty_tpl->decodeProperties(array ( Phone: 231-487-0692 - E-Mail: info@gaslightmedia.com
http://www.gaslightmedia.com - + tpl_vars['adminDebug']->value) {?> > diff --git a/views/admin/footer.html b/views/admin/footer.html index 5b06a432..d34194cb 100644 --- a/views/admin/footer.html +++ b/views/admin/footer.html @@ -6,7 +6,7 @@ Phone: 231-487-0692 - E-Mail: info@gaslightmedia.com
http://www.gaslightmedia.com - + {if $adminDebug}