Commit 426f5587 by Scott

Refactor messages code

parent 96e247ce
...@@ -619,14 +619,14 @@ ...@@ -619,14 +619,14 @@
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$fields=array('raw' => $message); $fields = array('raw' => $message);
$fields['tags']='id="m'.qa_html($message['messageid']).'"'; $fields['tags'] = 'id="m'.qa_html($message['messageid']).'"';
// Message content // Message content
$viewer=qa_load_viewer($message['content'], $message['format']); $viewer = qa_load_viewer($message['content'], $message['format']);
$fields['content']=$viewer->get_html($message['content'], $message['format'], array( $fields['content'] = $viewer->get_html($message['content'], $message['format'], array(
'blockwordspreg' => @$options['blockwordspreg'], 'blockwordspreg' => @$options['blockwordspreg'],
'showurllinks' => @$options['showurllinks'], 'showurllinks' => @$options['showurllinks'],
'linksnewwindow' => @$options['linksnewwindow'], 'linksnewwindow' => @$options['linksnewwindow'],
...@@ -634,14 +634,14 @@ ...@@ -634,14 +634,14 @@
// Set ordering of meta elements which can be language-specific // Set ordering of meta elements which can be language-specific
$fields['meta_order']=qa_lang_html('main/meta_order'); $fields['meta_order'] = qa_lang_html('main/meta_order');
$fields['what']=qa_lang_html('main/written'); $fields['what'] = qa_lang_html('main/written');
// When it was written // When it was written
if (@$options['whenview']) if (@$options['whenview'])
$fields['when']=qa_when_to_html($message['created'], @$options['fulldatedays']); $fields['when'] = qa_when_to_html($message['created'], @$options['fulldatedays']);
// Who wrote it, and their avatar // Who wrote it, and their avatar
......
...@@ -40,11 +40,11 @@ ...@@ -40,11 +40,11 @@
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
if ((!QA_FINAL_EXTERNAL_USERS) && qa_opt('allow_user_walls')) { if (!QA_FINAL_EXTERNAL_USERS && qa_opt('allow_user_walls')) {
if ( ($touserflags & QA_USER_FLAGS_NO_WALL_POSTS) && !(isset($fromuserid) && ($fromuserid==$touserid)) ) if ( ($touserflags & QA_USER_FLAGS_NO_WALL_POSTS) && !(isset($fromuserid) && $fromuserid == $touserid) )
return qa_lang_html('profile/post_wall_blocked'); return qa_lang_html('profile/post_wall_blocked');
else else {
switch (qa_user_permit_error('permit_post_wall', QA_LIMIT_WALL_POSTS)) { switch (qa_user_permit_error('permit_post_wall', QA_LIMIT_WALL_POSTS)) {
case 'limit': case 'limit':
return qa_lang_html('profile/post_wall_limit'); return qa_lang_html('profile/post_wall_limit');
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
return false; return false;
break; break;
} }
}
} }
return qa_lang_html('users/no_permission'); return qa_lang_html('users/no_permission');
...@@ -83,7 +84,7 @@ ...@@ -83,7 +84,7 @@
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-db-messages.php'; require_once QA_INCLUDE_DIR.'qa-db-messages.php';
$messageid=qa_db_message_create($userid, $touserid, $content, $format, true); $messageid = qa_db_message_create($userid, $touserid, $content, $format, true);
qa_db_user_recount_posts($touserid); qa_db_user_recount_posts($touserid);
qa_report_event('u_wall_post', $userid, $handle, $cookieid, array( qa_report_event('u_wall_post', $userid, $handle, $cookieid, array(
...@@ -126,18 +127,18 @@ ...@@ -126,18 +127,18 @@
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$userid=qa_get_logged_in_userid(); $userid = qa_get_logged_in_userid();
$userdeleteall=!(qa_user_permit_error('permit_hide_show') || qa_user_permit_error('permit_delete_hidden')); $userdeleteall = !(qa_user_permit_error('permit_hide_show') || qa_user_permit_error('permit_delete_hidden'));
// reuse "Hiding or showing any post" and "Deleting hidden posts" permissions // reuse "Hiding or showing any post" and "Deleting hidden posts" permissions
$userrecent=($start==0) && isset($userid); // User can delete all of the recent messages they wrote on someone's wall... $userrecent = $start == 0 && isset($userid); // User can delete all of the recent messages they wrote on someone's wall...
foreach ($usermessages as $key => $message) { foreach ($usermessages as $key => $message) {
if ($message['fromuserid']!=$userid) if ($message['fromuserid'] != $userid)
$userrecent=false; // ... until we come across one that they didn't write (which could be a reply) $userrecent = false; // ... until we come across one that they didn't write (which could be a reply)
$usermessages[$key]['deleteable'] = $usermessages[$key]['deleteable'] =
($message['touserid']==$userid) || // if it's this user's wall $message['touserid'] == $userid || // if it's this user's wall
($userrecent && ($message['fromuserid']==$userid)) || // if it's one the user wrote that no one replied to yet ($userrecent && $message['fromuserid'] == $userid) || // if it's one the user wrote that no one replied to yet
$userdeleteall; // if the user has enough permissions to delete from any wall $userdeleteall; // if the user has enough permissions to delete from any wall
} }
...@@ -153,12 +154,12 @@ ...@@ -153,12 +154,12 @@
{ {
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
$options=qa_message_html_defaults(); $options = qa_message_html_defaults();
$htmlfields=qa_message_html_fields($message, $options); $htmlfields = qa_message_html_fields($message, $options);
if ($message['deleteable']) if ($message['deleteable']) {
$htmlfields['form']=array( $htmlfields['form'] = array(
'style' => 'light', 'style' => 'light',
'buttons' => array( 'buttons' => array(
...@@ -169,6 +170,7 @@ ...@@ -169,6 +170,7 @@
), ),
), ),
); );
}
return $htmlfields; return $htmlfields;
} }
...@@ -179,8 +181,9 @@ ...@@ -179,8 +181,9 @@
Returns an element to add to $qa_content['message_list']['messages'] with a link to view all wall posts Returns an element to add to $qa_content['message_list']['messages'] with a link to view all wall posts
*/ */
{ {
$url = qa_path_html( 'user/'.$handle.'/wall', array('start' => $start) );
return array( return array(
'content' => '<a href="'.qa_path_html('user/'.$handle.'/wall', array('start' => $start)).'">'.qa_lang_html('profile/wall_view_more').'</a>', 'content' => '<a href="'.$url.'">'.qa_lang_html('profile/wall_view_more').'</a>',
); );
} }
......
...@@ -459,8 +459,14 @@ ...@@ -459,8 +459,14 @@
{ {
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return strlen($handle) ? ('<a href="'.qa_path_html('user/'.$handle).'" class="qa-user-link' if (!strlen($handle))
.($favorited ? ' qa-user-favorited' : '').($microformats ? ' url nickname' : '').'">'.qa_html($handle).'</a>') : ''; return '';
$url = qa_path_html('user/'.$handle);
$favclass = $favorited ? ' qa-user-favorited' : '';
$mfclass = $microformats ? ' url nickname' : '';
return '<a href="'.$url.'" class="qa-user-link'.$favclass.$mfclass.'">'.qa_html($handle).'</a>';
} }
......
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
require_once QA_INCLUDE_DIR.'qa-app-format.php'; require_once QA_INCLUDE_DIR.'qa-app-format.php';
require_once QA_INCLUDE_DIR.'qa-app-limits.php'; require_once QA_INCLUDE_DIR.'qa-app-limits.php';
$handle=qa_request_part(1); $handle = qa_request_part(1);
$loginuserid=qa_get_logged_in_userid(); $loginuserid = qa_get_logged_in_userid();
// Check we have a handle, we're not using Q2A's single-sign on integration and that we're logged in // Check we have a handle, we're not using Q2A's single-sign on integration and that we're logged in
...@@ -47,15 +47,15 @@ ...@@ -47,15 +47,15 @@
qa_redirect('users'); qa_redirect('users');
if (!isset($loginuserid)) { if (!isset($loginuserid)) {
$qa_content=qa_content_prepare(); $qa_content = qa_content_prepare();
$qa_content['error']=qa_insert_login_links(qa_lang_html('misc/message_must_login'), qa_request()); $qa_content['error'] = qa_insert_login_links(qa_lang_html('misc/message_must_login'), qa_request());
return $qa_content; return $qa_content;
} }
// Find the user profile and questions and answers for this handle // Find the user profile and questions and answers for this handle
list($toaccount, $torecent, $fromrecent)=qa_db_select_with_pending( list($toaccount, $torecent, $fromrecent) = qa_db_select_with_pending(
qa_db_user_account_selectspec($handle, false), qa_db_user_account_selectspec($handle, false),
qa_db_recent_messages_selectspec($loginuserid, true, $handle, false), qa_db_recent_messages_selectspec($loginuserid, true, $handle, false),
qa_db_recent_messages_selectspec($handle, false, $loginuserid, true) qa_db_recent_messages_selectspec($handle, false, $loginuserid, true)
...@@ -64,66 +64,66 @@ ...@@ -64,66 +64,66 @@
// Check the user exists and work out what can and can't be set (if not using single sign-on) // Check the user exists and work out what can and can't be set (if not using single sign-on)
if ( (!qa_opt('allow_private_messages')) || (!is_array($toaccount)) || ($toaccount['flags'] & QA_USER_FLAGS_NO_MESSAGES) ) if ( !qa_opt('allow_private_messages') || !is_array($toaccount) || ($toaccount['flags'] & QA_USER_FLAGS_NO_MESSAGES) )
return include QA_INCLUDE_DIR.'qa-page-not-found.php'; return include QA_INCLUDE_DIR.'qa-page-not-found.php';
// Check that we have permission and haven't reached the limit // Check that we have permission and haven't reached the limit
$errorhtml=null; $errorhtml = null;
switch (qa_user_permit_error(null, QA_LIMIT_MESSAGES)) { switch (qa_user_permit_error(null, QA_LIMIT_MESSAGES)) {
case 'limit': case 'limit':
$errorhtml=qa_lang_html('misc/message_limit'); $errorhtml = qa_lang_html('misc/message_limit');
break; break;
case false: case false:
break; break;
default: default:
$errorhtml=qa_lang_html('users/no_permission'); $errorhtml = qa_lang_html('users/no_permission');
break; break;
} }
if (isset($errorhtml)) { if (isset($errorhtml)) {
$qa_content=qa_content_prepare(); $qa_content = qa_content_prepare();
$qa_content['error']=$errorhtml; $qa_content['error'] = $errorhtml;
return $qa_content; return $qa_content;
} }
// Process sending a message to user // Process sending a message to user
$messagesent=(qa_get_state()=='message-sent'); $messagesent = (qa_get_state() == 'message-sent');
if (qa_post_text('domessage')) { if (qa_post_text('domessage')) {
$inmessage=qa_post_text('message'); $inmessage = qa_post_text('message');
if (!qa_check_form_security_code('message-'.$handle, qa_post_text('code'))) if ( !qa_check_form_security_code('message-'.$handle, qa_post_text('code')) )
$pageerror=qa_lang_html('misc/form_security_again'); $pageerror = qa_lang_html('misc/form_security_again');
else { else {
if (empty($inmessage)) if (empty($inmessage))
$errors['message']=qa_lang('misc/message_empty'); $errors['message'] = qa_lang('misc/message_empty');
if (empty($errors)) { if (empty($errors)) {
require_once QA_INCLUDE_DIR.'qa-db-messages.php'; require_once QA_INCLUDE_DIR.'qa-db-messages.php';
require_once QA_INCLUDE_DIR.'qa-app-emails.php'; require_once QA_INCLUDE_DIR.'qa-app-emails.php';
if (qa_opt('show_message_history')) if (qa_opt('show_message_history'))
$messageid=qa_db_message_create($loginuserid, $toaccount['userid'], $inmessage, '', false); $messageid = qa_db_message_create($loginuserid, $toaccount['userid'], $inmessage, '', false);
else else
$messageid=null; $messageid = null;
$fromhandle=qa_get_logged_in_handle(); $fromhandle = qa_get_logged_in_handle();
$canreply=!(qa_get_logged_in_flags() & QA_USER_FLAGS_NO_MESSAGES); $canreply = !(qa_get_logged_in_flags() & QA_USER_FLAGS_NO_MESSAGES);
$more=strtr(qa_lang($canreply ? 'emails/private_message_reply' : 'emails/private_message_info'), array( $more = strtr(qa_lang($canreply ? 'emails/private_message_reply' : 'emails/private_message_info'), array(
'^f_handle' => $fromhandle, '^f_handle' => $fromhandle,
'^url' => qa_path_absolute($canreply ? ('message/'.$fromhandle) : ('user/'.$fromhandle)), '^url' => qa_path_absolute($canreply ? ('message/'.$fromhandle) : ('user/'.$fromhandle)),
)); ));
$subs=array( $subs = array(
'^message' => $inmessage, '^message' => $inmessage,
'^f_handle' => $fromhandle, '^f_handle' => $fromhandle,
'^f_url' => qa_path_absolute('user/'.$fromhandle), '^f_url' => qa_path_absolute('user/'.$fromhandle),
...@@ -133,9 +133,9 @@ ...@@ -133,9 +133,9 @@
if (qa_send_notification($toaccount['userid'], $toaccount['email'], $toaccount['handle'], if (qa_send_notification($toaccount['userid'], $toaccount['email'], $toaccount['handle'],
qa_lang('emails/private_message_subject'), qa_lang('emails/private_message_body'), $subs)) qa_lang('emails/private_message_subject'), qa_lang('emails/private_message_body'), $subs))
$messagesent=true; $messagesent = true;
else else
$pageerror=qa_lang_html('main/general_error'); $pageerror = qa_lang_html('main/general_error');
qa_report_event('u_message', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array( qa_report_event('u_message', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array(
'userid' => $toaccount['userid'], 'userid' => $toaccount['userid'],
...@@ -153,13 +153,13 @@ ...@@ -153,13 +153,13 @@
// Prepare content for theme // Prepare content for theme
$qa_content=qa_content_prepare(); $qa_content = qa_content_prepare();
$qa_content['title']=qa_lang_html('misc/private_message_title'); $qa_content['title'] = qa_lang_html('misc/private_message_title');
$qa_content['error']=@$pageerror; $qa_content['error'] = @$pageerror;
$qa_content['form_message']=array( $qa_content['form_message'] = array(
'tags' => 'method="post" action="'.qa_self_html().'"', 'tags' => 'method="post" action="'.qa_self_html().'"',
'style' => 'tall', 'style' => 'tall',
...@@ -189,10 +189,10 @@ ...@@ -189,10 +189,10 @@
), ),
); );
$qa_content['focusid']='message'; $qa_content['focusid'] = 'message';
if ($messagesent) { if ($messagesent) {
$qa_content['form_message']['ok']=qa_lang_html('misc/message_sent'); $qa_content['form_message']['ok'] = qa_lang_html('misc/message_sent');
unset($qa_content['form_message']['buttons']); unset($qa_content['form_message']['buttons']);
if (qa_opt('show_message_history')) if (qa_opt('show_message_history'))
...@@ -207,26 +207,26 @@ ...@@ -207,26 +207,26 @@
// If relevant, show recent message history // If relevant, show recent message history
if (qa_opt('show_message_history')) { if (qa_opt('show_message_history')) {
$recent=array_merge($torecent, $fromrecent); $recent = array_merge($torecent, $fromrecent);
qa_sort_by($recent, 'created'); qa_sort_by($recent, 'created');
$showmessages=array_slice(array_reverse($recent, true), 0, QA_DB_RETRIEVE_MESSAGES); $showmessages = array_slice(array_reverse($recent, true), 0, QA_DB_RETRIEVE_MESSAGES);
if (count($showmessages)) { if (count($showmessages)) {
$qa_content['message_list']=array( $qa_content['message_list'] = array(
'title' => qa_lang_html_sub('misc/message_recent_history', qa_html($toaccount['handle'])), 'title' => qa_lang_html_sub('misc/message_recent_history', qa_html($toaccount['handle'])),
); );
$options=qa_message_html_defaults(); $options = qa_message_html_defaults();
foreach ($showmessages as $message) foreach ($showmessages as $message)
$qa_content['message_list']['messages'][]=qa_message_html_fields($message, $options); $qa_content['message_list']['messages'][] = qa_message_html_fields($message, $options);
} }
} }
$qa_content['raw']['account']=$toaccount; // for plugin layers to access $qa_content['raw']['account'] = $toaccount; // for plugin layers to access
return $qa_content; return $qa_content;
......
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