<?php /**
 * Jthoor free theme v 1.0
 *
 * this site use free theme ffrom jthoor,com.
 *
 * @package 	Jthoor free theme * @copyright	Copyright (c) 2013-2014, Jthoor * @license		http://www.jthoor.com
 *
 * @since 		1.0
 */
 ?>
<?php    if( file_exists(get_template_directory().'/adminp/options.php') )
    include_once(get_template_directory().'/adminp/options.php');

  if( file_exists(get_template_directory().'/theme-options/general.php') )
    include_once(get_template_directory().'/theme-options/general.php');
           global $up_options;
        ?><?php              if ( function_exists('add_theme_support') )
add_theme_support('post-thumbnails');

function string_limit_words($string, $word_limit)
{
  $words = explode(' ', $string, ($word_limit + 1));
  if(count($words) > $word_limit)
  array_pop($words);
  return implode(' ', $words);
}


function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0";
    }
    return $count.' ';
}
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}


include('meta/meta.php');
$themename = "لوحة تحكم الاقسام ";
$shortname = "nt";
$categories = get_categories('hide_empty=0&orderby=name');
$wp_cats = array();
foreach ($categories as $category_list ) {
       $wp_cats[$category_list->cat_ID] = $category_list->cat_name;
}
array_unshift($wp_cats, "اختار القسم");
$options = array (
array( "name" => $themename." Options",
	"type" => "title"),
/******************************************/










/******************************************/

array( "name" => "إعدادات عامة", "type" => "section"),
array( "type" => "open"),


	array( "name" => "الاقسام التى تلغى من المقالاات الاساسية",
	"desc" => "	فى مربع المقالاات الرئيسية لالغاء ظهور قسم او اقسام يرجى وضع اى دى القيم كالتالى 	( -15,-90,-55 ) بدون اقواس	",
	"id" => $shortname."_shr_ex",
	"type" => "text",
	"std" => ""),



array( "name" => "شريط الاخبار",
	"desc" => "اختر المصدر بين last حيث سيتم اخيار اخر الاخبار وعرضعا او categry وستقوم باختيار القسم يدويا بالاسفل",
	"id" => $shortname."_shr_true",
	"type" => "select",
	"options" => array("last", "category"),
	"std" => "last"),
	array( "name" => "اقسم الذى يعرض فى الشريط",
	"desc" => "مفعل فقط فى حالة اختيار category من الاعلى",
	"id" => $shortname."_shr_cat",
	"type" => "select",
	"options" => $wp_cats,
	"std" => "اختار القسم"),
	array( "name" => "عدد شريط الاخبار",
	"desc" => "اختر عدد الاخبار للظهور",
	"id" => $shortname."_shr_num",
	"type" => "text",
	"std" => "10"),














array( "name" => "سلايدر الاخبار",
	"desc" => "اختر المصدر بين last حيث سيتم اخيار اخر الاخبار وعرضعا او categry وستقوم باختيار القسم يدويا بالاسفل",
	"id" => $shortname."_slider_true",
	"type" => "select",
	"options" => array("last", "category"),
	"std" => "last"),
	array( "name" => "اقسم الذى يعرض فى سلايدر الاخبار",
	"desc" => "مفعل فقط فى حالة اختيار category من الاعلى",
	"id" => $shortname."_slider_cat",
	"type" => "select",
	"options" => $wp_cats,
	"std" => "اختار القسم"),
	array( "name" => "عدد سلايدر الاخبار",
	"desc" => "اختر عدد الاخبار للظهور",
	"id" => $shortname."_slider_num",
	"type" => "text",
	"std" => "4"),
array( "name" => "البوم الصور",
	"desc" => "اختر المصدر بين last حيث سيتم اخيار اخر الاخبار وعرضعا او categry وستقوم باختيار القسم يدويا بالاسفل",
	"id" => $shortname."_gallery_true",
	"type" => "select",
	"options" => array("last", "category"),
	"std" => "last"),
	array( "name" => "اقسم الذى يعرض فى البوم الصور",
	"desc" => "مفعل فقط فى حالة اختيار category من الاعلى",
	"id" => $shortname."_gallery_cat",
	"type" => "select",
	"options" => $wp_cats,
	"std" => "اختار القسم"),
	array( "name" => "عنوان البوم الصور",
	"desc" => "الاسم",
	"id" => $shortname."_gallery_title",
	"type" => "text",
	"std" => "البوم الصور"),
	array( "name" => "عدد البوم الصور",
	"desc" => "اختر عدد الاخبار للظهور",
	"id" => $shortname."_gallery_num",
	"type" => "text",
	"std" => "4"),
array( "name" => "العرض مربعات",
	"desc" => "اختر المصدر بين last حيث سيتم اخيار اخر الاخبار وعرضعا او categry وستقوم باختيار القسم يدويا بالاسفل",
	"id" => $shortname."_gridd_true",
	"type" => "select",
	"options" => array("last", "category"),
	"std" => "last"),
	array( "name" => "اقسم الذى يعرض فى العرض مربعات",
	"desc" => "مفعل فقط فى حالة اختيار category من الاعلى",
	"id" => $shortname."_gridd_cat",
	"type" => "select",
	"options" => $wp_cats,
	"std" => "اختار القسم"),
	array( "name" => "عنوان العرض مربعات",
	"desc" => "الاسم",
	"id" => $shortname."_gridd_title",
	"type" => "text",
	"std" => "اخبار مربعات"),
	array( "name" => "عدد العرض مربعات",
	"desc" => "اختر عدد الاخبار للظهور",
	"id" => $shortname."_gridd_num",
	"type" => "text",
	"std" => "10"),
array( "name" => "مقالاات متطورة",
	"desc" => "اختر المصدر بين last حيث سيتم اخيار اخر الاخبار وعرضعا او categry وستقوم باختيار القسم يدويا بالاسفل",
	"id" => $shortname."_mq_true",
	"type" => "select",
	"options" => array("last", "category"),
	"std" => "last"),
	array( "name" => "اقسم الذى يعرض فى مقالاات متطورة",
	"desc" => "مفعل فقط فى حالة اختيار category من الاعلى",
	"id" => $shortname."_mq_cat",
	"type" => "select",
	"options" => $wp_cats,
	"std" => "اختار القسم"),
	array( "name" => "عدد مقالاات متطورة",
	"desc" => "اختر عدد الاخبار للظهور",
	"id" => $shortname."_mq_num",
	"type" => "text",
	"std" => "4"),
array( "type" => "close"));
function mytheme_add_admin() {
global $themename, $shortname, $options;
if ( $_GET['page'] == basename(__FILE__) ) {
	if ( 'save' == $_REQUEST['action'] ) {
		foreach ($options as $value) {
		update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
foreach ($options as $value) {
	if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
	header("Location: admin.php?page=functions.php&saved=true");
die;
 }else if( 'reset' == $_REQUEST['action'] ) {
	foreach ($options as $value) {
		delete_option( $value['id'] ); }
	header("Location: admin.php?page=functions.php&reset=true");
die;
}
}
add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');
}

function mytheme_add_init() {

$file_dir=get_bloginfo('template_directory');
wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all");
wp_enqueue_script("rm_script", $file_dir."/functions/rm_script.js", false, "1.0");

}
function mytheme_admin() {
global $themename, $shortname, $options;
$i=0;
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' تم الحفظ.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' تم استعادة البيانات.</strong></p></div>';
?>
<div class="wrap rm_wrap">
	<div class="logo"></div>
<div class="rm_opts">
<form method="post">
<?php foreach ($options as $value) {
switch ( $value['type'] ) {
case "open":
?>
<?php break;
case "close":
?>
</div>
</div>
<br />

<?php break;
case "title":
?>
<p>
<?php echo $themename;?></p>
<?php break;
case 'text':
?>
<div class="rm_input rm_text">
	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
 	<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id'])  ); } else { echo $value['std']; } ?>" />
 <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
 </div>
<?php
break;
case 'textarea':
?>

<div class="rm_input rm_textarea">
	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
 	<textarea name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id']) ); } else { echo $value['std']; } ?></textarea>
 <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
 </div>
 <?php
break;
case 'select':
?>

<div class="rm_input rm_select">
	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
	
<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
<?php foreach ($value['options'] as $option) { ?>
		<option <?php if (get_option( $value['id'] ) == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>
</select>

	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
</div>
<?php
break;
case "checkbox":
?>

<div class="rm_input rm_checkbox">
	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
	
<?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
<input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />


	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
 </div>
<?php break;case "section":

$i++;

?>

<div class="rm_section">
<div class="rm_title"><h3><img src="<?php bloginfo('template_directory')?>/functions/images/trans.gif" class="inactive" alt="""><?php echo $value['name']; ?></h3><span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="حفظ التغييرات" />
</span><div class="clearfix"></div></div>
<div class="rm_options">

<?php break;
}
}
?>
<input type="hidden" name="action" value="save" />
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="استعادة" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
<div style="font-size:9px; margin-bottom:10px;">بواسطة: <a href="http://jthoor.com">جذور لخدمات الويب</a></div>
 </div> </div>
<?php
}
?>
<?php
add_action('admin_init', 'mytheme_add_init');
add_action('admin_menu', 'mytheme_add_admin');
 function wpbeginner_numeric_posts_nav() {

	if( is_singular() )
		return;

	global $wp_query;

	/** Stop execution if there's only 1 page */
	if( $wp_query->max_num_pages <= 1 )
		return;

	$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
	$max   = intval( $wp_query->max_num_pages );

	/**	Add current page to the array */
	if ( $paged >= 1 )
		$links[] = $paged;

	/**	Add the pages around the current page to the array */
	if ( $paged >= 3 ) {
		$links[] = $paged - 1;
		$links[] = $paged - 2;
	}

	if ( ( $paged + 2 ) <= $max ) {
		$links[] = $paged + 2;
		$links[] = $paged + 1;
	}

	echo '<div class="navigation"><ul>' . "\n";

	/**	Previous Post Link */
	if ( get_previous_posts_link() )
		printf( '<li>%s</li>' . "\n", get_previous_posts_link() );

	/**	Link to first page, plus ellipses if necessary */
	if ( ! in_array( 1, $links ) ) {
		$class = 1 == $paged ? ' class="active"' : '';

		printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );

		if ( ! in_array( 2, $links ) )
			echo '<li>…</li>';
	}

	/**	Link to current page, plus 2 pages in either direction if necessary */
	sort( $links );
	foreach ( (array) $links as $link ) {
		$class = $paged == $link ? ' class="active"' : '';
		printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
	}

	/**	Link to last page, plus ellipses if necessary */
	if ( ! in_array( $max, $links ) ) {
		if ( ! in_array( $max - 1, $links ) )
			echo '<li>…</li>' . "\n";

		$class = $paged == $max ? ' class="active"' : '';
		printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
	}

	/**	Next Post Link */
	if ( get_next_posts_link() )
		printf( '<li></li>' . "\n", get_next_posts_link() );

	echo '</ul></div>' . "\n";
}
 include('inc/remove.php');
 include('inc/menu.php');
 include('inc/side.php');
 include('inc/theme-widget.php');                      