예제 #1
0
파일: users.py 프로젝트: eiritana/SynDBB
def get_avatar(user_id):
    default_avatar = '/images/default_avatar.png'
    root_path = syndbb.app.static_folder
    user = d2_user.query.filter_by(user_id=user_id).first()
    if user.user_id:
        avatar_path = '/data/avatars/{}.png'.format(user.user_id)
        if syndbb.os.path.isfile(root_path + avatar_path):
            return cdn_path() + avatar_path + "?v=" + str(user.avatar_date)
        else:
            return cdn_path() + default_avatar
    else:
        return default_avatar
예제 #2
0
파일: profile.py 프로젝트: eiritana/SynDBB
def view_avatar_source(username):
    davatar = cdn_path() + '/images/default_avatar.png'
    if username:
        user = d2_user.query.filter_by(username=username).first()
        if user:
            dynamic_js_footer = ["js/jquery.cropit.js", "js/bootbox.min.js", "js/delete.js"]
            avatar_path = syndbb.app.static_folder + "/data/avatars/"+str(user.user_id)+"-src.png"
            uavatar = cdn_path() + "/data/avatars/"+str(user.user_id)+"-src.png?v="+str(user.avatar_date)
            if syndbb.os.path.isfile(avatar_path):
                return syndbb.redirect(uavatar)
            else:
                return syndbb.redirect(davatar)
        else:
            return syndbb.redirect(davatar)
예제 #3
0
파일: users.py 프로젝트: eiritana/SynDBB
def get_avatar_source(user_id):
    root_path = syndbb.app.static_folder
    user = d2_user.query.filter_by(user_id=user_id).first()
    if user.user_id:
        avatar_path = '/data/avatars/{}-src.png'.format(user.user_id)
        if syndbb.os.path.isfile(root_path + avatar_path):
            return cdn_path() + avatar_path + "?v=" + str(user.avatar_date)
        else:
            return ""
    else:
        return ""
