<?php
include_once("include/config.php");

/*
 * If we are on the new theme and this is the homepage,
 * load the new look and view!
 * 3/16/2018
 *
 *
 * Removed from rtest, added a var to use it as a param.
 *
 * 2023-01-05 10:25:38 JD
 */
if ($_REQUEST['ld'] == 1 && ($_SERVER['REQUEST_URI'] == '/' || $_SERVER['REQUEST_URI'] == ''))
{
	// if ($__loggedUserDetails['USERID'] > 0)
	// {
	// 	include 'dashboard.php';
	// 	die();
	// }
	// else
	// {
	// 	include 'index_homepage.php';
	// 	die();
	// }

	if (!$config['isIonicware'])
	{
		include 'index_homepage.php';
		die();
	}

	include 'index_homepage.php';
	die();
}
include_once('include/functions/includes/string.php');
include_once("include/functions/import.php");
include_once("include/functions/includes/service.php");
include('ajax/paymentMethodMap.php');

/**
 * This is for custom subdomains. If a user has a custom
 * domain, we should load their profile page instead of the
 * index page.
 *
 * 2021-08-20 09:56:33 JD
 */
$subdomain = join('.', explode('.', $_SERVER['HTTP_HOST'], -2));

/**
 * Don't do anything for our main
 */
if (
	(stristr($_SERVER['SERVER_NAME'], 'seoclerk.com') ||
	stristr($_SERVER['SERVER_NAME'], 'seoclerks.com')) &&
	$subdomain != 'www' &&
	$subdomain != 'test' &&
	$subdomain != 'rtest' &&
	$subdomain != 'a' &&
	strlen($subdomain) > 3
  )
{
	/**
	 * Determine if it is a valid and active user
	 */
	if (GetUseridFromUsername($subdomain, 1) > 0)
	{
		$config['include']['wysibb'] 	= 1;
		$_REQUEST['uname'] 				= $subdomain;
		include "user.php";
		die();
	}
}

/**
 * If the users are coming from some sort of paid advertisement,
 * let's only show sellers who accept credit card (includes PayPal).
 *
 * This is in order to get a higher conversion rate.
 *
 * 2023-01-05 10:50:36 JD
 */
if (
		$_REQUEST['utm_content'] == 'ad' ||
		$_REQUEST['utm_source'] == 'adroll' ||
		!empty($_REQUEST['utm_source'])
	)
{
	$_REQUEST['filter'] 		= 1;
	$_REQUEST['paymentMethod'] 	= 'CreditCard'; // Includes PayPal
}

/**
 * This is a map of the filter array
 */
include('ajax/filterMap.php');

$thebaseurl = $config['baseurl'];

$s = stripslashes(strip_tags(cleanit($_REQUEST['s'])));

/*
 * We have to clean it here to prevent
 * reflected XSS when we display it in the code
 * 12-22-2014
 */
$s = str_ireplace(array('.', '<', '>', '"', "'", '/', '\\'), ' ', urldecode(stripslashes(strip_tags($s))));
//$s = cleanit($s);

/*
 * Set the default active page
 */
$sortactive = 'default';

/*
 * For the custom landing page
 * to do split testing
 * 1/13/2013
 */
$landing = intval($_REQUEST['l']);

//if (empty($_SESSION['USERID']) || $_SESSION['USERID'] == 0)
//{
//	$landing = 1;
//}
// Moved below to isHomePage section

/*
 * Get the type of listing we are looking for
 * 7/28/2012
 */
$type 		= addslashes(intval(stripslashes(strip_tags(cleanit($_REQUEST['t'])))));
$cid  		= addslashes(stripslashes(strip_tags(cleanit($_REQUEST['cid']))));
$cid  		= str_ireplace(array('.', '<', '>', "'", '"', '/', '\\'), ' ', urldecode(stripslashes(strip_tags($cid))));
$includes  	= addslashes(stripslashes(strip_tags(cleanit($_REQUEST['includes']))));
$includes 	= str_ireplace(array('.', '<', '>', '"', '/', '\\'), ' ', urldecode(stripslashes(strip_tags($includes))));
$tag  		= addslashes(stripslashes(strip_tags(cleanit($_REQUEST['tag']))));
$tag 		= str_ireplace(array('.', '<', '>', '"', '/', '\\'), ' ', urldecode(stripslashes(strip_tags($tag))));
$onsale 	= intval(stripslashes(strip_tags(cleanit($_REQUEST['o']))));
$subonly 	= stripslashes(strip_tags(cleanit($_REQUEST['sub'])));
$subonly 	= str_ireplace(array('.', '<', '>', "'", '"', '/', '\\'), ' ', urldecode(stripslashes(strip_tags($subonly))));
$trending 	= stripslashes(strip_tags(cleanit($_REQUEST['tnd'])));
$trending 	= str_ireplace(array('.', '<', '>', "'", '"', '/', '\\'), ' ', urldecode(stripslashes(strip_tags($trending))));
$proven 	= stripslashes(strip_tags(cleanit($_REQUEST['hq'])));
$proven 	= str_ireplace(array('.', '<', '>', "'", '"', '/', '\\'), ' ', urldecode(stripslashes(strip_tags($proven))));
$squery 	= cleanit($_REQUEST['query']); // Periods were being removed, which messed up searching 2022-09-01 21:10:47 - SE
$displayType = legacyNumber($_GET['displaytype']) > 0 ? intval($_GET['displaytype']) : intval($_POST['displaytype']); // the URL's text compared as 7.4 did: 8 compares 'abc' with a number as text (#1925)
$page 				= intval($_REQUEST['page']);
$removeFeatured 	= false;
$memberJoin 		= 0; // Used to include the members as C on the count query
$showbreadcrumbs	= 0; // Uni theme

/*
 * User level selection
 * 7/1/2016
 */
if ($_REQUEST['filter'] == 1)
{
	$latentAdds 	.= '&filter=1';

	if (!empty($_REQUEST['level']))
	{
		foreach ($_REQUEST['level'] as $lvl)
		{
			if (intval($lvl) && intval($lvl) >= 1 && intval($lvl) <= 5)
			{
				if (intval($lvl) == 4)
				{
					$levelString 	.= " C.userlevel >= '".addslashes($lvl)."' OR ";
				}
				else if (intval($lvl) == 5)
				{
					$levelString 	.= " C.userlevel >= '".addslashes($lvl)."' OR ";
				}
				else
				{
					$levelString 	.= " C.userlevel = '".addslashes($lvl)."' OR ";
				}
				$levelCounter = $levelCounter + intval($lvl);

				$latentAdds 	.= '&level[]=' . intval($lvl);
			}
		}

		if (!empty($levelString) && $levelCounter != 10) // 10 means they selected all levels
		{
			if (substr($levelString, -3) == 'OR ')
			{
				$levelString = substr($levelString, 0, -3);
			}
			$addsql			.= " AND ({$levelString})";
			$memberJoin 	= 1; // Enable the joining of the member table
		}
	}

	if (!empty($_REQUEST['pricerange']) && is_string($_REQUEST['pricerange']) && stristr($_REQUEST['pricerange'], ',')) // ?pricerange[]= skipped here on 7.4 too
	{
		$rangeArray = explode(',', $_REQUEST['pricerange']);

		if (intval($rangeArray[0]) > 1 || intval($rangeArray[1]) < 100)
		{
			if (intval($rangeArray[1]) == 100)
			{
				$addsql .= " AND price >= '".addslashes(intval($rangeArray[0]))."'";
			}
			else
			{
				$addsql .= " AND (price BETWEEN '".addslashes(intval($rangeArray[0]))."' AND '".addslashes(intval($rangeArray[1]))."' OR onsaleamount BETWEEN '".addslashes(intval($rangeArray[0]))."' AND '".addslashes(intval($rangeArray[1]))."')";
			}

			/**
			 * Price range fix.
			 * URLs cannot have periods in the middle of a url
			 * 7/18/2019 - SE
			 */
			$priceRange = strip_tags(cleanit(intval($rangeArray[0]))) . ',' . strip_tags(cleanit(intval($rangeArray[1])));

			$latentAdds 	.= '&pricerange=' . $priceRange;
			STemplate::assign('pricerangemin',intval($rangeArray[0]));
			STemplate::assign('pricerangemax',intval($rangeArray[1]));
		}
	}

	if (!empty($_REQUEST['paymentMethod']))
	{
		if (!is_array($_REQUEST['paymentMethod'])) $paymentMethods[] = $_REQUEST['paymentMethod'];
		else $paymentMethods = $_REQUEST['paymentMethod'];

		/**
		 * Keep the selected groups in pagination instead of expanding them into
		 * their individual payment methods.
		 *
		 * 2021-11-20 06:17:08 JD
		 */
		foreach ($paymentMethods as $pm) $latentAdds 	.= '&paymentMethod[]=' . strip_tags(cleanit($pm));

		/**
		 * Payment settings moved out of members.profile_data in 2021. Checkout
		 * reads payment_user_method, so marketplace results need to use the same
		 * current settings or an enabled method can be offered on the service but
		 * filtered out of search.
		 *
		 * 2026-09-12 JD
		 */
		$paymentFilterSql = PaymentMethodFilterSql($paymentMethods);
		if (!empty($paymentFilterSql))
		{
			$addsql .= " AND {$paymentFilterSql}";
		}
	}

	/*
	 * Phone verification
	 * 7/2/2016
	 */
	if ($_REQUEST['phoneverified'] == 1)
	{
		$addsql 		.= " AND C.phone_verified=1 ";
		$memberJoin 	= 1; // Enable the joining of the member table
		$latentAdds 	.= '&phoneverified=1';
	}
	STemplate::assign('phoneverified',intval($_REQUEST['phoneverified']));

	/*
	 * Address verified
	 * 7/2/2016
	 */
	if ($_REQUEST['addressverified'] == 1)
	{
		$addsql 		.= " AND C.address_verified=1 ";
		$memberJoin 	= 1; // Enable the joining of the member table
		$latentAdds 	.= '&addressverified=1';
	}
	STemplate::assign('addressverified',intval($_REQUEST['addressverified']));

	/*
	 * Address verified
	 * 7/2/2016
	 */
	if ($_REQUEST['idverified'] == 1)
	{
		$addsql 		.= " AND C.identity_verified=1 ";
		$memberJoin 	= 1; // Enable the joining of the member table
		$latentAdds 	.= '&idverified=1';
	}
	STemplate::assign('idverified',intval($_REQUEST['idverified']));

	/*
	 * Vetted seller filter (issue #1264)
	 * 2026-09-22
	 */
	if ($_REQUEST['vetted'] == 1)
	{
		$addsql 		.= " AND C.vetted=1 ";
		$memberJoin 	= 1; // Enable the joining of the member table
		$latentAdds 	.= '&vetted=1';
	}
	STemplate::assign('vetted',intval($_REQUEST['vetted']));


	/*
	 * Address verified
	 * 7/2/2016
	 */
	if ($_REQUEST['onlinenow'] == 1)
	{
		$addsql 		.= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-1800 "; // 30 min
		$memberJoin 	= 1; // Enable the joining of the member table
		$latentAdds 	.= '&onlinenow=1';
	}
	else if ($_REQUEST['onlinenow'] == 2)
	{
		$addsql 		.= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-86400 "; // 24 hours
		$memberJoin 	= 1;
		$latentAdds 	.= '&onlinenow=2';
	}
	else if ($_REQUEST['onlinenow'] == 3)
	{
		$addsql 		.= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-432000 "; // 5 days
		$memberJoin 	= 1;
		$latentAdds 	.= '&onlinenow=3';
	}
	else if ($_REQUEST['onlinenow'] == 4)
	{
		$addsql 		.= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-864000 "; // 10 days
		$memberJoin 	= 1;
		$latentAdds 	.= '&onlinenow=4';
	}
	else if ($_REQUEST['onlinenow'] == 5)
	{
		$addsql 		.= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-4320000 "; // 50 days
		$memberJoin 	= 1;
		$latentAdds 	.= '&onlinenow=5';
	}
	else if ($_REQUEST['onlinenow'] == 6)
	{
		$addsql 		.= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-12960000 "; // 150 days
		$memberJoin 	= 1;
		$latentAdds 	.= '&onlinenow=6';
	}
	else if ($_REQUEST['onlinenow'] == 7)
	{
		$addsql 		.= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-31536000 "; // 1 year
		$memberJoin 	= 1;
		$latentAdds 	.= '&onlinenow=7';
	}
	STemplate::assign('onlinenow',intval($_REQUEST['onlinenow']));

	/*
	 * Active for 30 days or less
	 * 2022-12-20 10:16:42 - SE
	 */
	if ($_REQUEST['activeonly'] == 1)
	{
		$addsql 		.= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-2592000 "; // 30 min
		$memberJoin 	= 1; // Enable the joining of the member table
		$latentAdds 	.= '&activeonly=1';
	}

	/*
	 * Average response time
	 */
	if (!empty($_REQUEST['avgrestime']) && is_string($_REQUEST['avgrestime']) && stristr($_REQUEST['avgrestime'], ',')) // ?avgrestime[]= skipped here on 7.4 too
	{
		$rangeArray = explode(',', $_REQUEST['avgrestime']);

		/*
		 * Convert these into seconds
		 */
		$minSeconds = legacyNumber($rangeArray[0]) * 3600; // the URL's text read as 7.4 did: 8 throws on ?avgrestime=a,b
		$maxSeconds = legacyNumber($rangeArray[1]) * 3600;

		if (intval($rangeArray[0]) > 1 || intval($rangeArray[1]) < 100)
		{
			if (intval($rangeArray[1]) == 100)
			{
				$addsql .= " AND C.average_response_time >= '".addslashes(intval($minSeconds))."'";
			}
			else if (intval($rangeArray[0]) == 1)
			{
				$addsql .= " AND C.average_response_time <= '".addslashes(intval($maxSeconds))."'";
			}
			else
			{
				$addsql .= " AND C.average_response_time BETWEEN '".addslashes(intval($minSeconds))."' AND '".addslashes(intval($maxSeconds))."'";
			}

			$memberJoin 	= 1; // Enable the joining of the member table
			STemplate::assign('avgrestimemin',intval($rangeArray[0]));
			STemplate::assign('avgrestimemax',intval($rangeArray[1]));
			$latentAdds 	.= '&avgrestime=' . strip_tags(cleanit($_REQUEST['avgrestime']));

		}
	}

	/*
	* Apply include filter
	*/
	if (!empty($_REQUEST['filterInclude']))
	{
		foreach ($_REQUEST['filterInclude'] as $additonal)
		{
			$additonal = removeNonAlphaNumeric($additonal);
			$addsql .= " AND includes_data LIKE '%".addslashes($additonal)."%' ";

			$latentAdds 	.= '&filterInclude[]=' . intval($additonal);
		}
	}

	/*
	 * Country filter
	 * Filters by seller country using members_security.country (set during address verification).
	 * The field stores an encrypted ISO 2-letter country code.
	 * encryptLegacyLookup(), NOT encrypt(): this filter matches by comparing
	 * ciphertexts, which only works with a deterministic cipher. encrypt() has
	 * been randomized (issue #978), so members_security.country stays in the
	 * legacy deterministic format - it is excluded from the encryption
	 * migration and its write sites use the legacy encoder too.
	 */
	if (!empty($_REQUEST['country']) && is_string($_REQUEST['country']))
	{
		$country = strtoupper(preg_replace('/[^A-Za-z]/', '', $_REQUEST['country']));
		if (array_key_exists($country, getCountriesMap()))
		{
			/*
			 * Plaintext code (issue #978 retirement, phase 1) - and, until
			 * migrateCountryPlaintext.php has run, the legacy ciphertext of
			 * it too. Phase 2 drops the second value.
			 */
			$plainCountry		= escape($country);
			$encryptedCountry	= escape(encryptLegacyLookup($country, $config['telephoneKey']));
			$addsql		.= " AND A.USERID IN (SELECT USERID FROM seoclerks.members_security WHERE country IN ('{$plainCountry}', '{$encryptedCountry}'))";
			$latentAdds	.= '&country=' . urlencode($country);
		}
	}

	/*
	 * Turn off the landing page
	 * 5/1/2017
	 */
	$landing = 0;
}

