diff --git a/r2/r2/lib/pages/things.py b/r2/r2/lib/pages/things.py new file mode 100644 index 000000000..38675e79e --- /dev/null +++ b/r2/r2/lib/pages/things.py @@ -0,0 +1,142 @@ +## The contents of this file are subject to the Common Public Attribution +## License Version 1.0. (the "License"); you may not use this file except in +## compliance with the License. You may obtain a copy of the License at +## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public +## License Version 1.1, but Sections 14 and 15 have been added to cover use of +## software over a computer network and provide for limited attribution for the +## Original Developer. In addition, Exhibit A has been modified to be consistent +## with Exhibit B. +## +## Software distributed under the License is distributed on an "AS IS" basis, +## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +## the specific language governing rights and limitations under the License. +## +## The Original Code is Reddit. +## +## The Original Developer is the Initial Developer. The Initial Developer of +## the Original Code is CondeNet, Inc. +## +## All portions of the code written by CondeNet are Copyright (c) 2006-2009 +## CondeNet, Inc. All Rights Reserved. +################################################################################ +from r2.lib.menus import Styled +from r2.lib.wrapped import Wrapped +from r2.models import LinkListing, make_wrapper, Link, IDBuilder, PromotedLink, Thing +from r2.lib.utils import tup +from r2.lib.strings import Score +from pylons import c + +class PrintableButtons(Styled): + def __init__(self, style, thing, show_ban = True, + show_delete = False, show_report = True, **kw): + show_report = show_report and c.user_is_loggedin + Styled.__init__(self, style = style, + fullnaem = thing._fullname, + can_ban = thing.can_ban, + show_spam = thing.show_spam, + show_reports = thing.show_reports, + show_ban = show_ban, + show_delete = show_delete, + show_report = show_report, **kw) + +class BanButtons(PrintableButtons): + def __init__(self, thing, show_ban = True, + show_delete = False, show_report = True): + PrintableButtons.__init__(self, "banbuttons", thing) + +class LinkButtons(PrintableButtons): + def __init__(self, thing, comments = True, delete = True, report = True, + ban = True): + # is the current user the author? + is_author = (c.user_is_loggedin and thing.author and + c.user.name == thing.author.name) + # do we show the report button? + show_report = not is_author and report + # do we show the delete button? + show_delete = is_author and delete and not thing._deleted + + PrintableButtons.__init__(self, 'linkbuttons', thing, + # user existence and preferences + is_loggedin = c.user_is_loggedin, + new_window = c.user.pref_newwindow, + # comment link params + comment_label = thing.comment_label, + commentcls = thing.commentcls, + permalink = thing.permalink, + # button visibility + saved = thing.saved, + editable = thing.editable, + hidden = thing.hidden, + show_delete = show_delete, + show_report = show_report, + show_ban = ban, + show_comments = comments) + +class CommentButtons(PrintableButtons): + def __init__(self, thing, delete = True, report = True): + # is the current user the author? + is_author = (c.user_is_loggedin and thing.author and + c.user.name == thing.author.name) + # do we show the report button? + show_report = not is_author and report + # do we show the delete button? + show_delete = is_author and delete and not thing._deleted + + PrintableButtons.__init__(self, "commentbuttons", thing, + is_author = is_author, + profilepage = c.profilepage, + permalink = thing.permalink, + deleted = thing.deleted, + parent_permalink = thing.parent_permalink, + can_reply = thing.can_reply, + show_report = show_report, + show_delete = show_delete, + show_ban = True) + +class MessageButtons(PrintableButtons): + def __init__(self, thing, delete = False, report = True): + was_comment = getattr(thing, 'was_comment', False) + permalink = thing.permalink if was_comment else "" + + PrintableButtons.__init__(self, "messagebuttons", thing, + profilepage = c.profilepage, + permalink = permalink, + was_comment = was_comment, + can_reply = c.user_is_loggedin, + show_report = True, + show_delete = False, + show_ban = True) + +# formerly ListingController.builder_wrapper +def default_thing_wrapper(**params): + style = params.get('style', c.render_style) + def _default_thing_wrapper(thing): + w = Wrapped(thing) + if isinstance(thing, Link): + if thing.promoted: + w.render_class = PromotedLink + w.rowstyle = 'promoted link' + elif style == 'htmllite': + w.score_fmt = Score.points + + return w + params['parent_wrapper'] = _default_thing_wrapper + return make_wrapper(**params) + +# TODO: move this into lib somewhere? +def wrap_links(links, wrapper = default_thing_wrapper(), + listing_cls = LinkListing, + num = None, show_nums = False, nextprev = False, + num_margin = None, mid_margin = None): + links = tup(links) + if not all(isinstance(x, str) for x in links): + links = [x._fullname for x in links] + b = IDBuilder(links, num = num, wrap = wrapper) + l = listing_cls(b, nextprev = nextprev, show_nums = show_nums) + if num_margin is not None: + l.num_margin = num_margin + if mid_margin is not None: + l.mid_margin = mid_margin + return l.listing() + + diff --git a/r2/r2/public/static/css/mobile.css b/r2/r2/public/static/css/mobile.css new file mode 100644 index 000000000..80cabe465 --- /dev/null +++ b/r2/r2/public/static/css/mobile.css @@ -0,0 +1,135 @@ +body { + font-family: verdana,arial,helvetica,sans-serif; + margin: 0; + padding: 0; + font-size: x-small; + color: #888; +} + +a { + text-decoration: none; + color: #369; + } + +p { + margin: 0px; + padding: 0px; + } + +ul { + margin: 0px; + padding: 0px; + list-style: none; + } + +.link { + margin-left: 2px; + } + +.title { + color: blue; + font-size: small; + margin-right: .5em; + } + +.byline { + margin: 0px 0px .5em 2px; + } + +.description { + margin-bottom: .5em; + } + +.domain { + color: #369; + } + +.buttons { + font-weight: bold; + } + +.child { + margin-left: 2em; + } + +.headerbar { + background:lightgray none repeat scroll 0%; + margin: 5px 0px 5px 2px; +} + +.headerbar span { + background-color: white; + color: gray; + font-size: x-small; + font-weight: bold; + margin-left: 15px; + padding: 0px 3px; +} + +.score { + margin: 0px .5em 0px .5em; +} + +.error { + color: red; + margin: 5px; + } + +.nextprev { + margin: 10px; + } + +.tabmenu { + list-style-type: none; +} + +.tabmenu li { + display: inline; + margin-right: .25em; + padding-left: .25em; + border-left: thin solid #000; + } + +.redditname { + font-weight: bold; + margin: 0px 3px 0px 3px; + } + +.selected { + font-weight: bold; + } + +.pagename { + font-weight: bold; + margin-right: 1ex; + color: black; + } + +.or { + border-left:thin solid #000000; + border-right:thin solid #000000; + padding: 0px .25em 0px .25em; + } + +#header { + background-color: #CEE3F8; + } + +#header .redditname a{ + color: black; + } + +#header img { + margin-right: 3px; + } + +/* markdown */ +.md { max-width: 60em; overflow: auto; } +.md p, .md h1 { margin-bottom: .5em;} +.md h1 { font-weight: normal; font-size: 100%; } +.md > * { margin-bottom: 0px } +.md strong { font-weight: bold; } +.md em { font-style: italic; } +.md img { display: none } +.md ol, .md ul { margin: 10px 2em; } +.md pre { margin: 10px; } diff --git a/r2/r2/templates/printablebuttons.html b/r2/r2/templates/printablebuttons.html new file mode 100644 index 000000000..5f381ad56 --- /dev/null +++ b/r2/r2/templates/printablebuttons.html @@ -0,0 +1,277 @@ +## The contents of this file are subject to the Common Public Attribution +## License Version 1.0. (the "License"); you may not use this file except in +## compliance with the License. You may obtain a copy of the License at +## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public +## License Version 1.1, but Sections 14 and 15 have been added to cover use of +## software over a computer network and provide for limited attribution for the +## Original Developer. In addition, Exhibit A has been modified to be consistent +## with Exhibit B. +## +## Software distributed under the License is distributed on an "AS IS" basis, +## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +## the specific language governing rights and limitations under the License. +## +## The Original Code is Reddit. +## +## The Original Developer is the Initial Developer. The Initial Developer of +## the Original Code is CondeNet, Inc. +## +## All portions of the code written by CondeNet are Copyright (c) 2006-2009 +## CondeNet, Inc. All Rights Reserved. +################################################################################ +<%namespace file="utils.html" import="plain_link" /> +<%! + from r2.lib.strings import strings + %> + +<%def name="banbuttons()"> + %if thing.show_report: +
  • + ${ynbutton(_("report"), _("reported"), "report", "hide_thing")} +
  • + %endif + %if thing.show_delete: +
  • + ${ynbutton(_("delete"), _("deleted"), "del", "hide_thing")} +
  • + %endif + %if thing.can_ban and thing.show_ban: + %if thing.show_spam: +
  • + ${self.state_button("unban", _("unban"), + "return change_state(this, 'unban');", _("unbanned"))} +
  • + %else: +
  • + ${self.state_button("ban", _("ban"), + "return change_state(this, 'ban');", _("banned"))} +
  • + %endif + %if thing.show_reports: +
  • + ${self.state_button("ignore", _("ignore"), \ + "change_state(this, 'ignore');", _("ignored"))} +
  • + %endif + %endif + + +<%def name="linkbuttons()"> + %if thing.show_comments: +
  • + ${self.comment_button("comment", thing.comment_label, thing.permalink, + a_class = thing.commentcls, + newwindow = thing.new_window)} +
  • + %endif + %if thing.editable: +
  • + ${self.simple_button(_("edit"), "edit_usertext")} +
  • + %endif +
  • + ${self.toggle_button("share-button", _("share"), _("cancel"), + "share", "cancelShare", login_required = True)} +
  • + %if thing.is_loggedin: +
  • + %if thing.saved: + ${self.state_button("unsave", _("unsave"), \ + "return change_state(this, 'unsave', unsave_thing);", _("unsaved"))} + %else: + ${self.state_button("save", _("save"), \ + "return change_state(this, 'save', save_thing);", _("saved"))} + %endif +
  • + %if thing.hidden: + ${self.state_button("unhide", _("unhide"), \ + "change_state(this, 'unhide', hide_thing);", _("unhidden"))} + %else: + ${self.state_button("hide", _("hide"), \ + "change_state(this, 'hide', hide_thing);", _("hidden"))} + %endif +
  • + %endif + ${self.banbuttons()} + + +<%def name="commentbuttons()"> +
  • + ${self.bylink_button(_("permalink"), thing.permalink)} +
  • + %if thing.deleted: + %if thing.parent_permalink and not thing.profilepage: +
  • + ${self.bylink_button(_("parent"), thing.parent_permalink)} +
  • + %endif + %else: + %if not thing.profilepage: + %if thing.parent_permalink: +
  • + ${self.bylink_button(_("parent"), thing.parent_permalink)} +
  • + %endif + %if thing.is_author: +
  • + ${self.simple_button(_("edit"), "edit_usertext")} +
  • + %endif + %endif + ${self.banbuttons()} + %if not thing.profilepage and thing.can_reply: +
  • + ${self.simple_button(_("reply"), "reply")} +
  • + %endif + %endif + + + +<%def name="messagebuttons()"> + %if thing.was_comment: +
  • + ${self.bylink_button(_("context"), thing.permalink + "?context=3")} +
  • + %endif + ${self.banbuttons()} + %if not thing.was_comment and thing.can_reply: +
  • + ${self.simple_button(_("reply {verb}"), "reply")} +
  • + %endif + + +##------------ +<%def name="state_button(name, title, onclick, executed, clicked=False, a_class = '', fmt=None, fmt_param = '', hidden_data = {})"> + + <%def name="_link()" buffered="True"> + ${title} + + <% + link = _link() + if fmt: + link = fmt % {fmt_param: link} + ## preserve spaces before and after < & > for space compression + link = link.replace(" <", " <").replace("> ", "> ") + %> + + %if clicked: + ${executed} + %else: +
    + + %for key, value in hidden_data.iteritems(): + + %endfor + + ${unsafe(link)} + +
    + %endif + + + +<%def name="ynbutton(title, executed, op, callback = 'null', + question = None, + format = '%(link)s', + format_arg = 'link', + hidden_data = {})"> + <% + if question is None: + question = _("are you sure?") + link = ('' + + title + '') + link = format % {format_arg : link} + link = unsafe(link.replace(" <", " <").replace("> ", "> ")) + %> +
    + + %for k, v in hidden_data.iteritems(): + + %endfor + + ${link} + + + ${question} + + ${_("yes")} + / + ${_("no")} + +
    + + +<%def name="simple_button(title, nameFunc)"> + ${title} + + +<%def name="toggle_button(class_name, title, alt_title, + callback, cancelback, + css_class = '', alt_css_class = '', + reverse = False, + login_required = False, + style = '', )"> +<% + if reverse: + callback, cancelback = cancelback, callback + title, alt_title = alt_title, title + css_class, alt_css_class = alt_css_class, css_class + %> + + + ${title} + + ${alt_title} + + + +### originally in commentbutton +<%def name="comment_button(name, link_text, link,\ + a_class='', title='', newwindow = False)"> + ${plain_link(link_text, link, + _class=a_class, title=title, + target='_blank' if newwindow else '_parent')} + + +<%def name="bylink_button(title, link)"> + ${plain_link(title, link, _class="bylink", rel="nofollow")} + + +<%def name="toggleable_label(class_name, + title, alt_title, + callback, cancelback, + reverse = False)"> + <% + if reverse: + callback, cancelback = cancelback, callback + title, alt_title = alt_title, title + %> + + ${title} + ${alt_title} + ( + + ${_("toggle")} + + ) + + + diff --git a/r2/r2/templates/usertext.htmllite b/r2/r2/templates/usertext.htmllite new file mode 100644 index 000000000..e69de29bb diff --git a/r2/r2/templates/usertext.xml b/r2/r2/templates/usertext.xml new file mode 100644 index 000000000..e69de29bb