From af1dba7ff0fc036bf8578e1c261f2bbd595c688a Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Wed, 30 Mar 2016 12:57:01 -0400 Subject: [PATCH] Now capable of finding ajax models in all plugins --- controllers/admin.php | 49 +++++++++------- models/admin/ajax/pdfOutput.php | 100 -------------------------------- setup/validActions.php | 3 +- 3 files changed, 30 insertions(+), 122 deletions(-) delete mode 100644 models/admin/ajax/pdfOutput.php diff --git a/controllers/admin.php b/controllers/admin.php index 9b5ba5ca..6504bd4a 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -319,32 +319,41 @@ class glmMembersAdmin extends GlmPluginSupport trigger_error ( 'ERROR: No "glm_action" itme in POST array.', E_USER_ERROR); } - // Check for a valid action. This only looks in the main plugin. Might have to change this later. - if (!isset($this->config['addOns'][GLM_MEMBERS_PLUGIN_SLUG]['actions']['adminActions']['ajax'][$glmAction])) { - // Menu item/Action not in valid actions array - trigger_error ( 'ERROR: The specified action is not valid - '.$glmAction, E_USER_ERROR); - } + // Scan through the plugins to find the specified action + $actionFound = false; + foreach ($this->config['addOns'] as $a) { - // Build model and path and class names - $modelName = GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/'.$glmAction.'.php'; - $className = 'GlmMembersAdmin_ajax_'.$glmAction; + // Check for a valid action in this plugin + if (isset($a['actions']['adminActions']['ajax'][$glmAction])) { - // If model file doesn't exist - we have an error - if (!file_exists($modelName)) { - trigger_error ( "ERROR: The specified model file doesn't exist. ($modelName)", E_USER_ERROR); - } + // Build model and path and class names + $modelName = $a['dir'].'/models/admin/ajax/'.$glmAction.'.php'; + $className = 'GlmMembersAdmin_ajax_'.$glmAction; - // Load the model file - require_once ($modelName); + // If model file doesn't exist - we have an error + if (!file_exists($modelName)) { + trigger_error ( "ERROR: The specified model file doesn't exist. ($modelName)", E_USER_ERROR); + } + + // Load the model file + require_once ($modelName); - // check for an invalid model class name - if (!class_exists($className)) { - trigger_error ( "ERROR: The specified class naeme doesn't exist. ($className)", E_USER_ERROR); + // check for an invalid model class name + if (!class_exists($className)) { + trigger_error ( "ERROR: The specified class naeme doesn't exist. ($className)", E_USER_ERROR); + } + + // Instantiate the model and ask it to perform the work + $model = new $className($this->wpdb, $this->config); + $model->modelAction(); + + } } - // Instantiate the model and ask it to perform the work - $model = new $className($this->wpdb, $this->config); - $model->modelAction(); + // Check if no matching action found + if (!$actionFound) { + trigger_error ( 'ERROR: The specified action is not valid - '.$glmAction, E_USER_ERROR); + } wp_die(); diff --git a/models/admin/ajax/pdfOutput.php b/models/admin/ajax/pdfOutput.php deleted file mode 100644 index 95ac50c2..00000000 --- a/models/admin/ajax/pdfOutput.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @version 0.1 - */ - -/* - * Steve Note... - * - * You can get to this using the following URL. - * - * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=pdfOutput&mystuff=THIS - * - * You should be able to do this as POST or GET and should be able to add and read additional parameters. - * I added a "mystuff" parameter to the URL above and it does output from the code in the - * modelAction() function below. - * - * To add another model under models/admin/ajax all you need to do is create it and add it to the - * setup/validActions.php file. - * - */ - -// Load Members data abstract -// require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php'); - -/* - * This class performs the work of handling images passed to it via - * an AJAX call that goes through the WorPress AJAX Handler. - * - */ -class GlmMembersAdmin_ajax_pdfOutput // extends GlmDataImages -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - /** - * Plugin Configuration Data - * - * @var $config - * @access public - */ - public $config; - - /* - * Constructor - * - * This contructor sets up this model. At this time that only includes - * storing away the WordPress data object. - * - * @return object Class object - * - */ - public function __construct ($wpdb, $config) - { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - // Run constructor for members data class -// parent::__construct(false, false); - - } - - /* - * Perform Model Action - * - * This modelAction takes an AJAX image upload and stores the image in the - * media/images directory of the plugin. - * - * This model action does not return, it simply does it's work then calls die(); - * - * @param $actionData - * - * Echos JSON string as response and does not return - */ - public function modelAction ($actionData = false) - { - echo "Stuff = ".$_REQUEST['mystuff']."
"; - die(); - } - - -} diff --git a/setup/validActions.php b/setup/validActions.php index 8a3d3544..f3b9208c 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -33,8 +33,7 @@ $glmMembersValidActions = array( 'adminActions' => array( 'ajax' => array( - 'imageUpload' => 'glm-member-db', - 'pdfOutput' => 'glm-member-db' + 'imageUpload' => 'glm-member-db' ), 'dashboardWidget' => array( 'index' => 'glm-member-db' -- 2.17.1