<?php

// Uncomment this to test your localization, make sure to enter the right language code.
// function test_localization( $locale ) {
// 	return "nl_NL";
// }
// add_filter('locale','test_localization');

load_theme_textdomain('studiopress', TEMPLATEPATH.'/languages/');

add_filter('comments_template', 'legacy_comments');

function legacy_comments($file) {

	if(!function_exists('wp_list_comments')) : // WP 2.7-only check
		$file = TEMPLATEPATH . '/legacy.comments.php';
	endif;

	return $file;
}

// Turn a category ID to a Name
function cat_id_to_name($id) {
	foreach((array)(get_categories()) as $category) {
    	if ($id == $category->cat_ID) { return $category->cat_name; break; }
	}
}

// Load the scripts
if(get_theme_mod('subnav') == 'Yes') { 
	wp_enqueue_script('subnav', get_bloginfo('template_url').'/js/subnav.js','','1.0',true);
} else { 
	wp_enqueue_script('nav', get_bloginfo('template_url').'/js/nav.js','','1.0',true);
}
if(get_theme_mod('tabber') == 'Yes') { 
	wp_enqueue_script('tabber', get_bloginfo('template_url').'/js/tabber.js','','1.0',true);
}

// include the breadcrumb nav tool
include(TEMPLATEPATH."/tools/breadcrumbs.php");

// include the theme options
include(TEMPLATEPATH."/tools/theme-options.php");

if ( function_exists('register_sidebars') )
	register_sidebar(array('name'=>'Sidebar Right','before_title'=>'<h4>','after_title'=>'</h4>'));

function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = strip_tags($content);

   if (strlen($_GET['p']) > 0) {
      echo "<p>";
      echo $content;
		if ($more_link_text != '') {
	      echo "&nbsp;<a rel='nofollow' href='";
	      the_permalink();
	      echo "'>".__('Read More', 'studiopress')." &rarr;</a>";
		}
      echo "</p>";
   }
   else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content;
        echo "<p>";
        echo $content;
        echo "...";
		if ($more_link_text != '') {
        	echo "&nbsp;<a rel='nofollow' href='";
        	the_permalink();
        	echo "'>".$more_link_text."</a>";
		}
        echo "</p>";
   }
   else {
      echo "<p>";
      echo $content;
		if ($more_link_text != '') {
	      echo "&nbsp;<a rel='nofollow' href='";
	      the_permalink();
	      echo "'>".__('Read More', 'studiopress')." &rarr;</a>";			
		}
      echo "</p>";
   }
}

function sp_widget() {
    require_once(ABSPATH.WPINC.'/rss.php'); 
    if ( $rss = fetch_rss( 'http://feeds2.feedburner.com/studiopress' ) ) {
        $content = '<div class="rss-widget>"';
        $content .= '<p style="border-bottom: 1px solid #ccc; padding-bottom: 10px; font-weight: bold;"><a rel="nofollow" href="http://www.studiopress.com/themes/pro-plus">Upgrade now to the Pro Plus All-Theme package for only $140 --></a <br /> <small>(Use PPUPG as the discount code when you are on the shopping cart page.)</small></p>';
        $content .= '<ul>';
        foreach ( array_slice( $rss->items, 0, 5 ) as $item ) {
            $content .= '<li>';
            $content .= '<a class="rsswidget" href="'.esc_url( $item['link'] ).'">'.htmlentities( $item['title'] ).'</a>';
            $content .= ' <span class="rss-date">'.date('F j, Y',strtotime($item['published'])).'</span>';
            $content .= '<div class="rssSummary">'.htmlentities( $item['summary'] ).'</div>';
            $content .= '</li>';
        }
        $content .= '</ul>';
		$content .= '<p style="border-top: 1px solid #ccc; padding-top: 10px; font-weight: bold;"><a target="_blank" href="http://feeds2.feedburner.com/studiopress"><img style="vertical-align:middle;margin:0px 3px 3px 0px;" src="http://www.studiopress.com/images/rss.png" alt="Subscribe to StudioPress" /></a><a target="_blank" href="http://feeds2.feedburner.com/studiopress">Subscribe to RSS</a><a target="_blank" href="http://feedburner.google.com/fb/a/mailverify?uri=studiopress"></a>&nbsp;&nbsp;<img style="vertical-align:middle;margin:0px 3px 3px 0px;" src="http://www.studiopress.com/images/rss.png" alt="Subscribe to StudioPress" /></a><a target="_blank" href="http://feedburner.google.com/fb/a/mailverify?uri=studiopress">Subscribe via Email</a></p>';
        $content .= '</div>';
        echo $content;
    }
}
 
function sp_widget_setup() {
    wp_add_dashboard_widget( 'sp_db_widget' , 'The Latest News From StudioPress' , 'sp_widget');
}
 
add_action('wp_dashboard_setup', 'sp_widget_setup');  

// Remove WP Generator for security reasons
remove_action('wp_head', 'wp_generator');
?>