Перенос файлов движка в корень

This commit is contained in:
Exile 2014-10-28 21:35:42 +03:00
commit f94c0dd2ee
585 changed files with 14 additions and 14 deletions

View file

@ -0,0 +1,2 @@
order allow,deny
deny from all

View file

@ -0,0 +1,82 @@
<?php
if (!defined('IN_FORUM')) die("Hacking attempt");
require(ATTACH_DIR .'includes/functions_includes.php');
require(ATTACH_DIR .'includes/functions_attach.php');
require(ATTACH_DIR .'includes/functions_delete.php');
require(ATTACH_DIR .'includes/functions_thumbs.php');
require(ATTACH_DIR .'includes/functions_filetypes.php');
if (defined('ATTACH_INSTALL'))
{
return;
}
/**
* wrapper function for determining the correct language directory
*/
function attach_mod_get_lang($language_file)
{
global $attach_config, $bb_cfg;
$language = $bb_cfg['default_lang'];
if (!file_exists(LANG_ROOT_DIR ."$language/$language_file.php"))
{
$language = $attach_config['board_lang'];
if (!file_exists(LANG_ROOT_DIR ."$language/$language_file.php"))
{
bb_die('Attachment mod language file does not exist: language/' . $language . '/' . $language_file . '.php');
}
else
{
return $language;
}
}
else
{
return $language;
}
}
/**
* Get attachment mod configuration
*/
function get_config()
{
global $bb_cfg;
$attach_config = array();
$sql = 'SELECT * FROM ' . BB_ATTACH_CONFIG;
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not query attachment information');
}
while ($row = DB()->sql_fetchrow($result))
{
$attach_config[$row['config_name']] = trim($row['config_value']);
}
// We assign the original default board language here, because it gets overwritten later with the users default language
$attach_config['board_lang'] = trim($bb_cfg['default_lang']);
return $attach_config;
}
// Get Attachment Config
$attach_config = array();
if (!$attach_config = CACHE('bb_cache')->get('attach_config'))
{
$attach_config = get_config();
CACHE('bb_cache')->set('attach_config', $attach_config, 86400);
}
include(ATTACH_DIR .'displaying.php');
include(ATTACH_DIR .'posting_attachments.php');
$upload_dir = $attach_config['upload_dir'];

View file

@ -0,0 +1,346 @@
<?php
if (!defined('IN_FORUM')) die("Hacking attempt");
$allowed_extensions = array();
$display_categories = array();
$download_modes = array();
$upload_icons = array();
$attachments = array();
/**
* Create needed arrays for Extension Assignments
*/
function init_complete_extensions_data()
{
global $allowed_extensions, $display_categories, $download_modes, $upload_icons;
if (!$extension_informations = get_extension_informations())
{
$extension_informations = $GLOBALS['datastore']->update('attach_extensions'); //get_extension_informations()
$extension_informations = get_extension_informations();
}
$allowed_extensions = array();
for ($i = 0, $size = sizeof($extension_informations); $i < $size; $i++)
{
$extension = strtolower(trim($extension_informations[$i]['extension']));
$allowed_extensions[] = $extension;
$display_categories[$extension] = intval($extension_informations[$i]['cat_id']);
$download_modes[$extension] = intval($extension_informations[$i]['download_mode']);
$upload_icons[$extension] = trim($extension_informations[$i]['upload_icon']);
}
}
/**
* Writing Data into plain Template Vars
*/
function init_display_template($template_var, $replacement, $filename = 'viewtopic_attach.tpl')
{
global $template;
// This function is adapted from the old template class
// I wish i had the functions from the 3.x one. :D (This class rocks, can't await to use it in Mods)
// Handle Attachment Informations
if (!isset($template->uncompiled_code[$template_var]) && empty($template->uncompiled_code[$template_var]))
{
// If we don't have a file assigned to this handle, die.
if (!isset($template->files[$template_var]))
{
die("Template->loadfile(): No file specified for handle $template_var");
}
$filename_2 = $template->files[$template_var];
$str = implode('', @file($filename_2));
if (empty($str))
{
die("Template->loadfile(): File $filename_2 for handle $template_var is empty");
}
$template->uncompiled_code[$template_var] = $str;
}
$complete_filename = $filename;
if (substr($complete_filename, 0, 1) != '/')
{
$complete_filename = $template->root . '/' . $complete_filename;
}
if (!file_exists($complete_filename))
{
die("Template->make_filename(): Error - file $complete_filename does not exist");
}
$content = implode('', file($complete_filename));
if (empty($content))
{
die('Template->loadfile(): File ' . $complete_filename . ' is empty');
}
// replace $replacement with uncompiled code in $filename
$template->uncompiled_code[$template_var] = str_replace($replacement, $content, $template->uncompiled_code[$template_var]);
}
/**
* Display Attachments in Posts
*/
function display_post_attachments($post_id, $switch_attachment)
{
global $attach_config, $is_auth;
if (intval($switch_attachment) == 0 || intval($attach_config['disable_mod']))
{
return;
}
if ($is_auth['auth_download'] && $is_auth['auth_view'])
{
display_attachments($post_id);
}
}
/**
* Initializes some templating variables for displaying Attachments in Posts
*/
function init_display_post_attachments($switch_attachment)
{
global $attach_config, $is_auth, $template, $lang, $postrow, $total_posts, $attachments, $forum_row, $t_data;
if (empty($t_data) && !empty($forum_row))
{
$switch_attachment = $forum_row['topic_attachment'];
}
if (intval($switch_attachment) == 0 || intval($attach_config['disable_mod']) || (!($is_auth['auth_download'] && $is_auth['auth_view'])))
{
init_display_template('body', '{postrow.ATTACHMENTS}', 'viewtopic_attach_guest.tpl');
return;
}
$post_id_array = array();
for ($i = 0; $i < $total_posts; $i++)
{
if ($postrow[$i]['post_attachment'] == 1)
{
$post_id_array[] = (int) $postrow[$i]['post_id'];
}
}
if (sizeof($post_id_array) == 0)
{
return;
}
$rows = get_attachments_from_post($post_id_array);
$num_rows = sizeof($rows);
if ($num_rows == 0)
{
return;
}
@reset($attachments);
for ($i = 0; $i < $num_rows; $i++)
{
$attachments['_' . $rows[$i]['post_id']][] = $rows[$i];
//bt
if ($rows[$i]['tracker_status'])
{
if (defined('TORRENT_POST'))
{
bb_die('Multiple registered torrents in one topic<br /><br />first torrent found in post_id = '. TORRENT_POST .'<br />current post_id = '. $rows[$i]['post_id'] .'<br /><br />attachments info:<br /><pre style="text-align: left;">'. print_r($rows, TRUE) .'</pre>');
}
define('TORRENT_POST', $rows[$i]['post_id']);
}
//bt end
}
init_display_template('body', '{postrow.ATTACHMENTS}');
init_complete_extensions_data();
}
/**
* END ATTACHMENT DISPLAY IN POSTS
*/
/**
* Assign Variables and Definitions based on the fetched Attachments - internal
* used by all displaying functions, the Data was collected before, it's only dependend on the template used. :)
* before this function is usable, init_display_attachments have to be called for specific pages (pm, posting, review etc...)
*/
function display_attachments($post_id)
{
global $template, $upload_dir, $userdata, $allowed_extensions, $display_categories, $download_modes, $lang, $attachments, $upload_icons, $attach_config;
$num_attachments = @sizeof($attachments['_' . $post_id]);
if ($num_attachments == 0)
{
return;
}
$template->assign_block_vars('postrow.attach', array());
for ($i = 0; $i < $num_attachments; $i++)
{
// Some basic things...
$filename = $upload_dir . '/' . basename($attachments['_' . $post_id][$i]['physical_filename']);
$thumbnail_filename = $upload_dir . '/' . THUMB_DIR . '/t_' . basename($attachments['_' . $post_id][$i]['physical_filename']);
$upload_image = '';
if ($attach_config['upload_img'] && empty($upload_icons[$attachments['_' . $post_id][$i]['extension']]))
{
$upload_image = '<img src="' . $attach_config['upload_img'] . '" alt="" border="0" />';
}
else if (trim($upload_icons[$attachments['_' . $post_id][$i]['extension']]) != '')
{
$upload_image = '<img src="' . $upload_icons[$attachments['_' . $post_id][$i]['extension']] . '" alt="" border="0" />';
}
$filesize = humn_size($attachments['_' . $post_id][$i]['filesize']);
$display_name = htmlspecialchars($attachments['_' . $post_id][$i]['real_filename']);
$comment = htmlspecialchars($attachments['_' . $post_id][$i]['comment']);
$comment = str_replace("\n", '<br />', $comment);
$denied = false;
// Admin is allowed to view forbidden Attachments, but the error-message is displayed too to inform the Admin
if (!in_array($attachments['_' . $post_id][$i]['extension'], $allowed_extensions))
{
$denied = true;
$template->assign_block_vars('postrow.attach.denyrow', array(
'L_DENIED' => sprintf($lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachments['_' . $post_id][$i]['extension']))
);
}
if (!$denied || IS_ADMIN)
{
// define category
$image = FALSE;
$thumbnail = FALSE;
$link = FALSE;
if (@intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && intval($attach_config['img_display_inlined']))
{
if (intval($attach_config['img_link_width']) != 0 || intval($attach_config['img_link_height']) != 0)
{
list($width, $height) = image_getdimension($filename);
if ($width == 0 && $height == 0)
{
$image = TRUE;
}
else
{
if ($width <= intval($attach_config['img_link_width']) && $height <= intval($attach_config['img_link_height']))
{
$image = TRUE;
}
}
}
else
{
$image = TRUE;
}
}
if (@intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT && $attachments['_' . $post_id][$i]['thumbnail'] == 1)
{
$thumbnail = TRUE;
$image = FALSE;
}
if (!$image && !$thumbnail)
{
$link = TRUE;
}
if ($image)
{
// Images
if ($attach_config['upload_dir'][0] == '/' || ( $attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':'))
{
$img_source = BB_ROOT . DOWNLOAD_URL . $attachments['_' . $post_id][$i]['attach_id'];
$download_link = TRUE;
}
else
{
$img_source = $filename;
$download_link = FALSE;
}
$template->assign_block_vars('postrow.attach.cat_images', array(
'DOWNLOAD_NAME' => $display_name,
'S_UPLOAD_IMAGE' => $upload_image,
'IMG_SRC' => $img_source,
'FILESIZE' => $filesize,
'COMMENT' => $comment,
));
// Directly Viewed Image ... update the download count
if (!$download_link)
{
$sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . '
SET download_count = download_count + 1
WHERE attach_id = ' . (int) $attachments['_' . $post_id][$i]['attach_id'];
if (!(DB()->sql_query($sql)))
{
bb_die('Could not update attachment download count');
}
}
}
if ($thumbnail)
{
// Images, but display Thumbnail
if ($attach_config['upload_dir'][0] == '/' || ( $attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':'))
{
$thumb_source = BB_ROOT . DOWNLOAD_URL . $attachments['_' . $post_id][$i]['attach_id'] . '&thumb=1';
}
else
{
$thumb_source = $thumbnail_filename;
}
$template->assign_block_vars('postrow.attach.cat_thumb_images', array(
'DOWNLOAD_NAME' => $display_name,
'S_UPLOAD_IMAGE' => $upload_image,
'IMG_SRC' => BB_ROOT . DOWNLOAD_URL . $attachments['_' . $post_id][$i]['attach_id'],
'IMG_THUMB_SRC' => $thumb_source,
'FILESIZE' => $filesize,
'COMMENT' => $comment,
));
}
// bt
if ($link && ($attachments['_'. $post_id][$i]['extension'] === TORRENT_EXT))
{
include(ATTACH_DIR .'displaying_torrent.php');
}
else if ($link)
{
$target_blank = ( (@intval($display_categories[$attachments['_' . $post_id][$i]['extension']]) == IMAGE_CAT) ) ? 'target="_blank"' : '';
// display attachment
$template->assign_block_vars('postrow.attach.attachrow', array(
'U_DOWNLOAD_LINK' => BB_ROOT . DOWNLOAD_URL . $attachments['_' . $post_id][$i]['attach_id'],
'S_UPLOAD_IMAGE' => $upload_image,
'DOWNLOAD_NAME' => $display_name,
'FILESIZE' => $filesize,
'COMMENT' => $comment,
'TARGET_BLANK' => $target_blank,
'DOWNLOAD_COUNT' => sprintf($lang['DOWNLOAD_NUMBER'], $attachments['_' . $post_id][$i]['download_count']),
));
}
}
}
}

View file

@ -0,0 +1,604 @@
<?php
if (!defined('IN_FORUM')) die(basename(__FILE__));
global $bb_cfg, $t_data, $poster_id, $is_auth, $dl_link_css, $dl_status_css, $lang, $images;
$change_peers_bgr_over = true;
$bgr_class_1 = 'row1';
$bgr_class_2 = 'row2';
$bgr_class_over = 'row3';
$show_peers_limit = 300;
$max_peers_before_overflow = 20;
$peers_overflow_div_height = '400px';
$peers_div_style_normal = 'padding: 3px;';
$peers_div_style_overflow = "padding: 6px; height: $peers_overflow_div_height; overflow: auto; border: 1px inset;";
$s_last_seed_date_format = 'Y-m-d';
$upload_image = '<img src="'. $images['icon_dn'] .'" alt="'. $lang['DL_TORRENT'] .'" border="0" />';
$peers_cnt = $seed_count = 0;
$seeders = $leechers = '';
$tor_info = array();
$template->assign_vars(array(
'SEED_COUNT' => false,
'LEECH_COUNT' => false,
'TOR_SPEED_UP' => false,
'TOR_SPEED_DOWN' => false,
'SHOW_RATIO_WARN' => false,
));
// Define show peers mode (count only || user names with complete % || full details)
$cfg_sp_mode = $bb_cfg['bt_show_peers_mode'];
$get_sp_mode = (isset($_GET['spmode'])) ? $_GET['spmode'] : '';
$s_mode = 'count';
if ($cfg_sp_mode == SHOW_PEERS_NAMES)
{
$s_mode = 'names';
}
else if ($cfg_sp_mode == SHOW_PEERS_FULL)
{
$s_mode = 'full';
}
if ($bb_cfg['bt_allow_spmode_change'])
{
if ($get_sp_mode == 'names')
{
$s_mode = 'names';
}
else if ($get_sp_mode == 'full')
{
$s_mode = 'full';
}
}
$bt_topic_id = $t_data['topic_id'];
$bt_user_id = $userdata['user_id'];
$attach_id = $attachments['_'. $post_id][$i]['attach_id'];
$tracker_status = $attachments['_'. $post_id][$i]['tracker_status'];
$download_count = $attachments['_'. $post_id][$i]['download_count'];
$tor_file_size = humn_size($attachments['_'. $post_id][$i]['filesize']);
$tor_file_time = bb_date($attachments['_'. $post_id][$i]['filetime']);
$tor_reged = (bool) $tracker_status;
$show_peers = (bool) $bb_cfg['bt_show_peers'];
$locked = ($t_data['forum_status'] == FORUM_LOCKED || $t_data['topic_status'] == TOPIC_LOCKED);
$tor_auth = ($bt_user_id != GUEST_UID && (($bt_user_id == $poster_id && !$locked) || $is_auth['auth_mod']));
$tor_auth_reg = ($tor_auth && $t_data['allow_reg_tracker'] && $post_id == $t_data['topic_first_post_id']);
$tor_auth_del = ($tor_auth && $tor_reged);
$tracker_link = ($tor_reged) ? $lang['BT_REG_YES'] : $lang['BT_REG_NO'];
$download_link = DOWNLOAD_URL . $attach_id;
$description = ($comment) ? $comment : preg_replace("#.torrent$#i", '', $display_name);
if ($tor_auth_reg || $tor_auth_del)
{
$reg_tor_url = '<a class="txtb" href="#" onclick="ajax.exec({ action: \'change_torrent\', attach_id : '. $attach_id .', type: \'reg\'}); return false;">'. $lang['BT_REG_ON_TRACKER'] .'</a>';
$unreg_tor_url = '<a class="txtb" href="#" onclick="ajax.exec({ action: \'change_torrent\', attach_id : '. $attach_id .', type: \'unreg\'}); return false;">'. $lang['BT_UNREG_FROM_TRACKER'] .'</a>';
$tracker_link = ($tor_reged) ? $unreg_tor_url : $reg_tor_url;
}
if ($bb_cfg['torrent_name_style'])
{
$display_name = '['.$bb_cfg['server_name'].'].t' . $bt_topic_id . '.torrent';
}
if (!$tor_reged)
{
$template->assign_block_vars('postrow.attach.tor_not_reged', array(
'DOWNLOAD_NAME' => $display_name,
'TRACKER_LINK' => $tracker_link,
'ATTACH_ID' => $attach_id,
'S_UPLOAD_IMAGE' => $upload_image,
'U_DOWNLOAD_LINK' => $download_link,
'FILESIZE' => $tor_file_size,
'DOWNLOAD_COUNT' => sprintf($lang['DOWNLOAD_NUMBER'], $download_count),
'POSTED_TIME' => $tor_file_time,
));
if ($comment)
{
$template->assign_block_vars('postrow.attach.tor_not_reged.comment', array('COMMENT' => $comment));
}
}
else
{
$sql = "SELECT bt.*, u.user_id, u.username, u.user_rank
FROM ". BB_BT_TORRENTS ." bt
LEFT JOIN ". BB_USERS ." u ON(bt.checked_user_id = u.user_id)
WHERE bt.attach_id = $attach_id";
if (!$result = DB()->sql_query($sql))
{
bb_die('Could not obtain torrent information');
}
$tor_info = DB()->sql_fetchrow($result);
DB()->sql_freeresult($result);
}
if ($tor_reged && !$tor_info)
{
DB()->query("UPDATE ". BB_ATTACHMENTS_DESC ." SET tracker_status = 0 WHERE attach_id = $attach_id");
bb_die('Torrent status fixed');
}
if ($tor_auth)
{
$template->assign_vars(array(
'TOR_CONTROLS' => true,
'TOR_ATTACH_ID' => $attach_id,
));
if ($t_data['self_moderated'] || $is_auth['auth_mod'])
{
$template->assign_vars(array('AUTH_MOVE' => true));
}
}
if ($tor_reged && $tor_info)
{
$tor_size = ($tor_info['size']) ? $tor_info['size'] : 0;
$tor_id = $tor_info['topic_id'];
$tor_type = $tor_info['tor_type'];
// Magnet link
$passkey = DB()->fetch_row("SELECT auth_key FROM ". BB_BT_USERS ." WHERE user_id = ". (int) $bt_user_id ." LIMIT 1");
$tor_magnet = create_magnet($tor_info['info_hash'], $passkey['auth_key'], $userdata['session_logged_in']);
// ratio limits
$min_ratio_dl = $bb_cfg['bt_min_ratio_allow_dl_tor'];
$min_ratio_warn = $bb_cfg['bt_min_ratio_warning'];
$dl_allowed = true;
$user_ratio = 0;
if (($min_ratio_dl || $min_ratio_warn) && $bt_user_id != $poster_id)
{
$sql = "SELECT u.*, dl.user_status
FROM ". BB_BT_USERS ." u
LEFT JOIN ". BB_BT_DLSTATUS ." dl ON dl.user_id = $bt_user_id AND dl.topic_id = $bt_topic_id
WHERE u.user_id = $bt_user_id
LIMIT 1";
}
else
{
$sql = "SELECT user_status
FROM ". BB_BT_DLSTATUS ."
WHERE user_id = $bt_user_id
AND topic_id = $bt_topic_id
LIMIT 1";
}
$bt_userdata = DB()->fetch_row($sql);
$user_status = isset($bt_userdata['user_status']) ? $bt_userdata['user_status'] : null;
if (($min_ratio_dl || $min_ratio_warn) && $user_status != DL_STATUS_COMPLETE && $bt_user_id != $poster_id && $tor_type != TOR_TYPE_GOLD)
{
if (($user_ratio = get_bt_ratio($bt_userdata)) !== null)
{
$dl_allowed = ($user_ratio > $min_ratio_dl);
}
if ((isset($user_ratio) && isset($min_ratio_warn) && $user_ratio < $min_ratio_warn && TR_RATING_LIMITS) || ($bt_userdata['u_down_total'] < MIN_DL_FOR_RATIO))
{
$template->assign_vars(array(
'SHOW_RATIO_WARN' => true,
'RATIO_WARN_MSG' => sprintf($lang['BT_RATIO_WARNING_MSG'], $min_ratio_dl, $bb_cfg['ratio_url_help']),
));
}
}
if (!$dl_allowed)
{
$template->assign_block_vars('postrow.attach.tor_reged', array());
$template->assign_vars(array(
'TOR_BLOCKED' => true,
'TOR_BLOCKED_MSG' => sprintf($lang['BT_LOW_RATIO_FOR_DL'], round($user_ratio, 2), "search.php?dlu=$bt_user_id&amp;dlc=1"),
));
}
else
{
$template->assign_block_vars('postrow.attach.tor_reged', array(
'DOWNLOAD_NAME' => $display_name,
'TRACKER_LINK' => $tracker_link,
'ATTACH_ID' => $attach_id,
'TOR_SILVER_GOLD' => $tor_type,
// torrent status mod
'TOR_FROZEN' => (!IS_AM) ? (isset($bb_cfg['tor_frozen'][$tor_info['tor_status']]) && !(isset($bb_cfg['tor_frozen_author_download'][$tor_info['tor_status']]) && $userdata['user_id'] == $tor_info['poster_id'])) ? true : '' : '',
'TOR_STATUS_TEXT' => $lang['TOR_STATUS_NAME'][$tor_info['tor_status']],
'TOR_STATUS_ICON' => $bb_cfg['tor_icons'][$tor_info['tor_status']],
'TOR_STATUS_BY' => ($tor_info['checked_user_id'] && $is_auth['auth_mod']) ? ('<span title="'. bb_date($tor_info['checked_time']) .'"> &middot; '. profile_url($tor_info) .' &middot; <i>'. delta_time($tor_info['checked_time']) . $lang['TOR_BACK'] .'</i></span>') : '',
'TOR_STATUS_SELECT' => build_select('sel_status', array_flip($lang['TOR_STATUS_NAME']), TOR_APPROVED),
'TOR_STATUS_REPLY' => $bb_cfg['tor_comment'] && !IS_GUEST && in_array($tor_info['tor_status'], $bb_cfg['tor_reply']) && $userdata['user_id'] == $tor_info['poster_id'] && $t_data['topic_status'] != TOPIC_LOCKED,
//end torrent status mod
'S_UPLOAD_IMAGE' => $upload_image,
'U_DOWNLOAD_LINK' => $download_link,
'DL_LINK_CLASS' => (isset($bt_userdata['user_status'])) ? $dl_link_css[$bt_userdata['user_status']] : 'genmed',
'DL_TITLE_CLASS' => (isset($bt_userdata['user_status'])) ? $dl_status_css[$bt_userdata['user_status']] : 'gen',
'FILESIZE' => $tor_file_size,
'MAGNET' => $tor_magnet,
'HASH' => strtoupper(bin2hex($tor_info['info_hash'])),
'DOWNLOAD_COUNT' => sprintf($lang['DOWNLOAD_NUMBER'], $download_count),
'REGED_TIME' => bb_date($tor_info['reg_time']),
'REGED_DELTA' => delta_time($tor_info['reg_time']),
'TORRENT_SIZE' => humn_size($tor_size),
'COMPLETED' => sprintf($lang['DOWNLOAD_NUMBER'], $tor_info['complete_count']),
));
if ($comment)
{
$template->assign_block_vars('postrow.attach.tor_reged.comment', array('COMMENT' => $comment));
}
}
if ($bb_cfg['show_tor_info_in_dl_list'])
{
$template->assign_vars(array(
'SHOW_DL_LIST' => true,
'SHOW_DL_LIST_TOR_INFO' => true,
'TOR_SIZE' => humn_size($tor_size),
'TOR_LONGEVITY' => delta_time($tor_info['reg_time']),
'TOR_COMPLETED' => declension($tor_info['complete_count'], 'times'),
));
}
// Show peers
if ($show_peers)
{
// Sorting order in full mode
if ($s_mode == 'full')
{
$full_mode_order = 'tr.remain';
$full_mode_sort_dir = 'ASC';
if (isset($_REQUEST['psortasc']))
{
$full_mode_sort_dir = 'ASC';
}
else if (isset($_REQUEST['psortdesc']))
{
$full_mode_sort_dir = 'DESC';
}
if (isset($_REQUEST['porder']))
{
$peer_orders = array(
'name' => 'u.username',
'ip' => 'tr.ip',
'port' => 'tr.port',
'compl' => 'tr.remain',
'cup' => 'tr.uploaded',
'cdown' => 'tr.downloaded',
'sup' => 'tr.speed_up',
'sdown' => 'tr.speed_down',
'time' => 'tr.update_time',
);
foreach ($peer_orders as $get_key => $order_by_value)
{
if ($_REQUEST['porder'] == $get_key)
{
$full_mode_order = $order_by_value;
break;
}
}
}
}
// SQL for each mode
if ($s_mode == 'count')
{
$sql = "SELECT seeders, leechers, speed_up, speed_down
FROM ". BB_BT_TRACKER_SNAP ."
WHERE topic_id = $tor_id
LIMIT 1";
}
else if ($s_mode == 'names')
{
$sql = "SELECT tr.user_id, tr.ip, tr.port, tr.remain, tr.seeder, u.username, u.user_rank
FROM ". BB_BT_TRACKER ." tr, ". BB_USERS ." u
WHERE tr.topic_id = $tor_id
AND u.user_id = tr.user_id
GROUP BY tr.ip, tr.user_id, tr.port, tr.seeder
ORDER BY u.username
LIMIT $show_peers_limit";
}
else
{
$sql = "SELECT
tr.user_id, tr.ip, tr.port, tr.uploaded, tr.downloaded, tr.remain,
tr.seeder, tr.releaser, tr.speed_up, tr.speed_down, tr.update_time,
tr.complete_percent, u.username, u.user_rank
FROM ". BB_BT_TRACKER ." tr
LEFT JOIN ". BB_USERS ." u ON u.user_id = tr.user_id
WHERE tr.topic_id = $tor_id
GROUP BY tr.ip, tr.user_id, tr.port, tr.seeder
ORDER BY $full_mode_order $full_mode_sort_dir
LIMIT $show_peers_limit";
}
// Build peers table
if ($peers = DB()->fetch_rowset($sql))
{
$peers_cnt = count($peers);
$cnt = $tr = $sp_up = $sp_down = $sp_up_tot = $sp_down_tot = array();
$cnt['s'] = $tr['s'] = $sp_up['s'] = $sp_down['s'] = $sp_up_tot['s'] = $sp_down_tot['s'] = 0;
$cnt['l'] = $tr['l'] = $sp_up['l'] = $sp_down['l'] = $sp_up_tot['l'] = $sp_down_tot['l'] = 0;
$max_up = $max_down = $max_sp_up = $max_sp_down = array();
$max_up['s'] = $max_down['s'] = $max_sp_up['s'] = $max_sp_down['s'] = 0;
$max_up['l'] = $max_down['l'] = $max_sp_up['l'] = $max_sp_down['l'] = 0;
$max_up_id['s'] = $max_down_id['s'] = $max_sp_up_id['s'] = $max_sp_down_id['s'] = ($peers_cnt + 1);
$max_up_id['l'] = $max_down_id['l'] = $max_sp_up_id['l'] = $max_sp_down_id['l'] = ($peers_cnt + 1);
if ($s_mode == 'full')
{
foreach ($peers as $pid => $peer)
{
$x = ($peer['seeder']) ? 's' : 'l';
$cnt[$x]++;
$sp_up_tot[$x] += $peer['speed_up'];
$sp_down_tot[$x] += $peer['speed_down'];
$guest = ($peer['user_id'] == GUEST_UID || is_null($peer['username']));
$p_max_up = $peer['uploaded'];
$p_max_down = $peer['downloaded'];
if ($p_max_up > $max_up[$x])
{
$max_up[$x] = $p_max_up;
$max_up_id[$x] = $pid;
}
if ($peer['speed_up'] > $max_sp_up[$x])
{
$max_sp_up[$x] = $peer['speed_up'];
$max_sp_up_id[$x] = $pid;
}
if ($p_max_down > $max_down[$x])
{
$max_down[$x] = $p_max_down;
$max_down_id[$x] = $pid;
}
if ($peer['speed_down'] > $max_sp_down[$x])
{
$max_sp_down[$x] = $peer['speed_down'];
$max_sp_down_id[$x] = $pid;
}
}
$max_down_id['s'] = $max_sp_down_id['s'] = ($peers_cnt + 1);
if ($cnt['s'] == 1)
{
$max_up_id['s'] = $max_sp_up_id['s'] = ($peers_cnt + 1);
}
if ($cnt['l'] == 1)
{
$max_up_id['l'] = $max_down_id['l'] = $max_sp_up_id['l'] = $max_sp_down_id['l'] = ($peers_cnt + 1);
}
}
if ($s_mode == 'count')
{
$tmp = array();
$tmp[0]['seeder'] = $tmp[0]['username'] = $tmp[1]['username'] = 0;
$tmp[1]['seeder'] = 1;
$tmp[0]['username'] = (int) @$peers[0]['leechers'];
$tmp[1]['username'] = (int) @$peers[0]['seeders'];
$tor_speed_up = (int) @$peers[0]['speed_up'];
$tor_speed_down = (int) @$peers[0]['speed_down'];
$peers = $tmp;
$template->assign_vars(array(
'TOR_SPEED_UP' => ($tor_speed_up) ? humn_size($tor_speed_up, 0, 'KB') .'/s' : '0 KB/s',
'TOR_SPEED_DOWN' => ($tor_speed_down) ? humn_size($tor_speed_down, 0, 'KB') .'/s' : '0 KB/s',
));
}
foreach ($peers as $pid => $peer)
{
$u_prof_href = ($s_mode == 'count') ? '#' : "profile.php?mode=viewprofile&amp;u=". $peer['user_id'] ."#torrent";
// Full details mode
if ($s_mode == 'full')
{
$ip = bt_show_ip($peer['ip']);
$port = bt_show_port($peer['port']);
// peer max/current up/down
$p_max_up = $peer['uploaded'];
$p_max_down = $peer['downloaded'];
$p_cur_up = $peer['uploaded'];
$p_cur_down = $peer['downloaded'];
if ($peer['seeder'])
{
$x = 's';
$x_row = 'srow';
$x_full = 'sfull';
if (!defined('SEEDER_EXIST'))
{
define('SEEDER_EXIST', true);
$seed_order_action = "viewtopic.php?". POST_TOPIC_URL ."=$bt_topic_id&amp;spmode=full#seeders";
$template->assign_block_vars("$x_full", array(
'SEED_ORD_ACT' => $seed_order_action,
'SEEDERS_UP_TOT' => humn_size($sp_up_tot[$x], 0, 'KB') .'/s'
));
if ($ip)
{
$template->assign_block_vars("$x_full.iphead", array());
}
if ($port !== false)
{
$template->assign_block_vars("$x_full.porthead", array());
}
}
$compl_perc = ($tor_size) ? round(($p_max_up / $tor_size), 1) : 0;
}
else
{
$x = 'l';
$x_row = 'lrow';
$x_full = 'lfull';
if (!defined('LEECHER_EXIST'))
{
define('LEECHER_EXIST', true);
$leech_order_action = "viewtopic.php?". POST_TOPIC_URL ."=$bt_topic_id&amp;spmode=full#leechers";
$template->assign_block_vars("$x_full", array(
'LEECH_ORD_ACT' => $leech_order_action,
'LEECHERS_UP_TOT' => humn_size($sp_up_tot[$x], 0, 'KB') .'/s',
'LEECHERS_DOWN_TOT' => humn_size($sp_down_tot[$x], 0, 'KB') .'/s'
));
if ($ip)
{
$template->assign_block_vars("$x_full.iphead", array());
}
if ($port !== false)
{
$template->assign_block_vars("$x_full.porthead", array());
}
}
$compl_size = ($peer['remain'] && $tor_size && $tor_size > $peer['remain']) ? ($tor_size - $peer['remain']) : 0;
$compl_perc = ($compl_size) ? floor($compl_size * 100 / $tor_size) : 0;
}
$rel_sign = (!$guest && $peer['releaser']) ? '&nbsp;<b><sup>&reg;</sup></b>' : '';
$name = profile_url($peer). $rel_sign;
$up_tot = ($p_max_up) ? humn_size($p_max_up) : '-';
$down_tot = ($p_max_down) ? humn_size($p_max_down) : '-';
$up_ratio = ($p_max_down) ? round(($p_max_up / $p_max_down), 2) : '';
$sp_up = ($peer['speed_up']) ? humn_size($peer['speed_up'], 0, 'KB') .'/s' : '-';
$sp_down = ($peer['speed_down']) ? humn_size($peer['speed_down'], 0, 'KB') .'/s' : '-';
$bgr_class = (!($tr[$x] % 2)) ? $bgr_class_1 : $bgr_class_2;
$row_bgr = ($change_peers_bgr_over) ? " class=\"$bgr_class\" onmouseover=\"this.className='$bgr_class_over';\" onmouseout=\"this.className='$bgr_class';\"" : '';
$tr[$x]++;
$template->assign_block_vars("$x_full.$x_row", array(
'ROW_BGR' => $row_bgr,
'NAME' => ($peer['update_time']) ? $name : "<s>$name</s>",
'COMPL_PRC' => $compl_perc,
'UP_TOTAL' => ($max_up_id[$x] == $pid) ? "<b>$up_tot</b>" : $up_tot,
'DOWN_TOTAL' => ($max_down_id[$x] == $pid) ? "<b>$down_tot</b>" : $down_tot,
'SPEED_UP' => ($max_sp_up_id[$x] == $pid) ? "<b>$sp_up</b>" : $sp_up,
'SPEED_DOWN' => ($max_sp_down_id[$x] == $pid) ? "<b>$sp_down</b>" : $sp_down,
'UP_TOTAL_RAW' => $peer['uploaded'],
'DOWN_TOTAL_RAW' => $peer['downloaded'],
'SPEED_UP_RAW' => $peer['speed_up'],
'SPEED_DOWN_RAW' => $peer['speed_down'],
'UPD_EXP_TIME' => ($peer['update_time']) ? $lang['DL_UPD'] . bb_date($peer['update_time'], 'd-M-y H:i') .' &middot; '. delta_time($peer['update_time']) . $lang['TOR_BACK'] : $lang['DL_STOPPED'],
'TOR_RATIO' => ($up_ratio) ? $lang['USER_RATIO'] . "UL/DL: $up_ratio" : '',
));
if ($ip)
{
$template->assign_block_vars("$x_full.$x_row.ip", array('IP' => $ip));
}
if ($port !== false)
{
$template->assign_block_vars("$x_full.$x_row.port", array('PORT' => $port));
}
}
// Count only & only names modes
else
{
if ($peer['seeder'])
{
$seeders .= '<nobr><a href="'. $u_prof_href .'" class="seedmed">'. $peer['username'] .'</a>,</nobr> ';
$seed_count = $peer['username'];
}
else
{
$compl_size = (@$peer['remain'] && $tor_size && $tor_size > $peer['remain']) ? ($tor_size - $peer['remain']) : 0;
$compl_perc = ($compl_size) ? floor($compl_size * 100 / $tor_size) : 0;
$leechers .= '<nobr><a href="'. $u_prof_href .'" class="leechmed">'. $peer['username'] .'</a>';
$leechers .= ($s_mode == 'names') ? ' ['. $compl_perc .'%]' : '';
$leechers .= ',</nobr> ';
$leech_count = $peer['username'];
}
}
}
if ($s_mode != 'full' && $seeders)
{
$seeders[strlen($seeders)-9] = ' ';
$template->assign_vars(array(
'SEED_LIST' => $seeders,
'SEED_COUNT' => ($seed_count) ? $seed_count : 0,
));
}
if ($s_mode != 'full' && $leechers)
{
$leechers[strlen($leechers)-9] = ' ';
$template->assign_vars(array(
'LEECH_LIST' => $leechers,
'LEECH_COUNT' => ($leech_count) ? $leech_count : 0,
));
}
}
unset($peers);
// Show "seeder last seen info"
if (($s_mode == 'count' && !$seed_count) || (!$seeders && !defined('SEEDER_EXIST')))
{
$last_seen_time = ($tor_info['seeder_last_seen']) ? delta_time($tor_info['seeder_last_seen']) : $lang['NEVER'];
$template->assign_vars(array(
'SEEDER_LAST_SEEN' => sprintf($lang['SEEDER_LAST_SEEN'], $last_seen_time),
));
}
}
$template->assign_block_vars('tor_title', array('U_DOWNLOAD_LINK' => $download_link));
if ($peers_cnt > $max_peers_before_overflow && $s_mode == 'full')
{
$template->assign_vars(array('PEERS_DIV_STYLE' => $peers_div_style_overflow));
$template->assign_vars(array('PEERS_OVERFLOW' => true));
}
else
{
$template->assign_vars(array('PEERS_DIV_STYLE' => $peers_div_style_normal));
}
}
if ($bb_cfg['bt_allow_spmode_change'] && $s_mode != 'full')
{
$template->assign_vars(array(
'PEERS_FULL_LINK' => true,
'SPMODE_FULL_HREF' => "viewtopic.php?". POST_TOPIC_URL ."=$bt_topic_id&amp;spmode=full#seeders",
));
}
$template->assign_vars(array(
'SHOW_DL_LIST_LINK' => (($bb_cfg['bt_show_dl_list'] || $bb_cfg['allow_dl_list_names_mode']) && $t_data['topic_dl_type'] == TOPIC_DL_TYPE_DL),
'SHOW_TOR_ACT' => ($tor_reged && $show_peers && (!isset($bb_cfg['tor_no_tor_act'][$tor_info['tor_status']]) || IS_AM)),
'S_MODE_COUNT' => ($s_mode == 'count'),
'S_MODE_NAMES' => ($s_mode == 'names'),
'S_MODE_FULL' => ($s_mode == 'full'),
'PEER_EXIST' => ($seeders || $leechers || defined('SEEDER_EXIST') || defined('LEECHER_EXIST')),
'SEED_EXIST' => ($seeders || defined('SEEDER_EXIST')),
'LEECH_EXIST' => ($leechers || defined('LEECHER_EXIST')),
'TOR_HELP_LINKS' => $bb_cfg['tor_help_links'],
'CALL_SEED' => ($bb_cfg['callseed'] && $tor_reged && !isset($bb_cfg['tor_no_tor_act'][$tor_info['tor_status']]) && $seed_count < 3 && $tor_info['call_seed_time'] < (TIMENOW - 86400)),
));

