<?php
    include "../common.php";
    header('Content-type: text/xml');
    $today = date("Y-m-d H:i:s");
    $todaysdate = date("D, d M Y H:i:s T");
?>
<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom">
<channel>
<atom:link href="<?PHP print $siteurl; ?>xml/companynews.xml" rel="self" type="application/rss+xml" />
<?PHP
// SET HEADER DATA
$biztype = "";
if(isset($_GET['company'])) {

    $company = htmlentities(strip_tags($_GET['company']));
	$GetCompany = mysqli_query($linkID, "SELECT * FROM admanager where companycode='" . mysqli_real_escape_string($linkID, $company) . "' and frstatus = 4 ");
	while ($c = mysqli_fetch_object($GetCompany)) {
        $company = $c->company;
        $companycode = $c->companycode;

        // IF FRANCHISE OPPORTUNITY
        if($c->fr == 1) {

          if($c->bizopp == 0) {
              $biztype = "Franchise";
            } else {
              $biztype = "Business";
            }
          $clink = $c->companycode . "/";
        }


        // IF SUPPLIER DIRECTORY
        if($c->frsd == 1 || $c->fusd == 1) {
          $biztype     = "Business";
          $clink       = "suppliers/" . $c->companycode . "/";
        }
    }

	$cq = " and clientcode='$companycode' ";
    ?>
	    <title><?PHP print $company; ?> News Ticker</title>
	    <link><?PHP print $siteurl . $clink; ?></link>
	    <description><?PHP print $company; ?> <?PHP print strtolower($biztype); ?> news feed covering: general announcements, mergers, acquisitions, personnel changes, business expansion, media coverage, conference calls, earnings claims, product announcements, and strategic alliances.
</description>
	    <language>en-us</language>
		<managingEditor>benjaminf@franchiseupdatemedia.com (<?PHP print $siteident; ?> News Wire)</managingEditor>
		<lastBuildDate><?php print $todaysdate; ?></lastBuildDate>
		<copyright>Copyright 2004-<?PHP print date("Y"); ?> Franchise Update Media Group. All rights reserved.</copyright>
<?PHP
} else {
	$cq = "";
	?>
    <title>Franchise News Wire by <?PHP print $siteident; ?></title>
    <link><?PHP print  $siteurl; ?></link>
    <description>Franchise industry news from over 1,000 franchise companies and business opportunities worldwide. Covering: general announcements, mergers, acquisitions, personnel changes, business expansion, media coverage, conference calls,earnings claims, product announcements, and strategic alliances.</description>
    <language>en-us</language>
	<managingEditor>bfoley@franchise-update.com (<?PHP print $siteident; ?> News Wire)</managingEditor>
	<lastBuildDate><?php print $todaysdate; ?></lastBuildDate>
	<copyright>Copyright 2004-<?php print date('Y'); ?> Franchise UPDATE Inc. All rights reserved.</copyright>
<?PHP
}

// BUILD CONTENT

$resultID = mysqli_query($linkID, "SELECT * FROM press WHERE active = 1 $cq and postdate <= '$today' ORDER BY postdate desc LIMIT 0,50");
$recordcount = mysqli_num_rows($resultID);
while ($row = mysqli_fetch_object($resultID)) {
    $frsb = "0";
    $ImageType = "";
    $CheckClient = mysqli_query($linkID, "SELECT companycode,fr,frstatus,frsb FROM admanager WHERE companycode = '$row->clientcode' and fr=1 and frstatus = 4");
    $ClientCount = mysqli_num_rows($CheckClient);
    while ($client = mysqli_fetch_object($CheckClient)) {
        $frsb = $client->frsb;
        $companycode = $client->companycode;
    }
    

	if($ClientCount > 0) {
      if(file_exists("s3://fum-assets/brands/logos/".$row->clientcode.".png")) {
        $ImageBanner = "https://imgs.franchising.com/brands/logos/".$row->clientcode.".png";
        $ImageType = "png";
      }
	}

    $ThisLink = "https://www.franchising.com/news/" .  $row->slug . ".html";

// Sanitize Output
$rsssanitize = array("“", "᾿", "‘", "’", "—", "…",chr(150), chr(147), chr(148), chr(146), chr(130),	 chr(133), chr(145), chr(151), chr(150), chr(180), chr(169), chr(153),"&#039;", "&rdquo;", "&ldquo;", "&rsquo;", "&lsquo;", "&#8212;", "&quot;", '&#174;','&reg;','&ndash;','&mdash;','&eacute;','&trade;','&hellip;');
$rssreplaced = array ("\"","\"","'","'","--","...","-","\"","\"","'",",","...","'","--","-","'","(C)","TM","'",'"','"',"'","'","--",'"','(R)','(R)','-','--','e',"TM","...");

$description = str_replace($rsssanitize, $rssreplaced, $row->description);
$headline = str_replace($rsssanitize, $rssreplaced, $row->headline);
$company = str_replace($rsssanitize, $rssreplaced, $row->company);
?>
<item>
  <guid><?PHP print $ThisLink; ?>?ref=rss</guid>
  <title><?php print ucwords($headline); ?></title>
  <?PHP if($ClientCount != 0) { ?>
  <description><![CDATA[<a href="https://www.franchising.com/<?PHP print $row->clientcode; ?>/?ref=rss"><img src="<?PHP print $ImageBanner; ?>" width="250"  style="width: 20%; max-width: 250px;" border="0" align="right" hspace="10" /></a><?php print $description; ?>]]></description>
  <?PHP } else { ?>
  <description><![CDATA[<?php print $description; ?>]]></description>
  <?PHP } ?>
  <link><?PHP print $ThisLink; ?>?ref=rss</link>
  <pubDate><?php print date("D, d M Y H:i:s T",  strtotime($row->postdate)); ?></pubDate>
</item>
<?php } ?>
</channel>
</rss>
<?PHP mysqli_close($linkID); ?>