Пример #1
0
def ban_list():
    bans = d2_bans.query.filter(d2_bans.banned_id != 0).filter(
        d2_bans.display != 0).all()
    ban_list = ""

    for ban in bans:
        banned = d2_user.query.filter_by(user_id=ban.banned_id).first()
        banner = d2_user.query.filter_by(user_id=ban.banner).first()

        if ban.length is not 0:
            banduration = display_time(ban.length)
            timeleft = get_ban_expiry(ban.expires)
        else:
            banduration = "FOREVER"
            timeleft = "NEVER"
        if ban.length is -1:
            banduration = "UNBANNED"
            timeleft = "EXPIRED"

        ban_list += '''<tr>
                        <td>''' + recent_date(ban.time) + '''</td>
                        <td><a href="/user/''' + banned.username + '''" class="username ''' + get_group_style_from_id(
            banned.user_id) + '''">''' + banned.username + '''</a></td>
                        <td>''' + ban.reason + '''</td>
                        <td>''' + banduration + '''</td>
                        <td>''' + timeleft + '''</td>
                        <td><a href="/user/''' + banner.username + '''" class="username ''' + get_group_style_from_id(
                banner.user_id) + '''">''' + banner.username + '''</a></td>
                    </tr>'''

    return {'ban_list': ban_list}
Пример #2
0
def get_recent_posts(limit=20):
    activity = []
    activity_sorted = []
    activity_item = ""
    count = 0

    posts = d2_activity.query.filter(d2_activity.replyto != 0).order_by(
        d2_activity.time.desc()).limit(limit).all()
    threads = d2_activity.query.filter(d2_activity.category != 0).order_by(
        d2_activity.reply_time.desc()).limit(limit).all()

    for post in posts:
        activity.append([post.time, "post", post.id, post.replyto])

    for thread in threads:
        activity.append([thread.time, "thread", thread.id, thread.id])

    activity.sort(reverse=True)
    activity = unique_items(activity)

    for item in activity:
        if count < limit:
            if item[1] == "post":
                post = d2_activity.query.filter(
                    d2_activity.id == item[2]).first()
                thread = d2_activity.query.filter(
                    d2_activity.id == post.replyto).first()
                forum = d2_forums.query.filter(
                    d2_forums.id == thread.category).first()

                if post and thread and forum:
                    if thread.anonymous == 0:
                        threadcreator = '<a href="/user/' + thread.user.username + '" class="profile-inline">' + thread.user.username + '</a>'
                    else:
                        threadcreator = '<a href="#">Anonymous</a>'

                    if post.anonymous == 0:
                        latestreplier = '<a href="/user/' + post.user.username + '" class="profile-inline">' + post.user.username + '</a>'
                    else:
                        latestreplier = '<a href="#">Anonymous</a>'

                    activity_item += '''<tr>
                                            <td class="home-forum home-forum-icon"><a href="/''' + str(
                        forum.short_name
                    ) + '''/''' + str(
                        thread.id
                    ) + '''#''' + str(post.id) + '''"><img src="''' + cdn_path(
                    ) + '''/images/posticons/icon''' + str(
                        thread.post_icon
                    ) + '''.png" alt=""/></a></td>
                                            <td class="home-forum">
                                            <span class="small align-right home-forum-latest">
                                                <span class="timedisplay">''' + recent_date(
                        post.time
                    ) + '''</span><br/>
                                                by ''' + latestreplier + ''' <a href="/''' + str(
                        forum.short_name
                    ) + '''/''' + str(
                        thread.id
                    ) + '''#''' + str(post.id) + '''"><img src="''' + cdn_path(
                    ) + '''/icons/thread_new.png" style="margin-top: -2px;"/></a>
                                            </span>
                                            <a href="/''' + str(
                        forum.short_name
                    ) + '''/''' + str(thread.id) + '''#''' + str(
                        post.id) + '''"><b>''' + thread.title + '''</b></a>
                                            <span class="small"><br/>
                                            ''' + threadcreator + ''', <span class="timedisplay">''' + recent_date(
                            thread.time) + '''</span>, <a href="/''' + str(
                                forum.short_name
                            ) + '''">''' + forum.name + '''</a>
                                            </span>
                                        </tr>'''

            if item[1] == "thread":
                thread = d2_activity.query.filter(
                    d2_activity.id == item[2]).first()
                forum = d2_forums.query.filter(
                    d2_forums.id == thread.category).first()

                if thread.anonymous == 0:
                    threadcreator = '<a href="/user/' + thread.user.username + '" class="profile-inline">' + thread.user.username + '</a>'
                else:
                    threadcreator = '<a href="#">Anonymous</a>'

                if thread and forum:
                    activity_item += '''<tr>
                                            <td class="home-forum home-forum-icon"><a href="/''' + str(
                        forum.short_name
                    ) + '''/''' + str(
                        thread.id
                    ) + '''"><img src="''' + cdn_path(
                    ) + '''/images/posticons/icon''' + str(
                        thread.post_icon
                    ) + '''.png" alt=""/></a></td>
                                            <td class="home-forum">
                                            <span class="small align-right home-forum-latest">
                                                <span class="timedisplay">''' + recent_date(
                        thread.reply_time
                    ) + '''</span><br/>
                                                by ''' + threadcreator + ''' <a href="/''' + str(
                        forum.short_name
                    ) + '''/''' + str(
                        thread.id
                    ) + '''"><img src="''' + cdn_path(
                    ) + '''/icons/thread_new.png" style="margin-top: -2px;"/></a>
                                            </span>
                                            <a href="/''' + str(
                        forum.short_name) + '''/''' + str(
                            thread.id
                        ) + '''"><b>''' + thread.title + '''</b></a>
                                            <span class="small"><br/>
                                            ''' + threadcreator + ''', <span class="timedisplay">''' + recent_date(
                            thread.time) + '''</span>, <a href="/''' + str(
                                forum.short_name
                            ) + '''">''' + forum.name + '''</a>
                                            </span></td>
                                        </tr>'''
            count += 1

    return activity_item
Пример #3
0
def get_recent_posts(limit=20, include=[]):  ## TODO: add exclusions
    activity = []
    activity_sorted = []
    posts = []
    threads = []
    activity_item = ""
    count = 0

    for included_channel in include:
        channel = d2_channels.query.filter(
            d2_channels.short_name == included_channel).first()
        if channel:
            post_finder = d2_activity.query.filter(
                d2_activity.replyto != 0).order_by(
                    d2_activity.time.desc()).limit(limit).all()
            for post in post_finder:
                thread_check = d2_activity.query.filter(
                    d2_activity.id == post.replyto).first()
                if thread_check:
                    category_check = d2_channels.query.filter(
                        d2_channels.id == thread_check.category).first()
                    if included_channel == category_check.short_name:
                        posts.append(post)
            thread_finder = d2_activity.query.filter(
                d2_activity.category == channel.id).order_by(
                    d2_activity.time.desc()).limit(limit).all()
            for thread in thread_finder:
                threads.append(thread)

    for post in posts:
        activity.append([post.time, "post", post.id, post.replyto])

    for thread in threads:
        activity.append([thread.time, "thread", thread.id, thread.id])

    activity.sort(reverse=True)
    activity = unique_items(activity)

    for item in activity:
        if count < limit:
            if item[1] == "post":
                post = d2_activity.query.filter(
                    d2_activity.id == item[2]).first()
                thread = d2_activity.query.filter(
                    d2_activity.id == post.replyto).first()
                channel = d2_channels.query.filter(
                    d2_channels.id == thread.category).first()

                if (post and thread and channel):
                    if thread.anonymous == 0 and thread.user_id:
                        threadcreator = '<a href="/user/' + get_username_by_id(
                            thread.user_id
                        ) + '" class="profile-inline">' + get_displayed_name_by_id(
                            thread.user_id) + '</a>'
                    else:
                        threadcreator = '<a href="#">Anonymous</a>'

                    if post.anonymous == 0 and post.user_id:
                        latestreplier = '<a href="/user/' + get_username_by_id(
                            post.user_id
                        ) + '" class="profile-inline">' + get_displayed_name_by_id(
                            post.user_id) + '</a>'
                    else:
                        latestreplier = '<a href="#">Anonymous</a>'

                    activity_item += '''<tr>
                                            <td class="home-channel home-channel-icon"><a href="/''' + str(
                        channel.short_name
                    ) + '''/''' + str(
                        thread.id
                    ) + '''#''' + str(post.id) + '''"><img src="''' + cdn_path(
                    ) + '''/images/posticons/''' + str(
                        thread.post_icon
                    ) + '''.png" alt=""/></a></td>
                                            <td class="home-channel">
                                            <span class="small align-right home-channel-latest">
                                                <span class="timedisplay">''' + recent_date(
                        post.time
                    ) + '''</span><br/>
                                                by ''' + latestreplier + ''' <a href="/''' + str(
                        channel.short_name
                    ) + '''/''' + str(
                        thread.id
                    ) + '''#''' + str(post.id) + '''"><img src="''' + cdn_path(
                    ) + '''/icons/thread_new.png" style="margin-top: -2px;"/></a>
                                            </span>
                                            <a href="/''' + str(
                        channel.short_name
                    ) + '''/''' + str(thread.id) + '''#''' + str(
                        post.id) + '''"><b>''' + thread.title + '''</b></a>
                                            <span class="small"><br/>
                                            ''' + threadcreator + ''', <span class="timedisplay">''' + recent_date(
                            thread.time) + '''</span>, <a href="/''' + str(
                                channel.short_name
                            ) + '''">''' + channel.name + '''</a>
                                            </span>
                                        </tr>'''
                    count += 1

            if item[1] == "thread":
                thread = d2_activity.query.filter(
                    d2_activity.id == item[2]).first()
                channel = d2_channels.query.filter(
                    d2_channels.id == thread.category).first()
                if (thread and channel):
                    if thread.anonymous == 0:
                        threadcreator = '<a href="/user/' + get_username_by_id(
                            thread.user_id
                        ) + '" class="profile-inline">' + get_displayed_name_by_id(
                            thread.user_id) + '</a>'
                    else:
                        threadcreator = '<a href="#">Anonymous</a>'
                    activity_item += '''<tr>
                                            <td class="home-channel home-channel-icon"><a href="/''' + str(
                        channel.short_name
                    ) + '''/''' + str(
                        thread.id
                    ) + '''"><img src="''' + cdn_path(
                    ) + '''/images/posticons/''' + str(
                        thread.post_icon
                    ) + '''.png" alt=""/></a></td>
                                            <td class="home-channel">
                                            <span class="small align-right home-channel-latest">
                                                <span class="timedisplay">''' + recent_date(
                        thread.reply_time
                    ) + '''</span><br/>
                                                by ''' + threadcreator + ''' <a href="/''' + str(
                        channel.short_name
                    ) + '''/''' + str(
                        thread.id
                    ) + '''"><img src="''' + cdn_path(
                    ) + '''/icons/thread_new.png" style="margin-top: -2px;"/></a>
                                            </span>
                                            <a href="/''' + str(
                        channel.short_name) + '''/''' + str(
                            thread.id
                        ) + '''"><b>''' + thread.title + '''</b></a>
                                            <span class="small"><br/>
                                            ''' + threadcreator + ''', <span class="timedisplay">''' + recent_date(
                            thread.time) + '''</span>, <a href="/''' + str(
                                channel.short_name
                            ) + '''">''' + channel.name + '''</a>
                                            </span></td>
                                        </tr>'''
                    count += 1

    return activity_item
