<?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;
}

function css_file_dropdown($args) {
	$themes = get_themes();
	$theme = get_current_theme();
	$stylesheets = $themes[$theme]['Stylesheet Files'];
	
	echo '<select name="'.$args['name'].'" >'."\n";
		
		echo '<option style="padding-right:10px;" value="">style.css</option>';
		foreach((array)$stylesheets as $stylesheet) {
			$stylesheet = basename($stylesheet);
			if($stylesheet == $args['selected']) $selected = 'selected';
			if($stylesheet != 'style.css')
			echo '<option value="'.$stylesheet.'" '.$selected.'>'. $stylesheet . '</option>'."\n";
		}
	
	echo '</select>'."\n";
}

// outputs the sidebar_alt.php file if the Split blog layout theme is chosen
function sidebar_alt() {
    if(get_theme_mod('blog_layout') == 'Split')
        include(TEMPLATEPATH."/sidebar_alt.php");
    else return;
}

// Outputs the correct div (with id) depending on the option chosen
function sp_content_div() {
    $div = get_theme_mod('blog_layout');
    if($div == 'Left') $div = 'right';
    elseif($div == 'Split') $div = 'split';
    else $div = 'left';
    echo '<div id="content'.$div.'">';
}

// turns 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; }
	}
}

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

// includes breadcrumb code
include(TEMPLATEPATH."/tools/breadcrumbs.php");

// includes write panel file for special boxes
include(TEMPLATEPATH."/tools/write-panel.php");

// include our custom widgets, if we're using 2.8 or above
global $wp_version;
if(version_compare($wp_version, '2.8', '>=')) {
	// includes the enews widget in the dashboard
	include(TEMPLATEPATH."/tools/enews.php");

	// includes the twitter widget in the dashboard
	include(TEMPLATEPATH."/tools/twitter.php");
}

if ( function_exists('register_sidebars') ) {
	register_sidebar(array('name'=>'Sidebar','before_title'=>'<h4>','after_title'=>'</h4>'));
	register_sidebar(array('name'=>'Sidebar Alt','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;
      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 "...";
        echo "&nbsp;<a rel='nofollow' href='";
        the_permalink();
        echo "'>".$more_link_text."</a>";
        echo "</p>";
   }
   else {
      echo "<p>";
      echo $content;
      echo "</p>";
   }
}

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