<?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines
 * @copyright 2011 Simple Machines
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.0.14
 */

/*	This template is, perhaps, the most important template in the theme. It
	contains the main template layer that displays the header and footer of
	the forum, namely with main_above and main_below. It also contains the
	menu sub template, which appropriately displays the menu; the init sub
	template, which is there to set the theme up; (init can be missing.) and
	the linktree sub template, which sorts out the link tree.

	The init sub template should load any data and set any hardcoded options.

	The main_above sub template is what is shown above the main content, and
	should contain anything that should be shown up there.

	The main_below sub template, conversely, is shown after the main content.
	It should probably contain the copyright statement and some other things.

	The linktree sub template should display the link tree, using the data
	in the $context['linktree'] variable.

	The menu sub template should display all the relevant buttons the user
	wants and or needs.

	For more information on the templating system, please see the site at:
	http://www.simplemachines.org/
*/

// Initialize the template... mainly little settings.
function template_init()
{
	global $context, $settings, $options, $txt;

	/* Use images from default theme when using templates from the default theme?
		if this is 'always', images from the default theme will be used.
		if this is 'defaults', images from the default theme will only be used with default templates.
		if this is 'never' or isn't set at all, images from the default theme will not be used. */
	$settings['use_default_images'] = 'never';

	/* What document type definition is being used? (for font size and other issues.)
		'xhtml' for an XHTML 1.0 document type definition.
		'html' for an HTML 4.01 document type definition. */
	$settings['doctype'] = 'xhtml';

	/* The version this template/theme is for.
		This should probably be the version of SMF it was created for. */
	$settings['theme_version'] = '2.0';

	/* Set a setting that tells the theme that it can render the tabs. */
	$settings['use_tabs'] = true;

	/* Use plain buttons - as opposed to text buttons? */
	$settings['use_buttons'] = true;

	/* Show sticky and lock status separate from topic icons? */
	$settings['separate_sticky_lock'] = true;

	/* Does this theme use the strict doctype? */
	$settings['strict_doctype'] = false;

	/* Does this theme use post previews on the message index? */
	$settings['message_index_preview'] = false;

	/* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
	$settings['require_theme_strings'] = true;
}

// The main sub template above the content.
function template_html_above()
{
	global $context, $settings, $options, $scripturl, $txt, $modSettings;

	// Show right to left and the character set for ease of translating.
	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
<head>';

	// The ?fin20 part of this link is just here to make sure browsers don't cache it wrongly.
	echo '
	<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />
	<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/responsive', $context['theme_variant'], '.css?fin20" />
	<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/bootstrap.css" />
	<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/bootstrap.offcanvas.min.css" />
	<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/font-awesome.css" />
	<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/scroll.css" />
	<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet" />';

	// Some browsers need an extra stylesheet due to bugs/compatibility issues.
	foreach (array('ie7', 'ie6', 'webkit') as $cssfix)
		if ($context['browser']['is_' . $cssfix])
			echo '
	<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/', $cssfix, '.css" />';

	// RTL languages require an additional stylesheet.
	if ($context['right_to_left'])
		echo '
	<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl.css" />';

	// Here comes the JavaScript bits!
	echo '
	<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/script.js?fin20"></script>
	<script type="text/javascript" src="', $settings['theme_url'], '/scripts/theme.js?fin20"></script>
	<script type="text/javascript"><!-- // --><![CDATA[
		var smf_theme_url = "', $settings['theme_url'], '";
		var smf_default_theme_url = "', $settings['default_theme_url'], '";
		var smf_images_url = "', $settings['images_url'], '";
		var smf_scripturl = "', $scripturl, '";
		var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
		var smf_charset = "', $context['character_set'], '";', $context['show_pm_popup'] ? '
		var fPmPopup = function ()
		{
			if (confirm("' . $txt['show_personal_messages'] . '"))
				window.open(smf_prepareScriptUrl(smf_scripturl) + "action=pm");
		}
		addLoadEvent(fPmPopup);' : '', '
		var ajax_notification_text = "', $txt['ajax_in_progress'], '";
		var ajax_notification_cancel_text = "', $txt['modify_cancel'], '";
	// ]]></script>';

	echo '
	<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
	<meta name="description" content="', $context['page_title_html_safe'], '" />', !empty($context['meta_keywords']) ? '
	<meta name="keywords" content="' . $context['meta_keywords'] . '" />' : '', '
	<meta name="viewport" content="width=device-width, initial-scale=1"> 
	<meta name="theme-color" content="#272727">
	<meta name="msapplication-navbutton-color" content="#272727">
	<meta name="apple-mobile-web-app-status-bar-style" content="#272727">
	<title>', $context['page_title_html_safe'], '</title>';

	// Please don't index these Mr Robot.
	if (!empty($context['robot_no_index']))
		echo '
	<meta name="robots" content="noindex" />';

	// Present a canonical url for search engines to prevent duplicate content in their indices.
	if (!empty($context['canonical_url']))
		echo '
	<link rel="canonical" href="', $context['canonical_url'], '" />';

	// Show all the relative links, such as help, search, contents, and the like.
	echo '
	<link rel="help" href="', $scripturl, '?action=help" />
	<link rel="search" href="', $scripturl, '?action=search" />
	<link rel="contents" href="', $scripturl, '" />';

	// If RSS feeds are enabled, advertise the presence of one.
	if (!empty($modSettings['xmlnews_enable']) && (!empty($modSettings['allow_guestAccess']) || $context['user']['is_logged']))
		echo '
	<link rel="alternate" type="application/rss+xml" title="', $context['forum_name_html_safe'], ' - ', $txt['rss'], '" href="', $scripturl, '?type=rss;action=.xml" />';

	// If we're viewing a topic, these should be the previous and next topics, respectively.
	if (!empty($context['current_topic']))
		echo '
	<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
	<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';

	// If we're in a board, or a topic for that matter, the index will be the board's index.
	if (!empty($context['current_board']))
		echo '
	<link rel="index" href="', $scripturl, '?board=', $context['current_board'], '.0" />';

	// Output any remaining HTML headers. (from mods, maybe?)
	echo $context['html_headers'];

	echo '
</head>
<body>';
}

function template_body_above()
{
	global $context, $settings, $options, $scripturl, $txt, $modSettings;

echo '
	<div id="search">
		<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">		
			<input type="text" name="search" value="" placeholder="', $txt['search'], '" />
			<input type="submit" name="submit" value="', $txt['search'], '" class="search_btn" />
			<input type="hidden" name="advanced" value="0" />';
			// Search within current topic?
			if (!empty($context['current_topic']))
				echo '
				<input type="hidden" name="topic" value="', $context['current_topic'], '" />';
			// If we're on a certain board, limit it to this board ;).
			elseif (!empty($context['current_board']))
				echo '
				<input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';
			echo '
		</form>
	</div>
	<div class="myinfo">
		<div class="myname">
			<span>', $txt['hello_member_ndt'], '</span><br />
			', $context['user']['name'], '
		</div>';
		if (!empty($context['user']['avatar'])){
			echo '
			<div class="myavatar">
				', $context['user']['avatar']['image'], '
			</div>';
		}
		else {
			echo '
			<div class="myavatar">
				<img src="', $settings['images_url'], '/default-avatar.png" />
			</div>';
		}
		if(!empty($context['user']['unread_messages'])) {
			echo '
			<div class="pm-alert" data-toggle="tooltip" data-placement="right" title="', $txt['new'], ' PM">', $context['user']['unread_messages'] , '</div>';
		}
		echo '
	</div>
	<nav class="navbar navbar-default" role="navigation">
		<div class="container-fluid">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle offcanvas-toggle pull-right" data-toggle="offcanvas" data-target="#js-bootstrap-offcanvas">
					<span class="sr-only">Toggle navigation</span>
					<span>
					  <span class="icon-bar"></span>
					  <span class="icon-bar"></span>
					  <span class="icon-bar"></span>
					</span>
				</button>
			</div>
			<div class="navbar-offcanvas navbar-offcanvas-touch" id="js-bootstrap-offcanvas">
				<ul class="nav navbar-nav">
					',template_menu(),'
				</ul>
				<div class="social-icons">
					<ul>';
					if(!empty($settings['facebook_url']))
						echo '
						<li class="facebook"><a href="', $settings['facebook_url'] , '" target="_blank"><i class="fa fa-facebook"></i></a></li>';
					if(!empty($settings['twitter_url']))
						echo '
						<li class="twitter"><a href="', $settings['twitter_url'] , '" target="_blank"><i class="fa fa-twitter"></i></a></li>';
					if(!empty($settings['instagram_url']))
						echo '
						<li class="instagram"><a href="', $settings['instagram_url'] , '" target="_blank"><i class="fa fa-instagram"></i></a></li>';
					if(!empty($settings['youtube_url']))
						echo '
						<li class="youtube"><a href="', $settings['youtube_url'] , '" target="_blank"><i class="fa fa-youtube-play"></i></a></li>';
					if(!empty($settings['googleplus_url']))
						echo '
						<li class="google"><a href="', $settings['googleplus_url'] , '" target="_blank"><i class="fa fa-google-plus"></i></a></li>';
					echo'
					</ul>
				</div>
			</div>
		</div>
	</nav>
	<header id="header">';
		echo !empty($settings['forum_width']) ? '
		<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
			<div class="logo">
				<a href="'.$scripturl.'"></a>
			</div>';
			if (!empty($settings['enable_news']))
			echo '
				<div class="header-news">
					<i class="fa fa-newspaper-o"></i>', $context['random_news_line'], '
				</div>';
			echo '
			', !empty($settings['forum_width']) ? '
		</div>' : '';echo '
	</header>';

	echo !empty($settings['forum_width']) ? '
	<div id="wrapper" style="width: ' . $settings['forum_width'] . '">' : '', '
	
	<div class="myicons">';
	if ($context['user']['is_logged']){
		echo '
		<ul>
			<li><a href="', $scripturl, '?action=unread"><i class="fa fa-file-text-o"></i>', $txt['show_unread'], '</a></li>
			<li><a href="', $scripturl, '?action=unreadreplies"><i class="fa fa-file-text"></i>', $txt['show_replies'], '</a></li>
			<li><a href="', $scripturl, '?action=profile;area=showposts"><i class="fa fa-file-o"></i>', $txt['showposts'], '</a></li>
		</ul>';
		}
	echo '
		<div class="search_box">
			<a href="#search"><i class="fa fa-search"></i></a>
		</div>
	</div>';

	// The main content should go here.
	echo '
	<div id="content_section">
		<div id="main_content_section">';

		// Is the forum in maintenance mode?
		if ($context['in_maintenance'] && $context['user']['is_admin'])
			echo '
			<div class="alert alert-danger alert-dismissable">
				<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
				', $txt['maintain_mode_on'], '
			</div>';

		// Are there any members waiting for approval?
		if (!empty($context['unapproved_members']))
			echo '
			<div class="alert alert-danger" alert-dismissable>
				<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
				', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=admin;area=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'], '
			</div>';

		if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
			echo '
			<div class="alert alert-danger" alert-dismissable>
				<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
				<a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a>
			</div>';
		
	// Custom banners and shoutboxes should be placed here, before the linktree.

	// Show the navigation tree.
	theme_linktree();
}

function template_body_below()
{
	global $context, $settings, $options, $scripturl, $txt, $modSettings;

	echo '
		</div>
	</div>', !empty($settings['forum_width']) ? '
</div>' : '';

	// Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!
	echo '
	<footer id="footer_section">
		<a href="#" class="scroll-to-top" data-toggle="tooltip" data-placement="top"><i class="fa fa-angle-up"></i></a>
		<div class="footer_left">';
			if(!empty($settings['footer_title']))
			echo '
			<p>' , $settings['footer_title'] , '</p>';
			echo '
			<ul>';
				if(!empty($settings['quicknav_but1']))
				echo '
					<li><a href="', $settings['quicknav_url1'] , '">' , $settings['quicknav_but1'] , '</a></li>';
				if(!empty($settings['quicknav_but2']))
				echo '
					<li><a href="', $settings['quicknav_url2'] , '">' , $settings['quicknav_but2'] , '</a></li>';
				if(!empty($settings['quicknav_but3']))
				echo '
					<li><a href="', $settings['quicknav_url3'] , '">' , $settings['quicknav_but3'] , '</a></li>';
				if(!empty($settings['quicknav_but4']))
				echo '
					<li><a href="', $settings['quicknav_url4'] , '">' , $settings['quicknav_but4'] , '</a></li>';
				if(!empty($settings['quicknav_but5']))
				echo '
					<li><a href="', $settings['quicknav_url5'] , '">' , $settings['quicknav_but5'] , '</a></li>';
				echo '
			</ul>
		</div>
		<div class="footer_left footer_center">
			 Crafted with <i class="fa fa-heart pulse2"></i> by <a href="http://smftricks.com/index.php?action=profile;u=356" target="_blank">SMCreative</a> &#169;'; echo date("Y");echo '<br />
			', theme_copyright(), '';
			// Show the load time?
			if ($context['show_load_time'])
				echo '
				<br />', $txt['page_created'], $context['load_time'], $txt['seconds_with'], $context['load_queries'], $txt['queries'], '';
			echo '
		</div>
		<div class="footer_left">
			<p>', $txt['forum_stats'], '</p>
			<ul>
				<li>', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', $context['common_stats']['total_members'], '</a></li>
				<li>', $txt['total_posts'], ': ', $context['common_stats']['total_posts'], '</li>
				<li>', $txt['total_topics'], ': ', $context['common_stats']['total_topics'], '</li>
				<li>', !empty($settings['show_latest_member']) ? $txt['latest_member'] . ': ' . $context['common_stats']['latest_member']['link'] . '' : '', '</li>
			</ul>
		</div>
	</footer>';
}

function template_html_below()
{
	global $context, $settings, $options, $scripturl, $txt, $modSettings;

	echo '
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
	<script type="text/javascript" src="', $settings['theme_url'], '/scripts/bootstrap.min.js"></script>
	<script type="text/javascript" src="', $settings['theme_url'], '/scripts/bootstrap.offcanvas.min.js"></script>
	<script type="text/javascript" src="', $settings['theme_url'], '/scripts/jquery.mCustomScrollbar.concat.min.js"></script>
	<script type="text/javascript" src="', $settings['theme_url'], '/scripts/custom.js"></script>
</body></html>';
}

// Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
function theme_linktree($force_show = false)
{
	global $context, $settings, $options, $shown_linktree;

	// If linktree is empty, just return - also allow an override.
	if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
		return;

	echo '
	<div class="navigate_section">
		<ul>
			<li class="nav_icon"><i class="fa fa-home"></i></li>';

	// Each tree item has a URL and name. Some may have extra_before and extra_after.
	foreach ($context['linktree'] as $link_num => $tree)
	{
		echo '
			<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';

		// Show something before the link?
		if (isset($tree['extra_before']))
			echo $tree['extra_before'];

		// Show the link, including a URL if it should have one.
		echo $settings['linktree_link'] && isset($tree['url']) ? '
				<a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>' : '<span>' . $tree['name'] . '</span>';

		// Show something after the link...?
		if (isset($tree['extra_after']))
			echo $tree['extra_after'];

		// Don't show a separator for the last one.
		if ($link_num != count($context['linktree']) - 1)
			echo ' &#187;';

		echo '
			</li>';
	}
	echo '
		</ul>
	</div>';

	$shown_linktree = true;
}

// Show the menu up top. Something like [home] [help] [profile] [logout]...
function template_menu()
{
	global $context, $settings, $options, $scripturl, $txt;

	foreach ($context['menu_buttons'] as $act => $button)
	{
		echo '
				<li id="button_', $act, '" class="popover-nav ', $button['sub_buttons'] ? '' : '', '', $button['active_button'] ? 'active ' : '', '">
					<a class="', $button['active_button'] ? 'active ' : '', '" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
						<span class="', isset($button['is_last']) ? 'last ' : '', '"><i class="fa fa-'. $act. '"></i></span>
						<span class="pop-nav hide">', $button['title'], '</span>
					</a>
				</li>';
	}
}

// Generate a strip of buttons.
function template_button_strip($button_strip, $direction = 'top', $strip_options = array())
{
	global $settings, $context, $txt, $scripturl;

	if (!is_array($strip_options))
		$strip_options = array();

	// List the buttons in reverse order for RTL languages.
	if ($context['right_to_left'])
		$button_strip = array_reverse($button_strip, true);

	// Create the buttons...
	$buttons = array();
	foreach ($button_strip as $key => $value)
	{
		if (!isset($value['test']) || !empty($context[$value['test']]))
			$buttons[] = '
				<li><a' . (isset($value['id']) ? ' id="button_strip_' . $value['id'] . '"' : '') . ' class="button_strip_' . $key . (isset($value['active']) ? ' active' : '') . '" href="' . $value['url'] . '"' . (isset($value['custom']) ? ' ' . $value['custom'] : '') . '><i class="fa fa-'.$key.' fa-fw"></i><span>' . $txt[$value['text']] . '</span></a></li>';
	}

	// No buttons? No button strip either.
	if (empty($buttons))
		return;

	// Make the last one, as easy as possible.
	$buttons[count($buttons) - 1] = str_replace('<span>', '<span class="last">', $buttons[count($buttons) - 1]);

	echo '
		<div class="buttonlist', !empty($direction) ? ' float' . $direction : '', '"', (empty($buttons) ? ' style="display: none;"' : ''), (!empty($strip_options['id']) ? ' id="' . $strip_options['id'] . '"': ''), '>
			<ul class="dugmicizaodgovore-message">',
				implode('', $buttons), '
			</ul>
		</div>';
}
/**
This is the custom codes
License - smftricks.com code */
function PrikaziAvatarIndex($memid)
{
	global $memberContext, $settings, $context;

	// Find out the member avatar...
	$temp = loadMemberData($memid, false, 'profile');
	if (!empty($temp))
	{
		loadMemberContext($memid);
		if ($memberContext[$memid]['avatar']['href'] == '')
			$context['avataronboard']['avatar']['href'] = $settings['images_url']. '/default-avatar.png';
		else
			$context['avataronboard']['avatar']['href'] = $memberContext[$memid]['avatar']['href'];
	}
	$context['avataronboard']['avatar']['image'] = '<img src="'. $context['avataronboard']['avatar']['href']. '" alt="" />';

	return $context['avataronboard']['avatar']['image'];
}
function recentpostindex()
{
	global $settings, $txt, $context, $sourcedir, $scripturl;

	if (file_exists($sourcedir.'/ST_Customs.php')) {
		RecentPostsCustom();

	// This is the "Recent Posts" bar.
	if (!empty($settings['number_recent_posts']) && (!empty($context['latest_posts']) || !empty($context['latest_post']))){
		if (!empty($context['latest_posts'])){
			echo '
			<div class="board_stats board_left">
				<div class="title_barIC">
					<h4 class="titlebg">
						<span class="ie6_header floatleft">
							<a href="', $scripturl, '?action=recent"><img class="icon" src="', $settings['images_url'], '/custom/recent.png" alt="', $txt['recent_posts'], '" /></a>
							', $txt['recent_posts'], '
						</span>
					</h4>
				</div>
				<div class="recent_main mCustomScrollbar">
					<table class="board_recent">';
					/* Each post in latest_posts has:
					board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
					subject, short_subject (shortened with...), time, link, and href. */
					foreach ($context['latest_posts'] as $post){
					echo '
					<tr>
						<td width="5%" class="recent_avatar">'. PrikaziAvatarIndex($post['poster']['id']) .'</td>
						<td width="95%">', $post['link'], '<br />', $txt['by'], ' ', $post['poster']['link'], '</td>
					</tr>';
				}
				echo '
					</table>
				</div>
			</div>';
			}
		}
	}
}
?>