diff --git a/classes/sitehistory.class.php b/classes/sitehistory.class.php new file mode 100644 index 00000000..51a744ad --- /dev/null +++ b/classes/sitehistory.class.php @@ -0,0 +1,251 @@ + "Code", "Event", "Milestone", "Policy", "Release", "Staff Change"); + private static $SubCategories = array(1 => "Announcement", "Blog Post", "Change Log", "Forum Post", "Wiki"); + private static $Tags = array( + "api", + "celebration", + "class.primary", + "class.secondary", + "collage", + "community", + "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", + "report", + "request", + "requirement", + "retirement", + "rippy", + "search", + "settings", + "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; + } +} \ No newline at end of file diff --git a/classes/sitehistoryview.class.php b/classes/sitehistoryview.class.php new file mode 100644 index 00000000..8f937eda --- /dev/null +++ b/classes/sitehistoryview.class.php @@ -0,0 +1,210 @@ + + + +
+
+
+ + Edit + + + + - + [] + [] + + + + + + +
+
+ +
+
+ +
+ full_format($Event['Body'])?> +
+ +
+" . $Tag . ", "; + } + echo rtrim($FormattedTags, ', '); + } + + public static function render_months($Months) { ?> +
+
Calendar
+
+$Year"; + } ?> + + +
+
+ +
+
Search
+
+
+ + +

+ +

+ +

+ +

+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Title: + +
Link: + +
Date: + + value=""/> + +
Category: + +
Subcategory: + +
Tags: + + +
Body: + +
+ + + + +
+ +
+
+ Latest site history +
+ +
+ +
Stats
- -
- + diff --git a/sections/user/lastfm.php b/sections/user/lastfm.php index 72597975..833a9061 100644 --- a/sections/user/lastfm.php +++ b/sections/user/lastfm.php @@ -3,7 +3,7 @@ $DB->query(" SELECT username FROM lastfm_users - WHERE ID = '$UserID'"); + WHERE ID = $UserID"); if ($DB->has_results()) { list($LastFMUsername) = $DB->next_record(); $LastFMInfo = LastFM::get_user_info($LastFMUsername); @@ -13,21 +13,21 @@ if ($DB->has_results()) {
Last.fm
diff --git a/sitehistory.php b/sitehistory.php new file mode 100644 index 00000000..172ee44a --- /dev/null +++ b/sitehistory.php @@ -0,0 +1,2 @@ +\[/,""); - } else if ( $(this).attr("href") == "#topartists" ) { + } else if ($(this).attr("href") == "#topartists") { topArtists = topArtists.replace(/\ class="hidden"/g,""); topArtists = topArtists.replace(/
  • \[/,""); - } else if ( $(this).attr("href") == "#topalbums" ) { + } else if ($(this).attr("href") == "#topalbums") { topAlbums = topAlbums.replace(/\ class="hidden"/g,""); topAlbums = topAlbums.replace(/
  • \[/,""); - } else if ( $(this).attr("href") == "#toptracks" ) { + } else if ($(this).attr("href") == "#toptracks") { topTracks = topTracks.replace(/\ class="hidden"/g,""); topTracks = topTracks.replace(/
  • \[/,""); } @@ -98,7 +98,7 @@ html += '
  • Loading...
  • '; div.html(html); // If the data isn't expanded hide most of the info. - if ( expanded == false ) { + if (expanded == false) { $("#lastfm_stats").children(":not(.lastfm_essential)").addClass("hidden"); $("#lastfm_reload_container").addClass("hidden"); } else { @@ -128,12 +128,12 @@ //Own profile, don't show tasteometer and shared artists. tasteometer = " "; sharedArtists = " "; - } else { + } else if (username) { $.get('user.php?action=lastfm_compare&username=' + username, function (response) { // Two separate elements are received from one Last.fm API call. var tasteometerHtml = ""; var sharedArtistsHtml = ""; - if ( response ) { + if (response && response != "false") { json = JSON.parse(response); if (json != null && json['error']) { console.log("Tasteometer: " + json['message']); @@ -156,7 +156,7 @@ compatibility = "Unknown"; tasteometerHtml += compatibility; } else { - if (compatibility < 50) { + if (compatibility < 50) { background = 'rgb(255, '+Math.floor(255*compatibility/50)+', 0)' } else { background = 'rgb('+Math.floor((1-(compatibility-50)/50)*255)+', 255, 0)' @@ -173,11 +173,13 @@ if (j['artists']['matches'] != 0) { sharedArtistsHtml += '
  • Shared artists: