2007-06-30 01:19:11 +00:00
< ? php
class UploadTheme extends Themelet {
2009-01-04 19:54:16 +00:00
public function display_block ( Page $page ) {
2007-06-30 01:19:11 +00:00
$page -> add_block ( new Block ( " Upload " , $this -> build_upload_block (), " left " , 20 ));
}
2009-01-04 19:54:16 +00:00
public function display_full ( Page $page ) {
2008-07-24 07:50:31 +00:00
$page -> add_block ( new Block ( " Upload " , " Disk nearly full, uploads disabled " , " left " , 20 ));
}
2009-01-04 19:54:16 +00:00
public function display_page ( Page $page ) {
2012-01-18 08:09:49 +00:00
global $config , $page ;
2012-03-06 15:38:53 +00:00
$tl_enabled = ( $config -> get_string ( " transload_engine " , " none " ) != " none " );
$max_size = $config -> get_int ( 'upload_size' );
$max_kb = to_shorthand_int ( $max_size );
$upload_list = $this -> h_upload_list_1 ();
$html = "
" .make_form(make_link( " upload " ), " POST " , $multipart =True, 'file_upload'). "
< table id = 'large_upload_form' class = 'vert' >
$upload_list
2012-03-08 03:34:57 +00:00
< tr >< td width = '20' > Tags < td colspan = '5' >< input name = 'tags' type = 'text' placeholder = 'tagme' class = 'autocomplete_tags' ></ td ></ tr >
< tr >< td > Source </ td >< td colspan = '5' >< input name = 'source' type = 'text' ></ td ></ tr >
< tr >< td colspan = '6' >< input id = 'uploadbutton' type = 'submit' value = 'Post' ></ td ></ tr >
2012-03-06 15:38:53 +00:00
</ table >
</ form >
< small > ( Max file size is $max_kb ) </ small >
" ;
2011-12-19 01:43:46 +00:00
2012-03-06 15:38:53 +00:00
$page -> set_title ( " Upload " );
$page -> set_heading ( " Upload " );
$page -> add_block ( new NavBlock ());
$page -> add_block ( new Block ( " Upload " , $html , " main " , 20 ));
if ( $tl_enabled ) {
$page -> add_block ( new Block ( " Bookmarklets " , $this -> h_bookmarklets (), " left " , 20 ));
}
}
protected function h_upload_list_1 () {
global $config ;
$upload_list = " " ;
$upload_count = $config -> get_int ( 'upload_count' );
$tl_enabled = ( $config -> get_string ( " transload_engine " , " none " ) != " none " );
if ( $tl_enabled ) {
$upload_list .= "
< tr >
< td colspan = '2' > Files </ td >
< td colspan = '2' > URLs </ td >
2012-03-08 03:34:57 +00:00
< td colspan = '2' > Image - Specific Tags </ td >
2012-03-06 15:38:53 +00:00
</ tr >
" ;
for ( $i = 0 ; $i < $upload_count ; $i ++ ) {
$upload_list .= "
< tr >
< td colspan = '2' >< input type = 'file' name = 'data$i' ></ td >
< td colspan = '2' >< input type = 'text' name = 'url$i' </ td >
2012-03-08 03:34:57 +00:00
< td colspan = '2' >< input type = 'text' name = 'tags$i' ></ td >
2012-03-06 15:38:53 +00:00
</ tr >
" ;
}
}
else {
2012-03-08 03:34:57 +00:00
$upload_list .= "
< tr >
< td colspan = '4' > Files </ td >
< td colspan = '2' > Image - Specific Tags </ td >
</ tr >
" ;
2012-03-06 15:38:53 +00:00
for ( $i = 0 ; $i < $upload_count ; $i ++ ) {
$upload_list .= "
< tr >
< td colspan = '4' >< input type = 'file' name = 'data$i' ></ td >
2012-03-08 03:34:57 +00:00
< td colspan = '2' >< input type = 'text' name = 'tags$i' ></ td >
2012-03-06 15:38:53 +00:00
</ tr >
" ;
}
}
return $upload_list ;
}
protected function h_upload_List_2 () {
global $config ;
2012-01-18 08:09:49 +00:00
$tl_enabled = ( $config -> get_string ( " transload_engine " , " none " ) != " none " );
2011-12-19 01:43:46 +00:00
// Uploader 2.0!
2007-07-19 17:47:07 +00:00
$upload_list = " " ;
2012-01-16 05:07:04 +00:00
$upload_count = $config -> get_int ( 'upload_count' );
2012-03-06 12:22:08 +00:00
for ( $i = 0 ; $i < $upload_count ; $i ++ ) {
2012-03-06 15:38:53 +00:00
$a = $i + 1 ;
$s = $i - 1 ;
2012-01-16 21:10:51 +00:00
2012-03-06 15:38:53 +00:00
if ( $i != 0 ) {
2011-12-24 23:28:33 +00:00
$upload_list .= " <tr id='row $i ' style='display:none'> " ;
} else {
$upload_list .= " <tr id='row $i '> " ;
2012-01-16 21:10:51 +00:00
}
$upload_list .= " <td width='15'> " ;
2011-12-24 23:28:33 +00:00
2012-03-06 15:38:53 +00:00
if ( $i == 0 ) {
2012-01-16 21:10:51 +00:00
$js = ' javascript : $ ( function () {
$ ( " #row'. $a .' " ) . show ();
$ ( " #hide'. $i .' " ) . hide ();
$ ( " #hide'. $a .' " ) . show ();}); ' ;
2012-03-06 15:38:53 +00:00
$upload_list .= "
< div id = 'hide$i' >
< img id = 'wrapper' src = 'ext/upload/minus.png' />
< a href = '#' onclick = '$js' >< img src = 'ext/upload/plus.png' ></ a >
</ div >
" ;
2012-01-16 21:10:51 +00:00
} else {
$js = ' javascript : $ ( function () {
$ ( " #row'. $i .' " ) . hide ();
$ ( " #hide'. $i .' " ) . hide ();
$ ( " #hide'. $s .' " ) . show ();
$ ( " #data'. $i .' " ) . val ( " " );
$ ( " #url'. $i .' " ) . val ( " " );
}); ' ;
2012-03-06 15:38:53 +00:00
$upload_list .= "
< div id = 'hide$i' >
< a href = '#' onclick = '$js' >< img src = 'ext/upload/minus.png' /></ a >
" ;
2012-01-16 21:10:51 +00:00
2012-02-04 19:17:52 +00:00
if ( $a == $upload_count ){
2012-01-17 10:56:52 +00:00
$upload_list .= " <img id='wrapper' src='ext/upload/plus.png' /> " ;
2012-03-06 15:38:53 +00:00
}
else {
2012-01-16 21:10:51 +00:00
$js1 = ' javascript : $ ( function () {
$ ( " #row'. $a .' " ) . show ();
$ ( " #hide'. $i .' " ) . hide ();
$ ( " #hide'. $a .' " ) . show (); }); ' ;
2011-12-24 23:28:33 +00:00
$upload_list .=
2012-01-16 21:10:51 +00:00
" <a href='#' onclick=' $js1 '> " .
" <img src='ext/upload/plus.png' /></a> " ;
}
2012-03-06 15:38:53 +00:00
$upload_list .= " </div> " ;
2012-01-16 21:10:51 +00:00
}
2012-03-06 15:38:53 +00:00
$upload_list .= " </td> " ;
2011-12-19 01:43:46 +00:00
2012-01-16 21:10:51 +00:00
$js2 = ' javascript : $ ( function () {
2012-01-17 10:56:52 +00:00
$ ( " #url'. $i .' " ) . hide ();
2012-01-16 21:10:51 +00:00
$ ( " #url'. $i .' " ) . val ( " " );
$ ( " #data'. $i .' " ) . show (); }); ' ;
2012-03-06 15:38:53 +00:00
$upload_list .= "
< form >< td width = '60' >< input id = 'radio_button_a$i' type = 'radio' name = 'method' value = 'file' checked = 'checked' onclick = '$js2' /> File < br > " ;
2012-01-16 21:10:51 +00:00
if ( $tl_enabled ) {
$js = ' javascript : $ ( function () {
$ ( " #data'. $i .' " ) . hide ();
$ ( " #data'. $i .' " ) . val ( " " );
$ ( " #url'. $i .' " ) . show (); }); ' ;
$upload_list .=
2012-01-17 10:56:52 +00:00
" <input id='radio_button_b $i ' type='radio' name='method' value='url' onclick=' $js ' /> URL</ br></td></form>
2012-01-16 21:10:51 +00:00
< td >
< input id = 'data$i' name = 'data$i' class = 'wid' type = 'file' >
< input id = 'url$i' name = 'url$i' class = 'wid' type = 'text' style = 'display:none' >
</ td > " ;
} else {
$upload_list .= " </td>
< td width = '250' >< input id = 'data$i' name = 'data$i' class = 'wid' type = 'file' ></ td >
" ;
}
2011-12-19 01:43:46 +00:00
2007-07-19 17:47:07 +00:00
$upload_list .= "
</ tr >
" ;
}
2011-12-14 07:53:48 +00:00
2012-03-06 15:38:53 +00:00
return $upload_list ;
2007-07-19 17:47:07 +00:00
}
2012-03-06 12:22:08 +00:00
protected function h_bookmarklets () {
global $config ;
$link = make_http ( make_link ( " upload " ));
$main_page = make_http ( make_link ());
$title = $config -> get_string ( 'title' );
$max_size = $config -> get_int ( 'upload_size' );
$max_kb = to_shorthand_int ( $max_size );
$delimiter = $config -> get_bool ( 'nice_urls' ) ? '?' : '&' ;
$html = '' ;
$js = ' javascript : (
function () {
if ( typeof window == " undefined " || ! window . location || window . location . href == " about:blank " ) {
window . location = " '. $main_page .' " ;
}
else if ( typeof document == " undefined " || ! document . body ) {
window . location = " '. $main_page .'?url= " + encodeURIComponent ( window . location . href );
}
else if ( window . location . href . match ( " \ / \ /'. $_SERVER["HTTP_HOST"] .'.* " )) {
alert ( " You are already at '. $title .'! " );
}
else {
var tags = prompt ( " Please enter tags " , " tagme " );
if ( tags != " " && tags != null ) {
var link = " '. $link . $delimiter .'url= " + location . href + " &tags= " + tags ;
var w = window . open ( link , " _blank " );
}
}
}
)(); ' ;
2012-03-06 15:38:53 +00:00
$html .= '<a href=\'' . $js . '\'>Upload to ' . $title . '</a>' ;
2012-03-06 12:22:08 +00:00
$html .= ' (Drag & drop onto your bookmarks toolbar, then click when looking at an image)' ;
// Bookmarklet checks if shimmie supports ext. If not, won't upload to site/shows alert saying not supported.
$supported_ext = " jpg jpeg gif png " ;
2012-05-23 09:39:21 +00:00
if ( class_exists ( " FlashFileHandler " )){ $supported_ext .= " swf " ;}
if ( class_exists ( " ICOFileHandler " )){ $supported_ext .= " ico ani cur " ;}
if ( class_exists ( " MP3FileHandler " )){ $supported_ext .= " mp3 " ;}
if ( class_exists ( " SVGFileHandler " )){ $supported_ext .= " svg " ;}
2012-03-06 12:22:08 +00:00
$title = " Booru to " . $config -> get_string ( 'title' );
// CA=0: Ask to use current or new tags | CA=1: Always use current tags | CA=2: Always use new tags
$html .= ' < p >< a href = " javascript:
var ste =& quot ; '. $link . $delimiter .' url =& quot ;;
var supext =& quot ; '.$supported_ext.' & quot ;;
var maxsize =& quot ; '.$max_kb.' & quot ;;
var CA = 0 ;
void ( document . body . appendChild ( document . createElement ( & quot ; script & quot ;)) . src =& quot ; '.make_http(get_base_href())."/ext/upload/bookmarklet.js".' & quot ;)
2012-03-06 15:38:53 +00:00
" >'. $title . '</a> (Click when looking at an image page. Works on sites running Shimmie / Danbooru / Gelbooru. (This also grabs the tags / rating / source!))';
2012-03-06 12:22:08 +00:00
return $html ;
}
2011-08-25 00:53:53 +00:00
/* only allows 1 file to be uploaded - for replacing another image file */
2012-02-10 05:08:03 +00:00
public function display_replace_page ( Page $page , /*int*/ $image_id ) {
2012-01-18 15:32:43 +00:00
global $config , $page ;
2011-08-25 00:53:53 +00:00
$tl_enabled = ( $config -> get_string ( " transload_engine " , " none " ) != " none " );
2012-01-18 15:32:43 +00:00
$js2 = ' javascript : $ ( function () {
$ ( " #data " ) . hide ();
$ ( " #data " ) . val ( " " );
$ ( " #url " ) . show (); }); ' ;
$js1 = ' javascript : $ ( function () {
$ ( " #url " ) . hide ();
$ ( " #url " ) . val ( " " );
$ ( " #data " ) . show (); }); ' ;
2011-08-25 00:53:53 +00:00
$upload_list = '' ;
$upload_list .= "
2011-12-21 02:40:30 +00:00
< tr >
2012-01-18 15:32:43 +00:00
< td width = '60' >< form >< input id = 'radio_button_a' type = 'radio' name = 'method' value = 'file' checked = 'checked' onclick = '$js1' /> File < br > " ;
2011-12-21 02:40:30 +00:00
if ( $tl_enabled ) {
$upload_list .= "
2012-01-18 15:32:43 +00:00
< input id = 'radio_button_b' type = 'radio' name = 'method' value = 'url' onclick = '$js2' /> URL </ br ></ td ></ form >
< td >< input id = 'data' name = 'data' class = 'wid' type = 'file' >< input id = 'url' name = 'url' class = 'wid' type = 'text' style = 'display:none' ></ td >
2011-12-21 02:40:30 +00:00
" ;
} else {
$upload_list .= " </form></td>
" ;
}
2011-08-25 00:53:53 +00:00
$max_size = $config -> get_int ( 'upload_size' );
$max_kb = to_shorthand_int ( $max_size );
2011-08-26 01:35:59 +00:00
$image = Image :: by_id ( $image_id );
$thumbnail = $this -> build_thumb_html ( $image , null );
2011-09-04 17:46:12 +00:00
$html = "
< div style = 'clear:both;' ></ div >
< p > Replacing Image ID " . $image_id . " < br > Please note : You will have to refresh the image page , or empty your browser cache .</ p > "
2011-08-26 01:35:59 +00:00
. $thumbnail . " <br> "
. make_form ( make_link ( " upload/replace/ " . $image_id ), " POST " , $multipart = True ) . "
2011-08-25 03:55:44 +00:00
< input type = 'hidden' name = 'image_id' value = '$image_id' >
2011-12-21 02:40:30 +00:00
< table id = 'large_upload_form' class = 'vert' >
2011-08-25 00:53:53 +00:00
$upload_list
< tr >< td > Source </ td >< td colspan = '3' >< input name = 'source' type = 'text' ></ td ></ tr >
< tr >< td colspan = '4' >< input id = 'uploadbutton' type = 'submit' value = 'Post' ></ td ></ tr >
</ table >
</ form >
< small > ( Max file size is $max_kb ) </ small >
" ;
2011-08-25 03:55:44 +00:00
2011-08-26 01:35:59 +00:00
$page -> set_title ( " Replace Image " );
$page -> set_heading ( " Replace Image " );
2011-08-25 00:53:53 +00:00
$page -> add_block ( new NavBlock ());
2011-08-26 01:35:59 +00:00
$page -> add_block ( new Block ( " Upload Replacement Image " , $html , " main " , 20 ));
2011-08-25 00:53:53 +00:00
}
2012-02-10 05:08:03 +00:00
public function display_upload_status ( Page $page , /*bool*/ $ok ) {
2007-06-30 01:19:11 +00:00
if ( $ok ) {
$page -> set_mode ( " redirect " );
2007-08-23 11:14:03 +00:00
$page -> set_redirect ( make_link ());
2007-06-30 01:19:11 +00:00
}
else {
$page -> set_title ( " Upload Status " );
$page -> set_heading ( " Upload Status " );
$page -> add_block ( new NavBlock ());
}
}
2012-02-10 05:08:03 +00:00
public function display_upload_error ( Page $page , /*string*/ $title , /*string*/ $message ) {
2007-06-30 01:19:11 +00:00
$page -> add_block ( new Block ( $title , $message ));
}
2007-08-23 11:14:03 +00:00
protected function build_upload_block () {
2007-06-30 01:19:11 +00:00
global $config ;
$upload_list = " " ;
2012-01-16 05:07:04 +00:00
$upload_count = $config -> get_int ( 'upload_count' );
for ( $i = 0 ; $i < $upload_count ; $i ++ ) {
2007-06-30 01:19:11 +00:00
if ( $i == 0 ) $style = " " ; // "style='display:visible'";
else $style = " style='display:none' " ;
2012-06-26 18:38:22 +00:00
$upload_list .= " <input id='data $i ' name='data $i ' $style onchange= \" $ ('#data " . ( $i + 1 ) . " ').show() \" size='16' type='file'> \n " ;
2007-06-30 01:19:11 +00:00
}
2007-07-16 13:15:56 +00:00
$max_size = $config -> get_int ( 'upload_size' );
2007-07-19 12:54:49 +00:00
$max_kb = to_shorthand_int ( $max_size );
2007-06-30 01:19:11 +00:00
// <input type='hidden' name='max_file_size' value='$max_size' />
return "
2012-02-12 12:00:19 +00:00
< div class = 'mini_upload' >
2010-10-11 11:20:49 +00:00
" .make_form(make_link( " upload " ), " POST " , $multipart =True). "
2007-06-30 01:19:11 +00:00
$upload_list
2012-02-09 14:45:18 +00:00
< input name = 'tags' type = 'text' placeholder = 'tagme' class = 'autocomplete_tags' >
2007-06-30 01:19:11 +00:00
< input type = 'submit' value = 'Post' >
</ form >
2012-02-12 12:40:07 +00:00
< small > ( Max file size is $max_kb ) </ small >
2009-10-26 12:08:54 +00:00
< noscript >< a href = '".make_link("upload")."' > Larger Form </ a ></ noscript >
2012-02-12 12:00:19 +00:00
</ div >
2007-06-30 01:19:11 +00:00
" ;
}
}
2012-02-09 14:45:18 +00:00
?>