vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4.x Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=245)
-   -   Show Thread Enhancements - Mark Threads Unread (vB4) (https://vborg.vbsupport.ru/showthread.php?t=302901)

nerbert 10-06-2013 11:28 PM

I fixed the problem with cookie based thread marking and now the link shows only for threads younger than the marking cut off limit.


Here's a quick paste in update.

For the "Build Form and Link" Plugin:

Code:

if($vbulletin->options['enable_mark_unread'])
{
        $template_hook['showthread_after_activeusers'] .= '
                <form name="unmark">
                        <input type="hidden" name="do" value="unmark" />
                        <input type="hidden" name="threadid" value="' . $threadinfo['threadid'] . '" />
                        <input type="hidden" name="forumid" value="' . $foruminfo['forumid'] . '" />
                        <input type="hidden" name="userid" value="' . $vbulletin->userinfo['userid'] . '" />
                        <input type="hidden" name="s" value="' . $session['sessionhash'] . '" />
                        <input type="hidden" name="securitytoken" value="' . $vbulletin->userinfo['securitytoken'] . '" />
                </form>
                <script>
                        function vB_AJAX_Mark_Unread(form) {
                                this.form = form;
                                this.lastPost = ' . $threadinfo['lastpost'] . ';
                                this.cutOff  = ' . (TIMENOW - ($vbulletin->options['markinglimit'] * 86400)) . ';
                        }
                        vB_AJAX_Mark_Unread.prototype.addLink = function() {
                                if(this.lastPost > this.cutOff) {
                                        var unmark = document.createElement("li");
                                        unmark.innerHTML = \'<a id="mark_unread"  href="javascript:markUnread.unmark();">' . $vbphrase['mark_unread'] . '</a>\';
                                        fetch_object("threadtools").getElementsByTagName("ul")[0].appendChild(unmark);
                                }
                        }
                        vB_AJAX_Mark_Unread.prototype.unmark = function() {
                                YAHOO.util.Connect.setForm(this.form);
                                YAHOO.util.Connect.asyncRequest("POST","showthread.php?do=unmark",{success:this.confirm,failure:this.confirm,timeout:vB_Default_Timeout,scope:this});
                        }
                        vB_AJAX_Mark_Unread.prototype.confirm = function(doc) {
                                fetch_object("mark_unread").parentNode.innerHTML = \'<a style="background:rgb(200,50,20);color:white;">' . $vbphrase['marked_unread'] .'</a>\';
                        }
                        markUnread = new vB_AJAX_Mark_Unread(document.forms.unmark);
                        window.onload = function() {
                                markUnread.addLink();
                        }
                </script>
        ';
}

For the "Delete Query" plugin:

Code:

if($vbulletin->options['enable_mark_unread'])
{
        if($_REQUEST['do'] == 'unmark')
        {

                $vbulletin->input->clean_array_gpc('r', array(
                        'threadid'        => TYPE_STR,
                        'forumid'        => TYPE_STR,
                        'userid'        => TYPE_STR
                ));
               
                $threadid = intval($vbulletin->GPC['threadid']);
                $forumid  = intval($vbulletin->GPC['forumid']);
                $userid  = intval($vbulletin->GPC['userid']);
               
                if ($vbulletin->options['threadmarking'])
                {
                       
                        $vbulletin->db->query_write("
                                DELETE FROM " . TABLE_PREFIX . "threadread
                                WHERE threadid = $threadid
                                AND  userid  = $userid;
                        ");
                       
                        $vbulletin->db->query_write("
                                DELETE FROM " . TABLE_PREFIX . "forumread
                                WHERE forumid  = $forumid
                                AND  userid  = $userid;       
                        ");
               
                        die('done');
                }
                else
                {
                        set_bbarray_cookie('thread_lastview', $threadid, 0);
                }
        }
}


djbaxter 10-07-2013 12:31 PM

Quote:

Originally Posted by nerbert (Post 2450556)
I fixed the problem with cookie based thread marking and now the link shows only for threads younger than the marking cut off limit.


Here's a quick paste in update.

For the "Build Form and Link" Plugin:

Code:

if($vbulletin->options['enable_mark_unread'])
{
        $template_hook['showthread_after_activeusers'] .= '
                <form name="unmark">
                        <input type="hidden" name="do" value="unmark" />
                        <input type="hidden" name="threadid" value="' . $threadinfo['threadid'] . '" />
                        <input type="hidden" name="forumid" value="' . $foruminfo['forumid'] . '" />
                        <input type="hidden" name="userid" value="' . $vbulletin->userinfo['userid'] . '" />
                        <input type="hidden" name="s" value="' . $session['sessionhash'] . '" />
                        <input type="hidden" name="securitytoken" value="' . $vbulletin->userinfo['securitytoken'] . '" />
                </form>
                <script>
                        function vB_AJAX_Mark_Unread(form) {
                                this.form = form;
                                this.lastPost = ' . $threadinfo['lastpost'] . ';
                                this.cutOff  = ' . TIMENOW - ($vbulletin->options['markinglimit'] * 86400) . ';
                        }
                        vB_AJAX_Mark_Unread.prototype.addLink = function() {
                                if(this.lastPost > this.cutOff) {
                                        var unmark = document.createElement("li");
                                        unmark.innerHTML = \'<a id="mark_unread"  href="javascript:markUnread.unmark();">' . $vbphrase['mark_unread'] . '</a>\';
                                        fetch_object("threadtools").getElementsByTagName("ul")[0].appendChild(unmark);
                                }
                        }
                        vB_AJAX_Mark_Unread.prototype.unmark = function() {
                                YAHOO.util.Connect.setForm(this.form);
                                YAHOO.util.Connect.asyncRequest("POST","showthread.php?do=unmark",{success:this.confirm,failure:this.confirm,timeout:vB_Default_Timeout,scope:this});
                        }
                        vB_AJAX_Mark_Unread.prototype.confirm = function(doc) {
                                fetch_object("mark_unread").parentNode.innerHTML = \'<a style="background:rgb(200,50,20);color:white;">' . $vbphrase['marked_unread'] .'</a>\';
                        }
                        markUnread = new vB_AJAX_Mark_Unread(document.forms.unmark);
                        window.onload = function() {
                                markUnread.addLink();
                        }
                </script>
        ';
}

For the "Delete Query" plugin:

Code:

if($vbulletin->options['enable_mark_unread'])
{
        if($_REQUEST['do'] == 'unmark')
        {

                $vbulletin->input->clean_array_gpc('r', array(
                        'threadid'        => TYPE_STR,
                        'forumid'        => TYPE_STR,
                        'userid'        => TYPE_STR
                ));
               
                $threadid = intval($vbulletin->GPC['threadid']);
                $forumid  = intval($vbulletin->GPC['forumid']);
                $userid  = intval($vbulletin->GPC['userid']);
               
                if ($vbulletin->options['threadmarking'])
                {
                       
                        $vbulletin->db->query_write("
                                DELETE FROM " . TABLE_PREFIX . "threadread
                                WHERE threadid = $threadid
                                AND  userid  = $userid;
                        ");
                       
                        $vbulletin->db->query_write("
                                DELETE FROM " . TABLE_PREFIX . "forumread
                                WHERE forumid  = $forumid
                                AND  userid  = $userid;       
                        ");
               
                        die('done');
                }
                else
                {
                        set_bbarray_cookie('thread_lastview', $threadid, 0);
                }
        }
}


Not working correctly. It now fails to show the Mark Unread option in threads that are well within the timeframe (using database marking).

Fortunately, I didn't overwrite my saved copy of the previous version which was better, IMO.

nerbert 10-07-2013 01:28 PM

Bug fixed. After I had tested it I tidied up the code and introduced a bug. The file is corrected and a the paste-in code in my earlier post is corrected. Sorry

tbworld 10-08-2013 01:11 AM

Really nice @Nerbert! :)

DF031 10-12-2013 08:19 AM

It seems there are no instructions on how to insdtall this mod. Or am I missing something ?

ozzy47 10-12-2013 09:53 AM

Sure there is, this is in the first post:

Installation: Import the product file in Product Manager

nerbert 10-12-2013 09:55 AM

Just upload the product xml file in the Import Product page and it's ready to go.

edgeless 04-14-2014 06:43 PM

Will someone please take a guess on what I'm missing here or what's wrong? I've imported this mod and it installed correctly. It shows as being enabled by default in the AdminCP General Settings panel. However, when I go into a thread and click on the 'Mark Unread' menu item, it changes to a bright red highlight and the menu remains visible (i.e., it doesn't go away). The particular thread then does not appear to be marked as unread (no boldface subject text, etc). Am I missing something obvious? Thanks in advance.

tbworld 04-14-2014 07:27 PM

Make sure you have read through the thread and you are using the database for thread marking. Check for JavaScript errors on the AJAX calls.

edgeless 04-14-2014 08:17 PM

Thanks for the reply.

Quote:

Originally Posted by tbworld (Post 2493158)
Make sure you have read through the thread and you are using the database for thread marking. Check for JavaScript errors on the AJAX calls.

The threads I'm testing have been read and were recently created. I'm using the cookie thread marking option, BUT the description for this mod says:

Quote:

Improved version now handles both database and cookie methods of marking threads read.
Both the statement above and nerbert's dialog here lead me to believe that he coded this mod to work with the cookie thread marking option as well. So I'm confused about the behavior I'm noticing. Any ideas what's going on?


All times are GMT. The time now is 10:17 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01106 seconds
  • Memory Usage 1,777KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete