1a107601fa490ca69215facceebe3d0dc5e7f1f8 | 6bcef0037bdb2d139a15065c3f31e872bae79df3 | ||
---|---|---|---|
1 | ## "The contents of this file are subject to the Common Public Attribution. | 1 | ## The contents of this file are subject to the Common Public Attribution. |
2 | ## License Version 1.0. (the "License"); you may not use this file except in | 2 | ## License Version 1.0. (the "License"); you may not use this file except in |
3 | ## compliance with the License. You may obtain a copy of the License at | 3 | ## compliance with the License. You may obtain a copy of the License at |
4 | ## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public | 4 | ## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public |
... | ... | ||
17 | ## the Original Code is CondeNet, Inc. | 17 | ## the Original Code is CondeNet, Inc. |
18 | ## | 18 | ## |
19 | ## All portions of the code written by CondeNet are Copyright (c) 2006-2008 | 19 | ## All portions of the code written by CondeNet are Copyright (c) 2006-2008 |
20 | ## CondeNet, Inc. All Rights Reserved." | 20 | ## CondeNet, Inc. All Rights Reserved. |
21 | ################################################################################ | 21 | ################################################################################ |
22 | 22 | ||
23 | <%! | 23 | <%! |
24 | from r2.controllers.errors import errors | 24 | from r2.controllers.errors import errors |
25 | from r2.lib.filters import spaceCompress | 25 | from r2.lib.filters import spaceCompress, unsafe |
26 | from r2.lib.template_helpers import reddit_link | 26 | from r2.lib.template_helpers import add_sr |
27 | from r2.lib.utils import cols | 27 | from r2.lib.utils import cols |
28 | %> | 28 | %> |
29 | <%def name="tags(**kw)"> | 29 | <%def name="tags(**kw)"> |
... | ... | ||
94 | </script> | 94 | </script> |
95 | </%def> | 95 | </%def> |
96 | 96 | ||
97 | <%def name="img_link(title, img, path, _id='', **kw)"> | 97 | <%def name="img_link(link_text, img, path, _id='', target='', img_id = None, **kw)"> |
98 | <% | ||
99 | if (not target or target == '_parent') and c.cname: | ||
100 | target = '_top' | ||
101 | if target: | ||
102 | kw['target'] = target | ||
103 | |||
104 | path = add_sr(path, sr_path = False) | ||
105 | kw['target'] = target | ||
106 | %> | ||
98 | <%call expr="_a(href=path, _id=_id, **kw)"> | 107 | <%call expr="_a(href=path, _id=_id, **kw)"> |
99 | <img src="${img}" alt="${title}"/> | 108 | <img ${("id='%s'" % img_id) if img_id else ''} src="${img}" alt="${link_text}"/> |
100 | </%call> | 109 | </%call> |
101 | </%def> | 110 | </%def> |
102 | 111 | ||
103 | <%def name="plain_link(title, path, _sr_path = True, fmt='', **kw)"> | 112 | <%def name="plain_link(link_text, path, _sr_path = True, nocname=False, fmt='', target='', **kw)"> |
104 | <% link = _a_buffered(title, href=reddit_link(path, url=_sr_path), **kw) %> | 113 | <% |
114 | if (not target or target == '_parent') and c.cname: | ||
115 | target = '_top' | ||
116 | if c.cname and path.startswith('http://'): | ||
117 | target = '_top' | ||
118 | if target: | ||
119 | kw['target'] = target | ||
120 | |||
121 | link = _a_buffered(link_text, href=add_sr(path, sr_path=_sr_path, nocname=nocname), **kw) | ||
122 | %> | ||
123 | |||
105 | ${unsafe((fmt % link) if fmt else link)} | 124 | ${unsafe((fmt % link) if fmt else link)} |
106 | </%def> | 125 | </%def> |
107 | 126 | ||
108 | 127 | ||
109 | <%def name="text_with_links(txt, _sr_path = False, **kw)"> | 128 | <%def name="text_with_links(txt, _sr_path = False, nocname=False, **kw)"> |
110 | <% | 129 | <% |
111 | from r2.lib.filters import _force_unicode | 130 | from r2.lib.filters import _force_unicode |
112 | for key, (text, href) in kw.iteritems(): | 131 | for key, (text, href) in kw.iteritems(): |
113 | kw[key]=spaceCompress(capture(plain_link, text, href, _sr_path=_sr_path)) | 132 | kw[key]=spaceCompress(capture(plain_link, text, href, _sr_path=_sr_path, nocname=nocname)) |
114 | txt = _force_unicode(txt) % kw | 133 | txt = _force_unicode(txt) % kw |
115 | txt = txt.replace(" <", " <").replace("> ", "> ") | 134 | txt = txt.replace(" <", " <").replace("> ", "> ") |
116 | 135 |