Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 52cd906
Showing
6 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
npm-debug.log | ||
node_modules/ | ||
sftp-config.json | ||
public/css/*.css | ||
*.sublime-project | ||
*.sublime-workspace | ||
.project | ||
.idea | ||
*.swp | ||
Vagrantfile | ||
.vagrant | ||
provision.sh | ||
*.komodoproject | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# NodeBB Twitter Hashtag | ||
|
||
Converts twitter hashtags into twitter search links | ||
|
||
## Installation | ||
|
||
npm install nodebb-plugin-twitter-hashtag | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
|
||
var request = require('request'), | ||
winston = require('winston'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
|
||
db = module.parent.require('./database'), | ||
templates = module.parent.require('./../public/src/templates'), | ||
meta = module.parent.require('./meta'); | ||
|
||
(function(imgur) { | ||
"use strict"; | ||
|
||
imgur.upload = function (image, callback) { | ||
if(!image || !image.data) { | ||
return callback(new Error('invalid image')); | ||
} | ||
|
||
uploadToImgur(meta.config.imgurClientID, image.data, 'base64', function(err, data) { | ||
if(err) { | ||
return callback(err); | ||
} | ||
|
||
callback(null, { | ||
url: data.link, | ||
name: image.name | ||
}); | ||
}); | ||
} | ||
|
||
function uploadToImgur(clientID, image, type, callback) { | ||
var options = { | ||
url: 'https://api.imgur.com/3/upload.json', | ||
headers: { | ||
'Authorization': 'Client-ID ' + clientID | ||
} | ||
}; | ||
|
||
var post = request.post(options, function (err, req, body) { | ||
if(err) { | ||
return callback(err); | ||
} | ||
|
||
try { | ||
var response = JSON.parse(body); | ||
|
||
if(response.success) { | ||
callback(null, response.data); | ||
} else { | ||
callback(new Error(response.data.error.message)); | ||
} | ||
} catch(e) { | ||
winston.error('Unable to parse Imgur json response. [' + body +']'); | ||
callback(e); | ||
} | ||
}); | ||
|
||
post.form({ | ||
type: type, | ||
image: image | ||
}); | ||
}; | ||
|
||
var admin = {}; | ||
|
||
admin.menu = function(custom_header, callback) { | ||
custom_header.plugins.push({ | ||
"route": '/plugins/imgur', | ||
"icon": 'fa-picture-o', | ||
"name": 'Imgur' | ||
}); | ||
|
||
return custom_header; | ||
}; | ||
|
||
admin.route = function(custom_routes, callback) { | ||
|
||
fs.readFile(path.join(__dirname, 'public/templates/admin.tpl'), function(err, tpl) { | ||
|
||
custom_routes.routes.push({ | ||
route: '/plugins/imgur', | ||
method: 'get', | ||
options: function(req, res, callback) { | ||
|
||
db.getObjectField('nodebb-plugin-imgur', 'imgurClientID', function(err, imgurClientID) { | ||
|
||
var newTpl = templates.prepare(tpl.toString()).parse({imgurClientID: imgurClientID}); | ||
|
||
callback({ | ||
req: req, | ||
res: res, | ||
route: '/plugins/imgur', | ||
name: 'Imgur', | ||
content: newTpl | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
custom_routes.api.push({ | ||
route: '/plugins/imgur/save', | ||
method: 'post', | ||
callback: function(req, res, callback) { | ||
|
||
if(req.body.imgurClientID !== null && req.body.imgurClientID !== undefined) { | ||
db.setObjectField('nodebb-plugin-imgur', 'imgurClientID', req.body.imgurClientID); | ||
} | ||
|
||
callback({message: 'Imgur Client ID saved!'}); | ||
} | ||
}); | ||
|
||
callback(null, custom_routes); | ||
}); | ||
}; | ||
|
||
imgur.admin = admin; | ||
|
||
}(module.exports)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "nodebb-plugin-imgur", | ||
"version": "0.0.1", | ||
"description": "A Plugin that uploads images to imgur", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"nodebb", | ||
"plugin", | ||
"link" | ||
], | ||
"author": "Baris Usakli <baris@designcreateplay.com>", | ||
"license": "BSD-2-Clause", | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"id": "nodebb-plugin-imgur", | ||
"name": "Imgur Upload Plugin", | ||
"description": "A Plugin that uploads images to imgur", | ||
"url": "https://github.com/barisusakli/nodebb-plugin-imgur", | ||
"library": "./index.js", | ||
"staticDir": "./public", | ||
"hooks": [ | ||
{ "hook": "filter:post.uploadImage", "method": "upload", "callbacked": true, "priority": 6 }, | ||
{ "hook": "filter:admin.create_routes", "method": "admin.route", "callbacked": true }, | ||
{ "hook": "filter:admin.header.build", "method": "admin.menu", "callbacked": false } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<h1>Imgur</h1> | ||
|
||
|
||
<form class="form"> | ||
<div class="row"> | ||
<div class="col-sm-4 col-xs-12"> | ||
<div class="form-group"> | ||
<label>Imgur Client ID</label> | ||
<input id="imgurClientID" type="text" class="form-control" placeholder="Enter Imgur Client ID" value="{imgurClientID}"> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<button class="btn btn-lg btn-primary" id="save">Save</button> | ||
|
||
<script type="text/javascript"> | ||
$('#save').on('click', function() { | ||
$.post('/api/admin/plugins/imgur/save', {_csrf : $('#csrf_token').val(), imgurClientID : $('#imgurClientID').val()}, function(data) { | ||
app.alertSuccess(data.message); | ||
}); | ||
return false; | ||
}); | ||
</script> |