From c1294d48b13bf61167d01ba4338fcb9ea05da7a8 Mon Sep 17 00:00:00 2001 From: Git Date: Mon, 29 Oct 2012 08:00:20 +0000 Subject: [PATCH] Empty commit --- classes/class_mass_user_bookmarks_editor.php | 146 +++---- classes/class_mass_user_torrents_editor.php | 196 ++++----- classes/class_textarea_preview.php | 396 +++++++++--------- classes/class_torrents.php | 3 +- design/views/generic/textarea/buttons.phtml | 6 +- design/views/generic/textarea/preview.phtml | 8 +- .../generic/textarea/script_factory.phtml | 8 +- design/views/generic/textarea/textarea.phtml | 8 +- gazelle.sql | 5 +- sections/ajax/takevote.php | 22 +- sections/artist/artist.php | 230 +++++----- sections/artist/take_warn.php | 76 ++-- sections/artist/warn.php | 16 +- sections/bookmarks/edit_torrents.php | 56 +-- sections/collages/all_comments.php | 8 +- sections/comments/artistcomments.php | 6 +- sections/comments/index.php | 1 - sections/comments/post.php | 12 +- sections/forums/newthread.php | 8 +- sections/forums/thread.php | 194 +++++---- sections/reports/takereport.php | 6 + sections/requests/request.php | 88 ++-- sections/tools/tools.php | 1 + sections/top10/torrents.php | 2 +- sections/top10/votes.php | 16 +- sections/torrents/details.php | 153 ++++--- sections/torrents/voter_picks.php | 2 +- sections/user/community_stats.php | 11 + sections/userhistory/post_history.php | 8 +- sections/userhistory/subscriptions.php | 8 +- sections/userhistory/token_history.php | 2 +- static/functions/comments.js | 2 +- static/functions/rippy.js | 19 +- static/styles/proton/style.css | 18 + 34 files changed, 935 insertions(+), 806 deletions(-) diff --git a/classes/class_mass_user_bookmarks_editor.php b/classes/class_mass_user_bookmarks_editor.php index 4bc127af..6690d287 100644 --- a/classes/class_mass_user_bookmarks_editor.php +++ b/classes/class_mass_user_bookmarks_editor.php @@ -1,74 +1,74 @@ -set_table($Table); - } - - /** - * Runs a SQL query and clears the bookmarks_torrent_{$UserID}_full Cache key - * - * $Cache->delete_value didn't always work, but setting the key to null, did. (?) - * - * @param string $sql - */ - protected function query_and_clear_cache ($sql) - { - if (is_string($sql) && $this->DB->query($sql)) { - $this->Cache->cache_value('bookmarks_torrent_' . $this->UserID, null, 0); - $this->Cache->cache_value('bookmarks_torrent_' . $this->UserID . '_full', null, 0); - } - } - - /** - * Uses (checkboxes) $_POST['remove'] to delete entries. - * - * Uses an IN() to match multiple items in one query. - */ - public function mass_remove () { - $SQL = array(); - foreach ($_POST['remove'] as $GroupID => $K) { - if (is_number($GroupID)) - $SQL[] = sprintf('%d', $GroupID); - } - - if (!empty($SQL)) { - $SQL = sprintf('DELETE FROM %s WHERE UserID = %d AND GroupID IN (%s)', - $this->Table, - $this->UserID, - implode(', ', $SQL) - ); - $this->query_and_clear_cache($SQL); - } - } - - /** - * Uses $_POST['sort'] values to update the DB. - */ - public function mass_update () { - $SQL = array(); - foreach ($_POST['sort'] as $GroupID => $Sort) { - if (is_number($Sort) && is_number($GroupID)) - $SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, $this->UserID); - } - - if (!empty($SQL)) { - $SQL = sprintf('INSERT INTO %s (GroupID, Sort, UserID) VALUES %s - ON DUPLICATE KEY UPDATE Sort = VALUES (Sort)', - $this->Table, - implode(', ', $SQL)); - $this->query_and_clear_cache($SQL); - } - } +set_table($Table); + } + + /** + * Runs a SQL query and clears the bookmarks_torrent_{$UserID}_full Cache key + * + * $Cache->delete_value didn't always work, but setting the key to null, did. (?) + * + * @param string $sql + */ + protected function query_and_clear_cache ($sql) + { + if (is_string($sql) && $this->DB->query($sql)) { + $this->Cache->cache_value('bookmarks_torrent_' . $this->UserID, null, 0); + $this->Cache->cache_value('bookmarks_torrent_' . $this->UserID . '_full', null, 0); + } + } + + /** + * Uses (checkboxes) $_POST['remove'] to delete entries. + * + * Uses an IN() to match multiple items in one query. + */ + public function mass_remove () { + $SQL = array(); + foreach ($_POST['remove'] as $GroupID => $K) { + if (is_number($GroupID)) + $SQL[] = sprintf('%d', $GroupID); + } + + if (!empty($SQL)) { + $SQL = sprintf('DELETE FROM %s WHERE UserID = %d AND GroupID IN (%s)', + $this->Table, + $this->UserID, + implode(', ', $SQL) + ); + $this->query_and_clear_cache($SQL); + } + } + + /** + * Uses $_POST['sort'] values to update the DB. + */ + public function mass_update () { + $SQL = array(); + foreach ($_POST['sort'] as $GroupID => $Sort) { + if (is_number($Sort) && is_number($GroupID)) + $SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, $this->UserID); + } + + if (!empty($SQL)) { + $SQL = sprintf('INSERT INTO %s (GroupID, Sort, UserID) VALUES %s + ON DUPLICATE KEY UPDATE Sort = VALUES (Sort)', + $this->Table, + implode(', ', $SQL)); + $this->query_and_clear_cache($SQL); + } + } } \ No newline at end of file diff --git a/classes/class_mass_user_torrents_editor.php b/classes/class_mass_user_torrents_editor.php index 11da274b..ec67d3ac 100644 --- a/classes/class_mass_user_torrents_editor.php +++ b/classes/class_mass_user_torrents_editor.php @@ -1,99 +1,99 @@ -Cache = $Cache; - $this->DB = $DB; - $this->UserID = (int) $UserID; - if ($this->UserID < 1) error(403); - } - - /** - * Set the Table - * @param string $Table - */ - final public function set_table ($Table) - { - $this->Table = db_string($Table); - } - - /** - * Get the Table - * @param sting $Table - * @return string $Table - */ - final public function get_table () - { - return $this->Table; - } - - /** - * The extending class must provide a method to send a query and clear the cache - */ - abstract protected function query_and_clear_cache ($sql); - - /** - * A method to insert many rows into a single table - * Not required in subsequent classes - */ - public function mass_add () {} - - /** - * A method to remove many rows from a table - * The extending class must have a mass_remove method - */ - abstract public function mass_remove (); - - /** - * A method to update many rows in a table - * The extending class must have a mass_update method - */ - abstract public function mass_update (); +Cache = $Cache; + $this->DB = $DB; + $this->UserID = (int) $UserID; + if ($this->UserID < 1) error(403); + } + + /** + * Set the Table + * @param string $Table + */ + final public function set_table ($Table) + { + $this->Table = db_string($Table); + } + + /** + * Get the Table + * @param sting $Table + * @return string $Table + */ + final public function get_table () + { + return $this->Table; + } + + /** + * The extending class must provide a method to send a query and clear the cache + */ + abstract protected function query_and_clear_cache ($sql); + + /** + * A method to insert many rows into a single table + * Not required in subsequent classes + */ + public function mass_add () {} + + /** + * A method to remove many rows from a table + * The extending class must have a mass_remove method + */ + abstract public function mass_remove (); + + /** + * A method to update many rows in a table + * The extending class must have a mass_update method + */ + abstract public function mass_update (); } \ No newline at end of file diff --git a/classes/class_textarea_preview.php b/classes/class_textarea_preview.php index 63865d63..15743df7 100644 --- a/classes/class_textarea_preview.php +++ b/classes/class_textarea_preview.php @@ -1,199 +1,199 @@ - - * @return void - */ - static public function JavaScript ($all = true) - { - if (self::$Textareas === 0) return; - if (self::$Exectuted === false && $all) - View::parse('generic/textarea/script.phtml'); - - self::$Exectuted = true; - self::iterator(); - } - - /** - * This iterator generates JavaScript to initialize each JavaScript - * TextareaPreview object. - * - * It will generate a numeric or custom ID related to the textarea. - * @static - * @return void - */ - static private function iterator () - { - $script = array(); - for($i = 0; $i < self::$Textareas; $i++) { - if (isset(self::$_ID[$i]) && is_string(self::$_ID[$i])) { - $a = sprintf('%d, "%s"', $i, self::$_ID[$i]); - } else { - $a = $i; - } - $script[] = sprintf('[%s]', $a); - } - if (!empty($script)) - View::parse('generic/textarea/script_factory.phtml', - array('script' => join(', ', $script))); - } -} - -/** - * Textarea Preview Class - * - * This class generates a textarea that works with the JS preview script. - * - * Templates found in design/views/generic/textarea - * - * @example
buttons(); // output buttons
- *
- *  $text->preview(); // output preview div
- *
- * // Create a textarea with custom preview wrapper around a table
- * // the table will be (in)visible depending on the toggle
- * $text = new TEXTAREA_PREVIEW('body', '', '', 30, 10, false, false);
- * $id = $text->getID();
- *
- * // some template
- * 
- * - * - * - * - *
- *
- *
- *
- *
- */ -class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER -{ - /** - * @var int Unique ID - */ - private $id; - - /** - * Flag for preview output - * @var bool $preview - */ - private $preview = false; - - /** - * This method creates a textarea - * - * @param string $Name name attribute - * @param string $ID id attribute - * @param string $Value default text attribute - * @param string $Cols cols attribute - * @param string $Rows rows attribute - * @param bool $Preview add the preview divs near the textarea - * @param bool $Buttons add the edit/preview buttons near the textarea - * - * If false for either, use the appropriate methods to add the those - * elements elsewhere. Alternatively, use getID to create your own. - * - * @param array $ExtraAttributes array of attribute="value" - */ - public function __construct ($Name, $ID = '', $Value='', $Cols=50, $Rows=10, - $Preview = true, $Buttons = true, array $ExtraAttributes = array() - ) { - $this->id = parent::$Textareas; - parent::$Textareas += 1; - array_push(parent::$_ID, $ID); - - if (empty($ID)) $ID = 'quickpost_' . $this->id; - - if (!empty($ExtraAttributes)) - $Attributes = ' ' . implode(' ', $ExtraAttributes); - else - $Attributes = ''; - - if ($Preview === true) $this->preview(); - - View::parse('generic/textarea/textarea.phtml', array( - 'ID' => $ID, - 'NID' => $this->id, - 'Name' => &$Name, - 'Value' => &$Value, - 'Cols' => &$Cols, - 'Rows' => &$Rows, - 'Attributes' => &$Attributes - )); - - if ($Buttons === true) $this->buttons(); - } - - /** - * Outputs the divs required for previewing the AJAX content - * Will only output once - */ - public function preview () - { - if (!$this->preview) - View::parse('generic/textarea/preview.phtml', array('ID' => $this->id)); - $this->preview = true; - } - - /** - * Outputs the preview and edit buttons - * Can be called many times to place buttons in different areas - */ - public function buttons () - { - View::parse('generic/textarea/buttons.phtml', array('ID' => $this->id)); - } - - /** - * Returns the textarea's numeric ID. - */ - public function getID () - { - return $this->id; - } + + * @return void + */ + static public function JavaScript ($all = true) + { + if (self::$Textareas === 0) return; + if (self::$Exectuted === false && $all) + View::parse('generic/textarea/script.phtml'); + + self::$Exectuted = true; + self::iterator(); + } + + /** + * This iterator generates JavaScript to initialize each JavaScript + * TextareaPreview object. + * + * It will generate a numeric or custom ID related to the textarea. + * @static + * @return void + */ + static private function iterator () + { + $script = array(); + for($i = 0; $i < self::$Textareas; $i++) { + if (isset(self::$_ID[$i]) && is_string(self::$_ID[$i])) { + $a = sprintf('%d, "%s"', $i, self::$_ID[$i]); + } else { + $a = $i; + } + $script[] = sprintf('[%s]', $a); + } + if (!empty($script)) + View::parse('generic/textarea/script_factory.phtml', + array('script' => join(', ', $script))); + } +} + +/** + * Textarea Preview Class + * + * This class generates a textarea that works with the JS preview script. + * + * Templates found in design/views/generic/textarea + * + * @example
buttons(); // output buttons
+ *
+ *  $text->preview(); // output preview div
+ *
+ * // Create a textarea with custom preview wrapper around a table
+ * // the table will be (in)visible depending on the toggle
+ * $text = new TEXTAREA_PREVIEW('body', '', '', 30, 10, false, false);
+ * $id = $text->getID();
+ *
+ * // some template
+ * 
+ * + * + * + * + *
+ *
+ *
+ *
+ *
+ */ +class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER +{ + /** + * @var int Unique ID + */ + private $id; + + /** + * Flag for preview output + * @var bool $preview + */ + private $preview = false; + + /** + * This method creates a textarea + * + * @param string $Name name attribute + * @param string $ID id attribute + * @param string $Value default text attribute + * @param string $Cols cols attribute + * @param string $Rows rows attribute + * @param bool $Preview add the preview divs near the textarea + * @param bool $Buttons add the edit/preview buttons near the textarea + * + * If false for either, use the appropriate methods to add the those + * elements elsewhere. Alternatively, use getID to create your own. + * + * @param array $ExtraAttributes array of attribute="value" + */ + public function __construct ($Name, $ID = '', $Value='', $Cols=50, $Rows=10, + $Preview = true, $Buttons = true, array $ExtraAttributes = array() + ) { + $this->id = parent::$Textareas; + parent::$Textareas += 1; + array_push(parent::$_ID, $ID); + + if (empty($ID)) $ID = 'quickpost_' . $this->id; + + if (!empty($ExtraAttributes)) + $Attributes = ' ' . implode(' ', $ExtraAttributes); + else + $Attributes = ''; + + if ($Preview === true) $this->preview(); + + View::parse('generic/textarea/textarea.phtml', array( + 'ID' => $ID, + 'NID' => $this->id, + 'Name' => &$Name, + 'Value' => &$Value, + 'Cols' => &$Cols, + 'Rows' => &$Rows, + 'Attributes' => &$Attributes + )); + + if ($Buttons === true) $this->buttons(); + } + + /** + * Outputs the divs required for previewing the AJAX content + * Will only output once + */ + public function preview () + { + if (!$this->preview) + View::parse('generic/textarea/preview.phtml', array('ID' => $this->id)); + $this->preview = true; + } + + /** + * Outputs the preview and edit buttons + * Can be called many times to place buttons in different areas + */ + public function buttons () + { + View::parse('generic/textarea/buttons.phtml', array('ID' => $this->id)); + } + + /** + * Returns the textarea's numeric ID. + */ + public function getID () + { + return $this->id; + } } \ No newline at end of file diff --git a/classes/class_torrents.php b/classes/class_torrents.php index 2b522f14..66e0a841 100644 --- a/classes/class_torrents.php +++ b/classes/class_torrents.php @@ -615,7 +615,8 @@ public static function has_snatched($TorrentID) { $Cache->cache_value('users_snatched_'.$UserID.'_'.$i, $SnatchedTorrents[$i], 0); } } - $Cache->cache_value('users_snatched_'.$UserID.'_lastupdate', $CurTime, 21600); + $Cache->cache_value('users_snatched_'.$UserID.'_lastupdate', $CurTime, 0); + $LastUpdate = $CurTime; } } return isset($CurSnatchedTorrents[$TorrentID]); diff --git a/design/views/generic/textarea/buttons.phtml b/design/views/generic/textarea/buttons.phtml index 907e70d3..ca3cd968 100644 --- a/design/views/generic/textarea/buttons.phtml +++ b/design/views/generic/textarea/buttons.phtml @@ -1,3 +1,3 @@ - - - + + + diff --git a/design/views/generic/textarea/preview.phtml b/design/views/generic/textarea/preview.phtml index 2af2d71d..2ba5e703 100644 --- a/design/views/generic/textarea/preview.phtml +++ b/design/views/generic/textarea/preview.phtml @@ -1,4 +1,4 @@ - - + + diff --git a/design/views/generic/textarea/script_factory.phtml b/design/views/generic/textarea/script_factory.phtml index a1d2f0ee..d948afe0 100644 --- a/design/views/generic/textarea/script_factory.phtml +++ b/design/views/generic/textarea/script_factory.phtml @@ -1,4 +1,4 @@ - - + + diff --git a/design/views/generic/textarea/textarea.phtml b/design/views/generic/textarea/textarea.phtml index a49787ee..c8959969 100644 --- a/design/views/generic/textarea/textarea.phtml +++ b/design/views/generic/textarea/textarea.phtml @@ -1,4 +1,4 @@ - -
- -
+ +
+ +
diff --git a/gazelle.sql b/gazelle.sql index ac7d8189..fa7ea7c2 100644 --- a/gazelle.sql +++ b/gazelle.sql @@ -1614,7 +1614,10 @@ CREATE TABLE `xbt_snatched` ( KEY `tstamp` (`tstamp`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -; +CREATE DEFINER=`root`@`localhost` FUNCTION `binomial_ci`(p int, n int) RETURNS float + DETERMINISTIC + SQL SECURITY INVOKER +RETURN IF(n = 0,0.0,((p + 1.9208) / n - 1.96 * SQRT((p * (n-p)) / n + 0.9604) / n) / (1 + 3.8416 / n)); SET FOREIGN_KEY_CHECKS = 1; diff --git a/sections/ajax/takevote.php b/sections/ajax/takevote.php index 60401909..e6b4ccdf 100644 --- a/sections/ajax/takevote.php +++ b/sections/ajax/takevote.php @@ -8,7 +8,7 @@ } // What groups has this guy voted? -$UserVotes = $Cache->get_value('voted_albums_'.$LoggedUser['ID']); +$UserVotes = $Cache->get_value('voted_albums_'.$LoggedUser['ID'], true); if ($UserVotes === FALSE) { $DB->query('SELECT GroupID, Type FROM users_votes WHERE UserID='.$LoggedUser['ID']); $UserVotes = $DB->to_array('GroupID', MYSQL_ASSOC, false); @@ -16,7 +16,7 @@ } // What are the votes for this group? -$GroupVotes = $Cache->get_value('votes_'.$GroupID); +$GroupVotes = $Cache->get_value('votes_'.$GroupID, true); if ($GroupVotes === FALSE) { $DB->query("SELECT Ups AS Ups, Total AS Total FROM torrents_votes WHERE GroupID=$GroupID"); if ($DB->record_count() == 0) { @@ -59,7 +59,7 @@ $DB->query("INSERT INTO torrents_votes (GroupID, Total, Ups, Score) VALUES ($GroupID, 1, ".($Type=='Up'?1:0).", 0) ON DUPLICATE KEY UPDATE Total = Total + 1, - Score = IFNULL(binomial_ci(".$GroupVotes['Ups'].",". $GroupVotes['Total']."),0)". + Score = IFNULL(binomial_ci(Ups".($Type=='Up'?'+1':'').",Total),0)". ($Type=='Up'?', Ups = Ups+1':'')); $UserVotes[$GroupID] = array('GroupID' => $GroupID, 'Type' => $Type); @@ -71,7 +71,7 @@ // First update this album's paired votes. If this keys is magically not set, // our life just got a bit easier. We're only tracking paired votes on upvotes. if ($Type == 'Up') { - $VotePairs = $Cache->get_value('vote_pairs_'.$GroupID); + $VotePairs = $Cache->get_value('vote_pairs_'.$GroupID, true); if ($VotePairs !== FALSE) { foreach ($UserVotes as $Vote) { if ($Vote['GroupID'] == $GroupID) { @@ -100,8 +100,11 @@ // We're only track paired votes on upvotes continue; } + if ($VGID == $GroupID) { + continue; + } // Again, if the cache key is not set, move along - $VotePairs = $Cache->get_value('vote_pairs_'.$VGID); + $VotePairs = $Cache->get_value('vote_pairs_'.$VGID, true); if ($VotePairs !== FALSE) { // Go through all of the other albums paired to this one, and update // this group's entry in their vote_pairs keys @@ -142,14 +145,14 @@ $Cache->cache_value('votes_'.$GroupID, $GroupVotes); $DB->query("UPDATE torrents_votes SET Total = GREATEST(0, Total - 1), - Score = IFNULL(binomial_ci(".$GroupVotes['Ups'].",".$GroupVotes['Total']."),0)". + Score = IFNULL(binomial_ci(GREATEST(0,Ups".($Type=='Up'?'-1':'')."),GREATEST(0, Total)),0)". ($Type=='Up'?', Ups = GREATEST(0, Ups - 1)':'')." WHERE GroupID=$GroupID"); // Update paired cache keys // First update this album's paired votes. If this keys is magically not set, // our life just got a bit easier. We're only tracking paired votes on upvotes. if ($Type == 'Up') { - $VotePairs = $Cache->get_value('vote_pairs_'.$GroupID); + $VotePairs = $Cache->get_value('vote_pairs_'.$GroupID, true); if ($VotePairs !== FALSE) { foreach ($UserVotes as $Vote) { if (isset($VotePairs[$Vote['GroupID']])) { @@ -178,8 +181,11 @@ // We're only track paired votes on upvotes continue; } + if ($VGID == $GroupID) { + continue; + } // Again, if the cache key is not set, move along - $VotePairs = $Cache->get_value('vote_pairs_'.$VGID); + $VotePairs = $Cache->get_value('vote_pairs_'.$VGID, true); if ($VotePairs !== FALSE) { if (isset($VotePairs[$GroupID])) { if ($VotePairs[$GroupID]['Total'] == 0) { diff --git a/sections/artist/artist.php b/sections/artist/artist.php index 333cfa37..3bd1f0e3 100644 --- a/sections/artist/artist.php +++ b/sections/artist/artist.php @@ -420,7 +420,7 @@ function compare($X, $Y){ ?> - + - +
Search File Lists
- - + + -