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) {
|
2013-08-28 23:08:41 +00:00
|
|
|
$QueryID = G::$DB->get_query_id();
|
2013-07-28 08:00:53 +00:00
|
|
|
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();
|
2013-08-28 23:08:41 +00:00
|
|
|
G::$DB->set_query_id($QueryID);
|
2013-07-28 08:00:53 +00:00
|
|
|
G::$Cache->cache_value("site_history_months", $Results, 0);
|
|
|
|
}
|
|
|
|
return $Results;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_event($ID) {
|
|
|
|
if (!empty($ID)) {
|
2013-08-28 23:08:41 +00:00
|
|
|
$QueryID = G::$DB->get_query_id();
|
2013-07-28 08:00:53 +00:00
|
|
|
G::$DB->query("
|
2013-08-28 23:08:41 +00:00
|
|
|
SELECT
|
|
|
|
ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
|
|
|
|
FROM site_history
|
|
|
|
WHERE ID = '$ID'
|
|
|
|
ORDER BY Date DESC");
|
|
|
|
$Event = G::$DB->next_record();
|
|
|
|
G::$DB->set_query_id($QueryID);
|
|
|
|
return $Event;
|
2013-07-28 08:00:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2013-08-28 23:08:41 +00:00
|
|
|
$Month = (int)$Month;
|
|
|
|
$Year = (int)$Year;
|
2013-07-28 08:00:53 +00:00
|
|
|
$Title = db_string($Title);
|
2013-08-28 23:08:41 +00:00
|
|
|
$Category = (int)$Category;
|
|
|
|
$SubCategory = (int)$SubCategory;
|
2013-07-28 08:00:53 +00:00
|
|
|
$Tags = db_string($Tags);
|
2013-08-28 23:08:41 +00:00
|
|
|
$Limit = (int)$Limit;
|
2013-07-28 08:00:53 +00:00
|
|
|
$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)) {
|
2013-08-28 23:08:41 +00:00
|
|
|
$Tags = explode(',', $Tags);
|
|
|
|
$Or = '(';
|
|
|
|
foreach ($Tags as $Tag) {
|
2013-07-28 08:00:53 +00:00
|
|
|
$Tag = trim($Tag);
|
|
|
|
$Or .= " Tags LIKE '%$Tag%' OR ";
|
|
|
|
}
|
|
|
|
if (strlen($Or) > 1) {
|
2013-08-28 23:08:41 +00:00
|
|
|
$Or = rtrim($Or, 'OR ');
|
|
|
|
$Or .= ')';
|
2013-07-28 08:00:53 +00:00
|
|
|
$Where[] = $Or;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($Limit)) {
|
|
|
|
$Limit = " LIMIT $Limit";
|
|
|
|
} else {
|
2013-08-28 23:08:41 +00:00
|
|
|
$Limit = '';
|
2013-07-28 08:00:53 +00:00
|
|
|
}
|
|
|
|
if (count($Where) > 0) {
|
2013-08-28 23:08:41 +00:00
|
|
|
$Query = ' WHERE ' . implode('AND', $Where);
|
2013-07-28 08:00:53 +00:00
|
|
|
} else {
|
2013-08-28 23:08:41 +00:00
|
|
|
$Query = '';
|
2013-07-28 08:00:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 23:08:41 +00:00
|
|
|
$QueryID = G::$DB->get_query_id();
|
2013-07-28 08:00:53 +00:00
|
|
|
G::$DB->query("
|
2013-08-28 23:08:41 +00:00
|
|
|
SELECT
|
|
|
|
ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
|
|
|
|
FROM site_history
|
|
|
|
$Query
|
|
|
|
ORDER BY Date DESC
|
|
|
|
$Limit");
|
|
|
|
$Events = G::$DB->to_array();
|
|
|
|
G::$DB->set_query_id($QueryID);
|
|
|
|
return $Events;
|
2013-07-28 08:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2013-08-28 23:08:41 +00:00
|
|
|
$Category = (int)$Category;
|
|
|
|
$SubCategory = (int)$SubCategory;
|
2013-07-28 08:00:53 +00:00
|
|
|
$Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
|
2013-08-28 23:08:41 +00:00
|
|
|
$ExplodedTags = explode(',', $Tags);
|
|
|
|
foreach ($ExplodedTags as $Tag) {
|
2013-07-28 08:00:53 +00:00
|
|
|
if (!in_array($Tag, self::get_tags())) {
|
|
|
|
error("Invalid tag");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$Body = db_string($Body);
|
2013-08-28 23:08:41 +00:00
|
|
|
$UserID = (int)$UserID;
|
2013-07-28 08:00:53 +00:00
|
|
|
|
|
|
|
if (empty($Title) || empty($Category) || empty($SubCategory)) {
|
|
|
|
error("Error");
|
|
|
|
}
|
|
|
|
|
2013-08-28 23:08:41 +00:00
|
|
|
$QueryID = G::$DB->get_query_id();
|
2013-07-28 08:00:53 +00:00
|
|
|
G::$DB->query("
|
2013-08-28 23:08:41 +00:00
|
|
|
INSERT INTO site_history
|
|
|
|
(Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date)
|
|
|
|
VALUES
|
|
|
|
('$Title', '$Link', '$Category', '$SubCategory', '$Tags', '$Body', '$UserID', '$Date')");
|
|
|
|
G::$DB->set_query_id($QueryID);
|
2013-07-28 08:00:53 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 23:08:41 +00:00
|
|
|
$ID = (int)$ID;
|
2013-07-28 08:00:53 +00:00
|
|
|
$Title = db_string($Title);
|
|
|
|
$Link = db_string($Link);
|
2013-08-28 23:08:41 +00:00
|
|
|
$Category = (int)$Category;
|
|
|
|
$SubCategory = (int)$SubCategory;
|
2013-07-28 08:00:53 +00:00
|
|
|
$Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
|
|
|
|
$ExplodedTags = explode(",", $Tags);
|
2013-08-28 23:08:41 +00:00
|
|
|
foreach ($ExplodedTags as $Tag) {
|
2013-07-28 08:00:53 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2013-08-28 23:08:41 +00:00
|
|
|
$QueryID = G::$DB->get_query_id();
|
2013-07-28 08:00:53 +00:00
|
|
|
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'");
|
2013-08-28 23:08:41 +00:00
|
|
|
G::$DB->set_query_id($QueryID);
|
2013-07-28 08:00:53 +00:00
|
|
|
G::$Cache->delete_value("site_history_months");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function delete_event($ID) {
|
|
|
|
if (empty($ID)) {
|
|
|
|
error(404);
|
|
|
|
}
|
2013-08-28 23:08:41 +00:00
|
|
|
$QueryID = G::$DB->get_query_id();
|
2013-07-28 08:00:53 +00:00
|
|
|
G::$DB->query("DELETE FROM site_history WHERE ID = '$ID'");
|
2013-08-28 23:08:41 +00:00
|
|
|
G::$DB->set_query_id($QueryID);
|
2013-07-28 08:00:53 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-08-28 23:08:41 +00:00
|
|
|
}
|