<?php
/**
 * @version    $Id$
* @package    IT_Theme_Framework
* @author     InnoThemes Team <support@innothemes.com>
* @copyright  Copyright (C) 2012 InnoThemes.com. All Rights Reserved.
* @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* Websites: http://www.innothemes.com
*/

/**
 * Radio image field renderer.
*
* @package  IT_Theme_Framework
* @since    1.0.0
*/
class IT_Form_Field_Radio_Image extends IT_Form_Field_Radio {
	/**
	 * Field type.
	 *
	 * @var  string
	 */
	protected $type = 'radio-image';

	/**
	 * How many image should be rendered in a row?
	 *
	 * Zero (0) means all images will be rendered in the same row.
	 *
	 * @var  integer
	 */
	protected $image_per_row = 0;

	/**
	 * Generate radio image attributes.
	 *
	 * @param   mixed    &$image  Image attributes.
	 * @param   string   &$label  Radio image label.
	 * @param   boolean  $return  Whether to return or print generated attributes?
	 *
	 * @return  string
	 */
	protected function radio_image_attributes( &$image, &$label, $return = false ) {
		// Prepare attributes
		$image = is_array( $image ) ? $image : array( 'image' => $image );
		$attrs = array();

		$image['class'] = isset( $image['class'] ) ? $image['class'] : 'span12';

		// Build attributes for radio image
		foreach ( $image as $k => $v ) {
			if ( 'label' == $k ) {
				$label = $v;
			} elseif ( 'image' != $k ) {
				if ( $return ) {
					$attrs[] = esc_attr( $k ) . '="' . esc_attr( $v ) . '"';
				} else {
					esc_attr_e( $k ) . '="' . esc_attr( $v ) . '"';
				}
			}
		}

		$image = $image['image'];

		// If image link is relative, prepend root URL
		if ( strpos( $image, '://' ) === false ) {
			$image = site_url( $image );
		}

		if ( $return ) {
			return implode( ' ', $attrs );
		}
	}
}
