Example #1
0
 /**
  * Generates and echoes the HTML for the options menu and sets Deko Boko
  * options in WordPress.
  *
  * @static
  * @access public
  * @uses DekoBoko::uninstall()
  * @returns string HTML for Settings form
  */
 function getOptionsMenu()
 {
     // check for valid nonce on form submission (WP displays its own message on failure)
     if ($_REQUEST['dekoboko_action'] && !check_admin_referer('dekoboko_nonce', 'dekoboko_nonce')) {
         return false;
     }
     // Start the cache
     ob_start();
     // uninstall
     if ($_REQUEST['dekoboko_action'] == 'uninstall') {
         // make doubly sure they want to uninstall
         if ($_REQUEST['dekoboko_uninstall'] == 'y') {
             if (DekoBoko::uninstall($_REQUEST['dekoboko_remove_keys']) == true) {
                 $message = __("Deko Boko has been uninstalled. You can now deactivate Deko Boko on your plugins management page.", DEKOBOKO_L10N_NAME);
             } else {
                 $message = __("Uninstall of Deko Boko failed. Database error:", DEKOBOKO_L10N_NAME);
                 $db_error = true;
             }
         } else {
             $message = __("You must check the 'Uninstall Deko Boko' checkbox to confirm you want to uninstall Deko Boko", DEKOBOKO_L10N_NAME);
         }
     } elseif ($_REQUEST['dekoboko_action'] == 'update_options') {
         array_walk($_REQUEST['dekoboko_options'], array(DEKOBOKO_PLUGIN_NAME, '_trim'));
         array_walk($_REQUEST['recaptcha'], array(DEKOBOKO_PLUGIN_NAME, '_trim'));
         // process any page slugs - save as an array
         if ($_REQUEST['dekoboko_options']['pages']) {
             $_REQUEST['dekoboko_options']['pages'] = preg_split("/[\\s,]+/", $_REQUEST['dekoboko_options']['pages']);
         }
         $dekoboko_options = array_merge(unserialize(get_option('dekoboko_options')), $_REQUEST['dekoboko_options']);
         update_option('dekoboko_options', serialize($dekoboko_options));
         $recaptcha_options = get_option('recaptcha');
         if (is_array($recaptcha_options)) {
             $recaptcha_options = array_merge($recaptcha_options, $_REQUEST['recaptcha']);
         } else {
             $recaptcha_options = $_REQUEST['recaptcha'];
         }
         update_option('recaptcha', $recaptcha_options);
         $message = __("Deko Boko settings saved.", DEKOBOKO_L10N_NAME);
     }
     // don't try to refresh options data if we just uninstalled
     if ($_REQUEST['dekoboko_action'] != 'uninstall') {
         // options may have changed - re-fetch
         $dekoboko_options = unserialize(get_option('dekoboko_options'));
         // flatten pages array for display
         if (is_array($dekoboko_options['pages'])) {
             $dekoboko_options['pages'] = implode("\n", $dekoboko_options['pages']);
         }
         // prepare for display in the form
         array_walk($dekoboko_options, array(DEKOBOKO_PLUGIN_NAME, '_htmlentities'));
         array_walk($dekoboko_options, array(DEKOBOKO_PLUGIN_NAME, '_stripslashes'));
         $recaptcha_options = get_option('recaptcha');
         if (is_array($recaptcha_options)) {
             array_walk($recaptcha_options, array(DEKOBOKO_PLUGIN_NAME, '_htmlentities'));
             array_walk($recaptcha_options, array(DEKOBOKO_PLUGIN_NAME, '_stripslashes'));
         }
     }
     // for linking to the recaptcha site for key signup
     $site_url = parse_url(get_option('site_url'));
     if (!function_exists('recaptcha_get_signup_url')) {
         require_once DEKOBOKO_DIR . '/recaptcha/recaptchalib.php';
     }
     // Get the markup and display
     require DEKOBOKO_DIR . '/display/options-main.php';
     $options_form = ob_get_contents();
     ob_end_clean();
     echo $options_form;
 }