Esempio n. 1
0
def twitter_card(submitid):
    query = d.execute(
        """
        SELECT
            su.title, su.settings, su.content, su.subtype, su.userid, pr.username, pr.full_name, pr.config, ul.link_value, su.rating
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN user_links ul ON su.userid = ul.userid AND ul.link_type = 'twitter'
        WHERE submitid = %i
        LIMIT 1
    """, [submitid], ["single"])

    if not query:
        raise WeasylError("submissionRecordMissing")
    title, settings, content, subtype, userid, username, full_name, config, twitter, rating = query
    if 'h' in settings:
        raise WeasylError("submissionRecordMissing")
    elif 'f' in settings:
        raise WeasylError("FriendsOnly")

    if 'v' in settings:
        content = d.text_first_line(content, strip=True)
    content = d.summarize(html.strip_html(content))
    if not content:
        content = "[This submission has no description.]"

    ret = {
        'url':
        d.absolutify_url('/submission/%s/%s' %
                         (submitid, text.slug_for(title))),
    }

    if twitter:
        ret['creator'] = '@%s' % (twitter.lstrip('@'), )
        ret['title'] = title
    else:
        ret['title'] = '%s by %s' % (title, full_name)

    if ratings.CODE_MAP[rating].minimum_age >= 18:
        ret['card'] = 'summary'
        ret['description'] = 'This image is rated 18+ and only viewable on weasyl.com'
        return ret

    ret['description'] = content

    subcat = subtype / 1000 * 1000
    media_items = media.get_submission_media(submitid)
    if subcat == m.ART_SUBMISSION_CATEGORY and media_items.get('submission'):
        ret['card'] = 'photo'
        ret['image:src'] = d.absolutify_url(
            media_items['submission'][0]['display_url'])
    else:
        ret['card'] = 'summary'
        thumb = media_items.get('thumbnail-custom') or media_items.get(
            'thumbnail-generated')
        if thumb:
            ret['image:src'] = d.absolutify_url(thumb[0]['display_url'])

    return ret
Esempio n. 2
0
def twitter_card(submitid):
    query = d.execute("""
        SELECT
            su.title, su.settings, su.content, su.subtype, su.userid, pr.username, pr.full_name, pr.config, ul.link_value, su.rating
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN user_links ul ON su.userid = ul.userid AND ul.link_type = 'twitter'
        WHERE submitid = %i
        LIMIT 1
    """, [submitid], ["single"])

    if not query:
        raise WeasylError("submissionRecordMissing")
    title, settings, content, subtype, userid, username, full_name, config, twitter, rating = query
    if 'h' in settings:
        raise WeasylError("submissionRecordMissing")
    elif 'f' in settings:
        raise WeasylError("FriendsOnly")

    if 'v' in settings:
        content = d.text_first_line(content, strip=True)
    content = d.summarize(html.strip_html(content))
    if not content:
        content = "[This submission has no description.]"

    ret = {
        'url': d.absolutify_url(
            '/submission/%s/%s' % (submitid, text.slug_for(title))),
    }

    if twitter:
        ret['creator'] = '@%s' % (twitter.lstrip('@'),)
        ret['title'] = title
    else:
        ret['title'] = '%s by %s' % (title, full_name)

    if ratings.CODE_MAP[rating].minimum_age >= 18:
        ret['card'] = 'summary'
        ret['description'] = 'This image is rated 18+ and only viewable on weasyl.com'
        return ret

    ret['description'] = content

    subcat = subtype / 1000 * 1000
    media_items = media.get_submission_media(submitid)
    if subcat == m.ART_SUBMISSION_CATEGORY and media_items.get('submission'):
        ret['card'] = 'photo'
        ret['image:src'] = d.absolutify_url(media_items['submission'][0]['display_url'])
    else:
        ret['card'] = 'summary'
        thumb = media_items.get('thumbnail-custom') or media_items.get('thumbnail-generated')
        if thumb:
            ret['image:src'] = d.absolutify_url(thumb[0]['display_url'])

    return ret
