<?php
include_once REZA_PATH . '/admin/menu/admin-menu.php';
include_once REZA_PATH . '/admin/theme-options/functions.options.php' ;
include_once REZA_PATH . '/admin/theme-options/index.php';
include_once REZA_PATH . '/admin/array.php';
include_once REZA_PATH . '/admin/multi-array.php';
include_once REZA_PATH . '/admin/category-array.php';
include_once REZA_PATH . '/admin/admin-custom-css.php';



include_once REZA_PATH . '/admin/post-type/blog_post_type.php';   
include_once REZA_PATH . '/admin/metabox/blog-metabox.php';  
include_once REZA_PATH . '/admin/metabox/page-metabox.php';   
include_once REZA_PATH . '/admin/metabox/author-metabox.php';   
include_once REZA_PATH . '/admin/metabox/product-metabox.php';   
 
 
 
global $pagenow;
function reza_builder_has_type() {
  global $post, $typenow, $current_screen;
	  if ( $post && $post->post_type ) {
		return $post->post_type;
	  }
	  elseif ( $typenow ) {
		return $typenow;
	  }
	  elseif ( $current_screen && $current_screen->post_type ) {
		return $current_screen->post_type;
	  }
	  elseif ( isset( $_REQUEST['post_type'] ) ) {
		return sanitize_key( $_REQUEST['post_type'] );
	  }
	  elseif ( isset( $_REQUEST['post'] ) ) {
		return get_post_type( $_REQUEST['post'] );
	  }
	  return null;
}
add_action('admin_enqueue_scripts', 'reza_admin_enqueue');
function reza_admin_enqueue($hook) {
  	$var = '1.7';
		global $pagenow,$post; 

	wp_enqueue_style( 'sao-iransans', REZA_DIR.'/css/fonts/sao-iransans.css',array() );
  	wp_enqueue_style('reza-meta-box', REZA_DIR . '/admin/assets/css/meta_box.css');

 

	if(in_array( $pagenow, array( 'post-new.php', 'post.php','admin-ajax.php' ) )&& (reza_builder_has_type() ==  'page' || reza_builder_has_type() ==  'post' ||  reza_builder_has_type() ==  'sao_slide')){
 	 	wp_enqueue_style( 'reza-element', REZA_DIR.'/admin/assets/css/admin-element.css',array() );
  		wp_add_inline_style( 'reza-element', reza_custom_css() ); 
	}
  
 	    // enqueue style


	wp_enqueue_style( 'rang_coloris',REZA_DIR .'/admin/assets/css/coloris.css'); 
	wp_enqueue_script( 'rang_coloris', REZA_DIR .'/admin/assets/js/coloris.js'); 
	wp_localize_script('rang_coloris', 'rang_coloris',array('rtl'=>is_rtl()?'true':''));
 
  	wp_enqueue_script('migrate', REZA_DIR . '/admin/assets/js/jquery-migrate-1.0.0.js','1.0', true );
  	wp_register_script('reza-meta-box', REZA_DIR . '/admin/assets/js/scripts.js', array('jquery', 'jquery-ui-sortable') ,'1.933', true );
    wp_enqueue_script( 'reza-meta-box' );

	wp_enqueue_media();
			

 
			
} 



if(function_exists('elementor_load_plugin_textdomain')){

add_action('elementor/editor/before_enqueue_scripts', 'reza_editor_elementor',1);
function reza_editor_elementor(){
	if(is_rtl()){
      	wp_enqueue_style( 'sao-iransans', REZA_DIR.'/css/fonts/sao-iransans.css',array() );
      	wp_enqueue_style( 'reza-editor-elementor', REZA_DIR.'/admin/assets/css/editor-elementor.css',array() );
	}
}
 
add_action('elementor/preview/enqueue_styles', 'reza_perview_elementor');
function reza_perview_elementor(){
	
		wp_enqueue_script( 'reza-elementor', REZA_DIR . '/js/elementor-scripts.js', array( 'jquery'),'1');
			if(is_rtl()){

       	wp_enqueue_style( 'sao-iransans', REZA_DIR.'/css/fonts/sao-iransans.css',array() );
      	wp_enqueue_style( 'reza-perview-elementor', REZA_DIR.'/admin/assets/css/perview-elementor.css',array() );
			}
}
add_action('elementor/preview/enqueue_styles', 'reza_common_elementor');
function reza_common_elementor()
{			if(is_rtl()){

       	wp_enqueue_style( 'sao-iransans', REZA_DIR.'/css/fonts/sao-iransans.css',array() );
      	wp_enqueue_style( 'reza-common-elementor', REZA_DIR.'/admin/assets/css/common-elementor.css',array() );
}
 
}
  }
 // WordPress Custom Font @ Admin
function custom_admin_open_sans_font() {
     echo '<style>#wpadminbar *, .rtl #wpadminbar *, html:lang(he-il) .rtl #wpadminbar *, #wpadminbar, #wpadminbar > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input body.rtl td, #plugin-information-title.with-banner h2, body.rtl, body.rtl .press-this a.wp-switch-editor, .rtl h1, .rtl h2, .rtl h3, .rtl h4, .rtl h5, .rtl h6, body.locale-he-il, body.locale-he-il .press-this a.wp-switch-editor, .media-frame, .media-modal, .media-frame input[type="color"], .media-frame input[type="date"], .media-frame input[type="datetime-local"], .media-frame input[type="datetime"], .media-frame input[type="email"], .media-frame input[type="month"], .media-frame input[type="number"], .media-frame input[type="password"], .media-frame input[type="search"], .media-frame input[type="tel"], .media-frame input[type="text"], .media-frame input[type="time"], .media-frame input[type="url"], .media-frame input[type="week"], .media-frame select, .media-frame textarea, .media-frame .search, .rtl .media-frame, .rtl .media-frame .search, .rtl .media-frame input[type="email"], .rtl .media-frame input[type="number"], .rtl .media-frame input[type="password"], .rtl .media-frame input[type="search"], .rtl .media-frame input[type="tel"], .rtl .media-frame input[type="text"], .rtl .media-frame input[type="url"], .rtl .media-frame select, .rtl .media-frame textarea, .rtl .media-modal, :lang(he-il) .rtl .media-frame, :lang(he-il) .rtl .media-frame .search, :lang(he-il) .rtl .media-frame input[type="email"], :lang(he-il) .rtl .media-frame input[type="number"], :lang(he-il) .rtl .media-frame input[type="password"], :lang(he-il) .rtl .media-frame input[type="search"], :lang(he-il) .rtl .media-frame input[type="text"], :lang(he-il) .rtl .media-frame input[type="url"], :lang(he-il) .rtl .media-frame select, :lang(he-il) .rtl .media-frame textarea, :lang(he-il) .rtl .media-modal, body.rtl, body.rtl h1, body.rtl h2, .widefat td, .widefat td ol, .widefat td p, .widefat td ul, body.rtl h3, body.rtl h4, body.rtl h5, body.rtl h6, body.rtl input, body.rtl select, body.rtl textarea, body.rtl .press-this a.wp-switch-editor{
	font-family: "sao-iransans",roboto,Tahoma,Arial,sans-serif 
 }</style>' ;
}
add_action( 'admin_head', 'custom_admin_open_sans_font' );

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

																		Post Views
																		
*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function reza_setPostViews($postID) {
    $count_key = 'reza_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{
		$counter=  $count + 0.5;
		update_post_meta($postID, $count_key, $counter);
    }
}

// Add it to a column in WP-Admin 
add_filter('manage_posts_columns', 'reza_posts_column_views');
function reza_posts_column_views($defaults){
    $defaults['reza_post_views'] = esc_html__('Views' , 'reza' );
    return $defaults;
}

// Posts Custom Column Views

add_action('manage_posts_custom_column', 'reza_posts_custom_column_views',5,2);
function reza_posts_custom_column_views($column_name, $id){
	if($column_name === 'reza_post_views'){
        echo reza_number_replace(reza_getPostViews(get_the_ID()));
    }
}