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

Recent

Welcome to TinyPortal. Please login or sign up.

Recent posts

#1
Support / Re: Promote to Front Page
Last post by @rjen - April 29, 2025, 10:22:02 PM
The avatar issue is most likely because my forum has custom avatars folders
#2
Support / Re: Promote to Front Page
Last post by sgm09 - April 29, 2025, 10:17:15 PM
Well that depends on each forum's use case, if they want or not to show topics based on permissions. It will render the title and author, but won't allow actual access to topic. Didn't have any issues with the avatars over here.
#3
Support / Re: Promote to Front Page
Last post by @rjen - April 29, 2025, 10:12:34 PM
Thanks, the blockcodes have some issues with the avatars, and as far as I can see the code also does not respect the member permissions, meaning that the blocks will show topics to users that do not have permissions to view the boards.

This may work for some users, but not all.

Will have a look
#4
Support / Re: Promote to Front Page
Last post by sgm09 - April 29, 2025, 09:10:14 PM
Sure, it's just some chatgpt generated code. Here's an even nicer one that works on sticky posts, and retrieves the first img it finds in the post, or else falls back to avatar (was meant for movie posters).

global $context, $smcFunc, $scripturl, $settings, $txt, $modSettings;
// Number of sticky topics to show
$sticky_limit = 15;

// Query to retrieve sticky topics and their message bodies
$request = $smcFunc['db_query']('', '
    SELECT t.id_topic, t.id_first_msg, m.subject, m.body, m.id_member, m.poster_name, m.poster_time,
           mem.real_name
    FROM {db_prefix}topics AS t
    INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
    LEFT JOIN {db_prefix}members AS mem ON (m.id_member = mem.id_member)
    WHERE t.is_sticky = 1
    ORDER BY m.poster_time DESC
    LIMIT {int:limit}',
    array(
        'limit' => $sticky_limit,
    )
);

$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
    $topics[] = $row;
}
$smcFunc['db_free_result']($request);

if (!empty($topics))
{
    echo '
    <div style="display: flex; flex-wrap: wrap; gap: 0.75rem; width: 100%;">';
    foreach ($topics as $topic)
    {
        // Extract image from [img] BBCode in the message body
        $image_html = '<img src="' . $settings['images_url'] . '/default_avatar.png" alt="" style="width:60px;height:60px;object-fit:cover;">';

        if (!empty($topic['body'])) {
            if (preg_match('/\[img(?:[^\]]*)\](.*?)\[\/img\]/i', $topic['body'], $matches)) {
                $img_url = trim($matches[1]);
                if (stripos($img_url, 'http') === 0) {
                    $image_html = '<img src="' . htmlspecialchars($img_url) . '" alt="" style="width:60px;height:88px;object-fit:cover;">';
                }
            }
        }

        $member_id = (int) $topic['id_member'];

        echo '
        <div style="display: flex; align-items: center; border: 1px solid #ccc; border-radius: 6px; padding: 2px; width: 280px; box-sizing: border-box;">
            <div style="flex-shrink: 0; margin-right: 6px;">
                <a href="', $scripturl, '?action=profile;u=', $member_id, '">', $image_html, '</a>
            </div>
            <div style="flex-grow: 1;">
                <div style="font-weight: bold;">
                    <a href="', $scripturl, '?topic=', $topic['id_topic'], '.0">', $topic['subject'], '</a>
                </div>
                <div style="font-size: smaller; color: #666; margin-top: 2px;">', $txt['by'], ' <a href="', $scripturl, '?action=profile;u=', $member_id, '">', !empty($topic['real_name']) ? htmlspecialchars($topic['real_name']) : htmlspecialchars($topic['poster_name']), '</a> | ', timeformat($topic['poster_time']), '</div>
            </div>
        </div>';
    }
    echo '
    </div>';
}
else
{
    echo '<div class="smalltext">No sticky topics available.</div>';
}

#5
Support / Re: Promote to Front Page
Last post by @rjen - April 29, 2025, 05:04:34 PM
I do like the idea, althought there are some layout details I would change...
Although the 'Promote to Frontpage' was originally used for frontpage display, we could 'revamp' the function in a future release.

What would make it more universal:
- rename the 'Promote to Frontpage' to 'Make Promoted Topic'
- I can add an extra option in Article settings to allow switching the Promotion on and off (regardless of the Frontpage setting)
- I would add a standard block to Tinyportal to show Promoted topics

For the block I would like to use your input as the starting point. Would that be ok for you?
#6
Support / Re: Promote to Front Page
Last post by sgm09 - April 29, 2025, 12:48:00 AM
Here's the code for the promoted topics block, as generated by chatgpt.
global $context, $smcFunc, $scripturl, $settings, $txt, $modSettings;

// Number of promoted topics to show
$promoted_limit = 15;

