From 1578602e395217ed44ac08414ed05e49c8cef9f3 Mon Sep 17 00:00:00 2001 From: GM-Script-Writer-62850 Date: Sat, 13 Jul 2013 18:23:57 -0400 Subject: [PATCH] Improved Imgur Album Support --- imgur.php | 3 +- inc/main.js | 85 ++++++++++++++++++++++++++++------- inc/previewlinks.php | 8 ++-- inc/style.php | 27 +++++++++++ inc/writescripts/imgur-box.js | 32 ++++++++++--- 5 files changed, 130 insertions(+), 25 deletions(-) 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

'+ '
'+ '
    '+ @@ -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) @@ -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'); diff --git a/inc/previewlinks.php b/inc/previewlinks.php index 74af722..8921524 100755 --- a/inc/previewlinks.php +++ b/inc/previewlinks.php @@ -1,5 +1,7 @@ var fileJS=""; @@ -13,10 +15,10 @@ Delete \ Edit (Disabled) \\'; + echo 'Edit (Disabled)'; else - echo 'Edit \\'; - ?> + echo 'Edit'; + ?> \ View \ Upload to Imgur \ Email \ diff --git a/inc/style.php b/inc/style.php index 846bf36..1ab2dbc 100755 --- a/inc/style.php +++ b/inc/style.php @@ -666,6 +666,33 @@ cursor: pointer; } +#imgur-uploads .box .album{ + width: 160px; + height: 160px; + margin-top: 3px; + border: 1px solid #; + 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%; } diff --git a/inc/writescripts/imgur-box.js b/inc/writescripts/imgur-box.js index 31ca8c7..6e8c27f 100644 --- a/inc/writescripts/imgur-box.js +++ b/inc/writescripts/imgur-box.js @@ -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?' ':data; + id=Array(id,t['del'],t['title']); + t='12345'+encodeHTML(id[2])+'.'; + } + else + var a=false,id=Array(id,t); + document.write('

    '+t.slice(5,t.lastIndexOf('.'))+ + 'Hide

    '+ + (a?'
    ':''+t+'')+ + (a?a+'
    ':'')+'View '+(a?'Album':'Codes')+'
    '); + } data=parseJSON(data); document.write('

    Imgur Uploads'+ 'Hide

    '); - for(var i in data){ - id=data[i]['imgur_page'].substr(data[i]['imgur_page'].lastIndexOf('/')+1); - document.write('

    '+i.slice(5,i.lastIndexOf('.'))+ - 'Hide

    '+ - ''+i+'View Codes
    '); + for(var x in data){ + if(x=='albums'){ + for(var y in data[x]){ + album=''; + for(var z in data[x][y]['imgs']){ + album+=''+data[x][y]['imgs'][z]+''; + } + insert(y,data[x][y],album); + } + } + else + insert(data[x]['imgur_page'].substr(data[x]['imgur_page'].lastIndexOf('/')+1),x,data); } document.write('
    '); }());