Esempio n. 3
0
def select_view(userid, submitid, rating, ignore=True, anyway=None):
    query = d.engine.execute("""
        SELECT
            su.userid, pr.username, su.folderid, su.unixtime, su.title, su.content, su.subtype, su.rating, su.settings,
            su.page_views, fd.title, su.favorites, su.image_representations
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN folder fd USING (folderid)
        WHERE su.submitid = %(id)s
    """,
                             id=submitid).first()

    # Sanity check
    if query and userid in staff.MODS and anyway == "true":
        pass
    elif not query or "h" in query[8]:
        raise WeasylError("submissionRecordMissing")
    elif query[7] > rating and (
        (userid != query[0] and userid not in staff.MODS) or d.is_sfw_mode()):
        raise WeasylError("RatingExceeded")
    elif "f" in query[8] and not frienduser.check(userid, query[0]):
        raise WeasylError("FriendsOnly")
    elif ignore and ignoreuser.check(userid, query[0]):
        raise WeasylError("UserIgnored")
    elif ignore and blocktag.check(userid, submitid=submitid):
        raise WeasylError("TagBlocked")

    # Get submission filename
    submitfile = media.get_submission_media(submitid).get(
        'submission', [None])[0]

    # Get submission text
    if submitfile and submitfile['file_type'] in ['txt', 'htm']:
        submittext = files.read(submitfile['full_file_path'])
    else:
        submittext = None

    embedlink = d.text_first_line(query[5]) if "v" in query[8] else None

    google_doc_embed = None
    if 'D' in query[8]:
        db = d.connect()
        gde = d.meta.tables['google_doc_embeds']
        q = (sa.select([gde.c.embed_url]).where(gde.c.submitid == submitid))
        results = db.execute(q).fetchall()
        if not results:
            raise WeasylError("can't find embed information")
        google_doc_embed = results[0]

    tags, artist_tags = searchtag.select_with_artist_tags(submitid)
    settings = d.get_profile_settings(query[0])

    if query[12] is None:
        sub_media = media.get_submission_media(submitid)
    else:
        sub_media = media.deserialize_image_representations(query[12])

    return {
        "submitid":
        submitid,
        "userid":
        query[0],
        "username":
        query[1],
        "folderid":
        query[2],
        "unixtime":
        query[3],
        "title":
        query[4],
        "content": (d.text_first_line(query[5], strip=True)
                    if "v" in query[8] else query[5]),
        "subtype":
        query[6],
        "rating":
        query[7],
        "settings":
        query[8],
        "page_views": (query[9] + 1 if d.common_view_content(
            userid, 0 if anyway == "true" else submitid, "submit") else
                       query[9]),
        "fave_count":
        query[11],
        "mine":
        userid == query[0],
        "reported":
        report.check(submitid=submitid),
        "favorited":
        favorite.check(userid, submitid=submitid),
        "friends_only":
        "f" in query[8],
        "hidden_submission":
        "h" in query[8],
        "collected":
        collection.owns(userid, submitid),
        "no_request":
        not settings.allow_collection_requests,
        "text":
        submittext,
        "sub_media":
        sub_media,
        "user_media":
        media.get_user_media(query[0]),
        "submit":
        submitfile,
        "embedlink":
        embedlink,
        "embed":
        embed.html(embedlink) if embedlink is not None else None,
        "google_doc_embed":
        google_doc_embed,
        "tags":
        tags,
        "artist_tags":
        artist_tags,
        "removable_tags":
        searchtag.removable_tags(userid, query[0], tags, artist_tags),
        "can_remove_tags":
        searchtag.can_remove_tags(userid, query[0]),
        "folder_more":
        select_near(userid, rating, 1, query[0], query[2], submitid),
        "folder_title":
        query[10] if query[10] else "Root",
        "comments":
        comment.select(userid, submitid=submitid),
    }
Esempio n. 4
0
def select_view(userid, submitid, rating, ignore=True, anyway=None):
    query = d.execute("""
        SELECT
            su.userid, pr.username, su.folderid, su.unixtime, su.title, su.content, su.subtype, su.rating, su.settings,
            su.page_views, su.sorttime, pr.config, fd.title
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN folder fd USING (folderid)
        WHERE su.submitid = %i
    """, [submitid], options=["single", "list"])

    # Sanity check
    if query and userid in staff.MODS and anyway == "true":
        pass
    elif not query or "h" in query[8]:
        raise WeasylError("submissionRecordMissing")
    elif query[7] > rating and ((userid != query[0] and userid not in staff.MODS) or d.is_sfw_mode()):
        raise WeasylError("RatingExceeded")
    elif "f" in query[8] and not frienduser.check(userid, query[0]):
        raise WeasylError("FriendsOnly")
    elif ignore and ignoreuser.check(userid, query[0]):
        raise WeasylError("UserIgnored")
    elif ignore and blocktag.check(userid, submitid=submitid):
        raise WeasylError("TagBlocked")

    # Get submission filename
    submitfile = media.get_submission_media(submitid).get('submission', [None])[0]

    # Get submission text
    if submitfile and submitfile['file_type'] in ['txt', 'htm']:
        submittext = files.read(submitfile['full_file_path'])
    else:
        submittext = None

    embedlink = d.text_first_line(query[5]) if "v" in query[8] else None

    google_doc_embed = None
    if 'D' in query[8]:
        db = d.connect()
        gde = d.meta.tables['google_doc_embeds']
        q = (sa.select([gde.c.embed_url])
             .where(gde.c.submitid == submitid))
        results = db.execute(q).fetchall()
        if not results:
            raise WeasylError("can't find embed information")
        google_doc_embed = results[0]

    tags, artist_tags = searchtag.select_with_artist_tags(submitid)
    settings = d.get_profile_settings(query[0])

    return {
        "submitid": submitid,
        "userid": query[0],
        "username": query[1],
        "folderid": query[2],
        "unixtime": query[3],
        "title": query[4],
        "content": (d.text_first_line(query[5], strip=True) if "v" in query[8] else query[5]),
        "subtype": query[6],
        "rating": query[7],
        "settings": query[8],
        "page_views": (
            query[9] + 1 if d.common_view_content(userid, 0 if anyway == "true" else submitid, "submit") else query[9]),
        "fave_count": d.execute(
            "SELECT COUNT(*) FROM favorite WHERE (targetid, type) = (%i, 's')",
            [submitid], ["element"]),


        "mine": userid == query[0],
        "reported": report.check(submitid=submitid),
        "favorited": favorite.check(userid, submitid=submitid),
        "friends_only": "f" in query[8],
        "hidden_submission": "h" in query[8],
        "collectors": collection.find_owners(submitid),
        "no_request": not settings.allow_collection_requests,

        "text": submittext,
        "sub_media": media.get_submission_media(submitid),
        "user_media": media.get_user_media(query[0]),
        "submit": submitfile,
        "embedlink": embedlink,
        "embed": embed.html(embedlink) if embedlink is not None else None,
        "google_doc_embed": google_doc_embed,


        "tags": tags,
        "artist_tags": artist_tags,
        "removable_tags": searchtag.removable_tags(userid, query[0], tags, artist_tags),
        "can_remove_tags": searchtag.can_remove_tags(userid, query[0]),
        "folder_more": select_near(userid, rating, 1, query[0], query[2], submitid),
        "folder_title": query[12] if query[12] else "Root",


        "comments": comment.select(userid, submitid=submitid),
    }