mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Adding share api calls to bookmarklet.
This commit is contained in:
parent
189fbe0b2f
commit
c2c983ee81
8 changed files with 180 additions and 55 deletions
|
@ -7,4 +7,6 @@ urlpatterns = patterns('',
|
|||
url(r'^signup', views.signup, name='api-signup'),
|
||||
url(r'^add_site_load_script/(?P<token>\w+)', views.add_site_load_script, name='api-add-site-load-script'),
|
||||
url(r'^add_site/(?P<token>\w+)', views.add_site, name='api-add-site'),
|
||||
url(r'^check_share_on_site/(?P<token>\w+)', views.check_share_on_site, name='api-check-share-on-site'),
|
||||
url(r'^share_story/(?P<token>\w+)', views.share_story, name='api-share-story'),
|
||||
)
|
||||
|
|
|
@ -135,4 +135,51 @@ def add_site(request, token):
|
|||
'code': code,
|
||||
'message': message,
|
||||
'usersub': us and us.feed_id,
|
||||
}) + ')', mimetype='text/plain')
|
||||
|
||||
def check_share_on_site(request, token):
|
||||
code = 0
|
||||
story_url = request.GET['story_url']
|
||||
rss_url = request.GET['rss_url']
|
||||
callback = request.GET['callback']
|
||||
message = None
|
||||
|
||||
|
||||
if not story_url:
|
||||
code = -1
|
||||
else:
|
||||
try:
|
||||
profile = Profile.objects.get(secret_token=token)
|
||||
except Profile.DoesNotExist:
|
||||
code = -1
|
||||
|
||||
logging.user(profile.user, "~BY~FRChecking share from site: ~SB%s" % (story_url))
|
||||
|
||||
return HttpResponse(callback + '(' + json.encode({
|
||||
'code': code,
|
||||
'message': message,
|
||||
'feed': None,
|
||||
}) + ')', mimetype='text/plain')
|
||||
|
||||
def share_story(request, token):
|
||||
code = 0
|
||||
story_url = request.GET['story_url']
|
||||
comments = request.GET['comments']
|
||||
callback = request.GET['callback']
|
||||
message = None
|
||||
|
||||
if not story_url:
|
||||
code = -1
|
||||
else:
|
||||
try:
|
||||
profile = Profile.objects.get(secret_token=token)
|
||||
except Profile.DoesNotExist:
|
||||
code = -1
|
||||
|
||||
logging.user(profile.user, "~BY~FRSharing story from site: ~SB%s: %s" % (story_url, comments))
|
||||
|
||||
return HttpResponse(callback + '(' + json.encode({
|
||||
'code': code,
|
||||
'message': message,
|
||||
'story': None,
|
||||
}) + ')', mimetype='text/plain')
|
|
@ -262,6 +262,7 @@ class MSocialProfile(mongo.Document):
|
|||
}
|
||||
if not compact:
|
||||
params.update({
|
||||
'large_photo_url': self.large_photo_url,
|
||||
'bio': self.bio,
|
||||
'website': self.website,
|
||||
'shared_stories_count': self.shared_stories_count,
|
||||
|
|
|
@ -90,6 +90,7 @@ javascripts:
|
|||
- media/js/vendor/jquery.tinysort.js
|
||||
- media/js/vendor/jquery.simplemodal-1.3.js
|
||||
- media/js/vendor/jquery.corners.js
|
||||
- media/js/vendor/jquery.hotkeys.js
|
||||
- media/js/vendor/readability-*.js
|
||||
blurblog:
|
||||
- media/js/vendor/jquery-*.js
|
||||
|
|
12
fabfile.py
vendored
12
fabfile.py
vendored
|
@ -689,12 +689,12 @@ def copy_task_settings():
|
|||
# = Tasks - DB =
|
||||
# ==============
|
||||
|
||||
def restore_postgres():
|
||||
backup_date = '2012-07-21-08-00'
|
||||
run('PYTHONPATH=/home/sclay/newsblur python s3.py get backup_postgresql_%s.sql.gz' % backup_date)
|
||||
sudo('su postgres -c "createuser -U newsblur"')
|
||||
sudo('su postgres -c "createdb newsblur -O newsblur"')
|
||||
sudo('su postgres -c "pg_restore --role=newsblur --dbname=newsblur backup_postgresql_%s.sql.gz"' % backup_date)
|
||||
def restore_postgres(port=5432):
|
||||
backup_date = '2012-08-17-08-00'
|
||||
# run('PYTHONPATH=%s python utils/backups/s3.py get backup_postgresql_%s.sql.gz' % (env.NEWSBLUR_PATH, backup_date))
|
||||
# sudo('su postgres -c "createuser -p %s -U newsblur"' % (port,))
|
||||
sudo('su postgres -c "createdb newsblur -p %s -O newsblur"' % (port,))
|
||||
sudo('su postgres -c "pg_restore -p %s --role=newsblur --dbname=newsblur backup_postgresql_%s.sql.gz"' % (port, backup_date))
|
||||
|
||||
def restore_mongo():
|
||||
backup_date = '2012-07-24-09-00'
|
||||
|
|
|
@ -90,14 +90,14 @@
|
|||
overflow: hidden;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-main {
|
||||
width: 60%;
|
||||
width: 70%;
|
||||
overflow: hidden;
|
||||
float: right;
|
||||
border-left: 6px solid #74B3B7;
|
||||
margin: 24px 0 0;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-side {
|
||||
width: 36%;
|
||||
width: 26%;
|
||||
float: left;
|
||||
height: 100%;
|
||||
padding: 12px;
|
||||
|
@ -224,6 +224,7 @@
|
|||
/* border-top: 1px solid #F0F0F0;*/
|
||||
padding: 12px 0 0 88px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-comment-photo {
|
||||
position: absolute;
|
||||
|
@ -235,8 +236,12 @@
|
|||
width: 48px;
|
||||
height: 48px;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-comment-input {
|
||||
float: left;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-comment-input textarea {
|
||||
width: 364px;
|
||||
width: 316px;
|
||||
float: left;
|
||||
border: 1px solid #E0E0E0;
|
||||
padding: 6px;
|
||||
margin: 0;
|
||||
|
@ -245,4 +250,14 @@
|
|||
font-size: 13px;
|
||||
height: 34px;
|
||||
background-color: white;
|
||||
display: block;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-comment-submit {
|
||||
float: left;
|
||||
clear: none;
|
||||
width: 100px;
|
||||
margin: 0 0 4px 12px;
|
||||
padding: 8px 0;
|
||||
line-height: 16px;
|
||||
font-weight: bold;
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
/*global window: false, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */
|
||||
|
||||
var dbg = (typeof console !== 'undefined') ? function(s) {
|
||||
console.log("Readability: " + s);
|
||||
// console.log("Readability: " + s);
|
||||
} : function() {};
|
||||
|
||||
/*
|
||||
|
@ -87,7 +87,7 @@ window.readability = {
|
|||
readability.parsedPages[window.location.href.replace(/\/$/, '')] = true;
|
||||
|
||||
/* Pull out any possible next page link first */
|
||||
var nextPageLink = readability.findNextPageLink(document.body);
|
||||
var nextPageLink = null; // readability.findNextPageLink(document.body);
|
||||
|
||||
// readability.prepDocument();
|
||||
|
||||
|
|
|
@ -28,6 +28,11 @@
|
|||
|
||||
NEWSBLUR.Bookmarklet.prototype = {
|
||||
|
||||
|
||||
// ==================
|
||||
// = Initialization =
|
||||
// ==================
|
||||
|
||||
fix_title: function() {
|
||||
var d = document;
|
||||
d.title = d.title.replace(/\(Sharing\.\.\.\)\s?/g, '');
|
||||
|
@ -52,44 +57,20 @@
|
|||
this.make_modal();
|
||||
this.open_modal();
|
||||
this.get_page_content();
|
||||
this.pre_share_check_story();
|
||||
|
||||
this.$modal.bind('click', $.rescope(this.handle_clicks, this));
|
||||
|
||||
var $comment = $('textarea[name=newsblur_comment]', this.$modal);
|
||||
$comment.bind('keydown', $.rescope(this.update_share_button_title, this));
|
||||
$comment.bind('keyup', $.rescope(this.update_share_button_title, this));
|
||||
$comment.bind('keydown', 'ctrl+return', $.rescope(this.share_story, this));
|
||||
$comment.bind('keydown', 'meta+return', $.rescope(this.share_story, this));
|
||||
},
|
||||
|
||||
show_error: function() {
|
||||
$('.NB-bookmarklet-folder-container', this.$modal).hide();
|
||||
$('.NB-modal-submit', this.$modal).html($.make('div', { className: 'NB-error-invalid' }, [
|
||||
'This bookmarklet no longer matches an account. Re-create it in ',
|
||||
$.make('a', { href: 'http://www.newsblur.com/?next=goodies' }, 'Goodies on NewsBlur'),
|
||||
'.'
|
||||
]));
|
||||
},
|
||||
|
||||
attach_css: function() {
|
||||
var css = "{% include_bookmarklet_css %}";
|
||||
var style = '<style id="newsblur_bookmarklet_css">' + css + '</style>';
|
||||
if ($('#newsblur_bookmarklet_css').length) {
|
||||
$('#newsblur_bookmarklet_css').replaceWith(style);
|
||||
} else if ($('head').length) {
|
||||
$('head').append(style);
|
||||
} else {
|
||||
$('body').append(style);
|
||||
}
|
||||
},
|
||||
|
||||
alert: function(message) {
|
||||
alert(message);
|
||||
},
|
||||
|
||||
check_if_on_newsblur: function() {
|
||||
if (window.location.href.indexOf(this.domain) != -1) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
make_modal: function() {
|
||||
var self = this;
|
||||
|
||||
|
||||
this.$modal = $.make('div', { className: 'NB-bookmarklet NB-modal' }, [
|
||||
$.make('div', { className: 'NB-modal-information' }, [
|
||||
'Signed in as ',
|
||||
|
@ -106,7 +87,8 @@
|
|||
]),
|
||||
$.make('div', { className: 'NB-bookmarklet-comment-input' }, [
|
||||
$.make('textarea', { name: 'newsblur_comment', placeholder: "Comments..." })
|
||||
])
|
||||
]),
|
||||
$.make('div', { className: 'NB-bookmarklet-comment-submit NB-modal-submit-button NB-modal-submit-green' }, 'Share this story')
|
||||
])
|
||||
])
|
||||
]),
|
||||
|
@ -126,16 +108,6 @@
|
|||
]);
|
||||
},
|
||||
|
||||
get_page_title: function() {
|
||||
var title = document.title;
|
||||
|
||||
if (title.length > 40) {
|
||||
title = title.substr(0, 40) + '...';
|
||||
}
|
||||
|
||||
return title;
|
||||
},
|
||||
|
||||
make_folders: function() {
|
||||
var folders = this.folders;
|
||||
var $options = $.make('select', { className: 'NB-folders'});
|
||||
|
@ -204,6 +176,19 @@
|
|||
$('body').css('overflow', 'hidden');
|
||||
},
|
||||
|
||||
// ============
|
||||
// = Add site =
|
||||
// ============
|
||||
|
||||
show_error: function() {
|
||||
$('.NB-bookmarklet-folder-container', this.$modal).hide();
|
||||
$('.NB-modal-submit', this.$modal).html($.make('div', { className: 'NB-error-invalid' }, [
|
||||
'This bookmarklet no longer matches an account. Re-create it in ',
|
||||
$.make('a', { href: 'http://www.newsblur.com/?next=goodies' }, 'Goodies on NewsBlur'),
|
||||
'.'
|
||||
]));
|
||||
},
|
||||
|
||||
save: function() {
|
||||
var self = this;
|
||||
var $submit = $('.NB-modal-submit-button');
|
||||
|
@ -252,6 +237,37 @@
|
|||
}
|
||||
},
|
||||
|
||||
// =============
|
||||
// = Pre-share =
|
||||
// =============
|
||||
|
||||
pre_share_check_story: function() {
|
||||
var check_story_url = "http://"+this.domain+"{% url api-check-share-on-site token %}?callback=?";
|
||||
var data = {
|
||||
story_url: window.location.href,
|
||||
rss_url: $('link[type="application/rss+xml"]').attr('href')
|
||||
};
|
||||
|
||||
$.getJSON(check_story_url, data, function(resp) {
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
// ===============
|
||||
// = Share story =
|
||||
// ===============
|
||||
|
||||
share_story: function() {
|
||||
$.ajax({
|
||||
url: 'http://'+this.domain+"{% url api-share-story token %}?callback=?",
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
post_share_story: function(data) {
|
||||
|
||||
},
|
||||
|
||||
open_add_folder: function() {
|
||||
var $new_folder = $('.NB-bookmarklet-new-folder-container', this.$modal);
|
||||
$new_folder.slideDown(500);
|
||||
|
@ -307,6 +323,38 @@
|
|||
return html;
|
||||
},
|
||||
|
||||
attach_css: function() {
|
||||
var css = "{% include_bookmarklet_css %}";
|
||||
var style = '<style id="newsblur_bookmarklet_css">' + css + '</style>';
|
||||
if ($('#newsblur_bookmarklet_css').length) {
|
||||
$('#newsblur_bookmarklet_css').replaceWith(style);
|
||||
} else if ($('head').length) {
|
||||
$('head').append(style);
|
||||
} else {
|
||||
$('body').append(style);
|
||||
}
|
||||
},
|
||||
|
||||
alert: function(message) {
|
||||
alert(message);
|
||||
},
|
||||
|
||||
check_if_on_newsblur: function() {
|
||||
if (window.location.href.indexOf(this.domain) != -1) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
|
||||
get_page_title: function() {
|
||||
var title = document.title;
|
||||
|
||||
if (title.length > 40) {
|
||||
title = title.substr(0, 40) + '...';
|
||||
}
|
||||
|
||||
return title;
|
||||
},
|
||||
|
||||
// ===========
|
||||
// = Actions =
|
||||
// ===========
|
||||
|
@ -338,6 +386,17 @@
|
|||
|
||||
$.modal.close();
|
||||
});
|
||||
},
|
||||
|
||||
update_share_button_title: function() {
|
||||
var $comment = $('textarea[name=newsblur_comment]', this.$modal);
|
||||
var $submit = $('.NB-bookmarklet-comment-submit', this.$modal);
|
||||
|
||||
if ($comment.val().length) {
|
||||
$submit.text('Share with comments');
|
||||
} else {
|
||||
$submit.text('Share this story');
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue