diff --git a/r2/example.ini b/r2/example.ini index 3699a93cd..891ac7848 100644 --- a/r2/example.ini +++ b/r2/example.ini @@ -133,6 +133,7 @@ RATELIMIT = 10 num_comments = 200 max_comments = 500 num_default_reddits = 10 +num_serendipity = 100 smtp_server = localhost new_link_share_delay = 5 minutes diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 5cde45a3a..8e582b20a 100644 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -79,15 +79,19 @@ class FrontController(RedditController): sort = 'new' if rand.choice((True,False)) else 'hot' links = c.site.get_links(sort, 'all') if isinstance(links, thing.Query): - links._limit = 25 + links._limit = g.num_serendipity links = [x._fullname for x in links] else: - links = list(links)[:25] + links = list(links)[:g.num_serendipity] + + builder = IDBuilder(links, skip = True, + keep_fn = lambda x: x.fresh, + num = g.num_serendipity) + links = builder.get_items()[0] if links: - name = rand.choice(links) - link = Link._by_fullname(name, data = True) - return self.redirect(add_sr("/tb/" + link._id36)) + l = rand.choice(links) + return self.redirect(add_sr("/tb/" + l._id36)) else: return self.redirect(add_sr('/')) diff --git a/r2/r2/controllers/toolbar.py b/r2/r2/controllers/toolbar.py index a78dbd5db..33a668b0a 100644 --- a/r2/r2/controllers/toolbar.py +++ b/r2/r2/controllers/toolbar.py @@ -23,7 +23,7 @@ from reddit_base import RedditController from r2.lib.pages import * from r2.models import * from r2.lib.menus import CommentSortMenu -from r2.lib.filters import spaceCompress +from r2.lib.filters import spaceCompress, safemarkdown from r2.lib.memoize import memoize from r2.lib.template_helpers import add_sr from r2.lib import utils @@ -177,15 +177,20 @@ class ToolbarController(RedditController): title = link.title, url = link.url) - b = TopCommentBuilder(link, CommentSortMenu.operator('top'), wrap = builder_wrapper) listing = NestedListing(b, num = 10, # TODO: add config var parent_name = link._fullname) + raw_bar = strings.comments_panel_text % dict( + fd_link=link.permalink) + + md_bar = safemarkdown(raw_bar, target="_top") + res = RedditMin(content=CommentsPanel(link=link, listing=listing.listing(), - expanded = auto_expand_panel(link))) + expanded=auto_expand_panel(link), + infobar=md_bar)) return res.render() @@ -198,9 +203,13 @@ class ToolbarController(RedditController): if link: link_builder = IDBuilder((link._fullname,)) + res = FrameToolbar(link = link_builder.get_items()[0][0], title = link.title, url = link.url, + domain = None + if link.is_self + else domain(link.url), expanded = auto_expand_panel(link)) else: res = FrameToolbar(link = None, diff --git a/r2/r2/lib/app_globals.py b/r2/r2/lib/app_globals.py index 8e0eb047d..72bc8436c 100644 --- a/r2/r2/lib/app_globals.py +++ b/r2/r2/lib/app_globals.py @@ -47,6 +47,7 @@ class Globals(object): 'num_default_reddits', 'num_query_queue_workers', 'max_sr_images', + 'num_serendipity', ] bool_props = ['debug', 'translator', diff --git a/r2/r2/lib/organic.py b/r2/r2/lib/organic.py index 6908dc4ee..8ff386d85 100644 --- a/r2/r2/lib/organic.py +++ b/r2/r2/lib/organic.py @@ -38,12 +38,7 @@ organic_length = 30 promoted_every_n = 5 def keep_link(link): - return not any((link.likes != None, - link.saved, - link.clicked, - link.hidden, - link._deleted, - link._spam)) + return link.fresh def insert_promoted(link_names, sr_ids, logged_in): """ diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 70381681b..c2b4303ab 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -947,8 +947,11 @@ class FrameToolbar(Wrapped): self.com_label = _("comment {verb}") else: # generates "XX comments" as a noun - com_label = ungettext("comment", "comments", link.num_comments) - self.com_label = strings.number_label % (link.num_comments, com_label) + com_label = ungettext("comment", "comments", + link.num_comments) + self.com_label = strings.number_label % ( + link.num_comments, com_label) + # generates "XX points" as a noun self.score_label = Score.safepoints(score) diff --git a/r2/r2/lib/strings.py b/r2/r2/lib/strings.py index 1a2745d81..21eeab3a7 100644 --- a/r2/r2/lib/strings.py +++ b/r2/r2/lib/strings.py @@ -109,6 +109,10 @@ string_dict = dict( permalink_title = _("%(author)s comments on %(title)s"), link_info_title = _("%(title)s : %(site)s"), banned_subreddit = _("""**this reddit has been banned**\n\nmost likely this was done automatically by our spam filtering program. the program is still learning, and may even have some bugs, so if you feel the ban was a mistake, please send a message to [feedback](%(link)s) and be sure to include the exact name of the reddit."""), + comments_panel_text = _(""" + The following is a sample of what Reddit users had to say about this + page. The full discussion is available [here](%(fd_link)s). + """), ) class StringHandler(object): diff --git a/r2/r2/lib/template_helpers.py b/r2/r2/lib/template_helpers.py index 29bea083b..e7ebb7981 100644 --- a/r2/r2/lib/template_helpers.py +++ b/r2/r2/lib/template_helpers.py @@ -292,4 +292,4 @@ def choose_width(link, width): def panel_size(state): "the frame.cols of the reddit-toolbar's inner frame" - return '100%, 400px' if state =='expanded' else '100%x, 0px' + return '400px, 100%' if state =='expanded' else '0px, 100%x' diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index 31b4d4927..f109f0547 100644 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -340,6 +340,13 @@ class Link(Thing, Printable): elif c.user.pref_frame: item.click_url = item.tblink + item.fresh = not any((item.likes != None, + item.saved, + item.clicked, + item.hidden, + item._deleted, + item._spam)) + if c.user_is_loggedin: incr_counts(wrapped) diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index 33da6b7c0..fb6c8c5b1 100644 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -718,7 +718,7 @@ a.star { text-decoration: none; color: #ff8b60 } /* compressed links */ .linkcompressed { margin: 4px 0; overflow: hidden; margin-top: 7px; } -.linkcompressed .title {margin-bottom: 2px; font-size:medium; font-weight: normal;} +.linkcompressed .title {margin-bottom: 3px; font-size:medium; font-weight: normal;} .linkcompressed .child h3 { margin: 15px; text-transform: none; @@ -728,7 +728,7 @@ a.star { text-decoration: none; color: #ff8b60 } .linkcompressed .score.likes { color: #FF8B60; } .linkcompressed .score.dislikes { color: #9494FF; } .linkcompressed .rank { - margin-top: 7px; + margin-top: 8px; float:left; color: #c6c6c6; font-family: arial; @@ -736,7 +736,7 @@ a.star { text-decoration: none; color: #ff8b60 } text-align: right; } .linkcompressed .arrow.down, .linkcompressed .arrow.downmod { - margin-top: 2px; + margin-top: 3px; } .linkcompressed .tagline { display: inline; margin-top: 0px; margin-bottom: 1px; } @@ -747,7 +747,7 @@ a.star { text-decoration: none; color: #ff8b60 } .linkcompressed .entry .buttons li.first {padding-left: .5em;} .linkcompressed .entry .buttons li a { padding: 0 2px; - background-color: #f8f8f8; + background-color: #f9f9f9; font-weight: bold } @@ -925,20 +925,6 @@ textarea.gray { color: gray; } padding-left: 5px; } -.starkcomment + .clearleft + .starkcomment { - margin-top: 10px -} -.starkcomment .commentbox { - color: black; - background-color: #f0f0f0; - padding: 5px; - margin-left: 10px; - margin-right: 5px; -} -.starkcomment .tagline { - text-align: right; -} - .fixedwidth { float: left; width: 100px; height: 0px; } .clearleft { clear: left; height: 0px; } .clear { clear: both; } @@ -1481,12 +1467,13 @@ textarea.gray { color: gray; } height: 19px; float: left; border-right: solid #336699 1px; - background-image: url(/static/button-normal.png); + background-color: #EFF7FF; } .toolbar .middle-side { text-align: center; - background-image: url(/static/button-normal.png); + background-color: #EFF7FF; + cursor: pointer; } .toolbar .middle-side a, .toolbar .middle-side b { @@ -1501,13 +1488,20 @@ textarea.gray { color: gray; } height: 18px; border: none; border-top: solid transparent 1px; + margin-left: 2px; } .toolbar .middle-side .url { overflow: hidden; } + +.toolbar .middle-side .domain { + color: #888; + font-size: small; +} + .toolbar .right-side { float: right; - background-image: url(/static/button-normal.png); + background-color: #EFF7FF; } .toolbar a, .toolbar b { @@ -1529,7 +1523,7 @@ textarea.gray { color: gray; } } .toolbar .clickable:active, .pushed-button { - background-image: url(/static/button-pressed.png) !important; + background-color: #cee3f8 !important; color: orangered !important; } @@ -1549,13 +1543,14 @@ textarea.gray { color: gray; } vertical-align: top; } .toolbar .title { - padding-left: 20px; + padding-left: 1em; + padding-right: 1em; color: black; - font-style: italic; - cursor: pointer; + display: block; + overflow: hidden; } -.toolbar .title:hover { - text-decoration: underline; +.toolbar .title:active { + color: orangered; } .toolbar .controls { float: right; @@ -1595,17 +1590,19 @@ textarea.gray { color: gray; } padding-right: 3px; } .tb-comments-panel-toggle { - display: block; - font-size: larger; - margin: 15px 13px; } +.comments-panel .infobar { + padding: 3px 10px 7px; + margin: 5px 10px 10px 3px; +} + .min-body { height: 100%; } .min-body .content { margin-top: 0px; - border-left: solid #369 1px; + border-right: solid #369 1px; min-height: 100%; max-width: 60em; overflow: auto; @@ -1620,6 +1617,20 @@ textarea.gray { color: gray; } margin: 0 0 0 13px; } +.starkcomment + .clearleft + .starkcomment { + margin-top: 10px +} +.starkcomment .commentbox { + color: black; + background-color: #f0f0f0; + padding: 5px; + margin-left: 0px; + margin-right: 10px; +} +.starkcomment .tagline { + text-align: right; +} + /* default form styles */ .pretty-form { font-size: larger; diff --git a/r2/r2/public/static/js/reddit.js b/r2/r2/public/static/js/reddit.js index 0bc1964fb..b6fd47177 100644 --- a/r2/r2/public/static/js/reddit.js +++ b/r2/r2/public/static/js/reddit.js @@ -147,6 +147,14 @@ function hide_thing(elem) { thing.addClass("hidden"); }; +function toggle_label (elem, callback, cancelback) { + $(elem).parent().find(".option").toggle(); + $(elem).onclick = function() { + return(toggle_label(elem, cancelback, callback)); + } + if (callback) callback(elem); +} + function toggle(elem, callback, cancelback) { var self = $(elem).parent().andSelf().filter(".option"); var sibling = self.removeClass("active") @@ -659,11 +667,12 @@ var toolbar_p = function(expanded_size, collapsed_size) { /* namespace for functions related to the reddit toolbar frame */ this.toggle_linktitle = function(s) { - $('.title, .submit, .url').toggle(); + $('.title, .submit, .url, .linkicon').toggle(); if($(s).is('.pushed-button')) { $(s).parents('.middle-side').removeClass('clickable'); } else { $(s).parents('.middle-side').addClass('clickable'); + $('.url').children('form').children('input').focus().select(); } return this.toggle_pushed(s); }; diff --git a/r2/r2/public/static/link-active.png b/r2/r2/public/static/link-active.png new file mode 100644 index 000000000..974ebe781 Binary files /dev/null and b/r2/r2/public/static/link-active.png differ diff --git a/r2/r2/templates/commentspanel.html b/r2/r2/templates/commentspanel.html index 15b2151f6..ea967216b 100644 --- a/r2/r2/templates/commentspanel.html +++ b/r2/r2/templates/commentspanel.html @@ -20,27 +20,28 @@ ## CondeNet, Inc. All Rights Reserved. ################################################################################ -<%namespace file="printable.html" import="toggle_button"/> +<%namespace file="printable.html" import="toggleable_label"/> + +
- ${_('top comments')} -
-- - ${_("full discussion")} - -
+<% from r2.lib.strings import strings %> + +