Category Block (regular list)

Started by Chen Zhen, September 10, 2024, 01:54:44 AM

Previous topic - Next topic

Chen Zhen

Category Block

Version: SMF Arcade 2.7.0.2+



For EhPortal users, you can have this show in your arcade (only) by selecting Advanced Options and enter the following into Custom Display Options:
~action|arcade


Note:
The categories can also be displayed with small icons. Just name the icon the same as your category name except change any spaces to an underscore (case sensitive) and make sure it's in gif format.
Place the icons in: / Themes / default / images / arc_icons
The icons are set at 20 x 20 but this can be edited within the block.



PHP Block Code:
global $db_prefix, $arcadeModSettings, $context, $sourcedir, $scripturl, $smcFunc, $boardurl, $settings;

// Set table width & column variables  -
// change $NumberOfColumns for the number of columns across
// change $block to "right" to align items on the right side

$NumberOfColumns = 4;
$columns = 0;
$block = 'left';
/**************************
set $gameTypes
0 = Permission based
1 = Flash/HTML
2 = ROM only
3 = All game types
**************************/
$gameTypes = 0;
list($requestit, $rowit, $category, $jam, $gameCats) = array(array(), array(), array(), array(), array());
$jam['arcade_category'] = array();
switch($gameTypes) {
case 1:
$where = ' AND game.rom_flag = {int:romflag}';
$romflag = 0;
break;
case 2:
$where = ' AND game.rom_flag = {int:romflag}';
$romflag = 1;
$included_game_types[] = 'rom';
break;
case 3:
$where = '';
$romflag = 0;
break;
default:
$romflag = 0;
if (allowedTo('arcade_view_retro_arch')) {
$where = '';
}
else {
$where = ' AND game.rom_flag = {int:romflag}';
}
}
$request = $smcFunc['db_query']('', '
    SELECT game.id_game, game.id_cat, game.enabled, game.rom_flag
    FROM {db_prefix}arcade_games as game
WHERE enabled = {int:enabled}' . $where . '
    ORDER BY game.id_game ASC',
    array('enabled' => 1,'romflag' => $romflag)
);
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$idCat = !empty($row['id_cat']) ? intval($row['id_cat']) : 0;
if (empty($gameTypes) && empty($row['rom_flag']) && !allowedTo('arcade_play'))
continue;
elseif (empty($gameTypes) && !empty($row['rom_flag']) && !allowedTo('arcade_view_retro_arch'))
continue;

$gameCats[$idCat][] = $row['id_game'];
}
$smcFunc['db_free_result']($request);
$requestit = $smcFunc['db_query']('', '
SELECT id_cat, cat_name, num_games, cat_order, cat_icon
FROM {db_prefix}arcade_categories
ORDER BY cat_order',
array()
);

while ($rowit = $smcFunc['db_fetch_assoc']($requestit))
{
if (empty($gameCats[$rowit['id_cat']]))
continue;

$jam['arcade_category'][] = array(
'id' => $rowit['id_cat'],
'name' => $rowit['cat_name'],
'href' => $scripturl . '?action=arcade;category=' . $rowit['id_cat'],
'games' => $rowit['num_games'],
'order' => $rowit['cat_order'],
'icon' => $rowit['cat_icon'],
);
}
$smcFunc['db_free_result']($requestit);

echo '
<div style="overflow: hidden;">
<div style="display: table;width: 100%;margin: 0 auto;border: 0px;padding: 5px 5px 1em 5px;text-align: center;overflow: hidden !important;" summary="cats_block2" class="smalltext">
<div style="display: table-row;overflow: hidden;">';

foreach ($jam['arcade_category'] as $category)
{
if ($columns <= $NumberOfColumns) {
$gamepic_name = str_replace (" ", "_", $category['name']);
$gamepic_name = str_replace ("/", "-", $gamepic_name);
$category_pic = '<img src="' .$settings['default_theme_url']. '/images/arc_icons/'.$category['icon'].'" style="border: 0px;width: 25px;height: 25px;padding: 0.1rem 0.3rem 0.3rem 0.3rem;vertical-align: middle;" alt="~"  title="'.$category['name'].'" />';

if ($block == 'right')
echo'
<div style="width: 320px;display: flex;height: 25px;align-items: top;justify-content: right;text-justify: inter-word;border-spacing: 2px;vertical-align: middle;">
<a href="', $category['href'], '"><span style="padding-left: 0.3rem;vertical-align: middle;">',$category['name'], '</span></a><span style="padding-left: 0.3rem;vertical-align: middle;">(', $category['games'] , ' games)</span>', $category_pic, '
</div>';
else
echo'
<div style="padding: 0.15rem 0rem 0.15rem 0rem;width: 320px;display: flex;align-items: top;justify-content: left;text-justify: inter-word;border-spacing: 2px;vertical-align: middle;">', $category_pic, " ", '
<a href="', $category['href'], '"><span style="padding-left: 0.3rem;vertical-align: middle;">',$category['name'], '</span></a><span style="padding-left: 0.3rem;vertical-align: middle;">(', $category['games'] , ' games)</span>
</div>';
$columns++;
}

if ($columns >= $NumberOfColumns)  {
$columns = 0;
echo '
</div>
<div style="display: table-row;overflow: hidden;">';
}
}

echo '
</div>
</div>
</div>';