View file

@ -0,0 +1,2 @@
order allow,deny
deny from all

View file

@ -0,0 +1,353 @@
<?php
/**
* All Attachment Functions only needed in Admin
*/
/**
* Set/Change Quotas
*/
function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0)
{
$id = (int) $id;
$quota_type = (int) $quota_type;
$quota_limit_id = (int) $quota_limit_id;
if ($mode == 'user')
{
if (!$quota_limit_id)
{
$sql = 'DELETE FROM ' . BB_QUOTA . "
WHERE user_id = $id
AND quota_type = $quota_type";
}
else
{
// Check if user is already entered
$sql = 'SELECT user_id
FROM ' . BB_QUOTA . "
WHERE user_id = $id
AND quota_type = $quota_type";
if( !($result = DB()->sql_query($sql)) )
{
bb_die('Could not get entry #1');
}
if (DB()->num_rows($result) == 0)
{
$sql_ary = array(
'user_id' => (int) $id,
'group_id' => 0,
'quota_type' => (int) $quota_type,
'quota_limit_id'=> (int) $quota_limit_id
);
$sql = 'INSERT INTO ' . BB_QUOTA . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary);
}
else
{
$sql = 'UPDATE ' . BB_QUOTA . "
SET quota_limit_id = $quota_limit_id
WHERE user_id = $id
AND quota_type = $quota_type";
}
DB()->sql_freeresult($result);
}
if (!($result = DB()->sql_query($sql)))
{
bb_die('Unable to update quota settings');
}
}
else if ($mode == 'group')
{
if (!$quota_limit_id)
{
$sql = 'DELETE FROM ' . BB_QUOTA . "
WHERE group_id = $id
AND quota_type = $quota_type";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Unable to delete quota settings');
}
}
else
{
// Check if user is already entered
$sql = 'SELECT group_id
FROM ' . BB_QUOTA . "
WHERE group_id = $id
AND quota_type = $quota_type";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not get entry #2');
}
if (DB()->num_rows($result) == 0)
{
$sql = 'INSERT INTO ' . BB_QUOTA . " (user_id, group_id, quota_type, quota_limit_id)
VALUES (0, $id, $quota_type, $quota_limit_id)";
}
else
{
$sql = 'UPDATE ' . BB_QUOTA . " SET quota_limit_id = $quota_limit_id
WHERE group_id = $id AND quota_type = $quota_type";
}
if (!DB()->sql_query($sql))
{
bb_die('Unable to update quota settings');
}
}
}
}
/**
* sort multi-dimensional Array
*/
function sort_multi_array ($sort_array, $key, $sort_order, $pre_string_sort = 0)
{
$last_element = sizeof($sort_array) - 1;
if (!$pre_string_sort)
{
$string_sort = (!is_numeric(@$sort_array[$last_element-1][$key]) ) ? true : false;
}
else
{
$string_sort = $pre_string_sort;
}
for ($i = 0; $i < $last_element; $i++)
{
$num_iterations = $last_element - $i;
for ($j = 0; $j < $num_iterations; $j++)
{
$next = 0;
// do checks based on key
$switch = false;
if (!$string_sort)
{
if (($sort_order == 'DESC' && intval(@$sort_array[$j][$key]) < intval(@$sort_array[$j + 1][$key])) || ($sort_order == 'ASC' && intval(@$sort_array[$j][$key]) > intval(@$sort_array[$j + 1][$key])))
{
$switch = true;
}
}
else
{
if (($sort_order == 'DESC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) < 0) || ($sort_order == 'ASC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) > 0))
{
$switch = true;
}
}
if ($switch)
{
$temp = $sort_array[$j];
$sort_array[$j] = $sort_array[$j + 1];
$sort_array[$j + 1] = $temp;
}
}
}
return $sort_array;
}
/**
* Returns the filesize of the upload directory in human readable format
*/
function get_formatted_dirsize()
{
global $attach_config, $upload_dir, $lang;
$upload_dir_size = 0;
if ($dirname = @opendir($upload_dir))
{
while ($file = @readdir($dirname))
{
if ($file != 'index.php' && $file != '.htaccess' && !is_dir($upload_dir . '/' . $file) && !is_link($upload_dir . '/' . $file))
{
$upload_dir_size += @filesize($upload_dir . '/' . $file);
}
}
@closedir($dirname);
}
else
{
$upload_dir_size = $lang['NOT_AVAILABLE'];
return $upload_dir_size;
}
return humn_size($upload_dir_size);
}
/*
* Build SQL-Statement for the search feature
*/
function search_attachments($order_by, &$total_rows)
{
global $lang;
$where_sql = array();
// Get submitted Vars
$search_vars = array('search_keyword_fname', 'search_keyword_comment', 'search_author', 'search_size_smaller', 'search_size_greater', 'search_count_smaller', 'search_count_greater', 'search_days_greater', 'search_forum', 'search_cat');
for ($i = 0; $i < sizeof($search_vars); $i++)
{
$$search_vars[$i] = get_var($search_vars[$i], '');
}
// Author name search
if ($search_author != '')
{
// Bring in line with 2.0.x expected username
$search_author = addslashes(html_entity_decode($search_author));
$search_author = stripslashes(clean_username($search_author));
// Prepare for directly going into sql query
$search_author = str_replace('*', '%', attach_mod_sql_escape($search_author));
// We need the post_id's, because we want to query the Attachment Table
$sql = 'SELECT user_id FROM ' . BB_USERS . " WHERE username LIKE '$search_author'";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not obtain list of matching users (searching for: ' . $search_author . ')');
}
$matching_userids = '';
if ( $row = DB()->sql_fetchrow($result) )
{
do
{
$matching_userids .= (($matching_userids != '') ? ', ' : '') . intval($row['user_id']);
}
while ($row = DB()->sql_fetchrow($result));
DB()->sql_freeresult($result);
}
else
{
bb_die($lang['NO_ATTACH_SEARCH_MATCH']);
}
$where_sql[] = ' (t.user_id_1 IN (' . $matching_userids . ')) ';
}
// Search Keyword
if ($search_keyword_fname != '')
{
$match_word = str_replace('*', '%', $search_keyword_fname);
$where_sql[] = " (a.real_filename LIKE '" . attach_mod_sql_escape($match_word) . "') ";
}
if ($search_keyword_comment != '')
{
$match_word = str_replace('*', '%', $search_keyword_comment);
$where_sql[] = " (a.comment LIKE '" . attach_mod_sql_escape($match_word) . "') ";
}
// Search Download Count
if ($search_count_smaller != '' || $search_count_greater != '')
{
if ($search_count_smaller != '')
{
$where_sql[] = ' (a.download_count < ' . (int) $search_count_smaller . ') ';
}
else if ($search_count_greater != '')
{
$where_sql[] = ' (a.download_count > ' . (int) $search_count_greater . ') ';
}
}
// Search Filesize
if ($search_size_smaller != '' || $search_size_greater != '')
{
if ($search_size_smaller != '')
{
$where_sql[] = ' (a.filesize < ' . (int) $search_size_smaller . ') ';
}
else if ($search_size_greater != '')
{
$where_sql[] = ' (a.filesize > ' . (int) $search_size_greater . ') ';
}
}
// Search Attachment Time
if ($search_days_greater != '')
{
$where_sql[] = ' (a.filetime < ' . ( TIMENOW - ((int) $search_days_greater * 86400)) . ') ';
}
// Search Forum
if ($search_forum)
{
$where_sql[] = ' (p.forum_id = ' . intval($search_forum) . ') ';
}
// Search Cat... nope... sorry :(
$sql = 'SELECT a.*, t.post_id, p.post_time, p.topic_id
FROM ' . BB_ATTACHMENTS . ' t, ' . BB_ATTACHMENTS_DESC . ' a, ' . BB_POSTS . ' p WHERE ';
if (sizeof($where_sql) > 0)
{
$sql .= implode('AND', $where_sql) . ' AND ';
}
$sql .= 't.post_id = p.post_id AND a.attach_id = t.attach_id ';
$total_rows_sql = $sql;
$sql .= $order_by;
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not query attachments #1');
}
$attachments = DB()->sql_fetchrowset($result);
$num_attach = DB()->num_rows($result);
DB()->sql_freeresult($result);
if ($num_attach == 0)
{
bb_die($lang['NO_ATTACH_SEARCH_MATCH']);
}
if (!($result = DB()->sql_query($total_rows_sql)))
{
bb_die('Could not query attachments #2');
}
$total_rows = DB()->num_rows($result);
DB()->sql_freeresult($result);
return $attachments;
}
/**
* perform LIMIT statement on arrays
*/
function limit_array($array, $start, $pagelimit)
{
// array from start - start+pagelimit
$limit = (sizeof($array) < ($start + $pagelimit)) ? sizeof($array) : $start + $pagelimit;
$limit_array = array();
for ($i = $start; $i < $limit; $i++)
{
$limit_array[] = $array[$i];
}
return $limit_array;
}

