def get_subreddit_stylesheet_url(sr): if not g.css_killswitch and c.can_apply_styles and c.allow_styles: if c.secure: if sr.stylesheet_url: return make_url_https(sr.stylesheet_url) elif sr.stylesheet_url_https: return sr.stylesheet_url_https else: if sr.stylesheet_url: return sr.stylesheet_url elif sr.stylesheet_url_http: return sr.stylesheet_url_http
def _oembed_post(thing, **embed_options): subreddit = thing.subreddit_slow if (not can_view_link_comments(thing) or subreddit.type in Subreddit.private_types): raise ForbiddenError(errors.POST_NOT_ACCESSIBLE) live = '' if embed_options.get('live'): time = datetime.now(g.tz).isoformat() live = 'data-card-created="{}"'.format(time) script = '' if not embed_options.get('omitscript', False): script = format_html( SCRIPT_TEMPLATE, embedly_script=EMBEDLY_SCRIPT, ) link_url = UrlParser(thing.make_permalink_slow(force_domain=True)) link_url.update_query(ref='share', ref_source='embed') author_name = "" if not thing._deleted: author = thing.author_slow if author._deleted: author_name = _("[account deleted]") else: author_name = author.name html = format_html( POST_EMBED_TEMPLATE, live_data_attr=live, link_url=link_url.unparse(), title=websafe(thing.title), subreddit_url=make_url_https(subreddit.path), subreddit_name=subreddit.name, script=script, ) oembed_response = dict( _OEMBED_BASE, type="rich", title=thing.title, author_name=author_name, html=html, ) return oembed_response
def _oembed_comment(thing, **embed_options): link = thing.link_slow subreddit = link.subreddit_slow if (not can_view_link_comments(link) or subreddit.type in Subreddit.private_types): raise ForbiddenError(errors.COMMENT_NOT_ACCESSIBLE) if not thing._deleted: author = thing.author_slow if author._deleted: author_name = _("[account deleted]") else: author_name = author.name title = _('%(author)s\'s comment from discussion "%(title)s"') % { "author": author_name, "title": _force_unicode(link.title), } else: author_name = "" title = "" parent = "true" if embed_options.get('parent') else "false" html = format_html( embeds.get_inject_template(embed_options.get('omitscript')), media=g.media_domain, parent=parent, live="true" if embed_options.get('live') else "false", created=datetime.now(g.tz).isoformat(), comment=thing.make_permalink_slow(force_domain=True), link=link.make_permalink_slow(force_domain=True), title=websafe(title), uuid=uuid1(), ) oembed_response = dict( _OEMBED_BASE, type="rich", title=title, author_name=author_name, html=html, ) if author_name: oembed_response['author_url'] = make_url_https('/user/' + author_name) return oembed_response
def _oembed_comment(thing, **embed_options): link = thing.link_slow subreddit = link.subreddit_slow if (not can_view_link_comments(link) or subreddit.type in Subreddit.private_types): raise ForbiddenError(errors.COMMENT_NOT_ACCESSIBLE) if not thing._deleted: author = thing.author_slow if author._deleted: author_name = _("[account deleted]") else: author_name = author.name title = _('%(author)s\'s comment from discussion "%(title)s"') % { "author": author_name, "title": _force_unicode(link.title), } else: author_name = "" title = "" parent = "true" if embed_options.get('parent') else "false" html = format_html(embeds.get_inject_template(embed_options.get('omitscript')), media=g.media_domain, parent=parent, live="true" if embed_options.get('live') else "false", created=datetime.now(g.tz).isoformat(), comment=thing.make_permalink_slow(force_domain=True), link=link.make_permalink_slow(force_domain=True), title=websafe(title), uuid=uuid1(), ) oembed_response = dict(_OEMBED_BASE, type="rich", title=title, author_name=author_name, html=html, ) if author_name: oembed_response['author_url'] = make_url_https('/user/' + author_name) return oembed_response
def _oembed_post(thing, **embed_options): subreddit = thing.subreddit_slow if (not can_view_link_comments(thing) or subreddit.type in Subreddit.private_types): raise ForbiddenError(errors.POST_NOT_ACCESSIBLE) live = '' if embed_options.get('live'): time = datetime.now(g.tz).isoformat() live = 'data-card-created="{}"'.format(time) script = '' if not embed_options.get('omitscript', False): script = format_html(SCRIPT_TEMPLATE, embedly_script=EMBEDLY_SCRIPT, ) link_url = UrlParser(thing.make_permalink_slow(force_domain=True)) link_url.update_query(ref='share', ref_source='embed') author_name = "" if not thing._deleted: author = thing.author_slow if author._deleted: author_name = _("[account deleted]") else: author_name = author.name html = format_html(POST_EMBED_TEMPLATE, live_data_attr=live, link_url=link_url.unparse(), title=websafe(thing.title), subreddit_url=make_url_https(subreddit.path), subreddit_name=subreddit.name, script=script, ) oembed_response = dict(_OEMBED_BASE, type="rich", title=thing.title, author_name=author_name, html=html, ) return oembed_response
def _oembed_comment(thing, **embed_options): link = thing.link_slow if not can_view_link_comments(link): raise ForbiddenError("Cannot access this comment.") if not thing._deleted: author = thing.author_slow if author._deleted: author_name = _("[account deleted]") else: author_name = author.name title = _('%(author)s\'s comment from discussion "%(title)s"') % { "author": author_name, "title": link.title, } else: author_name = "" title = "" html = format_html( embeds.get_inject_template(), media=g.media_domain, parent="true" if embed_options.get('parent') else "false", live="true" if embed_options.get('live') else "false", created=datetime.now(g.tz).isoformat(), comment=thing.make_permalink_slow(force_domain=True), link=link.make_permalink_slow(force_domain=True), title=websafe(title), ) oembed_response = dict( _OEMBED_BASE, type="rich", title=title, author_name=author_name, html=html, ) if author_name: oembed_response['author_url'] = make_url_https('/user/' + author_name) return oembed_response
def _oembed_comment(thing, **embed_options): link = thing.link_slow if not can_view_link_comments(link): raise ForbiddenError("Cannot access this comment.") if not thing._deleted: author = thing.author_slow if author._deleted: author_name = _("[account deleted]") else: author_name = author.name title = _('%(author)s\'s comment from discussion "%(title)s"') % { "author": author_name, "title": _force_unicode(link.title), } else: author_name = "" title = "" html = format_html(embeds.get_inject_template(), media=g.media_domain, parent="true" if embed_options.get('parent') else "false", live="true" if embed_options.get('live') else "false", created=datetime.now(g.tz).isoformat(), comment=thing.make_permalink_slow(force_domain=True), link=link.make_permalink_slow(force_domain=True), title=websafe(title), ) oembed_response = dict(_OEMBED_BASE, type="rich", title=title, author_name=author_name, html=html, ) if author_name: oembed_response['author_url'] = make_url_https('/user/' + author_name) return oembed_response
from pylons.i18n import _ from r2.controllers.reddit_base import MinimalController from r2.lib import embeds from r2.lib.base import abort from r2.lib.errors import ForbiddenError from r2.lib.filters import scriptsafe_dumps, websafe, _force_unicode from r2.lib.utils import url_to_thing from r2.lib.template_helpers import format_html, make_url_https from r2.lib.validator import can_view_link_comments, validate, VBoolean, VUrl from r2.models import Comment _OEMBED_BASE = { "version": "1.0", "provider_name": "reddit", "provider_url": make_url_https('/'), } def _oembed_for(thing, **embed_options): """Given a Thing, return a dict of oEmbed data for that thing. Raises NotImplementedError if this Thing type does not yet support oEmbeds. """ if isinstance(thing, Comment): return _oembed_comment(thing, **embed_options) raise NotImplementedError("Unable to render oembed for thing '%r'", thing)
from pylons.i18n import _ from r2.controllers.reddit_base import MinimalController from r2.lib import embeds from r2.lib.base import abort from r2.lib.errors import ForbiddenError from r2.lib.filters import scriptsafe_dumps, websafe from r2.lib.utils import url_to_thing from r2.lib.template_helpers import format_html, make_url_https from r2.lib.validator import can_view_link_comments, validate, VBoolean, VUrl from r2.models import Comment _OEMBED_BASE = { "version": "1.0", "provider_name": "reddit", "provider_url": make_url_https('/'), } def _oembed_for(thing, **embed_options): """Given a Thing, return a dict of oEmbed data for that thing. Raises NotImplementedError if this Thing type does not yet support oEmbeds. """ if isinstance(thing, Comment): return _oembed_comment(thing, **embed_options) raise NotImplementedError("Unable to render oembed for thing '%r'", thing)