<?php 

/*
SHORTCODES.PHP
*/



 



 




///////////////////////
/////////// THE LOGO
//////////////////////

add_shortcode('logo', 'load_logo');
	// THE "load_logo" function is located in the "functions.php", in root folder






///////////////////////
/////////// PRICING TABLES
//////////////////////


function pricing($atts="", $content = null)
	{
	$secondary_button=load_option("secondary_button");
	$primary_button=load_option("primary_button");
	extract(shortcode_atts(array(
		'col'=>'',
		'highlight'=>''
	    ), $atts));
	$return="";
	$return.="<div class='pricing_table pricing_".$col."'>".$content."<div class='clear'></div></div>";	
	return $return;
	}
	add_shortcode('pricing', 'pricing');

 


///////////////////////
/////////// SITEMAPS
//////////////////////

function sitemap($atts, $content = null)
	{
	extract(shortcode_atts(array(
	'type'=>''	 , 'title'=>''
	    ), $atts)); 
	$return="<ul class='sc_sitemap'>".wp_list_pages("sort_column=menu_order&echo=0&title_li=$title")."</ul>"; 
	return $return;		
	}
	add_shortcode('sitemap', 'sitemap'); 

///////////////////////
/////////// POPULAR POSTS
//////////////////////

function popular_post($atts, $content = null)
	{
	$ccolumn="";
	$echo="";
	extract(shortcode_atts( array("before"=>"","number" => '6'  ,'column'=>'2',"after"=>'', "text"=>"150","readmore"=>"true", "headline"=>"true", "image"=>"true"), $atts));
	$z=0;
	$i=1;
	switch ($column)
		{
		case "2":
			$ccolumn="one_half";
			break;
		case "3":
			$ccolumn="one_third";
			break;
		case "4":
			$ccolumn="one_fourth";
			break;
		case "5":
			$ccolumn="one_fifth";
			break;
		}
	$myargs = array(
			'posts_per_page'      => $number,
			'orderby'     => 'comment_count',
			);
		query_posts($myargs);
		if (have_posts()) :  
			while (have_posts()) : the_post(); 
			if($z<$number)	
				{
				$z++;
				if($i==$column)		
					{
					$stoper="_last";
					$i=1;
					$stopdiv="<div class='clear'></div>";
					}
					else
						{
						$i++;
						$stoper="";	
						$stopdiv="";
						}
				
				$echo.= "<div class='$ccolumn$stoper shortcode_posts'>";
				$echo.= "<div class='widget_posts_li'>";
				if($image=="true")
					{
					if ( has_post_thumbnail() ) 
						{  
						$echo.= "<div class='widget_posts_left'>";							
							$echo.="<img width='50' height='50' src='". img_icon_url(get_the_id()) ."' alt='' />"; 
						$echo.= "</div><!-- widget_posts_left-->";
						}
						else
							{
							$echo.= "<div class='widget_posts_left'>
								<img src='".get_stylesheet_directory_uri()."/images/noImageSmall.jpg' alt='' width='50' height='50' />
							        </div><!-- widget_posts_left-->";
							}
					}
				if($headline=="true")
					{
					$echo.= "<a href='".get_permalink()."'><h5>".get_the_title()."</h5></a>";
					}
				if($text!="0")
					{
					$content=do_shortcode(get_the_content());
					if((isset($content)) AND ($text>"0"))
						{
						if(strlen("$content")>$text)
							{
							$content=(substr( $content, 0, strpos( $content, " ", $text )+1 ) );
							}
						}
					$echo.= strip_tags($content);
					}
				if($readmore=="true")
					{
					$echo.= "<a href='".get_permalink()."'>read more...</a>";
					} 
				$echo.="</div>";
				}
			//$echo.= "</div>";
			$echo.= "</div>".$stopdiv;
	 		endwhile;
		endif; 
		wp_reset_query();
		return $echo;
	}
	add_shortcode('popular_post', 'popular_post');


/*
**
** CALLOUT BOXES
**
*/
function callout($atts, $content = null)
	{
	extract(shortcode_atts(array(
	'type'=>''	 
	    ), $atts));
	$return="<div class='callout callout_$type' "; 
	$return.="><div>".do_shortcode($content)."</div></div>";
	return do_shortcode($return);		
	}
	add_shortcode('callout', 'callout');





 


///////////////////////
/////////// BREADCRUMBS
//////////////////////

function breadcrumbs($atts, $content) 
	{
	extract(shortcode_atts( array(), $atts));
    	$return=oitheme_breadcrumbs();
	return $return;
	}
	add_shortcode('breadcrumbs', 'breadcrumbs');

 

///////////////////////
/////////// SOCIAL ICONS
//////////////////////

function social_icons($atts, $content) 
	{
	$social_media=load_option("social_media");
	extract(shortcode_atts( array("content"=>"" ), $atts));
	$echo="";
	for($i=0;$i<count($social_media);$i++)	
		{ 
		if(isset($social_media[$i]))
			{
			$echo.= stripslashes($social_media[$i]); 
			}
		} 
   	return $echo;
	}
	add_shortcode('social-icons', 'social_icons');





  
/*
**
** CLEAR SHORTCODE => CLEAR BOTH
**
*/


function clear($atts, $content) 
	{
	return "<div class='clear'></div>";
	}
	add_shortcode('clear', 'clear');

/*
**
** SEARCHFORM
**
*/

function search($atts, $content) 
	{
	return get_search_form();
	}
	add_shortcode('search', 'search');


 
/*
**
** BUTTONS
**
*/

function button( $atts, $content = null ) 
	{ 
	extract(shortcode_atts(array(
		'url'=>'#', 
		'size'=>'medium',
		'color'=>'gray',
		'style'=>'',
		'icon'=>''
		), $atts));
	if($icon!="")
		{	
		$icon="span class='icon icon_".$icon."'";
		}
	$return='<a class="sc_button '.$size . ' '.$style.' ' .$color. ' " href="'.$url.'"><span '.$icon.'>'.$content.'</span></a>';	 
	return $return;
	}
	add_shortcode( 'button', 'button' ); 

  

/*
**
** TOGGLE
**
*/

function toggle( $atts , $content= null)
	{
	extract( shortcode_atts( array(
		'title' => 'My Title',
		'type' => 'slide' ,
		'style'=>'default'
		), $atts ) );
	return "<div class='toggle'><h3 class='toggle-trigger-".$type." ".$style."  toggle-trigger'>". $title ."</h3><div class='toggle-content'>" . do_shortcode($content). "</div>\n</div>";
	}
	add_shortcode( 'toggle', 'toggle' );

/*
**
** HR LINES
**
*/

function hr( $atts , $content= null)
	{
	extract( shortcode_atts( array(
		'type' => 'line' ,
		'top'=>'false',
		'align'=>'right'
		), $atts ) );
	$return= "<div class='hr_lines hr_" .$type. " hr_top_align_".$align." '>";
	if($top=="true")
		{
		$return.= "<a href='#' class='top'>Top</a><!-- $top -->";
		}
	$return.="</div>";
	if($type=="line")
		{
		$return.="<div class='hr_line_simple'></div>";
		}		
	return $return;
	}
	add_shortcode( 'hr', 'hr' );


 


////////////////////
////////// LAYOUT 
///////////////////

add_shortcode('one_half', 'columns');
add_shortcode('one_half_last', 'columns');
add_shortcode('one_third', 'columns');
add_shortcode('one_third_last', 'columns');
add_shortcode('one_fourth', 'columns');
add_shortcode('one_fourth_last', 'columns');
add_shortcode('two_third', 'columns');
add_shortcode('two_third_last', 'columns');
add_shortcode('three_fourth', 'columns');
add_shortcode('three_fourth_last', 'columns');
function columns($atts, $content = null, $name='') {
	extract(shortcode_atts(array(
		"id" => '',
		"class" => '',
		"col" => "",
		"bgcol" =>"",
		"boxed" =>"false",
	), $atts));
	if($boxed=="true")
		{
		$boxclass="columnbox";
		}	
		else
			{
			$boxclass="";
			}	
	$id = ($id <> '') ? " id='{$id}'" : '';
	$class = ($class <> '') ? " {$class}" : '';
	$pos = strpos($name,'_last');	
	if($pos !== false)
	$name = str_replace('_last',' last',$name);
	$output = "<div{$id} class='sc_column {$name}{$class} $boxclass' ";
	if(($col!="") OR ($bgcol!=""))
		{ 
		$output.=" style='";
		if($col!="")
			{
			$output.="color: ".$col.";";
			}
		if($bgcol!="")
			{
			$output.="background-color: ".$bgcol.";";
			}
		$output.=" ' ";

		}
	$output.=">";
	if($boxed=="true")
		{
		$output.="<div class='column_boxed'>";
		}
	$output.=do_shortcode($content);
	if($boxed=="true")
		{
		$output.="</div>";
		}
	$output.="</div>";
	if($pos !== false) 
		$output .= "<div class='clear'></div>";
	
	return $output;
	}

 