Пример #4
0
def view_user_threads(user):
    if 'logged_in' in syndbb.session:
        userid = checkSession(str(syndbb.session['logged_in']))
        if userid:
            dynamic_css_header = ["css/bbcode_editor.css"]
            isInline = syndbb.request.args.get('inlinecontent', '')
            threadcheck = d2_activity.query.filter_by(user_id=user).filter(
                d2_activity.replyto == 0).filter(
                    d2_activity.anonymous != 1).order_by(
                        d2_activity.time.desc()).all()
            usercheck = d2_user.query.filter_by(user_id=user).first()
            if usercheck:
                if threadcheck:
                    thread_list = ""
                    for thread in threadcheck:
                        forumcheck = d2_forums.query.filter_by(
                            id=thread.category).first()
                        if thread.reply_count is 1:
                            replystr = "reply"
                        else:
                            replystr = "replies"
                        lastpost = d2_activity.query.filter_by(
                            replyto=thread.id).order_by(
                                d2_activity.time.desc()).first()
                        if lastpost:
                            latest = lastpost.id
                            latestreplier = lastpost
                        else:
                            latest = thread.id
                            latestreplier = thread
                        thread_list += '''<tr>
                                                <td class="home-forum home-forum-icon"><img src="''' + cdn_path(
                        ) + '''/images/posticons/icon''' + str(
                            thread.post_icon
                        ) + '''.png" alt=""/></td>
                                                <td class="home-forum">
                                                <span class="small" style="float:right; text-align: right;">
                                                    <span class="timedisplay">''' + recent_date(
                            thread.reply_time
                        ) + '''</span><br/>
                                                    by <a href="/user/''' + latestreplier.user.username + '''" class="profile-inline">''' + latestreplier.user.username + '''</a> <a href="/''' + str(
                            forumcheck.short_name
                        ) + '''/''' + str(thread.id) + '''#''' + str(
                            latest
                        ) + '''"><img src="''' + cdn_path(
                        ) + '''/icons/thread_new.png" style="margin-top: -2px;"/></a>
                                                </span>
                                                <a href="/''' + str(
                            forumcheck.short_name) + '''/''' + str(
                                thread.id
                            ) + '''"><b>''' + thread.title + '''</b></a>
                                                <span class="small"><br/>
                                                <a href="/user/''' + thread.user.username + '''" class="profile-inline">''' + thread.user.username + '''</a>, <span class="timedisplay">''' + recent_date(
                                thread.time) + '''</span>
                                                </span>
                                                </td>
                                            </tr>'''
                    subheading = []
                    subheading.append('<a href="/user/' + usercheck.username +
                                      '">' + usercheck.username + '</a>')
                    return syndbb.render_template(
                        'view_user_threads.html',
                        dynamic_css_header=dynamic_css_header,
                        isInline=isInline,
                        thread_list=thread_list,
                        title="All threads by " + usercheck.username,
                        subheading=subheading)
                else:
                    return syndbb.render_template(
                        'invalid.html', title=" &bull; No threads found")
            else:
                return syndbb.render_template('invalid.html',
                                              title=" &bull; No threads found")
    else:
        return syndbb.render_template('error_not_logged_in.html',
                                      title="Not logged in")
