TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,993
  • Total Topics: 21,324
  • Online today: 368
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 306
  • Total: 306

Suggestion: Forum Navigation in Sidebar

Started by likeatim, January 06, 2006, 10:48:48 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Rasyr

Okay, how is this? Through massive trial and error (I am no good at writing SQL queries - I removed everything I could that did not give me errors), I was able to whittle the function down to the following (I have absolutely no idea how to make it a dedicated blocktype either):

Remember - I have this at the end of the load.php file in the sources directory


// Create a list of Categories/Forums for a static display.
function loadBoardList()
{
global $txt, $scripturl, $db_prefix, $ID_MEMBER, $user_info, $sourcedir;
global $modSettings, $context, $settings;

if (isset($context['menuList']))
return;

// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
$result_boards = db_query("
SELECT
c.name AS catName, c.ID_CAT, b.ID_BOARD, b.name AS boardName,
b.ID_PARENT, IFNULL(mods_mem.ID_MEMBER, 0) AS ID_MODERATOR
FROM {$db_prefix}boards AS b
LEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)
LEFT JOIN {$db_prefix}moderators AS mods ON (mods.ID_BOARD = b.ID_BOARD)
LEFT JOIN {$db_prefix}members AS mods_mem ON (mods_mem.ID_MEMBER = mods.ID_MEMBER)
WHERE $user_info[query_see_board]", __FILE__, __LINE__);

// Run through the categories and boards....
$context['menuList'] = array();
while ($row_board = mysql_fetch_assoc($result_boards))
{
// Haven't set this category yet.
if (empty($context['menuList'][$row_board['ID_CAT']]))
{
$context['menuList'][$row_board['ID_CAT']] = array(
'id' => $row_board['ID_CAT'],
'name' => $row_board['catName'],
'boards' => array(),
);
}

// Let's save some typing.  Climbing the array might be slower, anyhow.
$this_category = &$context['menuList'][$row_board['ID_CAT']]['boards'];

// This is a parent board.
if (empty($row_board['ID_PARENT']))
{
// Is this a new board, or just another moderator?
if (!isset($this_category[$row_board['ID_BOARD']]))
{
// Not a child.
$isChild = false;

$this_category[$row_board['ID_BOARD']] = array(
'id' => $row_board['ID_BOARD'],
'name' => $row_board['boardName'],
'children' => array(),
'link_children' => array(),
'href' => $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0">' . $row_board['boardName'] . '</a>'
);
}
}
// Found a child board.... make sure we've found its parent and the child hasn't been set already.
elseif (isset($this_category[$row_board['ID_PARENT']]['children']) && !isset($this_category[$row_board['ID_PARENT']]['children'][$row_board['ID_BOARD']]))
{
// A valid child!
$isChild = true;

$this_category[$row_board['ID_PARENT']]['children'][$row_board['ID_BOARD']] = array(
'id' => $row_board['ID_BOARD'],
'name' => $row_board['boardName'],
'href' => $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row_board['ID_BOARD'] . '.0">' . $row_board['boardName'] . '</a>'
);
}

}
mysql_free_result($result_boards);
}





Then I changed the code on the index.php (in the root forum folder) to read:



//Create the Board Listing for use in a menu
if (is_null($context['menuList']))
loadBoardList();



I did not change any of the code that I used to display the list.


bloc


Rasyr

Pretty good, I think. As far as I could tell there was not any difference between what I originally had and the trimmed function. (though I did forget all about checking the page load times).


bloc


feline

Well Rasyr .. works good  :)

small changes ...
is_null (in the index.php) gives error ..
try better

//Create the Board Listing for use in a menu
if (!isset($context['menuList']))
loadBoardList();


and add the $context to global  ;)

My TP-Block:

