News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

[TIP/TRICK]Filter Topic Index with the help of the icons

Started by ディン1031, July 30, 2007, 12:59:53 PM

Previous topic - Next topic

ディン1031

I programmed a small filter for my Forum to show only the selected icon for the thread. Hope some people need it.

Source Changes:

Change in Filename: $sourcedir/MessageIndex.php

Search for

if (isset($_REQUEST['sort']))
$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['num_topics'], $maxindex, true);
else
$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%d', $_REQUEST['start'], $board_info['num_topics'], $maxindex, true);


Replace with

//Add On Filter the Icons... i need all icons at least :x the Stable and the not Stable ;)
$filter = '';
$context['current_addFilter'] = '';
$context['current_filter'] = 0;
$context['allowedToSeeFilter'] = false;
$context['filter_icons'] = array();

//Some Limits where i can use the filter ;D (I should insert it in the db but i'm lazy...)
$context['allowedToSeeFilter'] = !$user_info['is_guest']; //&& in_array($board, array(1,2,3...));

if($context['allowedToSeeFilter']) {
//Load the Icons from the Database :)
$icons = db_query("
SELECT ID_ICON, title, filename
FROM {$db_prefix}message_icons
WHERE ID_BOARD = 0 OR ID_BOARD = $board
ORDER BY title",__FILE__, __LINE__);

//First select is for All
$context['filter_icons'][0] = array(
'ID_ICON' => 0,
'title' => $txt[94],
'filename' => $txt[94]
);

while($icon = mysql_fetch_assoc($icons))
$context['filter_icons'][$icon['ID_ICON']] = array(
'ID_ICON' => $icon['ID_ICON'],
'title' => $icon['title'],
'filename' => $icon['filename'],
);

if(!empty($_REQUEST['filter'])) {
//There are three possible ways to use the filter easiest Numeric (i use trick to made 100%)
if(substr($_REQUEST['filter'], -3) == '.id' && is_numeric(substr($_REQUEST['filter'], 0, -3))) {
$ID_ICON = (int) substr($_REQUEST['filter'], 0, -3);
if(isset($context['filter_icons'][$ID_ICON]) && $ID_ICON != 0) {
$filter = "AND mf.icon = '".$context['filter_icons'][$ID_ICON]['filename']."'";
$context['current_addFilter'] = ';filter='.$ID_ICON.'.id';
$context['current_filter'] = $ID_ICON;
}
}
else {
//I search it via filename or title :)
foreach($context['filter_icons'] as $ID_ICON => $value) {
if(strtolower($value['filename']) == strtolower($_REQUEST['filter']) || strtolower($value['title']) == strtolower($_REQUEST['filter'])) {
$filter = "AND mf.icon = '".$value['filename']."'";
$context['current_addFilter'] = ';filter='.$ID_ICON.'.id';
$context['current_filter'] = $ID_ICON;
break; //Found it ;)
}
}
}
}
//need a new max index... so that it will remove a lot of errors...
if(!empty($context['current_filter'])) {
$newMax = db_query("
SELECT COUNT(*) AS maxIndex
FROM {$db_prefix}messages as mf
WHERE mf.ID_BOARD = $board
$filter", __FILE__, __LINE__);
list($board_info['num_topics']) = mysql_fetch_row($newMax);
$board_info['num_topics'] = (int) $board_info['num_topics']; //At least 100% a 0 is in it ;D
$maxindex = $modSettings['defaultMaxTopics'];
}
}
// Make sure the starting place makes sense and construct the page index.
if (isset($_REQUEST['sort']))
$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : '') . $context['current_addFilter'], $_REQUEST['start'], $board_info['num_topics'], $maxindex, true);
else
$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%d'.$context['current_addFilter'], $_REQUEST['start'], $board_info['num_topics'], $maxindex, true);


Search for

$request = db_query("
SELECT t.ID_TOPIC
FROM ({$db_prefix}topics AS t" . ($context['sort_by'] === 'last_poster' ? ", {$db_prefix}messages AS ml" : (in_array($context['sort_by'], array('starter', 'subject')) ? ", {$db_prefix}messages AS mf" : '')) . ')' . ($context['sort_by'] === 'starter' ? "
LEFT JOIN {$db_prefix}members AS memf ON (memf.ID_MEMBER = mf.ID_MEMBER)" : '') . ($context['sort_by'] === 'last_poster' ? "
LEFT JOIN {$db_prefix}members AS meml ON (meml.ID_MEMBER = ml.ID_MEMBER)" : '') . "
WHERE t.ID_BOARD = $board" . ($context['sort_by'] === 'last_poster' ? "
AND ml.ID_MSG = t.ID_LAST_MSG" : (in_array($context['sort_by'], array('starter', 'subject')) ? "
AND mf.ID_MSG = t.ID_FIRST_MSG" : '')) . "
ORDER BY " . (!empty($modSettings['enableStickyTopics']) ? 'isSticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . "
LIMIT $start, $maxindex", __FILE__, __LINE__);


Replace with

$request = db_query("
SELECT t.ID_TOPIC
FROM ({$db_prefix}topics AS t" . (!empty($filter) ? ", {$db_prefix}messages AS mfi" : "") . ($context['sort_by'] === 'last_poster' ? ", {$db_prefix}messages AS ml" : (in_array($context['sort_by'], array('starter', 'subject')) ? ", {$db_prefix}messages AS mf" : '')) . ')' . ($context['sort_by'] === 'starter' ? "
LEFT JOIN {$db_prefix}members AS memf ON (memf.ID_MEMBER = mf.ID_MEMBER)" : '') . ($context['sort_by'] === 'last_poster' ? "
LEFT JOIN {$db_prefix}members AS meml ON (meml.ID_MEMBER = ml.ID_MEMBER)" : '') . "
WHERE t.ID_BOARD = $board" . ($context['sort_by'] === 'last_poster' ? "
AND ml.ID_MSG = t.ID_LAST_MSG" : (in_array($context['sort_by'], array('starter', 'subject')) ? "
AND mf.ID_MSG = t.ID_FIRST_MSG" : '')) . (!empty($filter) ? "
".str_replace("mf", "mfi", $filter)." AND mfi.ID_MSG = t.ID_FIRST_MSG" : ""). "
ORDER BY " . (!empty($modSettings['enableStickyTopics']) ? 'isSticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . "
LIMIT $start, $maxindex", __FILE__, __LINE__);


Search for

AND ml.ID_MSG = t.ID_LAST_MSG
AND mf.ID_MSG = t.ID_FIRST_MSG


Add after

$filter


So now the Theme Changes:

Change in Filename: $themedir/MessageIndex.template.php

Search for

<tr>
<td class="middletext">', $txt[139], ': ', $context['page_index'], !empty($modSettings['topbottomEnable']) ? $context['menu_separator'] . '&nbsp;&nbsp;<a href="#bot"><b>' . $txt['topbottom5'] . '</b></a>' : '', '</td>


Replace with

<tr>
', ($context['allowedToSeeFilter'] ? '<form action="'.$scripturl.'" method="get" accept-charset="'.$context['character_set'].'" name="filterIcons">' : ''), '
<td class="middletext">', $txt[139], ': ', $context['page_index'], !empty($modSettings['topbottomEnable']) ? $context['menu_separator'] . '&nbsp;&nbsp;<a href="#bot"><b>' . $txt['topbottom5'] . '</b></a>' : '';
if($context['allowedToSeeFilter']) {
echo '
<input type="hidden" value="'.$context['current_board'].'.0" name="board" />
<select name="filter" onchange="document.filterIcons.submit();">';
foreach($context['filter_icons'] as $icon) {
echo '
<option value="'.$icon['ID_ICON'].'.id"'.($context['current_filter'] == $icon['ID_ICON'] ? ' selected="selected"' : '').'>'.$icon['title'].'</option>';
}
echo '
</select>
<input type="submit" value="Go">
</form>';
}
echo '
</td>


Search for


<td class="catbg3"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[70], $context['sort_by'] == 'subject' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" width="11%"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=starter', $context['sort_by'] == 'starter' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[109], $context['sort_by'] == 'starter' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" width="4%" align="center"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=replies', $context['sort_by'] == 'replies' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[110], $context['sort_by'] == 'replies' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" width="4%" align="center"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=views', $context['sort_by'] == 'views' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[301], $context['sort_by'] == 'views' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" width="22%"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=last_post', $context['sort_by'] == 'last_post' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[111], $context['sort_by'] == 'last_post' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>';


replace with


<td class="catbg3"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=subject', $context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[70], $context['sort_by'] == 'subject' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" width="11%"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=starter', $context['sort_by'] == 'starter' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[109], $context['sort_by'] == 'starter' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" width="4%" align="center"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=replies', $context['sort_by'] == 'replies' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[110], $context['sort_by'] == 'replies' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" width="4%" align="center"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=views', $context['sort_by'] == 'views' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[301], $context['sort_by'] == 'views' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>

<td class="catbg3" width="22%"><a href="', $scripturl, '?board=', $context['current_board'], '.', $context['start'], ';sort=last_post', $context['sort_by'] == 'last_post' && $context['sort_direction'] == 'up' ? ';desc' : '', $context['current_addFilter'] ,'">', $txt[111], $context['sort_by'] == 'last_post' ? ' <img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" />' : '', '</a></td>';


I think it's improvable so have no haste and post you better ideas, if someone like to made a mod out of feel free to do this ;) (I've no time to manage a mod for this).

Here some Pics how it should look like:



Bye
DIN1031
Support only via MOD Thread! NO PM Support!
My Forum: ayu][kult Forum
My Mods: My Small Mod Collection
My Parser: DIN1031's ModParser
Current Info: More away the next days, because i've to much work to do :x

Joshua Dickerson

Why don't you package it up and submit it as a customization?
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

ディン1031

At the moment i've not so much time to manage more mods *drop* and i thought it's something that not needed by many people so i think it's better for tips and tricks.

Bye
DIN1031
Support only via MOD Thread! NO PM Support!
My Forum: ayu][kult Forum
My Mods: My Small Mod Collection
My Parser: DIN1031's ModParser
Current Info: More away the next days, because i've to much work to do :x

Advertisement: