function getDownloads($files) { $webClass = new WebClass(); $query = "SELECT * FROM 2s2h_downloads;"; /* get all articles here */ $result = $webClass->executeQuery($query); $filesOnDb = array(); while ($row = mysql_fetch_assoc($result)) { //salvo tutto su un array $filesOnDb[] = $row; } $downloads = array(); foreach ($files as $file) { //controllo per ogni file se è già presente nel database $name = substr($file, strrpos($file, '/')); $found = false; foreach ($filesOnDb as $fileOnDb) { if (strcmp($fileOnDb['file'], $name) == 0) { $found = true; $downloads[$file] = $fileOnDb['number']; } } if (!$found) { //aggiungo un record al db $query = "INSERT INTO 2s2h_downloads VALUES ('',\"{$name}\",\"0\");"; $webClass->executeQuery($query); $downloads[$file] = 0; } } $webClass->close(); return $downloads; }
<?php header("Content-type: text/xml"); require '../functions/WebClass.php'; $link = "http://www.2s2h.com/2steps-2hell-news.php"; echo "<?xml version='1.0' encoding='ISO-8859-1'?>\n <rss version='2.0'>\n <channel>\n <title>2s2h news</title>\n <link>" . $link . "</link>\n <description>2Step2Hell's news</description>"; $webClass = new WebClass(); $newsQuery = "SELECT * FROM 2s2h_news ORDER BY 2s2h_news.time DESC;"; $result = $webClass->executeQuery($newsQuery); if ($result) { while ($row = mysql_fetch_assoc($result)) { $id = $row['id']; $title = $row['title']; $weblink = $link . "#" . $id; $article = html_entity_decode($row['article']); $author = $row['author']; $pubdate = $row['time']; echo "<item>\n <title>" . $title . "</title>\n <link>" . $weblink . "</link>\n <description><![CDATA[" . nl2br($article) . "]]></description>\n <author>" . $author . "</author>\n <pubDate>" . $pubdate . "</pubDate>\n </item>"; } // finish rss file echo "</channel>\n </rss>"; } $webClass->close();