This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 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, see . */ /** Include theme template */ require_once ( AK_CLASSES . '/abstract/theme.php' ); require_once ( AK_LIB . '/themes.php' ); require_once ( TEMPLATEPATH . '/includes/widget.php' ); /** * Theme main class. * * @uses akTheme * @package Alkivia * @subpackage Chameleon */ final class akChameleonTheme extends akThemeAbstract { /** * Class constructor. * * @return akChameleonTheme */ public function __construct() { parent::__construct('chameleon'); if ( $this->getOption('switch-styles') ) { add_action('ak_theme_widgets_init', array($this, 'registerWidgets')); } } /** * Load and configure the theme. * * @return void */ protected function moduleLoad() { if ( $this->getOption('switch-styles') && ! is_admin() ) { add_filter('ak_chameleon_palette', array($this, 'userPalette')); } if ( ! is_admin() ) { $js = '/js/dropdown.js'; if ( STYLESHEETPATH !== TEMPLATEPATH && file_exists(STYLESHEETPATH . $js) ) { $dropdown = get_stylesheet_directory_uri . $js; } else { $dropdown = get_template_directory_uri() . $js; } wp_register_script('ak_dropdown', $dropdown, array('jquery'), $this->getModData('Version')); wp_enqueue_script('ak_dropdown'); } $this->loadPalette(); } /** * Void theme Init. * @return void. */ protected function themeInit () {} /** * Void Theme Installation. * @return void */ protected function themeInstall () {} /** * Updates the theme (Renames options to new 2.0 settings) * * @return void */ protected function themeUpdate ( $version ) { if ( version_compare($version, '2.0', '<') ) { $old = $this->getOption(); $options = array( 'palette' => $old['style'], 'enable-selfping' => $old['self_ping'], 'allow-page-comments' => $old['page_comments'], 'disable-header-title' => $old['back_image'], 'menu-home' => $old['home_link'], 'menu-categories' => $old['cat_menu'], 'menu-categories-title' => $old['cat_title'], 'menu-set-categories' => $old['categories'], 'menu-login' => $old['login_link'], 'menu-admin' => $old['admin_link'], 'sidebar-pos' => $old['sidebar-pos'], 'switch-styles' => $old['switch_styles'], 'disable-tags' => $old['disable_tags'], 'sociable-plugin' => $old['sociable'], 'hide-theme-credits' => $old['no_credits'], 'author-pages' => $old['author'], 'navbar-pos' => $old['navbar'], 'widgetized-home' => $old['widgetized'], 'footer-text' => $old['footer'] ); if ( file_exists(AK_UPLOAD_DIR . '/theme_head.jpg') ) { $options['header-image'] = 'theme_head.jpg'; } $this->setNewOptions($options); } } /** * Default settings for Chameleon * * @return array Theme settings */ protected function defaultOptions() { return array( 'header-image' => '', 'disable-header-image' => '0', 'disable-header-title' => '0', 'disable-search-box' => '0', 'palette' => 'cafe', 'enable-selfping' => '0', 'allow-page-comments' => '1', 'menu-home' => '1', 'menu-categories' => '1', 'menu-categories-title' => '', 'menu-set-categories' => '', 'menu-exclude-pages' => '', 'menu-login' => '1', 'menu-admin' => '1', 'sidebar-pos' => 'right', 'switch-styles' => '0', 'disable-tags' => '0', 'sociable-plugin' => '0', 'hide-theme-credits' => '0', 'author-pages' => '1', 'navbar-pos' => 'bottom', 'widgetized-home' => '0', 'footer-text' => '© '. __('Copyright', 'aktheme') . date(' Y ') . get_bloginfo('name') .'. '. __('Some rights reserved.', 'aktheme') ); } /** * Registers theme widgets. * @return void */ public function registerWidgets() { register_widget('chameleonPalettes'); } /** * Sets admin menus on the 'Theme' admin section. * * @hook action 'admin_menu' * @access private * @return void */ function adminMenus() { add_theme_page( __('Customize Chameleon Theme', 'aktheme'), 'Chameleon', 'edit_themes', $this->ID, array($this, 'settingsAdmin')); } /** * Loads the settings admin page. * The admin settings page cannot be overriden by child themes, but can be extended via action hooks. * * @hook 'add_theme_page' * @access private * @return void */ function settingsAdmin() { if ( STYLESHEETPATH !== TEMPLATEPATH && file_exists(STYLESHEETPATH . '/includes/admin.php') ) { include ( STYLESHEETPATH .'/includes/admin.php' ); } else { include ( TEMPLATEPATH .'/includes/admin.php' ); } } /** * Loads palette style. * Palettes are searched in this locations order: Custom path, Child Theme, Parent Theme. * If specified palette is not found, will use the first found on parent theme. * * @uses apply_filters() Calls 'ak_chameleon_palette' on the palette name. * @uses apply_filters() Calls 'ak_chameleon_palette_url' on the palette url. * @return void */ private function loadPalette() { if ( is_admin() ) { return; // Palettes are only used for the frontend. } $style = apply_filters('ak_chameleon_palette' , $this->getOption('palette')) . '.css'; $custom_dir = $this->getOption('custom-palettes-dir'); $custom_url = $this->getOption('custom-palettes-url'); if ( false !== $custom_dir && false !== $custom_url && file_exists($custom_dir . '/' . $style) ) { $uri = $custom_url . '/' . $style; } elseif ( STYLESHEETPATH !== TEMPLATEPATH && file_exists(STYLESHEETPATH . '/styles/' . $style) ) { $uri = get_stylesheet_directory_uri() . '/styles/' . $style; } elseif ( file_exists( TEMPLATEPATH . '/styles/' . $style) ) { $uri = get_template_directory_uri() . '/styles/' . $style; } else { // Palette not found, take the first found on system. require_once ( AK_LIB . '/filesystem.php'); $palettes = ak_dir_content(TEMPLATEPATH . '/styles', 'extensions=css&tree=0&with_ext=0'); $uri = $uri = get_template_directory_uri() . '/styles/' . array_shift($palettes) .'.css'; } $style_url = apply_filters('ak_chameleon_palette_url', $uri); if ( ! empty($style_url) ) { wp_register_style('chameleon', $style_url, false, $this->getModData('Version')); wp_enqueue_style('chameleon'); } } /** * Register theme sidebars and front page widget areas. * * @return void */ protected function themeSideBars() { register_sidebar(array( 'name' => __('Wide Top', 'aktheme'), 'id' => 'wide_top' )); register_sidebar(array( 'name' => __('Narrow Left', 'aktheme'), 'id' => 'narrow_left' )); register_sidebar(array( 'name' => __('Narrow Right', 'aktheme'), 'id' => 'narrow_right' )); register_sidebar(array( 'name' => __('Wide Bottom', 'aktheme'), 'id' => 'wide_bottom' )); if ( $this->getOption('widgetized-home') ) { $this->homeSidebars(); } } /** * Register front-page widget areas. * * @return void */ private function homeSidebars() { register_sidebar(array( 'name' => __('Home Top', 'aktheme'), 'id' => 'home_top', )); register_sidebar(array( 'name' => __('Home Left', 'aktheme'), 'id' => 'home_left', )); register_sidebar(array( 'name' => __('Home Right', 'aktheme'), 'id' => 'home_right', )); } /** * Filter to change the user theme style. * If settingts allow users to change settings. * * @hook filter 'ak_chameleon_palette' * @access private * @param string $palette Current style url * @return string New palette url */ function userPalette( $palette ) { if ( isset($_GET['theme-style']) ) { $style = strtolower($_GET['theme-style']); } elseif ( isset($_COOKIE['chameleon-style']) ) { $style = strtolower($_COOKIE['chameleon-style']); } else { $style = ''; } if ( ! empty($style) ) { $custom_dir = $this->getOption('custom-palettes-dir'); if ( ( false !== $custom_dir && file_exists($custom_dir . '/' . $style.'.css') ) || file_exists(STYLESHEETPATH . '/styles/' . $style.'.css') || file_exists( TEMPLATEPATH . '/styles/' . $style.'.css') ) { $palette = $style; } setcookie('chameleon-style', $palette, time() + 3600, '/'); } return $palette; } }