News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Scrolling Recent Posts Custom PHP Code For SMF 2.1.3 and EHPortal 1.39

Started by Dman2, December 21, 2022, 04:28:13 AM

Previous topic - Next topic

Dman2

Wasn't sure where to share this, but having been using SMF for years in conjunction with Simple Portal, I have always used scrolling recent topics with the members really liked, and it allowed far more information to be provided, in a small footprint.  After upgrading to SMF 2.1.3 and EHPortal (the new portal branch for SMF 2.1), the older script started throwing errors in the log.  I contacted @Chen Zhen, who rapidly saw the errors with the old PHP block script, and tuned them up.  ALL credit is given to him.

If you TOO would like some great scrolling recent posts, and are using SMF 2.1X and EHPortal, look no further.  I was surprised to NOT be any good solutions before this post.

ehPortalRecentMarquee(null, 10, 'ssi_recentPosts', '13.33rem', '20rem', 25, 'compact');
function ehPortalRecentMarquee($boards, $limit, $type, $height, $maxHeight, $speed, $display = 'compact')
{
    global $txt, $scripturl, $settings, $context, $color_profile;

    $context['html_headers'] .= '
    <style>
        .ehPort_container {
            overflow: hidden;
            height: ' . $height . ';
            max-height: ' . $maxHeight . ';
        }
        .ehPort_scrolling:hover {
            -webkit-animation-play-state:paused;
            -moz-animation-play-state:paused;
            -o-animation-play-state:paused;
            animation-play-state:paused;
            cursor: pointer;
        }
        .ehPort_scrolling {
            animation: ehPort_marquee ' . $speed . 's linear infinite;
        }
        @keyframes ehPort_marquee {
            from {
                transform: translateY(' . $limit . 'rem);
            }
            to {
                transform: translateY(-100%);
            }
        }
    </style>
    ';
    $items = $type($limit, null, $boards, 'array');

    if (empty($items) || !is_array($items))
    {
        echo '
                                ', $txt['error_sp_no_posts_found'];
        return;
    }
    else
        $items[count($items) - 1]['is_last'] = true;

    $colorids = array();
    $newImage = file_exists($settings['actual_images_url'] . '/' . $context['user']['language'] . '/new.gif') ? $settings['actual_images_url'] . '/' . $context['user']['language'] . '/new.gif' : $settings['default_images_url'] . '/' . $context['user']['language'] . '/new.gif';
    foreach ($items as $item)
        $colorids[] = !empty($item['poster']['id']) ? $item['poster']['id'] : 0;

    if (!empty($colorids) && sp_loadColors($colorids) !== false)
    {
        foreach ($items as $k => $p)
        {
            if (!empty($p['poster']['id']) && !empty($color_profile[$p['poster']['id']]['link']))
                $items[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
        }
    }

    echo '
                        <div class="ehPort_container">
                            <div class="ehPort_scrolling">';
    if ($display == 'compact')
    {
        foreach ($items as $key => $item) {
            if (empty($item['href']))
                continue;
            echo '
                                <a href="', $item['href'], '">', $item['subject'], '</a> <div style="display: inline;" class="smalltext">', $txt['by'], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img style="border: 0px;" src="' . $newImage . '" alt="' . $txt['new'] . '" /></a>', '<div>[', $item['time'], ']</div></div><div>', (empty($item['is_last']) ? '<hr />' : ''), '</div>';
        }
    }
    else
    {
        echo '
                                <div style="display: table;" class="sp_fullwidth">';

        foreach ($items as $item) {
            if (empty($item['href']))
                continue;
            echo '
                                    <div style="display: table-row;">
                                        <div style="display: table-cell;" class="sp_recent_icon sp_center">
                                            ', sp_embed_image(empty($parameters['type']) ? 'post' : 'topic'), '
                                        </div>
                                        <div style="display: table-cell;" class="sp_recent_subject">
                                            <a href="', $item['href'], '">', $item['subject'], '</a>
                                            ', $item['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $newImage . '" alt="' . $txt['new'] . '" border="0" /></a>', '<div>[', $item['board']['link'], ']</div>
                                        </div>
                                        <div style="display: table-cell;" class="sp_recent_info sp_right">
                                            ', $item['poster']['link'], '<div>', $item['time'], '</div>
                                        </div>
                                    </div>';
        }

        echo '
                                </div>';
    }

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

https://web-develop.ca/index.php?topic=2132.0

Shades.

ShadesWeb.com - Custom Logos - My Themes on SMF | My Themes on ShadesWeb
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

Advertisement: