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;
......
......@@ -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