diff --git a/r2/r2/config/routing.py b/r2/r2/config/routing.py index 6330d040a..0fce3220a 100644 --- a/r2/r2/config/routing.py +++ b/r2/r2/config/routing.py @@ -64,6 +64,7 @@ def make_map(global_conf={}, app_conf={}): mc('/buttonlite', controller='buttons', action='button_lite') mc('/widget', controller='buttons', action='widget_demo_page') + mc('/socialite', controller='buttons', action='socialite_demo_page') mc('/bookmarklets', controller='buttons', action='bookmarklets') mc('/stats', controller='front', action='stats') diff --git a/r2/r2/controllers/buttons.py b/r2/r2/controllers/buttons.py index 6dcd8fb10..4de082c48 100644 --- a/r2/r2/controllers/buttons.py +++ b/r2/r2/controllers/buttons.py @@ -21,9 +21,10 @@ ################################################################################ from reddit_base import RedditController from r2.lib.pages import Button, ButtonNoBody, ButtonEmbed, ButtonLite, \ - ButtonDemoPanel, WidgetDemoPanel, Bookmarklets, BoringPage + ButtonDemoPanel, WidgetDemoPanel, Bookmarklets, BoringPage, Socialite from r2.models import * from r2.lib.strings import Score +from r2.lib.utils import tup from pylons import c, request from validator import * from pylons.i18n import _ @@ -36,29 +37,43 @@ class ButtonsController(RedditController): except ValueError: return 1 - @validate(url = nop('url'), + def get_link(self, url): + try: + sr = None if isinstance(c.site, FakeSubreddit) else c.site + links = tup(Link._by_url(url, sr)) + #find the one with the highest score + return max(links, key = lambda x: x._score) + except: + #we don't want to return 500s in other people's pages. + import traceback + g.log.debug("FULLPATH: get_link error in buttons code") + g.log.debug(traceback.format_exc()) + + def wrap_link(self, link): + if link and hasattr(link, "_fullname"): + rs = c.render_style + c.render_style = 'html' + from r2.controllers.listingcontroller import ListingController + link_builder = IDBuilder(link._fullname, wrap = ListingController.builder_wrapper) + + # link_listing will be the one-element listing at the top + link_listing = LinkListing(link_builder, nextprev=False).listing() + + # link is a wrapped Link object + c.render_style = rs + return link_listing.things[0] + + @validate(url = VSanitizedUrl('url'), title = nop('title'), css = nop('css'), vote = VBoolean('vote', default=True), newwindow = VBoolean('newwindow'), - width = VInt('width', 0, 300)) - def GET_button_content(self, url, title, css, vote, newwindow, width): - try: - links = Link._by_url(url,None) - #find the one with the highest score - l = max(links, key = lambda x: x._score) - - likes = Vote.likes(c.user, l) if c.user_is_loggedin else {} - likes = likes.get((c.user, l)) - if likes: - likes = (True if likes._name == '1' - else False if likes._name == '-1' - else None) - except: - #the only time we're gonna have an empty except. we don't - #want to return 500s in other people's pages. - l = likes = None - + width = VInt('width', 0, 800), + link = VByName('id')) + def GET_button_content(self, url, title, css, vote, newwindow, width, link): + l = self.wrap_link(link or self.get_link(url)) + if l: url = l.url + #disable css hack if (css != 'http://blog.wired.com/css/redditsocial.css' and css != 'http://www.wired.com/css/redditsocial.css'): @@ -78,57 +93,56 @@ class ButtonsController(RedditController): target = "_new" else: target = "_parent" - - c.response.content = page_handler(button=self.buttontype(), css=css, + + c.response.content = page_handler(button=bt, css=css, score_fmt = score_fmt, link = l, - likes = likes, url=url, title=title, + url=url, title=title, vote = vote, target = target, bgcolor=c.bgcolor, width=width).render() return c.response - @validate(buttontype = VInt('t', 1, 3), + @validate(buttontype = VInt('t', 1, 5), + url = VSanitizedUrl("url"), _height = VInt('height', 0, 300), _width = VInt('width', 0, 300)) - def GET_button_embed(self, buttontype, _height, _width): + def GET_button_embed(self, buttontype, _height, _width, url): c.render_style = 'js' c.response_content_type = 'text/javascript; charset=UTF-8' buttontype = buttontype or 1 - width, height = ((120, 22), (51, 69), (69, 52))[buttontype - 1] + width, height = ((120, 22), (51, 69), (69, 52), (51, 52), (600, 52))[min(buttontype - 1, 4)] if _width: width = _width if _height: height = _height bjs = ButtonEmbed(button=buttontype, width=width, height=height, + url = url, referer = request.referer).render() # we doing want the JS to be cached! c.used_cache = True return self.sendjs(bjs, callback='', escape=False) @validate(buttonimage = VInt('i', 0, 14), - url = nop('url'), + url = VSanitizedUrl('url'), + newwindow = VBoolean('newwindow', default = False), styled = VBoolean('styled', default=True)) - def GET_button_lite(self, buttonimage, url, styled): + def GET_button_lite(self, buttonimage, url, styled, newwindow): c.render_style = 'js' c.response_content_type = 'text/javascript; charset=UTF-8' if not url: url = request.referer - try: - links = Link._by_url(url,None) - #find the one with the highest score - l = max(links, key = lambda x: x._score) - except: - #we don't want to return 500s in other people's pages. - l = None - - if buttonimage == None: - image = 1 + if newwindow: + target = "_new" else: - image = buttonimage + target = "_parent" - bjs = ButtonLite(image = image, link = l, url = url, styled = styled).render() + l = self.wrap_link(self.get_link(url)) + image = 1 if buttonimage is None else buttonimage + + bjs = ButtonLite(image = image, link = l, url = l.url if l else url, + target = target, styled = styled).render() # we don't want the JS to be cached! c.used_cache = True return self.sendjs(bjs, callback='', escape=False) @@ -146,6 +160,11 @@ class ButtonsController(RedditController): show_sidebar = False, content=WidgetDemoPanel()).render() + def GET_socialite_demo_page(self): + return BoringPage(_("socialite toolbar"), + show_sidebar = False, + content=Socialite()).render() + def GET_bookmarklets(self): return BoringPage(_("bookmarklets"), diff --git a/r2/r2/controllers/error.py b/r2/r2/controllers/error.py index 340074787..7b0e262a2 100644 --- a/r2/r2/controllers/error.py +++ b/r2/r2/controllers/error.py @@ -99,13 +99,7 @@ class ErrorController(RedditController): try: return RedditController.__call__(self, environ, start_response) except: - if g.debug: - # if we're in debug mode, let this hit Pylons so we - # get a stack trace - raise - else: - c.response.content = "something really awful just happened" - return c.response + return handle_awful_failure("something really awful just happened.") def send403(self): @@ -154,5 +148,24 @@ class ErrorController(RedditController): else: return "page not found" except: - return "something really bad just happened" + return handle_awful_failure("something really bad just happened.") +def handle_awful_failure(fail_text): + """ + Makes sure that no errors generated in the error handler percolate + up to the user unless debug is enabled. + """ + if g.debug: + import sys + s = sys.exc_info() + # reraise the original error with the original stack trace + raise s[1], None, s[2] + try: + # log the traceback, and flag the "path" as the error location + import traceback + g.log.debug("FULLPATH: %s" % fail_text) + g.log.debug(traceback.format_exc()) + return redditbroke % fail_text + except: + # we are doomed. Admit defeat + return "This is an error that should never occur. You win." diff --git a/r2/r2/controllers/listingcontroller.py b/r2/r2/controllers/listingcontroller.py index 1068b1b1e..e3f274531 100644 --- a/r2/r2/controllers/listingcontroller.py +++ b/r2/r2/controllers/listingcontroller.py @@ -335,9 +335,10 @@ class ByIDController(ListingController): def query(self): return self.names - link_prefix = Link._type_prefix + str(Link._type_id) - @validate(VRegex('names', r'^('+link_prefix+'_[0-9a-z]+ ?)+$')) + @validate(names = VLinkFullnames("names")) def GET_listing(self, names, **env): + if not names: + return self.abort404() self.names = names.split(' ') return ListingController.GET_listing(self, **env) diff --git a/r2/r2/controllers/validator/validator.py b/r2/r2/controllers/validator/validator.py index 8b4341d03..ae40478e0 100644 --- a/r2/r2/controllers/validator/validator.py +++ b/r2/r2/controllers/validator/validator.py @@ -192,19 +192,19 @@ def chksrname(x): except UnicodeEncodeError: return None -class VRegex(Validator): - def __init__(self, item, rg, *a, **kw): - self.item = item - self.valid = re.compile(rg).match +class VLinkFullnames(Validator): + valid_re = re.compile(r'^(' + Link._type_prefix + str(Link._type_id) + + '_[0-9a-z]+ ?)+$') + + def __init__(self, item, *a, **kw): + self.item = item Validator.__init__(self, item, *a, **kw) def run(self, val): - if val is None or not self.valid(val): - abort('400','bad request') - else: + if val and self.valid_re.match(val): return val - + class VLength(Validator): def __init__(self, item, length = 10000, empty_error = errors.BAD_COMMENT, @@ -455,6 +455,10 @@ class VLogin(VRequired): return user +class VSanitizedUrl(Validator): + def run(self, url): + return utils.sanitize_url(url) + class VUrl(VRequired): def __init__(self, item, *a, **kw): VRequired.__init__(self, item, errors.NO_URL, *a, **kw) @@ -735,6 +739,9 @@ class VCnameDomain(Validator): except UnicodeEncodeError: c.errors.add(errors.BAD_CNAME) + + + # NOTE: make sure *never* to have res check these are present # otherwise, the response could contain reference to these errors...! class ValidIP(Validator): diff --git a/r2/r2/lib/menus.py b/r2/r2/lib/menus.py index 2234f11f8..7063e87e0 100644 --- a/r2/r2/lib/menus.py +++ b/r2/r2/lib/menus.py @@ -91,6 +91,7 @@ menu = MenuHandler(hot = _('hot'), #reddit footer strings feedback = _("feedback"), bookmarklets = _("bookmarklets"), + socialite = _("socialite"), buttons = _("buttons"), widget = _("widget"), code = _("code"), diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 2e2522fef..8a44023aa 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -192,8 +192,9 @@ class Reddit(Wrapped): """navigation buttons in the footer.""" buttons = [NamedButton("feedback", False), NamedButton("bookmarklets", False), - NamedButton("buttons", False), - NamedButton("widget", False), + NamedButton("socialite", False), + NamedButton("buttons", True), + NamedButton("widget", True), NamedButton("code", False, nocname=True), NamedButton("mobile", False, nocname=True), NamedButton("store", False, nocname=True), @@ -852,22 +853,23 @@ class UserStats(Wrapped): class ButtonEmbed(Wrapped): """Generates the JS wrapper around the buttons for embedding.""" - def __init__(self, button = None, width = 100, height=100, referer = ""): + def __init__(self, button = None, width = 100, height=100, referer = "", url = ""): Wrapped.__init__(self, button = button, width = width, height = height, - referer=referer) - + referer=referer, url = url) + class ButtonLite(Wrapped): """Generates the JS wrapper around the buttons for embedding.""" - def __init__(self, image = None, link = None, url = "", styled = True): - Wrapped.__init__(self, image = image, link = link, url = url, styled = styled) + def __init__(self, image = None, link = None, url = "", styled = True, target = '_top'): + Wrapped.__init__(self, image = image, link = link, url = url, styled = styled, target = target) class Button(Wrapped): """the voting buttons, embedded with the ButtonEmbed wrapper, shown on /buttons""" extension_handling = False - def __init__(self, link = None, likes = None, button = None, css=None, + def __init__(self, link = None, button = None, css=None, url = None, title = '', score_fmt = None, vote = True, target = "_parent", bgcolor = None, width = 100): - Wrapped.__init__(self, link = link, likes = likes, score_fmt = score_fmt, + Wrapped.__init__(self, link = link, score_fmt = score_fmt, + likes = link.likes if link else None, button = button, css = css, url = url, title = title, vote = vote, target = target, bgcolor=bgcolor, width=width) @@ -893,6 +895,10 @@ class WidgetDemoPanel(Wrapped): """Demo page for the .embed widget.""" pass +class Socialite(Wrapped): + """Demo page for the socialite Firefox extension""" + pass + class Bookmarklets(Wrapped): """The bookmarklets page.""" def __init__(self, buttons=["reddit", "like", "dislike", diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index 17f4494c3..684617528 100644 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -212,7 +212,11 @@ class Link(Thing, Printable): # htmllite depends on other get params s = ''.join(s) if c.render_style == "htmllite": - s += str(request.get.has_key('style')) + s += ''.join(map(str, [request.get.has_key('style'), + request.get.has_key('expanded'), + request.get.has_key('twocolumn'), + c.bgcolor, + c.bordercolor])) return s def make_permalink(self, sr, force_domain = False): diff --git a/r2/r2/public/static/reddit.css b/r2/r2/public/static/reddit.css index 5d6922aec..1f9478316 100644 --- a/r2/r2/public/static/reddit.css +++ b/r2/r2/public/static/reddit.css @@ -1174,6 +1174,52 @@ a.star { text-decoration: none; color: #ff8b60 } .button .blog3 .arrow { width: 100% } .button .blog3 .right { float: right; margin-top: 5px; } + +.blog5 .right { float: right; } +.blog5 .left { float: left; display:block; margin-top: 10px; } +.blog5 .clearleft { clear: left; } +.button .blog.blog5 { border: none; text-align: left; font-size: small; } +.blog5 .container { margin-left: 35px; margin-top: 2px; height: 50px;} +.blog5 ul { display: inline; } +.blog5 ul a { color: #515481; font-weight: bold; text-decoration: underline; } +.blog5 li { display: inline; padding: 1px 10px 1px 10px; } +.blog5 li.selected { + background-color: #F8F8F1; + color: #000; + border-color: #CCC; + border-style: solid solid none solid; + border-width: 1px; + +} +.blog5 .votes { + height: 25px; + background-color: #F8F8F1; + border: 1px solid #CCC; + padding-top: 5px; +} +.blog5 .arrow { + margin-right: 15px; + margin-left: 5px; + color: black; + cursor: pointer; + display: inline; + background-position: left center; + background-repeat: no-repeat; + padding-left: 20px; +} +.blog5 .votes.disabled .arrow { color: #888; } +.blog5 .arrow:hover { text-decoration: none; } +.blog5 .arrow b { font-size: larger; } +.blog5 .arrow.upmod b { color: #FF8B60; } +.blog5 .arrow.downmod b { color: #9494FF; } + +.blog5 .right { margin-right: 5px; font-size: medium; font-style: italic; } +.blog5 .controversy3 { color: #BB2222;} +.blog5 .controversy2 { color: #AB4242;} +.blog5 .controversy1 { color: #976B6B;} +.blog5 .controversy0 { color: #A8A8A8;} + + .optional {color: green} .instructions { font-size: larger; } .instructions h1, .instructions h2, .instructions h3 { margin-top: 20px; margin-bottom: 20px; } @@ -1196,13 +1242,14 @@ a.star { text-decoration: none; color: #ff8b60 } padding: 10px; max-width: 50em;} -#preview { float: right; width: 30em; margin-right: 10px; } +#preview { float: right; width: 30em; margin: 10px; } #preview span { color: lightgray; } #preview #previewbox { border-width: .2em; border-style: dashed; border-color: lightgray; padding: 1em; + font-size: larger; } /* the toolbar */ @@ -1418,3 +1465,81 @@ ul#image-preview-list .description pre { float: left; } + +/* Socialite */ +.socialite.instructions ul { + margin: 10px; + max-width: 60em; +} + +.socialite.instructions ul > li { + list-style-type: disc; + list-style-position: inside; +} + +.socialite.instructions hr { + color: #C6C6C6; + border: none; + border-top: 1px solid #C6C6C6; + margin: 20px 0px 20px 0px; + max-width: 60em; +} + +.socialite.instructions p.screenshot { + text-align: center; +} + +.socialite.instructions .logotext { + line-height: 32px; +} + +.socialite.instructions .logotext .logo { + float: left; + margin-right: 10px; +} + +.socialite.instructions .logoclear { + clear: left; +} + +.socialite.instructions .features { + padding-left: 15px; + max-width: 60em; +} + +/* From http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html */ +.socialite .buttonclear { + overflow: hidden; + float: right; + margin-right: 20px; + +} + +.socialite a.installbutton { + background: transparent url(/static/socialite/installbutton-end.png) no-repeat scroll top right; + color: #FFF; + display: block; + float: left; + font: bold 18px "Trebuchet MS",Helvetica,"Helvetica Neue",Arial,sans-serif; + height: 50px; + margin-right: 6px; + padding-right: 48px; /* sliding doors padding */ + text-decoration: none; +} + +.socialite a.installbutton span { + background: transparent url(/static/socialite/installbutton.png) no-repeat; + display: block; + line-height: 30px; + padding: 10px 0 10px 17px; +} + +.socialite a.installbutton:hover { + background-position: bottom right; +} + +.socialite a.installbutton:hover span { + background-position: bottom left; +} + + diff --git a/r2/r2/public/static/socialite/demopic.png b/r2/r2/public/static/socialite/demopic.png new file mode 100644 index 000000000..ddeccd6f6 Binary files /dev/null and b/r2/r2/public/static/socialite/demopic.png differ diff --git a/r2/r2/public/static/socialite/installbutton-end.png b/r2/r2/public/static/socialite/installbutton-end.png new file mode 100644 index 000000000..6d3c54f2f Binary files /dev/null and b/r2/r2/public/static/socialite/installbutton-end.png differ diff --git a/r2/r2/public/static/socialite/installbutton.png b/r2/r2/public/static/socialite/installbutton.png new file mode 100644 index 000000000..cb89a496b Binary files /dev/null and b/r2/r2/public/static/socialite/installbutton.png differ diff --git a/r2/r2/public/static/socialite/losbutton.png b/r2/r2/public/static/socialite/losbutton.png new file mode 100644 index 000000000..3777df641 Binary files /dev/null and b/r2/r2/public/static/socialite/losbutton.png differ diff --git a/r2/r2/public/static/socialite/sitepreferences.png b/r2/r2/public/static/socialite/sitepreferences.png new file mode 100644 index 000000000..6b6f292cb Binary files /dev/null and b/r2/r2/public/static/socialite/sitepreferences.png differ diff --git a/r2/r2/public/static/socialite/siteproperties.png b/r2/r2/public/static/socialite/siteproperties.png new file mode 100644 index 000000000..11827a506 Binary files /dev/null and b/r2/r2/public/static/socialite/siteproperties.png differ diff --git a/r2/r2/public/static/socialite/socialite.png b/r2/r2/public/static/socialite/socialite.png new file mode 100644 index 000000000..2e3b41ac4 Binary files /dev/null and b/r2/r2/public/static/socialite/socialite.png differ diff --git a/r2/r2/public/static/socialite/submitpic.png b/r2/r2/public/static/socialite/submitpic.png new file mode 100644 index 000000000..d771dadf1 Binary files /dev/null and b/r2/r2/public/static/socialite/submitpic.png differ diff --git a/r2/r2/public/static/widget_arrows.gif b/r2/r2/public/static/widget_arrows.gif index ae48b29e2..2edace845 100644 Binary files a/r2/r2/public/static/widget_arrows.gif and b/r2/r2/public/static/widget_arrows.gif differ diff --git a/r2/r2/public/static/widget_arrows_down.gif b/r2/r2/public/static/widget_arrows_down.gif index 140625c0c..a3ec39b06 100644 Binary files a/r2/r2/public/static/widget_arrows_down.gif and b/r2/r2/public/static/widget_arrows_down.gif differ diff --git a/r2/r2/public/static/widget_arrows_up.gif b/r2/r2/public/static/widget_arrows_up.gif index 18b4be05a..9ab16c7b7 100644 Binary files a/r2/r2/public/static/widget_arrows_up.gif and b/r2/r2/public/static/widget_arrows_up.gif differ diff --git a/r2/r2/templates/base.htmllite b/r2/r2/templates/base.htmllite index 99660169b..79cb22802 100644 --- a/r2/r2/templates/base.htmllite +++ b/r2/r2/templates/base.htmllite @@ -28,22 +28,29 @@ %>
+ ${optionalstyle("font-family:verdana,arial,helvetica,sans-serif;" + style_line(bgcolor="FFFFFF", bordercolor="336699"))}> -

