function mp_announcement_create($userid, $handle, $cookieid, $title, $content, $format, $text, $notify, $categoryid)
{
    /* 
     * Proceeds to create an announcement
     *
     */
    require_once QA_INCLUDE_DIR . 'qa-db-post-create.php';
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'mp-app-users.php';
    // persist data to database
    $postid = qa_db_post_create('AN', null, $userid, $cookieid, qa_remote_ip_address(), $title, $content, $format, null, $notify, $categoryid);
    qa_user_report_action(qa_get_logged_in_userid(), null, null, null, null);
    // update new post with category path hierarchy
    qa_db_posts_calc_category_path($postid);
    // send notifications
    if ($notify && isset($postid)) {
        $category = mp_get_categoryinfo($categoryid);
        $recipients = mp_get_category_userids($categoryid);
        foreach ($recipients as $recipient) {
            // retrieve the user flags
            $userflags = mp_get_user_flags($recipient['userid']);
            // check user flags to determine whether user should be notified or not
            // of the new answer post
            if (!($userflags & QA_USER_FLAGS_NOTIFY_ANNOUNCEMENTS)) {
                qa_send_notification($recipient['userid'], null, null, qa_lang('emails/an_posted_subject'), qa_lang('emails/an_posted_body'), array('^an_handle' => $handle, '^category_title' => $category['title'], '^an_title' => $title, '^an_url' => qa_path('mp-announcements-page', null, qa_opt('site_url'), null, null)));
            }
        }
    }
    // report announcement create event
    qa_report_event('an_post', $userid, $handle, $cookieid, array('postid' => $postid, 'title' => $title, 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $categoryid, 'notify' => $notify));
    return $postid;
}
function qa_wall_delete_post($userid, $handle, $cookieid, $message)
{
    require_once QA_INCLUDE_DIR . 'qa-db-messages.php';
    qa_db_message_delete($message['messageid']);
    qa_db_user_recount_posts($message['touserid']);
    qa_report_event('u_wall_delete', $userid, $handle, $cookieid, array('messageid' => $message['messageid'], 'oldmessage' => $message));
}
function qa_user_favorite_set($userid, $handle, $cookieid, $entitytype, $entityid, $favorite)
{
    require_once QA_INCLUDE_DIR . 'qa-db-favorites.php';
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    require_once QA_INCLUDE_DIR . 'qa-app-updates.php';
    if ($favorite) {
        qa_db_favorite_create($userid, $entitytype, $entityid);
    } else {
        qa_db_favorite_delete($userid, $entitytype, $entityid);
    }
    switch ($entitytype) {
        case QA_ENTITY_QUESTION:
            $action = $favorite ? 'q_favorite' : 'q_unfavorite';
            $params = array('postid' => $entityid);
            break;
        case QA_ENTITY_USER:
            $action = $favorite ? 'u_favorite' : 'u_unfavorite';
            $params = array('userid' => $entityid);
            break;
        case QA_ENTITY_TAG:
            $action = $favorite ? 'tag_favorite' : 'tag_unfavorite';
            $params = array('wordid' => $entityid);
            break;
        case QA_ENTITY_CATEGORY:
            $action = $favorite ? 'cat_favorite' : 'cat_unfavorite';
            $params = array('categoryid' => $entityid);
            break;
        default:
            qa_fatal_error('Favorite type not recognized');
            break;
    }
    qa_report_event($action, $userid, $handle, $cookieid, $params);
}
Beispiel #4
0
function qa_complete_reset_user($userid)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'qa-app-cookies.php';
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    $password = qa_random_alphanum(max(QA_MIN_PASSWORD_LEN, QA_NEW_PASSWORD_LEN));
    $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
    if (!qw_send_notification($userid, $userinfo['email'], $userinfo['handle'], qa_lang('emails/new_password_subject'), nl2br(qa_lang('emails/new_password_body')), array('^password' => $password, '^url' => qa_opt('site_url')))) {
        qa_fatal_error('Could not send new password - password not reset');
    }
    qa_db_user_set_password($userid, $password);
    // do this last, to be safe
    qa_db_user_set($userid, 'emailcode', '');
    // so can't be reused
    qa_report_event('u_reset', $userid, $userinfo['handle'], qa_cookie_get(), array('email' => $userinfo['email']));
}
 function process_request($request)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-format.php';
     require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
     require_once QA_INCLUDE_DIR . 'qa-db-post-create.php';
     require_once QA_INCLUDE_DIR . 'mp-db-users.php';
     // report that we entered this page
     qa_report_event('page_enter', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array('params' => $_SERVER['QUERY_STRING']));
     // create the editor and update its content
     qa_get_post_content('editor', 'content', $ineditor, $incontent, $informat, $intext);
     $editorname = isset($ineditor) ? $ineditor : qa_opt('editor_for_qs');
     $editor = qa_load_editor(@$incontent, @$informat, $editorname);
     // retrieve variable data
     $innotify = qa_post_text('notify') ? true : false;
     // handle creation of annoucement
     if (qa_post_text('docreate')) {
         //retrieve data
         $title = qa_post_text('title');
         $content = $incontent;
         $format = $informat;
         // validate data
         // handle create work
         // actual create process is in file mp-app-posts.php
         $postid = qa_post_create('AN', null, $title, $content, $format, mp_get_categoryid(), null, qa_get_logged_in_userid(), $innotify);
         // redirect page
         qa_redirect('mp-announcements-page');
         // our work is done here
     }
     $qa_content = qa_content_prepare();
     // if the user is not logged in, request user to login
     if (!qa_get_logged_in_userid()) {
         $qa_content['error'] = qa_insert_login_links('Please ^1log in^2 or ^3register^4 first.', $request);
         return $qa_content;
     }
     $qa_content['title'] = 'Create Announcement';
     $qa_content['form_newannouncement'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('title' => array('label' => qa_lang_html('announcements/a_title_label'), 'tags' => 'NAME="title"', 'value' => qa_html(qa_post_text('title')), 'error' => qa_html(@$errors['title'])), 'content' => array_merge($editor->get_field($qa_content, @$incontent, @$informat, 'content', 12, false), array('label' => qa_lang_html('announcements/a_content_label'), 'error' => qa_html(@$errors['content']))), 'notify' => array('label' => 'Send email notification to all registered students', 'tags' => 'NAME="notify"', 'type' => 'checkbox', 'value' => qa_html($innotify))), 'buttons' => array('ok' => array('tags' => 'NAME="docreate"', 'label' => 'Create Announcement', 'value' => '1')), 'hidden' => array('hiddenfield' => '1', 'editor' => qa_html($editorname)));
     // create the sub menu for navigation
     $qa_content['navigation']['sub'] = mp_announcements_sub_navigation();
     $qa_content['navigation']['sub']['create']['selected'] = true;
     return $qa_content;
 }
            require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
            if (qa_opt('show_message_history')) {
                $messageid = qa_db_message_create($loginuserid, $toaccount['userid'], $inmessage, '', false);
            } else {
                $messageid = null;
            }
            $fromhandle = qa_get_logged_in_handle();
            $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('^f_handle' => $fromhandle, '^url' => qa_path_absolute($canreply ? 'message/' . $fromhandle : 'user/' . $fromhandle)));
            $subs = array('^message' => $inmessage, '^f_handle' => $fromhandle, '^f_url' => qa_path_absolute('user/' . $fromhandle), '^more' => $more, '^a_url' => qa_path_absolute('account'));
            if (qa_send_notification($toaccount['userid'], $toaccount['email'], $toaccount['handle'], qa_lang('emails/private_message_subject'), qa_lang('emails/private_message_body'), $subs)) {
                $messagesent = true;
            } else {
                $pageerror = qa_lang_html('main/general_error');
            }
            qa_report_event('u_message', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array('userid' => $toaccount['userid'], 'handle' => $toaccount['handle'], 'messageid' => $messageid, 'message' => $inmessage));
            if ($messagesent && qa_opt('show_message_history')) {
                // show message as part of general history
                qa_redirect(qa_request(), array('state' => 'message-sent'));
            }
        }
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('misc/private_message_title');
$qa_content['error'] = @$pageerror;
$qa_content['form_message'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('message' => array('type' => $messagesent ? 'static' : '', 'label' => qa_lang_html_sub('misc/message_for_x', qa_get_one_user_html($handle, false)), 'tags' => 'name="message" id="message"', 'value' => qa_html(@$inmessage, $messagesent), 'rows' => 8, 'note' => qa_lang_html_sub('misc/message_explanation', qa_html(qa_opt('site_title'))), 'error' => qa_html(@$errors['message']))), 'buttons' => array('send' => array('tags' => 'onclick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('main/send_button'))), 'hidden' => array('domessage' => '1', 'code' => qa_get_form_security_code('message-' . $handle)));
$qa_content['focusid'] = 'message';
if ($messagesent) {
    $qa_content['form_message']['ok'] = qa_lang_html('misc/message_sent');
            qa_report_event('u_unblock', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array('userid' => $userid, 'handle' => $useraccount['handle']));
            qa_redirect(qa_request());
        }
        if (qa_clicked('dohideall') && !qa_user_permit_error('permit_hide_show')) {
            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);
            foreach ($postids as $postid) {
                qa_post_set_hidden($postid, true, $loginuserid);
            }
            qa_redirect(qa_request());
        }
        if (qa_clicked('dodelete') && $loginlevel >= QA_USER_LEVEL_ADMIN) {
            require_once QA_INCLUDE_DIR . 'qa-app-users-edit.php';
            qa_delete_user($userid);
            qa_report_event('u_delete', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array('userid' => $userid, 'handle' => $useraccount['handle']));
            qa_redirect('users');
        }
    }
}
//	Process bonus setting button
if ($loginlevel >= QA_USER_LEVEL_ADMIN && qa_clicked('dosetbonus')) {
    require_once QA_INCLUDE_DIR . 'qa-db-points.php';
    qa_db_points_set_bonus($userid, (int) qa_post_text('bonus'));
    qa_db_points_update_ifuser($userid, null);
    qa_redirect(qa_request(), null, null, null, 'activity');
}
//	Get information on user references in answers and other stuff need for page
$pagesize = qa_opt('page_size_user_posts');
$questions = qa_any_sort_and_dedupe(array_merge($questions, $answerqs, $commentqs, $editqs));
$questions = array_slice($questions, 0, $pagesize);
function qa_comment_set_userid($oldcomment, $userid, $handle, $cookieid)
{
    qa_db_post_set_userid($oldcomment['postid'], $userid);
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    qa_db_points_update_ifuser($userid, array('cposts'));
    qa_report_event('c_claim', $userid, $handle, $cookieid, array('postid' => $oldcomment['postid'], 'parentid' => $oldcomment['parentid'], 'oldcomment' => $oldcomment));
}
 function qa_set_logged_in_user($userid, $handle = '', $remember = false, $source = null, $categoryid = null)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-cookies.php';
     qa_start_session();
     $suffix = qa_session_var_suffix();
     if (isset($userid)) {
         $_SESSION['qa_session_userid_' . $suffix] = $userid;
         $_SESSION['qa_session_source_' . $suffix] = $source;
         $_SESSION['qa_session_verify_' . $suffix] = qa_session_verify_code($userid);
         $_SESSION['mp_session_category_id_' . $suffix] = $categoryid;
         // prevents one account on a shared server being able to create a log in a user to Q2A on another account on same server
         // PHP sessions time out too quickly on the server side, so we also set a cookie as backup.
         // Logging in from a second browser will make the previous browser's 'Remember me' no longer
         // work - I'm not sure if this is the right behavior - could see it either way.
         require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
         $userinfo = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
         // if we have logged in before, and are logging in the same way as before, we don't need to change the sessioncode/source
         // this means it will be possible to automatically log in (via cookies) to the same account from more than one browser
         if (empty($userinfo['sessioncode']) || $source !== $userinfo['sessionsource']) {
             $sessioncode = qa_db_user_rand_sessioncode();
             qa_db_user_set($userid, 'sessioncode', $sessioncode);
             qa_db_user_set($userid, 'sessionsource', $source);
         } else {
             $sessioncode = $userinfo['sessioncode'];
         }
         qa_db_user_logged_in($userid, qa_remote_ip_address());
         //qa_set_session_cookie($handle, $sessioncode, $remember);
         qa_set_session_cookie($handle, $sessioncode, $remember, $categoryid);
         qa_report_event('u_login', $userid, $userinfo['handle'], qa_cookie_get());
     } else {
         $olduserid = qa_get_logged_in_userid();
         $oldhandle = qa_get_logged_in_handle();
         qa_clear_session_cookie();
         unset($_SESSION['qa_session_userid_' . $suffix]);
         unset($_SESSION['qa_session_source_' . $suffix]);
         unset($_SESSION['qa_session_verify_' . $suffix]);
         unset($_SESSION['mp_session_category_id_' . $suffix]);
         qa_report_event('u_logout', $olduserid, $oldhandle, qa_cookie_get());
     }
 }
        if (qa_clicked('doblock')) {
            $oldblocked = qa_opt('block_ips_write');
            qa_set_option('block_ips_write', (strlen($oldblocked) ? $oldblocked . ' , ' : '') . $ip);
            qa_report_event('ip_block', $userid, qa_get_logged_in_handle(), qa_cookie_get(), array('ip' => $ip));
            qa_redirect(qa_request());
        }
        if (qa_clicked('dounblock')) {
            require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
            $blockipclauses = qa_block_ips_explode(qa_opt('block_ips_write'));
            foreach ($blockipclauses as $key => $blockipclause) {
                if (qa_block_ip_match($ip, $blockipclause)) {
                    unset($blockipclauses[$key]);
                }
            }
            qa_set_option('block_ips_write', implode(' , ', $blockipclauses));
            qa_report_event('ip_unblock', $userid, qa_get_logged_in_handle(), qa_cookie_get(), array('ip' => $ip));
            qa_redirect(qa_request());
        }
        if (qa_clicked('dohideall') && !qa_user_maximum_permit_error('permit_hide_show')) {
            // allow moderator in one category to hide posts across all categories if they are identified via IP page
            require_once QA_INCLUDE_DIR . 'qa-db-admin.php';
            require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
            $postids = qa_db_get_ip_visible_postids($ip);
            foreach ($postids as $postid) {
                qa_post_set_hidden($postid, true, $userid);
            }
            qa_redirect(qa_request());
        }
    }
}
//	Combine sets of questions and get information for users
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/
if (!defined('QA_VERSION')) {
    // don't allow this page to be requested directly from browser
    header('Location: ../');
    exit;
}
// report that we entered this page
qa_report_event('page_enter', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array('params' => $_SERVER['QUERY_STRING'], 'path' => $_SERVER['SCRIPT_NAME']));
require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
//	Get popular tags
$populartags = qa_db_select_with_pending(qa_db_popular_tags_selectspec($qa_start));
$tagcount = qa_opt('cache_tagcount');
$pagesize = qa_opt('page_size_tags');
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('main/popular_tags');
$qa_content['ranking'] = array('items' => array(), 'rows' => ceil($pagesize / qa_opt('columns_tags')), 'type' => 'tags');
if (count($populartags)) {
    $output = 0;
    foreach ($populartags as $word => $count) {
        $qa_content['ranking']['items'][] = array('label' => qa_tag_html($word), 'count' => number_format($count));
        if (++$output >= $pagesize) {
function qa_flags_clear_all($post, $userid, $handle, $cookieid)
{
    require_once QA_INCLUDE_DIR . 'qa-db-votes.php';
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    qa_db_userflags_clear_all($post['postid']);
    qa_db_post_recount_flags($post['postid']);
    switch ($post['basetype']) {
        case 'Q':
            $action = 'q_clearflags';
            break;
        case 'A':
            $action = 'a_clearflags';
            break;
        case 'C':
            $action = 'c_clearflags';
            break;
    }
    qa_report_write_action($userid, null, $action, $post['basetype'] == 'Q' ? $post['postid'] : null, $post['basetype'] == 'A' ? $post['postid'] : null, $post['basetype'] == 'C' ? $post['postid'] : null);
    qa_report_event($action, $userid, $handle, $cookieid, array('postid' => $post['postid']));
}
Beispiel #13
0
function qa_complete_reset_user($userid)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'util/string.php';
    require_once QA_INCLUDE_DIR . 'app/options.php';
    require_once QA_INCLUDE_DIR . 'app/emails.php';
    require_once QA_INCLUDE_DIR . 'app/cookies.php';
    require_once QA_INCLUDE_DIR . 'db/selects.php';
    $password = qa_random_alphanum(max(QA_MIN_PASSWORD_LEN, QA_NEW_PASSWORD_LEN));
    $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
    if (!qa_send_notification($userid, $userinfo['email'], $userinfo['handle'], qa_lang('emails/new_password_subject'), qa_lang('emails/new_password_body'), array('^password' => $password, '^url' => qa_opt('site_url')))) {
        qa_fatal_error('Could not send new password - password not reset');
    }
    qa_db_user_set_password($userid, $password);
    // do this last, to be safe
    qa_db_user_set($userid, 'emailcode', '');
    // so can't be reused
    qa_report_event('u_reset', $userid, $userinfo['handle'], qa_cookie_get(), array('email' => $userinfo['email']));
}
 function comment_vote_set($post, $userid, $handle, $cookieid, $vote)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-votes.php';
     /*
     			require_once QA_INCLUDE_DIR.'qa-db-points.php';
     			require_once QA_INCLUDE_DIR.'qa-db-hotness.php';
     			require_once QA_INCLUDE_DIR.'qa-app-limits.php';
     */
     $vote = (int) min(1, max(-1, $vote));
     $oldvote = (int) qa_db_uservote_get($post['postid'], $userid);
     qa_db_uservote_set($post['postid'], $userid, $vote);
     qa_db_post_recount_votes($post['postid']);
     /*
     			
     			$postisanswer=($post['basetype']=='A');
     			
     			$columns=array();
     			
     			if ( ($vote>0) || ($oldvote>0) )
     				$columns[]=$postisanswer ? 'aupvotes' : 'qupvotes';
     
     			if ( ($vote<0) || ($oldvote<0) )
     				$columns[]=$postisanswer ? 'adownvotes' : 'qdownvotes';
     	
     			qa_db_points_update_ifuser($userid, $columns);
     			
     			qa_db_points_update_ifuser($post['userid'], array($postisanswer ? 'avoteds' : 'qvoteds', 'upvoteds', 'downvoteds'));
     			
     			if ($post['basetype']=='Q')
     				qa_db_hotness_update($post['postid']);
     			
     			if ($vote<0)
     				$action=$postisanswer ? 'a_vote_down' : 'q_vote_down';
     			elseif ($vote>0)
     				$action=$postisanswer ? 'a_vote_up' : 'q_vote_up';
     			else
     				$action=$postisanswer ? 'a_vote_nil' : 'q_vote_nil';
     */
     if ($vote < 0) {
         $action = 'c_vote_down';
     } elseif ($vote > 0) {
         $action = 'c_vote_up';
     } else {
         $action = 'c_vote_nil';
     }
     //qa_report_write_action($userid, null, $action, null, null, null);
     qa_report_event($action, $userid, $handle, $cookieid, array('postid' => $post['postid'], 'vote' => $vote, 'oldvote' => $oldvote));
 }
function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question, $answer, $commentsfollows)
{
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $parent = isset($answer) ? $answer : $question;
    $postid = qa_db_post_create('C', $parent['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']);
    qa_db_posts_calc_category_path($postid);
    if (!($question['hidden'] || @$answer['hidden'])) {
        // don't index comment if parent or parent of parent is hidden
        qa_post_index($postid, 'C', $question['postid'], null, $text, null);
    }
    qa_db_points_update_ifuser($userid, 'cposts');
    qa_db_ccount_update();
    //	$senttoemail and $senttouserid ensure each user or email gets only one notification about an added comment,
    //	even if they have several previous comments in the same thread and asked for notifications for the parent.
    //	Still, if a person posted some comments as a registered user and some others anonymously,
    //	they could get two emails about a subsequent comment. Shouldn't be much of a problem in practice.
    $senttoemail = array();
    $senttouserid = array();
    switch ($parent['basetype']) {
        case 'Q':
            $subject = qa_lang('emails/q_commented_subject');
            $body = qa_lang('emails/q_commented_body');
            $context = $parent['title'];
            break;
        case 'A':
            $subject = qa_lang('emails/a_commented_subject');
            $body = qa_lang('emails/a_commented_body');
            $context = qa_viewer_text($parent['content'], $parent['format']);
            break;
    }
    $blockwordspreg = qa_get_block_words_preg();
    $sendhandle = isset($handle) ? $handle : qa_lang('main/anonymous');
    $sendcontext = qa_block_words_replace($context, $blockwordspreg);
    $sendtext = qa_block_words_replace($text, $blockwordspreg);
    $sendtitle = qa_block_words_replace($question['title'], $blockwordspreg);
    $sendurl = qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor($parent['basetype'], $parent['postid']));
    if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
        $senduserid = $parent['userid'];
        $sendemail = @$parent['notify'];
        if (qa_email_validate($sendemail)) {
            $senttoemail[$sendemail] = true;
        } elseif (isset($senduserid)) {
            $senttouserid[$senduserid] = true;
        }
        qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
    }
    foreach ($commentsfollows as $comment) {
        if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
            // find just those for this parent
            if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
                $senduserid = $comment['userid'];
                $sendemail = @$comment['notify'];
                if (qa_email_validate($sendemail)) {
                    if (@$senttoemail[$sendemail]) {
                        continue;
                    }
                    $senttoemail[$sendemail] = true;
                } elseif (isset($senduserid)) {
                    if (@$senttouserid[$senduserid]) {
                        continue;
                    }
                    $senttouserid[$senduserid] = true;
                }
                qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
            }
        }
    }
    qa_report_event('c_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $parent['postid'], 'parenttype' => $parent['basetype'], 'questionid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email));
    return $postid;
}
Beispiel #16
0
function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question, $parent, $commentsfollows, $queued = false)
{
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    if (!isset($parent)) {
        $parent = $question;
    }
    // for backwards compatibility with old answer parameter
    $postid = qa_db_post_create($queued ? 'C_QUEUED' : 'C', $parent['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']);
    qa_db_posts_calc_category_path($postid);
    if (!$queued) {
        if ($question['type'] == 'Q' && ($parent['type'] == 'Q' || $parent['type'] == 'A')) {
            // only index if antecedents fully visible
            qa_post_index($postid, 'C', $question['postid'], $parent['postid'], null, $content, $format, $text, null, $question['categoryid']);
        }
        qa_db_points_update_ifuser($userid, 'cposts');
        qa_db_ccount_update();
    }
    $thread = array();
    foreach ($commentsfollows as $comment) {
        if ($comment['type'] == 'C' && $comment['parentid'] == $parent['postid']) {
            // find just those for this parent, fully visible
            $thread[] = $comment;
        }
    }
    qa_report_event($queued ? 'c_queue' : 'c_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $parent['postid'], 'parenttype' => $parent['basetype'], 'parent' => $parent, 'questionid' => $question['postid'], 'question' => $question, 'thread' => $thread, 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email));
    return $postid;
}
function qa_comment_set_userid($oldcomment, $userid, $handle, $cookieid)
{
    require_once QA_INCLUDE_DIR . 'db/votes.php';
    $postid = $oldcomment['postid'];
    qa_db_post_set_userid($postid, $userid);
    qa_db_uservote_remove_own($postid);
    qa_db_post_recount_votes($postid);
    qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
    qa_db_points_update_ifuser($userid, array('cposts'));
    qa_report_event('c_claim', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $oldcomment['parentid'], 'oldcomment' => $oldcomment));
}
    $innewpassword2 = qa_post_text('newpassword2');
    $errors = array();
    if ($haspassword && strtolower(qa_db_calc_passcheck($inoldpassword, $useraccount['passsalt'])) != strtolower($useraccount['passcheck'])) {
        $errors['oldpassword'] = qa_lang_html('users/password_wrong');
    }
    $errors = array_merge($errors, qa_password_validate($innewpassword1));
    if ($innewpassword1 != $innewpassword2) {
        $errors['newpassword2'] = qa_lang_html('users/password_mismatch');
    }
    if (empty($errors)) {
        qa_db_user_set_password($qa_login_userid, $innewpassword1);
        qa_db_user_set($qa_login_userid, 'sessioncode', '');
        // stop old 'Remember me' style logins from still working
        qa_set_logged_in_user($qa_login_userid, $useraccount['handle'], false, $useraccount['sessionsource']);
        // reinstate this specific session
        qa_report_event('u_password', $qa_login_userid, $useraccount['handle'], $qa_cookieid);
        qa_redirect('account', array('state' => 'password-changed'));
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('profile/my_account_title');
$qa_content['form_profile'] = array('tags' => 'ENCTYPE="multipart/form-data" METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'wide', 'fields' => array('duration' => array('type' => 'static', 'label' => qa_lang_html('users/member_for'), 'value' => qa_time_to_string(qa_opt('db_time') - $useraccount['created'])), 'type' => array('type' => 'static', 'label' => qa_lang_html('users/member_type'), 'value' => qa_html(qa_user_level_string($useraccount['level']))), 'handle' => array('label' => qa_lang_html('users/handle_label'), 'tags' => 'NAME="handle"', 'value' => qa_html(isset($inhandle) ? $inhandle : $useraccount['handle']), 'error' => qa_html(@$errors['handle']), 'type' => $changehandle ? 'text' : 'static'), 'email' => array('label' => qa_lang_html('users/email_label'), 'tags' => 'NAME="email"', 'value' => qa_html(isset($inemail) ? $inemail : $useraccount['email']), 'error' => isset($errors['email']) ? qa_html($errors['email']) : ($doconfirms && !$isconfirmed ? qa_insert_login_links(qa_lang_html('users/email_please_confirm')) : null)), 'notify_annoucements' => array('type' => 'checkbox', 'label' => qa_lang_html('users/notify_announcements_label'), 'tags' => 'NAME="notify_an"', 'value' => !($useraccount['flags'] & QA_USER_FLAGS_NOTIFY_ANNOUNCEMENTS), 'note' => qa_lang_html('users/notify_annoucements_explanation')), 'notify_questions' => array('type' => 'checkbox', 'label' => qa_lang_html('users/notify_questions_label'), 'tags' => 'NAME="notify_q"', 'value' => !($useraccount['flags'] & QA_USER_FLAGS_NOTIFY_QUESTIONS), 'note' => qa_lang_html('users/notify_questions_explanation')), 'notify_answers' => array('type' => 'checkbox', 'label' => qa_lang_html('users/notify_answers_label'), 'tags' => 'NAME="notify_a"', 'value' => !($useraccount['flags'] & QA_USER_FLAGS_NOTIFY_ANSWERS), 'note' => qa_lang_html('users/notify_answers_explanation')), 'messages' => array('label' => qa_lang_html('users/private_messages'), 'tags' => 'NAME="messages"', 'type' => 'checkbox', 'value' => !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES), 'note' => qa_lang_html('users/private_messages_explanation')), 'avatar' => null), 'buttons' => array('save' => array('label' => qa_lang_html('users/save_profile'))), 'hidden' => array('dosaveprofile' => '1'));
if ($qa_state == 'profile-saved') {
    $qa_content['form_profile']['ok'] = qa_lang_html('users/profile_saved');
}
if (!qa_opt('allow_private_messages')) {
    unset($qa_content['form_profile']['fields']['messages']);
}
//	Avatar upload stuff
if (qa_opt('avatar_allow_gravatar') || qa_opt('avatar_allow_upload')) {
                qa_redirect($qa_request);
            }
            list($useraccount, $userprofile) = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true), qa_db_user_profile_selectspec($userid, true));
        }
    }
    if (isset($maxlevelassign) && $useraccount['level'] < QA_USER_LEVEL_MODERATOR) {
        if (qa_clicked('doblock')) {
            require_once QA_INCLUDE_DIR . 'qa-db-users.php';
            qa_db_user_set_flag($userid, QA_USER_FLAGS_USER_BLOCKED, true);
            qa_report_event('u_block', $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, array('userid' => $userid, 'handle' => $useraccount['handle']));
            qa_redirect($qa_request);
        }
        if (qa_clicked('dounblock')) {
            require_once QA_INCLUDE_DIR . 'qa-db-users.php';
            qa_db_user_set_flag($userid, QA_USER_FLAGS_USER_BLOCKED, false);
            qa_report_event('u_unblock', $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, array('userid' => $userid, 'handle' => $useraccount['handle']));
            qa_redirect($qa_request);
        }
        if (qa_clicked('dohideall') && !qa_user_permit_error('permit_hide_show')) {
            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);
            foreach ($postids as $postid) {
                qa_post_set_hidden($postid, true, $qa_login_userid);
            }
            qa_redirect($qa_request);
        }
    }
}
//	Get information on user references in answers and other stuff need for page
$pagesize = qa_opt('page_size_user_posts');
qa_report_event('page_enter', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array('params' => $_SERVER['QUERY_STRING'], 'path' => $_SERVER['SCRIPT_NAME']));
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
//	Perform the search if appropriate
if (strlen(qa_get('q'))) {
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $inquery = trim(qa_get('q'));
    $words = qa_string_to_words($inquery);
    $retrieve = 2 * QA_DB_RETRIEVE_QS_AS + 1;
    // get enough results to be able to give some idea of how many pages of search results there are
    $questions = qa_db_select_with_pending(qa_db_search_posts_selectspec($qa_login_userid, $words, $words, $words, $words, $inquery, $qa_start, false, $retrieve));
    $pagesize = qa_opt('page_size_search');
    $gotcount = count($questions);
    $questions = array_slice($questions, 0, $pagesize);
    $usershtml = qa_userids_handles_html($questions);
    qa_report_event('search', $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, array('query' => $inquery, 'start' => $qa_start));
}
//	Prepare content for theme
$qa_content = qa_content_prepare(true);
if (strlen(qa_get('q'))) {
    $qa_content['search']['value'] = qa_html($inquery);
}
if (isset($questions)) {
    if (count($questions)) {
        $qa_content['title'] = qa_lang_html_sub('main/results_for_x', qa_html($inquery));
    } else {
        $qa_content['title'] = qa_lang_html_sub('main/no_results_for_x', qa_html($inquery));
    }
    $qa_content['q_list']['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"');
    $qa_content['q_list']['qs'] = array();
    foreach ($questions as $question) {
Beispiel #21
0
function qa_flags_clear_all($oldpost, $userid, $handle, $cookieid)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'db/votes.php';
    require_once QA_INCLUDE_DIR . 'app/limits.php';
    require_once QA_INCLUDE_DIR . 'db/post-update.php';
    qa_db_userflags_clear_all($oldpost['postid']);
    qa_db_post_recount_flags($oldpost['postid']);
    qa_db_flaggedcount_update();
    switch ($oldpost['basetype']) {
        case 'Q':
            $event = 'q_clearflags';
            break;
        case 'A':
            $event = 'a_clearflags';
            break;
        case 'C':
            $event = 'c_clearflags';
            break;
    }
    qa_report_event($event, $userid, $handle, $cookieid, array('postid' => $oldpost['postid'], 'oldpost' => $oldpost));
}
        if ($haspassword && strtolower(qa_db_calc_passcheck($inoldpassword, $useraccount['passsalt'])) != strtolower($useraccount['passcheck'])) {
            $errors['oldpassword'] = qa_lang('users/password_wrong');
        }
        $useraccount['password'] = $inoldpassword;
        $errors = $errors + qa_password_validate($innewpassword1, $useraccount);
        // array union
        if ($innewpassword1 != $innewpassword2) {
            $errors['newpassword2'] = qa_lang('users/password_mismatch');
        }
        if (empty($errors)) {
            qa_db_user_set_password($userid, $innewpassword1);
            qa_db_user_set($userid, 'sessioncode', '');
            // stop old 'Remember me' style logins from still working
            qa_set_logged_in_user($userid, $useraccount['handle'], false, $useraccount['sessionsource']);
            // reinstate this specific session
            qa_report_event('u_password', $userid, $useraccount['handle'], qa_cookie_get());
            qa_redirect('account', array('state' => 'password-changed'));
        }
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('profile/my_account_title');
$qa_content['error'] = @$errors['page'];
$qa_content['form_profile'] = array('tags' => 'enctype="multipart/form-data" method="post" action="' . qa_self_html() . '"', 'style' => 'wide', 'fields' => array('duration' => array('type' => 'static', 'label' => qa_lang_html('users/member_for'), 'value' => qa_time_to_string(qa_opt('db_time') - $useraccount['created'])), 'type' => array('type' => 'static', 'label' => qa_lang_html('users/member_type'), 'value' => qa_html(qa_user_level_string($useraccount['level'])), 'note' => $isblocked ? qa_lang_html('users/user_blocked') : null), 'handle' => array('label' => qa_lang_html('users/handle_label'), 'tags' => 'name="handle"', 'value' => qa_html(isset($inhandle) ? $inhandle : $useraccount['handle']), 'error' => qa_html(@$errors['handle']), 'type' => $changehandle && !$isblocked ? 'text' : 'static'), 'email' => array('label' => qa_lang_html('users/email_label'), 'tags' => 'name="email"', 'value' => qa_html(isset($inemail) ? $inemail : $useraccount['email']), 'error' => isset($errors['email']) ? qa_html($errors['email']) : ($doconfirms && !$isconfirmed ? qa_insert_login_links(qa_lang_html('users/email_please_confirm')) : null), 'type' => $isblocked ? 'static' : 'text'), 'messages' => array('label' => qa_lang_html('users/private_messages'), 'tags' => 'name="messages"', 'type' => 'checkbox', 'value' => !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES), 'note' => qa_lang_html('users/private_messages_explanation')), 'wall' => array('label' => qa_lang_html('users/wall_posts'), 'tags' => 'name="wall"', 'type' => 'checkbox', 'value' => !($useraccount['flags'] & QA_USER_FLAGS_NO_WALL_POSTS), 'note' => qa_lang_html('users/wall_posts_explanation')), 'mailings' => array('label' => qa_lang_html('users/mass_mailings'), 'tags' => 'name="mailings"', 'type' => 'checkbox', 'value' => !($useraccount['flags'] & QA_USER_FLAGS_NO_MAILINGS), 'note' => qa_lang_html('users/mass_mailings_explanation')), 'avatar' => null), 'buttons' => array('save' => array('tags' => 'onclick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('users/save_profile'))), 'hidden' => array('dosaveprofile' => '1', 'code' => qa_get_form_security_code('account')));
if (qa_get_state() == 'profile-saved') {
    $qa_content['form_profile']['ok'] = qa_lang_html('users/profile_saved');
}
if (!qa_opt('allow_private_messages')) {
    unset($qa_content['form_profile']['fields']['messages']);
}
    if (empty($inmessage)) {
        $errors['message'] = qa_lang('misc/message_empty');
    }
    if (empty($errors)) {
        require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
        $fromhandle = qa_get_logged_in_handle();
        $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('^f_handle' => $fromhandle, '^url' => qa_path($canreply ? 'message/' . $fromhandle : 'user/' . $fromhandle, null, qa_opt('site_url'))));
        $subs = array('^message' => $inmessage, '^f_handle' => $fromhandle, '^f_url' => qa_path('user/' . $fromhandle, null, qa_opt('site_url')), '^more' => $more, '^a_url' => qa_path_html('account', null, qa_opt('site_url')));
        if (qa_send_notification($useraccount['userid'], $useraccount['email'], $useraccount['handle'], qa_lang('emails/private_message_subject'), qa_lang('emails/private_message_body'), $subs)) {
            $messagesent = true;
        } else {
            $page_error = qa_lang_html('main/general_error');
        }
        qa_limits_increment($qa_login_userid, 'M');
        qa_report_event('u_message', $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, array('userid' => $useraccount['userid'], 'handle' => $useraccount['handle'], 'message' => $inmessage));
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('misc/private_message_title');
$qa_content['error'] = @$page_error;
$qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('message' => array('type' => $messagesent ? 'static' : '', 'label' => qa_lang_html_sub('misc/message_for_x', qa_get_one_user_html($handle, false)), 'tags' => 'NAME="message" ID="message"', 'value' => qa_html(@$inmessage, $messagesent), 'rows' => 16, 'note' => qa_lang_html_sub('misc/message_explanation', qa_html(qa_opt('site_title'))), 'error' => qa_html(@$errors['message']))), 'buttons' => array('send' => array('label' => qa_lang_html('main/send_button'))), 'hidden' => array('domessage' => '1'));
$qa_content['focusid'] = 'message';
if ($messagesent) {
    $qa_content['form']['ok'] = qa_lang_html('misc/message_sent');
    unset($qa_content['form']['fields']['message']['note']);
    unset($qa_content['form']['buttons']);
}
return $qa_content;
/*
    //	Perform the search using appropriate module
    $results = qa_get_search_results($inquery, $start, $count, $userid, false, false);
    //	Count and truncate results
    $pagesize = qa_opt('page_size_search');
    $gotcount = count($results);
    $results = array_slice($results, 0, $pagesize);
    //	Retrieve extra information on users
    $fullquestions = array();
    foreach ($results as $result) {
        if (isset($result['question'])) {
            $fullquestions[] = $result['question'];
        }
    }
    $usershtml = qa_userids_handles_html($fullquestions);
    //	Report the search event
    qa_report_event('search', $userid, qa_get_logged_in_handle(), qa_cookie_get(), array('query' => $inquery, 'start' => $start));
}
//	Prepare content for theme
$qa_content = qa_content_prepare(true);
if (strlen(qa_get('q'))) {
    $qa_content['search']['value'] = qa_html($inquery);
    if (count($results)) {
        $qa_content['title'] = qa_lang_html_sub('main/results_for_x', qa_html($inquery));
    } else {
        $qa_content['title'] = qa_lang_html_sub('main/no_results_for_x', qa_html($inquery));
    }
    $qa_content['q_list']['form'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'hidden' => array('code' => qa_get_form_security_code('vote')));
    $qa_content['q_list']['qs'] = array();
    $qdefaults = qa_post_html_defaults('Q');
    foreach ($results as $result) {
        if (!isset($result['question'])) {
    $inemail = qa_post_text('email');
    $inreferer = qa_post_text('referer');
    if (empty($inmessage)) {
        $errors['message'] = qa_lang('misc/feedback_empty');
    }
    if ($usecaptcha) {
        qa_captcha_validate($_POST, $errors);
    }
    if (empty($errors)) {
        $subs = array('^message' => $inmessage, '^name' => empty($inname) ? '-' : $inname, '^email' => empty($inemail) ? '-' : $inemail, '^previous' => empty($inreferer) ? '-' : $inreferer, '^url' => isset($qa_login_userid) ? qa_path('user/' . qa_get_logged_in_handle(), null, qa_opt('site_url')) : '-', '^ip' => qa_remote_ip_address(), '^browser' => @$_SERVER['HTTP_USER_AGENT']);
        if (qa_send_email(array('fromemail' => qa_email_validate(@$inemail) ? $inemail : qa_opt('from_email'), 'fromname' => $inname, 'toemail' => qa_opt('feedback_email'), 'toname' => qa_opt('site_title'), 'subject' => qa_lang_sub('emails/feedback_subject', qa_opt('site_title')), 'body' => strtr(qa_lang('emails/feedback_body'), $subs), 'html' => false))) {
            $feedbacksent = true;
        } else {
            $page_error = qa_lang_html('main/general_error');
        }
        qa_report_event('feedback', $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, array('email' => $inemail, 'name' => $inname, 'message' => $inmessage, 'previous' => $inreferer, 'browser' => @$_SERVER['HTTP_USER_AGENT']));
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('misc/feedback_title');
$qa_content['error'] = @$page_error;
$qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('message' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html_sub('misc/feedback_message', qa_opt('site_title')), 'tags' => 'NAME="message" ID="message"', 'value' => qa_html(@$inmessage), 'rows' => 8, 'error' => qa_html(@$errors['message'])), 'name' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html('misc/feedback_name'), 'tags' => 'NAME="name"', 'value' => qa_html(isset($inname) ? $inname : @$userprofile['name'])), 'email' => array('type' => $feedbacksent ? 'static' : '', 'label' => qa_lang_html('misc/feedback_email'), 'tags' => 'NAME="email"', 'value' => qa_html(isset($inemail) ? $inemail : qa_get_logged_in_email()), 'note' => $feedbacksent ? null : qa_opt('email_privacy'))), 'buttons' => array('send' => array('label' => qa_lang_html('main/send_button'))), 'hidden' => array('dofeedback' => '1', 'referer' => qa_html(isset($inreferer) ? $inreferer : @$_SERVER['HTTP_REFERER'])));
if ($usecaptcha && !$feedbacksent) {
    qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors);
}
$qa_content['focusid'] = 'message';
if ($feedbacksent) {
    $qa_content['form']['ok'] = qa_lang_html('misc/feedback_sent');
    unset($qa_content['form']['buttons']);
}
Beispiel #26
0
 function qa_set_logged_in_user($userid, $handle = '', $remember = false, $source = null)
 {
     if (qa_to_override(__FUNCTION__)) {
         $args = func_get_args();
         return qa_call_override(__FUNCTION__, $args);
     }
     require_once QA_INCLUDE_DIR . 'app/cookies.php';
     qa_start_session();
     if (isset($userid)) {
         qa_set_session_user($userid, $source);
         // PHP sessions time out too quickly on the server side, so we also set a cookie as backup.
         // Logging in from a second browser will make the previous browser's 'Remember me' no longer
         // work - I'm not sure if this is the right behavior - could see it either way.
         require_once QA_INCLUDE_DIR . 'db/selects.php';
         $userinfo = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
         // if we have logged in before, and are logging in the same way as before, we don't need to change the sessioncode/source
         // this means it will be possible to automatically log in (via cookies) to the same account from more than one browser
         if (empty($userinfo['sessioncode']) || $source !== $userinfo['sessionsource']) {
             $sessioncode = qa_db_user_rand_sessioncode();
             qa_db_user_set($userid, 'sessioncode', $sessioncode);
             qa_db_user_set($userid, 'sessionsource', $source);
         } else {
             $sessioncode = $userinfo['sessioncode'];
         }
         qa_db_user_logged_in($userid, qa_remote_ip_address());
         qa_set_session_cookie($handle, $sessioncode, $remember);
         qa_report_event('u_login', $userid, $userinfo['handle'], qa_cookie_get());
     } else {
         $olduserid = qa_get_logged_in_userid();
         $oldhandle = qa_get_logged_in_handle();
         qa_clear_session_cookie();
         qa_clear_session_user();
         qa_report_event('u_logout', $olduserid, $oldhandle, qa_cookie_get());
     }
 }
Beispiel #27
0
function qa_redirect_raw($url)
{
    $eventParams = array('url' => $url);
    qa_report_event('page_redirect_raw', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), $eventParams);
    header('Location: ' . $url);
    exit;
}