<?php

header('Content-Type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;

include 'client/client.php';

$db = null;

$db = SetClientConnection();

if ($db) {

?>
<rss version="2.0">
  <channel>
    <title>Opinion Paper</title>
    <link>https://opinionpaper.com/</link>
    <description>Opinions and Creative Pursuits from Brett Rogers</description>
    <language>en-us</language>
    <?php

    $sql = "SELECT TOP 20 ContentID, ContentName, AuthorName, Content, DateEntered, ContentImage FROM OP_Author INNER JOIN OP_Content ON OP_Author.AuthorID = OP_Content.AuthorID WHERE (PageID = 0) ORDER BY DateEntered DESC";
    $result = sqlsrv_query($db, $sql);
    if($result === false) {
      die( print_r( sqlsrv_errors(), true));
    }

    while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
    ?>
    <item>
      <title><?=htmlspecialchars($row['ContentName'], ENT_QUOTES)?></title>
      <link><?=htmlspecialchars('https://opinionpaper.com/hmm.php?c=' . $row['ContentID'], ENT_QUOTES)?></link>
      <description><?=htmlspecialchars($row['Content'], ENT_QUOTES)?></description>
      <pubDate><?=date('r', strtotime(date_format($row['DateEntered'], 'M j, Y g:i A')))?></pubDate>
    </item>
    <?php
    }
    sqlsrv_free_stmt($result);
    ?>
  </channel>
</rss>
<?php

  $db = CloseClientConnection($db);
}
?>