<commit_before>/**
 * @file Main section for Frontier Forums Moderation Tools
 * @author <NAME>
 */

/*
 * HANDLER SECTIONS
 *
 * The next few blocks handle discrete chunks of the extension process.  They generally look like:
 *
 * function handle_foo( bb, v, ... ) { BabelExt.utils.dispatch( // arguments are bulletin board, variables and anything else needed
 *     { // actions are dispatched on pages that match the criteria
 *         match_pathname: '...',
 *         match_elements: [ ... ],
 *         callback: function(stash, pathname, params) {
 *             // performs the actions relevant to the page
 *         }
 *     },
 *     ... // more actions to dispatch in different circumstances
 * )}
 *
 * They're followed by a main block that initialised the extension then calls each handler in turn.
 *
 */

/**
 * @summary Handle the dashboard page
 * @param {BulletinBoard} bb          Bulletin Board to manipulate
 * @param {Variables}     v           Variables to use
 * @param {string}        loading_img HTML to create the "loading" icon
 */
function handle_dashboard( bb, v, loading_img ) { BabelExt.utils.dispatch(
    {
        match_pathname: '/',
        match_params: {
            do: 'dashboard',
        },
        match_elements: '.below_body',
        pass_storage: ['dashboard_cache'],
        callback: function( stash, pathname, params, below_body, dashboard_cache ) {

            // Dashboard CSS
            bb.css_add([ 'user_show', 'forum_show', 'thread_show' ]);

            var dashboard = $(BabelExt.resources.get('res/dashboard.html'));

            // Reported posts forum filter
            dashboard.find('[data-forum="reported-posts"]').data( 'filter', function(thread) {

                if ( thread.is_sticky || thread.status ) return false;

                // modify the container elements to make moderation easier
                $('.threadimod', thread.container_element).remove();

                var recently_reported_posts = {};
                thread.title.replace( /\[PID: ([0-9]*)\]/, function(match, pid) {
                    recently_reported_posts['#post_'+pid] = thread.thread_id;
                });

                $( '.threadstatus', this )
                    .css({ cursor: 'pointer' })
                    .attr( 'title', 'double-click to close this thread' )
                    .dblclick(function() {
                        var threadbit = $(this).closest('.threadbit');
                        bb.thread_openclose( thread.thread_id, $(this).closest('.threadbit').hasClass('lock') )
                            .done(function() { threadbit.toggleClass('lock') });
                    });

                /*
                  var title_suffix =
                  v.resolve('report process', 'report title suffix', { moderator: 'ANY_MODERATOR' })
                  .replace( /([.*+?^${}()|\[\]\/\\])/g, "\\$1" )
                  .replace( 'ANY_MODERATOR', '.*' )

                  if ( thread.title.search( title_suffix ) == -1 ) {
                  $('<a title="Click to take this thread" class="newcontent_textcontrol" rel="nofollow" href="newreply.php?t='+thread.thread_id+'&noquote=1" style="float:right">Take this report</a>')
                  .click(function(event) {
                  stash.take_thread_and_go( this.href, thread_id );
                  event.preventDefault();
                  })
                  .insertAfter(this);
                  }
                */

                return true;
            });

            var mod_log_thread_id = v.resolve('policy', 'mod log thread id');
            var report_forum_id = 48;
            dashboard.find( '[data-thread="mod-log"]'          ).data( 'thread', mod_log_thread_id );
            dashboard.find( 'a[href="#insert-mod-log-link"]'   ).attr( 'href', bb.url_for.thread_show({ thread_id: mod_log_thread_id, goto: 'newpost' }) );
            dashboard.find( '[data-forum="reported-posts"]'    ).data( 'thread', report_forum_id );
            dashboard.find( 'a[href="#insert-mod-log-link"]'   ).attr( 'href', bb.url_for.forum_show({ forum_id: report_forum_id }) );
            dashboard.find( 'a[href="#insert-mod-queue-link"]' ).attr( 'href', bb.url_for.moderation_posts() );
            dashboard.find( 'a[href="#insert-newbies-link"]'   ).attr( 'href', bb.url_for.users_show() );

            // log in to ModCP before loading the dashboard (which will then keep us logged in)
            body_wrapper = $('.body_wrapper').html( '<iframe style="margin:auto"></iframe>' );
            bb.moderation_page( body_wrapper.find('iframe'), '/modcp/index.php?do=nav', '.navlink', '.navlink' ).then(function() {

                document.title = 'Dashboard';
                body_wrapper.empty().append(dashboard);
                new Dashboard({
                    cache        : JSON.parse( dashboard_cache || '{}' ),
                    cache_updater: function(cache) { BabelExt.storage.set( 'dashboard_cache', JSON.stringify( cache ) ) },
                    container: body_wrapper,
                    interval : 60000,
                    bb       : bb

                });

            });

        }
    },

    {
        match_elements: '#globalsearch',
        pass_storage: ['dashboard_cache'],
        callback: function( stash, pathname, params, below_body, dashboard_cache ) {
            // Add "Dashboard" link to nav tab on all pages
            $('<li><a class="navtab" href="/?do=dashboard">Dashboard</a></li>').appendTo('#navtabs');
        }
    }

)}<commit_msg>Fix reported posts forum on the dashboard<commit_after>/**
 * @file Main section for Frontier Forums Moderation Tools
 * @author <NAME>
 */

