<?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 Module Latest in magazine homepage ###
*******************************************/
if ( !function_exists('ktz_module_latest') ) :
function ktz_module_latest() {	
	global $post;
	if ( get_theme_option ( 'ktz_latestmodule_activated' ) != '' ) :
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$numb_post = get_theme_option ('ktz_latestpost_number');
		$number_post = ( !empty($numb_post) ? $numb_post : 6 ); // returns true
		$args = array(
			'post_type' => 'post',
			'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="titlebox clearfix title-carousel"><h2>' . __('Latest post', ktz_theme_textdomain) . '</h2></div>';
		echo '<div class="featured-module">';
		echo '<div class="row">';
		echo '<div class="module-1 span4">';
		$count = 0; 
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		$count++; 
		if ( $count <= 1 ) {
		echo ktz_featured_img( 300, 200, 'thumbnail btn-box clearfix' ); // width, height, class
		echo '<div class="ktz-titlecust-big">';
		echo ktz_posted_title_a();
		echo '</div>';
		echo ktz_get_excerpt(20);
		echo '<div class="meta-content clearfix">';
		echo ktz_posted_on();		
		echo '<span class="borderview">/</span><span class="view">';
		echo ktz_getPostViews(get_the_ID());
		echo '</span>';
		echo '</div>';
		echo '</div>';
		echo '<div class="featured-related span4">';
		} else {
		echo '<div class="clearfix">';
		echo ktz_featured_img( 50, 50, 'thumbnail btn-box pull-left' ); // width, height, class
		echo ktz_posted_on();
		echo '<span class="borderview">/</span>';
		echo '<span class="view">';
		echo ktz_getPostViews(get_the_ID());
		echo '</span>';
		echo '<div class="ktz-titlecust"><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 1 in magazine homepage #######
*******************************************/
if ( !function_exists('ktz_module_1') ) :
function ktz_module_1() {	
	if ( get_theme_option ( 'ktz_catmodule_1' ) != '0' ) :
	$firstcount = 0; 
	$catopsi = get_theme_option ( 'ktz_catmodule_1' );
	if (is_array($catopsi))
	{
	foreach ( $catopsi as $categories ) : //FIX foreach with array. Huft...
	$firstcount++;
	global $post;
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$numb_post = get_theme_option ( 'ktz_catmodule_1_number' );
		$number_post = ( !empty($numb_post) ? $numb_post : 6 ); // returns true
		$args = array(
			'post_type' => 'post',
			'cat' => $categories,
			'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="titlebox clearfix title-carousel"><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="featured-module">';
		echo '<div class="row">';
		echo '<div class="module-1 span4">';
		$count = 0; 
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		$count++; 
		if ( $count <= 1 ) {
		echo ktz_featured_img( 300, 200, 'thumbnail btn-box clearfix' ); // width, height, class
		echo '<div class="ktz-titlecust-big">';
		echo ktz_posted_title_a();
		echo '</div>';
		echo ktz_get_excerpt(20);
		echo '<div class="meta-content clearfix">';
		echo ktz_posted_on();		
		echo '<span class="borderview">/</span><span class="view">';
		echo ktz_getPostViews(get_the_ID());
		echo '</span>';
		echo '</div>';
		echo '</div>';
		echo '<div class="featured-related span4">';
		} else {
		echo '<div class="clearfix">';
		echo ktz_featured_img( 50, 50, 'thumbnail btn-box pull-left clearfix' ); // width, height, class
		echo ktz_posted_on();
		echo '<span class="borderview">/</span><span class="view">';
		echo ktz_getPostViews(get_the_ID());
		echo '</span>';
		echo '<div class="ktz-titlecust"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo '</div>';
		} 
		endwhile;
		echo '</div></div></div>';
		endif;
		wp_reset_query();
	endforeach;
	}
	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' ) != '0' ) :
		$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 : 8 ); // 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="titlebox 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>';
		$count = 0; 
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		$count++; if ( $count <= 2 ) { 
		echo '<div class="wrapmodule-2 clearfix">';
		$permalink = get_permalink();
		echo ktz_featured_img( 70, 70, 'thumbnail btn-box pull-left' ); // width, height, class
		echo ktz_posted_on();		
		echo '<span class="borderview">/</span><span class="view">';
		echo ktz_getPostViews(get_the_ID());
		echo '</span>';
        echo '<div class="ktz-titlecust"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo ktz_get_excerpt(8);
		echo'</div>';
		echo'<a class="readmore-block" href="'. $permalink . '">' . __( '<strong>Read more</strong>', ktz_theme_textdomain ) . '</a>';
		} else { 
		echo '<div class="listmodule-2 clearfix">';
		$permalink = get_permalink();
        echo '<div class="ktz-titlecust"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
		echo'</div>';		
		}
		endwhile;
		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' ) != '0' ) :
		$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 : 7 ); // 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 titlebox 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 '<span class="borderview">/</span><span class="view">';
		echo ktz_getPostViews(get_the_ID());
		echo '</span>';
		echo '<div class="ktz-titlecust"><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 ticker in header
*******************************************/
if ( !function_exists('ktz_module_ticker') ) :
function ktz_module_ticker() {	
	global $post;
	if ( get_theme_option ( 'ktz_catmodule_4' ) != '0' ) :
		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
		$args = array(
			'post_type' => 'post',
			'cat' => get_theme_option('ktz_catmodule_4'),
			'orderby' => 'date',
			'order' => 'desc',
			'showposts' => 10,
			'post_status' => 'publish',
			'ignore_sticky_posts' => 1
		);
		$ktz_boxfeatquery = new WP_Query($args); 
		if ($ktz_boxfeatquery -> have_posts()) :
		echo '<div class="topticker pull-right clearfix">';
		echo'<ul id="listmodule-ticker">';
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		echo'<li>';
		echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a>';
		echo'</li>';
		endwhile;
		echo'</ul></div>';
		endif;
		wp_reset_query();
	endif;
	}
endif;

/*******************************************
# Add Module 5 in magazine homepage ####
*******************************************/
if ( !function_exists('ktz_module_5') ) :
function ktz_module_5() {	
	global $post;
	if ( get_theme_option ( 'ktz_catmodule_5' ) != '0' ) :
		$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">';
		$count = 0; 
		while ($ktz_boxfeatquery -> have_posts()) : $ktz_boxfeatquery -> the_post(); 
		$count++; if ( $count <= 1 ) { 
		echo'<li class="clearfix">';
		$permalink = get_permalink();
			echo '<div class="thumbnail2">';
		echo ktz_featured_img( 300, 200, 'clearfix' ); // width, height, class
			echo ktz_posted_on();		
			echo '<span class="borderview">/</span><span class="view">';
			echo ktz_getPostViews(get_the_ID());
			echo '</span>';
			echo '<div class="ktz-titlecust"><a href="' . get_permalink() . '" title="' . get_the_title() . '">'. get_the_title() . '</a></div>';
			echo '</div>';
		echo'</li>';
		} else { 
		echo'<li>';
		echo '<div class="ktz-titlecust"><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;