<?php
define('THEME_NICENAME','Calotropis');
define('THEME_URI','http://themes.itx.web.id/calotropis/');
define('THEME_VERSION', '1.5.1');

require_once 'includes/common.php';

function itx_content($pos=false){
    global $post;
?>
    <div <?php post_class($pos) ?>>
    <?php
	if ($pos=='featured'){add_filter('excerpt_length', 'itx_featured_length');$thumb=itx_thumbnail(1);$class='itx-featured';}
	else {add_filter('excerpt_length', 'itx_excerpt_length');$thumb=itx_thumbnail();$class='itx-thumb';}
        if(itx_get_option('front','not')||$thumb) $tclass='thumb'; else $tclass='nothumb';
    ?>
        <div class="postwrap <?php echo $tclass?>">
	    <div class="thumbwrap">
			<div class="<?php echo $class ?>">
				<?php echo $thumb;?>
			</div>
			<?php if (itx_is_active_meta('commentcount')||itx_is_active_meta('left')):?>
				<div class="meta">
					<?php itx_meta('left');?>
					<?php if (!post_password_required())itx_meta('commentcount'); ?>
				</div>
			<?php endif;?>
	    </div>
	    <div class="entry">
			<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
			<?php the_excerpt();?>
	    </div>
        </div>
    </div>
<?php if ($pos=='featured') echo '<div class="clear"></div>';
}

function itx_single_content($class=false){
   global $post;
?>
    <div <?php post_class($class) ?>>
        <div class="postwrap">
			<div class="titlewrap">
				<?php $thetitle=itx_single_title(); if ( !empty($thetitle) ) : ?>
				<?php if ( is_singular() && !is_front_page() ): ?>
				<h1>
					<a href="<?php the_permalink() ?>" rel="bookmark"><?php echo $thetitle; ?></a>
				</h1>
				<?php else: ?>
				<h3>
					<a href="<?php the_permalink() ?>" rel="bookmark"><?php echo $thetitle; ?></a>
				</h3>
				<?php endif;endif; ?>
				<?php if (itx_is_active_single_meta('commentcount')&&comments_open()):?>
					<?php if(!post_password_required()) itx_single_meta('commentcount');?>
					<div class="clear"></div>
				<?php endif;?>
				<?php if (!is_page()) itx_single_meta('date');?>
				<?php itx_single_meta('author');?>
			</div>
            <div class="clear"></div>
			<small><?php edit_post_link('Edit this entry?','',''); ?></small>
			<div class="clear"></div>
            <div class="entry">
				<?php the_content();?>
            </div>
            <div class="clear"></div>
            <span class="linkpages"><?php wp_link_pages(); ?></span>
            <div class="clear"></div>
            <?php if (itx_is_active_single_meta('categories')||itx_is_active_single_meta('tags')||itx_is_active_single_meta('author_info')): ?>
            <div class="footmeta">
                <?php itx_single_meta('categories');itx_single_meta('tags');itx_single_meta('author_info');?>
            </div>
            <?php endif; ?>
            <div class="clear"></div>
        </div>
        <?php if (is_singular())comments_template('',true); ?>
    </div>
<?php
}

function itx_line_content($class=false){
   global $post;
?>
    <div <?php post_class($class) ?>>
	<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
	<?php if (itx_is_active_meta('commentcount')||itx_is_active_meta('left')):?>
	<div class="meta">
		<?php itx_meta('left');?>
		<?php if (!post_password_required()) itx_meta('commentcount');?>
	</div>
	<?php endif;?>
    </div>
<?php
}

function itx_loop(){
	global $wp_query,$query_string;
	extract(itx_get_option('front'));
	if (is_archive()) $type=$archive_type;
	$column=itx_get_option('front','column');
	if (!is_paged()){
		itx_sidebar('name=innertop');
		if ($type=='fe'||$type=='fl'){
		if (have_posts()){itx_title();the_post(); itx_content('featured');}
		if ($wp_query->post_count<2) $nosearch=1;
		}
	}

	if ($type=='fe'||$type=='fl'){
		$sticky=get_option('sticky_posts');
		if(!$sticky){
			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
			$offset=array('offset'=>(($paged-1)*get_query_var('posts_per_page')+1));
		} else {
			$offset=array('post__not_in'=>array($sticky[0]));
		}
		query_posts(array_merge($offset,$wp_query->query));
	}

	if (have_posts()) {
		if (!($type=='fe'||$type=='fl')||is_paged()){itx_title();}
		if ($type=='fl') echo '<div class="singlepost">';
		$i=0;
		while (have_posts()) {
			the_post();
			if ($type=='traditional') itx_single_content('singlepost');
			elseif ($type=='fl') itx_line_content('linepost');
			else {
				$i++;
				$postwrap=ceil($i/$column);
				itx_content('posts postwrap-'.$postwrap);
			}
		}
		if ($type=='fl') echo '</div>';
	} elseif (empty($nosearch)) itx_notfound();
	?>
	<div class="clear"></div>
	<?php if (!is_paged()){itx_sidebar('name=innerbottom');}
}

function itx_single_title(){
	if ( is_singular() && function_exists('ghpseo_output') ) return ghpseo_output('secondary_title',false);
	else return get_the_title();
}

function itx_title(){
	if (function_exists('ghpseo_output')) {
		$out=ghpseo_output('secondary_title',false);
		if(!empty($out)) {?><h2 class="pagetitle"><?php ghpseo_output('secondary_title');?></h2><?php }
	} elseif (is_archive()) {
		?><h2 class="pagetitle"><?php
			if (is_category()) { 
				printf( __( 'Category Archives: %s', 'itx' ), '<span>' . single_cat_title( '', false ) . '</span>' );
			} elseif( is_tag() ) {
				printf( __( 'Tag Archives: %s', 'itx' ), '<span>' . single_tag_title( '', false ) . '</span>' );
			} elseif (is_author()) {
				the_post();
				printf( __( 'Author Archives: %s', 'itx' ), "<span class='vcard'><a class='url fn n' href='" . get_author_posts_url( get_the_author_meta( 'ID' ) ) . "' title='" . esc_attr( get_the_author() ) . "' rel='me'>" . get_the_author() . "</a></span>" );
			} elseif (is_day()) {
				printf( __( 'Daily Archives: <span>%s</span>', 'itx' ), get_the_date() );
			} elseif (is_month()) { 
				printf( __( 'Monthly Archives: <span>%s</span>', 'itx' ), get_the_date('F Y') );
			} elseif (is_year()) {
				printf( __( 'Yearly Archives: <span>%s</span>', 'itx' ), get_the_date('Y') );
			} else {
				_e( 'Blog Archives', 'itx' );
			}
		?> </h2> <?php
		if (is_author()){
			if ( get_the_author_meta( 'description' ) ){
				echo '<div class="author_info">'.
				get_avatar(get_the_author_meta('email'), 60);
				echo '<h3>';
				printf( __( 'About %s', 'itx' ), get_the_author() );
				echo '</h3><div>'.get_the_author_meta('description').'</div>';
				echo '<div class="clear"></div></div>';
			}
			rewind_posts();
		}
	} 
}

function itx_notfound(){
	global $post;
    if (is_search()) {
        $something ='<strong>'.get_search_query().'</strong>';
        $here='again';
    } else {
        $something="something";
        $here='here';
    }
    ?>
    <div class="post">
	<h2 class="title"><a href="<?php the_permalink() ?>">Not Found</a></h2>
	<div class="clear"></div>
	<div>
	    <p>Sorry, but you are looking for <?php echo $something ?> that isn't here.
		You can search <?php echo $here ?>
	     <?php if (itx_active_widget('search')):?>
		by using <a href="#searchform">this form</a>...
	     <?php else: ?> using the form below <br />
		<?php get_search_form(); endif;?>
	    </p>
	</div>
    </div>
<?php
}

function itx_links(){?>
	<?php extract(itx_get_option('links'));?>
	<ul id="links">
		<?php if ($twitter): ?><li>
		<a href="http://twitter.com/<?php echo $twitter ?>" rel="nofollow">
			<img src="<?php echo get_template_directory_uri(); ?>/images/twitter.gif" alt ="my twitter" title="Follow our twitter" />
		</a></li>
		<?php endif;?>

		<?php if ($facebook): ?><li>
		<a href="http://www.facebook.com/<?php echo $facebook ?>" rel="nofollow">
			<img src="<?php echo get_template_directory_uri(); ?>/images/facebook.gif" alt ="my facebook" title="Follow our facebook" />
		</a></li>
		<?php endif;?>

		<?php if ($plurk): ?><li>
		<a href="http://www.plurk.com/<?php echo $plurk ?>" rel="nofollow">
			<img src="<?php echo get_template_directory_uri(); ?>/images/plurk.gif" alt ="my plurk" title="Follow our plurk" />
		</a></li>
		<?php endif;?>

		<?php if(empty($hide_rss)):?>
		<li><a href="<?php echo $rss ?>">
			<img src="<?php echo get_template_directory_uri(); ?>/images/rss.gif" alt="<?php bloginfo('name'); ?>" title="Follow our RSS" />
		</a></li>
		<?php endif;?>
	</ul>
	<?php
}

?>