Skip to content

Commit

Permalink
Improved Imgur Album Support
Browse files Browse the repository at this point in the history
  • Loading branch information
GM-Script-Writer-62850 committed Jul 13, 2013
1 parent f656844 commit 1578602
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 25 deletions.
3 changes: 2 additions & 1 deletion imgur.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ function json_curl($data,$type,$anon){// type = upload/image||album ; anon = tru
array_push($Files,$file);
}
if(isset($_GET['album'])&&count($Files)>1){
$album=json_curl($_GET['album']==0?array():array('title' => $_GET['album']),'album',true); // album: https://api.imgur.com/endpoints/album#album-upload
$album=json_curl(strlen($_GET['album'])==0?array():array('title' => $_GET['album']),'album',true); // album: https://api.imgur.com/endpoints/album#album-upload
if(is_bool($album)||is_null($album))
die('{"album":false,"images":[],"success":false,"error":"Failed to connect to imgur"}');
if(!$album->{"success"})
die(json_encode(array('album' => $album, 'images' => array(), 'success' => false, "error" => false)));
if($anon&&!$album->{"data"}->{"deletehash"})
die('{"album":$album,"images":[],"success":false,"error":"Missing delete hash"}');
$album->{"data"}->{"title"}=strlen($_GET['album'])>0?$_GET['album']:'Compilation';
$destination=$anon?$album->{"data"}->{"deletehash"}:$album->{"data"}->{"id"};
}
$images=array();
Expand Down
85 changes: 70 additions & 15 deletions inc/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,23 +635,46 @@ function bulkView(link){
else
return printMsg('Error','No files selected','center',-1);
}
function storeImgurUploads(img){
if(typeof(localStorage)!="object")
return false;
var data=localStorage.getItem('imgur'),id,b,a,ele,ele2,div,f;
data=parseJSON(data==null?'{}':localStorage.getItem('imgur'));
ele=getID('imgur-uploads');
function getImgurBox(){
var ele=getID('imgur-uploads');
if(!ele){
ele=getID('imgur-box-setup');
if(ele){
ele2=document.createElement('div');
var ele2=document.createElement('div');
ele2.className='box box-full';
ele2.id='imgur-uploads';
ele2.innerHTML='<h2>Imgur Uploads<a href="#" onclick="return imgurDel(\'imgur-uploads\',false)" class="tool icon del"><span class="tip">Hide</span></a></h2>';
ele.parentNode.insertBefore(ele2,ele);
ele=ele2;
return ele2;
}
}
return ele;
}
function storeImgurAlbum(id,imgs){
if(typeof(localStorage)!="object")
return false;
var data=localStorage.getItem('imgur'),a='';
data=parseJSON(data==null?'{"albums":{}}':data);
if(!data['albums'])
data['albums']={};
data['albums'][id[0]]={"del":id[1],"title":id[2],"imgs":imgs};
for(var i in imgs)
a+='<img alt="'+imgs[i]+'" src="http://i.imgur.com/'+imgs[i]+'s.jpg"/>';
var div=document.createElement('div');
div.className="box";
div.id='imgur-'+id[0];
div.innerHTML='<h2 style="min-height:32px"><span>'+encodeHTML(id[2])+'</span><a href="#" onclick="return '+
'imgurDel(\'imgur-'+id[0]+'\',\''+id[0]+'\')" class="tool icon del"><span class="tip">Hide</span></a></h2>'+
'<span class="tool"><div class="album" onclick="imgurPopup(\''+encodeHTML(id[2])+'\',\''+id[0]+'\')">'+a+'</div><span class="tip">View Album</span></span>';
getImgurBox().appendChild(div);
localStorage.setItem('imgur',JSON.stringify(data));
}
function storeImgurUploads(img){
if(typeof(localStorage)!="object")
return false;
var data=localStorage.getItem('imgur'),id,b,a,ele,ele2,div,f;
data=parseJSON(data==null?'{}':data);
ele=getImgurBox();
for(var i in img){
if(typeof(img[i])=='boolean')
continue;
Expand Down Expand Up @@ -706,12 +729,12 @@ function bulkUpload(){
httpRequest.onreadystatechange = function(){
if(httpRequest.readyState==4){
if(httpRequest.status==200){//printMsg('Debug',encodeHTML(httpRequest.responseText),'center',0);
var json=parseJSON(httpRequest.responseText);
var json=parseJSON(httpRequest.responseText),ids=false,c=0;
if(json['success']){
printMsg('Success','All '+json['images'].length+' image(s) were uploaded to your new <a href="http://imgur.com/a/'+
json['album']['data']['id']+'" target="_blank">album</a><br/>You delete hash is <i>'+json['album']['data']['deletehash']+
'</i>. Sorry, I do not know the URL to delete albums. XP','center',0);
storeImgurUploads(json['images']);
ids=Array();
}
else{
if(json['images'].length==0){
Expand All @@ -725,10 +748,22 @@ function bulkUpload(){
json['album']['data']['id']+'" target="_blank">album</a> before a error occurred<br/>You delete hash is <i>'+
json['album']['data']['deletehash']+'</i>. Sorry, I do not know the URL to delete albums.<br/>The error message was: '+
(json['images'][json['images'].length-1]?json['images'][json['images'].length-1]["data"]["error"]:'Connection failure'),'center',0);
if(json['images'].length-1>0)
storeImgurUploads(json['images']);
delete(json['images'][json['images'].length-1]);
if(json['images'].length>0)
ids=Array();
}
}
if(ids!==false){
for(var i in json['images']){
if(c>3)
break;
ids.push(json['images'][i]["data"]["id"]);
c++;
}
storeImgurAlbum(Array(json['album']['data']['id'],json['album']['data']['deletehash'],json['album']['data']['title']),ids);
storeImgurUploads(json['images']);
imgurPopup(json['album']['data']['title'],json['album']['data']['id']);
}
var btn=getID('upload-'+now);
if(btn)
sendE(btn.nextSibling,'click');
Expand Down Expand Up @@ -819,11 +854,26 @@ function upload(file){
return false;
}
function imgurPopup(file,links){
var attrs='onclick="void(setClipboard(this)?null:this.select());" readonly="readonly" type="text"';
if(typeof(links)=='string'){
links='http://imgur.com/a/'+links;
file=encodeHTML(file);
getID("blanket").childNodes[0].innerHTML='<div style="float:left;width:270px;text-align:left;">'+
'<h2 class="center" style="font-size:12px;">'+file+'</h2><ul style="list-style:none;padding:0;margin:0;margin-top:90px">'+
'<li>View on Imgur:<ul><li><a href="'+links+'" target="_blank">'+file+'</a></li></ul></li>'+
'<li>Direct Link (email & IM)<ul><li><input '+attrs+' value="'+links+'"/></li></ul></li>'+
'<li>HTML Link (websites & blogs)<ul><li><input '+attrs+' value="&lt;a href=&quot;'+links+'&quot;&gt;'+file+'&lt;/a&gt;"/></li></ul></li>'+
'<li>BBCode Link (message boards & forums)<ul><li><input '+attrs+' value="[URL='+links+']'+file+'[/URL]"/></li></ul></li>'+
'<li>Markdown Link (reddit comment)<ul><li><input '+attrs+' value="['+file+']('+links+')"/></li></ul></li>'+
'</ul></div><iframe style="float:right;border-radius:5px;" width="400" height="400" frameborder="0" src="'+links+'/embed"></iframe>'+
'<input type="button" value="Close" style="width:100%;" onclick="toggle(\'blanket\')"/>';
popup('blanket',675);
return false;
}
if(links==null){
links=parseJSON(localStorage.getItem('imgur'));
links=links[file];
}
var attrs='onclick="void(setClipboard(this)?null:this.select());" readonly="readonly" type="text"';
getID("blanket").childNodes[0].innerHTML='<h2 style="font-size:12px;">'+file.substr(5)+' is on Imgur</h2>'+
'<div id="imgur-data"><div><img id="'+encodeHTML(file)+'" style="float:left;margin-right:5px;" src="'+links['small_square']+'" width="90" height="90"/>'+
'<ul style="list-style:none;">'+
Expand Down Expand Up @@ -901,6 +951,7 @@ function imgurPopup(file,links){
}
return false;
}

function imgurDel(id,img){
if(img===false){
if(confirm("Are you sure you want to hide ALL imgur uploads?\nThis only deletes the images from this page,\nnot imgur.")===false)
Expand All @@ -916,9 +967,13 @@ function imgurDel(id,img){
if(e==null)
return false;
e=parseJSON(e);
delete(e[img]);
if(!e[img]){
delete(e['albums'][img]);
}
else
delete(e[img]);
e=JSON.stringify(e);
if(e.length>2)
if(e.length>2&&e!='{"albums":{}}')
localStorage.setItem('imgur',e);
else{
localStorage.removeItem('imgur');
Expand Down
8 changes: 5 additions & 3 deletions inc/previewlinks.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
header("Content-Type: text/javascript");
if(!isset($_GET['page'])||!isset($_GET['file']))
die("alert('Error: One or more missing paramater(s)\\n".addslashes($_SERVER["SCRIPT_NAME"])."');");
$file=substr($_GET['file'],5);
?>
var fileJS="<?php echo str_replace("\n",'\\n',addslashes($file)); ?>";
Expand All @@ -13,10 +15,10 @@
<a href=\"index.php?page=Scans&amp;delete=Remove&amp;file="+fileURL+"\" class=\"tool icon del\" onclick=\"return confirm('Delete this scan')\"><span class=\"tip\">Delete</span></a> \
<?php
if($_GET['page']=="Edit")
echo '<span class=\\"tool icon edit-off\\"><span class=\\"tip\\">Edit (Disabled)</span></span> \\';
echo '<span class=\\"tool icon edit-off\\"><span class=\\"tip\\">Edit (Disabled)</span></span>';
else
echo '<a href=\\"index.php?page=Edit&amp;file="+file+"\\" class=\\"tool icon edit\\"><span class=\\"tip\\">Edit</span></a> \\';
?>
echo '<a href=\\"index.php?page=Edit&amp;file="+file+"\\" class=\\"tool icon edit\\"><span class=\\"tip\\">Edit</span></a>';
?> \
<a href=\"index.php?page=View&amp;file=Scan_"+fileURL+"\" class=\"tool icon view\"><span class=\"tip\">View</span></a> \
<a href=\"#\" class=\"tool icon upload\" onclick=\"return upload('Scan_"+fileJS+"')\"><span class=\"tip\">Upload to Imgur</span></a> \
<a href=\"#\" onclick=\"return emailManager('Scan_"+fileJS+"');\" class=\"tool icon email\"><span class=\"tip\">Email</span></a> \
Expand Down
27 changes: 27 additions & 0 deletions inc/style.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,33 @@
cursor: pointer;
}

#imgur-uploads .box .album{
width: 160px;
height: 160px;
margin-top: 3px;
border: 1px solid #<?php echo $BG_COLOR; ?>;
display: block;
overflow: hidden;
display: -webkit-box;
-webkit-box-pack: center;
-webkit-box-align: center;
display: -ms-flexbox;
-ms-flex-pack: center;
-ms-flex-align: center;
/*display: -moz-box; does not work in firefox as of writing this
-moz-box-pack: center;
-moz-box-align: center;*/
text-decoration: none;

}

#imgur-uploads .box .album img {
margin: 0;
border: none;
width: 80px;
height: 80px;
}

#imgur-codes,#imgur-scroller{
width: 100%;
}
Expand Down
32 changes: 26 additions & 6 deletions inc/writescripts/imgur-box.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
(function(){
if(typeof localStorage!="object")
return;
var data=localStorage.getItem("imgur"),id;
var data=localStorage.getItem("imgur"),id,album=false,ct;
if(data==null)
return;
function insert(id,t,data){
if(typeof(data)=='string'){
var a=data.length==0?'&nbsp;':data;
id=Array(id,t['del'],t['title']);
t='12345'+encodeHTML(id[2])+'.';
}
else
var a=false,id=Array(id,t);
document.write('<div class="box" id="imgur-'+id[0]+'"><h2 style="min-height:32px"><span>'+t.slice(5,t.lastIndexOf('.'))+
'</span><a href="#" onclick="return imgurDel(\'imgur-'+id[0]+'\',\''+id[0]+'\')" class="tool icon del"><span class="tip">Hide</span></a></h2><span class="tool">'+
(a?'<div class="album" onclick="imgurPopup(\''+encodeHTML(id[2])+'\',\''+id[0]+'\')">':'<img alt="'+t+'" src="'+data[t]['big_square']+'" onclick="imgurPopup(\''+t+'\',null)"/>')+
(a?a+'</div>':'')+'<span class="tip">View '+(a?'Album':'Codes')+'</span></span></div>');
}
data=parseJSON(data);
document.write('<div class="box box-full" id="imgur-uploads"><h2>Imgur Uploads'+
'<a href="#" onclick="return imgurDel(\'imgur-uploads\',false)" class="tool icon del"><span class="tip">Hide</span></a></h2>');
for(var i in data){
id=data[i]['imgur_page'].substr(data[i]['imgur_page'].lastIndexOf('/')+1);
document.write('<div class="box" id="imgur-'+id+'"><h2><span>'+i.slice(5,i.lastIndexOf('.'))+
'</span><a href="#" onclick="return imgurDel(\'imgur-'+id+'\',\''+i+'\')" class="tool icon del"><span class="tip">Hide</span></a></h2>'+
'<span class="tool"><img alt="'+i+'" src="'+data[i]['big_square']+'" onclick="imgurPopup(\''+i+'\',null)"/><span class="tip">View Codes</span></span></div>');
for(var x in data){
if(x=='albums'){
for(var y in data[x]){
album='';
for(var z in data[x][y]['imgs']){
album+='<img alt="'+data[x][y]['imgs'][z]+'" src="http://i.imgur.com/'+data[x][y]['imgs'][z]+'s.jpg"/>';
}
insert(y,data[x][y],album);
}
}
else
insert(data[x]['imgur_page'].substr(data[x]['imgur_page'].lastIndexOf('/')+1),x,data);
}
document.write('</div>');
}());

0 comments on commit 1578602

Please sign in to comment.