Академический Документы
Профессиональный Документы
Культура Документы
php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 5.0.5 - Licence Number VBFZ48KZZQ
|| # ---------------------------------------------------------------- # ||
|| # Copyright 2000-2013 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
@set_time_limit(0);
// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('CVS_REVISION', '$RCSfile$ - $Revision: 76965 $');
// #################### PRE-CACHE TEMPLATES AND DATA ######################
global $phrasegroups, $specialtemplates, $vbphrase, $vbulletin;
$phrasegroups = array('attachment_image');
$specialtemplates = array();
// ########################## REQUIRE BACK-END ############################
require_once(dirname(__FILE__) . '/global.php');
require_once(DIR . '/includes/adminfunctions_attachment.php');
require_once(DIR . '/includes/functions_file.php');
//require_once(DIR . '/packages/vbattach/attach.php');
// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminthreads'))
{
print_cp_no_permission();
}
// ############################# LOG ACTION ###############################
$vbulletin->input->clean_array_gpc('r', array(
'nodeid' => vB_Cleaner::TYPE_INT,
'extension'
=> vB_Cleaner::TYPE_STR,
'attachpath' => vB_Cleaner::TYPE_STR,
'dowhat'
=> vB_Cleaner::TYPE_STR,
));
log_admin_action(iif($vbulletin->GPC['nodeid'] != 0, 'node id = ' . $vbulletin->
GPC['nodeid'],
iif(!empty($vbulletin->GPC['extension']), "extension = " . $vbulletin->G
PC['extension'], '')));
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
$vboptions = vB::getDatastore()->getValue('options');
$vb5_config =& vB::getConfig();
$baseurl = vB::getDatastore()->getOption('frontendurl');
if ($vb5_config['report_all_php_errors'])
{
@ini_set('display_errors', 'On');
}
print_cp_header($vbphrase['attachment_manager_gattachment_image']);
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'intro';
}
// ###################### Swap from database to file system and vice versa #####
#####
if ($_REQUEST['do'] == 'storage')
{
if ($vboptions['attachfile'])
{
$options = array(
'FS_to_DB' => $vbphrase['move_items_from_filesystem_into
_database'],
'FS_to_FS' => $vbphrase['move_items_to_a_different_direc
tory']
);
}
else
{
$options = array(
'DB_to_FS' => $vbphrase['move_items_from_database_into_f
ilesystem']
);
}
$i = 0;
$dowhat = '';
foreach($options AS $value => $text)
{
$dowhat .= "<label for=\"dw$value\"><input type=\"radio\" name=\
"dowhat\" id=\"dw$value\" value=\"$value\"" . iif($i++ == 0, ' checked="checked"
') . " />$text</label><br />";
}
print_form_header('attachment', 'switchtype');
print_table_header("$vbphrase[storage_type]: <span class=\"normal\">$vbp
hrase[attachments]</span>");
if ($vboptions['attachfile'])
{
print_description_row(construct_phrase($vbphrase['attachments_ar
e_currently_being_stored_in_the_filesystem_at_x'], '<b>' . $vboptions['attachpat
h'] . '</b>'));
}
else
{
print_description_row($vbphrase['attachments_are_currently_being
_stored_in_the_database']);
}
print_label_row($vbphrase['action'], $dowhat);
print_submit_row($vbphrase['go'], 0);
}
// ###################### Swap from database to file system and vice versa #####
#####
if ($_REQUEST['do'] == 'switchtype')
{
$vbulletin->input->clean_array_gpc('r', array(
'dowhat'
=> vB_Cleaner::TYPE_STR
));
if ($vbulletin->GPC['dowhat'] == 'FS_to_DB')
{
// redirect straight through to attachment mover
$vbulletin->GPC['attachpath'] = $vboptions['attachpath'];
$vbulletin->GPC['dowhat'] = 'FS_to_DB';
$_POST['do'] = 'doswitchtype';
}
else
{
if ($vbulletin->GPC['dowhat'] == 'FS_to_FS')
{
// show a form to allow user to specify file path
print_form_header('attachment', 'doswitchtype');
construct_hidden_code('dowhat', $vbulletin->GPC['dowhat'
]);
print_table_header($vbphrase['move_items_to_a_different_
directory']);
print_description_row(construct_phrase($vbphrase['attach
ments_are_currently_being_stored_in_the_filesystem_at_x'], '<b>' . $vboptions['a
ttachpath'] . '</b>'));
}
else
{
if (SAFEMODE)
{
// Attachments as files is not compatible with s
afe_mode since it creates directories
// Safe_mode does not allow you to write to dire
ctories created by PHP
print_stop_message2('your_server_has_safe_mode_e
nabled');
}
// show a form to allow user to specify file path
print_form_header('attachment', 'doswitchtype');
construct_hidden_code('dowhat', $vbulletin->GPC['dowhat'
]);
print_table_header($vbphrase['move_items_from_database_i
nto_filesystem']);
print_description_row($vbphrase['attachments_are_current
ly_being_stored_in_the_database']);
}
print_input_row($vbphrase['attachment_file_path_dfn'], 'attachpa
th', $vboptions['attachpath']);
print_submit_row($vbphrase['go']);
}
}
// ############### Move files from database to file system and vice versa ######
#####
if ($_POST['do'] == 'doswitchtype')
{
$vbulletin->GPC['attachpath'] = preg_replace('#[/\\\]+$#', '', $vbulleti
n->GPC['attachpath']);
switch($vbulletin->GPC['dowhat'])
{
// #############################################################
################
// update attachment file path
case 'FS_to_FS':
if ($vbulletin->GPC['attachpath'] === $vboptions['attach
path'])
{
// new and old path are the same - show error
print_stop_message2('invalid_file_path_specified
');
}
else
{
// new and old paths are different - check the d
irectory is valid
verify_upload_folder($vbulletin->GPC['attachpath
']);
$oldpath = $vboptions['attachpath'];
// update $vboptions
vB_Api::instanceInternal('options')->updateValue
('attachpath', $vbulletin->GPC['attachpath']);
// show message
print_stop_message2(array('your_vb_settings_have
_been_updated_to_store_attachments_in_x', $vbulletin->GPC['attachpath'], $oldpat
h));
}
break;
// #############################################################
################
// move attachments from database to filesystem
case 'DB_to_FS':
// check path is valid
verify_upload_folder($vbulletin->GPC['attachpath']);
// update $vboptions
vB_Api::instanceInternal('options')->updateValue('attach
path', $vbulletin->GPC['attachpath']);
break;
}
// #####################################################################
########
print_form_header('attachment', 'domoveattachment');
print_table_header($vbphrase['edit_storage_type']);
construct_hidden_code('dowhat', $vbulletin->GPC['dowhat']);
if ($vbulletin->GPC['dowhat'] == 'DB_to_FS')
{
print_description_row($vbphrase['we_are_ready_to_attempt_to_move
_your_attachments_from_database_to_filesystem']);
}
else
{
print_description_row($vbphrase['we_are_ready_to_attempt_to_move
_your_attachments_from_filesystem_to_database']);
}
print_input_row($vbphrase['number_of_attachments_to_process_per_cycle_ga
ttachment_image'], 'perpage', 300, 1, 5);
if ($vb5_config['Misc']['debug'])
{
print_input_row($vbphrase['attachmentid_start_at'], 'startat', 0
, 1, 5);
}
print_submit_row($vbphrase['go']);
}
// ################### Move attachments ######################################
if ($_REQUEST['do'] == 'domoveattachment')
{
$vbulletin->input->clean_array_gpc('r', array(
'perpage'
=> vB_Cleaner::TYPE_UINT,
'startat'
=> vB_Cleaner::TYPE_UINT,
'attacherrorcount' => vB_Cleaner::TYPE_UINT,
'count'
=> vB_Cleaner::TYPE_UINT
));
if (is_demo_mode())
{
print_cp_message('This function is disabled within demo mode');
}
if ($vbulletin->GPC['perpage'] < 1)
{
$vbulletin->GPC['perpage'] = 10;
}
if (empty($vbulletin->GPC['startat'])) // Grab the first attachmentid so
that we don't process a bunch of nonexistent ids to begin with.
{
$start = vB::getDbAssertor()->getRow('vBForum:fetchMinFiledataId
');
$vbulletin->GPC['startat'] = intval($start['min']);
}
$finishat = $vbulletin->GPC['startat'] + $vbulletin->GPC['perpage'];
// echo '<p>' . $vbphrase['attachments'] . '</p>';
$attachments = vB::getDbAssertor()->assertQuery('filedata', array(
vB_dB_Query::CONDITIONS_KEY => array(
array('field' => 'filedataid', 'value' => $vbull
etin->GPC['startat'], 'operator' => vB_dB_Query::OPERATOR_GTE),
array('field' => 'filedataid', 'value' => $finis
hat, 'operator' => vB_dB_Query::OPERATOR_LT),
)
),
array('field' => 'filedataid', 'direction' => vB_dB_Query::SORT_
ASC)
);
if ($vb5_config['Misc']['debug'])
{
echo '<table width="100%" border="1" cellspacing="0" cellpadding
="1">
<tr>
<td><b>Filedata ID</b></td><td><b>Size in Databa
se</b></td><td><b>Size in Filesystem</b></td>
</tr>
';
}
$attachments_count = 0;
foreach ($attachments as $attachment)
{
$vbulletin->GPC['count']++;
$attachments_count ++;
$attacherror = false;
$fileData = vB::getDbAssertor()->getRows(
"vBForum:filedataresize", array(
vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELE
CT,
'filedataid' => $attachment['filedataid']
));
//
if ($vboptions['attachfile'] == ATTACH_AS_DB)
{ // Converting FROM mysql TO fs
$vboptions['attachfile'] = ATTACH_AS_FILES_NEW;
//
}
$vboptions['attachfile'] = ATTACH_AS_DB;
}
else
{ // Converting FROM fs TO mysql
$path = fetch_attachment_path($attachment['userid'], $at
tachment['filedataid']);
//
$temp = $vboptions['attachfile'];
$vboptions['attachfile'] = ATTACH_AS_DB;
if ($filedata = @file_get_contents($path))
{
$filesize = filesize($path);
$attachdata = new vB_Datamanager_Filedata($vbull
etin, vB_DataManager_Constants::ERRTYPE_SILENT);
$attachdata->setStorage(ATTACH_AS_DB);
$attachdata->set_existing($attachment);
$attachdata->setr('filedata', $filedata);
if (!($result = $attachdata->save()))
{
if (empty($attachdata->errors[0]))
{
$attacherror = fetch_error('uplo
ad_file_failed'); // change this error
}
else
{
$attacherror =& $attachdata->err
ors[0];
}
}
$thumbnail_path = fetch_attachment_path($attachm
ent['userid'], $attachment['filedataid'], vB_Api_Filedata::SIZE_THUMB);
$icon_path = fetch_attachment_path($attachment['
userid'], $attachment['filedataid'], vB_Api_Filedata::SIZE_ICON);
$small_path = fetch_attachment_path($attachment[
'userid'], $attachment['filedataid'], vB_Api_Filedata::SIZE_SMALL);
$medium_path = fetch_attachment_path($attachment
['userid'], $attachment['filedataid'], vB_Api_Filedata::SIZE_MEDIUM);
$large_path = fetch_attachment_path($attachment[
'userid'], $attachment['filedataid'], vB_Api_Filedata::SIZE_LARGE);
if ($filedata = @file_get_contents($thumbnail_pa
th))
{
vB::getDbAssertor()->update('vBForum:fil
edataresize',
array(
'resize_filedata' => $fi
ledata
),
array(
'filedataid' => $attach
ment['filedataid'],
'resize_type' => vB_Api_
Filedata::SIZE_THUMB
));
}
if ($filedata = @file_get_contents($icon_path))
{
vB::getDbAssertor()->update('vBForum:fil
edataresize',
array(
'resize_filedata' => $fi
ledata
),
array(
'filedataid' => $attach
ment['filedataid'],
'resize_type' => vB_Api_
Filedata::SIZE_ICON
));
}
if ($filedata = @file_get_contents($small_path))
{
vB::getDbAssertor()->update('vBForum:fil
edataresize',
array(
'resize_filedata' => $fi
ledata
),
array(
'filedataid' => $attach
ment['filedataid'],
'resize_type' => vB_Api_
Filedata::SIZE_SMALL
));
}
if ($filedata = @file_get_contents($medium_path)
)
{
vB::getDbAssertor()->update('vBForum:fil
edataresize',
array(
'resize_filedata' => $fi
ledata
),
array(
'filedataid' => $attach
ment['filedataid'],
'resize_type' => vB_Api_
Filedata::SIZE_MEDIUM
));
}
if ($filedata = @file_get_contents($medium_path)
)
{
vB::getDbAssertor()->update('vBForum:fil
edataresize',
array(
'resize_filedata' => $fi
ledata
),
array(
'filedataid' => $attach
ment['filedataid'],
'resize_type' => vB_Api_
Filedata::SIZE_LARGE
));
}
unset($attachdata);
}
else
{
// Add error about file missing..
$vbulletin->GPC['attacherrorcount']++;
}
$vboptions['attachfile'] = $temp;
}
if ($vb5_config['Misc']['debug'])
{
echo " <tr>
<td>$attachment[filedataid]" . iif($atta
cherror, "<br />$attacherror") . "</td>
<td>$attachment[filesize]</td>
<td>$filesize / $thumbnail_filesize</td>
</tr>
";
}
else
{
echo "$vbphrase[attachment] : <b>$attachment[filedataid]
</b><br />";
if ($attacherror)
{
echo "$vbphrase[attachment] : <b>$attachment[fil
edataid] $vbphrase[error]</b> $attacherror<br />";
}
vbflush();
}
}
if ($vb5_config['Misc']['debug'])
{
echo '</table>';
//vbflush();
}
$checkmore = vB::getDbAssertor()->getRow('filedata', array(
vB_dB_Query::CONDITIONS_KEY => array(
array('field' => 'filedataid', 'value' =
> $finishat, 'operator' => vB_dB_Query::OPERATOR_GTE)
)
));
if ($checkmore)
{
$args = array();
parse_str(vB::getCurrentSession()->get('sessionurl'),$args);
$args = array_merge($args, array(
'do'=> 'domoveattachment',
'startat' => $finishat,
"pp" => $vbulletin->GPC['perpage'],
if ($totalattach['count'] != $vbulletin->GPC['count'] OR
!$vbulletin->GPC['count'] OR ($vbulletin->GPC['attacherrorcount'] / $vbulletin>GPC['count']) * 10 > 1)
{
$finalizeoption = false;
}
else
{
$finalizeoption = true;
}
print_yes_no_row($vbphrase['finalize'], 'removeattachmen
ts', $finalizeoption);
print_submit_row($vbphrase['go']);
}
else
{
$filetype = $vboptions['attachfile'];
// update $vboptions // attachments are now being read f
rom and saved to the database
vB_Api::instanceInternal('options')->updateValue('attach
file', ATTACH_AS_DB);
print_form_header('attachment', 'confirmfileremove');
print_table_header($vbphrase['confirm_attachment_removal
']);
print_description_row(construct_phrase($vbphrase['file_r
emoval'], $totalattach['count'], $vbulletin->GPC['count'], $vbulletin->GPC['atta
cherrorcount'],$vbphrase['go']));
construct_hidden_code('attachtype', $filetype);
print_submit_row($vbphrase['go']);
}
}
}
// ###################### Confirm emptying of filedata ##########
if ($_REQUEST['do'] == 'confirmfileremove')
{
$vbulletin->input->clean_array_gpc('r', array(
'startat'
=> vB_Cleaner::TYPE_UINT,
'perpage'
=> vB_Cleaner::TYPE_UINT,
'attachtype' => vB_Cleaner::TYPE_UINT,
));
if (empty($vbulletin->GPC['perpage']))
{
$vbulletin->GPC['perpage'] = 200;
}
$attachments = vB::getDbAssertor()->assertQuery('vBForum:fetchFiledataLi
mit', array(vB_dB_Query::PARAM_LIMITSTART => $vbulletin->GPC['startat'], vB_dB_Q
uery::PARAM_LIMIT => $vbulletin->GPC['perpage']));
if ($attachments->valid())
{
foreach ($attachments AS $attachment)
{
if ($userid === null)
{
$userid = $attachment['userid'];
}
if ($vbulletin->GPC['attachtype'] == ATTACH_AS_FILES_NEW
)
{
$path = $vboptions['attachpath'] . '/' . implode
('/', preg_split('//', $attachment['userid'], -1, PREG_SPLIT_NO_EMPTY));
}
else
{
$path = $vboptions['attachpath'] . '/' . $attach
ment['userid'];
}
if (file_exists($path . '/' . $attachment['filedataid']
. '.attach'))
{
@unlink($path . '/' . $attachment['filedataid']
. '.attach');
}
$thumbnail_path = fetch_attachment_path($attachment['use
rid'], $attachment['filedataid'], vB_Api_Filedata::SIZE_THUMB);
$icon_path = fetch_attachment_path($attachment['userid']
, $attachment['filedataid'], vB_Api_Filedata::SIZE_ICON);
$small_path = fetch_attachment_path($attachment['userid'
], $attachment['filedataid'], vB_Api_Filedata::SIZE_SMALL);
$medium_path = fetch_attachment_path($attachment['userid
'], $attachment['filedataid'], vB_Api_Filedata::SIZE_MEDIUM);
$large_path = fetch_attachment_path($attachment['userid'
], $attachment['filedataid'], vB_Api_Filedata::SIZE_LARGE);
if (file_exists($thumbnail_path))
{
@unlink($thumbnail_path);
}
if (file_exists($icon_path))
{
@unlink($icon_path);
}
if ($small_path )
{
@unlink($small_path );
}
if (file_exists($medium_path))
{
@unlink($medium_path);
}
if (file_exists($large_path))
{
@unlink($large_path);
}
if ($userid != $attachment['userid'])
{
// Try to remove directory of previous userid
if ($vbulletin->GPC['attachtype'] == ATTACH_AS_F
ILES_NEW)
{
$path = $vboptions['attachpath'] . '/' .
print_cp_redirect2('attachment', $args);
echo "<p><a href=\"attachment.php?" . vB::getCurrentSession()->g
et('sessionurl') . "do=confirmfileremove&startat=$finishat&attachtype="
. $vbulletin->GPC['attachtype'] .
"&pp=" . $vbulletin->GPC['perpage'] . "\">" .
$vbphrase['click_here_to_continue_processing'] . "</a></p>";
}
else
{
print_stop_message2('attachments_moved_to_the_database',NULL,arr
ay(),null, 'attachment.php?do=stats');
}
}
// ###################### Confirm emptying of filedata ##########
if ($_REQUEST['do'] == 'confirmattachmentremove')
{
$vbulletin->input->clean_array_gpc('r', array(
'removeattachments' => vB_Cleaner::TYPE_BOOL,
'startat'
=> vB_Cleaner::TYPE_UINT,
'perpage'
=> vB_Cleaner::TYPE_UINT,
));
if ($vbulletin->GPC['removeattachments'])
{
if (empty($vbulletin->GPC['perpage']))
{
$vbulletin->GPC['perpage'] = 500;
}
if ($vbulletin->GPC['startat'] == 0)
{
// update $vboptions to attachments as files...
// attachfile is only set to 1 to indicate the PRE 3.0.0
RC1 attachment FS behaviour
vB_Api::instanceInternal('options')->updateValue('attach
file', ATTACH_AS_FILES_NEW);
}
$attachments = vB::getDbAssertor()->assertQuery('vBForum:fetchFi
ledataLimit', array(vB_dB_Query::PARAM_LIMITSTART => $vbulletin->GPC['startat'],
vB_dB_Query::PARAM_LIMIT => $vbulletin->GPC['perpage']));
if ($attachments->valid())
{
$attachmentids = array();
foreach ($attachments as $attachment)
{
$attachmentids[] = $attachment['filedataid'];
}
vB::getDbAssertor()->update('filedata', array('filedata'
=> ''), array('filedataid' => $attachmentids));
vB::getDbAssertor()->update('vBForum:filedataresize', ar
ray('resize_filedata' => ''), array('filedataid' => $attachmentids));
$finishat = $vbulletin->GPC['startat'] + $vbulletin->GPC
['perpage'];
$args = array();
parse_str(vB::getCurrentSession()->get('sessionurl'),$ar
gs);
$args = array_merge($args, array(
'do'=> 'confirmattachmentremove',
'startat' => $finishat,
"pp" => $vbulletin->GPC['perpage'],
"removeattachments" => 1
));
print_cp_redirect2('attachment', $args);
echo "<p><a href=\"attachment.php?" . vB::getCurrentSess
ion()->get('sessionurl') . "do=confirmattachmentremove&startat=$finishat&
;removeattachments=1" .
"&pp=" . $vbulletin->GPC['perpage'] . "\">" .
$vbphrase['click_here_to_continue_processing'] . "</a></p>";
}
else
{
// Again, make sure we are on attachments as files setti
ng.
vB_Api::instanceInternal('options')->updateValue('attach
file', ATTACH_AS_FILES_NEW);
print_stop_message2(array('attachments_moved_to_the_file
system', vB::getCurrentSession()->get('sessionurl')),NULL,array(),null, 'attach
ment.php?do=stats');
}
}
else
{
print_stop_message2('attachments_not_moved_to_the_filesystem',NU
LL,array(),null, 'attachment.php?do=stats');
}
}
// ###################### Search attachments ####################
$vbulletin->input->clean_array_gpc('r', array(
'massdelete' => vB_Cleaner::TYPE_STR
));
if ($_REQUEST['do'] == 'search' AND $vbulletin->GPC['massdelete'])
{
$vbulletin->input->clean_array_gpc('r', array(
'a_delete' => vB_Cleaner::TYPE_ARRAY_UINT
));
// they hit the mass delete submit button
if (!is_array($vbulletin->GPC['a_delete']))
{
// nothing in the array
print_stop_message2('invalid_attachments_specified');
}
else
{
$_REQUEST['do'] = 'massdelete';
}
}
// special case
if ($vbulletin->GPC['prunedate'] > 0)
{
$vbulletin->GPC['search']['datelinebefore'] = date('Y-m-d', TIME
NOW - 86400 * $vbulletin->GPC['prunedate']);
}
if ($vbulletin->GPC['pagenum'] < 1)
{
$vbulletin->GPC['pagenum'] = 1;
}
if ($vbulletin->GPC['next_page'])
{
++$vbulletin->GPC['pagenum'];
}
else if ($vbulletin->GPC['prev_page'])
{
--$vbulletin->GPC['pagenum'];
}
if ($vbulletin->GPC['search']['attachedby'])
{
$user = vB::getDbAssertor()->getRow('user', array(
vB_dB_Query::CONDITIONS_KEY => array(
array('field' => 'username', 'value' =>
$vbulletin->GPC['search']['attachedby'], 'operator' => vB_dB_Query::OPERATOR_INC
LUDES)
)
)
);
if (empty($user))
{
print_stop_message2('invalid_user_specified');
}
else
{
$vbulletin->GPC['search']['attachedbyuser'] = $user['use
rid'];
}
}
$attachments = vB::getDbAssertor()->getRow('vBForum:searchAttach', array
('search' => $vbulletin->GPC['search'], 'countonly' => true));
$pages = ceil($attachments['count'] / $vbulletin->GPC['search']['results
']);
if (!$pages)
{
$pages = 1;
}
print_form_header('attachment', 'search', 0, 1);
construct_hidden_code('prevsearch', $vbulletin->GPC['prevsearch']);
construct_hidden_code('prunedate', $vbulletin->GPC['prunedate']);
construct_hidden_code('pagenum', $vbulletin->GPC['pagenum']);
print_table_header(construct_phrase($vbphrase['showing_attachments_x_to_
y_of_z'], ($vbulletin->GPC['pagenum'] - 1) * $vbulletin->GPC['search']['results'
] + 1, iif($vbulletin->GPC['search']['results'] * $vbulletin->GPC['pagenum'] >
$attachments['count'], $attachments['count'], $vbulletin->GPC['search']['results
id'], array(
'filename' => $vbulletin->GPC['a_filename'],
'visible' => $vbulletin->GPC['a_visible'],
'counter' => $vbulletin->GPC['a_counter'],
));
print_stop_message2('updated_attachment_successfully', 'attachment', arr
ay('do'=>'stats'));
}
// ###################### Delete an attachment ####################
if ($_REQUEST['do'] == 'delete')
{
$vbulletin->input->clean_array_gpc('r', array(
'nodeid' => vB_Cleaner::TYPE_INT
));
$attachment = vB::getDbAssertor()->getRow('vBForum:fetchAttach', array('
nodeid' => $vbulletin->GPC['nodeid']));
print_form_header('attachment', 'dodelete');
construct_hidden_code('nodeid', $vbulletin->GPC['nodeid']);
print_table_header($vbphrase['confirm_deletion_gcpglobal']);
print_description_row(construct_phrase($vbphrase['are_you_sure_you_want_
to_delete_the_attachment_x'], $attachment['filename'], $vbulletin->GPC['nodeid']
));
print_submit_row($vbphrase['yes'], '', 2, $vbphrase['no']);
}
// ###################### Do delete the attachment ####################
if ($_POST['do'] == 'dodelete')
{
$vbulletin->input->clean_array_gpc('p', array(
'nodeid' => vB_Cleaner::TYPE_UINT
));
vB_Api::instanceInternal('Content_Attach')->delete($vbulletin->GPC['node
id']);
print_stop_message2('deleted_attachment_successfully', 'attachment', arr
ay('do'=>'intro'));
}
// ###################### Mass Delete attachments ####################
if ($_REQUEST['do'] == 'massdelete')
{
$vbulletin->input->clean_array_gpc('r', array(
'a_delete' => vB_Cleaner::TYPE_ARRAY_UINT
));
print_form_header('attachment','domassdelete');
construct_hidden_code('a_delete', sign_client_string(serialize($vbulleti
n->GPC['a_delete'])));
print_table_header($vbphrase['confirm_deletion_gcpglobal']);
print_description_row($vbphrase['are_you_sure_you_want_to_delete_these_a
ttachments']);
print_submit_row($vbphrase['yes'], '', 2, $vbphrase['no']);
}
print_label_row($vbphrase['average_attachment_filesize'], $astats['avera
ge']);
print_label_row($vbphrase['total_downloads'], vb_number_format($astats['
downloads']));
print_table_break();
$position = 0;
print_table_header($vbphrase['five_most_popular_attachments'], 5);
print_cells_row(array('', $vbphrase['filename_gcpglobal'], $vbphrase['us
ername'], $vbphrase['downloads_gattachment_image'], ' '), 1);
if ($attachments = vB::getDbAssertor()->assertQuery('vBForum:fetchTopAtt
achmentsCounter'))
{
foreach ($attachments AS $attachment)
{
$position++;
$cell = array();
$cell[] = $position . '.';
$cell[] = "<a href=\"../attachment.php?" . vB::getCurren
tSession()->get('sessionurl') . "nodeid=$attachment[nodeid]&d=$attachment[da
teline]\">$attachment[filename]</a>";
$cell[] = iif($attachment['userid'], "<a href=\"user.php
?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&u=$attachment[use
rid]\">$attachment[authorname]</a>", $attachment['authorname']);
$cell[] = vb_number_format($attachment['counter']);
$cell[] = '<span class="smallfont">' .
construct_link_code($vbphrase['view_content_gatt
achment_image'], $baseurl . '/filedata/fetch?filedataid=' . $attachment['filedat
aid'] , true) .
construct_link_code($vbphrase['edit'], "attachme
nt.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&nodeidid=$a
ttachment[nodeid]") .
construct_link_code($vbphrase['delete'], "attach
ment.php?" . vB::getCurrentSession()->get('sessionurl') . "do=delete&nodeid=
$attachment[nodeid]") .
'</span>';
print_cells_row($cell);
}
}
print_table_break();
$position = 0;
print_table_header($vbphrase['five_largest_attachments'], 5);
print_cells_row(array(' ', $vbphrase['filename_gcpglobal'], $vbphra
se['username'], $vbphrase['filesize_gattachment_image'], ' '), 1);
if ($attachments = vB::getDbAssertor()->assertQuery('vBForum:fetchTopAtt
achmentsSize'))
{
foreach ($attachments AS $attachment)
{
$position++;
$cell = array();
$cell[] = $position . '.';
$cell[] = "<a href=\"../attachment.php?" . vB::getCurren
tSession()->get('sessionurl') . "nodeid=$attachment[nodeid]&d=$attachment[da
teline]\">$attachment[filename]</a>";
$cell[] = iif($attachment['userid'], "<a href=\"user.php
?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&u=$attachment[use
rid]\">$attachment[authorname]</a>", $attachment['authorname']);
$cell[] = vb_number_format($attachment['filesize'], 1, t
rue);
$cell[] = '<span class="smallfont">' .
construct_link_code($vbphrase['view_content_gatt
achment_image'], $baseurl . '/filedata/fetch?filedataid=' . $attachment['filedat
aid'] , true) .
construct_link_code($vbphrase['edit'], "attachme
nt.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&nodeid=$att
achment[nodeid]") .
construct_link_code($vbphrase['delete'], "attach
ment.php?" . vB::getCurrentSession()->get('sessionurl') . "do=delete&nodeid=
$attachment[nodeid]") .
'</span>';
print_cells_row($cell);
}
}
print_table_break();
$content = array();
$largestuser = vB::getDbAssertor()->assertQuery('vBForum:fetchAttachStat
sLargestUser');
$position = 0;
print_table_header($vbphrase['five_users_most_attachment_space'], 5);
print_cells_row(array(' ', $vbphrase['username'], $vbphrase['attach
ments'], $vbphrase['total_size_gattachment_image'], ' '), 1);
foreach ($largestuser as $thispop)
//while($thispop = $vbulletin->db->fetch_array($largestuser))
{
$position++;
$cell = array();
$cell[] = $position . '.';
$cell[] = "<a href=\"user.php?" . vB::getCurrentSession()->get('
sessionurl') . "do=edit&u=$thispop[userid]\">$thispop[username]</a>";
$cell[] = vb_number_format($thispop['count']);
$cell[] = vb_number_format($thispop['totalsize'], 1, true);
$cell[] = '<span class="smallfont">' . construct_link_code($vbph
rase['view_attachments'], "attachment.php?" . vB::getCurrentSession()->get('sess
ionurl') . "do=search&search[attachedby]=" . urlencode($thispop['username'])
) . '</span>';
print_cells_row($cell);
}
print_table_footer();
}
// ###################### Introduction ####################
if ($_REQUEST['do'] == 'intro')
{
print_form_header('attachment', 'search');
print_table_header($vbphrase['quick_search']);
print_description_row("
<ul style=\"margin:0px; padding:0px; list-style:none\">
<li><a href=\"attachment.php?" . vB::getCurrentSession()->get('s
essionurl') . "do=search&search[orderby]=fd.filesize&search[ordering]=DE
SC\">" . $vbphrase['view_largest_attachments'] . "</a></li>
print_table_header($vbphrase['attachment_manager_gattachment_image'], 5)
;
print_cells_row(array(
$vbphrase['extension'],
$vbphrase['maximum_filesize'],
$vbphrase['maximum_width'],
$vbphrase['maximum_height'],
$vbphrase['controls']
), 1, 'tcat');
$attachoptions =
'edit'
'remove'
'perms'
);
array(
=> $vbphrase['edit'],
=> $vbphrase['delete'],
=> $vbphrase['view_permissions_gattachment_image'],
{
$vbulletin->input->clean_array_gpc('r', array(
'extension' => vB_Cleaner::TYPE_STR
));
print_form_header('attachment', 'doupdatetype');
if ($vbulletin->GPC['extension'])
{ // This is an edit
$type = vB::getDbAssertor()->getRow('vBForum:attachmenttype',arr
ay('extension' => $vbulletin->GPC['extension']));
if ($type)
{
if ($type['mimetype'])
{
$type['mimetype'] = implode("\n", unserialize($t
ype['mimetype']));
}
construct_hidden_code('extension', $type['extension']);
print_table_header(construct_phrase($vbphrase['x_y_id_z'
], $vbphrase['attachment_type'], $type['extension'], $type['extension']));
}
}
else
{
$type = null;
}
if (!$type)
{
$type = array('enabled' => 1);
print_table_header($vbphrase['add_new_extension']);
}
print_input_row($vbphrase['extension'], 'type[extension]', $type['extens
ion']);
print_input_row(construct_phrase($vbphrase['maximum_filesize_dfn']), 'ty
pe[size]', $type['size']);
print_input_row($vbphrase['max_width_dfn'], 'type[width]', $type['width'
]);
print_input_row($vbphrase['max_height_dfn'], 'type[height]', $type['heig
ht']);
print_textarea_row($vbphrase['mime_type_dfn'], 'type[mimetype]', $type['
mimetype']);
// Legacy Hook 'admin_attachmenttype' Removed //
// TODO: Move this to proper channel permissions
// Enable/disable and new window options for each content type used to b
e here.
print_submit_row($vbulletin->GPC['extension'] ? $vbphrase['update'] : $v
bphrase['save'], '_default_', 4);
}
// ###################### Update File Type ####################
if ($_POST['do'] == 'doupdatetype')
{
$vbulletin->input->clean_array_gpc('p', array(
'extension'
=> vB_Cleaner::TYPE_STR,
'type'
=> vB_Cleaner::TYPE_ARRAY,
'contenttype' => vB_Cleaner::TYPE_ARRAY,
'default'
=> vB_Cleaner::TYPE_ARRAY,
));
$vbulletin->GPC['type']['extension'] = preg_replace('#[^a-z0-9_]#i', '',
$vbulletin->GPC['type']['extension']);
$vbulletin->GPC['type']['extension'] = strtolower($vbulletin->GPC['type'
]['extension']);
if (empty($vbulletin->GPC['type']['extension']))
{
print_stop_message2('please_complete_required_fields');
}
if ($vbulletin->GPC['extension'] != $vbulletin->GPC['type']['extension']
AND $test = vB::getDbAssertor()->getRow('vBForum:attachmenttype',array('extensi
on' => $vbulletin->GPC['type']['extension'])))
{
print_stop_message2(array('name_exists', $vbphrase['filetype_gat
tachment_image'], htmlspecialchars($vbulletin->GPC['type']['extension'])));
}
if ($vbulletin->GPC['type']['mimetype'])
{
$mimetype = explode("\n", $vbulletin->GPC['type']['mimetype']);
foreach($mimetype AS $index => $value)
{
$mimetype["$index"] = trim($value);
}
}
else
{
$mimetype = array('Content-type: unknown/unknown');
}
$vbulletin->GPC['type']['mimetype'] = serialize($mimetype);
//
//
n could be
//
if ($vbulletin->GPC['extension'])
{
vB::getDbAssertor()->update('vBForum:attachmenttype',$vbulletin>GPC['type'], array('extension' => $vbulletin->GPC['extension']));
build_attachment_permissions();
}
else
{
/*insert query*/
vB::getDbAssertor()->insert('vBForum:attachmenttype',array(
'extension' => $vbulletin->GPC['type']['extensio
n'],
'size' => intval($vbulletin->GPC['type']['size']
),
'height' => intval($vbulletin->GPC['type']['heig
ht']),
'width' => intval($vbulletin->GPC['type']['width
']),