Переменные picid0 -обложка, screen[0-2] - скрины, папка для файлов torpic в корне трекера (права не забываем), torpic/cache/ папка для thumbnail (уменьшенные копии больших картинок)
В базе соответственно создаем в torrents поля picid0, screen0, screen1, screen2 - varchar(32), default = 0
От хранения файлов на сервере я отказался (Nafania в этом вопросе прав), чего и вам желаю, поэтому это хоть и рабочая версия но все же требует доработки в плане php скриптов при загрузке (upload)
Скриншоты располагаются под спойлером, скачиваются (открываются) только после открытия спойлера. При отсутсвии скринов, спойлер не отображается.
include/details/edit.php
Перед (36 строка в оригинальном svn, далее по тексту просто номер строки)
- Код: Выделить всё
if ( $nfoaction == 'update' ) {
Добавляем (решено было использовать отдельный файл, проще модифицировать)
- Код: Выделить всё
require_once ($root_path . 'include/details/edit_torpic.php');
Содержимое include/details/edit_torpic.php
- Код: Выделить всё
<?php
$torpic_action = request_var('torpic_action', '');
if ( $torpic_action == 'update' ) {
if ( isset($_FILES['torpic']) && !empty($_FILES['torpic']['name']))
{
if ( $row['picid0'] ) {
@unlink($root_path . 'torpic/' . $row['picid0']);
@unlink($root_path . 'torpic/cache/' . $row['picid0']);
$torpic = check_upload_image($_FILES['torpic'], 'torpic/', 512000, 3000, 2000, $row['fid']);
$updateset['picid0'] = $torpic['filename'];
}
}
}
if ( $torpic_action == 'remove' ) {
if ( $row['picid0'] ) {
@unlink($root_path . 'torpic/' . $row['picid0']);
@unlink($root_path . 'torpic/cache/' . $row['picid0']);
$updateset['picid0'] = '0';
}
}
for ( $x=0; $x < 3; $x++ ) {
$img_action = request_var('screen_action' . $x, '');
if ( $img_action == 'update' ) {
if ( isset($_FILES[screen.$x]) && !empty($_FILES[screen.$x]['name']))
{
if ( $row['screen' . $x] ) {
@unlink($root_path . 'torpic/' . $row['screen' . $x]);
@unlink($root_path . 'torpic/cache/' . $row['screen' . $x]);
$screen = check_upload_image($_FILES[screen.$x], 'torpic/', 512000, 3000, 2000, $row['fid'] . '_' . $x);
$updateset['screen' . $x] = $screen['filename'];
}
}
}
if ( $img_action == 'remove' ) {
if ( $row['screen' . $x] ) {
@unlink($root_path . 'torpic/' . $row['screen' . $x]);
@unlink($root_path . 'torpic/cache/' . $row['screen' . $x]);
$updateset['screen' . $x] = '0';
}
}
}
?>
templates/Ваш темплейт(оригинально для main)/details_edit.html
После (23й строки)
- Код: Выделить всё
<tr>
<td><label for="nfo">{L_NFO_FILE}</label></td>
<td><input type="radio" name="nfoaction" id="nfoaction" value="keep" checked="checked" /> {L_KEEP_CURRENT} <input type="radio" name="nfoaction" id="nfoaction" value="update" /> {L_REFRESH} <input type="radio" name="nfoaction" id="nfoaction" value="remove" /> {L_DELETE}<br /><input type="file" name="nfo" id="nfo" size="80" /></td>
</tr>
Вставить (Подгонялось под main, правим если все убежало)
- Код: Выделить всё
<tr>
<td><label for="torpic">{L_TORPIC}</label></td>
<td><input type="radio" name="torpic_action" id="torpic_action" value="keep" checked="checked" />{L_KEEP_CURRENT} <input type="radio" name="torpic_action" id="torpic_action" value="update" />{L_REFRESH} <input type="radio" name="torpic_action" id="torpic_action" value="remove" />{L_DELETE}<br /><input type="file" name="torpic" id="torpic" size="77" /></td>
</tr>
<tr>
<td><label for="screen">{L_SCREEN}</label></td>
<td> <input type="radio" name="screen_action0" id="screen_action0" value="keep" checked="checked" />{L_KEEP_CURRENT} <input type="radio" name="screen_action0" id="screen_action0" value="update" />{L_REFRESH} <input type="radio" name="screen_action0" id="screen_action0" value="remove" />{L_DELETE}<br />№1 <input type="file" name="screen0" id="screen0" size="77" /><br />
<input type="radio" name="screen_action1" id="screen_action1" value="keep" checked="checked" />{L_KEEP_CURRENT} <input type="radio" name="screen_action1" id="screen_action1" value="update" />{L_REFRESH} <input type="radio" name="screen_action1" id="screen_action1" value="remove" />{L_DELETE}<br />№2 <input type="file" name="screen1" id="screen1" size="77" /><br />
<input type="radio" name="screen_action2" id="screen_action2" value="keep" checked="checked" />{L_KEEP_CURRENT} <input type="radio" name="screen_action2" id="screen_action2" value="update" />{L_REFRESH} <input type="radio" name="screen_action2" id="screen_action2" value="remove" />{L_DELETE}<br />№3 <input type="file" name="screen2" id="screen2" size="77" /></td>
</tr>
upload.php
После (230 строка)
- Код: Выделить всё
}
/* end tags */
Вставить
- Код: Выделить всё
if ( isset($_FILES['torpic']) && !empty($_FILES['torpic']['name']))
{
$torpic = check_upload_image($_FILES['torpic'], 'torpic/', 512000, 3000, 2000, $id);
$sql = 'UPDATE ' . TORRENTS_TABLE . ' SET picid0 = "' . $torpic['filename'] . '" WHERE fid = ' . $id;
$db->sql_query($sql);
}
for ( $x = 0; $x < 3; $x++ )
{
if ( isset($_FILES[screen.$x]) && !empty($_FILES[screen.$x]['name']))
{
$screen = check_upload_image($_FILES[screen.$x], 'torpic/', 512000, 3000, 2000, $id . '_' . $x);
$sql = 'UPDATE ' . TORRENTS_TABLE . ' SET screen' . $x . ' = "' . $screen['filename'] . '" WHERE fid = ' . $id;
$db->sql_query($sql);
}
}
templates/Ваш темплейт(оригинально для main)/upload_body.html
После
- Код: Выделить всё
33 <td valign="top" align=left><input type="file" name="nfo" size="80"><br />({L_NFO_UPLOAD_DESCR})</td>
34 </tr>
Вставить
- Код: Выделить всё
<tr>
<td valign="top" align="right">{L_TORPIC}</td>
<td valign="top" align=left><input type="file" name="torpic" size="80"><br />(Размер не более 500Кб)</td>
</tr>
<tr>
<td valign="top" align="right">{L_SCREEN}</td>
<td valign="top" align=left>№1 <input type="file" name="screen0" size="80"><br />
№2 <input type="file" name="screen1" size="80"><br />
№3 <input type="file" name="screen2" size="80"><br />(Размер не более 500Кб)</td>
</tr>
details.php
После
- Код: Выделить всё
196 break;
197
Перед (чтобы точно нашли
- Код: Выделить всё
198 case 'peerlist':
Вставить
- Код: Выделить всё
case 'screen':
$template->set_filenames(
array( 'screen_tpl' => 'details_screen.html'
));
$sql = 'SELECT f.screen0, f.screen1, f.screen2
FROM ' . TORRENTS_TABLE . ' f
WHERE f.fid = ' . $id;
$result = $db->sql_query( $sql );
$row = $db->sql_fetchrow( $result );
$template->assign_block_vars( 'screen_row', array(
'SCREEN0' => ($row['screen0'] ? trim($row['screen0']) : ''),
'SCREEN1' => ($row['screen0'] ? trim($row['screen1']) : ''),
'SCREEN2' => ($row['screen0'] ? trim($row['screen2']) : ''),
'TD_CLASS' => $theme['td_class2']
));
$db->sql_freeresult( $result );
$tpl = $template->assign_display( 'screen_tpl' );
if ( $use_ajax ) {
return $_RESULT = array( 'tpl' => $tpl );
}
break;
В конец строки
- Код: Выделить всё
399 t.completed, t.numfiles, t.category, t.hidden, t.free, t.comments, t.moderated, u.name AS username, u.class, u.privacy
Добавить
- Код: Выделить всё
,t.picid0, t.screen0, t.screen1, t.screen2
После
- Код: Выделить всё
523 'OWNER_ID' => ( is_numeric($owner) ? $owner : 0 ),
Вставить
- Код: Выделить всё
'TORPIC' => $row['picid0'],
'SCREEN' => (($row['screen0'] || $row['screen1'] || $row['screen2']) ? 1 : 0 ),
templates/Ваш темплейт(оригинально для main)/details.html
После
- Код: Выделить всё
46 <td>{INFO_HASH}</td>
47 </tr>
Вставить (можно использовать root_path и т.д., на ваше усмотрение)
- Код: Выделить всё
<!-- IF TORPIC -->
<tr>
<td valign="top">{L_TORPIC}</td>
<td valign="top"><center><a href='http://Ваш_сайт/torpic/{TORPIC}' target='_blank'><img border='0' src='http://Ваш_сайт/thumbnail.php?{TORPIC}' /></a></center></td>
</tr>
<!-- ENDIF -->
После
- Код: Выделить всё
<td valign="top">{DESCRIPTION}</td>
</tr>
Вставить
- Код: Выделить всё
<!-- IF SCREEN -->
<tr ALIGN="center">
<td></td>
<td valign="top"><a name="screen" id="screen"></a><b>{L_SCREEN}</b><br />
<a href="javascript:void(0);" onclick="view_details_ext('screen', '{ID}', 'details');" id="screen_href">[<!-- IF SCREEN_TPL -->{L_HIDE_LIST}<!-- ELSE -->{L_SEE_FULL_LIST}<!-- ENDIF -->]</a><br /><div id="screen_row">{SCREEN_TPL}</div>
</td>
<!-- ENDIF -->
Содержимое templates/Ваш темплейт(оригинально для main)/details_screen.html
- Код: Выделить всё
<!-- BEGIN screen_row -->
<td class="{screen_row.TD_CLASS}" valign="top">
<br />
<!-- IF screen_row.SCREEN0 -->
<center><a href="http://Ваш_сайт/torpic/{screen_row.SCREEN0}" target='_blank'><img border='0' src="http://Ваш_сайт/thumbnail.php?{screen_row.SCREEN0}" /></a></center></br>
<!-- ENDIF -->
<!-- IF screen_row.SCREEN1 -->
<center><a href="http://Ваш_сайт/torpic/{screen_row.SCREEN1}" target='_blank'><img border='0' src="http://Ваш_сайт/thumbnail.php?{screen_row.SCREEN1}" /></a></center></br>
<!-- ENDIF -->
<!-- IF screen_row.SCREEN2 -->
<center><a href="http://Ваш_сайт/torpic/{screen_row.SCREEN2}" target='_blank'><img border='0' src="http://Ваш_сайт/thumbnail.php?{screen_row.SCREEN2}" /></a></center>
<!-- ENDIF -->
<br />
<center><a href="javascript:void(0);" onclick="view_details_ext('screen', '{ID}', 'details');" id="screen_href">[<!-- IF SCREEN_TPL -->{L_SEE_FULL_LIST}<!-- ELSE -->{L_HIDE_LIST}<!-- ENDIF -->]</a></center>
</td>
<!-- END screen_row -->
Содержимое /thumbnail.php, переделанный немного Юна эдишн
- Код: Выделить всё
<?php
define('IMAGE_BASE', 'torpic');
define('THUMBS_BASE', 'torpic/cache');
define('MAX_WIDTH', 500);
if (!is_dir(THUMBS_BASE)) mkdir(THUMBS_BASE);
$image_file = trim($_SERVER['QUERY_STRING']);
$image_path = IMAGE_BASE . "/".$image_file;
$expName = explode('.', $image_file);
$id = $expName[0];
$size = @getimagesize($image_path);
$ext = strtolower( substr( $size['mime'], strpos($size['mime'], '/')+1 ) );
$thumb_path = THUMBS_BASE."/".$id.".".$ext;
if (file_exists($thumb_path))
{
Header("Location: ".$thumb_path);
die();
}
$img = null;
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = @imagecreatefrompng($image_path);
} else if ($ext == 'gif') {
$img = @imagecreatefromgif($image_path);
}
if ($img)
{
$width = imagesx($img);
$height = imagesy($img);
$scale = MAX_WIDTH/$width;
if ($scale < 1)
{
if ($width > MAX_WIDTH)
{
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
} else {
header("Location: ".$image_path);
die();
}
} else
create_error();
function create_error()
{
$img = imagecreate(100,100);
imagecolorallocate($img,0,0,0);
$c = imagecolorallocate($img,255,255,255);
$str = "Error creating";
$str2 = "thumbnail";
$size = 2;
$x_text = imagefontwidth($size)*strlen($str)-3;
$y_text = imagefontheight($size)-3;
imagestring($img, $size, 3, 3, $str,$c);
imagestring($img, $size, 3, 10, $str2,$c);
header("Content-type: image/jpeg");
imagejpeg($img);
die();
}
function save_image($image, $file, $extention)
{
if (file_exists($file))
{
@unlink($file);
save_image($image, $file, $extention);
} else {
switch ($extention)
{
case "jpg" :
case "jpeg" :
imagejpeg($image, $file);
header("Content-type: image/jpeg");
imagejpeg($image);
break;
case "png" :
imagepng($image, $file);
header("Content-type: image/png");
imagepng($image);
break;
case "gif" :
imagegif($image, $file);
header("Content-type: image/gif");
imagegif($image);
break;
}
return true;
}
}
save_image($img,$thumb_path,$ext);
?>
include/functions_delete.php
После
- Код: Выделить всё
54 @unlink($root_path . 'cache/png/torrent_nfo_' . $id . '.png');
Добавить (удалять то как-то надо, можно конечно и запрос добавить, только вот оно там надо?). Кеш чистим руками, можно и сюда дописать.
- Код: Выделить всё
@unlink($root_path . 'torpic/' . $id . '.jpg');
@unlink($root_path . 'torpic/' . $id . '.png');
@unlink($root_path . 'torpic/' . $id . '.gif');
for ( $x = 0; $x < 3; $x++ ) {
@unlink($root_path . 'torpic/' . $id . '_' . $x . '.jpg');
@unlink($root_path . 'torpic/' . $id . '_' . $x . '.png');
@unlink($root_path . 'torpic/' . $id . '_' . $x . '.gif');
}
