function import() { global $db, $template, $user; $import_schema = request_var('import_schema', ''); $images = request_var('images', array(''), true); $submit = isset($_POST['submit']) ? true : (empty($images) ? false : true); if ($import_schema) { if (phpbb_gallery_url::_file_exists($import_schema, 'import', '')) { include phpbb_gallery_url::_return_file($import_schema, 'import', ''); // Replace the md5 with the ' again and remove the space at the end to prevent \' troubles $user_data['username'] = utf8_substr(str_replace("{{$import_schema}}", "'", $user_data['username']), 0, -1); $image_name = utf8_substr(str_replace("{{$import_schema}}", "'", $image_name), 0, -1); } else { global $phpEx; trigger_error(sprintf($user->lang['MISSING_IMPORT_SCHEMA'], $import_schema . '.' . $phpEx), E_USER_WARNING); } $images_loop = 0; foreach ($images as $image_src) { /** * Import the images */ $image_src = str_replace("{{$import_schema}}", "'", $image_src); $image_src_full = phpbb_gallery_url::path('import') . utf8_decode($image_src); if (file_exists($image_src_full)) { $filetype = getimagesize($image_src_full); $filetype_ext = ''; switch ($filetype['mime']) { case 'image/jpeg': case 'image/jpg': case 'image/pjpeg': $filetype_ext = '.jpg'; $read_function = 'imagecreatefromjpeg'; if (substr(strtolower($image_src), -4) != '.jpg' && substr(strtolower($image_src), -5) != '.jpeg') { trigger_error(sprintf($user->lang['FILETYPE_MIMETYPE_MISMATCH'], $image_src, $filetype['mime']), E_USER_WARNING); } break; case 'image/png': case 'image/x-png': $filetype_ext = '.png'; $read_function = 'imagecreatefrompng'; if (substr(strtolower($image_src), -4) != '.png') { trigger_error(sprintf($user->lang['FILETYPE_MIMETYPE_MISMATCH'], $image_src, $filetype['mime']), E_USER_WARNING); } break; case 'image/gif': case 'image/giff': $filetype_ext = '.gif'; $read_function = 'imagecreatefromgif'; if (substr(strtolower($image_src), -4) != '.gif') { trigger_error(sprintf($user->lang['FILETYPE_MIMETYPE_MISMATCH'], $image_src, $filetype['mime']), E_USER_WARNING); } break; default: trigger_error('NOT_ALLOWED_FILE_TYPE'); break; } $image_filename = md5(unique_id()) . $filetype_ext; if (!@move_uploaded_file($image_src_full, phpbb_gallery_url::path('upload') . $image_filename)) { if (!@copy($image_src_full, phpbb_gallery_url::path('upload') . $image_filename)) { $user->add_lang('posting'); trigger_error(sprintf($user->lang['GENERAL_UPLOAD_ERROR'], phpbb_gallery_url::path('upload') . $image_filename), E_USER_WARNING); } } @chmod(phpbb_gallery_url::path('upload') . $image_filename, 0777); // The source image is imported, so we delete it. @unlink($image_src_full); $sql_ary = array('image_filename' => $image_filename, 'image_thumbnail' => '', 'image_desc' => '', 'image_desc_uid' => '', 'image_desc_bitfield' => '', 'image_user_id' => $user_data['user_id'], 'image_username' => $user_data['username'], 'image_username_clean' => utf8_clean_string($user_data['username']), 'image_user_colour' => $user_data['user_colour'], 'image_user_ip' => $user->ip, 'image_time' => $start_time + $done_images, 'image_album_id' => $album_id, 'image_status' => phpbb_gallery_image::STATUS_APPROVED, 'image_exif_data' => ''); $image_tools = new phpbb_gallery_image_tools(); $image_tools->set_image_options(phpbb_gallery_config::get('max_filesize'), phpbb_gallery_config::get('max_height'), phpbb_gallery_config::get('max_width')); $image_tools->set_image_data(phpbb_gallery_url::path('upload') . $image_filename); // Read exif data from file $image_tools->read_exif_data(); $sql_ary['image_exif_data'] = $image_tools->exif_data_serialized; $sql_ary['image_has_exif'] = $image_tools->exif_data_exist; if ($filetype[0] > phpbb_gallery_config::get('max_width') || $filetype[1] > phpbb_gallery_config::get('max_height')) { /** * Resize overside images */ if (phpbb_gallery_config::get('allow_resize')) { $image_tools->resize_image(phpbb_gallery_config::get('max_width'), phpbb_gallery_config::get('max_height')); if ($image_tools->resized) { $image_tools->write_image(phpbb_gallery_url::path('upload') . $image_filename, phpbb_gallery_config::get('jpg_quality'), true); } } } if (!$image_tools->exif_data_force_db && $sql_ary['image_has_exif'] == phpbb_gallery_constants::EXIF_DBSAVED) { // Image was not resized, so we can pull the Exif from the image to save db-memory. $sql_ary['image_has_exif'] = phpbb_gallery_constants::EXIF_AVAILABLE; $sql_ary['image_exif_data'] = ''; } // Try to get real filesize from temporary folder (not always working) ;) $sql_ary['filesize_upload'] = @filesize(phpbb_gallery_url::path('upload') . $image_filename) ? @filesize(phpbb_gallery_url::path('upload') . $image_filename) : 0; if ($filename || $image_name == '') { $sql_ary['image_name'] = str_replace("_", " ", utf8_substr($image_src, 0, -4)); } else { $sql_ary['image_name'] = str_replace('{NUM}', $num_offset + $done_images, $image_name); } $sql_ary['image_name_clean'] = utf8_clean_string($sql_ary['image_name']); // Put the images into the database $db->sql_query('INSERT INTO ' . GALLERY_IMAGES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); $done_images++; } // Remove the image from the list unset($images[$images_loop]); $images_loop++; if ($images_loop == 10) { // We made 10 images, so we end for this turn break; } } if ($images_loop) { $image_user = new phpbb_gallery_user($db, $user_data['user_id'], false); $image_user->update_images($images_loop); phpbb_gallery_config::inc('num_images', $images_loop); $todo_images = $todo_images - $images_loop; } phpbb_gallery_album::update_info($album_id); if (!$todo_images) { unlink(phpbb_gallery_url::_return_file($import_schema, 'import', '')); trigger_error(sprintf($user->lang['IMPORT_FINISHED'], $done_images) . adm_back_link($this->u_action)); } else { // Write the new list $this->create_import_schema($import_schema, $album_id, $user_data, $start_time, $num_offset, $done_images, $todo_images, $image_name, $filename, $images); // Redirect $forward_url = $this->u_action . "&import_schema={$import_schema}"; meta_refresh(1, $forward_url); trigger_error(sprintf($user->lang['IMPORT_DEBUG_MES'], $done_images, $todo_images)); } } else { if ($submit) { if (!check_form_key('acp_gallery')) { trigger_error('FORM_INVALID', E_USER_WARNING); } if (!$images) { trigger_error('NO_FILE_SELECTED', E_USER_WARNING); } // Who is the uploader? $username = request_var('username', '', true); $user_id = 0; if ($username) { if (!function_exists('user_get_id_name')) { phpbb_gallery_url::_include('functions_user', 'phpbb'); } user_get_id_name($user_id, $username); } if (is_array($user_id)) { $user_id = $user_id[0]; } if (!$user_id) { $user_id = $user->data['user_id']; } $sql = 'SELECT username, user_colour, user_id FROM ' . USERS_TABLE . ' WHERE user_id = ' . $user_id; $result = $db->sql_query($sql); $user_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$user_row) { trigger_error('HACKING_ATTEMPT', E_USER_WARNING); } // Where do we put them to? $album_id = request_var('album_id', 0); $sql = 'SELECT album_id, album_name FROM ' . GALLERY_ALBUMS_TABLE . ' WHERE album_id = ' . $album_id; $result = $db->sql_query($sql); $album_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$album_row) { trigger_error('HACKING_ATTEMPT', E_USER_WARNING); } $start_time = time(); $import_schema = md5($start_time); $filename = request_var('filename', '') == 'filename' ? true : false; $image_name = request_var('image_name', '', true); $num_offset = request_var('image_num', 0); $this->create_import_schema($import_schema, $album_row['album_id'], $user_row, $start_time, $num_offset, 0, sizeof($images), $image_name, $filename, $images); $forward_url = $this->u_action . "&import_schema={$import_schema}"; meta_refresh(2, $forward_url); trigger_error('IMPORT_SCHEMA_CREATED'); } } $handle = opendir(phpbb_gallery_url::path('import')); $files = array(); while ($file = readdir($handle)) { if (!is_dir(phpbb_gallery_url::path('import') . $file) && (substr(strtolower($file), -4) == '.png' && phpbb_gallery_config::get('allow_png') || substr(strtolower($file), -4) == '.gif' && phpbb_gallery_config::get('allow_gif') || substr(strtolower($file), -4) == '.jpg' && phpbb_gallery_config::get('allow_jpg') || substr(strtolower($file), -5) == '.jpeg' && phpbb_gallery_config::get('allow_jpg'))) { $files[utf8_strtolower($file)] = $file; } } closedir($handle); // Sort the files by name again ksort($files); foreach ($files as $file) { $template->assign_block_vars('imagerow', array('FILE_NAME' => utf8_encode($file))); } $template->assign_vars(array('S_IMPORT_IMAGES' => true, 'ACP_GALLERY_TITLE' => $user->lang['ACP_IMPORT_ALBUMS'], 'ACP_GALLERY_TITLE_EXPLAIN' => $user->lang['ACP_IMPORT_ALBUMS_EXPLAIN'], 'L_IMPORT_DIR_EMPTY' => sprintf($user->lang['IMPORT_DIR_EMPTY'], phpbb_gallery_url::path('import')), 'S_ALBUM_IMPORT_ACTION' => $this->u_action, 'S_SELECT_IMPORT' => phpbb_gallery_album::get_albumbox(false, 'album_id', false, false, false, phpbb_gallery_album::PUBLIC_ALBUM, phpbb_gallery_album::TYPE_UPLOAD), 'U_FIND_USERNAME' => phpbb_gallery_url::append_sid('phpbb', 'memberlist', 'mode=searchuser&form=acp_gallery&field=username&select_single=true'))); }
if ($personal_album_id) { $sql_ary['image_album_id'] = $personal_album_id; } } else { if ($album_data['album_last_image_id'] == $image_id) { $album_sql_ary = array('album_last_image_name' => $image_name); $sql = 'UPDATE ' . GALLERY_ALBUMS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $album_sql_ary) . ' WHERE ' . $db->sql_in_set('album_id', $image_data['image_album_id']); $db->sql_query($sql); } } $rotate = request_var('rotate', 0); if (phpbb_gallery_config::get('allow_rotate') && $rotate > 0 && $rotate % 90 == 0) { $image_tools = new phpbb_gallery_image_tools(); $image_tools->set_image_options(phpbb_gallery_config::get('max_filesize'), phpbb_gallery_config::get('max_height'), phpbb_gallery_config::get('max_width')); $image_tools->set_image_data(phpbb_gallery_url::path('upload') . $image_data['image_filename']); if ($image_data['image_has_exif'] != phpbb_gallery_constants::EXIF_UNAVAILABLE && $image_data['image_has_exif'] != phpbb_gallery_constants::EXIF_DBSAVED) { // Store exif-data to database if there are any and we didn't already do that. $image_tools->read_exif_data(); $sql_ary['image_exif_data'] = $image_tools->exif_data_serialized; $sql_ary['image_has_exif'] = $image_tools->exif_data_exist; } // Rotate the image $image_tools->rotate_image($rotate, phpbb_gallery_config::get('allow_resize')); if ($image_tools->rotated) { $image_tools->write_image($image_tools->image_source, phpbb_gallery_config::get('jpg_quality'), true); } @unlink(phpbb_gallery_url::path('cache') . $image_data['image_filename']); @unlink(phpbb_gallery_url::path('medium') . $image_data['image_filename']); } $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '