Example #1
0
function amr_getset_options($reset = false)
{
    /* get the options from wordpress if in wordpress
    	if no options, then set defaults */
    global $locale, $amr_options;
    /* has the initial default configuration */
    /* set up some global config initially */
    amr_set_defaults();
    /* we are requested to reset the options, so delete and update with default */
    if ($reset) {
        echo '<div class="updated"><p>';
        _e('Resetting options...', 'amr-ical-events-list');
        if ($d = delete_option('amr-ical-events-list') or $d = delete_option('AmRiCalEventList')) {
            _e('Options Deleted...', 'amr-ical-events-list');
        } else {
            _e('Option was not saved before or error deleting option...', 'amr-ical-events-list');
        }
        delete_option('amr_ical_images_to_use');
        echo '</p></div>';
    } else {
        /* *First setup the default config  */
        /* general config */
        $amr_options = get_option('amr-ical-events-list');
        if (!empty($amr_options)) {
            $alreadyhave = true;
            //if had one global option, now split into separate ?
            if (!empty($amr_options['no_types'])) {
                //and !empty($amr_options['1']))  { // then we have old list types, lets convert to new
                for ($i = 1; $i <= $amr_options['no_types']; $i++) {
                    $amr_options['listtypes'][$i] = $amr_options[$i];
                    $amr_options['listtypes'][$i]['compprop'] = amr_remove_array_level($amr_options['listtypes'][$i]['compprop']);
                    unset($amr_options[$i]);
                }
                unset($amr_options['no_types']);
                // no longer relevant
                if (is_admin()) {
                    // else might be on a front end page
                    amr_notice_listtypes_converted();
                    update_option('amr-ical-events-list', $amr_options);
                }
            }
        } else {
            // really old - can delete one day?
            if ($alreadyhave = get_option('AmRiCalEventList')) {
                delete_option('AmRiCalEventList');
                add_option('amr-ical-events-list', $alreadyhave);
                _e(' Converting option key to lowercase', 'amr-ical-events-list');
            }
        }
    }
    if (!isset($alreadyhave) or !$alreadyhave) {
        amr_set_defaults();
    }
    if (!empty($amr_options['usehumantime'])) {
        add_filter('amr_human_time', 'amr_human_time');
    }
    return $amr_options;
}
function amr_whats_in_use()
{
    global $amr_options;
    amr_set_defaults();
    // $amr_options will be set, don't fetch other options yet
    $defaults = $amr_options;
    $desc = amr_set_helpful_descriptions();
    $amr_options = amr_getset_options(false);
    $inuse = get_option('amr-event-fields-in-use');
    // overlay any existing
    // get all fields that have a column
    if (empty($inuse)) {
        $inuse = array();
    }
    foreach ($amr_options['listtypes'] as $i => $l) {
        // foreach list
        if (isset($l['compprop'])) {
            foreach ($l['compprop'] as $f => $opt) {
                if (empty($opt['Column'])) {
                    if (empty($allfieldsinuse[$f])) {
                        $allfieldsinuse[$f] = 0;
                    }
                } else {
                    if (empty($allfieldsinuse[$f])) {
                        $allfieldsinuse[$f] = 1;
                    } else {
                        $allfieldsinuse[$f]++;
                    }
                }
            }
        }
    }
    // any new defaults ?
    foreach ($defaults['listtypes'] as $i => $l) {
        if (isset($l['compprop'])) {
            foreach ($l['compprop'] as $f => $opt) {
                if (!isset($allfieldsinuse[$f])) {
                    $allfieldsinuse[$f] = 0;
                }
            }
        }
    }
    // check descriptions just in case ? - no also has componemts
    /*	foreach  ($desc as $i=> $l) {
    		if (empty($allfieldsinuse[$i]))
    			$allfieldsinuse[$i] = 0;
    	}	
    */
    if (!empty($inuse)) {
        // we already got somethingstored
        foreach ($inuse as $i => $l) {
            if (!isset($allfieldsinuse[$i])) {
                // its no longer possible, delete it
                unset($inuse[$i]);
            }
        }
    } else {
        $inuse = array();
    }
    // no option yet
    foreach ($allfieldsinuse as $i => $l) {
        // for all the fields we know about
        if (!isset($inuse[$i])) {
            // is maybe new? - not empty because thats just what we set before
            $inuse[$i] = $allfieldsinuse[$i];
        }
    }
    //	var_dump($inuse);
    array_multisort(array_values($inuse), SORT_DESC, array_keys($inuse), SORT_ASC, $inuse);
    return $inuse;
}