<?php
/**************************************************************************************************
| Ionicware
| http://www.ionicware.com
| support@ionicware.com
|
|**************************************************************************************************
|
| Copyright (c) 2011 ionicware.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];
$showmax = "25";

$userName 	= $_REQUEST['u'];
$CATID 		= intval($_REQUEST['c']);
$rand		= intval($_REQUEST['r']);
$CATNAME 	= $_REQUEST['cn'];

/*
 * If the baseurl is seoclerks.com, change
 * it to seoclerk.com
 * 2/27/2014
 */
if (stristr($config['baseurl'], 'seoclerks.com'))
{
	$config['baseurl'] = 'https://www.seoclerk.com';
}

/*
 * Is there an affiliate ID as well?
 * 6/27/2012
 */
if (!empty($_REQUEST['a'])) {
		$affId = intval($_REQUEST['a']);
}

/*
 * Random Orders
 */
if ($rand == 1)
{
	$orderby = " order by rand() ";
}
else
{
	$orderby = ' order by A.PID desc '; // A.feat desc, 
}

/*
 * If we have a type, we need to determine the
 * the query and all that great stuff
 * 10/10/2013
 */
if (!empty($_REQUEST['type']) && ($_REQUEST['type'] == 'wtt' || $_REQUEST['type'] == 'wtb'))
{
	/*
	 * Stopped here
	 */
	if ($_REQUEST['type'] == 'wtt')
	{
		$fromtable 	= "wanttotrade";
		$link   	= $config['baseurl']."/rss/wtt"; 
		$showtitle 	= $lang['1859'];
		$type 		= 'wtt';
		$idcol		= 'tradeid';
		$linkadd	= 'trade/';
	}
	else if ($_REQUEST['type'] == 'wtb')
	{
		$fromtable 	= "wanttobuy";
		$link   	= $config['baseurl']."/rss/wtb"; 
		$showtitle 	= $lang['1860'];
		$type		= 'wtb';
		$idcol		= 'wantid';
		$linkadd	= 'want/';
	}
	
	$query = "SELECT A.description as gdesc, A.{$idcol} as PID, A.title as gtitle, A.maxprice as price, A.category, C.username 
				FROM {$fromtable} A, seoclerks.members C
				WHERE A.active=1 AND A.canceled=0
					AND A.USERID=C.USERID
				ORDER BY A.{$idcol} DESC limit $showmax";
}
else
{
	$type 		= "normal";
	$linkadd	= '';
	
	if($CATID > 0)
	{
		$addcat = " AND A.category='".escape($CATID)."'";
	}
	
	/*
	 * Only display by category name
	 * 2/8/2014
	 */
	if(!empty($CATNAME))
	{
		$query 			= "SELECT CATID FROM categories WHERE seo='".escape($CATNAME)."'";
		$executequery	= $conn->execute($query);
		$category 		= $executequery->fields['CATID'];
	
		if (intval($category) > 0)
		{
			$addcat = " AND A.category='".escape($category)."'";
		}
	}
	
	/*
	 * Added on 11/30/2011
	 */
	if (!empty($userName)) {
		$addcat .= " AND C.username='".escape($userName)."'";
	}
	
	
	$query = "SELECT A.gdesc, A.gtitle, A.price, A.PID, A.viewcount, A.type, A.category, C.username
				FROM posts A, seoclerks.members C 
				WHERE A.active='1' AND type=0 $addcat AND A.USERID=C.USERID $orderby limit $showmax";
	$showtitle = $lang['108'];
	
	
	$link   = $config['baseurl']."/rss"; 

}


/*
 * If affiliate, add the a to it.
 * 7/17/2013
 */
if ($affId > 0) 
{
	$link = $link . '?a=' . $affId;	
}

/*
 * If the user is on SEOClerks.com instead of
 * seoclerk.com, we need to change that
 */
