Ejemplo n.º 1
0
 /**
  * Method called when settings form details are being saved.
  * @param Array $formValues The list of settings being saved.
  * @see wplib/EasyForm::handleSave()
  */
 protected function handleSave($formValues)
 {
     // Get existing settings first (in case we don't have all the setting to play with
     // on a certain page), then merge changes.
     $originalSettings = TidySettings_getSettings($this->settingPrefix);
     foreach ($formValues as $name => $value) {
         $originalSettings[$name] = $value;
     }
     $saveSuccess = TidySettings_saveSettings($originalSettings, $this->settingPrefix);
     if ($saveSuccess) {
         $this->messages = $this->showMessage('Settings successfully saved.');
     } else {
         $this->messages = $this->showMessage('There was a problem saving the settings.', true);
     }
 }
Ejemplo n.º 2
0
/**
 * Install the plugin, initialise the default settings, and create the tables for the websites and groups.
 */
function WPCW_plugin_setup($force)
{
    $installed_ver = get_option(WPCW_DATABASE_KEY) + 0;
    $current_ver = WPCW_DATABASE_VERSION + 0;
    // Performing an upgrade
    if ($current_ver != $installed_ver || $force) {
        global $wpdb, $wpcwdb;
        $wpcwdb = new WPCW_Database();
        // If settings don't already exist, create new settings based on defaults
        // only when plugin activates.
        $existingSettings = TidySettings_getSettings(WPCW_DATABASE_SETTINGS_KEY);
        // The default settings that should exist on initialisation.
        $defaultSettings = array('show_powered_by' => 'show_link', 'use_default_css' => 'show_css', 'license_activation' => 'activate_license', 'cert_background_type' => 'use_default', 'cert_logo_enabled' => 'no_cert_logo', 'cert_logo_enabled' => 'no_cert_logo', 'cert_signature_type' => 'text', 'cert_sig_text' => get_bloginfo('name'));
        // No settings at all, so save all settings direct to the database.
        if (!$existingSettings) {
            TidySettings_saveSettings($defaultSettings, WPCW_DATABASE_SETTINGS_KEY);
        } else {
            // Check all settings
            foreach ($defaultSettings as $key => $value) {
                if (!isset($existingSettings[$key])) {
                    $existingSettings[$key] = $value;
                }
            }
            // Save modified existing settings back to the settings
            TidySettings_saveSettings($existingSettings, WPCW_DATABASE_SETTINGS_KEY);
        }
        // Remove the flag for flushing rules
        delete_option('wpcw_flush_rules');
        // Upgrade database tables if version change.
        WPCW_database_upgradeTables($installed_ver, $force);
        // Create upload directory
        WPCW_files_createFileUploadDirectory_base();
    }
}
Ejemplo n.º 3
0
/**
 * Migrates settings from the older version of the plugin to a single entry if settings
 * cannot be found for the new style of data.
 * 
 * @param Boolean $forceMigrate If true, then force the migration of data from the old version.
 */
function STWWT_plugin_migrateSettings($forceMigrate = false)
{
    // Check we have existing settings - if not, do a migration.
    $allSettings = TidySettings_getSettings(STWWT_SETTINGS_KEY);
    if (!(!$allSettings || $forceMigrate)) {
        return false;
    }
    // Default cache length
    $allSettings['stwwt_embedded_cache_length'] = '7';
    // Access ID
    $stw_keyid = get_option('STWThumbnails_KeyId');
    if ($stw_keyid) {
        $allSettings['stwwt_access_id'] = $stw_keyid;
    }
    // Thumbnail Bubble	Method
    $stw_enable = get_option('STWThumbnails');
    $stw_method = get_option('STWThumbnails_method');
    if ($stw_enable && $stw_method) {
        // See if manual or automatic
        if ($stw_method == 'manual') {
            $allSettings['stwwt_bubble_method'] = 'manual';
        } else {
            $allSettings['stwwt_bubble_method'] = 'automatic';
        }
    } else {
        $allSettings['stwwt_bubble_method'] = 'disable';
    }
    // Thumbnail Bubble Size
    $stw_sz = get_option('STWThumbnails_sz');
    if (in_array($stw_sz, array('xlg', 'lg', 'sm'))) {
        $allSettings['stwwt_bubble_size'] = $stw_sz;
    } else {
        $allSettings['stwwt_bubble_size'] = 'lg';
    }
    // Embedded thumbnail size
    $stw_embedsz = get_option('STWThumbnails_embedsz');
    if (in_array($stw_embedsz, array('xlg', 'lg', 'sm', 'vsm', 'tny', 'mcr'))) {
        $allSettings['stwwt_embedded_default_size'] = $stw_embedsz;
    } else {
        $allSettings['stwwt_embedded_default_size'] = 'lg';
    }
    // Pro Features - Specific Pages
    $stw_permspec = get_option('STWThumbnails_permspec');
    if ($stw_permspec) {
        $allSettings['stwwt_embedded_pro_inside'] = 'enable';
    } else {
        $allSettings['stwwt_embedded_pro_inside'] = 'disable';
    }
    // Pro Features - Full Length
    $stw_permfull = get_option('STWThumbnails_permfull');
    if ($stw_permfull) {
        $allSettings['stwwt_embedded_pro_full_length'] = 'enable';
    } else {
        $allSettings['stwwt_embedded_pro_full_length'] = 'disable';
    }
    // Pro Features - Custom Quality
    $stw_permqual = get_option('STWThumbnails_permqual');
    $allSettings['stwwt_embedded_pro_custom_quality'] = false;
    if ($stw_permqual) {
        // Only copy quality if enabled and set to a number greater than 0.
        $stw_stwq = get_option('STWThumbnails_stwq');
        if ($stw_stwq + 0 > 0) {
            $allSettings['stwwt_embedded_pro_custom_quality'] = $stw_stwq + 0;
        }
    }
    // Save settings
    TidySettings_saveSettings($allSettings, STWWT_SETTINGS_KEY);
    // Remove all previous settings
    delete_option('STWThumbnails');
    delete_option('STWThumbnails_KeyId');
    delete_option('STWThumbnails_sz');
    delete_option('STWThumbnails_embedsz');
    delete_option('STWThumbnails_permspec');
    delete_option('STWThumbnails_permfull');
    delete_option('STWThumbnails_permqual');
    delete_option('STWThumbnails_stwq');
    delete_option('STWThumbnails_method');
}
Ejemplo n.º 4
0
 /**
  * Handle processing the form when it's posted, such as saving and handling errors.
  */
 protected function processPost()
 {
     // Process data as usual
     parent::processPost();
     // ### Now manipulate the interface
     // Get currently saved account details
     $settings = TidySettings_getSettings($this->settingPrefix);
     // Only do check if we have access ID and secret ID. Code will handle hiding pro features
     // automatically if we can't get the account details.
     $accountDetails = false;
     if (isset($settings['stwwt_access_id']) && isset($settings['stwwt_secret_id'])) {
         $accountDetails = $this->checkAccountType($settings['stwwt_access_id'], $settings['stwwt_secret_id']);
     }
     // Check account level
     $accountLevel = 'invalid';
     if (isset($accountDetails['account_type'])) {
         $accountLevel = $accountDetails['account_type'];
     }
     // Save the account details to the database for use later.
     TidySettings_saveSettings($accountDetails, STWWT_SETTINGS_KEY_ACCOUNT);
     // Set the account level in the interface
     if ($accountLevel == 'invalid') {
         $this->formObj->setElementHTML('stwwt_account_level', sprintf('<span class="stwwt_account_invalid"><span class="stwwt_account_level">Invalid</span> - please provide valid account details.</span>'));
     } else {
         $displayAcctName = ucwords($accountLevel);
         if ('Plus' == $displayAcctName) {
             $displayAcctName = 'PLUS';
         }
         $this->formObj->setElementHTML('stwwt_account_level', sprintf('<span class="stwwt_account_level stwwt_account_%s">%s</span>', $accountLevel, $displayAcctName));
     }
     if (!empty($this->paramList)) {
         // Look for any elements that have an account_level value. If that account level doesn't match the
         // desired account level, then that field doesn't get rendered. For all other fields, assume they
         // have account.
         foreach ($this->paramList as $fieldName => $fieldDetails) {
             // ### Check 1 - Account level required
             if (isset($fieldDetails['account_level']) && $fieldDetails['account_level']) {
                 // Got a list of account levels? Copy them all over
                 if (is_array($fieldDetails['account_level'])) {
                     if (!in_array($accountLevel, $fieldDetails['account_level'])) {
                         $this->removeElementDueToAccountLevel($fieldName, $fieldDetails);
                     }
                 } else {
                     if ($fieldDetails['account_level'] != $accountLevel) {
                         $this->removeElementDueToAccountLevel($fieldName, $fieldDetails);
                     }
                 }
             }
             // end if account level required
             // ### Check 2 - Check for account feature (independent of account level)
             if (isset($fieldDetails['account_feature']) && $fieldDetails['account_feature']) {
                 $featureName = $fieldDetails['account_feature'];
                 if (isset($accountDetails[$featureName]) && $accountDetails[$featureName] != 1 || $accountLevel == 'invalid') {
                     $this->removeElementDueToAccountLevel($fieldName, $fieldDetails);
                 }
             }
         }
         // end foreach
     }
     // end if (!empty($paramList))
 }