// Check if there are promoted topics
if (!empty($context['TPortal']['frontpage_topics']))
{
    $request = $smcFunc['db_query']('', '
        SELECT t.id_topic, t.id_first_msg, m.subject, m.id_member, m.poster_name, m.poster_time
        FROM {db_prefix}topics AS t
        INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
        WHERE t.id_topic IN ({array_int:topics})
        ORDER BY m.poster_time DESC
        LIMIT {int:limit}',
        array(
            'topics' => array_map('intval', explode(',', $context['TPortal']['frontpage_topics'])),
            'limit' => $promoted_limit,
        )
    );

    $topics = array();

    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        $topics[] = $row;
    }
    $smcFunc['db_free_result']($request);

    echo '
    <div style="display: flex; flex-wrap: wrap; gap: 1rem; width: 100%;">';

    foreach ($topics as $topic)
    {
        $member_id = (int) $topic['id_member'];
        $avatar_img = '';

        if (!empty($member_id)) {
            // Query avatar info directly
            $request2 = $smcFunc['db_query']('', '
                SELECT avatar, email_address
                FROM {db_prefix}members
                WHERE id_member = {int:id_member}
                LIMIT 1',
                array(
                    'id_member' => $member_id,
                )
            );

            if ($request2) {
                if ($row2 = $smcFunc['db_fetch_assoc']($request2)) {
                    $avatar_data = set_avatar_data(array(
                        'avatar' => $row2['avatar'],
                        'email' => $row2['email_address'],
                    ));

                    if (!empty($avatar_data['image'])) {
                        $avatar_img = $avatar_data['image'];
                    }
                }
                $smcFunc['db_free_result']($request2);
            }
        }

        // Fallback default avatar
        if (empty($avatar_img)) {
            $avatar_img = '<img src="' . $settings['images_url'] . '/default_avatar.png" alt="" style="width:50px;height:50px;border-radius:50%;">';
        }

        echo '
        <div style="display: flex; align-items: center; border: 1px solid #ccc; border-radius: 8px; padding: 10px; width: 300px; box-sizing: border-box;">
            <div style="flex-shrink: 0; margin-right: 10px;">
                <a href="', $scripturl, '?action=profile;u=', $member_id, '">', $avatar_img, '</a>
            </div>
            <div style="flex-grow: 1;">
                <div style="font-weight: bold; margin-bottom: 5px;">
                    <a href="', $scripturl, '?topic=', $topic['id_topic'], '.0">', $topic['subject'], '</a>
                </div>
                <div style="font-size: smaller; color: #666;">', $txt['by'], ' ', htmlspecialchars($topic['poster_name']), ' | ', timeformat($topic['poster_time']), '</div>
            </div>
        </div>';
    }

    echo '
    </div>';

}
else
{
    echo '<div class="smalltext">No promoted topics available.</div>';
}
#7
Support / Re: Promote to Front Page
Last post by @rjen - April 28, 2025, 10:05:08 PM
I do like the idea to create blocks with selected topics . Would you mind sharing the block code?

It may help formulating an alternative option...
#8
Support / Re: Promote to Front Page
Last post by sgm09 - April 28, 2025, 09:36:44 PM
Chatgpt is pretty clever indeed. So what do you suggest we use as an indicator then ?
I would disagree it's an edge case. Why should the idea of promoted topics be stuck to a particular display option, that is mandatory to be enabled for the promoted button to even appear ? This doesn't make much sense to me, in a project that allows extensive customization, custom php code blocks and so on.

Ok now I just found that there's sticky topics in smf, without mods. I willuse that :D
Still, the way this promoted posts is designed should be more flexible.
#9
Support / Re: Promote to Front Page
Last post by @rjen - April 28, 2025, 08:49:48 PM
I don't think so. Promote to front page is intended for exactly that.

If you wrote a custom block that uses that indicator than that's clever, but really an edge case. Not something we should adapt the core code to.

#10
Support / Re: Promote to Front Page
Last post by sgm09 - April 28, 2025, 08:32:01 PM
Quote from: @rjen on December 17, 2018, 03:24:11 PMI agree this is not very intuitive, especially since the 'Promote to frontpage' button is showing even when the chosen frontpage layout will not show the topics.

I think we should only show the button if the button can actually be used. I can fix this in the next bugfix release...

welp, this fix does more bad than good if you ask me.
I wrote with chatgpt a custom block code to display the promoted topics in a more compact manner, with poster avatar and a custom layout. After I got it working, I realised I can't actually promote the topics unless I have the promote topics option enabled in what to show on frontpage. Which of course, would lead to duplicate and unwated display of content. The promoted stuff can exist regardless if I choose the builtin option to display them, like in this example with the custom code.
Would you please consider fixing this again, maybe offering an option to display the promote button on topics that does not depend on any feture being enabled or not. Thanks

This website is proudly hosted on Crocweb Cloud Website Hosting.