_pluginOptionsArray; } // --------------------------------------------------------------------------- // Methods used to handle initialization of this plugin. // --------------------------------------------------------------------------- /** * Initialize() - Initializes the standard parameter set associated with this plugin. * * This function initializes the standard parameter set associated with this plugin so that the plugin * may be safely integrated into the Wordpress core. * * @param string $title The title of the plugin. * @param string $version The version of the plugin. * @param string $subfolderName The name of the plugin subfolder installed under the root plugins directory. * @param string $fileName The name of the plugin's main file. * * @return void None. * * @access public * @since {WP 2.3} * @author Keith Huster */ function Initialize( $title, $version, $subfolderName, $fileName ) { // Store the specified plugin parameters. $this->_pluginTitle = $title; $this->_pluginVersion = $version; $this->_pluginSubfolderName = $subfolderName; $this->_pluginFileName = $fileName; } // --------------------------------------------------------------------------- // Methods used to handle the administration page for this plugin. // --------------------------------------------------------------------------- /** * RegisterAdministrationPage() - Registers the plugin's administration page. * * This function registers the plugin's administration page with the Wordpress core via the add_action() * hook. This hook allows the plugin's administration paege to be processed as any standard Wordpress * administration page (such as the dashboard). * * @param string $parentMenu Parent menu of the plugin's administration menu. * @param string $minimumAccessLevel Minimum user access rights required to access the plugin's administration page. * @param string $adminMenuTitle Name of the plugin's administration menu. * @param string $adminMenuPageTitle Browser title of the plugin's administration page. * @param string $adminMenuPageSlug URI slug displayed for the plugin's administration webpage. * * @return void None. * * @access public * @since {WP 2.3} * @author Keith Huster */ function RegisterAdministrationPage( $parentMenu, $minimumAccessLevel, $adminMenuTitle, $adminMenuPageTitle, $adminMenuPageSlug ) { // Store the specified administration page parameters. $this->_pluginAdminMenuParentMenu = $parentMenu; $this->_pluginAdminMenuMinimumAccessLevel = $minimumAccessLevel; $this->_pluginAdminMenuTitle = $adminMenuTitle; $this->_pluginAdminMenuPageTitle = $adminMenuPageTitle; $this->_pluginAdminMenuPageSlug = $adminMenuPageSlug; // Wordpress hook for adding plugin admininistration menus. add_action( 'admin_menu', array( $this, '_AddAdministrationPage' ) ); } /** * _AddAdministrationPage() - Adds the plugin's administration page to the Wordpress core. * * This function adds the plugin's administration page to the Wordpress core by acting as a callback * function that was registered to the "admin_menu" function in the Wordpress core. * * @param void None. * * @return void None. * * @access private Access via admin_menu() callback only. * @since {WP 2.3} * @author Keith Huster */ function _AddAdministrationPage() { add_submenu_page( $this->_pluginAdminMenuParentMenu, $this->_pluginAdminMenuPageTitle, $this->_pluginAdminMenuTitle, $this->_pluginAdminMenuMinimumAccessLevel, $this->_pluginAdminMenuPageSlug, array( $this, '_DisplayPluginAdministrationPage' ) ); } /** * AddAdministrationPageBlock() - Adds a block of content to be displayed in the plugin's administration page. * * This function adds a block of content (i.e. an instance of a dbx-box class) to the plugin's administration * page. The placement and size of the block is controlled by the $blockType parameter. * * @param string $blockId ID of the content block used in HTML formatting (no spaces allowed). * @param string $blockTitle Title of the content block. * @param string $blockType Type of content block (one of CONTENT_BLOCK_TYPE_xxx). * @param string $blockFunctionPtr Function containing the content to be displayed. * * @return void None. * * @access public * @since {WP 2.3} * @author Keith Huster */ function AddAdministrationPageBlock( $blockId, $blockTitle, $blockType, $blockFunctionPtr ) { // Add a new page block to the array of available page blocks. $this->_pluginAdminMenuBlockArray[$blockId] = array( $blockTitle, $blockType, $blockFunctionPtr ); } /** * _DisplayAdministrationPageBlocks() - Displays the plugin's administration page blocks. * * This function displays each of the content blocks, of the specified type, that have been added to the * _pluginAdminMenuBlockArray via calls to the AddAdministrationPageBlock() function. The content blocks * are displayed from top to bottom in the order that they were added to the array. * * @param string $blockType Type of content block (one of CONTENT_BLOCK_TYPE_xxx). * * @return void None. * * @access private * @since {WP 2.3} * @author Keith Huster */ function _DisplayAdministrationPageBlocks( $blockType ) { if( is_array( $this->_pluginAdminMenuBlockArray ) ) { foreach( $this->_pluginAdminMenuBlockArray AS $blockKey=>$blockValue ) { if( $blockValue[$this->CONTENT_BLOCK_INDEX_TYPE] == $blockType ) { switch( $blockType ) { case $this->CONTENT_BLOCK_TYPE_SIDEBAR: // Create the markup necessary to display a SIDEBAR area content block. ?>

CONTENT_BLOCK_INDEX_TITLE] ); ?>

CONTENT_BLOCK_INDEX_FUNCTION][$this->CONTENT_BLOCK_INDEX_FUNCTION_CLASS]; $blockFunction = $blockValue[$this->CONTENT_BLOCK_INDEX_FUNCTION][$this->CONTENT_BLOCK_INDEX_FUNCTION_NAME]; $blockClass->$blockFunction(); ?>
CONTENT_BLOCK_TYPE_MAIN: // Create the markup necessary to display a MAIN area content block. ?>

CONTENT_BLOCK_INDEX_TITLE] ); ?>

CONTENT_BLOCK_INDEX_FUNCTION][$this->CONTENT_BLOCK_INDEX_FUNCTION_CLASS]; $blockFunction = $blockValue[$this->CONTENT_BLOCK_INDEX_FUNCTION][$this->CONTENT_BLOCK_INDEX_FUNCTION_NAME]; $blockClass->$blockFunction(); ?>
' ); echo( $htmlMessage ); echo( '' ); } /** * _DisplayPluginAdministrationPage() - Displays the plugin's administration page. * * This function displays the plugin's administration page that previously registered by a call * to the AddAdministrationPage() function. This function utilizes the DBX Management system created * by the _InitializeDbxManagementSystem() function to properly parse and display the page. This function * acts as a callback for the add_submenu_page() Wordpress core function. * * @param void None. * * @return void None. * * @access private Access via add_submenu_page() callback only. * @since {WP 2.3} * @author Keith Huster */ function _DisplayPluginAdministrationPage() { ?>
_UpdatePluginOptions( &$_REQUEST ); } else if( $_REQUEST['plugin_options_reset'] ) { // Reset the plugin's options. $this->_ResetPluginOptions(); } else if( $_REQUEST['plugin_options_uninstall'] ) { // Uninstall the plugin by removing the plugin options from the Wordpress database. $this->_UnregisterPluginOptions(); } if( $this->_IsPluginInstalled() ) { ?>

_pluginTitle . ' (v' . $this->_pluginVersion . ')' ); ?>

_InitializeDbxManagementSystem(); ?>
_DisplayAdministrationPageBlocks( $this->CONTENT_BLOCK_TYPE_SIDEBAR ); ?>
_DisplayAdministrationPageBlocks( $this->CONTENT_BLOCK_TYPE_MAIN ); ?>



_pluginSubfolderName . '/' . $this->_pluginFileName . '.php'; if( function_exists( 'wp_nonce_url' ) ) { $actionName = 'deactivate-plugin_' . $this->_pluginSubfolderName . '/' . $this->_pluginFileName . '.php'; $deactivateUrl = wp_nonce_url( $deactivateUrl, $actionName ); } // Remind the user to deactivate the plugin. $uninstalledMessage = '

All of the "' . $this->_pluginTitle . '" plugin options have been deleted from the database.

'; $uninstalledMessage .= '

Click here to finish the uninstallation and deactivate the "' . $this->_pluginTitle . '" plugin.

