<?php

/*********For Localization**************/
load_theme_textdomain( 'klasik', get_template_directory().'/languages' );

$locale = get_locale();
$locale_file = get_template_directory()."/languages/$locale.php";
if ( is_readable($locale_file) )
    require_once($locale_file);
/*********End For Localization**************/

// counting the widgets in sidebar
function count_sidebar_widgets( $sidebar_id, $echo = true ) {
    $the_sidebars = wp_get_sidebars_widgets();
    if( !isset( $the_sidebars[$sidebar_id] ) )
        return __( 'Invalid sidebar ID' );
    if( $echo )
        echo count( $the_sidebars[$sidebar_id] );
    else
        return count( $the_sidebars[$sidebar_id] );
}

// The excerpt based on character
if(!function_exists("klasik_string_limit_char")){
	function klasik_string_limit_char($excerpt, $substr=0, $strmore = ""){
		$string = strip_tags(str_replace('...', '...', $excerpt));
		if ($substr>0) {
			$string = substr($string, 0, $substr);
		}
		if(strlen($excerpt)>=$substr){
			$string .= $strmore;
		}
		return $string;
	}
}
// The excerpt based on words
if(!function_exists("klasik_string_limit_words")){
	function klasik_string_limit_words($string, $word_limit){
	  $words = explode(' ', $string, ($word_limit + 1));
	  if(count($words) > $word_limit)
	  array_pop($words);
	  
	  return implode(' ', $words);
	}
}

/* Remove inline styles printed when the gallery shortcode is used.*/
function klasik_remove_gallery_css( $css ) {
	return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
}
add_filter( 'gallery_style', 'klasik_remove_gallery_css' );

/*Template for comments and pingbacks. */
if ( ! function_exists( 'klasik_comment' ) ) :
function klasik_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
		case '' :
	?>
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
		<div id="comment-<?php comment_ID(); ?>" class="con-comment">
		<div class="comment-author vcard">
			<?php echo get_avatar( $comment, 40); ?>
		</div><!-- .comment-author .vcard -->


		<div class="comment-body">
			<?php  printf( __( '%s ', 'klasik' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
            <span class="time">
               <?php
                /* translators: 1: date, 2: time */
                printf( __( '%1$s %2$s', 'klasik' ), get_comment_date(),  get_comment_time() ); ?>
                <?php edit_comment_link( __( '/&nbsp;Edit', 'klasik' ), ' ' );?> <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ,'reply_text' => '/&nbsp;Reply') ) ); ?>
            </span>
			<div class="commenttext">
			<?php comment_text(); ?>
			<?php if ( $comment->comment_approved == '0' ) : ?>
				<em><?php _e( 'Your comment is awaiting moderation.', 'klasik' ); ?></em>
			<?php endif; ?>
			</div>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div><!-- #comment-##  -->

	<?php
			break;
		case 'pingback'  :
		case 'trackback' :
	?>
	<li class="post pingback">
		<p><?php _e( 'Pingback:', 'klasik' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'klasik'), ' ' ); ?></p>
	<?php
			break;
	endswitch;
}
endif;


/* social icon */
if (!function_exists('klasik_socialicon')){
	function klasik_socialicon(){
		
		$socialfolder = get_template_directory_uri() . '/images/social/';

		$outputli = "";
		$twitterlink = klasik_get_option( 'klasik_twitter_link', "" );
		if($twitterlink!=""){
			$twittericon = $socialfolder . "twitter.png" ;
			$outputli .= '<li><a href="'.$twitterlink.'"><span class="icon-img" style="background-image:url('.$twittericon.')"></span></a></li>'."\n";
		}
		
		$facebooklink = klasik_get_option( 'klasik_facebook_link', "" );
		if($facebooklink!=""){
			$facebookicon = $socialfolder . "fb.png" ;
			$outputli .= '<li><a href="'.$facebooklink.'"><span class="icon-img" style="background-image:url('.$facebookicon.')"></span></a></li>'."\n";
		}
		
		$gpluslink = klasik_get_option( 'klasik_googleplus_link', "" );
		if($gpluslink!=""){
			$gplusicon = $socialfolder . "googleplus.png" ;
			$outputli .= '<li><a href="'.$gpluslink.'"><span class="icon-img" style="background-image:url('.$gplusicon.')"></span></a></li>'."\n";
		}
		
		$pinterestlink = klasik_get_option( 'klasik_pinterest_link', "" );
		if($pinterestlink!=""){
			$pinteresticon = $socialfolder . "pinterest.png" ;
			$outputli .= '<li><a href="'.$pinterestlink.'"><span class="icon-img" style="background-image:url('.$pinteresticon.')"></span></a></li>'."\n";
		}
		
		$socialcustom = klasik_get_option( 'klasik_socialicon_custom', "" );
		if($socialcustom!=""){
			$outputli .= $socialcustom."\n";
		}
		
		$output = "";
		if($outputli!=""){
			$output .= '<ul class="sn">';
			$output .= $outputli;
			$output .= '</ul>';
		}
		return $output;
	}
}//end if(!function_exists('klasik_get_socialicon'))

/*Prints HTML with meta information for the current post (category, tags and permalink).*/
if ( ! function_exists( 'ts_posted_in' ) ) :
function ts_posted_in() {
	// Retrieves tag list of current post, separated by commas.
	$tag_list = get_the_tag_list( '', ', ' );
	if ( $tag_list ) {
		$posted_in = __( 'Categories: %1$s <br/> Tags: %2$s', 'klasik' );
	} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
		$posted_in = __( 'Categories: %1$s', 'klasik' );
	} else {
		$posted_in = __( '', 'klasik' );
	}
	// Prints the string, replacing the placeholders.
	printf(
		$posted_in,
		get_the_category_list( ', ' ),
		$tag_list,
		get_permalink(),
		the_title_attribute( 'echo=0' )
	);
}
endif;

/* for top menu */
function nav_page_fallback() {
if(is_front_page()){$class="current_page_item";}else{$class="";}
print '<ul id="topnav" class="sf-menu"><li class="'.$class.'"><a href=" '.home_url( '/') .' " title=" '.__('Click for Home','klasik').' ">'.__('Home','klasik').'</a></li>';
    wp_list_pages( 'title_li=&sort_column=menu_order' );
print '</ul>';
}

/* for shortcode widget  */
add_filter('widget_text', 'do_shortcode');
?>