if (stristr($_SERVER["HTTP_HOST"], 'seoclerks.com'))
{
	$link = str_ireplace('seoclerk.com', 'seoclerks.com', $link);
}
if (stristr($_SERVER["HTTP_HOST"], 'a.seoclerks.com'))
{
	$link = str_ireplace('www.seoclerks.com', 'a.seoclerks.com', $link);
}
if (stristr($_SERVER["HTTP_HOST"], 'a.seoclerk.com'))
{
	$link = str_ireplace('www.seoclerk.com', 'a.seoclerk.com', $link);
}
if ($_SERVER['SERVER_PORT'] == 80)
{
	$link = str_ireplace('https://', 'http://', $link);
}

header("Content-Type: text/xml"); 
header("X-Robots-Tag: noindex"); // A feed, not a page. Every profile links its /rss/u/ feed. 2026-09-23
header("Expires: 0"); 
print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; 
print "<rss xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\" version=\"2.0\">\n"; 
print "<channel>\n"; 
print "<title>".$showtitle." - ".$config['sitetitle']."</title>\n"; 
print "<link>$link</link>\n"; 
print "<atom:link rel=\"self\" type=\"application/rss+xml\" href=\"$link\"/>";
print "<description>".$showtitle."</description>\n"; 
echo  "<language>en-us</language>";
print " <pubDate>". date('r', time()) ."</pubDate>\n";

$executequery 	= $conn->Execute($query);

/*
 * A failed statement returns false, and ->getrows() on it is a fatal error
 * (seen in production on 7.4). An empty feed is the right answer here.
 * 2026-10-22
 */
$rssGet 		= ($executequery === false) ? array() : $executequery->getrows();
foreach ($rssGet as $results) 
{ 

   if (!empty($_REQUEST['type']) && ($_REQUEST['type'] == 'wtt' || $_REQUEST['type'] == 'wtb'))
   {
		$results['type'] 	= $type;
   }
	
   /*
	* Get the category based on the type
	* 10/10/2013
	*/
  $categoryDetails 	= GetCategorySeoFromType($results['type'], $results['category']);
  $results['seo'] 	= $categoryDetails['seo'];
  $results['name'] 	= $categoryDetails['name'];
  $description 		= RemoveTextBbcode($results['gdesc']); // htmlspecialchars(, ENT_QUOTES);
  $gtitle 			= RemoveTextBbcode($results['gtitle']); // htmlspecialchars(, ENT_QUOTES);
  $gprice 			= htmlspecialchars(RemoveTextBbcode($results['price']), ENT_QUOTES);
  $seo 				= htmlspecialchars($results['seo'], ENT_QUOTES);
  
  
  /*
	 * Change the title for MBL
	 * 4/22/2014
	 */
	if (stristr($_SERVER["HTTP_HOST"], 'monsterbacklinks.com'))
	{
		$gtitle 	= str_ireplace('SEOClerks.com', 'MonsterBacklinks.com', $gtitle);
		$gtitle		= str_ireplace('Seoclerks', 'Monster Backlinks', $gtitle);
		$gtitle 	= str_ireplace('SEOClerk', 'Monster Backlinks', $gtitle);
		$gtitle		= str_ireplace('Ionicware', 'SeoMerTech', $gtitle);	
		
		$description 	= str_ireplace('SEOClerks.com', 'MonsterBacklinks.com', $description);
		$description	= str_ireplace('Seoclerks', 'Monster Backlinks', $description);
		$description 	= str_ireplace('SEOClerk', 'Monster Backlinks', $description);
		$description	= str_ireplace('Ionicware', 'SeoMerTech', $description);	
	}
	else if (stristr($_SERVER["HTTP_HOST"], 'seocheckout.com'))
	{
		$gtitle 		= str_ireplace('SEOClerks.com', 'Seocheckout.com', $gtitle);
		$gtitle 		= str_ireplace('Seoclerks', 'Seocheckout', $gtitle);
		$gtitle 		= str_ireplace('SEOClerk', 'Seocheckout', $gtitle);
		$gtitle			= str_ireplace('Ionicware', 'Seocheckout', $gtitle);	
		
		$description 	= str_ireplace('SEOClerks.com', 'Seocheckout.com', $description);
		$description 	= str_ireplace('Seoclerks', 'Seocheckout', $description);
		$description 	= str_ireplace('SEOClerk', 'Seocheckout', $description);
		$description	= str_ireplace('Ionicware', 'Seocheckout', $description);
	}
	else if (stristr($_SERVER["HTTP_HOST"], 'seolads.com'))
	{
		$gtitle 		= str_ireplace('SEOClerks.com', 'SEOLads.com', $gtitle);
		$gtitle 		= str_ireplace('Seoclerks', 'SEOLads', $gtitle);
		$gtitle 		= str_ireplace('SEOClerk', 'SEOLads', $gtitle);
		$gtitle			= str_ireplace('Ionicware', 'SEOLads', $gtitle);	
		
		$description 	= str_ireplace('SEOClerks.com', 'SEOLads.com', $description);
		$description 	= str_ireplace('Seoclerks', 'SEOLads', $description);
		$description 	= str_ireplace('SEOClerk', 'SEOLads', $description);
		$description	= str_ireplace('Ionicware', 'SEOLads', $description);
	}
	
	 /*
	 * If the site is MBL, adjust the
	 * price up by 200%
	 * 4/6/2014
	 */
	if (stristr($_SERVER["HTTP_HOST"], 'seocheckout.com'))
	 {
		 $gprice 			= AdjustPriceUpSOC($gprice);

	 }
	 else  if (stristr($_SERVER["HTTP_HOST"], 'seolads.com'))
	 {
		 $gprice 			= AdjustPriceUpSOC($gprice);

	 }
	 else if (stristr($_SERVER["HTTP_HOST"], 'microjunky.com'))
	 {
		 $gprice 			= AdjustPriceUpMj($gprice);
	 }
  
  /*
   * Remove HTML from all items
   * 7/17/2013
   */
  $gtitle 		= strip_tags(html_entity_decode($gtitle, ENT_QUOTES));
  $description	= strip_tags(html_entity_decode($description, ENT_QUOTES));
  
  if ($affId > 0) {
	  $mylink       = $config['baseurl']."/linkin/{$affId}/{$linkadd}".$seo."/".$results['PID']."/".seo_clean_titles($gtitle); 
  } else {
	  $mylink       = $config['baseurl']."/{$linkadd}".$seo."/".$results['PID']."/".seo_clean_titles($gtitle);	  
  }
  $clink       = $config['baseurl']."/categories/".$seo;
  $getusername = htmlspecialchars($results['username'], ENT_QUOTES);
	print "<item>\n"; 
	print "  <title><![CDATA[".stripslashes($gtitle);
	
	/*
	 * Depending on the type, echo
	 * the for part out
	 */
	if ($type == "normal")
	{
		print " for $".stripslashes($gprice);
	}
	else if ($type == "wtb")
	{
		print ", max bid of $" .stripslashes($gprice);
	}
	
	print "]]></title>\n";
	print "  <link><![CDATA[".$mylink."]]></link>\n"; 
	print "  <guid><![CDATA[".$mylink."]]></guid>\n";
	print "  <description>\n"; 
	print "    <![CDATA["; 
	print stripslashes($description)."<br><br>".$lang['414'].": <a href=\"$config[baseurl]/".get_seo_profile($getusername)."\">$getusername</a>"; 
	print "<br />".$lang['360'].": ";
	$list=explode('-',$results['date_added']);
	print_r($list[2]);print_r('-');
	print_r($list[1]);print_r('-');
	print_r($list[0]);
	$category = $results['name'];
	print "<br>".$lang['66'].": <a href='".$clink."'>$category</a>"; 
	print "<br>".$lang['181'].": $results[viewcount]";	
	print "<br/><br/><br /><hr>"; 
	print "    ]]>\n"; 
	print "  </description>\n"; 
	print "  <dc:creator>".$getusername."</dc:creator>\n"; 
	print "</item>\n"; 
} 
print "</channel>\n"; 
print "</rss>"; 
?> 