Пример #5
0
def view_forum(category):
    forumcheck = d2_forums.query.filter_by(short_name=category).first()
    forumlogo = ""
    dynamic_js_footer = []
    dynamic_css_header = []
    if forumcheck:
        dynamic_js_footer = ["js/inline.js", "js/bootbox.min.js"]
        #        if forumcheck.short_name == "yiff":
        #            dynamic_css_header.append("css/oify.css")
        if (forumcheck.nsfw) and ('nsfwAllow' not in syndbb.request.cookies):
            dynamic_js_footer.append("js/nsfwprompt.js")
            dynamic_css_header.append("css/nsfw_fill.css")

        logo_file = syndbb.app.static_folder + "/images/logos/" + forumcheck.short_name + ".png"
        if syndbb.os.path.isfile(logo_file):
            forumlogo = '<img src="' + cdn_path(
            ) + '/images/logos/' + forumcheck.short_name + '.png" alt="D2K5" class="sitelogo mask">'

        threads = d2_activity.query.filter_by(category=forumcheck.id).order_by(
            d2_activity.reply_time.desc()).all()

        topbuttons = '<a href="/' + forumcheck.short_name + '/grid" title="Grid View" style="float:right;"><i class="silk-icon icon_application_view_tile" aria-hidden="true"></i></a>'
        topbuttons += '<a href="/im/?room=' + forumcheck.short_name + '" title="Join Chat" style="float:right;"><i class="silk-icon icon_comment" aria-hidden="true"></i></a>'
        if 'logged_in' in syndbb.session:
            userid = checkSession(str(syndbb.session['logged_in']))
            if userid:
                topbuttons += '<a href="/' + forumcheck.short_name + '/new_thread" title="New Thread" style="float:right;"><i class="silk-icon icon_add" aria-hidden="true"></i></a>'

        subheading = []
        subheading.append("")
        thread_list = ""
        for thread in threads:
            if thread.reply_count is 1:
                replystr = "reply"
            else:
                replystr = "replies"
            if thread.anonymous == 0:
                threadcreator = '<a href="/user/' + thread.user.username + '" class="profile-inline">' + thread.user.username + '</a>'
                latestreplier = '<a href="/user/' + thread.user.username + '" class="profile-inline">' + thread.user.username + '</a>'
            else:
                threadcreator = '<a href="#">Anonymous</a>'
                latestreplier = '<a href="#">Anonymous</a>'

            lastpost = d2_activity.query.filter_by(replyto=thread.id).order_by(
                d2_activity.time.desc()).first()
            if lastpost:
                latest = lastpost.id
                latestreplier = lastpost
                if lastpost.anonymous == 0:
                    latestreplier = '<a href="/user/' + lastpost.user.username + '" class="profile-inline">' + lastpost.user.username + '</a>'
                else:
                    latestreplier = '<a href="#">Anonymous</a>'
            else:
                latest = thread.id

            thread_list += '''<tr>
                                    <td class="home-forum home-forum-icon"><img src="''' + cdn_path(
            ) + '''/images/posticons/icon''' + str(
                thread.post_icon) + '''.png" alt=""/></td>
                                    <td class="home-forum">
                                    <span class="small" style="float:right; text-align: right;">
                                        <span class="timedisplay">''' + recent_date(
                    thread.reply_time
                ) + '''</span><br/>
                                        by ''' + latestreplier + '''</a> <a href="/''' + str(
                    forumcheck.short_name
                ) + '''/''' + str(
                    thread.id
                ) + '''#''' + str(latest) + '''"><img src="''' + cdn_path(
                ) + '''/icons/thread_new.png" style="margin-top: -2px;"/></a>
                                    </span>
                                    <a href="/''' + str(
                    forumcheck.short_name) + '''/''' + str(
                        thread.id) + '''"><b>''' + thread.title + '''</b></a>
                                    <span class="small"><br/>
                                    ''' + threadcreator + ''', <span class="timedisplay">''' + recent_date(
                            thread.time) + '''</span>
                                    </span>
                                    </td>
                                </tr>'''

        return syndbb.render_template('view_forum.html',
                                      forum=forumcheck,
                                      thread_list=thread_list,
                                      forumlogo=forumlogo,
                                      dynamic_js_footer=dynamic_js_footer,
                                      dynamic_css_header=dynamic_css_header,
                                      title=forumcheck.name,
                                      topbuttons=topbuttons,
                                      subheading=subheading)
    else:
        return syndbb.render_template('invalid.html', title="No page found")
Пример #6
0
def view_forum_grid(category):
    forumcheck = d2_forums.query.filter_by(short_name=category).first()
    forumlogo = ""
    dynamic_js_footer = []
    dynamic_css_header = []
    if forumcheck:
        #        if forumcheck.short_name == "yiff":
        #            dynamic_css_header.append("css/oify.css")
        if (forumcheck.nsfw) and ('nsfwAllow' not in syndbb.request.cookies):
            dynamic_js_footer.append("js/nsfwprompt.js")
            dynamic_css_header.append("css/nsfw_fill.css")

        logo_file = syndbb.app.static_folder + "/images/logos/" + forumcheck.short_name + ".png"
        if syndbb.os.path.isfile(logo_file):
            forumlogo = '<img src="' + cdn_path(
            ) + '/images/logos/' + forumcheck.short_name + '.png" alt="D2K5" class="sitelogo mask">'

        image_finder = "(?<=\[img\]).*?(?=\[/img\])"
        image_finder2 = "(?<=\[t\]).*?(?=\[/t\])"
        threads = d2_activity.query.filter_by(category=forumcheck.id).order_by(
            d2_activity.reply_time.desc()).all()

        topbuttons = '<a href="/' + forumcheck.short_name + '" title="List View" style="float:right;"><i class="silk-icon icon_application_view_list" aria-hidden="true"></i></a>'
        topbuttons += '<a href="/im/?room=' + forumcheck.short_name + '" title="Join Chat" style="float:right;"><i class="silk-icon icon_comment" aria-hidden="true"></i></a>'
        if 'logged_in' in syndbb.session:
            userid = checkSession(str(syndbb.session['logged_in']))
            if userid:
                topbuttons += '<a href="/' + forumcheck.short_name + '/new_thread" title="New Thread" style="float:right;"><i class="silk-icon icon_add" aria-hidden="true"></i></a>'

        subheading = []
        subheading.append("")
        thread_list = ""
        gridview = 1
        for thread in threads:
            if thread.reply_count is 1:
                replystr = "reply"
            else:
                replystr = "replies"
            thread_title = (thread.title[:25] +
                            '...') if len(thread.title) > 25 else thread.title
            lastpost = d2_activity.query.filter_by(replyto=thread.id).order_by(
                d2_activity.time.desc()).first()
            if lastpost:
                latest = lastpost.id
            else:
                latest = thread.id

            thumbfolder = syndbb.app.static_folder + "/data/threadimg/grid/"
            images = syndbb.re.findall(image_finder, thread.content,
                                       syndbb.re.IGNORECASE)
            images2 = syndbb.re.findall(image_finder2, thread.content,
                                        syndbb.re.IGNORECASE)
            if images:
                firstimg = images[0]
                hashname = hashlib.sha256(firstimg.encode()).hexdigest()
                thumbpath = thumbfolder + hashname + ".png"
                if not syndbb.os.path.isfile(thumbpath):
                    threadimg = requests.get(firstimg, verify=False, timeout=5)
                    im = Image.open(BytesIO(threadimg.content))
                    im = ImageOps.fit(im, (150, 150), Image.ANTIALIAS)
                    im.save(thumbpath, "PNG")
                timg = cdn_path() + "/data/threadimg/grid/" + hashname + ".png"
            elif images2:
                images = images2
                firstimg = images[0]
                hashname = hashlib.sha256(firstimg.encode()).hexdigest()
                thumbpath = thumbfolder + hashname + ".png"
                if not syndbb.os.path.isfile(thumbpath):
                    threadimg = requests.get(firstimg, verify=False, timeout=5)
                    im = Image.open(BytesIO(threadimg.content))
                    im = ImageOps.fit(im, (150, 150), Image.ANTIALIAS)
                    im.save(thumbpath, "PNG")
                timg = cdn_path() + "/data/threadimg/grid/" + hashname + ".png"
            else:
                timg = cdn_path() + "/images/noimage-grid.png"

            thread_list += '''<div class="panel panel-default text-center thread-grid" id="''' + str(
                thread.id
            ) + '''" onclick="location.href='/''' + forumcheck.short_name + '''/''' + str(
                thread.id
            ) + '''';" style="cursor: pointer;">
                                  <div class="panel-body">
                                	<div class="threadimg-grid center-block">
                                	  <a href="/''' + forumcheck.short_name + '''/''' + str(
                thread.id
            ) + '''/gallery">
                                		<img src="''' + timg + '''" title="''' + thread.title + '''" alt="Thread Image" class="activity-threadimg-grid">
                                	  </a>
                                	</div>
                                	<a href="/''' + forumcheck.short_name + '''/''' + str(
                thread.id
            ) + '''" title="''' + thread.title + '''"><b>''' + thread_title + '''</b></a><br/>
                                	<a href="/''' + forumcheck.short_name + '''/''' + str(
                thread.id
            ) + '''#''' + str(
                latest
            ) + '''" class="activity_lastpost"><i>last active ''' + recent_date(
                thread.reply_time) + '''&nbsp;</i></a>
                                  </div>
                              </div> '''

        return syndbb.render_template('view_forum.html',
                                      forum=forumcheck,
                                      gridview=gridview,
                                      thread_list=thread_list,
                                      forumlogo=forumlogo,
                                      title=forumcheck.name,
                                      topbuttons=topbuttons,
                                      subheading=subheading)
    else:
        return syndbb.render_template('invalid.html', title="No page found")
Пример #7
0
def view_channel(category):
    channelcheck = get_channel_data(category)
    channellogo = ""
    sidebar_extras = ""
    dynamic_js_footer = []
    dynamic_css_header = []
    if channelcheck:
        if not check_channel_auth(channelcheck): return syndbb.render_template('error_insufficient_permissions.html', title="Insufficient permission")
        dynamic_js_footer = ["js/inline.js", "js/bootbox.min.js"]
#        if channelcheck.short_name == "oify":
#            dynamic_css_header.append("css/oify.css")
        if (channelcheck.nsfw) and ('nsfwAllow' not in syndbb.request.cookies):
            dynamic_js_footer.append("js/nsfwprompt.js")
            dynamic_css_header.append("css/nsfw_fill.css")

        logo_file = syndbb.app.static_folder + "/images/logos/" + channelcheck.short_name + ".png"
        if syndbb.os.path.isfile(logo_file):
            channellogo = '<img src="'+cdn_path()+'/images/logos/' + channelcheck.short_name + '.png" alt="D2K5" class="sitelogo mask">'

        threads = get_thread_list(channelcheck.id)

        topbuttons = '<a href="/'+channelcheck.short_name+'/grid" title="Grid View" style="float:right;"><i class="silk-icon icon_application_view_tile" aria-hidden="true"></i></a>'
        if channelcheck.chat_url: topbuttons += '<a href="'+channelcheck.chat_url+'" title="Join Chat" style="float:right;"><i class="silk-icon icon_comments" aria-hidden="true"></i></a>'
        if 'logged_in' in syndbb.session:
            userid = check_session_by_id(str(syndbb.session['logged_in']))
            if userid:
                topbuttons += '<a href="/'+channelcheck.short_name+'/new_thread" title="New Thread" style="float:right;"><i class="silk-icon icon_add" aria-hidden="true"></i></a>'

        subheading = []
        subheading.append("")
        thread_list = ""
        for thread in threads:
            if thread.reply_count == 1:
                replystr = "reply"
            else:
                replystr = "replies"
            if thread.anonymous == 0:
                threadcreator = '<a href="/user/'+get_username_by_id(thread.user_id)+'" class="profile-inline">'+get_displayed_name_by_id(thread.user_id)+'</a>'
                latestreplier = '<a href="/user/'+get_username_by_id(thread.user_id)+'" class="profile-inline">'+get_displayed_name_by_id(thread.user_id)+'</a>'
            else:
                threadcreator = '<a href="#">Anonymous</a>'
                latestreplier = '<a href="#">Anonymous</a>'

            lastpost = d2_activity.query.filter_by(replyto=thread.id).order_by(d2_activity.time.desc()).first()
            if lastpost:
                latest = lastpost.id
                latestreplier = lastpost
                if lastpost.anonymous == 0 and lastpost.user_id:
                    latestreplier = '<a href="/user/'+get_username_by_id(lastpost.user_id)+'" class="profile-inline">'+get_displayed_name_by_id(lastpost.user_id)+'</a>'
                else:
                    latestreplier = '<a href="#">Anonymous</a>'
            else:
                latest = thread.id


            thread_list += '''<tr>
                                    <td class="home-channel home-channel-icon"><img src="'''+cdn_path()+'''/images/posticons/'''+str(thread.post_icon)+'''.png" alt=""/></td>
                                    <td class="home-channel">
                                    <span class="small" style="float:right; text-align: right;">
                                        <span class="timedisplay">'''+recent_date(thread.reply_time)+'''</span><br/>
                                        by '''+latestreplier+'''</a> <a href="/'''+str(channelcheck.short_name)+'''/'''+str(thread.id)+'''#'''+str(latest)+'''"><img src="'''+cdn_path()+'''/icons/thread_new.png" style="margin-top: -2px;"/></a>
                                    </span>
                                    <a href="/'''+str(channelcheck.short_name)+'''/'''+str(thread.id)+'''"><b>'''+thread.title+'''</b></a>
                                    <span class="small"><br/>
                                    '''+threadcreator+''', <span class="timedisplay">'''+recent_date(thread.time)+'''</span>
                                    </span>
                                    </td>
                                </tr>'''

        sidebar_extras = "<center><h4>"+channelcheck.name+"</h4></center>"
        sidebar_extras += '''<dl class="dl-horizontal statistics" style="margin-top: 10px; margin-bottom: 10px;">'''
        if channelcheck.description and channelcheck.description != "":
            sidebar_extras += '''<dt>Description:</dt>
            <dd>'''+ str(channelcheck.description) +'''</dd>'''
        if channelcheck.mod_list and channelcheck.mod_list != "":
            moderator_list_txt = ""
            for mod in channelcheck.mod_list.split(" "):
                if get_displayed_name_by_username(mod):
                    moderator_list_txt += '<a href="/user/'+mod+'" class="username '+get_group_style_by_username(mod)+'">'+get_displayed_name_by_username(mod)+'</a><br/>' 
            sidebar_extras += '''<dt>Moderators:</dt>
            <dd>'''+ moderator_list_txt +'''</dd>'''
        if channelcheck.user_list and channelcheck.user_list != "":
            usr_list_txt = ""
            for usr in channelcheck.user_list.split(" "):
                if get_displayed_name_by_username(usr):
                    usr_list_txt += '<a href="/user/'+usr+'" class="username '+get_group_style_by_username(usr)+'">'+get_displayed_name_by_username(usr)+'</a><br/>' 
            sidebar_extras += '''<dt>Members:</dt>
            <dd>'''+ usr_list_txt +'''</dd>'''
        sidebar_extras += '''</dl>'''
        return syndbb.render_template('view_channel.html', channel=channelcheck, thread_list=thread_list, channellogo=channellogo, dynamic_js_footer=dynamic_js_footer, dynamic_css_header=dynamic_css_header, title=channelcheck.name, topbuttons=topbuttons, subheading=subheading, sidebar_extras=sidebar_extras)
    else:
        return syndbb.render_template('invalid.html', title="No page found")
