Below code is not taking into consideration error handling and EXTERNAL USER. This code does not guarantee processing under all environment. Avatar needs to set up default picture. Please adjust CSS by yourself.
Sample core code: qa-db-selects.php
// Add [start]
function qa_db_user_favorited_users_selectspec($userid) {
require_once QA_INCLUDE_DIR.'qa-app-updates.php';
return array(
'columns' => array('^users.userid', 'handle', 'points', 'flags', '^users.email', 'avatarblobid', 'avatarwidth', 'avatarheight'),
'source' => "^users JOIN ^userpoints ON ^users.userid=^userpoints.userid JOIN ^userfavorites ON ^users.userid=^userfavorites.userid WHERE ^userfavorites.entityid=$ AND ^userfavorites.entitytype=$",
'arguments' => array($userid, QA_ENTITY_USER),
'sortasc' => 'handle',
);
}
// Add [end]
Sample plugin [definition]: qa-plugin/followed-user-widget/qa-plugin.php
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
qa_register_plugin_module('widget', 'qa-followed-user.php', 'qa_followed_user', 'Followed User');
Sample plugin [process]: qa-plugin/followed-user-widget/qa-followed-user.php
class qa_followed_user {
function option_default($option) {
if ($option=='followed_user_count_users') return 8;
if ($option=='followed_user_avatat_size') return 50;
}
function admin_form() {
$saved=false;
if (qa_clicked('followed_user_save_button')) {
qa_opt('followed_user_count_users', (int)qa_post_text('followed_user_count_users_field'));
qa_opt('followed_user_avatat_size', (int)qa_post_text('followed_user_avatat_size_field'));
$saved=true;
}
return array(
'ok' => $saved ? 'Followed User settings saved' : null,
'fields' => array(
array(
'label' => 'Maximum users to show:',
'type' => 'number',
'value' => (int)qa_opt('followed_user_count_users'),
'suffix' => 'users',
'tags' => 'NAME="followed_user_count_users_field"',
),
array(
'label' => 'Avatar size to show:',
'type' => 'number',
'value' => (int)qa_opt('followed_user_avatat_size'),
'suffix' => 'px',
'tags' => 'NAME="followed_user_avatat_size_field"',
),
),
'buttons' => array(
array(
'label' => 'Save Changes',
'tags' => 'NAME="followed_user_save_button"',
),
),
);
}
function allow_template($template) {
return ($template!='admin');
}
function allow_region($region) {
return ($region=='side');
}
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) {
$userid=qa_get_logged_in_userid();
if (!isset($userid)) return;
$users=qa_db_single_select(qa_db_user_favorited_users_selectspec($userid));
$themeobject->output('<H2>', qa_lang_html('addon/followed_user'), '</H2>');
$themeobject->output('<P class="qa-follow-users-message">', qa_lang_html_sub('addon/followed_user_count', count($users)), '</P>');
$output = null;
if (count($users) >= 1) {
$output = $output.'<UL CLASS="qa-follow-users qa-followed-users-widget">'."\n";
foreach (array_slice($users,0,(int)qa_opt('followed_user_count_users')) as $user){
$output = $output.'<LI>'."\n";
$output = $output.qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], (int)qa_opt('followed_user_avatat_size'), true)."\n";
$output = $output.'<DIV style="width:'.(int)qa_opt('followed_user_avatat_size').'px;overflow:hidden;white-space:nowrap;">'.qa_get_one_user_html($user['handle'], false).'</DIV>'."\n";
$output = $output.'</LI>'."\n";
}
$output = $output.'</UL>'."\n";
$output = $output.'<DIV STYLE="clear:both;"></DIV>'."\n";
}
$themeobject->output($output);
}
};
Sample lang [addon]: qa-lang/custom/qa-lang-addon.php
return array(
'followed_user' => 'Users followed up',
'followed_user_count' => 'followed up by ^ users.',
);