Empty commit

This commit is contained in:
Git 2013-02-11 08:00:34 +00:00
parent 35473bd15d
commit 91657d8624
17 changed files with 142 additions and 64 deletions

View File

@ -1,5 +1,7 @@
<?
class Torrents {
const FilelistDelim = 0xF7; // Hex for &divide; 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(' ', '&nbsp;', 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.

View File

@ -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.',

View File

@ -67,7 +67,7 @@
$TorrentTags=explode(' ',$TorrentTags);
foreach ($TorrentTags as $TagKey => $TagName) {
$TagName = str_replace('_','.',$TagName);
$TagList[]='<a href="torrents.php?searchtags='.$TagName.'">'.$TagName.'</a>';
$TagList[]='<a href="torrents.php?taglist='.$TagName.'">'.$TagName.'</a>';
}
$PrimaryTag = $TorrentTags[0];
$TagList = implode(', ', $TagList);

View File

@ -67,7 +67,7 @@
$TorrentTags=explode(' ',$TorrentTags);
foreach ($TorrentTags as $TagKey => $TagName) {
$TagName = str_replace('_','.',$TagName);
$TagList[]='<a href="torrents.php?searchtags='.$TagName.'">'.$TagName.'</a>';
$TagList[]='<a href="torrents.php?taglist='.$TagName.'">'.$TagName.'</a>';
}
$PrimaryTag = $TorrentTags[0];
$TagList = implode(', ', $TagList);

View File

@ -49,7 +49,7 @@
$TorrentTags=explode(' ',$TorrentTags);
foreach ($TorrentTags as $TagKey => $TagName) {
$TagName = str_replace('_','.',$TagName);
$TagList[]='<a href="torrents.php?searchtags='.$TagName.'">'.$TagName.'</a>';
$TagList[]='<a href="torrents.php?taglist='.$TagName.'">'.$TagName.'</a>';
}
$PrimaryTag = $TorrentTags[0];
$TagList = implode(', ', $TagList);

View File

@ -68,7 +68,7 @@
$TorrentTags=explode(' ',$TorrentTags);
foreach ($TorrentTags as $TagKey => $TagName) {
$TagName = str_replace('_','.',$TagName);
$TagList[]='<a href="torrents.php?searchtags='.$TagName.'">'.$TagName.'</a>';
$TagList[]='<a href="torrents.php?taglist='.$TagName.'">'.$TagName.'</a>';
}
$PrimaryTag = $TorrentTags[0];
$TagList = implode(', ', $TagList);

View File

@ -94,7 +94,7 @@
$TorrentTags=explode(' ',$TorrentTags);
foreach ($TorrentTags as $TagKey => $TagName) {
$TagName = str_replace('_','.',$TagName);
$TagList[]='<a href="torrents.php?searchtags='.$TagName.'">'.$TagName.'</a>';
$TagList[]='<a href="torrents.php?taglist='.$TagName.'">'.$TagName.'</a>';
}
$PrimaryTag = $TorrentTags[0];
$TagList = implode(', ', $TagList);

View File

@ -225,10 +225,12 @@
<?
$TopicLength=75-(2*count($PageLinks));
unset($PageLinks);
$Title = display_str($Title);
$DisplayTitle = $Title;
?>
<strong>
<a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>" title="<?=display_str($Title)?>"><?=display_str(Format::cut_string($Title, $TopicLength)) ?></a>
<a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>" title="<?=$Title?>"><?=Format::cut_string($DisplayTitle, $TopicLength) ?></a>
</strong>
<?=$PagesText?>
</span>

View File

@ -452,10 +452,37 @@ function filelist($Str) {
$CanEdit = (check_perms('torrents_edit') || (($UserID == $LoggedUser['ID'] && !$LoggedUser['DisableWiki']) && !($Remastered && !$RemasterYear)));
$FileList = str_replace(array('_','-'), ' ', $FileList);
$FileList = str_replace('|||','<tr><td>',display_str($FileList));
$FileList = preg_replace_callback('/\{\{\{([^\{]*)\}\}\}/i','filelist',$FileList);
$FileList = '<table class="filelist_table" style="overflow-x:auto;"><tr class="colhead_dark"><td><div style="float: left; display: block; font-weight: bold;">File Name'.(check_perms('users_mod') ? ' <a href="torrents.php?action=regen_filelist&amp;torrentid='.$TorrentID.'" class="brackets">Regenerate</a>' : '').'</div><div style="float:right; display:block;">'.(empty($FilePath) ? '' : '/'.$FilePath.'/' ).'</div></td><td><strong>Size</strong></td></tr><tr><td>'.$FileList."</table>";
$RegenLink = check_perms('users_mod') ? ' <a href="torrents.php?action=regen_filelist&amp;torrentid='.$TorrentID.'" class="brackets">Regenerate</a>' : '';
$FileTable = '
<table class="filelist_table">
<tr class="colhead_dark"><td>
<div class="filelist_title" style="float: left;">File Name' . $RegenLink . '</div>
<div class="filelist_path" style="float: right;">' . ($FilePath ? "/$FilePath/" : '') . '</div>
</td><td>
<strong>Size</strong>
</td></tr>';
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(' ', '&nbsp;', substr($Name, 0, $Spaces)) . substr($Name, $Spaces);
}
$FileSize = substr($File, $NameEnd+3, -3);
$FileTable .= sprintf("\n<tr><td>%s</td><td>%s</td></tr>",
$Name, Format::get_size($FileSize));
}
} else {
$FileListSplit = explode("\n", $FileList);
foreach ($FileListSplit as $File) {
$FileInfo = Torrents::filelist_get_file($File);
$FileTable .= sprintf("\n<tr><td>%s</td><td>%s</td></tr>",
$FileInfo['name'], Format::get_size($FileInfo['size']));
}
}
$FileTable .= '
</table>';
$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) {
<div id="peers_<?=$TorrentID?>" class="hidden"></div>
<div id="downloads_<?=$TorrentID?>" class="hidden"></div>
<div id="snatches_<?=$TorrentID?>" class="hidden"></div>
<div id="files_<?=$TorrentID?>" class="hidden"><?=$FileList?></div>
<div id="files_<?=$TorrentID?>" class="hidden"><?=$FileTable?></div>
<? if($Reported) { ?>
<div id="reported_<?=$TorrentID?>" class="hidden"><?=$ReportInfo?></div>
<? } ?>

View File

@ -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);