Пример #8
0
def view_channel_grid(category):
    channelcheck = get_channel_data(category)
    channellogo = ""
    sidebar_extras = ""
    dynamic_js_footer = []
    dynamic_css_header = []
    if channelcheck:
        if not check_channel_auth(channelcheck): return syndbb.render_template('error_insufficient_permissions.html', title="Insufficient permission")
#        if channelcheck.short_name == "oify":
#            dynamic_css_header.append("css/oify.css")
        if (channelcheck.nsfw) and ('nsfwAllow' not in syndbb.request.cookies):
            dynamic_js_footer.append("js/nsfwprompt.js")
            dynamic_css_header.append("css/nsfw_fill.css")

        logo_file = syndbb.app.static_folder + "/images/logos/" + channelcheck.short_name + ".png"
        if syndbb.os.path.isfile(logo_file):
            channellogo = '<img src="'+cdn_path()+'/images/logos/' + channelcheck.short_name + '.png" alt="D2K5" class="sitelogo mask">'

        threads = get_thread_list(channelcheck.id)

        topbuttons = '<a href="/'+channelcheck.short_name+'" title="List View" style="float:right;"><i class="silk-icon icon_application_view_list" aria-hidden="true"></i></a>'
        if channelcheck.chat_url: topbuttons += '<a href="'+channelcheck.chat_url+'" title="Join Chat" style="float:right;"><i class="silk-icon icon_comments" aria-hidden="true"></i></a>'
        if 'logged_in' in syndbb.session:
            userid = check_session_by_id(str(syndbb.session['logged_in']))
            if userid:
                topbuttons += '<a href="/'+channelcheck.short_name+'/new_thread" title="New Thread" style="float:right;"><i class="silk-icon icon_add" aria-hidden="true"></i></a>'

        subheading = []
        subheading.append("")
        thread_list = ""
        gridview = 1
        for thread in threads:
            if thread.reply_count == 1:
                replystr = "reply"
            else:
                replystr = "replies"
            thread_title = (thread.title[:25] + '...') if len(thread.title) > 25 else thread.title
            lastpost = d2_activity.query.filter_by(replyto=thread.id).order_by(d2_activity.time.desc()).first()
            if lastpost:
                latest = lastpost.id
            else:
                latest = thread.id

            timg = get_post_thumbnail(thread.id, method="crop", recheck=False)['src']

            thread_list += '''<div class="panel panel-default text-center thread-grid" id="''' + str(thread.id)+ '''" onclick="location.href='/''' + channelcheck.short_name+ '''/''' + str(thread.id)+ '''';" style="cursor: pointer;">
                                  <div class="panel-body">
                                	<div class="threadimg-grid center-block">
                                	  <a href="/''' + channelcheck.short_name+ '''/''' + str(thread.id)+ '''/gallery">
                                		<img src="'''+ timg +'''" title="''' + thread.title + '''" alt="Thread Image" class="activity-threadimg-grid">
                                	  </a>
                                	</div>
                                	<a href="/''' + channelcheck.short_name+ '''/''' + str(thread.id)+ '''" title="''' + thread.title + '''"><b>''' + thread_title + '''</b></a><br/>
                                	<a href="/''' + channelcheck.short_name+ '''/''' + str(thread.id)+ '''#'''+str(latest)+'''" class="activity_lastpost"><i>last active ''' + recent_date(thread.reply_time) + '''&nbsp;</i></a>
                                  </div>
                              </div> '''
        sidebar_extras = "<center><h4>"+channelcheck.name+"</h4></center>"
        sidebar_extras += '''<dl class="dl-horizontal statistics" style="margin-top: 10px; margin-bottom: 10px;">'''
        if channelcheck.description and channelcheck.description != "":
            sidebar_extras += '''<dt>Description:</dt>
            <dd>'''+ channelcheck.description +'''</dd>'''
        if channelcheck.mod_list and channelcheck.mod_list != "":
            moderator_list = []
            moderator_list_txt = ""
            for mod in channelcheck.mod_list.split(" "):
                if get_displayed_name_by_username(mod):
                    moderator_list_txt += '<a href="/user/'+mod+'" class="username '+get_group_style_by_username(mod)+'">'+get_displayed_name_by_username(mod)+'</a><br/>' 
            sidebar_extras += '''<dt>Moderators:</dt>
            <dd>'''+ moderator_list_txt +'''</dd>'''
        sidebar_extras += '''</dl>'''
        return syndbb.render_template('view_channel.html', channel=channelcheck, gridview=gridview, thread_list=thread_list, channellogo=channellogo, title=channelcheck.name, topbuttons=topbuttons, subheading=subheading, sidebar_extras=sidebar_extras)
    else:
        return syndbb.render_template('invalid.html', title="No page found")