0.- Registrarte en https://imgur.com/signin
1 - Conseguir un api key: https://imgur.com/signin (Sí ya lo tienes, puedes saltarte este paso)
2 - Editar: root/jscripts/sceditor/editor_themes/mybb.css
2.1 - Añadir al final de todo:
.sceditor-button-imgur div {
background-image:url(imgur.png);
}
.sceditor-button-imgur div.imgurup {
background-image:url(spinner.gif) !important;
}
2.2 - Repetir el paso 2.1 con todos los otros sceditor.
3 - Copiar imgur.png [Imagen: attachment.php?aid=31915] y spinner.gif [Imagen: attachment.php?aid=31916] en root/jscripts/sceditor/editor_themes/
4 - Editar root/jscripts/bbcodes_sceditor.js
4.1 - Buscar:
tooltip: 'Insert a video'
});
4.2 - Agregar luego:
/*********************
* Add imgur command *
*********************/
$.sceditor.command.set("imgur", {
_imgur: function () {
document.querySelector('textarea').insertAdjacentHTML( 'afterEnd', '<input class="imgur" style="visibility:hidden;position:absolute;top:0;" type="file" onchange="upload(this.files[0])" accept="image/*">' );
document.querySelector('input.imgur').click();
},
exec: function ()
{
$.sceditor.command.get('imgur')._imgur();
},
txtExec: function()
{
$.sceditor.command.get('imgur')._imgur();
},
tooltip: 'Subir a Imgur'
});
4.3 - Añadir después de todo:
/*****************************
* Add imgur upload function *
*****************************/
function upload(file) {
/* Is the file an image? */
if (!file || !file.type.match(/image.*/)) return;
/* It is! */
document.body.className = "uploading";
var d = document.querySelector(".sceditor-button-imgur div");
d.className = d.className + " imgurup";
/* 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
var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
xhr.open("POST", "https://api.imgur.com/3/image.json"); // Boooom!
xhr.onload = function() {
var code = '[img]' + JSON.parse(xhr.responseText).data.link + '[/img]';
$('#message, #signature, textarea[name*="value"]').data('sceditor').insert(code);
var d = document.querySelector(".sceditor-button-imgur div.imgurup");
d.className = d.className - " imgurup";
document.querySelector('input.imgur').remove();
}
// Ok, I don't handle the errors. An exercice for the reader.
xhr.setRequestHeader('Authorization', 'Client-ID your-key');
/* And now, we send the formdata */
xhr.send(fd);
};
4.4 - Coloca (En el paso 4.3)
your-key obtenida del paso numero 1
5 - Entrar al Admin CP - Templates (Plantillas) - Buscar Ungruped Templates (Plantillas sin grupo) - Abrir - Buscar "Codebuttons"
5.1 - Buscar:
{$basic2}image,{$email}
5.2 - Reemplazar por:
{$basic2}image,imgur,{$email}
Si usas Quick Advanced Editor (v4.0.0, +) o Quick Advanced Editor Plus (v0.6, +)
Repite el paso 5.1 y 5.2 enn Template Sets » Global Templates » codebutquick
Demostración:
Creditos: Martec (Mybb.com)
Tutorial traido a Mybb-es.com con derechos de autor.