mass source setter

This commit is contained in:
Shish 2012-03-19 19:42:52 +00:00
parent 31f70251bb
commit 49c0d09281
2 changed files with 52 additions and 0 deletions

View File

@ -85,6 +85,20 @@ class TagEdit extends Extension {
$page->set_redirect(make_link("admin"));
}
}
if($event->get_arg(0) == "mass_source_set") {
if($user->can("mass_tag_edit") && isset($_POST['tags']) && isset($_POST['source'])) {
$this->mass_source_edit($_POST['tags'], $_POST['source']);
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list"));
}
}
}
}
public function onPostListBuilding(PostListBuildingEvent $event) {
global $user;
if($user->is_admin() && !empty($event->search_terms)) {
$this->theme->display_mss(implode(" ", $event->search_terms));
}
}
@ -205,5 +219,29 @@ class TagEdit extends Extension {
}
}
}
private function mass_source_edit($tags, $source) {
global $database;
global $config;
$tags = Tag::explode($tags);
$last_id = -1;
while(true) {
// make sure we don't look at the same images twice.
// search returns high-ids first, so we want to look
// at images with lower IDs than the previous.
$search_forward = $tags;
if($last_id >= 0) $search_forward[] = "id<$last_id";
$images = Image::find_images(0, 100, $search_forward);
if(count($images) == 0) break;
foreach($images as $image) {
$image->set_source($source);
$last_id = $image->id;
}
}
}
}
?>

View File

@ -19,6 +19,20 @@ class TagEditTheme extends Themelet {
$page->add_block(new Block("Mass Tag Edit", $html));
}
public function display_mss($terms) {
global $page;
$h_terms = html_escape($terms);
$html = make_form(make_link("tag_edit/mass_source_set"), "POST") . "
<input type='hidden' name='tags' value='$h_terms'>
<input type='text' name='source' value=''>
<input type='submit' value='Set Source For All'>
</form>
";
$page->add_block(new Block("List Controls", $html, "left"));
}
public function get_tag_editor_html(Image $image) {
global $user;
$h_tags = html_escape($image->get_tag_list());