<?php
$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 (($ty_sub4settings["ty_blogmain_homeblog_rdo"]) == 2) {
	
echo '<style>.ty-blog-page {width:100%;}.ty1-blog-content{margin-left:4px;margin-right:4px;}.ty1-single-content{width: 100%;margin-left:0;margin-right:0;}.ty2-sidebox-homeposts,.ty1-single-content,.ty-banner728x90,.comments-area,{margin-left:0;},.zem_rp_wrap{margin:18px 0 !important;}</style>';

} else {

echo '<div class="ty1-all-sidebar">

';

if (!empty($ty_sub4settings["ty_blogsidebar_chk7"])) {
	dynamic_sidebar('sidebar-1');
	dynamic_sidebar('sidebar-2');
	dynamic_sidebar('sidebar-3');
}

if (!empty($ty_sub4settings["ty_blogsideads_1_cont"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-banner">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . stripslashes($ty_sub4settings["ty_blogsideads_1_title"]) . '</div>
		<div class="ty3-sb-cont">
			<div class="ty-banner-sidebar"><div>' . stripslashes($ty_sub4settings["ty_blogsideads_1_cont"]) . '</div></div>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (empty($ty_sub4settings["ty_blogsidebar_chk1"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-cats">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . (empty($ty_sub4settings["ty_blogsidebar_cattitle"])? 'دسته بندی ها' : stripslashes($ty_sub4settings["ty_blogsidebar_cattitle"])) . '</div>
		<div class="ty3-sb-cont">
			<ul ' . (empty($ty_sub4settings["ty_blogsidebar_catrss_chk"])? 'style="padding-left:0;"' : null) . '>
				'; wp_list_cats('' . (!empty($ty_sub4settings["ty_blogsidebar_catrss_chk"])? 'feed_image=' . stripslashes($ty_sub4settings["ty_blogsidebar_catrssimg"]) . '&feed=RSS' : null) . '&' . (!empty($ty_sub4settings["ty_blogsidebar_catnum_chk"])? 'optioncount=1' : null) . '&children=0&number=' . stripslashes($ty_sub4settings["ty_blogsidebar_catnum"]) . ''); echo '
			</ul>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (!empty($ty_sub4settings["ty_blogsideads_2_cont"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-banner">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . stripslashes($ty_sub4settings["ty_blogsideads_2_title"]) . '</div>
		<div class="ty3-sb-cont">
			<div class="ty-banner-sidebar"><div>' . stripslashes($ty_sub4settings["ty_blogsideads_2_cont"]) . '</div></div>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (empty($ty_sub4settings["ty_blogsidebar_chk2"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-search">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . (empty($ty_sub4settings["ty_blogsidebar_searchtitle"])? 'جستجو در بلاگ' : stripslashes($ty_sub4settings["ty_blogsidebar_searchtitle"])) . '</div>
		<div class="ty3-sb-cont">
			<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
				<label>
					<input type="search" class="search-field" name="s" />
				</label>
				<button type="submit" class="search-submit">جستجو</button>
			</form>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (!empty($ty_sub4settings["ty_blogsideads_3_cont"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-banner">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . stripslashes($ty_sub4settings["ty_blogsideads_3_title"]) . '</div>
		<div class="ty3-sb-cont">
			<div class="ty-banner-sidebar"><div>' . stripslashes($ty_sub4settings["ty_blogsideads_3_cont"]) . '</div></div>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (empty($ty_sub4settings["ty_blogsidebar_chk3"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-posts">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . (empty($ty_sub4settings["ty_blogsidebar_posttitle"])? 'آخرین مطالب' : stripslashes($ty_sub4settings["ty_blogsidebar_posttitle"])) . '</div>
		<div class="ty3-sb-cont">
			<ul>
				';
				query_posts('showposts=' . stripslashes($ty_sub4settings["ty_blogsidebar_postnum"]) . '');
					while (have_posts()) : the_post();
					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></li>';
					endwhile;
				echo '
			</ul>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (!empty($ty_sub4settings["ty_blogsideads_4_cont"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-banner">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . stripslashes($ty_sub4settings["ty_blogsideads_4_title"]) . '</div>
		<div class="ty3-sb-cont">
			<div class="ty-banner-sidebar"><div>' . stripslashes($ty_sub4settings["ty_blogsideads_4_cont"]) . '</div></div>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (empty($ty_sub4settings["ty_blogsidebar_chk4"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-comments">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . (empty($ty_sub4settings["ty_blogsidebar_commtitle"])? 'آخرین نظرات' : stripslashes($ty_sub4settings["ty_blogsidebar_commtitle"])) . '</div>
		<div class="ty3-sb-cont">
			<ul>
				';
				global $wpdb;
				$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
				comment_post_ID, comment_author, comment_date_gmt, comment_approved,
				comment_type,comment_author_url,
				SUBSTRING(comment_content,1,30) AS com_excerpt
				FROM $wpdb->comments
				LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
				$wpdb->posts.ID)
				WHERE comment_approved = '1' AND comment_type = '' AND
				post_password = ''
				ORDER BY comment_date_gmt DESC
				LIMIT " . stripslashes($ty_sub4settings["ty_blogsidebar_commnum"]) . "";
				$comments = $wpdb->get_results($sql);
				foreach($comments as $comm) :
				echo '<li>'; echo($comm->comment_author . ' : <a href="' . get_the_permalink($comm->ID) . '#comment-' . $comm->comment_ID . '" title="در مطلب : ' . $comm->post_title . '">' . $comm->com_excerpt . '' ); echo'</a></li>';
				endforeach;
				echo '
			</ul>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (!empty($ty_sub4settings["ty_blogsideads_5_cont"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-banner">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . stripslashes($ty_sub4settings["ty_blogsideads_5_title"]) . '</div>
		<div class="ty3-sb-cont">
			<div class="ty-banner-sidebar"><div>' . stripslashes($ty_sub4settings["ty_blogsideads_5_cont"]) . '</div></div>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (empty($ty_sub4settings["ty_blogsidebar_chk5"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-archives">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . (empty($ty_sub4settings["ty_blogsidebar_archtitle"])? 'آرشیو' : stripslashes($ty_sub4settings["ty_blogsidebar_archtitle"])) . '</div>
		<div class="ty3-sb-cont">
			<ul>
				';
				wp_get_archives('type=' . stripslashes($ty_sub4settings["ty_blogsidebar_archtype"]) . '&limit=' . stripslashes($ty_sub4settings["ty_blogsidebar_archnum"]) . '');
				echo '
			</ul>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (!empty($ty_sub4settings["ty_blogsideads_6_cont"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-banner">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . stripslashes($ty_sub4settings["ty_blogsideads_6_title"]) . '</div>
		<div class="ty3-sb-cont">
			<div class="ty-banner-sidebar"><div>' . stripslashes($ty_sub4settings["ty_blogsideads_6_cont"]) . '</div></div>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (empty($ty_sub4settings["ty_blogsidebar_chk6"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-tags">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . (empty($ty_sub4settings["ty_blogsidebar_tagtitle"])? 'برچسب ها' : stripslashes($ty_sub4settings["ty_blogsidebar_tagtitle"])) . '</div>
		<div class="ty3-sb-cont">
			<ul>
				';
				wp_tag_cloud('smallest=8&largest=18&number=' . stripslashes($ty_sub4settings["ty_blogsidebar_tagnum"]) . '');
				echo '
			</ul>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}

if (!empty($ty_sub4settings["ty_blogsideads_7_cont"])) {
	echo '
	<div class="ty2-sidebox ty2-sidebox-banner">
		<div class="ty3-sb-topbrdr"></div>
		<div class="ty3-sb-title">' . stripslashes($ty_sub4settings["ty_blogsideads_7_title"]) . '</div>
		<div class="ty3-sb-cont">
			<div class="ty-banner-sidebar"><div>' . stripslashes($ty_sub4settings["ty_blogsideads_7_cont"]) . '</div></div>
		</div>
		<div class="ty3-sb-bottbrdr"></div>
	</div>
	';
}
echo '
</div>
';

}


?>