Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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
Esempio n. 6
0
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