Welcome to Geeklog, Anonymous Friday, March 29 2024 @ 07:37 am EDT

Geeklog Forums

removing individual topic llnks


Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
I've sen this request around here and there so thought I'd share.
The geeklog core doesn't allow you to disable single topic links from the topics list. It will always display all topics available depending upon permissions or something like that.

so... here it is... and you don't have to modify your core. Just disable the topics block altogether. then place the the following modified version of COM_showTopics into your lib-custom.php. Create a php block accordingly and all is well.

Notice a new array within this function called $dontshow. this array is meant to hold those topic id's that you don't want to see.

here is the slightly modified function for your lib-custom.php
Text Formatted Code
/**
* Shows all available topics
*
* Show the topics in the system the user has access to and prints them in HTML.
* This function is used to show the topics in the sections block.
*
* @param        string      $topic      TopicID of currently selected
* @return   string    HTML formatted topic list
*
*/

function phpblock_custom_showTopics( $topic='' )
{
    global $_CONF, $_TABLES, $_USER, $_GROUPS, $LANG01, $HTTP_SERVER_VARS,
           $_THEME_URL, $_BLOCK_TEMPLATE, $page, $newstories;

    $sql = "SELECT tid,topic,imageurl FROM {$_TABLES['topics']}";
    if( $_USER['uid'] > 1 )
    {
        $tids = DB_getItem( $_TABLES['userindex'], 'tids',
                            "uid = '{$_USER['uid']}'" );
        if( !empty( $tids ))
        {
            $sql .= " WHERE (tid NOT IN ('" . str_replace( ' ', "','", $tids )
                 . "'))" . COM_getPermSQL( 'AND' );
        }
        else
        {
            $sql .= COM_getPermSQL();
        }
    }
    else
    {
        $sql .= COM_getPermSQL();
    }
    if( $_CONF['sortmethod'] == 'alpha' )
    {
        $sql .= ' ORDER BY topic ASC';
    }
    else
    {
        $sql .= ' ORDER BY sortnum';
    }
    $result = DB_query( $sql );

    $retval = '';
    $sections = new Template( $_CONF['path_layout'] );
    if( isset( $_BLOCK_TEMPLATE['topicoption'] ))
    {
        $templates = explode( ',', $_BLOCK_TEMPLATE['topicoption'] );
        $sections->set_file( array( 'option' => $templates[0],
                                     'current' => $templates[1] ));
    }
    else
    {
        $sections->set_file( array( 'option' => 'topicoption.thtml',
                                    'inactive' => 'topicoption_off.thtml' ));
    }
    $sections->set_var( 'site_url', $_CONF['site_url'] );
    $sections->set_var( 'layout_url', $_CONF['layout_url'] );
    $sections->set_var( 'block_name', str_replace( '_', '-', 'section_block' ));

    if( $_CONF['hide_home_link'] == 0 )
    {
        // Give a link to the homepage here since a lot of people use this for
        // navigating the site

        if( COM_isFrontpage() )
        {
            $sections->set_var( 'option_url',
                                $_CONF['site_url'] . '/index.php' );
            $sections->set_var( 'option_label', $LANG01[90] );
            $sections->set_var( 'option_count', '' );
            $retval .= $sections->parse( 'item', 'option' );
        }
        else
        {
            $sections->set_var( 'option_url', '' );
            $sections->set_var( 'option_label', $LANG01[90] );
            $sections->set_var( 'option_count', '' );
            $retval .= $sections->parse( 'item', 'inactive' );
        }
    }

    if( $_CONF['showstorycount'] )
    {
        $sql = "SELECT tid, count(*) AS count FROM {$_TABLES['stories']} "
             . 'WHERE (draft_flag = 0) AND (date <= NOW()) '
             . COM_getPermSQL( 'AND' )
             . ' GROUP BY tid';
        $rcount = DB_query( $sql );
        while( $C = DB_fetchArray( $rcount ))
        {
            $storycount[$C['tid']] = $C['count'];
        }
    }

    if( $_CONF['showsubmissioncount'] )
    {
        $sql = "SELECT tid, count(*) AS count FROM {$_TABLES['storysubmission']} "
             . ' GROUP BY tid';
        $rcount = DB_query( $sql );
        while( $C = DB_fetchArray( $rcount ))
        {
            $submissioncount[$C['tid']] = $C['count'];
        }
    }

    while( $A = DB_fetchArray( $result ) )
    {
        $dontshow = array('announcements', 'Security', 'someothertopicID');//use topic id's of those topics you don't want in the list
        if(!in_array($A['tid'], $dontshow))
        {
            $topicname = stripslashes( $A['topic'] );
            $sections->set_var( 'option_url', $_CONF['site_url']
                                . '/index.php?topic=' . $A['tid'] );
            $sections->set_var( 'option_label', $topicname );

            $countstring = '';
            if( $_CONF['showstorycount'] || $_CONF['showsubmissioncount'] )
            {
                $countstring .= '(';

                if( $_CONF['showstorycount'] )
                {
                    if( empty( $storycount[$A['tid']] ))
                    {
                        $countstring .= 0;
                    }
                    else
                    {
                        $countstring .= $storycount[$A['tid']];
                    }
                }

                if( $_CONF['showsubmissioncount'] )
                {
                    if( $_CONF['showstorycount'] )
                    {
                        $countstring .= '/';
                    }
                    if( empty( $submissioncount[$A['tid']] ) ) {
                        $countstring .= 0;
                    } else {
                        $countstring .= $submissioncount[$A['tid']];
                    }
                }

                $countstring .= ')';
            }
            $sections->set_var( 'option_count', $countstring );

            $topicimage = '';
            if( !empty( $A['imageurl'] ))
            {
                if( isset( $_THEME_URL ))
                {
                    $imagebase = $_THEME_URL;
                }
                else
                {
                    $imagebase = $_CONF['site_url'];
                }
                $topicimage = '<img src="' . $imagebase . $A['imageurl'] . '" alt="'
                            . $topicname . '" title="' . $topicname . '">';
            }
            $sections->set_var( 'topic_image', $topicimage );

            if(( $A['tid'] == $topic ) && ( $page == 1 ))
            {
                $retval .= $sections->parse( 'item', 'inactive' );
            }
            else
            {
                $retval .= $sections->parse( 'item', 'option' );
            }
        }
    }

    return $retval;
}

 

IMPORTANT: please note that this does not disable the topic, only the topic link as it appears in the topics block.
 Quote

Status: offline

ronack

Forum User
Full Member
Registered: 05/27/03
Posts: 612
First, this works pretty nicely, however on a system where I have multiple sites using one lib-custom.php, I instead put it in lib-common.php. That way if I turn off General in site A, it doesn't affect General in site B.

(I think the two files should be named the opposite because lib-custom.php is actually common to all my sites and lib-common.php only affects one site, but I digress.)

Second, it would be nice to see the array $dontshow dynamic, maybe a function in the Admin/Moderation section to select which topics to include or exclude.
 Quote

All times are EDT. The time is now 07:37 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content