QUICK NEWS

{NEW} - A new css video is up.

{OLD} - New video courtesy of Skhilled, Thanks for posting it up.

Video of the moment:


Internal Links

SMF Sites

Quick Info

Code-Blind: Potential help with coding 🙏🏻

Started by [chrisB], Feb 28, 2025, 11:26 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

[chrisB]

I'm still working on trying to polish my SMF site. I really love TinyPortal and I don't really want to stress anyone out there with constantly asking for help.

I am not a coder, but I tinker.

Rjen helped me in the past to improve some blocks; I have been reading how to bring in the "Avatars Display Integration" mod. I have managed to get it to work, but I can't see what I am doing wrong that is causing random ">" to be shown underneath users who have no avatar image.

This is how it looks:


Here's a link: https://poetryartonline.com/forum/ (second from bottom block, just above the "Follow Us".

global $smcFunc, $scripturl, $modSettings, $settings, $txt;

// Style of avatar
$style = 'width:36px; height:36px; border-radius:100%; object-fit:cover; box-shadow:1px 2px 4px rgba(0,0,0,0.4); display:block;';

// Number of top posters displayed
$topPoster = 6;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
    SELECT mem.id_member, mem.real_name, mem.posts, mem.avatar, a.id_attach, a.attachment_type, a.filename
    FROM {db_prefix}members AS mem
    LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
    WHERE mem.is_activated = 1
    ORDER BY posts DESC
    LIMIT {int:limit}',
    array('limit' => $topPoster)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request)) {
    // Correctly initialize the avatar variable
    $avatar = '<span class="default-avatar" style="' . $style . '" data-adi-id="' . htmlspecialchars($row['id_member']) . '"></span>';
   
    if (!empty($row['avatar'])) {
        $avatar = '<img src="' . (stristr($row['avatar'], 'http://') || stristr($row['avatar'], 'https://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar'])) . '" alt="" style="' . $style . '" title="' . htmlspecialchars($row['real_name']) . '" />';
    } elseif ($row['id_attach'] > 0) {
        $avatar = '<img src="' . (empty($row['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" style="' . $style . '" title="' . htmlspecialchars($row['real_name']) . '" />';
    }
   
    $users[$row['id_member']] = array(
        'id' => $row['id_member'],
        'name' => htmlspecialchars($row['real_name']),
        'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
        'link' => '<a href="https://poetryartonline.com/' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . htmlspecialchars($row['real_name']) . '</a>',
        'posts' => $row['posts'],
        'avatar' => $avatar
    );
}

$smcFunc['db_free_result']($request);

// Output our array of users with avatar, posts, and name
echo '<ul class="recent_topics" style="margin: 0; padding: 0; list-style: none;">';

foreach ($users as $user) {
    echo '<li style="display: flex; align-items: center; margin-bottom: 10px;">'
        . '<span class="tpavatar" style="margin-right: 10px;">' . $user['avatar'] . '</span>'
        . '<div>'
        . '<strong>' . $user['link'] . '</strong><br>'
        . '<span>' . $user['posts'] . ' ' . htmlspecialchars($txt['posts']) . '</span>'
        . '</div>'
        . '</li>';
}

echo '</ul>';

Link to mod: https://custom.simplemachines.org/index.php?mod=4246

PS. As silly as a stray ">" is, I go code-blind. 😟 If any of the wonderful, and far more knowledgable members here might be able to help me I would be grateful.

[chrisB]


Skhilled

The code that you've posted appears to fine, although, I'm not get best coder. LOL

And it appears that you have nice community. :) I'm a former musician and DJ who also dabbled with photography for a few years with my daughter.

[chrisB]

Quote from: Skhilled on Feb 28, 2025, 07:10 PMThe code that you've posted appears to fine, although, I'm not get best coder. LOL
Persistence is the key, but I'm not good either, TBH. Sometimes I just can't keep up with the simple stuff!  ;D

Quote from: Skhilled on Feb 28, 2025, 07:10 PMAnd it appears that you have nice community. :) I'm a former musician and DJ who also dabbled with photography for a few years with my daughter.

That's great! I like photography too, and my eldest daughter wants to do it for college. So, that's awesome that your own daughter shared the same interest. DJing is a great talent, something I am not skilled at, but I have made music. Did you mix or use records?

Thank you, I really appreciate your kind words.

I joined a songwriting forum back when I was 15, though I mostly wrote poetry. The forum wasn't very big on the creative arts, so I started Poetry & Art! Online. The first domain I owned was earned for free, by posting on a then-popular admin forum where you could earn points and exchange them for a domain name. Eventually, it led to poetryartonline.com (another then-IPB client, who suggested it to me and who owned the site muslimsonline.com).

MySpace played a huge part in people joining; I would find people who had interests related to the site and just start messaging them. This would never work now, but I did provide genuine feedback and conversation. Some also joined me from the songwriting community and have been very good friends. Unfortunately, I was very clueless as a teenager, and the site experienced several uphill battles. From poor shared hosting, to not vetting people who plagiarised. Those who raised concerns were thankful for the action, but some members started to feel like it wasn't a safe place to share their work. I had experienced three people who basically took my site's layout, name, etc, and tried convincing people to join their site (all at different times), but by then the damage had been done. The revival came many years down the line, focusing on social media and content, but with Invision's cost, I wasn't able to afford the license. It became inactive, and quite possibly was the final nail in its coffin, but I live in hope.

Skhilled

When I was a little boy I loved music of all kinds. I lived with my grandparents and they always played music. My grandfather tried to get me to learn the organ but I wasn't feeling it. When I was about 9 or so my grandfather bought himself a bass and me a guitar. We used to take music classes together. Eventually, my guitar was stolen and my grandfather gave me his bass. I play that until my early mid 20's.

When I was in college in my late teens I saw another doom mate DJing and it interested me. So, he started showing me how to do it. Eventually, I helped a friend who was a DJ in my 20's with a set and it branched out from there. But eventually, I ended up getting into computers early on because I loved playing games, around the mid-late 80's. It eventually grew until I started beta testing all kinds of software like AOL games, a lot of the old school games, Windows, Office, linux, Twitter before it was released, and much more. It's still a passion of mine but don't have a lot of time for it anymore. :(

My daughter and I used to pick a hiking trail every weekend and get up very early and walk it searching for animals or unique things to photograph. She eventually went to college for it and has a side business doing it. I've given it up because it because too expensive for me and I started spending a lot more time with cooking and baking. My grandmother started me baking when I was 5 years old and I loved it because I knew I would always have something good to eat. LOL I eventually taught myself real French and Italian cooking such as making fresh sausages and fresh pasta which I still do in my 60's and probably will never stop doing. LMAO

My grandson is 5 years old and I'm teaching him like my grandmother taught me. :)