Dit is een archief van het phpBBservice.nl forum. Nieuwe berichten plaatsen is niet meer mogelijk.
D
#1
Hallo :)

Ik vond pas dit script om alle externe avatars op mijn forum om te zetten naar lokale uploads:
https://gist.github.com/tierra/0024360d130d26660fa5

(mijn forum draait op https en externe http avatars geven vervelende mixed content waarschuwingen in recente browsers)

Dit 3.1 script gebruikt de functies in includes/functions_upload.php, maar die zijn verwijderd in phpbb3.3

De phpbb documentatie heeft het over deze veranderingen: https://area51.phpbb.com/docs/dev/3.3.x ... rview.html
Maar jammer genoeg lukt het me niet om hiermee het script aan te passen :( Mijn kennis van phpbb scripting is vrij beperkt.

Iemand suggesties om dit op te lossen? Of voorbeelden van recente 3.3 scripts die dezelfde logica gebruiken om me op weg te helpen?

Alvast bedankt voor jullie hulp :)

Script:

Code: Selecteer alles

if (php_sapi_name() != 'cli')
{
	echo 'This program must be run from the command line.' . PHP_EOL;
	exit(1);
}

define('IN_PHPBB', true);
$phpbb_root_path = __DIR__ . '/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'includes/startup.' . $phpEx);
require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx);

$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
$phpbb_class_loader->register();

$phpbb_config_php_file = new \phpbb\config_php_file($phpbb_root_path, $phpEx);
extract($phpbb_config_php_file->get_all());

require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx);
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
require($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);

$phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx);
$phpbb_container_builder->set_dump_container(false);
$phpbb_container_builder->set_use_extensions(false);

$phpbb_container = $phpbb_container_builder->get_container();
$phpbb_container->get('request')->enable_super_globals();
require($phpbb_root_path . 'includes/compatibility_globals.' . $phpEx);

/** @var \phpbb\config\config $config */
$config = $phpbb_container->get('config');

/** @var \phpbb\db\driver\factory $db */
$db = $phpbb_container->get('dbal.conn');

/** @var \phpbb\path_helper $path_helper */
$path_helper = $phpbb_container->get('path_helper');

/** @var \phpbb\mimetype\guesser $mimetype_guesser */
$mimetype_guesser = $phpbb_container->get('mimetype.guesser');

$db->sql_query("
	SELECT `user_id`, `user_avatar` FROM " . USERS_TABLE . "
	WHERE `user_avatar_type` = 'avatar.driver.remote'
");
$remote_avatars = $db->sql_fetchrowset();

foreach ($remote_avatars as $avatar)
{
	echo sprintf("ID: %7d URL: %s\n", $avatar['user_id'], $avatar['user_avatar']);

$upload = new \fileupload('AVATAR_',
		array('gif', 'jpg', 'jpeg', 'png'), $config['avatar_filesize'],
		$config['avatar_min_width'], $config['avatar_min_height'],
		$config['avatar_max_width'], $config['avatar_max_height'],
		(isset($config['mime_triggers']) ? explode('|', $config['mime_triggers']) : false)
);

	/** @var \filespec $file */
	$file = $upload->remote_upload($avatar['user_avatar'], $mimetype_guesser);
	$prefix = $config['avatar_salt'] . '_';
	$file->clean_filename('avatar', $prefix, $avatar['user_id']);

	$destination = $config['avatar_path'];

	// Adjust destination path (no trailing slash)
	if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
	{
		$destination = substr($destination, 0, -1);
	}

	$destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
	if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
	{
		$destination = '';
	}

	// Move file and overwrite any existing image
	$file->move_file($destination, true);

	if (!empty($file->error))
	{
		$file->remove();
		echo sprintf("Error (skipped): %s\n\n", $file->error[0]);
		continue;
	}

	$update_data = array(
		'user_avatar' => $avatar['user_id'] . '_' . time() . '.' . $file->get('extension'),
		'user_avatar_type' => 'avatar.driver.upload',
		'user_avatar_width' => $file->get('width'),
		'user_avatar_height' => $file->get('height'),
	);
	$db->sql_query("
		UPDATE " . USERS_TABLE . "
		SET " . $db->sql_build_array('UPDATE', $update_data) . "
		WHERE `user_id` = " . (int) $avatar['user_id']
	);
	if ($db->get_sql_error_triggered())
	{
		$file->remove();
		print_r($db->get_sql_error_returned());
		die();
	}
}
Upload snippets:

Code: Selecteer alles

require($phpbb_root_path . 'includes/functions_upload.' . $phpEx);

Code: Selecteer alles

$upload = new \fileupload('AVATAR_',
		array('gif', 'jpg', 'jpeg', 'png'), $config['avatar_filesize'],
		$config['avatar_min_width'], $config['avatar_min_height'],
		$config['avatar_max_width'], $config['avatar_max_height'],
		(isset($config['mime_triggers']) ? explode('|', $config['mime_triggers']) : false)
);
D
#2
that would need a complete rewrite of the code.

Code: Selecteer alles

$upload = $phpbb_container->get('files.upload'); //which holds the uploadfunctions previously found in require($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
sorry i got no time at my hand to rewrite it for you, you can try to ask the original maker https://www.phpbb.com/community/ucp.php ... &u=1788776

as he knows his code best on phpbb.com
or you can try to ask the question at phpbb.nl

sorry i have no better news to bring you.
hopefully you succeed.