From 91657d8624c8564ea2102e60abf38d877badde95 Mon Sep 17 00:00:00 2001 From: Git Date: Mon, 11 Feb 2013 08:00:34 +0000 Subject: [PATCH] Empty commit --- classes/class_torrents.php | 79 +++++++++++++++++++++++++++++-- classes/permissions_form.php | 1 + sections/better/files.php | 2 +- sections/better/folders.php | 2 +- sections/better/single.php | 2 +- sections/better/tags.php | 2 +- sections/better/upload.php | 2 +- sections/forums/forum.php | 4 +- sections/login/index.php | 2 +- sections/torrents/details.php | 39 ++++++++++++--- sections/torrents/index.php | 25 +--------- sections/torrents/notify.php | 8 ++-- sections/upload/upload_handle.php | 10 ++-- sections/user/search.php | 2 +- sections/wiki/article.php | 2 +- sphinx.conf | 16 ++----- static/styles/mono/style.css | 8 ++++ 17 files changed, 142 insertions(+), 64 deletions(-) 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 @@ 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 @@ - + 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('|||','',display_str($FileList)); - $FileList = preg_replace_callback('/\{\{\{([^\{]*)\}\}\}/i','filelist',$FileList); - $FileList = '
File Name'.(check_perms('users_mod') ? ' Regenerate' : '').'
'.(empty($FilePath) ? '' : '/'.$FilePath.'/' ).'
Size
'.$FileList."
"; + + $RegenLink = check_perms('users_mod') ? ' Regenerate' : ''; + $FileTable = ' + + '; + if (substr($FileList, -3) == '}}}') { // Old style + $FileListSplit = explode('|||', $FileList); + foreach ($FileListSplit as $File) { + $NameEnd = strrpos($File, '{{{'); + $Name = substr($File, 0, $NameEnd); + if ($Spaces = strspn($Name, ' ')) { + $Name = str_replace(' ', ' ', substr($Name, 0, $Spaces)) . substr($Name, $Spaces); + } + $FileSize = substr($File, $NameEnd+3, -3); + $FileTable .= sprintf("\n", + $Name, Format::get_size($FileSize)); + } + } else { + $FileListSplit = explode("\n", $FileList); + foreach ($FileListSplit as $File) { + $FileInfo = Torrents::filelist_get_file($File); + $FileTable .= sprintf("\n", + $FileInfo['name'], Format::get_size($FileInfo['size'])); + } + } + $FileTable .= ' +
+
File Name' . $RegenLink . '
+
' . ($FilePath ? "/$FilePath/" : '') . '
+
+ Size +
%s%s
%s%s
'; $ExtraInfo=''; // String that contains information on the torrent (e.g. format and encoding) $AddExtra=''; // Separator between torrent properties @@ -592,7 +619,7 @@ function filelist($Str) { - + diff --git a/sections/torrents/index.php b/sections/torrents/index.php index 5859102f..9d22ac80 100644 --- a/sections/torrents/index.php +++ b/sections/torrents/index.php @@ -312,29 +312,8 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) { break; case 'regen_filelist' : if(check_perms('users_mod') && !empty($_GET['torrentid']) && is_number($_GET['torrentid'])) { - $TorrentID = $_GET['torrentid']; - $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) { - list($Size, $Name) = $File; - $TmpFileList []= $Name .'{{{'.$Size.'}}}'; // Name {{{Size}}} - } - $FilePath = isset($Tor->Val['info']->Val['files']) ? Format::make_utf8($Tor->get_name()) : ""; - $FileString = Format::make_utf8(implode('|||', $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); - } - header('Location: torrents.php?torrentid='.$TorrentID); + Torrents::regenerate_filelist($_GET['torrentid']); + header('Location: torrents.php?torrentid='.$_GET['torrentid']); die(); } else { error(403); diff --git a/sections/torrents/notify.php b/sections/torrents/notify.php index c46c5a8b..ee9ee02a 100644 --- a/sections/torrents/notify.php +++ b/sections/torrents/notify.php @@ -187,9 +187,9 @@ function header_link($SortKey, $DefaultWay = "desc") { : 'unknown filter['.$FilterID.']'?> -