diff --git a/client/css/screen.css b/client/css/screen.css index 56e44e7d0..3ff788720 100644 --- a/client/css/screen.css +++ b/client/css/screen.css @@ -1420,13 +1420,13 @@ form .control-group, .accounts-dialog .control-group { margin-left: 150px; position: relative; } /* line 19, ../sass/modules/_forms.scss */ - form .control-group .controls .get-title-link, .accounts-dialog .control-group .controls .get-title-link { + form .control-group .controls .inline-link, .accounts-dialog .control-group .controls .inline-link { position: absolute; display: block; top: 2px; right: 8px; } /* line 24, ../sass/modules/_forms.scss */ - form .control-group .controls .get-title-link.loading, .accounts-dialog .control-group .controls .get-title-link.loading { + form .control-group .controls .inline-link.loading, .accounts-dialog .control-group .controls .inline-link.loading { background: url(/img/loading.gif) center center no-repeat; height: 22px; width: 18px; diff --git a/client/models/setting.js b/client/models/setting.js index 1ba1a435d..dfc41ce80 100644 --- a/client/models/setting.js +++ b/client/models/setting.js @@ -25,6 +25,7 @@ Setting = FormModel.extend({ clickyId:'', goSquaredId: '', embedlyId: '', + bitlyToken: '', footerCode: '', extraCode: '', notes: '' @@ -40,6 +41,7 @@ Setting = FormModel.extend({ this.overwriteTitle('mixpanelId', 'Mixpanel ID'); this.overwriteTitle('clickyId', 'Clicky ID'); this.overwriteTitle('goSquaredId', 'GoSquared ID'); + this.overwriteTitle('bitlyToken', 'Bitly Token'); this.overwriteTitle('logoUrl', 'Logo URL'); this.overwriteType('footerCode', 'textarea'); this.overwriteType('extraCode', 'textarea'); diff --git a/client/sass/modules/_forms.scss b/client/sass/modules/_forms.scss index 698d515d1..a7e51c88d 100644 --- a/client/sass/modules/_forms.scss +++ b/client/sass/modules/_forms.scss @@ -16,7 +16,7 @@ form, .accounts-dialog{ .controls{ margin-left:150px; position:relative; - .get-title-link{ + .inline-link{ position:absolute; display:block; top:2px; diff --git a/client/views/posts/post_edit.html b/client/views/posts/post_edit.html index c2ce18acc..526f244c5 100644 --- a/client/views/posts/post_edit.html +++ b/client/views/posts/post_edit.html @@ -14,6 +14,12 @@
+ {{#if shorten}} +
+ +
+
+ {{/if}}
diff --git a/client/views/posts/post_edit.js b/client/views/posts/post_edit.js index cf8997b39..dd7869066 100644 --- a/client/views/posts/post_edit.js +++ b/client/views/posts/post_edit.js @@ -51,7 +51,10 @@ Template.post_edit.helpers({ }, hasStatusRejected: function(){ return this.status == STATUS_REJECTED ? 'checked' : ''; - }, + }, + shorten: function(){ + return !!getSetting('bitlyToken'); + } }); Template.post_edit.rendered = function(){ @@ -78,6 +81,7 @@ Template.post_edit.events = { var post = Posts.findOne(selectedPostId); var categories = []; var url = $('#url').val(); + var shortUrl = $('#short-url').val(); var status = parseInt($('input[name=status]:checked').val()); $('input[name=category]:checked').each(function() { @@ -88,6 +92,7 @@ Template.post_edit.events = { var properties = { headline: $('#title').val(), + shortUrl: shortUrl, body: instance.editor.exportFile(), categories: categories, }; diff --git a/client/views/posts/post_submit.html b/client/views/posts/post_submit.html index 728991b6b..f1f16891e 100644 --- a/client/views/posts/post_submit.html +++ b/client/views/posts/post_submit.html @@ -8,7 +8,7 @@
-
Suggest title
+
Suggest title
diff --git a/client/views/posts/post_submit.js b/client/views/posts/post_submit.js index ecf27cd6a..46bb85ab3 100644 --- a/client/views/posts/post_submit.js +++ b/client/views/posts/post_submit.js @@ -36,6 +36,7 @@ Template.post_submit.events = { var title= $('#title').val(); var url = $('#url').val(); + var shortUrl = $('#short-url').val(); var body = instance.editor.exportFile(); var categories=[]; var sticky=!!$('#sticky').attr('checked'); @@ -50,6 +51,7 @@ Template.post_submit.events = { var properties = { headline: title , body: body + , shortUrl: shortUrl , categories: categories , sticky: sticky , submitted: submitted @@ -95,4 +97,5 @@ Template.post_submit.events = { $(".get-title-link").removeClass("loading"); } } + }; diff --git a/client/views/posts/posts_list.js b/client/views/posts/posts_list.js index 2b2bb163f..1e5727bc9 100644 --- a/client/views/posts/posts_list.js +++ b/client/views/posts/posts_list.js @@ -16,7 +16,6 @@ Template.posts_list.helpers({ return this.fetch(); }, postsReady: function() { - console.log('checking postsReady', this.ready(), this); return this.ready(); }, allPostsLoaded: function(){ diff --git a/collections/posts.js b/collections/posts.js index 35983df62..8c8e84bf3 100644 --- a/collections/posts.js +++ b/collections/posts.js @@ -44,6 +44,23 @@ Meteor.methods({ throw new Meteor.Error(605, 'Sorry, you cannot submit more than '+maxPostsPer24Hours+' posts per day'); } + // shorten URL + if(!this.isSimulation && (token=getSetting('bitlyToken'))){ + var shortenResponse = Meteor.http.get( + "https://api-ssl.bitly.com/v3/shorten?", + { + timeout: 5000, + params:{ + "format": "json", + "access_token": token, + "longUrl": post.url + } + } + ); + if(shortenResponse.statusCode == 200) + post.shortUrl = shortenResponse.data.data.url + } + post = _.extend(post, { headline: headline, body: body, diff --git a/lib/helpers.js b/lib/helpers.js index 58f3ccd62..abc02adc2 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -78,6 +78,20 @@ slugify = function(text) { text = text.toLowerCase(); return text; } +getShortUrl = function(url, func){ + $.getJSON( + "https://api-ssl.bitly.com/v3/shorten?callback=?", + { + "format": "json", + "access_token": getSetting('bitlyToken'), + "longUrl": url + }, + function(response){ + func(response.data.url); + } + ); +} + // ---------------------------------- String Helper Functions ----------------------------------- // cleanUp = function(s){ return stripHTML(s);