if (!empty($includes))
{
	$additonal = removeNonAlphaNumeric($includes);
	$addsql .= " AND includes_data LIKE '%".addslashes($additonal)."%' ";

	$latentAdds 	.= '&filterInclude[]=' . intval($additonal);
}

/*
 * Are we on the homepage?
 * 8/28/2012
 */
$isHomepage = false;

/*
 * H2 Header for good SEO
 * 7/3/2013
 */
$h2header = $lang['1429'];

/*
 * Disable certain twitter listings.
 * 11/22/2016
 */
/*$addsql	.= " AND
			(A.gtitle NOT LIKE '%twitter%' AND
				(A.gtitle NOT LIKE '%follow%'
					OR A.gtitle NOT LIKE '%comment%'
					OR A.gtitle NOT LIKE '%like%'
				)
			) ";*/

/*
 * Depending on the type, do some
 * different stuff
 * 0 = Gig
 * 1 = Article
 * 2 = ??
 * 3 = ??
 * 4 = Tweets
 * 5 = blogs
 * 6 = ebooks
 * 7 = Software
 * 8 = Theme
 * 20 = marketplace only (SEO Gigs only)
 *
 * 7/29/2012
 */
if ($type == 1)
{
	// article

	/*
	 * Change the Meta description
	 * 5/14/2013
	 */
	$h2header	= $lang['1894'];

	/*
	 * Uni theme variables.
	 * 06/19/2018
	 */
	$breadHome 		= 'articles';
	$breadHomeName	= $lang['1894'];
	$breadCatUrl	= 'articlecats';
	$breadTagUrl	= 'articletags';

	if (!empty($cid)) {
		$categoryDetails = GetCategoryInfoFromTypeSeo('1', $cid);

		if (!empty($tag)) {
			$pagevalue 	= "/articletags/{$cid}/{$tag}/page/";
			$sortvalue  = "articletags/{$cid}/{$tag}";
		} else {
			$pagevalue 	= "/articlecats/{$cid}/page/";
			$sortvalue  = "articlecats/{$cid}";
		}

		$tableCat	= 'categories_articles';

		/*
		 * Set the category SEO
		 * 11/7/2012
		 */
		if (!empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metakeywords'])) {
		}
		if (!empty($categoryDetails['metaheader']) && empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metatitle'])) {
			$pagetitle		 = $categoryDetails['metatitle'];
		} else {
			$pagetitle 		 = $categoryDetails['name'] . ' ' . $lang['519'] . ' ' . $lang['1090'];
		}

		/*
		 * If we have the h2header, lets assign
		 * it so users see it.
		 * 7/3/2013
		 */
		if (!empty($categoryDetails['h2header'])) {
			$h2header		 = $categoryDetails['h2header'];
		}

		/*
		 * Get the category in string
		 */
		$inString = GetCategoryChildString($tableCat, $categoryDetails['CATID']);

		/*
		 * Generate some AddSQL
		 *
		 * Added a forexIndex value
		 *
		 * 2025-07-21 06:14:06 JD
		 */
		if (!empty($inString))
		{
			$addsql 	.= " AND category IN ({$inString})";

			/**
			 * Force our query to use an index
			 *
			 * 2025-07-21 06:14:40 JD
			 */
			if (empty($forcedIndex )) $forcedIndex = "category";
		}

		/*
		 * get Tags
		 * 10/28/2012
		 */
		/*$query="SELECT gtags FROM posts
				WHERE category='".addslashes($categoryDetails['CATID'])."'
				AND type='1'
				order by rand() limit 20";
		$results=$conn->CacheExecute(60, $query);
		$gtags = $results->getrows();
		for($i=0; $i<count($gtags);$i++)
		{
			$tags .= FormatTags($gtags[$i][0]) ." ";
		}
		$tags = str_replace("  ", " ", $tags);
		$tags = str_replace("/", "", $tags);
		$tags = explode(" ", implode(" ", array_unique(explode(" ", $tags))));
		STemplate::assign('tags',$tags);
		STemplate::assign('showtags',1);*/

	} else {
		$pagetitle = $lang['520'];
		$pagevalue = '/articles/page/';
	}
} else if ($type == 6) {
	// ebooks

	/*
	 * Change the Meta description
	 * 5/14/2013
	 */
	$h2header = $lang['1082'];

	/*
	 * Uni theme variables.
	 * 06/19/2018
	 */
	$breadHome 		= 'ebooks';
	$breadHomeName	= $lang['1082'];
	$breadCatUrl	= 'ebookcats';
	$breadTagUrl	= 'ebooktags';

	if (!empty($cid)) {
		$categoryDetails = GetCategoryInfoFromTypeSeo('6', $cid);
		if (!empty($tag)) {
			$pagevalue 	= "/ebooktags/{$cid}/{$tag}/page/";
			$sortvalue  = "ebooktags/{$cid}/{$tag}";
		} else {
			$pagevalue 	= "/ebookcats/{$cid}/page/";
			$sortvalue  = "ebookcats/{$cid}";
		}

		$tableCat	= 'categories_ebooks';


		/*
		 * Set the category SEO
		 * 11/7/2012
		 */
		if (!empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metakeywords'])) {
		}
		if (!empty($categoryDetails['metaheader']) && empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metatitle'])) {
			$pagetitle		 = $categoryDetails['metatitle'];
		} else {
			$pagetitle 		 = $categoryDetails['name'] . ' ' . $lang['1082'] . ' ' . $lang['1090'];
		}

		/*
		 * If we have the h2header, lets assign
		 * it so users see it.
		 * 7/3/2013
		 */
		if (!empty($categoryDetails['h2header'])) {
			$h2header		 = $categoryDetails['h2header'];
		}

		/*
		 * Get the category in string
		 */
		$inString = GetCategoryChildString($tableCat, $categoryDetails['CATID']);

				/*
		 * Generate some AddSQL
		 *
		 * Added a forexIndex value
		 *
		 * 2025-07-21 06:14:06 JD
		 */
		if (!empty($inString))
		{
			$addsql 	.= " AND category IN ({$inString})";

			/**
			 * Force our query to use an index
			 *
			 * 2025-07-21 06:14:40 JD
			 */
			if (empty($forcedIndex )) $forcedIndex = "category";
		}

		/*
		 * get Tags
		 * 10/28/2012
		 */
		/*$query="SELECT gtags FROM posts
				WHERE category='".addslashes($categoryDetails['CATID'])."'
				AND type='6'
				order by rand() limit 20";
		$results=$conn->CacheExecute(60, $query);
		$gtags = $results->getrows();
		for($i=0; $i<count($gtags);$i++)
		{
			$tags .= removeNonAlphaNumeric($gtags[$i][0], ' ') ." ";
		}
		$tags = str_replace("  ", " ", $tags);
		$tags = str_replace("/", "", $tags);
		$tags = explode(" ", implode(" ", array_unique(explode(" ", $tags))));
		STemplate::assign('tags',$tags);
		STemplate::assign('showtags',1);*/

	} else {
		$pagetitle = $lang['1083'];
		$pagevalue = '/ebooks/page/';
	}
} else if ($type == 7) {
	// Software

	/*
	 * Change the Meta description
	 * 5/14/2013
	 */
	$h2header = $lang['1154'];

	/*
	 * Uni theme variables.
	 * 06/19/2018
	 */
	$breadHome 		= 'software';
	$breadHomeName	= $lang['1154'];
	$breadCatUrl	= 'softwarecats';
	$breadTagUrl	= 'softwaretags';

	if (!empty($cid)) {
		$categoryDetails = GetCategoryInfoFromTypeSeo('7', $cid);
		if (!empty($tag)) {
			$pagevalue 	= "/softwaretags/{$cid}/{$tag}/page/";
			$sortvalue  = "softwaretags/{$cid}/{$tag}";
		} else {
			$pagevalue 	= "/softwarecats/{$cid}/page/";
			$sortvalue  = "softwarecats/{$cid}";
		}

		$tableCat	= 'categories_software';


		/*
		 * Set the category SEO
		 * 11/7/2012
		 */
		if (!empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metakeywords'])) {
		}
		if (!empty($categoryDetails['metaheader']) && empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metatitle'])) {
			$pagetitle		 = $categoryDetails['metatitle'];
		} else {
			$pagetitle 		 = $categoryDetails['name'] . ' ' . $lang['1154'] . ' ' . $lang['1090'];
		}

		/*
		 * If we have the h2header, lets assign
		 * it so users see it.
		 * 7/3/2013
		 */
		if (!empty($categoryDetails['h2header'])) {
			$h2header		 = $categoryDetails['h2header'];
		}

		/*
		 * Get the category in string
		 */
		$inString = GetCategoryChildString($tableCat, $categoryDetails['CATID']);

		/*
		 * Generate some AddSQL
		 */
		if (!empty($inString)) $addsql .= " AND category IN ({$inString})";

		/*
		 * get Tags
		 * 10/28/2012
		 */
		/*$query="SELECT gtags FROM posts
				WHERE category='".addslashes($categoryDetails['CATID'])."'
				AND type='7'
				order by rand() limit 20";
		$results=$conn->CacheExecute(60, $query);
		$gtags = $results->getrows();
		for($i=0; $i<count($gtags);$i++)
		{
			$tags .= removeNonAlphaNumeric($gtags[$i][0], ' ') ." ";
		}
		$tags = str_replace("  ", " ", $tags);
		$tags = str_replace("/", "", $tags);
		$tags = explode(" ", implode(" ", array_unique(explode(" ", $tags))));
		STemplate::assign('tags',$tags);
		STemplate::assign('showtags',1);*/

	} else {
		$pagetitle = $lang['1157'];
		$pagevalue = '/software/page/';
	}
} else if ($type == 8) {
	// Theme

	/*
	 * Change the Meta description
	 * 5/14/2013
	 */
	$h2header = $lang['1156'];

	/*
	 * Uni theme variables.
	 * 06/19/2018
	 */
	$breadHome 		= 'theme';
	$breadHomeName	= $lang['1156'];
	$breadCatUrl	= 'themecats';
	$breadTagUrl	= 'themetags';

	if (!empty($cid)) {
		$categoryDetails = GetCategoryInfoFromTypeSeo('8', $cid);
		if (!empty($tag)) {
			$pagevalue 	= "/themetags/{$cid}/{$tag}/page/";
			$sortvalue  = "themetags/{$cid}/{$tag}";
		} else {
			$pagevalue 	= "/themecats/{$cid}/page/";
			$sortvalue  = "themecats/{$cid}";
		}

		$tableCat	= 'categories_theme';

		/*
		 * Set the category SEO
		 * 11/7/2012
		 */
		if (!empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metakeywords'])) {
		}
		if (!empty($categoryDetails['metaheader']) && empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metatitle'])) {
			$pagetitle		 = $categoryDetails['metatitle'];
		} else {
			$pagetitle 		 = $categoryDetails['name'] . ' ' . $lang['1156'] . ' ' . $lang['1090'];
		}

		/*
		 * If we have the h2header, lets assign
		 * it so users see it.
		 * 7/3/2013
		 */
		if (!empty($categoryDetails['h2header'])) {
			$h2header		 = $categoryDetails['h2header'];
		}

		/*
		 * Get the category in string
		 */
		$inString = GetCategoryChildString($tableCat, $categoryDetails['CATID']);

				/*
		 * Generate some AddSQL
		 *
		 * Added a forexIndex value
		 *
		 * 2025-07-21 06:14:06 JD
		 */
		if (!empty($inString))
		{
			$addsql 	.= " AND category IN ({$inString})";

			/**
			 * Force our query to use an index
			 *
			 * 2025-07-21 06:14:40 JD
			 */
			if (empty($forcedIndex )) $forcedIndex = "category";
		}

		/*
		 * get Tags
		 * 10/28/2012
		 */
		/*$query="SELECT gtags FROM posts
				WHERE category='".addslashes($categoryDetails['CATID'])."'
				AND type='8'
				order by rand() limit 20";
		$results=$conn->CacheExecute(60, $query);
		$gtags = $results->getrows();
		for($i=0; $i<count($gtags);$i++)
		{
			$tags .= removeNonAlphaNumeric($gtags[$i][0], ' ') ." ";
		}
		$tags = str_replace("  ", " ", $tags);
		$tags = str_replace("/", "", $tags);
		$tags = explode(" ", implode(" ", array_unique(explode(" ", $tags))));
		STemplate::assign('tags',$tags);
		STemplate::assign('showtags',1);*/

	} else {
		$pagetitle = $lang['1158'];
		$pagevalue = '/theme/page/';
	}
} else if ($type == 4) {
	// Tweets

	/*
	 * Change the Meta description
	 * 5/14/2013
	 */
	$h2header = $lang['543'];

	/*
	 * Uni theme variables.
	 * 06/19/2018
	 */
	$breadHome 		= 'sponsoredtweets';
	$breadHomeName	= $lang['543'];
	$breadCatUrl	= 'twittercats';
	$breadTagUrl	= 'twittertags';

	if (!empty($cid)) {
		$categoryDetails = GetCategoryInfoFromTypeSeo('4', $cid);
		if (!empty($tag)) {
			$pagevalue 	= "/twittertags/{$cid}/{$tag}/page/";
			$sortvalue  = "twittertags/{$cid}/{$tag}";
		} else {
			$pagevalue 	= "/twittercats/{$cid}/page/";
			$sortvalue  = "twittercats/{$cid}";
		}

		$tableCat	= 'categories_tweets';

		/*
		 * Set the category SEO
		 * 11/7/2012
		 */
		if (!empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metakeywords'])) {
		}
		if (!empty($categoryDetails['metaheader']) && empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metatitle'])) {
			$pagetitle		 = $categoryDetails['metatitle'];
		} else {
			$pagetitle 		 = $categoryDetails['name'] . ' ' . $lang['542'] . ' ' . $lang['1090'];
		}

		/*
		 * If we have the h2header, lets assign
		 * it so users see it.
		 * 7/3/2013
		 */
		if (!empty($categoryDetails['h2header'])) {
			$h2header		 = $categoryDetails['h2header'];
		}

		/*
		 * Get the category in string
		 */
		$inString = GetCategoryChildString($tableCat, $categoryDetails['CATID']);

				/*
		 * Generate some AddSQL
		 *
		 * Added a forexIndex value
		 *
		 * 2025-07-21 06:14:06 JD
		 */
		if (!empty($inString))
		{
			$addsql 	.= " AND category IN ({$inString})";

			/**
			 * Force our query to use an index
			 *
			 * 2025-07-21 06:14:40 JD
			 */
			if (empty($forcedIndex )) $forcedIndex = "category";
		}

		/*
		 * get Tags
		 * 10/28/2012
		 */
		/*$query="SELECT gtags FROM posts
				WHERE category='".addslashes($categoryDetails['CATID'])."'
				AND type='4'
				order by rand() limit 20";
		$results=$conn->CacheExecute(60, $query);
		$gtags = $results->getrows();
		for($i=0; $i<count($gtags);$i++)
		{
			$tags .= removeNonAlphaNumeric($gtags[$i][0], ' ') ." ";
		}
		$tags = str_replace("  ", " ", $tags);
		$tags = str_replace("/", "", $tags);
		$tags = explode(" ", implode(" ", array_unique(explode(" ", $tags))));
		STemplate::assign('tags',$tags);
		STemplate::assign('showtags',1);*/

	} else {
		$pagetitle = $lang['545'];
		$pagevalue = '/sponsoredtweets/page/';
	}
} else if ($type == 5) {
	// Blogs

	/*
	 * Change the Meta description
	 * 5/14/2013
	 */
	$h2header = $lang['1093'];

	/*
	 * Uni theme variables.
	 * 06/19/2018
	 */
	$breadHome 		= 'reviews';
	$breadHomeName	= $lang['1093'];
	$breadCatUrl	= 'reviewcats';
	$breadTagUrl	= 'reviewtags';

	if (!empty($cid)) {
		$categoryDetails = GetCategoryInfoFromTypeSeo('4', $cid);

		if (!empty($tag)) {
			$pagevalue 	= "/reviewtags/{$cid}/{$tag}/page/";
			$sortvalue  = "reviewtags/{$cid}/{$tag}";
		} else {
			$pagevalue 	= "/reviewcats/{$cid}/page/";
			$sortvalue  = "reviewcats/{$cid}";
		}

		$tableCat	= 'categories_blogs';

		/*
		 * Set the category SEO
		 * 11/7/2012
		 */
		if (!empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metakeywords'])) {
		}
		if (!empty($categoryDetails['metaheader']) && empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metatitle'])) {
			$pagetitle		 = $categoryDetails['metatitle'];
		} else {
			$pagetitle 		 = $categoryDetails['name'] . ' ' . $lang['1093'] . ' ' . $lang['1090'];
		}

		/*
		 * If we have the h2header, lets assign
		 * it so users see it.
		 * 7/3/2013
		 */
		if (!empty($categoryDetails['h2header'])) {
			$h2header		 = $categoryDetails['h2header'];
		}

		/*
		 * Get the category in string
		 */
		$inString = GetCategoryChildString($tableCat, $categoryDetails['CATID']);

				/*
		 * Generate some AddSQL
		 *
		 * Added a forexIndex value
		 *
		 * 2025-07-21 06:14:06 JD
		 */
		if (!empty($inString))
		{
			$addsql 	.= " AND category IN ({$inString})";

			/**
			 * Force our query to use an index
			 *
			 * 2025-07-21 06:14:40 JD
			 */
			if (empty($forcedIndex )) $forcedIndex = "category";
		}

		/*
		 * get Tags
		 * 10/28/2012
		 */
		/*$query="SELECT gtags FROM posts
				WHERE category='".addslashes($categoryDetails['CATID'])."'
				AND type='5'
				order by rand() limit 20";
		$results=$conn->CacheExecute(60, $query);
		$gtags = $results->getrows();
		for($i=0; $i<count($gtags);$i++)
		{
			$tags .= removeNonAlphaNumeric($gtags[$i][0], ' ') ." ";
		}
		$tags = str_replace("  ", " ", $tags);
		$tags = str_replace("/", "", $tags);
		$tags = explode(" ", implode(" ", array_unique(explode(" ", $tags))));
		STemplate::assign('tags',$tags);
		STemplate::assign('showtags',1);*/

	} else {
		$pagetitle = $lang['885'];
		$pagevalue = '/reviews/page/';
	}
} else if ($type == 20) {

	/*
	 * Uni theme variables.
	 * 06/19/2018
	 */
	$breadHome 		= 'marketplace';
	$breadHomeName	= $lang['493'];
	$breadCatUrl	= 'categories';
	$breadTagUrl	= 'tags';

	if (!empty($cid)) {
		$categoryDetails = GetCategoryInfoFromTypeSeo('0', $cid);

		/*
		 * Put the live service count and starting price into any {count} or
		 * {from} in the title, description and heading, before anything below
		 * reads them. See fillCategorySeoPlaceholders().
		 *
		 * 2026-09-22
		 */
		$categoryDetails = fillCategorySeoPlaceholders($categoryDetails, 'categories');

		if (!empty($tag)) {
			$pagevalue 	= "/tags/{$cid}/{$tag}/page/";
			$sortvalue  = "tags/{$cid}/{$tag}";
		} else {
			$pagevalue 	= "/categories/{$cid}/page/";
			$sortvalue  = "categories/{$cid}";
		}

		$tableCat	= 'categories';

		/*
		 * Set the category SEO
		 * 11/7/2012
		 */
		if (!empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metakeywords'])) {
		}
		if (!empty($categoryDetails['metaheader']) && empty($categoryDetails['metadescription'])) {
		}
		if (!empty($categoryDetails['metatitle'])) {
			$pagetitle		 = $categoryDetails['metatitle'];
		} else {
			$pagetitle 		 = $categoryDetails['name'] . ' ' . $lang['123'];
		}

		/*
		 * If we have the h2header, lets assign
		 * it so users see it.
		 * 7/3/2013
		 */
		if (!empty($categoryDetails['h2header'])) {
			$h2header		 = $categoryDetails['h2header'];
		}

		/*
		 * Get the category in string
		 */
		$inString = GetCategoryChildString($tableCat, $categoryDetails['CATID']);

				/*
		 * Generate some AddSQL
		 *
		 * Added a forexIndex value
		 *
		 * 2025-07-21 06:14:06 JD
		 */
		if (!empty($inString))
		{
			$addsql 	.= " AND category IN ({$inString})";

			/**
			 * Force our query to use an index
			 *
			 * 2025-07-21 06:14:40 JD
			 */
			if (empty($forcedIndex )) $forcedIndex = "category";
		}

		/*
		 * get Tags
		 * 10/28/2012
		 */
		/*$query="SELECT gtags FROM posts
				WHERE category='".addslashes($categoryDetails['CATID'])."'
				AND type='0'
				order by rand() limit 20";
		$results=$conn->CacheExecute(60, $query);
		$gtags = $results->getrows();
		for($i=0; $i<count($gtags);$i++)
		{
			$tags .= removeNonAlphaNumeric($gtags[$i][0], ' ') ." ";
		}
		$tags = str_replace("  ", " ", $tags);
		$tags = str_replace("/", "", $tags);
		$tags = explode(" ", implode(" ", array_unique(explode(" ", $tags))));
		STemplate::assign('tags',$tags);
		STemplate::assign('showtags',1);*/

	} else {
		$pagetitle = $lang['549'];
		$pagevalue = '/marketplace/page/';
	}
} else {
	$pagetitle  = stripslashes($config['site_slogan']);
	$pagevalue  = '/page/';
	$isHomepage = 1;
	$tableCat	= 'categories';

	/*
	 * Added on 4/3/2013
	 * If the user is linking into a gig using an
	 * affiliate link, forward them to the correct
	 * URL
	 *
	 * Aff should go to the affiliate
	 */
	$affLinkId = affiliateLinkId($_REQUEST['aff'] ?? '');
	if ($affLinkId > 0 && !stristr($_SERVER['HTTP_HOST'], 'a.')) {
		/*
		 * If the user is searching, forward
		 * them to the search URL
		 * 12/26/2013
		 */
		if ($_REQUEST['query']) {
			header("HTTP/1.1 301 Moved Permanently");
			header("location: $config[aurl]/linkin/{$affLinkId}/search/{$_REQUEST['query']}");
		}
		else
		{
			header("HTTP/1.1 301 Moved Permanently");
			header("location: $config[aurl]/linkin/{$affLinkId}");
		}

	}



	if (!empty($cid)) {
		$categoryDetails = GetCategoryInfoFromTypeSeo('0', $cid);
		$categoryDetails = fillCategorySeoPlaceholders($categoryDetails, 'categories');

		/*
		 * Get the category in string
		 */
		$inString = GetCategoryChildString($tableCat, $categoryDetails['CATID']);

				/*
		 * Generate some AddSQL
		 *
		 * Added a forexIndex value
		 *
		 * 2025-07-21 06:14:06 JD
		 */
		if (!empty($inString))
		{
			$addsql 	.= " AND category IN ({$inString})";

			/**
			 * Force our query to use an index
			 *
			 * 2025-07-21 06:14:40 JD
			 */
			if (empty($forcedIndex )) $forcedIndex = "category";
		}

		/*
		 * If we have the h2header, lets assign
		 * it so users see it.
		 * 7/3/2013
		 */
		if (!empty($categoryDetails['h2header'])) {
			$h2header		 = $categoryDetails['h2header'];
		}
		else
		{
			//$h2header		= $categoryDetails['name'];
		}

	}

}