global $context, $settings;
foreach ($context['menuList'] as $category)
{
$s = html_entity_decode($category['name']);
echo '<div class="titlebg" style="margin:0px; padding:3px 4px 2px 4px;font-weight:normal;">', (strlen($s) > 22) ? substr($s,0,21).'..' : $s , '</div>';
foreach ($category['boards'] as $board)
{
$s = html_entity_decode($board['name']);
echo '<div class="windowbg" style="font-size:x-small; padding:0px;">
<img src="'.$settings['theme_url'].'/images/TPdivider.gif" alt="" />
<a href="'. $board['href'] . '">', (strlen($s) > 25) ? substr($s, 0, 24).'..' : $s , '</a></div>';
// Show the "Child Boards:
foreach ($board['children'] as $child)
{
$s = html_entity_decode($child['name']);
echo '<div class="windowbg" style="font-size:x-small; margin:0px;">
<img src="'.$settings['theme_url'].'/images/blank.gif" width="5" alt="" />
<img src="'.$settings['theme_url'].'/images/TPdivider.gif" alt="" />
<a href="' . $child['href'] . '">', (strlen($s) > 25) ? substr($s, 0, 24).'..' : $s , '</a></div>';
}
}
}


that work with most themes ...

Fel

[attachment deleted by admin]

Rasyr

Good catch on that error - hadn't realized it. And I like what you did in styling the list. Nice!



Nokonium

I said I'd have a fiddle .......

Now I want to show off  8)

I've taken it a stage further and added links for the buttons as well. These will also display according to the membergroup permissions. I left out the Login and Register buttons.

The index.php and Load.php are as posted, this is the code for the block.

        global $context, $settings, $options, $txt, $scripturl, $modSettings;

     // Show the [home] button.
       echo '
                     <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="http://nokonium.co.uk/Fiddlers-Elbow/index.php">Home</a></div>';

     // Show the [forum] button.

       echo '        <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=forum">Forum</a></div>';
     // Show the [boards] .
foreach ($context['menuList'] as $category)
{
echo '<div class="menu"><img src="'.$settings['theme_url'].'/images/blank.gif" width="6" alt="" />' . $category['name'] . '</div>';
foreach ($category['boards'] as $board)
{
echo '<div class="menu2">
<img src="'.$settings['theme_url'].'/images/blank.gif" width="6" alt="" />
<img src="'.$settings['theme_url'].'/images/TPdivider.gif" alt="" /><a href="'. $board['href'] . '">'. $board['name'] . '</a></div>';
// Show the "Child Boards:
foreach ($board['children'] as $child)
{
echo '<div class="menu2">
<img src="'.$settings['theme_url'].'/images/blank.gif" width="12" alt="" />
<img src="'.$settings['theme_url'].'/images/TPdivider.gif" alt="" /><a href="' . $child['href'] . '">' . $child['name'] . '</a></div>';
}
}
}

     // Show the [help] button.
       echo '        <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=help" target="_blank">Help</a></div>';

     // How about the [search] button?
        if ($context['allow_search'])
                echo '
                                <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=search">Search</a></div>';

     // The [PM] button.
if ($context['user']['is_logged'] && $context['allow_pm'])
        echo '
                 <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=pm">Messages</a></div>';

     // The [unread] button.
        echo '
                 <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=unread">Unread</a></div>';

      // Is the user allowed to administrate at all? ([admin])
        if ($context['allow_admin']){
                echo '
                                <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=admin">Admin</a></div>';


        }

      // the Download section ([dlmanager])
         if ($context['TPortal']['show_download']=='1')
                echo '
                                <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=tpmod;dl=0">Downloads</a></div>';



        // Edit Profile... [profile]
        if ($context['allow_edit_profile'])
                echo '
                                <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=profile">Profile</a></div>';

        // The [calendar]!
        if ($context['allow_calendar'])
                echo '
                                <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=calendar">Calendar</a></div>';

        // The [Arcade]!
        echo '
                                <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=arcade">Arcade</a></div>';


        // Otherwise, they might want to [logout]...

                echo '
                                <div class="menu"><img src="'.$settings['images_url'].'/TPdivider.gif" alt="" /><img src="'.$settings['theme_url'].'/images/blank.gif" width="2" alt="" /><a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">Log Out</a></div>';


I have added a couple of new styles for this

/* This is for the BoardNavBlock */
.menu, .menu a:link, .menu a:visited
{
        margin: 0px;
        padding:0px 4px 0px 4px;
        font-weight:normal;
        color: #305244;
        font-style: normal;
        font-variant: small-caps;
}
.menu a:hover
{
        color: #000000;
}