View file

@ -0,0 +1,690 @@
<?php
/**
* All Attachment Functions needed everywhere
*/
/**
* html_entity_decode replacement (from php manual)
*/
if (!function_exists('html_entity_decode'))
{
function html_entity_decode($given_html, $quote_style = ENT_QUOTES)
{
$trans_table = array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style));
$trans_table['&#39;'] = "'";
return (strtr($given_html, $trans_table));
}
}
/**
* A simple dectobase64 function
*/
function base64_pack($number)
{
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-';
$base = strlen($chars);
if ($number > 4096)
{
return;
}
else if ($number < $base)
{
return $chars[$number];
}
$hexval = '';
while ($number > 0)
{
$remainder = $number%$base;
if ($remainder < $base)
{
$hexval = $chars[$remainder] . $hexval;
}
$number = floor($number/$base);
}
return $hexval;
}
/**
* base64todec function
*/
function base64_unpack($string)
{
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-';
$base = strlen($chars);
$length = strlen($string);
$number = 0;
for($i = 1; $i <= $length; $i++)
{
$pos = $length - $i;
$operand = strpos($chars, substr($string,$pos,1));
$exponent = pow($base, $i-1);
$decValue = $operand * $exponent;
$number += $decValue;
}
return $number;
}
/**
* Per Forum based Extension Group Permissions (Encode Number) -> Theoretically up to 158 Forums saveable. :)
* We are using a base of 64, but splitting it to one-char and two-char numbers. :)
*/
function auth_pack($auth_array)
{
$one_char_encoding = '#';
$two_char_encoding = '.';
$one_char = $two_char = false;
$auth_cache = '';
for ($i = 0; $i < sizeof($auth_array); $i++)
{
$val = base64_pack(intval($auth_array[$i]));
if (strlen($val) == 1 && !$one_char)
{
$auth_cache .= $one_char_encoding;
$one_char = true;
}
else if (strlen($val) == 2 && !$two_char)
{
$auth_cache .= $two_char_encoding;
$two_char = true;
}
$auth_cache .= $val;
}
return $auth_cache;
}
/**
* Reverse the auth_pack process
*/
function auth_unpack($auth_cache)
{
$one_char_encoding = '#';
$two_char_encoding = '.';
$auth = array();
$auth_len = 1;
for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len)
{
$forum_auth = substr($auth_cache, $pos, 1);
if ($forum_auth == $one_char_encoding)
{
$auth_len = 1;
continue;
}
else if ($forum_auth == $two_char_encoding)
{
$auth_len = 2;
$pos--;
continue;
}
$forum_auth = substr($auth_cache, $pos, $auth_len);
$forum_id = base64_unpack($forum_auth);
$auth[] = intval($forum_id);
}
return $auth;
}
/**
* Used for determining if Forum ID is authed, please use this Function on all Posting Screens
*/
function is_forum_authed($auth_cache, $check_forum_id)
{
$one_char_encoding = '#';
$two_char_encoding = '.';
if (trim($auth_cache) == '')
{
return true;
}
$auth = array();
$auth_len = 1;
for ($pos = 0; $pos < strlen($auth_cache); $pos+=$auth_len)
{
$forum_auth = substr($auth_cache, $pos, 1);
if ($forum_auth == $one_char_encoding)
{
$auth_len = 1;
continue;
}
else if ($forum_auth == $two_char_encoding)
{
$auth_len = 2;
$pos--;
continue;
}
$forum_auth = substr($auth_cache, $pos, $auth_len);
$forum_id = (int) base64_unpack($forum_auth);
if ($forum_id == $check_forum_id)
{
return true;
}
}
return false;
}
/**
* Deletes an Attachment
*/
function unlink_attach($filename, $mode = false)
{
global $upload_dir, $attach_config;
$filename = basename($filename);
if ($mode == MODE_THUMBNAIL)
{
$filename = $upload_dir . '/' . THUMB_DIR . '/t_' . $filename;
}
else
{
$filename = $upload_dir . '/' . $filename;
}
$deleted = @unlink($filename);
return $deleted;
}
/**
* Check if Attachment exist
*/
function attachment_exists($filename)
{
global $upload_dir, $attach_config;
$filename = basename($filename);
if (!@file_exists(@amod_realpath($upload_dir . '/' . $filename)))
{
return false;
}
else
{
return true;
}
}
/**
* Check if Thumbnail exist
*/
function thumbnail_exists($filename)
{
global $upload_dir, $attach_config;
$filename = basename($filename);
if (!@file_exists(@amod_realpath($upload_dir . '/' . THUMB_DIR . '/t_' . $filename)))
{
return false;
}
else
{
return true;
}
}
/**
* Physical Filename stored already ?
*/
function physical_filename_already_stored($filename)
{
if ($filename == '')
{
return false;
}
$filename = basename($filename);
$sql = 'SELECT attach_id
FROM ' . BB_ATTACHMENTS_DESC . "
WHERE physical_filename = '" . attach_mod_sql_escape($filename) . "'
LIMIT 1";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not get attachment information for filename: ' . htmlspecialchars($filename));
}
$num_rows = DB()->num_rows($result);
DB()->sql_freeresult($result);
return ($num_rows == 0) ? false : true;
}
/**
* get all attachments from a post (could be an post array too)
*/
function get_attachments_from_post($post_id_array)
{
global $attach_config;
$attachments = array();
if (!is_array($post_id_array))
{
if (empty($post_id_array))
{
return $attachments;
}
$post_id = intval($post_id_array);
$post_id_array = array();
$post_id_array[] = $post_id;
}
$post_id_array = implode(', ', array_map('intval', $post_id_array));
if ($post_id_array == '')
{
return $attachments;
}
$display_order = (intval($attach_config['display_order']) == 0) ? 'DESC' : 'ASC';
$sql = 'SELECT a.post_id, d.*
FROM ' . BB_ATTACHMENTS . ' a, ' . BB_ATTACHMENTS_DESC . " d
WHERE a.post_id IN ($post_id_array)
AND a.attach_id = d.attach_id
ORDER BY d.filetime $display_order";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not get attachment informations for post number ' . $post_id_array);
}
$num_rows = DB()->num_rows($result);
$attachments = DB()->sql_fetchrowset($result);
DB()->sql_freeresult($result);
if ($num_rows == 0)
{
return array();
}
return $attachments;
}
/**
* Count Filesize of Attachments in Database based on the attachment id
*/
function get_total_attach_filesize($attach_ids)
{
if (!is_array($attach_ids) || !sizeof($attach_ids))
{
return 0;
}
$attach_ids = implode(', ', array_map('intval', $attach_ids));
if (!$attach_ids)
{
return 0;
}
$sql = 'SELECT filesize FROM ' . BB_ATTACHMENTS_DESC . " WHERE attach_id IN ($attach_ids)";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not query total filesize');
}
$total_filesize = 0;
while ($row = DB()->sql_fetchrow($result))
{
$total_filesize += (int) $row['filesize'];
}
DB()->sql_freeresult($result);
return $total_filesize;
}
/**
* Get allowed Extensions and their respective Values
*/
function get_extension_informations()
{
return $GLOBALS['datastore']->get('attach_extensions');
}
//
// Sync Topic
//
function attachment_sync_topic ($topics)
{
if (is_array($topics))
{
$topics = join(',', $topics);
}
$posts_without_attach = $topics_without_attach = array();
// Check orphan post_attachment markers
$sql = "SELECT p.post_id
FROM ". BB_POSTS ." p
LEFT JOIN ". BB_ATTACHMENTS ." a USING(post_id)
WHERE p.topic_id IN($topics)
AND p.post_attachment = 1
AND a.post_id IS NULL";
if ($rowset = DB()->fetch_rowset($sql))
{
foreach ($rowset as $row)
{
$posts_without_attach[] = $row['post_id'];
}
if ($posts_sql = join(',', $posts_without_attach))
{
DB()->query("UPDATE ". BB_POSTS ." SET post_attachment = 0 WHERE post_id IN($posts_sql)");
}
}
// Update missing topic_attachment markers
DB()->query("
UPDATE ". BB_TOPICS ." t, ". BB_POSTS ." p SET
t.topic_attachment = 1
WHERE p.topic_id IN($topics)
AND p.post_attachment = 1
AND p.topic_id = t.topic_id
");
// Fix orphan topic_attachment markers
$sql = "SELECT t.topic_id
FROM ". BB_POSTS ." p, ". BB_TOPICS ." t
WHERE t.topic_id = p.topic_id
AND t.topic_id IN($topics)
AND t.topic_attachment = 1
GROUP BY p.topic_id
HAVING SUM(p.post_attachment) = 0";
if ($rowset = DB()->fetch_rowset($sql))
{
foreach ($rowset as $row)
{
$topics_without_attach[] = $row['topic_id'];
}
if ($topics_sql = join(',', $topics_without_attach))
{
DB()->query("UPDATE ". BB_TOPICS ." SET topic_attachment = 0 WHERE topic_id IN($topics_sql)");
}
}
}
/**
* Get Extension
*/
function get_extension($filename)
{
if (!stristr($filename, '.'))
{
return '';
}
$extension = strrchr(strtolower($filename), '.');
$extension[0] = ' ';
$extension = strtolower(trim($extension));
if (is_array($extension))
{
return '';
}
else
{
return $extension;
}
}
/**
* Delete Extension
*/
function delete_extension($filename)
{
return substr($filename, 0, strrpos(strtolower(trim($filename)), '.'));
}
/**
* Check if a user is within Group
*/
function user_in_group($user_id, $group_id)
{
$user_id = (int) $user_id;
$group_id = (int) $group_id;
if (!$user_id || !$group_id)
{
return false;
}
$sql = 'SELECT u.group_id
FROM ' . BB_USER_GROUP . ' u, ' . BB_GROUPS . " g
WHERE g.group_single_user = 0
AND u.group_id = g.group_id
AND u.user_id = $user_id
AND g.group_id = $group_id
LIMIT 1";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not get user group');
}
$num_rows = DB()->num_rows($result);
DB()->sql_freeresult($result);
if ($num_rows == 0)
{
return false;
}
return true;
}
/**
* Realpath replacement for attachment mod
*/
function amod_realpath($path)
{
return (function_exists('realpath')) ? realpath($path) : $path;
}
/**
* _set_var
*
* Set variable, used by {@link get_var the get_var function}
*
* @private
*/
function _set_var(&$result, $var, $type, $multibyte = false)
{
settype($var, $type);
$result = $var;
if ($type == 'string')
{
$result = trim(str_replace(array("\r\n", "\r", '\xFF'), array("\n", "\n", ' '), $result));
// 2.0.x is doing addslashes on all variables
$result = stripslashes($result);
if ($multibyte)
{
$result = preg_replace('#&amp;(\#[0-9]+;)#', '&\1', $result);
}
}
}
/**
* get_var
*
* Used to get passed variable
*/
function get_var($var_name, $default, $multibyte = false)
{
$request_var = (isset($_POST[$var_name])) ? $_POST : $_GET;
if (!isset($request_var[$var_name]) || (is_array($request_var[$var_name]) && !is_array($default)) || (is_array($default) && !is_array($request_var[$var_name])))
{
return (is_array($default)) ? array() : $default;
}
$var = $request_var[$var_name];
if (!is_array($default))
{
$type = gettype($default);
}
else
{
list($key_type, $type) = each($default);
$type = gettype($type);
$key_type = gettype($key_type);
}
if (is_array($var))
{
$_var = $var;
$var = array();
foreach ($_var as $k => $v)
{
if (is_array($v))
{
foreach ($v as $_k => $_v)
{
_set_var($k, $k, $key_type);
_set_var($_k, $_k, $key_type);
_set_var($var[$k][$_k], $_v, $type, $multibyte);
}
}
else
{
_set_var($k, $k, $key_type);
_set_var($var[$k], $v, $type, $multibyte);
}
}
}
else
{
_set_var($var, $var, $type, $multibyte);
}
return $var;
}
/**
* Escaping SQL
*/
function attach_mod_sql_escape($text)
{
if (function_exists('mysql_real_escape_string'))
{
return DB()->escape_string($text);
}
else
{
return str_replace("'", "''", str_replace('\\', '\\\\', $text));
}
}
/**
* Build sql statement from array for insert/update/select statements
*
* Idea for this from Ikonboard
* Possible query values: INSERT, INSERT_SELECT, MULTI_INSERT, UPDATE, SELECT
*/
function attach_mod_sql_build_array($query, $assoc_ary = false)
{
if (!is_array($assoc_ary))
{
return false;
}
$fields = array();
$values = array();
if ($query == 'INSERT' || $query == 'INSERT_SELECT')
{
foreach ($assoc_ary as $key => $var)
{
$fields[] = $key;
if (is_null($var))
{
$values[] = 'NULL';
}
else if (is_string($var))
{
$values[] = "'" . attach_mod_sql_escape($var) . "'";
}
else if (is_array($var) && is_string($var[0]))
{
$values[] = $var[0];
}
else
{
$values[] = (is_bool($var)) ? intval($var) : $var;
}
}
$query = ($query == 'INSERT') ? ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')' : ' (' . implode(', ', $fields) . ') SELECT ' . implode(', ', $values) . ' ';
}
else if ($query == 'MULTI_INSERT')
{
$ary = array();
foreach ($assoc_ary as $id => $sql_ary)
{
$values = array();
foreach ($sql_ary as $key => $var)
{
if (is_null($var))
{
$values[] = 'NULL';
}
elseif (is_string($var))
{
$values[] = "'" . attach_mod_sql_escape($var) . "'";
}
else
{
$values[] = (is_bool($var)) ? intval($var) : $var;
}
}
$ary[] = '(' . implode(', ', $values) . ')';
}
$query = ' (' . implode(', ', array_keys($assoc_ary[0])) . ') VALUES ' . implode(', ', $ary);
}
else if ($query == 'UPDATE' || $query == 'SELECT')
{
$values = array();
foreach ($assoc_ary as $key => $var)
{
if (is_null($var))
{
$values[] = "$key = NULL";
}
elseif (is_string($var))
{
$values[] = "$key = '" . attach_mod_sql_escape($var) . "'";
}
else
{
$values[] = (is_bool($var)) ? "$key = " . intval($var) : "$key = $var";
}
}
$query = implode(($query == 'UPDATE') ? ', ' : ' AND ', $values);
}
return $query;
}