+
+

<% style = capture(optionalstyle, "text-decoration:none;color:#336699") - link = '%s

' % (style, get_domain(), c.site.name) + name = c.site.name + if not isinstance(c.site, FakeSubreddit): + name += ".%s" % g.domain + link = '%s

' % (style, get_domain(), name) label = _("links from %(site)s").replace(" ", " "); - %> + %> ${unsafe(label % dict(site = link))} - - %if not isinstance(c.site, FakeSubreddit) or c.site != Default: -

+ %if c.cname: +

powered by @@ -54,6 +61,8 @@

%endif - - ${next.body()} +
+
+ ${next.body()} +
diff --git a/r2/r2/templates/bookmarklets.html b/r2/r2/templates/bookmarklets.html index 360a619fe..f55862251 100644 --- a/r2/r2/templates/bookmarklets.html +++ b/r2/r2/templates/bookmarklets.html @@ -32,7 +32,10 @@

${_("once added to your toolbar, these buttons will let you \"reddit this\" (submit the link, or if it's already been submitted, share it and/or comment on it), like, dislike, and save links while you surf.")}

${_("in Firefox")}

- ${_("click and drag")}  + Try out our new firefox add-on, Socialite. +

+

+ or ${_("click and drag")}  %for type in thing.buttons: ${type} diff --git a/r2/r2/templates/button.html b/r2/r2/templates/button.html index a0bdb51cc..290392087 100644 --- a/r2/r2/templates/button.html +++ b/r2/r2/templates/button.html @@ -25,7 +25,7 @@ %> <%inherit file="reddit.html"/> <%namespace module="r2.lib.template_helpers" import="generateurl"/> -<%namespace file="buttontypes.html" import="button1, button2, button3, submiturl, submitlink" /> +<%namespace file="buttontypes.html" import="*" /> @@ -41,7 +41,7 @@ <%def name="bodyHTML()"> - +

