/**
 * Get configuration for user image types
 *
 * @return array
 * @global Cache $cache
 */
function cot_userimages_config_get($ignorecache = false)
{
    global $cache;
    if ($cache && !$ignorecache && $cache->db->exists('cot_userimages_config', 'users')) {
        $cfg = $cache->db->get('cot_userimages_config', 'users');
        if (is_array($cfg)) {
            return $cfg;
        }
    }
    $cfg = array();
    $cot_cfg = cot_config_load('userimages');
    foreach ($cot_cfg as $entry) {
        $imagesettings = explode('x', $entry['value']);
        $cfg[$entry['name']] = array('width' => $imagesettings[0], 'height' => $imagesettings[1], 'crop' => isset($imagesettings[2]) ? $imagesettings[2] : '');
    }
    $cache && $cache->db->store('cot_userimages_config', $cfg, 'users');
    return $cfg;
}
Exemple #2
0
/**
 * Updates existing configuration map removing obsolete options, adding new
 * options and tweaking options which need to be updated.
 *
 * @param string $name Extension code
 * @param array $options Configuration options
 * @param bool $is_module TRUE for modules, FALSE for plugins
 * @param string $category Structure category code. Only for per-category config options
 * @param string $donor Extension name for extension-to-extension config implantations
 * @return int Number of entries affected
 */
function cot_config_update($name, $options, $is_module = false, $category = '', $donor = '')
{
    $affected = 0;
    $old_options = cot_config_load($name, $is_module, $category, $donor);
    // Find and remove options which no longer exist
    $remove_opts = array();
    foreach ($old_options as $old_opt) {
        $keep = false;
        foreach ($options as $opt) {
            if ($opt['name'] == $old_opt['name']) {
                $keep = true;
                break;
            }
        }
        if (!$keep && $old_opt['type'] != COT_CONFIG_TYPE_HIDDEN) {
            $remove_opts[] = $old_opt['name'];
        }
    }
    if (count($remove_opts) > 0) {
        $affected += cot_config_remove($name, $is_module, $remove_opts, $category, $donor);
    }
    // Find new options and options which have been modified
    $new_options = array();
    $upd_options = array();
    foreach ($options as $opt) {
        $existed = false;
        foreach ($old_options as $old_opt) {
            if ($opt['name'] == $old_opt['name']) {
                $changed = array_diff($opt, $old_opt);
                if (count($changed) > 0) {
                    // Values for modified options are set to default
                    // only if both type and default value have changed
                    if ($opt['type'] != $old_opt['type'] && $opt['default'] != $old_opt['default']) {
                        $opt['value'] = $opt['default'];
                    }
                    $upd_options[] = $opt;
                }
                $existed = true;
                break;
            }
        }
        if (!$existed) {
            $new_options[] = $opt;
        }
    }
    if (count($new_options) > 0) {
        $affected += cot_config_add($name, $new_options, $is_module, $category);
    }
    if (count($upd_options) > 0) {
        $affected += cot_config_modify($name, $upd_options, $is_module, $category);
    }
    return $affected;
}