added first version of mass tagger

This commit is contained in:
Christian Walde 2010-07-31 16:41:13 +02:00
parent 0396ec5283
commit 49d4f36071
6 changed files with 161 additions and 0 deletions

1
.gitignore vendored
View file

@ -29,6 +29,7 @@ ext/image_hash_ban
ext/ipban
ext/link_image
ext/log_db
ext/mass_tagger
ext/news
ext/notes
ext/notes

View file

@ -0,0 +1,60 @@
<?php
/*
* Name: Mass Tagger
* Author: Christian Walde <walde.christian@googlemail.com>
* License: WTFPL
* Description: Tag a bunch of images at once
* Documentation:
* Once enabled, a new "Mass Tagger" box will appear on the left hand side of
* post listings, with a button to enable the mass tagger. Once clicked JS will
* add buttons to each image to mark them for tagging, and a field for
* inputting tags will appear. Once the "Tag" button is clicked, the tags in
* the text field will be added to marked images.
*
* As of now only compatible with the lite theme.
*/
class MassTagger extends SimpleExtension {
public function onInitExt($event) {
return;
}
public function onPostListBuilding($event) {
global $config, $page, $user;
if( !$user->is_admin() ) return;
$this->theme->display_mass_tagger( $page, $event, $config );
}
public function onPageRequest($event) {
global $config, $page, $user;
if( !$event->page_matches("mass_tagger") ) return;
if( !$user->is_admin() ) return;
if($event->get_arg(0) == "tag") $this->_apply_mass_tags( $config, $page, $user, $event );
}
private function _apply_mass_tags( $config, $page, $user, $event ) {
if( !isset($_POST['ids']) or !isset($_POST['tag']) ) return;
$tag = $_POST['tag'];
$ids = explode( ':', $_POST['ids'] );
$ids = array_filter ( $ids , 'is_numeric' );
$ids = array_map( "Image::by_id", $ids );
$func = function( $image ) use ( $tag ) {
$tag .= " " . $image->get_tag_list();
$image->set_tags( $tag );
};
array_walk( $ids, $func );
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list"));
}
}
?>

View file

@ -0,0 +1,8 @@
.zoom{ position:absolute;display:none;margin:-110px 27px; }
.thumbblock:hover .zoom{ display:block; }
.zoom:hover{ border: 3px solid blue; }
/*.zoom img:hover{ background:url(/contrib/simpletest/data/pbx_screenshot.jpg) no-repeat;}*/
.zoom img { width: 100px; height: 100px; }
#mass_tagger_controls { display:none; }

View file

@ -0,0 +1,64 @@
function toggle_tag( button, id ) {
id += ":";
var list = $('#mass_tagger_ids');
var string = list.val();
if( string.indexOf( id ) > -1 ) return remove_mass_tag_id( button, list, id, string );
return add_mass_tag_id( button, list, id, string );
}
function add_mass_tag_id( button, list, id, string ) {
$(button).attr( 'style', 'display:block;border: 3px solid blue;' );
string += id;
list.val( string );
return false;
}
function remove_mass_tag_id( button, list, id, string ) {
$(button).attr( 'style', '' );
string = string.replace( id, '' );
list.val( string );
return false;
}
function activate_mass_tagger () {
$('.thumbblock').each(add_mass_tag_button);
$('#mass_tagger_controls').attr( 'style', 'display:block' );
$('#mass_tagger_activate').attr( 'style', 'display:none' );
return false;
}
function add_mass_tag_button ( index, block ) {
var id = get_image_id( block );
var button = create_mass_tag_button( id );
$(block).append( button );
return;
}
function get_image_id ( block ) {
var link = $(block).children(":first").attr('href');
var id = link.split('/').pop();
return id;
}
function create_mass_tag_button ( id ) {
var img = $('<img />');
img.attr("src",'/ext/mass_tagger/toggle.gif');
var link = $('<a />');
link.attr("class",'zoom');
link.attr("onclick",'return toggle_tag( this, "'+id+'")');
link.attr("href",'#');
link.append( img );
return link;
}

View file

@ -0,0 +1,28 @@
<?php
class MassTaggerTheme extends Themelet {
/*
* Show $text on the $page
*/
public function display_mass_tagger( Page $page, Event $event, $config ) {
$base_href = $config->get_string('base_href');
$page->add_header("<link href='/ext/mass_tagger/mass_tagger.css' type='text/css' rel='stylesheet' />");
$page->add_header("<script src='/ext/mass_tagger/mass_tagger.js' type='text/javascript'></script>");
$body = "
<form action='".make_link("mass_tagger/tag")."' method='POST'>
<input id='mass_tagger_activate' type='button' onclick='activate_mass_tagger();' value='Activate'/>
<div id='mass_tagger_controls'>
Click on images to mark them. Use the 'Index Options' in the Board Config to increase the amount of shown images.
<br />
<input type='hidden' name='ids' id='mass_tagger_ids' />
<label>Tags: <input type='text' name='tag' /></label>
<input type='submit' value='Tag Marked Images' />
</div>
</form>
";
$block = new Block("Mass Tagger", $body, "left", 50);
$page->add_block( $block );
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB