<?php
define ('TEMPLATE_DOMAIN','freshy');
load_theme_textdomain(TEMPLATE_DOMAIN);
if ( function_exists('register_sidebar') ) {
$freshy_options = get_option('freshy_options');
if ($freshy_options['sidebar_left'] && $freshy_options['sidebar_right']) $sidebars = 2;
else $sidebars = 1;
register_sidebars($sidebars, array(
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="title">',
'after_title' => '</h2>',
));
}
add_action('widgets_init', 'freshy_widgets_init');
add_filter("mce_css", "freshy_editor_mce_css", 0);
add_filter("mce_buttons", "freshy_editor_mce_buttons", 0);
if (!class_exists('Nice_theme')) add_action('wp_head','freshy_head');
function freshy_editor_mce_css($stylesheets) {
$stylesheets = get_bloginfo('stylesheet_directory').'/content.css';
return $stylesheets;
}
function freshy_editor_mce_buttons($buttons) {
$buttons[] = "styleselect";
return $buttons;
}
function freshy_widgets_init()
{
register_sidebar_widget('Categories OR Pages', 'freshy_menu');
register_widget_control('Categories OR Pages', 'freshy_menu_control', 300, 90);
}
function freshy_head()
{
if (get_option('nt_file'))
{
print '<link rel="stylesheet" href="'.get_bloginfo('stylesheet_directory').'/'.get_option('nt_file').'" type="text/css" media="screen"/>';
}
}
function freshy_menu_control() {
$options = $newoptions = get_option('widget_categories');
if ( $_POST['categories-submit'] ) {
$newoptions['title'] = strip_tags(stripslashes($_POST['categories-title']));
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('widget_categories', $options);
}
$title = wp_specialchars($options['title']);
?>
<p><label for="categories-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="categories-title" name="categories-title" type="text" value="<?php print $title; ?>" /></label></p>
<input type="hidden" id="categories-submit" name="categories-submit" value="1" />
<?php
}
function freshy_widget_links($args) {
global $wpdb;
$title = empty($options['title']) ? __('Links') : $options['title'];
?>
<h2><?php print $before_widget.$before_title.$title.$after_title; ; ?></h2>
<ul>
<?php freshy_links_menu(); ?>
</ul>
<?php
}
function freshy_links_menu() {
global $wpdb;
$ver = substr(get_bloginfo('version'), 0, 3);
if (floatval($ver) <= 2)
{
$link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories");
foreach ($link_cats as $link_cat)
{ ?>
<li id="linkcat-<?php print $link_cat->cat_id; ?>"><?php print $link_cat->cat_name; ?>
<ul>
<?php wp_get_links($link_cat->cat_id); ?>
</ul>
</li>
<?php
}
}
else {
$link_cats = $wpdb->get_results("SELECT DISTINCT cat_name, category_id FROM $wpdb->categories INNER JOIN $wpdb->link2cat ON $wpdb->categories.cat_id=$wpdb->link2cat.category_id");
foreach ($link_cats as $link_cat)
{ ?>
<li id="linkcat-<?php print $link_cat->cat_id; ?>"><?php print $link_cat->cat_name; ?>
<ul>
<?php wp_get_links('category='.$link_cat->category_id.'&before=<li>&after=</li>&show_description=0&limit=100'); ?>
</ul>
</li>
<?php
}
}
}
function freshy_menu($args_pages='', $args_cats='') {
global $post, $wpdb, $cat, $ID, $notfound, $freshy_options;
$options = get_option('widget_categories');
$c = 0;
$h = 0;
if ($freshy_options['menu_rss'] == 1) $rss = '&feed_image='.get_bloginfo('stylesheet_directory').'/images/icons/feed-icon-10x10.gif';
$title = empty($options['title']) ? __('Navigation') : $options['title'];
if ($freshy_options['menu_type']=='auto') {
// page menu
if (($post->post_status=='static' || is_page()) && $notfound!='1' && $args_pages!='none') {
?>
<h2><?php print $title; ?></h2>
<ul>
<?php
wp_list_pages($args_pages.'&title_li=');
?>
</ul>
<?php
}
// cats & posts menu
else if (!is_page() && $notfound!='1' && $args_cats!='none') {
?>
<h2><?php print $title; ?></h2>
<ul>
<?php
wp_list_cats($args_cats.'&hierarchical=$h'.$rss);
?>
</ul>
<?php
}
// bad things happened but dispay something anyway
else {
?>
<h2><?php _e('Categories',TEMPLATE_DOMAIN); ?></h2>
<ul>
<?php wp_list_cats($args_cats.'&hierarchical=$h'.$rss); ?>
</ul>
<?php
}
}
else {
?>
<h2><?php _e('Pages',TEMPLATE_DOMAIN); ?></h2>
<ul>
<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
</ul>
<h2><?php _e('Categories',TEMPLATE_DOMAIN); ?></h2>
<ul>
<?php wp_list_cats($args_cats.'&optioncount=$c&hierarchical=$h'.$rss); ?>
</ul>
<?php
}
}
function freshy_get_page_root($id,$level=0)
{
$parents = array();
$curpost = get_post($id);
array_push($parents,$id);
while ($curpost->post_parent != 0) {
array_push($parents,$curpost->post_parent);
$curpost = get_post($curpost->post_parent);
}
$parents = array_reverse($parents);
if (class_exists('YammYamm')) $level = $level+1;
return $parents[$level];
}
function freshy_layout_class() {
global $freshy_options, $post;
$freshy_options = get_option('freshy_options');
$return ='';
$ids_right = explode(',',$freshy_options['hide_sidebar_posts']);
$ids_left = explode(',',$freshy_options['hide_sidebar_left_posts']);
if ($freshy_options['sidebar_left'] == 1 && in_array($post->ID, $ids_left) === FALSE) $return .= 'sidebar_left';
if ($freshy_options['sidebar_right'] == 1 && in_array($post->ID, $ids_right) === FALSE) $return .= ' sidebar_right';
return 'class="'.$return.'"';
}
// SET OPTIONS
$freshy_options=array();
$freshy_default_options=array();
freshy_set_options();
function freshy_set_options() {
global $freshy_options;
$freshy_default_options['first_menu_label']='Home';
$freshy_default_options['blog_menu_label']='Blog';
$freshy_default_options['last_menu_label']='Contact';
$freshy_default_options['last_menu_type']='';
$freshy_default_options['contact_email']='';
$freshy_default_options['contact_link']='';
$freshy_default_options['sidebar_left']=0;
$freshy_default_options['sidebar_right']=1;
$freshy_default_options['menu_type']='auto';
$freshy_default_options['args_pages']='sort_column=menu_order&title_li=';
$freshy_default_options['args_cats']='hide_empty=0&sort_column=name&optioncount=0&title_li=&hierarchical=1';
$freshy_default_options['menu_rss']=0;
$freshy_default_options['date']=1;
$freshy_default_options['time']=0;
$freshy_default_options['author']=1;
$freshy_default_options['header_search']=0;
$freshy_default_options['header_rss']=1;
$freshy_default_options['hide_sidebar_posts']='';
$freshy_default_options['hide_sidebar_left_posts']='';
$existing_options = get_option('freshy_options');
if (is_array($existing_options)) {
foreach ($existing_options as $key=>$val) {
$freshy_options[$key]=$val;
}
foreach ($freshy_default_options as $key=>$val) {
if (!$freshy_options[$key]) $freshy_options[$key]=$val;
}
}
else {
$freshy_options=$freshy_default_options;
update_option('freshy_options', $freshy_options);
}
}
// ADMIN
add_action('admin_menu', 'freshy_add_theme_page');
function freshy_add_theme_page() {
add_theme_page('Freshy Options', 'Freshy Options', 'edit_themes', basename(__FILE__), 'freshy_theme_page');
}
[ ... ]
?>
Alles anzeigen