.menu2, .menu2 a:link, .menu2 a:visited
{
        margin: 0px;
        padding: 0px 4px 0px 4px;
        color: #305244;
        font-style: normal;
        font-size: 8pt;
}
.menu2 a:hover
{
        color: #000000;
}


[attachment deleted by admin]

Maya

 ;)This is excellent...I can see a lot of different uses for this.... Good job guys :)

feline

And now ... Forum Navigation with TP look & feel .. Shrink / Upshrink the categories ..  8)

A little bit javascript and one cookie help with this ...

Fel


global $context, $settings;

echo '
<script type="text/javascript">
<!--
cook=document.cookie;
a=cook.indexOf("Shrink=")
var mode=new Array();
if(a>=0)
{
a+=7;
e=cook.indexOf(";",a);
i=0;
while(a<e)
{
l=cook.indexOf(",",a)
mode[i]=cook.substr(a,l-a);
a=++l;
i++;
}
}

function cattoggle(id)
{
cook="Shrink=; expires=Thu, 01-Jan-70 00:00:01 GMT;";
document.cookie=cook;
catimgid="catimg"+id;
catid="cat"+id;
img=document.getElementById(catimgid).src;
md=img.indexOf("col.gif");
mode[id]=(md >= 0) ? "exp" : "col";
document.getElementById(catimgid).src="'.$settings['theme_url'].'/images/"+mode[id]+".gif";
document.getElementById(catid).style.display=(mode[id] == "col") ? "" : "none";
cook="Shrink="+mode.join(",")+",; expires=Thu, 31-Dec-30 00:00:01 GMT;";
document.cookie=cook;
}
//-->
</script>';

$id = 0;
foreach ($context['menuList'] as $category)
{
$s = $category['name'];
echo '<div class="titlebg" style="margin:2px 0px 3px 0px; padding:1px 4px 3px 1px; font-weight:normal; white-space:nowrap;">
<a href="javascript:void();" onclick="cattoggle('. $id .')">
<img id="catimg'.$id.'" src="'. $settings['theme_url'] .'/images/col.gif" border="0" alt="" /></a>
', (strlen($s) >= 20+(substr_count(substr($s,0,20),'&')*6)) ? substr($s,0,19+substr_count(substr($s,0,19),'&')*6).'..' : $s , '</div>
<div id="cat'. $id .'">';

foreach ($category['boards'] as $board)
{
$s = $board['name'];
echo '<div class="windowbg" style="font-size:x-small; margin-left:3px; white-space:nowrap;">
<img src="'.$settings['theme_url'].'/images/tpdivider.gif" alt="" />
<a href="'. $board['href'] . '">
', (strlen($s) > 28+(substr_count(substr($s,0,28),'&')*5)) ? substr($s,0,27+substr_count(substr($s,0,27),'&')*5).'..' : $s , '</div>';
// show the "child boards:
foreach ($board['children'] as $child)
{
$s = $child['name'];
echo '<div class="windowbg" style="font-size:x-small; margin-left:3px; white-space:nowrap;">
<img src="'.$settings['theme_url'].'/images/blank.gif" width="5" alt="" />
<img src="'.$settings['theme_url'].'/images/tpdivider.gif" alt="" />
<a href="' . $child['href'] . '">
', (strlen($s) > 28+(substr_count(substr($s,0,28),'&')*5)) ? substr($s,0,27+substr_count(substr($s,0,27),'&')*5).'..' : $s , '</div>';
}
}
echo '</div>';
$id++;
}

echo '
<script type="text/javascript">
<!--
for (i=0; i<'.$id.'; i++)
{
catid="cat"+i;
catimgid="catimg"+i;
if(mode[i] == undefined)
mode[i]="col";
document.getElementById(catimgid).src="'.$settings['theme_url'].'/images/"+mode[i]+".gif";
document.getElementById(catid).style.display=(mode[i] == "col") ? "" : "none";
}
//-->
</script>';



[attachment deleted by admin]

This website is proudly hosted on Crocweb Cloud Website Hosting.