diff --git a/imgur.php b/imgur.php index d0f87e6..2fbfe77 100644 --- a/imgur.php +++ b/imgur.php @@ -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(); diff --git a/inc/main.js b/inc/main.js index 77e6c69..121c167 100755 --- a/inc/main.js +++ b/inc/main.js @@ -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='

Imgur UploadsHide

'; 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+=''+imgs[i]+''; + var div=document.createElement('div'); + div.className="box"; + div.id='imgur-'+id[0]; + div.innerHTML='

'+encodeHTML(id[2])+'Hide

'+ + '
'+a+'
View Album
'; + 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; @@ -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 album
You delete hash is '+json['album']['data']['deletehash']+ '. Sorry, I do not know the URL to delete albums. XP','center',0); - storeImgurUploads(json['images']); + ids=Array(); } else{ if(json['images'].length==0){ @@ -725,10 +748,22 @@ function bulkUpload(){ json['album']['data']['id']+'" target="_blank">album before a error occurred
You delete hash is '+ json['album']['data']['deletehash']+'. Sorry, I do not know the URL to delete albums.
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'); @@ -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='
'+ + '

'+file+'

'+ + ''; + 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='

'+file.substr(5)+' is on Imgur

'+ '
'+ '