if (!empty($cid))
{

	$childArray = GetCategoryChild($tableCat, $categoryDetails['CATID']);

	/**
	 * Get each sub-category card ready
	 */
	foreach($childArray as &$chil)
	{
		// The child cards print metatitle, so a templated one needs its numbers too.
		$chil = fillCategorySeoPlaceholders($chil, $tableCat);

		if (strpos($chil['metatitle'], 'Social Post') !== false) $chil['metatitle'] = '';

		/*
		 * No colour class: every category has its own picture now
		 * (assets/brand/build/category_art.py), Navy under a white title, and the
		 * Navy behind it while it loads is .category-card's in styles.css. The card
		 * used to take a random colour on every request, and one in five was
		 * bg-white with a black title - unreadable on the art.
		 *
		 * 2026-09-24 JD
		 */
		$chil['color'] = '';
	}
}

/*
 * Does the user have some form of tags?
 * 10/28/2012
 */
if (!empty($tag))
{
	$tag = removeNonAlphaNumeric($tag);
	$addsql .= " AND gtags like'%".addslashes($tag)."%' ";

	/**
	 * Force our query to use an index
	 *
	 * 2025-07-21 06:14:40 JD
	 */
	if (empty($forcedIndex )) $forcedIndex = "homepage_search";

}

