<?php
/********** start getoptionspages **********/

$ty_settings = get_option( "ty_theme_settings" );
$ty_sub1settings = get_option( "ty_theme_sub1settings" );
$ty_sub2settings = get_option( "ty_theme_sub2settings" );
$ty_sub3settings = get_option( "ty_theme_sub3settings" );
$ty_sub4settings = get_option( "ty_theme_sub4settings" );

/********** end getoptionspages **********/

/********** start numpages **********/

function ty_numpages( $query ) {
	
$ty_settings = get_option( "ty_theme_settings" );
$ty_sub1settings = get_option( "ty_theme_sub1settings" );
$ty_sub2settings = get_option( "ty_theme_sub2settings" );
$ty_sub3settings = get_option( "ty_theme_sub3settings" );
$ty_sub4settings = get_option( "ty_theme_sub4settings" );

    if( ! is_admin()
        && $query->is_main_query() ) {
            $query->set( 'posts_per_page', '' . empty($ty_sub4settings["ty_blogposts_homeposts_num"])? '6' : stripslashes($ty_sub4settings["ty_blogposts_homeposts_num"]) . '' );
    }
}
add_action( 'pre_get_posts', 'ty_numpages' );

/********** end numpages **********/

/********** start bitpart **********/

function blogallposts() {
	
$ty_settings = get_option( "ty_theme_settings" );
$ty_sub1settings = get_option( "ty_theme_sub1settings" );
$ty_sub2settings = get_option( "ty_theme_sub2settings" );
$ty_sub3settings = get_option( "ty_theme_sub3settings" );
$ty_sub4settings = get_option( "ty_theme_sub4settings" );
	
if ( is_single() ) {
	echo '<div class="ty1-blog-content ty1-single-content">';
} else {
	echo '
	<div class="ty1-blog-content">
	';
}
	echo '
		<div class="ty2-b-thum">
		' . ((has_post_thumbnail())? get_the_post_thumbnail() : '<img src="' . get_template_directory_uri() . '/tyblue-files/tyimg4.png" alt="" />') . '
		
		';
		if (empty($ty_sub4settings["ty_blogposts_chk2"])) {
			echo '
			<script type="text/javascript">
				function goNewWin() {
				TheNewWin=window.open("' . site_url() . '","TheNewpop","toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1");
				TheNewWin.blur(); }
				function facebook(url) {
				window.open("http://www.facebook.com/share.php?u="+url, "mywindow", "width=800, height=500, scrollbars=auto"); }
				function twitter(title, url) {
				window.open("https://twitter.com/intent/tweet?source=webclient&text="+encodeURIComponent("مطلب مفید : "+title+" "+url+" .."), "mywindow", "width=800, height=500, scrollbars=auto"); }
				function google(url) {
				window.open("http://plus.google.com/share?url="+url, "mywindow", "width=800, height=500, scrollbars=auto"); }
			</script>
			<div style="text-align:center;" class="ty-allsocicons">
				  <span class="ty-asi-icon tyasi-facebook">
					<i class="fa fa-facebook" onclick="return facebook(\'' . get_the_permalink() . '\');" title="انتشار در فیس بوک"></i>
				  </span>
				  <span class="ty-asi-icon tyasi-twitter">
					<i class="fa fa-twitter" onclick="return twitter(\'' . get_the_title() . '\', \'' . get_the_permalink() . '\');" title="انتشار در توئیتر"></i>
				  </span>
				  <span class="ty-asi-icon tyasi-google">
					<i class="fa fa-google" onclick="return google(\'' . get_the_permalink() . '\');" title="انتشار در گوگل پلاس"></i>
				  </span>
			</div>
			';
		}
		echo '
		</div>
		';
		if ( !is_single() ) {
			echo '<div class="ty2-b-title"><h2><a href="' . get_the_permalink() . '">' . get_the_title() . '</a></h2></div>';
		}
		if (empty($ty_sub4settings["ty_blogposts_chk1"])) {
			echo do_shortcode( '[rate]' );
		}
		if ( is_single() ) {
			if (!empty($ty_sub4settings["ty_blogpagesads_4_cont"])) {echo '<div class="ty-banner728x90 tybnr72890-4"><div>' . stripslashes($ty_sub4settings["ty_blogpagesads_4_cont"]) . '</div></div>';}
			echo '<div class="ty2-b-con"><p>' . get_the_content() . '</p></div>';
			if (!empty($ty_sub4settings["ty_blogpagesads_5_cont"])) {echo '<div class="ty-banner336x280 tybnr336280-1"><div>' . stripslashes($ty_sub4settings["ty_blogpagesads_5_cont"]) . '</div></div>';}
			
		} else {
			echo '<div class="ty2-b-con"><p>' . get_excerpt() . '</p></div>';
		}
		echo '
		<div class="ty2-b-decbutt">
			<ul>
			';
			if (empty($ty_sub4settings["ty_blogposts_chk3"])) {
				echo '
				<li><a><i class="fa fa-calendar"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<p>' . get_the_time('j F Y') . ' - ' . get_the_time() . '</p>
						</li>
					</ol>
				</li>
				';
			}
			if (empty($ty_sub4settings["ty_blogposts_chk4"])) {
				echo '
				<li><a><i class="fa fa-paperclip"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<p>' . get_the_category_list(' ، ') . '</p>
						</li>
					</ol>
				</li>
				';
			}
			if (empty($ty_sub4settings["ty_blogposts_chk5"])) {
				echo '
				<li><a><i class="fa fa-pencil"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<a target="_blank" href="' . esc_url( home_url( '/' ) ) . 'index.php?author=' . get_the_author_ID() . '">' . get_the_author() . '</a>
						</li>
					</ol>
				</li>
				';
			}
			if (empty($ty_sub4settings["ty_blogposts_chk6"])) {
				echo '
				<li><a><i class="fa fa-commenting-o"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<p>'; comments_popup_link(__('0'), __('1'), __('%')); echo '</p>
						</li>
					</ol>
				</li>
				';
			}
			if (empty($ty_sub4settings["ty_blogposts_chk7"])) {
				echo '
				<li><a target="_blank"><i class="fa fa-rss"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<a target="_blank" href="' . get_the_permalink() . 'feed">RSS</a>
						</li>
					</ol>
				</li>
				';
			}
				$current_user = wp_get_current_user();
				if (user_can( $current_user, 'administrator' )) {
					echo '
					<li><a href="#"><i class="fa fa-pencil-square-o"></i></a>
						<ol class="ty3-bdb-ol">
							<li>
								<i class="fa fa-caret-down"></i>
								<a target="_blank" href="' . get_edit_post_link() . '">ویرایش</a>
							</li>
						</ol>
					</li>
					';
				}
			echo '
			</ul>
		</div>
		';
	if ( !is_single() ) {
		echo '<div class="ty2-b-more"><a href="' . get_the_permalink() . '">ادامه...</a></div>';
	}
	echo '
	</div>
	';
}
function blogpartposts() {
	
$ty_settings = get_option( "ty_theme_settings" );
$ty_sub1settings = get_option( "ty_theme_sub1settings" );
$ty_sub2settings = get_option( "ty_theme_sub2settings" );
$ty_sub3settings = get_option( "ty_theme_sub3settings" );
$ty_sub4settings = get_option( "ty_theme_sub4settings" );
	
	echo '
	<li>
	<a href="' . get_the_permalink() . '">' . ((has_post_thumbnail())? get_the_post_thumbnail() : '<img src="' . get_template_directory_uri() . '/tyblue-files/tyimg4.png" alt="" />') . '</a>
	<a href="' . get_the_permalink() . '">
	' . get_the_title() . '
	</a>
	<div class="ty2-b-decbutt ty2-b-decbuttpart">
			<ul>
				';
			if (empty($ty_sub4settings["ty_blogposts_chk3"])) {
				echo '
				<li><a><i class="fa fa-calendar"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<p>' . get_the_time('j F Y') . ' - ' . get_the_time() . '</p>
						</li>
					</ol>
				</li>
				';
			}
			if (empty($ty_sub4settings["ty_blogposts_chk4"])) {
				echo '
				<li><a><i class="fa fa-paperclip"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<p>' . get_the_category_list(' ، ') . '</p>
						</li>
					</ol>
				</li>
				';
			}
			if (empty($ty_sub4settings["ty_blogposts_chk5"])) {
				echo '
				<li><a><i class="fa fa-pencil"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<a target="_blank" href="' . esc_url( home_url( '/' ) ) . 'index.php?author=' . get_the_author_ID() . '">' . get_the_author() . '</a>
						</li>
					</ol>
				</li>
				';
			}
			if (empty($ty_sub4settings["ty_blogposts_chk6"])) {
				echo '
				<li><a><i class="fa fa-commenting-o"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<p>'; comments_popup_link(__('0'), __('1'), __('%')); echo '</p>
						</li>
					</ol>
				</li>
				';
			}
			if (empty($ty_sub4settings["ty_blogposts_chk7"])) {
				echo '
				<li><a target="_blank"><i class="fa fa-rss"></i></a>
					<ol class="ty3-bdb-ol">
						<li>
							<i class="fa fa-caret-down"></i>
							<a target="_blank" href="' . get_the_permalink() . 'feed">RSS</a>
						</li>
					</ol>
				</li>
				';
			}
				$current_user = wp_get_current_user();
				if (user_can( $current_user, 'administrator' )) {
					echo '
					<li><a href="#"><i class="fa fa-pencil-square-o"></i></a>
						<ol class="ty3-bdb-ol">
							<li>
								<i class="fa fa-caret-down"></i>
								<a target="_blank" href="' . get_edit_post_link() . '">ویرایش</a>
							</li>
						</ol>
					</li>
					';
				}
			echo '
			</ul>
		</div>
	</li>
	';
}

/********** end bitpart **********/


?>