MyBB Community Forums

Full Version: iAndrew Theme Effects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alright guys, so I have this plugin called IAndrew Theme effects

this is the php below, the issue is, it is showing the first posters avatar and the last posters avatar as the same avatar.


any idea why?



[Image: avissieiandrew.png]

<?php
/*
 * Thread Preview Plugin
 *
 * Displays Thread first and Last Post
 *
 * Version 1.0
 */

// Disallow direct access to this file for security reasons
if (!defined("IN_MYBB")) {
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

// Add Hooks
$plugins->add_hook("misc_start", "generateThreadPreview");

// Plugin Info
function themeEffects_info()
{

    return array(
        "name" => "iAndrew Theme Effects",
        "description" => "Custom Theme Effects for iAndrew Themes",
        "website" => "http://iandrew.me",
        "author" => "Jitendra M ",
        "authorsite" => "http://mybbplugins.com",
        "version" => "1.0",
        "guid" => "",
        "compatibility" => "18*"
    );
}

// Activate plugin
function themeEffects_activate()
{
    require_once MYBB_ROOT . "/inc/adminfunctions_templates.php";
    find_replace_templatesets("headerinclude", "#" . preg_quote('<script type="text/javascript" src="{$mybb->asset_url}/jscripts/jquery.js?ver=1800"></script>') . "#i", '<script type="text/javascript" src="jscripts/theme-effects.js"></script>', '', false);
}

// Deactivate plugin
function themeEffects_deactivate()
{
    require_once MYBB_ROOT . "/inc/adminfunctions_templates.php";
    find_replace_templatesets("headerinclude", "#" . preg_quote('<script type="text/javascript" src="jscripts/theme-effects.js"></script>') . "#i", ' ', '', false);
}


function generateThreadPreview()
{
    global $mybb, $db, $lang;

    if ($mybb->input['action'] == 'fetch_preview')
    {
        $thread = get_thread($mybb->input['tid']);
        $threadData = $thread;

        $forumpermissions = forum_permissions($thread['fid']);

        // Does the user have permission to view this thread?
        if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
        {
            error_no_permission();
        }

        if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
        {
            error_no_permission();
        }


        // First Post: User/Avatar/Post
        $firstPost = $db->fetch_array($db->simple_select('posts', 'uid, username, message', 'pid="' . $threadData['firstpost'] . '"'));
        $urlF = $db->fetch_field($db->simple_select('users', 'avatar', 'uid="' . $firstPost['uid'] . '"'), 'avatar');
        $firstPost['avatar'] = '<img src="' . $mybb->settings['bburl'] . '/' . $urlF . '" style="margin-right: 20px;float: left;max-height:45px; max-width: 45px;border-radius: 2px;" />';
        $order_by = array(
            'order_by' => 'pid',
            'order_dir' => 'DESC',
            'LIMIT' => 1,
        );

        $lastPost = $db->fetch_array($db->simple_select('posts', 'uid, username, message', 'tid="' . $threadData['tid'] . '"', $order_by));
        $urlL = $db->fetch_field($db->simple_select('users', 'avatar', 'uid="' . $firstPost['uid'] . '"'), 'avatar');
        $lastPost['avatar'] = '<br /><img src="' . $mybb->settings['bburl'] . '/' . $urlL . '" style="margin-right: 20px;float: left;max-height:45px; max-width: 45px;border-radius: 2px;" />';

        $firstPost['message'] = formatMessage($firstPost['message']);
        $lastPost['message'] = formatMessage($lastPost['message']);

        // Format the other info
        $firstPost['username'] = '<span style="font-weight:bold;">' . $firstPost['username'] . '</span> made the first post' . '<hr style="color: #f5f5f5; opacity: 0.7" />';
        $lastPost['username'] = '<span style="font-weight:bold;">' . $lastPost['username'] . '</span> made the last post' . '<hr style="color: #f5f5f5; opacity: 0.7" />';

        $preview = '<div id="firstPost" style="padding-top: 0; margin-top: 0;"></div>' . $firstPost['avatar'] . $firstPost['username'] . $firstPost['message'] .
            '<div id="lastPost" style="margin-top: 8px; padding: 0">' . $lastPost['avatar'] . $lastPost['username'] . $lastPost['message'] . '</div>';

        $data = array(
            'success' => true,
            'preview' => $preview
        );

        echo json_encode($data);
        exit;
    }
}

function formatMessage($message)
{
    global $parser;
    if (!is_object($parser)) {
        require_once MYBB_ROOT . 'inc/class_parser.php';
        $parser = new postParser;
    }

    $message = $parser->parse_message($message, array(
        'allow_html' => 0,
        'allow_mycode' => 1,
        'allow_smilies' => 0,
        'allow_imgcode' => 1,
        'filter_badwords' => 1,
        'nl2br' => 0
    ));

    // before stripping tags, try converting some into spaces
    $message = preg_replace(array(
        '~\<(?:img|hr).*?/\>~si',
        '~\<li\>(.*?)\</li\>~si'
    ), array(' ', "\n* $1"), $message);

    $message = unhtmlentities(strip_tags($message));


    // convert \xA0 to spaces (reverse &nbsp;)
    //$message = trim(preg_replace(array('~ {2,}~', "~\n{2,}~"), array(' ', "\n"), strtr($message, array("\xA0" => ' ', "\r" => '', "\t" => ' '))));

    // newline fix for browsers which don't support them
    $message = preg_replace("~ ?\n ?~", " \n", $message);

    if (strlen($message) > 200)
        $message = substr($message, 0, 200) . ' ... ';

    return $message;
}
can't see the image. in the next time try to use imgur as it's more reliable for hosting images.