<?php
$optres['css'][] = dirname(__FILE__) . "/css/sm.css";

$ss_root = false;
$ss_url = $protocol . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['REQUEST_URI'];
$ss_title = $webpage_title_en;

if($_SERVER['HTTP_HOST'] != $ultra_domainname) {
	if(str_replace('/', '', $_SERVER['REQUEST_URI']) == $ultra_addonname) {
		$ss_root = true;
	}
}
else {
	if(str_replace('/', '', $_SERVER['REQUEST_URI']) == "") {
		$ss_root = true;
	}
}

if(!$ss_root || ( isset($sm_show_likes) && $sm_show_likes == true )) {
	$sm_functions = dirname(__FILE__) . "/sm_functions.php";
	if(file_exists($sm_functions)) require_once($sm_functions);
}

//echo '<pre>', var_export($sm_defaults, true), '</pre>';
$have_sm = false;
foreach ($sm_defaults as $sm_code=>$sm_data) {
	if($sm_data['app_status'] == 1) {
		$have_sm = true;
		if(!$ss_root || ( isset($sm_show_likes) && $sm_show_likes == true )) echo $sm_codes[$sm_code];
	}
}

if($have_sm) {
	
	ob_start();
	
	if($ss_root && ( !isset($sm_show_likes) || $sm_show_likes == false ) ) {
		?>
		<div class="sm-root-media">
			<div class="sm-inner">
				<?php
				if($sm_title != "") {
					?>
					<span class="sm-title"><?php echo $sm_title;?></span>
					<?php
				}
				?>
				<ul class="sm-root">
					<?php
					foreach ($sm_defaults as $sm_code=>$sm_data) {
						if($sm_data['app_status'] == 1) {
							echo '<li>';
							$sm_app_url = $sm_defaults[$sm_code]['app_link'];
							echo '<a href="'.$sm_app_url.'" target="_blank" title="Follow us on '. $sm_objs[$sm_code] .'" class="sm-button '.str_replace('+', '', $sm_code).'"></a>';
							echo '</li>';
						}
					}
					?>
				</ul>
				<div style="clear: both;"></div>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div style="clear: both;"></div>
		<?php
	}
	else {
		
			if(!isset($sm_class) || $sm_class == "") {
				$sm_class = "sm-page";
			}
			
			if(isset($sm_class_overload) && $sm_class_overload != "") {
				$sm_class = $sm_class_overload;
			}
			?>
			<div class="<?php echo $sm_class;?>-media">
				<div class="<?php echo $sm_class;?>-inner">
					<ul class="<?php echo $sm_class;?>">
						
						<?php
						foreach ($sm_defaults as $sm_code=>$sm_data) {
							if($sm_data['app_status'] == 1) {
								echo '<li>';
								$button_content = $sm_defaults[$sm_code]['like_code'];
								$button_content = str_replace('[APP_URL]', $sm_defaults[$sm_code]['app_link'], $button_content);
								$button_content = str_replace('[URL]', $ss_url, $button_content);
								echo $button_content;
								echo '</li>';
							}
						}
						?>
					</ul>
					<div style="clear: both;"></div>
				</div>
				<div style="clear: both;"></div>
			</div>
			<div style="clear: both;"></div>
			<?php
			
		$sm_class_overload = "";
	}
	$sm_content = ob_get_contents();
	ob_end_clean();
	
	echo $sm_content;
}



?>