/*
 * HANDLER SECTIONS
 *
 * The next few blocks handle discrete chunks of the extension process.  They generally look like:
 *
 * function handle_foo( bb, v, ... ) { BabelExt.utils.dispatch( // arguments are bulletin board, variables and anything else needed
 *     { // actions are dispatched on pages that match the criteria
 *         match_pathname: '...',
 *         match_elements: [ ... ],
 *         callback: function(stash, pathname, params) {
 *             // performs the actions relevant to the page
 *         }
 *     },
 *     ... // more actions to dispatch in different circumstances
 * )}
 *
 * They're followed by a main block that initialised the extension then calls each handler in turn.
 *
 */

/**
 * @summary Handle the dashboard page
 * @param {BulletinBoard} bb          Bulletin Board to manipulate
 * @param {Variables}     v           Variables to use
 * @param {string}        loading_img HTML to create the "loading" icon
 */
function handle_dashboard( bb, v, loading_img ) { BabelExt.utils.dispatch(
    {
        match_pathname: '/',
        match_params: {
            do: 'dashboard',
        },
        match_elements: '.below_body',
        pass_storage: ['dashboard_cache'],
        callback: function( stash, pathname, params, below_body, dashboard_cache ) {

            // Dashboard CSS
            bb.css_add([ 'user_show', 'forum_show', 'thread_show' ]);

            var dashboard = $(BabelExt.resources.get('res/dashboard.html'));

            // Reported posts forum filter
            dashboard.find('[data-forum="reported-posts"]').data( 'filter', function(thread) {

                if ( thread.is_sticky || thread.status != 'open' ) return false;

                // modify the container elements to make moderation easier
                $('.threadimod', thread.container_element).remove();

                var recently_reported_posts = {};
                thread.title.replace( /\[PID: ([0-9]*)\]/, function(match, pid) {
                    recently_reported_posts['#post_'+pid] = thread.thread_id;
                });

                $( '.threadstatus', this )
                    .css({ cursor: 'pointer' })
                    .attr( 'title', 'double-click to close this thread' )
                    .dblclick(function() {
                        var threadbit = $(this).closest('.threadbit');
                        bb.thread_openclose( thread.thread_id, $(this).closest('.threadbit').hasClass('lock') )
                            .done(function() { threadbit.toggleClass('lock') });
                    });

                /*
                  var title_suffix =
                  v.resolve('report process', 'report title suffix', { moderator: 'ANY_MODERATOR' })
                  .replace( /([.*+?^${}()|\[\]\/\\])/g, "\\$1" )
                  .replace( 'ANY_MODERATOR', '.*' )

                  if ( thread.title.search( title_suffix ) == -1 ) {
                  $('<a title="Click to take this thread" class="newcontent_textcontrol" rel="nofollow" href="newreply.php?t='+thread.thread_id+'&noquote=1" style="float:right">Take this report</a>')
                  .click(function(event) {
                  stash.take_thread_and_go( this.href, thread_id );
                  event.preventDefault();
                  })
                  .insertAfter(this);
                  }
                */

                return true;
            });

            var mod_log_thread_id = v.resolve('policy', 'mod log thread id');
            var report_forum_id = 48;
            dashboard.find( '[data-thread="mod-log"]'              ).data( 'thread', mod_log_thread_id );
            dashboard.find( 'a[href="#insert-mod-log-link"]'       ).attr( 'href', bb.url_for.thread_show({ thread_id: mod_log_thread_id, goto: 'newpost' }) );
            dashboard.find( '[data-forum="reported-posts"]'        ).data( 'forum', report_forum_id );
            dashboard.find( 'a[href="#insert-reported-posts-link"]').attr( 'href', bb.url_for.forum_show({ forum_id: report_forum_id }) );
            dashboard.find( 'a[href="#insert-mod-queue-link"]'     ).attr( 'href', bb.url_for.moderation_posts() );
            dashboard.find( 'a[href="#insert-newbies-link"]'       ).attr( 'href', bb.url_for.users_show() );

            // log in to ModCP before loading the dashboard (which will then keep us logged in)
            body_wrapper = $('.body_wrapper').html( '<iframe style="margin:auto"></iframe>' );
            bb.moderation_page( body_wrapper.find('iframe'), '/modcp/index.php?do=nav', '.navlink', '.navlink' ).then(function() {

                document.title = 'Dashboard';
                body_wrapper.empty().append(dashboard);
                new Dashboard({
                    cache        : JSON.parse( dashboard_cache || '{}' ),
                    cache_updater: function(cache) { BabelExt.storage.set( 'dashboard_cache', JSON.stringify( cache ) ) },
                    container: body_wrapper,
                    interval : 60000,
                    bb       : bb

                });

            });

        }
    },

    {
        match_elements: '#globalsearch',
        pass_storage: ['dashboard_cache'],
        callback: function( stash, pathname, params, below_body, dashboard_cache ) {
            // Add "Dashboard" link to nav tab on all pages
            $('<li><a class="navtab" href="/?do=dashboard">Dashboard</a></li>').appendTo('#navtabs');
        }
    }

)}
{'fraction_non_alphanumeric': 0.14364044943820226, 'fraction_numerical': 0.0021573033707865167, 'mean_word_length': 1.9387216059165346, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '855054', 'n_tokens_mistral': 3211, 'n_tokens_neox': 3005, 'n_words': 702}