<?php
/*
/*-----------------------------------------------*/
/* KENTOOZ FRAMEWORK FOR MODULE MAGAZINE
/* Website: kentooz.com
/* The Author: Gian Mokhammad Ramadhan 
/* Social network :twitter.com/g14nnakal facebook.com/gianmr
/* Version :1.0
/*-----------------------------------------------*/

// Do not load directly...
if ( ! defined( 'ABSPATH' ) ) { die( 'Direct access forbidden.' ); }

/*******************************************
# Add Featured post on top below menu
*******************************************/
if ( !function_exists('ktz_top_feat') ) :
function ktz_top_feat() {	
	global $post;
	if ( get_theme_option ( 'ktz_topfeat_active' ) != '') :
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$args = array(
			'post_type' => 'post',
			'cat' => get_theme_option('ktz_topfeat_cat'),
			'orderby' => get_theme_option('ktz_topfeat_orderby'),
			'order' => 'desc',
			'showposts' => 5,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_topfeatquery = new WP_Query($args); 
		echo '<ul id="top-ticker">';
		if ($ktz_topfeatquery -> have_posts()) : while ($ktz_topfeatquery -> have_posts()) : $ktz_topfeatquery -> the_post();
		echo '<li>';
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</li>';
		endwhile; 
		endif;
		echo'</ul>';
	wp_reset_query();
	endif;
	}
endif;

/*******************************************
# Add Module 1 in magazine homepage ####
*******************************************/
if ( !function_exists('ktz_module_1') ) :
function ktz_module_1() {	
	global $post;
	if ( get_theme_option ( 'ktz_catmodule_1' ) != '' ) :
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$args = array(
			'post_type' => 'post',
			'cat' => get_theme_option('ktz_catmodule_1'),
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => 3,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="featured-module">';
		echo '<div class="module-1">';
		$count = 0; 
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		$count++; 
		if ( $count <= 1 ) {
		echo ktz_featured_just_img( 300, 300 );
		echo ktz_posted_on();
		echo '<div class="ktz-title-big"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo ktz_get_excerpt(20);
		echo '<div class="featured-titlerelated">';
		echo __('Related post', ktz_theme_textdomain);
		echo '</div>';
		echo '<div class="featured-related clearfix">';

		} else {
		echo '<div>';
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</div>';
		} 
		endwhile;
		echo '</div></div></div>';
		endif;
		wp_reset_query();
	endif;
	}
endif;

/*******************************************
# Add Module 2 in magazine homepage ####
*******************************************/
if ( !function_exists('ktz_module_2') ) :
function ktz_module_2() {	
	global $post;
	if ( get_theme_option ( 'ktz_catmodule_2' ) != '' ) :
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$numb_post = get_theme_option ( 'ktz_catmodule_2_number' );
		$number_post = ( !empty($numb_post) ? $numb_post : 5 ); // returns true
		$args = array(
			'post_type' => 'post',
			'cat' => get_theme_option('ktz_catmodule_2'),
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => $number_post,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="moduletitle-2 clearfix"><h2><a href="' . get_category_link( get_theme_option('ktz_catmodule_2') ) . '" title="' . get_cat_name( get_theme_option('ktz_catmodule_2') ) . '">' . get_cat_name( get_theme_option('ktz_catmodule_2') ) . '</a></h2><span class="feed-cat clearfix pull-right"><a href="' . get_category_feed_link ( get_theme_option( 'ktz_catmodule_2' ) ) . '" title="' . get_cat_name( get_theme_option('ktz_catmodule_2') ) . ' ' . __('RSS Feed',ktz_theme_textdomain) . '">&nbsp;</a></span></div>';
		echo '<div class="wrapmodule-2 clearfix">';
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
			echo ktz_posted_on();
			echo ktz_author_by();
		echo '<div class="ktz-title-big"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '<div class="module-2 clearfix">';
		echo '<span class="pull-left">';
		echo ktz_featured_just_img( 70, 70 );
		echo'</span>';
		echo ktz_get_excerpt(25);
		echo'</div>';
		endwhile;
		echo'</div>';
		endif;
		wp_reset_query();
	endif;
	}
endif;

/*******************************************
# Add Module 3 in magazine homepage ####
*******************************************/
if ( !function_exists('ktz_module_3') ) :
function ktz_module_3() {	
	global $post;
	if ( get_theme_option ( 'ktz_catmodule_3' ) != '' ) :
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$numb_post = get_theme_option ( 'ktz_catmodule_3_number' );
		$number_post = ( !empty($numb_post) ? $numb_post : 10 ); // returns true
		$args = array(
			'post_type' => 'post',
			'cat' => get_theme_option('ktz_catmodule_3'),
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => $number_post,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="moduletitle-3 clearfix"><h2><a href="' . get_category_link( get_theme_option('ktz_catmodule_3') ) . '" title="' . get_cat_name( get_theme_option('ktz_catmodule_3') ) . '">' . get_cat_name( get_theme_option('ktz_catmodule_3') ) . '</a></h2><span class="feed-cat clearfix pull-right"><a href="' . get_category_feed_link ( get_theme_option( 'ktz_catmodule_3' ) ) . '" title="' . get_cat_name( get_theme_option('ktz_catmodule_3') ) . ' ' . __('RSS Feed',ktz_theme_textdomain) . '">&nbsp;</a></span></div>';
		echo'<ul class="listmodule-3">';
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		echo'<li>';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo'</li>';
		endwhile;
		echo'</ul>';
		endif;
		wp_reset_query();
	endif;
	}
endif;

if ( !function_exists('ktz_module_4') ) :
function ktz_module_4() {	
	global $post;
	if ( get_theme_option ( 'ktz_catmodule_4' ) != '' ) :
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$numb_post = get_theme_option ( 'ktz_catmodule_4_number' );
		$number_post = ( !empty($numb_post) ? $numb_post : 10 ); // returns true
		$args = array(
			'post_type' => 'post',
			'cat' => get_theme_option('ktz_catmodule_4'),
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => $number_post,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="moduletitle-4 clearfix"><h2><a href="' . get_category_link( get_theme_option('ktz_catmodule_4') ) . '" title="' . get_cat_name( get_theme_option('ktz_catmodule_4') ) . '">' . get_cat_name( get_theme_option('ktz_catmodule_4') ) . '</a></h2><span class="feed-cat clearfix pull-right"><a href="' . get_category_feed_link ( get_theme_option( 'ktz_catmodule_4' ) ) . '" title="' . get_cat_name( get_theme_option('ktz_catmodule_4') ) . ' ' . __('RSS Feed',ktz_theme_textdomain) . '">&nbsp;</a></span></div>';
		echo'<ul id="listmodule-ticker">';
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		echo'<li>';
		echo '<span class="pull-left">';
		echo ktz_featured_just_img( 70, 70 );
		echo'</span>';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo'</li>';
		endwhile;
		echo'</ul>';
		endif;
		wp_reset_query();
	endif;
	}
endif;

/*******************************************
# Add Module 3 in magazine homepage ####
*******************************************/
if ( !function_exists('ktz_module_5') ) :
function ktz_module_5() {	
	global $post;
	if ( get_theme_option ( 'ktz_catmodule_5' ) != '' ) :
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$numb_post = get_theme_option ( 'ktz_catmodule_5_number' );
		$number_post = ( !empty($numb_post) ? $numb_post : 10 ); // returns true
		$args = array(
			'post_type' => 'post',
			'cat' => get_theme_option('ktz_catmodule_5'),
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => $number_post,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="module-5"><div class="moduletitle-5 clearfix"><h2><a href="' . get_category_link( get_theme_option('ktz_catmodule_5') ) . '" title="' . get_cat_name( get_theme_option('ktz_catmodule_5') ) . '">' . get_cat_name( get_theme_option('ktz_catmodule_5') ) . '</a></h2><span class="feed-cat clearfix pull-right"><a href="' . get_category_feed_link ( get_theme_option( 'ktz_catmodule_5' ) ) . '" title="' . get_cat_name( get_theme_option('ktz_catmodule_5') ) . ' ' . __('RSS Feed',ktz_theme_textdomain) . '">&nbsp;</a></span></div>';
		echo'<ul class="listmodule-5">';
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		echo'<li>';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo'</li>';
		endwhile;
		echo'</ul></div>';
		endif;
		wp_reset_query();
	endif;
	}
endif;

if ( !function_exists('ktz_module_footer') ) :
function ktz_module_footer() {	
	if ( get_theme_option ( 'ktz_catmodule_foot' ) != '' ) :
	echo '<div class="span4">';
	$firstcount = 0; 
	$catopsi = get_theme_option ( 'ktz_catmodule_foot' );
	foreach ( $catopsi as $categories ) : //FIX foreach with array. Huft...
	$firstcount++;
		global $post;
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$args = array(
			'post_type' => 'post',
			'cat' => $categories,
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => 3,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="moduletitle-foot clearfix"><h2><a href="' . get_category_link( $categories ) . '" title="' . get_cat_name( $categories ) . '">' . get_cat_name( $categories ) . '</a></h2><span class="feed-cat clearfix pull-right"><a href="' . get_category_feed_link ( $categories ) . '" title="' . get_cat_name( $categories ) . ' ' . __('RSS Feed',ktz_theme_textdomain) . '">&nbsp;</a></span></div>';
		echo '<div class="module-footer clearfix">';
		$count = 0; 
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		$count++; 
		if ( $count <= 1 ) {
		echo '<div class="main-modulefooter">';
		echo '<span class="pull-left">';
		echo ktz_featured_just_img( 70, 70 );
		echo'</span>';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</div>';
		} else {
		echo '<div class="related-modulefooter">';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</div>';
		} 
		endwhile;
		echo '</div>';
		endif;
		wp_reset_query();
	endforeach;
	echo '</div>';
	endif;
	}
endif;

if ( !function_exists('ktz_module_footer2') ) :
function ktz_module_footer2() {	
	if ( get_theme_option ( 'ktz_catmodule_foot2' ) != '' ) :
	echo '<div class="span4">';
	$firstcount = 0; 
	$catopsi = get_theme_option ( 'ktz_catmodule_foot2' );
	foreach ( $catopsi as $categories ) : //FIX foreach with array. Huft...
	$firstcount++;
		global $post;
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$args = array(
			'post_type' => 'post',
			'cat' => $categories,
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => 3,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="moduletitle-foot clearfix"><h2><a href="' . get_category_link( $categories ) . '" title="' . get_cat_name( $categories ) . '">' . get_cat_name( $categories ) . '</a></h2><span class="feed-cat clearfix pull-right"><a href="' . get_category_feed_link ( $categories ) . '" title="' . get_cat_name( $categories ) . ' ' . __('RSS Feed',ktz_theme_textdomain) . '">&nbsp;</a></span></div>';
		echo '<div class="module-footer clearfix">';
		$count = 0; 
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		$count++; 
		if ( $count <= 1 ) {
		echo '<div class="main-modulefooter">';
		echo '<span class="pull-left">';
		echo ktz_featured_just_img( 70, 70 );
		echo'</span>';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</div>';
		} else {
		echo '<div class="related-modulefooter">';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</div>';
		} 
		endwhile;
		echo '</div>';
		endif;
		wp_reset_query();
	endforeach;
	echo '</div>';
	endif;
	}
endif;

if ( !function_exists('ktz_module_footer3') ) :
function ktz_module_footer3() {	
	if ( get_theme_option ( 'ktz_catmodule_foot3' ) != '' ) :
	echo '<div class="span4">';
	$firstcount = 0; 
	$catopsi = get_theme_option ( 'ktz_catmodule_foot3' );
	foreach ( $catopsi as $categories ) : //FIX foreach with array. Huft...
	$firstcount++;
		global $post;
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$args = array(
			'post_type' => 'post',
			'cat' => $categories,
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => 3,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="moduletitle-foot clearfix"><h2><a href="' . get_category_link( $categories ) . '" title="' . get_cat_name( $categories ) . '">' . get_cat_name( $categories ) . '</a></h2><span class="feed-cat clearfix pull-right"><a href="' . get_category_feed_link ( $categories ) . '" title="' . get_cat_name( $categories ) . ' ' . __('RSS Feed',ktz_theme_textdomain) . '">&nbsp;</a></span></div>';
		echo '<div class="module-footer clearfix">';
		$count = 0; 
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		$count++; 
		if ( $count <= 1 ) {
		echo '<div class="main-modulefooter">';
		echo '<span class="pull-left">';
		echo ktz_featured_just_img( 70, 70 );
		echo'</span>';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</div>';
		} else {
		echo '<div class="related-modulefooter">';
		echo ktz_posted_on();
		echo '<div class="ktz-title-small"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</div>';
		} 
		endwhile;
		echo '</div>';
		endif;
		wp_reset_query();
	endforeach;
	echo '</div>';
	endif;
	}
endif;