diff --git a/classes/class_torrents.php b/classes/class_torrents.php index c5da7c28..83958217 100644 --- a/classes/class_torrents.php +++ b/classes/class_torrents.php @@ -1,5 +1,7 @@ class Torrents { + const FilelistDelim = 0xF7; // Hex for ÷ Must be the same as phrase_boundary in sphinx.conf! + /* * 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. @@ -391,9 +393,10 @@ public static function update_hash($GroupID) { Leechers, LogScore, CAST(Scene AS CHAR), CAST(HasLog AS CHAR), CAST(HasCue AS CHAR), CAST(FreeTorrent AS CHAR), Media, Format, Encoding, RemasterYear, RemasterTitle, RemasterRecordLabel, RemasterCatalogueNumber, - REPLACE(REPLACE(REPLACE(REPLACE(FileList, - '.flac', ' .flac'), - '.mp3', ' .mp3'), + REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(FileList, + '.flac{', ' .flac{'), + '.mp3{', ' .mp3{'), + '\n', ' \n'), '|||', '\n '), '_', ' ') AS FileList, $VoteScore, '".db_string($ArtistName)."' @@ -428,6 +431,76 @@ public static function update_hash($GroupID) { $Cache->delete_value('groups_artists_'.$GroupID); } + /** + * Regenerate a torrent's filelist from its meta data, + * update the database record and clear relevant cache keys + * + * @param int $TorrentID + */ + public static function regenerate_filelist($TorrentID) { + global $DB, $Cache; + $DB->query("SELECT tg.ID, + tf.File + FROM torrents_files AS tf + JOIN torrents AS t ON t.ID=tf.TorrentID + JOIN torrents_group AS tg ON tg.ID=t.GroupID + WHERE tf.TorrentID = ".$TorrentID); + if($DB->record_count() > 0) { + require(SERVER_ROOT.'/classes/class_torrent.php'); + list($GroupID, $Contents) = $DB->next_record(MYSQLI_NUM, false); + $Contents = unserialize(base64_decode($Contents)); + $Tor = new TORRENT($Contents, true); + list($TotalSize, $FileList) = $Tor->file_list(); + foreach($FileList as $File) { + $TmpFileList[] = self::filelist_format_file($File); + } + $FilePath = isset($Tor->Val['info']->Val['files']) ? Format::make_utf8($Tor->get_name()) : ""; + $FileString = Format::make_utf8(implode("\n", $TmpFileList)); + $DB->query("UPDATE torrents SET Size = ".$TotalSize.", FilePath = '".db_string($FilePath)."', FileList = '".db_string($FileString)."' WHERE ID = ".$TorrentID); + $Cache->delete_value('torrents_details_'.$GroupID); + } + } + + /** + * Return UTF-8 encoded string to use as file delimiter in torrent file lists + */ + public static function filelist_delim() { + static $FilelistDelimUTF8; + if (isset($FilelistDelimUTF8)) { + return $FilelistDelimUTF8; + } + return $FilelistDelimUTF8 = utf8_encode(chr(self::FilelistDelim)); + } + + /** + * Create a string that contains file info in a format that's easy to use for Sphinx + * + * @param array $File (File size, File name) + * @return formatted string with the format .EXT sSIZEs NAME DELIMITER + */ + public static function filelist_format_file($File) { + list($Size, $Name) = $File; + $Name = Format::make_utf8($Name); + $ExtPos = strrpos($Name, '.'); + $Ext = $ExtPos ? substr($Name, $ExtPos) : ''; + return sprintf("%s s%ds %s %s", $Ext, $Size, $Name, self::filelist_delim()); + } + + /** + * Translate a formatted file info string into a more useful array structure + * + * @param string $File string with the format .EXT sSIZEs NAME DELIMITER + * @return file info array with the keys 'ext', 'size' and 'name' + */ + public static function filelist_get_file($File) { + // Need this hack because filelists are always display_str()ed + $DelimLen = strlen(display_str(self::filelist_delim())) + 1; + list($FileExt, $Size, $Name) = explode(' ', $File, 3); + if ($Spaces = strspn($Name, ' ')) { + $Name = str_replace(' ', ' ', substr($Name, 0, $Spaces)) . substr($Name, $Spaces); + } + return array('ext' => $FileExt, 'size' => substr($Size, 1, -1), 'name' => substr($Name, 0, -$DelimLen)); + } /** * Format the information about a torrent. diff --git a/classes/permissions_form.php b/classes/permissions_form.php index e50872ef..4cd95ec2 100644 --- a/classes/permissions_form.php +++ b/classes/permissions_form.php @@ -72,6 +72,7 @@ 'users_view_keys' => 'Can view passkeys.', 'users_view_ips' => 'Can view IP addresses.', 'users_view_email' => 'Can view email addresses.', + 'users_override_paranoia' => 'Can override paranoia.', 'users_logout' => 'Can log users out (old?).', 'users_make_invisible' => 'Can make users invisible.', diff --git a/sections/better/files.php b/sections/better/files.php index 32f61362..f26a6c37 100644 --- a/sections/better/files.php +++ b/sections/better/files.php @@ -67,7 +67,7 @@ $TorrentTags=explode(' ',$TorrentTags); foreach ($TorrentTags as $TagKey => $TagName) { $TagName = str_replace('_','.',$TagName); - $TagList[]=''.$TagName.''; + $TagList[]=''.$TagName.''; } $PrimaryTag = $TorrentTags[0]; $TagList = implode(', ', $TagList); diff --git a/sections/better/folders.php b/sections/better/folders.php index ee4f5e6c..c6c88cf6 100644 --- a/sections/better/folders.php +++ b/sections/better/folders.php @@ -67,7 +67,7 @@ $TorrentTags=explode(' ',$TorrentTags); foreach ($TorrentTags as $TagKey => $TagName) { $TagName = str_replace('_','.',$TagName); - $TagList[]=''.$TagName.''; + $TagList[]=''.$TagName.''; } $PrimaryTag = $TorrentTags[0]; $TagList = implode(', ', $TagList); diff --git a/sections/better/single.php b/sections/better/single.php index 38613931..59f34f1d 100644 --- a/sections/better/single.php +++ b/sections/better/single.php @@ -49,7 +49,7 @@ $TorrentTags=explode(' ',$TorrentTags); foreach ($TorrentTags as $TagKey => $TagName) { $TagName = str_replace('_','.',$TagName); - $TagList[]=''.$TagName.''; + $TagList[]=''.$TagName.''; } $PrimaryTag = $TorrentTags[0]; $TagList = implode(', ', $TagList); diff --git a/sections/better/tags.php b/sections/better/tags.php index a00b660f..3e4f2458 100644 --- a/sections/better/tags.php +++ b/sections/better/tags.php @@ -68,7 +68,7 @@ $TorrentTags=explode(' ',$TorrentTags); foreach ($TorrentTags as $TagKey => $TagName) { $TagName = str_replace('_','.',$TagName); - $TagList[]=''.$TagName.''; + $TagList[]=''.$TagName.''; } $PrimaryTag = $TorrentTags[0]; $TagList = implode(', ', $TagList); diff --git a/sections/better/upload.php b/sections/better/upload.php index f4c498f5..14609c2c 100644 --- a/sections/better/upload.php +++ b/sections/better/upload.php @@ -94,7 +94,7 @@ $TorrentTags=explode(' ',$TorrentTags); foreach ($TorrentTags as $TagKey => $TagName) { $TagName = str_replace('_','.',$TagName); - $TagList[]=''.$TagName.''; + $TagList[]=''.$TagName.''; } $PrimaryTag = $TorrentTags[0]; $TagList = implode(', ', $TagList); diff --git a/sections/forums/forum.php b/sections/forums/forum.php index a7a3f979..63b4ce0c 100644 --- a/sections/forums/forum.php +++ b/sections/forums/forum.php @@ -225,10 +225,12 @@ $TopicLength=75-(2*count($PageLinks)); unset($PageLinks); + $Title = display_str($Title); + $DisplayTitle = $Title; ?> - =display_str(Format::cut_string($Title, $TopicLength)) ?> + =Format::cut_string($DisplayTitle, $TopicLength) ?> =$PagesText?> diff --git a/sections/login/index.php b/sections/login/index.php index 1df95f5f..0573641d 100644 --- a/sections/login/index.php +++ b/sections/login/index.php @@ -292,7 +292,7 @@ function log_attempt($UserID) { $Sql .= " WHERE ID='".db_string($UserID)."'"; $DB->query($Sql); - + if (!empty($_COOKIE['redirect'])) { $URL = $_COOKIE['redirect']; setcookie('redirect','',time()-60*60*24,'/','',false); diff --git a/sections/torrents/details.php b/sections/torrents/details.php index 9c161905..0d21ead9 100644 --- a/sections/torrents/details.php +++ b/sections/torrents/details.php @@ -451,11 +451,38 @@ function filelist($Str) { } $CanEdit = (check_perms('torrents_edit') || (($UserID == $LoggedUser['ID'] && !$LoggedUser['DisableWiki']) && !($Remastered && !$RemasterYear))); - - $FileList = str_replace(array('_','-'), ' ', $FileList); - $FileList = str_replace('|||','
File Name'.(check_perms('users_mod') ? ' Regenerate' : '').' '.(empty($FilePath) ? '' : '/'.$FilePath.'/' ).' | Size |
'.$FileList." |
+ File Name' . $RegenLink . '
+ ' . ($FilePath ? "/$FilePath/" : '') . '
+ | + Size + |
%s | %s |
%s | %s |