/*
 * Enable the landing page only for the homepage.
 * 6/4/2017
 */
if ($isHomepage == 1)
{
	if (empty($_SESSION['USERID']) || $_SESSION['USERID'] == 0)
	{
		$landing = 1;
	}
	else
	{
		$landing = 0;
	}
}
else
{
	$landing = 0;
}

/*
 * Fetch our breadcrumb data
 */
if (!empty($cid) && $isHomepage == 0)
{
	/*
	 * Get all of the parents
	 * Category data for the nav
	 * 6/18/2016
	 */
	if ($categoryDetails['parentid'] > 0)
	{
		$parentCatDetails = GetCategorySeoFromType($type, $categoryDetails['parentid']); // Art & design

		if ($parentCatDetails['parentid'] > 0)
		{
			$pParentCatDetails 	= GetCategorySeoFromType($type, $parentCatDetails['parentid']);

			if ($pParentCatDetails['parentid'] > 0)
			{
				$ppParentCatDetails 	= GetCategorySeoFromType($type, $pParentCatDetails['parentid']);
				$preCategory[] 			= $ppParentCatDetails;
			}

			$preCategory[] 		= $pParentCatDetails;
		}

		$preCategory[] 		= $parentCatDetails;
	}

	/*
	 * Assign values for the breadcrumb here
	 * 7/20/2017
	 */

	/*
	 * Uni theme variables.
	 * 06/19/2018
	 */
	$showbreadcrumbs 	= 1;
	$categoryseo		= $categoryDetails['seo'];
	$categoryname		= $categoryDetails['name'];
}

/*
 * Let the view know that we
 * are on the homepage or not
 * 8/28/2012
 */

/*
 * Do an addsql to add it below
 * 7/29/2012
 */
if ($type > 0 && $type != 20)
{
	$addsql .= " AND type={$type} ";
}
else if ($type == 20)
{
	/**
	 * On the unitheme, the marketplace is the global
	 * index for all services. On the old theme, the Marketplace was
	 * just for services while software and / (index) were for everything.
	 * 2/14/2019
	 */
	if ($config['themeUni'] != 1) $addsql .= " AND type=0 ";
}

/*
 * Onsale only services!
 * 1/10/2013
 */
if ($onsale == 1)
{
	$addsql 	.= " AND onsale=1 ";
	$pagetitle   = $lang['2401'];
	$sortactive	 = "price";
}

/*
 * Trending sales
 * 6/30/2016
 */
if (!empty($trending) && !empty($_REQUEST['tnd']))
{
	/*
	 * orders.time_added is a varchar, so comparing it to a number
	 * can't use its index and scans all ~8.6M orders (~20s cold).
	 * The string comparison uses the index (10-digit timestamps sort
	 * as strings); the numeric one keeps the exact old filter.
	 * 9/24/2026
	 */
	if ($trending == 'd')
	{
		$query = "SELECT
				    o.PID,
				    (COUNT(o.PID) / (UNIX_TIMESTAMP(NOW()) - (
				    	SELECT time_added FROM orders
				        	WHERE PID=o.PID
				                ORDER BY OID DESC
				                LIMIT 1
				    )) * 1000) AS rating
				FROM orders AS o,
					posts as p
				WHERE
				    o.time_added > CAST(UNIX_TIMESTAMP(NOW())-86400 AS CHAR)
				    AND o.time_added > UNIX_TIMESTAMP(NOW())-86400
				    AND o.PID NOT IN ({$config['ownedgigs']})
				    AND p.PID=o.PID
				GROUP BY o.PID
				ORDER BY rating DESC
				LIMIT 60";
		$results	= $conn->CacheExecute(60, $query);
		$r 			= $results->getrows();

		foreach ($r as $trend)
		{
			$trendingString .= $trend['PID'] . ',';
		}

		if (substr($trendingString, -1) == ',')
		{
			$trendingString = substr($trendingString, 0, -1);
		}

		$dby 			= " FIELD(A.PID, ".addslashes($trendingString).") ";
		$addsql			.= " AND A.PID IN (".addslashes($trendingString).") ";
		$removeFeatured = true;
		$sortactive	 	= 'trending';
		$pagetitle 		= $lang['2398'];
		$latentAdds 	.= '&tnd=' . strip_tags(cleanit($trending));
	}
	else if ($trending == 'w')
	{
		$query = "SELECT
				    o.PID,
				    (COUNT(o.PID) / (UNIX_TIMESTAMP(NOW()) - (
				    	SELECT time_added FROM orders
				        	WHERE PID=o.PID
				                ORDER BY OID DESC
				                LIMIT 1
				    ))+SUM(o.price) * 1000) AS rating
				FROM orders AS o,
					posts as p
				WHERE
				    o.time_added > CAST(UNIX_TIMESTAMP(NOW())-604800 AS CHAR)
				    AND o.time_added > UNIX_TIMESTAMP(NOW())-604800
				    AND o.PID NOT IN ({$config['ownedgigs']})
				    AND p.PID=o.PID
				GROUP BY o.PID
				HAVING count(o.PID) > 4
				ORDER BY rating DESC
				LIMIT 60";
		$results	= $conn->CacheExecute(60, $query);
		$r 			= $results->getrows();

		foreach ($r as $trend)
		{
			$trendingString .= $trend['PID'] . ',';
		}

		if (substr($trendingString, -1) == ',')
		{
			$trendingString = substr($trendingString, 0, -1);
		}

		$addsql			.= " AND A.PID IN (".addslashes($trendingString).") ";
		$dby 			= " FIELD(A.PID, ".addslashes($trendingString).") ";
		$removeFeatured = true;
		$sortactive	 	= 'trending';
		$pagetitle 		= $lang['2399'];
		$latentAdds 	.= '&tnd=' . strip_tags(cleanit($trending));
	}
	else if ($trending == 'm')
	{
		$query = "SELECT
				    o.PID,
				    (COUNT(o.PID) / (UNIX_TIMESTAMP(NOW()) - (
				    	SELECT time_added FROM orders
				        	WHERE PID=o.PID
				                ORDER BY OID DESC
				                LIMIT 1
				    ))+SUM(o.price) * 1000) AS rating
				FROM orders AS o,
					posts as p
				WHERE
				    o.time_added > CAST(UNIX_TIMESTAMP(NOW())-2678400 AS CHAR)
				    AND o.time_added > UNIX_TIMESTAMP(NOW())-2678400
				    AND o.PID NOT IN ({$config['ownedgigs']})
				    AND p.PID=o.PID
				GROUP BY o.PID
				HAVING count(o.PID) > 4
				ORDER BY rating DESC
				LIMIT 60";
		$results	= $conn->CacheExecute(60, $query);
		$r 			= $results->getrows();

		foreach ($r as $trend)
		{
			$trendingString .= $trend['PID'] . ',';
		}

		if (substr($trendingString, -1) == ',')
		{
			$trendingString = substr($trendingString, 0, -1);
		}

		$dby 			= " FIELD(A.PID, ".addslashes($trendingString).") ";
		$addsql			.= " AND A.PID IN (".addslashes($trendingString).") ";
		$removeFeatured = true;
		$sortactive	 	= 'trending';
		$pagetitle 		= $lang[2400];
		$latentAdds 	.= '&tnd=' . strip_tags(cleanit($trending));
	}
	else
	{
		$trending 	= "";
	}
}

/*
 * Subscription based services
 * only
 * 6/30/2016
 */
if (!empty($subonly))
{
	if ($subonly == 'W')
	{
		$addsql 	.= " AND is_sub=1 AND sub_time='W'";
		$pagetitle   = "Weekly Subscription Services Only ";
		$sortactive	 = 'subscription';
	}
	else if ($subonly == 'Y')
	{
		$addsql 	.= " AND is_sub=1 AND sub_time='Y'";
		$pagetitle   = "Yearly Subscription Services Only ";
		$sortactive	 = 'subscription';
	}
	else if ($subonly == 'D')
	{
		$addsql 	.= " AND is_sub=1 AND sub_time='D'";
		$pagetitle   = "Daily Subscription Services Only ";
		$sortactive	 = 'subscription';
	}
	else if ($subonly == 'M')
	{
		$addsql 	.= " AND is_sub=1 AND sub_time='M'";
		$pagetitle   = "Monthly Subscription Services Only ";
		$sortactive	 = 'subscription';
	}
	else if ($subonly == 'B')
	{
		$addsql 	.= " AND is_sub=1 AND sub_time='B'";
		$pagetitle   = "Biweekly Subscription Services Only ";
		$sortactive	 = 'subscription';
	}
	else
	{
		/*
		 * Invalid sub type.
		 * 8/17/2016
		 */
		$subonly 	= '';
	}
}

