merge mass tagger
This commit is contained in:
commit
853ea10fea
11 changed files with 178 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -35,6 +35,7 @@ ext/image_hash_ban
|
|||
ext/ipban
|
||||
ext/link_image
|
||||
ext/log_db
|
||||
ext/mass_tagger
|
||||
ext/news
|
||||
ext/notes
|
||||
ext/numeric_score
|
||||
|
|
60
contrib/mass_tagger/main.php
Normal file
60
contrib/mass_tagger/main.php
Normal 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"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
68
contrib/mass_tagger/script.js
Normal file
68
contrib/mass_tagger/script.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
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 ( image_link ) {
|
||||
|
||||
find_thumb_link_containers().each(
|
||||
function ( index, block ) {
|
||||
add_mass_tag_button( block, image_link );
|
||||
}
|
||||
);
|
||||
$('#mass_tagger_controls').attr( 'style', 'display:block' );
|
||||
$('#mass_tagger_activate').attr( 'style', 'display:none' );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function add_mass_tag_button ( block, image_link ) {
|
||||
|
||||
var id = get_image_id( block );
|
||||
|
||||
var button = create_mass_tag_button( id, image_link );
|
||||
$(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, image_link ) {
|
||||
var img = $('<img />');
|
||||
img.attr( "src", image_link+'/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;
|
||||
}
|
8
contrib/mass_tagger/style.css
Normal file
8
contrib/mass_tagger/style.css
Normal 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; }
|
26
contrib/mass_tagger/theme.php
Normal file
26
contrib/mass_tagger/theme.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
class MassTaggerTheme extends Themelet {
|
||||
/*
|
||||
* Show $text on the $page
|
||||
*/
|
||||
public function display_mass_tagger( Page $page, Event $event, $config ) {
|
||||
$data_href = get_base_href();
|
||||
$body = "
|
||||
<form action='".make_link("mass_tagger/tag")."' method='POST'>
|
||||
<input id='mass_tagger_activate' type='button' onclick='activate_mass_tagger(\"$data_href\");' 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 );
|
||||
}
|
||||
}
|
||||
?>
|
BIN
contrib/mass_tagger/toggle.gif
Normal file
BIN
contrib/mass_tagger/toggle.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
|
@ -106,7 +106,7 @@ class SimpleUrl {
|
|||
}
|
||||
if (preg_match('/^([^\/]*)@(.*)/', $url, $matches)) {
|
||||
$url = $prefix . $matches[2];
|
||||
$parts = split(":", $matches[1]);
|
||||
$parts = explode(":", $matches[1]);
|
||||
return array(
|
||||
urldecode($parts[0]),
|
||||
isset($parts[1]) ? urldecode($parts[1]) : false);
|
||||
|
|
|
@ -190,7 +190,7 @@ class HttpHeaderExpectation extends SimpleExpectation {
|
|||
* @access protected
|
||||
*/
|
||||
function _findHeader($compare) {
|
||||
$lines = split("\r\n", $compare);
|
||||
$lines = explode("\r\n", $compare);
|
||||
foreach ($lines as $line) {
|
||||
if ($this->_testHeaderLine($line)) {
|
||||
return $line;
|
||||
|
@ -206,7 +206,7 @@ class HttpHeaderExpectation extends SimpleExpectation {
|
|||
* @access private
|
||||
*/
|
||||
function _testHeaderLine($line) {
|
||||
if (count($parsed = split(':', $line, 2)) < 2) {
|
||||
if (count($parsed = explode(':', $line, 2)) < 2) {
|
||||
return false;
|
||||
}
|
||||
list($header, $value) = $parsed;
|
||||
|
|
|
@ -187,7 +187,7 @@ class MemcacheCache implements CacheEngine {
|
|||
var $memcache=null, $hits=0, $misses=0;
|
||||
|
||||
public function __construct($args) {
|
||||
$hp = split(":", $args);
|
||||
$hp = explode(":", $args);
|
||||
if(class_exists("Memcache")) {
|
||||
$this->memcache = new Memcache;
|
||||
@$this->memcache->pconnect($hp[0], $hp[1]);
|
||||
|
|
|
@ -990,7 +990,7 @@ function _get_page_request() {
|
|||
global $config;
|
||||
$args = _get_query_parts();
|
||||
|
||||
if( empty($args) || strlen($args[0]) === 0) {
|
||||
if(empty($args) || strlen($args[0]) === 0) {
|
||||
$args = explode('/', $config->get_string('front_page'));
|
||||
}
|
||||
|
||||
|
|
9
lib/helpers.js
Normal file
9
lib/helpers.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
function find_thumb_link_containers () {
|
||||
|
||||
var post_link = "a[href*='/post/view/']";
|
||||
var has_thumb_img = ":has(img[src*='/thumb/'])";
|
||||
|
||||
var list = $( post_link + has_thumb_img ).parent();
|
||||
|
||||
return list;
|
||||
}
|
Reference in a new issue