This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ define( 'ZEN_URL', path_join( WP_PLUGIN_URL, basename( dirname( __FILE__ ) ) ) ); define( 'ZEN_PATH', dirname( __FILE__ ) ); class zen { var $options_key = 'zen'; var $themes = array( array( 'slug' => 'zen-light', 'name' => 'Zen Light', 'thumb' => '', 'author' => '', 'credit' => '', ), array( 'slug' => 'zen-dark', 'name' => 'Zen Dark', 'thumb' => '', 'author' => '', 'credit' => '', ), array( 'slug' => 'zen-papyrus', 'name' => 'Zen Papyrus', 'thumb' => '', 'author' => '', 'credit' => 'Background by DevonTT (flickr)', ), array( 'slug' => 'zen-papyrus-lite', 'name' => 'Zen Papyrus Lite', 'thumb' => '', 'author' => ' by Andrew Spittle', 'credit' => '', ), array( 'slug' => 'zen-terminal', 'name' => 'Zen Terminal', 'thumb' => '', 'author' => ' by Andrew Spittle', 'credit' => '', ), array( 'slug' => 'zen-sunset', 'name' => 'Zen Sunset', 'thumb' => '', 'author' => '', 'credit' => 'Background by elkit (flickr)', ), array( 'slug' => 'zen-sky', 'name' => 'Zen Sea & Sky', 'thumb' => '', 'author' => '', 'credit' => 'Background by stevekrh19 (sxc.hu)', ), array( 'slug' => 'zen-foiled', 'name' => 'Zen Foiled Again', 'thumb' => '', 'author' => '', 'credit' => 'Background by asolario (sxc.hu)', ) ); function __construct() { add_action('admin_enqueue_scripts', array(&$this, 'admin_scripts')); add_action('admin_print_styles', array(&$this, 'admin_styles')); add_action('personal_options_update', array(&$this, 'update_user_profile')); add_action('profile_personal_options', array(&$this, 'show_user_profile_options')); add_action('save_post', array(&$this, 'update_active_theme')); } function show_user_profile_options( ) { global $user_id, $profileuser; if( current_user_can('edit_posts') ) : $user_options = $this->get_user_options($user_id); $themes = $this->get_themes(); ?>

_the_user_option_checkbox( 'onload', $user_options['onload'], __('Always open in Zen mode', 'zen'), $this->options_key); ?>


_the_user_option_theme($theme['slug'], $theme, $selected) ?>

email me.", 'zen'); ?>

z

q

t

options_key . '[active_theme]'; $checked = ( $selected ) ? ' checked="checked"' : ''; ?>
ID == 0 ) return; $user_id = $user->ID; if( current_user_can('edit_posts') && isset($_POST['zen_options_update']) ) { $options = $_POST[$this->options_key]; // Scrub the submitted options $options['onload'] = intval( $options['onload'] ); $options['modules_cats'] = intval( $options['modules_cats'] ); $options['modules_tags'] = intval( $options['modules_tags'] ); $options['active_theme'] = esc_html( $options['active_theme'] ); $this->update_user_options( $user_id, $this->options_key, $options ); } } function update_user_options( $user_id = 0, $option_key, $option_value ) { if( !$user_id ) { $user = wp_get_current_user(); $user_id = $user->ID; } if( !$user_id ) return false; update_metadata('user', $user_id, $option_key, $option_value ); } function get_user_options( $user_id = 0 ) { if( !$user_id ) { $user = wp_get_current_user(); $user_id = $user->ID; } if( $user_id ) $options = get_metadata( 'user', $user_id, $this->options_key, true ); if( empty($options) ) { $options = array(); } // Set option defaults, if not assigned if( empty($options['onload']) ) $options['onload'] = 0; if( empty($options['modules_cats']) ) $options['modules_cats'] = 0; if( empty($options['modules_tags']) ) $options['modules_tags'] = 0; if( empty($options['active_theme']) ) $options['active_theme'] = 'zen-light'; return $options; } /** * Updates the user's current theme as their preferred theme */ function update_active_theme( $post ) { if( wp_is_post_autosave($post) && isset( $_POST['active_theme'] ) ) { $active_theme = esc_html( trim( $_POST['active_theme'] ) ); $options = $this->get_user_options(); if( $active_theme && !empty($options) && $active != $options['active_theme'] ) { $options['active_theme'] = $active_theme; $this->update_user_options( 0, $this->options_key, $options ); } } } function get_themes( ) { return $this->themes; } function get_option( $slug ) { return $this->options[$this->get_option_name($slug)]; } function get_option_name( $slug ) { return $this->options_key . '_' . $slug; } function admin_scripts( ) { if( $this->is_edit_page() ) { wp_enqueue_script('jquery-shortkeys', ZEN_URL . '/js/jquery.shortkeys.js', array('jquery'), null, true); wp_enqueue_script('zen-js', ZEN_URL . '/js/zen.js', array('jquery', 'jquery-shortkeys'), null, true); $zen_options = $this->get_user_options(); $themes = $this->get_themes(); if( function_exists('json_encode') ) { $themes = json_encode($themes); } else { require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php"); $json_obj = new Moxiecode_JSON(); $themes = $json_obj->encode($themes); } $zen_options['themes'] = $themes; wp_localize_script('zen-js', 'zen_options', $zen_options); ?> is_edit_page() ) { wp_enqueue_style('zen-css', ZEN_URL . '/css/zen.css', false, false, 'all'); } if( $this->is_options_page() ) { wp_enqueue_style('zen-admin-css', ZEN_URL . '/css/zen-admin.css', false, false, 'all'); } } function is_edit_page( ) { global $pagenow; $edit_pages = array('post-new.php', 'post.php', 'page.php', 'page-new.php'); if( in_array($pagenow, $edit_pages) ) return true; else return false; } function is_options_page( ) { global $pagenow, $plugin_page; if( is_admin() && $pagenow == 'profile.php' ) return true; return false; } } add_action('init', 'zen_init'); function zen_init( ) { if( is_admin() ) { global $zen; $zen = new zen(); } } ?>