예제 #4
0
def view_thread(category, thread):
    forumcheck = d2_forums.query.filter_by(short_name=category).first()
    forumlogo = ""
    if forumcheck:
        if ('logged_in' in syndbb.session and checkSession(
                str(syndbb.session['logged_in']))) or not forumcheck.auth:
            topbuttons = '<a href="/' + forumcheck.short_name + '/' + thread + '/gallery" title="Gallery View" style="float:right;"><i class="silk-icon icon_application_view_tile" aria-hidden="true"></i></a>'
            dynamic_css_header = ["css/bbcode_editor.css"]
            dynamic_js_footer = [
                "js/bootstrap-filestyle.min.js", "js/jquery.rangyinputs.js",
                "js/bbcode_editor_forums.js", "js/posts.js",
                "js/post_ratings.js", "js/bootbox.min.js", "js/delete.js",
                "js/inline.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">'
            threadcheck = d2_activity.query.filter_by(id=thread).first()
            if threadcheck:
                subheading = []
                subheading.append('<a href="/' + forumcheck.short_name + '">' +
                                  forumcheck.name + '</a>')
                thread_title = (threadcheck.title[:75] + '...') if len(
                    threadcheck.title) > 75 else threadcheck.title
                replycheck = d2_activity.query.filter_by(replyto=thread).all()
                return syndbb.render_template(
                    'view_thread.html',
                    forum=forumcheck,
                    replies=replycheck,
                    thread=threadcheck,
                    forumlogo=forumlogo,
                    dynamic_css_header=dynamic_css_header,
                    dynamic_js_footer=dynamic_js_footer,
                    title="#" + forumcheck.short_name + " &bull; " +
                    thread_title + " &bull; " + forumcheck.name,
                    forumtitle=thread_title,
                    topbuttons=topbuttons,
                    subheading=subheading)
            else:
                return syndbb.render_template('invalid.html',
                                              title="No thread found")
        else:
            return syndbb.render_template('error_not_logged_in.html',
                                          title="Not logged in")
    else:
        return syndbb.render_template('invalid.html', title="No page found")
예제 #5
0
파일: channels.py 프로젝트: researcx/SynDBB
def get_post_thumbnail(id, method="crop", recheck=False):
    timg = cdn_path() + "/images/noimage-grid.png"
    link = timg
    thumbfolder = syndbb.app.static_folder + "/data/threadimg/grid/"
    post = d2_activity.query.filter_by(id=id).first()
    if post:
        hashname = str(post.id)+"-"+method
        thumbpath = thumbfolder + hashname + ".png"  

        lists = ["(?<=\[img\]).*?(?=\[/img\])", "(?<=\[t\]).*?(?=\[/t\])", "(?<=\[ct\]).*?(?=\[/ct\])"]            
        for type in lists:
            images = syndbb.re.findall(type, post.content, syndbb.re.IGNORECASE)
            if images:
                    if method == "imageboard-thumb":
                        timg = syndbb.os.path.splitext(images[0])[0]+"s.jpg"
                        link = images[0]
                        return {'src': timg, 'href': link}
                    if method == "imageboard-source":
                        link = images[0]
                        return {'src': link, 'href': link}
                    if syndbb.os.path.isfile(thumbpath):
                        timg = cdn_path() + "/data/threadimg/grid/" + hashname + ".png"
                        link = images[0]
                        return {'src': timg, 'href': link}
                    if not syndbb.os.path.isfile(thumbpath):
                        threadimg = requests.get(images[0], verify=False, timeout=5)
                        try:
                            im = Image.open(BytesIO(threadimg.content))
                            if method == "crop":
                                im = ImageOps.fit(im, (150, 150),  Image.ANTIALIAS)
                            elif method == "resize":
                                im.thumbnail((195, 195), Image.ANTIALIAS)
                            im.save(thumbpath, "PNG")
                        except:
                            pass
                        timg = cdn_path() + "/data/threadimg/grid/" + hashname + ".png"
                        link = images[0]
                        return {'src': timg, 'href': link}

    return {'src': timg, 'href': link}
예제 #6
0
파일: upload.py 프로젝트: researcx/SynDBB
def upload_file_external():
    if syndbb.request.method == 'POST':
        image_types = [".jpg", ".jpeg", ".jpe"]
        username = syndbb.request.form['username']
        if 'auth' in syndbb.request.form:
            password = syndbb.request.form['auth']
        elif 'password' in syndbb.request.form:
            password = syndbb.request.form['password']
        else:
            return "No password set."
        user = d2_user.query.filter_by(username=username).filter_by(
            upload_auth=password).first()
        if user:
            #            ban_check = check_ban_by_id(user.user_id)
            #            if ban_check:
            #                return "This user or IP address is banned."
            uploadfolder = syndbb.app.static_folder + "/data/uploads/" + user.username + "/"
            if not syndbb.os.path.exists(uploadfolder):
                syndbb.os.makedirs(uploadfolder)
            if 'file' not in syndbb.request.files:
                return "No file selected."
            file = syndbb.request.files['file']
            if file.filename == '':
                return "No file selected."
            if file:
                filename = secure_filename(file.filename)
                extension = syndbb.os.path.splitext(filename)[1]
                newname = ''.join(
                    random.sample(
                        "-_" + string.ascii_uppercase + string.ascii_lowercase
                        + string.digits, 20)) + extension
                file.save(syndbb.os.path.join(uploadfolder, newname))
                if extension in image_types:
                    piexif.remove(uploadfolder + newname)

                uploadurl = user.upload_url
                if uploadurl == "local":
                    uploadurl = cdn_path(
                    ) + "/data/uploads/" + user.username + "/" + newname
                else:
                    uploadurl = "https://" + uploadurl + "/" + user.username + "/" + newname
                syndbb.cache.delete_memoized(
                    syndbb.views.upload.get_user_files)

                return uploadurl
        else:
            return "Invalid details or not logged in."
    else:
        return "Invalid request, must be POST."
예제 #7
0
파일: channels.py 프로젝트: researcx/SynDBB
def parse_bbcode(text):
    # Do the bbcode parsing
    if not text: return "NO TEXT"
    text = syndbb.models.bbcode.parser.format(text)
    # Get @usernames and turn them into links
    postname = syndbb.re.findall('(@\w+)', text, syndbb.re.IGNORECASE)
    for user in postname:
        highlighted_user = user[1:]
        d2user = d2_user.query.filter_by(username=highlighted_user).first()
        if d2user:
            user_link = '<a href="/user/'+d2user.username+'" class="username '+get_group_style_by_id(d2user.user_id)+' link-postname profile-inline">'+d2user.username+'</a>'
            text = syndbb.re.sub(user, user_link, text)
    # Add in emotes
    for k, v in get_emote():
        text = text.replace(v, '<img src="'+cdn_path()+'/images/emots/'+k+'" alt="'+k+'" title="'+v+'" class="emoticon" />')
    return text
예제 #8
0
def view_forum_create(category):
    forumcheck = d2_forums.query.filter_by(short_name=category).first()
    forumlogo = ""
    if 'logged_in' in syndbb.session:
        userid = checkSession(str(syndbb.session['logged_in']))
        if userid:
            if forumcheck:
                dynamic_css_header = [
                    "css/bbcode_editor.css", "css/dropdown.css"
                ]
                dynamic_js_footer = [
                    "js/jquery.dd.min.js", "js/jquery.rangyinputs.js",
                    "js/bbcode_editor_forums.js", "js/threads.js",
                    "js/inline.js", "js/bootbox.min.js"
                ]
                #                if forumcheck.short_name == "yiff":
                #                    dynamic_css_header.append("css/oify.css")

                subheading = []
                subheading.append('<a href="/' + forumcheck.short_name + '">' +
                                  forumcheck.name + '</a>')

                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">'

                return syndbb.render_template(
                    'new_thread.html',
                    forum=forumcheck,
                    forumlogo=forumlogo,
                    dynamic_css_header=dynamic_css_header,
                    dynamic_js_footer=dynamic_js_footer,
                    title="New Thread",
                    subheading=subheading)
            else:
                return syndbb.render_template('invalid.html',
                                              title="No page found")
        else:
            return syndbb.render_template('error_not_logged_in.html',
                                          title="Not logged in")
    else:
        return syndbb.render_template('error_not_logged_in.html',
                                      title="Not logged in")
예제 #9
0
파일: channels.py 프로젝트: researcx/SynDBB
def view_thread_gallery(category, thread):
    channelcheck = get_channel_data(category)
    channellogo = ""
    if channelcheck:
        if not check_channel_auth(channelcheck): return syndbb.render_template('error_insufficient_permissions.html', title="Insufficient permission")
        topbuttons = '<a href="/'+channelcheck.short_name+'/'+thread+'" title="List View" style="float:right;"><i class="silk-icon icon_application_view_list" aria-hidden="true"></i></a>'
        dynamic_css_header = ["css/bbcode_editor.css"]
        dynamic_js_footer = ["js/jquery.rangyinputs.js", "js/bbcode_editor_channels.js", "js/posts.js", "js/bootbox.min.js", "js/delete.js", "js/inline.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">'
        threadcheck = get_thread_contents(thread)
        image_list = []
        if threadcheck:
            lists = ["(?<=\[img\]).*?(?=\[/img\])", "(?<=\[t\]).*?(?=\[/t\])", "(?<=\[ct\]).*?(?=\[/ct\])"]            
            for type in lists:
                images = syndbb.re.findall(type, threadcheck.content, syndbb.re.IGNORECASE)
                thread_title = (threadcheck.title[:75] + '...') if len(threadcheck.title) > 75 else threadcheck.title
                for image in images:
                    image_list.append(image)
                replycheck = d2_activity.query.filter_by(replyto=thread).all()
                for reply in replycheck:
                    images = syndbb.re.findall(type, reply.content, syndbb.re.IGNORECASE)
                    for image in images:
                        image_list.append(image)

                imagecount = str(len(image_list)) + " images"
                if len(image_list) == 1:
                    imagecount = imagecount.rstrip('s')

            subheading = []
            subheading.append('<a href="/'+channelcheck.short_name+'">'+channelcheck.name+'</a>')

            return syndbb.render_template('view_thread_gallery.html', channel=channelcheck, thread=threadcheck, channellogo=channellogo, images=image_list, imagecount=imagecount, title="#"+channelcheck.short_name + " &bull; " + thread_title + " &bull; " + channelcheck.name, channeltitle=thread_title, topbuttons=topbuttons, subheading=subheading)
        else:
            return syndbb.render_template('invalid.html', title="No thread found")
    else:
        return syndbb.render_template('invalid.html', title="No page found")
예제 #10
0
파일: channels.py 프로젝트: researcx/SynDBB
def view_channel_create(category):
    sidebar_extras = ""
    channelcheck = get_channel_data(category)
    channellogo = ""
    if 'logged_in' in syndbb.session:
        userid = check_session_by_id(str(syndbb.session['logged_in']))
        if userid:
            if channelcheck:
                if not check_channel_auth(channelcheck): return syndbb.render_template('error_insufficient_permissions.html', title="Insufficient permission")
                dynamic_css_header = ["css/bbcode_editor.css", "css/dropdown.css"]
                dynamic_js_footer = ["js/jquery.dd.min.js", "js/jquery.rangyinputs.js", "js/bbcode_editor_channels.js", "js/threads.js", "js/inline.js", "js/bootbox.min.js"]
#                if channelcheck.short_name == "oify":
#                    dynamic_css_header.append("css/oify.css")

                subheading = []
                subheading.append('<a href="/'+channelcheck.short_name+'">'+channelcheck.name+'</a>')

                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">'

                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('new_thread.html', channel=channelcheck, channellogo=channellogo, dynamic_css_header=dynamic_css_header, dynamic_js_footer=dynamic_js_footer, title="New Thread", subheading=subheading, sidebar_extras=sidebar_extras)
            else:
                return syndbb.render_template('invalid.html', title="No page found")
        else:
            return syndbb.render_template('error_not_logged_in.html', title="Not logged in")
    else:
        return syndbb.render_template('error_not_logged_in.html', title="Not logged in")
예제 #11
0
파일: upload.py 프로젝트: researcx/SynDBB
def upload_album():
    uname = syndbb.request.args.get('u', '')
    file_list = syndbb.request.args.get('i', '').split(";")
    image_types = [".jpg", ".jpeg", ".jpe", ".gif", ".png", ".bmp"]
    dynamic_js_footer = [
        "js/bootbox.min.js", "js/delete.js", "js/lazyload.transpiled.min.js"
    ]

    if uname and file_list:
        user = d2_user.query.filter_by(username=uname).first()
        if user:
            uploadurl = user.upload_url
            if uploadurl == "local":
                uploadurl = cdn_path() + "/data/uploads/" + user.username + "/"
            else:
                uploadurl = "https://" + uploadurl + "/" + user.username + "/"

            images = []
            for image in file_list:
                extension = syndbb.os.path.splitext(image)[1].lower()
                if extension in image_types:
                    images.append(image)

            return syndbb.render_template('upload_album.html',
                                          filecount=len(images),
                                          uploadurl=uploadurl,
                                          file_list=images,
                                          dynamic_js_footer=dynamic_js_footer,
                                          title=user.username +
                                          " &bull; Album",
                                          subheading=[""])
        else:
            return syndbb.render_template('invalid.html',
                                          title="Upload &bull; Gallery",
                                          subheading=[""])
    else:
        return syndbb.render_template('invalid.html',
                                      title="Upload &bull; Gallery",
                                      subheading=[""])
예제 #12
0
파일: channels.py 프로젝트: researcx/SynDBB
def view_thread(category, thread):
    channelcheck = get_channel_data(category)
    sidebar_extras = ""
    channellogo = ""
    if channelcheck:
        if not check_channel_auth(channelcheck): return syndbb.render_template('error_insufficient_permissions.html', title="Insufficient permission")
        topbuttons = '<a href="/'+channelcheck.short_name+'/'+thread+'/gallery" title="Gallery View" style="float:right;"><i class="silk-icon icon_application_view_tile" aria-hidden="true"></i></a>'
        dynamic_css_header = ["css/bbcode_editor.css"]
        dynamic_js_footer = ["js/bootstrap-filestyle.min.js", "js/jquery.rangyinputs.js", "js/bbcode_editor_channels.js", "js/posts.js", "js/post_ratings.js", "js/bootbox.min.js", "js/delete.js", "js/inline.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">'
        threadcheck = get_thread_contents(thread)
        if threadcheck:
            subheading = []
            subheading.append('<a href="/'+channelcheck.short_name+'">'+channelcheck.name+'</a>')
            thread_title = (threadcheck.title[:75] + '...') if len(threadcheck.title) > 75 else threadcheck.title
            replycheck = d2_activity.query.filter_by(replyto=thread).all()

            participants_txt = ""
            participant_list = []
            if not threadcheck.anonymous:
                participant_list.append(get_username_by_id(threadcheck.user_id))
            for reply in replycheck:
                if not reply.anonymous:
                    participant_list.append(get_username_by_id(reply.user_id))
            for participant in list(dict.fromkeys(participant_list)):
                if get_displayed_name_by_username(participant):
                    participants_txt += '<a href="/user/'+participant+'" class="username '+get_group_style_by_username(participant)+'">'+get_displayed_name_by_username(participant)+'</a><br/>' 

            sidebar_extras = "<center><h4 style='padding-left: 8px; padding-right: 8px;'>"+thread_title+"</h4></center>"
            sidebar_extras += '''<dl class="dl-horizontal statistics" style="margin-top: 10px; margin-bottom: 10px;">'''
            if participants_txt:
                sidebar_extras += '''<dt>Participants:</dt>
                <dd>'''+ participants_txt +'''</dd>'''
            sidebar_extras += '''</dl>'''
            sidebar_extras += '''<dl class="dl-horizontal statistics" style="margin-top: 10px; margin-bottom: 10px;">'''
            sidebar_extras += '''<dt>Channel:</dt>
            <dd>'''+ channelcheck.name +'''</dd>'''
            if 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>'''
            if channelcheck.type == 0:
                template = "view_thread.html"
            if channelcheck.type == 1:
                template = "view_thread_imageboard.html"
            return syndbb.render_template(template, channel=channelcheck, replies=replycheck, thread=threadcheck, channellogo=channellogo, dynamic_css_header=dynamic_css_header, dynamic_js_footer=dynamic_js_footer, title="#"+channelcheck.short_name + " &bull; " + thread_title + " &bull; " + channelcheck.name, channeltitle=thread_title, topbuttons=topbuttons, subheading=subheading, sidebar_extras=sidebar_extras)
        else:
            return syndbb.render_template('invalid.html', title="No thread found")
    else:
        return syndbb.render_template('invalid.html', title="No page found")
예제 #13
0
파일: channels.py 프로젝트: researcx/SynDBB
def get_channel_list(type):
    channels = []
    chlist = ""
    if type == 0:
        channel_list = d2_channels.query.filter_by(owned_by=0,nsfw=0,approved=1).all()
    elif type == 1:
        channel_list = d2_channels.query.filter(d2_channels.nsfw != 0).filter(d2_channels.approved != 0).all()
    elif type == 2:
        channel_list = d2_channels.query.filter(d2_channels.owned_by != 0).filter(d2_channels.approved != 0).all()
        
    for channel in channel_list:
        threadcount = 0
        messagecount = 0
        channel_icon = '/images/channelicons/{}.png'.format(channel.short_name)
        channel_icon_default = '/images/channelicons/blank.png'
        root_path = syndbb.app.static_folder
        if syndbb.os.path.isfile(root_path+channel_icon):
            channel_icon = cdn_path() + channel_icon
        else:
            channel_icon = cdn_path() + channel_icon_default
        threadcount = d2_activity.query.filter(d2_activity.category == channel.id).count()
        threadlist = d2_activity.query.filter(d2_activity.category == channel.id).all()
        
        for thread in threadlist:
            messagecount += d2_activity.query.filter(d2_activity.replyto == thread.id).count()
            
        messagecount = threadcount + messagecount
            
        channels.append({"id": channel.id, "name": channel.name, "description": channel.description, "alias": channel.short_name, "anon": channel.anon, "auth": channel.auth, "owned_by": channel.owned_by, "nsfw": channel.nsfw, "alias": channel.short_name, "icon": channel_icon, "messages": messagecount, "chat_url": channel.chat_url})
    channels.sort(key=itemgetter('id'))

    for channel in channels:
        modes = ""
        
        if channel['auth'] >= 1:
            modes += '<i title="Authorization required. (>='+get_title_by_rank(channel['auth'])+')" class="fa fa-lock" aria-hidden="true"></i> '
        if channel['anon'] == 1:
            modes += ' <i title="Anonymous posting allowed." class="fa fa-eye-slash" aria-hidden="true"></i> '
        if channel['nsfw'] == 1:
            modes += '<i title="Not safe for work. (18+)" class="fa fa-ban" aria-hidden="true"></i>'

        options = ""

        # display message counts on channel listings
        if syndbb.core_config['site']['display_message_counts']:
            options += '''<td class="home-channel home-channel-threads" title="Messages" style="padding-right: 9px !important;">
                    <span style="float: right;">
                    ''' + str(channel['messages']) + '''
                    </span>
                </td>'''


        options += '<td class="home-channel small home-channel-options" style="padding-right: 9px !important;">'
        
        if 'chat_url' in channel and channel['chat_url']: options += '''
                    <a href="'''+channel['chat_url']+'''" title="Join Chat">
                        <i class="silk-icon icon_comment" aria-hidden="true"></i>
                    </a>'''

        options += '''
                    <a href="/''' + str(channel['alias']) + '''/grid" title="Grid/Catalog View">
                        <i class="silk-icon icon_application_view_tile" aria-hidden="true"></i>
                    </a>
                    
                    <a href="/''' + str(channel['alias']) + '''/new_thread" title="Create A New Thread">
                        <i class="silk-icon icon_add" aria-hidden="true"></i>
                    </a>'''

        options += '</td>'
        
        if 'description' in channel and channel['description'] != "":
            has_description = "home-channel-desc"
        else:
            has_description = "home-channel-nodesc"

        chlist += '''<tr>
            <td class="home-channel home-channel-icon"><a href="/''' + str(channel['alias']) + '''"><img src="'''+ str(channel['icon']) + '''" alt=""/></a></td>
            <td class="home-channel '''+ has_description +'''"><a href="/''' + str(channel['alias']) + '''"><b>''' + str(channel['name']) + '''</b></a>
            <br/><span class="small">''' + str(channel['description']) + '''</span>
            </td>
            <td class="home-channel home-channel-modes" style="padding-right: 9px !important;">
                <span style="float: right;">
                   <span class="text-muted">''' + modes + '''</span>
                </span>
            </td>
            
            ''' + options + '''
            
          </tr>'''
    return chlist
예제 #14
0
파일: channels.py 프로젝트: researcx/SynDBB
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")
예제 #15
0
def view_thread_gallery(category, thread):
    forumcheck = d2_forums.query.filter_by(short_name=category).first()
    forumlogo = ""
    if forumcheck:
        if ('logged_in' in syndbb.session and checkSession(
                str(syndbb.session['logged_in']))) or not forumcheck.auth:
            topbuttons = '<a href="/' + forumcheck.short_name + '/' + thread + '" title="List View" style="float:right;"><i class="silk-icon icon_application_view_list" aria-hidden="true"></i></a>'
            dynamic_css_header = ["css/bbcode_editor.css"]
            dynamic_js_footer = [
                "js/jquery.rangyinputs.js", "js/bbcode_editor_forums.js",
                "js/posts.js", "js/bootbox.min.js", "js/delete.js",
                "js/inline.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">'
            threadcheck = d2_activity.query.filter_by(id=thread).first()
            image_list = []
            image_finder = "(?<=\[img\]).*?(?=\[/img\])"
            image_finder2 = "(?<=\[t\]).*?(?=\[/t\])"
            if threadcheck:
                thread_title = (threadcheck.title[:75] + '...') if len(
                    threadcheck.title) > 75 else threadcheck.title
                images = syndbb.re.findall(image_finder, threadcheck.content,
                                           syndbb.re.IGNORECASE)
                for image in images:
                    image_list.append(image)
                images = syndbb.re.findall(image_finder2, threadcheck.content,
                                           syndbb.re.IGNORECASE)
                for image in images:
                    image_list.append(image)

                replycheck = d2_activity.query.filter_by(replyto=thread).all()
                for reply in replycheck:
                    images = syndbb.re.findall(image_finder, reply.content,
                                               syndbb.re.IGNORECASE)
                    for image in images:
                        image_list.append(image)
                    images = syndbb.re.findall(image_finder2, reply.content,
                                               syndbb.re.IGNORECASE)
                    for image in images:
                        image_list.append(image)

                imagecount = str(len(image_list)) + " images"
                if len(image_list) == 1:
                    imagecount = imagecount.rstrip('s')

                subheading = []
                subheading.append('<a href="/' + forumcheck.short_name + '">' +
                                  forumcheck.name + '</a>')

                return syndbb.render_template(
                    'view_thread_gallery.html',
                    forum=forumcheck,
                    thread=threadcheck,
                    forumlogo=forumlogo,
                    images=image_list,
                    imagecount=imagecount,
                    title="#" + forumcheck.short_name + " &bull; " +
                    thread_title + " &bull; " + forumcheck.name,
                    forumtitle=thread_title,
                    topbuttons=topbuttons,
                    subheading=subheading)
            else:
                return syndbb.render_template('invalid.html',
                                              title="No thread found")
        else:
            return syndbb.render_template('error_not_logged_in.html',
                                          title="Not logged in")
    else:
        return syndbb.render_template('invalid.html', title="No page found")
예제 #16
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")
예제 #17
0
파일: activity.py 프로젝트: eiritana/SynDBB
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
예제 #18
0
파일: forums.py 프로젝트: eiritana/SynDBB
def get_channel_list(official):
    channels = []
    chlist = ""
    if official:
        forum_list = d2_forums.query.filter_by(owned_by=0).all()
    else:
        forum_list = d2_forums.query.filter(d2_forums.owned_by != 0).all()

    for forum in forum_list:
        threadcount = 0
        messagecount = 0
        forum_icon = '/images/forumicons/{}.png'.format(forum.short_name)
        forum_icon_default = '/images/forumicons/blank.png'
        root_path = syndbb.app.static_folder
        if syndbb.os.path.isfile(root_path + forum_icon):
            forum_icon = cdn_path() + forum_icon
        else:
            forum_icon = cdn_path() + forum_icon_default
        threadcount = d2_activity.query.filter(
            d2_activity.category == forum.id).count()
        threadlist = d2_activity.query.filter(
            d2_activity.category == forum.id).all()

        for thread in threadlist:
            messagecount += d2_activity.query.filter(
                d2_activity.replyto == thread.id).count()

        messagecount = threadcount + messagecount

        channels.append({
            "id": forum.id,
            "name": forum.name,
            "description": forum.description,
            "alias": forum.short_name,
            "anon": forum.anon,
            "auth": forum.auth,
            "owned_by": forum.owned_by,
            "nsfw": forum.nsfw,
            "alias": forum.short_name,
            "icon": forum_icon,
            "messages": messagecount
        })
    channels.sort(key=itemgetter('id'))

    for forum in channels:
        modes = ""

        if forum['auth'] == 1:
            modes += '<i title="Authorization required." class="fa fa-lock" aria-hidden="true"></i> '
        if forum['anon'] == 1:
            modes += ' <i title="Anonymous posting allowed." class="fa fa-eye-slash" aria-hidden="true"></i> '
        if forum['nsfw'] == 1:
            modes += '<i title="Not safe for work. [18+]" class="fa fa-ban" aria-hidden="true"></i>'

        chlist += '''<tr>
            <td class="home-forum home-forum-icon"><a href="/''' + str(
            forum['alias']
        ) + '''"><img src="''' + str(forum['icon']) + '''" alt=""/></a></td>
            <td class="home-forum"><a href="/''' + str(
            forum['alias']) + '''"><b>''' + str(forum['name']) + '''</b></a>
            <br/><span class="small">''' + str(
                forum['description']) + '''</span>
            </td>
            <td class="home-forum home-forum-modes" style="padding-right: 9px !important;">
                <span style="float: right;">
                   <span class="text-muted">''' + modes + '''</span>
                </span>
            </td>
            
            <td class="home-forum home-forum-threads" title="Messages" style="padding-right: 9px !important;">
                <span style="float: right;">
                   ''' + str(forum['messages']) + '''
                </span>
            </td>

            <td class="home-forum small home-forum-options" style="padding-right: 9px !important;">
                <a href="/''' + str(
                    forum['alias']) + '''/grid" title="Grid/Catalog View">
                    <i class="silk-icon icon_application_view_tile" aria-hidden="true"></i>
                </a>
                <a href="/''' + str(
                        forum['alias']
                    ) + '''/new_thread" title="Create A New Thread">
                    <i class="silk-icon icon_add" aria-hidden="true"></i>
                </a>
            </td>
          </tr>'''
    return chlist
예제 #19
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")
예제 #20
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
예제 #21
0
파일: upload.py 프로젝트: researcx/SynDBB
def upload_viewer():
    dynamic_js_footer = [
        "js/bootstrap-filestyle.min.js", "js/bootbox.min.js", "js/delete.js",
        "js/lazyload.transpiled.min.js"
    ]
    ufile = syndbb.request.args.get('file', '')
    uploadfolder = syndbb.app.static_folder + "/data/uploads/"

    if ufile:
        image_types = [".jpg", ".jpeg", ".jpe", ".gif", ".png", ".bmp"]
        audio_types = [".mp3", ".ogg", ".wav"]
        video_types = [".webm", ".mp4", ".avi", ".mpg", ".mpeg"]
        text_types = [".txt", ".pdf", ".doc"]
        archive_types = [".zip", ".rar", ".7z", ".tar", ".gz"]

        uploadurl = cdn_path() + "/data/uploads/"

        uploaduser = ufile.split('/')[0]
        uploadfile = ufile.split('/')[1]

        user = d2_user.query.filter_by(username=uploaduser).first()

        if user:
            if 'logged_in' in syndbb.session:
                userid = check_session_by_id(str(syndbb.session['logged_in']))
                user = d2_user.query.filter_by(user_id=userid).first()

                uploadurl = user.upload_url
                if uploadurl == "local":
                    uploadurl = cdn_path() + "/data/uploads/"
                else:
                    uploadurl = "https://" + uploadurl + "/"
            else:
                uploadurl = cdn_path() + "/data/uploads/"
        else:
            uploadurl = cdn_path() + "/data/uploads/"

        file_list = []
        filepath = uploadfolder + "/" + ufile
        if syndbb.os.path.isfile(filepath):
            type_icon = ''
            filetime = int(syndbb.os.stat(filepath).st_mtime)
            filesize = syndbb.os.path.getsize(filepath)
            extension = syndbb.os.path.splitext(ufile)[1].lower()
            hashname = hashlib.sha256(ufile.encode()).hexdigest()
            if extension in image_types:
                type_icon = '<img src="' + uploadurl + ufile + '" alt="' + ufile + '" class="bbcode-image img-thumb"\>'
            elif extension in audio_types:
                type_icon = '<i class="fa fa-file-audio-o" aria-hidden="true"></i><div style="margin-top: -0.8em;"><audio controls><source src="' + uploadurl + ufile + '" type="audio/mpeg"></audio></div>'
            elif extension in video_types:
                type_icon = '<video width="720" height="480" controls><source src="' + uploadurl + ufile + '" type="video/mp4"></video>'
            elif extension in text_types:
                type_icon = '<i class="fa fa-file-text-o" aria-hidden="true"></i>'
            elif extension in archive_types:
                type_icon = '<i class="fa fa-file-archive-o" aria-hidden="true"></i>'
            else:
                type_icon = '<i class="fa fa-file-o" aria-hidden="true"></i>'

            file_list.append([filetime, filesize, ufile, type_icon])
        return syndbb.render_template('upload_viewer.html',
                                      uploadurl=uploadurl,
                                      file_list=file_list,
                                      dynamic_js_footer=dynamic_js_footer,
                                      title=ufile,
                                      subheading=["Upload"])
    else:
        return syndbb.render_template('upload_viewer.html',
                                      dynamic_js_footer=dynamic_js_footer,
                                      title="View File",
                                      subheading=["Upload"])
예제 #22
0
파일: upload.py 프로젝트: researcx/SynDBB
def upload_simple():
    if 'logged_in' in syndbb.session:
        userid = check_session_by_id(str(syndbb.session['logged_in']))
        if userid:
            dynamic_js_footer = [
                "js/bootstrap-filestyle.min.js", "js/bootbox.min.js",
                "js/delete.js", "js/lazyload.transpiled.min.js"
            ]
            user = d2_user.query.filter_by(user_id=userid).first()
            uploadfolder = syndbb.app.static_folder + "/data/uploads/" + user.username + "/"
            thumbfolder = syndbb.app.static_folder + "/data/uploads/.thumbnails/"
            ufile = syndbb.request.args.get('file', '')

            if not syndbb.os.path.exists(uploadfolder):
                syndbb.os.makedirs(uploadfolder)
            if not syndbb.os.path.exists(thumbfolder):
                syndbb.os.makedirs(thumbfolder)

            if ufile:
                image_types = [".jpg", ".jpeg", ".jpe", ".gif", ".png", ".bmp"]
                audio_types = [".mp3", ".ogg", ".wav"]
                video_types = [".webm", ".mp4", ".avi", ".mpg", ".mpeg"]
                text_types = [".txt", ".pdf", ".doc"]
                archive_types = [".zip", ".rar", ".7z", ".tar", ".gz"]

                uploadurl = user.upload_url
                if uploadurl == "local":
                    uploadurl = cdn_path() + "/data/uploads/"
                else:
                    uploadurl = "https://" + uploadurl + "/"

                file_list = []
                filepath = uploadfolder + "/" + ufile
                if syndbb.os.path.isfile(filepath):
                    filetime = int(syndbb.os.stat(filepath).st_mtime)
                    filesize = syndbb.os.path.getsize(filepath)
                    extension = syndbb.os.path.splitext(ufile)[1].lower()
                    hashname = hashlib.sha256(ufile.encode()).hexdigest()
                    if extension in image_types:
                        type_icon = '<img src="' + cdn_path(
                        ) + '/data/uploads/.thumbnails/' + hashname + '.png" alt="' + ufile + '" class="uploadimg"></a>'
                        thumbpath = thumbfolder + hashname + ".png"
                        if not syndbb.os.path.isfile(thumbpath):
                            im = Image.open(filepath)
                            im.thumbnail((150, 150))
                            im.save(thumbpath, "PNG")
                        file_list.append(
                            [filetime, filesize, ufile, type_icon])
                return syndbb.render_template(
                    'upload_simple.html',
                    uploadurl=uploadurl,
                    file_list=file_list,
                    dynamic_js_footer=dynamic_js_footer,
                    title="Upload",
                    subheading=[""])
            else:
                return syndbb.render_template(
                    'upload_simple.html',
                    dynamic_js_footer=dynamic_js_footer,
                    title="Upload",
                    subheading=[""])
        else:
            return syndbb.render_template('error_not_logged_in.html',
                                          title="Upload",
                                          subheading=[""])
    else:
        return syndbb.render_template('error_not_logged_in.html',
                                      title="Upload",
                                      subheading=[""])
예제 #23
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")
예제 #24
0
파일: profile.py 프로젝트: eiritana/SynDBB
def no_avatar():
    davatar = cdn_path() + '/images/default_avatar.png'
    return syndbb.redirect(davatar)
예제 #25
0
파일: upload.py 프로젝트: researcx/SynDBB
def get_user_files(userid, anon=0, gallery=0, album=0):
    user = d2_user.query.filter_by(user_id=userid).first()

    if anon:
        uname = d2_hash(user.username + user.password)[:10]
    else:
        uname = user.username

    uploadfolder = syndbb.app.static_folder + "/data/uploads/" + uname + "/"
    thumbfolder = syndbb.app.static_folder + "/data/uploads/.thumbnails/"

    if not syndbb.os.path.exists(uploadfolder):
        syndbb.os.makedirs(uploadfolder)
    if not syndbb.os.path.exists(thumbfolder):
        syndbb.os.makedirs(thumbfolder)

    image_types = [".jpg", ".jpeg", ".jpe", ".gif", ".png", ".bmp"]
    audio_types = [".mp3", ".ogg", ".wav"]
    video_types = [".webm", ".mp4", ".avi", ".mpg", ".mpeg"]
    text_types = [".txt", ".pdf", ".doc"]
    archive_types = [".zip", ".rar", ".7z", ".tar", ".gz"]

    total_size = sum(
        syndbb.os.path.getsize(uploadfolder + f)
        for f in syndbb.os.listdir(uploadfolder)
        if syndbb.os.path.isfile(uploadfolder + f))

    uploadurl = user.upload_url
    if uploadurl == "local":
        uploadurl = cdn_path() + "/data/uploads/"
    else:
        uploadurl = "https://" + uploadurl + "/"

    file_list = []
    for fn in syndbb.os.listdir(uploadfolder):
        filepath = uploadfolder + "/" + fn
        if syndbb.os.path.isfile(filepath):
            filetime = int(syndbb.os.stat(filepath).st_mtime)
            filesize = syndbb.os.path.getsize(filepath)
            extension = syndbb.os.path.splitext(fn)[1].lower()
            hashname = hashlib.sha256(fn.encode()).hexdigest()
            if extension in image_types:
                if anon:
                    type_icon = '<i class="silk-icon icon_picture" aria-hidden="true"></i>'
                else:
                    type_icon = '<img src="' + cdn_path(
                    ) + '/data/uploads/.thumbnails/' + hashname + '.png" alt="' + fn + '" class="uploadimg"></a>'
                    thumbpath = thumbfolder + hashname + ".png"
                    if not syndbb.os.path.isfile(thumbpath):
                        im = Image.open(filepath)
                        im.thumbnail((150, 150))
                        im.save(thumbpath, "PNG")
            elif extension in audio_types:
                type_icon = '<i class="fa fa-file-audio-o" aria-hidden="true"></i>'
            elif extension in video_types:
                type_icon = '<i class="ffa fa-file-video-o" aria-hidden="true"></i>'
            elif extension in text_types:
                type_icon = '<i class="fa fa-file-text-o" aria-hidden="true"></i>'
            elif extension in archive_types:
                type_icon = '<i class="fa fa-file-archive-o" aria-hidden="true"></i>'
            else:
                type_icon = '<i class="fa fa-file-o" aria-hidden="true"></i>'

            file_list.append([filetime, filesize, fn, type_icon])

    file_list.sort(reverse=True)

    return {
        'file_list': file_list,
        'uploadurl': uploadurl,
        'file_count': len(file_list),
        'total_size': total_size,
        'user_name': uname
    }
예제 #26
0
파일: upload.py 프로젝트: researcx/SynDBB
def upload_gallery():
    dynamic_js_footer = [
        "js/bootstrap-filestyle.min.js", "js/uploadgallery.js",
        "js/bootbox.min.js", "js/delete.js", "js/lazyload.transpiled.min.js"
    ]
    if 'logged_in' in syndbb.session:
        userid = check_session_by_id(str(syndbb.session['logged_in']))
        if userid:
            user = d2_user.query.filter_by(user_id=userid).first()
            uploadfolder = syndbb.app.static_folder + "/data/uploads/" + user.username + "/"
            thumbfolder = syndbb.app.static_folder + "/data/uploads/.thumbnails/"

            if not syndbb.os.path.exists(uploadfolder):
                syndbb.os.makedirs(uploadfolder)
            if not syndbb.os.path.exists(thumbfolder):
                syndbb.os.makedirs(thumbfolder)

            image_types = [".jpg", ".jpeg", ".jpe", ".gif", ".png", ".bmp"]
            total_size = sum(
                syndbb.os.path.getsize(uploadfolder + f)
                for f in syndbb.os.listdir(uploadfolder)
                if syndbb.os.path.isfile(uploadfolder + f)
                and syndbb.os.path.splitext(f)[1].lower() in image_types)

            uploadurl = user.upload_url
            if uploadurl == "local":
                uploadurl = str(cdn_path) + "/data/uploads/"
            else:
                uploadurl = "https://" + uploadurl + "/"

            file_list = []
            for fn in syndbb.os.listdir(uploadfolder):
                filepath = uploadfolder + "/" + fn
                if syndbb.os.path.isfile(filepath):
                    filetime = int(syndbb.os.stat(filepath).st_mtime)
                    filesize = syndbb.os.path.getsize(filepath)
                    extension = syndbb.os.path.splitext(fn)[1].lower()
                    hashname = hashlib.sha256(fn.encode()).hexdigest()
                    if extension in image_types:
                        type_icon = cdn_path(
                        ) + '/data/uploads/.thumbnails/' + hashname + '.png'
                        thumbpath = thumbfolder + hashname + ".png"
                        if not syndbb.os.path.isfile(thumbpath):
                            im = Image.open(filepath)
                            im.thumbnail((150, 150))
                            im.save(thumbpath, "PNG")
                        file_list.append([filetime, filesize, fn, type_icon])
            file_list.sort(reverse=True)

            return syndbb.render_template('upload_gallery.html',
                                          uploadurl=uploadurl,
                                          filecount=len(file_list),
                                          file_list=file_list,
                                          total_size=total_size,
                                          dynamic_js_footer=dynamic_js_footer,
                                          title="Upload &bull; Gallery",
                                          subheading=[""])
        else:
            return syndbb.render_template('error_not_logged_in.html',
                                          title="Upload &bull; Gallery",
                                          subheading=[""])
    else:
        return syndbb.render_template('error_not_logged_in.html',
                                      title="Upload &bull; Gallery",
                                      subheading=[""])
예제 #27
0
파일: channels.py 프로젝트: researcx/SynDBB
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")