'/^([^\t]+)\t+(.*)$/', 'space' => '/^([^\s]+)\s+(.*)$/', 'comma' => '/^([^,]+),+(.*)$/', 'semicolon' => '/^([^;]+);+(.*)$/', ); if (isset($_POST['submit'])) { if (!in_array($_POST['separator'], array_keys($regex_for_separator))) { die('Hacking attempt!'); } if (!in_array($_POST['property'], array('name', 'comment', 'author', 'tags'))) { die('Hacking attempt!'); } } // +-----------------------------------------------------------------------+ // | Actions | // +-----------------------------------------------------------------------+ if (isset($_FILES) and !empty($_FILES['update'])) { $starttime = get_moment(); if (UPLOAD_ERR_OK == $_FILES['update']['error']) { if ('text/plain' == $_FILES['update']['type']) { $text_file = $_FILES['update']['tmp_name']; } else { array_push($page['errors'], l10n('Wrong file, please select a plain text file')); } if (isset($text_file)) { $raw = file_get_contents($text_file); $raw_lines = explode("\n", $raw); $query = 'SELECT id, file FROM '.IMAGES_TABLE.';'; $existing_files = hash_from_query($query, 'file'); $updates = array(); $update_files = array(); $missing_files = array(); $tags_of = array(); foreach ($raw_lines as $raw_line) { if (!preg_match($regex_for_separator[$_POST['separator']], $raw_line, $matches)) { continue; } // in case the same file is defined twice, we only save the first occurence if (isset($update_files[$matches[1]]) or isset($missing_files[$matches[1]])) { continue; } if (isset($existing_files[$matches[1]])) { $update_files[$matches[1]] = true; $image_id = $existing_files[$matches[1]]['id']; if ('tags' == $_POST['property']) { $tags_of[$image_id] = array(); $raw_tags = explode(',', $matches[2]); foreach ($raw_tags as $tag) { $tag = trim($tag); if (empty($tag)) { continue; } $tag_id = tag_id_from_tag_name($tag); array_push($tags_of[$image_id], $tag_id); } } else { array_push( $updates, array( 'id' => $image_id, $_POST['property'] => pwg_db_real_escape_string($matches[2]), // TODO right trim ) ); } } else { $missing_files[$matches[1]] = true; } } if ('tags' == $_POST['property']) { set_tags_of($tags_of); } else { mass_updates( IMAGES_TABLE, array( 'primary' => array('id'), 'update' => array($_POST['property']), ), $updates ); } $endtime = get_moment(); $elapsed = ($endtime - $starttime); array_push( $page['infos'], sprintf( l10n('%d photos updated'), count(array_keys($update_files)) ) ); if (count($missing_files) > 0) { array_push( $page['errors'], sprintf( l10n('%d photos are missing in Piwigo: %s'), count($missing_files), implode(', ', array_keys($missing_files)) ) ); } } } else { array_push($page['errors'], $_FILES['update']['error']); } } // +-----------------------------------------------------------------------+ // | form options | // +-----------------------------------------------------------------------+ // image level options $selected_level = isset($_POST['level']) ? $_POST['level'] : 0; $template->assign( array( 'level_options'=> get_privacy_level_options(), 'level_options_selected' => array($selected_level) ) ); ?>