View file

@ -0,0 +1,284 @@
<?php
/**
* All Attachment Functions processing the Deletion Process
*/
/**
* Delete Attachment(s) from post(s) (intern)
*/
function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, $user_id = 0)
{
global $bb_cfg;
// Generate Array, if it's not an array
if ($post_id_array === 0 && $attach_id_array === 0 && $page === 0)
{
return;
}
if ($post_id_array === 0 && $attach_id_array !== 0)
{
$post_id_array = array();
if (!is_array($attach_id_array))
{
if (strstr($attach_id_array, ', '))
{
$attach_id_array = explode(', ', $attach_id_array);
}
else if (strstr($attach_id_array, ','))
{
$attach_id_array = explode(',', $attach_id_array);
}
else
{
$attach_id = intval($attach_id_array);
$attach_id_array = array();
$attach_id_array[] = $attach_id;
}
}
// Get the post_ids to fill the array
$p_id = 'post_id';
$sql = "SELECT $p_id
FROM " . BB_ATTACHMENTS . '
WHERE attach_id IN (' . implode(', ', $attach_id_array) . ")
GROUP BY $p_id";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not select ids');
}
$num_post_list = DB()->num_rows($result);
if ($num_post_list == 0)
{
DB()->sql_freeresult($result);
return;
}
while ($row = DB()->sql_fetchrow($result))
{
$post_id_array[] = intval($row[$p_id]);
}
DB()->sql_freeresult($result);
}
if (!is_array($post_id_array))
{
if (trim($post_id_array) == '')
{
return;
}
if (strstr($post_id_array, ', '))
{
$post_id_array = explode(', ', $post_id_array);
}
else if (strstr($post_id_array, ','))
{
$post_id_array = explode(',', $post_id_array);
}
else
{
$post_id = intval($post_id_array);
$post_id_array = array();
$post_id_array[] = $post_id;
}
}
if (!sizeof($post_id_array))
{
return;
}
// First of all, determine the post id and attach_id
if ($attach_id_array === 0)
{
$attach_id_array = array();
// Get the attach_ids to fill the array
$whereclause = 'WHERE post_id IN (' . implode(', ', $post_id_array) . ')';
$sql = 'SELECT attach_id
FROM ' . BB_ATTACHMENTS . " $whereclause
GROUP BY attach_id";
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not select attachment id #1');
}
$num_attach_list = DB()->num_rows($result);
if ($num_attach_list == 0)
{
DB()->sql_freeresult($result);
return;
}
while ($row = DB()->sql_fetchrow($result))
{
$attach_id_array[] = (int) $row['attach_id'];
}
DB()->sql_freeresult($result);
}
if (!is_array($attach_id_array))
{
if (strstr($attach_id_array, ', '))
{
$attach_id_array = explode(', ', $attach_id_array);
}
else if (strstr($attach_id_array, ','))
{
$attach_id_array = explode(',', $attach_id_array);
}
else
{
$attach_id = intval($attach_id_array);
$attach_id_array = array();
$attach_id_array[] = $attach_id;
}
}
if (!sizeof($attach_id_array))
{
return;
}
$sql_id = 'post_id';
if (sizeof($post_id_array) && sizeof($attach_id_array))
{
$sql = 'DELETE FROM ' . BB_ATTACHMENTS . '
WHERE attach_id IN (' . implode(', ', $attach_id_array) . ")
AND $sql_id IN (" . implode(', ', $post_id_array) . ')';
if (!(DB()->sql_query($sql)))
{
bb_die($lang['ERROR_DELETED_ATTACHMENTS']);
}
//bt
if ($sql_id == 'post_id')
{
$sql = "SELECT topic_id FROM ". BB_BT_TORRENTS ." WHERE attach_id IN(". implode(',', $attach_id_array) .")";
if (!$result = DB()->sql_query($sql))
{
bb_die($lang['ERROR_DELETED_ATTACHMENTS']);
}
$torrents_sql = array();
while ($row = DB()->sql_fetchrow($result))
{
$torrents_sql[] = $row['topic_id'];
}
if ($torrents_sql = implode(',', $torrents_sql))
{
// Remove peers from tracker
$sql = "DELETE FROM ". BB_BT_TRACKER ."
WHERE topic_id IN($torrents_sql)";
if (!DB()->sql_query($sql))
{
bb_die('Could not delete peers');
}
}
// Delete torrents
$sql = "DELETE FROM ". BB_BT_TORRENTS ."
WHERE attach_id IN(". implode(',', $attach_id_array) .")";
if (!DB()->sql_query($sql))
{
bb_die($lang['ERROR_DELETED_ATTACHMENTS']);
}
}
//bt end
for ($i = 0; $i < sizeof($attach_id_array); $i++)
{
$sql = 'SELECT attach_id
FROM ' . BB_ATTACHMENTS . '
WHERE attach_id = ' . (int) $attach_id_array[$i];
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not select Attachment id #2');
}
$num_rows = DB()->num_rows($result);
DB()->sql_freeresult($result);
if ($num_rows == 0)
{
$sql = 'SELECT attach_id, physical_filename, thumbnail
FROM ' . BB_ATTACHMENTS_DESC . '
WHERE attach_id = ' . (int) $attach_id_array[$i];
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not query attach description table');
}
$num_rows = DB()->num_rows($result);
if ($num_rows != 0)
{
$num_attach = $num_rows;
$attachments = DB()->sql_fetchrowset($result);
DB()->sql_freeresult($result);
// delete attachments
for ($j = 0; $j < $num_attach; $j++)
{
unlink_attach($attachments[$j]['physical_filename']);
if (intval($attachments[$j]['thumbnail']) == 1)
{
unlink_attach($attachments[$j]['physical_filename'], MODE_THUMBNAIL);
}
$sql = 'DELETE FROM ' . BB_ATTACHMENTS_DESC . ' WHERE attach_id = ' . (int) $attachments[$j]['attach_id'];
if (!(DB()->sql_query($sql)))
{
bb_die($lang['ERROR_DELETED_ATTACHMENTS']);
}
}
}
else
{
DB()->sql_freeresult($result);
}
}
}
}
// Now Sync the Topic/PM
if (sizeof($post_id_array))
{
$sql = 'SELECT topic_id
FROM ' . BB_POSTS . '
WHERE post_id IN (' . implode(', ', $post_id_array) . ')
GROUP BY topic_id';
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not select topic id');
}
while ($row = DB()->sql_fetchrow($result))
{
attachment_sync_topic($row['topic_id']);
}
DB()->sql_freeresult($result);
}
}

View file

@ -0,0 +1,293 @@
<?php
/**
* All Attachment Functions needed to determine Special Files/Dimensions
*/
/**
* Read Long Int (4 Bytes) from File
*/
function read_longint($fp)
{
$data = fread($fp, 4);
$value = ord($data[0]) + (ord($data[1])<<8)+(ord($data[2])<<16)+(ord($data[3])<<24);
if ($value >= 4294967294)
{
$value -= 4294967296;
}
return $value;
}
/**
* Read Word (2 Bytes) from File - Note: It's an Intel Word
*/
function read_word($fp)
{
$data = fread($fp, 2);
$value = ord($data[1]) * 256 + ord($data[0]);
return $value;
}
/**
* Read Byte
*/
function read_byte($fp)
{
$data = fread($fp, 1);
$value = ord($data);
return $value;
}
/**
* Get Image Dimensions
*/
function image_getdimension($file)
{
$size = @getimagesize($file);
if ($size[0] != 0 || $size[1] != 0)
{
return $size;
}
// Try to get the Dimension manually, depending on the mimetype
$fp = @fopen($file, 'rb');
if (!$fp)
{
return $size;
}
$error = FALSE;
// BMP - IMAGE
$tmp_str = fread($fp, 2);
if ($tmp_str == 'BM')
{
$length = read_longint($fp);
if ($length <= 6)
{
$error = true;
}
if (!$error)
{
$i = read_longint($fp);
if ( $i != 0)
{
$error = true;
}
}
if (!$error)
{
$i = read_longint($fp);
if ($i != 0x3E && $i != 0x76 && $i != 0x436 && $i != 0x36)
{
$error = true;
}
}
if (!$error)
{
$tmp_str = fread($fp, 4);
$width = read_longint($fp);
$height = read_longint($fp);
if ($width > 3000 || $height > 3000)
{
$error = true;
}
}
}
else
{
$error = true;
}
if (!$error)
{
fclose($fp);
return array(
$width,
$height,
6
);
}
$error = false;
fclose($fp);
// GIF - IMAGE
$fp = @fopen($file, 'rb');
$tmp_str = fread($fp, 3);
if ($tmp_str == 'GIF')
{
$tmp_str = fread($fp, 3);
$width = read_word($fp);
$height = read_word($fp);
$info_byte = fread($fp, 1);
$info_byte = ord($info_byte);
if (($info_byte & 0x80) != 0x80 && ($info_byte & 0x80) != 0)
{
$error = true;
}
if (!$error)
{
if (($info_byte & 8) != 0)
{
$error = true;
}
}
}
else
{
$error = true;
}
if (!$error)
{
fclose($fp);
return array(
$width,
$height,
1
);
}
$error = false;
fclose($fp);
// JPG - IMAGE
$fp = @fopen($file, 'rb');
$tmp_str = fread($fp, 4);
$w1 = read_word($fp);
if (intval($w1) < 16)
{
$error = true;
}
if (!$error)
{
$tmp_str = fread($fp, 4);
if ($tmp_str == 'JFIF')
{
$o_byte = fread($fp, 1);
if (intval($o_byte) != 0)
{
$error = true;
}
if (!$error)
{
$str = fread($fp, 2);
$b = read_byte($fp);
if ($b != 0 && $b != 1 && $b != 2)
{
$error = true;
}
}
if (!$error)
{
$width = read_word($fp);
$height = read_word($fp);
if ($width <= 0 || $height <= 0)
{
$error = true;
}
}
}
}
else
{
$error = true;
}
if (!$error)
{
fclose($fp);
return array(
$width,
$height,
2
);
}
$error = false;
fclose($fp);
// PCX - IMAGE
$fp = @fopen($file, 'rb');
$tmp_str = fread($fp, 3);
if ((ord($tmp_str[0]) == 10) && (ord($tmp_str[1]) == 0 || ord($tmp_str[1]) == 2 || ord($tmp_str[1]) == 3 || ord($tmp_str[1]) == 4 || ord($tmp_str[1]) == 5) && (ord($tmp_str[2]) == 1))
{
$b = fread($fp, 1);
if (ord($b) != 1 && ord($b) != 2 && ord($b) != 4 && ord($b) != 8 && ord($b) != 24)
{
$error = true;
}
if (!$error)
{
$xmin = read_word($fp);
$ymin = read_word($fp);
$xmax = read_word($fp);
$ymax = read_word($fp);
$tmp_str = fread($fp, 52);
$b = fread($fp, 1);
if ($b != 0)
{
$error = true;
}
}
if (!$error)
{
$width = $xmax - $xmin + 1;
$height = $ymax - $ymin + 1;
}
}
else
{
$error = true;
}
if (!$error)
{
fclose($fp);
return array(
$width,
$height,
7
);
}
fclose($fp);
return $size;
}

View file

@ -0,0 +1,204 @@
<?php
/**
* Setup s_auth_can in viewforum and viewtopic (viewtopic.php/viewforum.php)
*/
function attach_build_auth_levels($is_auth, &$s_auth_can)
{
global $lang, $attach_config;
if (intval($attach_config['disable_mod']))
{
return;
}
// If you want to have the rules window link within the forum view too, comment out the two lines, and comment the third line
$s_auth_can .= (($is_auth['auth_attachments']) ? $lang['RULES_ATTACH_CAN'] : $lang['RULES_ATTACH_CANNOT'] ) . '<br />';
$s_auth_can .= (($is_auth['auth_download']) ? $lang['RULES_DOWNLOAD_CAN'] : $lang['RULES_DOWNLOAD_CANNOT'] ) . '<br />';
}
/**
* Called from admin_users.php and admin_groups.php in order to process Quota Settings (admin/admin_users.php:admin/admin_groups.php)
*/
function attachment_quota_settings($admin_mode, $submit = false, $mode)
{
global $template, $lang, $attach_config;
if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':'))
{
$upload_dir = $attach_config['upload_dir'];
}
else
{
$upload_dir = BB_ROOT . $attach_config['upload_dir'];
}
include(ATTACH_DIR .'includes/functions_selects.php');
if (!function_exists("process_quota_settings"))
include(ATTACH_DIR . 'includes/functions_admin.php');
$user_id = 0;
if ($admin_mode == 'user')
{
// We overwrite submit here... to be sure
$submit = (isset($_POST['submit'])) ? true : false;
if (!$submit && $mode != 'save')
{
$user_id = get_var(POST_USERS_URL, 0);
$u_name = get_var('username', '');
if (!$user_id && !$u_name)
{
bb_die($lang['NO_USER_ID_SPECIFIED'] );
}
if ($user_id)
{
$this_userdata['user_id'] = $user_id;
}
else
{
// Get userdata is handling the sanitizing of username
$this_userdata = get_userdata($_POST['username'], true);
}
$user_id = (int) $this_userdata['user_id'];
}
else
{
$user_id = get_var('id', 0);
if (!$user_id)
{
bb_die($lang['NO_USER_ID_SPECIFIED'] );
}
}
}
if ($admin_mode == 'user' && !$submit && $mode != 'save')
{
// Show the contents
$sql = 'SELECT quota_limit_id, quota_type FROM ' . BB_QUOTA . ' WHERE user_id = ' . (int) $user_id;
if (!($result = DB()->sql_query($sql)))
{
bb_die('Unable to get quota settings #1');
}
$pm_quota = $upload_quota = 0;
if ($row = DB()->sql_fetchrow($result))
{
do
{
if ($row['quota_type'] == QUOTA_UPLOAD_LIMIT)
{
$upload_quota = $row['quota_limit_id'];
}
else if ($row['quota_type'] == QUOTA_PM_LIMIT)
{
$pm_quota = $row['quota_limit_id'];
}
}
while ($row = DB()->sql_fetchrow($result));
}
else
{
// Set Default Quota Limit
$upload_quota = $attach_config['default_upload_quota'];
$pm_quota = $attach_config['default_pm_quota'];
}
DB()->sql_freeresult($result);
$template->assign_vars(array(
'S_SELECT_UPLOAD_QUOTA' => quota_limit_select('user_upload_quota', $upload_quota),
'S_SELECT_PM_QUOTA' => quota_limit_select('user_pm_quota', $pm_quota),
));
}
if ($admin_mode == 'user' && $submit && @$_POST['delete_user'])
{
process_quota_settings($admin_mode, $user_id, QUOTA_UPLOAD_LIMIT, 0);
process_quota_settings($admin_mode, $user_id, QUOTA_PM_LIMIT, 0);
}
else if ($admin_mode == 'user' && $submit && $mode == 'save')
{
// Get the contents
$upload_quota = get_var('user_upload_quota', 0);
$pm_quota = get_var('user_pm_quota', 0);
process_quota_settings($admin_mode, $user_id, QUOTA_UPLOAD_LIMIT, $upload_quota);
process_quota_settings($admin_mode, $user_id, QUOTA_PM_LIMIT, $pm_quota);
}
if ($admin_mode == 'group' && $mode == 'newgroup')
{
return;
}
if ($admin_mode == 'group' && !$submit && isset($_POST['edit']))
{
// Get group id again
$group_id = get_var(POST_GROUPS_URL, 0);
// Show the contents
$sql = 'SELECT quota_limit_id, quota_type FROM ' . BB_QUOTA . ' WHERE group_id = ' . (int) $group_id;
if (!($result = DB()->sql_query($sql)))
{
bb_die('Unable to get quota settings #2');
}
$pm_quota = $upload_quota = 0;
if ($row = DB()->sql_fetchrow($result))
{
do
{
if ($row['quota_type'] == QUOTA_UPLOAD_LIMIT)
{
$upload_quota = $row['quota_limit_id'];
}
else if ($row['quota_type'] == QUOTA_PM_LIMIT)
{
$pm_quota = $row['quota_limit_id'];
}
}
while ($row = DB()->sql_fetchrow($result));
}
else
{
// Set Default Quota Limit
$upload_quota = $attach_config['default_upload_quota'];
$pm_quota = $attach_config['default_pm_quota'];
}
DB()->sql_freeresult($result);
$template->assign_vars(array(
'S_SELECT_UPLOAD_QUOTA' => quota_limit_select('group_upload_quota', $upload_quota),
'S_SELECT_PM_QUOTA' => quota_limit_select('group_pm_quota', $pm_quota),
));
}
if ($admin_mode == 'group' && $submit && isset($_POST['group_delete']))
{
$group_id = get_var(POST_GROUPS_URL, 0);
process_quota_settings($admin_mode, $group_id, QUOTA_UPLOAD_LIMIT, 0);
process_quota_settings($admin_mode, $group_id, QUOTA_PM_LIMIT, 0);
}
else if ($admin_mode == 'group' && $submit)
{
$group_id = get_var(POST_GROUPS_URL, 0);
// Get the contents
$upload_quota = get_var('group_upload_quota', 0);
$pm_quota = get_var('group_pm_quota', 0);
process_quota_settings($admin_mode, $group_id, QUOTA_UPLOAD_LIMIT, $upload_quota);
process_quota_settings($admin_mode, $group_id, QUOTA_PM_LIMIT, $pm_quota);
}
}

View file

@ -0,0 +1,251 @@
<?php
/**
* Functions to build select boxes ;)
*/
/**
* select group
*/
function group_select($select_name, $default_group = 0)
{
global $lang;
$sql = 'SELECT group_id, group_name FROM ' . BB_EXTENSION_GROUPS . ' ORDER BY group_name';
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not query extension groups table #1');
}
$group_select = '<select name="' . $select_name . '">';
$group_name = DB()->sql_fetchrowset($result);
$num_rows = DB()->num_rows($result);
DB()->sql_freeresult($result);
if ($num_rows > 0)
{
$group_name[$num_rows]['group_id'] = 0;
$group_name[$num_rows]['group_name'] = $lang['NOT_ASSIGNED'];
for ($i = 0; $i < sizeof($group_name); $i++)
{
if (!$default_group)
{
$selected = ($i == 0) ? ' selected="selected"' : '';
}
else
{
$selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : '';
}
$group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
}
}
$group_select .= '</select>';
return $group_select;
}
/**
* select download mode
*/
function download_select($select_name, $group_id = 0)
{
global $types_download, $modes_download;
if ($group_id)
{
$sql = 'SELECT download_mode
FROM ' . BB_EXTENSION_GROUPS . '
WHERE group_id = ' . (int) $group_id;
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not query extension groups table #2');
}
$row = DB()->sql_fetchrow($result);
DB()->sql_freeresult($result);
if (!isset($row['download_mode']))
{
return '';
}
$download_mode = $row['download_mode'];
}
$group_select = '<select name="' . $select_name . '">';
for ($i = 0; $i < sizeof($types_download); $i++)
{
if (!$group_id)
{
$selected = ($types_download[$i] == INLINE_LINK) ? ' selected="selected"' : '';
}
else
{
$selected = ($row['download_mode'] == $types_download[$i]) ? ' selected="selected"' : '';
}
$group_select .= '<option value="' . $types_download[$i] . '"' . $selected . '>' . $modes_download[$i] . '</option>';
}
$group_select .= '</select>';
return $group_select;
}
/**
* select category types
*/
function category_select($select_name, $group_id = 0)
{
global $types_category, $modes_category;
$sql = 'SELECT group_id, cat_id FROM ' . BB_EXTENSION_GROUPS;
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not select category');
}
$rows = DB()->sql_fetchrowset($result);
$num_rows = DB()->num_rows($result);
DB()->sql_freeresult($result);
$type_category = 0;
if ($num_rows > 0)
{
for ($i = 0; $i < $num_rows; $i++)
{
if ($group_id == $rows[$i]['group_id'])
{
$category_type = $rows[$i]['cat_id'];
}
}
}
$types = array(NONE_CAT);
$modes = array('none');
for ($i = 0; $i < sizeof($types_category); $i++)
{
$types[] = $types_category[$i];
$modes[] = $modes_category[$i];
}
$group_select = '<select name="' . $select_name . '" style="width:100px">';
for ($i = 0; $i < sizeof($types); $i++)
{
if (!$group_id)
{
$selected = ($types[$i] == NONE_CAT) ? ' selected="selected"' : '';
}
else
{
$selected = ($types[$i] == $category_type) ? ' selected="selected"' : '';
}
$group_select .= '<option value="' . $types[$i] . '"' . $selected . '>' . $modes[$i] . '</option>';
}
$group_select .= '</select>';
return $group_select;
}
/**
* Select size mode
*/
function size_select($select_name, $size_compare)
{
global $lang;
$size_types_text = array($lang['BYTES'], $lang['KB'], $lang['MB']);
$size_types = array('b', 'kb', 'mb');
$select_field = '<select name="' . $select_name . '">';
for ($i = 0; $i < sizeof($size_types_text); $i++)
{
$selected = ($size_compare == $size_types[$i]) ? ' selected="selected"' : '';
$select_field .= '<option value="' . $size_types[$i] . '"' . $selected . '>' . $size_types_text[$i] . '</option>';
}
$select_field .= '</select>';
return $select_field;
}
/**
* select quota limit
*/
function quota_limit_select($select_name, $default_quota = 0)
{
global $lang;
$sql = 'SELECT quota_limit_id, quota_desc FROM ' . BB_QUOTA_LIMITS . ' ORDER BY quota_limit ASC';
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not query quota limits table #1');
}
$quota_select = '<select name="' . $select_name . '">';
$quota_name[0]['quota_limit_id'] = 0;
$quota_name[0]['quota_desc'] = $lang['NOT_ASSIGNED'];
while ($row = DB()->sql_fetchrow($result))
{
$quota_name[] = $row;
}
DB()->sql_freeresult($result);
for ($i = 0; $i < sizeof($quota_name); $i++)
{
$selected = ($quota_name[$i]['quota_limit_id'] == $default_quota) ? ' selected="selected"' : '';
$quota_select .= '<option value="' . $quota_name[$i]['quota_limit_id'] . '"' . $selected . '>' . $quota_name[$i]['quota_desc'] . '</option>';
}
$quota_select .= '</select>';
return $quota_select;
}
/**
* select default quota limit
*/
function default_quota_limit_select($select_name, $default_quota = 0)
{
global $lang;
$sql = 'SELECT quota_limit_id, quota_desc FROM ' . BB_QUOTA_LIMITS . ' ORDER BY quota_limit ASC';
if (!($result = DB()->sql_query($sql)))
{
bb_die('Could not query quota limits table #2');
}
$quota_select = '<select name="' . $select_name . '">';
$quota_name[0]['quota_limit_id'] = 0;
$quota_name[0]['quota_desc'] = $lang['NO_QUOTA_LIMIT'];
while ($row = DB()->sql_fetchrow($result))
{
$quota_name[] = $row;
}
DB()->sql_freeresult($result);
for ($i = 0; $i < sizeof($quota_name); $i++)
{
$selected = ( $quota_name[$i]['quota_limit_id'] == $default_quota ) ? ' selected="selected"' : '';
$quota_select .= '<option value="' . $quota_name[$i]['quota_limit_id'] . '"' . $selected . '>' . $quota_name[$i]['quota_desc'] . '</option>';
}
$quota_select .= '</select>';
return $quota_select;
}

View file

@ -0,0 +1,189 @@
<?php
if (!defined('IN_FORUM')) die("Hacking attempt");
$imagick = '';
/**
* Calculate the needed size for Thumbnail
*/
function get_img_size_format($width, $height)
{
// Maximum Width the Image can take
$max_width = 400;
if ($width > $height)
{
return array(
round($width * ($max_width / $width)),
round($height * ($max_width / $width))
);
}
else
{
return array(
round($width * ($max_width / $height)),
round($height * ($max_width / $height))
);
}
}
/**
* Check if imagick is present
*/
function is_imagick()
{
global $imagick, $attach_config;
if ($attach_config['img_imagick'] != '')
{
$imagick = $attach_config['img_imagick'];
return true;
}
else
{
return false;
}
}
/**
* Get supported image types
*/
function get_supported_image_types($type)
{
if (@extension_loaded('gd'))
{
$format = imagetypes();
$new_type = 0;
switch ($type)
{
case 1:
$new_type = ($format & IMG_GIF) ? IMG_GIF : 0;
break;
case 2:
case 9:
case 10:
case 11:
case 12:
$new_type = ($format & IMG_JPG) ? IMG_JPG : 0;
break;
case 3:
$new_type = ($format & IMG_PNG) ? IMG_PNG : 0;
break;
case 6:
case 15:
$new_type = ($format & IMG_WBMP) ? IMG_WBMP : 0;
break;
}
return array(
'gd' => ($new_type) ? true : false,
'format' => $new_type,
'version' => (function_exists('imagecreatetruecolor')) ? 2 : 1
);
}
return array('gd' => false);
}
/**
* Create thumbnail
*/
function create_thumbnail($source, $new_file, $mimetype)
{
global $attach_config, $imagick;
$source = amod_realpath($source);
$min_filesize = (int) $attach_config['img_min_thumb_filesize'];
$img_filesize = (@file_exists($source)) ? @filesize($source) : false;
if (!$img_filesize || $img_filesize <= $min_filesize)
{
return false;
}
list($width, $height, $type, ) = getimagesize($source);
if (!$width || !$height)
{
return false;
}
list($new_width, $new_height) = get_img_size_format($width, $height);
$tmp_path = $old_file = '';
$used_imagick = false;
if (is_imagick())
{
passthru($imagick . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $new_file) . '"');
if (@file_exists($new_file))
{
$used_imagick = true;
}
}
if (!$used_imagick)
{
$type = get_supported_image_types($type);
if ($type['gd'])
{
switch ($type['format'])
{
case IMG_GIF:
$image = imagecreatefromgif($source);
break;
case IMG_JPG:
$image = imagecreatefromjpeg($source);
break;
case IMG_PNG:
$image = imagecreatefrompng($source);
break;
case IMG_WBMP:
$image = imagecreatefromwbmp($source);
break;
}
if ($type['version'] == 1 || !$attach_config['use_gd2'])
{
$new_image = imagecreate($new_width, $new_height);
imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
}
else
{
$new_image = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
}
switch ($type['format'])
{
case IMG_GIF:
imagegif($new_image, $new_file);
break;
case IMG_JPG:
imagejpeg($new_image, $new_file, 90);
break;
case IMG_PNG:
imagepng($new_image, $new_file);
break;
case IMG_WBMP:
imagewbmp($new_image, $new_file);
break;
}
imagedestroy($new_image);
}
}
if (!@file_exists($new_file))
{
return false;
}
@chmod($new_file, 0664);
return true;
}

File diff suppressed because it is too large Load diff