<?php

/***** Global Variables goes here:
*/
global $assetsPath;
function get_assets_path(){
    $assetsPath = get_theme_root_uri() . '/parspatentTheme_01_assets';
    echo $assetsPath;
}


/**** Add Post Feature Image to the theme
*/
add_action( 'after_setup_theme', 'init_my_theme' );
function init_my_theme() {


    
    add_theme_support( 'post-thumbnails' );

}

function get_id_by_slug($page_slug) {
	$page = get_page_by_path($page_slug);
	if ($page) {
		return $page->ID;
	} else {
		return null;
	}
}




add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class($classes, $item){
     if( in_array('current-menu-item', $classes) ){
             $classes[] = 'active ';
     }
     return $classes;
}




/**** Get Image Url of Feature Image of a Post
*/
function the_img_url($size = 'large' , $id ){
		
			$template_url =  get_template_directory_uri();
			  
			  
			if ($id){
		 		 $image_id = get_post_thumbnail_id($id);
			}else{
		 		 $image_id = get_post_thumbnail_id();
			}
			
			
		  if($image_id != ''){
			  $image_url = wp_get_attachment_image_src($image_id, $size, true);
			  echo $image_url[0] ;
			  $size = '';
		  }else{
			  //apply noimage to all images
			  
			  switch ($size){
                  case 'large':
				  $image_url = get_assets_path() . '/images/noimageNews.png';
				  break;
                  
				  case 'news_cat':
				  $image_url = $template_url . '/images/noimage01.png';
				  break;
				  
				  case 'homepage_logo':
				  $image_url = $template_url . '/images/noimage02.png';
				  break;
				  
				  case 'single_pic':
				  $image_url =  $template_url . '/images/noimage03.png';
				  break;
				  
				  case 'lastnews_pic':
				  $image_url = $template_url . '/images/noimage04.png';
				  break;
				  
				  case 'footer_logo':
				  $image_url = $template_url . '/images/noimage05.png';
				  break;
				  
				  default:
				  $image_url = $template_url . '/images/noimage.png';
			  }		  
			  echo $image_url;
			  $size = '';
		  }
	}






/**** Gets post cat slug and looks for single-[cat slug].php and applies it
*/
add_filter('single_template', create_function(
	'$the_template',
	'foreach( (array) get_the_category() as $cat ) {
		if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") )
		return TEMPLATEPATH . "/single-{$cat->slug}.php"; }
	return $the_template;' )
);







/**
 * Filters wp_title to print a neat <title> tag based on what is being viewed.
 *
 * @param string $title Default title text for current view.
 * @param string $sep Optional separator.
 * @return string The filtered title.
 */
function theme_name_wp_title( $title, $sep ) {
	if ( is_feed() ) {
		return $title;
	}
	
	global $page, $paged;

	// Add the blog name
	$title .= get_bloginfo( 'name', 'display' );

	// Add the blog description for the home/front page.
	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) ) {
		$title .= " $sep $site_description";
	}

	// Add a page number if necessary:
	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
		$title .= " $sep " . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) );
	}

	return $title;
}
add_filter( 'wp_title', 'theme_name_wp_title', 10, 2 );





/****** Disable plugin update Notification ******/
remove_action('load-update-core.php','wp_update_plugins');
add_filter('pre_site_transient_update_plugins','__return_null');





/**** Register Navigation bar ****
*/
function register_my_menus() {
  register_nav_menus(
    array(
      'main-menu' => __( 'Main Menu' ),
      'footer-menu' => __( 'Footer Menu' )
    )
  );
}
add_action( 'init', 'register_my_menus' );


	
?>