Commit 5f069e8f by Scott

Refactor user-page controllers

parent 6625017e
......@@ -38,10 +38,10 @@
// Find the recent activity for this user
$loginuserid=qa_get_logged_in_userid();
$identifier=QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
$loginuserid = qa_get_logged_in_userid();
$identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
list($useraccount, $questions, $answerqs, $commentqs, $editqs)=qa_db_select_with_pending(
list($useraccount, $questions, $answerqs, $commentqs, $editqs) = qa_db_select_with_pending(
QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false),
qa_db_user_recent_qs_selectspec($loginuserid, $identifier, qa_opt_if_loaded('page_size_activity')),
qa_db_user_recent_a_qs_selectspec($loginuserid, $identifier),
......@@ -49,30 +49,30 @@
qa_db_user_recent_edit_qs_selectspec($loginuserid, $identifier)
);
if ((!QA_FINAL_EXTERNAL_USERS) && !is_array($useraccount)) // check the user exists
if (!QA_FINAL_EXTERNAL_USERS && !is_array($useraccount)) // check the user exists
return include QA_INCLUDE_DIR.'qa-page-not-found.php';
// Get information on user references
$questions=qa_any_sort_and_dedupe(array_merge($questions, $answerqs, $commentqs, $editqs));
$questions=array_slice($questions, 0, qa_opt('page_size_activity'));
$usershtml=qa_userids_handles_html(qa_any_get_userids_handles($questions), false);
$questions = qa_any_sort_and_dedupe(array_merge($questions, $answerqs, $commentqs, $editqs));
$questions = array_slice($questions, 0, qa_opt('page_size_activity'));
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions), false);
// Prepare content for theme
$qa_content=qa_content_prepare(true);
$qa_content = qa_content_prepare(true);
if (count($questions))
$qa_content['title']=qa_lang_html_sub('profile/recent_activity_by_x', $userhtml);
$qa_content['title'] = qa_lang_html_sub('profile/recent_activity_by_x', $userhtml);
else
$qa_content['title']=qa_lang_html_sub('profile/no_posts_by_x', $userhtml);
$qa_content['title'] = qa_lang_html_sub('profile/no_posts_by_x', $userhtml);
// Recent activity by this user
$qa_content['q_list']['form']=array(
$qa_content['q_list']['form'] = array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'hidden' => array(
......@@ -80,22 +80,23 @@
),
);
$qa_content['q_list']['qs']=array();
$qa_content['q_list']['qs'] = array();
$htmldefaults=qa_post_html_defaults('Q');
$htmldefaults['whoview']=false;
$htmldefaults['voteview']=false;
$htmldefaults['avatarsize']=0;
$htmldefaults = qa_post_html_defaults('Q');
$htmldefaults['whoview'] = false;
$htmldefaults['voteview'] = false;
$htmldefaults['avatarsize'] = 0;
foreach ($questions as $question)
$qa_content['q_list']['qs'][]=qa_any_to_q_html_fields($question, $loginuserid, qa_cookie_get(),
foreach ($questions as $question) {
$qa_content['q_list']['qs'][] = qa_any_to_q_html_fields($question, $loginuserid, qa_cookie_get(),
$usershtml, null, array('voteview' => false) + qa_post_html_options($question, $htmldefaults));
}
// Sub menu for navigation in user pages
$qa_content['navigation']['sub']=qa_user_sub_navigation($handle, 'activity',
isset($loginuserid) && ($loginuserid==(QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid'])));
$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'activity', $ismyuser);
return $qa_content;
......
......@@ -35,45 +35,45 @@
// $handle, $userhtml are already set by qa-page-user.php - also $userid if using external user integration
$start=qa_get_start();
$start = qa_get_start();
// Find the questions for this user
$loginuserid=qa_get_logged_in_userid();
$identifier=QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
$loginuserid = qa_get_logged_in_userid();
$identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
list($useraccount, $userpoints, $questions)=qa_db_select_with_pending(
list($useraccount, $userpoints, $questions) = qa_db_select_with_pending(
QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false),
qa_db_user_points_selectspec($identifier),
qa_db_user_recent_a_qs_selectspec($loginuserid, $identifier, qa_opt_if_loaded('page_size_activity'), $start)
);
if ((!QA_FINAL_EXTERNAL_USERS) && !is_array($useraccount)) // check the user exists
if (!QA_FINAL_EXTERNAL_USERS && !is_array($useraccount)) // check the user exists
return include QA_INCLUDE_DIR.'qa-page-not-found.php';
// Get information on user questions
$pagesize=qa_opt('page_size_activity');
$count=(int)@$userpoints['aposts'];
$questions=array_slice($questions, 0, $pagesize);
$usershtml=qa_userids_handles_html($questions, false);
$pagesize = qa_opt('page_size_activity');
$count = (int)@$userpoints['aposts'];
$questions = array_slice($questions, 0, $pagesize);
$usershtml = qa_userids_handles_html($questions, false);
// Prepare content for theme
$qa_content=qa_content_prepare(true);
$qa_content = qa_content_prepare(true);
if (count($questions))
$qa_content['title']=qa_lang_html_sub('profile/answers_by_x', $userhtml);
$qa_content['title'] = qa_lang_html_sub('profile/answers_by_x', $userhtml);
else
$qa_content['title']=qa_lang_html_sub('profile/no_answers_by_x', $userhtml);
$qa_content['title'] = qa_lang_html_sub('profile/no_answers_by_x', $userhtml);
// Recent questions by this user
$qa_content['q_list']['form']=array(
$qa_content['q_list']['form'] = array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'hidden' => array(
......@@ -81,29 +81,29 @@
),
);
$qa_content['q_list']['qs']=array();
$qa_content['q_list']['qs'] = array();
$htmldefaults=qa_post_html_defaults('Q');
$htmldefaults['whoview']=false;
$htmldefaults['avatarsize']=0;
$htmldefaults['ovoteview']=true;
$htmldefaults['answersview']=false;
$htmldefaults = qa_post_html_defaults('Q');
$htmldefaults['whoview'] = false;
$htmldefaults['avatarsize'] = 0;
$htmldefaults['ovoteview'] = true;
$htmldefaults['answersview'] = false;
foreach ($questions as $question) {
$options=qa_post_html_options($question, $htmldefaults);
$options['voteview']=qa_get_vote_view('A', false, false);
$options = qa_post_html_options($question, $htmldefaults);
$options['voteview'] = qa_get_vote_view('A', false, false);
$qa_content['q_list']['qs'][]=qa_other_to_q_html_fields($question, $loginuserid, qa_cookie_get(),
$qa_content['q_list']['qs'][] = qa_other_to_q_html_fields($question, $loginuserid, qa_cookie_get(),
$usershtml, null, $options);
}
$qa_content['page_links']=qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
// Sub menu for navigation in user pages
$qa_content['navigation']['sub']=qa_user_sub_navigation($handle, 'answers',
isset($loginuserid) && ($loginuserid==(QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid'])));
$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'answers', $ismyuser);
return $qa_content;
......
......@@ -46,10 +46,10 @@
// Find the user profile and questions and answers for this handle
$loginuserid=qa_get_logged_in_userid();
$identifier=QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
$loginuserid = qa_get_logged_in_userid();
$identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
list($useraccount, $userprofile, $userfields, $usermessages, $userpoints, $userlevels, $navcategories, $userrank)=
list($useraccount, $userprofile, $userfields, $usermessages, $userpoints, $userlevels, $navcategories, $userrank) =
qa_db_select_with_pending(
QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false),
QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_profile_selectspec($handle, false),
......@@ -61,17 +61,19 @@
qa_db_user_rank_selectspec($identifier)
);
if (!QA_FINAL_EXTERNAL_USERS)
foreach ($userfields as $index => $userfield)
if (!QA_FINAL_EXTERNAL_USERS) {
foreach ($userfields as $index => $userfield) {
if ( isset($userfield['permit']) && qa_permit_value_error($userfield['permit'], $loginuserid, qa_get_logged_in_level(), qa_get_logged_in_flags()) )
unset($userfields[$index]); // don't pay attention to user fields we're not allowed to view
}
}
// Check the user exists and work out what can and can't be set (if not using single sign-on)
$errors=array();
$errors = array();
$loginlevel=qa_get_logged_in_level();
$loginlevel = qa_get_logged_in_level();
if (!QA_FINAL_EXTERNAL_USERS) { // if we're using integrated user management, we can know and show more
require_once QA_INCLUDE_DIR.'qa-app-messages.php';
......@@ -79,65 +81,69 @@
if ((!is_array($userpoints)) && !is_array($useraccount))
return include QA_INCLUDE_DIR.'qa-page-not-found.php';
$userid=$useraccount['userid'];
$fieldseditable=false;
$maxlevelassign=null;
$userid = $useraccount['userid'];
$fieldseditable = false;
$maxlevelassign = null;
$maxuserlevel=$useraccount['level'];
$maxuserlevel = $useraccount['level'];
foreach ($userlevels as $userlevel)
$maxuserlevel=max($maxuserlevel, $userlevel['level']);
$maxuserlevel = max($maxuserlevel, $userlevel['level']);
if (
isset($loginuserid) &&
($loginuserid!=$userid) &&
(($loginlevel>=QA_USER_LEVEL_SUPER) || ($loginlevel>$maxuserlevel)) &&
($loginuserid != $userid) &&
(($loginlevel >= QA_USER_LEVEL_SUPER) || ($loginlevel > $maxuserlevel)) &&
(!qa_user_permit_error())
) { // can't change self - or someone on your level (or higher, obviously) unless you're a super admin
if ($loginlevel>=QA_USER_LEVEL_SUPER)
$maxlevelassign=QA_USER_LEVEL_SUPER;
if ($loginlevel >= QA_USER_LEVEL_SUPER)
$maxlevelassign = QA_USER_LEVEL_SUPER;
elseif ($loginlevel>=QA_USER_LEVEL_ADMIN)
$maxlevelassign=QA_USER_LEVEL_MODERATOR;
elseif ($loginlevel >= QA_USER_LEVEL_ADMIN)
$maxlevelassign = QA_USER_LEVEL_MODERATOR;
elseif ($loginlevel>=QA_USER_LEVEL_MODERATOR)
$maxlevelassign=QA_USER_LEVEL_EXPERT;
elseif ($loginlevel >= QA_USER_LEVEL_MODERATOR)
$maxlevelassign = QA_USER_LEVEL_EXPERT;
if ($loginlevel>=QA_USER_LEVEL_ADMIN)
$fieldseditable=true;
if ($loginlevel >= QA_USER_LEVEL_ADMIN)
$fieldseditable = true;
if (isset($maxlevelassign) && ($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED))
$maxlevelassign=min($maxlevelassign, QA_USER_LEVEL_EDITOR); // if blocked, can't promote too high
$maxlevelassign = min($maxlevelassign, QA_USER_LEVEL_EDITOR); // if blocked, can't promote too high
}
$approvebutton=isset($maxlevelassign) && ($useraccount['level']<QA_USER_LEVEL_APPROVED) && ($maxlevelassign>=QA_USER_LEVEL_APPROVED) && (!($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED)) && qa_opt('moderate_users');
$usereditbutton=$fieldseditable || isset($maxlevelassign);
$userediting=$usereditbutton && (qa_get_state()=='edit');
$approvebutton = isset($maxlevelassign)
&& $useraccount['level'] < QA_USER_LEVEL_APPROVED
&& $maxlevelassign >= QA_USER_LEVEL_APPROVED
&& !($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED)
&& qa_opt('moderate_users');
$usereditbutton = $fieldseditable || isset($maxlevelassign);
$userediting = $usereditbutton && (qa_get_state() == 'edit');
$wallposterrorhtml=qa_wall_error_html($loginuserid, $useraccount['userid'], $useraccount['flags']);
$wallposterrorhtml = qa_wall_error_html($loginuserid, $useraccount['userid'], $useraccount['flags']);
// This code is similar but not identical to that in to qq-page-user-wall.php
$usermessages=array_slice($usermessages, 0, qa_opt('page_size_wall'));
$usermessages=qa_wall_posts_add_rules($usermessages, 0);
$usermessages = array_slice($usermessages, 0, qa_opt('page_size_wall'));
$usermessages = qa_wall_posts_add_rules($usermessages, 0);
foreach ($usermessages as $message)
foreach ($usermessages as $message) {
if ($message['deleteable'] && qa_clicked('m'.$message['messageid'].'_dodelete')) {
if (!qa_check_form_security_code('wall-'.$useraccount['handle'], qa_post_text('code')))
$errors['page']=qa_lang_html('misc/form_security_again');
$errors['page'] = qa_lang_html('misc/form_security_again');
else {
qa_wall_delete_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $message);
qa_redirect(qa_request(), null, null, null, 'wall');
}
}
}
}
// Process edit or save button for user, and other actions
if (!QA_FINAL_EXTERNAL_USERS) {
$reloaduser=false;
$reloaduser = false;
if ($usereditbutton) {
if (qa_clicked('docancel'))
......@@ -150,17 +156,17 @@
require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
require_once QA_INCLUDE_DIR.'qa-db-users.php';
$inemail=qa_post_text('email');
$inemail = qa_post_text('email');
$inprofile=array();
$inprofile = array();
foreach ($userfields as $userfield)
$inprofile[$userfield['fieldid']]=qa_post_text('field_'.$userfield['fieldid']);
$inprofile[$userfield['fieldid']] = qa_post_text('field_'.$userfield['fieldid']);
if (!qa_check_form_security_code('user-edit-'.$handle, qa_post_text('code'))) {
$errors['page']=qa_lang_html('misc/form_security_again');
$userediting=true;
} else {
$errors['page'] = qa_lang_html('misc/form_security_again');
$userediting = true;
}
else {
if (qa_post_text('removeavatar')) {
qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_AVATAR, false);
qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_GRAVATAR, false);
......@@ -176,8 +182,8 @@
}
if ($fieldseditable) {
$filterhandle=$handle; // we're not filtering the handle...
$errors=qa_handle_email_filter($filterhandle, $inemail, $useraccount);
$filterhandle = $handle; // we're not filtering the handle...
$errors = qa_handle_email_filter($filterhandle, $inemail, $useraccount);
unset($errors['handle']); // ...and we don't care about any errors in it
if (!isset($errors['email']))
......@@ -187,7 +193,7 @@
}
if (count($inprofile)) {
$filtermodules=qa_load_modules_with('filter', 'filter_profile');
$filtermodules = qa_load_modules_with('filter', 'filter_profile');
foreach ($filtermodules as $filtermodule)
$filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile);
}
......@@ -197,7 +203,7 @@
qa_db_user_profile_set($userid, $userfield['title'], $inprofile[$userfield['fieldid']]);
if (count($errors))
$userediting=true;
$userediting = true;
qa_report_event('u_edit', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array(
'userid' => $userid,
......@@ -206,22 +212,22 @@
}
if (isset($maxlevelassign)) {
$inlevel=min($maxlevelassign, (int)qa_post_text('level')); // constrain based on maximum permitted to prevent simple browser-based attack
if ($inlevel!=$useraccount['level'])
$inlevel = min($maxlevelassign, (int)qa_post_text('level')); // constrain based on maximum permitted to prevent simple browser-based attack
if ($inlevel != $useraccount['level'])
qa_set_user_level($userid, $useraccount['handle'], $inlevel, $useraccount['level']);
if (qa_using_categories()) {
$inuserlevels=array();
$inuserlevels = array();
for ($index=1; $index<=999; $index++) {
$inlevel=qa_post_text('uc_'.$index.'_level');
for ($index = 1; $index <= 999; $index++) {
$inlevel = qa_post_text('uc_'.$index.'_level');
if (!isset($inlevel))
break;
$categoryid=qa_get_category_field_value('uc_'.$index.'_cat');
$categoryid = qa_get_category_field_value('uc_'.$index.'_cat');
if (strlen($categoryid) && strlen($inlevel))
$inuserlevels[]=array(
$inuserlevels[] = array(
'entitytype' => QA_ENTITY_CATEGORY,
'entityid' => $categoryid,
'level' => min($maxlevelassign, (int)$inlevel),
......@@ -235,7 +241,7 @@
if (empty($errors))
qa_redirect(qa_request());
list($useraccount, $userprofile, $userlevels)=qa_db_select_with_pending(
list($useraccount, $userprofile, $userlevels) = qa_db_select_with_pending(
qa_db_user_account_selectspec($userid, true),
qa_db_user_profile_selectspec($userid, true),
qa_db_user_levels_selectspec($userid, true, true)
......@@ -246,7 +252,7 @@
if (qa_clicked('doapprove') || qa_clicked('doblock') || qa_clicked('dounblock') || qa_clicked('dohideall') || qa_clicked('dodelete')) {
if (!qa_check_form_security_code('user-'.$handle, qa_post_text('code')))
$errors['page']=qa_lang_html('misc/form_security_again');
$errors['page'] = qa_lang_html('misc/form_security_again');
else {
if ($approvebutton && qa_clicked('doapprove')) {
......@@ -255,7 +261,7 @@
qa_redirect(qa_request());
}
if (isset($maxlevelassign) && ($maxuserlevel<QA_USER_LEVEL_MODERATOR)) {
if (isset($maxlevelassign) && ($maxuserlevel < QA_USER_LEVEL_MODERATOR)) {
if (qa_clicked('doblock')) {
require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
......@@ -274,7 +280,7 @@
require_once QA_INCLUDE_DIR.'qa-db-admin.php';
require_once QA_INCLUDE_DIR.'qa-app-posts.php';
$postids=qa_db_get_user_visible_postids($userid);
$postids = qa_db_get_user_visible_postids($userid);
foreach ($postids as $postid)
qa_post_set_hidden($postid, true, $loginuserid);
......@@ -282,7 +288,7 @@
qa_redirect(qa_request());
}
if (qa_clicked('dodelete') && ($loginlevel>=QA_USER_LEVEL_ADMIN)) {
if (qa_clicked('dodelete') && ($loginlevel >= QA_USER_LEVEL_ADMIN)) {
require_once QA_INCLUDE_DIR.'qa-app-users-edit.php';
qa_delete_user($userid);
......@@ -300,13 +306,13 @@
if (qa_clicked('dowallpost')) {
$inmessage=qa_post_text('message');
$inmessage = qa_post_text('message');
if (!strlen($inmessage))
$errors['message']=qa_lang('profile/post_wall_empty');
$errors['message'] = qa_lang('profile/post_wall_empty');
elseif (!qa_check_form_security_code('wall-'.$useraccount['handle'], qa_post_text('code')))
$errors['message']=qa_lang_html('misc/form_security_again');
$errors['message'] = qa_lang_html('misc/form_security_again');
elseif (!$wallposterrorhtml) {
qa_wall_add_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $userid, $useraccount['handle'], $inmessage, '');
......@@ -318,13 +324,13 @@
// Process bonus setting button
if ( ($loginlevel>=QA_USER_LEVEL_ADMIN) && qa_clicked('dosetbonus') ) {
if ( ($loginlevel >= QA_USER_LEVEL_ADMIN) && qa_clicked('dosetbonus') ) {
require_once QA_INCLUDE_DIR.'qa-db-points.php';
$inbonus=(int)qa_post_text('bonus');
$inbonus = (int)qa_post_text('bonus');
if (!qa_check_form_security_code('user-activity-'.$handle, qa_post_text('code')))
$errors['page']=qa_lang_html('misc/form_security_again');
$errors['page'] = qa_lang_html('misc/form_security_again');
else {
qa_db_points_set_bonus($userid, $inbonus);
......@@ -336,20 +342,20 @@
// Prepare content for theme
$qa_content=qa_content_prepare();
$qa_content = qa_content_prepare();
$qa_content['title']=qa_lang_html_sub('profile/user_x', $userhtml);
$qa_content['error']=@$errors['page'];
$qa_content['title'] = qa_lang_html_sub('profile/user_x', $userhtml);
$qa_content['error'] = @$errors['page'];
if (isset($loginuserid) && !QA_FINAL_EXTERNAL_USERS) {
$favoritemap=qa_get_favorite_non_qs_map();
$favorite=@$favoritemap['user'][$useraccount['userid']];
$favoritemap = qa_get_favorite_non_qs_map();
$favorite = @$favoritemap['user'][$useraccount['userid']];
$qa_content['favorite']=qa_favorite_form(QA_ENTITY_USER, $useraccount['userid'], $favorite,
$qa_content['favorite'] = qa_favorite_form(QA_ENTITY_USER, $useraccount['userid'], $favorite,
qa_lang_sub($favorite ? 'main/remove_x_favorites' : 'users/add_user_x_favorites', $handle));
}
$qa_content['script_rel'][]='qa-content/qa-user.js?'.QA_VERSION;
$qa_content['script_rel'][] = 'qa-content/qa-user.js?'.QA_VERSION;
// General information about the user, only available if we're using internal user management
......@@ -358,7 +364,7 @@
$membertime = qa_time_to_string(qa_opt('db_time')-$useraccount['created']);
$joindate = qa_when_to_html($useraccount['created'], 0);
$qa_content['form_profile']=array(
$qa_content['form_profile'] = array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'style' => 'wide',
......@@ -399,8 +405,8 @@
// Private message link
if ( qa_opt('allow_private_messages') && isset($loginuserid) && ($loginuserid!=$userid) && !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES) && !$userediting )
$qa_content['form_profile']['fields']['level']['value'].=strtr(qa_lang_html('profile/send_private_message'), array(
if ( qa_opt('allow_private_messages') && isset($loginuserid) && ($loginuserid != $userid) && !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES) && !$userediting )
$qa_content['form_profile']['fields']['level']['value'] .= strtr(qa_lang_html('profile/send_private_message'), array(
'^1' => '<a href="'.qa_path_html('message/'.$handle).'">',
'^2' => '</a>',
));
......@@ -411,25 +417,25 @@
if ($userediting) {
if (isset($maxlevelassign)) {
$qa_content['form_profile']['fields']['level']['type']='select';
$qa_content['form_profile']['fields']['level']['type'] = 'select';
$showlevels=array(QA_USER_LEVEL_BASIC);
$showlevels = array(QA_USER_LEVEL_BASIC);
if (qa_opt('moderate_users'))
$showlevels[]=QA_USER_LEVEL_APPROVED;
$showlevels[] = QA_USER_LEVEL_APPROVED;
array_push($showlevels, QA_USER_LEVEL_EXPERT, QA_USER_LEVEL_EDITOR, QA_USER_LEVEL_MODERATOR, QA_USER_LEVEL_ADMIN, QA_USER_LEVEL_SUPER);
$leveloptions=array();
$catleveloptions=array('' => qa_lang_html('users/category_level_none'));
$leveloptions = array();
$catleveloptions = array('' => qa_lang_html('users/category_level_none'));
foreach ($showlevels as $showlevel)
if ($showlevel<=$maxlevelassign) {
$leveloptions[$showlevel]=qa_html(qa_user_level_string($showlevel));
if ($showlevel>QA_USER_LEVEL_BASIC)
$catleveloptions[$showlevel]=$leveloptions[$showlevel];
if ($showlevel <= $maxlevelassign) {
$leveloptions[$showlevel] = qa_html(qa_user_level_string($showlevel));
if ($showlevel > QA_USER_LEVEL_BASIC)
$catleveloptions[$showlevel] = $leveloptions[$showlevel];
}
$qa_content['form_profile']['fields']['level']['options']=$leveloptions;
$qa_content['form_profile']['fields']['level']['options'] = $leveloptions;
// Category-specific levels
......@@ -438,23 +444,23 @@
$catleveladd = strlen(qa_get('catleveladd')) > 0;
if ((!$catleveladd) && !count($userlevels))
$qa_content['form_profile']['fields']['level']['suffix']=strtr(qa_lang_html('users/category_level_add'), array(
$qa_content['form_profile']['fields']['level']['suffix'] = strtr(qa_lang_html('users/category_level_add'), array(
'^1' => '<a href="'.qa_path_html(qa_request(), array('state' => 'edit', 'catleveladd' => 1)).'">',
'^2' => '</a>',
));
else
$qa_content['form_profile']['fields']['level']['suffix']=qa_lang_html('users/level_in_general');
$qa_content['form_profile']['fields']['level']['suffix'] = qa_lang_html('users/level_in_general');
if ($catleveladd || count($userlevels))
$userlevels[]=array('entitytype' => QA_ENTITY_CATEGORY);
$userlevels[] = array('entitytype' => QA_ENTITY_CATEGORY);
$index=0;
$index = 0;
foreach ($userlevels as $userlevel)
if ($userlevel['entitytype']==QA_ENTITY_CATEGORY) {
if ($userlevel['entitytype'] == QA_ENTITY_CATEGORY) {
$index++;
$id='ls_'.+$index;
$id = 'ls_'.+$index;
$qa_content['form_profile']['fields']['uc_'.$index.'_level']=array(
$qa_content['form_profile']['fields']['uc_'.$index.'_level'] = array(
'label' => qa_lang_html('users/category_level_label'),
'type' => 'select',
'tags' => 'name="uc_'.$index.'_level" id="'.qa_html($id).'" onchange="this.qa_prev=this.options[this.selectedIndex].value;"',
......@@ -463,12 +469,12 @@
'suffix' => qa_lang_html('users/category_level_in'),
);
$qa_content['form_profile']['fields']['uc_'.$index.'_cat']=array();
$qa_content['form_profile']['fields']['uc_'.$index.'_cat'] = array();
if (isset($userlevel['entityid']))
$fieldnavcategories=qa_db_select_with_pending(qa_db_category_nav_selectspec($userlevel['entityid'], true));
$fieldnavcategories = qa_db_select_with_pending(qa_db_category_nav_selectspec($userlevel['entityid'], true));
else
$fieldnavcategories=$navcategories;
$fieldnavcategories = $navcategories;
qa_set_up_category_field($qa_content, $qa_content['form_profile']['fields']['uc_'.$index.'_cat'],
'uc_'.$index.'_cat', $fieldnavcategories, @$userlevel['entityid'], true, true);
......@@ -476,7 +482,7 @@
unset($qa_content['form_profile']['fields']['uc_'.$index.'_cat']['note']);
}
$qa_content['script_lines'][]=array(
$qa_content['script_lines'][] = array(
"function qa_update_category_levels()",
"{",
"\tglob=document.getElementById('level_select');",
......@@ -497,44 +503,47 @@
"}",
);
$qa_content['script_onloads'][]=array(
$qa_content['script_onloads'][] = array(
"qa_update_category_levels();",
);
$qa_content['form_profile']['fields']['level']['tags'].=' id="level_select" onchange="qa_update_category_levels();"';
$qa_content['form_profile']['fields']['level']['tags'] .= ' id="level_select" onchange="qa_update_category_levels();"';
}
}
} else {
foreach ($userlevels as $userlevel)
if ( ($userlevel['entitytype']==QA_ENTITY_CATEGORY) && ($userlevel['level']>$useraccount['level']) )
$qa_content['form_profile']['fields']['level']['value'].='<br/>'.
}
else {
foreach ($userlevels as $userlevel) {
if ( $userlevel['entitytype'] == QA_ENTITY_CATEGORY && $userlevel['level'] > $useraccount['level'] ) {
$qa_content['form_profile']['fields']['level']['value'] .= '<br/>'.
strtr(qa_lang_html('users/level_for_category'), array(
'^1' => qa_html(qa_user_level_string($userlevel['level'])),
'^2' => '<a href="'.qa_path_html(implode('/', array_reverse(explode('/', $userlevel['backpath'])))).'">'.qa_html($userlevel['title']).'</a>',
));
}
}
}
// Show any extra privileges due to user's level or their points
$showpermits=array();
$permitoptions=qa_get_permit_options();
$showpermits = array();
$permitoptions = qa_get_permit_options();
foreach ($permitoptions as $permitoption)
if ( // if not available to approved and email confirmed users with no points, but yes available to the user, it's something special
qa_permit_error($permitoption, $userid, QA_USER_LEVEL_APPROVED, QA_USER_FLAGS_EMAIL_CONFIRMED, 0) &&
!qa_permit_error($permitoption, $userid, $useraccount['level'], $useraccount['flags'], $userpoints['points'])
) {
if ($permitoption=='permit_retag_cat')
$showpermits[]=qa_lang(qa_using_categories() ? 'profile/permit_recat' : 'profile/permit_retag');
if ($permitoption == 'permit_retag_cat')
$showpermits[] = qa_lang(qa_using_categories() ? 'profile/permit_recat' : 'profile/permit_retag');
else
$showpermits[]=qa_lang('profile/'.$permitoption); // then show it as an extra priviliege
$showpermits[] = qa_lang('profile/'.$permitoption); // then show it as an extra priviliege
}
if (count($showpermits))
$qa_content['form_profile']['fields']['permits']=array(
$qa_content['form_profile']['fields']['permits'] = array(
'type' => 'static',
'label' => qa_lang_html('profile/extra_privileges'),
'value' => qa_html(implode("\n", $showpermits), true),
......@@ -546,11 +555,11 @@
// Show email address only if we're an administrator
if (($loginlevel >= QA_USER_LEVEL_ADMIN) && !qa_user_permit_error()) {
$doconfirms = qa_opt('confirm_user_emails') && ($useraccount['level']<QA_USER_LEVEL_EXPERT);
$doconfirms = qa_opt('confirm_user_emails') && $useraccount['level'] < QA_USER_LEVEL_EXPERT;
$isconfirmed = ($useraccount['flags'] & QA_USER_FLAGS_EMAIL_CONFIRMED) > 0;
$htmlemail = qa_html(isset($inemail) ? $inemail : $useraccount['email']);
$qa_content['form_profile']['fields']['email']=array(
$qa_content['form_profile']['fields']['email'] = array(
'type' => $userediting ? 'text' : 'static',
'label' => qa_lang_html('users/email_label'),
'tags' => 'name="email"',
......@@ -566,8 +575,8 @@
// Show IP addresses and times for last login or write - only if we're a moderator or higher
if (($loginlevel>=QA_USER_LEVEL_MODERATOR) && !qa_user_permit_error()) {
$qa_content['form_profile']['fields']['lastlogin']=array(
if (($loginlevel >= QA_USER_LEVEL_MODERATOR) && !qa_user_permit_error()) {
$qa_content['form_profile']['fields']['lastlogin'] = array(
'type' => 'static',
'label' => qa_lang_html('users/last_login_label'),
'value' =>
......@@ -580,7 +589,7 @@
);
if (isset($useraccount['written']))
$qa_content['form_profile']['fields']['lastwrite']=array(
$qa_content['form_profile']['fields']['lastwrite'] = array(
'type' => 'static',
'label' => qa_lang_html('users/last_write_label'),
'value' =>
......@@ -599,37 +608,37 @@
// Show other profile fields
$fieldsediting=$fieldseditable && $userediting;
$fieldsediting = $fieldseditable && $userediting;
foreach ($userfields as $userfield) {
if (($userfield['flags'] & QA_FIELD_FLAGS_LINK_URL) && !$fieldsediting)
$valuehtml=qa_url_to_html_link(@$userprofile[$userfield['title']], qa_opt('links_in_new_window'));
$valuehtml = qa_url_to_html_link(@$userprofile[$userfield['title']], qa_opt('links_in_new_window'));
else {
$value=@$inprofile[$userfield['fieldid']];
$value = @$inprofile[$userfield['fieldid']];
if (!isset($value))
$value=@$userprofile[$userfield['title']];
$value = @$userprofile[$userfield['title']];
$valuehtml=qa_html($value, (($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) && !$fieldsediting));
$valuehtml = qa_html($value, (($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) && !$fieldsediting));
}
$label=trim(qa_user_userfield_label($userfield), ':');
$label = trim(qa_user_userfield_label($userfield), ':');
if (strlen($label))
$label.=':';
$label .= ':';
$notehtml=null;
$notehtml = null;
if (isset($userfield['permit']) && !$userediting) {
if ($userfield['permit']<=QA_PERMIT_ADMINS)
$notehtml=qa_lang_html('users/only_shown_admins');
elseif ($userfield['permit']<=QA_PERMIT_MODERATORS)
$notehtml=qa_lang_html('users/only_shown_moderators');
elseif ($userfield['permit']<=QA_PERMIT_EDITORS)
$notehtml=qa_lang_html('users/only_shown_editors');
elseif ($userfield['permit']<=QA_PERMIT_EXPERTS)
$notehtml=qa_lang_html('users/only_shown_experts');
if ($userfield['permit'] <= QA_PERMIT_ADMINS)
$notehtml = qa_lang_html('users/only_shown_admins');
elseif ($userfield['permit'] <= QA_PERMIT_MODERATORS)
$notehtml = qa_lang_html('users/only_shown_moderators');
elseif ($userfield['permit'] <= QA_PERMIT_EDITORS)
$notehtml = qa_lang_html('users/only_shown_editors');
elseif ($userfield['permit'] <= QA_PERMIT_EXPERTS)
$notehtml = qa_lang_html('users/only_shown_experts');
}
$qa_content['form_profile']['fields'][$userfield['title']]=array(
$qa_content['form_profile']['fields'][$userfield['title']] = array(
'type' => $fieldsediting ? 'text' : 'static',
'label' => qa_html($label),
'tags' => 'name="field_'.$userfield['fieldid'].'"',
......@@ -650,14 +659,14 @@
(qa_opt('avatar_allow_gravatar') && ($useraccount['flags'] & QA_USER_FLAGS_SHOW_GRAVATAR)) ||
(qa_opt('avatar_allow_upload') && (($useraccount['flags'] & QA_USER_FLAGS_SHOW_AVATAR)) && isset($useraccount['avatarblobid']))
) {
$qa_content['form_profile']['fields']['removeavatar']=array(
$qa_content['form_profile']['fields']['removeavatar'] = array(
'type' => 'checkbox',
'label' => qa_lang_html('users/remove_avatar'),
'tags' => 'name="removeavatar"',
);
}
$qa_content['form_profile']['buttons']=array(
$qa_content['form_profile']['buttons'] = array(
'save' => array(
'tags' => 'onclick="qa_show_waiting_after(this, false);"',
'label' => qa_lang_html('users/save_user'),
......@@ -669,75 +678,83 @@
),
);
$qa_content['form_profile']['hidden']=array(
$qa_content['form_profile']['hidden'] = array(
'dosave' => '1',
'code' => qa_get_form_security_code('user-edit-'.$handle),
);
} elseif ($usereditbutton) {
$qa_content['form_profile']['buttons']=array();
}
elseif ($usereditbutton) {
$qa_content['form_profile']['buttons'] = array();
if ($approvebutton)
$qa_content['form_profile']['buttons']['approve']=array(
if ($approvebutton) {
$qa_content['form_profile']['buttons']['approve'] = array(
'tags' => 'name="doapprove"',
'label' => qa_lang_html('users/approve_user_button'),
);
}
$qa_content['form_profile']['buttons']['edit']=array(
$qa_content['form_profile']['buttons']['edit'] = array(
'tags' => 'name="doedit"',
'label' => qa_lang_html('users/edit_user_button'),
);
if (isset($maxlevelassign) && ($useraccount['level']<QA_USER_LEVEL_MODERATOR)) {
if (isset($maxlevelassign) && $useraccount['level'] < QA_USER_LEVEL_MODERATOR) {
if ($useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED) {
$qa_content['form_profile']['buttons']['unblock']=array(
$qa_content['form_profile']['buttons']['unblock'] = array(
'tags' => 'name="dounblock"',
'label' => qa_lang_html('users/unblock_user_button'),
);
if (!qa_user_permit_error('permit_hide_show'))
$qa_content['form_profile']['buttons']['hideall']=array(
if (!qa_user_permit_error('permit_hide_show')) {
$qa_content['form_profile']['buttons']['hideall'] = array(
'tags' => 'name="dohideall" onclick="qa_show_waiting_after(this, false);"',
'label' => qa_lang_html('users/hide_all_user_button'),
);
}
if ($loginlevel>=QA_USER_LEVEL_ADMIN)
$qa_content['form_profile']['buttons']['delete']=array(
if ($loginlevel >= QA_USER_LEVEL_ADMIN) {
$qa_content['form_profile']['buttons']['delete'] = array(
'tags' => 'name="dodelete" onclick="qa_show_waiting_after(this, false);"',
'label' => qa_lang_html('users/delete_user_button'),
);
}
} else
$qa_content['form_profile']['buttons']['block']=array(
}
else {
$qa_content['form_profile']['buttons']['block'] = array(
'tags' => 'name="doblock"',
'label' => qa_lang_html('users/block_user_button'),
);
}
$qa_content['form_profile']['hidden']=array(
$qa_content['form_profile']['hidden'] = array(
'code' => qa_get_form_security_code('user-'.$handle),
);
}
} elseif (isset($loginuserid) && ($loginuserid==$userid))
$qa_content['form_profile']['buttons']=array(
}
elseif (isset($loginuserid) && ($loginuserid == $userid)) {
$qa_content['form_profile']['buttons'] = array(
'account' => array(
'tags' => 'name="doaccount"',
'label' => qa_lang_html('users/edit_profile'),
),
);
}
if (!is_array($qa_content['form_profile']['fields']['removeavatar']))
unset($qa_content['form_profile']['fields']['removeavatar']);
$qa_content['raw']['account']=$useraccount; // for plugin layers to access
$qa_content['raw']['profile']=$userprofile;
$qa_content['raw']['account'] = $useraccount; // for plugin layers to access
$qa_content['raw']['profile'] = $userprofile;
}
// Information about user activity, available also with single sign-on integration
$qa_content['form_activity']=array(
$qa_content['form_activity'] = array(
'title' => '<a name="activity">'.qa_lang_html_sub('profile/activity_by_x', $userhtml).'</a>',
'style' => 'wide',
......@@ -755,7 +772,7 @@
'points' => array(
'type' => 'static',
'label' => qa_lang_html('profile/score'),
'value' => (@$userpoints['points']==1)
'value' => (@$userpoints['points'] == 1)
? qa_lang_html_sub('main/1_point', '<span class="qa-uf-user-points">1</span>', '1')
: qa_lang_html_sub('main/x_points', '<span class="qa-uf-user-points">'.qa_html(number_format(@$userpoints['points'])).'</span>'),
'id' => 'points',
......@@ -784,28 +801,29 @@
),
);
if ($loginlevel>=QA_USER_LEVEL_ADMIN) {
$qa_content['form_activity']['tags']='method="post" action="'.qa_self_html().'"';
if ($loginlevel >= QA_USER_LEVEL_ADMIN) {
$qa_content['form_activity']['tags'] = 'method="post" action="'.qa_self_html().'"';
$qa_content['form_activity']['buttons']=array(
$qa_content['form_activity']['buttons'] = array(
'setbonus' => array(
'tags' => 'name="dosetbonus"',
'label' => qa_lang_html('profile/set_bonus_button'),
),
);
$qa_content['form_activity']['hidden']=array(
$qa_content['form_activity']['hidden'] = array(
'code' => qa_get_form_security_code('user-activity-'.$handle),
);
} else
}
else
unset($qa_content['form_activity']['fields']['bonus']);
if (!isset($qa_content['form_activity']['fields']['title']['value']))
unset($qa_content['form_activity']['fields']['title']);
if (qa_opt('comment_on_qs') || qa_opt('comment_on_as')) { // only show comment count if comments are enabled
$qa_content['form_activity']['fields']['comments']=array(
$qa_content['form_activity']['fields']['comments'] = array(
'type' => 'static',
'label' => qa_lang_html('profile/comments'),
'value' => '<span class="qa-uf-user-c-posts">'.qa_html(number_format(@$userpoints['cposts'])).'</span>',
......@@ -814,58 +832,58 @@
}
if (qa_opt('voting_on_qs') || qa_opt('voting_on_as')) { // only show vote record if voting is enabled
$votedonvalue='';
$votedonvalue = '';
if (qa_opt('voting_on_qs')) {
$qvotes=@$userpoints['qupvotes']+@$userpoints['qdownvotes'];
$qvotes = @$userpoints['qupvotes']+@$userpoints['qdownvotes'];
$innervalue='<span class="qa-uf-user-q-votes">'.number_format($qvotes).'</span>';
$votedonvalue.=($qvotes==1) ? qa_lang_html_sub('main/1_question', $innervalue, '1')
$innervalue = '<span class="qa-uf-user-q-votes">'.number_format($qvotes).'</span>';
$votedonvalue .= ($qvotes == 1) ? qa_lang_html_sub('main/1_question', $innervalue, '1')
: qa_lang_html_sub('main/x_questions', $innervalue);
if (qa_opt('voting_on_as'))
$votedonvalue.=', ';
$votedonvalue .= ', ';
}
if (qa_opt('voting_on_as')) {
$avotes=@$userpoints['aupvotes']+@$userpoints['adownvotes'];
$avotes = @$userpoints['aupvotes']+@$userpoints['adownvotes'];
$innervalue='<span class="qa-uf-user-a-votes">'.number_format($avotes).'</span>';
$votedonvalue.=($avotes==1) ? qa_lang_html_sub('main/1_answer', $innervalue, '1')
$innervalue = '<span class="qa-uf-user-a-votes">'.number_format($avotes).'</span>';
$votedonvalue .= ($avotes == 1) ? qa_lang_html_sub('main/1_answer', $innervalue, '1')
: qa_lang_html_sub('main/x_answers', $innervalue);
}
$qa_content['form_activity']['fields']['votedon']=array(
$qa_content['form_activity']['fields']['votedon'] = array(
'type' => 'static',
'label' => qa_lang_html('profile/voted_on'),
'value' => $votedonvalue,
'id' => 'votedon',
);
$upvotes=@$userpoints['qupvotes']+@$userpoints['aupvotes'];
$innervalue='<span class="qa-uf-user-upvotes">'.number_format($upvotes).'</span>';
$votegavevalue=(($upvotes==1) ? qa_lang_html_sub('profile/1_up_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_up_votes', $innervalue)).', ';
$upvotes = @$userpoints['qupvotes']+@$userpoints['aupvotes'];
$innervalue = '<span class="qa-uf-user-upvotes">'.number_format($upvotes).'</span>';
$votegavevalue = (($upvotes == 1) ? qa_lang_html_sub('profile/1_up_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_up_votes', $innervalue)).', ';
$downvotes=@$userpoints['qdownvotes']+@$userpoints['adownvotes'];
$innervalue='<span class="qa-uf-user-downvotes">'.number_format($downvotes).'</span>';
$votegavevalue.=($downvotes==1) ? qa_lang_html_sub('profile/1_down_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_down_votes', $innervalue);
$downvotes = @$userpoints['qdownvotes']+@$userpoints['adownvotes'];
$innervalue = '<span class="qa-uf-user-downvotes">'.number_format($downvotes).'</span>';
$votegavevalue .= ($downvotes == 1) ? qa_lang_html_sub('profile/1_down_vote', $innervalue, '1') : qa_lang_html_sub('profile/x_down_votes', $innervalue);
$qa_content['form_activity']['fields']['votegave']=array(
$qa_content['form_activity']['fields']['votegave'] = array(
'type' => 'static',
'label' => qa_lang_html('profile/gave_out'),
'value' => $votegavevalue,
'id' => 'votegave',
);
$innervalue='<span class="qa-uf-user-upvoteds">'.number_format(@$userpoints['upvoteds']).'</span>';
$votegotvalue=((@$userpoints['upvoteds']==1) ? qa_lang_html_sub('profile/1_up_vote', $innervalue, '1')
$innervalue = '<span class="qa-uf-user-upvoteds">'.number_format(@$userpoints['upvoteds']).'</span>';
$votegotvalue = ((@$userpoints['upvoteds'] == 1) ? qa_lang_html_sub('profile/1_up_vote', $innervalue, '1')
: qa_lang_html_sub('profile/x_up_votes', $innervalue)).', ';
$innervalue='<span class="qa-uf-user-downvoteds">'.number_format(@$userpoints['downvoteds']).'</span>';
$votegotvalue.=(@$userpoints['downvoteds']==1) ? qa_lang_html_sub('profile/1_down_vote', $innervalue, '1')
$innervalue = '<span class="qa-uf-user-downvoteds">'.number_format(@$userpoints['downvoteds']).'</span>';
$votegotvalue .= (@$userpoints['downvoteds'] == 1) ? qa_lang_html_sub('profile/1_down_vote', $innervalue, '1')
: qa_lang_html_sub('profile/x_down_votes', $innervalue);
$qa_content['form_activity']['fields']['votegot']=array(
$qa_content['form_activity']['fields']['votegot'] = array(
'type' => 'static',
'label' => qa_lang_html('profile/received'),
'value' => $votegotvalue,
......@@ -874,16 +892,16 @@
}
if (@$userpoints['points'])
$qa_content['form_activity']['fields']['points']['value'].=
$qa_content['form_activity']['fields']['points']['value'] .=
qa_lang_html_sub('profile/ranked_x', '<span class="qa-uf-user-rank">'.number_format($userrank).'</span>');
if (@$userpoints['aselects'])
$qa_content['form_activity']['fields']['questions']['value'].=($userpoints['aselects']==1)
$qa_content['form_activity']['fields']['questions']['value'] .= ($userpoints['aselects'] == 1)
? qa_lang_html_sub('profile/1_with_best_chosen', '<span class="qa-uf-user-q-selects">1</span>', '1')
: qa_lang_html_sub('profile/x_with_best_chosen', '<span class="qa-uf-user-q-selects">'.number_format($userpoints['aselects']).'</span>');
if (@$userpoints['aselecteds'])
$qa_content['form_activity']['fields']['answers']['value'].=($userpoints['aselecteds']==1)
$qa_content['form_activity']['fields']['answers']['value'] .= ($userpoints['aselecteds'] == 1)
? qa_lang_html_sub('profile/1_chosen_as_best', '<span class="qa-uf-user-a-selecteds">1</span>', '1')
: qa_lang_html_sub('profile/x_chosen_as_best', '<span class="qa-uf-user-a-selecteds">'.number_format($userpoints['aselecteds']).'</span>');
......@@ -891,15 +909,15 @@
// For plugin layers to access
$qa_content['raw']['userid']=$userid;
$qa_content['raw']['points']=$userpoints;
$qa_content['raw']['rank']=$userrank;
$qa_content['raw']['userid'] = $userid;
$qa_content['raw']['points'] = $userpoints;
$qa_content['raw']['rank'] = $userrank;
// Wall posts
if ((!QA_FINAL_EXTERNAL_USERS) && qa_opt('allow_user_walls')) {
$qa_content['message_list']=array(
if (!QA_FINAL_EXTERNAL_USERS && qa_opt('allow_user_walls')) {
$qa_content['message_list'] = array(
'title' => '<a name="wall">'.qa_lang_html_sub('profile/wall_for_x', $userhtml).'</a>',
'tags' => 'id="wallmessages"',
......@@ -919,10 +937,10 @@
);
if ($wallposterrorhtml)
$qa_content['message_list']['error']=$wallposterrorhtml; // an error that means we are not allowed to post
$qa_content['message_list']['error'] = $wallposterrorhtml; // an error that means we are not allowed to post
else {
$qa_content['message_list']['form']['fields']=array(
$qa_content['message_list']['form']['fields'] = array(
'message' => array(
'tags' => 'name="message" id="message"',
'value' => qa_html(@$inmessage, false),
......@@ -931,7 +949,7 @@
),
);
$qa_content['message_list']['form']['buttons']=array(
$qa_content['message_list']['form']['buttons'] = array(
'post' => array(
'tags' => 'name="dowallpost" onclick="return qa_submit_wall_post(this, true);"',
'label' => qa_lang_html('profile/post_wall_button'),
......@@ -940,17 +958,17 @@
}
foreach ($usermessages as $message)
$qa_content['message_list']['messages'][]=qa_wall_post_view($message);
$qa_content['message_list']['messages'][] = qa_wall_post_view($message);
if ($useraccount['wallposts']>count($usermessages))
$qa_content['message_list']['messages'][]=qa_wall_view_more_link($handle, count($usermessages));
if ($useraccount['wallposts'] > count($usermessages))
$qa_content['message_list']['messages'][] = qa_wall_view_more_link($handle, count($usermessages));
}
// Sub menu for navigation in user pages
$qa_content['navigation']['sub']=qa_user_sub_navigation($handle, 'profile',
isset($loginuserid) && ($loginuserid==(QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid'])));
$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'profile', $ismyuser);
return $qa_content;
......
......@@ -35,15 +35,15 @@
// $handle, $userhtml are already set by qa-page-user.php - also $userid if using external user integration
$start=qa_get_start();
$start = qa_get_start();
// Find the questions for this user
$loginuserid=qa_get_logged_in_userid();
$identifier=QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
$loginuserid = qa_get_logged_in_userid();
$identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
list($useraccount, $userpoints, $questions)=qa_db_select_with_pending(
list($useraccount, $userpoints, $questions) = qa_db_select_with_pending(
QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false),
qa_db_user_points_selectspec($identifier),
qa_db_user_recent_qs_selectspec($loginuserid, $identifier, qa_opt_if_loaded('page_size_qs'), $start)
......@@ -55,25 +55,25 @@
// Get information on user questions
$pagesize=qa_opt('page_size_qs');
$count=(int)@$userpoints['qposts'];
$questions=array_slice($questions, 0, $pagesize);
$usershtml=qa_userids_handles_html($questions, false);
$pagesize = qa_opt('page_size_qs');
$count = (int)@$userpoints['qposts'];
$questions = array_slice($questions, 0, $pagesize);
$usershtml = qa_userids_handles_html($questions, false);
// Prepare content for theme
$qa_content=qa_content_prepare(true);
$qa_content = qa_content_prepare(true);
if (count($questions))
$qa_content['title']=qa_lang_html_sub('profile/questions_by_x', $userhtml);
$qa_content['title'] = qa_lang_html_sub('profile/questions_by_x', $userhtml);
else
$qa_content['title']=qa_lang_html_sub('profile/no_questions_by_x', $userhtml);
$qa_content['title'] = qa_lang_html_sub('profile/no_questions_by_x', $userhtml);
// Recent questions by this user
$qa_content['q_list']['form']=array(
$qa_content['q_list']['form'] = array(
'tags' => 'method="post" action="'.qa_self_html().'"',
'hidden' => array(
......@@ -81,23 +81,23 @@
),
);
$qa_content['q_list']['qs']=array();
$qa_content['q_list']['qs'] = array();
$htmldefaults=qa_post_html_defaults('Q');
$htmldefaults['whoview']=false;
$htmldefaults['avatarsize']=0;
$htmldefaults = qa_post_html_defaults('Q');
$htmldefaults['whoview'] = false;
$htmldefaults['avatarsize'] = 0;
foreach ($questions as $question)
$qa_content['q_list']['qs'][]=qa_post_html_fields($question, $loginuserid, qa_cookie_get(),
$qa_content['q_list']['qs'][] = qa_post_html_fields($question, $loginuserid, qa_cookie_get(),
$usershtml, null, qa_post_html_options($question, $htmldefaults));
$qa_content['page_links']=qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
// Sub menu for navigation in user pages
$qa_content['navigation']['sub']=qa_user_sub_navigation($handle, 'questions',
isset($loginuserid) && ($loginuserid==(QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid'])));
$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'questions', $ismyuser);
return $qa_content;
......
......@@ -41,12 +41,12 @@
// $handle, $userhtml are already set by qa-page-user.php
$start=qa_get_start();
$start = qa_get_start();
// Find the questions for this user
list($useraccount, $usermessages)=qa_db_select_with_pending(
list($useraccount, $usermessages) = qa_db_select_with_pending(
qa_db_user_account_selectspec($handle, false),
qa_db_recent_messages_selectspec(null, null, $handle, false, qa_opt_if_loaded('page_size_wall'), $start)
);
......@@ -57,24 +57,24 @@
// Perform pagination
$pagesize=qa_opt('page_size_wall');
$count=$useraccount['wallposts'];
$loginuserid=qa_get_logged_in_userid();
$pagesize = qa_opt('page_size_wall');
$count = $useraccount['wallposts'];
$loginuserid = qa_get_logged_in_userid();
$usermessages=array_slice($usermessages, 0, $pagesize);
$usermessages=qa_wall_posts_add_rules($usermessages, $start);
$usermessages = array_slice($usermessages, 0, $pagesize);
$usermessages = qa_wall_posts_add_rules($usermessages, $start);
// Process deleting or adding a wall post (similar but not identical code to qq-page-user-profile.php)
$errors=array();
$errors = array();
$wallposterrorhtml=qa_wall_error_html($loginuserid, $useraccount['userid'], $useraccount['flags']);
$wallposterrorhtml = qa_wall_error_html($loginuserid, $useraccount['userid'], $useraccount['flags']);
foreach ($usermessages as $message)
if ($message['deleteable'] && qa_clicked('m'.$message['messageid'].'_dodelete')) {
if (!qa_check_form_security_code('wall-'.$useraccount['handle'], qa_post_text('code')))
$errors['page']=qa_lang_html('misc/form_security_again');
$errors['page'] = qa_lang_html('misc/form_security_again');
else {
qa_wall_delete_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $message);
......@@ -83,13 +83,13 @@
}
if (qa_clicked('dowallpost')) {
$inmessage=qa_post_text('message');
$inmessage = qa_post_text('message');
if (!strlen($inmessage))
$errors['message']=qa_lang('profile/post_wall_empty');
$errors['message'] = qa_lang('profile/post_wall_empty');
elseif (!qa_check_form_security_code('wall-'.$useraccount['handle'], qa_post_text('code')))
$errors['message']=qa_lang_html('misc/form_security_again');
$errors['message'] = qa_lang_html('misc/form_security_again');
elseif (!$wallposterrorhtml) {
qa_wall_add_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $useraccount['userid'], $useraccount['handle'], $inmessage, '');
......@@ -100,14 +100,14 @@
// Prepare content for theme
$qa_content=qa_content_prepare();
$qa_content = qa_content_prepare();
$qa_content['title']=qa_lang_html_sub('profile/wall_for_x', $userhtml);
$qa_content['error']=@$errors['page'];
$qa_content['title'] = qa_lang_html_sub('profile/wall_for_x', $userhtml);
$qa_content['error'] = @$errors['page'];
$qa_content['script_rel'][]='qa-content/qa-user.js?'.QA_VERSION;
$qa_content['script_rel'][] = 'qa-content/qa-user.js?'.QA_VERSION;
$qa_content['message_list']=array(
$qa_content['message_list'] = array(
'tags' => 'id="wallmessages"',
'form' => array(
......@@ -126,10 +126,10 @@
if ($start==0) { // only allow posting on first page
if ($wallposterrorhtml)
$qa_content['message_list']['error']=$wallposterrorhtml; // an error that means we are not allowed to post
$qa_content['message_list']['error'] = $wallposterrorhtml; // an error that means we are not allowed to post
else {
$qa_content['message_list']['form']['fields']=array(
$qa_content['message_list']['form']['fields'] = array(
'message' => array(
'tags' => 'name="message" id="message"',
'value' => qa_html(@$inmessage, false),
......@@ -138,7 +138,7 @@
),
);
$qa_content['message_list']['form']['buttons']=array(
$qa_content['message_list']['form']['buttons'] = array(
'post' => array(
'tags' => 'name="dowallpost" onclick="return qa_submit_wall_post(this, false);"',
'label' => qa_lang_html('profile/post_wall_button'),
......@@ -148,15 +148,15 @@
}
foreach ($usermessages as $message)
$qa_content['message_list']['messages'][]=qa_wall_post_view($message);
$qa_content['message_list']['messages'][] = qa_wall_post_view($message);
$qa_content['page_links']=qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
// Sub menu for navigation in user pages
$qa_content['navigation']['sub']=qa_user_sub_navigation($handle, 'wall',
isset($loginuserid) && ($loginuserid==(QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid'])));
$qa_content['navigation']['sub'] = qa_user_sub_navigation( $handle, 'wall',
isset($loginuserid) && ($loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid'])) );
return $qa_content;
......
......@@ -32,25 +32,27 @@
// Determine the identify of the user
$handle=qa_request_part(1);
$handle = qa_request_part(1);
if (!strlen($handle)) {
$handle=qa_get_logged_in_handle();
qa_redirect(isset($handle) ? ('user/'.$handle) : 'users');
$handle = qa_get_logged_in_handle();
qa_redirect(isset($handle) ? 'user/'.$handle : 'users');
}
// Get the HTML to display for the handle, and if we're using external users, determine the userid
if (QA_FINAL_EXTERNAL_USERS) {
$userid=qa_handle_to_userid($handle);
$userid = qa_handle_to_userid($handle);
if (!isset($userid))
return include QA_INCLUDE_DIR.'qa-page-not-found.php';
$usershtml=qa_get_users_html(array($userid), false, qa_path_to_root(), true);
$userhtml=@$usershtml[$userid];
$usershtml = qa_get_users_html(array($userid), false, qa_path_to_root(), true);
$userhtml = @$usershtml[$userid];
} else
$userhtml=qa_html($handle);
}
else
$userhtml = qa_html($handle);
// Display the appropriate page based on the request
......@@ -58,30 +60,30 @@
switch (qa_request_part(2)) {
case 'wall':
qa_set_template('user-wall');
$qa_content=include QA_INCLUDE_DIR.'qa-page-user-wall.php';
$qa_content = include QA_INCLUDE_DIR.'qa-page-user-wall.php';
break;
case 'activity':
qa_set_template('user-activity');
$qa_content=include QA_INCLUDE_DIR.'qa-page-user-activity.php';
$qa_content = include QA_INCLUDE_DIR.'qa-page-user-activity.php';
break;
case 'questions':
qa_set_template('user-questions');
$qa_content=include QA_INCLUDE_DIR.'qa-page-user-questions.php';
$qa_content = include QA_INCLUDE_DIR.'qa-page-user-questions.php';
break;
case 'answers':
qa_set_template('user-answers');
$qa_content=include QA_INCLUDE_DIR.'qa-page-user-answers.php';
$qa_content = include QA_INCLUDE_DIR.'qa-page-user-answers.php';
break;
case null:
$qa_content=include QA_INCLUDE_DIR.'qa-page-user-profile.php';
$qa_content = include QA_INCLUDE_DIR.'qa-page-user-profile.php';
break;
default:
$qa_content=include QA_INCLUDE_DIR.'qa-page-not-found.php';
$qa_content = include QA_INCLUDE_DIR.'qa-page-not-found.php';
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment