You are on page 1of 11

<?

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);
// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('CVS_REVISION', '$RCSfile$ - $Revision: 70576 $');
// #################### 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');
// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminimages'))
{
print_cp_no_permission();
}
// ############################# LOG ACTION ###############################
log_admin_action();
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
$assertor = vB::getDbAssertor();
$vb5_config =& vB::getConfig();
print_cp_header($vbphrase['userpic_manager']);
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'storage';
}
// ###################### Start checkpath #######################
function verify_upload_folder($imagepath)
{
if ($imagepath == '')
{
print_stop_message2('please_complete_required_fields');
}
// Get realpath.
$test = realpath($imagepath);
if (!$test)

{
// If above fails, try relative path instead.
$test = realpath(DIR . DIRECTORY_SEPARATOR . $imagepath);
}
if ($fp = @fopen($test . '/test.image', 'wb'))
{
fclose($fp);
if (!@unlink($test . '/test.image'))
{
print_stop_message2(array('test_file_write_failed', $im
agepath));
}
return true;
}
else
{
print_stop_message2(array('test_file_write_failed', $imagepath)
);
}
}
$vbulletin->input->clean_array_gpc('r', array(
'avatarpath'
=> vB_Cleaner::TYPE_STR,
'avatarurl'
=> vB_Cleaner::TYPE_STR,
'profilepicpath' => vB_Cleaner::TYPE_STR,
'profilepicurl' => vB_Cleaner::TYPE_STR,
'sigpicpath'
=> vB_Cleaner::TYPE_STR,
'sigpicurl'
=> vB_Cleaner::TYPE_STR,
'dowhat'
=> vB_Cleaner::TYPE_STR
));
// ###################### Swap from database to file system and vice versa #####
#####
if ($_REQUEST['do'] == 'storage')
{
if ($vbulletin->options['usefileavatar'])
{
print_form_header('avatar', 'switchtype');
print_table_header("$vbphrase[storage_type]: <span class=\"norma
l\">$vbphrase[user_pictures]</span>");
print_description_row(construct_phrase($vbphrase['avatars_are_cu
rrently_being_served_from_the_filesystem_at_x'], '<b>' . $vbulletin->options['av
atarpath'] . '</b>'));
print_description_row(construct_phrase($vbphrase['profilepics_ar
e_currently_being_served_from_the_filesystem_at_x'], '<b>' . $vbulletin->options
['profilepicpath'] . '</b>'));
print_description_row(construct_phrase($vbphrase['sigpics_are_cu
rrently_being_served_from_the_filesystem_at_x'], '<b>' . $vbulletin->options['si
gpicpath'] . '</b>'));
print_table_break();
print_table_header('&nbsp;');
print_radio_row($vbphrase['move_items_from_filesystem_into_datab
ase'], 'dowhat', array('FS_to_DB' => ''), 'FS_to_DB');
print_table_break();
print_table_header('&nbsp;');
print_radio_row($vbphrase['move_avatars_to_a_different_directory
'], 'dowhat', array('FS_to_FS1' => ''));
print_radio_row($vbphrase['move_profilepics_to_a_different_direc

tory'], 'dowhat', array('FS_to_FS2' => ''));


print_radio_row($vbphrase['move_sigpics_to_a_different_directory
'], 'dowhat', array('FS_to_FS3' => ''));
print_submit_row($vbphrase['go'], 0);
}
else
{
$vbulletin->GPC['dowhat'] = 'DB_to_FS';
$_REQUEST['do'] = 'switchtype';
}
}
// ###################### Swap from database to file system and vice versa #####
#####
if ($_REQUEST['do'] == 'switchtype')
{
if ($vbulletin->GPC['dowhat'] == 'FS_to_DB')
{
// redirect straight through to image mover
$vbulletin->GPC['avatarpath'] = $vbulletin->options['avatarpath'
];
$vbulletin->GPC['avatarurl'] = $vbulletin->options['avatarurl'];
$vbulletin->GPC['profilepicpath'] = $vbulletin->options['profile
picpath'];
$vbulletin->GPC['profilepicurl'] = $vbulletin->options['profilep
icurl'];
$vbulletin->GPC['sigpicpath'] = $vbulletin->options['sigpicpath'
];
$vbulletin->GPC['sigpicurl'] = $vbulletin->options['sigpicurl'];
$_POST['do'] = 'doswitchtype';
}
else
{
// show a form to allow user to specify file path
print_form_header('avatar', 'doswitchtype');
construct_hidden_code('dowhat', $vbulletin->GPC['dowhat']);
switch($vbulletin->GPC['dowhat'])
{
case 'FS_to_FS1':
print_table_header($vbphrase['move_avatars_to_a_
different_directory']);
print_description_row(construct_phrase($vbphrase
['avatars_are_currently_being_served_from_the_filesystem_at_x'], '<b>' . $vbulle
tin->options['avatarpath'] . '</b>'));
print_input_row($vbphrase['avatar_file_path_dfn'
], 'avatarpath', $vbulletin->options['avatarpath']);
print_input_row($vbphrase['url_to_avatars_relati
ve_to_your_forums_home_page'], 'avatarurl', $vbulletin->options['avatarurl']);
break;
case 'FS_to_FS2':
print_table_header($vbphrase['move_profilepics_t
o_a_different_directory']);
print_description_row(construct_phrase($vbphrase
['profilepics_are_currently_being_served_from_the_filesystem_at_x'], '<b>' . $vb
ulletin->options['profilepicpath'] . '</b>'));

print_input_row($vbphrase['profilepic_file_path_
dfn'], 'profilepicpath', $vbulletin->options['profilepicpath']);
print_input_row($vbphrase['url_to_profilepics_re
lative_to_your_forums_home_page'], 'profilepicurl', $vbulletin->options['profile
picurl']);
break;
case 'FS_to_FS3':
print_table_header($vbphrase['move_sigpics_to_a_
different_directory']);
print_description_row(construct_phrase($vbphrase
['sigpics_are_currently_being_served_from_the_filesystem_at_x'], '<b>' . $vbulle
tin->options['sigpicpath'] . '</b>'));
print_input_row($vbphrase['sigpic_file_path_dfn'
], 'sigpicpath', $vbulletin->options['sigpicpath']);
print_input_row($vbphrase['url_to_sigpics_relati
ve_to_your_forums_home_page'], 'sigpicurl', $vbulletin->options['sigpicurl']);
break;
default:
print_table_header($vbphrase['move_items_from_da
tabase_into_filesystem']);
print_description_row($vbphrase['images_are_curr
ently_being_served_from_the_database'], false, 2, '', 'center');
print_input_row($vbphrase['avatar_file_path_dfn'
], 'avatarpath', $vbulletin->options['avatarpath']);
print_input_row($vbphrase['url_to_avatars_relati
ve_to_your_forums_home_page'], 'avatarurl', $vbulletin->options['avatarurl']);
print_input_row($vbphrase['profilepic_file_path_
dfn'], 'profilepicpath', $vbulletin->options['profilepicpath']);
print_input_row($vbphrase['url_to_profilepics_re
lative_to_your_forums_home_page'], 'profilepicurl', $vbulletin->options['profile
picurl']);
print_input_row($vbphrase['sigpic_file_path_dfn'
], 'sigpicpath', $vbulletin->options['sigpicpath']);
print_input_row($vbphrase['url_to_sigpics_relati
ve_to_your_forums_home_page'], 'sigpicurl', $vbulletin->options['sigpicurl']);
}
print_submit_row($vbphrase['go']);
}
}
// ############### Move files from database to file system and vice versa ######
#####
if ($_POST['do'] == 'doswitchtype')
{
$vbulletin->GPC['avatarpath'] = preg_replace('/(\/|\\\)$/s', '', $vbulle
tin->GPC['avatarpath']);
$vbulletin->GPC['avatarurl'] = preg_replace('/(\/|\\\)$/s', '', $vbullet
in->GPC['avatarurl']);
$vbulletin->GPC['profilepicpath'] = preg_replace('/(\/|\\\)$/s', '', $vb
ulletin->GPC['profilepicpath']);
$vbulletin->GPC['profilepicurl'] = preg_replace('/(\/|\\\)$/s', '', $vbu
lletin->GPC['profilepicurl']);
$vbulletin->GPC['sigpicpath'] = preg_replace('/(\/|\\\)$/s', '', $vbulle
tin->GPC['sigpicpath']);
$vbulletin->GPC['sigpicurl'] = preg_replace('/(\/|\\\)$/s', '', $vbullet
in->GPC['sigpicurl']);

if ($vbulletin->GPC['dowhat'] == 'FS_to_FS1')
{
$imagepath =& $vbulletin->GPC['avatarpath'];
$imageurl =& $vbulletin->GPC['avatarurl'];
$path = 'avatarpath';
$url = 'avatarurl';
}
else if ($vbulletin->GPC['dowhat'] == 'FS_to_FS2')
{
$imagepath =& $vbulletin->GPC['profilepicpath'];
$imageurl =& $vbulletin->GPC['profilepicurl'];
$path = 'profilepicpath';
$url = 'profilepicurl';
}
else
{
$imagepath =& $vbulletin->GPC['sigpicpath'];
$imageurl =& $vbulletin->GPC['sigpicurl'];
$path = 'sigpicpath';
$url = 'sigpicurl';
}
switch($vbulletin->GPC['dowhat'])
{
// #############################################################
################
// update image file path
case 'FS_to_FS1':
case 'FS_to_FS2':
case 'FS_to_FS3':
if ($imagepath === $vbulletin->options["$path"] AND $ima
geurl === $vbulletin->options["$url"])
{
// 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($imagepath);
$oldpath = $vbulletin->options["$path"];
$assertor->assertQuery('vBForum:updateSettingVal
ues',
array(vB_dB_Query::TYPE_KEY => vB_dB_Que
ry::QUERY_STORED,
'path' => $path,
'url' => $url,
'imagepath' => $imagepath,
'imageurl' => $imageurl
)
);
vB::getDatastore()->build_options();
// show message
print_stop_message2(array('your_vb_settings_have
_been_updated_to_store_images_in_x', $imagepath, $oldpath));

}
break;
// #############################################################
################
// move userpics from database to filesystem
case 'DB_to_FS':
// check path is valid
verify_upload_folder($vbulletin->GPC['avatarpath']);
verify_upload_folder($vbulletin->GPC['profilepicpath']);
verify_upload_folder($vbulletin->GPC['sigpicpath']);
$assertor->assertQuery('vBForum:updateSettingValuesByVar
name',
array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUER
Y_STORED,
'avatarpath' => $vbulletin->GPC['avatarp
ath'],
'avatarurl' => $vbulletin->GPC['avatarur
l'],
'profilepicpath' => $vbulletin->GPC['pro
filepicpath'],
'profilepicurl' => $vbulletin->GPC['prof
ilepicurl'],
'sigpicpath' => $vbulletin->GPC['sigpicp
ath'],
'sigpicurl' => $vbulletin->GPC['sigpicur
l']
)
);
vB::getDatastore()->build_options();
break;
}
// #####################################################################
########
print_form_header('avatar', 'domoveavatar');
print_table_header(construct_phrase($vbphrase['edit_storage_type'], "<sp
an class=\"normal\">" . $vbphrase['user_pictures'] . "</span>"));
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_images_from_database_to_filesystem']);
}
else
{
print_description_row($vbphrase['we_are_ready_to_attempt_to_move
_your_images_from_filesystem_to_database']);
}
print_input_row($vbphrase['number_of_users_to_process_per_cycle_gattachm
ent_image'], 'perpage', 300, 1, 5);
print_submit_row($vbphrase['go']);

}
// ################### Move avatars ######################################
if ($_REQUEST['do'] == 'domoveavatar')
{
$vbulletin->input->clean_array_gpc('r', array(
'perpage' => vB_Cleaner::TYPE_INT,
'startat' => vB_Cleaner::TYPE_INT,
));
if (is_demo_mode())
{
print_cp_message('This function is disabled within demo mode');
}
if ($vbulletin->GPC['perpage'] < 1)
{
$vbulletin->GPC['perpage'] = 10;
}
if ($vbulletin->GPC['startat'] < 0)
{
$vbulletin->GPC['startat'] = 0;
}
$finishat = $vbulletin->GPC['startat'] + $vbulletin->GPC['perpage'];
$images = $assertor->assertQuery('vBForum:fetchAvatarInfo',
array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED,
vB_dB_Query::PARAM_LIMITSTART => $vbulletin->GPC['starta
t'],
vB_dB_Query::PARAM_LIMIT => $vbulletin->GPC['perpage']
)
);
//while ($image = $vbulletin->db->fetch_array($images))
if ($images AND $images->valid())
{
foreach ($images AS $image)
{
if ($vb5_config['Misc']['debug'])
{
echo "<strong>$vbphrase[user] : $image[userid]</
strong><br />";
if ($image['afilename'])
{
echo "&nbsp;&nbsp;$vbphrase[avatar] : $i
mage[afilename]<br />";
}
if ($image['pfilename'])
{
echo "&nbsp;&nbsp;$vbphrase[profile_pict
ure] : $image[pfilename]<br />";
}
if ($image['sfilename'])
{
echo "&nbsp;&nbsp;$vbphrase[signature_pi
cture] : $image[pfilename]<br />";
}
}

if (!$vbulletin->options['usefileavatar'])
{
$vbulletin->options['usefileavatar'] = true;
// Converting FROM mysql TO fs
if (!empty($image['afiledata']))
{
$userpic = vB_DataManager_Userpic::fetch
_library($vbulletin, vB_DataManager_Constants::ERRTYPE_CP, 'userpic_avatar', tru
e);
$userpic->set_existing($image);
$userpic->setr('filedata', $image['afile
data']);
if (!$userpic->save())
{
print_stop_message2(array('error
_writing_x', $image['afilename']));
}
}
if (!empty($image['pfiledata']))
{
$userpic = vB_DataManager_Userpic::fetch
_library($vbulletin, vB_DataManager_Constants::ERRTYPE_CP, 'userpic_profilepic',
true);
$userpic->set_existing($image);
$userpic->setr('filedata', $image['pfile
data']);
if (!$userpic->save())
{
print_stop_message2(array('error
_writing_x', $image['pfilename']));
}
}
if (!empty($image['sfiledata']))
{
$userpic = vB_DataManager_Userpic::fetch
_library($vbulletin, vB_DataManager_Constants::ERRTYPE_CP, 'userpic_sigpic', tru
e);
$userpic->set_existing($image);
$userpic->setr('filedata', $image['sfile
data']);
if (!$userpic->save())
{
print_stop_message2(array('error
_writing_x', $image['sfilename']));
}
}
unset($userpic);
$vbulletin->options['usefileavatar'] = false;
}
else
{
$vbulletin->options['usefileavatar'] = false;
// Converting FROM fs TO mysql
if (!empty($image['afilename']))

{
$path = $vbulletin->options['avatarpath'
] . "/$image[afilename]";
$thumbpath = $vbulletin->options['avatar
path'] . "/thumbs/$image[afilename]";
chdir(DIR);
$filedata = @file_get_contents($path);
if ($filedata)
{
$userpic = new vB_Datamanager_Us
erpic_Avatar($vbulletin, vB_DataManager_Constants::ERRTYPE_CP, 'userpic');
$userpic->set_existing($image);
$userpic->setr('filedata', $file
data);
$userpic->save();
unset($userpic);
}
}
if (!empty($image['pfilename']))
{
$path = $vbulletin->options['profilepicp
ath'] . "/profilepic$image[userid]_$image[profilepicrevision].gif";
$filedata = @file_get_contents($path);
if ($filedata)
{
$userpic = new vB_Datamanager_Us
erpic_Profilepic($vbulletin, vB_DataManager_Constants::ERRTYPE_CP, 'userpic');
$userpic->set_existing($image);
$userpic->setr('filedata', $file
data);
$userpic->save();
unset($userpic);
}
}
if (!empty($image['sfilename']))
{
$path = $vbulletin->options['sigpicpath'
] . "/sigpic$image[userid]_$image[sigpicrevision].gif";
$filedata = @file_get_contents($path);
if ($filedata)
{
$userpic = new vB_Datamanager_Us
erpic_Sigpic($vbulletin, vB_DataManager_Constants::ERRTYPE_CP, 'userpic');
$userpic->set_existing($image);
$userpic->setr('filedata', $file
data);
$userpic->save();
unset($userpic);
}
}
$vbulletin->options['usefileavatar'] = true;
}
$lastuser = $image['userid'];
}
}
$userid = $assertor->getRow('vBForum:fetchUserIdByAvatar', array(vB_dB_Q
uery::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'lastuser' => $lastuser));

if ($lastuser AND $userid)


{
$args = array();
parse_str(vB::getCurrentSession()->get('sessionurl'),$args);
$args['do'] = 'domoveavatar';
$args['startat'] = $finishat;
$args['pp'] = $vbulletin->GPC['perpage'];
print_cp_redirect2('avatar', $args);
echo "<p><a href=\"avatar.php?" . vB::getCurrentSession()->get('
sessionurl') . "do=domoveavatar&amp;startat=$finishat&amp;pp=" . $vbulletin->GPC
['perpage'] . "\">" . $vbphrase['click_here_to_continue_processing'] . "</a></p>
";
}
else
{
if (!$vbulletin->options['usefileavatar'])
{
$assertor->assertQuery('setting',
array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUER
Y_UPDATE, 'value' => 1,
vB_dB_Query::CONDITIONS_KEY => array(
array('field' => 'varname', 'val
ue' => 'usefileavatar', 'operator' => vB_dB_Query::OPERATOR_EQ)
)
)
);
vB::getDatastore()->build_options();
$assertor->assertQuery('vBForum:clearPictureData', array
(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD));
$assertor->assertQuery('vBForum:optimizePictureTables',
array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD));
print_stop_message2('images_moved_to_the_filesystem','av
atar', array('do' => 'storage'));
}
else
{
$assertor->assertQuery('setting',
array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUER
Y_UPDATE, 'value' => 0,
vB_dB_Query::CONDITIONS_KEY => array(
array('field' => 'varname', 'val
ue' => 'usefileavatar', 'operator' => vB_dB_Query::OPERATOR_EQ)
)
)
);
vB::getDatastore()->build_options();
print_stop_message2('images_moved_to_the_database','avat
ar', array('do' => 'storage'));
}
}
}
print_cp_footer();
/*======================================================================*\

|| ####################################################################
|| # Downloaded: 12:34, Sat Sep 28th 2013
|| # CVS: $RCSfile$ - $Revision: 70576 $
|| ####################################################################
\*======================================================================*/
?>

You might also like