/*
 * High Quality and Proven only
 * 2/25/2013
 */
if ($proven == 1)
{
	$addsql 	.= " AND staff_proven=1 ";
	$pagetitle 	 = $lang['1284'];
}

/*
 * If it is a blog, we need to add special
 * sql.. :|
 * 7/29/2012
 */
if ($type == 5) {
	$addsql .= " AND bd.PID=A.PID ";
}

/*
 * Don't display any WTB posts
 * 1/9/2012
 */
$addsql .= " AND type !=99 ";


/*
 * Some users do not want to be displayed
 * on MBL or MJ, exclude them here.
 * 4/11/2014
 */
if ($config['baseurl'] == 'http://www.monsterbacklinks.com' || $config['baseurl'] == 'https://www.seolads.com' || $config['baseurl'] == 'https://www.seocheckout.com')
{
	$addsql .= " AND A.USERID NOT IN (337, 153019) AND A.gtitle NOT LIKE '%alexa%' AND A.gdesc NOT LIKE '%alexa%' ";
}

/*
 * Only show services that the user has logged in in the
 * last 45 days.
 * 9/19/2014
 */
/*if ($config['sitetitle'] != 'ListingDock' && $config['sitetitle'] != 'CodeClerks')
{
	//$addsql .= " AND C.lastlogin>UNIX_TIMESTAMP(NOW())-3888000 ";
}*/

/*
 * Set the title for searches up here so
 * it includes the page number in the
 * title.
 * 11/11/2012
 */
if (!empty($squery))
{

	/*
	 * Turn off the landing page
	 * 5/1/2017
	 */
	$landing 	= 0;
	$pagetitle 	= $lang['124'] . ' ' . $lang['537'] . ' ' . $squery;
}

/*
 * If this is a category listing, lets
 * do some special things as well.
 * 8/8/2012
 */

/*
 * Make $page 1 unique title
 * 7/14/2013
 */
if ($page == 1)
{
	$pagetitle = $lang['788'] . ' ' . $page . ' of ' . $pagetitle;
}

if($page=="")
{
	$page = "1";
}
$currentpage = $page;

if ($page >=2)
{
	/*
	 * Turn off the landing page
	 * 5/1/2017
	 */
	$landing = 0;

	$pagetitle = $lang['788'] . ' ' . $page . ' of ' . $pagetitle;
	$pagingstart = ($page-1)*$config['items_per_page'];
}
else
{
	$pagingstart = "0";
}

/*
 * Get the sorting option
 */
if (empty($trending))
{
	$sortData 		= GetSortBy($s);
	$dby 			= $sortData['dby'];
	$removeFeatured = $sortData['removeFeatured'];

	/*
	 * IF the sort by data has
	 * C. in it, we need the
	 * members joined
	 * 7/2/2016
	 */
	if (stristr($dby, 'C.'))
	{
		$memberJoin = 1;
	}

	/*
	 * Remove non-completed
	 * services
	 * 7/13/2016
	 */
	if (stristr($dby, 'average_completion_time'))
	{
		$addsql .= ' AND A.average_completion_time>0 ';
	}

	/*
	 * They are sorting by new so
	 * we only show the ones in the last
	 * 24 hours.
	 * 11/15/2016
	 */
	if ($s == 'n' || $s == 'nz')
	{
		$addsql .= ' AND A.time_added>UNIX_TIMESTAMP(NOW())-86400 ';
	}

	/*
	 * If sort by isn't set, se something
	 * else
	 * 7/1/2016
	 */
	if (empty($sortactive) || $sortactive == 'default')
	{
		if (!empty($sortData['sortactive']))
		{
			$sortactive = $sortData['sortactive'];
		}
	}
}

/*
 * Remove featured if page > 1
 * 10/26/2013
 */
if ($page > 1)
{
	$pg1RemoveFeatured 	= $removeFeatured;
	$removeFeatured 	= true;
}

if (!empty($sortData['title']))
{
	/*
	 * Turn off the landing page
	 * 5/1/2017
	 */
	$landing = 0;

	$addTitle		= '(' . $lang['1485'] . ': ' . $sortData['title'];
}

/*
 * The user is searching for services based on USERID
 * 8/21/2018
 */
if (intval($_REQUEST['searchuid']) > 0)
{
	$searchUid = addslashes(intval($_REQUEST['searchuid']));
	$addsql .= ' AND A.USERID=$searchUid ';
}

/*
 * Add a title if the tag field is
 * not blank.
 *7/14/2013
 */
if (!empty($tag))
{
	/*
	 * Turn off the landing page
	 * 5/1/2017
	 */
	$landing = 0;

	if (!empty($addTitle))
	{
		$addTitle .= ', ' . $lang['1510'] . ': ' . $tag;
	}
	else
	{
		$addTitle = '(' . $lang['1510'] . ': ' . $tag;
	}

	$metaheader	= $lang['1510'] . ': <strong>' . $tag . '</strong>';
	//STemplate::assign('metaheader',  $metaheader);
}

if (!empty($sortData['title']) || !empty($tag))
{
	$addTitle .= ')';
}

$query1 = "SELECT count(A.PID) as total FROM posts A  ";
$query2 = "SELECT A.*, C.username, C.profilepicture, C.userlevel, C.ratingcount, C.rating, C.vetted, C.vetted_human, C.lastlogin, C.ip, C.lip, C.profile_data FROM posts A";

/**
 * If we are forcing an index on the posts table,
 * add it here.
 *
 * 2025-07-21 06:11:31 JD
 */
/**
 * The count query is forced; the listing query is forced only when the index
 * is one that can actually serve it.
 *
 * homepage_search is (USERID, feat, active, type, sold_out, catfeatured_upgrade).
 * Its leftmost column is USERID, which a search or a tag filter never
 * constrains, so the index cannot be used at all - and forcing it ALSO takes
 * lastgigedit away from the ORDER BY, turning the listing into a full scan plus
 * a filesort over 1.15 million rows. Measured on production, 2026-10-07:
 *
 *   search listing   forced 1257ms   free 37ms
 *   tag listing      forced 1361ms   free 29ms
 *
 * Left alone the optimiser walks lastgigedit in sort order and stops at forty.
 *
 * category is the opposite and must keep its hint: category IS constrained, so
 * the index is usable, and without it the optimiser picks badly -
 *
 *   category listing forced 64ms     free 730ms
 *
 * The counts have no ORDER BY to exploit and have to examine the same rows
 * either way, so they keep the hint in both cases; it was marginally the faster
 * of the two on every shape measured.
 *
 * 2026-10-07 JD
 */
if (!empty($forcedIndex))
{
	$query1 .= " FORCE INDEX (" . escape($forcedIndex) . ") ";

	if ($forcedIndex != 'homepage_search')
	{
		$query2 .= " FORCE INDEX (" . escape($forcedIndex) . ") ";
	}
}

/**
 * Finish the query
 *
 * 2025-07-21 06:11:17 JD
 */
$query2 .= ", seoclerks.members C ";

/*
 * If it is blogs, we need to
 * include the blog-data :)
 * 7/29/2012
 */
if ($type == 5) {
	$query1 .= ", blogdata bd ";
	$query2 .= ", blogdata bd ";
}

/*
 * must have two of these for modifying
 * 10/28/2012
 */
if ($memberJoin == 1) {
		$query1 .= ", seoclerks.members C";
}

/**
 * These queries are here no matter the filter
 */
// $query1 .= " WHERE active=1 AND sold_out=0 ";
$query1 .= " WHERE A.active=1 AND A.sold_out=0 ";
$query2 .= " WHERE A.active=1 AND A.USERID=C.USERID AND A.sold_out=0 ";

if ($memberJoin == 1)
{
	$query1 .= " AND A.USERID=C.USERID ";
}

/**
 * The count query and listing query mostly share the same filters, but
 * searches can use a cheaper member lookup for count.
 */
$addsqlCount = $addsql;

/*
 * If the user is searching for some data
 * 10/28/2012
 */
if (!empty($squery))
{
	/*
	 * Turn off the landing page
	 * 5/1/2017
	 */
	$landing = 0;

	/**
	 * three or more words because there's no categories with less than 3 words.
	 *
	 * I commented this out below because it doesn't seem to be relevant anymore :)
	 *
	 * 5/18/2021 SE
	 */
	// if (strlen($squery) > 2)
	// {
	// 	/**
	// 	 * See if this is related to any categories.
	// 	 */
	// 	$query = "SELECT EXISTS(SELECT *
	// 									FROM categories
	// 									WHERE name = ?
	// 								) AS total";

	// 	$likeVar = "%" . $squery . "%";

	// 	$preStat = array($likeVar);

	// 	$results 	= $conn->execute($query, $preStat);
	// 	$return 	= $results->fields['total'];

	// 	/**
	// 	 * If we find any lets change the way we sort category featured services
	// 	 */
	// 	if (!empty($return))
	// 	{
	// 		/**
	// 		 * All searches use category featured services first
	// 		 */
	// 		$dby = 'A.catfeatured_upgrade desc, ' . $dby;
	// 	}
	// }

	/*
	 * Forward the user to a proper URL that
	 * google will love.
	 * 1/9/2013
	 */
	if (stristr($_SERVER['REQUEST_URI'], '/search?query='))
	{
		$newsquery = urlencode($squery);
		header("location: $config[baseurl]/search/{$newsquery}");
		die();
	}

	/*
	 * Insert the search query into the database
	 * so we can later build a typeahead based
	 * on it.
	 * 6/17/2013
	 */
	InsertSearchTerm($squery);

	/*
	 * Expode the string by spaces and then
	 * create the proper like statement
	 * 4/28/2012
	 */
	$queryArray   = explode(' ', $squery);
	$likeString = array();
	foreach ($queryArray as $search)
	{
		$search = trim($search);

		/**
		 * If this string is short we need to search it as a word itself instead of a char found in text
		 */
		if (strlen($search) < 3)
		{
			$search = " " . $search . " ";
		}

		if (!empty($search) && $search != ' ')
		{
			$likeString[] = "'%".addslashes($search)."%'";
			$likeStringMem[] = "'".addslashes($search)."%'";
		}
	}

	/*
	 * Added so sorting options work
	 * 1/9/2013
	 */

	/*
	 * Implode the string
	 */
	$gtitleSearch   = implode(' and gtitle like', $likeString);
	//$gdescSearch    = implode(' and gdesc like', $likeString);
	$usernameSearch = implode(' and C.USERNAME like', $likeStringMem);
	$usernameSearchCount = implode(' and C2.USERNAME like', $likeStringMem);
	//$tagsSearch     = implode(' and gtags like', $likeString);

	$searchFilter = "((A.gtitle like $gtitleSearch)
			OR (C.username like $usernameSearch))";

	/**
	 * When no other member filters are active, avoid joining members in the
	 * counting query and check usernames via EXISTS instead.
	 */
	if ($memberJoin == 1)
	{
		$addsqlCount .= " AND {$searchFilter}";
	}
	else
	{
		$addsqlCount .= " AND
			((A.gtitle like $gtitleSearch)
			OR EXISTS(
				SELECT 1
				FROM seoclerks.members C2
				WHERE C2.USERID=A.USERID
					AND C2.username like $usernameSearchCount
			)) ";
	}

	$addsql	.= " AND {$searchFilter}";

			// OR (A.gdesc like $gdescSearch)
			// OR (A.gtags like $tagsSearch)

	/**
	 * Keep search requests on the search index.
	 */
	if (empty($forcedIndex))
	{
		$forcedIndex = "homepage_search";

		// FORCE INDEX must appear immediately after the posts table reference.
		$query1 = str_replace("FROM posts A  ", "FROM posts A FORCE INDEX (" . escape($forcedIndex) . ") ", $query1);

		/**
		 * $query2 is deliberately NOT forced here - see the note above where
		 * the same decision is made for the other paths. homepage_search
		 * begins at USERID, which a search never constrains, so forcing it on
		 * the listing cost a full scan and a filesort instead of forty rows
		 * read straight off lastgigedit: 1257ms against 37ms on production.
		 */
	}

	$pagevalue = "/search/{$squery}/page/";



	/*
	 * We have to remove some variables to
	 * prevent xss attacks
	 * 8/21/2014
	 */

	/*
	 * Uni theme variables for breadcrumbs
	 * 06/19/2018
	 */
	$showbreadcrumbs 	= 1;
	$breadHome			= 'marketplace';
	$breadHomeName		= $lang['493'];
}

/*
 * Does the user want only guaranteed
 * gigs?
 * 8/9/2012
 */
if ($s == "g")
{
	$query1 .= " AND A.guarantee=1 ";
	$query2 .= " AND A.guarantee=1 ";

	/*
	 * Add a custom title
	 * 7/14/2013
	 */
	$addTitle = $lang['1509'];
}

// $query1 .= " AND A.PID=650416 ";
// $query2 .= " AND A.PID=650416 ";

/*
 * Does the user want only guaranteed
 * gigs?
 * 8/9/2012
 */
if ($s == "su")
{
	$query1 .= " AND is_sub=1 ";
	$query2 .= " AND is_sub=1 ";

	/*
	 * Add a custom title
	 * 7/14/2013
	 */
	$addTitle = $lang[480];
}

/*
 * If this is the software section
 * and the user wants to sort by
 * platform.
 * 2/20/2013
 */
if ($type == 7) {
 	if ($s == "plw") {  // Software - Windows
 		$query1 .= " AND A.sortable_data1 LIKE '%Windows%' ";
 		$query2 .= " AND A.sortable_data1 LIKE '%Windows%' ";
 		$sortactive = 'software';
	} else if ($s == "plm") {  // Software - Mac
		$query1 .= " AND A.sortable_data1 LIKE '%Mac%' ";
 		$query2 .= " AND A.sortable_data1 LIKE '%Mac%' ";
 		$sortactive = 'software';
	} else if ($s == "pll") {  // Software - Linux
		$query1 .= " AND A.sortable_data1 LIKE '%Linux%' ";
 		$query2 .= " AND A.sortable_data1 LIKE '%Linux%' ";
 		$sortactive = 'software';
	} else if ($s == "pla") {  // Software - android
		$query1 .= " AND A.sortable_data1 LIKE '%Android%' ";
 		$query2 .= " AND A.sortable_data1 LIKE '%Android%' ";
 		$sortactive = 'software';
	} else if ($s == "pli") {  // Software - iOS
		$query1 .= " AND A.sortable_data1 LIKE '%iOS%' ";
 		$query2 .= " AND A.sortable_data1 LIKE '%iOS%' ";
 		$sortactive = 'software';
	} else if ($s == "plc") {  // Software - code/scripts/other
		$query1 .= " AND (A.sortable_data1 LIKE '%Webware%' OR A.sortable_data1 LIKE '%Code%' OR A.sortable_data1 LIKE '%Other%')";
 		$query2 .= " AND (A.sortable_data1 LIKE '%Webware%' OR A.sortable_data1 LIKE '%Code%' OR A.sortable_data1 LIKE '%Other%')";
 		$sortactive = 'software';
	}
}

/*
 * If they are sorting blog reviews by
 * Alexa, don't include those that don't
 * have alexa data.
 * 10/21/2013
 */
if ($type == 5) {
	if ($s == "ax" || $s == 'axz')
	{
		$query1 .= " AND bd.alexa!='No Data available.' ";
		$query2 .= " AND bd.alexa!='No Data available.' ";
	}
}

/*
 * Add our extras
 * 7/29/2012
 */
$query1 .= $addsqlCount;
$query2 .= $addsql;

/*
 * Make a replacement variable for the maximum results
 * because we don't want to change the config value
 * which is used for other calculations.
 * 11/3/2013
 */
 $items_per_page = $config['items_per_page'];

 /*
  * If this is the mobile site, lets only
  * display 10 items so that it loads fast
  * 3/17/2014
  */
if ($_SESSION['userbrowser'] == 'mobile') $items_per_page = 30;

/*
 * We do a seperate query for featured
 * only because the order by on double
 * values sucks
 * 10/26/2013
 */
if ($removeFeatured === false)
{
	$query3 = $query2;
	$query3 .= ' AND A.feat=1 ';

	/*
	 * Take 10 off of this value for a total
	 * of 50 items.
	 * 11/3/2013
	 */
	 // $items_per_page = $items_per_page - 10;

	/*
	 * Unless we are in a category
	 * don't include the category featured
	 * only.
	 * 10/28/2013
	 */
	if (empty($cid))
	{
			$query3 .= ' AND A.catfeatured_upgrade=0 ';
			$query2 .= ' AND (A.feat=0 OR A.catfeatured_upgrade>0) ';
	}
	else
	{
			$query2 .= ' AND A.feat=0 AND A.catfeatured_upgrade=0 ';
	}
}
else
{
	if ($pg1RemoveFeatured === FALSE && $page == 2)
	{
		/*
		 * We have to adjust to show the 10 on page 2 that never
		 * would show here otherwise. only for page 2
		 * 11/3/2013
		 */
		 $pagingstart 		= $pagingstart - 10;
		 //$items_per_page 	= $items_per_page + 10;
	 }

	/*
	 * I'm not sure what the point was of
	 * this but it wasn't correct. When you remove
	 * featured, you just don't want them showing at
	 * the top but they can still be shown in the listing
	 * 11/2/2013
	 */
	//$query1 .= ' AND A.feat=0 ';
	//$query2 .= ' AND A.feat=0 ';
}

/*
 * Remove certain categories from the homepage
 * 7/19/2018
 */
if ($isHomepage == 1 || ($_SERVER['REQUEST_URI'] == '/marketplace'))
{
	//$query1 .= " AND A.category NOT IN (39, 55, 23, 54, 34, 53) ";
	//$query2 .= " AND A.category NOT IN (39, 55, 23, 54, 34, 53) ";
}

/*
 * Put back our order by clause
 * 7/29/2012
 *
 * Removed the order by and limit below on Query 1. It
 * is a counting query so why do we need to order it or
 * limit it?
 *
 * 2021-07-05 06:02:26 - JD
 */
// $query1 .= " order by A.PID desc limit $config[maximum_results]"; // Why do we need order by and limit here??
$query2 .= " order by ";


/**
 * Although this could cause inaccurate numbers, if these queries
 * are executed they will hang the DB. The number below was missing
 * one zero somehow (1000000 instead of 10000000) which caused this
 * query to execute and DB issues ensued.
 *
 * 2021-05-11 05:02:39 - JD
 */
// $queryTest = preg_replace('!\s+!', ' ', $query1);
// if (
// 	(
// 		stristr($queryTest, 'SELECT count(A.PID) as total from posts A where active=1 AND sold_out=0 AND type !=99 order by A.PID') ||
// 		$query1 == 'SELECT count(A.PID) as total from posts A   where active=1 AND sold_out=0  AND type !=99  order by A.PID desc limit 10000000' ||
// 		$query1 == 'SELECT count(A.PID) as total from posts A where active=1 AND sold_out=0 AND type=0 AND type !=99' ||
// 		$query1 == 'SELECT count(A.PID) as total from posts A where active=1 AND sold_out=0 AND type=0 AND type !=99 AND A.category NOT IN (39, 55, 23, 54, 34, 53)'
// 	) && isSeoclerksStorefront())
// {
// 	/**
// 	 * Temporary disabled for the great happening.
// 	 * 2021-06-21 15:37:11 - JD
// 	 */
// 	$noExecuteCount = 1;

// }
// else
// {
// 	$noExecuteCount = 0;
// }

/*
 * Added to remove the featured listings from certain sorts
 * 12/3/2011
 */
if ($removeFeatured == false) {
	//$query2 .= "A.feat desc, ";
}

$query2 .= "$dby limit $pagingstart, $items_per_page";

/**
 * Testing on 5-11-2021
 * 2021-05-11 11:25:30 - JD
 */
// if ($_SERVER['REMOTE_ADDR'] == '64.147.209.74') {
// 	echo $query1 . '<br />'. $query2;
//
// }

// if ($noExecuteCount == 1)
// {
// 	$total = $config['maximum_results'];
// }
// else
// {

	/**
	 * Run our cache query
	 *
	 * 2021-07-01 05:14:15 - JD
	 */
	$executequery1 			= queryCache($query1, 3600, true);

	// $executequery1 = $conn->CacheExecute(210, $query1);
// }
// if ($noExecuteCount == 0)
// {
	$total = $executequery1['total'];
// }
// else
// {
// 	$scriptolution = $config['maximum_results'];
// }

if ($total > 0)
{
	// if ($noExecuteCount == 0)
	// {
	// 	if($executequery1->fields['total']<=$config['maximum_results'])
	// 	{
	// 		$total = $executequery1->fields['total'];
	// 	}
	// 	else
	// 	{
	// 		$total = $config['maximum_results'];
	// 	}
	// }
	$toppage = ceil($total/$items_per_page);

	if($toppage==0)
	{
		$xpage=$toppage+1;
	}
	else
	{
		$xpage = $toppage;
	}

	$executequery2 = $conn->CacheExecute(220, $query2);
	$posts = $executequery2->getrows();

	/*
	 * We do a seperate query for featured
	 * only because the order by on double
	 * values sucks
	 * 10/26/2013
	 */
	if ($removeFeatured == false)
	{
		$executequery3 		= $conn->CacheExecute(220, $query3);
		$postsFeat 		    = $executequery3->getrows();
		$postsFeat			= SortArrayByVaule($postsFeat, 'lastgigedit', $sortHow='desc');
		$posts				= array_merge($postsFeat, $posts);
	}

	/*
	 * Global Function instead of the old
	 * one that was the same for each....
	 */
	$posts = ChangePostData($posts);

	$beginning	= $pagingstart+1;
	$ending		= $pagingstart+$executequery2->recordcount();

	if($s != "")
	{
		$adds = "?s=$s";
	}

	/*
	 * From the sorting above
	 * 7/3/2016
	 */
	if (!empty($latentAdds))
	{
		$adds .= $latentAdds;
	}
	else
	{
	}

	/*
	 * Add onsale to page nav.
	 * 1/12/2013
	 */
	if ($onsale == 1) {
		$adds 			= "&o=1";
	}

	/*
	 * Add trending to page nav.
	 * 1/12/2013
	 */
	if (!empty($trending))
	{
		if ($trending == 'd')
		{
			$rewriteEnding = 'today';
		}
		else if ($trending == 'w')
		{
			$rewriteEnding = 'week';
		}
		else if ($trending == 'm')
		{
			$rewriteEnding = 'month';
		}
		// Old way of adding trending broke the page
		// $adds = "/trending/{$rewriteEnding}";

		$adds = "?tnd={$trending}";
	}

	/*
	 * Add subscription to page nav.
	 * 1/12/2013
	 */
	if (!empty($subonly))
	{
		$adds = "?sub={$subonly}";
	}

	/*
	 * Add HQ ending.
	 * 2/25/2013
	 */
	if ($proven == 1)
	{
		$adds = "?hq=1";
	}

	/*
	 * If there is a type, add that to the end
	 * of the page values
	 * 6/11/2013
	 */
	if ($type > 0)
	{
		$adds .= "&t={$type}";
	}

	if (intval($displayType) == 1)
	{
		$adds .= "&displaytype=" . $displayType;
	}
	else if (intval($displayType) == 3)
	{
		$adds .= "&displaytype=" . $displayType;
	}

	$linkUrl 			= $config['baseurl'] . $pagevalue;

	$linkWithCategory 	= str_replace("/page/", "", $linkUrl);

	// Create the pagination
	$paginationArray = createPagination($beginning, $ending, $currentpage, $toppage, $linkUrl, $adds, 7, "ajaxTableSort grid-update", "data-droplet='marketlistings'", true, true, true, true);

	// Set the array results to local values
	$pageShowingUni = $paginationArray['pageShowingUni'];
	$pagetoplinks	= $paginationArray['pagetoplinks'];
	$pagelinks		= $paginationArray['pagelinks'];
	$pageNext		= $paginationArray['pageNext'];
	$pagelinksUni	= $paginationArray['pagelinksUni'];
}

/*
 * If the user has not see the promotion
 * and it is enabled..
 * 7/20/2012
 */
if (($_SESSION['seentweetpromo'] == 0 || empty($_SESSION['seentweetpromo'])) && $config['freeMoneyStatus'] == 1 && 1 == 2) {

	/*
	 * Set so user does not see again.
	 */
	if ($_SESSION['ADMINUSERLOGIN'] == 0 && $_SESSION['USERID'] > 0) {
		TweetPromoSeen();
	} else if ($_SESSION['USERID'] <= 0) {
		$_SESSION['seentweetpromo'] = 1;
	}

	/*
	 * Get stats
	 */
	$promoData = GetPromoData();

	/*
	 * Assign Variables
	 */
	if ($_SESSION['USERID'] <= 0) {
	} else {
	}
} else {
}

