Quantcast
Channel: MyBB Community Forums - Tutorials
Viewing all articles
Browse latest Browse all 690

Imgur Upload

$
0
0
1 - Get imgur api key: https://imgur.com/register/api_anon

2 - Create imgur.php in root

PHP Code:
<html>
<
head>
<
title>Upload to Imgur</title>
</
head>
</
html>
<
div><img src="images/imgur.png" border="0" /></div>
<
br /><br />
<
button onclick="document.querySelector('input').click()">Select file...</button>
<
input style="visibility: collapse; width: 0px;" type="file" onchange="upload(this.files[0])">

<
script>
    
window.ondragover = function(e) {e.preventDefault()}
    
window.ondrop = function(e) {e.preventDefault(); upload(e.dataTransfer.files[0]); }
    function 
upload(file) {

        
/* Is the file an image? */
        
if (!file || !file.type.match(/image.*/)) return;

        
/* It is! */
        
document.body.className "uploading";

        
/* Lets build a FormData object*/
        
var fd = new FormData(); // I wrote about it: https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
        
fd.append("image"file); // Append the file
        
fd.append("key""your key"); // Get your own key http://api.imgur.com/
        
var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
        
xhr.open("POST""http://api.imgur.com/2/upload.json"); // Boooom!
        
xhr.onload = function() {
            var 
code '[img]' JSON.parse(xhr.responseText).upload.links.original '[/img]';
            var 
editor = eval('opener.' 'clickableEditor');
            
editor.performInsert(code);
            
javascript:window.close()
        }
        
// Ok, I don't handle the errors. An exercice for the reader.

        /* And now, we send the formdata */
        
xhr.send(fd);
    }
</script>

<!-- Bla bla bla stuff ... -->

<style>
    body {text-align: center; background-color: #181817; overflow-x:hidden; overflow-y:auto;}
    div { background-color: rgb(43, 43, 43); border-bottom: 4px solid rgb(68, 68, 66); margin: -8px;}
    p {display: none}
    .uploading p {display: inline}
</style>
<br /><br />
<p><img src="images/loader.gif" border="0" /></p> 

2.1 - Change your key in imgur.php with key obtained in 1

3 - Copy loader.gif and imgur.png in images folder of your mybb installation.

4 - Copy imgurbut.png in jscripts/editor_themes/default/images/ and jscripts/editor_themes/office2007/images/

5 - Open jscripts/editor.js

5.1 - Find

Code:
{type: 'button', name: 'img', sprite: 'image', insert: 'image', extra: 1, title: this.options.lang.title_image},

5.2 - Add after

Code:
{type: 'button', name: 'imgur', insert: 'imgur', image: 'imgurbut.png', title: 'Upload to Imgur'},

5.3 - Find

Code:
insertIMG: function()
    {
        image = prompt(this.options.lang.enter_image, "http://");

        if(image)
        {
            this.performInsert("[img]"+image+"[/img]", "", true);
        }
    },

5.4 - Add after

Code:
insertImgur: function()
    {
        MyBB.popupWindow('imgur.php', 'imgur', 240, 200);
    },

5.5 - Find

Code:
case "image":
                this.insertIMG();
                break;

5.6 - Add after

Code:
case "imgur":
                this.insertImgur();
                break;

Credit: https://hacks.mozilla.org/category/drag-.../complete/

.gif  loader.gif (Size: 6.22 KB / Downloads: 279)

.png  imgur.png (Size: 2.26 KB / Downloads: 280)

.png  imgurbut.png (Size: 1.13 KB / Downloads: 278)

Viewing all articles
Browse latest Browse all 690

Trending Articles