From e830d8d5178b4491aa9f608f274674d7c8d51dea Mon Sep 17 00:00:00 2001
From: Git
Date: Thu, 11 Oct 2012 08:00:15 +0000
Subject: [PATCH] Empty commit
---
classes/ajax_start.php | 4 +-
classes/class_artist.php | 18 +-
classes/class_artists.php | 274 ++
classes/class_artists_similar.php | 155 +-
classes/class_cache.php | 45 +-
classes/class_charts.php | 2 +-
classes/class_debug.php | 14 +-
classes/class_format.php | 396 +++
classes/class_invite_tree.php | 22 +-
classes/class_irc.php | 12 +-
classes/class_misc.php | 395 +++
classes/class_mysql.php | 4 +-
classes/class_permissions.php | 100 +
classes/class_requests.php | 120 +
classes/class_sphinxql.php | 20 +-
classes/class_text.php | 8 +-
classes/class_text2.php | 2 +-
classes/class_tools.php | 239 ++
classes/class_torrent_form.php | 14 +-
classes/class_torrents.php | 481 ++++
classes/class_tracker.php | 73 +
classes/class_users.php | 452 +++
classes/class_view.php | 73 +
classes/class_zip.php | 2 +-
classes/script_start.php | 2417 +----------------
classes/util.php | 95 +
design/privatefooter.php | 2 +-
design/privateheader.php | 6 +-
image.php | 2 +-
sections/ajax/artist.php | 28 +-
sections/ajax/better/single.php | 2 +-
sections/ajax/better/transcode.php | 6 +-
sections/ajax/bookmarks/torrents.php | 6 +-
sections/ajax/browse.php | 8 +-
sections/ajax/forum/forum.php | 8 +-
sections/ajax/forum/main.php | 2 +-
sections/ajax/forum/thread.php | 10 +-
sections/ajax/inbox/inbox.php | 6 +-
sections/ajax/inbox/viewconv.php | 2 +-
sections/ajax/notifications.php | 6 +-
sections/ajax/request.php | 12 +-
sections/ajax/requests.php | 12 +-
sections/ajax/subscriptions.php | 2 +-
sections/ajax/tcomments.php | 6 +-
sections/ajax/top10/torrents.php | 2 +-
sections/ajax/torrentgroup.php | 2 +-
sections/ajax/userhistory/post_history.php | 4 +-
sections/ajax/usersearch.php | 4 +-
sections/artist/add_alias.php | 6 +-
sections/artist/artist.php | 111 +-
sections/artist/artist_rearrange.php | 65 +-
sections/artist/change_artistid.php | 10 +-
sections/artist/delete.php | 6 +-
sections/artist/delete_alias.php | 2 +-
sections/artist/download.php | 24 +-
sections/artist/edit.php | 4 +-
sections/artist/history.php | 4 +-
sections/artist/rename.php | 14 +-
sections/better/better.php | 4 +-
sections/better/files.php | 10 +-
sections/better/folders.php | 10 +-
sections/better/single.php | 8 +-
sections/better/snatch.php | 8 +-
sections/better/tags.php | 10 +-
sections/better/transcode.php | 10 +-
sections/better/upload.php | 8 +-
sections/blog/index.php | 6 +-
sections/bookmarks/add.php | 2 +-
sections/bookmarks/artists.php | 6 +-
sections/bookmarks/torrents.php | 22 +-
sections/chat/index.php | 4 +-
sections/collages/all_comments.php | 12 +-
sections/collages/browse.php | 18 +-
sections/collages/collage.php | 24 +-
sections/collages/delete.php | 4 +-
sections/collages/download.php | 24 +-
sections/collages/edit.php | 4 +-
sections/collages/edit_handle.php | 2 +-
sections/collages/manage.php | 12 +-
sections/collages/new.php | 4 +-
sections/collages/new_handle.php | 4 +-
sections/collages/recover.php | 6 +-
sections/collages/take_delete.php | 2 +-
sections/comments/index.php | 24 +-
sections/donate/cancel.php | 4 +-
sections/donate/complete.php | 4 +-
sections/donate/donate.php | 6 +-
sections/donate/donate_gpal.php | 6 +-
sections/donate/ipn.php | 10 +-
sections/error/index.php | 6 +-
sections/forums/ajax_get_edit.php | 2 +-
sections/forums/edit_rules.php | 4 +-
sections/forums/forum.php | 14 +-
sections/forums/main.php | 8 +-
sections/forums/mod_thread.php | 2 +-
sections/forums/newthread.php | 6 +-
sections/forums/search.php | 12 +-
sections/forums/take_new_thread.php | 2 +-
sections/forums/take_warn.php | 8 +-
sections/forums/thread.php | 24 +-
sections/forums/warn.php | 8 +-
sections/friends/friends.php | 16 +-
sections/image/index.php | 2 +-
sections/inbox/compose.php | 4 +-
sections/inbox/conversation.php | 6 +-
sections/inbox/forward.php | 2 +-
sections/inbox/inbox.php | 14 +-
sections/inbox/takecompose.php | 2 +-
sections/index/feat_album.php | 6 +-
sections/index/private.php | 14 +-
sections/index/public.php | 4 +-
sections/log/index.php | 8 +-
sections/log/sphinx.php | 6 +-
sections/log/sql.php | 2 +-
sections/login/disabled.php | 4 +-
sections/login/index.php | 20 +-
sections/login/login.php | 4 +-
sections/login/recover_step1.php | 4 +-
sections/login/recover_step2.php | 4 +-
sections/peerupdate/index.php | 4 +-
sections/register/closed.php | 4 +-
sections/register/code.php | 4 +-
sections/register/index.php | 12 +-
sections/register/step1.php | 4 +-
sections/register/step2.php | 4 +-
sections/reports/compose.php | 18 +-
sections/reports/report.php | 4 +-
sections/reports/reports.php | 8 +-
sections/reports/stats.php | 4 +-
sections/reports/takecompose.php | 2 +-
sections/reportsv2/ajax_new_report.php | 2 +-
sections/reportsv2/ajax_take_pm.php | 2 +-
sections/reportsv2/report.php | 4 +-
sections/reportsv2/reports.php | 4 +-
sections/reportsv2/search.php | 4 +-
sections/reportsv2/static.php | 12 +-
sections/reportsv2/takeresolve.php | 10 +-
sections/reportsv2/views.php | 4 +-
sections/requests/interim.php | 4 +-
sections/requests/new_edit.php | 16 +-
sections/requests/request.php | 56 +-
sections/requests/requests.php | 30 +-
sections/requests/requests.php.presphinx | 2 +-
sections/requests/takedelete.php | 8 +-
sections/requests/takefill.php | 8 +-
sections/requests/takenew_edit.php | 10 +-
sections/requests/takeunfill.php | 10 +-
sections/requests/takevote.php | 2 +-
sections/rules/chat.php | 4 +-
sections/rules/clients.php | 4 +-
sections/rules/collages.php | 4 +-
sections/rules/ratio.php | 4 +-
sections/rules/requests.php | 4 +-
sections/rules/rules.php | 4 +-
sections/rules/tag.php | 4 +-
sections/rules/upload.php | 4 +-
sections/schedule/index.php | 50 +-
sections/staff/index.php | 10 +-
sections/staffblog/index.php | 4 +-
sections/staffpm/assign.php | 2 +-
sections/staffpm/common_responses.php | 4 +-
sections/staffpm/staff_inbox.php | 22 +-
sections/staffpm/user_inbox.php | 4 +-
sections/staffpm/viewconv.php | 12 +-
sections/stats/torrents.php | 4 +-
sections/stats/users.php | 6 +-
sections/tools/data/bitcoin_balance.php | 6 +-
sections/tools/data/common_snatches.php | 4 +-
sections/tools/data/database_specifics.php | 18 +-
sections/tools/data/donation_log.php | 10 +-
sections/tools/data/economic_stats.php | 26 +-
sections/tools/data/invite_pool.php | 10 +-
sections/tools/data/opcode_stats.php | 12 +-
sections/tools/data/registration_log.php | 16 +-
sections/tools/data/service_stats.php | 22 +-
sections/tools/data/special_users.php | 6 +-
sections/tools/data/torrent_stats.php | 20 +-
sections/tools/data/upscale_pool.php | 20 +-
sections/tools/data/user_flow.php | 8 +-
sections/tools/managers/bans.php | 16 +-
sections/tools/managers/dnu_list.php | 6 +-
sections/tools/managers/eb.php | 6 +-
sections/tools/managers/forum_list.php | 6 +-
sections/tools/managers/login_watch.php | 6 +-
sections/tools/managers/news.php | 4 +-
sections/tools/managers/official_tags.php | 6 +-
sections/tools/managers/permissions_alter.php | 4 +-
sections/tools/managers/permissions_list.php | 4 +-
sections/tools/managers/recommend_add.php | 2 +-
sections/tools/managers/recommend_list.php | 6 +-
sections/tools/managers/tag_aliases.php | 4 +-
sections/tools/managers/tokens.php | 4 +-
sections/tools/managers/whitelist_alter.php | 6 +-
sections/tools/managers/whitelist_list.php | 4 +-
sections/tools/misc/analysis.php | 4 +-
sections/tools/misc/clear_cache.php | 4 +-
sections/tools/misc/countries.php | 4 +-
sections/tools/misc/create_user.php | 14 +-
sections/tools/misc/dupe_ip.php | 12 +-
sections/tools/misc/manipulate_tree.php | 4 +-
sections/tools/misc/quick_ban.php | 2 +-
sections/tools/misc/update_geoip.php | 6 +-
sections/tools/services/get_cc.php | 2 +-
sections/tools/services/get_host.php | 4 +-
sections/tools/tools.php | 4 +-
sections/top10/history.php | 8 +-
sections/top10/index.php | 4 +-
sections/top10/tags.php | 4 +-
sections/top10/torrents.php | 90 +-
sections/top10/users.php | 16 +-
sections/torrents/add_alias.php | 8 +-
sections/torrents/add_tag.php | 6 +-
sections/torrents/browse.php | 24 +-
sections/torrents/browse2.php | 120 +-
sections/torrents/delete.php | 4 +-
sections/torrents/delete_alias.php | 8 +-
sections/torrents/delete_tag.php | 2 +-
sections/torrents/details.php | 52 +-
sections/torrents/download.php | 16 +-
sections/torrents/downloadlist.php | 2 +-
sections/torrents/edit.php | 4 +-
sections/torrents/editgroup.php | 4 +-
sections/torrents/editgroupid.php | 20 +-
sections/torrents/functions.php | 2 +-
sections/torrents/grouplog.php | 10 +-
sections/torrents/history.php | 4 +-
sections/torrents/index.php | 6 +-
sections/torrents/manage_artists.php | 6 +-
sections/torrents/masspm.php | 4 +-
sections/torrents/merge.php | 16 +-
sections/torrents/nonwikiedit.php | 4 +-
sections/torrents/notify.php | 18 +-
sections/torrents/peerlist.php | 4 +-
sections/torrents/redownload.php | 14 +-
sections/torrents/rename.php | 6 +-
sections/torrents/reseed.php | 16 +-
sections/torrents/snatchlist.php | 2 +-
sections/torrents/take_warn.php | 8 +-
sections/torrents/takedelete.php | 10 +-
sections/torrents/takeedit.php | 8 +-
sections/torrents/takegroupedit.php | 2 +-
sections/torrents/takemasspm.php | 4 +-
sections/torrents/takenewgroup.php | 8 +-
sections/torrents/user.php | 66 +-
sections/torrents/warn.php | 8 +-
sections/upload/upload.php | 6 +-
sections/upload/upload_handle.php | 34 +-
sections/user/advancedsearch.php | 24 +-
sections/user/community_stats.php | 26 +-
sections/user/connchecker.php | 4 +-
sections/user/edit.php | 6 +-
sections/user/invite.php | 18 +-
sections/user/invitetree.php | 8 +-
sections/user/linkedfunctions.php | 12 +-
sections/user/notify_edit.php | 4 +-
sections/user/permissions.php | 10 +-
sections/user/search.php | 12 +-
sections/user/sessions.php | 8 +-
sections/user/takeedit.php | 16 +-
sections/user/takeinvite.php | 4 +-
sections/user/takemoderate.php | 60 +-
sections/user/user.php | 92 +-
sections/userhistory/email_history.php | 6 +-
sections/userhistory/email_history2.php | 36 +-
sections/userhistory/ip_history.php | 16 +-
sections/userhistory/ip_tracker_history.php | 10 +-
sections/userhistory/passkey_history.php | 6 +-
sections/userhistory/password_history.php | 6 +-
sections/userhistory/post_history.php | 14 +-
sections/userhistory/subscribed_collages.php | 22 +-
sections/userhistory/subscriptions.php | 12 +-
sections/userhistory/token_history.php | 22 +-
sections/wiki/aliases.php | 4 +-
sections/wiki/article.php | 12 +-
sections/wiki/compare.php | 4 +-
sections/wiki/create.php | 4 +-
sections/wiki/delete.php | 2 +-
sections/wiki/edit.php | 4 +-
sections/wiki/index.php | 2 +-
sections/wiki/link.php | 4 +-
sections/wiki/revisions.php | 8 +-
sections/wiki/search.php | 10 +-
sections/wiki/splash.php | 4 +-
sections/wiki/takecreate.php | 2 +-
sections/wiki/wiki_browse.php | 6 +-
285 files changed, 4358 insertions(+), 3865 deletions(-)
create mode 100644 classes/class_artists.php
create mode 100644 classes/class_format.php
create mode 100644 classes/class_misc.php
create mode 100644 classes/class_permissions.php
create mode 100644 classes/class_requests.php
create mode 100644 classes/class_tools.php
create mode 100644 classes/class_torrents.php
create mode 100644 classes/class_tracker.php
create mode 100644 classes/class_users.php
create mode 100644 classes/class_view.php
create mode 100644 classes/util.php
diff --git a/classes/ajax_start.php b/classes/ajax_start.php
index 2c6e0487..07e6de6e 100644
--- a/classes/ajax_start.php
+++ b/classes/ajax_start.php
@@ -13,11 +13,11 @@
if (isset($_COOKIE['session'])) { $LoginCookie=$Enc->decrypt($_COOKIE['session']); }
if(isset($LoginCookie)) {
list($SessionID, $UserID)=explode("|~|",$Enc->decrypt($LoginCookie));
-
+
if(!$UserID || !$SessionID) {
die('Not logged in!');
}
-
+
if(!$Enabled = $Cache->get_value('enabled_'.$UserID)){
require(SERVER_ROOT.'/classes/class_mysql.php'); //Require the database wrapper
$DB=NEW DB_MYSQL; //Load the database wrapper
diff --git a/classes/class_artist.php b/classes/class_artist.php
index 547ef9af..a31986bb 100644
--- a/classes/class_artist.php
+++ b/classes/class_artist.php
@@ -1,19 +1,3 @@
-class ARTIST {
- var $ID = 0;
- var $Name = 0;
- var $NameLength = 0;
- var $SimilarID = 0;
- var $Displayed = false;
- var $x = 0;
- var $y = 0;
- var $Similar = array();
-
- function ARTIST($ID='', $Name=''){
- $this->ID = $ID;
- $this->NameLength = mb_strlen($Name, 'utf8');
- $this->Name = display_str($Name);
- }
-
-}
+// Placeholder for if we ever decide to actaully have a model for an artist.
?>
diff --git a/classes/class_artists.php b/classes/class_artists.php
new file mode 100644
index 00000000..a04f7685
--- /dev/null
+++ b/classes/class_artists.php
@@ -0,0 +1,274 @@
+
+class Artists {
+ /**
+ * Given an array of GroupIDs, return their associated artists.
+ *
+ * @param array $GroupIDs
+ * @return an array of the following form:
+ * GroupID => {
+ * [ArtistType] => {
+ * id, name, aliasid
+ * }
+ * }
+ * ArtistType is an int. It can be:
+ * 1 => Main artist
+ * 2 => Guest artist
+ * 4 => Composer
+ * 5 => Conductor
+ * 6 => DJ
+ */
+ public static function get_artists($GroupIDs) {
+ global $Cache, $DB;
+ $Results = array();
+ $DBs = array();
+ foreach($GroupIDs as $GroupID) {
+ if(!is_number($GroupID)) {
+ continue;
+ }
+ $Artists = $Cache->get_value('groups_artists_'.$GroupID);
+ if(is_array($Artists)) {
+ $Results[$GroupID] = $Artists;
+ } else {
+ $DBs[] = $GroupID;
+ }
+ }
+ if(count($DBs) > 0) {
+ $IDs = implode(',', $DBs);
+ if(empty($IDs)) {
+ $IDs = "null";
+ }
+ $DB->query("SELECT ta.GroupID,
+ ta.ArtistID,
+ aa.Name,
+ ta.Importance,
+ ta.AliasID
+ FROM torrents_artists AS ta
+ JOIN artists_alias AS aa ON ta.AliasID = aa.AliasID
+ WHERE ta.GroupID IN ($IDs)
+ ORDER BY ta.GroupID ASC,
+ ta.Importance ASC,
+ aa.Name ASC;");
+ while(list($GroupID,$ArtistID,$ArtistName,$ArtistImportance,$AliasID) = $DB->next_record(MYSQLI_BOTH, false)) {
+ $Results[$GroupID][$ArtistImportance][] = array('id' => $ArtistID, 'name' => $ArtistName, 'aliasid' => $AliasID);
+ $New[$GroupID][$ArtistImportance][] = array('id' => $ArtistID, 'name' => $ArtistName, 'aliasid' => $AliasID);
+ }
+ foreach($DBs as $GroupID) {
+ if(isset($New[$GroupID])) {
+ $Cache->cache_value('groups_artists_'.$GroupID, $New[$GroupID]);
+ }
+ else {
+ $Cache->cache_value('groups_artists_'.$GroupID, array());
+ }
+ }
+ $Missing = array_diff($GroupIDs, array_keys($Results));
+ if(!empty($Missing)) {
+ $Results += array_fill_keys($Missing, array());
+ }
+ }
+ return $Results;
+ }
+
+
+ /**
+ * Convenience function for get_artists, when you just need one group.
+ *
+ * @param int $GroupID
+ * @return array - see get_artists
+ */
+ public static function get_artist($GroupID) {
+ $Results = Artists::get_artists(array($GroupID));
+ return $Results[$GroupID];
+ }
+
+
+ /**
+ * Format an array of artists for display.
+ * TODO: Revisit the logic of this, see if we can helper-function the copypasta.
+ *
+ * @param array Artists an array of the form output by get_artists
+ * @param boolean $MakeLink if true, the artists will be links, if false, they will be text.
+ * @param boolean $IncludeHyphen if true, appends " - " to the end.
+ * @param $Escape if true, output will be escaped. Think carefully before setting it false.
+ */
+ public static function display_artists($Artists, $MakeLink = true, $IncludeHyphen = true, $Escape = true) {
+ if(!empty($Artists)) {
+ $ampersand = ($Escape) ? ' & ' : ' & ';
+ $link = '';
+
+ $MainArtists = $Artists[1];
+ $Guests = $Artists[2];
+ $Composers = $Artists[4];
+ $Conductors = $Artists[5];
+ $DJs = $Artists[6];
+
+ if ((count($MainArtists) + count($Conductors) + count($DJs) == 0) && (count($Composers) == 0)) {
+ return '';
+ }
+
+ // Various Composers is not needed and is ugly and should die
+ switch(count($Composers)) {
+ case 0:
+ break;
+ case 1:
+ $link .= Artists::display_artist($Composers[0], $MakeLink, $Escape);
+ break;
+ case 2:
+ $link .= Artists::display_artist($Composers[0], $MakeLink, $Escape).$ampersand.Artists::display_artist($Composers[1], $MakeLink, $Escape);
+ break;
+ }
+
+ if ((count($Composers) > 0) && (count($Composers) < 3) && (count($MainArtists) > 0)) {
+ $link .= ' performed by ';
+ }
+
+ $ComposerStr .= $link;
+
+ switch(count($MainArtists)) {
+ case 0:
+ break;
+ case 1:
+ $link .= Artists::display_artist($MainArtists[0], $MakeLink, $Escape);
+ break;
+ case 2:
+ $link .= Artists::display_artist($MainArtists[0], $MakeLink, $Escape).$ampersand.Artists::display_artist($MainArtists[1], $MakeLink, $Escape);
+ break;
+ default:
+ $link .= 'Various Artists';
+ }
+
+ /*if(!empty($Guests) && (count($MainArtists) + count($Composers) > 0) && (count($MainArtists) + count($Composers) + count($Conductors) < 3)) {
+ switch(count($Guests)) {
+ case 1:
+ $link .= ' with '.Artists::display_artist($Guests[0], $MakeLink, $Escape);
+ break;
+ case 2:
+ $link .= ' with '.Artists::display_artist($Guests[0], $MakeLink, $Escape).$ampersand.Artists::display_artist($Guests[1], $MakeLink, $Escape);
+ break;
+ }
+ }*/
+
+ if ((count($Conductors) > 0) && (count($MainArtists) + count($Composers) > 0) && (count($Composers) < 3 || count($MainArtists) > 0)) {
+ $link .= ' under ';
+ }
+ switch(count($Conductors)) {
+ case 0:
+ break;
+ case 1:
+ $link .= Artists::display_artist($Conductors[0], $MakeLink, $Escape);
+ break;
+ case 2:
+ $link .= Artists::display_artist($Conductors[0], $MakeLink, $Escape).$ampersand.Artists::display_artist($Conductors[1], $MakeLink, $Escape);
+ break;
+ default:
+ $link .= ' Various Conductors';
+ }
+
+ if ((count($Composers) > 0) && (count($MainArtists) + count($Conductors) > 3) && (count($MainArtists) > 1) && (count($Conductors) > 1)) {
+ $link = $ComposerStr . 'Various Artists';
+ } elseif ((count($Composers) > 2) && (count($MainArtists) + count($Conductors) == 0)) {
+ $link = 'Various Composers';
+ }
+
+ // DJs override everything else
+ switch(count($DJs)) {
+ case 0:
+ break;
+ case 1:
+ $link = Artists::display_artist($DJs[0], $MakeLink, $Escape);
+ break;
+ case 2:
+ $link = Artists::display_artist($DJs[0], $MakeLink, $Escape).$ampersand.Artists::display_artist($DJs[1], $MakeLink, $Escape);
+ break;
+ default :
+ $link = 'Various DJs';
+ }
+
+ return $link.($IncludeHyphen?' - ':'');
+ } else {
+ return '';
+ }
+ }
+
+
+ /**
+ * Formats a single artist name.
+ *
+ * @param array $Artist an array of the form ('id'=>ID, 'name'=>Name)
+ * @param boolean $MakeLink If true, links to the artist page.
+ * @param boolean $Escape If false and $MakeLink is false, returns the unescaped, unadorned artist name.
+ * @return string Formatted artist name.
+ */
+ public static function display_artist($Artist, $MakeLink = true, $Escape = true) {
+ if ($MakeLink && !$Escape) {
+ error('Invalid parameters to Artists::display_artist()');
+ } elseif ($MakeLink) {
+ return ''.display_str($Artist['name']).' ';
+ } elseif ($Escape) {
+ return display_str($Artist['name']);
+ } else {
+ return $Artist['name'];
+ }
+ }
+
+ /**
+ * Deletes an artist and their requests, wiki, and tags.
+ * Does NOT delete their torrents.
+ *
+ * @param int $ArtistID
+ */
+ public static function delete_artist($ArtistID) {
+ global $DB, $LoggedUser, $Cache;
+
+ $DB->query("SELECT Name FROM artists_group WHERE ArtistID = ".$ArtistID);
+ list($Name) = $DB->next_record(MYSQLI_NUM, false);
+
+ // Delete requests
+ $DB->query("SELECT RequestID FROM requests_artists WHERE ArtistID=".$ArtistID." AND ArtistID != 0");
+ $Requests = $DB->to_array();
+ foreach($Requests AS $Request) {
+ list($RequestID) = $Request;
+ $DB->query('DELETE FROM requests WHERE ID='.$RequestID);
+ $DB->query('DELETE FROM requests_votes WHERE RequestID='.$RequestID);
+ $DB->query('DELETE FROM requests_tags WHERE RequestID='.$RequestID);
+ $DB->query('DELETE FROM requests_artists WHERE RequestID='.$RequestID);
+ }
+
+ // Delete artist
+ $DB->query('DELETE FROM artists_group WHERE ArtistID='.$ArtistID);
+ $DB->query('DELETE FROM artists_alias WHERE ArtistID='.$ArtistID);
+ $Cache->decrement('stats_artist_count');
+
+ // Delete wiki revisions
+ $DB->query('DELETE FROM wiki_artists WHERE PageID='.$ArtistID);
+
+ // Delete tags
+ $DB->query('DELETE FROM artists_tags WHERE ArtistID='.$ArtistID);
+
+ $Cache->delete_value('artist_'.$ArtistID);
+ // Record in log
+
+ if(!empty($LoggedUser['Username'])) {
+ $Username = $LoggedUser['Username'];
+ } else {
+ $Username = 'System';
+ }
+ Misc::write_log('Artist '.$ArtistID.' ('.$Name.') was deleted by '.$Username);
+ }
+
+
+ /**
+ * Remove LRM (left-right-marker) and trims, because people copypaste carelessly.
+ * If we don't do this, we get seemingly duplicate artist names.
+ * TODO: make stricter, e.g. on all whitespace characters or Unicode normalisation
+ *
+ * @param string $ArtistName
+ */
+ public static function normalise_artist_name($ArtistName) {
+ // \u200e is
+ $ArtistName = trim($ArtistName);
+ $ArtistName = preg_replace('/^(\xE2\x80\x8E)+/', '', $ArtistName);
+ $ArtistName = preg_replace('/(\xE2\x80\x8E)+$/', '', $ArtistName);
+ return trim(preg_replace('/ +/', ' ', $ArtistName));
+ }
+}
+?>
diff --git a/classes/class_artists_similar.php b/classes/class_artists_similar.php
index f5464847..aa2c5a9a 100644
--- a/classes/class_artists_similar.php
+++ b/classes/class_artists_similar.php
@@ -1,35 +1,52 @@
+class ARTIST {
+ var $ID = 0;
+ var $Name = 0;
+ var $NameLength = 0;
+ var $SimilarID = 0;
+ var $Displayed = false;
+ var $x = 0;
+ var $y = 0;
+ var $Similar = array();
+
+ function ARTIST($ID='', $Name=''){
+ $this->ID = $ID;
+ $this->NameLength = mb_strlen($Name, 'utf8');
+ $this->Name = display_str($Name);
+ }
+}
+
class ARTISTS_SIMILAR extends ARTIST{
var $Artists = array();
var $TotalScore = 0;
-
+
var $xValues = array(WIDTH=>1);
var $yValues = array(HEIGHT=>1);
-
+
var $LargestDecimal = 0;
var $LowestDecimal = 1;
-
-
-
+
+
+
function dump_data(){
return serialize(array(time(), $this->Name, $this->x, $this->y, serialize($this->Artists), serialize($this->Similar)));
}
-
+
function load_data($Data){
list($LastUpdated, $this->Name, $this->x, $this->y, $this->Artists, $this->Similar) = unserialize($Data);
$this->Artists = unserialize($this->Artists);
$this->Similar = unserialize($this->Similar);
}
-
+
function set_up(){
$this->x = ceil(WIDTH/2);
$this->y = ceil(HEIGHT/2);
-
+
$this->xValues[$this->x] = $this->ID;
$this->yValues[$this->y] = $this->ID;
-
+
global $DB;
-
+
// Get artists that are directly similar to the artist
$ArtistIDs = array();
$DB->query("
@@ -44,11 +61,11 @@ function set_up(){
WHERE s1.ArtistID=".$this->ID."
ORDER BY ass.Score DESC
LIMIT 14");
-
+
if($DB->record_count() == 0){
return;
}
-
+
// Build into array. Each artist is its own object in $this->Artists
while(list($ArtistID, $Name, $Score) = $DB->next_record(MYSQLI_NUM, false)){
if($Score<0){
@@ -59,7 +76,7 @@ function set_up(){
$this->TotalScore+=$Score;
$ArtistIDs[]=$ArtistID;
}
-
+
// Get similarities between artists on the map
$DB->query("SELECT
s1.ArtistID,
@@ -71,17 +88,17 @@ function set_up(){
WHERE s1.ArtistID IN(".implode(',',$ArtistIDs).")
AND s2.ArtistID IN(".implode(',',$ArtistIDs).")
");
-
+
// Build into array
while(list($Artist1ID, $Artist2ID) = $DB->next_record()){
$this->Artists[$Artist1ID]->Similar[$Artist2ID] = array('ID'=>$Artist2ID);
}
-
+
// Calculate decimal point scores between artists
foreach($this->Similar as $SimilarArtist) {
list($ArtistID, $Similar) = array_values($SimilarArtist);
$this->Similar[$ArtistID]['Decimal'] = $this->similarity($Similar['Score'], $this->TotalScore);
-
+
if($this->Similar[$ArtistID]['Decimal'] < $this->LowestDecimal){
$this->LowestDecimal = $this->Similar[$ArtistID]['Decimal'];
}
@@ -91,28 +108,28 @@ function set_up(){
}
reset($this->Artists);
}
-
+
function set_positions(){
$xValues = array(); // Possible x values
$Root = ceil(WIDTH/4); // Half-way into half of the image
$Offset = 4; // Distance from the root (a quarter of the way into the image) to the x value
-
+
// The number of artists placed in the top or the bottom
$NumTop = 0;
$NumBottom = 0;
-
+
// The number of artists placed in the left or the right
$NumLeft = 0;
$NumRight = 0;
-
+
$Multiplier = 0;
-
+
// Build up an impressive list of possible x values
// We later iterate through these, and pick out the ones we want
-
+
// These x values are all below WIDTH/2 (all on the left)
// The script later chooses which side to put them on
-
+
// We create more very low x values because they're more likely to be skipped
for($i = 0; $i<=count($this->Artists)*4; $i++){
if($Offset>=((WIDTH/4))){
@@ -120,20 +137,20 @@ function set_positions(){
}
$Plus = $Root+$Offset; // Point on the right of the root
$Minus = abs($Root-$Offset); // Point on the left of the root
-
+
$xValues[$Plus]=$Plus;
-
+
$xValues[$Minus]=$Minus;
-
+
// Throw in an extra x value closer to the edge, because they're more likely to be skipped
-
+
if($Minus>30){
// $xValues[$Minus-30]=$Minus-30;
}
-
+
$Offset = $Offset+rand(5,20); // Increase offset, and go again
}
-
+
foreach($this->Artists as $Artist){
$ArtistID = $Artist->ID;
if($Artist->Displayed == true){
@@ -142,14 +159,14 @@ function set_positions(){
$this->Similar[$ArtistID]['Decimal'] = $this->Similar[$ArtistID]['Decimal'] * (1/($this->LargestDecimal))-0.1;
// Calculate the distance away from the center, based on similarity
$IdealDistance = $this->calculate_distance($this->Similar[$ArtistID]['Decimal'], $this->x, $this->y);
-
+
$this->Similar[$ArtistID]['Distance'] = $IdealDistance;
-
+
// 1 = left, 2 = right
$Horizontal = 0;
$Vertical = 0;
-
- // See if any similar artists have been placed yet. If so, place artist in that half
+
+ // See if any similar artists have been placed yet. If so, place artist in that half
// (provided that there are enough in the other half to visually balance out)
reset($Artist->Similar);
foreach($Artist->Similar as $SimilarArtist) {
@@ -163,17 +180,17 @@ function set_positions(){
break;
}
}
-
+
shuffle($xValues);
-
+
while($xValue = array_shift($xValues)){
if(abs($this->x - $xValue) <= $IdealDistance) {
- if(hypot(abs($this->x - $xValue), ($this->y - 50)) > $IdealDistance
+ if(hypot(abs($this->x - $xValue), ($this->y - 50)) > $IdealDistance
|| ceil(sqrt(pow($IdealDistance, 2) - pow($this->x - $xValue, 2))) > (HEIGHT/2)){
$xValue = $this->x - ceil(sqrt(pow($IdealDistance, 2) - pow($IdealDistance*0.1*rand(5,9), 2)));
//echo "Had to change x value for ".$Artist->Name." to ".$xValue."\n";
}
- // Found a match (Is close enough to the center to satisfy $IdealDistance),
+ // Found a match (Is close enough to the center to satisfy $IdealDistance),
// Now it's time to choose which half to put it on
if(!$Horizontal) {
// No similar artists displayed
@@ -185,11 +202,11 @@ function set_positions(){
} else {
$NumLeft++;
}
-
+
$Artist->x = $xValue;
$this->xValues[$xValue] = $ArtistID;
unset($xValues[$xValue]);
-
+
break;
}
}
@@ -200,14 +217,14 @@ function set_positions(){
$this->xValues[$xValue] = $ArtistID;
unset($xValues[$xValue]);
}
-
-
+
+
// Pythagoras. $yValue is the vertical distance from the center to the y value
$yValue = sqrt(pow($IdealDistance, 2) - pow(abs($this->x - $Artist->x), 2));
-
-
+
+
// Now we pick if it should go on the top or bottom
-
+
if($NumTop>$NumBottom){ // Send it to the bottom half
$yValue=(HEIGHT/2)+$yValue;
$NumBottom++;
@@ -215,20 +232,20 @@ function set_positions(){
$yValue=(HEIGHT/2)-$yValue;
$NumTop++;
}
-
+
$yValue = ceil($yValue);
-
+
// $yValue is now a proper y coordinate
// Now time to do some spacing out
-
+
if($yValue < 10){
$yValue+=(10+abs($yValue))+rand(10,20);
}
-
+
if($yValue > (HEIGHT - 10)){
$yValue-=((HEIGHT/2)-rand(10,20));
}
-
+
$i = 1;
while($Conflict = $this->scan_array_range($this->yValues, abs($yValue-13), $yValue+13)) {
if($i > 10){
@@ -237,7 +254,7 @@ function set_positions(){
if(!$this->scan_array_range($this->yValues, abs($yValue-5), $yValue-20)){
$yValue -= 20;
}
-
+
$yValue=$Conflict + rand(10, 20);
if($yValue>HEIGHT-10){
$yValue-=ceil(HEIGHT/2.5);
@@ -246,16 +263,16 @@ function set_positions(){
}
$i++;
}
-
+
$Artist->y = $yValue;
$this->yValues[$yValue] = $ArtistID;
}
reset($this->Artists);
reset($this->xValues);
reset($this->yValues);
-
+
}
-
+
// Calculate the ideal distance from the center point ($Rootx, $Rooty) to the artist's point on the board
// Pythagoras as fun!
function calculate_distance($SimilarityCoefficient, $Rootx, $Rooty){
@@ -265,13 +282,13 @@ function calculate_distance($SimilarityCoefficient, $Rootx, $Rooty){
$y = $MaxHeight - ($SimilarityCoefficient*$MaxHeight); // Possible y value
$Hypot = hypot($Rootx - $x, $Rooty - $y);
return $MaxWidth - $Hypot;
-
+
}
-
+
function similarity($Score, $TotalArtistScore){
return (pow(($Score/($TotalArtistScore+1)), (1/1)));
}
-
+
function scan_array_range($Array, $Start, $Finish){
if($Start<0){
die($Start);
@@ -283,15 +300,15 @@ function scan_array_range($Array, $Start, $Finish){
}
return false;
}
-
+
function write_artists(){
?>
-
-
+
+
foreach($this->Artists as $Artist){
if($Artist->ID == $this->ID){
continue;
@@ -303,7 +320,7 @@ function write_artists(){
}
$Decimal = $this->Similar[$Artist->ID]['Decimal'];
-
+
if($Decimal<0.2){
$FontSize = 8;
} elseif($Decimal<0.3){
@@ -321,7 +338,7 @@ function write_artists(){
}
reset($this->Artists);
}
-
+
function background_image(){
global $Img;
reset($this->Similar);
@@ -330,9 +347,9 @@ function background_image(){
$Artist = $this->Artists[$ArtistID];
$Decimal = $this->Similar[$ArtistID]['Decimal'];
$Width = ceil($Decimal*4)+1;
-
+
$Img->line($this->x, $this->y, $Artist->x, $Artist->y,$Img->color(199,218,255), $Width);
-
+
unset($Artist->Similar[$this->ID]);
reset($Artist->Similar);
foreach($Artist->Similar as $SimilarArtist2) {
@@ -345,10 +362,10 @@ function background_image(){
}
reset($this->xValues);
}
-
+
$Img->make_png(SERVER_ROOT.'/static/similar/'.$this->ID.'.png');
}
-
+
function dump(){
echo "Similarities:\n";
foreach($this->Artists as $Artist){
@@ -362,10 +379,10 @@ function dump(){
//print_r($Artist->Similar);
echo "\n\n---\n\n";
}
-
+
}
-
-
+
+
}
diff --git a/classes/class_cache.php b/classes/class_cache.php
index d3bc5a21..aae3b8cb 100644
--- a/classes/class_cache.php
+++ b/classes/class_cache.php
@@ -40,7 +40,7 @@ class CACHE extends Memcache {
'top10tor_*',
'query_lock_*'
);
-
+
public $CanClear = false;
public $InternalCache = true;
@@ -72,6 +72,14 @@ public function cache_value($Key, $Value, $Duration=2592000) {
$this->Time+=(microtime(true)-$StartTime)*1000;
}
+ // Wrapper for Memcache::add, with the zlib option removed and default duration of 30 days
+ public function add_value($Key, $Value, $Duration=2592000) {
+ $StartTime=microtime(true);
+ $Added=$this->add($Key, $Value, 0, $Duration);
+ $this->Time+=(microtime(true)-$StartTime)*1000;
+ return $Added;
+ }
+
public function replace_value($Key, $Value, $Duration=2592000) {
$StartTime=microtime(true);
$this->replace($Key, $Value, false, $Duration);
@@ -87,13 +95,13 @@ public function get_value($Key, $NoCache=false) {
trigger_error("Cache retrieval failed for empty key");
}
- if (isset($_GET['clearcache']) && $this->CanClear && !in_array_partial($Key, $this->PersistentKeys)) {
+ if (isset($_GET['clearcache']) && $this->CanClear && !Misc::in_array_partial($Key, $this->PersistentKeys)) {
if ($_GET['clearcache'] == 1) {
//Because check_perms isn't true until loggeduser is pulled from the cache, we have to remove the entries loaded before the loggeduser data
//Because of this, not user cache data will require a secondary pageload following the clearcache to update
if (count($this->CacheHits) > 0) {
foreach (array_keys($this->CacheHits) as $HitKey) {
- if (!in_array_partial($HitKey, $this->PersistentKeys)) {
+ if (!Misc::in_array_partial($HitKey, $this->PersistentKeys)) {
$this->delete($HitKey);
unset($this->CacheHits[$HitKey]);
}
@@ -308,23 +316,22 @@ public function update($Key, $Rows, $Values, $Time=2592000) {
}
- // Built-in increment/decrement functions are said not to be thread safe
-/* Supposedly fixed in v1.4.6
- public function increment($Key, $Value=1) {
- if(($OldValue = $this->get($Key)) === false || !is_number($Value)) {
- return false;
- }
- $this->replace_value($Key, $OldValue+$Value);
+ /**
+ * Tries to set a lock. Expiry time is one hour to avoid indefinite locks
+ *
+ * @param string $LockName name on the lock
+ * @return true if lock was acquired
+ */
+ public function get_query_lock($LockName) {
+ return $this->add_value('query_lock_'.$LockName, 1, 3600);
}
- public function decrement($Key, $Value=1) {
- if(($OldValue = $this->get($Key)) === false || !is_number($Value) || !is_number($OldValue)) {
- return false;
- }
- if($Value > $OldValue) {
- $OldValue = $Value = 0;
- }
- $this->replace_value($Key, $OldValue-$Value);
+ /**
+ * Remove lock
+ *
+ * @param string $LockName name on the lock
+ */
+ public function clear_query_lock($LockName) {
+ $this->delete_value('query_lock_'.$LockName);
}
-*/
}
diff --git a/classes/class_charts.php b/classes/class_charts.php
index dfb4b690..683f1532 100644
--- a/classes/class_charts.php
+++ b/classes/class_charts.php
@@ -171,7 +171,7 @@ public function __construct () {
public function add($Label, $Data) {
if ($Label !== false) {
- $this->Labels[] = cut_string($Label,35);
+ $this->Labels[] = Format::cut_string($Label,35);
}
$this->Data[] = $Data;
}
diff --git a/classes/class_debug.php b/classes/class_debug.php
index be630bad..e0ae41d3 100644
--- a/classes/class_debug.php
+++ b/classes/class_debug.php
@@ -36,7 +36,7 @@ public function profile($Automatic='') {
*/
$Ram = memory_get_usage(true);
if ($Ram > MAX_MEMORY && !defined('MEMORY_EXCEPTION')) {
- $Reason[] = get_size($Ram).' Ram Used';
+ $Reason[] = Format::get_size($Ram).' Ram Used';
}
if (isset($_REQUEST['profile'])) {
@@ -57,7 +57,7 @@ public function analysis($Message, $Report='', $Time=43200) {
if (empty($Report)) {
$Report = $Message;
}
- $Identifier = make_secret(5);
+ $Identifier = Users::make_secret(5);
$Cache->cache_value(
'analysis_'.$Identifier,
array(
@@ -245,14 +245,14 @@ public function get_sphinx_time() {
}
public function get_sphinxql_queries() {
- if(class_exists(SPHINXQL)) {
- return SPHINXQL::$Queries;
+ if(class_exists(SphinxQL)) {
+ return SphinxQL::$Queries;
}
}
public function get_sphinxql_time() {
- if(class_exists(SPHINXQL)) {
- return SPHINXQL::$Time;
+ if(class_exists(SphinxQL)) {
+ return SphinxQL::$Time;
}
}
@@ -354,7 +354,7 @@ public function flag_table($Flags=false) {
=$Event?>
=$MicroTime?> ms
- =get_size($Memory)?>
+ =Format::get_size($Memory)?>
}
diff --git a/classes/class_format.php b/classes/class_format.php
new file mode 100644
index 00000000..a1b6c9df
--- /dev/null
+++ b/classes/class_format.php
@@ -0,0 +1,396 @@
+
+class Format {
+ /**
+ * Shorten a string
+ *
+ * @param $Str string to cut
+ * @param $Length cut at length
+ * @param $Hard force cut at length instead of at closest word
+ * @param $ShowDots Show dots at the end
+ * @return string formatted string
+ */
+ public static function cut_string($Str, $Length, $Hard = false, $ShowDots = true) {
+ if (mb_strlen($Str, 'UTF-8') > $Length) {
+ if ($Hard == 0) {
+ // Not hard, cut at closest word
+ $CutDesc = mb_substr($Str, 0, $Length, 'UTF-8');
+ $DescArr = explode(' ', $CutDesc);
+ if (count($DescArr) > 1) {
+ array_pop($DescArr);
+ $CutDesc = implode(' ', $DescArr);
+ }
+ if ($ShowDots) { $CutDesc .= '...'; }
+ } else {
+ $CutDesc = mb_substr($Str, 0, $Length, 'UTF-8');
+ if ($ShowDots) { $CutDesc .= '...'; }
+ }
+ return $CutDesc;
+ } else {
+ return $Str;
+ }
+ }
+
+
+ /**
+ * Gets the CSS class corresponding to a ratio
+ *
+ * @param $Ratio ratio to get the css class for
+ * @return string the CSS class corresponding to the ratio range
+ */
+ public static function get_ratio_color($Ratio) {
+ if ($Ratio < 0.1) { return 'r00'; }
+ if ($Ratio < 0.2) { return 'r01'; }
+ if ($Ratio < 0.3) { return 'r02'; }
+ if ($Ratio < 0.4) { return 'r03'; }
+ if ($Ratio < 0.5) { return 'r04'; }
+ if ($Ratio < 0.6) { return 'r05'; }
+ if ($Ratio < 0.7) { return 'r06'; }
+ if ($Ratio < 0.8) { return 'r07'; }
+ if ($Ratio < 0.9) { return 'r08'; }
+ if ($Ratio < 1) { return 'r09'; }
+ if ($Ratio < 2) { return 'r10'; }
+ if ($Ratio < 5) { return 'r20'; }
+ return 'r50';
+ }
+
+
+ /**
+ * Calculates and formats a ratio.
+ *
+ * @param int $Dividend AKA numerator
+ * @param int $Divisor
+ * @param boolean $Color if true, ratio will be coloured.
+ * @return formatted ratio HTML
+ */
+ public static function get_ratio_html($Dividend, $Divisor, $Color = true) {
+ if ($Divisor == 0 && $Dividend == 0) {
+ return '--';
+ } elseif ($Divisor == 0) {
+ return '∞ ';
+ }
+ $Ratio = number_format(max($Dividend/$Divisor-0.005,0), 2); //Subtract .005 to floor to 2 decimals
+ if ($Color) {
+ $Class = Format::get_ratio_color($Ratio);
+ if ($Class) {
+ $Ratio = ''.$Ratio.' ';
+ }
+ }
+ return $Ratio;
+ }
+
+
+ /**
+ * Gets the query string of the current page, minus the parameters in $Exclude
+ *
+ * @param array $Exclude Query string parameters to leave out, or blank to include all parameters.
+ * @return An HTML sanatized query string
+ */
+ public static function get_url($Exclude = false) {
+ if ($Exclude !== false) {
+ $QueryItems = array();
+ parse_str($_SERVER['QUERY_STRING'], $QueryItems);
+
+ foreach ($QueryItems AS $Key => $Val) {
+ if (!in_array(strtolower($Key),$Exclude)) {
+ $Query[$Key] = $Val;
+ }
+ }
+ if (empty($Query)) {
+ return;
+ }
+ return display_str(http_build_query($Query));
+ } else {
+ return display_str($_SERVER['QUERY_STRING']);
+ }
+ }
+
+
+ /**
+ * Finds what page we're on and gives it to us, as well as the LIMIT clause for SQL
+ * Takes in $_GET['page'] as an additional input
+ *
+ * @param $PerPage Results to show per page
+ * @param $DefaultResult Optional, which result's page we want if no page is specified
+ * If this parameter is not specified, we will default to page 1
+ *
+ * @return array(int,string) What page we are on, and what to use in the LIMIT section of a query
+ * i.e. "SELECT [...] LIMIT $Limit;"
+ */
+ public static function page_limit($PerPage, $DefaultResult = 1) {
+ if (!isset($_GET['page'])) {
+ $Page = ceil($DefaultResult/$PerPage);
+ if ($Page == 0) $Page = 1;
+ $Limit=$PerPage;
+ } else {
+ if (!is_number($_GET['page'])) {
+ error(0);
+ }
+ $Page = $_GET['page'];
+ if ($Page <= 0) { $Page = 1; }
+ $Limit=$PerPage*$Page-$PerPage . ', ' . $PerPage;
+ }
+ return array($Page,$Limit);
+ }
+
+ // A9 magic. Some other poor soul can write the phpdoc.
+ // For data stored in memcached catalogues (giant arrays), eg. forum threads
+ public static function catalogue_limit($Page, $PerPage, $CatalogueSize=500) {
+ $CatalogueID = floor(($PerPage*$Page-$PerPage)/$CatalogueSize);;
+ $CatalogueLimit = ($CatalogueID*$CatalogueSize).', '.$CatalogueSize;
+ return array($CatalogueID, $CatalogueLimit);
+ }
+
+ public static function catalogue_select($Catalogue, $Page, $PerPage, $CatalogueSize=500) {
+ return array_slice($Catalogue,(($PerPage*$Page-$PerPage)%$CatalogueSize),$PerPage,true);
+ }
+
+
+ /* Get pages
+ * Returns a page list, given certain information about the pages.
+ *
+ * @param int $StartPage: The current record the page you're on starts with.
+ * eg. if you're on page 2 of a forum thread with 25 posts per page, $StartPage is 25.
+ * If you're on page 1, $StartPage is 0.
+ * @param int $TotalRecords: The total number of records in the result set.
+ * eg. if you're on a forum thread with 152 posts, $TotalRecords is 152.
+ * @param int $ItemsPerPage: Self-explanatory. The number of records shown on each page
+ * eg. if there are 25 posts per forum page, $ItemsPerPage is 25.
+ * @param int $ShowPages: The number of page links that are shown.
+ * eg. If there are 20 pages that exist, but $ShowPages is only 11, only 11 links will be shown.
+ * @param string $Anchor A URL fragment to attach to the links.
+ * eg. '#comment12'
+ * @return A sanitized HTML page listing.
+ */
+ public static function get_pages($StartPage,$TotalRecords,$ItemsPerPage,$ShowPages=11,$Anchor='') {
+ global $Document, $Method, $Mobile;
+ $Location = $Document.'.php';
+ $StartPage = ceil($StartPage);
+ $TotalPages = 0;
+ if ($TotalRecords > 0) {
+ $StartPage = min($StartPage, ceil($TotalRecords/$ItemsPerPage));
+
+ $ShowPages--;
+ $TotalPages = ceil($TotalRecords/$ItemsPerPage);
+
+ if ($TotalPages > $ShowPages) {
+ $StartPosition = $StartPage-round($ShowPages/2);
+
+ if ($StartPosition <= 0) {
+ $StartPosition = 1;
+ } else {
+ if ($StartPosition >= ($TotalPages-$ShowPages)) {
+ $StartPosition = $TotalPages-$ShowPages;
+ }
+ }
+
+ $StopPage = $ShowPages+$StartPosition;
+
+ } else {
+ $StopPage = $TotalPages;
+ $StartPosition = 1;
+ }
+
+ $StartPosition = max($StartPosition, 1);
+
+ $QueryString = Format::get_url(array('page','post'));
+ if ($QueryString != '') {
+ $QueryString = '&'.$QueryString;
+ }
+
+ $Pages = '';
+
+ if ($StartPage > 1) {
+ $Pages .= '<< First ';
+ $Pages .= ' | ';
+ }
+ //End change
+
+ if (!$Mobile) {
+ for ($i = $StartPosition; $i <= $StopPage; $i++) {
+ if ($i != $StartPage) {
+ $Pages .= '';
+ }
+ $Pages .= "";
+ if ($i*$ItemsPerPage > $TotalRecords) {
+ $Pages .= ((($i-1)*$ItemsPerPage)+1).'-'.($TotalRecords);
+ } else {
+ $Pages .= ((($i-1)*$ItemsPerPage)+1).'-'.($i*$ItemsPerPage);
+ }
+
+ $Pages .= " ";
+ if ($i != $StartPage) {
+ $Pages.=' ';
+ }
+ if ($i < $StopPage) {
+ $Pages.=" | ";
+ }
+ }
+ } else {
+ $Pages .= $StartPage;
+ }
+
+ if ($StartPage && $StartPage < $TotalPages) {
+ $Pages .= ' | ';
+ $Pages .= ' Last >> ';
+ }
+ }
+ if ($TotalPages > 1) {
+ return $Pages;
+ }
+ }
+
+
+ /**
+ * Format a size in bytes as a human readable string in KiB/MiB/...
+ *
+ * @param int $Size
+ * @param int $Levels Number of decimal places. Defaults to 2, unless the size >= 1TB, in which case it defaults to 4.
+ * @return string formatted number.
+ */
+ public static function get_size($Size, $Levels = 2) {
+ $Units = array(' B',' KB',' MB',' GB',' TB',' PB',' EB',' ZB',' YB');
+ $Size = (double) $Size;
+ for($Steps = 0; abs($Size) >= 1024; $Size /= 1024, $Steps++) {}
+ if (func_num_args() == 1 && $Steps >= 4) {
+ $Levels++;
+ }
+ return number_format($Size,$Levels) . $Units[$Steps];
+ }
+
+
+ /**
+ * Format a number as a multiple of its highest power of 1000 (eg. 10035 -> '10.04k')
+ *
+ * @param int $Number
+ * @return string formatted number.
+ */
+ public static function human_format($Number) {
+ $Steps = 0;
+ while($Number>=1000) {
+ $Steps++;
+ $Number=$Number/1000;
+ }
+ switch ($Steps) {
+ case 0: return round($Number); break;
+ case 1: return round($Number,2).'k'; break;
+ case 2: return round($Number,2).'M'; break;
+ case 3: return round($Number,2).'G'; break;
+ case 4: return round($Number,2).'T'; break;
+ case 5: return round($Number,2).'P'; break;
+ default:
+ return round($Number,2).'E + '.$Steps*3;
+ }
+ }
+
+
+ /**
+ * Given a formatted string of a size, get the number of bytes it represents.
+ *
+ * @param string $Size formatted size string, eg. 123.45k
+ * @return Number of bytes it represents, eg. (123.45 * 1024)
+ */
+ public static function get_bytes($Size) {
+ list($Value,$Unit) = sscanf($Size, "%f%s");
+ $Unit = ltrim($Unit);
+ if (empty($Unit)) {
+ return $Value ? round($Value) : 0;
+ }
+ switch(strtolower($Unit[0])) {
+ case 'k': return round($Value * 1024);
+ case 'm': return round($Value * 1048576);
+ case 'g': return round($Value * 1073741824);
+ case 't': return round($Value * 1099511627776);
+ default: return 0;
+ }
+ }
+
+
+ /**
+ * Reverse the effects of display_str - un-sanitize HTML.
+ * Use sparingly.
+ *
+ * @param string $Str the string to unsanitize
+ * @return unsanitized string
+ */
+ // Use sparingly
+ public static function undisplay_str($Str) {
+ return mb_convert_encoding($Str, 'UTF-8', 'HTML-ENTITIES');
+ }
+
+
+ /**
+ * Echo data sent in a GET form field, useful for text areas.
+ *
+ * @param string $Index the name of the form field
+ * @param boolean $Return if set to true, value is returned instead of echoed.
+ * @return Sanitized value of field index if $Return == true
+ */
+ public static function form($Index, $Return = false) {
+ if (!empty($_GET[$Index])) {
+ if ($Return) {
+ return display_str($_GET[$Index]);
+ } else {
+ echo display_str($_GET[$Index]);
+ }
+ }
+ }
+
+
+ /**
+ * Convenience function to echo out selected='selected' and checked='checked' so you don't have to.
+ *
+ * @param $Name the name of the option in the select (or field in $Array)
+ * @param $Value the value that the option must be for the option to be marked as selected or checked
+ * @param $Attribute The value returned/echoed is $Attribute="$Attribute"
+ * @param $Array The array the option is in, defaults to GET.
+ * @return
+ */
+ public static function selected($Name, $Value, $Attribute='selected', $Array = array()) {
+ if (empty($Array)) {
+ $Array == $_GET;
+ }
+ if (isset($Array[$Name]) && $Array[$Name]!=='') {
+ if ($Array[$Name] == $Value) {
+ echo ' '.$Attribute.'="'.$Attribute.'"';
+ }
+ }
+ }
+
+ /**
+ * Detect the encoding of a string and transform it to UTF-8.
+ *
+ * @param string $Str
+ * @return UTF-8 encoded version of $Str
+ */
+ public static function make_utf8($Str) {
+ if ($Str!="") {
+ if (Format::is_utf8($Str)) { $Encoding="UTF-8"; }
+ if (empty($Encoding)) { $Encoding=mb_detect_encoding($Str,'UTF-8, ISO-8859-1'); }
+ if (empty($Encoding)) { $Encoding="ISO-8859-1"; }
+ if ($Encoding=="UTF-8") { return $Str; }
+ else { return @mb_convert_encoding($Str,"UTF-8",$Encoding); }
+ }
+ }
+
+ /**
+ * Magical function.
+ *
+ * @param string $Str function to detect encoding on.
+ * @return true if the string is in UTF-8.
+ */
+ public static function is_utf8($Str) {
+ return preg_match('%^(?:
+ [\x09\x0A\x0D\x20-\x7E] // ASCII
+ | [\xC2-\xDF][\x80-\xBF] // non-overlong 2-byte
+ | \xE0[\xA0-\xBF][\x80-\xBF] // excluding overlongs
+ | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} // straight 3-byte
+ | \xED[\x80-\x9F][\x80-\xBF] // excluding surrogates
+ | \xF0[\x90-\xBF][\x80-\xBF]{2} // planes 1-3
+ | [\xF1-\xF3][\x80-\xBF]{3} // planes 4-15
+ | \xF4[\x80-\x8F][\x80-\xBF]{2} // plane 16
+ )*$%xs', $Str
+ );
+ }
+
+}
+?>
diff --git a/classes/class_invite_tree.php b/classes/class_invite_tree.php
index 26a96c40..d2b005dc 100644
--- a/classes/class_invite_tree.php
+++ b/classes/class_invite_tree.php
@@ -118,15 +118,15 @@ function make_tree(){
echo "";
}
?>
- =format_username($ID, true, true, $Enabled != 2 ? false : true, true)?>
+ =Users::format_username($ID, true, true, $Enabled != 2 ? false : true, true)?>
if(check_paranoia(array('uploaded', 'downloaded'), $Paranoia, $UserClass)) {
$TotalUpload += $Uploaded;
$TotalDownload += $Downloaded;
?>
- Uploaded: =get_size($Uploaded)?>
- Downloaded: =get_size($Downloaded)?>
- Ratio: =ratio($Uploaded, $Downloaded)?>
+ Uploaded: =Format::get_size($Uploaded)?>
+ Downloaded: =Format::get_size($Downloaded)?>
+ Ratio: =Format::get_ratio_html($Uploaded, $Downloaded)?>
} else {
$ParanoidCount++;
@@ -152,7 +152,7 @@ function make_tree(){
$ClassStrings = array();
foreach ($ClassSummary as $ClassID => $ClassCount) {
if($ClassCount == 0) { continue; }
- $LastClass = make_class_string($ClassID);
+ $LastClass = Users::make_class_string($ClassID);
if($ClassCount>1) {
if($LastClass == "Torrent Celebrity") {
$LastClass = 'Torrent Celebrities';
@@ -186,15 +186,15 @@ function make_tree(){
echo '.
';
echo '';
- echo 'The total amount uploaded by the entire tree was '.get_size($TotalUpload);
- echo '; the total amount downloaded was '.get_size($TotalDownload);
- echo '; and the total ratio is '.ratio($TotalUpload, $TotalDownload).'. ';
+ echo 'The total amount uploaded by the entire tree was '.Format::get_size($TotalUpload);
+ echo '; the total amount downloaded was '.Format::get_size($TotalDownload);
+ echo '; and the total ratio is '.Format::get_ratio_html($TotalUpload, $TotalDownload).'. ';
echo '
';
echo '';
- echo 'The total amount uploaded by direct invitees (the top level) was '.get_size($TopLevelUpload);
- echo '; the total amount downloaded was '.get_size($TopLevelDownload);
- echo '; and the total ratio is '.ratio($TopLevelUpload, $TopLevelDownload).'. ';
+ echo 'The total amount uploaded by direct invitees (the top level) was '.Format::get_size($TopLevelUpload);
+ echo '; the total amount downloaded was '.Format::get_size($TopLevelDownload);
+ echo '; and the total ratio is '.Format::get_ratio_html($TopLevelUpload, $TopLevelDownload).'. ';
echo 'These numbers include the stats of paranoid users, and will be factored in to the invitation giving script.
';
diff --git a/classes/class_irc.php b/classes/class_irc.php
index da036162..4046dd51 100644
--- a/classes/class_irc.php
+++ b/classes/class_irc.php
@@ -9,7 +9,7 @@ function halt($Msg) {
abstract class IRC_BOT {
abstract protected function connect_events();
abstract protected function channel_events();
- abstract protected function query_events();
+ abstract protected function query_events();
abstract protected function listener_events();
protected $Debug = false;
@@ -92,7 +92,7 @@ protected function get_message() {
return trim($Msg[1]);
}
- protected function get_host() {
+ protected function get_irc_host() {
preg_match('/:[^!:]+!.+@([^\s]+) PRIVMSG [^:]+ :.+/', $this->Data, $Host);
return trim($Host[1]);
}
@@ -126,10 +126,10 @@ protected function whois($Nick) {
$this->Whois = $Nick;
$this->send_raw("WHOIS $Nick");
}
-
+
/*
- This function uses blacklisted_ip, which is no longer in RC2.
- You can probably find it in old RC1 code kicking aronud if you need it.
+ This function uses blacklisted_ip, which is no longer in RC2.
+ You can probably find it in old RC1 code kicking aronud if you need it.
protected function ip_check($IP,$Gline=false,$Channel=BOT_REPORT_CHAN) {
global $Cache, $DB;
if(blacklisted_ip($IP)) {
@@ -209,7 +209,7 @@ protected function listen() {
if($this->Listened = @socket_accept($this->ListenSocket)) {
$this->listener_events();
}
-
+
$DB->LinkID = false;
$DB->Queries = array();
usleep(5000);
diff --git a/classes/class_misc.php b/classes/class_misc.php
new file mode 100644
index 00000000..48877a97
--- /dev/null
+++ b/classes/class_misc.php
@@ -0,0 +1,395 @@
+
+class Misc {
+ /**
+ * Send an email.
+ *
+ * @param string $To the email address to send it to.
+ * @param string $Subject
+ * @param string $Body
+ * @param string $From The user part of the user@NONSSL_SITE_URL email address.
+ * @param string $ContentType text/plain or text/html
+ */
+ public static function send_email($To,$Subject,$Body,$From='noreply',$ContentType='text/plain') {
+ $Headers='MIME-Version: 1.0'."\r\n";
+ $Headers.='Content-type: '.$ContentType.'; charset=iso-8859-1'."\r\n";
+ $Headers.='From: '.SITE_NAME.' <'.$From.'@'.NONSSL_SITE_URL.'>'."\r\n";
+ $Headers.='Reply-To: '.$From.'@'.NONSSL_SITE_URL."\r\n";
+ $Headers.='X-Mailer: Project Gazelle'."\r\n";
+ $Headers.='Message-Id: <'.Users::make_secret().'@'.NONSSL_SITE_URL.">\r\n";
+ $Headers.='X-Priority: 3'."\r\n";
+ mail($To,$Subject,$Body,$Headers,"-f ".$From."@".NONSSL_SITE_URL);
+ }
+
+
+ /**
+ * Sanitize a string to be allowed as a filename.
+ *
+ * @param string $EscapeStr the string to escape
+ * @return the string with all banned characters removed.
+ */
+ public static function file_string($EscapeStr) {
+ return str_replace(array('"','*','/',':','<','>','?','\\','|'), '', $EscapeStr);
+ }
+
+
+ /**
+ * Sends a PM from $FromId to $ToId.
+ *
+ * @param string $ToID ID of user to send PM to. If $ToID is an array and $ConvID is empty, a message will be sent to multiple users.
+ * @param string $FromID ID of user to send PM from, 0 to send from system
+ * @param string $Subject
+ * @param string $Body
+ * @param int $ConvID The conversation the message goes in. Leave blank to start a new conversation.
+ * @return
+ */
+ public static function send_pm($ToID,$FromID,$Subject,$Body,$ConvID='') {
+ global $DB, $Cache, $Time;
+ if ($ToID == 0 || $ToID == $FromID) {
+ // Don't allow users to send messages to the system or themselves
+ return;
+ }
+ if ($ConvID=='') {
+ // Create a new conversation.
+ $DB->query("INSERT INTO pm_conversations(Subject) VALUES ('".$Subject."')");
+ $ConvID = $DB->inserted_id();
+ $DB->query("INSERT INTO pm_conversations_users
+ (UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead) VALUES
+ ('$ToID', '$ConvID', '1','0','".sqltime()."', '".sqltime()."', '1')");
+ if ($FromID != 0) {
+ $DB->query("INSERT INTO pm_conversations_users
+ (UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead) VALUES
+ ('$FromID', '$ConvID', '0','1','".sqltime()."', '".sqltime()."', '0')");
+ }
+ $ToID = array($ToID);
+ } else {
+ // Update the pre-existing conversations.
+ $DB->query("UPDATE pm_conversations_users SET
+ InInbox='1',
+ UnRead='1',
+ ReceivedDate='".sqltime()."'
+ WHERE UserID IN (".implode(',', $ToID).")
+ AND ConvID='$ConvID'");
+
+ $DB->query("UPDATE pm_conversations_users SET
+ InSentbox='1',
+ SentDate='".sqltime()."'
+ WHERE UserID='$FromID'
+ AND ConvID='$ConvID'");
+ }
+
+ // Now that we have a $ConvID for sure, send the message.
+ $DB->query("INSERT INTO pm_messages
+ (SenderID, ConvID, SentDate, Body) VALUES
+ ('$FromID', '$ConvID', '".sqltime()."', '".$Body."')");
+
+ // Update the cached new message count.
+ foreach ($ToID as $ID) {
+ $DB->query("SELECT COUNT(ConvID) FROM pm_conversations_users WHERE UnRead = '1' and UserID='$ID' AND InInbox = '1'");
+ list($UnRead) = $DB->next_record();
+ $Cache->cache_value('inbox_new_'.$ID, $UnRead);
+ }
+
+ return $ConvID;
+ }
+
+
+ /**
+ * Create thread function, things should already be escaped when sent here.
+ *
+ * @param int $ForumID
+ * @param int $AuthorID ID of the user creating the post.
+ * @param string $Title
+ * @param string $PostBody
+ * @return -1 on error, -2 on user not existing, thread id on success.
+ */
+ public static function create_thread($ForumID, $AuthorID, $Title, $PostBody) {
+ global $DB, $Cache, $Time;
+ if (!$ForumID || !$AuthorID || !is_number($AuthorID) || !$Title || !$PostBody) {
+ return -1;
+ }
+
+ $DB->query("SELECT Username FROM users_main WHERE ID=".$AuthorID);
+ if ($DB->record_count() < 1) {
+ return -2;
+ }
+ list($AuthorName) = $DB->next_record();
+
+ $ThreadInfo = array();
+ $ThreadInfo['IsLocked'] = 0;
+ $ThreadInfo['IsSticky'] = 0;
+
+ $DB->query("INSERT INTO forums_topics
+ (Title, AuthorID, ForumID, LastPostTime, LastPostAuthorID)
+ Values
+ ('".$Title."', '".$AuthorID."', '$ForumID', '".sqltime()."', '".$AuthorID."')");
+ $TopicID = $DB->inserted_id();
+ $Posts = 1;
+
+ $DB->query("INSERT INTO forums_posts
+ (TopicID, AuthorID, AddedTime, Body)
+ VALUES
+ ('$TopicID', '".$AuthorID."', '".sqltime()."', '".$PostBody."')");
+ $PostID = $DB->inserted_id();
+
+ $DB->query("UPDATE forums SET
+ NumPosts = NumPosts+1,
+ NumTopics = NumTopics+1,
+ LastPostID = '$PostID',
+ LastPostAuthorID = '".$AuthorID."',
+ LastPostTopicID = '$TopicID',
+ LastPostTime = '".sqltime()."'
+ WHERE ID = '$ForumID'");
+
+ $DB->query("UPDATE forums_topics SET
+ NumPosts = NumPosts+1,
+ LastPostID = '$PostID',
+ LastPostAuthorID = '".$AuthorID."',
+ LastPostTime = '".sqltime()."'
+ WHERE ID = '$TopicID'");
+
+ // Bump this topic to head of the cache
+ list($Forum,,,$Stickies) = $Cache->get_value('forums_'.$ForumID);
+ if (!empty($Forum)) {
+ if (count($Forum) == TOPICS_PER_PAGE && $Stickies < TOPICS_PER_PAGE) {
+ array_pop($Forum);
+ }
+ $DB->query("SELECT f.IsLocked, f.IsSticky, f.NumPosts FROM forums_topics AS f
+ WHERE f.ID ='$TopicID'");
+ list($IsLocked,$IsSticky,$NumPosts) = $DB->next_record();
+ $Part1 = array_slice($Forum,0,$Stickies,true); //Stickys
+ $Part2 = array(
+ $TopicID=>array(
+ 'ID' => $TopicID,
+ 'Title' => $Title,
+ 'AuthorID' => $AuthorID,
+ 'IsLocked' => $IsLocked,
+ 'IsSticky' => $IsSticky,
+ 'NumPosts' => $NumPosts,
+ 'LastPostID' => $PostID,
+ 'LastPostTime' => sqltime(),
+ 'LastPostAuthorID' => $AuthorID,
+ )
+ ); //Bumped thread
+ $Part3 = array_slice($Forum,$Stickies,TOPICS_PER_PAGE,true); //Rest of page
+ if ($Stickies > 0) {
+ $Part1 = array_slice($Forum,0,$Stickies,true); //Stickies
+ $Part3 = array_slice($Forum,$Stickies,TOPICS_PER_PAGE-$Stickies-1,true); //Rest of page
+ } else {
+ $Part1 = array();
+ $Part3 = $Forum;
+ }
+ if (is_null($Part1)) { $Part1 = array(); }
+ if (is_null($Part3)) { $Part3 = array(); }
+ $Forum = $Part1 + $Part2 + $Part3;
+ $Cache->cache_value('forums_'.$ForumID, array($Forum,'',0,$Stickies), 0);
+ }
+
+ //Update the forum root
+ $Cache->begin_transaction('forums_list');
+ $UpdateArray = array(
+ 'NumPosts'=>'+1',
+ 'NumTopics'=>'+1',
+ 'LastPostID'=>$PostID,
+ 'LastPostAuthorID'=>$AuthorID,
+ 'LastPostTopicID'=>$TopicID,
+ 'LastPostTime'=>sqltime(),
+ 'Title'=>$Title,
+ 'IsLocked'=>$ThreadInfo['IsLocked'],
+ 'IsSticky'=>$ThreadInfo['IsSticky']
+ );
+
+ $UpdateArray['NumTopics']='+1';
+
+ $Cache->update_row($ForumID, $UpdateArray);
+ $Cache->commit_transaction(0);
+
+ $CatalogueID = floor((POSTS_PER_PAGE*ceil($Posts/POSTS_PER_PAGE)-POSTS_PER_PAGE)/THREAD_CATALOGUE);
+ $Cache->begin_transaction('thread_'.$TopicID.'_catalogue_'.$CatalogueID);
+ $Post = array(
+ 'ID'=>$PostID,
+ 'AuthorID'=>$LoggedUser['ID'],
+ 'AddedTime'=>sqltime(),
+ 'Body'=>$PostBody,
+ 'EditedUserID'=>0,
+ 'EditedTime'=>'0000-00-00 00:00:00',
+ 'Username'=>''
+ );
+ $Cache->insert('', $Post);
+ $Cache->commit_transaction(0);
+
+ $Cache->begin_transaction('thread_'.$TopicID.'_info');
+ $Cache->update_row(false, array('Posts'=>'+1', 'LastPostAuthorID'=>$AuthorID));
+ $Cache->commit_transaction(0);
+
+ return $TopicID;
+ }
+
+ /**
+ * If the suffix of $Haystack is $Needle
+ *
+ * @param string $Haystack String to search in
+ * @param string $Needle String to search for
+ * @return boolean True if $Needle is a suffix of $Haystack
+ */
+ public static function ends_with($Haystack, $Needle) {
+ return substr($Haystack, strlen($Needle) * -1) == $Needle;
+ }
+
+
+ /**
+ * If the preix of $Haystack is $Needle
+ *
+ * @param string $Haystack String to search in
+ * @param string $Needle String to search for
+ * @return boolean True if $Needle is a preix of $Haystack
+ */
+ public static function starts_with($Haystack, $Needle) {
+ return strpos($Haystack, $Needle) === 0;
+ }
+
+ /**
+ * Variant of in_array() with trailing wildcard support
+ *
+ * @param string $Needle, array $Haystack
+ * @return boolean true if (substring of) $Needle exists in $Haystack
+ */
+ public static function in_array_partial($Needle, $Haystack) {
+ static $Searches = array();
+ if (array_key_exists($Needle, $Searches)) {
+ return $Searches[$Needle];
+ }
+ foreach ($Haystack as $String) {
+ if (substr($String, -1) == '*') {
+ if (!strncmp($Needle, $String, strlen($String)-1)) {
+ $Searches[$Needle] = true;
+ return true;
+ }
+ } elseif (!strcmp($Needle, $String)) {
+ $Searches[$Needle] = true;
+ return true;
+ }
+ }
+ $Searches[$Needle] = false;
+ return false;
+ }
+
+ /**
+ * Used to check if keys in $_POST and $_GET are all set, and throws an error if not.
+ * This reduces 'if' statement redundancy for a lot of variables
+ *
+ * @param array $Request Either $_POST or $_GET, or whatever other array you want to check.
+ * @param array $Keys The keys to ensure are set.
+ * @param boolean $AllowEmpty If set to true, a key that is in the request but blank will not throw an error.
+ * @param int $Error The error code to throw if one of the keys isn't in the array.
+ */
+ public static function assert_isset_request($Request, $Keys=NULL, $AllowEmpty = False, $Error=0) {
+ if (isset($Keys)) {
+ foreach ($Keys as $K) {
+ if (!isset($Request[$K]) || ($AllowEmpty == False && $Request[$K] == '')) {
+ error($Error);
+ break;
+ }
+ }
+ } else {
+ foreach ($Request as $R) {
+ if (!isset($R) || ($AllowEmpty == False && $R == '')) {
+ error($Error);
+ break;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Given an array of tags, return an array of their IDs.
+ *
+ * @param arary $TagNames
+ * @return array IDs
+ */
+ public static function get_tags($TagNames) {
+ global $Cache, $DB;
+ $TagIDs = array();
+ foreach ($TagNames as $Index => $TagName) {
+ $Tag = $Cache->get_value('tag_id_'.$TagName);
+ if (is_array($Tag)) {
+ unset($TagNames[$Index]);
+ $TagIDs[$Tag['ID']] = $Tag['Name'];
+ }
+ }
+ if (count($TagNames) > 0) {
+ $DB->query("SELECT ID, Name FROM tags WHERE Name IN ('".implode("', '", $TagNames)."')");
+ $SQLTagIDs = $DB->to_array();
+ foreach ($SQLTagIDs as $Tag) {
+ $TagIDs[$Tag['ID']] = $Tag['Name'];
+ $Cache->cache_value('tag_id_'.$Tag['Name'], $Tag, 0);
+ }
+ }
+
+ return($TagIDs);
+ }
+
+
+ /**
+ * Gets the alias of the tag, if there is no alias silently returns the original tag.
+ *
+ * @param string $BadTag the tag we want to alias
+ * @return string The aliased tag.
+ */
+ public static function get_alias_tag($BadTag) {
+ global $DB;
+ $DB->query("SELECT AliasTag FROM tag_aliases WHERE BadTag = '". $BadTag ."' LIMIT 1");
+ if ($DB->record_count() > 0) {
+ list($AliasTag) = $DB->next_record();
+ return $AliasTag;
+ }
+ return $BadTag;
+ }
+
+
+ /*
+ * Write a message to the system log.
+ *
+ * @param string $Message the message to write.
+ */
+ public static function write_log($Message) {
+ global $DB,$Time;
+ $DB->query('INSERT INTO log (Message, Time) VALUES (\''
+ .db_string($Message).'\', \''.sqltime().'\')');
+ }
+
+
+ /**
+ * Get a tag ready for database input and display.
+ *
+ * @param string $Str
+ * @return sanitized version of $Str
+ */
+ public static function sanitize_tag($Str) {
+ $Str = strtolower($Str);
+ $Str = preg_replace('/[^a-z0-9.]/', '', $Str);
+ $Str = preg_replace('/(^[.,]*)|([.,]*$)/','',$Str);
+ $Str = htmlspecialchars($Str);
+ $Str = db_string(trim($Str));
+ return $Str;
+ }
+
+ /**
+ * HTML escape an entire array for output.
+ * @param array $Array, what we want to escape
+ * @param boolean/array $Escape
+ * if true, all keys escaped
+ * if false, no escaping.
+ * If array, it's a list of array keys not to escape.
+ * @return mutated version of $Array with values escaped.
+ */
+ public static function display_array($Array, $Escape = array()) {
+ foreach ($Array as $Key => $Val) {
+ if((!is_array($Escape) && $Escape == true) || !in_array($Key, $Escape)) {
+ $Array[$Key] = display_str($Val);
+ }
+ }
+ return $Array;
+ }
+}
+?>
diff --git a/classes/class_mysql.php b/classes/class_mysql.php
index c44cbc48..cd522de2 100644
--- a/classes/class_mysql.php
+++ b/classes/class_mysql.php
@@ -255,7 +255,7 @@ function next_record($Type=MYSQLI_BOTH, $Escape = true) { // $Escape can be true
if (!is_array($this->Record)) {
$this->QueryID = FALSE;
} elseif($Escape !== FALSE){
- $this->Record = display_array($this->Record, $Escape);
+ $this->Record = Misc::display_array($this->Record, $Escape);
}
return $this->Record;
}
@@ -303,7 +303,7 @@ function to_array($Key = false, $Type = MYSQLI_BOTH, $Escape = true) {
$Return = array();
while($Row = mysqli_fetch_array($this->QueryID,$Type)){
if($Escape!==FALSE) {
- $Row = display_array($Row, $Escape);
+ $Row = Misc::display_array($Row, $Escape);
}
if($Key !== false) {
$Return[$Row[$Key]] = $Row;
diff --git a/classes/class_permissions.php b/classes/class_permissions.php
new file mode 100644
index 00000000..6cda611c
--- /dev/null
+++ b/classes/class_permissions.php
@@ -0,0 +1,100 @@
+
+class Permissions {
+ /* Check to see if a user has the permission to perform an action
+ * This is called by check_perms in util.php, for convenience.
+ *
+ * @param string PermissionName
+ * @param string $MinClass Return false if the user's class level is below this.
+ */
+ public static function check_perms($PermissionName,$MinClass = 0) {
+ global $LoggedUser;
+ return (
+ isset($LoggedUser['Permissions'][$PermissionName])
+ && $LoggedUser['Permissions'][$PermissionName]
+ && ($LoggedUser['Class']>=$MinClass
+ || $LoggedUser['EffectiveClass']>=$MinClass)) ? true : false;
+ }
+
+ /**
+ * Gets the permissions associated with a certain permissionid
+ *
+ * @param int $PermissionID the kind of permissions to fetch
+ * @return array permissions
+ */
+ public static function get_permissions($PermissionID) {
+ global $DB, $Cache;
+ $Permission = $Cache->get_value('perm_'.$PermissionID);
+ if (empty($Permission)) {
+ $DB->query("SELECT p.Level AS Class, p.Values as Permissions, p.Secondary, p.PermittedForums FROM permissions AS p WHERE ID='$PermissionID'");
+ $Permission = $DB->next_record(MYSQLI_ASSOC, array('Permissions'));
+ $Permission['Permissions'] = unserialize($Permission['Permissions']);
+ $Cache->cache_value('perm_'.$PermissionID, $Permission, 2592000);
+ }
+ return $Permission;
+ }
+
+ /**
+ * Get a user's permissions.
+ *
+ * @param $UserID
+ * @param array|false $CustomPermissions
+ * Pass in the user's custom permissions if you already have them.
+ * Leave false if you don't have their permissions, the function will fetch them.
+ * @return array Mapping of PermissionName=>bool/int
+ */
+ public static function get_permissions_for_user($UserID, $CustomPermissions = false) {
+ global $DB;
+
+ $UserInfo = Users::user_info($UserID);
+
+ // Fetch custom permissions if they weren't passed in.
+ if ($CustomPermissions === false) {
+ $DB->query('SELECT um.CustomPermissions FROM users_main AS um
+ WHERE um.ID = '.((int)$UserID));
+ list($CustomPermissions) = $DB->next_record(MYSQLI_NUM, false);
+ }
+
+ if (!empty($CustomPermissions) && !is_array($CustomPermissions)) {
+ $CustomPermissions = unserialize($CustomPermissions);
+ }
+
+ $Permissions = Permissions::get_permissions($UserInfo['PermissionID']);
+
+ // Manage 'special' inherited permissions
+ $BonusPerms = array();
+ $BonusCollages = 0;
+ foreach ($UserInfo['ExtraClasses'] as $PermID => $Value) {
+ $ClassPerms = Permissions::get_permissions($PermID);
+ $BonusCollages += $ClassPerms['Permissions']['MaxCollages'];
+ unset($ClassPerms['Permissions']['MaxCollages']);
+ $BonusPerms = array_merge($BonusPerms, $ClassPerms['Permissions']);
+ }
+
+ if (!empty($CustomPermissions)) {
+ $CustomPerms = $CustomPermissions;
+ } else {
+ $CustomPerms = array();
+ }
+
+ // This is legacy donor cruft
+ if ($UserInfo['Donor']) {
+ $DonorPerms = Permissions::get_permissions(DONOR);
+ } else {
+ $DonorPerms = array('Permissions' => array());
+ }
+
+ $MaxCollages = $Permissions['Permissions']['MaxCollages']
+ + $BonusCollages
+ + $CustomPerms['MaxCollages']
+ + $DonorPerms['Permissions']['MaxCollages'];
+
+ //Combine the permissions
+ return array_merge(
+ $Permissions['Permissions'],
+ $BonusPerms,
+ $CustomPerms,
+ $DonorPerms['Permissions'],
+ array('MaxCollages' => $MaxCollages));
+ }
+}
+?>
diff --git a/classes/class_requests.php b/classes/class_requests.php
new file mode 100644
index 00000000..4ba0cd3b
--- /dev/null
+++ b/classes/class_requests.php
@@ -0,0 +1,120 @@
+
+class Requests {
+ /**
+ * Update the sphinx requests delta table for a request.
+ *
+ * @param $RequestID
+ */
+ public static function update_sphinx_requests($RequestID) {
+ global $DB, $Cache;
+
+ $DB->query("REPLACE INTO sphinx_requests_delta (
+ ID, UserID, TimeAdded, LastVote, CategoryID, Title,
+ Year, ReleaseType, CatalogueNumber, BitrateList,
+ FormatList, MediaList, LogCue, FillerID, TorrentID,
+ TimeFilled, Visible, Votes, Bounty)
+ SELECT
+ ID, r.UserID, UNIX_TIMESTAMP(TimeAdded) AS TimeAdded,
+ UNIX_TIMESTAMP(LastVote) AS LastVote, CategoryID,
+ Title, Year, ReleaseType, CatalogueNumber, BitrateList,
+ FormatList, MediaList, LogCue, FillerID, TorrentID,
+ UNIX_TIMESTAMP(TimeFilled) AS TimeFilled, Visible,
+ COUNT(rv.UserID) AS Votes, SUM(rv.Bounty) >> 10 AS Bounty
+ FROM requests AS r LEFT JOIN requests_votes AS rv ON rv.RequestID=r.ID
+ wHERE ID = ".$RequestID."
+ GROUP BY r.ID");
+
+ $DB->query("UPDATE sphinx_requests_delta
+ SET ArtistList = (SELECT
+ GROUP_CONCAT(aa.Name SEPARATOR ' ')
+ FROM requests_artists AS ra
+ JOIN artists_alias AS aa ON aa.AliasID=ra.AliasID
+ WHERE ra.RequestID = ".$RequestID."
+ GROUP BY NULL)
+ WHERE ID = ".$RequestID);
+
+ $Cache->delete_value('requests_'.$RequestID);
+ }
+
+
+
+ /**
+ * Function to get data from an array of $RequestIDs.
+ * In places where the output from this is merged with sphinx filters, it will be in a different order.
+ *
+ * @param array $RequestIDs
+ * @param boolean $Return if set to false, data won't be returned (ie. if we just want to prime the cache.)
+ * @return The array of requests.
+ * Format: array(RequestID => Associative array)
+ * To see what's exactly inside each associate array, peek inside the function. It won't bite.
+ */
+ //
+ //In places where the output from this is merged with sphinx filters, it will be in a different order.
+ public static function get_requests($RequestIDs, $Return = true) {
+ global $DB, $Cache;
+
+ // Try to fetch the requests from the cache first.
+ $Found = array_flip($RequestIDs);
+ $NotFound = array_flip($RequestIDs);
+
+ foreach ($RequestIDs as $RequestID) {
+ $Data = $Cache->get_value('request_'.$RequestID);
+ if (!empty($Data)) {
+ unset($NotFound[$RequestID]);
+ $Found[$RequestID] = $Data;
+ }
+ }
+
+ $IDs = implode(',',array_flip($NotFound));
+
+ /*
+ Don't change without ensuring you change everything else that uses get_requests()
+ */
+
+ if (count($NotFound) > 0) {
+ $DB->query("SELECT
+ r.ID AS ID,
+ r.UserID,
+ u.Username,
+ r.TimeAdded,
+ r.LastVote,
+ r.CategoryID,
+ r.Title,
+ r.Year,
+ r.Image,
+ r.Description,
+ r.CatalogueNumber,
+ r.RecordLabel,
+ r.ReleaseType,
+ r.BitrateList,
+ r.FormatList,
+ r.MediaList,
+ r.LogCue,
+ r.FillerID,
+ filler.Username,
+ r.TorrentID,
+ r.TimeFilled,
+ r.GroupID,
+ r.OCLC
+ FROM requests AS r
+ LEFT JOIN users_main AS u ON u.ID=r.UserID
+ LEFT JOIN users_main AS filler ON filler.ID=FillerID AND FillerID!=0
+ WHERE r.ID IN (".$IDs.")
+ ORDER BY ID");
+
+ $Requests = $DB->to_array();
+ foreach ($Requests as $Request) {
+ unset($NotFound[$Request['ID']]);
+ $Request['Tags'] = get_request_tags($Request['ID']);
+ $Found[$Request['ID']] = $Request;
+ $Cache->cache_value('request_'.$Request['ID'], $Request, 0);
+ }
+ }
+
+ if ($Return) { // If we're interested in the data, and not just caching it
+ $Matches = array('matches'=>$Found, 'notfound'=>array_flip($NotFound));
+ return $Matches;
+ }
+ }
+}
+?>
diff --git a/classes/class_sphinxql.php b/classes/class_sphinxql.php
index 58f98b07..16a92874 100644
--- a/classes/class_sphinxql.php
+++ b/classes/class_sphinxql.php
@@ -3,7 +3,7 @@
error('Mysqli Extension not loaded.');
}
-class SPHINXQL extends mysqli {
+class SphinxQL extends mysqli {
private static $Connections = array();
private $Server;
private $Port;
@@ -56,7 +56,7 @@ private function get_ident($Server, $Port, $Socket) {
public static function init_connection($Server, $Port, $Socket) {
$Ident = self::get_ident($Server, $Port, $Socket);
if(!isset(self::$Connections[$Ident])) {
- self::$Connections[$Ident] = new SPHINXQL($Server, $Port, $Socket);
+ self::$Connections[$Ident] = new SphinxQL($Server, $Port, $Socket);
}
return self::$Connections[$Ident];
}
@@ -130,12 +130,12 @@ public function escape_string($String) {
* @param param $QueryProcessTime time building and processing the query
*/
public function register_query($QueryString, $QueryProcessTime) {
- SPHINXQL::$Queries[] = array($QueryString, $QueryProcessTime);
- SPHINXQL::$Time += $QueryProcessTime;
+ SphinxQL::$Queries[] = array($QueryString, $QueryProcessTime);
+ SphinxQL::$Time += $QueryProcessTime;
}
}
-class SPHINXQL_QUERY {
+class SphinxQL_Query {
private $SphinxQL;
private $Expressions;
@@ -157,7 +157,7 @@ class SPHINXQL_QUERY {
* @param string $Socket Unix socket address, overrides $Server:$Port
*/
public function __construct($Server = SPHINXQL_HOST, $Port = SPHINXQL_PORT, $Socket = SPHINXQL_SOCK) {
- $this->SphinxQL = SPHINXQL::init_connection($Server, $Port, $Socket);
+ $this->SphinxQL = SphinxQL::init_connection($Server, $Port, $Socket);
$this->reset();
}
@@ -248,7 +248,7 @@ public function where_match($Expr, $Field = '*') {
if(empty($Expr)) {
return $this;
}
- $this->Expressions[] = "@$Field ".SPHINXQL::escape_string($Expr);
+ $this->Expressions[] = "@$Field ".SphinxQL::escape_string($Expr);
return $this;
}
@@ -370,7 +370,7 @@ public function query($GetMeta = true) {
$QueryString = $this->QueryString;
$Result = $this->send_query($GetMeta);
$QueryProcessTime = (microtime(true) - $QueryStartTime)*1000;
- SPHINXQL::register_query($QueryString, $QueryProcessTime);
+ SphinxQL::register_query($QueryString, $QueryProcessTime);
return $Result;
}
@@ -405,7 +405,7 @@ private function send_query($GetMeta) {
} else {
$Meta = $GetMeta ? $this->get_meta() : null;
}
- return new SPHINXQL_RESULT($Result, $Meta, $Errno, $Error);
+ return new SphinxQL_Result($Result, $Meta, $Errno, $Error);
}
/**
@@ -441,7 +441,7 @@ private function error($Msg, $Halt = false) {
}
}
-class SPHINXQL_RESULT {
+class SphinxQL_Result {
private $Result;
private $Meta;
public $Errno;
diff --git a/classes/class_text.php b/classes/class_text.php
index 770fcf1d..f3fdcccb 100644
--- a/classes/class_text.php
+++ b/classes/class_text.php
@@ -458,24 +458,24 @@ function to_html($Array) {
$Str.=''.$Block['Val'].' ';
break;
case 'artist':
- $Str.=''.$Block['Val'].' ';
+ $Str.=''.$Block['Val'].' ';
break;
case 'rule':
$Rule = trim(strtolower($Block['Val']));
if($Rule[0] != 'r' && $Rule[0] != 'h') {
$Rule = 'r'.$Rule;
}
- $Str.=''.preg_replace('/[aA-zZ]/', '', $Block['Val']).' ';
+ $Str.=''.preg_replace('/[aA-zZ]/', '', $Block['Val']).' ';
break;
case 'torrent':
$Pattern = '/('.NONSSL_SITE_URL.'\/torrents\.php.*[\?&]id=)?(\d+)($|&|\#).*/i';
$Matches = array();
if (preg_match($Pattern, $Block['Val'], $Matches)) {
if (isset($Matches[2])) {
- $Groups = get_groups(array($Matches[2]), true, true, false);
+ $Groups = Torrents::get_groups(array($Matches[2]), true, true, false);
if (!empty($Groups['matches'][$Matches[2]])) {
$Group = $Groups['matches'][$Matches[2]];
- $Str .= display_artists($Group['ExtendedArtists']).''.$Group['Name'].' ';
+ $Str .= Artists::display_artists($Group['ExtendedArtists']).''.$Group['Name'].' ';
} else {
$Str .= '[torrent]'.str_replace('[inlineurl]','',$Block['Val']).'[/torrent]';
}
diff --git a/classes/class_text2.php b/classes/class_text2.php
index a77a1a15..46f79f29 100644
--- a/classes/class_text2.php
+++ b/classes/class_text2.php
@@ -470,7 +470,7 @@ function to_html($Array) {
$Str.=''.$Block['Val'].' ';
break;
case 'artist':
- $Str.=''.$Block['Val'].' ';
+ $Str.=''.$Block['Val'].' ';
break;
case 'wiki':
$Str.=''.$Block['Val'].' ';
diff --git a/classes/class_tools.php b/classes/class_tools.php
new file mode 100644
index 00000000..5cf2e120
--- /dev/null
+++ b/classes/class_tools.php
@@ -0,0 +1,239 @@
+
+class Tools {
+ /**
+ * Returns true if given IP is banned.
+ *
+ * @param string $IP
+ */
+ public static function site_ban_ip($IP) {
+ global $DB, $Cache;
+ $IPNum = Tools::ip_to_unsigned($IP);
+ $IPBans = $Cache->get_value('ip_bans');
+ if (!is_array($IPBans)) {
+ $DB->query("SELECT ID, FromIP, ToIP FROM ip_bans");
+ $IPBans = $DB->to_array(0, MYSQLI_NUM);
+ $Cache->cache_value('ip_bans', $IPBans, 0);
+ }
+ foreach ($IPBans as $Index => $IPBan) {
+ list ($ID, $FromIP, $ToIP) = $IPBan;
+ if ($IPNum >= $FromIP && $IPNum <= $ToIP) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the unsigned form of an IP address.
+ *
+ * @param string $IP The IP address x.x.x.x
+ * @return string the long it represents.
+ */
+ public static function ip_to_unsigned($IP) {
+ return sprintf("%u", ip2long($IP));
+ }
+
+ /**
+ * Geolocate an IP address using the database
+ *
+ * @param $IP the ip to fetch the country for
+ * @return the country of origin
+ */
+ public static function geoip($IP) {
+ static $IPs = array();
+ if (isset($IPs[$IP])) {
+ return $IPs[$IP];
+ }
+ $Long = Tools::ip_to_unsigned($IP);
+ if(!$Long || $Long == 2130706433) { // No need to check cc for 127.0.0.1
+ return false;
+ }
+ global $DB;
+ $DB->query("SELECT EndIP,Code FROM geoip_country WHERE $Long >= StartIP ORDER BY StartIP DESC LIMIT 1");
+ if((!list($EndIP,$Country) = $DB->next_record()) || $EndIP < $Long) {
+ $Country = '?';
+ }
+ $IPs[$IP] = $Country;
+ return $Country;
+ }
+
+ /**
+ * Gets the hostname for an IP address
+ *
+ * @param $IP the IP to get the hostname for
+ * @return hostname fetched
+ */
+ public static function get_host_by_ip($IP)
+ {
+ $testar = explode('.',$IP);
+ if (count($testar)!=4) {
+ return $IP;
+ }
+ for ($i=0;$i<4;++$i) {
+ if (!is_numeric($testar[$i])) {
+ return $IP;
+ }
+ }
+
+ $host = `host -W 1 $IP`;
+ return (($host ? end ( explode (' ', $host)) : $IP));
+ }
+
+ /**
+ * Gets an hostname using AJAX
+ *
+ * @param $IP the IP to fetch
+ * @return a span with javascript code
+ */
+ public static function get_host_by_ajax($IP) {
+ static $ID = 0;
+ ++$ID;
+ return 'Resolving host... ';
+ }
+
+
+ /**
+ * Looks up the full host of an IP address, by system call.
+ * Used as the server-side counterpart to get_host_by_ajax.
+ *
+ * @param string $IP The IP address to look up.
+ * @return string the host.
+ */
+ public static function lookup_ip($IP) {
+ //TODO: use the $Cache
+ $Output = explode(' ',shell_exec('host -W 1 '.escapeshellarg($IP)));
+ if(count($Output) == 1 && empty($Output[0])) {
+ //No output at all implies the command failed
+ return '';
+ }
+
+ if(count($Output) != 5) {
+ return false;
+ } else {
+ return $Output[4];
+ }
+ }
+
+ /**
+ * Format an IP address with links to IP history.
+ *
+ * @param string IP
+ * @return string The HTML
+ */
+ public static function display_ip($IP) {
+ $Line = display_str($IP).' ('.Tools::get_country_code_by_ajax($IP).') ';
+ $Line .= '[S ]';
+
+ return $Line;
+ }
+
+ public static function get_country_code_by_ajax($IP) {
+ static $ID = 0;
+ ++$ID;
+ return 'Resolving CC... ';
+ }
+
+
+
+
+ /**
+ * Disable an array of users.
+ *
+ * @param array $UserIDs (You can also send it one ID as an int, because fuck types)
+ * @param BanReason 0 - Unknown, 1 - Manual, 2 - Ratio, 3 - Inactive, 4 - Unused.
+ */
+ public static function disable_users($UserIDs, $AdminComment, $BanReason = 1) {
+ global $Cache, $DB;
+ if(!is_array($UserIDs)) {
+ $UserIDs = array($UserIDs);
+ }
+ $DB->query("UPDATE users_info AS i JOIN users_main AS m ON m.ID=i.UserID
+ SET m.Enabled='2',
+ m.can_leech='0',
+ i.AdminComment = CONCAT('".sqltime()." - ".($AdminComment ? $AdminComment : 'Disabled by system')."\n\n', i.AdminComment),
+ i.BanDate='".sqltime()."',
+ i.BanReason='".$BanReason."',
+ i.RatioWatchDownload=".($BanReason == 2?'m.Downloaded':"'0'")."
+ WHERE m.ID IN(".implode(',',$UserIDs).") ");
+ $Cache->decrement('stats_user_count',$DB->affected_rows());
+ foreach($UserIDs as $UserID) {
+ $Cache->delete_value('enabled_'.$UserID);
+ $Cache->delete_value('user_info_'.$UserID);
+ $Cache->delete_value('user_info_heavy_'.$UserID);
+ $Cache->delete_value('user_stats_'.$UserID);
+
+ $DB->query("SELECT SessionID FROM users_sessions WHERE UserID='$UserID' AND Active = 1");
+ while(list($SessionID) = $DB->next_record()) {
+ $Cache->delete_value('session_'.$UserID.'_'.$SessionID);
+ }
+ $Cache->delete_value('users_sessions_'.$UserID);
+
+
+ $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'");
+
+ }
+
+ // Remove the users from the tracker.
+ $DB->query("SELECT torrent_pass FROM users_main WHERE ID in (".implode(", ",$UserIDs).")");
+ $PassKeys = $DB->collect('torrent_pass');
+ $Concat = "";
+ foreach($PassKeys as $PassKey) {
+ if(strlen($Concat) > 4000) {
+ Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
+ $Concat = $PassKey;
+ } else {
+ $Concat .= $PassKey;
+ }
+ }
+ Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
+ }
+
+ /**
+ * Warn a user.
+ *
+ * @param int $UserID
+ * @param int $Duration length of warning in seconds
+ * @param string $reason
+ */
+ public static function warn_user($UserID, $Duration, $Reason) {
+ global $LoggedUser, $DB, $Cache, $Time;
+
+ $DB->query("SELECT Warned FROM users_info
+ WHERE UserID=".$UserID."
+ AND Warned <> '0000-00-00 00:00:00'");
+ if($DB->record_count() > 0) {
+ //User was already warned, appending new warning to old.
+ list($OldDate) = $DB->next_record();
+ $NewExpDate = date('Y-m-d H:i:s', strtotime($OldDate) + $Duration);
+
+ Misc::send_pm($UserID, 0,
+ db_string("You have received multiple warnings."),
+ db_string("When you received your latest warning (Set to expire on ".date("Y-m-d", (time() + $Duration))."), you already had a different warning (Set to expire on ".date("Y-m-d", strtotime($OldDate)).").\n\n Due to this collision, your warning status will now expire at ".$NewExpDate."."));
+
+ $AdminComment = date("Y-m-d").' - Warning (Clash) extended to expire at '.$NewExpDate.' by '.$LoggedUser['Username']."\nReason: $Reason\n\n";
+
+ $DB->query('UPDATE users_info SET
+ Warned=\''.db_string($NewExpDate).'\',
+ WarnedTimes=WarnedTimes+1,
+ AdminComment=CONCAT(\''.db_string($AdminComment).'\',AdminComment)
+ WHERE UserID=\''.db_string($UserID).'\'');
+ } else {
+ //Not changing, user was not already warned
+ $WarnTime = time_plus($Duration);
+
+ $Cache->begin_transaction('user_info_'.$UserID);
+ $Cache->update_row(false, array('Warned' => $WarnTime));
+ $Cache->commit_transaction(0);
+
+ $AdminComment = date("Y-m-d").' - Warned until '.$WarnTime.' by '.$LoggedUser['Username']."\nReason: $Reason\n\n";
+
+ $DB->query('UPDATE users_info SET
+ Warned=\''.db_string($WarnTime).'\',
+ WarnedTimes=WarnedTimes+1,
+ AdminComment=CONCAT(\''.db_string($AdminComment).'\',AdminComment)
+ WHERE UserID=\''.db_string($UserID).'\'');
+ }
+ }
+}
+?>
diff --git a/classes/class_torrent_form.php b/classes/class_torrent_form.php
index 905e187e..547a4213 100644
--- a/classes/class_torrent_form.php
+++ b/classes/class_torrent_form.php
@@ -93,9 +93,9 @@ function head() {
Disabled?>>
- foreach(display_array($this->Categories) as $Index => $Cat) {
+ foreach(Misc::display_array($this->Categories) as $Index => $Cat) {
echo "Torrent['CategoryName']) { echo ' selected="selected"'; }
+ if($Cat == $this->Torrent['CategoryName']) { echo " selected='selected'"; }
echo ">";
echo $Cat;
echo " \n";
@@ -398,7 +398,7 @@ function show() {
---
- foreach(display_array($this->Formats) as $Format) {
+ foreach(Misc::display_array($this->Formats) as $Format) {
echo "";
@@ -432,7 +432,7 @@ function show() {
$SimpleBitrate = $SimpleBitrate[0];
- foreach(display_array($this->Bitrates) as $Bitrate) {
+ foreach(Misc::display_array($this->Bitrates) as $Bitrate) {
echo "
Disabled?>>
---
- foreach(display_array($GenreTags) as $Genre) { ?>
+ foreach(Misc::display_array($GenreTags) as $Genre) { ?>
=$Genre ?>
} ?>
@@ -655,7 +655,7 @@ function audiobook_form() {
---
- foreach(display_array($this->Formats) as $Format) {
+ foreach(Misc::display_array($this->Formats) as $Format) {
echo "";
@@ -681,7 +681,7 @@ function audiobook_form() {
} else {
$OtherBitrate = false;
}
- foreach(display_array($this->Bitrates) as $Bitrate) {
+ foreach(Misc::display_array($this->Bitrates) as $Bitrate) {
echo " (
+ * Name
+ * Year
+ * RecordLabel
+ * CatalogueNumber
+ * TagList
+ * ReleaseType
+ * VanityHouse
+ * Torrents => {
+ * ID => {
+ * GroupID, Media, Format, Encoding, RemasterYear, Remastered,
+ * RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, Scene,
+ * HasLog, HasCue, LogScore, FileCount, FreeTorrent, Size, Leechers,
+ * Seeders, Snatched, Time, HasFile
+ * }
+ * }
+ * ExtendedArtists => {
+ * [1-6] => { // See documentation on Artists::get_artists
+ * id, name, aliasid
+ * }
+ * }
+ */
+ public static function get_groups($GroupIDs, $Return = true, $GetArtists = true, $Torrents = true) {
+ global $DB, $Cache;
+
+ $Found = array_flip($GroupIDs);
+ $NotFound = array_flip($GroupIDs);
+ $Key = $Torrents ? 'torrent_group_' : 'torrent_group_light_';
+
+ foreach ($GroupIDs as $GroupID) {
+ $Data = $Cache->get_value($Key.$GroupID);
+ if (!empty($Data) && (@$Data['ver'] >= 4)) {
+ unset($NotFound[$GroupID]);
+ $Found[$GroupID] = $Data['d'];
+ }
+ }
+
+ $IDs = implode(',',array_flip($NotFound));
+
+ /*
+ Changing any of these attributes returned will cause very large, very dramatic site-wide chaos.
+ Do not change what is returned or the order thereof without updating:
+ torrents, artists, collages, bookmarks, better, the front page,
+ and anywhere else the get_groups function is used.
+ */
+
+ if (count($NotFound)>0) {
+ $DB->query("SELECT
+ g.ID, g.Name, g.Year, g.RecordLabel, g.CatalogueNumber, g.TagList, g.ReleaseType, g.VanityHouse
+ FROM torrents_group AS g WHERE g.ID IN ($IDs)");
+
+ while($Group = $DB->next_record(MYSQLI_ASSOC, true)) {
+ unset($NotFound[$Group['ID']]);
+ $Found[$Group['ID']] = $Group;
+ $Found[$Group['ID']]['Torrents'] = array();
+ $Found[$Group['ID']]['Artists'] = array();
+ }
+
+ if ($Torrents) {
+ $DB->query("SELECT
+ ID, GroupID, Media, Format, Encoding, RemasterYear, Remastered, RemasterTitle,
+ RemasterRecordLabel, RemasterCatalogueNumber, Scene, HasLog, HasCue, LogScore,
+ FileCount, FreeTorrent, Size, Leechers, Seeders, Snatched, Time, ID AS HasFile
+ FROM torrents AS t
+ WHERE GroupID IN($IDs)
+ ORDER BY GroupID, Remastered, (RemasterYear <> 0) DESC, RemasterYear, RemasterTitle,
+ RemasterRecordLabel, RemasterCatalogueNumber, Media, Format, Encoding, ID");
+ while($Torrent = $DB->next_record(MYSQLI_ASSOC, true)) {
+ $Found[$Torrent['GroupID']]['Torrents'][$Torrent['ID']] = $Torrent;
+
+ $Cache->cache_value('torrent_group_'.$Torrent['GroupID'],
+ array('ver'=>4, 'd'=>$Found[$Torrent['GroupID']]), 0);
+ $Cache->cache_value('torrent_group_light_'.$Torrent['GroupID'],
+ array('ver'=>4, 'd'=>$Found[$Torrent['GroupID']]), 0);
+ }
+ } else {
+ foreach ($Found as $Group) {
+ $Cache->cache_value('torrent_group_light_'.$Group['ID'], array('ver'=>4, 'd'=>$Found[$Group['ID']]), 0);
+ }
+ }
+ }
+ if ($GetArtists) {
+ $Artists = Artists::get_artists($GroupIDs);
+ } else {
+ $Artists = array();
+ }
+
+ if ($Return) { // If we're interested in the data, and not just caching it
+ foreach ($Artists as $GroupID=>$Data) {
+ if (array_key_exists(1, $Data) || array_key_exists(4, $Data) || array_key_exists(6, $Data)) {
+ $Found[$GroupID]['Artists']=$Data[1]; // Only use main artists (legacy)
+ $Found[$GroupID]['ExtendedArtists'][1]=$Data[1];
+ $Found[$GroupID]['ExtendedArtists'][2]=$Data[2];
+ $Found[$GroupID]['ExtendedArtists'][3]=$Data[3];
+ $Found[$GroupID]['ExtendedArtists'][4]=$Data[4];
+ $Found[$GroupID]['ExtendedArtists'][5]=$Data[5];
+ $Found[$GroupID]['ExtendedArtists'][6]=$Data[6];
+ }
+ else {
+ $Found[$GroupID]['ExtendedArtists'] = false;
+ }
+ }
+
+ $Matches = array('matches'=>$Found, 'notfound'=>array_flip($NotFound));
+
+ return $Matches;
+ }
+ }
+
+
+ /*
+ * Write to the group log.
+ *
+ * @param int $GroupID
+ * @param int $TorrentID
+ * @param int $UserID
+ * @param string $Message
+ * @param boolean $Hidden Currently does fuck all. TODO: Fix that.
+ */
+ public static function write_group_log($GroupID, $TorrentID, $UserID, $Message, $Hidden) {
+ global $DB,$Time;
+ $DB->query("INSERT INTO group_log (GroupID, TorrentID, UserID, Info, Time, Hidden) VALUES ("
+ .$GroupID.", ".$TorrentID.", ".$UserID.", '".db_string($Message)."', '".sqltime()."', ".$Hidden.")");
+ }
+
+
+ /**
+ * Delete a torrent.
+ *
+ * @param int $ID The ID of the torrent to delete.
+ * @param int $GroupID Set it if you have it handy, to save a query. Otherwise, it will be found.
+ * @param string $OcelotReason The deletion reason for ocelot to report to users.
+ */
+ public static function delete_torrent($ID, $GroupID=0, $OcelotReason=-1) {
+ global $DB, $Cache, $LoggedUser;
+ if (!$GroupID) {
+ $DB->query("SELECT GroupID, UserID FROM torrents WHERE ID='$ID'");
+ list($GroupID, $UploaderID) = $DB->next_record();
+ }
+ if (empty($UserID)) {
+ $DB->query("SELECT UserID FROM torrents WHERE ID='$ID'");
+ list($UserID) = $DB->next_record();
+ }
+
+ $RecentUploads = $Cache->get_value('recent_uploads_'.$UserID);
+ if (is_array($RecentUploads)) {
+ foreach ($RecentUploads as $Key => $Recent) {
+ if ($Recent['ID'] == $GroupID) {
+ $Cache->delete_value('recent_uploads_'.$UserID);
+ }
+ }
+ }
+
+
+ $DB->query("SELECT info_hash FROM torrents WHERE ID = ".$ID);
+ list($InfoHash) = $DB->next_record(MYSQLI_BOTH, false);
+ $DB->query("DELETE FROM torrents WHERE ID = ".$ID);
+ Tracker::update_tracker('delete_torrent', array('info_hash' => rawurlencode($InfoHash), 'id' => $ID, 'reason' => $OcelotReason));
+
+ $Cache->decrement('stats_torrent_count');
+
+ $DB->query("SELECT COUNT(ID) FROM torrents WHERE GroupID='$GroupID'");
+ list($Count) = $DB->next_record();
+
+ if ($Count == 0) {
+ Torrents::delete_group($GroupID);
+ } else {
+ Torrents::update_hash($GroupID);
+ //Artists
+ $DB->query("SELECT ArtistID
+ FROM torrents_artists
+ WHERE GroupID = ".$GroupID);
+ $ArtistIDs = $DB->collect('ArtistID');
+ foreach ($ArtistIDs as $ArtistID) {
+ $Cache->delete_value('artist_'.$ArtistID);
+ }
+ }
+
+ // Torrent notifications
+ $DB->query("SELECT UserID FROM users_notify_torrents WHERE TorrentID='$ID'");
+ while(list($UserID) = $DB->next_record()) {
+ $Cache->delete_value('notifications_new_'.$UserID);
+ }
+ $DB->query("DELETE FROM users_notify_torrents WHERE TorrentID='$ID'");
+
+
+ $DB->query("UPDATE reportsv2 SET
+ Status='Resolved',
+ LastChangeTime='".sqltime()."',
+ ModComment='Report already dealt with (Torrent deleted)'
+ WHERE TorrentID=".$ID."
+ AND Status != 'Resolved'");
+ $Reports = $DB->affected_rows();
+ if ($Reports) {
+ $Cache->decrement('num_torrent_reportsv2', $Reports);
+ }
+
+ $DB->query("DELETE FROM torrents_files WHERE TorrentID='$ID'");
+ $DB->query("DELETE FROM torrents_bad_tags WHERE TorrentID = ".$ID);
+ $DB->query("DELETE FROM torrents_bad_folders WHERE TorrentID = ".$ID);
+ $DB->query("DELETE FROM torrents_bad_files WHERE TorrentID = ".$ID);
+ $DB->query("DELETE FROM torrents_cassette_approved WHERE TorrentID = ".$ID);
+ $DB->query("DELETE FROM torrents_lossymaster_approved WHERE TorrentID = ".$ID);
+ $DB->query("DELETE FROM torrents_lossyweb_approved WHERE TorrentID = ".$ID);
+ $Cache->delete_value('torrent_download_'.$ID);
+ $Cache->delete_value('torrent_group_'.$GroupID);
+ $Cache->delete_value('torrents_details_'.$GroupID);
+ }
+
+
+ /**
+ * Delete a group, called after all of its torrents have been deleted.
+ * IMPORTANT: Never call this unless you're certain the group is no longer used by any torrents
+ *
+ * @param int $GroupID
+ */
+ public static function delete_group($GroupID) {
+ global $DB, $Cache;
+
+ Misc::write_log("Group ".$GroupID." automatically deleted (No torrents have this group).");
+
+ $DB->query("SELECT CategoryID FROM torrents_group WHERE ID='$GroupID'");
+ list($Category) = $DB->next_record();
+ if ($Category == 1) {
+ $Cache->decrement('stats_album_count');
+ }
+ $Cache->decrement('stats_group_count');
+
+
+
+ // Collages
+ $DB->query("SELECT CollageID FROM collages_torrents WHERE GroupID='$GroupID'");
+ if ($DB->record_count()>0) {
+ $CollageIDs = $DB->collect('CollageID');
+ $DB->query("UPDATE collages SET NumTorrents=NumTorrents-1 WHERE ID IN (".implode(', ',$CollageIDs).")");
+ $DB->query("DELETE FROM collages_torrents WHERE GroupID='$GroupID'");
+
+ foreach ($CollageIDs as $CollageID) {
+ $Cache->delete_value('collage_'.$CollageID);
+ }
+ $Cache->delete_value('torrent_collages_'.$GroupID);
+ }
+
+ // Artists
+ // Collect the artist IDs and then wipe the torrents_artist entry
+ $DB->query("SELECT ArtistID FROM torrents_artists WHERE GroupID = ".$GroupID);
+ $Artists = $DB->collect('ArtistID');
+
+ $DB->query("DELETE FROM torrents_artists WHERE GroupID='$GroupID'");
+
+ foreach ($Artists as $ArtistID) {
+ if (empty($ArtistID)) { continue; }
+ // Get a count of how many groups or requests use the artist ID
+ $DB->query("SELECT COUNT(ag.ArtistID)
+ FROM artists_group as ag
+ LEFT JOIN requests_artists AS ra ON ag.ArtistID=ra.ArtistID
+ WHERE ra.ArtistID IS NOT NULL
+ AND ag.ArtistID = '$ArtistID'");
+ list($ReqCount) = $DB->next_record();
+ $DB->query("SELECT COUNT(ag.ArtistID)
+ FROM artists_group as ag
+ LEFT JOIN torrents_artists AS ta ON ag.ArtistID=ta.ArtistID
+ WHERE ta.ArtistID IS NOT NULL
+ AND ag.ArtistID = '$ArtistID'");
+ list($GroupCount) = $DB->next_record();
+ if (($ReqCount + $GroupCount) == 0) {
+ //The only group to use this artist
+ Artists::delete_artist($ArtistID);
+ } else {
+ //Not the only group, still need to clear cache
+ $Cache->delete_value('artist_'.$ArtistID);
+ }
+ }
+
+ // Requests
+ $DB->query("SELECT ID FROM requests WHERE GroupID='$GroupID'");
+ $Requests = $DB->collect('ID');
+ $DB->query("UPDATE requests SET GroupID = NULL WHERE GroupID = '$GroupID'");
+ foreach ($Requests as $RequestID) {
+ $Cache->delete_value('request_'.$RequestID);
+ }
+
+ $DB->query("DELETE FROM torrents_group WHERE ID='$GroupID'");
+ $DB->query("DELETE FROM torrents_tags WHERE GroupID='$GroupID'");
+ $DB->query("DELETE FROM torrents_tags_votes WHERE GroupID='$GroupID'");
+ $DB->query("DELETE FROM torrents_comments WHERE GroupID='$GroupID'");
+ $DB->query("DELETE FROM bookmarks_torrents WHERE GroupID='$GroupID'");
+ $DB->query("DELETE FROM wiki_torrents WHERE PageID='$GroupID'");
+
+ // Tells Sphinx that the group is removed
+ $DB->query("REPLACE INTO sphinx_delta (ID,Time) VALUES ('$GroupID',UNIX_TIMESTAMP())");
+
+ $Cache->delete_value('torrents_details_'.$GroupID);
+ $Cache->delete_value('torrent_group_'.$GroupID);
+ $Cache->delete_value('groups_artists_'.$GroupID);
+ }
+
+
+ /**
+ * Update the cache and sphinx delta index to keep everything up to date.
+ *
+ * @param int $GroupID
+ */
+ public static function update_hash($GroupID) {
+ global $DB, $Cache;
+ $DB->query("UPDATE torrents_group SET TagList=(SELECT REPLACE(GROUP_CONCAT(tags.Name SEPARATOR ' '),'.','_')
+ FROM torrents_tags AS t
+ INNER JOIN tags ON tags.ID=t.TagID
+ WHERE t.GroupID='$GroupID'
+ GROUP BY t.GroupID)
+ WHERE ID='$GroupID'");
+
+ $DB->query("REPLACE INTO sphinx_delta
+ (ID, GroupName, TagList, Year, CategoryID, Time, ReleaseType, RecordLabel,
+ CatalogueNumber, VanityHouse, Size, Snatched, Seeders, Leechers, LogScore,
+ Scene, HasLog, HasCue, FreeTorrent, Media, Format, Encoding, RemasterYear,
+ RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, FileList)
+ SELECT
+ g.ID AS ID,
+ g.Name AS GroupName,
+ g.TagList,
+ g.Year,
+ g.CategoryID,
+ UNIX_TIMESTAMP(g.Time) AS Time,
+ g.ReleaseType,
+ g.RecordLabel,
+ g.CatalogueNumber,
+ g.VanityHouse,
+ MAX(CEIL(t.Size/1024)) AS Size,
+ SUM(t.Snatched) AS Snatched,
+ SUM(t.Seeders) AS Seeders,
+ SUM(t.Leechers) AS Leechers,
+ MAX(t.LogScore) AS LogScore,
+ MAX(t.Scene) AS Scene,
+ MAX(t.HasLog) AS HasLog,
+ MAX(t.HasCue) AS HasCue,
+ BIT_OR(t.FreeTorrent-1) AS FreeTorrent,
+ GROUP_CONCAT(DISTINCT t.Media SEPARATOR ' ') AS Media,
+ GROUP_CONCAT(DISTINCT t.Format SEPARATOR ' ') AS Format,
+ GROUP_CONCAT(DISTINCT t.Encoding SEPARATOR ' ') AS Encoding,
+ GROUP_CONCAT(DISTINCT t.RemasterYear SEPARATOR ' ') AS RemasterYear,
+ GROUP_CONCAT(DISTINCT t.RemasterTitle SEPARATOR ' ') AS RemasterTitle,
+ GROUP_CONCAT(DISTINCT t.RemasterRecordLabel SEPARATOR ' ') AS RemasterRecordLabel,
+ GROUP_CONCAT(DISTINCT t.RemasterCatalogueNumber SEPARATOR ' ') AS RemasterCatalogueNumber,
+ GROUP_CONCAT(REPLACE(REPLACE(FileList, '|||', '\n '), '_', ' ') SEPARATOR '\n ') AS FileList
+ FROM torrents AS t
+ JOIN torrents_group AS g ON g.ID=t.GroupID
+ WHERE g.ID=$GroupID
+ GROUP BY g.ID");
+
+ $DB->query("INSERT INTO sphinx_delta
+ (ID, ArtistName)
+ SELECT
+ GroupID,
+ GROUP_CONCAT(aa.Name separator ' ')
+ FROM torrents_artists AS ta
+ JOIN artists_alias AS aa ON aa.AliasID=ta.AliasID
+ JOIN torrents_group AS tg ON tg.ID=ta.GroupID
+ WHERE ta.GroupID=$GroupID AND ta.Importance IN ('1', '4', '5', '6')
+ GROUP BY tg.ID
+ ON DUPLICATE KEY UPDATE ArtistName=values(ArtistName)");
+
+ $Cache->delete_value('torrents_details_'.$GroupID);
+ $Cache->delete_value('torrent_group_'.$GroupID);
+
+ $ArtistInfo = Artists::get_artist($GroupID);
+ foreach ($ArtistInfo as $Importances => $Importance) {
+ foreach ($Importance as $Artist) {
+ $Cache->delete_value('artist_'.$Artist['id']); //Needed for at least freeleech change, if not others.
+ }
+ }
+
+ $Cache->delete_value('groups_artists_'.$GroupID);
+ }
+
+
+ /**
+ * Format the information about a torrent.
+ * @param $Data an array a subset of the following keys:
+ * Format, Encoding, HasLog, LogScore HasCue, Media, Scene, RemasterYear
+ * RemasterTitle, FreeTorrent, PersonalFL
+ * @param boolean $ShowMedia if false, Media key will be omitted
+ * @param boolean $ShowEdition if false, RemasterYear/RemasterTitle will be omitted
+ */
+ public static function torrent_info($Data, $ShowMedia = false, $ShowEdition = false) {
+ $Info = array();
+ if (!empty($Data['Format'])) { $Info[]=$Data['Format']; }
+ if (!empty($Data['Encoding'])) { $Info[]=$Data['Encoding']; }
+ if (!empty($Data['HasLog'])) {
+ $Str = 'Log';
+ if (!empty($Data['LogScore'])) {
+ $Str.=' ('.$Data['LogScore'].'%)';
+ }
+ $Info[]=$Str;
+ }
+ if (!empty($Data['HasCue'])) { $Info[]='Cue'; }
+ if ($ShowMedia && !empty($Data['Media'])) { $Info[]=$Data['Media']; }
+ if (!empty($Data['Scene'])) { $Info[]='Scene'; }
+ if ($ShowEdition) {
+ $EditionInfo = array();
+ if (!empty($Data['RemasterYear'])) { $EditionInfo[]=$Data['RemasterYear']; }
+ if (!empty($Data['RemasterTitle'])) { $EditionInfo[]=$Data['RemasterTitle']; }
+ if (count($EditionInfo)) { $Info[]=implode(' ',$EditionInfo); }
+ }
+ if ($Data['FreeTorrent'] == '1') { $Info[]='Freeleech! '; }
+ if ($Data['FreeTorrent'] == '2') { $Info[]='Neutral Leech! '; }
+ if ($Data['PersonalFL'] == 1) { $Info[]='Personal Freeleech! '; }
+ return implode(' / ', $Info);
+ }
+
+
+ /**
+ * Will freeleech / neutralleech / normalise a set of torrents
+ *
+ * @param array $TorrentIDs An array of torrents IDs to iterate over
+ * @param int $FreeNeutral 0 = normal, 1 = fl, 2 = nl
+ * @param int $FreeLeechType 0 = Unknown, 1 = Staff picks, 2 = Perma-FL (Toolbox, etc.), 3 = Vanity House
+ */
+ public static function freeleech_torrents($TorrentIDs, $FreeNeutral = 1, $FreeLeechType = 0) {
+ global $DB, $Cache, $LoggedUser;
+
+ if (!is_array($TorrentIDs)) {
+ $TorrentIDs = array($TorrentIDs);
+ }
+
+ $DB->query("UPDATE torrents SET FreeTorrent = '".$FreeNeutral."', FreeLeechType = '".$FreeLeechType
+ ."' WHERE ID IN (".implode(", ", $TorrentIDs).")");
+
+ $DB->query("SELECT ID, GroupID, info_hash FROM torrents WHERE ID IN (".implode(", ", $TorrentIDs).") ORDER BY GroupID ASC");
+ $Torrents = $DB->to_array(false, MYSQLI_NUM, false);
+ $GroupIDs = $DB->collect('GroupID');
+
+ foreach ($Torrents as $Torrent) {
+ list($TorrentID, $GroupID, $InfoHash) = $Torrent;
+ Tracker::update_tracker('update_torrent', array('info_hash' => rawurlencode($InfoHash), 'freetorrent' => $FreeNeutral));
+ $Cache->delete_value('torrent_download_'.$TorrentID);
+ Misc::write_log($LoggedUser['Username']." marked torrent ".$TorrentID." freeleech type ".$FreeLeechType."!");
+ Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], "marked as freeleech type ".$FreeLeechType."!", 0);
+ }
+
+ foreach ($GroupIDs as $GroupID) {
+ Torrents::update_hash($GroupID);
+ }
+ }
+
+ /**
+ * Convenience function to allow for passing groups to Torrents::freeleech_torrents()
+ *
+ * @param array $GroupIDs the groups in question
+ * @param int $FreeNeutral see Torrents::freeleech_torrents()
+ * @param int $FreeLeechType see Torrents::freeleech_torrents()
+ */
+ public static function freeleech_groups($GroupIDs, $FreeNeutral = 1, $FreeLeechType = 0) {
+ global $DB;
+
+ if (!is_array($GroupIDs)) {
+ $GroupIDs = array($GroupIDs);
+ }
+
+ $DB->query("SELECT ID from torrents WHERE GroupID IN (".implode(", ", $GroupIDs).")");
+ if ($DB->record_count()) {
+ $TorrentIDs = $DB->collect('ID');
+ Torrents::freeleech_torrents($TorrentIDs, $FreeNeutral, $FreeLeechType);
+ }
+ }
+
+}
+?>
diff --git a/classes/class_tracker.php b/classes/class_tracker.php
new file mode 100644
index 00000000..e27a0347
--- /dev/null
+++ b/classes/class_tracker.php
@@ -0,0 +1,73 @@
+
+// TODO: Turn this into a class with nice functions like update_user, delete_torrent, etc.
+class Tracker {
+ /**
+ * Send a GET request over a socket directly to the tracker
+ * For example, Tracker::update_tracker('change_passkey', array('oldpasskey' => OLD_PASSKEY, 'newpasskey' => NEW_PASSKEY)) will send the request:
+ * GET /tracker_32_char_secret_code/update?action=change_passkey&oldpasskey=OLD_PASSKEY&newpasskey=NEW_PASSKEY HTTP/1.1
+ *
+ * @param string $Action The action to send
+ * @param array $Updates An associative array of key->value pairs to send to the tracker
+ * @param boolean $ToIRC Sends a message to the channel #tracker with the GET URL.
+ */
+ function update_tracker($Action, $Updates, $ToIRC = false) {
+ global $Cache;
+ //Build request
+ $Get = '/update?action='.$Action;
+ foreach ($Updates as $Key => $Value) {
+ $Get .= '&'.$Key.'='.$Value;
+ }
+
+ if ($ToIRC != false) {
+ send_irc('PRIVMSG #tracker :'.$Get);
+ }
+ $Path = TRACKER_SECRET.$Get;
+
+ $Return = "";
+ $Attempts = 0;
+ while ($Return != "success" && $Attempts < 3) {
+
+ // Send update
+ $File = fsockopen(TRACKER_HOST, TRACKER_PORT, $ErrorNum, $ErrorString);
+ if ($File) {
+ $Header = 'GET /'.$Path.' HTTP/1.1\r\n';
+ if (fwrite($File, $Header) === false) {
+ $Attempts++;
+ $Err = "Failed to fwrite()";
+ sleep(3);
+ continue;
+ }
+ } else {
+ $Attempts++;
+ $Err = "Failed to fsockopen() - ".$ErrorNum." - ".$ErrorString;
+ sleep(6);
+ continue;
+ }
+
+ // Check for response.
+
+ $ResHeader = '';
+ do {
+ $ResHeader .= fread($File, 1);
+ } while (!feof($File) && !Misc::ends_with($ResHeader, "\r\n\r\n"));
+
+ $Response = '';
+ while($Line = fgets($File)) {
+ $Response .= $Line;
+ }
+
+ $Return = chop($Response);
+ $Attempts++;
+ }
+
+ if ($Return != "success") {
+ send_irc("PRIVMSG #tracker :{$Attempts} {$Err} {$Get}");
+ if ($Cache->get_value('ocelot_error_reported') === false) {
+ send_irc("PRIVMSG ".ADMIN_CHAN." :Failed to update ocelot: ".$Err." : ".$Get);
+ $Cache->cache_value('ocelot_error_reported', true, 900);
+ }
+ }
+ return ($Return == "success");
+ }
+}
+?>
diff --git a/classes/class_users.php b/classes/class_users.php
new file mode 100644
index 00000000..4d30700f
--- /dev/null
+++ b/classes/class_users.php
@@ -0,0 +1,452 @@
+
+class Users {
+ /**
+ * Get $Classes (list of classes keyed by ID) and $ClassLevels
+ * (list of classes keyed by level)
+ * @return array ($Classes, $ClassLevels)
+ */
+ public static function get_classes() {
+ global $Cache, $DB, $Debug;
+ // Get permissions
+ list($Classes, $ClassLevels) = $Cache->get_value('classes');
+ if (!$Classes || !$ClassLevels) {
+ $DB->query('SELECT ID, Name, Level, Secondary FROM permissions ORDER BY Level');
+ $Classes = $DB->to_array('ID');
+ $ClassLevels = $DB->to_array('Level');
+ $Cache->cache_value('classes', array($Classes, $ClassLevels), 0);
+ }
+ $Debug->set_flag('Loaded permissions');
+
+ return array($Classes, $ClassLevels);
+ }
+
+
+ /**
+ * Get user info, is used for the current user and usernames all over the site.
+ *
+ * @param $UserID int The UserID to get info for
+ * @return array with the following keys:
+ * int ID
+ * string Username
+ * int PermissionID
+ * array Paranoia - $Paranoia array sent to class_paranoia
+ * boolean Artist
+ * boolean Donor
+ * string Warned - When their warning expires in international time format
+ * string Avatar - URL
+ * boolean Enabled
+ * string Title
+ * string CatchupTime - When they last caught up on forums
+ * boolean Visible - If false, they don't show up on peer lists
+ * array ExtraClasses - Secondary classes.
+ * int EffectiveClass - the highest level of their main and secondary classes
+ */
+ public static function user_info($UserID) {
+ global $DB, $Cache, $Classes, $SSL;
+ $UserInfo = $Cache->get_value('user_info_'.$UserID);
+ // the !isset($UserInfo['Paranoia']) can be removed after a transition period
+ if (empty($UserInfo) || empty($UserInfo['ID']) || !isset($UserInfo['Paranoia']) || empty($UserInfo['Class'])) {
+ $OldQueryID = $DB->get_query_id();
+
+
+ $DB->query("SELECT
+ m.ID,
+ m.Username,
+ m.PermissionID,
+ m.Paranoia,
+ i.Artist,
+ i.Donor,
+ i.Warned,
+ i.Avatar,
+ m.Enabled,
+ m.Title,
+ i.CatchupTime,
+ m.Visible,
+ GROUP_CONCAT(ul.PermissionID SEPARATOR ',') AS Levels
+ FROM users_main AS m
+ INNER JOIN users_info AS i ON i.UserID=m.ID
+ LEFT JOIN users_levels AS ul ON ul.UserID = m.ID
+ WHERE m.ID='$UserID'
+ GROUP BY m.ID");
+ if ($DB->record_count() == 0) { // Deleted user, maybe?
+ $UserInfo = array('ID'=>'','Username'=>'','PermissionID'=>0,'Artist'=>false,'Donor'=>false,'Warned'=>'0000-00-00 00:00:00','Avatar'=>'','Enabled'=>0,'Title'=>'', 'CatchupTime'=>0, 'Visible'=>'1');
+
+ } else {
+ $UserInfo = $DB->next_record(MYSQLI_ASSOC, array('Paranoia', 'Title'));
+ $UserInfo['CatchupTime'] = strtotime($UserInfo['CatchupTime']);
+ $UserInfo['Paranoia'] = unserialize($UserInfo['Paranoia']);
+ if ($UserInfo['Paranoia'] === false) {
+ $UserInfo['Paranoia'] = array();
+ }
+ }
+
+
+ $UserInfo['Class'] = $Classes[$UserInfo['PermissionID']]['Level'];
+
+ if (!empty($UserInfo['Levels'])) {
+ $UserInfo['ExtraClasses'] = array_fill_keys(explode(',', $UserInfo['Levels']), 1);
+ } else {
+ $UserInfo['ExtraClasses'] = array();
+ }
+ unset($UserInfo['Levels']);
+ $EffectiveClass = $Classes[$UserInfo['PermissionID']]['Level'];
+ foreach ($UserInfo['ExtraClasses'] as $Class => $Val) {
+ $EffectiveClass = max($EffectiveClass, $Classes[$Class]['Level']);
+ }
+ $UserInfo['EffectiveClass'] = $EffectiveClass;
+
+ $Cache->cache_value('user_info_'.$UserID, $UserInfo, 2592000);
+ $DB->set_query_id($OldQueryID);
+ }
+ if (strtotime($UserInfo['Warned']) < time()) {
+ $UserInfo['Warned'] = '0000-00-00 00:00:00';
+ $Cache->cache_value('user_info_'.$UserID, $UserInfo, 2592000);
+ }
+
+ // Image proxy
+ if (check_perms('site_proxy_images') && !empty($UserInfo['Avatar'])) {
+ $UserInfo['Avatar'] = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&avatar='.$UserID.'&i='.urlencode($UserInfo['Avatar']);
+ }
+ return $UserInfo;
+ }
+
+ /**
+ * Gets the heavy user info
+ * Only used for current user
+ *
+ * @param $UserID The userid to get the information for
+ * @return fetched heavy info.
+ * Just read the goddamn code, I don't have time to comment this shit.
+ */
+ public static function user_heavy_info($UserID) {
+ global $DB, $Cache;
+ //global $Debug;
+
+ $HeavyInfo = $Cache->get_value('user_info_heavy_'.$UserID);
+
+ if (empty($HeavyInfo)) {
+
+ $DB->query("SELECT
+ m.Invites,
+ m.torrent_pass,
+ m.IP,
+ m.CustomPermissions,
+ m.can_leech AS CanLeech,
+ i.AuthKey,
+ i.RatioWatchEnds,
+ i.RatioWatchDownload,
+ i.StyleID,
+ i.StyleURL,
+ i.DisableInvites,
+ i.DisablePosting,
+ i.DisableUpload,
+ i.DisableWiki,
+ i.DisableAvatar,
+ i.DisablePM,
+ i.DisableRequests,
+ i.DisableForums,
+ i.SiteOptions,
+ i.DownloadAlt,
+ i.LastReadNews,
+ i.LastReadBlog,
+ i.RestrictedForums,
+ i.PermittedForums,
+ m.FLTokens,
+ m.PermissionID
+ FROM users_main AS m
+ INNER JOIN users_info AS i ON i.UserID=m.ID
+ WHERE m.ID='$UserID'");
+ $HeavyInfo = $DB->next_record(MYSQLI_ASSOC, array('CustomPermissions', 'SiteOptions'));
+
+ if (!empty($HeavyInfo['CustomPermissions'])) {
+ $HeavyInfo['CustomPermissions'] = unserialize($HeavyInfo['CustomPermissions']);
+ } else {
+ $HeavyInfo['CustomPermissions'] = array();
+ }
+
+ if (!empty($HeavyInfo['RestrictedForums'])) {
+ $RestrictedForums = array_map('trim', explode(',', $HeavyInfo['RestrictedForums']));
+ } else {
+ $RestrictedForums = array();
+ }
+ unset($HeavyInfo['RestrictedForums']);
+ if (!empty($HeavyInfo['PermittedForums'])) {
+ $PermittedForums = array_map('trim', explode(',', $HeavyInfo['PermittedForums']));
+ } else {
+ $PermittedForums = array();
+ }
+ unset($HeavyInfo['PermittedForums']);
+ //$Debug->log_var($PermittedForums, 'PermittedForums - User');
+
+ $DB->query("SELECT PermissionID FROM users_levels WHERE UserID = $UserID");
+ $PermIDs = $DB->collect('PermissionID');
+ foreach ($PermIDs AS $PermID) {
+ $Perms = Permissions::get_permissions($PermID);
+ if (!empty($Perms['PermittedForums'])) {
+ //$Debug->log_var("'".$Perms['PermittedForums']."'", "PermittedForums - Perm $PermID");
+ $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',',$Perms['PermittedForums'])));
+ //$Debug->log_var($PermittedForums, "PermittedForums - After Perm $PermID");
+ }
+ }
+ $Perms = Permissions::get_permissions($HeavyInfo['PermissionID']);
+ unset($HeavyInfo['PermissionID']);
+ if (!empty($Perms['PermittedForums'])) {
+ $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',',$Perms['PermittedForums'])));
+ }
+ //$Debug->log_var($PermittedForums, 'PermittedForums - Done');
+
+ if (!empty($PermittedForums) || !empty($RestrictedForums)) {
+ $HeavyInfo['CustomForums'] = array();
+ foreach ($RestrictedForums as $ForumID) {
+ $HeavyInfo['CustomForums'][$ForumID] = 0;
+ }
+ foreach ($PermittedForums as $ForumID) {
+ $HeavyInfo['CustomForums'][$ForumID] = 1;
+ }
+ } else {
+ $HeavyInfo['CustomForums'] = null;
+ }
+ //$Debug->log_var($HeavyInfo['CustomForums'], 'CustomForums');
+
+ $HeavyInfo['SiteOptions'] = unserialize($HeavyInfo['SiteOptions']);
+ if (!empty($HeavyInfo['SiteOptions'])) {
+ $HeavyInfo = array_merge($HeavyInfo, $HeavyInfo['SiteOptions']);
+ }
+ unset($HeavyInfo['SiteOptions']);
+
+ $Cache->cache_value('user_info_heavy_'.$UserID, $HeavyInfo, 0);
+ }
+ return $HeavyInfo;
+ }
+
+ /**
+ * Updates the site options in the database
+ *
+ * @param int $UserID the UserID to set the options for
+ * @param array $NewOptions the new options to set
+ * @return false if $NewOptions is empty, true otherwise
+ */
+ public static function update_site_options($UserID, $NewOptions) {
+ if (!is_number($UserID)) {
+ error(0);
+ }
+ if (empty($NewOptions)) {
+ return false;
+ }
+ global $DB, $Cache, $LoggedUser;
+
+ // Get SiteOptions
+ $DB->query("SELECT SiteOptions FROM users_info WHERE UserID = $UserID");
+ list($SiteOptions) = $DB->next_record(MYSQLI_NUM,false);
+ $SiteOptions = unserialize($SiteOptions);
+
+ // Get HeavyInfo
+ $HeavyInfo = Users::user_heavy_info($UserID);
+
+ // Insert new/replace old options
+ $SiteOptions = array_merge($SiteOptions, $NewOptions);
+ $HeavyInfo = array_merge($HeavyInfo, $NewOptions);
+
+ // Update DB
+ $DB->query("UPDATE users_info SET SiteOptions = '".db_string(serialize($SiteOptions))."' WHERE UserID = $UserID");
+
+ // Update cache
+ $Cache->cache_value('user_info_heavy_'.$UserID, $HeavyInfo, 0);
+
+ // Update $LoggedUser if the options are changed for the current
+ if ($LoggedUser['ID'] == $UserID) {
+ $LoggedUser = array_merge($LoggedUser, $NewOptions);
+ $LoggedUser['ID'] = $UserID; // We don't want to allow userid switching
+ }
+ return true;
+ }
+
+
+ /**
+ * Generate a random string
+ *
+ * @param Length
+ * @return random alphanumeric string
+ */
+ public static function make_secret($Length = 32) {
+ $Secret = '';
+ $Chars='abcdefghijklmnopqrstuvwxyz0123456789';
+ $CharLen = strlen($Chars)-1;
+ for ($i = 0; $i < $Length; ++$i) {
+ $Secret .= $Chars[mt_rand(0, $CharLen)];
+ }
+ return $Secret;
+ }
+
+ /**
+ * Create a password hash. This method is deprecated and
+ * should not be used to create new passwords
+ *
+ * @param $Str password
+ * @param $Secret salt
+ * @return password hash
+ */
+ public static function make_hash($Str,$Secret) {
+ return sha1(md5($Secret).$Str.sha1($Secret).SITE_SALT);
+ }
+
+ /**
+ * Verify a password against a password hash
+ *
+ * @param $Password password
+ * @param $Hash password hash
+ * @param $Secret salt - Only used if the hash was created
+ * with the deprecated Users::make_hash() method
+ * @return true on correct password
+ */
+ public static function check_password($Password, $Hash, $Secret='') {
+ if (!$Password || !$Hash) {
+ return false;
+ }
+ if (Users::is_crypt_hash($Hash)) {
+ return crypt($Password, $Hash) == $Hash;
+ } elseif ($Secret) {
+ return Users::make_hash($Password, $Secret) == $Hash;
+ }
+ return false;
+ }
+
+ /**
+ * Test if a given hash is a crypt hash
+ *
+ * @param $Hash password hash
+ * @return true if hash is a crypt hash
+ */
+ public static function is_crypt_hash($Hash) {
+ return preg_match('/\$\d[axy]?\$/', substr($Hash, 0, 4));
+ }
+
+ /**
+ * Create salted crypt hash for a given string with
+ * settings specified in CRYPT_HASH_PREFIX
+ *
+ * @param $Str string to hash
+ * @return salted crypt hash
+ */
+ public static function make_crypt_hash($Str) {
+ $Salt = CRYPT_HASH_PREFIX.Users::gen_crypt_salt().'$';
+ return crypt($Str, $Salt);
+ }
+
+ /**
+ * Create salt string for eksblowfish hashing. If /dev/urandom cannot be read,
+ * fall back to an unsecure method based on mt_rand(). The last character needs
+ * a special case as it must be either '.', 'O', 'e', or 'u'.
+ *
+ * @return salt suitable for eksblowfish hashing
+ */
+ public static function gen_crypt_salt() {
+ $Salt = '';
+ $Chars = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ $Numchars = strlen($Chars) - 1;
+ if ($Handle = @fopen('/dev/urandom', 'r')) {
+ $Bytes = fread($Handle, 22);
+ for($i = 0; $i < 21; $i++) {
+ $Salt .= $Chars[ord($Bytes[$i]) & $Numchars];
+ }
+ $Salt[$i] = $Chars[(ord($Bytes[$i]) & 3) << 4];
+ } else {
+ for($i = 0; $i < 21; $i++) {
+ $Salt .= $Chars[mt_rand(0, $Numchars)];
+ }
+ $Salt[$i] = $Chars[mt_rand(0, 3) << 4];
+ }
+ return $Salt;
+ }
+
+ /**
+ * Returns a username string for display
+ *
+ * @param int $UserID
+ * @param boolean $Badges whether or not badges (donor, warned, enabled) should be shown
+ * @param boolean $IsWarned -- TODO: Why the fuck do we need this?
+ * @param boolean $IsEnabled -- TODO: Why the fuck do we need this?
+ * @param boolean $Class whether or not to show the class
+ * @param boolean $Title whether or not to show the title
+ * @return HTML formatted username
+ */
+ public static function format_username($UserID, $Badges = false, $IsWarned = true, $IsEnabled = true, $Class = false, $Title = false) {
+ global $Classes;
+
+ // This array is a hack that should be made less retarded, but whatevs
+ // PermID => ShortForm
+ $SecondaryClasses = array(
+ );
+
+ if ($UserID == 0) {
+ return 'System';
+ }
+
+ $UserInfo = Users::user_info($UserID);
+ if ($UserInfo['Username'] == '') {
+ return "Unknown [$UserID]";
+ }
+
+ $Str = '';
+
+ if ($Title) {
+ $Str .= ''.$UserInfo['Username'].' ';
+ } else {
+ $Str .= ''.$UserInfo['Username'].' ';
+ }
+
+ if ($Badges) {
+ $Str .= ($UserInfo['Donor'] == 1) ? ' ' : '';
+ }
+ $Str .= ($IsWarned && $UserInfo['Warned'] != '0000-00-00 00:00:00') ? ' ' : '';
+ $Str .= ($IsEnabled && $UserInfo['Enabled'] == 2) ? ' ' : '';
+
+ if ($Badges) {
+ $ClassesDisplay = array();
+ foreach($SecondaryClasses as $PermID => $PermHTML) {
+ if ($UserInfo['ExtraClasses'][$PermID]) {
+ $ClassesDisplay[] = ''.$PermHTML.' ';
+ }
+ }
+ if (!empty($ClassesDisplay)) {
+ $Str .= ' '.implode(' ', $ClassesDisplay);
+ }
+ }
+
+ if ($Class) {
+ if ($Title) {
+ $Str .= ' ('.Users::make_class_string($UserInfo['PermissionID']).') ';
+ } else {
+ $Str .= ' ('.Users::make_class_string($UserInfo['PermissionID']).')';
+ }
+ }
+
+ if ($Title) {
+ // Image proxy CTs
+ if (check_perms('site_proxy_images') && !empty($UserInfo['Title'])) {
+ $UserInfo['Title'] = preg_replace_callback('~src=("?)(http.+?)(["\s>])~',
+ function($Matches) {
+ return 'src='.$Matches[1].'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&i='.urlencode($Matches[2]).$Matches[3];
+ },
+ $UserInfo['Title']);
+ }
+
+ if ($UserInfo['Title']) {
+ $Str .= ' ('.$UserInfo['Title'].') ';
+ }
+ }
+ return $Str;
+ }
+
+ /**
+ * Given a class ID, return its name.
+ *
+ * @param int $ClassID
+ * @return string name
+ */
+ public static function make_class_string($ClassID) {
+ global $Classes;
+ return $Classes[$ClassID]['Name'];
+ }
+}
+?>
diff --git a/classes/class_view.php b/classes/class_view.php
new file mode 100644
index 00000000..73167097
--- /dev/null
+++ b/classes/class_view.php
@@ -0,0 +1,73 @@
+
+class View {
+ /**
+ * This function is to include the header file on a page.
+ *
+ * @param $PageTitle the title of the page
+ * @param $JSIncludes is a comma separated list of js files to be inclides on
+ * the page, ONLY PUT THE RELATIVE LOCATION WITHOUT .js
+ * ex: 'somefile,somdire/somefile'
+ */
+ public static function show_header($PageTitle='',$JSIncludes='') {
+ global $Document, $Cache, $DB, $LoggedUser, $Mobile, $Classes;
+
+ if($PageTitle!='') { $PageTitle.=' :: '; }
+ $PageTitle .= SITE_NAME;
+
+ if(!is_array($LoggedUser) || empty($LoggedUser['ID'])) {
+ require(SERVER_ROOT.'/design/publicheader.php');
+ } else {
+ require(SERVER_ROOT.'/design/privateheader.php');
+ }
+ }
+
+ /**
+ * This function is to include the footer file on a page.
+ *
+ * @param $Options an optional array that you can pass information to the
+ * header through as well as setup certain limitations
+ * Here is a list of parameters that work in the $Options array:
+ * ['disclaimer'] = [boolean] (False) Displays the disclaimer in the footer
+ */
+ public static function show_footer($Options=array()) {
+ global $ScriptStartTime, $LoggedUser, $Cache, $DB, $SessionID, $UserSessions, $Debug, $Time;
+ if (!is_array($LoggedUser)) { require(SERVER_ROOT.'/design/publicfooter.php'); }
+ else { require(SERVER_ROOT.'/design/privatefooter.php'); }
+ }
+
+
+ /**
+ * This is a generic function to load a template fromm /design and render it.
+ * The template should be in /design/my_template_name.php, and have a class
+ * in it called MyTemplateNameTemplate (my_template_name transformed to
+ * MixedCase, with the word 'Template' appended).
+ * This class should have a public static function render($Args), where
+ * $Args is an associative array of the template variables.
+ * You should note that by "Template", we mean "php file that outputs stuff".
+ *
+ * This function loads /design/$TemplateName.php, and then calls
+ * render($Args) on the class.
+ *
+ * @param string $TemplateName The name of the template, in underscore_format
+ * @param array $Args the arguments passed to the template.
+ */
+ public static function render_template($TemplateName, $Args) {
+ static $LoadedTemplates; // Keep track of templates we've already loaded.
+ $ClassName = '';
+ if (isset($LoadedTemplates[$TemplateName])) {
+ $ClassName = $LoadedTemplates[$TemplateName];
+ } else {
+ include(SERVER_ROOT.'/design/' . $TemplateName . '.php');
+
+ // Turn template_name into TemplateName
+ $ClassNameParts = explode('_', $TemplateName);
+ foreach ($ClassNameParts as $Index => $Part) {
+ $ClassNameParts[$Index] = ucfirst($Part);
+ }
+ $ClassName = implode($ClassNameParts). 'Template';
+ $LoadedTemplates[$TemplateName] = $ClassName;
+ }
+ $ClassName::render($Args);
+ }
+}
+?>
diff --git a/classes/class_zip.php b/classes/class_zip.php
index d9cddfe9..a561f960 100644
--- a/classes/class_zip.php
+++ b/classes/class_zip.php
@@ -61,7 +61,7 @@
require('classes/class_zip.php');
$Zip = new ZIP('FileName');
$Name = 'Ubuntu-8.10';
-$Zip->add_file($TorrentData, 'Torrents/'.file_string($Name).'.torrent');
+$Zip->add_file($TorrentData, 'Torrents/'.Misc::file_string($Name).'.torrent');
$Zip->add_file(file_get_contents('zip.php'), 'zip.php');
$Zip->close_stream();
diff --git a/classes/script_start.php b/classes/script_start.php
index 147b0eeb..90ba7b2e 100644
--- a/classes/script_start.php
+++ b/classes/script_start.php
@@ -13,23 +13,40 @@
require 'config.php'; //The config contains all site wide configuration information
//Deal with dumbasses
-if(isset($_REQUEST['info_hash']) && isset($_REQUEST['peer_id'])) { die('d14:failure reason40:Invalid .torrent, try downloading again.e'); }
+if (isset($_REQUEST['info_hash']) && isset($_REQUEST['peer_id'])) { die('d14:failure reason40:Invalid .torrent, try downloading again.e'); }
require(SERVER_ROOT.'/classes/class_proxies.php');
-if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && proxyCheck($_SERVER['REMOTE_ADDR']) && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
+
+// Get the user's actual IP address if they're proxied.
+if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])
+ && proxyCheck($_SERVER['REMOTE_ADDR'])
+ && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'],
+ FILTER_VALIDATE_IP,
+ FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
-$SSL = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443);
-if (!isset($argv) && !empty($_SERVER['HTTP_HOST'])) { //Skip this block if running from cli or if the browser is old and shitty
- if (!$SSL && $_SERVER['HTTP_HOST'] == 'www.'.NONSSL_SITE_URL) { header('Location: http://'.NONSSL_SITE_URL.$_SERVER['REQUEST_URI']); die(); }
- if ($SSL && $_SERVER['HTTP_HOST'] == 'www.'.NONSSL_SITE_URL) { header('Location: https://'.SSL_SITE_URL.$_SERVER['REQUEST_URI']); die(); }
- if(SSL_SITE_URL != NONSSL_SITE_URL) {
- if (!$SSL && $_SERVER['HTTP_HOST'] == SSL_SITE_URL) { header('Location: https://'.SSL_SITE_URL.$_SERVER['REQUEST_URI']); die(); }
- if ($SSL && $_SERVER['HTTP_HOST'] == NONSSL_SITE_URL) { header('Location: https://'.SSL_SITE_URL.$_SERVER['REQUEST_URI']); die(); }
+$SSL = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443);
+if (!isset($argv) && !empty($_SERVER['HTTP_HOST'])) {
+//Skip this block if running from cli or if the browser is old and shitty
+ if (!$SSL && $_SERVER['HTTP_HOST'] == 'www.'.NONSSL_SITE_URL) {
+ header('Location: http://'.NONSSL_SITE_URL.$_SERVER['REQUEST_URI']); die();
+ }
+ if ($SSL && $_SERVER['HTTP_HOST'] == 'www.'.NONSSL_SITE_URL) {
+ header('Location: https://'.SSL_SITE_URL.$_SERVER['REQUEST_URI']); die();
+ }
+ if (SSL_SITE_URL != NONSSL_SITE_URL) {
+ if (!$SSL && $_SERVER['HTTP_HOST'] == SSL_SITE_URL) {
+ header('Location: https://'.SSL_SITE_URL.$_SERVER['REQUEST_URI']); die();
+ }
+ if ($SSL && $_SERVER['HTTP_HOST'] == NONSSL_SITE_URL) {
+ header('Location: https://'.SSL_SITE_URL.$_SERVER['REQUEST_URI']); die();
+ }
+ }
+ if ($_SERVER['HTTP_HOST'] == 'www.m.'.NONSSL_SITE_URL) {
+ header('Location: http://m.'.NONSSL_SITE_URL.$_SERVER['REQUEST_URI']); die();
}
- if($_SERVER['HTTP_HOST'] == 'www.m.'.NONSSL_SITE_URL) { header('Location: http://m.'.NONSSL_SITE_URL.$_SERVER['REQUEST_URI']); die(); }
}
@@ -48,6 +65,7 @@
require(SERVER_ROOT.'/classes/class_search.php'); //Require the searching class
require(SERVER_ROOT.'/classes/class_paranoia.php'); //Require the paranoia check_paranoia function
require(SERVER_ROOT.'/classes/regex.php');
+require(SERVER_ROOT.'/classes/util.php');
$Debug = new DEBUG;
$Debug->handle_errors();
@@ -59,6 +77,52 @@
$UA = new USER_AGENT;
$SS = new SPHINX_SEARCH;
+// Autoload classes.
+
+spl_autoload_register(function ($ClassName) {
+ $FileName='';
+ switch ($ClassName) {
+ case 'Artists':
+ $FileName = 'class_artists';
+ break;
+ case 'Format':
+ $FileName = 'class_format';
+ break;
+ case 'Misc':
+ $FileName = 'class_misc';
+ break;
+ case 'Permissions':
+ $FileName = 'class_permissions';
+ break;
+ case 'Requests':
+ $FileName = 'class_requests';
+ break;
+ case 'SphinxQL':
+ case 'SphinxQL_Query':
+ case 'SphinxQL_Result':
+ $FileName = 'class_sphinxql';
+ break;
+ case 'Tracker':
+ $FileName = 'class_tracker';
+ break;
+ case 'Tools':
+ $FileName = 'class_tools';
+ break;
+ case 'Torrents':
+ $FileName = 'class_torrents';
+ break;
+ case 'Users':
+ $FileName = 'class_users';
+ break;
+ case 'View':
+ $FileName = 'class_view';
+ break;
+ default:
+ die("Couldn't import class " . $ClassName);
+ }
+ require_once(SERVER_ROOT.'/classes/' . $FileName . '.php');
+});
+
//Begin browser identification
@@ -70,19 +134,11 @@
$Debug->set_flag('start user handling');
-// Get permissions
-list($Classes, $ClassLevels) = $Cache->get_value('classes');
-if(!$Classes || !$ClassLevels) {
- $DB->query('SELECT ID, Name, Level, Secondary FROM permissions ORDER BY Level');
- $Classes = $DB->to_array('ID');
- $ClassLevels = $DB->to_array('Level');
- $Cache->cache_value('classes', array($Classes, $ClassLevels), 0);
-}
-$Debug->set_flag('Loaded permissions');
+// Get classes
+// TODO: Remove these globals, replace by calls into Users
+list($Classes, $ClassLevels) = Users::get_classes();
-//-----------------------------------------------------------------------------------
-/////////////////////////////////////////////////////////////////////////////////////
-//-- Load user information ----------------------------------------------------------
+//-- Load user information
// User info is broken up into many sections
// Heavy - Things that the site never has to look at if the user isn't logged in (as opposed to things like the class, donor status, etc)
// Light - Things that appear in format_user
@@ -92,7 +148,7 @@
// Permissions
if (isset($_COOKIE['session'])) { $LoginCookie=$Enc->decrypt($_COOKIE['session']); }
-if(isset($LoginCookie)) {
+if (isset($LoginCookie)) {
list($SessionID, $LoggedUser['ID'])=explode("|~|",$Enc->decrypt($LoginCookie));
$LoggedUser['ID'] = (int)$LoggedUser['ID'];
@@ -101,9 +157,9 @@
if (!$LoggedUser['ID'] || !$SessionID) {
logout();
}
-
+
$UserSessions = $Cache->get_value('users_sessions_'.$UserID);
- if(!is_array($UserSessions)) {
+ if (!is_array($UserSessions)) {
$DB->query("SELECT
SessionID,
Browser,
@@ -121,10 +177,10 @@
if (!array_key_exists($SessionID,$UserSessions)) {
logout();
}
-
+
// Check if user is enabled
$Enabled = $Cache->get_value('enabled_'.$LoggedUser['ID']);
- if($Enabled === false) {
+ if ($Enabled === false) {
$DB->query("SELECT Enabled FROM users_main WHERE ID='$LoggedUser[ID]'");
list($Enabled)=$DB->next_record();
$Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
@@ -138,18 +194,18 @@
// Up/Down stats
$UserStats = $Cache->get_value('user_stats_'.$LoggedUser['ID']);
- if(!is_array($UserStats)) {
+ if (!is_array($UserStats)) {
$DB->query("SELECT Uploaded AS BytesUploaded, Downloaded AS BytesDownloaded, RequiredRatio FROM users_main WHERE ID='$LoggedUser[ID]'");
$UserStats = $DB->next_record(MYSQLI_ASSOC);
$Cache->cache_value('user_stats_'.$LoggedUser['ID'], $UserStats, 3600);
}
// Get info such as username
- $LightInfo = user_info($LoggedUser['ID']);
- $HeavyInfo = user_heavy_info($LoggedUser['ID']);
+ $LightInfo = Users::user_info($LoggedUser['ID']);
+ $HeavyInfo = Users::user_heavy_info($LoggedUser['ID']);
// Get user permissions
- $Permissions = get_permissions($LightInfo['PermissionID']);
+ $Permissions = Permissions::get_permissions($LightInfo['PermissionID']);
// Create LoggedUser array
$LoggedUser = array_merge($HeavyInfo, $LightInfo, $Permissions, $UserStats);
@@ -162,7 +218,7 @@
time() < strtotime($LoggedUser['RatioWatchEnds']) &&
($LoggedUser['BytesDownloaded']*$LoggedUser['RequiredRatio'])>$LoggedUser['BytesUploaded']
);
- if(!isset($LoggedUser['ID'])) {
+ if (!isset($LoggedUser['ID'])) {
$Debug->log_var($LightInfo, 'LightInfo');
$Debug->log_var($HeavyInfo, 'HeavyInfo');
$Debug->log_var($Permissions, 'Permissions');
@@ -170,16 +226,16 @@
}
//Load in the permissions
- $LoggedUser['Permissions'] = get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
-
+ $LoggedUser['Permissions'] = Permissions::get_permissions_for_user($LoggedUser['ID'], $LoggedUser['CustomPermissions']);
+
//Change necessary triggers in external components
$Cache->CanClear = check_perms('admin_clear_cache');
-
+
// Because we <3 our staff
if (check_perms('site_disable_ip_history')) { $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; }
// Update LastUpdate every 10 minutes
- if(strtotime($UserSessions[$SessionID]['LastUpdate'])+600query("UPDATE users_main SET LastAccess='".sqltime()."' WHERE ID='$LoggedUser[ID]'");
$DB->query("UPDATE users_sessions SET IP='".$_SERVER['REMOTE_ADDR']."', Browser='".$Browser."', OperatingSystem='".$OperatingSystem."', LastUpdate='".sqltime()."' WHERE UserID='$LoggedUser[ID]' AND SessionID='".db_string($SessionID)."'");
$Cache->begin_transaction('users_sessions_'.$UserID);
@@ -193,28 +249,28 @@
));
$Cache->commit_transaction(0);
}
-
+
// Notifications
- if(isset($LoggedUser['Permissions']['site_torrents_notify'])) {
+ if (isset($LoggedUser['Permissions']['site_torrents_notify'])) {
$LoggedUser['Notify'] = $Cache->get_value('notify_filters_'.$LoggedUser['ID']);
- if(!is_array($LoggedUser['Notify'])) {
+ if (!is_array($LoggedUser['Notify'])) {
$DB->query("SELECT ID, Label FROM users_notify_filters WHERE UserID='$LoggedUser[ID]'");
$LoggedUser['Notify'] = $DB->to_array('ID');
$Cache->cache_value('notify_filters_'.$LoggedUser['ID'], $LoggedUser['Notify'], 2592000);
}
}
-
+
// We've never had to disable the wiki privs of anyone.
if ($LoggedUser['DisableWiki']) {
unset($LoggedUser['Permissions']['site_edit_wiki']);
}
-
+
// IP changed
- if($LoggedUser['IP'] != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
+ if ($LoggedUser['IP'] != $_SERVER['REMOTE_ADDR'] && !check_perms('site_disable_ip_history')) {
- if(site_ban_ip($_SERVER['REMOTE_ADDR'])) {
+ if (Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
error('Your IP has been banned.');
}
@@ -229,7 +285,7 @@
(UserID, IP, StartTime) VALUES
('$LoggedUser[ID]', '$NewIP', '".sqltime()."')");
- $ipcc = geoip($NewIP);
+ $ipcc = Tools::geoip($NewIP);
$DB->query("UPDATE users_main SET IP='$NewIP', ipcc='".$ipcc."' WHERE ID='$LoggedUser[ID]'");
$Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
$Cache->update_row(false, array('IP' => $_SERVER['REMOTE_ADDR']));
@@ -237,9 +293,9 @@
}
+
-
-
+
// Get stylesheets
$Stylesheets = $Cache->get_value('stylesheets');
if (!is_array($Stylesheets)) {
@@ -250,8 +306,8 @@
//A9 TODO: Clean up this messy solution
$LoggedUser['StyleName']=$Stylesheets[$LoggedUser['StyleID']]['Name'];
-
- if(empty($LoggedUser['Username'])) {
+
+ if (empty($LoggedUser['Username'])) {
logout(); // Ghost
}
}
@@ -261,439 +317,6 @@
$Debug->set_flag('start function definitions');
-/**
- * Get cached user info, is used for the user loading the page and usernames all over the site
- *
- * @param $UserID int The UserID to get info for
- */
-function user_info($UserID) {
- global $DB, $Cache, $Classes, $SSL;
- $UserInfo = $Cache->get_value('user_info_'.$UserID);
- // the !isset($UserInfo['Paranoia']) can be removed after a transition period
- if(empty($UserInfo) || empty($UserInfo['ID']) || !isset($UserInfo['Paranoia']) || empty($UserInfo['Class'])) {
- $OldQueryID = $DB->get_query_id();
-
-
- $DB->query("SELECT
- m.ID,
- m.Username,
- m.PermissionID,
- m.Paranoia,
- i.Artist,
- i.Donor,
- i.Warned,
- i.Avatar,
- m.Enabled,
- m.Title,
- i.CatchupTime,
- m.Visible,
- GROUP_CONCAT(ul.PermissionID SEPARATOR ',') AS Levels
- FROM users_main AS m
- INNER JOIN users_info AS i ON i.UserID=m.ID
- LEFT JOIN users_levels AS ul ON ul.UserID = m.ID
- WHERE m.ID='$UserID'
- GROUP BY m.ID");
- if($DB->record_count() == 0) { // Deleted user, maybe?
- $UserInfo = array('ID'=>'','Username'=>'','PermissionID'=>0,'Artist'=>false,'Donor'=>false,'Warned'=>'0000-00-00 00:00:00','Avatar'=>'','Enabled'=>0,'Title'=>'', 'CatchupTime'=>0, 'Visible'=>'1');
-
- } else {
- $UserInfo = $DB->next_record(MYSQLI_ASSOC, array('Paranoia', 'Title'));
- $UserInfo['CatchupTime'] = strtotime($UserInfo['CatchupTime']);
- $UserInfo['Paranoia'] = unserialize($UserInfo['Paranoia']);
- if($UserInfo['Paranoia'] === false) {
- $UserInfo['Paranoia'] = array();
- }
- }
-
- $UserInfo['Class'] = $Classes[$UserInfo['PermissionID']]['Level'];
-
- if (!empty($UserInfo['Levels'])) {
- $UserInfo['ExtraClasses'] = array_fill_keys(explode(',', $UserInfo['Levels']), 1);
- } else {
- $UserInfo['ExtraClasses'] = array();
- }
- unset($UserInfo['Levels']);
- $EffectiveClass = $Classes[$UserInfo['PermissionID']]['Level'];
- foreach($UserInfo['ExtraClasses'] as $Class => $Val) {
- $EffectiveClass = max($EffectiveClass, $Classes[$Class]['Level']);
- }
- $UserInfo['EffectiveClass'] = $EffectiveClass;
-
- $Cache->cache_value('user_info_'.$UserID, $UserInfo, 2592000);
- $DB->set_query_id($OldQueryID);
- }
- if(strtotime($UserInfo['Warned']) < time()) {
- $UserInfo['Warned'] = '0000-00-00 00:00:00';
- $Cache->cache_value('user_info_'.$UserID, $UserInfo, 2592000);
- }
-
- // Image proxy
- if(check_perms('site_proxy_images') && !empty($UserInfo['Avatar'])) {
- $UserInfo['Avatar'] = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&avatar='.$UserID.'&i='.urlencode($UserInfo['Avatar']);
- }
- return $UserInfo;
-}
-
-/**
- * Gets the heavy user info
- * Only used for current user
- * @param $UserID The userid to get the information for
- * @return fetched heavy info
- */
-function user_heavy_info($UserID) {
- global $DB, $Cache;
- //global $Debug;
-
- $HeavyInfo = $Cache->get_value('user_info_heavy_'.$UserID);
-
- if(empty($HeavyInfo)) {
-
- $DB->query("SELECT
- m.Invites,
- m.torrent_pass,
- m.IP,
- m.CustomPermissions,
- m.can_leech AS CanLeech,
- i.AuthKey,
- i.RatioWatchEnds,
- i.RatioWatchDownload,
- i.StyleID,
- i.StyleURL,
- i.DisableInvites,
- i.DisablePosting,
- i.DisableUpload,
- i.DisableWiki,
- i.DisableAvatar,
- i.DisablePM,
- i.DisableRequests,
- i.DisableForums,
- i.SiteOptions,
- i.DownloadAlt,
- i.LastReadNews,
- i.LastReadBlog,
- i.RestrictedForums,
- i.PermittedForums,
- m.FLTokens,
- m.PermissionID
- FROM users_main AS m
- INNER JOIN users_info AS i ON i.UserID=m.ID
- WHERE m.ID='$UserID'");
- $HeavyInfo = $DB->next_record(MYSQLI_ASSOC, array('CustomPermissions', 'SiteOptions'));
-
- if (!empty($HeavyInfo['CustomPermissions'])) {
- $HeavyInfo['CustomPermissions'] = unserialize($HeavyInfo['CustomPermissions']);
- } else {
- $HeavyInfo['CustomPermissions'] = array();
- }
-
- if (!empty($HeavyInfo['RestrictedForums'])) {
- $RestrictedForums = array_map('trim', explode(',', $HeavyInfo['RestrictedForums']));
- } else {
- $RestrictedForums = array();
- }
- unset($HeavyInfo['RestrictedForums']);
- if (!empty($HeavyInfo['PermittedForums'])) {
- $PermittedForums = array_map('trim', explode(',', $HeavyInfo['PermittedForums']));
- } else {
- $PermittedForums = array();
- }
- unset($HeavyInfo['PermittedForums']);
- //$Debug->log_var($PermittedForums, 'PermittedForums - User');
-
- $DB->query("SELECT PermissionID FROM users_levels WHERE UserID = $UserID");
- $PermIDs = $DB->collect('PermissionID');
- foreach ($PermIDs AS $PermID) {
- $Perms = get_permissions($PermID);
- if(!empty($Perms['PermittedForums'])) {
- //$Debug->log_var("'".$Perms['PermittedForums']."'", "PermittedForums - Perm $PermID");
- $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',',$Perms['PermittedForums'])));
- //$Debug->log_var($PermittedForums, "PermittedForums - After Perm $PermID");
- }
- }
- $Perms = get_permissions($HeavyInfo['PermissionID']);
- unset($HeavyInfo['PermissionID']);
- if(!empty($Perms['PermittedForums'])) {
- $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',',$Perms['PermittedForums'])));
- }
- //$Debug->log_var($PermittedForums, 'PermittedForums - Done');
-
- if (!empty($PermittedForums) || !empty($RestrictedForums)) {
- $HeavyInfo['CustomForums'] = array();
- foreach ($RestrictedForums as $ForumID) {
- $HeavyInfo['CustomForums'][$ForumID] = 0;
- }
- foreach ($PermittedForums as $ForumID) {
- $HeavyInfo['CustomForums'][$ForumID] = 1;
- }
- } else {
- $HeavyInfo['CustomForums'] = null;
- }
- //$Debug->log_var($HeavyInfo['CustomForums'], 'CustomForums');
-
- $HeavyInfo['SiteOptions'] = unserialize($HeavyInfo['SiteOptions']);
- if(!empty($HeavyInfo['SiteOptions'])) {
- $HeavyInfo = array_merge($HeavyInfo, $HeavyInfo['SiteOptions']);
- }
- unset($HeavyInfo['SiteOptions']);
-
- $Cache->cache_value('user_info_heavy_'.$UserID, $HeavyInfo, 0);
- }
- return $HeavyInfo;
-}
-
-/**
- * Updates the site options in the database
- *
- * @param $UserID the UserID to set the options for
- * @param $NewOptions the new options to set
- * @return false if $NewOptions is empty, otherwise void.
- */
-function update_site_options($UserID, $NewOptions) {
- if(!is_number($UserID)) {
- error(0);
- }
- if(empty($NewOptions)) {
- return false;
- }
- global $DB, $Cache, $LoggedUser;
-
- // Get SiteOptions
- $DB->query("SELECT SiteOptions FROM users_info WHERE UserID = $UserID");
- list($SiteOptions) = $DB->next_record(MYSQLI_NUM,false);
- $SiteOptions = unserialize($SiteOptions);
-
- // Get HeavyInfo
- $HeavyInfo = user_heavy_info($UserID);
-
- // Insert new/replace old options
- $SiteOptions = array_merge($SiteOptions, $NewOptions);
- $HeavyInfo = array_merge($HeavyInfo, $NewOptions);
-
- // Update DB
- $DB->query("UPDATE users_info SET SiteOptions = '".db_string(serialize($SiteOptions))."' WHERE UserID = $UserID");
-
- // Update cache
- $Cache->cache_value('user_info_heavy_'.$UserID, $HeavyInfo, 0);
-
- // Update $LoggedUser if the options are changed for the current
- if($LoggedUser['ID'] == $UserID) {
- $LoggedUser = array_merge($LoggedUser, $NewOptions);
- $LoggedUser['ID'] = $UserID; // We don't want to allow userid switching
- }
-}
-
-/**
- * Gets the permissions associated with a certain permissionid
- *
- * @param $PermissionID the kind of permissions to fetch
- * @return permissions
- */
-function get_permissions($PermissionID) {
- global $DB, $Cache;
- $Permission = $Cache->get_value('perm_'.$PermissionID);
- if(empty($Permission)) {
- $DB->query("SELECT p.Level AS Class, p.Values as Permissions, p.Secondary, p.PermittedForums FROM permissions AS p WHERE ID='$PermissionID'");
- $Permission = $DB->next_record(MYSQLI_ASSOC, array('Permissions'));
- $Permission['Permissions'] = unserialize($Permission['Permissions']);
- $Cache->cache_value('perm_'.$PermissionID, $Permission, 2592000);
- }
- return $Permission;
-}
-
-function get_permissions_for_user($UserID, $CustomPermissions = false) {
- global $DB;
-
- $UserInfo = user_info($UserID);
-
- if ($CustomPermissions === false) {
- $DB->query('SELECT um.CustomPermissions FROM users_main AS um WHERE um.ID = '.((int)$UserID));
-
- list($CustomPermissions) = $DB->next_record(MYSQLI_NUM, false);
- }
-
- if (!empty($CustomPermissions) && !is_array($CustomPermissions)) {
- $CustomPermissions = unserialize($CustomPermissions);
- }
-
- $Permissions = get_permissions($UserInfo['PermissionID']);
-
-
- // Manage 'special' inherited permissions
- $BonusPerms = array();
- $BonusCollages = 0;
- foreach ($UserInfo['ExtraClasses'] as $PermID => $Value) {
- $ClassPerms = get_permissions($PermID);
- $BonusCollages += $ClassPerms['Permissions']['MaxCollages'];
- unset($ClassPerms['Permissions']['MaxCollages']);
- $BonusPerms = array_merge($BonusPerms, $ClassPerms['Permissions']);
- }
-
- if(!empty($CustomPermissions)) {
- $CustomPerms = $CustomPermissions;
- } else {
- $CustomPerms = array();
- }
-
- // This is legacy donor cruft
- if($UserInfo['Donor']) {
- $DonorPerms = get_permissions(DONOR);
- } else {
- $DonorPerms = array('Permissions' => array());
- }
-
- $MaxCollages = $Permissions['Permissions']['MaxCollages'] + $BonusCollages + $CustomPerms['MaxCollages'] + $DonorPerms['Permissions']['MaxCollages'];
- //Combine the permissions
- return array_merge($Permissions['Permissions'], $BonusPerms, $CustomPerms, $DonorPerms['Permissions'], array('MaxCollages' => $MaxCollages));
-
- //$MaxCollages = $Permissions['Permissions']['MaxCollages'] + $BonusCollages + $CustomPerms['MaxCollages'];
- //Combine the permissions
- //return array_merge($Permissions['Permissions'], $BonusPerms, $CustomPerms, array('MaxCollages' => $MaxCollages));
-}
-
-// This function is slow. Don't call it unless somebody's logging in.
-function site_ban_ip($IP) {
- global $DB, $Cache;
- $IPNum = ip2unsigned($IP);
- $IPBans = $Cache->get_value('ip_bans');
- if(!is_array($IPBans)) {
- $DB->query("SELECT ID, FromIP, ToIP FROM ip_bans");
- $IPBans = $DB->to_array(0, MYSQLI_NUM);
- $Cache->cache_value('ip_bans', $IPBans, 0);
- }
- foreach($IPBans as $Index => $IPBan) {
- list($ID, $FromIP, $ToIP) = $IPBan;
- if($IPNum >= $FromIP && $IPNum <= $ToIP) {
- return true;
- }
- }
-
- return false;
-}
-
-
-
-function ip2unsigned($IP) {
- return sprintf("%u", ip2long($IP));
-}
-
-/**
- * Geolocate an IP address using the database
- *
- * @param $IP the ip to fetch the country for
- * @return the country of origin
- */
-function geoip($IP) {
- static $IPs = array();
- if (isset($IPs[$IP])) {
- return $IPs[$IP];
- }
- $Long = ip2unsigned($IP);
- if(!$Long || $Long == 2130706433) { // No need to check cc for 127.0.0.1
- return false;
- }
- global $DB;
- $DB->query("SELECT EndIP,Code FROM geoip_country WHERE $Long >= StartIP ORDER BY StartIP DESC LIMIT 1");
- if((!list($EndIP,$Country) = $DB->next_record()) || $EndIP < $Long) {
- $Country = '?';
- }
- $IPs[$IP] = $Country;
- return $Country;
-}
-
-/**
- * Geolocate an IP address using DNS
- *
- * @param $IP the ip to fetch the country for
- * @return the country of origin
- */
-function old_geoip($IP) {
- static $Countries = array();
- if(empty($Countries[$IP])) {
- $Country = 0;
- // Reverse IP, so 127.0.0.1 becomes 1.0.0.127
- $ReverseIP = implode('.', array_reverse(explode('.', $IP)));
- $TestHost = $ReverseIP.'.country.netop.org';
- $Return = dns_get_record($TestHost, DNS_TXT);
- if (!empty($Return)) {
- $Country = $Return[0]['txt'];
- }
- if(!$Country) {
- $Return = gethostbyaddr($IP);
- $Return = explode('.',$Return);
- $Return = array_pop($Return);
- if(strlen($Return) == 2 && !is_number($Return)) {
- $Country = strtoupper($Return);
- } else {
- $Country = '?';
- }
- }
- if($Country == 'UK') { $Country = 'GB'; }
- $Countries[$IP] = $Country;
- }
- return $Countries[$IP];
-}
-
-/**
- * Gets the hostname for an ip
- * @param $ip the ip to get the hostname for
- * @return hostname fetched
- */
-function gethostbyip($ip)
-{
- $testar = explode('.',$ip);
- if (count($testar)!=4) {
- return $ip;
- }
- for ($i=0;$i<4;++$i) {
- if (!is_numeric($testar[$i])) {
- return $ip;
- }
- }
-
- $host = `host -W 1 $ip`;
- return (($host ? end ( explode (' ', $host)) : $ip));
-}
-
-
-/**
- * Gets an hostname using AJAX
- *
- * @param $IP the IP to fetch
- * @return a span with javascript code
- */
-function get_host($IP) {
- static $ID = 0;
- ++$ID;
- return 'Resolving host... ';
-}
-
-function lookup_ip($IP) {
- //TODO: use the $Cache
- $Output = explode(' ',shell_exec('host -W 1 '.escapeshellarg($IP)));
- if(count($Output) == 1 && empty($Output[0])) {
- //No output at all implies the command failed
- return '';
- }
-
- if(count($Output) != 5) {
- return false;
- } else {
- return $Output[4];
- }
-}
-
-function get_cc($IP) {
- static $ID = 0;
- ++$ID;
- return 'Resolving CC... ';
-}
-
-function display_ip($IP) {
- $Line = display_str($IP).' ('.get_cc($IP).') ';
- $Line .= '[S ]';
-
- return $Line;
-}
/**
* Log out the current session
@@ -703,7 +326,7 @@ function logout() {
setcookie('session','',time()-60*60*24*365,'/','',false);
setcookie('keeplogged','',time()-60*60*24*365,'/','',false);
setcookie('session','',time()-60*60*24*365,'/','',false);
- if($SessionID) {
+ if ($SessionID) {
$DB->query("DELETE FROM users_sessions WHERE UserID='$LoggedUser[ID]' AND SessionID='".db_string($SessionID)."'");
@@ -717,7 +340,7 @@ function logout() {
$Cache->delete_value('user_info_heavy_'.$LoggedUser['ID']);
header('Location: login.php');
-
+
die();
}
@@ -738,7 +361,7 @@ function enforce_login() {
*/
function authorize($Ajax = false) {
global $LoggedUser;
- if(empty($_REQUEST['auth']) || $_REQUEST['auth'] != $LoggedUser['AuthKey']) {
+ if (empty($_REQUEST['auth']) || $_REQUEST['auth'] != $LoggedUser['AuthKey']) {
send_irc("PRIVMSG ".LAB_CHAN." :".$LoggedUser['Username']." just failed authorize on ".$_SERVER['REQUEST_URI']." coming from ".$_SERVER['HTTP_REFERER']);
error('Invalid authorization key. Go back, refresh, and try again.', $Ajax);
return false;
@@ -746,1844 +369,24 @@ function authorize($Ajax = false) {
return true;
}
-/**
- * This function is to include the header file on a page.
- *
- * @param $PageTitle the title of the page
- * @param $JSIncludes is a comma separated list of js files to be inclides on
- * the page, ONLY PUT THE RELATIVE LOCATION WITHOUT .js
- * ex: 'somefile,somdire/somefile'
- */
-function show_header($PageTitle='',$JSIncludes='') {
- global $Document, $Cache, $DB, $LoggedUser, $Mobile, $Classes;
- if($PageTitle!='') { $PageTitle.=' :: '; }
- $PageTitle .= SITE_NAME;
-
- if(!is_array($LoggedUser) || empty($LoggedUser['ID'])) {
- require(SERVER_ROOT.'/design/publicheader.php');
- } else {
- require(SERVER_ROOT.'/design/privateheader.php');
- }
-}
-
-/**
- * This function is to include the footer file on a page.
- *
- * @param $Options an optional array that you can pass information to the
- * header through as well as setup certain limitations
- * Here is a list of parameters that work in the $Options array:
- * ['disclaimer'] = [boolean] (False) Displays the disclaimer in the footer
- */
-function show_footer($Options=array()) {
- global $ScriptStartTime, $LoggedUser, $Cache, $DB, $SessionID, $UserSessions, $Debug, $Time;
- if (!is_array($LoggedUser)) { require(SERVER_ROOT.'/design/publicfooter.php'); }
- else { require(SERVER_ROOT.'/design/privatefooter.php'); }
-}
-
-/**
- * Shorten a string
- *
- * @param $Str string to cut
- * @param $Length cut at length
- * @param $Hard force cut at length instead of at closest word
- * @param $ShowDots Show dots at the end
- * @return string formatted string
- */
-function cut_string($Str, $Length, $Hard = false, $ShowDots = true) {
- if (mb_strlen($Str, 'UTF-8') > $Length) {
- if ($Hard == 0) {
- // Not hard, cut at closest word
- $CutDesc = mb_substr($Str, 0, $Length, 'UTF-8');
- $DescArr = explode(' ', $CutDesc);
- if (count($DescArr) > 1) {
- array_pop($DescArr);
- $CutDesc = implode(' ', $DescArr);
- }
- if ($ShowDots) { $CutDesc .= '...'; }
- } else {
- $CutDesc = mb_substr($Str, 0, $Length, 'UTF-8');
- if ($ShowDots) { $CutDesc .= '...'; }
- }
- return $CutDesc;
- } else {
- return $Str;
- }
-}
-
-/**
- * Gets the CSS class corresponding to a ratio
- *
- * @param $Ratio ratio to get the css class for
- * @return string the CSS class corresponding to the ratio range
- */
-function get_ratio_color($Ratio) {
- if ($Ratio < 0.1) { return 'r00'; }
- if ($Ratio < 0.2) { return 'r01'; }
- if ($Ratio < 0.3) { return 'r02'; }
- if ($Ratio < 0.4) { return 'r03'; }
- if ($Ratio < 0.5) { return 'r04'; }
- if ($Ratio < 0.6) { return 'r05'; }
- if ($Ratio < 0.7) { return 'r06'; }
- if ($Ratio < 0.8) { return 'r07'; }
- if ($Ratio < 0.9) { return 'r08'; }
- if ($Ratio < 1) { return 'r09'; }
- if ($Ratio < 2) { return 'r10'; }
- if ($Ratio < 5) { return 'r20'; }
- return 'r50';
-}
-
-function ratio($Dividend, $Divisor, $Color = true) {
- if($Divisor == 0 && $Dividend == 0) {
- return '--';
- } elseif($Divisor == 0) {
- return '∞ ';
- }
- $Ratio = number_format(max($Dividend/$Divisor-0.005,0), 2); //Subtract .005 to floor to 2 decimals
- if($Color) {
- $Class = get_ratio_color($Ratio);
- if($Class) {
- $Ratio = ''.$Ratio.' ';
- }
- }
- return $Ratio;
-
-}
-
-function get_url($Exclude = false) {
- if($Exclude !== false) {
- $QueryItems = array();
- parse_str($_SERVER['QUERY_STRING'], $QueryItems);
-
- foreach($QueryItems AS $Key => $Val) {
- if(!in_array(strtolower($Key),$Exclude)) {
- $Query[$Key] = $Val;
- }
- }
-
- if(empty($Query)) {
- return;
- }
- return display_str(http_build_query($Query));
- } else {
- return display_str($_SERVER['QUERY_STRING']);
- }
-}
-
-/**
- * Finds what page we're on and gives it to us, as well as the LIMIT clause for SQL
- * Takes in $_GET['page'] as an additional input
- *
- * @param $PerPage Results to show per page
- *
- * @param $DefaultResult Optional, which result's page we want if no page is specified
- * If this parameter is not specified, we will default to page 1
- *
- * @return array(int,string) What page we are on, and what to use in the LIMIT section of a query
- * i.e. "SELECT [...] LIMIT $Limit;"
- */
-function page_limit($PerPage, $DefaultResult = 1) {
- if(!isset($_GET['page'])) {
- $Page = ceil($DefaultResult/$PerPage);
- if($Page == 0) $Page = 1;
- $Limit=$PerPage;
- } else {
- if(!is_number($_GET['page'])) {
- error(0);
- }
- $Page = $_GET['page'];
- if ($Page <= 0) { $Page = 1; }
- $Limit=$PerPage*$Page-$PerPage . ', ' . $PerPage;
- }
- return array($Page,$Limit);
-}
-
-// For data stored in memcached catalogues (giant arrays), eg. forum threads
-function catalogue_limit($Page,$PerPage,$CatalogueSize=500) {
- $CatalogueID = floor(($PerPage*$Page-$PerPage)/$CatalogueSize);;
- $CatalogueLimit = ($CatalogueID*$CatalogueSize).', '.$CatalogueSize;
- return array($CatalogueID,$CatalogueLimit);
-}
-
-function catalogue_select($Catalogue,$Page,$PerPage,$CatalogueSize=500) {
- return array_slice($Catalogue,(($PerPage*$Page-$PerPage)%$CatalogueSize),$PerPage,true);
-}
-
-function get_pages($StartPage,$TotalRecords,$ItemsPerPage,$ShowPages=11,$Anchor='') {
- global $Document, $Method, $Mobile;
- $Location = $Document.'.php';
- /*-- Get pages ---------------------------------------------------------------//
- This function returns a page list, given certain information about the pages.
-
- Explanation of arguments:
- * $StartPage: The current record the page you're on starts with.
- eg. if you're on page 2 of a forum thread with 25 posts per page, $StartPage is 25.
- If you're on page 1, $StartPage is 0.
- * $TotalRecords: The total number of records in the result set.
- eg. if you're on a forum thread with 152 posts, $TotalRecords is 152.
- * $ItemsPerPage: Self-explanatory. The number of records shown on each page
- eg. if there are 25 posts per forum page, $ItemsPerPage is 25.
- $ShowPages: The number of page links that are shown.
- eg. If there are 20 pages that exist, but $ShowPages is only 11, only 11 links will be shown.
- //----------------------------------------------------------------------------*/
- $StartPage = ceil($StartPage);
- $TotalPages = 0;
- if ($TotalRecords > 0) {
- $StartPage = min($StartPage, ceil($TotalRecords/$ItemsPerPage));
-
- $ShowPages--;
- $TotalPages = ceil($TotalRecords/$ItemsPerPage);
-
- if ($TotalPages > $ShowPages) {
- $StartPosition = $StartPage-round($ShowPages/2);
-
- if ($StartPosition <= 0) {
- $StartPosition = 1;
- } else {
- if ($StartPosition >= ($TotalPages-$ShowPages)) {
- $StartPosition = $TotalPages-$ShowPages;
- }
- }
-
- $StopPage = $ShowPages+$StartPosition;
-
- } else {
- $StopPage = $TotalPages;
- $StartPosition = 1;
- }
-
- $StartPosition = max($StartPosition, 1);
-
- $QueryString = get_url(array('page','post'));
- if ($QueryString != '') {
- $QueryString = '&'.$QueryString;
- }
-
- $Pages = '';
-
- if ($StartPage > 1) {
- $Pages .= '<< First ';
- $Pages .= ' | ';
- }
- //End change
-
- if (!$Mobile) {
- for ($i = $StartPosition; $i <= $StopPage; $i++) {
- //if ($i!=$StartPage) { $Pages.=''; }
- if ($i != $StartPage) {
- $Pages .= ' ';
- }
- $Pages .= "";
- if($i*$ItemsPerPage > $TotalRecords) {
- $Pages .= ((($i-1)*$ItemsPerPage)+1).'-'.($TotalRecords);
- } else {
- $Pages .= ((($i-1)*$ItemsPerPage)+1).'-'.($i*$ItemsPerPage);
- }
-
- $Pages .= " ";
- if ($i != $StartPage) {
- $Pages.=' ';
- }
- if ($i < $StopPage) {
- $Pages.=" | ";
- }
- }
- } else {
- $Pages .= $StartPage;
- }
-
- if ($StartPage && $StartPage < $TotalPages) {
- $Pages .= ' | ';
- $Pages .= ' Last >> ';
- }
-
- }
-
- if ($TotalPages > 1) {
- return $Pages;
- }
-
-}
-
-function send_email($To,$Subject,$Body,$From='noreply',$ContentType='text/plain') {
- $Headers='MIME-Version: 1.0'."\r\n";
- $Headers.='Content-type: '.$ContentType.'; charset=iso-8859-1'."\r\n";
- $Headers.='From: '.SITE_NAME.' <'.$From.'@'.NONSSL_SITE_URL.'>'."\r\n";
- $Headers.='Reply-To: '.$From.'@'.NONSSL_SITE_URL."\r\n";
- $Headers.='X-Mailer: Project Gazelle'."\r\n";
- $Headers.='Message-Id: <'.make_secret().'@'.NONSSL_SITE_URL.">\r\n";
- $Headers.='X-Priority: 3'."\r\n";
- mail($To,$Subject,$Body,$Headers,"-f ".$From."@".NONSSL_SITE_URL);
-}
-
-function get_size($Size, $Levels = 2) {
- $Units = array(' B',' KB',' MB',' GB',' TB',' PB',' EB',' ZB',' YB');
- $Size = (double) $Size;
- for($Steps = 0; abs($Size) >= 1024; $Size /= 1024, $Steps++) {}
- if(func_num_args() == 1 && $Steps >= 4) {
- $Levels++;
- }
- return number_format($Size,$Levels).$Units[$Steps];
-}
-
-function get_bytes($Size) {
- list($Value,$Unit) = sscanf($Size, "%f%s");
- $Unit = ltrim($Unit);
- if(empty($Unit)) {
- return $Value ? round($Value) : 0;
- }
- switch(strtolower($Unit[0])) {
- case 'k': return round($Value * 1024);
- case 'm': return round($Value * 1048576);
- case 'g': return round($Value * 1073741824);
- case 't': return round($Value * 1099511627776);
- default: return 0;
- }
-}
-
-function human_format($Number) {
- $Steps = 0;
- while($Number>=1000) {
- $Steps++;
- $Number=$Number/1000;
- }
- switch ($Steps) {
- case 0: return round($Number); break;
- case 1: return round($Number,2).'k'; break;
- case 2: return round($Number,2).'M'; break;
- case 3: return round($Number,2).'G'; break;
- case 4: return round($Number,2).'T'; break;
- case 5: return round($Number,2).'P'; break;
- default:
- return round($Number,2).'E + '.$Steps*3;
- }
-}
-
-function is_number($Str) {
- $Return = true;
- if ($Str < 0) { $Return = false; }
- // We're converting input to a int, then string and comparing to original
- $Return = ($Str == strval(intval($Str)) ? true : false);
- return $Return;
-}
-
-function file_string($EscapeStr) {
- return str_replace(array('"','*','/',':','<','>','?','\\','|'), '', $EscapeStr);
-}
-
-// This is preferable to htmlspecialchars because it doesn't screw up upon a double escape
-function display_str($Str) {
- if ($Str === NULL || $Str === FALSE || is_array($Str)) {
- return '';
- }
- if ($Str!='' && !is_number($Str)) {
- $Str=make_utf8($Str);
- $Str=mb_convert_encoding($Str,"HTML-ENTITIES","UTF-8");
- $Str=preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/m","&",$Str);
-
- $Replace = array(
- "'",'"',"<",">",
- '','','','','
','','','','','','','','','','','','','','','','','','','','','',''
- );
-
- $With=array(
- ''','"','<','>',
- '€','‚','ƒ','„','…','†','‡','ˆ','‰','Š','‹','Œ','Ž','‘','’','“','”','•','–','—','˜','™','š','›','œ','ž','Ÿ'
- );
-
- $Str=str_replace($Replace,$With,$Str);
- }
- return $Str;
-}
-
-// Use sparingly
-function undisplay_str($Str) {
- return mb_convert_encoding($Str, 'UTF-8', 'HTML-ENTITIES');
-}
-
-function make_utf8($Str) {
- if ($Str!="") {
- if (is_utf8($Str)) { $Encoding="UTF-8"; }
- if (empty($Encoding)) { $Encoding=mb_detect_encoding($Str,'UTF-8, ISO-8859-1'); }
- if (empty($Encoding)) { $Encoding="ISO-8859-1"; }
- if ($Encoding=="UTF-8") { return $Str; }
- else { return @mb_convert_encoding($Str,"UTF-8",$Encoding); }
- }
-}
-
-function is_utf8($Str) {
- return preg_match('%^(?:
- [\x09\x0A\x0D\x20-\x7E] // ASCII
- | [\xC2-\xDF][\x80-\xBF] // non-overlong 2-byte
- | \xE0[\xA0-\xBF][\x80-\xBF] // excluding overlongs
- | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} // straight 3-byte
- | \xED[\x80-\x9F][\x80-\xBF] // excluding surrogates
- | \xF0[\x90-\xBF][\x80-\xBF]{2} // planes 1-3
- | [\xF1-\xF3][\x80-\xBF]{3} // planes 4-15
- | \xF4[\x80-\x8F][\x80-\xBF]{2} // plane 16
- )*$%xs', $Str
- );
-}
-
-// Escape an entire array for output
-// $Escape is either true, false, or a list of array keys to not escape
-function display_array($Array, $Escape = array()) {
- foreach ($Array as $Key => $Val) {
- if((!is_array($Escape) && $Escape == true) || !in_array($Key, $Escape)) {
- $Array[$Key] = display_str($Val);
- }
- }
- return $Array;
-}
-
-// Gets a tag ready for database input and display
-function sanitize_tag($str) {
- $str = strtolower($str);
- $str = preg_replace('/[^a-z0-9.]/', '', $str);
- $str = preg_replace('/(^[.,]*)|([.,]*$)/','',$str);
- $str = htmlspecialchars($str);
- $str = db_string(trim($str));
- return $str;
-}
-
-
-/**
- * Gets the alias of the tag, if there is no alias silently returns the original tag.
- * @return the tag
- */
-function get_alias_tag($str) {
- global $DB;
- $DB->query("SELECT AliasTag FROM tag_aliases WHERE BadTag = '". $str ."' LIMIT 1");
- if($DB->record_count() > 0) {
- list($AliasTag) = $DB->next_record();
- return $AliasTag;
- }
- return $str;
-}
-
-// Generate a random string
-function make_secret($Length = 32) {
- $Secret = '';
- $Chars='abcdefghijklmnopqrstuvwxyz0123456789';
- for($i=0; $i<$Length; $i++) {
- $Rand = mt_rand(0, strlen($Chars)-1);
- $Secret .= substr($Chars, $Rand, 1);
- }
- return str_shuffle($Secret);
-}
-
-//TODO: Read and add this one
-/*
-function make_secret($Length = 32) {
- $Secret = '';
- $Chars='abcdefghijklmnopqrstuvwxyz0123456789';
- $CharLen = strlen($Chars)-1;
- for ($i = 0; $i < $Length; ++$i) {
- $Secret .= $Chars[mt_rand(0, $CharLen)];
- }
- return $Secret;
-}
-*/
-
-/**
- * Create a password hash. This method is deprecated and
- * should not be used to create new passwords
- *
- * @param $Str password
- * @param $Secret salt
- * @return password hash
- */
-function make_hash($Str,$Secret) {
- return sha1(md5($Secret).$Str.sha1($Secret).SITE_SALT);
-}
-
-/**
- * Verify a password against a password hash
- *
- * @param $Password password
- * @param $Hash password hash
- * @param $Secret salt - Only used if the hash was created
- * with the deprecated make_hash() method
- * @return true on correct password
- */
-function check_password($Password, $Hash, $Secret='') {
- if(!$Password || !$Hash) {
- return false;
- }
- if(is_crypt_hash($Hash)) {
- return crypt($Password, $Hash) == $Hash;
- } elseif($Secret) {
- return make_hash($Password, $Secret) == $Hash;
- }
- return false;
-}
-
-/**
- * Test if a given hash is a crypt hash
- *
- * @param $Hash password hash
- * @return true if hash is a crypt hash
- */
-function is_crypt_hash($Hash) {
- return preg_match('/\$\d[axy]?\$/', substr($Hash, 0, 4));
-}
-
-/**
- * Create salted crypt hash for a given string with
- * settings specified in CRYPT_HASH_PREFIX
- *
- * @param $Str string to hash
- * @return salted crypt hash
- */
-function make_crypt_hash($Str) {
- $Salt = CRYPT_HASH_PREFIX.gen_crypt_salt().'$';
- return crypt($Str, $Salt);
-}
-
-/**
- * Create salt string for eksblowfish hashing. If /dev/urandom cannot be read,
- * fall back to an unsecure method based on mt_rand(). The last character needs
- * a special case as it must be either '.', 'O', 'e', or 'u'.
- *
- * @return salt suitable for eksblowfish hashing
- */
-function gen_crypt_salt() {
- $Salt = '';
- $Chars = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- $Numchars = strlen($Chars) - 1;
- if($Handle = @fopen('/dev/urandom', 'r')) {
- $Bytes = fread($Handle, 22);
- for($i = 0; $i < 21; $i++) {
- $Salt .= $Chars[ord($Bytes[$i]) & $Numchars];
- }
- $Salt[$i] = $Chars[(ord($Bytes[$i]) & 3) << 4];
- } else {
- for($i = 0; $i < 21; $i++) {
- $Salt .= $Chars[mt_rand(0, $Numchars)];
- }
- $Salt[$i] = $Chars[mt_rand(0, 3) << 4];
- }
- return $Salt;
-}
-
-/*
-Returns a username string for display
-$Class and $Title can be omitted for an abbreviated version
-$IsDonor, $IsWarned and $IsEnabled can be omitted for a *very* abbreviated version
-*/
-function format_username($UserID, $Badges = false, $IsWarned = true, $IsEnabled = true, $Class = false, $Title = false) {
- global $Classes;
-
- // This array is a hack that should be made less retarded, but whatevs
- // PermID => ShortForm
- $SecondaryClasses = array(
- );
-
- if($UserID == 0) {
- return 'System';
- }
-
- $UserInfo = user_info($UserID);
- if($UserInfo['Username'] == '') {
- return "Unknown [$UserID]";
- }
-
- $Str = '';
-
- if ($Title) {
- $Str .= ''.$UserInfo['Username'].' ';
- } else {
- $Str .= ''.$UserInfo['Username'].' ';
- }
-
- if ($Badges) {
- $Str .= ($UserInfo['Donor'] == 1) ? ' ' : '';
- }
- $Str .= ($IsWarned && $UserInfo['Warned'] != '0000-00-00 00:00:00') ? ' ' : '';
- $Str .= ($IsEnabled && $UserInfo['Enabled'] == 2) ? ' ' : '';
-
- if ($Badges) {
- $ClassesDisplay = array();
- foreach($SecondaryClasses as $PermID => $PermHTML) {
- if ($UserInfo['ExtraClasses'][$PermID]) {
- $ClassesDisplay[] = ''.$PermHTML.' ';
- }
- }
- if(!empty($ClassesDisplay)) {
- $Str .= ' '.implode(' ', $ClassesDisplay);
- }
- }
-
- if ($Class) {
- if ($Title) {
- $Str .= ' ('.make_class_string($UserInfo['PermissionID']).') ';
- } else {
- $Str .= ' ('.make_class_string($UserInfo['PermissionID']).')';
- }
- }
-
- if ($Title) {
- // Image proxy CTs
- if(check_perms('site_proxy_images') && !empty($UserInfo['Title'])) {
- $UserInfo['Title'] = preg_replace_callback('~src=("?)(http.+?)(["\s>])~',
- function($Matches) {
- return 'src='.$Matches[1].'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&i='.urlencode($Matches[2]).$Matches[3];
- },
- $UserInfo['Title']);
- }
-
- if ($UserInfo['Title']) {
- $Str .= ' ('.$UserInfo['Title'].') ';
- }
- }
- return $Str;
-}
-
-function make_class_string($ClassID) {
- global $Classes;
- return $Classes[$ClassID]['Name'];
-}
-
-//Write to the group log
-function write_group_log($GroupID, $TorrentID, $UserID, $Message, $Hidden) {
- global $DB,$Time;
- $DB->query("INSERT INTO group_log (GroupID, TorrentID, UserID, Info, Time, Hidden) VALUES (".$GroupID.", ".$TorrentID.", ".$UserID.", '".db_string($Message)."', '".sqltime()."', ".$Hidden.")");
-}
-
-// Write a message to the system log
-function write_log($Message) {
- global $DB,$Time;
- $DB->query('INSERT INTO log (Message, Time) VALUES (\''.db_string($Message).'\', \''.sqltime().'\')');
-}
-
-// Send a message to an IRC bot listening on SOCKET_LISTEN_PORT
-function send_irc($Raw) {
- $IRCSocket = fsockopen(SOCKET_LISTEN_ADDRESS, SOCKET_LISTEN_PORT);
- $Raw = str_replace(array("\n", "\r"), '', $Raw);
- fwrite($IRCSocket, $Raw);
- fclose($IRCSocket);
-}
-
-function delete_torrent($ID, $GroupID=0, $OcelotReason=-1) {
- global $DB, $Cache, $LoggedUser;
- if(!$GroupID) {
- $DB->query("SELECT GroupID, UserID FROM torrents WHERE ID='$ID'");
- list($GroupID, $UploaderID) = $DB->next_record();
-
- }
- if(empty($UserID)) {
- $DB->query("SELECT UserID FROM torrents WHERE ID='$ID'");
- list($UserID) = $DB->next_record();
- }
-
- $RecentUploads = $Cache->get_value('recent_uploads_'.$UserID);
- if(is_array($RecentUploads)) {
- foreach($RecentUploads as $Key => $Recent) {
- if($Recent['ID'] == $GroupID) {
- $Cache->delete_value('recent_uploads_'.$UserID);
- }
- }
- }
-
-
- $DB->query("SELECT info_hash FROM torrents WHERE ID = ".$ID);
- list($InfoHash) = $DB->next_record(MYSQLI_BOTH, false);
- $DB->query("DELETE FROM torrents WHERE ID = ".$ID);
- update_tracker('delete_torrent', array('info_hash' => rawurlencode($InfoHash), 'id' => $ID, 'reason' => $OcelotReason));
-
- $Cache->decrement('stats_torrent_count');
-
- $DB->query("SELECT COUNT(ID) FROM torrents WHERE GroupID='$GroupID'");
- list($Count) = $DB->next_record();
-
- if($Count == 0) {
- delete_group($GroupID);
- } else {
- update_hash($GroupID);
- //Artists
- $DB->query("SELECT ArtistID
- FROM torrents_artists
- WHERE GroupID = ".$GroupID);
- $ArtistIDs = $DB->collect('ArtistID');
- foreach($ArtistIDs as $ArtistID) {
- $Cache->delete_value('artist_'.$ArtistID);
- }
- }
-
- // Torrent notifications
- $DB->query("SELECT UserID FROM users_notify_torrents WHERE TorrentID='$ID'");
- while(list($UserID) = $DB->next_record()) {
- $Cache->delete_value('notifications_new_'.$UserID);
- }
- $DB->query("DELETE FROM users_notify_torrents WHERE TorrentID='$ID'");
-
-
- $DB->query("UPDATE reportsv2 SET
- Status='Resolved',
- LastChangeTime='".sqltime()."',
- ModComment='Report already dealt with (Torrent deleted)'
- WHERE TorrentID=".$ID."
- AND Status != 'Resolved'");
- $Reports = $DB->affected_rows();
- if($Reports) {
- $Cache->decrement('num_torrent_reportsv2', $Reports);
- }
-
- $DB->query("DELETE FROM torrents_files WHERE TorrentID='$ID'");
- $DB->query("DELETE FROM torrents_bad_tags WHERE TorrentID = ".$ID);
- $DB->query("DELETE FROM torrents_bad_folders WHERE TorrentID = ".$ID);
- $DB->query("DELETE FROM torrents_bad_files WHERE TorrentID = ".$ID);
- $DB->query("DELETE FROM torrents_cassette_approved WHERE TorrentID = ".$ID);
- $DB->query("DELETE FROM torrents_lossymaster_approved WHERE TorrentID = ".$ID);
- $DB->query("DELETE FROM torrents_lossyweb_approved WHERE TorrentID = ".$ID);
- $Cache->delete_value('torrent_download_'.$ID);
- $Cache->delete_value('torrent_group_'.$GroupID);
- $Cache->delete_value('torrents_details_'.$GroupID);
-}
-
-function delete_group($GroupID) {
- global $DB, $Cache;
-
- write_log("Group ".$GroupID." automatically deleted (No torrents have this group).");
- //$DB->query("DELETE FROM group_log WHERE GroupID = ".$GroupID);
-
- //Never call this unless you're certain the group is no longer used by any torrents
- $DB->query("SELECT CategoryID FROM torrents_group WHERE ID='$GroupID'");
- list($Category) = $DB->next_record();
- if($Category == 1) {
- $Cache->decrement('stats_album_count');
- }
- $Cache->decrement('stats_group_count');
-
-
-
- // Collages
- $DB->query("SELECT CollageID FROM collages_torrents WHERE GroupID='$GroupID'");
- if($DB->record_count()>0) {
- $CollageIDs = $DB->collect('CollageID');
- $DB->query("UPDATE collages SET NumTorrents=NumTorrents-1 WHERE ID IN (".implode(', ',$CollageIDs).")");
- $DB->query("DELETE FROM collages_torrents WHERE GroupID='$GroupID'");
-
- foreach($CollageIDs as $CollageID) {
- $Cache->delete_value('collage_'.$CollageID);
- }
- $Cache->delete_value('torrent_collages_'.$GroupID);
- }
-
- //Artists
- //Collect the artist IDs and then wipe the torrents_artist entry
- $DB->query("SELECT ArtistID FROM torrents_artists WHERE GroupID = ".$GroupID);
- $Artists = $DB->collect('ArtistID');
-
- $DB->query("DELETE FROM torrents_artists WHERE GroupID='$GroupID'");
-
- foreach($Artists as $ArtistID) {
- if(empty($ArtistID)) { continue; }
- //Get a count of how many groups or requests use the artist ID
- $DB->query("SELECT COUNT(ag.ArtistID)
- FROM artists_group as ag
- LEFT JOIN requests_artists AS ra ON ag.ArtistID=ra.ArtistID
- WHERE ra.ArtistID IS NOT NULL
- AND ag.ArtistID = '$ArtistID'");
- list($ReqCount) = $DB->next_record();
- $DB->query("SELECT COUNT(ag.ArtistID)
- FROM artists_group as ag
- LEFT JOIN torrents_artists AS ta ON ag.ArtistID=ta.ArtistID
- WHERE ta.ArtistID IS NOT NULL
- AND ag.ArtistID = '$ArtistID'");
- list($GroupCount) = $DB->next_record();
- if(($ReqCount + $GroupCount) == 0) {
- //The only group to use this artist
- delete_artist($ArtistID);
- } else {
- //Not the only group, still need to clear cache
- $Cache->delete_value('artist_'.$ArtistID);
- }
- }
-
- // Requests
- $DB->query("SELECT ID FROM requests WHERE GroupID='$GroupID'");
- $Requests = $DB->collect('ID');
- $DB->query("UPDATE requests SET GroupID = NULL WHERE GroupID = '$GroupID'");
- foreach ($Requests as $RequestID) {
- $Cache->delete_value('request_'.$RequestID);
- }
-
- $DB->query("DELETE FROM torrents_group WHERE ID='$GroupID'");
- $DB->query("DELETE FROM torrents_tags WHERE GroupID='$GroupID'");
- $DB->query("DELETE FROM torrents_tags_votes WHERE GroupID='$GroupID'");
- $DB->query("DELETE FROM torrents_comments WHERE GroupID='$GroupID'");
- $DB->query("DELETE FROM bookmarks_torrents WHERE GroupID='$GroupID'");
- $DB->query("DELETE FROM wiki_torrents WHERE PageID='$GroupID'");
- $DB->query("REPLACE INTO sphinx_delta (ID,Time) VALUES ('$GroupID',UNIX_TIMESTAMP())"); // Tells Sphinx that the group is removed
-
- $Cache->delete_value('torrents_details_'.$GroupID);
- $Cache->delete_value('torrent_group_'.$GroupID);
- $Cache->delete_value('groups_artists_'.$GroupID);
-}
-
-function delete_artist($ArtistID) {
- global $DB, $LoggedUser, $Cache;
-
- $DB->query("SELECT Name FROM artists_group WHERE ArtistID = ".$ArtistID);
- list($Name) = $DB->next_record(MYSQLI_NUM, false);
-
- // Delete requests
- $DB->query("SELECT RequestID FROM requests_artists WHERE ArtistID=".$ArtistID." AND ArtistID != 0");
- $Requests = $DB->to_array();
- foreach($Requests AS $Request) {
- list($RequestID) = $Request;
- $DB->query('DELETE FROM requests WHERE ID='.$RequestID);
- $DB->query('DELETE FROM requests_votes WHERE RequestID='.$RequestID);
- $DB->query('DELETE FROM requests_tags WHERE RequestID='.$RequestID);
- $DB->query('DELETE FROM requests_artists WHERE RequestID='.$RequestID);
- }
-
- // Delete artist
- $DB->query('DELETE FROM artists_group WHERE ArtistID='.$ArtistID);
- $DB->query('DELETE FROM artists_alias WHERE ArtistID='.$ArtistID);
- $Cache->decrement('stats_artist_count');
-
- // Delete wiki revisions
- $DB->query('DELETE FROM wiki_artists WHERE PageID='.$ArtistID);
-
- // Delete tags
- $DB->query('DELETE FROM artists_tags WHERE ArtistID='.$ArtistID);
-
- $Cache->delete_value('artist_'.$ArtistID);
- // Record in log
-
- if(!empty($LoggedUser['Username'])) {
- $Username = $LoggedUser['Username'];
- } else {
- $Username = 'System';
- }
- write_log('Artist '.$ArtistID.' ('.$Name.') was deleted by '.$Username);
-}
-
-function warn_user($UserID, $Duration, $Reason) {
- global $LoggedUser, $DB, $Cache, $Time;
-
- $DB->query("SELECT Warned FROM users_info WHERE UserID=".$UserID." AND Warned <> '0000-00-00 00:00:00'");
- if($DB->record_count() > 0) {
- //User was already warned, appending new warning to old.
- list($OldDate) = $DB->next_record();
- $NewExpDate = date('Y-m-d H:i:s', strtotime($OldDate) + $Duration);
-
- send_pm($UserID, 0, db_string("You have received multiple warnings."), db_string("When you received your latest warning (Set to expire on ".date("Y-m-d", (time() + $Duration))."), you already had a different warning (Set to expire on ".date("Y-m-d", strtotime($OldDate)).").\n\n Due to this collision, your warning status will now expire at ".$NewExpDate."."));
-
- $AdminComment = date("Y-m-d").' - Warning (Clash) extended to expire at '.$NewExpDate.' by '.$LoggedUser['Username']."\nReason: $Reason\n\n";
-
- $DB->query('UPDATE users_info SET
- Warned=\''.db_string($NewExpDate).'\',
- WarnedTimes=WarnedTimes+1,
- AdminComment=CONCAT(\''.db_string($AdminComment).'\',AdminComment)
- WHERE UserID=\''.db_string($UserID).'\'');
- } else {
- //Not changing, user was not already warned
- $WarnTime = time_plus($Duration);
-
- $Cache->begin_transaction('user_info_'.$UserID);
- $Cache->update_row(false, array('Warned' => $WarnTime));
- $Cache->commit_transaction(0);
-
- $AdminComment = date("Y-m-d").' - Warned until '.$WarnTime.' by '.$LoggedUser['Username']."\nReason: $Reason\n\n";
-
- $DB->query('UPDATE users_info SET
- Warned=\''.db_string($WarnTime).'\',
- WarnedTimes=WarnedTimes+1,
- AdminComment=CONCAT(\''.db_string($AdminComment).'\',AdminComment)
- WHERE UserID=\''.db_string($UserID).'\'');
- }
-}
-
-/*-- update_hash function ------------------------------------------------*/
-/*------------------------------------------------------------------------*/
-/* This function is to update the cache and sphinx delta index to keep */
-/* everything up to date */
-/*-- TODO ----------------------------------------------------------------*/
-/* Add in tag sorting based on positive negative votes algo */
-/**************************************************************************/
-
-function update_hash($GroupID) {
- global $DB, $Cache;
- $DB->query("UPDATE torrents_group SET TagList=(SELECT REPLACE(GROUP_CONCAT(tags.Name SEPARATOR ' '),'.','_')
- FROM torrents_tags AS t
- INNER JOIN tags ON tags.ID=t.TagID
- WHERE t.GroupID='$GroupID'
- GROUP BY t.GroupID)
- WHERE ID='$GroupID'");
-
- $DB->query("REPLACE INTO sphinx_delta (ID, GroupName, TagList, Year, CategoryID, Time, ReleaseType, RecordLabel, CatalogueNumber, VanityHouse, Size, Snatched, Seeders, Leechers, LogScore, Scene, HasLog, HasCue, FreeTorrent, Media, Format, Encoding, RemasterYear, RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, FileList)
- SELECT
- g.ID AS ID,
- g.Name AS GroupName,
- g.TagList,
- g.Year,
- g.CategoryID,
- UNIX_TIMESTAMP(g.Time) AS Time,
- g.ReleaseType,
- g.RecordLabel,
- g.CatalogueNumber,
- g.VanityHouse,
- MAX(CEIL(t.Size/1024)) AS Size,
- SUM(t.Snatched) AS Snatched,
- SUM(t.Seeders) AS Seeders,
- SUM(t.Leechers) AS Leechers,
- MAX(t.LogScore) AS LogScore,
- MAX(t.Scene) AS Scene,
- MAX(t.HasLog) AS HasLog,
- MAX(t.HasCue) AS HasCue,
- BIT_OR(t.FreeTorrent-1) AS FreeTorrent,
- GROUP_CONCAT(DISTINCT t.Media SEPARATOR ' ') AS Media,
- GROUP_CONCAT(DISTINCT t.Format SEPARATOR ' ') AS Format,
- GROUP_CONCAT(DISTINCT t.Encoding SEPARATOR ' ') AS Encoding,
- GROUP_CONCAT(DISTINCT t.RemasterYear SEPARATOR ' ') AS RemasterYear,
- GROUP_CONCAT(DISTINCT t.RemasterTitle SEPARATOR ' ') AS RemasterTitle,
- GROUP_CONCAT(DISTINCT t.RemasterRecordLabel SEPARATOR ' ') AS RemasterRecordLabel,
- GROUP_CONCAT(DISTINCT t.RemasterCatalogueNumber SEPARATOR ' ') AS RemasterCatalogueNumber,
- GROUP_CONCAT(REPLACE(REPLACE(FileList, '|||', '\n '), '_', ' ') SEPARATOR '\n ') AS FileList
- FROM torrents AS t
- JOIN torrents_group AS g ON g.ID=t.GroupID
- WHERE g.ID=$GroupID
- GROUP BY g.ID");
-
- $DB->query("INSERT INTO sphinx_delta
- (ID, ArtistName)
- SELECT
- GroupID,
- GROUP_CONCAT(aa.Name separator ' ')
- FROM torrents_artists AS ta
- JOIN artists_alias AS aa ON aa.AliasID=ta.AliasID
- JOIN torrents_group AS tg ON tg.ID=ta.GroupID
- WHERE ta.GroupID=$GroupID AND ta.Importance IN ('1', '4', '5', '6')
- GROUP BY tg.ID
- ON DUPLICATE KEY UPDATE ArtistName=values(ArtistName)");
-
- $Cache->delete_value('torrents_details_'.$GroupID);
- $Cache->delete_value('torrent_group_'.$GroupID);
-
- $ArtistInfo = get_artist($GroupID);
- foreach($ArtistInfo as $Importances => $Importance) {
- foreach($Importance as $Artist) {
- $Cache->delete_value('artist_'.$Artist['id']); //Needed for at least freeleech change, if not others.
- }
- }
-
- $Cache->delete_value('groups_artists_'.$GroupID);
-}
-
-// this function sends a PM to the userid $ToID and from the userid $FromID, sets date to now
-// this function no longer uses db_string() so you will need to escape strings before using this function!
-// set userid to 0 for a PM from 'system'
-// if $ConvID is not set, it auto increments it, ie. starting a new conversation
-function send_pm($ToID,$FromID,$Subject,$Body,$ConvID='') {
- global $DB, $Cache, $Time;
- if($ToID == 0 || $ToID == $FromID) {
- // Don't allow users to send messages to the system or themselves
- return;
- }
- if($ConvID=='') {
- $DB->query("INSERT INTO pm_conversations(Subject) VALUES ('".$Subject."')");
- $ConvID = $DB->inserted_id();
- $DB->query("INSERT INTO pm_conversations_users
- (UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead) VALUES
- ('$ToID', '$ConvID', '1','0','".sqltime()."', '".sqltime()."', '1')");
- if ($FromID != 0) {
- $DB->query("INSERT INTO pm_conversations_users
- (UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead) VALUES
- ('$FromID', '$ConvID', '0','1','".sqltime()."', '".sqltime()."', '0')");
- }
- $ToID = array($ToID);
- } else {
- $DB->query("UPDATE pm_conversations_users SET
- InInbox='1',
- UnRead='1',
- ReceivedDate='".sqltime()."'
- WHERE UserID IN (".implode(',', $ToID).")
- AND ConvID='$ConvID'");
-
- $DB->query("UPDATE pm_conversations_users SET
- InSentbox='1',
- SentDate='".sqltime()."'
- WHERE UserID='$FromID'
- AND ConvID='$ConvID'");
- }
- $DB->query("INSERT INTO pm_messages
- (SenderID, ConvID, SentDate, Body) VALUES
- ('$FromID', '$ConvID', '".sqltime()."', '".$Body."')");
-
- // Clear the caches of the inbox and sentbox
- //$DB->query("SELECT UnRead from pm_conversations_users WHERE ConvID='$ConvID' AND UserID='$ToID'");
- foreach($ToID as $ID) {
- $DB->query("SELECT COUNT(ConvID) FROM pm_conversations_users WHERE UnRead = '1' and UserID='$ID' AND InInbox = '1'");
- list($UnRead) = $DB->next_record();
- $Cache->cache_value('inbox_new_'.$ID, $UnRead);
- }
-
- //if ($UnRead == 0) {
- // $Cache->increment('inbox_new_'.$ToID);
- //}
- return $ConvID;
-}
-
-//Create thread function, things should already be escaped when sent here.
-//Almost all the code is stolen straight from the forums and tailored for new posts only
-function create_thread($ForumID, $AuthorID, $Title, $PostBody) {
- global $DB, $Cache, $Time;
- if(!$ForumID || !$AuthorID || !is_number($AuthorID) || !$Title || !$PostBody) {
- return -1;
- }
-
- $DB->query("SELECT Username FROM users_main WHERE ID=".$AuthorID);
- if($DB->record_count() < 1) {
- return -2;
- }
- list($AuthorName) = $DB->next_record();
-
- $ThreadInfo = array();
- $ThreadInfo['IsLocked'] = 0;
- $ThreadInfo['IsSticky'] = 0;
-
- $DB->query("INSERT INTO forums_topics
- (Title, AuthorID, ForumID, LastPostTime, LastPostAuthorID)
- Values
- ('".$Title."', '".$AuthorID."', '$ForumID', '".sqltime()."', '".$AuthorID."')");
- $TopicID = $DB->inserted_id();
- $Posts = 1;
-
- $DB->query("INSERT INTO forums_posts
- (TopicID, AuthorID, AddedTime, Body)
- VALUES
- ('$TopicID', '".$AuthorID."', '".sqltime()."', '".$PostBody."')");
- $PostID = $DB->inserted_id();
-
- $DB->query("UPDATE forums SET
- NumPosts = NumPosts+1,
- NumTopics = NumTopics+1,
- LastPostID = '$PostID',
- LastPostAuthorID = '".$AuthorID."',
- LastPostTopicID = '$TopicID',
- LastPostTime = '".sqltime()."'
- WHERE ID = '$ForumID'");
-
- $DB->query("UPDATE forums_topics SET
- NumPosts = NumPosts+1,
- LastPostID = '$PostID',
- LastPostAuthorID = '".$AuthorID."',
- LastPostTime = '".sqltime()."'
- WHERE ID = '$TopicID'");
-
- // Bump this topic to head of the cache
- list($Forum,,,$Stickies) = $Cache->get_value('forums_'.$ForumID);
- if (!empty($Forum)) {
- if (count($Forum) == TOPICS_PER_PAGE && $Stickies < TOPICS_PER_PAGE) {
- array_pop($Forum);
- }
- $DB->query("SELECT f.IsLocked, f.IsSticky, f.NumPosts FROM forums_topics AS f WHERE f.ID ='$TopicID'");
- list($IsLocked,$IsSticky,$NumPosts) = $DB->next_record();
- $Part1 = array_slice($Forum,0,$Stickies,true); //Stickys
- $Part2 = array(
- $TopicID=>array(
- 'ID' => $TopicID,
- 'Title' => $Title,
- 'AuthorID' => $AuthorID,
- 'IsLocked' => $IsLocked,
- 'IsSticky' => $IsSticky,
- 'NumPosts' => $NumPosts,
- 'LastPostID' => $PostID,
- 'LastPostTime' => sqltime(),
- 'LastPostAuthorID' => $AuthorID,
- )
- ); //Bumped thread
- $Part3 = array_slice($Forum,$Stickies,TOPICS_PER_PAGE,true); //Rest of page
- if ($Stickies > 0) {
- $Part1 = array_slice($Forum,0,$Stickies,true); //Stickies
- $Part3 = array_slice($Forum,$Stickies,TOPICS_PER_PAGE-$Stickies-1,true); //Rest of page
- } else {
- $Part1 = array();
- $Part3 = $Forum;
- }
- if (is_null($Part1)) { $Part1 = array(); }
- if (is_null($Part3)) { $Part3 = array(); }
- $Forum = $Part1 + $Part2 + $Part3;
- $Cache->cache_value('forums_'.$ForumID, array($Forum,'',0,$Stickies), 0);
- }
-
- //Update the forum root
- $Cache->begin_transaction('forums_list');
- $UpdateArray = array(
- 'NumPosts'=>'+1',
- 'NumTopics'=>'+1',
- 'LastPostID'=>$PostID,
- 'LastPostAuthorID'=>$AuthorID,
- 'LastPostTopicID'=>$TopicID,
- 'LastPostTime'=>sqltime(),
- 'Title'=>$Title,
- 'IsLocked'=>$ThreadInfo['IsLocked'],
- 'IsSticky'=>$ThreadInfo['IsSticky']
- );
-
- $UpdateArray['NumTopics']='+1';
-
- $Cache->update_row($ForumID, $UpdateArray);
- $Cache->commit_transaction(0);
-
- $CatalogueID = floor((POSTS_PER_PAGE*ceil($Posts/POSTS_PER_PAGE)-POSTS_PER_PAGE)/THREAD_CATALOGUE);
- $Cache->begin_transaction('thread_'.$TopicID.'_catalogue_'.$CatalogueID);
- $Post = array(
- 'ID'=>$PostID,
- 'AuthorID'=>$LoggedUser['ID'],
- 'AddedTime'=>sqltime(),
- 'Body'=>$PostBody,
- 'EditedUserID'=>0,
- 'EditedTime'=>'0000-00-00 00:00:00',
- 'Username'=>''
- );
- $Cache->insert('', $Post);
- $Cache->commit_transaction(0);
-
- $Cache->begin_transaction('thread_'.$TopicID.'_info');
- $Cache->update_row(false, array('Posts'=>'+1', 'LastPostAuthorID'=>$AuthorID));
- $Cache->commit_transaction(0);
-
- return $TopicID;
-}
-
-
-
-// Check to see if a user has the permission to perform an action
-function check_perms($PermissionName,$MinClass = 0) {
- global $LoggedUser;
- return (isset($LoggedUser['Permissions'][$PermissionName]) && $LoggedUser['Permissions'][$PermissionName]
- && ($LoggedUser['Class']>=$MinClass || $LoggedUser['EffectiveClass']>=$MinClass))?true:false;
-}
-
-// TODO: make stricter, e.g. on all whitespace characters or Unicode normalisation
-function normalise_artist_name($ArtistName) {
- // \u200e is
- $ArtistName = trim($ArtistName);
- $ArtistName = preg_replace('/^(\xE2\x80\x8E)+/', '', $ArtistName);
- $ArtistName = preg_replace('/(\xE2\x80\x8E)+$/', '', $ArtistName);
- return trim(preg_replace('/ +/', ' ', $ArtistName));
-}
-
-function get_artists($GroupIDs, $Escape = array()) {
- global $Cache, $DB;
- $Results = array();
- $DBs = array();
- foreach($GroupIDs as $GroupID) {
- if(!is_number($GroupID)) {
- continue;
- }
- $Artists = $Cache->get_value('groups_artists_'.$GroupID);
- if(is_array($Artists)) {
- $Results[$GroupID] = $Artists;
- } else {
- $DBs[] = $GroupID;
- }
- }
- if(count($DBs) > 0) {
- $IDs = implode(',', $DBs);
- if(empty($IDs)) {
- $IDs = "null";
- }
- $DB->query("SELECT ta.GroupID,
- ta.ArtistID,
- aa.Name,
- ta.Importance,
- ta.AliasID
- FROM torrents_artists AS ta
- JOIN artists_alias AS aa ON ta.AliasID = aa.AliasID
- WHERE ta.GroupID IN ($IDs)
- ORDER BY ta.GroupID ASC,
- ta.Importance ASC,
- aa.Name ASC;");
- while(list($GroupID,$ArtistID,$ArtistName,$ArtistImportance,$AliasID) = $DB->next_record(MYSQLI_BOTH, false)) {
- $Results[$GroupID][$ArtistImportance][] = array('id' => $ArtistID, 'name' => $ArtistName, 'aliasid' => $AliasID);
- $New[$GroupID][$ArtistImportance][] = array('id' => $ArtistID, 'name' => $ArtistName, 'aliasid' => $AliasID);
- }
- foreach($DBs as $GroupID) {
- if(isset($New[$GroupID])) {
- $Cache->cache_value('groups_artists_'.$GroupID, $New[$GroupID]);
- }
- else {
- $Cache->cache_value('groups_artists_'.$GroupID, array());
- }
- }
- $Missing = array_diff($GroupIDs, array_keys($Results));
- if(!empty($Missing)) {
- $Results += array_fill_keys($Missing, array());
- }
- }
- return $Results;
-}
-
-/**
- * Convenience class for when you just need one group
- * @param $GroupID
- * @return unknown_type
- */
-function get_artist($GroupID) {
- $Results = get_artists(array($GroupID));
- return $Results[$GroupID];
-}
-
-function display_artists($Artists, $MakeLink = true, $IncludeHyphen = true, $Escape = true) {
- if(!empty($Artists)) {
- $ampersand = ($Escape) ? ' & ' : ' & ';
- $link = '';
-
- $MainArtists = $Artists[1];
- $Guests = $Artists[2];
- $Composers = $Artists[4];
- $Conductors = $Artists[5];
- $DJs = $Artists[6];
-
- if ((count($MainArtists) + count($Conductors) + count($DJs) == 0) && (count($Composers) == 0)) {
- return '';
- }
-
- // Various Composers is not needed and is ugly and should die
- switch(count($Composers)) {
- case 0:
- break;
- case 1:
- $link .= display_artist($Composers[0], $MakeLink, $Escape);
- break;
- case 2:
- $link .= display_artist($Composers[0], $MakeLink, $Escape).$ampersand.display_artist($Composers[1], $MakeLink, $Escape);
- break;
- }
-
- if ((count($Composers) > 0) && (count($Composers) < 3) && (count($MainArtists) > 0)) {
- $link .= ' performed by ';
- }
-
- $ComposerStr .= $link;
-
- switch(count($MainArtists)) {
- case 0:
- break;
- case 1:
- $link .= display_artist($MainArtists[0], $MakeLink, $Escape);
- break;
- case 2:
- $link .= display_artist($MainArtists[0], $MakeLink, $Escape).$ampersand.display_artist($MainArtists[1], $MakeLink, $Escape);
- break;
- default:
- $link .= 'Various Artists';
- }
-
- /*if(!empty($Guests) && (count($MainArtists) + count($Composers) > 0) && (count($MainArtists) + count($Composers) + count($Conductors) < 3)) {
- switch(count($Guests)) {
- case 1:
- $link .= ' with '.display_artist($Guests[0], $MakeLink, $Escape);
- break;
- case 2:
- $link .= ' with '.display_artist($Guests[0], $MakeLink, $Escape).$ampersand.display_artist($Guests[1], $MakeLink, $Escape);
- break;
- }
- }*/
-
- if ((count($Conductors) > 0) && (count($MainArtists) + count($Composers) > 0) && (count($Composers) < 3 || count($MainArtists) > 0)) {
- $link .= ' under ';
- }
- switch(count($Conductors)) {
- case 0:
- break;
- case 1:
- $link .= display_artist($Conductors[0], $MakeLink, $Escape);
- break;
- case 2:
- $link .= display_artist($Conductors[0], $MakeLink, $Escape).$ampersand.display_artist($Conductors[1], $MakeLink, $Escape);
- break;
- default:
- $link .= ' Various Conductors';
- }
-
- if ((count($Composers) > 0) && (count($MainArtists) + count($Conductors) > 3) && (count($MainArtists) > 1) && (count($Conductors) > 1)) {
- $link = $ComposerStr . 'Various Artists';
- } elseif ((count($Composers) > 2) && (count($MainArtists) + count($Conductors) == 0)) {
- $link = 'Various Composers';
- }
-
- // DJs override everything else
- switch(count($DJs)) {
- case 0:
- break;
- case 1:
- $link = display_artist($DJs[0], $MakeLink, $Escape);
- break;
- case 2:
- $link = display_artist($DJs[0], $MakeLink, $Escape).$ampersand.display_artist($DJs[1], $MakeLink, $Escape);
- break;
- default :
- $link = 'Various DJs';
- }
-
- return $link.($IncludeHyphen?' - ':'');
- } else {
- return '';
- }
-}
-
-function display_artist($Artist, $MakeLink = true, $Escape = true) {
- if ($MakeLink && !$Escape) {
- error('Invalid parameters to display_artist()');
- } elseif ($MakeLink) {
- return ''.display_str($Artist['name']).' ';
- } elseif ($Escape) {
- return display_str($Artist['name']);
- } else {
- return $Artist['name'];
- }
-}
-
-// Function to get data and torrents for an array of GroupIDs.
-// In places where the output from this is merged with sphinx filters, it will be in a different order.
-function get_groups($GroupIDs, $Return = true, $GetArtists = true, $Torrents = true) {
- global $DB, $Cache;
-
- $Found = array_flip($GroupIDs);
- $NotFound = array_flip($GroupIDs);
- $Key = $Torrents ? 'torrent_group_' : 'torrent_group_light_';
-
- foreach($GroupIDs as $GroupID) {
- $Data = $Cache->get_value($Key.$GroupID);
- if(!empty($Data) && (@$Data['ver'] >= 4)) {
- unset($NotFound[$GroupID]);
- $Found[$GroupID] = $Data['d'];
- }
- }
-
- $IDs = implode(',',array_flip($NotFound));
-
- /*
- Changing any of these attributes returned will cause very large, very dramatic site-wide chaos.
- Do not change what is returned or the order thereof without updating:
- torrents, artists, collages, bookmarks, better, the front page,
- and anywhere else the get_groups function is used.
- */
-
- if(count($NotFound)>0) {
- $DB->query("SELECT g.ID, g.Name, g.Year, g.RecordLabel, g.CatalogueNumber, g.TagList, g.ReleaseType, g.VanityHouse FROM torrents_group AS g WHERE g.ID IN ($IDs)");
-
- while($Group = $DB->next_record(MYSQLI_ASSOC, true)) {
- unset($NotFound[$Group['ID']]);
- $Found[$Group['ID']] = $Group;
- $Found[$Group['ID']]['Torrents'] = array();
- $Found[$Group['ID']]['Artists'] = array();
- }
-
- if ($Torrents) {
- $DB->query("SELECT
- ID, GroupID, Media, Format, Encoding, RemasterYear, Remastered, RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, Scene, HasLog, HasCue, LogScore, FileCount, FreeTorrent, Size, Leechers, Seeders, Snatched, Time, ID AS HasFile
- FROM torrents AS t WHERE GroupID IN($IDs) ORDER BY GroupID, Remastered, (RemasterYear <> 0) DESC, RemasterYear, RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, Media, Format, Encoding, ID");
- while($Torrent = $DB->next_record(MYSQLI_ASSOC, true)) {
- $Found[$Torrent['GroupID']]['Torrents'][$Torrent['ID']] = $Torrent;
-
- $Cache->cache_value('torrent_group_'.$Torrent['GroupID'], array('ver'=>4, 'd'=>$Found[$Torrent['GroupID']]), 0);
- $Cache->cache_value('torrent_group_light_'.$Torrent['GroupID'], array('ver'=>4, 'd'=>$Found[$Torrent['GroupID']]), 0);
- }
- } else {
- foreach ($Found as $Group) {
- $Cache->cache_value('torrent_group_light_'.$Group['ID'], array('ver'=>4, 'd'=>$Found[$Group['ID']]), 0);
- }
- }
- }
- if($GetArtists) {
- $Artists = get_artists($GroupIDs);
- } else {
- $Artists = array();
- }
-
- if($Return) { // If we're interested in the data, and not just caching it
- foreach($Artists as $GroupID=>$Data) {
- if(array_key_exists(1, $Data) || array_key_exists(4, $Data) || array_key_exists(6, $Data)) {
- $Found[$GroupID]['Artists']=$Data[1]; // Only use main artists (legacy)
- $Found[$GroupID]['ExtendedArtists'][1]=$Data[1];
- $Found[$GroupID]['ExtendedArtists'][2]=$Data[2];
- $Found[$GroupID]['ExtendedArtists'][3]=$Data[3];
- $Found[$GroupID]['ExtendedArtists'][4]=$Data[4];
- $Found[$GroupID]['ExtendedArtists'][5]=$Data[5];
- $Found[$GroupID]['ExtendedArtists'][6]=$Data[6];
- }
- else {
- $Found[$GroupID]['ExtendedArtists'] = false;
- }
- }
-
- $Matches = array('matches'=>$Found, 'notfound'=>array_flip($NotFound));
-
- return $Matches;
- }
-}
-
-//Function to get data from an array of $RequestIDs.
-//In places where the output from this is merged with sphinx filters, it will be in a different order.
-function get_requests($RequestIDs, $Return = true) {
- global $DB, $Cache;
-
- $Found = array_flip($RequestIDs);
- $NotFound = array_flip($RequestIDs);
-
- foreach($RequestIDs as $RequestID) {
- $Data = $Cache->get_value('request_'.$RequestID);
- if(!empty($Data)) {
- unset($NotFound[$RequestID]);
- $Found[$RequestID] = $Data;
- }
- }
-
- $IDs = implode(',',array_flip($NotFound));
-
- /*
- Don't change without ensuring you change everything else that uses get_requests()
- */
-
- if(count($NotFound) > 0) {
- $DB->query("SELECT
- r.ID AS ID,
- r.UserID,
- u.Username,
- r.TimeAdded,
- r.LastVote,
- r.CategoryID,
- r.Title,
- r.Year,
- r.Image,
- r.Description,
- r.CatalogueNumber,
- r.RecordLabel,
- r.ReleaseType,
- r.BitrateList,
- r.FormatList,
- r.MediaList,
- r.LogCue,
- r.FillerID,
- filler.Username,
- r.TorrentID,
- r.TimeFilled,
- r.GroupID,
- r.OCLC
- FROM requests AS r
- LEFT JOIN users_main AS u ON u.ID=r.UserID
- LEFT JOIN users_main AS filler ON filler.ID=FillerID AND FillerID!=0
- WHERE r.ID IN (".$IDs.")
- ORDER BY ID");
-
- $Requests = $DB->to_array();
- foreach($Requests as $Request) {
- unset($NotFound[$Request['ID']]);
- $Request['Tags'] = get_request_tags($Request['ID']);
- $Found[$Request['ID']] = $Request;
- $Cache->cache_value('request_'.$Request['ID'], $Request, 0);
- }
- }
-
- if($Return) { // If we're interested in the data, and not just caching it
- $Matches = array('matches'=>$Found, 'notfound'=>array_flip($NotFound));
- return $Matches;
- }
-}
-
-function update_sphinx_requests($RequestID) {
- global $DB, $Cache;
-
- $DB->query("REPLACE INTO sphinx_requests_delta (
- ID, UserID, TimeAdded, LastVote, CategoryID, Title,
- Year, ReleaseType, CatalogueNumber, BitrateList,
- FormatList, MediaList, LogCue, FillerID, TorrentID,
- TimeFilled, Visible, Votes, Bounty)
- SELECT
- ID, r.UserID, UNIX_TIMESTAMP(TimeAdded) AS TimeAdded,
- UNIX_TIMESTAMP(LastVote) AS LastVote, CategoryID,
- Title, Year, ReleaseType, CatalogueNumber, BitrateList,
- FormatList, MediaList, LogCue, FillerID, TorrentID,
- UNIX_TIMESTAMP(TimeFilled) AS TimeFilled, Visible,
- COUNT(rv.UserID) AS Votes, SUM(rv.Bounty) >> 10 AS Bounty
- FROM requests AS r LEFT JOIN requests_votes AS rv ON rv.RequestID=r.ID
- wHERE ID = ".$RequestID."
- GROUP BY r.ID");
-
- $DB->query("UPDATE sphinx_requests_delta
- SET ArtistList = (SELECT
- GROUP_CONCAT(aa.Name SEPARATOR ' ')
- FROM requests_artists AS ra
- JOIN artists_alias AS aa ON aa.AliasID=ra.AliasID
- WHERE ra.RequestID = ".$RequestID."
- GROUP BY NULL)
- WHERE ID = ".$RequestID);
-
- $Cache->delete_value('requests_'.$RequestID);
-}
-
-function get_tags($TagNames) {
- global $Cache, $DB;
- $TagIDs = array();
- foreach($TagNames as $Index => $TagName) {
- $Tag = $Cache->get_value('tag_id_'.$TagName);
- if(is_array($Tag)) {
- unset($TagNames[$Index]);
- $TagIDs[$Tag['ID']] = $Tag['Name'];
- }
- }
- if(count($TagNames) > 0) {
- $DB->query("SELECT ID, Name FROM tags WHERE Name IN ('".implode("', '", $TagNames)."')");
- $SQLTagIDs = $DB->to_array();
- foreach($SQLTagIDs as $Tag) {
- $TagIDs[$Tag['ID']] = $Tag['Name'];
- $Cache->cache_value('tag_id_'.$Tag['Name'], $Tag, 0);
- }
- }
-
- return($TagIDs);
-}
-
-function torrent_info($Data, $ShowMedia = false, $ShowEdition = false) {
- $Info = array();
- if(!empty($Data['Format'])) { $Info[]=$Data['Format']; }
- if(!empty($Data['Encoding'])) { $Info[]=$Data['Encoding']; }
- if(!empty($Data['HasLog'])) {
- $Str = 'Log';
- if(!empty($Data['LogScore'])) {
- $Str.=' ('.$Data['LogScore'].'%)';
- }
- $Info[]=$Str;
- }
- if(!empty($Data['HasCue'])) { $Info[]='Cue'; }
- if($ShowMedia && !empty($Data['Media'])) { $Info[]=$Data['Media']; }
- if(!empty($Data['Scene'])) { $Info[]='Scene'; }
- if($ShowEdition) {
- $EditionInfo = array();
- if(!empty($Data['RemasterYear'])) { $EditionInfo[]=$Data['RemasterYear']; }
- if(!empty($Data['RemasterTitle'])) { $EditionInfo[]=$Data['RemasterTitle']; }
- if(count($EditionInfo)) { $Info[]=implode(' ',$EditionInfo); }
- }
- if($Data['FreeTorrent'] == '1') { $Info[]='Freeleech! '; }
- if($Data['FreeTorrent'] == '2') { $Info[]='Neutral Leech! '; }
- if($Data['PersonalFL'] == 1) { $Info[]='Personal Freeleech! '; }
- return implode(' / ', $Info);
-}
-
-// Echo data sent in a form, typically a text area
-function form($Index, $Return = false) {
- if(!empty($_GET[$Index])) {
- if($Return) {
- return display_str($_GET[$Index]);
- } else {
- echo display_str($_GET[$Index]);
- }
- }
-}
-
-// Check/select tickboxes and s
-function selected($Name, $Value, $Attribute='selected', $Array = array()) {
- if(!empty($Array)) {
- if(isset($Array[$Name]) && $Array[$Name]!=='') {
- if($Array[$Name] == $Value) {
- echo ' '.$Attribute.'="'.$Attribute.'"';
- }
- }
- } else {
- if(isset($_GET[$Name]) && $_GET[$Name]!=='') {
- if($_GET[$Name] == $Value) {
- echo ' '.$Attribute.'="'.$Attribute.'"';
- }
- }
- }
-}
-function error($Error, $Ajax=false, $Log=false) {
- global $Debug;
- require(SERVER_ROOT.'/sections/error/index.php');
- $Debug->profile();
- die();
-}
-
-/**
- * @param BanReason 0 - Unknown, 1 - Manual, 2 - Ratio, 3 - Inactive, 4 - Unused.
- */
-
-function disable_users($UserIDs, $AdminComment, $BanReason = 1) {
- global $Cache, $DB;
- if(!is_array($UserIDs)) {
- $UserIDs = array($UserIDs);
- }
- $DB->query("UPDATE users_info AS i JOIN users_main AS m ON m.ID=i.UserID
- SET m.Enabled='2',
- m.can_leech='0',
- i.AdminComment = CONCAT('".sqltime()." - ".($AdminComment ? $AdminComment : 'Disabled by system')."\n\n', i.AdminComment),
- i.BanDate='".sqltime()."',
- i.BanReason='".$BanReason."',
- i.RatioWatchDownload=".($BanReason == 2?'m.Downloaded':"'0'")."
- WHERE m.ID IN(".implode(',',$UserIDs).") ");
- $Cache->decrement('stats_user_count',$DB->affected_rows());
- foreach($UserIDs as $UserID) {
- /*
- $Cache->cache_value('enabled_'.$UserID, 2, 2592000);
- $Cache->begin_transaction('user_info_'.$UserID);
- $Cache->update_row(false, array('Enabled' => 2));
- $Cache->commit_transaction(0);
- */
- $Cache->delete_value('enabled_'.$UserID);
- $Cache->delete_value('user_info_'.$UserID);
- $Cache->delete_value('user_info_heavy_'.$UserID);
- $Cache->delete_value('user_stats_'.$UserID);
-
- $DB->query("SELECT SessionID FROM users_sessions WHERE UserID='$UserID' AND Active = 1");
- while(list($SessionID) = $DB->next_record()) {
- $Cache->delete_value('session_'.$UserID.'_'.$SessionID);
- }
- $Cache->delete_value('users_sessions_'.$UserID);
-
-
- $DB->query("DELETE FROM users_sessions WHERE UserID='$UserID'");
-
- }
- $DB->query("SELECT torrent_pass FROM users_main WHERE ID in (".implode(", ",$UserIDs).")");
- $PassKeys = $DB->collect('torrent_pass');
- $Concat = "";
- foreach($PassKeys as $PassKey) {
- if(strlen($Concat) > 4000) {
- update_tracker('remove_users', array('passkeys' => $Concat));
- $Concat = $PassKey;
- } else {
- $Concat .= $PassKey;
- }
- }
- update_tracker('remove_users', array('passkeys' => $Concat));
-}
-
-
-/**
- * Send a GET request over a socket directly to the tracker
- * For example, update_tracker('change_passkey', array('oldpasskey' => OLD_PASSKEY, 'newpasskey' => NEW_PASSKEY)) will send the request:
- * GET /tracker_32_char_secret_code/update?action=change_passkey&oldpasskey=OLD_PASSKEY&newpasskey=NEW_PASSKEY HTTP/1.1
- * @param $Action The action to send
- * @param $Updates An associative array of key->value pairs to send to the tracker
- */
-function update_tracker($Action, $Updates, $ToIRC = false) {
- global $Cache;
- //Build request
- $Get = '/update?action='.$Action;
- foreach($Updates as $Key => $Value) {
- $Get .= '&'.$Key.'='.$Value;
- }
-
- if($ToIRC != false) {
- send_irc('PRIVMSG #tracker :'.$Get);
- }
- $Path = TRACKER_SECRET.$Get;
-
- $Return = "";
- $Attempts = 0;
- while($Return != "success" && $Attempts < 3) {
-
- // Send update
- $File = fsockopen(TRACKER_HOST, TRACKER_PORT, $ErrorNum, $ErrorString);
- if($File) {
- $Header = 'GET /'.$Path.' HTTP/1.1\r\n';
- if(fwrite($File, $Header) === false) {
- $Attempts++;
- $Err = "Failed to fwrite()";
- sleep(3);
- continue;
- }
- } else {
- $Attempts++;
- $Err = "Failed to fsockopen() - ".$ErrorNum." - ".$ErrorString;
- sleep(6);
- continue;
- }
-
- // Check for response.
-
- $ResHeader = '';
- do {
- $ResHeader .= fread($File, 1);
- } while (!feof($File) && !ends_with($ResHeader, "\r\n\r\n"));
-
- $Response = '';
- while($Line = fgets($File)) {
- $Response .= $Line;
- }
-
- $Return = chop($Response);
- $Attempts++;
- }
-
- if($Return != "success") {
- send_irc("PRIVMSG #tracker :{$Attempts} {$Err} {$Get}");
- if($Cache->get_value('ocelot_error_reported') === false) {
- send_irc("PRIVMSG ".ADMIN_CHAN." :Failed to update ocelot: ".$Err." : ".$Get);
- $Cache->cache_value('ocelot_error_reported', true, 900);
- }
- }
- return ($Return == "success");
-}
-/*
-function ends_with($Haystack, $Needle) {
- return strrpos($Haystack, $Needle) === strlen($Haystack)-strlen($Needle);
-}
-*/
-
-/** This ends_with is slightly slower when the string is found, but a lot faster when it isn't.
- */
-function ends_with($Haystack, $Needle) {
- return substr($Haystack, strlen($Needle) * -1) == $Needle;
-}
-
-function starts_with($Haystack, $Needle) {
- return strpos($Haystack, $Needle) === 0;
-}
-
-/**
- * Variant of in_array() with trailing wildcard support
- * @param string $Needle, array $Haystack
- * @return true if (substring of) $Needle exists in $Haystack
- */
-function in_array_partial($Needle, $Haystack) {
- static $Searches = array();
- if(array_key_exists($Needle, $Searches)) {
- return $Searches[$Needle];
- }
- foreach($Haystack as $String) {
- if(substr($String, -1) == '*') {
- if(!strncmp($Needle, $String, strlen($String)-1)) {
- $Searches[$Needle] = true;
- return true;
- }
- } elseif(!strcmp($Needle, $String)) {
- $Searches[$Needle] = true;
- return true;
- }
- }
- $Searches[$Needle] = false;
- return false;
-}
-
-/**
- * Will freeleech / neutralleech / normalise a set of torrents
- * @param array $TorrentIDs An array of torrents IDs to iterate over
- * @param int $FreeNeutral 0 = normal, 1 = fl, 2 = nl
- * @param int $FreeLeechType 0 = Unknown, 1 = Staff picks, 2 = Perma-FL (Toolbox, etc.), 3 = Vanity House
- */
-function freeleech_torrents($TorrentIDs, $FreeNeutral = 1, $FreeLeechType = 0) {
- global $DB, $Cache, $LoggedUser;
-
- if(!is_array($TorrentIDs)) {
- $TorrentIDs = array($TorrentIDs);
- }
-
- $DB->query("UPDATE torrents SET FreeTorrent = '".$FreeNeutral."', FreeLeechType = '".$FreeLeechType."' WHERE ID IN (".implode(", ", $TorrentIDs).")");
- $DB->query("SELECT ID, GroupID, info_hash FROM torrents WHERE ID IN (".implode(", ", $TorrentIDs).") ORDER BY GroupID ASC");
- $Torrents = $DB->to_array(false, MYSQLI_NUM, false);
- $GroupIDs = $DB->collect('GroupID');
-
- foreach($Torrents as $Torrent) {
- list($TorrentID, $GroupID, $InfoHash) = $Torrent;
- update_tracker('update_torrent', array('info_hash' => rawurlencode($InfoHash), 'freetorrent' => $FreeNeutral));
- $Cache->delete_value('torrent_download_'.$TorrentID);
- write_log($LoggedUser['Username']." marked torrent ".$TorrentID." freeleech type ".$FreeLeechType."!");
- write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], "marked as freeleech type ".$FreeLeechType."!", 0);
- }
-
- foreach($GroupIDs as $GroupID) {
- update_hash($GroupID);
- }
-}
-
-/**
- * Convenience function to allow for passing groups to freeleech_torrents()
- */
-function freeleech_groups($GroupIDs, $FreeNeutral = 1, $FreeLeechType = 0) {
- global $DB;
-
- if(!is_array($GroupIDs)) {
- $GroupIDs = array($GroupIDs);
- }
-
- $DB->query("SELECT ID from torrents WHERE GroupID IN (".implode(", ", $GroupIDs).")");
- if($DB->record_count()) {
- $TorrentIDs = $DB->collect('ID');
- freeleech_torrents($TorrentIDs, $FreeNeutral, $FreeLeechType);
- }
-}
-
-/**
- * Used to check if keys in $_POST and $_GET are all set
- * This reduces 'if' statement redundancy for a lot of variables
- */
-function isset_request($Request, $Keys=NULL, $AllowEmpty = False, $Error=0) {
- if(isset($Keys)) {
- foreach($Keys as $K) {
- if(!isset($Request[$K]) || ($AllowEmpty == False && $Request[$K] == '')) {
- error($Error);
- break;
- }
- }
- }
- else {
- foreach($Request as $R) {
- if(!isset($R) || ($AllowEmpty == False && $R == '')) {
- error($Error);
- break;
- }
- }
- }
-}
-
-/**
- * Test if there's an active lock with the given name
- *
- * @param string $LockName name on the lock
- * @return true if lock is active
- */
-function query_locked($LockName) {
- global $Cache;
- if ($Cache->get_value('query_lock_'.$LockName) !== false) {
- return true;
- }
- return false;
-}
-
-/**
- * Add lock. Expiry time is one hour to avoid indefinite locks
- *
- * @param string $LockName name on the lock
- */
-function set_query_lock($LockName) {
- global $Cache;
- $Cache->cache_value('query_lock_'.$LockName, 1, 3600);
-}
-
-/**
- * Remove lock. Expiry time is one hour to avoid indefinite locks
- *
- * @param string $LockName name on the lock
- */
-function clear_query_lock($LockName) {
- global $Cache;
- $Cache->delete_value('query_lock_'.$LockName);
-}
$Debug->set_flag('ending function definitions');
//Include /sections/*/index.php
$Document = basename(parse_url($_SERVER['SCRIPT_FILENAME'], PHP_URL_PATH), '.php');
-if(!preg_match('/^[a-z0-9]+$/i', $Document)) { error(404); }
+if (!preg_match('/^[a-z0-9]+$/i', $Document)) { error(404); }
require(SERVER_ROOT.'/sections/'.$Document.'/index.php');
$Debug->set_flag('completed module execution');
-/* Required in the absence of session_start() for providing that pages will change
+/* Required in the absence of session_start() for providing that pages will change
upon hit rather than being browser cached for changing content.
Old versions of Internet Explorer choke when downloading binary files over HTTPS with disabled cache.
Define the following constant in files that handle file downloads */
-if(!defined('IE_WORKAROUND_NO_CACHE_HEADERS')) {
+if (!defined('IE_WORKAROUND_NO_CACHE_HEADERS')) {
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
}
diff --git a/classes/util.php b/classes/util.php
new file mode 100644
index 00000000..c4f2051c
--- /dev/null
+++ b/classes/util.php
@@ -0,0 +1,95 @@
+
+// This is a file of miscellaneous functions that are called so damn often
+// that it'd just be annoying to stick them in namespaces.
+
+/**
+ * Return true if the given string is numeric.
+ *
+ * @param string $Str
+ * @return true if $Str numeric
+ */
+function is_number($Str) {
+ $Return = true;
+ if ($Str < 0) { $Return = false; }
+ // We're converting input to a int, then string and comparing to original
+ $Return = ($Str == strval(intval($Str)) ? true : false);
+ return $Return;
+}
+
+
+/**
+ * HTML-escape a string for output.
+ * This is preferable to htmlspecialchars because it doesn't screw up upon a double escape.
+ *
+ * @param string $Str
+ * @return string escaped string.
+ */
+function display_str($Str) {
+ if ($Str === NULL || $Str === FALSE || is_array($Str)) {
+ return '';
+ }
+ if ($Str!='' && !is_number($Str)) {
+ $Str = Format::make_utf8($Str);
+ $Str = mb_convert_encoding($Str,"HTML-ENTITIES","UTF-8");
+ $Str = preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/m","&",$Str);
+
+ $Replace = array(
+ "'",'"',"<",">",
+ '','','','','
','','','',
+ '','','','','','','','',
+ '','','','','','','','',
+ '','',''
+ );
+
+ $With = array(
+ ''','"','<','>',
+ '€','‚','ƒ','„','…','†','‡','ˆ',
+ '‰','Š','‹','Œ','Ž','‘','’','“',
+ '”','•','–','—','˜','™','š','›',
+ 'œ','ž','Ÿ'
+ );
+
+ $Str = str_replace($Replace, $With, $Str);
+ }
+ return $Str;
+}
+
+
+/**
+ * Send a message to an IRC bot listening on SOCKET_LISTEN_PORT
+ *
+ * @param string $Raw An IRC protocol snippet to send.
+ */
+function send_irc($Raw) {
+ $IRCSocket = fsockopen(SOCKET_LISTEN_ADDRESS, SOCKET_LISTEN_PORT);
+ $Raw = str_replace(array("\n", "\r"), '', $Raw);
+ fwrite($IRCSocket, $Raw);
+ fclose($IRCSocket);
+}
+
+
+/**
+ * Display a critical error and kills the page.
+ *
+ * @param string $Error Error type. Automatically supported:
+ * 403, 404, 0 (invalid input), -1 (invalid request)
+ * If you use your own string for Error, it becomes the error description.
+ * @param boolean $Ajax If true, the header/footer won't be shown, just the description.
+ * @param string $Log If true, the user is given a link to search $Log in the site log.
+ */
+function error($Error, $Ajax=false, $Log=false) {
+ global $Debug;
+ require(SERVER_ROOT.'/sections/error/index.php');
+ $Debug->profile();
+ die();
+}
+
+
+/**
+ * Convenience function. See doc in class_permissions.php
+ */
+function check_perms($PermissionName, $MinClass = 0) {
+ return Permissions::check_perms($PermissionName, $MinClass);
+}
+
+?>
diff --git a/design/privatefooter.php b/design/privatefooter.php
index e47be3b1..c3143bfe 100644
--- a/design/privatefooter.php
+++ b/design/privatefooter.php
@@ -24,7 +24,7 @@
if(!empty($LastActive)){ ?>Last activity =time_diff($LastActive['LastUpdate'])?> from =$LastActive['IP']?>.
} ?>
Time: =number_format(((microtime(true)-$ScriptStartTime)*1000),5)?> ms
- Used: =get_size(memory_get_usage(true))?>
+ Used: =Format::get_size(memory_get_usage(true))?>
Load: =number_format($Load[0],2).' '.number_format($Load[1],2).' '.number_format($Load[2],2)?>
Date: =date('M d Y, H:i')?>
diff --git a/design/privateheader.php b/design/privateheader.php
index 8b296fba..6758396e 100644
--- a/design/privateheader.php
+++ b/design/privateheader.php
@@ -115,9 +115,9 @@
- Up : =get_size($LoggedUser['BytesUploaded'])?>
- Down : =get_size($LoggedUser['BytesDownloaded'])?>
- Ratio: =ratio($LoggedUser['BytesUploaded'], $LoggedUser['BytesDownloaded'])?>
+ Up : =Format::get_size($LoggedUser['BytesUploaded'])?>
+ Down : =Format::get_size($LoggedUser['BytesDownloaded'])?>
+ Ratio: =Format::get_ratio_html($LoggedUser['BytesUploaded'], $LoggedUser['BytesDownloaded'])?>
if(!empty($LoggedUser['RequiredRatio'])) {?>
Required : =number_format($LoggedUser['RequiredRatio'], 2)?>
}
diff --git a/image.php b/image.php
index 67fd9c2e..6cb0bc27 100644
--- a/image.php
+++ b/image.php
@@ -53,7 +53,7 @@ function invisible($Image) {
$TotalAlpha += $Color['alpha'];
}
return (($TotalAlpha/$Count) == 127) ? true : false;
-
+
}
function is_number($Str) {
diff --git a/sections/ajax/artist.php b/sections/ajax/artist.php
index e631c96b..4c66aecd 100644
--- a/sections/ajax/artist.php
+++ b/sections/ajax/artist.php
@@ -11,10 +11,6 @@ function compare($X, $Y){
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
$Text = new TEXT;
-// Similar artist map
-include(SERVER_ROOT.'/classes/class_artist.php');
-include(SERVER_ROOT.'/classes/class_artists_similar.php');
-
$ArtistID = $_GET['id'];
if(!is_number($ArtistID)) {
print json_encode(array('status' => 'failure'));
@@ -53,7 +49,7 @@ function compare($X, $Y){
wiki.Image,
wiki.body,
a.VanityHouse
- FROM wiki_artists AS wiki
+ FROM wiki_artists AS wiki
LEFT JOIN artists_group AS a ON wiki.RevisionID=a.RevisionID
WHERE wiki.RevisionID='$RevisionID' ";
} else {
@@ -91,7 +87,7 @@ function compare($X, $Y){
SUM(rv.Bounty) AS Bounty
FROM requests AS r
LEFT JOIN requests_votes AS rv ON rv.RequestID=r.ID
- LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID
+ LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID
WHERE ra.ArtistID = ".$ArtistID."
AND r.TorrentID = 0
GROUP BY r.ID
@@ -108,18 +104,18 @@ function compare($X, $Y){
$LastReleaseType = 0;
if(empty($Importances) || empty($TorrentList)) {
- $DB->query("SELECT
+ $DB->query("SELECT
DISTINCT ta.GroupID, ta.Importance, tg.VanityHouse
FROM torrents_artists AS ta
JOIN torrents_group AS tg ON tg.ID=ta.GroupID
WHERE ta.ArtistID='$ArtistID'
- ORDER BY IF(ta.Importance IN ('2', '3', '4', '7'),ta.Importance, 1),
+ ORDER BY IF(ta.Importance IN ('2', '3', '4', '7'),ta.Importance, 1),
tg.ReleaseType ASC, tg.Year DESC, tg.Name DESC");
$GroupIDs = $DB->collect('GroupID');
$Importances = $DB->to_array('GroupID', MYSQLI_BOTH, false);
if(count($GroupIDs)>0) {
- $TorrentList = get_groups($GroupIDs, true,true);
+ $TorrentList = Torrents::get_groups($GroupIDs, true,true);
$TorrentList = $TorrentList['matches'];
} else {
$TorrentList = array();
@@ -181,8 +177,8 @@ function compare($X, $Y){
$Tags[$Tag]['count']++;
}
}
-
-
+
+
$DisplayName =''.$GroupName.' ';
if(check_perms('users_mod')) {
@@ -197,9 +193,9 @@ function compare($X, $Y){
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
- $DisplayName = display_artists($ExtendedArtists).$DisplayName;
+ $DisplayName = Artists::display_artists($ExtendedArtists).$DisplayName;
} elseif(count($GroupArtists)>0) {
- $DisplayName = display_artists(array(1 => $Artists), true, true).$DisplayName;
+ $DisplayName = Artists::display_artists(array(1 => $Artists), true, true).$DisplayName;
}
break;
case 1022: // Show performers on composer pages
@@ -207,14 +203,14 @@ function compare($X, $Y){
unset($ExtendedArtists[4]);
unset($ExtendedArtists[3]);
unset($ExtendedArtists[6]);
- $DisplayName = display_artists($ExtendedArtists).$DisplayName;
+ $DisplayName = Artists::display_artists($ExtendedArtists).$DisplayName;
} elseif(count($GroupArtists)>0) {
- $DisplayName = display_artists(array(1 => $Artists), true, true).$DisplayName;
+ $DisplayName = Artists::display_artists(array(1 => $Artists), true, true).$DisplayName;
}
break;
default: // Show composers otherwise
if (!empty($ExtendedArtists[4])) {
- $DisplayName = display_artists(array(4 => $ExtendedArtists[4]), true, true).$DisplayName;
+ $DisplayName = Artists::display_artists(array(4 => $ExtendedArtists[4]), true, true).$DisplayName;
}
}
diff --git a/sections/ajax/better/single.php b/sections/ajax/better/single.php
index 5d702495..70a5ebba 100644
--- a/sections/ajax/better/single.php
+++ b/sections/ajax/better/single.php
@@ -13,7 +13,7 @@
$Cache->cache_value('better_single_groupids', $GroupIDs, 30*60);
}
-$Results = get_groups(array_keys($GroupIDs));
+$Results = Torrents::get_groups(array_keys($GroupIDs));
$Results = $Results['matches'];
diff --git a/sections/ajax/better/transcode.php b/sections/ajax/better/transcode.php
index 9fc67bd2..4c767c2a 100644
--- a/sections/ajax/better/transcode.php
+++ b/sections/ajax/better/transcode.php
@@ -33,7 +33,7 @@
// If some were fetched from memcached, get their artists
if(!empty($Results['matches'])) { // Fetch the artists for groups
$GroupIDs = array_keys($Results['matches']);
- $Artists = get_artists($GroupIDs);
+ $Artists = Artists::get_artists($GroupIDs);
foreach($Artists as $GroupID=>$Data) {
if(!empty($Data[1])) {
$Results['matches'][$GroupID]['Artists']=$Data[1]; // Only use main artists
@@ -44,7 +44,7 @@
*/
// These ones were not found in the cache, run SQL
if(!empty($Results['notfound'])) {
- $SQLResults = get_groups($Results['notfound']);
+ $SQLResults = Torrents::get_groups($Results['notfound']);
if(is_array($SQLResults['notfound'])) { // Something wasn't found in the db, remove it from results
reset($SQLResults['notfound']);
@@ -70,7 +70,7 @@
$DisplayName = '';
if(count($Artists)>0) {
- $DisplayName = display_artists(array('1'=>$Artists));
+ $DisplayName = Artists::display_artists(array('1'=>$Artists));
}
$DisplayName.=''.$GroupName.' ';
if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; }
diff --git a/sections/ajax/bookmarks/torrents.php b/sections/ajax/bookmarks/torrents.php
index 9df12701..a8babc40 100644
--- a/sections/ajax/bookmarks/torrents.php
+++ b/sections/ajax/bookmarks/torrents.php
@@ -41,7 +41,7 @@ function compare($X, $Y){
$GroupIDs = $DB->collect('GroupID');
$CollageDataList=$DB->to_array('GroupID', MYSQLI_ASSOC);
if(count($GroupIDs)>0) {
- $TorrentList = get_groups($GroupIDs);
+ $TorrentList = Torrents::get_groups($GroupIDs);
$TorrentList = $TorrentList['matches'];
} else {
$TorrentList = array();
@@ -94,7 +94,7 @@ function compare($X, $Y){
$DisplayName = '';
if(count($GroupArtists)>0) {
- $DisplayName = display_artists(array('1'=>$GroupArtists));
+ $DisplayName = Artists::display_artists(array('1'=>$GroupArtists));
}
$DisplayName .= ''.$GroupName.' ';
if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';}
@@ -170,7 +170,7 @@ function compare($X, $Y){
$DisplayName = '';
if(!empty($GroupArtists)) {
- $DisplayName.= display_artists(array('1'=>$GroupArtists), false);
+ $DisplayName.= Artists::display_artists(array('1'=>$GroupArtists), false);
}
$DisplayName .= $GroupName;
if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';}
diff --git a/sections/ajax/browse.php b/sections/ajax/browse.php
index 714f3963..b8d6e065 100644
--- a/sections/ajax/browse.php
+++ b/sections/ajax/browse.php
@@ -12,7 +12,7 @@ function header_link($SortKey,$DefaultWay="desc") {
else { $NewWay="desc"; }
} else { $NewWay=$DefaultWay; }
- return "torrents.php?order_way=".$NewWay."&order_by=".$SortKey."&".get_url(array('order_way','order_by'));
+ return "torrents.php?order_way=".$NewWay."&order_by=".$SortKey."&".Format::get_url(array('order_way','order_by'));
}
$TokenTorrents = $Cache->get_value('users_tokens_'.$UserID);
@@ -284,7 +284,7 @@ function header_link($SortKey,$DefaultWay="desc") {
// These ones were not found in the cache, run SQL
if(!empty($Results['notfound'])) {
- $SQLResults = get_groups($Results['notfound']);
+ $SQLResults = Torrents::get_groups($Results['notfound']);
if(is_array($SQLResults['notfound'])) { // Something wasn't found in the db, remove it from results
reset($SQLResults['notfound']);
@@ -362,7 +362,7 @@ function header_link($SortKey,$DefaultWay="desc") {
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
- $DisplayName = display_artists($ExtendedArtists, false, false, true);
+ $DisplayName = Artists::display_artists($ExtendedArtists, false, false, true);
foreach ($ExtendedArtists[1] as $Artist) {
$JsonArtists[] = array(
'id' => (int) $Artist['id'],
@@ -371,7 +371,7 @@ function header_link($SortKey,$DefaultWay="desc") {
);
}
} elseif(!empty($Artists)) {
- $DisplayName = display_artists(array(1=>$Artists), false, false, true);
+ $DisplayName = Artists::display_artists(array(1=>$Artists), false, false, true);
foreach ($Artists as $Artist) {
$JsonArtists[] = array(
'id' => (int) $Artist['id'],
diff --git a/sections/ajax/forum/forum.php b/sections/ajax/forum/forum.php
index bc8bd16f..6cddf24d 100644
--- a/sections/ajax/forum/forum.php
+++ b/sections/ajax/forum/forum.php
@@ -28,7 +28,7 @@
$PerPage = POSTS_PER_PAGE;
}
-list($Page,$Limit) = page_limit(TOPICS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(TOPICS_PER_PAGE);
//---------- Get some data to start processing
@@ -80,7 +80,7 @@
);
}
-$Pages=get_pages($Page,$Forums[$ForumID]['NumTopics'],TOPICS_PER_PAGE,9);
+$Pages=Format::get_pages($Page,$Forums[$ForumID]['NumTopics'],TOPICS_PER_PAGE,9);
if (count($Forum) == 0) {
print
@@ -118,9 +118,9 @@
} else {
$Read = 'read';
}
- $UserInfo = user_info($AuthorID);
+ $UserInfo = Users::user_info($AuthorID);
$AuthorName = $UserInfo['Username'];
- $UserInfo = user_info($LastAuthorID);
+ $UserInfo = Users::user_info($LastAuthorID);
$LastAuthorName = $UserInfo['Username'];
$JsonTopics[] = array(
diff --git a/sections/ajax/forum/main.php b/sections/ajax/forum/main.php
index 9e1bd235..f7e219c2 100644
--- a/sections/ajax/forum/main.php
+++ b/sections/ajax/forum/main.php
@@ -62,7 +62,7 @@
} else {
$Read = 'read';
}
- $UserInfo = user_info($LastAuthorID);
+ $UserInfo = Users::user_info($LastAuthorID);
$JsonForums[] = array(
'forumId' => (int) $ForumID,
diff --git a/sections/ajax/forum/thread.php b/sections/ajax/forum/thread.php
index 6ec8b27a..46766ee3 100644
--- a/sections/ajax/forum/thread.php
+++ b/sections/ajax/forum/thread.php
@@ -73,11 +73,11 @@
} else {
$PostNum = 1;
}
-list($Page,$Limit) = page_limit($PerPage, min($ThreadInfo['Posts'],$PostNum));
+list($Page,$Limit) = Format::page_limit($PerPage, min($ThreadInfo['Posts'],$PostNum));
if(($Page-1)*$PerPage > $ThreadInfo['Posts']) {
$Page = ceil($ThreadInfo['Posts']/$PerPage);
}
-list($CatalogueID,$CatalogueLimit) = catalogue_limit($Page,$PerPage,THREAD_CATALOGUE);
+list($CatalogueID,$CatalogueLimit) = Format::catalogue_limit($Page,$PerPage,THREAD_CATALOGUE);
// Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
if(!$Catalogue = $Cache->get_value('thread_'.$ThreadID.'_catalogue_'.$CatalogueID)) {
@@ -96,7 +96,7 @@
$Cache->cache_value('thread_'.$ThreadID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
}
}
-$Thread = catalogue_select($Catalogue,$Page,$PerPage,THREAD_CATALOGUE);
+$Thread = Format::catalogue_select($Catalogue,$Page,$PerPage,THREAD_CATALOGUE);
if ($_GET['updatelastread'] != '0') {
$LastPost = end($Thread);
@@ -220,8 +220,8 @@
$JsonPosts = array();
foreach ($Thread as $Key => $Post) {
list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime) = array_values($Post);
- list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(user_info($AuthorID));
- $UserInfo = user_info($EditedUserID);
+ list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
+ $UserInfo = Users::user_info($EditedUserID);
$JsonPosts[] = array(
'postId' => (int) $PostID,
'addedTime' => $AddedTime,
diff --git a/sections/ajax/inbox/inbox.php b/sections/ajax/inbox/inbox.php
index 7f92f215..2ac43576 100644
--- a/sections/ajax/inbox/inbox.php
+++ b/sections/ajax/inbox/inbox.php
@@ -18,7 +18,7 @@
die();
}
-list($Page,$Limit) = page_limit(MESSAGES_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(MESSAGES_PER_PAGE);
$Sort = empty($_GET['sort']) || $_GET['sort'] != "unread" ? "Date DESC" : "cu.Unread = '1' DESC, DATE DESC";
@@ -70,14 +70,14 @@
list($NumResults) = $DB->next_record();
$DB->set_query_id($Results);
-$CurURL = get_url(array('sort'));
+$CurURL = Format::get_url(array('sort'));
if(empty($CurURL)) {
$CurURL = "inbox.php?";
} else {
$CurURL = "inbox.php?".$CurURL."&";
}
-$Pages=get_pages($Page,$NumResults,MESSAGES_PER_PAGE,9);
+$Pages=Format::get_pages($Page,$NumResults,MESSAGES_PER_PAGE,9);
$JsonMessages = array();
while(list($ConvID, $Subject, $Unread, $Sticky, $ForwardedID, $ForwardedName, $SenderID, $Username, $Donor, $Warned, $Enabled, $Date) = $DB->next_record()) {
diff --git a/sections/ajax/inbox/viewconv.php b/sections/ajax/inbox/viewconv.php
index 7e5a4887..3b680b2c 100644
--- a/sections/ajax/inbox/viewconv.php
+++ b/sections/ajax/inbox/viewconv.php
@@ -46,7 +46,7 @@
while(list($PMUserID, $Username) = $DB->next_record()) {
$PMUserID = (int)$PMUserID;
- $Users[$PMUserID]['UserStr'] = format_username($PMUserID, true, true, true, true);
+ $Users[$PMUserID]['UserStr'] = Users::format_username($PMUserID, true, true, true, true);
$Users[$PMUserID]['Username'] = $Username;
}
$Users[0]['UserStr'] = 'System'; // in case it's a message from the system
diff --git a/sections/ajax/notifications.php b/sections/ajax/notifications.php
index 51f44f32..835acf0c 100644
--- a/sections/ajax/notifications.php
+++ b/sections/ajax/notifications.php
@@ -12,7 +12,7 @@
}
define('NOTIFICATIONS_PER_PAGE', 50);
-list($Page,$Limit) = page_limit(NOTIFICATIONS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(NOTIFICATIONS_PER_PAGE);
$TokenTorrents = $Cache->get_value('users_tokens_'.$LoggedUser['ID']);
if (empty($TokenTorrents)) {
@@ -36,10 +36,10 @@
list($TorrentCount) = $DB->next_record();
if(count($GroupIDs)) {
- $TorrentGroups = get_groups($GroupIDs);
+ $TorrentGroups = Torrents::get_groups($GroupIDs);
$TorrentGroups = $TorrentGroups['matches'];
- // Need some extra info that get_groups() doesn't return
+ // Need some extra info that Torrents::get_groups() doesn't return
$DB->query("SELECT ID, CategoryID FROM torrents_group WHERE ID IN (".implode(',', $GroupIDs).")");
$GroupCategoryIDs = $DB->to_array('ID', MYSQLI_ASSOC, false);
diff --git a/sections/ajax/request.php b/sections/ajax/request.php
index 73e9b3a5..06fb9ce9 100644
--- a/sections/ajax/request.php
+++ b/sections/ajax/request.php
@@ -31,7 +31,7 @@
//First things first, lets get the data for the request.
-$Request = get_requests(array($RequestID));
+$Request = Requests::get_requests(array($RequestID));
$Request = $Request['matches'][$RequestID];
if(empty($Request)) {
print
@@ -59,8 +59,8 @@
//Do we need to get artists?
if($CategoryName == "Music") {
$ArtistForm = get_request_artists($RequestID);
- $ArtistName = display_artists($ArtistForm, false, true);
- $ArtistLink = display_artists($ArtistForm, true, true);
+ $ArtistName = Artists::display_artists($ArtistForm, false, true);
+ $ArtistLink = Artists::display_artists($ArtistForm, true, true);
if($IsFilled) {
$DisplayLink = $ArtistLink."".$Title." [".$Year."]";
@@ -141,7 +141,7 @@
$Cache->cache_value('request_comments_'.$RequestID, $Results, 0);
}
-list($Page,$Limit) = page_limit(TORRENT_COMMENTS_PER_PAGE,$Results);
+list($Page,$Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE,$Results);
//Get the cache catalogue
$CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE*$Page-TORRENT_COMMENTS_PER_PAGE)/THREAD_CATALOGUE);
@@ -175,7 +175,7 @@
$JsonRequestComments = array();
foreach($Thread as $Key => $Post){
list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
- list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(user_info($AuthorID));
+ list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
$JsonRequestComments[] = array(
'postId' => (int) $PostID,
'authorId' => (int) $AuthorID,
@@ -183,7 +183,7 @@
'donor' => $Donor == 1,
'warned' => ($Warned!='0000-00-00 00:00:00'),
'enabled' => ($Enabled == 2 ? false : true),
- 'class' => make_class_string($PermissionID),
+ 'class' => Users::make_class_string($PermissionID),
'addedTime' => $AddedTime,
'avatar' => $Avatar,
'comment' => $Text->full_format($Body),
diff --git a/sections/ajax/requests.php b/sections/ajax/requests.php
index 348d9ec3..a029743d 100644
--- a/sections/ajax/requests.php
+++ b/sections/ajax/requests.php
@@ -5,12 +5,12 @@
$Queries = array();
$OrderWays = array('year', 'votes', 'bounty', 'created', 'lastvote', 'filled');
-list($Page,$Limit) = page_limit(REQUESTS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(REQUESTS_PER_PAGE);
$Submitted = !empty($_GET['submit']);
//Paranoia
-$UserInfo = user_info((int)$_GET['userid']);
-$Perms = get_permissions($UserInfo['PermissionID']);
+$UserInfo = Users::user_info((int)$_GET['userid']);
+$Perms = Permissions::get_permissions($UserInfo['PermissionID']);
$UserClass = $Perms['Class'];
$BookmarkView = false;
@@ -96,12 +96,12 @@
$Tags = explode(',', $_GET['tags']);
$TagNames = array();
foreach ($Tags as $Tag) {
- $Tag = sanitize_tag($Tag);
+ $Tag = Misc::sanitize_tag($Tag);
if(!empty($Tag)) {
$TagNames[] = $Tag;
}
}
- $Tags = get_tags($TagNames);
+ $Tags = Misc::get_tags($TagNames);
}
if(empty($_GET['tags_type']) && !empty($Tags)) {
@@ -278,7 +278,7 @@
//We don't use sphinxapi's default cache searcher, we use our own functions
if(!empty($SphinxResults['notfound'])) {
- $SQLResults = get_requests($SphinxResults['notfound']);
+ $SQLResults = Requests::get_requests($SphinxResults['notfound']);
if(is_array($SQLResults['notfound'])) {
//Something wasn't found in the db, remove it from results
reset($SQLResults['notfound']);
diff --git a/sections/ajax/subscriptions.php b/sections/ajax/subscriptions.php
index cf546a59..5fc16a3b 100644
--- a/sections/ajax/subscriptions.php
+++ b/sections/ajax/subscriptions.php
@@ -23,7 +23,7 @@
} else {
$PerPage = POSTS_PER_PAGE;
}
-list($Page,$Limit) = page_limit($PerPage);
+list($Page,$Limit) = Format::page_limit($PerPage);
if($LoggedUser['CustomForums']) {
unset($LoggedUser['CustomForums']['']);
diff --git a/sections/ajax/tcomments.php b/sections/ajax/tcomments.php
index 5da0d628..9d93afc1 100644
--- a/sections/ajax/tcomments.php
+++ b/sections/ajax/tcomments.php
@@ -19,9 +19,9 @@
if(isset($_GET['postid']) && is_number($_GET['postid']) && $Results > TORRENT_COMMENTS_PER_PAGE) {
$DB->query("SELECT COUNT(ID) FROM torrents_comments WHERE GroupID = $GroupID AND ID <= $_GET[postid]");
list($PostNum) = $DB->next_record();
- list($Page,$Limit) = page_limit(TORRENT_COMMENTS_PER_PAGE,$PostNum);
+ list($Page,$Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE,$PostNum);
} else {
- list($Page,$Limit) = page_limit(TORRENT_COMMENTS_PER_PAGE,$Results);
+ list($Page,$Limit) = Format::page_limit(TORRENT_COMMENTS_PER_PAGE,$Results);
}
//Get the cache catalogue
@@ -57,7 +57,7 @@
$JsonComments = array();
foreach ($Thread as $Key => $Post) {
list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
- list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(user_info($AuthorID));
+ list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
$JsonComments[] = array(
'postId' => (int) $PostID,
'addedTime' => $AddedTime,
diff --git a/sections/ajax/top10/torrents.php b/sections/ajax/top10/torrents.php
index ec5655df..ce63d336 100644
--- a/sections/ajax/top10/torrents.php
+++ b/sections/ajax/top10/torrents.php
@@ -146,7 +146,7 @@ function generate_torrent_json($Caption, $Tag, $Details, $Limit) {
$Format,$Encoding,$Media,$Scene,$HasLog,$HasCue,$LogScore,$Year,$GroupYear,
$RemasterTitle,$Snatched,$Seeders,$Leechers,$Data) = $Detail;
- $Artist = display_artists(get_artist($GroupID), false, true);
+ $Artist = Artists::display_artists(Artists::get_artist($GroupID), false, true);
$TruncArtist = substr($Artist, 0, strlen($Artist)-3);
$TagList=array();
diff --git a/sections/ajax/torrentgroup.php b/sections/ajax/torrentgroup.php
index 2467bd6b..2c8ebaf6 100644
--- a/sections/ajax/torrentgroup.php
+++ b/sections/ajax/torrentgroup.php
@@ -20,7 +20,7 @@ function filter_by_key($input, $keys) { return array_intersect_key($input, array
$TorrentDetails = filter_by_key($TorrentCache[0][0], $GroupAllowed);
-$ArtistForm = get_artist($GroupID);
+$ArtistForm = Artists::get_artist($GroupID);
if($TorrentDetails['CategoryID'] == 0) {
$CategoryName = "Unknown";
} else {
diff --git a/sections/ajax/userhistory/post_history.php b/sections/ajax/userhistory/post_history.php
index ef3fdc7d..676e39d5 100644
--- a/sections/ajax/userhistory/post_history.php
+++ b/sections/ajax/userhistory/post_history.php
@@ -1,5 +1,5 @@
-//TODO: replace 24-43 with user_info()
+//TODO: replace 24-43 with Users::user_info()
/*
User post history page
*/
@@ -32,7 +32,7 @@ function error_out($reason = "") {
$PerPage = POSTS_PER_PAGE;
}
-list($Page,$Limit) = page_limit($PerPage);
+list($Page,$Limit) = Format::page_limit($PerPage);
if(($UserInfo = $Cache->get_value('user_info_'.$UserID)) === FALSE) {
$DB->query("SELECT
diff --git a/sections/ajax/usersearch.php b/sections/ajax/usersearch.php
index 4b6c9fcc..216fa3ec 100644
--- a/sections/ajax/usersearch.php
+++ b/sections/ajax/usersearch.php
@@ -13,7 +13,7 @@
if(isset($_GET['username'])){
$_GET['username'] = trim($_GET['username']);
- list($Page,$Limit) = page_limit(USERS_PER_PAGE);
+ list($Page,$Limit) = Format::page_limit(USERS_PER_PAGE);
$DB->query("SELECT SQL_CALC_FOUND_ROWS
ID,
Username,
@@ -42,7 +42,7 @@
'donor' => $Donor == 1,
'warned' => ($Warned!='0000-00-00 00:00:00'),
'enabled' => ($Enabled == 2 ? false : true),
- 'class' => make_class_string($PermissionID)
+ 'class' => Users::make_class_string($PermissionID)
);
}
diff --git a/sections/artist/add_alias.php b/sections/artist/add_alias.php
index 694b950f..05d191ac 100644
--- a/sections/artist/add_alias.php
+++ b/sections/artist/add_alias.php
@@ -4,7 +4,7 @@
if(!check_perms('torrents_edit')) { error(403); }
$ArtistID = $_POST['artistid'];
$Redirect = $_POST['redirect'];
-$AliasName = normalise_artist_name($_POST['name']);
+$AliasName = Artists::normalise_artist_name($_POST['name']);
$DBAliasName = db_string($AliasName);
if(!$Redirect) { $Redirect = 0; }
@@ -35,7 +35,7 @@
if($ArtistID == $CloneArtistID && $Redirect == 0) {
if($CloneRedirect != 0) {
$DB->query("UPDATE artists_alias SET ArtistID='".$ArtistID."', Redirect=0 WHERE AliasID='".$CloneAliasID."'");
- write_log("Redirection for the alias $CloneAliasID ($DBAliasName) for the artist $ArtistID was removed by user $LoggedUser[ID] ($LoggedUser[Username])");
+ Misc::write_log("Redirection for the alias $CloneAliasID ($DBAliasName) for the artist $ArtistID was removed by user $LoggedUser[ID] ($LoggedUser[Username])");
} else {
error('No changes were made as the target alias did not redirect anywhere.');
}
@@ -66,7 +66,7 @@
$DB->query("SELECT Name FROM artists_group WHERE ArtistID = ".$ArtistID);
list($ArtistName) = $DB->next_record(MYSQLI_NUM, false);
- write_log("The alias ".$AliasID." (".$DBAliasName.") was added to the artist ".$ArtistID." (".db_string($ArtistName).") by user ".$LoggedUser['ID']." (".$LoggedUser['Username'].")");
+ Misc::write_log("The alias ".$AliasID." (".$DBAliasName.") was added to the artist ".$ArtistID." (".db_string($ArtistName).") by user ".$LoggedUser['ID']." (".$LoggedUser['Username'].")");
}
header('Location: '.$_SERVER['HTTP_REFERER']);
?>
diff --git a/sections/artist/artist.php b/sections/artist/artist.php
index 3b1c8b95..2a3a0120 100644
--- a/sections/artist/artist.php
+++ b/sections/artist/artist.php
@@ -13,7 +13,6 @@ function compare($X, $Y){
include(SERVER_ROOT.'/sections/requests/functions.php');
// Similar artist map
-include(SERVER_ROOT.'/classes/class_artist.php');
include(SERVER_ROOT.'/classes/class_artists_similar.php');
include(SERVER_ROOT.'/classes/class_image_tools.php');
@@ -33,7 +32,7 @@ function compare($X, $Y){
if($Data) {
$Data = unserialize($Data);
list($K, list($Name, $Image, $Body, $NumSimilar, $SimilarArray, $TorrentList, $Importances, $VanityHouseArtist)) = each($Data);
-
+
} else {
if ($RevisionID) {
$sql = "SELECT
@@ -41,7 +40,7 @@ function compare($X, $Y){
wiki.Image,
wiki.body,
a.VanityHouse
- FROM wiki_artists AS wiki
+ FROM wiki_artists AS wiki
LEFT JOIN artists_group AS a ON wiki.RevisionID=a.RevisionID
WHERE wiki.RevisionID='$RevisionID' ";
} else {
@@ -56,9 +55,9 @@ function compare($X, $Y){
}
$sql .= " GROUP BY a.ArtistID";
$DB->query($sql);
-
+
if($DB->record_count()==0) { error(404); }
-
+
list($Name, $Image, $Body, $VanityHouseArtist) = $DB->next_record(MYSQLI_NUM, array(0));
}
@@ -86,12 +85,12 @@ function compare($X, $Y){
SUM(rv.Bounty) AS Bounty
FROM requests AS r
LEFT JOIN requests_votes AS rv ON rv.RequestID=r.ID
- LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID
+ LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID
WHERE ra.ArtistID = ".$ArtistID."
AND r.TorrentID = 0
GROUP BY r.ID
ORDER BY Votes DESC");
-
+
if($DB->record_count() > 0) {
$Requests = $DB->to_array();
} else {
@@ -103,19 +102,19 @@ function compare($X, $Y){
$LastReleaseType = 0;
if(empty($Importances) || empty($TorrentList)) {
- $DB->query("SELECT
+ $DB->query("SELECT
DISTINCTROW ta.GroupID, ta.Importance, tg.VanityHouse
FROM torrents_artists AS ta
JOIN torrents_group AS tg ON tg.ID=ta.GroupID
WHERE ta.ArtistID='$ArtistID'
- ORDER BY IF(ta.Importance IN ('2', '3', '4', '7'),1000 + ta.Importance, tg.ReleaseType) ASC,
+ ORDER BY IF(ta.Importance IN ('2', '3', '4', '7'),1000 + ta.Importance, tg.ReleaseType) ASC,
tg.Year DESC, tg.Name DESC");
-
+
$GroupIDs = $DB->collect('GroupID');
$Importances = $DB->to_array(false, MYSQLI_BOTH, false);
-
+
if(count($GroupIDs)>0) {
- $TorrentList = get_groups($GroupIDs, true,true);
+ $TorrentList = Torrents::get_groups($GroupIDs, true,true);
$TorrentList = $TorrentList['matches'];
} else {
$TorrentList = array();
@@ -138,32 +137,32 @@ function compare($X, $Y){
//$TorrentList[$GroupID]['ReleaseType'] = 1024;
$GuestAlbums = true;
break;
-
+
case '3':
$Importances[$ID]['ReleaseType'] = 1023;
//$TorrentList[$GroupID]['ReleaseType'] = 1023;
$RemixerAlbums = true;
break;
-
+
case '4':
$Importances[$ID]['ReleaseType'] = 1022;
//$TorrentList[$GroupID]['ReleaseType'] = 1022;
$ComposerAlbums = true;
break;
-
+
case '7':
$Importances[$ID]['ReleaseType'] = 1021;
//$TorrentList[$GroupID]['ReleaseType'] = 1021;
$ProducerAlbums = true;
break;
-
+
default:
$Importances[$ID]['ReleaseType'] = $TorrentList[$Group['GroupID']]['ReleaseType'];
}
-
+
if(!in_array($Importances[$ID]['ReleaseType'], $UsedReleases)) {
$UsedReleases[] = $Importances[$ID]['ReleaseType'];
- }
+ }
}
if(!empty($GuestAlbums)) {
@@ -199,7 +198,7 @@ function compare($X, $Y){
$DisplayName = $ReleaseTypes[$ReleaseID]."s";
break;
}
-
+
if (!empty($LoggedUser['DiscogView']) || (isset($LoggedUser['HideTypes']) && in_array($ReleaseID, $LoggedUser['HideTypes']))) {
$ToggleStr = " onclick=\"$('.releases_$ReleaseID').show(); return true;\"";
} else {
@@ -225,7 +224,7 @@ function compare($X, $Y){
$TagList = explode(' ',str_replace('_','.',$Group['TagList']));
$TorrentTags = array();
-
+
// $Tags array is for the sidebar on the right. Skip compilations and soundtracks.
if ($Group['ReleaseType'] != 7 && $Group['ReleaseType'] != 3) {
foreach($TagList as $Tag) {
@@ -238,14 +237,14 @@ function compare($X, $Y){
}
$TorrentTags = implode(', ', $TorrentTags);
$TorrentTags = ''.$TorrentTags.'
';
-
+
foreach ($Group['Torrents'] as $TorrentID => $Torrent) {
$NumTorrents++;
-
+
$Torrent['Seeders'] = (int)$Torrent['Seeders'];
$Torrent['Leechers'] = (int)$Torrent['Leechers'];
$Torrent['Snatched'] = (int)$Torrent['Snatched'];
-
+
$NumSeeders+=$Torrent['Seeders'];
$NumLeechers+=$Torrent['Leechers'];
$NumSnatches+=$Torrent['Snatched'];
@@ -264,31 +263,31 @@ function compare($X, $Y){
list($GroupID, $GroupName, $GroupYear, $GroupRecordLabel, $GroupCatalogueNumber, $TagList, $ReleaseType, $GroupVanityHouse, $Torrents, $Artists, $ExtendedArtists) = array_values($TorrentList[$Group['GroupID']]);
$ReleaseType = $Group['ReleaseType'];
$GroupVanityHouse = $Group['VanityHouse'];
-
+
if ($GroupID == $OldGroupID && $ReleaseType == $OldReleaseType) {
continue;
} else {
$OldGroupID = $GroupID;
$OldReleaseType = $ReleaseType;
}
-
+
if (!empty($LoggedUser['DiscogView']) || (isset($LoggedUser['HideTypes']) && in_array($ReleaseType, $LoggedUser['HideTypes']))) {
$HideDiscog = ' hidden';
} else {
$HideDiscog = '';
}
-
+
$TagList = explode(' ',str_replace('_','.',$TagList));
$TorrentTags = array();
-
+
// $Tags array is for the sidebar on the right. Skip compilations and soundtracks.
foreach($TagList as $Tag) {
$TorrentTags[] = ''.$Tag.' ';
}
$TorrentTags = implode(', ', $TorrentTags);
$TorrentTags = ''.$TorrentTags.'
';
-
+
if($ReleaseType!=$LastReleaseType) {
switch($ReleaseTypes[$ReleaseType]) {
case "Remix" :
@@ -322,13 +321,13 @@ function compare($X, $Y){
$LastReleaseType = $ReleaseType;
}
-
+
$DisplayName =''.$GroupName.' ';
if(check_perms('users_mod') || check_perms('torrents_fix_ghosts')) {
$DisplayName .= ' [Fix ]';
}
-
+
switch($ReleaseType){
case 1023: // Remixes, DJ Mixes, Guest artists, and Producers need the artist name
case 1024:
@@ -337,9 +336,9 @@ function compare($X, $Y){
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
- $DisplayName = display_artists($ExtendedArtists).$DisplayName;
+ $DisplayName = Artists::display_artists($ExtendedArtists).$DisplayName;
} elseif(count($GroupArtists)>0) {
- $DisplayName = display_artists(array(1 => $Artists), true, true).$DisplayName;
+ $DisplayName = Artists::display_artists(array(1 => $Artists), true, true).$DisplayName;
}
break;
case 1022: // Show performers on composer pages
@@ -347,14 +346,14 @@ function compare($X, $Y){
unset($ExtendedArtists[4]);
unset($ExtendedArtists[3]);
unset($ExtendedArtists[6]);
- $DisplayName = display_artists($ExtendedArtists).$DisplayName;
+ $DisplayName = Artists::display_artists($ExtendedArtists).$DisplayName;
} elseif(count($GroupArtists)>0) {
- $DisplayName = display_artists(array(1 => $Artists), true, true).$DisplayName;
+ $DisplayName = Artists::display_artists(array(1 => $Artists), true, true).$DisplayName;
}
break;
default: // Show composers otherwise
if (!empty($ExtendedArtists[4])) {
- $DisplayName = display_artists(array(4 => $ExtendedArtists[4]), true, true).$DisplayName;
+ $DisplayName = Artists::display_artists(array(4 => $ExtendedArtists[4]), true, true).$DisplayName;
}
}
@@ -383,19 +382,19 @@ function compare($X, $Y){
$EditionID = 0;
unset($FirstUnknown);
-
+
foreach ($Torrents as $TorrentID => $Torrent) {
if ($Torrent['Remastered'] && !$Torrent['RemasterYear']) {
$FirstUnknown = !isset($FirstUnknown);
}
-
+
if (in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent'])) {
$Torrent['PersonalFL'] = 1;
}
if($Torrent['RemasterTitle'] != $LastRemasterTitle || $Torrent['RemasterYear'] != $LastRemasterYear ||
$Torrent['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Torrent['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber || $FirstUnknown || $Torrent['Media'] != $LastMedia) {
-
+
$EditionID++;
if($Torrent['Remastered'] && $Torrent['RemasterYear'] != 0) {
@@ -405,7 +404,7 @@ function compare($X, $Y){
if($Torrent['RemasterCatalogueNumber']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterCatalogueNumber']); $AddExtra=' / '; }
if($Torrent['RemasterTitle']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterTitle']); $AddExtra=' / '; }
$RemasterName .= $AddExtra.display_str($Torrent['Media']);
-
+
?>
− =$RemasterName?>
@@ -438,14 +437,14 @@ function compare($X, $Y){
[ =$Torrent['HasFile'] ? 'DL' : 'Missing'?>
- if (($LoggedUser['FLTokens'] > 0) && ($Torrent['Size'] < 1073741824)
+ if (($LoggedUser['FLTokens'] > 0) && ($Torrent['Size'] < 1073741824)
&& !in_array($TorrentID, $TokenTorrents) && empty($Torrent['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?>
| FL
} ?> ]
- » =torrent_info($Torrent)?>
+ » =Torrents::torrent_info($Torrent)?>
- =get_size($Torrent['Size'])?>
+ =Format::get_size($Torrent['Size'])?>
=number_format($Torrent['Snatched'])?>
>=number_format($Torrent['Seeders'])?>
=number_format($Torrent['Leechers'])?>
@@ -457,12 +456,12 @@ function compare($X, $Y){
}
-
+
$TorrentDisplayList = ob_get_clean();
//----------------- End building list and getting stats
-show_header($Name, 'browse,requests,bbcode');
+View::show_header($Name, 'browse,requests,bbcode');
?>
@@ -656,10 +655,10 @@ function compare($X, $Y){
if($NumSimilar == 0) { ?>
- None found
+ None found
}
$First = true;
- foreach ($SimilarArray as $SimilarArtist) {
+ foreach ($SimilarArray as $SimilarArtist) {
list($Artist2ID, $Artist2Name, $Score, $SimilarID) = $SimilarArtist;
$Score = $Score/100;
if($First) {
@@ -730,7 +729,7 @@ function compare($X, $Y){
if($CategoryName == "Music") {
$ArtistForm = get_request_artists($RequestID);
- $ArtistLink = display_artists($ArtistForm, true, true);
+ $ArtistLink = Artists::display_artists($ArtistForm, true, true);
$FullName = $ArtistLink."".$Title." [".$Year."] ";
} else if($CategoryName == "Audiobooks" || $CategoryName == "Comedy") {
$FullName = "".$Title." [".$Year."] ";
@@ -764,7 +763,7 @@ function compare($X, $Y){
} ?>
- =get_size($Bounty)?>
+ =Format::get_size($Bounty)?>
=time_diff($TimeAdded)?>
@@ -815,7 +814,7 @@ function compare($X, $Y){
- } // if $NumSimilar>0
+ } // if $NumSimilar>0
if($NumSimilar>0) { ?>
@@ -894,14 +893,14 @@ function require(file, callback) {
-show_footer();
+View::show_footer();
// Cache page for later use
-if($RevisionID) {
+if($RevisionID) {
$Key = "artist_$ArtistID"."_revision_$RevisionID";
-} else {
+} else {
$Key = 'artist_'.$ArtistID;
}
diff --git a/sections/artist/artist_rearrange.php b/sections/artist/artist_rearrange.php
index 6a1fa5af..c4cd40a0 100644
--- a/sections/artist/artist_rearrange.php
+++ b/sections/artist/artist_rearrange.php
@@ -13,7 +13,6 @@ function compare($X, $Y){
// Similar artist map
-include(SERVER_ROOT.'/classes/class_artist.php');
include(SERVER_ROOT.'/classes/class_artists_similar.php');
$ArtistID = $_GET['id'];
@@ -31,7 +30,7 @@ function compare($X, $Y){
if($Data) {
$Data = unserialize($Data);
list($K, list($Name, $Image, $Body, $NumSimilar, $SimilarArray, $TorrentList, $GroupMeta)) = each($Data);
-
+
} else {
$sql = "SELECT
a.Name,
@@ -48,9 +47,9 @@ function compare($X, $Y){
}
$sql .= " GROUP BY a.ArtistID";
$DB->query($sql, MYSQLI_NUM, true);
-
+
if($DB->record_count()==0) { error(404); }
-
+
list($Name, $Image, $Body, $VanityHouseArtist) = $DB->next_record();
}
@@ -72,12 +71,12 @@ function compare($X, $Y){
SUM(rv.Bounty) AS Bounty
FROM requests AS r
LEFT JOIN requests_votes AS rv ON rv.RequestID=r.ID
- LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID
+ LEFT JOIN requests_artists AS ra ON r.ID=ra.RequestID
WHERE ra.ArtistID = ".$ArtistID."
AND r.TorrentID = 0
GROUP BY r.ID
ORDER BY Votes DESC");
-
+
if($DB->record_count() > 0) {
$Requests = $DB->to_array();
} else {
@@ -89,17 +88,17 @@ function compare($X, $Y){
$LastReleaseType = 0;
if(empty($GroupMeta) || empty($TorrentList)) {
- $DB->query("SELECT
+ $DB->query("SELECT
DISTINCT ta.GroupID, ta.Importance, tg.VanityHouse
FROM torrents_artists AS ta
JOIN torrents_group AS tg ON tg.ID=ta.GroupID
WHERE ta.ArtistID='$ArtistID'
ORDER BY ta.Importance, tg.ReleaseType ASC, tg.Year DESC");
-
+
$GroupIDs = $DB->collect('GroupID');
$GroupMeta = $DB->to_array('GroupID', MYSQLI_BOTH, false);
if(count($GroupIDs)>0) {
- $TorrentList = get_groups($GroupIDs, true, true);
+ $TorrentList = Torrents::get_groups($GroupIDs, true, true);
$TorrentList = $TorrentList['matches'];
} else {
$TorrentList = array();
@@ -204,7 +203,7 @@ function display_name($ReleaseType) {
$OpenTable = false;
foreach ($TorrentListByReleaseType as $ReleaseType => $TorrentListForReleaseType) {
$NumTorrentsReleaseType = count($TorrentListForReleaseType);
- if($OpenTable) {
+ if($OpenTable) {
?>
$OpenTable = false;
}
@@ -223,12 +222,12 @@ function display_name($ReleaseType) {
if ((isset($LoggedUser['ArtistOptions']) && array_key_exists($ReleaseType, $LoggedUser['ArtistOptions'])) && $LoggedUser['ArtistOptions'][$ReleaseType] == 0) {
$HideDiscog = " hidden";
- $HideDiscogDefault = true;
+ $HideDiscogDefault = true;
}
else {
$HideDiscog = "";
- $HideDiscogDefault = false;
- }
+ $HideDiscogDefault = false;
+ }
?>
" id="torrents_=$ReleaseTypeLabel?>">
@@ -267,7 +266,7 @@ function display_name($ReleaseType) {
$TagList = explode(' ',str_replace('_','.',$TagList));
$TorrentTags = array();
-
+
// $Tags array is for the sidebar on the right
foreach($TagList as $Tag) {
if(!isset($Tags[$Tag])) {
@@ -281,11 +280,11 @@ function display_name($ReleaseType) {
$TorrentTags = ''.$TorrentTags.'
';
if (($ReleaseType == 1023) || ($ReleaseType == 1024)) {
- $ArtistPrefix = display_artists(array(1 => $GroupArtists));
+ $ArtistPrefix = Artists::display_artists(array(1 => $GroupArtists));
} else {
$ArtistPrefix = '';
}
-
+
$DisplayName = $ArtistPrefix . ''.$GroupName.' ';
if($GroupYear>0) { $DisplayName = $GroupYear. ' - '.$DisplayName; }
@@ -307,33 +306,33 @@ function display_name($ReleaseType) {
$LastRemasterRecordLabel = '';
$LastRemasterCatalogueNumber = '';
$LastMedia = '';
-
+
$EditionID = 0;
-
+
foreach ($Torrents as $TorrentID => $Torrent) {
$NumTorrents++;
-
+
$Torrent['Seeders'] = (int)$Torrent['Seeders'];
$Torrent['Leechers'] = (int)$Torrent['Leechers'];
$Torrent['Snatched'] = (int)$Torrent['Snatched'];
-
+
$NumSeeders+=$Torrent['Seeders'];
$NumLeechers+=$Torrent['Leechers'];
$NumSnatches+=$Torrent['Snatched'];
-
+
if($Torrent['RemasterTitle'] != $LastRemasterTitle || $Torrent['RemasterYear'] != $LastRemasterYear ||
$Torrent['RemasterRecordLabel'] != $LastRemasterRecordLabel || $Torrent['RemasterCatalogueNumber'] != $LastRemasterCatalogueNumber || $Torrent['Media'] != $LastMedia) {
-
+
$EditionID++;
-
- if($Torrent['RemasterTitle'] || $Torrent['RemasterYear'] || $Torrent['RemasterRecordLabel'] || $Torrent['RemasterCatalogueNumber']) {
+
+ if($Torrent['RemasterTitle'] || $Torrent['RemasterYear'] || $Torrent['RemasterRecordLabel'] || $Torrent['RemasterCatalogueNumber']) {
$RemasterName = $Torrent['RemasterYear'];
$AddExtra = " - ";
if($Torrent['RemasterRecordLabel']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterRecordLabel']); $AddExtra=' / '; }
if($Torrent['RemasterCatalogueNumber']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterCatalogueNumber']); $AddExtra=' / '; }
if($Torrent['RemasterTitle']) { $RemasterName .= $AddExtra.display_str($Torrent['RemasterTitle']); $AddExtra=' / '; }
$RemasterName .= $AddExtra.display_str($Torrent['Media']);
-
+
?>
− =$RemasterName?>
@@ -363,9 +362,9 @@ function display_name($ReleaseType) {
[ DL ]
- » =torrent_info($Torrent)?>
+ » =Torrents::torrent_info($Torrent)?>
- =get_size($Torrent['Size'])?>
+ =Format::get_size($Torrent['Size'])?>
=number_format($Torrent['Snatched'])?>
=number_format($Torrent['Seeders'])?>
=number_format($Torrent['Leechers'])?>
@@ -387,7 +386,7 @@ function display_name($ReleaseType) {
//----------------- End building list and getting stats
-show_header($Name, 'browse,requests,artists,bbcode');
+View::show_header($Name, 'browse,requests,artists,bbcode');
?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/better/files.php b/sections/better/files.php
index d1991ba5..27af98c4 100644
--- a/sections/better/files.php
+++ b/sections/better/files.php
@@ -16,13 +16,13 @@
$All = false;
}
-show_header('Torrents with bad file names');
+View::show_header('Torrents with bad file names');
$DB->query("SELECT tfi.TorrentID, t.GroupID FROM torrents_bad_files AS tfi JOIN torrents AS t ON t.ID = tfi.TorrentID ".$Join." ORDER BY tfi.TimeAdded ASC");
$TorrentsInfo = $DB->to_array('TorrentID', MYSQLI_ASSOC);
foreach($TorrentsInfo as $Torrent) {
$GroupIDs[] = $Torrent['GroupID'];
}
-$Results = get_groups($GroupIDs);
+$Results = Torrents::get_groups($GroupIDs);
$Results = $Results['matches'];
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/better/folders.php b/sections/better/folders.php
index af54f581..1df566aa 100644
--- a/sections/better/folders.php
+++ b/sections/better/folders.php
@@ -16,13 +16,13 @@
$All = false;
}
-show_header('Torrents with bad folder names');
+View::show_header('Torrents with bad folder names');
$DB->query("SELECT tbf.TorrentID, t.GroupID FROM torrents_bad_folders AS tbf JOIN torrents AS t ON t.ID = tbf.TorrentID ".$Join." ORDER BY tbf.TimeAdded ASC");
$TorrentsInfo = $DB->to_array('TorrentID', MYSQLI_ASSOC);
foreach($TorrentsInfo as $Torrent) {
$GroupIDs[] = $Torrent['GroupID'];
}
-$Results = get_groups($GroupIDs);
+$Results = Torrents::get_groups($GroupIDs);
$Results = $Results['matches'];
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/better/single.php b/sections/better/single.php
index 1fbc47dc..5e2acce7 100644
--- a/sections/better/single.php
+++ b/sections/better/single.php
@@ -13,9 +13,9 @@
$Cache->cache_value('better_single_groupids', $GroupIDs, 30*60);
}
-$Results = get_groups(array_keys($GroupIDs));
+$Results = Torrents::get_groups(array_keys($GroupIDs));
-show_header('Single seeder FLACs');
+View::show_header('Single seeder FLACs');
?>
@@ -30,7 +30,7 @@
$DisplayName = '';
if(count($Artists)>0) {
- $DisplayName = display_artists(array('1'=>$Artists));
+ $DisplayName = Artists::display_artists(array('1'=>$Artists));
}
$DisplayName.=''.$GroupName.' ';
if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; }
@@ -59,5 +59,5 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/better/snatch.php b/sections/better/snatch.php
index 6b70cd30..17a72a8c 100644
--- a/sections/better/snatch.php
+++ b/sections/better/snatch.php
@@ -49,9 +49,9 @@
if(count($GroupIDs) == 0) { error('No results found'); }
-$Results = get_groups($GroupIDs);
+$Results = Torrents::get_groups($GroupIDs);
-show_header('Transcode Snatches');
+View::show_header('Transcode Snatches');
?>
if($SeedingOnly) { ?>
@@ -76,7 +76,7 @@
$DisplayName = '';
if(count($Artists)>0) {
- $DisplayName = display_artists(array('1'=>$Artists));
+ $DisplayName = Artists::display_artists(array('1'=>$Artists));
}
$DisplayName.='
'.$GroupName.' ';
if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; }
@@ -116,5 +116,5 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/better/tags.php b/sections/better/tags.php
index 844e8ccd..86136a28 100644
--- a/sections/better/tags.php
+++ b/sections/better/tags.php
@@ -16,13 +16,13 @@
$All = false;
}
-show_header('Torrents with bad tags');
+View::show_header('Torrents with bad tags');
$DB->query("SELECT tbt.TorrentID, t.GroupID FROM torrents_bad_tags AS tbt JOIN torrents AS t ON t.ID = tbt.TorrentID ".$Join." ORDER BY tbt.TimeAdded ASC");
$TorrentsInfo = $DB->to_array('TorrentID', MYSQLI_ASSOC);
foreach($TorrentsInfo as $Torrent) {
$GroupIDs[] = $Torrent['GroupID'];
}
-$Results = get_groups($GroupIDs);
+$Results = Torrents::get_groups($GroupIDs);
$Results = $Results['matches'];
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/better/transcode.php b/sections/better/transcode.php
index 8196e19f..62e692b7 100644
--- a/sections/better/transcode.php
+++ b/sections/better/transcode.php
@@ -33,7 +33,7 @@
// If some were fetched from memcached, get their artists
if(!empty($Results['matches'])) { // Fetch the artists for groups
$GroupIDs = array_keys($Results['matches']);
- $Artists = get_artists($GroupIDs);
+ $Artists = Artists::get_artists($GroupIDs);
foreach($Artists as $GroupID=>$Data) {
if(!empty($Data[1])) {
$Results['matches'][$GroupID]['Artists']=$Data[1]; // Only use main artists
@@ -44,7 +44,7 @@
*/
// These ones were not found in the cache, run SQL
if(!empty($Results['notfound'])) {
- $SQLResults = get_groups($Results['notfound']);
+ $SQLResults = Torrents::get_groups($Results['notfound']);
if(is_array($SQLResults['notfound'])) { // Something wasn't found in the db, remove it from results
reset($SQLResults['notfound']);
@@ -64,7 +64,7 @@
$Results = $Results['matches'];
-show_header('Transcode Search');
+View::show_header('Transcode Search');
?>
@@ -96,7 +96,7 @@
$DisplayName = '';
if(count($Artists)>0) {
- $DisplayName = display_artists(array('1'=>$Artists));
+ $DisplayName = Artists::display_artists(array('1'=>$Artists));
}
$DisplayName.='
'.$GroupName.' ';
if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; }
@@ -142,5 +142,5 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/better/upload.php b/sections/better/upload.php
index d5debc57..a5e102a9 100644
--- a/sections/better/upload.php
+++ b/sections/better/upload.php
@@ -43,9 +43,9 @@
if(count($GroupIDs) == 0) { error('No results found'); }
-$Results = get_groups($GroupIDs);
+$Results = Torrents::get_groups($GroupIDs);
-show_header('Transcode Uploads');
+View::show_header('Transcode Uploads');
?>
@@ -63,7 +63,7 @@
$DisplayName = '';
if(count($Artists)>0) {
- $DisplayName = display_artists(array('1'=>$Artists));
+ $DisplayName = Artists::display_artists(array('1'=>$Artists));
}
$DisplayName.=''.$GroupName.' ';
if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; }
@@ -103,5 +103,5 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/blog/index.php b/sections/blog/index.php
index eff79182..63e40c74 100644
--- a/sections/blog/index.php
+++ b/sections/blog/index.php
@@ -2,7 +2,7 @@
enforce_login();
define('ANNOUNCEMENT_FORUM_ID', 19);
-show_header('Blog','bbcode');
+View::show_header('Blog','bbcode');
require(SERVER_ROOT.'/classes/class_text.php');
$Text = new TEXT;
@@ -55,7 +55,7 @@
header('Location: blog.php');
}
} else {
- $ThreadID = create_thread(ANNOUNCEMENT_FORUM_ID, $LoggedUser[ID], $Title, $Body);
+ $ThreadID = Misc::create_thread(ANNOUNCEMENT_FORUM_ID, $LoggedUser[ID], $Title, $Body);
if($ThreadID < 1) {
error(0);
}
@@ -169,5 +169,5 @@
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/bookmarks/add.php b/sections/bookmarks/add.php
index 8ecd6b29..8555b291 100644
--- a/sections/bookmarks/add.php
+++ b/sections/bookmarks/add.php
@@ -46,7 +46,7 @@
if ($Freeleech == "1") { $Title .= " / Freeleech!"; }
if ($Freeleech == "2") { $Title .= " / Neutral leech!"; }
- $UploaderInfo = user_info($UploaderID);
+ $UploaderInfo = Users::user_info($UploaderID);
$Item = $Feed->item($Title,
$Text->strip_bbcode($Body),
'torrents.php?action=download&authkey=[[AUTHKEY]]&torrent_pass=[[PASSKEY]]&id='.$TorrentID,
diff --git a/sections/bookmarks/artists.php b/sections/bookmarks/artists.php
index 91c561f6..25300978 100644
--- a/sections/bookmarks/artists.php
+++ b/sections/bookmarks/artists.php
@@ -27,7 +27,7 @@
$Title = ($Sneaky)?"$Username's bookmarked artists":'Your bookmarked artists';
-show_header($Title,'browse');
+View::show_header($Title,'browse');
?>
@@ -46,7 +46,7 @@
- show_footer();
+ View::show_footer();
die();
} ?>
@@ -92,6 +92,6 @@
-show_footer();
+View::show_footer();
$Cache->cache_value('bookmarks_'.$UserID, serialize(array(array($Username, $TorrentList, $CollageDataList))), 3600);
?>
diff --git a/sections/bookmarks/torrents.php b/sections/bookmarks/torrents.php
index f86c1f1e..d1658a1c 100644
--- a/sections/bookmarks/torrents.php
+++ b/sections/bookmarks/torrents.php
@@ -43,7 +43,7 @@ function compare($X, $Y){
$GroupIDs = $DB->collect('GroupID');
$CollageDataList=$DB->to_array('GroupID', MYSQLI_ASSOC);
if(count($GroupIDs)>0) {
- $TorrentList = get_groups($GroupIDs);
+ $TorrentList = Torrents::get_groups($GroupIDs);
$TorrentList = $TorrentList['matches'];
} else {
$TorrentList = array();
@@ -103,9 +103,9 @@ function compare($X, $Y){
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
- $DisplayName = display_artists($ExtendedArtists);
+ $DisplayName = Artists::display_artists($ExtendedArtists);
} elseif(count($GroupArtists)>0) {
- $DisplayName = display_artists(array('1'=>$GroupArtists));
+ $DisplayName = Artists::display_artists(array('1'=>$GroupArtists));
} else {
$DisplayName = '';
}
@@ -210,9 +210,9 @@ function compare($X, $Y){
} ?>
| RP ]
- » =torrent_info($Torrent)?>
+ » =Torrents::torrent_info($Torrent)?>
- =get_size($Torrent['Size'])?>
+ =Format::get_size($Torrent['Size'])?>
=number_format($Torrent['Snatched'])?>
>=number_format($Torrent['Seeders'])?>
=number_format($Torrent['Leechers'])?>
@@ -255,7 +255,7 @@ function compare($X, $Y){
=time_diff($AddedTime);?>
- =get_size($Torrent['Size'])?>
+ =Format::get_size($Torrent['Size'])?>
=number_format($Torrent['Snatched'])?>
>=number_format($Torrent['Seeders'])?>
=number_format($Torrent['Leechers'])?>
@@ -272,9 +272,9 @@ function compare($X, $Y){
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5])|| !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
- $DisplayName .= display_artists($ExtendedArtists, false);
+ $DisplayName .= Artists::display_artists($ExtendedArtists, false);
} elseif(count($GroupArtists)>0) {
- $DisplayName .= display_artists(array('1'=>$GroupArtists), false);
+ $DisplayName .= Artists::display_artists(array('1'=>$GroupArtists), false);
}
$DisplayName .= $GroupName;
if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';}
@@ -308,7 +308,7 @@ function compare($X, $Y){
$CollagePages[] = $CollagePage;
}
-show_header($Title, 'browse,collage');
+View::show_header($Title, 'browse,collage');
?>
- show_footer();
+ View::show_footer();
die();
} ?>
-show_footer();
+View::show_footer();
$Cache->cache_value('bookmarks_torrent_'.$UserID.'_full', serialize(array(array($TorrentList, $CollageDataList))), 3600);
?>
diff --git a/sections/chat/index.php b/sections/chat/index.php
index 47588fb2..25693756 100644
--- a/sections/chat/index.php
+++ b/sections/chat/index.php
@@ -1,6 +1,6 @@
enforce_login();
-show_header('IRC');
+View::show_header('IRC');
$DB->query("SELECT IRCKey FROM users_main WHERE ID = $LoggedUser[ID]");
list($IRCKey) = $DB->next_record();
@@ -89,5 +89,5 @@
}
}
-show_footer();
+View::show_footer();
?>
diff --git a/sections/collages/all_comments.php b/sections/collages/all_comments.php
index 84b87a11..9e3a5387 100644
--- a/sections/collages/all_comments.php
+++ b/sections/collages/all_comments.php
@@ -19,7 +19,7 @@
error(0);
}
-list($Page,$Limit) = page_limit(POSTS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(POSTS_PER_PAGE);
//Get the cache catalogue
$CatalogueID = floor((POSTS_PER_PAGE*$Page-POSTS_PER_PAGE)/THREAD_CATALOGUE);
@@ -50,7 +50,7 @@
list($Name) = $DB->next_record();
// Start printing
-show_header('Comments for collage '.$Name, 'comments,bbcode');
+View::show_header('Comments for collage '.$Name, 'comments,bbcode');
?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/collages/edit_handle.php b/sections/collages/edit_handle.php
index d899c43d..27dc2c4a 100644
--- a/sections/collages/edit_handle.php
+++ b/sections/collages/edit_handle.php
@@ -20,7 +20,7 @@
$TagList = explode(',',$_POST['tags']);
foreach($TagList as $ID=>$Tag) {
- $TagList[$ID] = sanitize_tag($Tag);
+ $TagList[$ID] = Misc::sanitize_tag($Tag);
}
$TagList = implode(' ',$TagList);
diff --git a/sections/collages/manage.php b/sections/collages/manage.php
index 2d3611a0..d6258eeb 100644
--- a/sections/collages/manage.php
+++ b/sections/collages/manage.php
@@ -21,13 +21,13 @@
$CollageDataList=$DB->to_array('GroupID', MYSQLI_ASSOC);
if(count($GroupIDs)>0) {
- $TorrentList = get_groups($GroupIDs);
+ $TorrentList = Torrents::get_groups($GroupIDs);
$TorrentList = $TorrentList['matches'];
} else {
$TorrentList = array();
}
- show_header('Manage collage '.$Name);
+ View::show_header('Manage collage '.$Name);
?>
@@ -85,9 +85,9 @@
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
- $DisplayName .= display_artists($ExtendedArtists, true, false);
+ $DisplayName .= Artists::display_artists($ExtendedArtists, true, false);
} elseif(count($GroupArtists)>0) {
- $DisplayName .= display_artists(array('1'=>$GroupArtists), true, false);
+ $DisplayName .= Artists::display_artists(array('1'=>$GroupArtists), true, false);
}
$TorrentLink = '
'.$GroupName.' ';
$GroupYear = $GroupYear > 0 ? $GroupYear : '';
@@ -104,7 +104,7 @@
=$GroupYear?>
=$DisplayName?>
=$TorrentLink?>
-
=format_username($UserID, $Username)?>
+
=Users::format_username($UserID, $Username)?>
@@ -131,4 +131,4 @@
- show_footer(); ?>
\ No newline at end of file
+ View::show_footer(); ?>
\ No newline at end of file
diff --git a/sections/collages/new.php b/sections/collages/new.php
index e9433f9b..f3c0b2c2 100644
--- a/sections/collages/new.php
+++ b/sections/collages/new.php
@@ -1,5 +1,5 @@
-show_header('Create a collage');
+View::show_header('Create a collage');
if (!check_perms('site_collages_renamepersonal')) {
$ChangeJS = "OnChange=\"if ( this.options[this.selectedIndex].value == '0') { $('#namebox').hide(); $('#personal').show(); } else { $('#namebox').show(); $('#personal').hide(); }\"";
@@ -86,4 +86,4 @@
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/collages/new_handle.php b/sections/collages/new_handle.php
index a4e80a1e..d8ce2fb4 100644
--- a/sections/collages/new_handle.php
+++ b/sections/collages/new_handle.php
@@ -66,7 +66,7 @@
$TagList = explode(',',$_POST['tags']);
foreach($TagList as $ID=>$Tag) {
- $TagList[$ID] = sanitize_tag($Tag);
+ $TagList[$ID] = Misc::sanitize_tag($Tag);
}
$TagList = implode(' ',$TagList);
@@ -77,7 +77,7 @@
$CollageID = $DB->inserted_id();
$Cache->delete_value('collage_'.$CollageID);
-write_log("Collage ".$CollageID." (".$_POST['name'].") was created by ".$LoggedUser['Username']);
+Misc::write_log("Collage ".$CollageID." (".$_POST['name'].") was created by ".$LoggedUser['Username']);
header('Location: collages.php?id='.$CollageID);
?>
diff --git a/sections/collages/recover.php b/sections/collages/recover.php
index 478db893..6da6500d 100644
--- a/sections/collages/recover.php
+++ b/sections/collages/recover.php
@@ -13,11 +13,11 @@
} else {
$DB->query("UPDATE collages SET Deleted = '0' WHERE ID=$CollageID");
$Cache->delete_value('collage_'.$CollageID);
- write_log("Collage ".$CollageID." was recovered by ".$LoggedUser['Username']);
+ Misc::write_log("Collage ".$CollageID." was recovered by ".$LoggedUser['Username']);
header("Location: collages.php?id=$CollageID");
}
}
-show_header("Collage recovery!");
+View::show_header("Collage recovery!");
?>
- show_footer();
+ View::show_footer();
diff --git a/sections/collages/take_delete.php b/sections/collages/take_delete.php
index 057b3501..6f5824bd 100644
--- a/sections/collages/take_delete.php
+++ b/sections/collages/take_delete.php
@@ -35,7 +35,7 @@
$DB->query("UPDATE collages SET Deleted = '1' WHERE ID='$CollageID'");
}
-write_log("Collage ".$CollageID." (".$Name.") was deleted by ".$LoggedUser['Username'].": ".$Reason);
+Misc::write_log("Collage ".$CollageID." (".$Name.") was deleted by ".$LoggedUser['Username'].": ".$Reason);
$Cache->delete_value('collage_'.$CollageID);
header('Location: collages.php');
diff --git a/sections/comments/index.php b/sections/comments/index.php
index c17c51ed..f1d4b13e 100644
--- a/sections/comments/index.php
+++ b/sections/comments/index.php
@@ -17,14 +17,14 @@
if(!is_number($UserID)) {
error(404);
}
- $UserInfo = user_info($UserID);
+ $UserInfo = Users::user_info($UserID);
$Username = $UserInfo['Username'];
if($LoggedUser['ID'] == $UserID) {
$Self = true;
} else {
$Self = false;
}
- $Perms = get_permissions($UserInfo['PermissionID']);
+ $Perms = Permissions::get_permissions($UserInfo['PermissionID']);
$UserClass = $Perms['Class'];
if (!check_paranoia('torrentcomments', $UserInfo['Paranoia'], $UserClass, $UserID)) { error(403); }
} else {
@@ -39,7 +39,7 @@
$PerPage = POSTS_PER_PAGE;
}
-list($Page,$Limit) = page_limit($PerPage);
+list($Page,$Limit) = Format::page_limit($PerPage);
$OtherLink = '';
if($MyTorrents) {
@@ -51,7 +51,7 @@
else {
$Conditions = "WHERE tc.AuthorID = $UserID";
$Title = 'Comments made by '.($Self?'you':$Username);
- $Header = 'Torrent comments left by '.($Self?'you':format_username($UserID, false, false, false)).'';
+ $Header = 'Torrent comments left by '.($Self?'you':Users::format_username($UserID, false, false, false)).'';
if($Self) $OtherLink = 'Display comments left on your uploads ';
}
@@ -82,14 +82,14 @@
$DB->query("SELECT FOUND_ROWS()");
list($Results) = $DB->next_record();
-$Pages=get_pages($Page,$Results,$PerPage, 11);
+$Pages=Format::get_pages($Page,$Results,$PerPage, 11);
$DB->set_query_id($Comments);
$GroupIDs = $DB->collect('GroupID');
-$Artists = get_artists($GroupIDs);
+$Artists = Artists::get_artists($GroupIDs);
-show_header($Title,'bbcode');
+View::show_header($Title,'bbcode');
$DB->set_query_id($Comments);
?>
@@ -107,14 +107,14 @@
while(list($UserID, $TorrentID, $GroupID, $Title, $PostID, $Body, $AddedTime, $EditedTime, $EditorID) = $DB->next_record()) {
- $UserInfo = user_info($UserID);
+ $UserInfo = Users::user_info($UserID);
?>
#=$PostID?>
- by =format_username($UserID, true, true, true, true, false)?> =time_diff($AddedTime) ?>
- on =display_artists($Artists[$GroupID])?>=$Title?>
+ by =Users::format_username($UserID, true, true, true, true, false)?> =time_diff($AddedTime) ?>
+ on =Artists::display_artists($Artists[$GroupID])?>=$Title?>
@@ -144,7 +144,7 @@
?>
Last edited by
- =format_username($EditorID, false, false, false) ?> =time_diff($EditedTime)?>
+ =Users::format_username($EditorID, false, false, false) ?> =time_diff($EditedTime)?>
}
?>
@@ -164,6 +164,6 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/donate/cancel.php b/sections/donate/cancel.php
index 37590515..7c37bd55 100644
--- a/sections/donate/cancel.php
+++ b/sections/donate/cancel.php
@@ -1,6 +1,6 @@
enforce_login();
-show_header('Donation Canceled');
+View::show_header('Donation Canceled');
?>
- show_footer(); ?>
\ No newline at end of file
+ View::show_footer(); ?>
\ No newline at end of file
diff --git a/sections/donate/complete.php b/sections/donate/complete.php
index f27b8e2a..04fdf4ab 100644
--- a/sections/donate/complete.php
+++ b/sections/donate/complete.php
@@ -1,6 +1,6 @@
enforce_login();
-show_header('Donation Complete');
+View::show_header('Donation Complete');
?>
- show_footer();?>
+ View::show_footer();?>
diff --git a/sections/donate/donate.php b/sections/donate/donate.php
index e637985a..f1d88959 100644
--- a/sections/donate/donate.php
+++ b/sections/donate/donate.php
@@ -13,10 +13,10 @@
$Cache->cache_value('stats_user_count', $UserCount, 0); //inf cache
}
-$DonorPerms = get_permissions(DONOR);
+$DonorPerms = Permissions::get_permissions(DONOR);
if ($_GET['miner']) { $LoggedUser['BitcoinMiner'] = 1; $_GET['showminer'] = 1; }
-show_header('Donate');
+View::show_header('Donate');
?>
@@ -103,4 +103,4 @@
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/donate/donate_gpal.php b/sections/donate/donate_gpal.php
index e7381d12..af46a1d9 100644
--- a/sections/donate/donate_gpal.php
+++ b/sections/donate/donate_gpal.php
@@ -13,9 +13,9 @@
$Cache->cache_value('stats_user_count', $UserCount, 0); //inf cache
}
-$DonorPerms = get_permissions(DONOR);
+$DonorPerms = Permissions::get_permissions(DONOR);
-show_header('Donate');
+View::show_header('Donate');
?>
@@ -105,4 +105,4 @@
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/donate/ipn.php b/sections/donate/ipn.php
index 4778ee3b..82bd6433 100644
--- a/sections/donate/ipn.php
+++ b/sections/donate/ipn.php
@@ -47,10 +47,10 @@
$Cache->begin_transaction('user_info_heavy_'.$_POST['custom']);
$Cache->update_row(false, array('Invites' => $Invites));
$Cache->commit_transaction(0);
- send_pm($_POST['custom'],0,db_string('Thank you for your donation'),db_string('Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Because this is your first time donating, you have now been awarded Donor status as represented by the <3 found on your profile and next to your username where it appears. This has entitled you to a additional site features which you can now explore, and has granted you '.DONOR_INVITES.' invitations to share with others. Thank you for supporting '.SITE_NAME.'.'),'');
+ Misc::send_pm($_POST['custom'],0,db_string('Thank you for your donation'),db_string('Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Because this is your first time donating, you have now been awarded Donor status as represented by the <3 found on your profile and next to your username where it appears. This has entitled you to a additional site features which you can now explore, and has granted you '.DONOR_INVITES.' invitations to share with others. Thank you for supporting '.SITE_NAME.'.'),'');
} else {
//Repeat donor
- send_pm($_POST['custom'],0,db_string('Thank you for your donation'),db_string('Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Your continued support is highly appreciated and helps to make this place possible.'),'');
+ Misc::send_pm($_POST['custom'],0,db_string('Thank you for your donation'),db_string('Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Your continued support is highly appreciated and helps to make this place possible.'),'');
}
@@ -60,7 +60,7 @@
} else {
if ($_POST['mc_gross'] > 0) {
//Donation less than minimum
- send_pm($_POST['custom'],0,db_string('Thank you for your donation'),db_string('Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Unfortunately however this donation was less than the specified minimum donation of '.PAYPAL_MINIMUM.' '.PAYPAL_CURRENCY.' and while we are grateful, no special privileges have been awarded to you.'),'');
+ Misc::send_pm($_POST['custom'],0,db_string('Thank you for your donation'),db_string('Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Unfortunately however this donation was less than the specified minimum donation of '.PAYPAL_MINIMUM.' '.PAYPAL_CURRENCY.' and while we are grateful, no special privileges have been awarded to you.'),'');
} else {
//Failed pending donation
$Message = "User http://".NONSSL_SITE_URL."/user.php?id=".$_POST['custom']." had donation of ".$TotalDonated." ".PAYPAL_CURRENCY." at ".$DonationTime." UTC from ".$_POST['payer_email']." returned.";
@@ -83,7 +83,7 @@
$Cache->begin_transaction('user_info_heavy_'.$_POST['custom']);
$Cache->update_row(false, array('Invites' => $Invites));
$Cache->commit_transaction(0);
- send_pm($_POST['custom'],0,db_string('Notice of donation failure'),db_string('PapPal has just notified us that the donation you sent from '.$_POST['payer_email'].' of '.$TotalDonated.' '.PAYPAL_CURRENCY.' at '.$DonationTime.' UTC has been revoked. Because of this your special privileges have been revoked, and your invites removed.'),'');
+ Misc::send_pm($_POST['custom'],0,db_string('Notice of donation failure'),db_string('PapPal has just notified us that the donation you sent from '.$_POST['payer_email'].' of '.$TotalDonated.' '.PAYPAL_CURRENCY.' at '.$DonationTime.' UTC has been revoked. Because of this your special privileges have been revoked, and your invites removed.'),'');
send_irc("PRIVMSG ".BOT_REPORT_CHAN." :".$Message);
@@ -100,7 +100,7 @@
} else {
$DB->query("INSERT INTO ip_bans
(FromIP, ToIP, Reason) VALUES
- ('".ip2unsigned($_SERVER['REMOTE_ADDR'])."','".ip2long($_SERVER['REMOTE_ADDR'])."', 'Attempted to exploit donation system.')");
+ ('".Tools::ip_to_unsigned($_SERVER['REMOTE_ADDR'])."','".ip2long($_SERVER['REMOTE_ADDR'])."', 'Attempted to exploit donation system.')");
}
fclose ($Socket);
if (check_perms('site_debug')) {
diff --git a/sections/error/index.php b/sections/error/index.php
index 13dce62a..459f4417 100644
--- a/sections/error/index.php
+++ b/sections/error/index.php
@@ -2,7 +2,7 @@
function notify ($Channel, $Message) {
global $LoggedUser;
- send_irc("PRIVMSG ".$Channel." :".$Message." error by ".(!empty($LoggedUser['ID']) ? "https://".SSL_SITE_URL."/user.php?id=".$LoggedUser['ID'] ." (".$LoggedUser['Username'].")" : $_SERVER['REMOTE_ADDR']." (".geoip($_SERVER['REMOTE_ADDR']).")")." accessing https://".SSL_SITE_URL."".$_SERVER['REQUEST_URI'].(!empty($_SERVER['HTTP_REFERER'])? " from ".$_SERVER['HTTP_REFERER'] : ''));
+ send_irc("PRIVMSG ".$Channel." :".$Message." error by ".(!empty($LoggedUser['ID']) ? "https://".SSL_SITE_URL."/user.php?id=".$LoggedUser['ID'] ." (".$LoggedUser['Username'].")" : $_SERVER['REMOTE_ADDR']." (".Tools::geoip($_SERVER['REMOTE_ADDR']).")")." accessing https://".SSL_SITE_URL."".$_SERVER['REQUEST_URI'].(!empty($_SERVER['HTTP_REFERER'])? " from ".$_SERVER['HTTP_REFERER'] : ''));
}
$Errors = array('403','404','413','504');
@@ -47,7 +47,7 @@ function notify ($Channel, $Message) {
}
if(empty($Ajax) && $Error != -1) {
- show_header($Title);
+ View::show_header($Title);
?>
- show_footer();
+ View::show_footer();
} else {
echo $Description;
}
diff --git a/sections/forums/ajax_get_edit.php b/sections/forums/ajax_get_edit.php
index 4c9cde6e..63ae5983 100644
--- a/sections/forums/ajax_get_edit.php
+++ b/sections/forums/ajax_get_edit.php
@@ -65,7 +65,7 @@
if($Depth < count($Edits)) { ?>
«
=(($Depth == 0) ? 'Last edited by' : 'Edited by')?>
- =format_username($UserID, false, false, false) ?> =time_diff($Time,2,true,true)?>
+ =Users::format_username($UserID, false, false, false) ?> =time_diff($Time,2,true,true)?>
} else { ?>
Original Post
}
diff --git a/sections/forums/edit_rules.php b/sections/forums/edit_rules.php
index 0bd48b94..b87dd3ce 100644
--- a/sections/forums/edit_rules.php
+++ b/sections/forums/edit_rules.php
@@ -30,7 +30,7 @@
$DB->query("SELECT ThreadID FROM forums_specific_rules WHERE ForumID = ".$ForumID);
$ThreadIDs = $DB->collect('ThreadID');
-show_header();
+View::show_header();
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/forums/forum.php b/sections/forums/forum.php
index 15d97b60..fa951f83 100644
--- a/sections/forums/forum.php
+++ b/sections/forums/forum.php
@@ -22,7 +22,7 @@
$PerPage = POSTS_PER_PAGE;
}
-list($Page,$Limit) = page_limit(TOPICS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(TOPICS_PER_PAGE);
//---------- Get some data to start processing
@@ -64,7 +64,7 @@
if($LoggedUser['CustomForums'][$ForumID] != 1 && $Forums[$ForumID]['MinClassRead'] > $LoggedUser['Class']) { error(403); }
// Start printing
-show_header('Forums > '. $Forums[$ForumID]['Name']);
+View::show_header('Forums > '. $Forums[$ForumID]['Name']);
?>
Forums > =$ForumName?>
@@ -137,7 +137,7 @@
} ?>
@@ -222,7 +222,7 @@
unset($PageLinks);
?>
- =display_str(cut_string($Title, $TopicLength)) ?>
+ =display_str(Format::cut_string($Title, $TopicLength)) ?>
=$PagesText?>
@@ -232,11 +232,11 @@
} ?>
- by =format_username($LastAuthorID, false, false, false)?> =time_diff($LastTime,1)?>
+ by =Users::format_username($LastAuthorID, false, false, false)?> =time_diff($LastTime,1)?>
=number_format($PostCount-1)?>
- =format_username($AuthorID, false, false, false)?>
+ =Users::format_username($AuthorID, false, false, false)?>
}
} ?>
@@ -249,4 +249,4 @@
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/forums/main.php b/sections/forums/main.php
index 94a18967..185aab2e 100644
--- a/sections/forums/main.php
+++ b/sections/forums/main.php
@@ -27,7 +27,7 @@
$LastRead = array();
}
-show_header('Forums');
+View::show_header('Forums');
?>
Forums
@@ -91,14 +91,14 @@
} else { ?>
- =display_str(cut_string($LastTopic, 50, 1))?>
+ =display_str(Format::cut_string($LastTopic, 50, 1))?>
if (!empty($LastRead[$LastTopicID])) { ?>
} ?>
- by =format_username($LastAuthorID, false, false, false)?> =time_diff($LastTime,1)?>
+ by =Users::format_username($LastAuthorID, false, false, false)?> =time_diff($LastTime,1)?>
=number_format($NumTopics)?>
=number_format($NumPosts)?>
@@ -108,4 +108,4 @@
- show_footer();
+ View::show_footer();
diff --git a/sections/forums/mod_thread.php b/sections/forums/mod_thread.php
index f6807abd..4c736f49 100644
--- a/sections/forums/mod_thread.php
+++ b/sections/forums/mod_thread.php
@@ -117,7 +117,7 @@
$UpdateArray = array(
'IsSticky'=>$Sticky,
'IsLocked'=>$Locked,
- 'Title'=>cut_string($RawTitle, 150, 1, 0),
+ 'Title'=>Format::cut_string($RawTitle, 150, 1, 0),
'ForumID'=>$ForumID
);
$Cache->update_row(false, $UpdateArray);
diff --git a/sections/forums/newthread.php b/sections/forums/newthread.php
index 4d1cfa42..7e5e3454 100644
--- a/sections/forums/newthread.php
+++ b/sections/forums/newthread.php
@@ -20,7 +20,7 @@
if(!check_forumperm($ForumID, 'Write') || !check_forumperm($ForumID, 'Create')) { error(403); }
-show_header('Forums > '.$Forum['Name'].' > New Topic','comments,bbcode');
+View::show_header('Forums > '.$Forum['Name'].' > New Topic','comments,bbcode');
?>
@@ -46,7 +46,7 @@
#XXXXXX
- by =format_username($LoggedUser['ID'], true, true, true, true, true)?>
+ by =Users::format_username($LoggedUser['ID'], true, true, true, true, true)?>
Just now
@@ -149,4 +149,4 @@ function RemoveAnswerField() {
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/forums/search.php b/sections/forums/search.php
index a8866610..2f1a554c 100644
--- a/sections/forums/search.php
+++ b/sections/forums/search.php
@@ -6,7 +6,7 @@
include(SERVER_ROOT.'/classes/class_text.php');
$Text = new TEXT;
-list($Page,$Limit) = page_limit(POSTS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(POSTS_PER_PAGE);
if($LoggedUser['CustomForums']) {
unset($LoggedUser['CustomForums']['']);
@@ -74,7 +74,7 @@
}
// Let's hope we got some results - start printing out the content.
-show_header('Forums'.' > '.'Search', 'bbcode');
+View::show_header('Forums'.' > '.'Search', 'bbcode');
?>
Forums > Search=$Title?>
@@ -257,7 +257,7 @@
list($Results) = $DB->next_record();
$DB->set_query_id($Records);
-$Pages=get_pages($Page,$Results,POSTS_PER_PAGE,9);
+$Pages=Format::get_pages($Page,$Results,POSTS_PER_PAGE,9);
echo $Pages;
?>
@@ -282,9 +282,9 @@
if(empty($ThreadID)) { ?>
- =cut_string($Title, 80); ?>
+ =Format::cut_string($Title, 80); ?>
} else { ?>
- =cut_string($Title, 80); ?>
+ =Format::cut_string($Title, 80); ?>
}
if ($Type == 'body') { ?>
(show)
@@ -308,4 +308,4 @@
=$Pages?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/forums/take_new_thread.php b/sections/forums/take_new_thread.php
index a886a85b..897a414d 100644
--- a/sections/forums/take_new_thread.php
+++ b/sections/forums/take_new_thread.php
@@ -41,7 +41,7 @@
error('Your posting rights have been removed');
}
-$Title = cut_string(trim($_POST['title']), 150, 1, 0);
+$Title = Format::cut_string(trim($_POST['title']), 150, 1, 0);
$ForumID = $_POST['forum'];
diff --git a/sections/forums/take_warn.php b/sections/forums/take_warn.php
index 42bc1b1d..8ac1744a 100644
--- a/sections/forums/take_warn.php
+++ b/sections/forums/take_warn.php
@@ -1,7 +1,7 @@
$LoggedUser['Class']) {
error(403);
}
@@ -20,7 +20,7 @@
$URL = "https://".SSL_SITE_URL."/forums.php?action=viewthread&postid=$PostID#post$PostID";
if ($Length != 'verbal') {
$Time = ((int)$Length) * (7 * 24 * 60 * 60);
- warn_user($UserID, $Time, "$URL - " . $Reason);
+ Tools::warn_user($UserID, $Time, "$URL - " . $Reason);
$Subject = "You have received a warning";
$PrivateMessage = "You have received a $Length week warning for [url=$URL]this post.[/url]\n\n" . $PrivateMessage;
@@ -35,7 +35,7 @@
$DB -> query("INSERT INTO users_warnings_forums (UserID, Comment) VALUES('$UserID', '" . db_string($AdminComment) . "')
ON DUPLICATE KEY UPDATE Comment = CONCAT('" . db_string($AdminComment) . "', Comment)");
-send_pm($UserID, $LoggedUser['ID'], $Subject, $PrivateMessage);
+Misc::send_pm($UserID, $LoggedUser['ID'], $Subject, $PrivateMessage);
//edit the post
$DB -> query("SELECT
diff --git a/sections/forums/thread.php b/sections/forums/thread.php
index 55c0b582..10218b59 100644
--- a/sections/forums/thread.php
+++ b/sections/forums/thread.php
@@ -71,11 +71,11 @@
} else {
$PostNum = 1;
}
-list($Page,$Limit) = page_limit($PerPage, min($ThreadInfo['Posts'],$PostNum));
+list($Page,$Limit) = Format::page_limit($PerPage, min($ThreadInfo['Posts'],$PostNum));
if(($Page-1)*$PerPage > $ThreadInfo['Posts']) {
$Page = ceil($ThreadInfo['Posts']/$PerPage);
}
-list($CatalogueID,$CatalogueLimit) = catalogue_limit($Page,$PerPage,THREAD_CATALOGUE);
+list($CatalogueID,$CatalogueLimit) = Format::catalogue_limit($Page,$PerPage,THREAD_CATALOGUE);
// Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
if(!$Catalogue = $Cache->get_value('thread_'.$ThreadID.'_catalogue_'.$CatalogueID)) {
@@ -96,7 +96,7 @@
$Cache->cache_value('thread_'.$ThreadID.'_catalogue_'.$CatalogueID, $Catalogue, 0);
}
}
-$Thread = catalogue_select($Catalogue,$Page,$PerPage,THREAD_CATALOGUE);
+$Thread = Format::catalogue_select($Catalogue,$Page,$PerPage,THREAD_CATALOGUE);
if($_GET['updatelastread'] != '0') {
$LastPost = end($Thread);
@@ -138,7 +138,7 @@
}
// Start printing
-show_header('Forums'.' > '.$Forums[$ForumID]['Name'].' > '.$ThreadInfo['Title'],'comments,subscriptions,bbcode');
+View::show_header('Forums'.' > '.$Forums[$ForumID]['Name'].' > '.$ThreadInfo['Title'],'comments,subscriptions,bbcode');
?>
@@ -176,7 +176,7 @@
-$Pages=get_pages($Page,$ThreadInfo['Posts'],$PerPage,9);
+$Pages=Format::get_pages($Page,$ThreadInfo['Posts'],$PerPage,9);
echo $Pages;
?>
@@ -381,13 +381,13 @@
foreach($Thread as $Key => $Post){
list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
- list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(user_info($AuthorID));
+ list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
?>
- #=$PostID?>
- =format_username($AuthorID, true, true, true, true, true)?>
+
#=$PostID?>
+ =Users::format_username($AuthorID, true, true, true, true, true)?>
=time_diff($AddedTime,2)?>
if(!$ThreadInfo['IsLocked'] || check_perms('site_moderate_forums')){ ?>
-
[Quote]
@@ -414,7 +414,7 @@
[Report]
if(check_perms('users_warn') && $AuthorID != $LoggedUser['ID']) {
- $AuthorInfo = user_info($AuthorID);
+ $AuthorInfo = Users::user_info($AuthorID);
if($LoggedUser['Class'] >= $AuthorInfo['Class']) { ?>
@@ -478,7 +478,7 @@
#XXXXXX
- by =format_username($LoggedUser['ID'], true, true, true, true, true)?> Just now
+ by =Users::format_username($LoggedUser['ID'], true, true, true, true, true)?> Just now
[Report Post]
@@ -606,4 +606,4 @@
} // If user is moderator
?>
- show_footer();
+ View::show_footer();
diff --git a/sections/forums/warn.php b/sections/forums/warn.php
index 5ab35d2d..cbadc803 100644
--- a/sections/forums/warn.php
+++ b/sections/forums/warn.php
@@ -1,16 +1,16 @@
query("SELECT
p.Body, t.ForumID
FROM forums_posts as p JOIN forums_topics as t on p.TopicID = t.ID
WHERE p.ID='$PostID'");
list($PostBody, $ForumID) = $DB -> next_record();
-show_header('Warn User');
+View::show_header('Warn User');
?>
@@ -61,4 +61,4 @@
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/friends/friends.php b/sections/friends/friends.php
index 9c5f0897..61625b6b 100644
--- a/sections/friends/friends.php
+++ b/sections/friends/friends.php
@@ -13,13 +13,13 @@
-show_header('Friends');
+View::show_header('Friends');
$UserID = $LoggedUser['ID'];
-list($Page,$Limit) = page_limit(FRIENDS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(FRIENDS_PER_PAGE);
// Main query
$DB->query("SELECT
@@ -53,7 +53,7 @@
// Pagination
-$Pages=get_pages($Page,$Results,FRIENDS_PER_PAGE,9);
+$Pages=Format::get_pages($Page,$Results,FRIENDS_PER_PAGE,9);
echo $Pages;
?>
@@ -71,15 +71,15 @@
- =format_username($FriendID, true, true, true, true)?>
+ =Users::format_username($FriendID, true, true, true, true)?>
if(check_paranoia('ratio', $Paranoia, $Class, $FriendID)) { ?>
- Ratio: =ratio($Uploaded, $Downloaded)?>
+ Ratio: =Format::get_ratio_html($Uploaded, $Downloaded)?>
} ?>
if(check_paranoia('uploaded', $Paranoia, $Class, $FriendID)) { ?>
- Up: =get_size($Uploaded)?>
+ Up: =Format::get_size($Uploaded)?>
} ?>
if(check_paranoia('downloaded', $Paranoia, $Class, $FriendID)) { ?>
- Down: =get_size($Downloaded)?>
+ Down: =Format::get_size($Downloaded)?>
} ?>
if(check_paranoia('lastseen', $Paranoia, $Class, $FriendID)) { ?>
@@ -128,5 +128,5 @@
// close ?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/image/index.php b/sections/image/index.php
index a2be933e..14ecaa4a 100644
--- a/sections/image/index.php
+++ b/sections/image/index.php
@@ -67,7 +67,7 @@
// Send PM
- send_pm($UserID,0,"Your avatar has been automatically reset","The following avatar rules have been in effect for months now:
+ Misc::send_pm($UserID,0,"Your avatar has been automatically reset","The following avatar rules have been in effect for months now:
[b]Avatars must not exceed 256kB or be vertically longer than 400px. [/b]
diff --git a/sections/inbox/compose.php b/sections/inbox/compose.php
index 09584562..e7f95ce5 100644
--- a/sections/inbox/compose.php
+++ b/sections/inbox/compose.php
@@ -17,7 +17,7 @@
$DB->query("SELECT Username FROM users_main WHERE ID='$ToID'");
list($Username) = $DB->next_record();
if(!$Username) { error(404); }
-show_header('Compose', 'inbox,bbcode');
+View::show_header('Compose', 'inbox,bbcode');
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/inbox/conversation.php b/sections/inbox/conversation.php
index e446380e..ec112c17 100644
--- a/sections/inbox/conversation.php
+++ b/sections/inbox/conversation.php
@@ -40,7 +40,7 @@
while(list($PMUserID, $Username) = $DB->next_record()) {
$PMUserID = (int)$PMUserID;
- $Users[$PMUserID]['UserStr'] = format_username($PMUserID, true, true, true, true);
+ $Users[$PMUserID]['UserStr'] = Users::format_username($PMUserID, true, true, true, true);
$Users[$PMUserID]['Username'] = $Username;
}
$Users[0]['UserStr'] = 'System'; // in case it's a message from the system
@@ -55,7 +55,7 @@
$Cache->decrement('inbox_new_'.$UserID);
}
-show_header('View conversation '.$Subject, 'comments,inbox,bbcode');
+View::show_header('View conversation '.$Subject, 'comments,inbox,bbcode');
// Get messages
$DB->query("SELECT SentDate, SenderID, Body, ID FROM pm_messages AS m WHERE ConvID='$ConvID' ORDER BY ID");
@@ -165,5 +165,5 @@
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/inbox/forward.php b/sections/inbox/forward.php
index abc96525..a93e0bce 100644
--- a/sections/inbox/forward.php
+++ b/sections/inbox/forward.php
@@ -22,5 +22,5 @@
error("$StaffIDs[$ReceiverID] already has this conversation in their inbox.");
header('Location: inbox.php?action=viewconv&id='.$ConvID);
}
-//show_footer();
+//View::show_footer();
?>
diff --git a/sections/inbox/inbox.php b/sections/inbox/inbox.php
index 5b82b885..027184ba 100644
--- a/sections/inbox/inbox.php
+++ b/sections/inbox/inbox.php
@@ -10,9 +10,9 @@
}
if(!in_array($Section, array('inbox', 'sentbox'))) { error(404); }
-list($Page,$Limit) = page_limit(MESSAGES_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(MESSAGES_PER_PAGE);
-show_header('Inbox');
+View::show_header('Inbox');
?>
= ($Section == 'sentbox') ? 'Sentbox' : 'Inbox' ?>
@@ -72,14 +72,14 @@
list($NumResults) = $DB->next_record();
$DB->set_query_id($Results);
-$CurURL = get_url(array('sort'));
+$CurURL = Format::get_url(array('sort'));
if(empty($CurURL)) {
$CurURL = "inbox.php?";
} else {
$CurURL = "inbox.php?".$CurURL."&";
}
-$Pages=get_pages($Page,$NumResults,MESSAGES_PER_PAGE,9);
+$Pages=Format::get_pages($Page,$NumResults,MESSAGES_PER_PAGE,9);
echo $Pages;
?>
@@ -145,10 +145,10 @@
if($Unread) { echo '';} ?>
- =format_username($SenderID, true, true, true, true)?>
+ =Users::format_username($SenderID, true, true, true, true)?>
=time_diff($Date)?>
if(check_perms('users_mod')) { ?>
- =($ForwardedID && $ForwardedID != $LoggedUser['ID'] ? format_username($ForwardedID, false, false, false):'')?>
+ =($ForwardedID && $ForwardedID != $LoggedUser['ID'] ? Users::format_username($ForwardedID, false, false, false):'')?>
} ?>
} ?>
@@ -162,5 +162,5 @@
=$Pages?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/inbox/takecompose.php b/sections/inbox/takecompose.php
index 87cd9c71..eb92c2c6 100644
--- a/sections/inbox/takecompose.php
+++ b/sections/inbox/takecompose.php
@@ -48,7 +48,7 @@
die();
}
-$ConvID = send_pm($ToID,$LoggedUser['ID'],db_string($Subject),db_string($Body),$ConvID);
+$ConvID = Misc::send_pm($ToID,$LoggedUser['ID'],db_string($Subject),db_string($Body),$ConvID);
header('Location: inbox.php');
?>
diff --git a/sections/index/feat_album.php b/sections/index/feat_album.php
index 3148bafb..76caef18 100644
--- a/sections/index/feat_album.php
+++ b/sections/index/feat_album.php
@@ -6,12 +6,12 @@
$Cache->cache_value('featured_album', $FeaturedAlbum, 0);
}
if(is_number($FeaturedAlbum['GroupID'])) {
- $Artists = get_artist($FeaturedAlbum['GroupID']);
+ $Artists = Artists::get_artist($FeaturedAlbum['GroupID']);
?>
diff --git a/sections/index/private.php b/sections/index/private.php
index 3bad0ee4..3b830467 100644
--- a/sections/index/private.php
+++ b/sections/index/private.php
@@ -25,7 +25,7 @@
$LoggedUser['LastReadNews'] = $News[0][0];
}
-show_header('News','bbcode');
+View::show_header('News','bbcode');
?>
-show_footer(array('disclaimer'=>true));
+View::show_footer(array('disclaimer'=>true));
function contest() {
global $DB, $Cache, $LoggedUser;
@@ -458,7 +458,7 @@ function contest() {
foreach ($Contest as $User) {
list($UserID, $Points, $Username) = $User;
?>
- =format_username($UserID, false, false, false)?> (=number_format($Points)?>)
+ =Users::format_username($UserID, false, false, false)?> (=number_format($Points)?>)
}
?>
diff --git a/sections/index/public.php b/sections/index/public.php
index 94451d12..00eb1311 100644
--- a/sections/index/public.php
+++ b/sections/index/public.php
@@ -1,4 +1,4 @@
- show_header(); ?>
+ View::show_header(); ?>
You've stumbled upon a door where your mind is the key. There are none who will lend you guidance; these trials are yours to conquer alone. Entering here will take more than mere logic and strategy, but the criteria are just as hidden as what they reveal. Find yourself, and you will find the very thing hidden behind this page. Beyond here is something like a utopia - beyond here is What.CD.
This is a mirage.
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/log/index.php b/sections/log/index.php
index bbfc5cfa..012b3f9c 100644
--- a/sections/log/index.php
+++ b/sections/log/index.php
@@ -3,7 +3,7 @@
if (!defined('LOG_ENTRIES_PER_PAGE')) {
define('LOG_ENTRIES_PER_PAGE', 100);
}
-show_header("Site log");
+View::show_header("Site log");
include(SERVER_ROOT.'/sections/log/sphinx.php');
?>
@@ -22,14 +22,14 @@
-
+
if($TotalMatches > LOG_ENTRIES_PER_PAGE) { ?>
- $Pages = get_pages($Page,$TotalMatches,LOG_ENTRIES_PER_PAGE,9);
+ $Pages = Format::get_pages($Page,$TotalMatches,LOG_ENTRIES_PER_PAGE,9);
echo $Pages;?>
} ?>
@@ -195,4 +195,4 @@
-show_footer(); ?>
+View::show_footer(); ?>
diff --git a/sections/log/sphinx.php b/sections/log/sphinx.php
index caccda35..049f147d 100644
--- a/sections/log/sphinx.php
+++ b/sections/log/sphinx.php
@@ -1,6 +1,4 @@
-require(SERVER_ROOT.'/classes/class_sphinxql.php');
-
if(!empty($_GET['page']) && is_number($_GET['page'])) {
$Page = min(SPHINX_MAX_MATCHES/LOG_ENTRIES_PER_PAGE, $_GET['page']);
$Offset = ($Page-1)*LOG_ENTRIES_PER_PAGE;
@@ -15,7 +13,7 @@
$TotalMatches = 0;
} elseif($NumResults == LOG_ENTRIES_PER_PAGE) {
// This is a lot faster than SQL_CALC_FOUND_ROWS
- $SphQL = new SPHINXQL_QUERY();
+ $SphQL = new SphinxQL_Query();
$Result = $SphQL->select('id')->from('log, log_delta')->limit(0, 1, 1)->query();
$Debug->log_var($Result, '$Result');
$TotalMatches = min(SPHINX_MAX_MATCHES, $Result->get_meta('total_found'));
@@ -25,7 +23,7 @@
$QueryStatus = 0;
} else {
$Page = min(SPHINX_MAX_MATCHES/TORRENTS_PER_PAGE, $Page);
- $SphQL = new SPHINXQL_QUERY();
+ $SphQL = new SphinxQL_Query();
$SphQL->select('id')
->from('log, log_delta')
->where_match($_GET['search'], 'message')
diff --git a/sections/log/sql.php b/sections/log/sql.php
index e81f48b0..f52cf0a6 100644
--- a/sections/log/sql.php
+++ b/sections/log/sql.php
@@ -1,5 +1,5 @@
-list($Page,$Limit) = page_limit(LOG_ENTRIES_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(LOG_ENTRIES_PER_PAGE);
if(!empty($_GET['search'])) {
$Search = db_string($_GET['search']);
diff --git a/sections/login/disabled.php b/sections/login/disabled.php
index 3080d387..5ce4c133 100644
--- a/sections/login/disabled.php
+++ b/sections/login/disabled.php
@@ -1,5 +1,5 @@
-show_header('Disabled');
+View::show_header('Disabled');
if(empty($_POST['submit']) || empty($_POST['username'])) {
?>
@@ -90,5 +90,5 @@ function toggle_visibility(id) {
}
-show_footer();
+View::show_footer();
?>
diff --git a/sections/login/index.php b/sections/login/index.php
index a9bcf8c1..b635e41d 100644
--- a/sections/login/index.php
+++ b/sections/login/index.php
@@ -14,7 +14,7 @@
}
// Check if IP is banned
-if(site_ban_ip($_SERVER['REMOTE_ADDR'])) {
+if(Tools::site_ban_ip($_SERVER['REMOTE_ADDR'])) {
error('Your IP has been banned.');
}
@@ -56,7 +56,7 @@
$DB->query("UPDATE
users_main AS m,
users_info AS i
- SET m.PassHash='".db_string(make_crypt_hash($_REQUEST['password']))."',
+ SET m.PassHash='".db_string(Users::make_crypt_hash($_REQUEST['password']))."',
i.ResetKey='',
i.ResetExpires='0000-00-00 00:00:00'
WHERE m.ID='".db_string($UserID)."'
@@ -111,7 +111,7 @@
if ($UserID) {
// Email exists in the database
// Set ResetKey, send out email, and set $Sent to 1 to show success page
- $ResetKey=make_secret();
+ $ResetKey=Users::make_secret();
$DB->query("UPDATE users_info SET
ResetKey='".db_string($ResetKey)."',
ResetExpires='".time_plus(60*60)."'
@@ -127,7 +127,7 @@
$TPL->set('SITE_NAME',SITE_NAME);
$TPL->set('SITE_URL',NONSSL_SITE_URL);
- send_email($Email,'Password reset information for '.SITE_NAME,$TPL->get(),'noreply');
+ Misc::send_email($Email,'Password reset information for '.SITE_NAME,$TPL->get(),'noreply');
$Sent=1; // If $Sent is 1, recover_step1.php displays a success message
//Log out all of the users current sessions
@@ -185,7 +185,7 @@ function log_attempt($UserID) {
WHERE ID='".db_string($AttemptID)."'");
if ($Bans>9) { // Automated bruteforce prevention
- $IP = ip2unsigned($_SERVER['REMOTE_ADDR']);
+ $IP = Tools::ip_to_unsigned($_SERVER['REMOTE_ADDR']);
$DB->query("SELECT Reason FROM ip_bans WHERE ".$IP." BETWEEN FromIP AND ToIP");
if($DB->record_count() > 0) {
//Ban exists already, only add new entry if not for same reason
@@ -236,13 +236,13 @@ function log_attempt($UserID) {
AND Username<>''");
list($UserID,$PermissionID,$CustomPermissions,$PassHash,$Secret,$Enabled)=$DB->next_record(MYSQLI_NUM, array(2));
if (strtotime($BannedUntil)query("UPDATE users_main SET passhash = '".db_string($CryptHash)."' WHERE ID = $UserID");
}
if ($Enabled == 1) {
- $SessionID = make_secret();
+ $SessionID = Users::make_secret();
$Cookie = $Enc->encrypt($Enc->encrypt($SessionID.'|~|'.$UserID));
if(isset($_POST['keeplogged']) && $_POST['keeplogged']) {
@@ -255,7 +255,7 @@ function log_attempt($UserID) {
//TODO: another tracker might enable this for donors, I think it's too stupid to bother adding that
// Because we <3 our staff
- $Permissions = get_permissions($PermissionID);
+ $Permissions = Permissions::get_permissions($PermissionID);
$CustomPermissions = unserialize($CustomPermissions);
if (
isset($Permissions['Permissions']['site_disable_ip_history']) ||
diff --git a/sections/login/login.php b/sections/login/login.php
index a1d645f4..bfe3c74b 100644
--- a/sections/login/login.php
+++ b/sections/login/login.php
@@ -1,4 +1,4 @@
- show_header('Login'); ?>
+ View::show_header('Login'); ?>
You appear to have cookies disabled.
You appear to have javascript disabled.
@@ -63,4 +63,4 @@
$('#no-cookies').show();
}
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/login/recover_step1.php b/sections/login/recover_step1.php
index 864cb0fb..aa84eda8 100644
--- a/sections/login/recover_step1.php
+++ b/sections/login/recover_step1.php
@@ -1,5 +1,5 @@
-show_header('Recover Password','validate');
+View::show_header('Recover Password','validate');
echo $Validate->GenerateJS('recoverform');
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/login/recover_step2.php b/sections/login/recover_step2.php
index 6f035787..e764e047 100644
--- a/sections/login/recover_step2.php
+++ b/sections/login/recover_step2.php
@@ -1,5 +1,5 @@
-show_header('Recover Password','validate');
+View::show_header('Recover Password','validate');
echo $Validate->GenerateJS('recoverform');
?>
@@ -34,5 +34,5 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/peerupdate/index.php b/sections/peerupdate/index.php
index e7662a31..db21eee7 100644
--- a/sections/peerupdate/index.php
+++ b/sections/peerupdate/index.php
@@ -6,7 +6,7 @@
}
if (check_perms('admin_schedule')) {
- show_header();
+ View::show_header();
echo '';
}
@@ -76,6 +76,6 @@
if (check_perms('admin_schedule')) {
echo '';
- show_footer();
+ View::show_footer();
}
?>
diff --git a/sections/register/closed.php b/sections/register/closed.php
index aca9bc7c..c9ba8322 100644
--- a/sections/register/closed.php
+++ b/sections/register/closed.php
@@ -1,9 +1,9 @@
-show_header('Registration Closed');
+View::show_header('Registration Closed');
?>
Sorry, the site is currently invite only.
-show_footer();
+View::show_footer();
?>
diff --git a/sections/register/code.php b/sections/register/code.php
index c59833ca..1f2abf00 100644
--- a/sections/register/code.php
+++ b/sections/register/code.php
@@ -1,5 +1,5 @@
-show_header('Register');
+View::show_header('Register');
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/register/index.php b/sections/register/index.php
index 4e654e42..6d2307d7 100644
--- a/sections/register/index.php
+++ b/sections/register/index.php
@@ -66,7 +66,7 @@
}
if(!$Err) {
- $torrent_pass=make_secret();
+ $torrent_pass=Users::make_secret();
//Previously SELECT COUNT(ID) FROM users_main, which is a lot slower.
$DB->query("SELECT ID FROM users_main LIMIT 1");
@@ -81,12 +81,12 @@
$Enabled = '0';
}
- $ipcc = geoip($_SERVER['REMOTE_ADDR']);
+ $ipcc = Tools::geoip($_SERVER['REMOTE_ADDR']);
$DB->query("INSERT INTO users_main
(Username,Email,PassHash,torrent_pass,IP,PermissionID,Enabled,Invites,Uploaded,ipcc) VALUES
- ('".db_string(trim($_POST['username']))."','".db_string($_POST['email'])."','".db_string(make_crypt_hash($_POST['password']))."','".db_string($torrent_pass)."','".db_string($_SERVER['REMOTE_ADDR'])."','".$Class."','".$Enabled."','".STARTING_INVITES."', '524288000', '$ipcc')");
+ ('".db_string(trim($_POST['username']))."','".db_string($_POST['email'])."','".db_string(Users::make_crypt_hash($_POST['password']))."','".db_string($torrent_pass)."','".db_string($_SERVER['REMOTE_ADDR'])."','".$Class."','".$Enabled."','".STARTING_INVITES."', '524288000', '$ipcc')");
$UserID = $DB->inserted_id();
@@ -96,7 +96,7 @@
$DB->query("SELECT ID FROM stylesheets WHERE `Default`='1'");
list($StyleID) = $DB->next_record();
- $AuthKey = make_secret();
+ $AuthKey = Users::make_secret();
$DB->query("INSERT INTO users_info (UserID,StyleID,AuthKey, Inviter, JoinDate) VALUES ('$UserID','$StyleID','".db_string($AuthKey)."', '$InviterID', '".sqltime()."')");
@@ -187,8 +187,8 @@
$TPL->set('SITE_NAME',SITE_NAME);
$TPL->set('SITE_URL',SITE_URL);
- send_email($_REQUEST['email'],'New account confirmation at '.SITE_NAME,$TPL->get(),'noreply');
- update_tracker('add_user', array('id' => $UserID, 'passkey' => $torrent_pass));
+ Misc::send_email($_REQUEST['email'],'New account confirmation at '.SITE_NAME,$TPL->get(),'noreply');
+ Tracker::update_tracker('add_user', array('id' => $UserID, 'passkey' => $torrent_pass));
$Sent=1;
diff --git a/sections/register/step1.php b/sections/register/step1.php
index 06c4c2f9..4ba7513b 100644
--- a/sections/register/step1.php
+++ b/sections/register/step1.php
@@ -1,5 +1,5 @@
-show_header('Register','validate');
+View::show_header('Register','validate');
echo $Val->GenerateJS('registerform');
?>
@@ -66,4 +66,4 @@
-show_footer();
+View::show_footer();
diff --git a/sections/register/step2.php b/sections/register/step2.php
index c79cb304..4af732a0 100644
--- a/sections/register/step2.php
+++ b/sections/register/step2.php
@@ -1,10 +1,10 @@
-show_header('Registration Complete');
+View::show_header('Registration Complete');
?>
Congratulations! Your account has been created.
You can now log into your account using the
login page.
-show_footer();
+View::show_footer();
?>
diff --git a/sections/reports/compose.php b/sections/reports/compose.php
index 43f007e6..6767e2f5 100644
--- a/sections/reports/compose.php
+++ b/sections/reports/compose.php
@@ -32,7 +32,7 @@
if(!$ComposeToUsername) {
error(404);
}
-show_header('Compose', 'inbox,bbcode');
+View::show_header('Compose', 'inbox,bbcode');
switch($Type) {
case "user" :
@@ -52,7 +52,7 @@
$Error = "No request with the reported ID found";
} else {
list($Name) = $DB->next_record();
- $TypeLink = "[url=https://".SSL_SITE_URL."requests.php?action=view&id=".$ThingID."]".display_str($Name)."[/url]";
+ $TypeLink = "[url=https://".SSL_SITE_URL."/requests.php?action=view&id=".$ThingID."]".display_str($Name)."[/url]";
$Subject = "Request Report: ". display_str($Name);
}
@@ -63,7 +63,7 @@
$Error = "No collage with the reported ID found";
} else {
list($Name) = $DB->next_record();
- $TypeLink = "[url=https://".SSL_SITE_URL."collage.php?id=".$ThingID."]".display_str($Name)."[/url]";
+ $TypeLink = "[url=https://".SSL_SITE_URL."/collage.php?id=".$ThingID."]".display_str($Name)."[/url]";
$Subject = "Collage Report: ". display_str($Name);
}
@@ -74,7 +74,7 @@
$Error = "No forum thread with the reported ID found";
} else {
list($Title) = $DB->next_record();
- $TypeLink = "[url=https://".SSL_SITE_URL."forums.php?action=viewthread&threadid=".$ThingID."]".display_str($Title)."[/url]";
+ $TypeLink = "[url=https://".SSL_SITE_URL."/forums.php?action=viewthread&threadid=".$ThingID."]".display_str($Title)."[/url]";
$Subject = "Thread Report: ". display_str($Title);
}
@@ -90,7 +90,7 @@
$Error = "No forum post with the reported ID found";
} else {
list($PostID,$Body,$TopicID,$PostNum) = $DB->next_record();
- $TypeLink = "[url=https://".SSL_SITE_URL."forums.php?action=viewthread&threadid=".$TopicID."&post=".$PostNum."#post".$PostID."]FORUM POST[/url]";
+ $TypeLink = "[url=https://".SSL_SITE_URL."/forums.php?action=viewthread&threadid=".$TopicID."&post=".$PostNum."#post".$PostID."]FORUM POST[/url]";
$Subject = "Post Report";
}
@@ -102,7 +102,7 @@
} else {
list($RequestID, $Body, $PostNum) = $DB->next_record();
$PageNum = ceil($PostNum / TORRENT_COMMENTS_PER_PAGE);
- $TypeLink = "[url=https://".SSL_SITE_URL."requests.php?action=view&id=".$RequestID."&page=".$PageNum."#post".$ThingID."]REQUEST COMMENT[/url]";
+ $TypeLink = "[url=https://".SSL_SITE_URL."/requests.php?action=view&id=".$RequestID."&page=".$PageNum."#post".$ThingID."]REQUEST COMMENT[/url]";
$Subject = "Request Comment Report";
}
@@ -114,7 +114,7 @@
} else {
list($GroupID, $Body, $PostNum) = $DB->next_record();
$PageNum = ceil($PostNum / TORRENT_COMMENTS_PER_PAGE);
- $TypeLink = "[url=https://".SSL_SITE_URL."torrents.php?id=".$GroupID."&page=".$PageNum."#post".$ThingID."]TORRENT COMMENT[/url]";
+ $TypeLink = "[url=https://".SSL_SITE_URL."/torrents.php?id=".$GroupID."&page=".$PageNum."#post".$ThingID."]TORRENT COMMENT[/url]";
$Subject = "Torrent Comment Report";
}
@@ -127,7 +127,7 @@
list($CollageID, $Body, $PostNum) = $DB->next_record();
$PerPage = POSTS_PER_PAGE;
$PageNum = ceil($PostNum / $PerPage);
- $TypeLink = "[url=https://".SSL_SITE_URL."collage.php?action=comments&collageid=".$CollageID."&page=".$PageNum."#post".$ThingID."]COLLAGE COMMENT[/url]";
+ $TypeLink = "[url=https://".SSL_SITE_URL."/collage.php?action=comments&collageid=".$CollageID."&page=".$PageNum."#post".$ThingID."]COLLAGE COMMENT[/url]";
$Subject = "Collage Comment Report";
}
break;
@@ -173,5 +173,5 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/reports/report.php b/sections/reports/report.php
index 5789b856..f12719f5 100644
--- a/sections/reports/report.php
+++ b/sections/reports/report.php
@@ -100,7 +100,7 @@
break;
}
-show_header('Report a '.$Type['title'],'bbcode');
+View::show_header('Report a '.$Type['title'],'bbcode');
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/reports/stats.php b/sections/reports/stats.php
index 1da56f41..0347eb3c 100644
--- a/sections/reports/stats.php
+++ b/sections/reports/stats.php
@@ -4,7 +4,7 @@
error(403);
}
-show_header('Other reports stats');
+View::show_header('Other reports stats');
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/reports/takecompose.php b/sections/reports/takecompose.php
index 35ec6a1e..4532e9b8 100644
--- a/sections/reports/takecompose.php
+++ b/sections/reports/takecompose.php
@@ -48,7 +48,7 @@
die();
}
-$ConvID = send_pm($ToID,$LoggedUser['ID'],db_string($Subject),db_string($Body),$ConvID);
+$ConvID = Misc::send_pm($ToID,$LoggedUser['ID'],db_string($Subject),db_string($Body),$ConvID);
header('Location: reports.php');
?>
diff --git a/sections/reportsv2/ajax_new_report.php b/sections/reportsv2/ajax_new_report.php
index b98ea5bd..393497a3 100644
--- a/sections/reportsv2/ajax_new_report.php
+++ b/sections/reportsv2/ajax_new_report.php
@@ -289,7 +289,7 @@
GROUP BY tg.ID");
list($ExtraGroupName, $ExtraGroupID, $ExtraArtistID, $ExtraArtistName, $ExtraYear, $ExtraTime, $ExtraRemastered, $ExtraRemasterTitle,
- $ExtraRemasterYear, $ExtraMedia, $ExtraFormat, $ExtraEncoding, $ExtraSize, $ExtraHasCue, $ExtraHasLog, $ExtraLogScore, $ExtraUploaderID, $ExtraUploaderName) = display_array($DB->next_record());
+ $ExtraRemasterYear, $ExtraMedia, $ExtraFormat, $ExtraEncoding, $ExtraSize, $ExtraHasCue, $ExtraHasLog, $ExtraLogScore, $ExtraUploaderID, $ExtraUploaderName) = Misc::display_array($DB->next_record());
if($ExtraGroupName) {
diff --git a/sections/reportsv2/ajax_take_pm.php b/sections/reportsv2/ajax_take_pm.php
index 5ef52061..1f607667 100644
--- a/sections/reportsv2/ajax_take_pm.php
+++ b/sections/reportsv2/ajax_take_pm.php
@@ -70,5 +70,5 @@
if(isset($Err)) {
echo $Err;
} else {
- send_pm($ToID, $LoggedUser['ID'], db_string($Subject), db_string($Message));
+ Misc::send_pm($ToID, $LoggedUser['ID'], db_string($Subject), db_string($Message));
}
diff --git a/sections/reportsv2/report.php b/sections/reportsv2/report.php
index f3bb9c2c..44799e78 100644
--- a/sections/reportsv2/report.php
+++ b/sections/reportsv2/report.php
@@ -15,7 +15,7 @@
list($CategoryID) = $DB->next_record();
}
-show_header('Report', 'reportsv2');
+View::show_header('Report', 'reportsv2');
?>
@@ -83,5 +83,5 @@
-show_footer();
+View::show_footer();
?>
\ No newline at end of file
diff --git a/sections/reportsv2/reports.php b/sections/reportsv2/reports.php
index 258250cc..efbfe984 100644
--- a/sections/reportsv2/reports.php
+++ b/sections/reportsv2/reports.php
@@ -8,7 +8,7 @@
error(403);
}
-show_header('Reports V2!', 'reportsv2');
+View::show_header('Reports V2!', 'reportsv2');
?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/upload/upload_handle.php b/sections/upload/upload_handle.php
index 27f4a89c..ba866602 100644
--- a/sections/upload/upload_handle.php
+++ b/sections/upload/upload_handle.php
@@ -287,7 +287,7 @@
for($i = 0, $il = count($Artists); $i < $il; $i++) {
if(trim($Artists[$i]) != "") {
if(!in_array($Artists[$i], trim($ArtistNames))) {
- $ArtistForm[$Importance[$i]][] = array('name' => normalise_artist_name($Artists[$i]));
+ $ArtistForm[$Importance[$i]][] = array('name' => Artists::normalise_artist_name($Artists[$i]));
if($Importance[$i] == 1) {
$MainArtistCount++;
}
@@ -299,14 +299,14 @@
$Err = "Please enter at least one main artist";
$ArtistForm = array();
}
- $LogName .= display_artists($ArtistForm, false, true, false);
+ $LogName .= Artists::display_artists($ArtistForm, false, true, false);
} elseif($Type == "Music" && empty($ArtistForm)) {
$DB->query("SELECT ta.ArtistID,aa.Name,ta.Importance FROM torrents_artists AS ta JOIN artists_alias AS aa ON ta.AliasID = aa.AliasID WHERE ta.GroupID = ".$Properties['GroupID']." ORDER BY ta.Importance ASC, aa.Name ASC;");
while(list($ArtistID,$ArtistName,$ArtistImportance) = $DB->next_record(MYSQLI_BOTH, false)) {
$ArtistForm[$ArtistImportance][] = array('id' => $ArtistID, 'name' => display_str($ArtistName));
$ArtistsUnescaped[$ArtistImportance][] = array('name' => $ArtistName);
}
- $LogName .= display_artists($ArtistsUnescaped, false, true, false);
+ $LogName .= Artists::display_artists($ArtistsUnescaped, false, true, false);
}
@@ -388,10 +388,10 @@
}
// To be stored in the database
-$FilePath = isset($Tor->Val['info']->Val['files']) ? db_string(make_utf8($DirName)) : "";
+$FilePath = isset($Tor->Val['info']->Val['files']) ? db_string(Format::make_utf8($DirName)) : "";
// Name {{{Size}}}|||Name {{{Size}}}|||Name {{{Size}}}|||Name {{{Size}}}
-$FileString = "'".db_string(make_utf8(implode('|||', $TmpFileList)))."'";
+$FileString = "'".db_string(Format::make_utf8(implode('|||', $TmpFileList)))."'";
// Number of files described in torrent
$NumFiles = count($FileList);
@@ -460,7 +460,7 @@
$NoRevision = true;
}
}
- $Properties['Artist'] = display_artists(get_artist($GroupID), false, false);
+ $Properties['Artist'] = Artists::display_artists(Artists::get_artist($GroupID), false, false);
}
}
if(!$GroupID) {
@@ -492,7 +492,7 @@
$NoRevision = true;
}
}
- $ArtistForm = get_artist($GroupID);
+ $ArtistForm = Artists::get_artist($GroupID);
//This torrent belongs in a group
break;
@@ -598,9 +598,9 @@
$Tags = explode(',', $Properties['TagList']);
if(!$Properties['GroupID']) {
foreach($Tags as $Tag) {
- $Tag = sanitize_tag($Tag);
+ $Tag = Misc::sanitize_tag($Tag);
if(!empty($Tag)) {
- $Tag = get_alias_tag($Tag);
+ $Tag = Misc::get_alias_tag($Tag);
$DB->query("INSERT INTO tags
(Name, UserID) VALUES
('".$Tag."', $LoggedUser[ID])
@@ -637,7 +637,7 @@
$Cache->increment('stats_torrent_count');
$TorrentID = $DB->inserted_id();
-update_tracker('add_torrent', array('id' => $TorrentID, 'info_hash' => rawurlencode($InfoHash), 'freetorrent' => $T['FreeLeech']));
+Tracker::update_tracker('add_torrent', array('id' => $TorrentID, 'info_hash' => rawurlencode($InfoHash), 'freetorrent' => $T['FreeLeech']));
@@ -646,10 +646,10 @@
$DB->query("INSERT INTO torrents_files (TorrentID, File) VALUES ($TorrentID, '".db_string($Tor->dump_data())."')");
-write_log("Torrent $TorrentID ($LogName) (".number_format($TotalSize/(1024*1024), 2)." MB) was uploaded by " . $LoggedUser['Username']);
-write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], "uploaded (".number_format($TotalSize/(1024*1024), 2)." MB)", 0);
+Misc::write_log("Torrent $TorrentID ($LogName) (".number_format($TotalSize/(1024*1024), 2)." MB) was uploaded by " . $LoggedUser['Username']);
+Torrents::write_group_log($GroupID, $TorrentID, $LoggedUser['ID'], "uploaded (".number_format($TotalSize/(1024*1024), 2)." MB)", 0);
-update_hash($GroupID);
+Torrents::update_hash($GroupID);
@@ -682,7 +682,7 @@
if(count($RecentUploads) == 5) {
array_pop($RecentUploads);
}
- array_unshift($RecentUploads, array('ID'=>$GroupID,'Name'=>trim($Properties['Title']),'Artist'=>display_artists($ArtistForm, false, true),'WikiImage'=>trim($Properties['Image'])));
+ array_unshift($RecentUploads, array('ID'=>$GroupID,'Name'=>trim($Properties['Title']),'Artist'=>Artists::display_artists($ArtistForm, false, true),'WikiImage'=>trim($Properties['Image'])));
$Cache->cache_value('recent_uploads_'.$UserID, $RecentUploads, 0);
} while (0);
}
@@ -699,7 +699,7 @@
//--------------- IRC announce and feeds ---------------------------------------//
$Announce = "";
-if($Type == 'Music'){ $Announce .= display_artists($ArtistForm, false); }
+if($Type == 'Music'){ $Announce .= Artists::display_artists($ArtistForm, false); }
$Announce .= trim($Properties['Title'])." ";
if($Type == 'Music'){
$Announce .= '['.trim($Properties['Year']).']';
@@ -932,12 +932,12 @@
}
if (!$Private) {
- show_header("Warning");
+ View::show_header("Warning");
?>
Warning
Your torrent has been uploaded; however, you must download your torrent from here because you didn't make your torrent using the "private" option.
- show_footer();
+ View::show_footer();
die();
} elseif($RequestID) {
header("Location: requests.php?action=takefill&requestid=".$RequestID."&torrentid=".$TorrentID."&auth=".$LoggedUser['AuthKey']);
diff --git a/sections/user/advancedsearch.php b/sections/user/advancedsearch.php
index d26bf62a..b506dad7 100644
--- a/sections/user/advancedsearch.php
+++ b/sections/user/advancedsearch.php
@@ -420,12 +420,12 @@ function num_compare($Field, $Operand, $Num1, $Num2 = ''){
$RunQuery = true;
}
- list($Page,$Limit) = page_limit(USERS_PER_PAGE);
+ list($Page,$Limit) = Format::page_limit(USERS_PER_PAGE);
$SQL.=" LIMIT $Limit";
} else { error($Err); }
}
-show_header('User search');
+View::show_header('User search');
?>
@@ -507,7 +507,7 @@ function num_compare($Field, $Operand, $Num1, $Num2 = ''){
usort($Secondaries, $fnc);
foreach($Secondaries as $Class) {
?>
- >=cut_string($Class['Name'], 20, 1, 1)?>
+ >=Format::cut_string($Class['Name'], 20, 1, 1)?>
} ?>
@@ -651,7 +651,7 @@ function num_compare($Field, $Operand, $Num1, $Num2 = ''){
Any
foreach($Stylesheets as $Style) { ?>
- >=$Style['ProperName']?>
+ >=$Style['ProperName']?>
} ?>
@@ -716,7 +716,7 @@ function num_compare($Field, $Operand, $Num1, $Num2 = ''){
?>
-$Pages=get_pages($Page,$NumResults,USERS_PER_PAGE,11);
+$Pages=Format::get_pages($Page,$NumResults,USERS_PER_PAGE,11);
echo $Pages;
?>
@@ -738,14 +738,14 @@ function num_compare($Field, $Operand, $Num1, $Num2 = ''){
while(list($UserID, $Username, $Uploaded, $Downloaded, $Snatched, $Class, $Email, $Enabled, $IP, $Invites, $DisableInvites, $Warned, $Donor, $JoinDate, $LastAccess) = $DB->next_record()){ ?>
- =format_username($UserID, true, true, true, true)?>
- =ratio($Uploaded, $Downloaded)?>
- =display_str($IP)?> (=get_cc($IP)?>)
+ =Users::format_username($UserID, true, true, true, true)?>
+ =Format::get_ratio_html($Uploaded, $Downloaded)?>
+ =display_str($IP)?> (=Tools::get_country_code_by_ajax($IP)?>)
=display_str($Email)?>
=time_diff($JoinDate)?>
=time_diff($LastAccess)?>
- =get_size($Uploaded)?>
- =get_size($Downloaded)?>
+ =Format::get_size($Uploaded)?>
+ =Format::get_size($Downloaded)?>
$DB->query("SELECT COUNT(ud.UserID) FROM users_downloads AS ud JOIN torrents AS t ON t.ID = ud.TorrentID WHERE ud.UserID = ".$UserID);
list($Downloads) = $DB->next_record();
$DB->set_query_id($Results);
@@ -763,5 +763,5 @@ function num_compare($Field, $Operand, $Num1, $Num2 = ''){
=$Pages?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/user/community_stats.php b/sections/user/community_stats.php
index 9ac510f9..791c9add 100644
--- a/sections/user/community_stats.php
+++ b/sections/user/community_stats.php
@@ -23,9 +23,9 @@
- Link this user with:
+ Link this user with:
diff --git a/sections/user/notify_edit.php b/sections/user/notify_edit.php
index fe6f5cf6..287a3207 100644
--- a/sections/user/notify_edit.php
+++ b/sections/user/notify_edit.php
@@ -1,6 +1,6 @@
if(!check_perms('site_torrents_notify')){ error(403); }
-show_header('Manage notifications');
+View::show_header('Manage notifications');
?>
- show_footer(); ?>
\ No newline at end of file
+ View::show_footer(); ?>
\ No newline at end of file
diff --git a/sections/user/permissions.php b/sections/user/permissions.php
index 10dbd665..e8546c6d 100644
--- a/sections/user/permissions.php
+++ b/sections/user/permissions.php
@@ -5,7 +5,7 @@
include(SERVER_ROOT."/classes/permissions_form.php");
-list($UserID, $Username, $PermissionID) = array_values(user_info($_REQUEST['userid']));
+list($UserID, $Username, $PermissionID) = array_values(Users::user_info($_REQUEST['userid']));
$DB->query("SELECT
u.CustomPermissions
@@ -15,7 +15,7 @@
list($Customs)=$DB->next_record(MYSQLI_NUM, false);
-$Defaults = get_permissions_for_user($UserID, array());
+$Defaults = Permissions::get_permissions_for_user($UserID, array());
$Delta=array();
if (isset($_POST['action'])) {
@@ -52,7 +52,7 @@ function display_perm($Key,$Title) {
echo $Perm;
}
-show_header($Username.' > Permissions');
+View::show_header($Username.' > Permissions');
?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/user/sessions.php b/sections/user/sessions.php
index 3a82446e..e5eca6b1 100644
--- a/sections/user/sessions.php
+++ b/sections/user/sessions.php
@@ -38,11 +38,11 @@
$Cache->cache_value('users_sessions_'.$UserID, $UserSessions, 0);
}
-list($UserID, $Username) = array_values(user_info($UserID));
-show_header($Username.' > Sessions');
+list($UserID, $Username) = array_values(Users::user_info($UserID));
+View::show_header($Username.' > Sessions');
?>
-
=format_username($UserID,$Username)?> > Sessions
+
=Users::format_username($UserID,$Username)?> > Sessions
Note: Clearing cookies can result in ghost sessions which are automatically removed after 30 days.
@@ -87,5 +87,5 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/user/takeedit.php b/sections/user/takeedit.php
index 070d88f4..db29e22f 100644
--- a/sections/user/takeedit.php
+++ b/sections/user/takeedit.php
@@ -7,13 +7,13 @@
}
//For the entire of this page we should in general be using $UserID not $LoggedUser['ID'] and $U[] not $LoggedUser[]
-$U = user_info($UserID);
+$U = Users::user_info($UserID);
if (!$U) {
error(404);
}
-$Permissions = get_permissions($U['PermissionID']);
+$Permissions = Permissions::get_permissions($U['PermissionID']);
if ($UserID != $LoggedUser['ID'] && !check_perms('users_edit_profiles', $Permissions['Class'])) {
send_irc("PRIVMSG ".ADMIN_CHAN." :User ".$LoggedUser['Username']." (https://".SSL_SITE_URL."/user.php?id=".$LoggedUser['ID'].") just tried to edit the profile of https://".SSL_SITE_URL."/user.php?id=".$_REQUEST['userid']);
error(403);
@@ -130,7 +130,7 @@
if(!check_perms('users_edit_profiles')) { // Non-admins have to authenticate to change email
$DB->query("SELECT PassHash,Secret FROM users_main WHERE ID='".db_string($UserID)."'");
list($PassHash,$Secret)=$DB->next_record();
- if(!check_password($_POST['cur_pass'], $PassHash, $Secret)) {
+ if(!Users::check_password($_POST['cur_pass'], $PassHash, $Secret)) {
$Err = "You did not enter the correct password.";
}
}
@@ -159,7 +159,7 @@
$DB->query("SELECT PassHash,Secret FROM users_main WHERE ID='".db_string($UserID)."'");
list($PassHash,$Secret)=$DB->next_record();
- if (check_password($_POST['cur_pass'], $PassHash, $Secret)) {
+ if (Users::check_password($_POST['cur_pass'], $PassHash, $Secret)) {
if ($_POST['new_pass_1'] && $_POST['new_pass_2']) {
$ResetPassword = true;
}
@@ -258,7 +258,7 @@
if($ResetPassword) {
$ChangerIP = db_string($LoggedUser['IP']);
- $PassHash=make_crypt_hash($_POST['new_pass_1']);
+ $PassHash=Users::make_crypt_hash($_POST['new_pass_1']);
$SQL.=",m.PassHash='".db_string($PassHash)."'";
$DB->query("INSERT INTO users_history_passwords
(UserID, ChangerIP, ChangeTime) VALUES
@@ -271,9 +271,9 @@
- $UserInfo = user_heavy_info($UserID);
+ $UserInfo = Users::user_heavy_info($UserID);
$OldPassKey = db_string($UserInfo['torrent_pass']);
- $NewPassKey = db_string(make_secret());
+ $NewPassKey = db_string(Users::make_secret());
$ChangerIP = db_string($LoggedUser['IP']);
$SQL.=",m.torrent_pass='$NewPassKey'";
$DB->query("INSERT INTO users_history_passkeys
@@ -284,7 +284,7 @@
$Cache->commit_transaction(0);
$Cache->delete_value('user_'.$OldPassKey);
- update_tracker('change_passkey', array('oldpasskey' => $OldPassKey, 'newpasskey' => $NewPassKey));
+ Tracker::update_tracker('change_passkey', array('oldpasskey' => $OldPassKey, 'newpasskey' => $NewPassKey));
}
$SQL.="WHERE m.ID='".db_string($UserID)."'";
diff --git a/sections/user/takeinvite.php b/sections/user/takeinvite.php
index 918ff767..3b759cd3 100644
--- a/sections/user/takeinvite.php
+++ b/sections/user/takeinvite.php
@@ -52,7 +52,7 @@
header('Location: user.php?action=invite');
die();
}
- $InviteKey = db_string(make_secret());
+ $InviteKey = db_string(Users::make_secret());
$Message = <<commit_transaction(0);
}
- send_email($CurEmail, 'You have been invited to '.SITE_NAME, $Message,'noreply');
+ Misc::send_email($CurEmail, 'You have been invited to '.SITE_NAME, $Message,'noreply');
}
diff --git a/sections/user/takemoderate.php b/sections/user/takemoderate.php
index 414f7643..03d0f691 100644
--- a/sections/user/takemoderate.php
+++ b/sections/user/takemoderate.php
@@ -38,11 +38,11 @@
if(isset($_POST['Uploaded']) && isset($_POST['Downloaded'])) {
$Uploaded = ($_POST['Uploaded'] == "" ? 0 : $_POST['Uploaded']);
if($Arithmetic = strpbrk($Uploaded, '+-')) {
- $Uploaded += max(-$Uploaded, get_bytes($Arithmetic));
+ $Uploaded += max(-$Uploaded, Format::get_bytes($Arithmetic));
}
$Downloaded = ($_POST['Downloaded'] == "" ? 0 : $_POST['Downloaded']);
if($Arithmetic = strpbrk($Downloaded, '+-')) {
- $Downloaded += max(-$Downloaded, get_bytes($Arithmetic));
+ $Downloaded += max(-$Downloaded, Format::get_bytes($Arithmetic));
}
if(!is_number($Uploaded) || !is_number($Downloaded)) {
error(0);
@@ -156,12 +156,12 @@
// If we're deleting the user, we can ignore all the other crap
if ($_POST['UserStatus']=="delete" && check_perms('users_delete_users')) {
- write_log("User account ".$UserID." (".$Cur['Username'].") was deleted by ".$LoggedUser['Username']);
+ Misc::write_log("User account ".$UserID." (".$Cur['Username'].") was deleted by ".$LoggedUser['Username']);
$DB->query("DELETE FROM users_main WHERE id=".$UserID);
$DB->query("DELETE FROM users_info WHERE UserID=".$UserID);
$Cache->delete_value('user_info_'.$UserID);
- update_tracker('remove_user', array('passkey' => $Cur['torrent_pass']));
+ Tracker::update_tracker('remove_user', array('passkey' => $Cur['torrent_pass']));
header("Location: log.php?search=User+".$UserID);
die();
@@ -252,7 +252,7 @@
($Classes[$Class]['Level'] < $LoggedUser['Class'] && check_perms('users_promote_below', $Cur['Class']))
|| ($Classes[$Class]['Level'] <= $LoggedUser['Class'] && check_perms('users_promote_to', $Cur['Class']-1)))) {
$UpdateSet[]="PermissionID='$Class'";
- $EditSummary[]="class changed to ".make_class_string($Class);
+ $EditSummary[]="class changed to ".Users::make_class_string($Class);
$LightUpdates['PermissionID']=$Class;
$DeleteKeys = true;
@@ -341,14 +341,14 @@
if ($Uploaded!=$Cur['Uploaded'] && $Uploaded!=$_POST['OldUploaded'] && (check_perms('users_edit_ratio')
|| (check_perms('users_edit_own_ratio') && $UserID == $LoggedUser['ID']))) {
$UpdateSet[]="Uploaded='".$Uploaded."'";
- $EditSummary[]="uploaded changed from ".get_size($Cur['Uploaded'])." to ".get_size($Uploaded);
+ $EditSummary[]="uploaded changed from ".Format::get_size($Cur['Uploaded'])." to ".Format::get_size($Uploaded);
$Cache->delete_value('users_stats_'.$UserID);
}
if ($Downloaded!=$Cur['Downloaded'] && $Downloaded!=$_POST['OldDownloaded'] && (check_perms('users_edit_ratio')
|| (check_perms('users_edit_own_ratio') && $UserID == $LoggedUser['ID']))) {
$UpdateSet[]="Downloaded='".$Downloaded."'";
- $EditSummary[]="downloaded changed from ".get_size($Cur['Downloaded'])." to ".get_size($Downloaded);
+ $EditSummary[]="downloaded changed from ".Format::get_size($Cur['Downloaded'])." to ".Format::get_size($Downloaded);
$Cache->delete_value('users_stats_'.$UserID);
}
@@ -365,7 +365,7 @@
}
if ($Warned == 1 && $Cur['Warned']=='0000-00-00 00:00:00' && check_perms('users_warn')) {
- send_pm($UserID,0,db_string('You have received a warning'),db_string("You have been [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&id=218]warned for $WarnLength week(s)[/url] by [user]".$LoggedUser['Username']."[/user]. The reason given was: $WarnReason"));
+ Misc::send_pm($UserID,0,db_string('You have received a warning'),db_string("You have been [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&id=218]warned for $WarnLength week(s)[/url] by [user]".$LoggedUser['Username']."[/user]. The reason given was: $WarnReason"));
$UpdateSet[]="Warned='".sqltime()."' + INTERVAL $WarnLength WEEK";
$Msg = "warned for $WarnLength week(s)";
if ($WarnReason) { $Msg.=" for $WarnReason"; }
@@ -379,7 +379,7 @@
} elseif ($Warned == 1 && $ExtendWarning!='---' && check_perms('users_warn')) {
- send_pm($UserID,0,db_string('Your warning has been extended'),db_string("Your warning has been extended by $ExtendWarning week(s) by [user]".$LoggedUser['Username']."[/user]. The reason given was: $WarnReason"));
+ Misc::send_pm($UserID,0,db_string('Your warning has been extended'),db_string("Your warning has been extended by $ExtendWarning week(s) by [user]".$LoggedUser['Username']."[/user]. The reason given was: $WarnReason"));
$UpdateSet[]="Warned=Warned + INTERVAL $ExtendWarning WEEK";
$DB->query("SELECT Warned + INTERVAL $ExtendWarning WEEK FROM users_info WHERE UserID='$UserID'");
@@ -390,7 +390,7 @@
$LightUpdates['Warned']=$WarnedUntil;
} elseif ($Warned == 1 && $ExtendWarning=='---' && $ReduceWarning!='---' && check_perms('users_warn')) {
- send_pm($UserID,0,db_string('Your warning has been reduced'),db_string("Your warning has been reduced by $ReduceWarning week(s) by [user]".$LoggedUser['Username']."[/user]. The reason given was: $WarnReason"));
+ Misc::send_pm($UserID,0,db_string('Your warning has been reduced'),db_string("Your warning has been reduced by $ReduceWarning week(s) by [user]".$LoggedUser['Username']."[/user]. The reason given was: $WarnReason"));
$UpdateSet[]="Warned=Warned - INTERVAL $ReduceWarning WEEK";
$DB->query("SELECT Warned - INTERVAL $ReduceWarning WEEK FROM users_info WHERE UserID='$UserID'");
@@ -444,7 +444,7 @@
$EditSummary[]="avatar status changed";
$HeavyUpdates['DisableAvatar']=$DisableAvatar;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your avatar privileges have been disabled'),db_string("Your avatar privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your avatar privileges have been disabled'),db_string("Your avatar privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
}
@@ -454,9 +454,9 @@
$HeavyUpdates['DisableLeech']=$DisableLeech;
$HeavyUpdates['CanLeech']=$DisableLeech;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your leeching privileges have been disabled'),db_string("Your leeching privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your leeching privileges have been disabled'),db_string("Your leeching privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
- update_tracker('update_user', array('passkey' => $Cur['torrent_pass'], 'can_leech' => $DisableLeech));
+ Tracker::update_tracker('update_user', array('passkey' => $Cur['torrent_pass'], 'can_leech' => $DisableLeech));
}
if ($DisableInvites!=$Cur['DisableInvites'] && check_perms('users_disable_any')) {
@@ -464,7 +464,7 @@
if ($DisableInvites == 1) {
//$UpdateSet[]="Invites='0'";
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your invite privileges have been disabled'),db_string("Your invite privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your invite privileges have been disabled'),db_string("Your invite privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
}
$EditSummary[]="invites status changed";
@@ -476,7 +476,7 @@
$EditSummary[]="posting status changed";
$HeavyUpdates['DisablePosting']=$DisablePosting;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your forum posting privileges have been disabled'),db_string("Your forum posting privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your forum posting privileges have been disabled'),db_string("Your forum posting privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
}
@@ -485,7 +485,7 @@
$EditSummary[]="forums status changed";
$HeavyUpdates['DisableForums']=$DisableForums;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your forum privileges have been disabled'),db_string("Your forum privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your forum privileges have been disabled'),db_string("Your forum privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
}
@@ -494,7 +494,7 @@
$EditSummary[]="tagging status changed";
$HeavyUpdates['DisableTagging']=$DisableTagging;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your tagging privileges have been disabled'),db_string("Your tagging privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your tagging privileges have been disabled'),db_string("Your tagging privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
}
@@ -503,7 +503,7 @@
$EditSummary[]="upload status changed";
$HeavyUpdates['DisableUpload']=$DisableUpload;
if ($DisableUpload == 1) {
- send_pm($UserID, 0, db_string('Your upload privileges have been disabled'),db_string("Your upload privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your upload privileges have been disabled'),db_string("Your upload privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
}
@@ -513,7 +513,7 @@
$HeavyUpdates['DisableWiki']=$DisableWiki;
$HeavyUpdates['site_edit_wiki']=0;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your site editing privileges have been disabled'),db_string("Your site editing privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your site editing privileges have been disabled'),db_string("Your site editing privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
}
@@ -523,7 +523,7 @@
$EditSummary[]="PM status changed";
$HeavyUpdates['DisablePM']=$DisablePM;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your PM privileges have been disabled'),db_string("Your PM privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
+ Misc::send_pm($UserID, 0, db_string('Your PM privileges have been disabled'),db_string("Your PM privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]."));
}
}
@@ -532,7 +532,7 @@
$EditSummary[]="IRC status changed";
$HeavyUpdates['DisableIRC']=$DisableIRC;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your IRC privileges have been disabled'),db_string("Your IRC privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]. This loss of privileges does not affect the ability to join and talk to staff in #what.cd-disabled."));
+ Misc::send_pm($UserID, 0, db_string('Your IRC privileges have been disabled'),db_string("Your IRC privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]. This loss of privileges does not affect the ability to join and talk to staff in #what.cd-disabled."));
}
}
@@ -541,7 +541,7 @@
$EditSummary[]="request status changed";
$HeavyUpdates['DisableRequests']=$DisableRequests;
if (!empty($UserReason)) {
- send_pm($UserID, 0, db_string('Your request privileges have been disabled'),db_string("Your request privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]. This loss of privileges does not affect the ability to join and talk to staff in #what.cd-disabled."));
+ Misc::send_pm($UserID, 0, db_string('Your request privileges have been disabled'),db_string("Your request privileges have been disabled. The reason given was: $UserReason. If you would like to discuss this please join ".BOT_DISABLED_CHAN." on our IRC network. Instructions can be found [url=http://".NONSSL_SITE_URL."/wiki.php?action=article&name=IRC+-+How+to+join]here[/url]. This loss of privileges does not affect the ability to join and talk to staff in #what.cd-disabled."));
}
}
@@ -550,10 +550,10 @@
if ($EnableUser!=$Cur['Enabled'] && check_perms('users_disable_users')) {
$EnableStr = 'account '.translateUserStatus($Cur['Enabled']).'->'.translateUserStatus($EnableUser);
if($EnableUser == '2') {
- disable_users($UserID, '', 1);
+ Tools::disable_users($UserID, '', 1);
} elseif($EnableUser == '1') {
$Cache->increment('stats_user_count');
- update_tracker('add_user', array('id' => $UserID, 'passkey' => $Cur['torrent_pass']));
+ Tracker::update_tracker('add_user', array('id' => $UserID, 'passkey' => $Cur['torrent_pass']));
if (($Cur['Downloaded'] == 0) || ($Cur['Uploaded']/$Cur['Downloaded'] >= $Cur['RequiredRatio'])) {
$UpdateSet[]="i.RatioWatchEnds='0000-00-00 00:00:00'";
$CanLeech = 1;
@@ -566,7 +566,7 @@
$UpdateSet[]="i.RatioWatchDownload=m.Downloaded";
$CanLeech = 0;
}
- update_tracker('update_user', array('passkey' => $Cur['torrent_pass'], 'can_leech' => '0'));
+ Tracker::update_tracker('update_user', array('passkey' => $Cur['torrent_pass'], 'can_leech' => '0'));
}
$UpdateSet[]="Enabled='1'";
$LightUpdates['Enabled'] = 1;
@@ -576,7 +576,7 @@
}
if ($ResetPasskey == 1 && check_perms('users_edit_reset_keys')) {
- $Passkey = db_string(make_secret());
+ $Passkey = db_string(Users::make_secret());
$UpdateSet[]="torrent_pass='$Passkey'";
$EditSummary[]="passkey reset";
$HeavyUpdates['torrent_pass']=$Passkey;
@@ -586,11 +586,11 @@
$DB->query("INSERT INTO users_history_passkeys
(UserID, OldPassKey, NewPassKey, ChangerIP, ChangeTime) VALUES
('$UserID', '".$Cur['torrent_pass']."', '$Passkey', '0.0.0.0', '".sqltime()."')");
- update_tracker('change_passkey', array('oldpasskey' => $Cur['torrent_pass'], 'newpasskey' => $Passkey));
+ Tracker::update_tracker('change_passkey', array('oldpasskey' => $Cur['torrent_pass'], 'newpasskey' => $Passkey));
}
if ($ResetAuthkey == 1 && check_perms('users_edit_reset_keys')) {
- $Authkey = db_string(make_secret());
+ $Authkey = db_string(Users::make_secret());
$UpdateSet[]="AuthKey='$Authkey'";
$EditSummary[]="authkey reset";
$HeavyUpdates['AuthKey']=$Authkey;
@@ -598,7 +598,7 @@
if ($SendHackedMail && check_perms('users_disable_any')) {
$EditSummary[]="hacked email sent to ".$HackedEmail;
- send_email($HackedEmail, "Your ".SITE_NAME." account.","Your ".SITE_NAME." account appears to have been compromised. As a security measure we have disabled your account. To resolve this please visit us on IRC.
+ Misc::send_email($HackedEmail, "Your ".SITE_NAME." account.","Your ".SITE_NAME." account appears to have been compromised. As a security measure we have disabled your account. To resolve this please visit us on IRC.
This is the information to connect to our server:
IRC Server: ".BOT_SERVER."
@@ -624,7 +624,7 @@
}
if ($Pass && check_perms('users_edit_password')) {
- $UpdateSet[]="PassHash='".db_string(make_crypt_hash($Pass))."'";
+ $UpdateSet[]="PassHash='".db_string(Users::make_crypt_hash($Pass))."'";
$EditSummary[]='password reset';
$Cache->delete_value('user_info_'.$UserID);
diff --git a/sections/user/user.php b/sections/user/user.php
index 1e83cd11..fb96844f 100644
--- a/sections/user/user.php
+++ b/sections/user/user.php
@@ -6,13 +6,13 @@
include(SERVER_ROOT.'/sections/requests/functions.php');
include(SERVER_ROOT.'/classes/class_image_tools.php');
-if (empty($_GET['id']) || !is_numeric($_GET['id']))
- error(404);
-
+if (empty($_GET['id']) || !is_numeric($_GET['id']))
+ error(404);
+
$UserID = $_GET['id'];
-if($UserID == $LoggedUser['ID']) {
+if($UserID == $LoggedUser['ID']) {
$OwnProfile = true;
-} else {
+} else {
$OwnProfile = false;
}
@@ -152,7 +152,7 @@ function check_paranoia_here($Setting) {
$Badges.=($Enabled == '1' || $Enabled == '0' || !$Enabled) ? '': ' ';
-show_header($Username,'user,bbcode,requests');
+View::show_header($Username,'user,bbcode,requests');
?>
=$Username?>
@@ -191,7 +191,7 @@ function check_paranoia_here($Setting) {
if (check_perms('users_mod')) {
?>
[
FL Tokens ]
- }
+ }
if (check_perms('admin_clear_cache') && check_perms('users_override_paranoia')) {
?>
[
Clear Cache ]
@@ -217,13 +217,13 @@ function check_paranoia_here($Setting) {
>Last Seen: =$LastAccess?>
} ?>
if (($Override=check_paranoia_here('uploaded'))) { ?>
-
>Uploaded: =get_size($Uploaded)?>
+
>Uploaded: =Format::get_size($Uploaded)?>
} ?>
if (($Override=check_paranoia_here('downloaded'))) { ?>
-
>Downloaded: =get_size($Downloaded)?>
+
>Downloaded: =Format::get_size($Downloaded)?>
} ?>
if (($Override=check_paranoia_here('ratio'))) { ?>
-
>Ratio: =ratio($Uploaded, $Downloaded)?>
+
>Ratio: =Format::get_ratio_html($Uploaded, $Downloaded)?>
} ?>
if (($Override=check_paranoia_here('requiredratio')) && isset($RequiredRatio)) { ?>
>Required ratio: =number_format((double)$RequiredRatio, 2)?>
@@ -288,10 +288,10 @@ function check_paranoia_here($Setting) {
Percentile Rankings (Hover for values)
if (($Override=check_paranoia_here('uploaded'))) { ?>
- title="=get_size($Uploaded)?>">Data uploaded: =$UploadedRank === false ? 'Server busy' : number_format($UploadedRank)?>
+ title="=Format::get_size($Uploaded)?>">Data uploaded: =$UploadedRank === false ? 'Server busy' : number_format($UploadedRank)?>
} ?>
if (($Override=check_paranoia_here('downloaded'))) { ?>
- title="=get_size($Downloaded)?>">Data downloaded: =$DownloadedRank === false ? 'Server busy' : number_format($DownloadedRank)?>
+ title="=Format::get_size($Downloaded)?>">Data downloaded: =$DownloadedRank === false ? 'Server busy' : number_format($DownloadedRank)?>
} ?>
if (($Override=check_paranoia_here('uploads+'))) { ?>
title="=$Uploads?>">Torrents uploaded: =$UploadsRank === false ? 'Server busy' : number_format($UploadsRank)?>
@@ -300,7 +300,7 @@ function check_paranoia_here($Setting) {
title="=$RequestsFilled?>">Requests filled: =$RequestRank === false ? 'Server busy' : number_format($RequestRank)?>
} ?>
if (($Override=check_paranoia_here('requestsvoted_bounty'))) { ?>
- title="=get_size($TotalSpent)?>">Bounty spent: =$BountyRank === false ? 'Server busy' : number_format($BountyRank)?>
+ title="=Format::get_size($TotalSpent)?>">Bounty spent: =$BountyRank === false ? 'Server busy' : number_format($BountyRank)?>
} ?>
Posts made: =$PostRank === false ? 'Server busy' : number_format($PostRank)?>
if (($Override=check_paranoia_here('artistsadded'))) { ?>
@@ -366,7 +366,7 @@ function check_paranoia_here($Setting) {
Class: =$ClassLevels[$Class]['Name']?>
-$UserInfo = user_info($UserID);
+$UserInfo = Users::user_info($UserID);
if (!empty($UserInfo['ExtraClasses'])) {
?>
@@ -404,8 +404,8 @@ function check_paranoia_here($Setting) {
if (check_perms('users_view_ips',$Class)) {
?>
- IP: =display_ip($IP)?>
- Host: =get_host($IP)?>
+ IP: =Tools::display_ip($IP)?>
+ Host: =Tools::get_host_by_ajax($IP)?>
}
@@ -497,7 +497,7 @@ function check_paranoia_here($Setting) {
AND r.TorrentID = 0
GROUP BY r.ID
ORDER BY Votes DESC");
-
+
if($DB->record_count() > 0) {
$Requests = $DB->to_array();
?>
@@ -523,7 +523,7 @@ function check_paranoia_here($Setting) {
foreach($Requests as $Request) {
list($RequestID, $CategoryID, $Title, $Year, $TimeAdded, $Votes, $Bounty) = $Request;
- $Request = get_requests(array($RequestID));
+ $Request = Requests::get_requests(array($RequestID));
$Request = $Request['matches'][$RequestID];
if(empty($Request)) {
continue;
@@ -531,26 +531,26 @@ function check_paranoia_here($Setting) {
list($RequestID, $RequestorID, $RequestorName, $TimeAdded, $LastVote, $CategoryID, $Title, $Year, $Image, $Description, $CatalogueNumber, $ReleaseType,
$BitrateList, $FormatList, $MediaList, $LogCue, $FillerID, $FillerName, $TorrentID, $TimeFilled) = $Request;
-
+
$CategoryName = $Categories[$CategoryID - 1];
-
+
if($CategoryName == "Music") {
$ArtistForm = get_request_artists($RequestID);
- $ArtistLink = display_artists($ArtistForm, true, true);
+ $ArtistLink = Artists::display_artists($ArtistForm, true, true);
$FullName = $ArtistLink."".$Title." [".$Year."] ";
} else if($CategoryName == "Audiobooks" || $CategoryName == "Comedy") {
$FullName = "".$Title." [".$Year."] ";
} else {
$FullName ="".$Title." ";
}
-
+
$Row = (empty($Row) || $Row == 'a') ? 'b' : 'a';
?>
=$FullName?>
- =get_size($Bounty)?>
+ =Format::get_size($Bounty)?>
=time_diff($TimeAdded)?>
@@ -584,18 +584,18 @@ function check_paranoia_here($Setting) {
}
$IsFLS = $LoggedUser['ExtraClasses'][41];
-if (check_perms('users_mod', $Class) || $IsFLS) {
+if (check_perms('users_mod', $Class) || $IsFLS) {
$UserLevel = $LoggedUser['EffectiveClass'];
- $DB->query("SELECT
+ $DB->query("SELECT
SQL_CALC_FOUND_ROWS
- ID,
- Subject,
- Status,
- Level,
- AssignedToUser,
- Date,
- ResolverID
- FROM staff_pm_conversations
+ ID,
+ Subject,
+ Status,
+ Level,
+ AssignedToUser,
+ Date,
+ ResolverID
+ FROM staff_pm_conversations
WHERE UserID = $UserID AND (Level <= $UserLevel OR AssignedToUser='".$LoggedUser['ID']."')
ORDER BY Date DESC");
if ($DB->record_count()) {
@@ -618,18 +618,18 @@ function check_paranoia_here($Setting) {
$Assigned = ($Level == 0) ? "First Line Support" : $ClassLevels[$Level]['Name'];
// No + on Sysops
if ($Assigned != 'Sysop') { $Assigned .= "+"; }
-
+
} else {
// Assigned to user
- $Assigned = format_username($UserID, true, true, true, true);
- }
-
+ $Assigned = Users::format_username($UserID, true, true, true, true);
+ }
+
if ($ResolverID) {
- $Resolver = format_username($ResolverID, true, true, true, true);
+ $Resolver = Users::format_username($ResolverID, true, true, true, true);
} else {
$Resolver = "(unresolved)";
}
-
+
?>
=display_str($Subject)?>
@@ -637,7 +637,7 @@ function check_paranoia_here($Setting) {
=$Assigned?>
=$Resolver?>
- } ?>
+ } ?>
}
@@ -659,7 +659,7 @@ function check_paranoia_here($Setting) {
-
+
}
}
if (check_perms('users_mod', $Class)) { ?>
@@ -819,7 +819,7 @@ function check_paranoia_here($Setting) {
IP History |
Email History
- Snatch List |
+ Snatch List |
Download List
@@ -936,7 +936,7 @@ function check_paranoia_here($Setting) {
Hacked:
- Send hacked account email to
+ Send hacked account email to
foreach($Emails as $Email) {
@@ -1022,4 +1022,4 @@ function check_paranoia_here($Setting) {
} ?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/userhistory/email_history.php b/sections/userhistory/email_history.php
index c0bfe943..8f21b40a 100644
--- a/sections/userhistory/email_history.php
+++ b/sections/userhistory/email_history.php
@@ -25,7 +25,7 @@
$DB->query("SELECT Username FROM users_main WHERE ID = ".$UserID);
list($Username)= $DB->next_record();
-show_header("Email history for $Username");
+View::show_header("Email history for $Username");
if ($UsersOnly == 1) {
$DB->query("SELECT
@@ -109,7 +109,7 @@
list($Enabled)=$DB->next_record();
$DB->set_query_id($ueQuery);
?>
- =format_username($UserID2, false, false, true)?>
+ =Users::format_username($UserID2, false, false, true)?>
}
@@ -117,4 +117,4 @@
?>
} ?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/userhistory/email_history2.php b/sections/userhistory/email_history2.php
index e8e7f15f..f59cd770 100644
--- a/sections/userhistory/email_history2.php
+++ b/sections/userhistory/email_history2.php
@@ -24,7 +24,7 @@
$DB->query("SELECT Username FROM users_main WHERE ID = ".$UserID);
list($Username)= $DB->next_record();
-show_header("Email history for $Username");
+View::show_header("Email history for $Username");
// Get current email (and matches)
$DB->query("
@@ -86,7 +86,7 @@
$UserIPs=explode('|', $CurrentEmail['UserIPs']);
foreach($UserIDs as $Key => $Val) {
- $CurrentMatches[$Key]['Username'] = ' » '.format_username($Val, true, true, true);
+ $CurrentMatches[$Key]['Username'] = ' » '.Users::format_username($Val, true, true, true);
$CurrentMatches[$Key]['IP'] = $UserIPs[$Key];
$CurrentMatches[$Key]['EndTime'] = $UserSetTimes[$Key];
}
@@ -132,7 +132,7 @@
if ($Val['Usernames'] != '') {
// Match with old email
$OldMatches[$Key]['Email'] = $Val['Email'];
- $OldMatches[$Key]['Username'] = ' » '.format_username($Val['UserIDs'], true, true, true);
+ $OldMatches[$Key]['Username'] = ' » '.Users::format_username($Val['UserIDs'], true, true, true);
$OldMatches[$Key]['EndTime'] = $Val['UserSetTimes'];
$OldMatches[$Key]['IP'] = $Val['UserIPs'];
}
@@ -176,12 +176,12 @@
=time_diff($Current['StartTime'])?>
- =display_str($Current['CurrentIP'])?> (=get_cc($Current['CurrentIP'])?>) [S ] [WI ]
- =get_host($Current['CurrentIP'])?>
+ =display_str($Current['CurrentIP'])?> (=Tools::get_country_code_by_ajax($Current['CurrentIP'])?>) [S ] [WI ]
+ =Tools::get_host_by_ajax($Current['CurrentIP'])?>
- =display_str($Current['IP'])?> (=get_cc($Current['IP'])?>) [S ] [WI ]
- =get_host($Current['IP'])?>
+ =display_str($Current['IP'])?> (=Tools::get_country_code_by_ajax($Current['IP'])?>) [S ] [WI ]
+ =Tools::get_host_by_ajax($Current['IP'])?>
@@ -195,8 +195,8 @@
=time_diff($Match['EndTime'])?>
- =display_str($Match['IP'])?> (=get_cc($Match['IP'])?>) [S ] [WI ]
- =get_host($Match['IP'])?>
+ =display_str($Match['IP'])?> (=Tools::get_country_code_by_ajax($Match['IP'])?>) [S ] [WI ]
+ =Tools::get_host_by_ajax($Match['IP'])?>
@@ -232,8 +232,8 @@
=time_diff($Match['EndTime'])?>
- =display_str($Match['IP'])?> (=get_cc($Match['IP'])?>) [S ] [WI ]
- =get_host($Match['IP'])?>
+ =display_str($Match['IP'])?> (=Tools::get_country_code_by_ajax($Match['IP'])?>) [S ] [WI ]
+ =Tools::get_host_by_ajax($Match['IP'])?>
@@ -251,8 +251,8 @@
=time_diff($Record['EndTime'])?>
=time_diff($Record['ElapsedTime'])?>
- =display_str($Record['IP'])?> (=get_cc($Record['IP'])?>) [S ] [WI ]
- =get_host($Record['IP'])?>
+ =display_str($Record['IP'])?> (=Tools::get_country_code_by_ajax($Record['IP'])?>) [S ] [WI ]
+ =Tools::get_host_by_ajax($Record['IP'])?>
@@ -290,8 +290,8 @@
=time_diff($Match['EndTime'])?>
- =display_str($Match['IP'])?> (=get_cc($Match['IP'])?>) [S ] [WI ]
- =get_host($Match['IP'])?>
+ =display_str($Match['IP'])?> (=Tools::get_country_code_by_ajax($Match['IP'])?>) [S ] [WI ]
+ =Tools::get_host_by_ajax($Match['IP'])?>
@@ -308,8 +308,8 @@
=time_diff($Invite['EndTime'])?>
=time_diff($Invite['AccountAge'])?>
- =display_str($Invite['IP'])?> (=get_cc($Invite['IP'])?>) [S ] [WI ]
- =get_host($Invite['IP'])?>
+ =display_str($Invite['IP'])?> (=Tools::get_country_code_by_ajax($Invite['IP'])?>) [S ] [WI ]
+ =Tools::get_host_by_ajax($Invite['IP'])?>
@@ -321,4 +321,4 @@
?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/userhistory/ip_history.php b/sections/userhistory/ip_history.php
index 37082af5..b43f3990 100644
--- a/sections/userhistory/ip_history.php
+++ b/sections/userhistory/ip_history.php
@@ -29,7 +29,7 @@
$SearchIPQuery = " AND h1.IP = '$SearchIP' ";
}
-show_header("IP history for $Username");
+View::show_header("IP history for $Username");
?>
-list($Page,$Limit) = page_limit(IPS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(IPS_PER_PAGE);
if ($UsersOnly == 1) {
$RS = $DB->query("SELECT SQL_CALC_FOUND_ROWS
@@ -121,7 +121,7 @@ function UnBan(ip, id, elemID) {
list($NumResults) = $DB->next_record();
$DB->set_query_id($RS);
-$Pages=get_pages($Page,$NumResults,IPS_PER_PAGE,9);
+$Pages=Format::get_pages($Page,$NumResults,IPS_PER_PAGE,9);
?>
@@ -181,11 +181,11 @@ function UnBan(ip, id, elemID) {
?>
- =$IP?> (=get_cc($IP)?>)
+ =$IP?> (=Tools::get_country_code_by_ajax($IP)?>)
if($CanManageIPBans) {
if(!isset($IPs[$IP])) {
- $sql = "SELECT ID, FromIP, ToIP FROM ip_bans WHERE '".ip2unsigned($IP)."' BETWEEN FromIP AND ToIP LIMIT 1";
+ $sql = "SELECT ID, FromIP, ToIP FROM ip_bans WHERE '".Tools::ip_to_unsigned($IP)."' BETWEEN FromIP AND ToIP LIMIT 1";
$DB->query($sql);
if($DB->record_count() > 0) {
@@ -204,7 +204,7 @@ function UnBan(ip, id, elemID) {
- =get_host($IP)?>
+ =Tools::get_host_by_ajax($IP)?>
=($HasDupe ?
'('.count($UserIDs).') '
: '(0)')?>
@@ -219,7 +219,7 @@ function UnBan(ip, id, elemID) {
if(!$UserEndTimes[$Key]){ $UserEndTimes[$Key] = sqltime(); }
?>
- » =format_username($Val, true, true, true)?>
+ » =Users::format_username($Val, true, true, true)?>
=time_diff($UserStartTimes[$Key])?>
=time_diff($UserEndTimes[$Key])?>
//time_diff(strtotime($UserStartTimes[$Key]), strtotime($UserEndTimes[$Key])); ?>
@@ -238,4 +238,4 @@ function UnBan(ip, id, elemID) {
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/userhistory/ip_tracker_history.php b/sections/userhistory/ip_tracker_history.php
index a89b1b98..2456b79a 100644
--- a/sections/userhistory/ip_tracker_history.php
+++ b/sections/userhistory/ip_tracker_history.php
@@ -26,7 +26,7 @@
$UsersOnly = $_GET['usersonly'];
-show_header("Tracker IP history for $Username");
+View::show_header("Tracker IP history for $Username");
?>
-list($Page,$Limit) = page_limit(IPS_PER_PAGE);
+list($Page,$Limit) = Format::page_limit(IPS_PER_PAGE);
$TrackerIps = $DB->query("SELECT IP, fid, tstamp FROM xbt_snatched WHERE uid = ".$UserID." AND IP != '' ORDER BY tstamp DESC LIMIT $Limit");
@@ -42,7 +42,7 @@ function ShowIPs(rowname) {
list($NumResults) = $DB->next_record();
$DB->set_query_id($TrackerIps);
-$Pages=get_pages($Page,$NumResults,IPS_PER_PAGE,9);
+$Pages=Format::get_pages($Page,$NumResults,IPS_PER_PAGE,9);
?>
@@ -63,7 +63,7 @@ function ShowIPs(rowname) {
?>
- =$IP?> (=get_cc($IP)?>) =get_host($IP)?>
+ =$IP?> (=Tools::get_country_code_by_ajax($IP)?>) =Tools::get_host_by_ajax($IP)?>
[WI ]
=$TorrentID?>
=date("Y-m-d g:i:s", $Time)?>
@@ -78,5 +78,5 @@ function ShowIPs(rowname) {
-show_footer();
+View::show_footer();
?>
diff --git a/sections/userhistory/passkey_history.php b/sections/userhistory/passkey_history.php
index 7d148d52..3fc80e6d 100644
--- a/sections/userhistory/passkey_history.php
+++ b/sections/userhistory/passkey_history.php
@@ -20,7 +20,7 @@
error(403);
}
-show_header("PassKey history for $Username");
+View::show_header("PassKey history for $Username");
$DB->query("SELECT
OldPassKey,
@@ -47,8 +47,8 @@
=display_str($OldPassKey)?>
=display_str($NewPassKey)?>
=time_diff($ChangeTime)?>
- =display_str($ChangerIP)?> [S ] =display_str(gethostbyip($ChangerIP))?>
+ =display_str($ChangerIP)?> [S ] =display_str(Tools::get_host_by_ip($ChangerIP))?>
} ?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/userhistory/password_history.php b/sections/userhistory/password_history.php
index e9f6d57d..4ac22417 100644
--- a/sections/userhistory/password_history.php
+++ b/sections/userhistory/password_history.php
@@ -20,7 +20,7 @@
error(403);
}
-show_header("Password reset history for $Username");
+View::show_header("Password reset history for $Username");
$DB->query("SELECT
ChangeTime,
@@ -41,8 +41,8 @@
while(list($ChangeTime, $ChangerIP) = $DB->next_record()){ ?>
=time_diff($ChangeTime)?>
- =display_str($ChangerIP)?> [S ] =get_host($ChangerIP)?>
+ =display_str($ChangerIP)?> [S ] =Tools::get_host_by_ajax($ChangerIP)?>
} ?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/userhistory/post_history.php b/sections/userhistory/post_history.php
index 08f4abe1..2654063c 100644
--- a/sections/userhistory/post_history.php
+++ b/sections/userhistory/post_history.php
@@ -1,5 +1,5 @@
-//TODO: replace 24-43 with user_info()
+//TODO: replace 24-43 with Users::user_info()
/*
User post history page
*/
@@ -24,7 +24,7 @@
$PerPage = POSTS_PER_PAGE;
}
-list($Page,$Limit) = page_limit($PerPage);
+list($Page,$Limit) = Format::page_limit($PerPage);
if(($UserInfo = $Cache->get_value('user_info_'.$UserID)) === FALSE) {
$DB->query("SELECT
@@ -50,7 +50,7 @@
$Avatar = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&i='.urlencode($Avatar);
}
-show_header('Post history for '.$Username,'subscriptions,comments,bbcode');
+View::show_header('Post history for '.$Username,'subscriptions,comments,bbcode');
if($LoggedUser['CustomForums']) {
unset($LoggedUser['CustomForums']['']);
@@ -246,7 +246,7 @@
?>
- $Pages=get_pages($Page,$Results,$PerPage, 11);
+ $Pages=Format::get_pages($Page,$Results,$PerPage, 11);
echo $Pages;
?>
@@ -258,7 +258,7 @@
=time_diff($AddedTime) ?>
- in =cut_string($ThreadTitle, 75)?>
+ in =Format::cut_string($ThreadTitle, 75)?>
if($ViewingOwn) {
if ((!$Locked || $Sticky) && (!$LastRead || $LastRead < $LastPostID)) { ?>
@@ -315,7 +315,7 @@
«
} ?>
Last edited by
- =format_username($EditedUserID, false, false, false) ?> =time_diff($EditedTime,2,true,true)?>
+ =Users::format_username($EditedUserID, false, false, false) ?> =time_diff($EditedTime,2,true,true)?>
} ?>
@@ -332,6 +332,6 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/userhistory/subscribed_collages.php b/sections/userhistory/subscribed_collages.php
index 7ccf02e1..144d14df 100644
--- a/sections/userhistory/subscribed_collages.php
+++ b/sections/userhistory/subscribed_collages.php
@@ -7,7 +7,7 @@
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
$Text = new TEXT;
-show_header('Subscribed collages','browse,collage');
+View::show_header('Subscribed collages','browse,collage');
$ShowAll = !empty($_GET['showall']);
@@ -86,23 +86,23 @@
ORDER BY ct.AddedOn");
$NewTorrentCount = $DB->record_count();
//$NewTorrents = $DB->to_array();
- //$Artists = get_artists($GroupID);
+ //$Artists = Artists::get_artists($GroupID);
$GroupIDs = $DB->collect('GroupID');
$CollageDataList=$DB->to_array('GroupID', MYSQLI_ASSOC);
if(count($GroupIDs)>0) {
- $TorrentList = get_groups($GroupIDs);
+ $TorrentList = Torrents::get_groups($GroupIDs);
$TorrentList = $TorrentList['matches'];
} else {
$TorrentList = array();
}
- $Artists = get_artists($GroupIDs);
+ $Artists = Artists::get_artists($GroupIDs);
$Number = 0;
// foreach ($NewTorrents as $TorrentGroup) {
// list($GroupID, $GroupName, $GroupYear, $ReleaseType, $RecordLabel, $CatalogueNumber, $WikiImage) = $TorrentGroup;
- // $DisplayName = display_artists($Artists[$GroupID]);
+ // $DisplayName = Artists::display_artists($Artists[$GroupID]);
// $AltName=$GroupName;
foreach ($TorrentList as $GroupID => $Group) {
list($GroupID, $GroupName, $GroupYear, $GroupRecordLabel, $GroupCatalogueNumber, $TagList, $ReleaseType, $GroupVanityHouse, $Torrents, $GroupArtists, $ExtendedArtists) = array_values($Group);
@@ -128,9 +128,9 @@
if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4]) || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
unset($ExtendedArtists[2]);
unset($ExtendedArtists[3]);
- $DisplayName .= display_artists($ExtendedArtists);
+ $DisplayName .= Artists::display_artists($ExtendedArtists);
} elseif(count($GroupArtists)>0) {
- $DisplayName .= display_artists(array('1'=>$GroupArtists));
+ $DisplayName .= Artists::display_artists(array('1'=>$GroupArtists));
}
$DisplayName .= ''.$GroupName.' ';
if($GroupYear>0) { $DisplayName = $DisplayName. ' ['. $GroupYear .']';}
@@ -226,9 +226,9 @@
[ DL ]
- » =torrent_info($Torrent)?>
+ » =Torrents::torrent_info($Torrent)?>
- =get_size($Torrent['Size'])?>
+ =Format::get_size($Torrent['Size'])?>
=number_format($Torrent['Snatched'])?>
>=number_format($Torrent['Seeders'])?>
=number_format($Torrent['Leechers'])?>
@@ -260,7 +260,7 @@
=$DisplayName?>
=$TorrentTags?>
- =get_size($Torrent['Size'])?>
+ =Format::get_size($Torrent['Size'])?>
=number_format($Torrent['Snatched'])?>
>=number_format($Torrent['Seeders'])?>
=number_format($Torrent['Leechers'])?>
@@ -304,6 +304,6 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/userhistory/subscriptions.php b/sections/userhistory/subscriptions.php
index 4d9ba036..0b0c7667 100644
--- a/sections/userhistory/subscriptions.php
+++ b/sections/userhistory/subscriptions.php
@@ -15,9 +15,9 @@
} else {
$PerPage = POSTS_PER_PAGE;
}
-list($Page,$Limit) = page_limit($PerPage);
+list($Page,$Limit) = Format::page_limit($PerPage);
-show_header('Subscribed topics','subscriptions,bbcode');
+View::show_header('Subscribed topics','subscriptions,bbcode');
if($LoggedUser['CustomForums']) {
unset($LoggedUser['CustomForums']['']);
@@ -131,7 +131,7 @@
?>
- $Pages=get_pages($Page,$NumResults,$PerPage, 11);
+ $Pages=Format::get_pages($Page,$NumResults,$PerPage, 11);
echo $Pages;
?>
@@ -143,7 +143,7 @@
=$ForumName?> >
- =cut_string($ThreadTitle, 75)?>
+ =Format::cut_string($ThreadTitle, 75)?>
if($PostID<$LastPostID && !$Locked) { ?>
(New!)
} ?>
@@ -176,7 +176,7 @@
if($EditedUserID) { ?>
Last edited by
- =format_username($EditedUserID, false, false, false) ?> =time_diff($EditedTime)?>
+ =Users::format_username($EditedUserID, false, false, false) ?> =time_diff($EditedTime)?>
} ?>
@@ -190,6 +190,6 @@
-show_footer();
+View::show_footer();
?>
diff --git a/sections/userhistory/token_history.php b/sections/userhistory/token_history.php
index ead9fb62..f06f95fb 100644
--- a/sections/userhistory/token_history.php
+++ b/sections/userhistory/token_history.php
@@ -15,8 +15,8 @@
}
if (!is_number($UserID)) { error(404); }
-$UserInfo = user_info($UserID);
-$Perms = get_permissions($UserInfo['PermissionID']);
+$UserInfo = Users::user_info($UserID);
+$Perms = Permissions::get_permissions($UserInfo['PermissionID']);
$UserClass = $Perms['Class'];
if(!check_perms('users_mod')) {
@@ -35,14 +35,14 @@
if (list($InfoHash) = $DB->next_record(MYSQLI_NUM, FALSE)) {
$DB->query("UPDATE users_freeleeches SET Expired=TRUE WHERE UserID=$UserID AND TorrentID=$TorrentID");
$Cache->delete_value('users_tokens_'.$UserID);
- update_tracker('remove_token', array('info_hash' => rawurlencode($InfoHash), 'userid' => $UserID));
+ Tracker::update_tracker('remove_token', array('info_hash' => rawurlencode($InfoHash), 'userid' => $UserID));
}
header("Location: userhistory.php?action=token_history&userid=$UserID");
}
-show_header('Freeleech token history');
+View::show_header('Freeleech token history');
-list($Page,$Limit) = page_limit(25);
+list($Page,$Limit) = Format::page_limit(25);
$DB->query("SELECT SQL_CALC_FOUND_ROWS
f.TorrentID,
@@ -64,11 +64,11 @@
$DB->query("SELECT FOUND_ROWS()");
list($NumResults) = $DB->next_record();
-$Pages=get_pages($Page, $NumResults, 25);
+$Pages=Format::get_pages($Page, $NumResults, 25);
?>
=$Pages?>
@@ -85,14 +85,14 @@
foreach ($Tokens as $Token) {
$GroupIDs[] = $Token['GroupID'];
}
-$Artists = get_artists($GroupIDs);
+$Artists = Artists::get_artists($GroupIDs);
$i = true;
foreach ($Tokens as $Token) {
$i = !$i;
list($TorrentID, $GroupID, $Time, $Expired, $Downloaded, $Uses, $Name, $Format, $Encoding) = $Token;
$Name = "$Name ";
- $ArtistName = display_artists($Artists[$GroupID]);
+ $ArtistName = Artists::display_artists($Artists[$GroupID]);
if($ArtistName) {
$Name = $ArtistName.$Name;
}
@@ -106,7 +106,7 @@
=($Expired ? 'Yes' : 'No')?>=(check_perms('users_mod') && !$Expired)?" (expire) ":''?>
if (check_perms('users_mod')) { ?>
- =get_size($Downloaded)?>
+ =Format::get_size($Downloaded)?>
=$Uses?>
} ?>
@@ -115,5 +115,5 @@
=$Pages?>
-show_footer();
+View::show_footer();
?>
diff --git a/sections/wiki/aliases.php b/sections/wiki/aliases.php
index 74d825a9..e9c37e76 100644
--- a/sections/wiki/aliases.php
+++ b/sections/wiki/aliases.php
@@ -6,7 +6,7 @@
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Latest);
if($Edit > $LoggedUser['EffectiveClass']){ error(404); }
-show_header($Title." Aliases");
+View::show_header($Title." Aliases");
?>
- show_footer(); ?>
\ No newline at end of file
+ View::show_footer(); ?>
\ No newline at end of file
diff --git a/sections/wiki/article.php b/sections/wiki/article.php
index 3333f343..29added1 100644
--- a/sections/wiki/article.php
+++ b/sections/wiki/article.php
@@ -12,7 +12,7 @@
}
if(!$ArticleID) { //No article found
- show_header('No article found');
+ View::show_header('No article found');
?>
- show_footer();
+ View::show_footer();
die();
}
$Article = $Alias->article($ArticleID);
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName, $Aliases, $UserIDs) = array_shift($Article);
if($Read > $LoggedUser['EffectiveClass']){ error('You must be a higher user class to view this wiki article'); }
-show_header($Title,'wiki,bbcode');
+View::show_header($Title,'wiki,bbcode');
?>
- show_footer(); ?>
+ View::show_footer(); ?>
diff --git a/sections/wiki/compare.php b/sections/wiki/compare.php
index eebb6907..b3ba23ed 100644
--- a/sections/wiki/compare.php
+++ b/sections/wiki/compare.php
@@ -79,7 +79,7 @@ function get_body($ID, $Rev) {
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Article);
if($Read > $LoggedUser['EffectiveClass']){ error(404); }
-show_header('Compare Article Revisions');
+View::show_header('Compare Article Revisions');
$Diff2 = get_body($ArticleID, $_GET['new']);
$Diff1 = get_body($ArticleID, $_GET['old']);
?>
@@ -92,5 +92,5 @@ function get_body($ID, $Rev) {
-show_footer();
+View::show_footer();
?>
diff --git a/sections/wiki/create.php b/sections/wiki/create.php
index 867f32aa..6771bfd0 100644
--- a/sections/wiki/create.php
+++ b/sections/wiki/create.php
@@ -1,5 +1,5 @@
-show_header('Create an article');
+View::show_header('Create an article');
?>
- show_footer(); ?>
\ No newline at end of file
+ View::show_footer(); ?>
\ No newline at end of file
diff --git a/sections/wiki/delete.php b/sections/wiki/delete.php
index 656ea2fd..a8088da9 100644
--- a/sections/wiki/delete.php
+++ b/sections/wiki/delete.php
@@ -12,7 +12,7 @@
list($Title) = $DB->next_record(MYSQLI_NUM, false);
//Log
-write_log("Wiki article ".$ID." (".$Title.") was deleted by ".$LoggedUser['Username']);
+Misc::write_log("Wiki article ".$ID." (".$Title.") was deleted by ".$LoggedUser['Username']);
//Delete
$DB->query("DELETE FROM wiki_articles WHERE ID = $ID");
$DB->query("DELETE FROM wiki_aliases WHERE ArticleID = $ID");
diff --git a/sections/wiki/edit.php b/sections/wiki/edit.php
index b237559e..ec490e14 100644
--- a/sections/wiki/edit.php
+++ b/sections/wiki/edit.php
@@ -8,7 +8,7 @@
error('You do not have access to edit this article.');
}
-show_header('Edit '.$Title);
+View::show_header('Edit '.$Title);
?>
- show_footer(); ?>
\ No newline at end of file
+ View::show_footer(); ?>
\ No newline at end of file
diff --git a/sections/wiki/index.php b/sections/wiki/index.php
index 121cd7e4..63ef3fbf 100644
--- a/sections/wiki/index.php
+++ b/sections/wiki/index.php
@@ -18,7 +18,7 @@ function class_list($Selected=0){
if($Selected == $Class['Level']){
$Return.=' selected="selected"';
}
- $Return.='>'.cut_string($Class['Name'], 20, 1).''."\n";
+ $Return.='>'.Format::cut_string($Class['Name'], 20, 1).''."\n";
}
}
reset($Classes);
diff --git a/sections/wiki/link.php b/sections/wiki/link.php
index 984ab1c3..367b6ba1 100644
--- a/sections/wiki/link.php
+++ b/sections/wiki/link.php
@@ -1,5 +1,5 @@
-show_header('Link an article');
+View::show_header('Link an article');
?>
- show_footer(); ?>
\ No newline at end of file
+ View::show_footer(); ?>
\ No newline at end of file
diff --git a/sections/wiki/revisions.php b/sections/wiki/revisions.php
index ee40cc37..38385c45 100644
--- a/sections/wiki/revisions.php
+++ b/sections/wiki/revisions.php
@@ -7,7 +7,7 @@
if($Read > $LoggedUser['EffectiveClass']){ error(404); }
if($Edit > $LoggedUser['EffectiveClass']){ error(403); }
-show_header("Revisions of ".$Title);
+View::show_header("Revisions of ".$Title);
?>
- show_footer(); ?>
\ No newline at end of file
+ View::show_footer(); ?>
\ No newline at end of file