/*
 * This is for the contest promotion only
 * 10/12/2012
 */
if (($_SESSION['seencontestpromo2'] == 0 || empty($_SESSION['seencontestpromo2'])) && 1 == 2 && $_SESSION['USERID'] > 0) {

	/*
	 * Set so user does not see again.
	 */
	if ($_SESSION['ADMINUSERLOGIN'] == 0 && $_SESSION['USERID'] > 0) {
		ContestPromoSeen();
	} else if ($_SESSION['USERID'] <= 0) {
		$_SESSION['seencontestpromo2'] = 1;
	}

	/*
	 * Assign Variables
	 */
} else {
}

/*
 * Add any extra title tags. This will
 * add things such as the sorting critera
 * to make the page unique.
 * 7/6/2013
 */
$pagetitle = trim($pagetitle . ' ' . $addTitle); // no trailing space before " - Seoclerks" when there is nothing to add

/*
 * Get our recently viewed
 * services.
 * 5/11/2016
 */
if (!empty($_SESSION['recentlyviewed']))
{
	$recentlyViewed = json_decode($_SESSION['recentlyviewed'], true);

	/*
	 * For the uni-theme, we only need the count and no actual
	 * DB query as this will come from the AJAX call.
	 * 5/10/2018
	 */
	if ($config['themeUni'] == 1)
	{
		foreach ($recentlyViewed as $recentView)
		{
			if (intval($recentView) > 0 )
			{
				$showrecent++;
			}
		}
	}
	else
	{
		foreach ($recentlyViewed as $recentView)
		{
			$recentView = intval($recentView);
			//$recentInString = implode(',', $recentlyViewed);
			if (!empty($recentView))
			{
				$recentInString .= $recentView . ',';
			}
		}
		if (substr($recentInString, -1) == ',')
		{
			$recentInString = substr($recentInString, 0, -1);
		}

			if (!empty($recentInString))
			{
				/*
				* Lets do a search based on title
				* and category and type
				*/
				$query="SELECT A.PID, A.gtitle, A.p1, A.type, A.category, A.USERID, A.price
						FROM posts A
						WHERE A.PID IN (".addslashes($recentInString).")
						AND A.active='1'
						AND A.p1 != '3030-1.jpg'
						ORDER BY FIELD(A.PID, ".addslashes($recentInString).");
						";
				$results	= $conn->CacheExecute(60, $query);
				$r 			= $results->getrows();

				foreach ($r as $key => &$recent)
				{
					/*
					* Make sure the picture exists before showing the
					* actual recent
					* 6/2/2016
					*/
					if (file_exists($config['basedir'] . "/pics/t2/" . $recent['p1']))
					{
						/*
						* We have to get the correct category
						* based on the type
						* 7/18/2012
						*/
						$catData 		= GetCategorySeoFromType($recent['type'], $recent['category']);
						$recent['seo'] 	= $catData['seo'];
						$recent['name'] = $catData['name'];

						/*
						* Correct any puncuation issues
						* 6/16/2016
						*/
						$recent['gtitle'] = FormatNonUTF8Chars($recent['gtitle']);
						$recent['gtitle'] = removeNonAlphaNumeric($recent['gtitle'], '', true);
						$recent['gtitle'] = formatPuncuation($recent['gtitle']);

						/*
						* Short title for the thumbnail view
						* 12/22/2013
						*/
						$recent['thumbtitle'] 	= GenerateThumbTitleListings(stripslashes($recent['gtitle']), 36);
					}
					else
					{
						unset($r[$key]);
					}
				}
			}

		if (count($r) > 0)
		{
		}
		else
		{
		}

	} // End if NOT unitheme
}
else
{
	$showrecent = 0;
}

/*
 * This isn't required for the uni-theme since it is
 * in a droplet and loads via AJAX.
 * 11/7/2018
*/
if ($config['themeUni'] != 1)
{
	/*
	* Fetch a randomly features service to advertise
	* on the right hand side of the FAQ section
	* 6/27/2016
	*/
	$query = "SELECT p.*, m.USERID, m.profilepicture, m.username, m.userlevel,
					m.lastlogin, m.ip, m.lip
				FROM posts as p,
					seoclerks.members as m
				WHERE m.USERID=p.USERID
					AND ";

	/*
	* The user is in a category so let's
	* include those category featured
	* services
	* 7/6/2016
	*/
	if ($categoryDetails['CATID'] > 0)
	{
		$query .= "  (p.alwaysfeatured_upgrade>0 OR (catfeatured_upgrade>0
												AND p.category='".addslashes($categoryDetails['CATID'])."'
												)
						)";
	}
	else
	{
		$query .= " p.alwaysfeatured_upgrade>0  ";
	}

	$query .= "	AND p.feat=1
					AND p.active=1
					AND p.type!=99
				ORDER BY RAND()
				LIMIT 3
			";

	$randomAdQuery			= $conn->CacheExecute(60, $query);
	$randomAd	 			= $randomAdQuery->getrows();
	$randomAd				= ChangePostData($randomAd);
}

/*
 * Changes the display into thumbnails
 * 7/14/2013
 *
 * 12/2/2018 - Replaced all of the $_REQUEST with $_GET below. $_REQUEST['displaytype'] was ALWAYS
 * equal to 1, even if you echoed it out as the first line of PHP and called the scritp directly. It
 * is not in .htaccess or elsewhere that I can find. It could a bug with PHP.
 *
 * The old theme uses post so we setup this new variable before, begrudgingly
 *
 */

/*
 * The display type actually asked for this request.
 *
 * The block below rewrites a list request (3) into 0, and setcookie()
 * does not populate $_COOKIE within the same request - so by the time
 * the mobile default at the bottom runs, neither $displayType nor the
 * cookie can say that a list was asked for, and the first tap on the
 * list toggle came back as a grid. This keeps the original answer.
 *
 * 2026-09-10 JD
 */
$displayTypeRequested = intval($displayType);

if (intval($displayType) > 0  || !is_null($_SESSION['displaytype']) || !is_null($_COOKIE['displaytype']) && CSFRRequestCheck())
{
	if (intval($displayType) > 0)
	{
		/*
		 * Normal view is 3
		 */
		if ($displayType == 3)
		{
			$displayType = 0;
		}

		if (empty($_SESSION['ADMINUSERLOGIN']) || $_SESSION['ADMINUSERLOGIN'] != 1)
		{
			UpdateMembersDisplayType($displayType);
		}

		$_SESSION['displaytype'] = intval($displayType);
		setcookie('displaytype', $_SESSION['displaytype'], time()+2592000); // 30 days in seconds
	}
	else if (intval($_COOKIE['displaytype']) >= 0 && !empty($_COOKIE['displaytype']))
	{
		if (empty($_SESSION['ADMINUSERLOGIN']) || $_SESSION['ADMINUSERLOGIN'] != 1)
		{
			$_SESSION['displaytype'] = intval($_COOKIE['displaytype']);
			setcookie('displaytype', $_SESSION['displaytype'], time()+2592000); // 30 days in seconds
		}
	}

	$thumbnail = $_SESSION['displaytype'];
}
else
{
	if (CSFRRequestCheck())
	{
		/*
		* Make the default display type different
		* different sites
		* 9/18/2013
		*/
		$thumbnail = GetDefaultDisplayType();
	}
}

/*
 * Phones open on the grid (thumbnail) view - a list row is far too wide
 * to read on a narrow screen. 1/9/2013
 *
 * This sets the default only; working the grid/list toggle still wins.
 * Two things have to be consulted for that to hold:
 *
 * $displayTypeRequested rather than $displayType, because the block
 * above rewrites a list request (3) into 0 - so by this point
 * $displayType can no longer tell a tap on "list" apart from no
 * request at all, and the first tap came back as a grid.
 *
 * The displaytype cookie for every request after that one. It is
 * written only when the toggle is used, so its presence is the one
 * honest "they picked this" signal available. The members column
 * cannot stand in for it: 0 means both "chose the list" and "never
 * touched it", and all but a rounding error of that table sits on 0.
 *
 * $thumbnail has to move with the assign. views/view_index.php is a
 * plain include reading the PHP variable rather than the template one,
 * so assigning on its own left every phone rendering the list.
 *
 * 2026-09-10 JD
 */
if ($_SESSION['userbrowser'] == 'mobile'
	&& $displayTypeRequested <= 0
	&& !isset($_COOKIE['displaytype']))
{
	$thumbnail = 1;
}


$templateselect = "index.tpl";

/*
 * Promo
 */
// if (empty($message))
// {
// 	$useralert = '<strong>Happy Fathers Day</strong>! Buy any 3 services or products and get 10% of the total added back to your account instantly.';
// 	STemplate::assign('useralert', $useralert);
// }
/*if (empty($message) && isSeoclerksStorefront())
{
	$useralert = '<strong>July Fourth Promo</strong>: <a href="' . $config['baseurl'] . '/order/2658">Add $50 to your balance and get an extra 5% free, $100 or more get an extra 10% free.</a>';
	STemplate::assign('useralert', $useralert);
}*/
/*if (empty($message) && isSeoclerksStorefront())
{
	$useralert = '<strong>July 4th Balance Promo</strong>: <a href="' . $config['baseurl'] . '/order/2658">Add $50 to your balance and get an extra 5% free, $100 or more for an extra 10% free.</a>';
	STemplate::assign('useralert', $useralert);
}*/
/*if (empty($message))
{
	$useralert = '<strong>Happy Labor Day</strong>! Buy any 3 services or products and get 10% of the total added back to your account instantly.';
	STemplate::assign('useralert', $useralert);
}*/
// if (empty($message))
// {
// 	$useralert = '<strong>Happy Thanksgiving!</strong>! Buy any 3 services or products and get 10% of the total added back to your account instantly.';
// 	STemplate::assign('useralert', $useralert);
// }

//TEMPLATES BEGIN
$config['showindextext'] = 1;

/**
* Fetch the last promotion and display it
* 3/29/2019
*
* Disabled by JD on 2021-08-16 11:59:50. This query is terrible
* and needs to be reworked/optimized.
*
* Optimized by removing the file searching part.
* We only display the generic image anyway so we don't need that.
* 2022-08-29 08:21:43 - SE
*/
$query = "SELECT p.*
			FROM promotions as p
			WHERE p.date_expire > UNIX_TIMESTAMP(NOW())
			AND p.date_added < UNIX_TIMESTAMP(NOW())
			ORDER BY p.date_added DESC
		";

$executequery	= $conn->Execute($query);
$promo		 	= $executequery === false ? array() : $executequery->getrows();

/*
 * Determine what to use for the theme.
 * 2/24/2018
 */
if ($config['themeUni']	== 1)
{
	// /**
	//  * This finds out if we should display a holiday alert
	//  */
	// include('ajax/holidayMap.php');

	// foreach($holidayMap as $map)
	// {
	// 	if(strtotime($map['day']) < strtotime('now') && strtotime($map['day']) > strtotime("-3 day"))
	// 	{
	// 		$holiday['message'] = $map['desc'];
	// 		$holiday['image'] 	= $map['image'];
	// 	}
	// }

	/**
	* Get the inbox folder for the user
	*/
//    $inboxFolders = getFoldersFromUser($__loggedUserDetails['USERID'], 'folders_favorites');

	//$thumbnail 					= 0;
	$firstLoad 						= 1;
	$ajax 							= intval($_REQUEST['ajax']);
	$ajaxAdds 						= str_ireplace('?', '&', $adds);
	$ajaxAdds 						.= str_ireplace('?', '&', $latentAdds);
	$ajaxDefaults					= '';
	$config['pagetitle']			= $pagetitle;

	/*
	 * Every category branch above hands the category's description and keywords to
	 * STemplate::assign(). That has been an empty stub since the Smarty templates
	 * went, so neither ever reached the <head>: every category page, on every
	 * storefront, carried the site-wide description and no keywords, whatever was
	 * written in the admin. The header reads $config, so they go there.
	 *
	 * Decoded then encoded, because the column holds a mix - some rows plain text,
	 * some with &amp; already in them - and the header prints the value raw inside a
	 * quoted attribute.
	 *
	 * $categoryDetails is only set by the branches that look a category up, so the
	 * marketplace home, search and the rest keep the default.
	 */
	if (!empty($categoryDetails['metadescription']))
	{
		$config['metadescription'] = htmlspecialchars(html_entity_decode($categoryDetails['metadescription'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
	}

	if (!empty($categoryDetails['metakeywords']))
	{
		$config['metakeywords'] = htmlspecialchars(html_entity_decode($categoryDetails['metakeywords'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
	}

	$config['include']['modals'][0] = 'views/modal/view_modal-marketplace-filters.php';
	$config['include']['modals'][1] = 'views/modal/view_modal-quick-look.php';
	$config['include']['modals'][2] = 'views/modal/view_modal-compare.php';

	if (isStaff())
	{
		$reportComponentDroplet['type'] = 'post';
		$reportComponentDroplet['url'] 	= 'fetch/report';
		$config['include']['modals'][3] = 'views/modal/view_modal-report-droplet.php';
	}
	$config['include']['hdr']['sub-nav'] = 1;

	/**
	 * Get the main category
	 */
	if ($type == 7)
	{
		$mainCategory = 'software';
	}
	else if (!empty($preCategory))
	{
		$mainCategory = $preCategory[0]['seo'];
	}
	else
	{
		$mainCategory = $categoryseo;
	}

	/*
	* Set so user does not see again.
	*/
	if (!empty($promo))
	{
		if (userHasSeenPromo())
		{
			$promoModalData['title'] 	= stripcslashes($promo[0]['title']);
			$promoModalData['desc'] 	= stripcslashes($promo[0]['content']);
			$promoModalData['img'] 		= $config['baseurl'] . '/assets/img/illustrations/money.png';

			$config['include']['modals'][4] = 'views/modal/view_modal-promo.php';
			$config['include']['footerJs'] .= '<script type="text/javascript">(function() {$("#modalPromo").modal("show");})();</script>';
		}
	}
	else
	{
		$customDataArray = json_decode($__loggedUserDetails['profile_data'], true);

		/**
		 * Sellers will get a popup if they don't have any payment methods
		 */
		if (	userHasSeenRate() &&
				empty(countPaymentMethod($__loggedUserDetails['USERID'])) &&
				updateUserTerm() > 0
			)
		{
			/**
			 * Generate the toaster alert data
			 * 6/21/2021
			 */
			$toastData['theme'] 			= isUserInDarkMode() == true ? 'dark' : 'light'; // dark, light
			$toastData['timeout'] 			= 8000;
			$toastData['color'] 			= 'white';
			$toastData['icon'] 				= 'fas fa-thumbs-up';
			$toastData['animateInside'] 	= 'right';
			$toastData['position'] 			= 'bottomRight'; // bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter
			$toastData['progressBarColor'] 	= 'rgb(0, 255, 184)';
			$toastData['title']				=  $lang[3877];
			$toastData['message']			=  $lang[4111];

			$gritterJs 			= genericToast($toastData);
		}

		/**
		 * Show a modal popup for order fees. Disregard if we are
		 * not on an Ionicware site.
		 *
		 * 2021-08-26 08:59:32 JD
		 */
		if (
				$customDataArray['invoicePage'] == 1
				&& intval($customDataArray['invoiceTimestamp']) < (time() - 86400)
				&& $config['isIonicware']
		) // 86400 1 day in seconds
		{
			$config['include']['modals'][5] = 'views/modal/view_modal-more.php';
			$config['include']['footerJs'] .= '<script type="text/javascript">(function() {$("#modalInfo").modal("show");})();</script>';

			$infoModalData['classText']		= 'text-center';
			$infoModalData['buttonLink']	= 'order/update/invoice';
			$infoModalData['buttonColor'] 	= 'btn-primary';
			$infoModalData['buttonText'] 	= $lang[4108];

			/**
			 * Get the amount of skips left that we have.
			 *
			 * 2021-07-26 13:23:22 JD
			 */
			$skipsLeft = 3 - $customDataArray['invoiceCount'];
			if ($skipsLeft > 0)
			{
				$infoModalData['buttonLink2']	= 'CLOSE';
				$infoModalData['buttonColor2'] 	= 'btn-secondary';
				$infoModalData['buttonText2'] 	= $lang[4113 ] . '(' . $skipsLeft . ' ' . $lang[4112] . ')';
			}

			$infoModalData['title'] 		= $lang[4109];
			$infoModalData['desc'] 			= $lang[4110];
			$infoModalData['img'] 			= $config['baseurl'] . "/assets/img/illustrations/image-verify.png";
			$infoModalData['cardOn'] 		= true;

			/**
			 * We can skip the invoice for 3 days but we need to force them after a while
			 * 2021-07-25 13:59:49 - SE
			 */
			if ($customDataArray['invoiceCount'] < 4)
			{
				/**
				 * Give a timestamp to when they got this message
				 * 2021-07-25 13:48:08 - SE
				 */
				$customDataArray['invoiceTimestamp'] 	= time();
				$customDataArray['invoiceCount'] 		= $customDataArray['invoiceCount'] + 1;
			}
			else
			{
				/**
				 * Reset all our invoice data
				 * 2021-07-25 13:53:17 - SE
				 */
				$customDataArray['invoiceTimestamp'] 	= 0;
				$customDataArray['invoiceCount'] 		= 0;
				$customDataArray['invoicePage']			= 0;

				/**
				 * Force an invoice on the user
				 */
				$customDataArray['invoiceForce']		= 1;
			}

			$customDataJson 						= json_encode($customDataArray);

			/**
			 * Update the time this user was checked
			 */
			UpdateUserData($__loggedUserDetails['USERID'], $customDataJson);
		}
		else if (userHasSeenRate() && rand(1, 4) == 1 && isSeoclerksStorefront())
		{
			/**
			 * Generate the toaster alert data
			 * 5/14/2020
			 */
			$toastData['theme'] 			= isUserInDarkMode() == true ? 'dark' : 'light'; // dark, light
			$toastData['timeout'] 			= 8000;
			$toastData['color'] 			= 'white';
			$toastData['icon'] 				= 'fas fa-thumbs-up';
			$toastData['animateInside'] 	= 'right';
			$toastData['position'] 			= 'bottomRight'; // bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter
			$toastData['progressBarColor'] 	= 'rgb(0, 255, 184)';
			$toastData['title']				=  $lang[3631];
			$toastData['message']			=  $lang[3632];

			$gritterJs 			= genericToast($toastData);
		}
	}

	/*
	 * Change to thumbnail view for certain AJAX calls
	 * 8/21/2018
	 */
	if (intval($_REQUEST['searchuid']) > 0 && $ajax == 1)
	{
		$thumbnail = 0;
	}

	if (!empty($cid))
	{
		$ajaxAdds 		.= '&cid=' . $cid;
		$ajaxDefaults 	.= '&cid=' . $cid;
	}
	if (!empty($tag))
	{
		$ajaxAdds .= '&tag=' . $tag;
	}
	if (!empty($onsale))
	{
		$ajaxAdds .= '&o=' . $onsale;
	}
	if (!empty($subonly))
	{
		$ajaxAdds .= '&sub=' . $subonly;
	}
	if (!empty($trending))
	{
		$ajaxAdds .= '&tnd=' . $trending;
	}
	if (!empty($squery))
	{
		$ajaxAdds .= '&query=' . addslashes($squery);
	}
//	$type 		= addslashes(intval(stripslashes(strip_tags(cleanit($_REQUEST['t'])))));
//	$page 				= intval($_REQUEST['page']);

	/*
	 * If we are in a category, enable the category header data
	 * 06/19/2018
	 */
	if (!empty($cid))
	{
		if (empty($categoryDetails['image_name']))
		{
			if (!empty($parentCatDetails['image_name']))
			{
				$categoryDetails['image_name']  = $parentCatDetails['image_name'];
			}
			else
			{
				if (!empty($ppParentCatDetails['image_name']))
				{
					$categoryDetails['image_name']  = $ppParentCatDetails['image_name'];
				}
				else
				{
					$categoryDetails['image_name'] = 'seo-reports.jpg';
				}
			}
		}

		$config['include']['hdr']['topbar'] 			= 0;
		$config['include']['hdr']['topbar_header']		= $h2header;
		$config['include']['hdr']['topbar_desc']		= $categoryDetails['metadescription'];
		$showbreadcrumbs								= 1;
	}
	else
	{
		$showbreadcrumbs				= 0;
		$categoryDetails['image_name'] 	= 'link-building.jpg';
	}

	/*
	* Set the header category
	* 10/10/2018
	*/
	$header_sub_cat_active 	= 'marketplace';
	$header_cat_active 		= 'home';

	$config['include']['tagsinput'] = 1;
	$config['include']['footerJs'] 	.= getLanguageForJS(array(3846, 3847, 3848, 3849, 3850));

	/*
	 * Nothing capped the page number, so /page/99999 of any list rendered an empty
	 * grid at 200 (a soft 404 to Google). Past the last page is a 404, and a tag
	 * list with nothing in it stays out of the index.
	 * 2026-09-23
	 */
	if ($ajax != 1)
	{
		if ($page > 1 && (intval($total) == 0 || $page > $toppage))
		{
			include '404.php';
			die();
		}

		if (!empty($tag) && intval($total) == 0) $config['noindex'] = 1;
	}

	if ($ajax == 1)
	{
		$firstLoad = 0;

		/*
		 * This will place caching headers in the call which will cause the browser to
		 * load the data from local disk.
		 *
		 * The only argument is the time in seconds, default is 180 (3 minutes)
		 * 10/5/2018
		 */
		//showCachingHeaders();

		/**
		 * HACK, needs to be fixed. The last value for pagination changed to be PAGEDATA
		 * but this does not actually use it.
		 *
		 * @TODO: fix
		 *
		 */
		/**
		 * Fetch our page data
		 */
		$pageData = fetchCurrentPageData($total, 'page');

		/**
		 * Replaced the code below with this as the code below was
		 * redundant in multiple files.
		 * 12/4/2018
		 */
		$ajaxJs = paginationFooterAjax($pagelinksUni, $pageShowingUni, $pageNext, $pageData);
		include 'views/view_index-bit.php';
		die();
	}
	else
	{
		/*
		 * Include templates that we need, called in the footer-loader.php file.
		*/
		$__includeTemplates[0]['path']	= $config['basedir']  . '/views/js/autocomplete/__view-marketplace.js.html';

		/**
		 * The subscription deposit promo's banner (subscription_promo.php), '' when
		 * it is not running or has nothing to offer this member. It is not a
		 * `promotions` row, so the $promo alert never shows it. Worked out here,
		 * not with $promo, so the listing fetches above do not pay for it.
		 *
		 * 2026-09-24 JD
		 */
		$subscriptionPromoBanner = function_exists('subscriptionPromoBannerText')
			? subscriptionPromoBannerText(isset($__loggedUserDetails['USERID']) ? intval($__loggedUserDetails['USERID']) : 0)
			: '';

		include 'views/header/view_header-loader.php';
		include 'views/view_index.php';
		include 'views/footer/view_footer-loader.php';
	}
}
else
{

	if (empty($message) && !empty($promo))
	{
		if ($promo[0]['new_theme_only'] == 1)
		{
			$ualert = $promo[0]['content'];

			if(!empty($promo[0]['buttonText']))
			{
				$ualert .= ' ' . $promo[0]['buttonLink'];
			}

			$CSFR 		= GenerateCSFRCode();
			$useralert  = $ualert . ". This promo is exclusive to our new theme. <a href='{$config['baseurl']}/settings/switch/theme/{$CSFR}'>Switch now</a>"; // Promotion text if it is for new theme only
		}
		else
		{
			$useralert = $promo[0]['content'];

			if(!empty($promo[0]['buttonText']))
			{
				$useralert .= ' ' . $promo[0]['buttonLink'];
			}
		}

	}

	if (empty($promo))
	{
		$CSFR = GenerateCSFRCode();

		/**
		 * Switching themes alert
		 */
 		$useralert = $config['sitetitle'] . " will be switching to our new theme on January 6, 2020. <a href='{$config['baseurl']}/settings/switch/theme/{$CSFR}'>Click here</a> to switch now.";
	 }

	/*
	 * If the user arrives on the landing page,
	 * we want them to see the landing design
	 * template
	 * 1/13/2013
	 */
	if ($landing == 1)
	{
	}
	else
	{
	}

}

//TEMPLATES END
?>
