<?php
/**
 * This file initialize widgets area used in this theme.
 *
 *
 * @package    NOO Framework
 * @subpackage Widget Initiation
 * @version    1.0.0
 * @author     Kan Nguyen <khanhnq@nootheme.com>
 * @copyright  Copyright (c) 2014, NooTheme
 * @license    http://opensource.org/licenses/gpl-2.0.php GPL v2 or later
 * @link       http://nootheme.com
 */

if ( ! function_exists( 'noo_widgets_init' ) ) :

	function noo_widgets_init() {
		
		// Default Sidebar (WP main sidebar)
		register_sidebar( 
			array(  // 1
				'name' => __( 'Main Sidebar', 'noo' ), 
				'id' => 'sidebar-main', 
				'description' => __( 'Default Blog Sidebar.', 'noo' ), 
				'before_widget' => '<div id="%1$s" class="widget %2$s">', 
				'after_widget' => '</div>', 
				'before_title' => '<h4 class="widget-title">', 
				'after_title' => '</h4>' ) );
		// Shop Sidebar (WP main sidebar)
		register_sidebar( 
			array(  // 1
				'name' => __( 'Shop Sidebar', 'noo' ), 
				'id' => 'sidebar-shop', 
				'description' => __( 'Default Shop Sidebar.', 'noo' ), 
				'before_widget' => '<div id="%1$s" class="widget %2$s">', 
				'after_widget' => '</div>', 
				'before_title' => '<h4 class="widget-title">', 
				'after_title' => '</h4>' ) );
		
		// Footer Columns (Widgetized)
		$num = ( noo_get_option( 'noo_footer_widgets' ) == '' ) ? 4 : noo_get_option( 'noo_footer_widgets' );
		for ( $i = 1; $i <= $num; $i++ ) :
			register_sidebar( 
				array( 
					'name' => __( 'NOO - Footer Column #', 'noo' ) . $i, 
					'id' => 'noo-footer-' . $i, 
					'before_widget' => '<div id="%1$s" class="widget %2$s">', 
					'after_widget' => '</div>', 
					'before_title' => '<h4 class="widget-title">', 
					'after_title' => '</h4>' ) );
		endfor
		;
	}
	add_action( 'widgets_init', 'noo_widgets_init' );

endif;

if ( ! function_exists( 'noo_widget_title_display_callback' ) ) :

	function noo_widget_title_display_callback($instance, $widget,$args){
		if (isset($instance['title'])){
			$title = $instance['title'];
			if(!empty($title))
				$instance['title'] = noo_nth_word($title,'first',false);
		}
		return $instance;
	}

	add_filter('widget_display_callback','noo_widget_title_display_callback',10,3);

endif;

if ( ! function_exists( 'noo_widget_title_filter' ) ) :
	function noo_widget_title_filter($title){
		return wp_specialchars_decode($title);
	}
	add_filter( 'widget_title', 'noo_widget_title_filter',100 );
endif;