XF 2.0 get avatar url from external app

amurri

New member
Hello, i need to get a list of users and respective avatars from an external php script.

I do this but i get:
An unexpected error occurred. Please try again later.

PHP:
<?php

$fileDir = $_SERVER['DOCUMENT_ROOT'].'/forums/';
require($fileDir . '/src/XF.php');

XF::start($fileDir);
$app = \XF::setupApp('XF\App');

$db = $app->getDb();
$utente = $db->fetchRow("SELECT * FROM xf_user WHERE username = ?", 'zuleika_scarpa');
//print_r($utente);

$avatar = XenForo_Template_Helper_Core::callHelper('avatar', array($utente, 's'));

?>

anyone can help me? I prefer to avoid use the REST APIs
thanks
 
$avatar = XenForo_Template_Helper_Core::callHelper('avatar', array($utente, 's'));

This is XF1 code. Also use the finder system as described in the dev docks instead of a blunt db query.
 
I just re-animate this thread for a solution.

PHP:
$fileDir = "/path/to/xenforo"; // CHANGE IT!
    require $fileDir . '/src/XF.php';
    XF::start($fileDir);
    $app = XF::setupApp('XF\Pub\App');
    $app->start();
    $visitor = \XF::visitor();
// Now you have access to the visitor's data e.g.
// $visitor["user_id"]
// $visitor["username"] etc...
// You want the link for users avatar
echo  $visitor->getAvatarUrl('s', null, true); // s, m, l, o => avatar sizes
 
Back
Top Bottom