'; $this->_DisplayFadingMessageBox( $uninstalledMessage ); } ?>
_pluginOptionsArray[$optionName] = array( $optionValue, $optionDescription, $optionType, $optionValuesArray ); } /** * RegisterOptions() - Registers the plugin options with the Wordpress core. * * This function registers the Wordpress core activation hook required to store the plugin options * in the Wordpress options database. * * @param string $pluginFile Full path to the plugin's file. * * @return void None. * * @access public * @since {WP 2.3} * @author Keith Huster */ function RegisterOptions( $pluginFile ) { // Register the hooks required to properly handle activation of this plugin. register_activation_hook( $pluginFile, array( $this, '_RegisterPluginOptions' ) ); } /** * _RegisterPluginOptions() - Adds the plugin's options to the Wordpress options database. * * This function utilizes the Wordpress core update_option() function to add each of the options * specified in the plugin's option array to the Wordpress options database. This function verifies * that the specified options have not been previously added to the database to prevent overwriting * stored configuration values. * * @param void None. * * @return void None. * * @access private Access via register_activation_hook() callback only. * @since {WP 2.3} * @author Keith Huster */ function _RegisterPluginOptions() { if( is_array( $this->_pluginOptionsArray ) ) { global $wpdb; $registeredOptions = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" ); foreach( $this->_pluginOptionsArray AS $optionKey => $optionValue ) { // Only update the option value if the option has not been previously added to the database. $optionFound = false; foreach( (array) $registeredOptions AS $registeredOption ) { $registeredOption->option_name = attribute_escape( $registeredOption->option_name ); if( $optionKey == $registeredOption->option_name ) { $optionFound = true; } } if( $optionFound == false ) { update_option( $optionKey, $optionValue[$this->OPTION_INDEX_VALUE] ); } } } } /** * _UnregisterPluginOptions() - Removes the plugin's options from the Wordpress options database. * * This function utilizes the Wordpress core delete_option() function to remove each of the options * specified in the plugin's option array from the Wordpress options database. * * @param void None. * * @return void None. * * @access private * @since {WP 2.3} * @author Keith Huster */ function _UnregisterPluginOptions() { if( is_array( $this->_pluginOptionsArray ) ) { foreach( $this->_pluginOptionsArray AS $optionKey => $optionValue ) { delete_option( $optionKey ); } } } /** * _IsPluginInstalled() - Determines if the plugin is installed. * * This function verifies that the plugin options have been installed in the Wordpress options database and * returns "true" if they are and "false" if the are not. * * @param void None. * * @return bool $pluginInstalled Returns "true" if installed and "false" if not. * * @access private * @since {WP 2.3} * @author Keith Huster */ function _IsPluginInstalled() { $pluginInstalled = true; if( is_array( $this->_pluginOptionsArray ) ) { global $wpdb; $registeredOptions = $wpdb->get_results( "SELECT * FROM $wpdb->options ORDER BY option_name" ); foreach( $this->_pluginOptionsArray AS $optionKey => $optionValue ) { // Only update the option value if the option has not been previously added to the database. $optionFound = false; foreach( (array) $registeredOptions AS $registeredOption ) { $registeredOption->option_name = attribute_escape( $registeredOption->option_name ); if( $optionKey == $registeredOption->option_name ) { $optionFound = true; } } if( $optionFound == false ) { // The plugin is not fully installed so we need to break out of this loop and // update the installed flag. $pluginInstalled = false; break; } } } return $pluginInstalled; } /** * _UpdatePluginOptions() - Updates the plugin options in the Wordpress database. * * This function retrieves the plugin's options from the _POST[] method and updates the associated * options stored within the Wordpress options database. * * @param array &$requestArray Reference to the _REQUEST[] array. * * @return void None. * * @access private * @since {WP 2.3} * @author Keith Huster */ function _UpdatePluginOptions( &$requestArray ) { // Update the plugin's options using the values retrieved from the POST method. foreach( $this->_pluginOptionsArray AS $optionKey => $optionValueArray ) { update_option( $optionKey, $requestArray[$optionKey] ); } // Now display to the user that the plugins have been updated. $updatedMessage = '

The "' . $this->_pluginTitle . '" plugin options have been updated in the database.

'; $this->_DisplayFadingMessageBox( $updatedMessage ); } /** * _ResetPluginOptions() - Resets the plugin options in the Wordpress database. * * This function retrieves the plugin's default options from the options array and updates the associated * options stored within the Wordpress options database. * * @param void None. * * @return void None. * * @access private * @since {WP 2.3} * @author Keith Huster */ function _ResetPluginOptions() { // Update the plugin's options using the default values from the options array. foreach( $this->_pluginOptionsArray AS $optionKey => $optionValueArray ) { update_option( $optionKey, $optionValueArray[$this->OPTION_INDEX_VALUE] ); } // Now display to the user that the plugins have been reset to default values. $resetMessage = '

The "' . $this->_pluginTitle . '" plugin options have been reset to default values in the database.

'; $this->_DisplayFadingMessageBox( $resetMessage ); } /** * GetOptionValue() - Retrieves the option value for the specified option ID. * * This function retrieves the option value for the specified option ID from the Wordpress options database. * * @param string $optionName Name of the option whose value you are attempting to retrieve. * * @return mixed $optionValue Value of the requested option or "OPTION_PARAMETER_NOT_FOUND". * * @access public * @since {WP 2.3} * @author Keith Huster */ function GetOptionValue( $optionName ) { $optionValue = get_option( $optionName ); return $optionValue; } /** * GetOptionType() - Retrieves the option type for the specified option ID. * * This function retrieves the option type for the specified option ID from the plugin's option array. * This option parameter is not stored in the Wordpress options database so it is only accessible via the * plugin's options array. * * @param string $optionName Name of the option whose value you are attempting to retrieve. * * @return string $optionType Type of the requested option or "OPTION_PARAMETER_NOT_FOUND". * * @access public * @since {WP 2.3} * @author Keith Huster */ function GetOptionType( $optionName ) { $optionDescription = $this->OPTION_PARAMETER_NOT_FOUND; if( array_key_exists( $optionName, $this->_pluginOptionsArray ) ) { $optionDescription = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_TYPE]; } return $optionDescription; } /** * GetOptionDescription() - Retrieves the option description for the specified option ID. * * This function retrieves the option description for the specified option ID from the plugin's option array. * This option parameter is not stored in the Wordpress options database so it is only accessible via the * plugin's options array. * * @param string $optionName Name of the option whose value you are attempting to retrieve. * * @return string $optionDescription Description of the requested option or "OPTION_PARAMETER_NOT_FOUND". * * @access public * @since {WP 2.3} * @author Keith Huster */ function GetOptionDescription( $optionName ) { $optionDescription = $this->OPTION_PARAMETER_NOT_FOUND; if( array_key_exists( $optionName, $this->_pluginOptionsArray ) ) { $optionDescription = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_DESCRIPTION]; } return $optionDescription; } /** * GetOptionValuesArray() - Retrieves the option values array for the specified option ID. * * This function retrieves the option values array for the specified option ID from the plugin's option array. * This option parameter is not stored in the Wordpress options database so it is only accessible via the * plugin's options array. * * @param string $optionName Name of the option whose value you are attempting to retrieve. * * @return string $optionValuesList Comma-delimited list of the option values array. * * @access public * @since {WP 2.3} * @author Keith Huster */ function GetOptionValuesArray( $optionName ) { $optionValuesList = $this->OPTION_PARAMETER_NOT_FOUND; if( array_key_exists( $optionName, $this->_pluginOptionsArray ) ) { $optionValues = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_VALUES_ARRAY]; if( is_array( $optionValues ) ) { $optionValuesList = ''; foreach( $optionValues AS $optionValue ) { $optionValuesList .= ',' . $optionValue; } $optionValuesList = trim( $optionValuesList, ',' ); } else { $optionValuesList = $optionValues; } } return $optionValuesList; } /** * DisplayPluginOption() - Displays the plugin's specified option. * * This function generates the markup required to display the specified option and displays it on the * plugin's administration page via the echo() function. * * @param string $optionName Name of the option to display. * * @return void None. * * @access public * @since {WP 2.3} * @author Keith Huster */ function DisplayPluginOption( $optionName ) { $optionMarkup = ''; if( array_key_exists( $optionName, $this->_pluginOptionsArray ) ) { switch( $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_TYPE] ) { case $this->OPTION_TYPE_TEXTBOX: // Generate the markup required to display an XHTML compliant textbox. $optionMarkup = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_DESCRIPTION] . ' '; $optionMarkup .= ' '; break; case $this->OPTION_TYPE_TEXTAREA: // Generate the markup required to display an XHTML compliant textarea. $optionMarkup = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_DESCRIPTION] . '
'; $optionMarkup .= ' '; break; case $this->OPTION_TYPE_CHECKBOX: // Generate the markup required to display an XHTML compliant checkbox. $checkBoxValue = ( get_option( $optionName ) == true ) ? 'checked="checked"' : ''; $optionMarkup .= ' '; $optionMarkup .= $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_DESCRIPTION]; break; case $this->OPTION_TYPE_RADIOBUTTONS: // Split the comma delimited option description and values for the radio buttons. $optionIdCount = 0; $optionMarkup = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_DESCRIPTION] . '
'; $valuesArray = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_VALUES_ARRAY]; if( is_array( $valuesArray ) ) { // Loop through each of the comma delimited values to process the radiobuttons. foreach( $valuesArray AS $valueName ) { // The rest of the parameters are the values for each of the radio buttons so we can // generate the markup required to display an XHTML compliant set of radio buttons. $selectedValue = ( get_option( $optionName ) == $valueName ) ? 'checked="checked"' : ''; $optionMarkup .= ' '; $optionMarkup .= $valueName; $optionMarkup .= '
'; // Finally increment the option ID value so that the next radiobutton will have // and ID field of 1 greater than the previous radiobutton. $optionIdCount++; } } break; case $this->OPTION_TYPE_PASSWORDBOX: // Generate the markup required to display an XHTML compliant passwordbox. $optionMarkup = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_DESCRIPTION] . ' '; $optionMarkup .= ' '; break; case $this->OPTION_TYPE_COMBOBOX: // Split the comma delimited option description and values for the combobox. $optionIdCount = 0; $optionMarkup = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_DESCRIPTION] . ' '; } break; case $this->OPTION_TYPE_FILEBROWSER: // Generate the markup required to display an XHTML compliant file input box. $optionMarkup = $this->_pluginOptionsArray[$optionName][$this->OPTION_INDEX_DESCRIPTION] . ' '; $optionMarkup .= ' '; break; case $this->OPTION_TYPE_HIDDEN: // Generate the markup required to display an XHTML compliant hidden input box. $optionMarkup .= ' '; break; default: // Simply return nothing. $optionMarkup = ''; break; } } echo( $optionMarkup ); } } ?>