diff --git a/classes/class_cache.php b/classes/class_cache.php index a3d53454..41414aaa 100644 --- a/classes/class_cache.php +++ b/classes/class_cache.php @@ -16,10 +16,10 @@ as get, but cache_value only takes the key, the value, and the duration (no zlib). -//unix sockets +// Unix sockets memcached -d -m 5120 -s /var/run/memcached.sock -a 0777 -t16 -C -u root -//tcp bind +// TCP bind memcached -d -m 8192 -l 10.10.0.1 -t8 -C |*************************************************************************/ @@ -28,8 +28,7 @@ die('Memcache Extension not loaded.'); } -class CACHE extends Memcache -{ +class CACHE extends Memcache { /** * Torrent Group cache version */ @@ -64,51 +63,51 @@ function __construct($Servers) { // Allows us to set an expiration on otherwise perminantly cache'd values // Useful for disabled users, locked threads, basically reducing ram usage - public function expire_value($Key, $Duration=2592000) { - $StartTime=microtime(true); + public function expire_value($Key, $Duration = 2592000) { + $StartTime = microtime(true); $this->set($Key, $this->get($Key), $Duration); - $this->Time+=(microtime(true)-$StartTime)*1000; + $this->Time += (microtime(true) - $StartTime) * 1000; } // Wrapper for Memcache::set, with the zlib option removed and default duration of 30 days - public function cache_value($Key, $Value, $Duration=2592000) { - $StartTime=microtime(true); + public function cache_value($Key, $Value, $Duration = 2592000) { + $StartTime = microtime(true); if (empty($Key)) { trigger_error("Cache insert failed for empty key"); } if (!$this->set($Key, $Value, 0, $Duration)) { trigger_error("Cache insert failed for key $Key"); } - $this->Time+=(microtime(true)-$StartTime)*1000; + $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; + 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); + public function replace_value($Key, $Value, $Duration = 2592000) { + $StartTime = microtime(true); $this->replace($Key, $Value, false, $Duration); - $this->Time+=(microtime(true)-$StartTime)*1000; + $this->Time += (microtime(true) - $StartTime) * 1000; } - public function get_value($Key, $NoCache=false) { + public function get_value($Key, $NoCache = false) { if (!$this->InternalCache) { $NoCache = true; } $StartTime=microtime(true); if (empty($Key)) { - trigger_error("Cache retrieval failed for empty key"); + trigger_error('Cache retrieval failed for empty key'); } 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 + // 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 (!Misc::in_array_partial($HitKey, $this->PersistentKeys)) { @@ -118,11 +117,11 @@ public function get_value($Key, $NoCache=false) { } } $this->delete($Key); - $this->Time+=(microtime(true)-$StartTime)*1000; + $this->Time += (microtime(true) - $StartTime) * 1000; return false; } elseif ($_GET['clearcache'] == $Key) { $this->delete($Key); - $this->Time+=(microtime(true)-$StartTime)*1000; + $this->Time += (microtime(true) - $StartTime) * 1000; return false; } elseif (in_array($_GET['clearcache'], $this->CacheHits)) { unset($this->CacheHits[$_GET['clearcache']]); @@ -130,9 +129,9 @@ public function get_value($Key, $NoCache=false) { } } - //For cases like the forums, if a keys already loaded grab the existing pointer + // For cases like the forums, if a key is already loaded, grab the existing pointer if (isset($this->CacheHits[$Key]) && !$NoCache) { - $this->Time+=(microtime(true)-$StartTime)*1000; + $this->Time += (microtime(true) - $StartTime) * 1000; return $this->CacheHits[$Key]; } @@ -140,26 +139,26 @@ public function get_value($Key, $NoCache=false) { if ($Return !== false) { $this->CacheHits[$Key] = $NoCache ? null : $Return; } - $this->Time+=(microtime(true)-$StartTime)*1000; + $this->Time += (microtime(true) - $StartTime) * 1000; return $Return; } // Wrapper for Memcache::delete. For a reason, see above. public function delete_value($Key) { - $StartTime=microtime(true); + $StartTime = microtime(true); if (empty($Key)) { - trigger_error("Cache deletion failed for empty key"); + trigger_error('Cache deletion failed for empty key'); } if (!$this->delete($Key)) { //trigger_error("Cache delete failed for key $Key"); } - $this->Time+=(microtime(true)-$StartTime)*1000; + $this->Time += (microtime(true) - $StartTime) * 1000; } - public function increment_value($Key,$Value=1) { - $StartTime=microtime(true); - $this->increment($Key,$Value); - $this->Time+=(microtime(true)-$StartTime)*1000; + public function increment_value($Key, $Value = 1) { + $StartTime = microtime(true); + $this->increment($Key, $Value); + $this->Time += (microtime(true) - $StartTime) * 1000; } //---------- memcachedb functions ----------// @@ -184,7 +183,7 @@ public function cancel_transaction() { $this->MemcacheDBKey = ''; } - public function commit_transaction($Time=2592000) { + public function commit_transaction($Time = 2592000) { if (!$this->InTransaction) { return false; } @@ -261,10 +260,10 @@ public function increment_row($Row, $Values) { } foreach ($Values as $Key => $Value) { if (!array_key_exists($Key, $UpdateArray)) { - trigger_error('Bad transaction key ('.$Key.') for cache '.$this->MemcacheDBKey); + trigger_error("Bad transaction key ($Key) for cache ".$this->MemcacheDBKey); } if (!is_number($Value)) { - trigger_error('Tried to increment with non-number ('.$Key.') for cache '.$this->MemcacheDBKey); + trigger_error("Tried to increment with non-number ($Key) for cache ".$this->MemcacheDBKey); } $UpdateArray[$Key] += $Value; // Increment value } @@ -316,12 +315,12 @@ public function delete_row($Row) { return false; } if (!isset($this->MemcacheDBArray[$Row])) { - trigger_error('Tried to delete non-existent row ('.$Row.') for cache '.$this->MemcacheDBKey); + trigger_error("Tried to delete non-existent row ($Row) for cache ".$this->MemcacheDBKey); } unset($this->MemcacheDBArray[$Row]); } - public function update($Key, $Rows, $Values, $Time=2592000) { + public function update($Key, $Rows, $Values, $Time = 2592000) { if (!$this->InTransaction) { $this->begin_transaction($Key); $this->update_transaction($Rows, $Values); @@ -329,7 +328,6 @@ public function update($Key, $Rows, $Values, $Time=2592000) { } else { $this->update_transaction($Rows, $Values); } - } /** diff --git a/classes/class_text.php b/classes/class_text.php index 05300e2f..5d28630c 100644 --- a/classes/class_text.php +++ b/classes/class_text.php @@ -658,7 +658,7 @@ private function to_html ($Array) { $Str.=''.$Block['Val'].''; break; case 'tex': - $Str.=''.$Block['Val'].''; + $Str.=''.$Block['Val'].''; break; case 'plain': $Str.=$Block['Val']; @@ -729,7 +729,7 @@ private function to_html ($Array) { $Exploded = explode('|', $this->to_html($Block['Attr'])); if (isset($Exploded[1]) && is_numeric($Exploded[1])) { $PostID = trim($Exploded[1]); - $Str.=''.$Exploded[0].' wrote: '; + $Str.=''.$Exploded[0].' wrote: '; } else { $Str.=''.$Exploded[0].' wrote: '; diff --git a/sections/ajax/forum/thread.php b/sections/ajax/forum/thread.php index 5b5feed1..840c21df 100644 --- a/sections/ajax/forum/thread.php +++ b/sections/ajax/forum/thread.php @@ -182,13 +182,13 @@ $JsonPoll['totalVotes'] = $TotalVotes; $JsonPollAnswers = array(); - foreach($Answers as $i => $Answer) { + foreach ($Answers as $i => $Answer) { if (!empty($Votes[$i]) && $TotalVotes > 0) { - $Ratio = $Votes[$i]/$MaxVotes; - $Percent = $Votes[$i]/$TotalVotes; + $Ratio = $Votes[$i] / $MaxVotes; + $Percent = $Votes[$i] / $TotalVotes; } else { - $Ratio=0; - $Percent=0; + $Ratio = 0; + $Percent = 0; } $JsonPollAnswers[] = array( 'answer' => $Answer, diff --git a/sections/ajax/usersearch.php b/sections/ajax/usersearch.php index 11b4e06e..dc1a64d4 100644 --- a/sections/ajax/usersearch.php +++ b/sections/ajax/usersearch.php @@ -15,15 +15,16 @@ $_GET['username'] = trim($_GET['username']); list($Page,$Limit) = Format::page_limit(USERS_PER_PAGE); - $DB->query("SELECT SQL_CALC_FOUND_ROWS - ID, - Username, - Enabled, - PermissionID, - Donor, - Warned + $DB->query(" + SELECT SQL_CALC_FOUND_ROWS + ID, + Username, + Enabled, + PermissionID, + Donor, + Warned FROM users_main AS um - JOIN users_info AS ui ON ui.UserID=um.ID + JOIN users_info AS ui ON ui.UserID=um.ID WHERE Username LIKE '%".db_string($_GET['username'])."%' ORDER BY Username LIMIT $Limit"); @@ -34,7 +35,7 @@ } $JsonUsers = array(); -foreach($Results as $Result) { +foreach ($Results as $Result) { list($UserID, $Username, $Enabled, $PermissionID, $Donor, $Warned) = $Result; $JsonUsers[] = array( diff --git a/sections/artist/artist.php b/sections/artist/artist.php index 21edd4b6..e7e617f5 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -523,9 +523,7 @@ function compare($X, $Y) { if ($RevisionID && check_perms('site_edit_wiki')) { ?> - - Revert to this revision - + Revert to this revision diff --git a/sections/captcha/index.php b/sections/captcha/index.php index 51f9cd89..a0256d0e 100644 --- a/sections/captcha/index.php +++ b/sections/captcha/index.php @@ -1,5 +1,7 @@ \ No newline at end of file +$_SESSION['captcha'] = make_captcha_img(); +?> diff --git a/sections/inbox/conversation.php b/sections/inbox/conversation.php index f2cf1fc2..ce36af97 100644 --- a/sections/inbox/conversation.php +++ b/sections/inbox/conversation.php @@ -73,7 +73,7 @@ next_record()) { ?> +while (list($SentDate, $SenderID, $Body, $MessageID) = $DB->next_record()) { ?>
- Quote @@ -84,7 +84,12 @@
query("SELECT UserID FROM pm_conversations_users WHERE UserID!='$LoggedUser[ID]' AND ConvID='$ConvID' AND (ForwardedTo=0 OR ForwardedTo=UserID)"); +$DB->query(" + SELECT UserID + FROM pm_conversations_users + WHERE UserID!='$LoggedUser[ID]' + AND ConvID='$ConvID' + AND (ForwardedTo=0 OR ForwardedTo=UserID)"); $ReceiverIDs = $DB->collect('UserID'); diff --git a/sections/log/index.php b/sections/log/index.php index 14a6d388..48805ecd 100644 --- a/sections/log/index.php +++ b/sections/log/index.php @@ -45,7 +45,7 @@ next_record()) { +while (list($ID, $Message, $LogTime) = $DB->next_record()) { $MessageParts = explode(" ", $Message); $Message = ""; $Color = $Colon = false; diff --git a/sections/reports/takereport.php b/sections/reports/takereport.php index 5615e623..188c5d47 100644 --- a/sections/reports/takereport.php +++ b/sections/reports/takereport.php @@ -90,7 +90,7 @@ } -foreach($Channels as $Channel) { +foreach ($Channels as $Channel) { send_irc("PRIVMSG ".$Channel." :".$ReportID." - ".$LoggedUser['Username']." just reported a ".$Short.": https://".SSL_SITE_URL."/".$Link." : ".strtr($Reason, "\n", " ")); } diff --git a/sections/reportsv2/ajax_report.php b/sections/reportsv2/ajax_report.php index a086275f..ddb69cb5 100644 --- a/sections/reportsv2/ajax_report.php +++ b/sections/reportsv2/ajax_report.php @@ -20,7 +20,7 @@ die(); } -foreach($ReportType['report_messages'] as $Message) { +foreach ($ReportType['report_messages'] as $Message) { ?>
  • Warning - + diff --git a/sections/torrents/merge.php b/sections/torrents/merge.php index cd2e2696..db521e3a 100644 --- a/sections/torrents/merge.php +++ b/sections/torrents/merge.php @@ -106,7 +106,7 @@ //Collages $DB->query("SELECT CollageID FROM collages_torrents WHERE GroupID='$OldGroupID'"); //Select all collages that contain edited group - while(list($CollageID) = $DB->next_record()) { + while (list($CollageID) = $DB->next_record()) { $DB->query("UPDATE IGNORE collages_torrents SET GroupID='$NewGroupID' WHERE GroupID='$OldGroupID' AND CollageID='$CollageID'"); //Change collage groupid to new ID $DB->query("DELETE FROM collages_torrents WHERE GroupID='$OldGroupID' AND CollageID='$CollageID'"); $Cache->delete_value('collage_'.$CollageID); @@ -121,7 +121,7 @@ } $DB->query("SELECT ID FROM torrents WHERE GroupID='$OldGroupID'"); - while(list($TorrentID) = $DB->next_record()) { + while (list($TorrentID) = $DB->next_record()) { $Cache->delete_value('torrent_download_'.$TorrentID); } $Cache->delete_value('torrents_details_'.$GroupID); diff --git a/sections/torrents/takegroupedit.php b/sections/torrents/takegroupedit.php index 46f79b87..1af86813 100644 --- a/sections/torrents/takegroupedit.php +++ b/sections/torrents/takegroupedit.php @@ -109,16 +109,19 @@ $Image = db_string($Image); // Update torrents table (technically, we don't need the RevisionID column, but we can use it for a join which is nice and fast) -$DB->query("UPDATE torrents_group SET - RevisionID='$RevisionID', - ".((isset($VanityHouse)) ? "VanityHouse='$VanityHouse'," : '')." - WikiBody='$Body', - WikiImage='$Image' +$DB->query(" + UPDATE torrents_group + SET + RevisionID='$RevisionID', + ".((isset($VanityHouse)) ? "VanityHouse='$VanityHouse'," : '')." + WikiBody='$Body', + WikiImage='$Image' WHERE ID='$GroupID'"); // Log VH changes if ($OldVH != $VanityHouse && check_perms('torrents_edit_vanityhouse')) { - $DB->query("INSERT INTO group_log (GroupID, UserID, Time, Info) - VALUES ('$GroupID',".$LoggedUser['ID'].",'".sqltime()."','".db_string('Vanity house status changed to '.($VanityHouse?'true':'false'))."')"); + $DB->query(" + INSERT INTO group_log (GroupID, UserID, Time, Info) + VALUES ('$GroupID',".$LoggedUser['ID'].",'".sqltime()."','".db_string('Vanity house status changed to '.($VanityHouse ? 'true' : 'false'))."')"); } // There we go, all done! @@ -126,16 +129,17 @@ $Cache->delete_value('torrents_details_'.$GroupID); $DB->query("SELECT CollageID FROM collages_torrents WHERE GroupID='$GroupID'"); if ($DB->record_count() > 0) { - while(list($CollageID) = $DB->next_record()) { + while (list($CollageID) = $DB->next_record()) { $Cache->delete_value('collage_'.$CollageID); } } //Fix Recent Uploads/Downloads for image change -$DB->query("SELECT DISTINCT UserID - FROM torrents AS t - LEFT JOIN torrents_group AS tg ON t.GroupID=tg.ID - WHERE tg.ID = $GroupID"); +$DB->query(" + SELECT DISTINCT UserID + FROM torrents AS t + LEFT JOIN torrents_group AS tg ON t.GroupID=tg.ID + WHERE tg.ID = $GroupID"); $UserIDs = $DB->collect('UserID'); foreach ($UserIDs as $UserID) { diff --git a/static/functions/comments.js b/static/functions/comments.js index 1443cd04..17b37298 100644 --- a/static/functions/comments.js +++ b/static/functions/comments.js @@ -188,18 +188,18 @@ function Newthread_Preview(mode) { if (pollanswers && pollanswers.children.length > 4) { pollanswers = pollanswers.children; $('#pollquestion').raw().innerHTML = $('#pollquestionfield').raw().value; - for(var i=0; i