function tbxAvatarEdit() { global $t; $DB = GetDB(); $v = Validator::Create(); Uploads::ProcessNew(Config::Get('avatar_extensions')); $upload = Uploads::Get('avatar_file'); $v->Register(empty($upload), Validator_Type::IS_FALSE, _T('Validation:No image uploaded')); if (!empty($upload)) { $v->Register(empty($upload['error']), Validator_Type::IS_TRUE, $upload['error']); $imagesize = @getimagesize($upload['path']); $v->Register($imagesize, Validator_Type::NOT_FALSE, _T('Validation:Invalid image upload')); // Check dimensions and filesize if ($imagesize !== false) { list($width, $height) = explode('x', Config::Get('avatar_dimensions')); $v->Register($imagesize[0] > $width || $imagesize[1] > $height, Validator_Type::IS_FALSE, _T('Validation:Invalid image dimensions', Config::Get('avatar_dimensions'))); $v->Register(filesize($upload['path']), Validator_Type::LESS_EQ, _T('Validation:Invalid image size', Config::Get('avatar_filesize')), Format::StringToBytes(Config::Get('avatar_filesize'))); } } if ($v->Validate()) { $user = $DB->Row('SELECT * FROM `tbx_user` WHERE `username`=?', array(AuthenticateUser::GetUsername())); if (!empty($user['avatar_id'])) { Uploads::RemoveExisting($user['avatar_id']); } DatabaseUpdate('tbx_user', array('username' => $user['username'], 'avatar_id' => $upload['upload_id'])); $t->Assign('g_success', true); } else { Uploads::RemoveCurrent(); $t->Assign('g_errors', $v->GetErrors()); } $t->Display('user-avatar.tpl'); }
function tbxBannerEdit($phase) { switch ($phase) { case Phase::PRE_VALIDATE: Uploads::ProcessNew(); $upload = Uploads::Get('upload_file'); if (!empty($upload)) { $v = Validator::Get(); $v->Register(empty($upload['error']), Validator_Type::IS_TRUE, $upload['error']); $v->Register(stripos(Request::Get('banner_html'), '{$upload_file}'), Validator_Type::NOT_FALSE, 'The Banner HTML must contain {$upload_file} where you want the URL of the upload file placed'); } break; case Phase::VALIDATION_FAILED: Uploads::RemoveCurrent(); break; case Phase::PRE_UPDATE: $DB = GetDB(); $banner = $DB->Row('SELECT * FROM `tbx_banner` WHERE `banner_id`=?', array($_REQUEST['banner_id'])); $upload = Uploads::Get('upload_file'); if (!empty($upload)) { if (!empty($banner['upload_id'])) { Uploads::RemoveExisting($banner['upload_id']); } $_REQUEST['upload_id'] = $upload['upload_id']; $_REQUEST['banner_html'] = str_replace('{$upload_file}', $upload['uri'], $_REQUEST['banner_html']); } $_REQUEST['sponsor_id'] = String::Nullify($_REQUEST['sponsor_id']); if (!empty($_REQUEST['sponsor_id'])) { $DB = GetDB(); $sponsor = $DB->Row('SELECT * FROM `tbx_sponsor` WHERE `sponsor_id`=?', array($_REQUEST['sponsor_id'])); if (!empty($sponsor)) { $_REQUEST['banner_html'] = str_replace('{$sponsor_url}', $sponsor['url'], $_REQUEST['banner_html']); } } break; } }