Fuhrmann
Well-known member
Fuhrmann submitted a new resource: Profile Tab Manager
Create new profile tabs in the user's profiles.
Read more
Create new profile tabs in the user's profiles.
Read more
I wonder if anyone managed to find out how to display the profile owners username for example instead of the visitor's one?
//Get URL requestions
$request = new Zend_Controller_Request_Http;
$request = $request->get('REQUEST_URI');
$request = explode('/', $request);
$request = explode('.', $request[2]);
$user_id = $request[0];
// Got the username and not ID
if( !(is_numeric($user_id)) )
{
$userModel = XenForo_Model::create('XenForo_Model_User');
$user = $userModel->getUsersByNames(Array($user_id));
$user = $userModel->prepareUser($user);
$user = reset($user);
$user_id = $user['user_id'];
}
The dirty method that I used was using the request URL:
class ProfileTabManager_Callbacks_Sites extends XenForo_Application
{
/**
* Load the J! config. Assumes that XF lives in a folder inside the main J!
* root, which is the case on sandbox and live site.
*
* @return JConfig|boolean
*/
static public function loadJoomlaConfig()
{
if (class_exists('JConfig', false))
{
return new JConfig();
}
else
{
// $$$ Is there a better way of getting XF's root dir?
$xfRoot = dirname(__FILE__) . '/../../..';
$JoomlaConfig = $xfRoot . '/../configuration.php';
if (file_exists($JoomlaConfig))
{
include($JoomlaConfig);
if (class_exists('JConfig', false))
{
return new JConfig();
}
}
}
return false;
}
/**
* Create a db connection to the J! database.
*
* @param string $jConfig
* @return boolean
*/
private static function getJoomlaDb($jConfig = false)
{
$jConfig = self::loadJoomlaConfig();
if ($jConfig !== false)
{
$zConfig = new Zend_Config(
array(
'adapter' => 'mysqli',
'host' => $jConfig->host,
'username' => $jConfig->user,
'password' => $jConfig->password,
'dbname' => $jConfig->db,
'port' => '3306',
'charset' => 'utf8'
)
);
return XenForo_Application::getInstance()->loadDb($zConfig);
}
return false;
}
/**
* Little helper func to get a J! config setting
*
* @param string $name J! config setting name
* @return boolean
*/
static private function getJoomlaSetting($name)
{
$config = self::loadJoomlaConfig();
if ($config !== false)
{
return $config->$name;
}
return false;
}
/**
* The Meat Of The Thing
*
* Callback function for Profile Tab Manager, to build list of sites we provide
* support for, from a custom table on our Joomla! database. This will add
* 'user_sites' to the view data for the profile tab.
*
* @return array site list
*/
public static function getSites()
{
/*
* Set up default empty sites
*/
$userSites = array();
/**
* There MUST be a simple way of getting the member details being viewed,
* but I can't find it, so for now, do it by steam, by fetching the
* raw request and parsing the name/id out of the query string.
*/
$request = new Zend_Controller_Request_Http;
$request = $request->get('REQUEST_URI');
$request = explode('?', $request);
$request = explode('/', $request[1]);
/*
* Quick sanity check to make sure we have a members/foo.x/ URI
*/
if ($request[0] !== 'members' || count($request) < 2)
{
return $userSites;
}
$request = explode('.', $request[1]);
$user_id = $request[0];
/*
* Well, we've got something that is probably a name or an ID!
*/
if (!empty($user_id))
{
$userModel = XenForo_Model::create('XenForo_Model_User');
/*
* Use the appropriate method to look up the user, depending on
* whether we have a string (username) or a number (ID)
*/
if (!is_numeric($user_id))
{
$user = $userModel->getUsersByNames(Array($user_id));
}
else
{
$user = $userModel->getUsersByIds(Array($user_id));
}
/*
* if it's not empty, we got our member user. Yay!
*/
if (!empty($user))
{
$user = $userModel->prepareUser($user);
$user = reset($user);
/*
* Probably don't need to check for empty, but as we're going
* to use it in a query, best to make sure.
*/
if (!empty($user['email']))
{
/*
* Get the Joomla DB instance
*/
$db = self::getJoomlaDb();
if ($db !== false)
{
/*
* Find the J! user by keying on the email, relying on jFusion
* to be syncing those between XF and Joomla, and fetch that J!
* users site list from the fabrik_user_sites table
*/
$query = "
SELECT *
FROM fabrik_user_sites AS s
LEFT JOIN " . self::getJoomlaSetting('dbprefix') . "users AS u ON u.id = s.user_id
WHERE u.email = " . $db->quote($user['email']) . "
";
$user_sites = $db->fetchAll($query);
}
}
}
}
/*
* Done. Return the $user_sites array inside an array, as it's going to
* get merged into the main view params array by the Tab manager
*/
return array('user_sites' => $user_sites);
}
}
$callBackParams = call_user_func_array(array($tabsTemplate['tab_callback_class'], $tabsTemplate['tab_callback_method']), array(array('tabsTemplate' => $tabsTemplate, 'viewParams' => $viewParams)));
$profile_email = $params['viewParams']['user']['email'];
public static function getSites($params)
{
/*
* Set up default empty sites
*/
$userSites = array();
/*
* Get the email for the owner of the profile being viewed,
* from the viewParams passed in to our callback by the tabs manager
*/
$profile_email = $params['viewParams']['user']['email'];
if (!empty($profile_email))
{
/*
* Get the Joomla DB instance
*/
$db = self::getJoomlaDb();
if ($db !== false)
{
/*
* Find the J! user by keying on the email, relying on jFusion
* to be syncing those between XF and Joomla, and fetch that J!
* users site list from the fabrik_user_sites table
*/
$query = "
SELECT *
FROM fabrik_user_sites AS s
LEFT JOIN " . self::getJoomlaSetting('dbprefix') . "users AS u ON u.id = s.user_id
WHERE u.email = " . $db->quote($profile_email) . "
";
$user_sites = $db->fetchAll($query);
}
}
/*
* Done. Return the $user_sites array inside an array, as it's going to
* get merged into the main view params array by the Tab manager
*/
return array('user_sites' => $user_sites);
}
Hi, can someone help me how I get the trophy in the tab?
![]()
public function loadTemplateLinks(XenForo_Template_Abstract $template, $viewParams)
{
$visitor = XenForo_Visitor::getInstance();
$tabModel = $this->_getProfileTabsModel();
//Get all tabs that are activy (only the links)
$tabsLinks = $tabModel->getAllActiviesTabs();
if ($tabsLinks)
{
foreach ($tabsLinks as $tabsTemplate)
{
if (!in_array($viewParams['user']['user_group_id'], explode(',',$tabsTemplate['tab_usergroups_exclude_id'])) &&
(!array_intersect(explode(',',$tabsTemplate['tab_usergroups_exclude_id']), explode(',', $viewParams['user']['secondary_group_ids']))))
{
if (in_array($viewParams['user']['user_group_id'], explode(',',$tabsTemplate['tab_usergroups_id'])) ||
(array_intersect(explode(',',$tabsTemplate['tab_usergroups_id']), explode(',', $viewParams['user']['secondary_group_ids']))))
{
$ourTemplate = $template->create($tabsTemplate['tab_template_link'], $template->getParams());
$rendered .= $ourTemplate->render();
$rendered = str_replace ('__tab__', $tabsTemplate['tab_title'], $rendered);
}
}
}
}
return $rendered;
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.