<?php
/**
 * @package SP Page Builder
 * @author JoomShaper http://www.joomshaper.com
 * @copyright Copyright (c) 2010 - 2015 JoomShaper
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
//no direct accees
defined ('_JEXEC') or die ('resticted aceess');

AddonParser::addAddon('sp_ob_image','sp_ob_image_addon');
AddonParser::addAddon('sp_ob_image_item','sp_ob_image_item_addon');

function sp_ob_image_addon($atts, $content){

	$column = $class = $style = '';
	extract(spAddonAtts(array(
		"class"=>'',
		"column"=>'',
		"style"=>'',
		), $atts));
	ob_start();
	?>
	<div class="ob_image_col <?php echo $style;?>">
		<div class="row">
			<?php
			if($column!=5) {
				$columns = 12 / $column;
			} else {
				$columns = $column;
			}
			preg_match_all('/\[[^\]]*\]/i', $content, $matches);
			if (isset($matches[0]) && count($matches[0] > 0)) {
				foreach ($matches[0] as $item) {
					?>
					<div class="image_item col-md-<?php echo $columns;?> col-sm-3 col-xs-6">
						<?php echo AddonParser::spDoAddon($item);?>
					</div>
					<?php
				}
			} else {
				$output .= AddonParser::spDoAddon($content);
			}
			?>
		</div>
	</div>
	<?php
	$html = ob_get_clean();
	return $html;

}

function sp_ob_image_item_addon( $atts ){

	$title = $img = $link = '';
	extract(spAddonAtts(array(
		"title"=>'',
		"img"=>'',
		"link" => '',
		), $atts));
	ob_start();
	$int_rand = rand(1,100);
	?>
	<?php if($link) echo '<a href="'.$link.'" target="_blank">';?>
		<img src="<?php echo $img;?>" alt="<?php echo $title;?>">
	<?php if($link) echo '</a>';?>
	<?php
	$html = ob_get_clean();
	return $html;
}