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 ) {
2007-07-19 17:47:07 +00:00
global $config ;
$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 = " " ;
for ( $i = 0 ; $i < $config -> get_int ( 'upload_count' ); $i ++ ) {
2011-12-24 23:28:33 +00:00
$a = $i + 1 ;
$s = $i - 1 ;
if ( ! $i == 0 ){
$upload_list .= " <tr id='row $i ' style='display:none'> " ;
} else {
$upload_list .= " <tr id='row $i '> " ;
}
$upload_list .= " <td width='15'> " ;
if ( $i == 0 ){
$upload_list .= " <div id='hide $i '><img id='wrapper' src='ext/upload/minus.png' /> " .
2011-12-27 12:10:01 +00:00
" <a href='#' onclick='javascript:document.getElementById("row $a ").style.display = "";document.getElementById("hide $i ").style.display = "none";document.getElementById("hide $a ").style.display = "";'> " .
2011-12-24 23:28:33 +00:00
" <img src='ext/upload/plus.png'></a></div></td> " ;
} else {
$upload_list .= " <div id='hide $i '>
2011-12-27 12:10:01 +00:00
< a href = '#' onclick = ' javascript : document . getElementById ( & quot ; row $i & quot ;) . style . display = & quot ; none & quot ;; " .
2011-12-24 23:28:33 +00:00
" document.getElementById("hide $i ").style.display = "none"; " .
" document.getElementById("hide $s ").style.display = ""; " .
" document.getElementById("data $i ").value = ""; " .
" document.getElementById("url $i ").value = "";'> " .
" <img src='ext/upload/minus.png' /></a> " ;
if ( $a == $config -> get_int ( 'upload_count' )){
$upload_list .= " <img id='wrapper' src='ext/upload/plus.png' /> " ;
} else {
$upload_list .=
2011-12-27 12:10:01 +00:00
" <a href='#' onclick='javascript:document.getElementById("row $a ").style.display = ""; " .
2011-12-24 23:28:33 +00:00
" document.getElementById("hide $i ").style.display = "none"; " .
" document.getElementById("hide $a ").style.display = "";'> " .
" <img src='ext/upload/plus.png' /></a> " ;
}
$upload_list .= " </div></td> " ;
}
$upload_list .=
" <td width='60'><form><input id='radio_buttona' type='radio' name='method' value='file' checked='checked' onclick='javascript:document.getElementById("url $i ").style.display = "none";document.getElementById("url $i ").value = "";document.getElementById("data $i ").style.display = ""' /> File<br> " ;
2011-12-19 01:43:46 +00:00
if ( $tl_enabled ) {
2011-12-24 23:28:33 +00:00
$upload_list .=
" <input id='radio_buttonb' type='radio' name='method' value='url' onclick='javascript:document.getElementById("data $i ").style.display = "none";document.getElementById("data $i ").value = "";document.getElementById("url $i ").style.display = ""' /> URL</ br></td></form>
2011-12-19 01:43:46 +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 .= " </form></td>
< td width = '250' >< input id = 'data$i' name = 'data$i' class = 'wid' type = 'file' ></ td >
" ;
}
2007-07-19 17:47:07 +00:00
$upload_list .= "
</ tr >
" ;
}
$max_size = $config -> get_int ( 'upload_size' );
$max_kb = to_shorthand_int ( $max_size );
$html = "
2011-08-13 01:40:51 +00:00
< script type = 'text/javascript' >
2010-04-26 05:00:41 +00:00
$ ( document ) . ready ( function () {
$ ( '#tag_box' ) . DefaultValue ( 'tagme' );
$ ( '#tag_box' ) . autocomplete ( '".make_link("api/internal/tag_list/complete")."' , {
width : 320 ,
max : 15 ,
highlight : false ,
multiple : true ,
multipleSeparator : ' ' ,
scroll : true ,
2010-04-28 10:21:02 +00:00
scrollHeight : 300 ,
selectFirst : false
2010-04-26 05:00:41 +00:00
});
});
</ script >
2010-10-11 11:20:49 +00:00
" .make_form(make_link( " upload " ), " POST " , $multipart =True). "
2011-12-19 01:43:46 +00:00
< table id = 'large_upload_form' class = 'vert' >
2007-07-19 17:47:07 +00:00
$upload_list
2011-12-24 23:28:33 +00:00
< tr >< td ></ td >< td > Tags < td colspan = '3' >< input id = 'tag_box' name = 'tags' type = 'text' ></ td ></ tr >
< tr >< td ></ td >< td > Source </ td >< td colspan = '3' >< input name = 'source' type = 'text' ></ td ></ tr >
2009-07-15 16:09:50 +00:00
< tr >< td colspan = '4' >< input id = 'uploadbutton' type = 'submit' value = 'Post' ></ td ></ tr >
2007-07-19 17:47:07 +00:00
</ table >
</ form >
2010-04-26 05:00:41 +00:00
< small > ( Max file size is $max_kb ) </ small >
2007-07-19 17:47:07 +00:00
" ;
2011-12-19 01:43:46 +00:00
2008-01-03 00:05:53 +00:00
if ( $tl_enabled ) {
2011-12-14 07:53:48 +00:00
$link = make_http ( make_link ( " upload " ));
if ( $config -> get_bool ( 'nice_urls' )){
$delimiter = '?' ;
} else {
$delimiter = '&' ;
}
{
2008-01-03 00:05:53 +00:00
$title = " Upload to " . $config -> get_string ( 'title' );
$html .= '<p><a href="javascript:location.href="' .
2011-12-14 07:53:48 +00:00
$link . $delimiter . 'url="+location.href+"&tags="+prompt("enter tags")">' .
2008-01-03 00:05:53 +00:00
$title . '</a> (Drag & drop onto your bookmarks toolbar, then click when looking at an image)' ;
2011-12-14 07:53:48 +00:00
}
{
2011-12-23 21:28:47 +00:00
/* Danbooru > Shimmie Bookmarklet .
This " should " work on any site running danbooru , unless for some odd reason they switched around the id 's or aren' t using post / list .
2011-12-26 21:29:04 +00:00
Most likely this will stop working when Danbooru updates to v2 , all depends if they switch the ids or not > _ >.
Clicking the link on a danbooru image page should give you something along the lines of :
'http://www.website.com/shimmie/upload?url="http://sonohara.donmai.us/data/crazylongurl.jpg&tags="too many tags"&rating="s"&source="http://danbooru.donmai.us/post/show/012345/"'
TODO : Possibly make the entire / most of the script into a . js file , and just make the bookmarklet load it on click ( Something like that ? )
2011-12-23 21:28:47 +00:00
*/
2011-12-11 06:13:00 +00:00
$title = " Danbooru to " . $config -> get_string ( 'title' );
2011-12-26 21:29:04 +00:00
$html .= '<p><a href="javascript:' .
/* This should stop the bookmarklet being insanely long...not that it's already huge or anything. */
'var ste="' . $link . $delimiter . 'url=";var tag=document.getElementById("post_tags").value;var rtg=document.documentElement.innerHTML.match("<li>Rating: (.*)<\/li>");var srx="http://" + document.location.hostname+document.location.href.match("\/post\/show\/.*\/");' .
//The default confirm sucks, mainly due to being unable to change the text in the Ok/Cancel box (Yes/No would be better.)
'if (confirm("OK = Use Current tags.\nCancel = Use new tags.")==true){' . //Just incase some people don't want the insane amount of tags danbooru has.
//The flash check is kind of picky, although it should work on "most" images..there will be either some old or extremely new ones that lack the flash tag.
'if(tag.search(/\bflash\b/)==-1){' .
'location.href=ste+document.getElementById("highres").href+"&tags="+tag+"&rating="+rtg[1]+"&source="+srx;}' .
'else{' .
'location.href=ste+document.getElementsByName("movie")[0].value+"&tags="+tag+"&rating="+rtg[1]+"&source="+srx;}' .
//The following is more or less the same as above, instead using the tags on danbooru, should load a prompt box instead.
'}else{' .
'var p=prompt("Enter Tags","");' .
'if(tag.search(/\bflash\b/)==-1){' .
'location.href=ste+document.getElementById("highres").href+"&tags="+p+"&rating="+rtg[1]+"&source="+srx;}' .
'else{' .
'location.href=ste+document.getElementsByName("movie")[0].value+"&tags="+p+"&rating="+rtg[1]+"&source="+srx;}' .
'}">' .
$title . '</a> (As above, Click on a Danbooru-run image page. (This also grabs the tags/rating/source!))' ;
2011-12-14 07:53:48 +00:00
}
2011-12-11 06:13:00 +00:00
}
2011-12-14 07:53:48 +00:00
2007-07-19 17:47:07 +00:00
$page -> set_title ( " Upload " );
$page -> set_heading ( " Upload " );
$page -> add_block ( new NavBlock ());
$page -> add_block ( new Block ( " Upload " , $html , " main " , 20 ));
}
2011-08-25 00:53:53 +00:00
/* only allows 1 file to be uploaded - for replacing another image file */
2011-08-25 03:55:44 +00:00
public function display_replace_page ( Page $page , $image_id ) {
2011-08-25 00:53:53 +00:00
global $config ;
$tl_enabled = ( $config -> get_string ( " transload_engine " , " none " ) != " none " );
$upload_list = '' ;
$upload_list .= "
2011-12-21 02:40:30 +00:00
< tr >
2011-12-24 23:28:33 +00:00
< td width = '60' >< form >< input id = 'radio_buttona' type = 'radio' name = 'method' value = 'file' checked = 'checked' onclick = 'javascript:document.getElementById("url0").style.display = "none";document.getElementById("url0").value = "";document.getElementById("data0").style.display = ""' /> File < br > " ;
2011-12-21 02:40:30 +00:00
if ( $tl_enabled ) {
$upload_list .= "
2011-12-24 23:28:33 +00:00
< input id = 'radio_buttonb' type = 'radio' name = 'method' value = 'url' onclick = 'javascript:document.getElementById("data0").style.display = "none";document.getElementById("data0").value = "";document.getElementById("url0").style.display = ""' /> URL </ br ></ td ></ form >
2011-12-21 02:40:30 +00:00
< td >< input id = 'data0' name = 'data0' class = 'wid' type = 'file' >< input id = 'url0' name = 'url0' class = 'wid' type = 'text' style = 'display:none' ></ td >
" ;
} 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
}
2009-01-04 19:54:16 +00:00
public function display_upload_status ( Page $page , $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 ());
}
}
2009-01-04 19:54:16 +00:00
public function display_upload_error ( Page $page , $title , $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 = " " ;
2007-07-16 13:15:56 +00:00
for ( $i = 0 ; $i < $config -> get_int ( 'upload_count' ); $i ++ ) {
2007-06-30 01:19:11 +00:00
if ( $i == 0 ) $style = " " ; // "style='display:visible'";
else $style = " style='display:none' " ;
2011-01-10 16:39:46 +00:00
$upload_list .= " <input size='10' " .
2009-07-07 14:40:59 +00:00
" id='data $i ' name='data $i ' $style onchange= \" $ ('#data " . ( $i + 1 ) . " ').show() \" 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 "
2011-08-13 01:40:51 +00:00
< script type = 'text/javascript' >
2009-07-07 14:40:59 +00:00
$ ( document ) . ready ( function () {
2010-04-26 05:00:41 +00:00
$ ( '#tag_input' ) . DefaultValue ( 'tagme' );
$ ( '#tag_input' ) . autocomplete ( '".make_link("api/internal/tag_list/complete")."' , {
width : 320 ,
max : 15 ,
highlight : false ,
multiple : true ,
multipleSeparator : ' ' ,
scroll : true ,
2010-04-28 10:21:02 +00:00
scrollHeight : 300 ,
selectFirst : false
2010-04-26 05:00:41 +00:00
});
2009-07-07 14:40:59 +00:00
});
</ script >
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
2009-07-07 14:40:59 +00:00
< input id = 'tag_input' name = 'tags' type = 'text' autocomplete = 'off' >
2007-06-30 01:19:11 +00:00
< input type = 'submit' value = 'Post' >
</ form >
2007-07-19 12:54:49 +00:00
< div id = 'upload_completions' style = 'clear: both;' >< small > ( Max file size is $max_kb ) </ small ></ div >
2009-10-26 12:08:54 +00:00
< noscript >< a href = '".make_link("upload")."' > Larger Form </ a ></ noscript >
2007-06-30 01:19:11 +00:00
" ;
}
}
2011-12-14 07:53:48 +00:00
?>