## 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 reddit Inc. ## ## All portions of the code written by reddit are Copyright (c) 2006-2012 ## reddit Inc. All Rights Reserved. ############################################################################### <%! import json from r2.models import FakeSubreddit from r2.lib.filters import spaceCompress, unsafe, safemarkdown from r2.lib.template_helpers import add_sr, js_config, static from r2.lib.utils import cols, long_datetime, timesince from r2.lib.tracking import UserInfo from datetime import datetime %> <%def name="tags(**kw)"> %for k, v in kw.iteritems(): %if v: ${k.strip('_')}="${v}" \ %endif %endfor ## override the link _class so that we can globally update ## the way links are handled (if need be) <%def name="_a(**kw)"> ${caller.body()} <%def name="_a_buffered(body, **kw)" buffered="True"> ${body} ## thing should be global <%def name="_id(arg)"> id="${arg}_${thing and thing._fullname or ''}" <%def name="css_class(thing)"> ${' '+thing.css_class if hasattr(thing, 'css_class') and thing.css_class else ''} <%def name="submit_form(onsubmit='', action='', _class='', method='post', _id='', **params)">
%if c.user_is_loggedin: %endif %for key, value in params.iteritems(): %endfor ${caller.body()}
<%def name="first_defined(*kw)"> %if not kw or kw[0] == UNDEFINED or not kw[0]: ${first_defined(kw[1:])} %endif <%def name="error_field(error_name, field_name, kind='span')"> <% error_key = (error_name, field_name) %> <${kind} class="error ${error_name} field-${field_name}" style="${'' if error_key in c.errors else 'display:none'}"> %if error_key in c.errors: ${c.errors[error_key].message} %endif <%def name="success_field(success_str, kind='p', successful=False, hide='')"> <${kind} class="error success"> %if successful: ${success_str} %endif <%def name="img_link(link_text, img, path, _id='', target='', img_id=None, size=None, **kw)"> <% if (not target or target == '_parent') and c.cname: target = '_top' if target: kw['target'] = target path = add_sr(path, sr_path = False) kw['target'] = target if size is None: size_str = "" else: size_str = "width='%d' height='%d'" % (size[0], size[1]) %> <%call expr="_a(href=path, _id=_id, **kw)"> ${link_text} <%def name="plain_link(link_text, path, _sr_path = True, nocname=False, fmt='', target='', **kw)"> ## caching comment: ## in addition to the args, this function also makes use of c.cname, ## and, via add_sr, both c.site.name and c.render_style. ## ## This function is called by (among other places) NavMenu as the ## primary rendering view. Any changes to the c-usage of this function ## will have to be propagated up. <% if (not target or target == '_parent') and c.cname: target = '_top' if c.cname and path.startswith('http://'): target = '_top' if target: kw['target'] = target link = _a_buffered(link_text, href=path and add_sr(path, sr_path=_sr_path, nocname=nocname), **kw) %> ${unsafe((fmt % link) if fmt else link)} <%def name="post_link(link_text, post_path, redir_path, params, _sr_path=True, nocname=False, fmt='', target='', **kw)"> <% action = add_sr(post_path, sr_path=_sr_path, nocname=nocname) href = add_sr(redir_path, sr_path=_sr_path, nocname=nocname) if (not target or target == '_parent') and c.cname: target = '_top' if c.cname and redir_path.startswith('http://'): target = '_top' if target: kw['target'] = target onclick = "$(this).parent().submit(); return false;" link = _a_buffered(link_text, href=href, onclick=onclick, **kw) %>
%for k, v in params.iteritems(): %endfor ${unsafe((fmt % link) if fmt else link)}
<%def name="text_with_links(txt, _sr_path = False, nocname=False, **kw)"> <% from r2.lib.filters import _force_unicode for key, link_args in kw.iteritems(): link_args.setdefault("_sr_path", _sr_path) link_args.setdefault("nocname", nocname) kw[key]=spaceCompress(capture(plain_link, **link_args)) txt = _force_unicode(txt) % kw txt = txt.replace(" <", " <").replace("> ", "> ") %> ${unsafe(txt)} <%def name="language_tool(name='lang', allow_blank = False, default_lang = g.lang, show_regions = False, all_langs = False)"> <% langs = g.all_languages if all_langs else g.languages if not show_regions: langs = [x for x in langs if len(x) == 2] %> %if langs: %endif <%def name="language_checkboxes(default = 'all')"> <% all_checked, some_checked = "checked='checked'", "" if default != "all": all_checked, some_checked = some_checked, all_checked %>

<% all_langs = [x for x in g.all_languages if len(x) == 2] %> %for col in cols(all_langs, 3): %for lang in col: %endfor %endfor
<% idname = "lang-" + lang if default != "all" and lang in default: checked = "checked='checked'" else: checked = "" %>
<%def name="separator(separator_char)"> ${separator_char} <%def name="optionalstyle(style)"> %if request.get.get('style') != "off": style="${style}" %endif <%def name="checkbox(name, text, val)"> ${text} <%def name="image_upload(post_target, current_image = None, onsubmit = '', onchange = '', label = '', form_id = 'image-upload', ask_type = False)">
%if label: %endif %if not c.default_sr: %endif
%if ask_type:   
%endif ${error_field("IMAGE_ERROR", "span")}
header preview
%if caller: ${caller.body()} %endif
<%def name="js_setup()"> <%def name="googleanalytics(uitype)"> %if g.googleanalytics and thing.site_tracking: %endif <%def name="logout(top=False,dest=None,a_class='')">
%if dest: %endif ${_("logout")}
<%def name="block_field(title, description = '', css_class= '', **kw)">
${title} %if description: ${description} %endif
${caller.body()}
<%def name="block_field(kind, title, description = '', css_class= '', **kw)">
${title} %if description: ${description} %endif
${caller.body()}
<%def name="round_field(title, description = '', css_class= '', **kw)"> <%call expr="block_field('roundfield', title, description = description, css_class= css_class, **kw)"> ${caller.body()} <%def name="line_field(title, description = '', css_class= '', **kw)"> <%call expr="block_field('linefield', title, description = description, css_class= css_class, **kw)"> ${caller.body()} <%def name="radio_type(field_name, val_name, title, text=None, checked=False)"> <% full_name = field_name + "_" + val_name %> %if text: ${text} %endif <%def name="reddit_selector(default_sr, sr_searches, subreddits)">
${error_field("SUBREDDIT_NOEXIST", "sr", "div")} ${error_field("SUBREDDIT_NOTALLOWED", "sr", "div")} ${error_field("SUBREDDIT_REQUIRED", "sr", "div")}
${_("popular choices")}
<%def name="timestamp(date, since=None)"> ## todo: use pubdate attribute once things are
tags. ## note: comment and link templates will pass a CachedVariable stub as since. <%def name="thing_timestamp(thing, since=None)"> ## todo: use pubdate attribute once things are
tags. ## note: comment and link templates will pass a CachedVariable stub as since. ${timestamp(thing._date, since=since)} <%def name="percentage(slice, total)"> %if total is None or total == "" or total == 0 or slice is None or slice == "": -- %else: ${int(100 * slice / total)}% %endif <%def name="pretty_button(label, func=None, func_vars='', extra_class='')"> ${label} <%def name="edited(thing, lastedited=None)"> %if isinstance(thing.editted, datetime): %elif thing.editted: * %endif <%def name="_md(text, wrap=False)"> ${unsafe(safemarkdown(_(text), wrap=wrap))}