%if not c.user_is_loggedin: diff --git a/r2/r2/templates/buttondemopanel.html b/r2/r2/templates/buttondemopanel.html index b3e001fb4..b2cb882b1 100644 --- a/r2/r2/templates/buttondemopanel.html +++ b/r2/r2/templates/buttondemopanel.html @@ -50,12 +50,14 @@ %endfor

${_("customizing the look of your buttons")}

-

${_('the buttons with points have two additional options.')}

+

${_('the buttons with points have three additional options.')}

${_('Example:')}

@@ -88,6 +90,10 @@

${_("specify a title")}

${drawoption('title','[TITLE]')} +
  • +

    ${_("open links in a new window")}

    + ${drawoption('newwindow','1')} +
  • ${_("specify the color")}

    ${drawoption('bgcolor','[COLOR]')} @@ -119,7 +125,7 @@ <%def name="drawbadge(image)">
    -submit to reddit +submit to reddit @@ -137,7 +143,7 @@ onclick="window.location = 'http://${domain}/submit?url=' + encodeURIComponent(w <%def name="point_option_example()"> - + <%def name="point_button_demo(image)"> diff --git a/r2/r2/templates/buttonembed.js b/r2/r2/templates/buttonembed.js index d2d33ba93..fb7e4e1f5 100644 --- a/r2/r2/templates/buttonembed.js +++ b/r2/r2/templates/buttonembed.js @@ -28,14 +28,16 @@ arg = "cnameframe=1&" if c.cname else "" %> (function() { -var write_string='"; document.write(write_string); })() diff --git a/r2/r2/templates/buttonlite.js b/r2/r2/templates/buttonlite.js index e9e4cf66f..0aa376268 100644 --- a/r2/r2/templates/buttonlite.js +++ b/r2/r2/templates/buttonlite.js @@ -28,19 +28,17 @@ <% domain = get_domain() - if thing.link: - thing.link.score = thing.link._ups - thing.link._downs %> (function() { - var styled_submit = ''; - var unstyled_submit = ''; + var styled_submit = ''; + var unstyled_submit = ''; var write_string=''; %if thing.image > 0: - write_string += ''; + write_string += unstyled_submit + '' + ""; %endif %if thing.link: write_string += '${Score.safepoints(thing.link.score)}'; diff --git a/r2/r2/templates/buttonnobody.html b/r2/r2/templates/buttonnobody.html index 4dd9e7538..a43172986 100644 --- a/r2/r2/templates/buttonnobody.html +++ b/r2/r2/templates/buttonnobody.html @@ -28,4 +28,8 @@ ${button2(thing)} %elif thing.button == 3: ${button3(thing)} +%elif thing.button == 4: + ${button4(thing)} +%elif thing.button == 5: + ${button5(thing)} %endif diff --git a/r2/r2/templates/buttontypes.html b/r2/r2/templates/buttontypes.html index 92d4273fa..1f136c6fe 100644 --- a/r2/r2/templates/buttontypes.html +++ b/r2/r2/templates/buttontypes.html @@ -27,7 +27,7 @@ <%namespace file="printable.html" import="arrow, score" /> <%namespace file="utils.html" import="img_link" /> -<%def name="submiturl(url, title='')">${("http://%s/submit" % get_domain(True)) + query_string(dict(url=url, title=title))} +<%def name="submiturl(url, title='')">${("http://%s/submit" % get_domain(cname = c.cname)) + query_string(dict(url=url, title=title))} <%def name="submitlink(url, title='', text='submit')"> ${text} @@ -49,7 +49,6 @@ ${class_def(1, width=choose_width(thing.link, thing.width))}
  • %if thing.link: - <% thing.link.score = thing.link._ups - thing.link._downs %> %if thing.vote: ${arrow(thing.link, 1, thing.likes)} ${arrow(thing.link, 0, thing.likes == False)} @@ -67,7 +66,6 @@ ${class_def(1, width=choose_width(thing.link, thing.width))} <%def name="button2(thing)"> ${class_def(2)} %if thing.link: - <% thing.link.score = thing.link._ups - thing.link._downs %> %if thing.vote: ${arrow(thing.link, 1, thing.likes)} ${score(thing.link, thing.likes, inline=False, label = False)} @@ -96,7 +94,6 @@ ${class_def(1, width=choose_width(thing.link, thing.width))} ${class_def(3)}
    %if thing.link: - <% thing.link.score = thing.link._ups - thing.link._downs %> %if thing.vote: ${arrow(thing.link, 1, thing.likes)} ${score(thing.link, thing.likes, inline=False, label = False)} @@ -113,8 +110,139 @@ ${class_def(3)} %endif
    - ${img_link('submit', '/static/blog_snoo.gif', '/submit' + query_string(dict(url=thing.url, title=thing.title)))} + ${img_link('submit', '/static/blog_snoo.gif', capture(submiturl, thing.url, thing.title))}
    + +<%def name="button4(thing)"> + ${class_def(2)} + %if thing.link: + %if thing.vote: + ${arrow(thing.link, 1, thing.likes)} + ${score(thing.link, thing.likes, inline=False, label = False)} + ${arrow(thing.link, 0, thing.likes == False)} + %else: +  
    + ${thing.link.score} +  
    + %endif + %else: + + ${submitlink(thing.url, thing.title, 'submit to')} + %endif + + + +<%def name="button5(thing)"> + ${class_def(5, width=choose_width(thing.link, thing.width))} + ${img_link('submit', '/static/blog_snoo.gif', capture(submiturl, thing.url, thing.title), _class="left")} + <% + submitlink = capture(submiturl, thing.url, thing.title) + if thing.link: + fullname = thing.link._fullname + ups = thing.link.upvotes + downs = thing.link.downvotes + if hasattr(c.site, "domain"): + c.cname = True + link = "http://%s%s" % (get_domain(cname = True, subreddit = False), + thing.link.make_permalink_slow()) + else: + fullname = "" + ups = 0 + downs = 0 + link = submitlink + if c.user_is_loggedin: + dir = 1 if thing.likes else 0 if thing.likes is None else -1 + ups = ups - (1 if dir > 0 else 0) + downs = downs - (1 if dir < 0 else 0) + else: + dir = 0 + + other_votes = float(ups + downs) + ups = [ups, ups, ups + 1] + downs = [downs + 1, downs, downs] + votes = [other_votes + 1, other_votes, other_votes + 1] + up_pct = [int( 100 * ups[i] / votes[i]) if votes[i] else "--" for i in range(len(votes))] + down_pct = [int( 100 * downs[i] / votes[i]) if votes[i] else "--" for i in range(len(votes))] + + def controversy_text(_up_pct): + if isinstance(_up_pct, str): + return "" + p = abs(50 - _up_pct) + msg = "%s" + if p <= 5: + return msg % (3, _("quite controversial")) + elif p <= 15: + return msg % (2, _("controversial")) + elif p <= 25: + return msg % (1, _("uncontroversial")) + else: + return msg % (0, _("quite uncontroversial")) + controversy = map(controversy_text, up_pct) + %> + +
    + + +
    +
    + + diff --git a/r2/r2/templates/link.htmllite b/r2/r2/templates/link.htmllite index 500da7670..ffbf0d1cb 100644 --- a/r2/r2/templates/link.htmllite +++ b/r2/r2/templates/link.htmllite @@ -47,23 +47,63 @@ else: arrow = "http://%s/static/widget_arrows.gif" arrow = arrow % domain + expanded = request.get.get("expanded") + two_col = request.get.has_key("twocolumn") if l else False %> + %if expanded: +
    + + <% + url = "http://%s/button_content?t=4&id=%s" % (get_domain(cname = c.cname, subreddit = True), thing._fullname) + if c.bgcolor: + url += "&bgcolor=%s&bordercolor=%s" % (c.bgcolor, c.bgcolor) + else: + url += "&bgcolor=FFFFFF&bordercolor=FFFFFF" + %> + +
    + %else: - vote + vote -
    + %endif +
    + ${optionalstyle("text-decoration:none;color:#336699;font-size:small;")}> ${thing.title} -
    - + %if not expanded: +
    + %endif + + %if not expanded: ${thing.score} ${ungettext("point", "points", thing.score)} | + %endif ${com_label}
    + diff --git a/r2/r2/templates/listing.htmllite b/r2/r2/templates/listing.htmllite index f4deb9ccf..e75d886f4 100644 --- a/r2/r2/templates/listing.htmllite +++ b/r2/r2/templates/listing.htmllite @@ -36,11 +36,11 @@ %if two_col: %if i == 0:
    + ${optionalstyle("float:left;width:47%")}> %elif i - 1 < (l+1)/2 and i >= (l+1)/2:
    + ${optionalstyle("float:right; width:49%;")}> %endif %endif diff --git a/r2/r2/templates/socialite.html b/r2/r2/templates/socialite.html new file mode 100644 index 000000000..9c5d552de --- /dev/null +++ b/r2/r2/templates/socialite.html @@ -0,0 +1,84 @@ +
    + +

    install Socialite, a reddit Firefox extension

    + +

    + + Socialite integrates the features of reddit into Firefox. +

    + +

    + When you click on links on reddit, Socialite displays a toolbar above the page, allowing you to vote articles up and down, view comments, and save links to your profile. Features include: +

    + +
    +

    + + Add to Firefox + +

    + +
      +
    • simple like reddit
    • +
    • vote, save, and hide links using the toolbar
    • +
    • look up sites on reddit with a single click
    • +
    • meditate on those clever titles without leaving the page
    • +
    +
    + +

    how to use it

    + +

    + Socialite will display a toolbar automatically when you click on reddit links.

    +

    + Socialite screenshot +

    + +

    + In addition, you can open the bar manually by clicking on the reddit + icon on the right side of your location bar: +

    + +

    + lookup-or-submit button +

    + +

    + If the page is not submitted to reddit, or you click again, a submit + bar will appear: +

    + +

    + submit bar screenshot +

    + +

    + (HINT: if you want to skip straight to the submit bar, + middle-click on the reddit icon.) +

    + + +

    Configuration

    + +

    + you can configure what buttons are displayed in the toolbar in the + extensions preferences: +

    + +

    + site properties window screenshot +

    + +

    configure for other reddit sites

    +

    + Since reddit lets you + + host reddits from other domains, like + BaconBuzz, Socialite will also let you edit the list of domains that it works for. +

    +

    + preferences window screenshot +

    + +
    diff --git a/r2/r2/templates/widgetdemopanel.html b/r2/r2/templates/widgetdemopanel.html index e4673dac5..8a826d8c1 100644 --- a/r2/r2/templates/widgetdemopanel.html +++ b/r2/r2/templates/widgetdemopanel.html @@ -48,6 +48,9 @@ function update() { if (which == "all") { url = "http://${sr_domain}/" + f.what.value + "/.embed?limit=" + f.num.value + "&t=" + f.when.value; + if(f.what.value == "new") { + url += "&sort=new"; + } } else if (which == "one") { if (!f.who.value) return; url = "http://${domain}/user/"+f.who.value+"/"+ @@ -62,6 +65,9 @@ function update() { alert(which); } $("preview").style.width = ""; + if(f.expanded.checked) { + url += "&expanded=1"; + } if(f.nostyle.checked) { url += "&style=off"; hide("css-options"); @@ -76,7 +82,7 @@ function update() { } if(f.twocol.checked) { url += "&twocolumn=true"; - $("preview").style.width = "40em"; + $("preview").style.width = "550px"; } } @@ -96,7 +102,7 @@ function update() {
    preview
    - +
    @@ -196,6 +202,17 @@ function update() {

    +

    + + +