<?php
/**
 * Registering meta boxes
 *
 * In this file, I'll show you how to extend the class to add more field type (in this case, the 'taxonomy' type)
 * All the definitions of meta boxes are listed below with comments, please read them carefully.
 * Note that each validation method of the Validation Class MUST return value instead of boolean as before
 *
 * You also should read the changelog to know what has been changed
 *
 * For more information, please visit: http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html
 *
 */

/********************* BEGIN EXTENDING CLASS ***********************/

/**
 * Extend RW_Meta_Box class
 * Add field type: 'taxonomy'
 */
class RW_Meta_Box_Taxonomy extends RW_Meta_Box {
	
	function add_missed_values() {
		parent::add_missed_values();
		
		// add 'multiple' option to taxonomy field with checkbox_list type
		foreach ($this->_meta_box['fields'] as $key => $field) {
			if ('taxonomy' == $field['type'] && 'checkbox_list' == $field['options']['type']) {
				$this->_meta_box['fields'][$key]['multiple'] = true;
			}
		}
	}
	
	// show taxonomy list
	function show_field_taxonomy($field, $meta) {
		global $post;
		
		if (!is_array($meta)) $meta = (array) $meta;
		
		$this->show_field_begin($field, $meta);
		
		$options = $field['options'];
		$terms = get_terms($options['taxonomy'], $options['args']);
		
		// checkbox_list
		if ('checkbox_list' == $options['type']) {
			foreach ($terms as $term) {
				echo "<input type='checkbox' name='{$field['id']}[]' value='$term->slug'" . checked(in_array($term->slug, $meta), true, false) . " /> $term->name<br/>";
			}
		}
		// select
		else {
			echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">";
		
			foreach ($terms as $term) {
				echo "<option value='$term->slug'" . selected(in_array($term->slug, $meta), true, false) . ">$term->name</option>";
			}
			echo "</select>";
		}
		
		$this->show_field_end($field, $meta);
	}
}

/********************* END EXTENDING CLASS ***********************/

/********************* BEGIN DEFINITION OF META BOXES ***********************/

// prefix of meta keys, optional
// use underscore (_) at the beginning to make keys hidden, for example $prefix = '_rw_';
// you also can make prefix empty to disable it
$prefix = 'lioit_';

$meta_boxes = array();

if(is_rtl()) { 
$imagepath =  get_stylesheet_directory_uri() . '/admin/images';
$meta_boxes[] = array(
	'id' => 'type_setting',
	'title' => 'type Options',
	'pages' => array('post'),


	'fields' => array(
	 
		array(
			'id' => $prefix . 'post_type',
			'type' => 'radio',
			'std' =>'none-type',
			'class' => 'post-type',
			'options' => array (
				'none-type' => '<img class="radio_img" src="'. $imagepath . '/badges/none.png">',
				'breaking-type' => '<img class="radio_img" style="padding:2px;" src="'. $imagepath . '/badges/breakingar.png">',
				'exclusive-type' => '<img class="radio_img" style="padding:2px;" src="'. $imagepath . '/badges/exclusivear.png">',
				'freebie-type' => '<img class="radio_img" style="padding:2px;" src="'. $imagepath . '/badges/freebiear.png">',
				'hot-type' => '<img class="radio_img" style="padding:2px;" src="'. $imagepath . '/badges/hotar.png">',
				'live-type' => '<img class="radio_img" style="padding:2px;" src="'. $imagepath . '/badges/livear.png">',
				'new-type' => '<img class="radio_img" style="padding:2px;" src="'. $imagepath . '/badges/newar.png">',
				'news-type' => '<img class="radio_img" style="padding:2px;" src="'. $imagepath . '/badges/newsar.png">',
				'review-type' => '<img class="radio_img" style="padding:2px;" src="'. $imagepath . '/badges/reviewar.png">',
				
			)
		),
		

		), 
		
);
 } else {
$imagepath =  get_stylesheet_directory_uri() . '/admin/images';
$meta_boxes[] = array(
	'id' => 'type_setting',
	'title' => 'type Options',
	'pages' => array('post'),


	'fields' => array(
	 
		array(
			'id' => $prefix . 'post_type',
			'type' => 'radio',
			'std' =>'none-type',
			'class' => 'post-type',
			'options' => array (
				'none-type' => '<img class="radio_img" src="'. $imagepath . '/badges/none.png">',
				'breaking-type' => '<img class="radio_img" src="'. $imagepath . '/badges/breaking.png">',
				'exclusive-type' => '<img class="radio_img" src="'. $imagepath . '/badges/exclusive.png">',
				'freebie-type' => '<img class="radio_img" src="'. $imagepath . '/badges/freebie.png">',
				'hot-type' => '<img class="radio_img" src="'. $imagepath . '/badges/hot.png">',
				'live-type' => '<img class="radio_img" src="'. $imagepath . '/badges/live.png">',
				'new-type' => '<img class="radio_img" src="'. $imagepath . '/badges/new.png">',
				'news-type' => '<img class="radio_img" src="'. $imagepath . '/badges/news.png">',
				'review-type' => '<img class="radio_img" src="'. $imagepath . '/badges/review.png">',
				
			)
		),
		

		), 
		
);
 }


$meta_boxes[] = array(
	'id' => 'images_setting',
	'title' => __('The Slideshow', 'lioit'),
	'pages' => array('post'),

	'fields' => array(
		array(
			'name' => __('Hide/show', 'lioit'),
			'id' => $prefix . 'slideshow',
			'type' => 'checkbox',
			'std' => false,
		),

		array(
			'name' => __('Upload The Images', 'lioit'),
			'id' => $prefix . 'slideshow_imgs',
			'class' => 'hide slidelayout',
			'type' => 'plupload_image',
			'std' => ''

		),

	)
);
$imagepath =  get_stylesheet_directory_uri() . '/admin/images';
$meta_boxes[] = array(
	'id' => 'sidebar_setting',
	'title' => 'Sidebar Options',
	'pages' => array('post'),


	'fields' => array(
	
		array(
			'name' => __('Enable Sidebar Option', 'lioit'),
			'id' => $prefix . 'sideoption',
			"desc" => __('enable this option if you want make changes for sidebar postion', 'lioit'),
			'type' => 'checkbox',
			'std' => false,
		),
		array(
			'id' => $prefix . 'side_layout',
			'type' => 'radio',
			'std' =>'rightside',
			'class' => 'hide postlayout',
			'options' => array (
				'leftside' => '<img class="radio_img" src="'. $imagepath . '/left-sidebar.png">',
				'fullwidth' =>'<img class="radio_img" src="'. $imagepath . '/no-sidebar.png">',
				'rightside' => '<img class="radio_img" src="'. $imagepath . '/right-sidebar.png">'
			)
		),
		

		), 
		
);
$meta_boxes[] = array(
	'id' => 'sidebar_setting',
	'title' => 'Sidebar Options',
	'pages' => array('page'),


	'fields' => array(
	
		array(
			'name' => __('Enable Sidebar Option', 'lioit'),
			'id' => $prefix . 'sideoption',
			"desc" => __('enable this option if you want make changes for sidebar postion', 'lioit'),
			'type' => 'checkbox',
			'std' => false,
		),
		array(
			'id' => $prefix . 'side_layout',
			'type' => 'radio',
			'std' =>'rightside',
			'class' => 'hide postlayout',
			'options' => array (
				'leftside' => '<img class="radio_img" src="'. $imagepath . '/left-sidebar.png">',
				'fullwidth' =>'<img class="radio_img" src="'. $imagepath . '/no-sidebar.png">',
				'rightside' => '<img class="radio_img" src="'. $imagepath . '/right-sidebar.png">'
			)
		),
		

		), 
		
);



$meta_boxes[] = array(
	'id' => 'vsidebar_setting',
	'title' => 'Video Options',
	'context' => 'side',
	'pages' => array('videos'),


	'fields' => array(
	
		array(
			'name'     => 'Video Type',
			'id'       => $prefix . "video_type",
			'type'     => 'select',
			'options'  => array(
				'Youtube' => 'Youtube',
				'Vimeo' => 'Vimeo',
				'Dialymotion' => 'Dialymotion',
			),
			'multiple' => false,
		),
		array(
			'name'     => 'Show Thumb',
			'id'       => $prefix . "video_thumb",
			'type'     => 'select',
			'std'      => 'video',
			'options'  => array(
				'featured_image' => 'Featured Image',
				'video' => 'Video',
			),
			'multiple' => false,
		),
		array(
			'name'  => 'Vedio ID',
			'id'    => $prefix . "video_id",
			'desc'  => 'Type Video ID  <span style="color:#f89625;"> EX : 36829547</span>',
			'type'  => 'text',
		),
		
		
		
		
		
),);


$meta_boxes[] = array(
	'id' => 'videos_setting',
	'title' => 'Sidebar Options',
	'priority' => 'high',
	
	'pages' => array('videos'),


	'fields' => array(
	
		array(
			'name' => __('Enable Sidebar Option', 'lioit'),
			'id' => $prefix . 'sideoption',
			"desc" => __('enable this option if you want make changes for sidebar postion', 'lioit'),
			'type' => 'checkbox',
			'std' => false,
		),
		array(
			'id' => $prefix . 'side_layout',
			'type' => 'radio',
			'std' =>'rightside',
			'class' => 'hide postlayout',
			'options' => array (
				'leftside' => '<img class="radio_img" src="'. $imagepath . '/left-sidebar.png">',
				'fullwidth' =>'<img class="radio_img" src="'. $imagepath . '/no-sidebar.png">',
				'rightside' => '<img class="radio_img" src="'. $imagepath . '/right-sidebar.png">'
			)
		),
		
		
		
		
		
),);






foreach ($meta_boxes as $meta_box) {
	new RW_Meta_Box_Taxonomy($meta_box);
}

/********************* END DEFINITION OF META BOXES ***********************/

/********************* BEGIN VALIDATION ***********************/

/**
 * Validation class
 * Define ALL validation methods inside this class
 * Use the names of these methods in the definition of meta boxes (key 'validate_func' of each field)
 */
class RW_Meta_Box_Validate {
	function check_name($text) {
		if ($text == 'Anh Tran') {
			return 'He is Rilwis';
		}
		return $text;
	}
}

/********************* END VALIDATION ***********************/
?>
