Tarski Options, or /wp-admin/themes.php?page=tarski-options * in your WordPress directory. * @package Tarski * @since 2.0 */ class Options { var $installed; var $deleted; var $update_notification; var $sidebar_pp_type; var $header; var $display_title; var $display_tagline; var $nav_pages; var $home_link_name; var $nav_extlinkcat; var $style; var $asidescategory; var $centred_theme; var $swap_sides; var $tags_everywhere; var $show_categories; var $show_authors; var $use_pages; /** * tarski_options_defaults() - Sets Options object's properties to their default values. * * @since 2.0 */ function tarski_options_defaults() { $this->installed = theme_version('current'); $this->update_notification = true; $this->sidebar_pp_type = 'main'; $this->header = 'greytree.jpg'; $this->display_title = true; $this->display_tagline = true; $this->nav_pages = false; $this->home_link_name = __('Home','tarski'); $this->nav_extlinkcat = 0; $this->style = false; $this->asidescategory = 0; $this->centred_theme = true; $this->swap_sides = false; $this->swap_title_order = false; $this->tags_everywhere = false; $this->show_categories = true; $this->show_authors = tarski_should_show_authors(); $this->use_pages = false; } /** * tarski_options_get() - Sets Options properties to the values retrieved from the database. * * @since 2.0 */ function tarski_options_get() { $saved_options = unserialize(get_option('tarski_options')); if(!empty($saved_options) && is_object($saved_options)) { foreach($saved_options as $name => $value) { $this->$name = $value; } } } /** * tarski_options_update() - Sets Options properties to the values set on the Options page. * * Note that this function doesn't save anything to the database, that's the * preserve of save_tarski_options(). * @since 2.0 * @see save_tarski_options() */ function tarski_options_update() { if(($_POST['delete_options'] == 1)) { $this->deleted = time(); } elseif($_POST['restore_options'] == 1) { unset($this->deleted); } else { if($_POST['update_notification'] == 'off') $this->update_notification = false; elseif($_POST['update_notification'] == 'on') $this->update_notification = true; $header = $_POST['header_image']; if(isset($header)) { $header = str_replace('-thumb', '', $header); $this->header = $header; } $nav_pages = $_POST['nav_pages']; if(isset($nav_pages)) { $nav_pages = implode(',', $nav_pages); $this->nav_pages = $nav_pages; } else { $this->nav_pages = false; } $stylefile = $_POST['alternate_style']; if(is_valid_tarski_style($stylefile)) $this->style = $stylefile; elseif(!$stylefile) $this->style = false; $this->display_title = (bool) $_POST['display_title']; $this->display_tagline = (bool) $_POST['display_tagline']; $this->show_categories = (bool) $_POST['show_categories']; $this->tags_everywhere = (bool) $_POST['tags_everywhere']; $this->use_pages = (bool) $_POST['use_pages']; $this->centred_theme = (bool) $_POST['centred_theme']; $this->swap_sides = (bool) $_POST['swap_sides']; $this->swap_title_order = (bool) $_POST['swap_title_order']; $this->asidescategory = $_POST['asides_category']; $this->nav_extlinkcat = $_POST['nav_extlinkcat']; $this->home_link_name = $_POST['home_link_name']; $this->sidebar_type = $_POST['sidebar_type']; $this->sidebar_pp_type = $_POST['sidebar_pp_type']; $this->show_authors = tarski_should_show_authors(); unset($this->deleted); } } } /** * save_tarski_options() - Saves a new set of Tarski options. * * If the Tarski Options page request includes a $_POST call * and it's been generated by hitting the 'submit' button, this * function will generate a new Options object, set its properties * to the existing set of options, and then save the new options * over the old ones. It then flushes the options so the Options * page, which executes after this function, will display the new * values rather than the old ones. * @see tarskiupdate() which it replaces * @since 2.0 */ function save_tarski_options() { $tarski_options = new Options; $tarski_options->tarski_options_get(); if(ready_to_delete_options($tarski_options->deleted)) { delete_option('tarski_options'); flush_tarski_options(); return; } tarski_upgrade_and_flush_options(); if(isset($_POST['submit'])) { $tarski_options->tarski_options_update(); update_option('tarski_options', serialize($tarski_options)); } flush_tarski_options(); } /** * flush_tarski_options() - Flushes Tarski's options for use by the theme. * * Creates a new Options object, and gets the current options. If * no options have been set in the database, it will return the * defaults. Additionally, if the 'deleted' property has been set * then the function will check to see if it was set more than two * hours ago--if it was, the tarski_options database row will be * dropped. If the 'deleted' property has been set, then the defaults * will be returned regardless of whether other options are set. * @since 1.4 * @global object $tarski_options * @return object $tarski_options */ function flush_tarski_options() { global $tarski_options; $tarski_options = new Options; $tarski_options->tarski_options_get(); if(!get_option('tarski_options') || isset($tarski_options->deleted)) $tarski_options->tarski_options_defaults(); } /** * update_tarski_option() - Updates the given Tarski option with a new value. * * This function can be used either to update a particular option * with a new value, or to delete that option altogether by setting * $drop to true. * @since 1.4 * @param string $option * @param string $value * @param boolean $drop * @global object $tarski_options */ function update_tarski_option($option, $value) { $tarski_options = new Options; $tarski_options->tarski_options_get(); if(empty($value)) unset($tarski_options->$option); else $tarski_options->$option = $value; update_option('tarski_options', serialize($tarski_options)); flush_tarski_options(); } /** * get_tarski_option() - Returns the given Tarski option. * * @since 1.4 * @param string $name * @return mixed */ function get_tarski_option($name) { global $tarski_options; if(!is_object($tarski_options)) flush_tarski_options(); return $tarski_options->$name; } ?>