<?php
/*.Sverige NSS Theme for PHP-Fusion v7.02.X......*|
|*.Author: JoiNNN // Spo0kye@yahoo.com...........*|
|*.Released under the Affero GPLv3...............*/
if (!defined("IN_FUSION")) { die("Access Denied"); }

//Theme Settings
define("THEME_MAXWIDTH", "1024px"); //theme width. Make sure to adapt the margin-left in the first div (-width/2).
define("THEME_MINWIDTH", "980px");
define("THEME_BULLET", "<img src='".THEME."images/bullet.png' class='bullet' width='3' height='5' alt='>' />"); //bullet image

define("MCARD", "1"); // 1=Member Card On || 0=Member Card Off
//Theme Settings /

require_once THEME."functions.php";
require_once INCLUDES."theme_functions_include.php";

function get_head_tags(){
	echo "<!--[if lte IE 7]><style type='text/css'>hr{border: solid #ccc 1px;height: 1px;margin:0} .button{padding: 3px 3px;} .clearfix {display:inline-block;} * html .clearfix{height: 1px;}</style><![endif]-->\n";
}

function render_page($license=false) {
global $aidlink, $locale, $settings, $main_style;

add_handler("theme_output");

//Check for locale
if (file_exists(THEME."locale/".$settings['locale'].".php")) {
	include THEME."locale/".$settings['locale'].".php";
    } else {
	include THEME."locale/English.php";
    }

add_to_footer("<script type='text/javascript'>
var locale_show = '".$locale['show_info']."';
var locale_hide = '".$locale['hide_info']."';
</script>");

//$js_info  = file_get_contents (THEME."js/infoslider.js"); 
//add_to_footer("<script type='text/javascript'>/* <![CDATA[ */".$js_info."/* ]]> */</script>");
add_to_footer("<script type='text/javascript' src='".THEME."js/infoslider.js'></script>");

//Scroll to top script
$js_scroll  = file_get_contents (THEME."js/scrolltopcontrol.js"); 
add_to_footer("<script type='text/javascript'>/* <![CDATA[ */".$js_scroll."/* ]]> */</script>");

//Stop chrome's autocomplete from making your input fields that nasty yellow. Yuck.
$js_input  = file_get_contents (THEME."js/chromeinputcolor.js"); 
add_to_footer("<script type='text/javascript'>/* <![CDATA[ */".$js_input."/* ]]> */</script>");

add_to_footer("<script type='text/javascript' src='".THEME."js/jquery.cookie.js'></script>");

//Member Area
echo "<div id='member-area'>
		<div class='line'></div>
		<div class='center' style='max-width: ".THEME_MAXWIDTH.";min-width: ".THEME_MINWIDTH.";position:relative;'>
		<div class='member_wrap center'>";
		require_once THEME."user_info.php";
echo "</div>
			<a href='".BASEDIR."login.php' class='show' id='topMember'>
					<span class='micon flleft'> </span>".$locale['member_area']."
			</a>
		</div>
		</div>\n";
//Header
echo "<div id='header' class='clearfix'>
			<div id='mainheader' style='max-width: ".THEME_MAXWIDTH.";min-width: ".THEME_MINWIDTH."'>
				<h1 id='logo' class='flleft'>".showbanners()."</h1>
				<div id='subheader' class='flleft'>
				".preg_replace("^(li)( class='(first-link)')*(><a href='(\.\./)*".preg_quote(START_PAGE)."')^i", "\\1 class='active \\3'\\4", showsublinks(""))."
				</div>
			</div>
		</div>\n";

if (MCARD == 1) {
/*=======================*/
/*===== Member Card =====*/
/*=======================*/
add_to_head("<link type='text/css' href='".THEME."css/basicw.css' rel='stylesheet' media='screen' />");
add_to_footer("<script type='text/javascript' src='".THEME."js/jquery.simplemodal.min.js'></script>");
add_to_footer("<script type='text/javascript'>
jQuery(function ($) {
	var basic = {
		init: function () {
			$('.profile-link').click(function (e) {
				e.preventDefault();

				//split the url by = and get the id number
				var parts = this.href.split('=');
				var trgt = parts[1];
				$.get(\"".THEME."membercard.php?lookup=\" + trgt, function (data) {
				// load the basic form using ajax
					// create a modal info with the data
					$(data).modal({
						overlayClose: true,
						opacity: 70,
						onOpen: basic.open,
						onClose: basic.close,
						position: ['18%' ]
					});
				});
			});
		},
		open: function (info) {
			info.overlay.fadeIn(100, function () {
				info.container.fadeIn(80, function () {});
				info.data.fadeIn(100, function () {});		
			});
		},
		close: function (info) {
				info.data.fadeOut(100, function () {});
				info.container.fadeOut(100, function () {});
						info.overlay.fadeOut(100, function () {
							$.modal.close();
						});
		}
	};
	basic.init();
});
</script>"); }

echo "<div id='phpfusion-info'>
			<div class='info_wrap center'>
				<div class='download_fusion flleft'>
				<a href='".$locale['download_fusion_link']."'>
					<img src='".THEME."images/blank.gif' alt='' width='58' height='58' />
					<span class='txt flleft'>
					<span class='h1'>".$locale['download_fusion']."</span>
					<span>".$locale['download_fusion_txt']."</span>
					</span>
				</a>
				</div>
				<div class='fusion_manual flleft'>
				<a href='".$locale['fusion_manual_link']."'>
					<img src='".THEME."images/blank.gif' alt='' width='58' height='58' />
					<span class='txt flleft'>
					<span class='h1'>".$locale['fusion_manual']."</span>
					<span>".$locale['fusion_manual_txt']."</span>
					</span>
				</a>
				</div>
				<div class='code_conduct flleft'>
				<a href='".$locale['code_conduct_link']."'>
					<img src='".THEME."images/blank.gif' alt='' width='58' height='58' />
					<span class='txt flleft'>
					<span class='h1'>".$locale['code_conduct']."</span>
					<span>".$locale['code_conduct_txt']."</span>
					</span>
				</a>
				</div>

		</div>
			<div class='openCloseWrap center'>
				<span id='infoSlideBtn' class=''></span>
			</div>
	</div>\n";

	echo "<div id='main' class='$main_style clearfix' style='max-width: ".THEME_MAXWIDTH.";min-width: ".THEME_MINWIDTH."'>\n";

//Theme structure
	echo "".(LEFT ? "<div id='side-border-left'>".LEFT."</div>" : "")."
			".(RIGHT ? "<div id='side-border-right'>".RIGHT."</div>" : "")."
			<div id='main-bg'><div id='container'>
			".U_CENTER
			 .CONTENT
			 .L_CENTER."
			</div></div>
		</div>\n";
//Footer logos
	echo "<div id='footer-part'><ul>";
				include THEME."partners.php";
	echo "</ul></div>\n";

//Footer
	echo "<div class='footer-bg'>
			<div id='footer' style='max-width: ".THEME_MAXWIDTH.";min-width: ".THEME_MINWIDTH."'>
				<div class='footernav clearfix'>";
			?>
		<!-- Latest news -->
		<div class="section">
			<?php
			echo "<h4>".$locale['latest_news']."</h4><ul>\n";
			$result = dbquery("SELECT news_id, news_subject
		               FROM ".DB_NEWS." 
		               WHERE ".groupaccess('news_visibility')."
							AND news_draft='0'
		               ORDER BY news_datestamp DESC LIMIT 0,5");
			if (dbrows($result) != 0) {
			while($data = dbarray($result)) {
			$newsid = $data['news_id'];
			$newstitle = trimlink($data['news_subject'], 23);
			echo "<li><a href='".BASEDIR."news.php?readmore=".$data['news_id']."'  title='".$data['news_subject']."' target='_blank'>".$newstitle."</a></li>\n";
				}
			} else {
			echo "<li>".$locale['no_news']."</li>\n";
			}
			echo "</ul>\n";
		echo "</div>\n";

			?>
		<!-- Newest Threads -->
		<div class="section">
			<?php
			echo "<h4>".$locale['global_021']."</h4><ul>\n";
			$result = dbquery("
				SELECT tt.forum_id, tt.thread_id, tt.thread_subject, tt.thread_lastpost FROM ".DB_THREADS." tt
				INNER JOIN ".DB_FORUMS." tf ON tt.forum_id=tf.forum_id
				WHERE ".groupaccess('tf.forum_access')." AND tt.thread_hidden='0'
				ORDER BY thread_lastpost DESC LIMIT 5");
			if (dbrows($result)) {
				while($data = dbarray($result)) {
					$itemsubject = trimlink($data['thread_subject'], 23);
					echo "<li><a href='".FORUM."viewthread.php?thread_id=".$data['thread_id']."' title='".$data['thread_subject']."'>".$itemsubject."</a></li>\n";
				}
			} else {
				echo "<li>".$locale['global_023']."</li>\n";
			}
			echo "</ul>";
		echo "</div>\n";

			?>
		<!-- Hottest Threads -->
		<div class="section">
			<?php
			echo "<h4>".$locale['global_022']."</h4><ul>\n";
			$timeframe = ($settings['popular_threads_timeframe'] != 0 ? "thread_lastpost >= ".(time()-$settings['popular_threads_timeframe']) : "");
			list($min_posts) = dbarraynum(dbquery("SELECT thread_postcount FROM ".DB_THREADS.($timeframe ? " WHERE ".$timeframe : "")." ORDER BY thread_postcount DESC LIMIT 4,1"));
			$timeframe = ($timeframe ? " AND tt.".$timeframe : "");
			$result = dbquery("
				SELECT tf.forum_id, tt.thread_id, tt.thread_subject, tt.thread_postcount
				FROM ".DB_FORUMS." tf
				INNER JOIN ".DB_THREADS." tt USING(forum_id)
				WHERE ".groupaccess('tf.forum_access')." AND tt.thread_postcount >= '".$min_posts."'".$timeframe." AND tt.thread_hidden='0'
				ORDER BY thread_postcount DESC, thread_lastpost DESC LIMIT 5");
			if (dbrows($result) != 0) {
				while($data = dbarray($result)) {
					$itemsubject = trimlink($data['thread_subject'], 20);
					echo "<li style='position:relative'><a href='".FORUM."viewthread.php?thread_id=".$data['thread_id']."' title='".$data['thread_subject']."'>".$itemsubject."</a><span style='position:absolute;right:0' class='side-small'>[".($data['thread_postcount'] - 1)."]</span>\n";
					echo "</li>\n";}
				} else {
				echo "<li>".$locale['global_023']."</li>\n";
			}
			echo "</ul>\n";
		echo "</div>\n";

			?>
		<!-- Latest Weblinks -->
		<div class="section">
			<?php
			echo "<h4>".$locale['latest_weblinks']."</h4><ul>\n";
			$result = dbquery("SELECT * FROM ".DB_WEBLINKS." ORDER BY weblink_datestamp DESC LIMIT 5");
			if (dbrows($result) != 0) {
			while($data = dbarray($result)) {
			$itemsubjectlink = trimlink($data['weblink_name'], 23);
			$itemdescriptionlink = trimlink($data['weblink_description'], 23);
			echo "<li><a href='".$data['weblink_url']."' target='_blank'>".$itemsubjectlink."</a></li>\n";
				}
			} else {
			echo "<li>".$locale['no_links']."</li>\n";
			}
			echo "</ul></div></div>\n";

//Subfooter			
	echo "<div class='flleft' style='width: 24%;padding: 14px 0 30px;text-align: left;'>Theme designed by <a href='http://www.php-fusion.co.uk'>JoiNNN</a></div>
			<div class='flright' style='width: 24%;padding: 14px 0 30px;text-align: right;'><a href='#member-area' id='top-link' class='scroll' >".$locale['scroll_top']."</a></div>
			".(!$license ? "<div id='copyright'>".showcopyright()."</div>" : "")."
			<div style='margin-top: 20px;text-align: center;'>".stripslashes($settings['footer'])."</div>\n";
	
	echo "<div id='subfooter' class='clearfix'>";
	echo "<div class='flleft' style='width: 50%'>";
			if ($settings['rendertime_enabled'] == 1 || ($settings['rendertime_enabled'] == 2 && iADMIN)) {echo "".showrendertime()."";}
	echo "</div>
			<div class='flright' style='width: 50%; text-align: right;'>".showcounter()."</div>
			</div>
			</div>
			</div>\n";
}


// Readmore function
function newsreadmore($info) {
	global $locale; $res = "";
	if (!isset($_GET['readmore']) && $info['news_ext'] == "y")
	$res = "<!--news_readmore-->
	<div class='read_more'>
		<a href='news.php?readmore=".$info['news_id']."'>
			<span>".$locale['global_072']."...</span>
		</a>
	</div>";
	return $res;
	}

// Render News
function render_news($subject, $news, $info) {
global $locale, $settings;
opentableN($subject, $info);
	echo "<ul class='info'>\n";
	//Author
	echo "<li class='author'>".profile_link($info['user_id'], $info['user_name'], $info['user_status'])."</li>\n";
	//Date
	echo "<li class='date'>".showdate("%d %b %Y", $info['news_date'])."</li>\n";
	//Category
	echo "<li class='cat'>\n";
		if ($info['cat_id']) { echo "<a href='".BASEDIR."news_cats.php?cat_id=".$info['cat_id']."'>".$info['cat_name']."</a>\n";
	} else { echo "<a href='".BASEDIR."news_cats.php?cat_id=0'>".$locale['global_080']."</a>"; }
	echo "</li>\n";
	//Reads
	if ($info['news_ext'] == "y" || ($info['news_allow_comments'] && $settings['comments_enabled'] == "1")) {
	echo "<li class='reads'>\n";
		echo $info['news_reads'].$locale['global_074']; 
	echo "</li>\n";}
	//Comments
	if ($info['news_allow_comments'] && $settings['comments_enabled'] == "1") { echo "<li class='comments'><a href='news.php?readmore=".$info['news_id']."#comments'>".$info['news_comments']."".($info['news_comments'] == 1 ? $locale['global_073b'] : $locale['global_073'])."</a></li>\n"; }
	echo "</ul>\n";
	//The message
	echo " ".$info['cat_image'].$news."\n".newsreadmore($info)."\n";
closetable();
}

// Render Articles
function render_article($subject, $article, $info) {
global $locale, $settings, $aidlink;
opentableA($subject, $info);
	echo "<ul class='info'>\n";
	//Author
	echo "<li class='author'>".profile_link($info['user_id'], $info['user_name'], $info['user_status'])."</li>\n";
	//Date
	echo "<li class='date'>".showdate("%d %b %Y", $info['article_date'])."</li>\n";
	//Category
	echo "<li class='cat'>\n";
		if ($info['cat_id']) { echo "<a href='".BASEDIR."articles.php?cat_id=".$info['cat_id']."'>".$info['cat_name']."</a>\n";
	} else { echo "<a href='".BASEDIR."articles.php?cat_id=0'>".$locale['global_080']."</a>"; }
	echo "</li>\n";
	//Reads
	echo "<li class='reads'>".$info['article_reads'].$locale['global_074']."</li>\n";
	//Comments
	if ($info['article_allow_comments'] && $settings['comments_enabled'] == "1") { echo "<li class='comments'><a href='".BASEDIR."articles.php?article_id=".$info['article_id']."#comments'>".$info['article_comments'].($info['article_comments'] == 1 ? $locale['global_073b'] : $locale['global_073'])."</a></li>\n"; }
	echo "</ul>\n";
	//The message
	echo " ".($info['article_breaks'] == "y" ? nl2br($article) : $article)."\n";
closetable();
}

//Render comments
function render_comments($c_data, $c_info){
		global $locale, $settings;
		opentable($locale['c100']);
		if (!empty($c_data)){
			echo "<div class='user-comments floatfix'>\n";
 			$c_makepagenav = '';
 			if ($c_info['c_makepagenav'] !== FALSE) { 
				echo $c_makepagenav = "<div style='text-align:center;margin-bottom:5px;'>".$c_info['c_makepagenav']."</div>\n"; 
			}

 			foreach($c_data as $data) {
				echo "<div id='c".$data['comment_id']."' class='comment'>\n";
					//User avatar
					if ($settings['comments_avatar'] == "1") { echo "<span class='user_avatar'>".$data['user_avatar']."</span>\n"; $noav = ""; } else { $noav = "noavatar"; }
					echo "<div class='tbl1 comment_wrap $noav'>";
					//Pointer tip
					if ($settings['comments_avatar'] == "1") { echo "<div class='pointer'><span class='bgc'></span></div>\n"; }
					//Options
					echo "<div class='comment-info'>";
					if ($data['edit_dell'] !== FALSE) { 
						echo "<div style='float:right' class='comment_actions'>".$data['edit_dell']."\n</div>\n";
					}
					//Info
					echo "<a href='".FUSION_REQUEST."#c".$data['comment_id']."'>#".$data['i']."</a> |\n";
					echo "<span class='comment-name'>".$data['comment_name']."</span>\n";
					echo "<span class='small'>".$data['comment_datestamp']."</span></div>\n";
					//The message
					echo "<div class='comment-msg'>".$data['comment_message']."</div></div></div>\n";
			}

			echo $c_makepagenav;
			if ($c_info['admin_link'] !== FALSE) {
				echo "<div class='comment_admin flright'>".$c_info['admin_link']."</div>\n";
			}
			echo "</div>\n";
		} else {
			echo $locale['c101']."\n";
		}
		closetable();   
	}

// News and Articles options
function newsopts2($info) {
	global $locale; $res = "";
	$res .= "<span class='print'><a href='print.php?type=N&item_id=".$info['news_id']."'><img src='".get_image("printer")."' alt='".$locale['global_075']."' title='".$locale['global_075']."' width='20' height='16' style='border:0;' /></a></span>\n";
	return "<!--news_opts-->".$res;
	}

function articleopts2($info) {
	global $locale; $res = "";
	$res .= "<span class='print'><a href='print.php?type=A&item_id=".$info['article_id']."'><img src='".get_image("printer")."' alt='".$locale['global_075']."' title='".$locale['global_075']."' width='20' height='16' style='border:0;' /></a></span>\n";
	return "<!--article_opts-->".$res;
}

function itemoptions2($item_type, $item_id) {
	global $locale, $aidlink; $res = "";
	if ($item_type == "N") {
		if (iADMIN && checkrights($item_type)) { $res .= "<span class='edit'><!--article_news_opts--> <a href='".ADMIN."news.php".$aidlink."&action=edit&news_id=".$item_id."'><img src='".get_image("edit")."' alt='".$locale['global_076']."' title='".$locale['global_076']."' width='16' height='16' style='border:0;' /></a></span>\n"; }
	} elseif ($item_type == "A") {
		if (iADMIN && checkrights($item_type)) { $res .= "<span class='edit'><!--article_admin_opts--> <a href='".ADMIN."articles.php".$aidlink."&action=edit&article_id=".$item_id."'><img src='".get_image("edit")."' alt='".$locale['global_076']."' title='".$locale['global_076']."' width='16' height='16' style='border:0;' /></a></span>\n"; }
	}
	return $res;
	}

// Content Panels
function opentable($title) {
echo "<div class='panel'>
			<h2 class='maincap'>
				<span>
					<span>
						<span class='title'>".$title."</span>
					</span>
				</span>
			</h2>\n";
echo "<div class='contentbody clearfix'>";
}

// News Panels
function opentableN($title, $info) {
echo "<div class='post'>
		 <h2 class='maincap'>
				<span>
					<span>
						<span class='title'>".$title."</span>
							<span class='options'>
								".itemoptions2("N",$info['news_id'])."
								".newsopts2($info)."
							</span>
					</span>
				</span>
			</h2>\n";
echo "<div class='contentbody clearfix'>";
}

// Article Panels
function opentableA($title, $info) {
echo "<div class='article'>
		 <h2 class='maincap'>
				<span>
					<span>
						<span class='title'>".$title."</span>
							<span class='options'>
								".itemoptions2("A",$info['article_id'])."
								".articleopts2($info)."
							</span>
					</span>
				</span>
			</h2>\n";
echo "<div class='contentbody clearfix'>";
}

function closetable() {
echo "</div></div>\n";
}

// Side panels
function openside($title, $collapse = false, $state = "on") {
global $panel_collapse, $p_data; $panel_collapse = $collapse;

echo "<h2 class='panelcap'>
			<span>
				<span>
					<span class='title'>".$title."</span>\n";
					if ($collapse == true) {
						$boxname = str_replace(" ", "", $title);
						echo "<span class='switcherbutton flright'>".panelbutton($state, $boxname)."</span>\n";
					}
			echo "</span>
			</span>
		</h2>
<div class='panelbody'>\n";
if ($collapse == true) { echo panelstate($state, $boxname); }
if ($p_data['panel_filename'] == "member_poll_panel"){echo "<div class='poll-panel'>";}
}

function closeside() {
global $panel_collapse, $p_data;

echo "</div>\n";
if ($p_data['panel_filename'] == "member_poll_panel"){echo "</div>";}
if ($panel_collapse == true) { echo "</div>\n"; }
}

?>
