From 49d4f36071a1bdea5ed6adc313a18317e30c08e0 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Sat, 31 Jul 2010 16:41:13 +0200 Subject: [PATCH] added first version of mass tagger --- .gitignore | 1 + contrib/mass_tagger/main.php | 60 ++++++++++++++++++++++++++ contrib/mass_tagger/mass_tagger.css | 8 ++++ contrib/mass_tagger/mass_tagger.js | 64 ++++++++++++++++++++++++++++ contrib/mass_tagger/theme.php | 28 ++++++++++++ contrib/mass_tagger/toggle.gif | Bin 0 -> 3455 bytes 6 files changed, 161 insertions(+) create mode 100644 contrib/mass_tagger/main.php create mode 100644 contrib/mass_tagger/mass_tagger.css create mode 100644 contrib/mass_tagger/mass_tagger.js create mode 100644 contrib/mass_tagger/theme.php create mode 100644 contrib/mass_tagger/toggle.gif diff --git a/.gitignore b/.gitignore index 182c8212..000cecbd 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/contrib/mass_tagger/main.php b/contrib/mass_tagger/main.php new file mode 100644 index 00000000..65276e20 --- /dev/null +++ b/contrib/mass_tagger/main.php @@ -0,0 +1,60 @@ + + * 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")); + + } + +} +?> diff --git a/contrib/mass_tagger/mass_tagger.css b/contrib/mass_tagger/mass_tagger.css new file mode 100644 index 00000000..13467ae1 --- /dev/null +++ b/contrib/mass_tagger/mass_tagger.css @@ -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; } diff --git a/contrib/mass_tagger/mass_tagger.js b/contrib/mass_tagger/mass_tagger.js new file mode 100644 index 00000000..2461fa8b --- /dev/null +++ b/contrib/mass_tagger/mass_tagger.js @@ -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.attr("src",'/ext/mass_tagger/toggle.gif'); + + var link = $(''); + link.attr("class",'zoom'); + link.attr("onclick",'return toggle_tag( this, "'+id+'")'); + link.attr("href",'#'); + + link.append( img ); + + return link; +} diff --git a/contrib/mass_tagger/theme.php b/contrib/mass_tagger/theme.php new file mode 100644 index 00000000..3d28f344 --- /dev/null +++ b/contrib/mass_tagger/theme.php @@ -0,0 +1,28 @@ +get_string('base_href'); + $page->add_header(""); + $page->add_header(""); + $body = " +
+ +
+ Click on images to mark them. Use the 'Index Options' in the Board Config to increase the amount of shown images. +
+ + + + +
+
+ "; + $block = new Block("Mass Tagger", $body, "left", 50); + $page->add_block( $block ); + } +} +?> diff --git a/contrib/mass_tagger/toggle.gif b/contrib/mass_tagger/toggle.gif new file mode 100644 index 0000000000000000000000000000000000000000..64c3c765f29bb025b1f3e883504848cfbf629b07 GIT binary patch literal 3455 zcmdUx`#;l<;V4?1OoB#@j)OE zetv#IK|vuQAs7q>hr>lgL_|eJkw~PtxHt-hLZi`AQc}{=(lRnK7z{>MR#r|5_+s2aQJa^z`)d^78if z_VMw#di5%uPWSco{rm5~{rvp={rv+10s;dAgM))ZLPEmA!otJDBO)RqBO{}tqN1at zV`5?$3`SyNVsdhFN=nN0>(`k~W?EX>jT<*IGBR%7yqTGqnVp@To12@TpI=y5SX^9O zT3T9GR#skKURhaLRaJHG-o5JT>YAFG+S=N>y1M%M`i6#v#>U3`_wP3~HMO*~w6?ak zwY5Eb_^`dboy}%ecM*?A+Yk>({T}ym>P}KmYda+l7UN#l^*?rKRQN<&~9{ckkY+9C@-WpTB(h^7ZT2jg5`X&CRW?t#9AHZEtUX|Ni~Qj~_cbJG;BPdwYBP z`};qC{`~dp*YDrI|NQy$e}(%0WD0u_5CHH1;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