/*
**
** ACCORDION (A PART OF THE ACCORDIONS SHORTCODE)
**
*/
function accordion( $atts , $content= null)
	{
	extract( shortcode_atts( array(
		'title' => 'My Title',
		'type' => 'fade' ,
		'style'=>'default'
		), $atts ) );
	$return="<h3 class='".$style."'>". $title ."</h3> <div class='accordion-content'>" . do_shortcode($content). "</div>";	
	return $return;
	}
	add_shortcode( 'accordion', 'accordion' );

/*
**
** ACCORDIONS
**
*/
function accordions( $atts , $content= null)
	{
	extract( shortcode_atts( array(
		'style'=>'default',
		'type'=>''
		), $atts ) );
	$return="<div class='accordion ".$type." ".$style." '>" . do_shortcode($content). "</div>\n";
	return $return;
	}
	add_shortcode( 'accordions', 'accordions' );
/*
**
** TABS
**
*/
function tabs_main($atts, $content = null) 
	{
	extract(shortcode_atts(array(
	'type'=>'','style'=>'default'    ), $atts));
	global $tab_counter_2;
	if($type!="")	{ $effect="-$type"; }
	$tab_counter_1 = 1;
	$output="";
	$tab_counter_2 = 1;
	$output .= "<div class='ui-tabs$effect ui-tabs$style '>";
	$output .= '<ul class="template_ul ' .$style. '">';
	foreach ($atts as $k=>$tab) 
		{
		if(($k!="style") AND ($k!="type"))
			{
			$output .= '<li class=" '.$style.' "><h3><a href="#tab-' . $tab_counter_1 . '" class="tabs-trigger"> ' .$tab. ' </a></h3></li>';
			$tab_counter_1++;
			}
		}
	$output .= '</ul>' . do_shortcode($content);
	$output .='<div class="clear"></div></div>';
	return $output;
	unset($tab_counter_2);
	}
	add_shortcode('tabs', 'tabs_main');
function tab_elements($atts, $content = null) 
	{
	extract(shortcode_atts(array(    ), $atts));
	global $tab_counter_2, $style;
	$output="";
	$output .= '<div id="tab-' . $tab_counter_2 . '" class="'.$style.'">' . do_shortcode($content) . '</div>';
	$tab_counter_2++;
	return $output;
	}
	add_shortcode('tab', 'tab_elements');
 
/*
**
** Highlight
**
*/
function highlight($atts, $content = null)
	{
	extract(shortcode_atts(array(
	'type'=>'',
	'color'=>'',
	'bgcolor'=>''
	    ), $atts));
	$return="<span class='highlight_$type' ";
	if($color!="")
		{
		$i=1;
		$style="color: $color;";
		}
	if($bgcolor!="")
		{
		$i=1;
		$style.="background-color: $bgcolor;";
		}
	if($i!="")
		{
		$return.=" style='".$style."' ";
		}
	$return.=">$content</span>";
	return $return;		
	}
	add_shortcode('highlight', 'highlight');
 
/*
**
** QOUTES
**
*/
function quote($atts, $content = null)
	{
	extract(shortcode_atts(array('align'=>'', 'cite'=>''), $atts));
	$return="<blockquote class='quote".$align."'>$content";
	if($cite!="")
		{
		$return.="<cite>$cite</cite>";
		}
	$return.="</blockquote>";
	return $return;		
	}
	add_shortcode('quote', 'quote');

/*
**
** STYLED TABLES
**
*/
function table($atts, $content = null)
	{
	extract(shortcode_atts(array(
	'type'=>''
	    ), $atts));
	$return="<div class='stable stable_".$type."'>".do_shortcode($content)."</div>";
	return $return;		
	}
	add_shortcode('table', 'table');

 

/*
**
** ALERT BOXES
**
*/
function abox($atts, $content = null)
	{
	extract(shortcode_atts(array(
	'type'=>'',
	'color'=>'',
	'bgcolor'=>'',
	'bordercolor'=>''
	    ), $atts));
	$return="<div class='alert alert_$type' ";
	$i="";
	if($color!="")
		{
		$i=1;
		$style="color: $color !important; ";
		}
	if($bgcolor!="")
		{
		$i=1;
		$style.="background-color: $bgcolor !important; ";
		}
	if($bordercolor!="")
		{
		$i=1;
		$style.="border:1px solid $bordercolor !important; ";
		}
	if($i!="")
		{
		$return.=" style='".$style."' ";
		}
	$return.=">".do_shortcode($content)."</div>";
	return $return;		
	}
	add_shortcode('alert', 'abox');

 

 


 