Gazelle/classes/sitehistory.class.php

254 lines
6.2 KiB
PHP
Raw Normal View History

2013-07-28 08:00:53 +00:00
<?
class SiteHistory {
private static $Categories = array(1 => "Code", "Event", "Milestone", "Policy", "Release", "Staff Change");
2013-07-29 08:00:49 +00:00
private static $SubCategories = array(1 => "Announcement", "Blog Post", "Change Log", "Forum Post", "Wiki", "Other", "External Source");
2013-07-28 08:00:53 +00:00
private static $Tags = array(
"api",
"celebration",
"class.primary",
"class.secondary",
"collage",
"community",
2013-07-29 08:00:49 +00:00
"conclusion",
2013-07-28 08:00:53 +00:00
"contest",
"design",
"donate",
"editing",
"editorial",
"feature",
"featured.article",
"featured.album",
"featured.product",
"finances",
"format",
"forum",
"freeleech",
"freeleech.tokens",
"gazelle",
"hierarchy",
"inbox",
"infrastructure",
"interview",
"irc",
"log",
"neutral.leech",
"notifications",
"ocelot",
"paranoia",
"picks.guest",
"picks.staff",
"promotion",
"ratio",
2013-07-29 08:00:49 +00:00
"record",
2013-07-28 08:00:53 +00:00
"report",
"request",
"requirement",
"retirement",
"rippy",
"search",
"settings",
2013-07-29 08:00:49 +00:00
"start",
2013-07-28 08:00:53 +00:00
"stats",
"store",
"stylesheet",
"tagging",
"transcode",
"toolbox",
"top.10",
"torrent",
"torrent.group",
"upload",
"vanity.house",
"voting",
"whitelist",
"wiki");
public static function get_months() {
$Results = G::$Cache->get_value("site_history_months");
if (!$Results) {
G::$DB->query("
SELECT DISTINCT
YEAR(DATE) AS Year, MONTH(Date) AS Month, MONTHNAME(Date) AS MonthName
FROM site_history
ORDER BY Date DESC");
$Results = G::$DB->to_array();
G::$Cache->cache_value("site_history_months", $Results, 0);
}
return $Results;
}
public static function get_event($ID) {
if (!empty($ID)) {
G::$DB->query("
SELECT
ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
FROM site_history
WHERE ID = '$ID'
ORDER BY Date DESC");
return G::$DB->next_record();
}
}
public static function get_latest_events($Limit) {
self::get_events(null, null, null, null, null, null, $Limit);
}
public static function get_events($Month, $Year, $Title, $Category, $SubCategory, $Tags, $Limit) {
$Month = (int) $Month;
$Year = (int) $Year;
$Title = db_string($Title);
$Category = (int) $Category;
$SubCategory = (int) $SubCategory;
$Tags = db_string($Tags);
$Limit = (int) $Limit;
$Where = array();
if (!empty($Month)) {
$Where[] = " MONTH(Date) = '$Month' ";
}
if (!empty($Year)) {
$Where[] = " YEAR(Date) = '$Year' ";
}
if (!empty($Title)) {
$Where[] = " Title LIKE '%$Title%' ";
}
if (!empty($Category)) {
$Where[] = " Category = '$Category '";
}
if (!empty($SubCategory)) {
$Where[] = " SubCategory = '$SubCategory '";
}
if (!empty($Tags)) {
$Tags = explode(",", $Tags);
$Or = "(";
foreach($Tags as $Tag) {
$Tag = trim($Tag);
$Or .= " Tags LIKE '%$Tag%' OR ";
}
if (strlen($Or) > 1) {
$Or = rtrim($Or, "OR ");
$Or .= ")";
$Where[] = $Or;
}
}
if (!empty($Limit)) {
$Limit = " LIMIT $Limit";
} else {
$Limit = "";
}
if (count($Where) > 0) {
$Query = " WHERE " . implode("AND", $Where);
} else {
$Query = "";
}
G::$DB->query("
SELECT
ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
FROM site_history
$Query
ORDER BY Date DESC
$Limit");
return G::$DB->to_array();
}
public static function add_event($Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID) {
if (empty($Date)) {
$Date = sqltime();
} else {
list($Y, $M, $D) = explode('-', $Date);
if (!checkdate($M, $D, $Y)) {
error("Error");
}
}
$Title = db_string($Title);
$Link = db_string($Link);
$Category = (int) $Category;
$SubCategory = (int) $SubCategory;
$Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
$ExplodedTags = explode(",", $Tags);
foreach($ExplodedTags as $Tag) {
if (!in_array($Tag, self::get_tags())) {
error("Invalid tag");
}
}
$Body = db_string($Body);
$UserID = (int) $UserID;
if (empty($Title) || empty($Category) || empty($SubCategory)) {
error("Error");
}
G::$DB->query("
INSERT INTO site_history
(Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date)
VALUES
('$Title', '$Link', '$Category', '$SubCategory', '$Tags', '$Body', '$UserID', '$Date')");
G::$Cache->delete_value("site_history_months");
}
public static function update_event($ID, $Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID) {
if (empty($Date)) {
$Date = sqltime();
} else {
$Date = db_string($Date);
list($Y, $M, $D) = explode('-', $Date);
if (!checkdate($M, $D, $Y)) {
error("Error");
}
}
$ID = (int) $ID;
$Title = db_string($Title);
$Link = db_string($Link);
$Category = (int) $Category;
$SubCategory = (int) $SubCategory;
$Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
$ExplodedTags = explode(",", $Tags);
foreach($ExplodedTags as $Tag) {
if (!in_array($Tag, self::get_tags())) {
error("Invalid tag");
}
}
$Body = db_string($Body);
$UserID = (int) $UserID;
if (empty($ID) || empty($Title) || empty($Category) || empty($SubCategory)) {
error("Error");
}
G::$DB->query("
UPDATE site_history
SET
Title = '$Title',
Url = '$Link',
Category = '$Category',
SubCategory = '$SubCategory',
Tags = '$Tags',
Body = '$Body',
AddedBy = '$UserID',
Date = '$Date'
WHERE
ID = '$ID'");
G::$Cache->delete_value("site_history_months");
}
public static function delete_event($ID) {
if (empty($ID)) {
error(404);
}
G::$DB->query("DELETE FROM site_history WHERE ID = '$ID'");
G::$Cache->delete_value("site_history_months");
}
public static function get_categories() {
return self::$Categories;
}
public static function get_sub_categories() {
return self::$SubCategories;
}
public static function get_tags() {
return self::$Tags;
}
}