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 3 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, see .
*/
define ('CHAM_ABSPATH', dirname(__FILE__));
require_once ( CHAM_ABSPATH . '/framework/filesystem.php' );
/**
* Sets the menu for theme settings.
*
* @hook action 'admin_menu'
* @return void
*/
function _cham_settings_menu() {
add_theme_page(__('Customize Chameleon Theme', 'chameleon'), 'Chameleon', 'edit_themes', 'chameleon', '_cham_settings_page');
}
add_action('admin_menu', '_cham_settings_menu');
/**
* Loads the settings page in Dashboard.
*
* @hook add_theme_page
* @return void
*/
function _cham_settings_page() {
global $cham_settings;
include ( dirname(__FILE__) .'/settings.php' );
}
/**
* Sets the favorites icon for blog and admin pages.
*
* @hook action 'wp_head' and 'admin_head'
* @return void
*/
function _cham_favicon() {
echo '';
}
/**
* Disables self pings.
* This will disabloe sending pings to our own blog.
*
* @author Michael D. Adams
* @link http://blogwaffe.com/2006/10/04/421/
* @version 0.2
* @hook action 'pre_ping'
* @param array $links Link list of URLs to ping.
*/
function _cham_disable_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
/**
* Sets the styles for the WordPress Gallery.
* As styles are included in CSS files, here we just start the DIV for gallery.
*
* @hook filter 'gallery_style'
* @param string $style Default WordPress styles
* @return string New theme styles
*/
function _cham_gallery_style( $style ) {
return '
';
}
add_filter('gallery_style', '_cham_gallery_style');
/**
* Filter to disable the default stylesheet for Alkivia plugins.
* The styles needed are included in the theme style, so don't need to load them again.
*
* @hook filter '{pluginID}_style_url
* @param $url Default stylesheed url
* @return string An empty string as URL to disable the default style.
*/
function _cham_disable_alkivia_styles( $url ) {
return '';
}
add_filter('akucom_style_url', '_cham_disable_alkivia_styles');
add_filter('pagelist_style_url', '_cham_disable_alkivia_styles');
add_filter('sideposts_style_url', '_cham_disable_alkivia_styles');
/**
* Filter to change the user theme style.
* If settingts allow users to change settings.
*
* @hook filter 'chameleon_style_url'
* @param string $palette Current style url
* @return string New palette url
*/
function _cham_user_palette( $palette ) {
if ( isset($_GET['theme-style']) && file_exists(dirname(__FILE__) . '/styles/' . strtolower($_GET['theme-style']) . '.css') ) {
$style = strtolower($_GET['theme-style']);
} elseif ( isset($_COOKIE['chameleon-style']) && file_exists(dirname(__FILE__) . '/styles/' . strtolower($_COOKIE['chameleon-style']) . '.css') ) {
$style = strtolower($_COOKIE['chameleon-style']);
} else {
$settings = get_option('chameleon_settings');
$style = $settings['style'];
}
setcookie('chameleon-style', $style, time() + 3600, '/');
$palette = get_bloginfo('template_directory') . "/styles/{$style}.css";
return $palette;
}
/**
* Redirects user to a new page.
* This is done if the custom field 'redirect' is defined as:
* + Filed Name: redirect
* + Field Value: New target URL.
*
* @return void
*/
function cham_redirect() {
global $post;
if ( is_page() || is_single() ) {
if ( $meta = get_post_meta($post->ID, 'redirect', true) ) {
wp_redirect($meta, 301);
exit;
}
}
}
/**
* Creates the header menu bar based on settings.
*
* @uses apply_filters() Calls the 'chameleon_pages_menu' hook on the menu page list.
* @uses apply_filters() Calls the 'register' hook on register/admin item.
* @uses apply_filters() Calls the 'loginout' hook on login/logout item.
* @return string HTML formated menu bar.
*/
function cham_menubar() {
$settings = get_option('chameleon_settings');
$menu = '