View File

@ -187,9 +187,9 @@ function header_link($SortKey, $DefaultWay = "desc") {
: 'unknown filter['.$FilterID.']'?>
</h3>
</div>
<div class="notify_filter_links">
<a href="javascript:GroupClear($('#notificationform_<?=$FilterID?>').raw())" class="brackets">Clear selected in filter</a>&nbsp;&nbsp;&nbsp;
<a href="torrents.php?action=notify_clear_filter&amp;filterid=<?=$FilterID?>&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Clear all old in filter</a>&nbsp;&nbsp;&nbsp;
<div class="linkbox notify_filter_links">
<a href="javascript:GroupClear($('#notificationform_<?=$FilterID?>').raw())" class="brackets">Clear selected in filter</a>
<a href="torrents.php?action=notify_clear_filter&amp;filterid=<?=$FilterID?>&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Clear all old in filter</a>
<a href="torrents.php?action=notify_catchup_filter&amp;filterid=<?=$FilterID?>&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Mark all in filter as read</a>
</div>
<form class="manage_form" name="torrents" id="notificationform_<?=$FilterID?>" action="">

View File

@ -387,9 +387,8 @@
if(mb_strlen($Name, 'UTF-8') + mb_strlen($DirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) {
$TooLongPaths[] = $Name;
}
// Add file and size to array
$TmpFileList[] = $Name .'{{{'.$Size.'}}}'; // Name {{{Size}}}
// Add file info to array
$TmpFileList[] = Torrents::filelist_format_file($File);
}
if(count($TooLongPaths)!=0) {
@ -402,8 +401,7 @@
// To be stored in the database
$FilePath = isset($Tor->Val['info']->Val['files']) ? db_string(Format::make_utf8($DirName)) : "";
// Name {{{Size}}}|||Name {{{Size}}}|||Name {{{Size}}}|||Name {{{Size}}}
$FileString = "'".db_string(Format::make_utf8(implode('|||', $TmpFileList)))."'";
$FileString = db_string(implode("\n", $TmpFileList));
// Number of files described in torrent
$NumFiles = count($FileList);
@ -643,7 +641,7 @@
VALUES
(".$GroupID.", ".$LoggedUser['ID'].", ".$T['Media'].", ".$T['Format'].", ".$T['Encoding'].",
".$T['Remastered'].", ".$T['RemasterYear'].", ".$T['RemasterTitle'].", ".$T['RemasterRecordLabel'].", ".$T['RemasterCatalogueNumber'].",
".$T['Scene'].", ".$HasLog.", ".$HasCue.", '".db_string($InfoHash)."', ".$NumFiles.", ".$FileString.", '".$FilePath."', ".$TotalSize.", '".sqltime()."',
".$T['Scene'].", ".$HasLog.", ".$HasCue.", '".db_string($InfoHash)."', ".$NumFiles.", '".$FileString."', '".$FilePath."', ".$TotalSize.", '".sqltime()."',
".$T['TorrentDescription'].", '".(($HasLog == "'1'") ? $LogScoreAverage : 0)."', '".$T['FreeLeech']."', '".$T['FreeLeechType']."')");
$Cache->increment('stats_torrent_count');

View File

@ -10,7 +10,7 @@
define('USERS_PER_PAGE', 30);
if(isset($_GET['username'])){
if (isset($_GET['username'])) {
$_GET['username'] = trim($_GET['username']);
// form submitted

View File

@ -43,7 +43,7 @@
<div class="thin">
<div class="header">
<h2><?=$Title?></h2>
<div class="linkbox box">
<div class="linkbox">
<a href="wiki.php?action=create" class="brackets">Create</a>
<a href="wiki.php?action=edit&amp;id=<?=$ArticleID?>" class="brackets">Contribute</a>
<a href="wiki.php?action=revisions&amp;id=<?=$ArticleID?>" class="brackets">History</a>

View File

@ -102,12 +102,7 @@ source torrents : torrents_base {
media, format, encoding, remyear remasteryear, \
remtitle remastertitle, remrlabel remasterrecordlabel, \
remcnumber remastercataloguenumber, \
replace(replace(replace(replace(filelist, \
'.flac', ' .flac'), \
'.mp3', ' .mp3'), \
'|||', '\n '), \
'_', ' ') \
filelist \
replace(filelist, '_', ' ') filelist \
from sphinx_t t \
join sphinx_tg g on t.gid=g.id
@ -125,13 +120,8 @@ index torrents {
morphology = none
min_word_len = 2
charset_type = utf-8
# Note: \n cannot be used as phrase boundary character in Sphinx 2.0.4 and later.
# This makes searching the file lists inaccurate since there's
# no way to ensure that all keywords match the same file.
# If an older version of Sphinx is used, uncomment the following two lines.
# phrase_boundary = U+000A
# phrase_boundary_step = 20
phrase_boundary = U+F7 # This needs to the the same as the file delimiter in classes/class_torrents.php
phrase_boundary_step = 50
charset_table = \
U+00C0->a, U+00C1->a, U+00C2->a, U+00C3->a, U+00C4->a, U+00C5->a, U+00E0->a, U+00E1->a, U+00E2->a, \

View File

@ -729,6 +729,10 @@ body#index #recommended #vanityhouse {
text-align: center;
}
.linkbox.notify_filter_links {
margin-bottom: 5px;
}
.head a {
color: #3e3e3e;
}
@ -1261,6 +1265,10 @@ form.manage_form[name=friends] .left input[type=submit] {
margin-top: 10px;
}
.torrent_table .filelist_table {
width: 100%;
}
/* Fix for artist.php sidebar layout */
[class="box box_search"] #filelist, [class="box box_addartists box_addartists_similar"] #artistsimilar {
width: 150px;