コード例 #1
0
ファイル: qa-plugin.php プロジェクト: NoahY/q2a-privileges
function qa_priv_notification($uid, $oid, $badge_slug)
{
    require_once QA_INCLUDE_DIR . 'qa-app-users.php';
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    if (QA_FINAL_EXTERNAL_USERS) {
        $publictohandle = qa_get_public_from_userids(array($uid));
        $handle = @$publictohandle[$uid];
    } else {
        $user = qa_db_single_select(qa_db_user_account_selectspec($uid, true));
        $handle = @$user['handle'];
    }
    $subject = qa_opt('badge_email_subject');
    $body = qa_opt('badge_email_body');
    $body = preg_replace('/\\^if_post_text="([^"]*)"/', $oid ? '$1' : '', $body);
    // if post text
    $site_url = qa_opt('site_url');
    $profile_url = qa_path_html('user/' . $handle, null, $site_url);
    if ($oid) {
        $post = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $oid), true);
        if ($post['parentid']) {
            $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $post['parentid']), true);
        }
        if (isset($parent)) {
            $anchor = urlencode(qa_anchor($post['basetype'], $oid));
            $post_title = $parent['title'];
            $post_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor);
        } else {
            $post_title = $post['title'];
            $post_url = qa_path_html(qa_q_request($post['postid'], $post['title']), null, qa_opt('site_url'));
        }
    }
    $subs = array('^badge_name' => qa_opt('badge_' . $badge_slug . '_name'), '^post_title' => @$post_title, '^post_url' => @$post_url, '^profile_url' => $profile_url, '^site_url' => $site_url);
    qa_send_notification($uid, '@', $handle, $subject, $body, $subs);
}
コード例 #2
0
 function getEmail($userid)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     if (QA_FINAL_EXTERNAL_USERS) {
         $email = qa_get_user_email($userid);
     } else {
         $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
         $email = @$useraccount['email'];
     }
     return $email;
 }
コード例 #3
0
 function getHandleFromId($userid)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-users.php';
     if (QA_FINAL_EXTERNAL_USERS) {
         $publictohandle = qa_get_public_from_userids(array($userid));
         $handle = @$publictohandle[$userid];
     } else {
         $user = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
         $handle = @$user['handle'];
     }
     return $handle;
 }
コード例 #4
0
function qa_send_notification($userid, $email, $handle, $subject, $body, $subs)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    global $qa_notifications_suspended;
    if ($qa_notifications_suspended > 0) {
        return false;
    }
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    if (isset($userid)) {
        $needemail = !qa_email_validate(@$email);
        // take from user if invalid, e.g. @ used in practice
        $needhandle = empty($handle);
        if ($needemail || $needhandle) {
            if (QA_FINAL_EXTERNAL_USERS) {
                if ($needhandle) {
                    $handles = qa_get_public_from_userids(array($userid));
                    $handle = @$handles[$userid];
                }
                if ($needemail) {
                    $email = qa_get_user_email($userid);
                }
            } else {
                $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
                if ($needhandle) {
                    $handle = @$useraccount['handle'];
                }
                if ($needemail) {
                    $email = @$useraccount['email'];
                }
            }
        }
    }
    if (isset($email) && qa_email_validate($email)) {
        $subs['^site_title'] = qa_opt('site_title');
        $subs['^handle'] = $handle;
        $subs['^email'] = $email;
        $subs['^open'] = "\n";
        $subs['^close'] = "\n";
        return qa_send_email(array('fromemail' => qa_opt('from_email'), 'fromname' => qa_opt('site_title'), 'toemail' => $email, 'toname' => $handle, 'subject' => strtr($subject, $subs), 'body' => (empty($handle) ? '' : qa_lang_sub('emails/to_handle_prefix', $handle)) . strtr($body, $subs), 'html' => false));
    } else {
        return false;
    }
}
コード例 #5
0
ファイル: qa-page.php プロジェクト: ramo01/1kapp
function qa_page_queue_pending()
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    qa_preload_options();
    $loginuserid = qa_get_logged_in_userid();
    if (isset($loginuserid)) {
        if (!QA_FINAL_EXTERNAL_USERS) {
            qa_db_queue_pending_select('loggedinuser', qa_db_user_account_selectspec($loginuserid, true));
        }
        qa_db_queue_pending_select('notices', qa_db_user_notices_selectspec($loginuserid));
    }
    qa_db_queue_pending_select('navpages', qa_db_pages_selectspec(array('B', 'M', 'O', 'F')));
    qa_db_queue_pending_select('widgets', qa_db_widgets_selectspec());
}
コード例 #6
0
ファイル: overrides.php プロジェクト: rahularyan/dude-theme
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']));
}
コード例 #7
0
ファイル: user_model.php プロジェクト: mathjoy/math-duodaa
 function get_qa_avartar_html($user, $size = 200)
 {
     $userid_array = qa_handles_to_userids(array($user));
     $userid = $userid_array[$user];
     $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
     $avartahtml = qa_get_user_avatar_html($useraccount['flags'], $useraccount['email'], $useraccount['handle'], $useraccount['avatarblobid'], $useraccount['avatarwidth'], $useraccount['avatarheight'], qa_opt('avatar_profile_size'));
     $avartahtml = strtolower($avartahtml);
     if ($avartahtml != null) {
         $avartahtml = strtolower($avartahtml);
         $avartahtml = str_replace('?', '\\?', $avartahtml);
         //生成avarta的html串,从站点的根目录引用
     } else {
         $avartahtml = '<a href="' . $this->config->item('qaroot_src') . '?qa=user/' . $user . '" class="qa-user-link">';
         $avartahtml .= '<img src="' . base_url($this->config->item('app_src')) . '/views/theme/' . $this->config->item('theme') . '/img/default_avatar.jpg' . '"/>';
         $avartahtml .= '</a>';
     }
     return $avartahtml;
 }
コード例 #8
0
ファイル: register.php プロジェクト: GitFuture/bmf
function sendNewConfirm($userid)
{
    require_once QA_INCLUDE_DIR . 'db/users.php';
    require_once QA_INCLUDE_DIR . 'db/selects.php';
    require_once QA_INCLUDE_DIR . 'app/emails.php';
    $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/confirm_subject'), qa_lang('emails/confirm_body'), array('^url' => getNewConfirmUrl($userid, $userinfo['handle'])))) {
        qa_fatal_error('Could not send email confirmation');
    }
    // $userinfo=qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
    // $params = array();
    // $params['fromemail'] = qa_opt('from_email'),
    // $params['fromname'] = qa_opt('site_title'),
    // $params['toemail'] = $userinfo['email'];
    // $params['toname'] = $userinfo['handle'];
    // $params['subject'] = qa_lang('emails/confirm_subject');
    // $params['body'] = qa_lang('emails/confirm_body');
    // qa_send_email($params);
}
コード例 #9
0
ファイル: functions.php プロジェクト: microbye/CleanStrap
function cs_user_data($handle)
{
    $userid = qa_handle_to_userid($handle);
    $identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
    if (defined('QA_WORDPRESS_INTEGRATE_PATH')) {
        $u = qa_db_select_with_pending(qa_db_user_rank_selectspec($handle), qa_db_user_points_selectspec($identifier));
        $user = array();
        $user[]['points'] = $u[1]['points'];
        unset($u[1]['points']);
        $user[] = 0;
        $user[] = $u[1];
    } else {
        $user[0] = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
        $user[1]['rank'] = qa_db_select_with_pending(qa_db_user_rank_selectspec($handle));
        $user[2] = qa_db_select_with_pending(qa_db_user_points_selectspec($identifier));
        $user = $user[0] + $user[1] + $user[2];
    }
    return $user;
}
コード例 #10
0
 function get_user_activity($handle, $limit = 10)
 {
     $userid = qa_handle_to_userid($handle);
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     require_once QA_INCLUDE_DIR . 'qa-app-format.php';
     $identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
     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($userid, $identifier, $limit), qa_db_user_recent_a_qs_selectspec($userid, $identifier), qa_db_user_recent_c_qs_selectspec($userid, $identifier), qa_db_user_recent_edit_qs_selectspec($userid, $identifier));
     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, $limit);
     $usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions), false);
     $htmldefaults = qa_post_html_defaults('Q');
     $htmldefaults['whoview'] = false;
     $htmldefaults['voteview'] = false;
     $htmldefaults['avatarsize'] = 0;
     foreach ($questions as $question) {
         $qa_content[] = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, array('voteview' => false) + qa_post_html_options($question, $htmldefaults));
     }
     $output = '<div class="user-activities">';
     $output .= '<ul>';
     if (isset($qa_content)) {
         foreach ($qa_content as $qs) {
             $icon = 'icon-time undefined';
             $output .= '<li class="activity-item">';
             $output .= '<div class="list-right">';
             $output .= '<div class="type pull-left ' . $icon . '"></div>';
             $output .= '<div class="what"><a class="what-task" href="' . @$qs['url'] . '">' . $qs['what'] . '</a>';
             $output .= '<a href="' . $qs['url'] . '">' . $qs['title'] . '</a> </div>';
             $output .= '<strong class="when">' . implode(' ', $qs['when']) . '</strong>';
             $output .= '</div>';
             $output .= '</li>';
         }
     } else {
         $output .= '<li>' . qa_lang('cleanstrap/no_activity_yet') . '</li>';
     }
     $output .= '</ul>';
     $output .= '</div>';
     return $output;
 }
コード例 #11
0
 function process_request($request)
 {
     $userid = qa_get_logged_in_userid();
     $categoryid = mp_get_categoryid();
     $users = mp_get_category_userids($categoryid);
     $qa_content = qa_content_prepare();
     $qa_content['title'] = 'Classroom';
     $data = "<div class='mp-classroom'>";
     $data .= "<center><div class='mp-classroom-teacher'>&nbsp;</div></center>";
     $data .= "<div class='mp-classroom-users'>";
     foreach ($users as $user) {
         $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($user['userid'], true));
         $data .= "<div class='mp-classroom-user'>";
         $data .= "<div class='mp-classroom-avatar'></div>";
         $data .= "<div class='mp-classroom-useremail'>" . qa_get_one_user_html($userinfo['handle'], false) . "</div>";
         $data .= "</div>";
     }
     $data .= "</div></div>";
     $qa_content['custom'] = $data;
     return $qa_content;
 }
コード例 #12
0
ファイル: CustomAJAXChat.php プロジェクト: arjunsuresh/chat
 function getValidLoginUserData()
 {
     // Check if we have a valid registered user:
     if (!(qa_get_logged_in_userid() === null)) {
         $userData = array();
         $userId = qa_get_logged_in_userid();
         $userData['userID'] = $userId;
         $userData['userName'] = $this->trimUserName(qa_get_logged_in_handle());
         if (qa_get_logged_in_level() >= QA_USER_LEVEL_MODERATOR) {
             $userData['userRole'] = AJAX_CHAT_ADMIN;
         } elseif (qa_get_logged_in_level() == QA_USER_LEVEL_EDITOR) {
             $userData['userRole'] = AJAX_CHAT_MODERATOR;
         } else {
             $userData['userRole'] = AJAX_CHAT_USER;
         }
         $user = qa_db_select_with_pending(qa_db_user_account_selectspec($userId, true));
         $userData['avatar'] = qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true);
         return $userData;
     } else {
         // Guest users:
         return $this->getGuestUser();
     }
 }
コード例 #13
0
                    }
                    break;
            }
        }
        if (count($inprofile)) {
            $filtermodules = qa_load_modules_with('filter', 'filter_profile');
            foreach ($filtermodules as $filtermodule) {
                $filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile);
            }
        }
        foreach ($userfields as $userfield) {
            if (!isset($errors[$userfield['fieldid']])) {
                qa_db_user_profile_set($userid, $userfield['title'], $inprofile[$userfield['fieldid']]);
            }
        }
        list($useraccount, $userprofile) = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true), qa_db_user_profile_selectspec($userid, true));
        qa_report_event('u_save', $userid, $useraccount['handle'], qa_cookie_get());
        if (empty($errors)) {
            qa_redirect('account', array('state' => 'profile-saved'));
        }
        qa_logged_in_user_flush();
    }
}
//	Process change password if clicked
if (qa_clicked('dochangepassword')) {
    require_once QA_INCLUDE_DIR . 'qa-app-users-edit.php';
    $inoldpassword = qa_post_text('oldpassword');
    $innewpassword1 = qa_post_text('newpassword1');
    $innewpassword2 = qa_post_text('newpassword2');
    if (!qa_check_form_security_code('password', qa_post_text('code'))) {
        $errors['page'] = qa_lang_html('misc/form_security_again');
コード例 #14
0
$handle = qa_request_part(1);
$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
if (QA_FINAL_EXTERNAL_USERS) {
    qa_fatal_error('User accounts are handled by external code');
}
if (!strlen($handle)) {
    qa_redirect('users');
}
if (!isset($loginuserid)) {
    $qa_content = qa_content_prepare();
    $qa_content['error'] = qa_insert_login_links(qa_lang_html('misc/message_must_login'), qa_request());
    return $qa_content;
}
//	Find the user profile and questions and answers for this handle
list($toaccount, $torecent, $fromrecent) = qa_db_select_with_pending(qa_db_user_account_selectspec($handle, false), qa_db_recent_messages_selectspec($loginuserid, true, $handle, false), qa_db_recent_messages_selectspec($handle, false, $loginuserid, true));
//	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) {
    return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
}
//	Check that we have permission and haven't reached the limit
$errorhtml = null;
switch (qa_user_permit_error(null, QA_LIMIT_MESSAGES)) {
    case 'limit':
        $errorhtml = qa_lang_html('misc/message_limit');
        break;
    case false:
        break;
    default:
        $errorhtml = qa_lang_html('users/no_permission');
        break;
コード例 #15
0
ファイル: user-wall.php プロジェクト: swuit/swuit-q2a
*/
if (!defined('QA_VERSION')) {
    // don't allow this page to be requested directly from browser
    header('Location: ../');
    exit;
}
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/messages.php';
//	Check we're not using single-sign on integration, which doesn't allow walls
if (QA_FINAL_EXTERNAL_USERS) {
    qa_fatal_error('User accounts are handled by external code');
}
//	$handle, $userhtml are already set by qa-page-user.php
$start = qa_get_start();
//	Find the questions for this user
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));
if (!is_array($useraccount)) {
    // check the user exists
    return include QA_INCLUDE_DIR . 'qa-page-not-found.php';
}
//	Perform pagination
$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);
//	Process deleting or adding a wall post (similar but not identical code to qq-page-user-profile.php)
$errors = array();
$wallposterrorhtml = qa_wall_error_html($loginuserid, $useraccount['userid'], $useraccount['flags']);
foreach ($usermessages as $message) {
    if ($message['deleteable'] && qa_clicked('m' . $message['messageid'] . '_dodelete')) {
コード例 #16
0
 function notify($uid, $notices)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-users.php';
     require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
     if (QA_FINAL_EXTERNAL_USERS) {
         $publictohandle = qa_get_public_from_userids(array($uid));
         $handle = @$publictohandle[$uid];
     } else {
         $user = qa_db_single_select(qa_db_user_account_selectspec($uid, true));
         $handle = @$user['handle'];
     }
     $subject = qa_opt('priv_email_subject');
     $body = qa_opt('priv_email_body');
     $n = explode(',', $notices);
     if (count($n) > 1) {
         $body = preg_replace('/\\^single=`([^`]+)`/', '', $body);
         preg_match('/\\^multi=`([^`]+)`/', $body, $multi);
         $m = str_replace('#', count($n), $multi[1]);
         $body = preg_replace('/\\^multi=`([^`]+)`/', $m, $body);
     } else {
         $body = preg_replace('/\\^single=`([^`]+)`/', '$1', $body);
         $body = preg_replace('/\\^multi=`([^`]+)`/', '', $body);
     }
     $site_url = qa_opt('site_url');
     $profile_url = qa_path_html('user/' . $handle, null, $site_url);
     $subs = array('^profile_url' => $profile_url, '^site_url' => $site_url);
     qa_send_notification($uid, '@', $handle, $subject, $body, $subs);
 }
コード例 #17
0
ファイル: qa-app-posts.php プロジェクト: mathjoy/math-duodaa
function qa_post_userid_to_handle($userid)
{
    if (isset($userid)) {
        if (QA_FINAL_EXTERNAL_USERS) {
            require_once QA_INCLUDE_DIR . 'qa-app-users.php';
            $handles = qa_get_public_from_userids(array($userid));
            return @$handles[$userid];
        } else {
            $user = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
            if (!is_array($user)) {
                qa_fatal_error('User ID could not be found: ' . $userid);
            }
            return $user['handle'];
        }
    }
    return null;
}
コード例 #18
0
	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;
}
require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
//	$handle, $userhtml are already set by qa-page-user.php - also $userid if using external user integration
//	Find the recent activity for this user
$loginuserid = qa_get_logged_in_userid();
$identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
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), qa_db_user_recent_c_qs_selectspec($loginuserid, $identifier), qa_db_user_recent_edit_qs_selectspec($loginuserid, $identifier));
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);
//	Prepare content for theme
$qa_content = qa_content_prepare(true);
if (count($questions)) {
    $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);
}
コード例 #19
0
 function core_login($username, $password, $remember = false)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
     if (qa_user_limits_remaining(QA_LIMIT_LOGINS)) {
         require_once QA_INCLUDE_DIR . 'qa-db-users.php';
         require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
         $errors = array();
         if (qa_opt('allow_login_email_only') || strpos($username, '@') !== false) {
             // handles can't contain @ symbols
             $matchusers = qa_db_user_find_by_email($username);
         } else {
             $matchusers = qa_db_user_find_by_handle($username);
         }
         if (count($matchusers) == 1) {
             // if matches more than one (should be impossible), don't log in
             $inuserid = $matchusers[0];
             $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($inuserid, true));
             if (strtolower(qa_db_calc_passcheck($password, $userinfo['passsalt'])) == strtolower($userinfo['passcheck'])) {
                 // login
                 require_once QA_INCLUDE_DIR . 'qa-app-users.php';
                 qa_set_logged_in_user($inuserid, $userinfo['handle'], $remember ? true : false);
                 return $userinfo;
             } else {
                 $this->error = new IXR_Error(1512, qa_lang('users/password_wrong'));
             }
         } else {
             $this->error = new IXR_Error(1512, qa_lang('users/user_not_found'));
         }
     } else {
         $this->error = new IXR_Error(1512, qa_lang('users/login_limit'));
     }
     qa_limits_increment(null, QA_LIMIT_LOGINS);
     // log on failure
     return false;
 }
コード例 #20
0
 function check_user_fields($userid, $params)
 {
     list($useraccount, $userprofile, $userfields) = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true), qa_db_user_profile_selectspec($userid, true), qa_db_userfields_selectspec());
     // avatar badge
     if (qa_opt('avatar_allow_upload') && isset($useraccount['avatarblobid'])) {
         $badges = array('avatar');
         qa_badge_award_check($badges, false, $userid);
     }
     // profile completion
     $missing = false;
     foreach ($userfields as $userfield) {
         if (!isset($userprofile[$userfield['title']]) || @$userprofile[$userfield['title']] === '') {
             $missing = true;
             break;
         }
     }
     if (!$missing) {
         $badges = array('profiler');
         qa_badge_award_check($badges, false, $userid);
     }
 }
コード例 #21
0
ファイル: unsubscribe.php プロジェクト: swuit/swuit-q2a
    exit;
}
require_once QA_INCLUDE_DIR . 'db/users.php';
//	Check we're not using single-sign on integration
if (QA_FINAL_EXTERNAL_USERS) {
    qa_fatal_error('User login is handled by external code');
}
//	Check the code and unsubscribe the user if appropriate
$unsubscribed = false;
$loginuserid = qa_get_logged_in_userid();
$incode = trim(qa_get('c'));
// trim to prevent passing in blank values to match uninitiated DB rows
$inhandle = qa_get('u');
if (!empty($inhandle)) {
    // match based on code and handle provided on URL
    $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($inhandle, false));
    if (strtolower(trim(@$userinfo['emailcode'])) == strtolower($incode)) {
        qa_db_user_set_flag($userinfo['userid'], QA_USER_FLAGS_NO_MAILINGS, true);
        $unsubscribed = true;
    }
}
if (!$unsubscribed && isset($loginuserid)) {
    // as a backup, also unsubscribe logged in user
    qa_db_user_set_flag($loginuserid, QA_USER_FLAGS_NO_MAILINGS, true);
    $unsubscribed = true;
}
//	Prepare content for theme
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('users/unsubscribe_title');
if ($unsubscribed) {
    $qa_content['error'] = strtr(qa_lang_html('users/unsubscribe_complete'), array('^0' => qa_html(qa_opt('site_title')), '^1' => '<a href="' . qa_path_html('account') . '">', '^2' => '</a>'));
コード例 #22
0
function qa_admin_single_click($entityid, $action)
{
    $userid = qa_get_logged_in_userid();
    if (!QA_FINAL_EXTERNAL_USERS && ($action == 'userapprove' || $action == 'userblock')) {
        // approve/block moderated users
        require_once QA_INCLUDE_DIR . 'db/selects.php';
        $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($entityid, true));
        if (isset($useraccount) && qa_get_logged_in_level() >= QA_USER_LEVEL_MODERATOR) {
            switch ($action) {
                case 'userapprove':
                    if ($useraccount['level'] <= QA_USER_LEVEL_APPROVED) {
                        // don't demote higher level users
                        require_once QA_INCLUDE_DIR . 'app/users-edit.php';
                        qa_set_user_level($useraccount['userid'], $useraccount['handle'], QA_USER_LEVEL_APPROVED, $useraccount['level']);
                        return true;
                    }
                    break;
                case 'userblock':
                    require_once QA_INCLUDE_DIR . 'app/users-edit.php';
                    qa_set_user_blocked($useraccount['userid'], $useraccount['handle'], true);
                    return true;
                    break;
            }
        }
    } else {
        // something to do with a post
        require_once QA_INCLUDE_DIR . 'app/posts.php';
        $post = qa_post_get_full($entityid);
        if (isset($post)) {
            $queued = substr($post['type'], 1) == '_QUEUED';
            switch ($action) {
                case 'approve':
                    if ($queued && !qa_user_post_permit_error('permit_moderate', $post)) {
                        qa_post_set_hidden($entityid, false, $userid);
                        return true;
                    }
                    break;
                case 'reject':
                    if ($queued && !qa_user_post_permit_error('permit_moderate', $post)) {
                        qa_post_set_hidden($entityid, true, $userid);
                        return true;
                    }
                    break;
                case 'hide':
                    if (!$queued && !qa_user_post_permit_error('permit_hide_show', $post)) {
                        qa_post_set_hidden($entityid, true, $userid);
                        return true;
                    }
                    break;
                case 'reshow':
                    if ($post['hidden'] && !qa_user_post_permit_error('permit_hide_show', $post)) {
                        qa_post_set_hidden($entityid, false, $userid);
                        return true;
                    }
                    break;
                case 'delete':
                    if ($post['hidden'] && !qa_user_post_permit_error('permit_delete_hidden', $post)) {
                        qa_post_delete($entityid);
                        return true;
                    }
                    break;
                case 'clearflags':
                    require_once QA_INCLUDE_DIR . 'app/votes.php';
                    if (!qa_user_post_permit_error('permit_hide_show', $post)) {
                        qa_flags_clear_all($post, $userid, qa_get_logged_in_handle(), null);
                        return true;
                    }
                    break;
            }
        }
    }
    return false;
}
コード例 #23
0
function qa_post_userid_to_handle($userid)
{
    if (isset($userid)) {
        $user = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
        if (!is_array($user)) {
            qa_fatal_error('User ID could not be found: ' . $userid);
        }
        return $user['handle'];
    }
    return null;
}
コード例 #24
0
ファイル: users.php プロジェクト: kosmoluna/question2answer
 function qa_get_user_email($userid)
 {
     $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true));
     return $userinfo['email'];
 }
コード例 #25
0
ファイル: wallpost.php プロジェクト: Trideon/gigolo
	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
*/
require_once QA_INCLUDE_DIR . 'app/messages.php';
require_once QA_INCLUDE_DIR . 'app/users.php';
require_once QA_INCLUDE_DIR . 'app/cookies.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
$message = qa_post_text('message');
$tohandle = qa_post_text('handle');
$morelink = qa_post_text('morelink');
$touseraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($tohandle, false));
$loginuserid = qa_get_logged_in_userid();
$errorhtml = qa_wall_error_html($loginuserid, $touseraccount['userid'], $touseraccount['flags']);
if ($errorhtml || !strlen($message) || !qa_check_form_security_code('wall-' . $tohandle, qa_post_text('code'))) {
    echo "QA_AJAX_RESPONSE\n0";
} else {
    $messageid = qa_wall_add_post($loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), $touseraccount['userid'], $touseraccount['handle'], $message, '');
    $touseraccount['wallposts']++;
    // won't have been updated
    $usermessages = qa_db_select_with_pending(qa_db_recent_messages_selectspec(null, null, $touseraccount['userid'], true, qa_opt('page_size_wall')));
    $usermessages = qa_wall_posts_add_rules($usermessages, 0);
    $themeclass = qa_load_theme_class(qa_get_site_theme(), 'wall', null, null);
    echo "QA_AJAX_RESPONSE\n1\n";
    echo 'm' . $messageid . "\n";
    // element in list to be revealed
    foreach ($usermessages as $message) {
コード例 #26
0
ファイル: users-edit.php プロジェクト: swuit/swuit-q2a
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']));
}
コード例 #27
0
 require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
 qa_limits_increment(null, QA_LIMIT_LOGINS);
 $inemailhandle = qa_post_text('emailhandle');
 $inpassword = qa_post_text('password');
 $inremember = qa_post_text('remember');
 $errors = array();
 if (qa_opt('allow_login_email_only') || strpos($inemailhandle, '@') !== false) {
     // handles can't contain @ symbols
     $matchusers = qa_db_user_find_by_email($inemailhandle);
 } else {
     $matchusers = qa_db_user_find_by_handle($inemailhandle);
 }
 if (count($matchusers) == 1) {
     // if matches more than one (should be impossible), don't log in
     $inuserid = $matchusers[0];
     $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($inuserid, true));
     if (strtolower(qa_db_calc_passcheck($inpassword, $userinfo['passsalt'])) == strtolower($userinfo['passcheck'])) {
         // login and redirect
         require_once QA_INCLUDE_DIR . 'qa-app-users.php';
         qa_set_logged_in_user($inuserid, $userinfo['handle'], $inremember ? true : false);
         $topath = qa_get('to');
         if (isset($topath)) {
             qa_redirect_raw(qa_path_to_root() . $topath);
         } elseif ($passwordsent) {
             qa_redirect('account');
         } else {
             qa_redirect('welcome');
         }
     } else {
         $errors['password'] = qa_lang('users/password_wrong');
     }
コード例 #28
0
	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;
}
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
//	$handle, $userhtml are already set by qa-page-user.php - also $userid if using external user integration
$start = qa_get_start();
//	Find the questions for this user
$loginuserid = qa_get_logged_in_userid();
$identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
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
    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);
//	Prepare content for theme
$qa_content = qa_content_prepare(true);
if (count($questions)) {
    $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);
コード例 #29
0
 function qa_check_all_users_badges()
 {
     $awarded = 0;
     $users;
     $temp = qa_db_query_sub('SELECT * FROM ^posts');
     while (($post = qa_db_read_one_assoc($temp, true)) !== null) {
         if (!$post['userid']) {
             continue;
         }
         $user = '******' . $post['userid'];
         $pid = $post['postid'];
         $pt = $post['type'];
         // get post count
         if (isset($users[$user]) && isset($users[$user][$pt])) {
             $users[$user][$pt]++;
         } else {
             $users[$user][$pt] = 1;
         }
         // get post votes
         if ($post['netvotes'] != 0) {
             $users[$user][$pt . 'votes'][] = array('id' => $pid, 'votes' => (int) $post['netvotes'], 'parentid' => $post['parentid'], 'created' => $post['created']);
         }
         // get post views
         if ($post['views']) {
             $users[$user]['views'][] = array('id' => $pid, 'views' => $post['views']);
         }
     }
     //votes received and given out
     $voter = qa_db_read_all_assoc(qa_db_query_sub('SELECT userid,qupvotes,qdownvotes,aupvotes,adownvotes,upvoteds FROM ^userpoints'));
     foreach ($voter as $idx => $votes) {
         $user = '******' . $votes['userid'];
         // votes
         $users[$user]['votes'] = (int) $votes['qupvotes'] + (int) $votes['qdownvotes'] + (int) $votes['aupvotes'] + (int) $votes['adownvotes'];
         // voteds
         $users[$user]['voted'] = (int) $votes['upvoteds'];
         unset($voter[$idx]);
     }
     // flags
     $flag_result = qa_db_read_all_values(qa_db_query_sub('SELECT userid FROM ^uservotes WHERE flag > 0'));
     foreach ($flag_result as $idx => $flag) {
         $user = '******' . $flag;
         // get flag count
         if (isset($users[$user]) && isset($users[$user]['flags'])) {
             $users[$user]['flags']++;
         } else {
             $users[$user]['flags'] = 1;
         }
         unset($flag_result[$idx]);
     }
     // per user loop
     foreach ($users as $user => $data) {
         $uid = (int) substr($user, 4);
         // bulk posts
         $badges = array('Q' => array('asker', 'questioner', 'inquisitor'), 'A' => array('answerer', 'lecturer', 'preacher'), 'C' => array('commenter', 'commentator', 'annotator'));
         foreach ($badges as $pt => $slugs) {
             if (!isset($data[$pt])) {
                 continue;
             }
             $awarded += count(qa_badge_award_check($slugs, $data[$pt], $uid, null, 0));
         }
         // nice Q&A
         $badges = array('nice_question', 'good_question', 'great_question', 'nice_answer', 'good_answer', 'great_answer');
         if ($this->badge_activated($badges)) {
             $badges = array('Q' => array('nice_question', 'good_question', 'great_question'), 'A' => array('nice_answer', 'good_answer', 'great_answer'));
             foreach ($badges as $pt => $slugs) {
                 foreach ($slugs as $badge_slug) {
                     if (!isset($data[$pt . 'votes'])) {
                         continue;
                     }
                     foreach ($data[$pt . 'votes'] as $idv) {
                         // poll plugin integration
                         if ($pt == 'A' && qa_opt('poll_enable')) {
                             $poll = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^postmeta WHERE post_id=# AND meta_key=$', $idv['id'], 'is_poll'), true);
                             if ($poll) {
                                 continue;
                             }
                         }
                         if ((int) $idv['votes'] >= (int) qa_opt('badge_' . $badge_slug . '_var') && qa_opt('badge_' . $badge_slug . '_enabled') !== '0') {
                             $result = qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND object_id=# AND badge_slug=$', $uid, $idv['id'], $badge_slug), true);
                             if ($result == null) {
                                 // not already awarded this badge
                                 $this->award_badge($idv['id'], $uid, $badge_slug, false, true);
                                 $awarded++;
                             }
                             // old question answer vote checks
                             if ($pt == 'A') {
                                 $qid = $idv['parentid'];
                                 $create = strtotime($idv['created']);
                                 $parent = $this->get_post_data($qid);
                                 $pcreate = strtotime($parent['created']);
                                 $diff = round(abs($pcreate - $create) / 60 / 60 / 24);
                                 $badge_slug2 = $badge_slug . '_old';
                                 if ($diff >= (int) qa_opt('badge_' . $badge_slug2 . '_var') && qa_opt('badge_' . $badge_slug2 . '_enabled') !== '0') {
                                     $result = qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND object_id=# AND badge_slug=$', $uid, $idv['id'], $badge_slug2), true);
                                     if ($result == null) {
                                         // not already awarded for this answer
                                         $this->award_badge($idv['id'], $uid, $badge_slug2);
                                         $awarded++;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // votes per user badges
         if (isset($data['votes'])) {
             $votes = $data['votes'];
             $badges = array('voter', 'avid_voter', 'devoted_voter');
             $awarded += count(qa_badge_award_check($badges, $votes, $uid, null, 0));
         }
         // voted per user badges
         if (isset($data['voted'])) {
             $votes = $data['voted'];
             $badges = array('liked', 'loved', 'revered');
             $awarded += count(qa_badge_award_check($badges, $votes, $uid, null, 0));
         }
         // views per post badges
         if (isset($data['views'])) {
             $badges = array('notable_question', 'popular_question', 'famous_question');
             foreach ($data['views'] as $idv) {
                 $awarded += count(qa_badge_award_check($badges, $idv['views'], $uid, $idv['id'], 0));
             }
         }
         // flags per user
         if (isset($data['flags'])) {
             $flags = $data['flags'];
             $badges = array('watchdog', 'bloodhound', 'pitbull');
             $awarded += count(qa_badge_award_check($badges, $flags, $uid, null, 0));
         }
         unset($users[$user]);
     }
     // selects, selecteds
     $badges = array('gifted', 'wise', 'enlightened', 'grateful', 'respectful', 'reverential');
     if ($this->badge_activated($badges)) {
         $selects = qa_db_read_all_assoc(qa_db_query_sub('SELECT aselects, aselecteds, userid FROM ^userpoints'));
         foreach ($selects as $idx => $s) {
             $uid = $s['userid'];
             if (isset($s['aselecteds'])) {
                 $count = $s['aselecteds'];
                 $badges = array('gifted', 'wise', 'enlightened');
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             if (isset($s['aselects'])) {
                 $count = $s['aselects'];
                 $badges = array('grateful', 'respectful', 'reverential');
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             unset($selects[$idx]);
         }
     }
     // achievements
     $badges = array('dedicated', 'devoted', 'zealous', 'visitor', 'trouper', 'veteran', 'regular', 'old_timer', 'ancestor', 'reader', 'avid_reader', 'devoted_reader');
     if ($this->badge_activated($badges)) {
         $userq = qa_db_query_sub('SELECT user_id AS uid,questions_read AS qr,oldest_consec_visit AS ocv,longest_consec_visit AS lcv,total_days_visited AS tdv,last_visit AS lv,first_visit AS fv,posts_edited AS pe FROM ^achievements');
         while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
             $uid = $user['uid'];
             // edits
             $count = $user['pe'];
             $badges = array('editor', 'copy_editor', 'senior_editor');
             $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             // on-sign-in badges
             // check lapse in days since last visit
             // using julian days
             $todayj = GregorianToJD(date('n'), date('j'), date('Y'));
             $last_visit = strtotime($user['lv']);
             $lastj = GregorianToJD(date('n', $last_visit), date('j', $last_visit), date('Y', $last_visit));
             $last_diff = $todayj - $lastj;
             $first_visit = strtotime($user['fv']);
             $first_visitj = GregorianToJD(date('n', $first_visit), date('j', $first_visit), date('Y', $first_visit));
             $first_visit_diff = $todayj - $first_visitj;
             $badges = array('dedicated', 'devoted', 'zealous');
             $awarded += count(qa_badge_award_check($badges, $user['lcv'], $uid, null, 0));
             $badges = array('visitor', 'trouper', 'veteran');
             $awarded += count(qa_badge_award_check($badges, $user['tdv'], $uid, null, 0));
             $badges = array('regular', 'old_timer', 'ancestor');
             $awarded += count(qa_badge_award_check($badges, $first_visit_diff, $uid, null, 0));
             // views
             $badges = array('reader', 'avid_reader', 'devoted_reader');
             $awarded += count(qa_badge_award_check($badges, $user['qr'], $uid, null, 0));
         }
     }
     // points
     $badges = array('100_club', '1000_club', '10000_club');
     if ($this->badge_activated($badges)) {
         $userq = qa_db_query_sub('SELECT userid, points FROM ^userpoints');
         while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
             $awarded += count(qa_badge_award_check($badges, $user['points'], $user['userid'], null, 0));
         }
     }
     if (!QA_FINAL_EXTERNAL_USERS) {
         // verified
         $badges = array('verified');
         if ($this->badge_activated($badges)) {
             $userq = qa_db_query_sub('SELECT userid, flags FROM ^users WHERE flags&#', QA_USER_FLAGS_EMAIL_CONFIRMED);
             while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
                 $awarded += count(qa_badge_award_check($badges, false, $user['userid'], null, 0));
             }
         }
         // profile stuff
         $badges = array('avatar', 'profiler');
         if ($this->badge_activated($badges)) {
             $userq = qa_db_query_sub('SELECT userid FROM ^users');
             while (($userid = qa_db_read_one_value($userq, true)) !== null) {
                 list($useraccount, $userprofile, $userfields) = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true), qa_db_user_profile_selectspec($userid, true), qa_db_userfields_selectspec());
                 // avatar badge
                 if (qa_opt('avatar_allow_upload') && isset($useraccount['avatarblobid'])) {
                     $badges = array('avatar');
                     $awarded += count(qa_badge_award_check($badges, false, $userid, null, 0));
                 }
                 // profile completion
                 $missing = false;
                 foreach ($userfields as $userfield) {
                     if (!isset($userprofile[$userfield['title']]) || @$userprofile[$userfield['title']] === '') {
                         $missing = true;
                         break;
                     }
                 }
                 if (!$missing) {
                     $badges = array('profiler');
                     $awarded += count(qa_badge_award_check($badges, false, $userid, null, 0));
                 }
             }
         }
     }
     // rebuild badges from other plugins - experimental! - $module->custom_badges_rebuild() returns number of badges awarded.
     $moduletypes = qa_list_module_types();
     foreach ($moduletypes as $moduletype) {
         $modulenames = qa_list_modules($moduletype);
         foreach ($modulenames as $modulename) {
             $module = qa_load_module($moduletype, $modulename);
             if (method_exists($module, 'custom_badges_rebuild')) {
                 $awarded += $module->custom_badges_rebuild();
             }
         }
     }
     // badges
     $badges = array('medalist', 'champion', 'olympian');
     if ($this->badge_activated($badges)) {
         $badgelist = qa_db_read_all_values(qa_db_query_sub('SELECT user_id FROM ^userbadges'));
         $users = array();
         foreach ($badgelist as $idx => $medal) {
             $user = '******' . $medal;
             // get badge count
             if (isset($users[$user]) && isset($users[$user]['medals'])) {
                 $users[$user]['medals']++;
             } else {
                 $users[$user]['medals'] = 1;
             }
             unset($badgelist[$idx]);
         }
         foreach ($users as $user => $data) {
             $uid = (int) substr($user, 4);
             // check badges
             if (isset($data['medals'])) {
                 $uid = (int) substr($user, 4);
                 $count = $data['medals'];
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             unset($users[$user]);
         }
     }
     // return ok text
     return $awarded . ' badge' . ($awarded != 1 ? 's' : '') . ' awarded.';
 }
コード例 #30
0
 function process_request($request)
 {
     $qa_content = qa_content_prepare();
     $qa_content['title'] = qa_lang('badges/badge_list_title');
     $badges = qa_get_badge_list();
     $totalawarded = 0;
     $qa_content['custom'] = '<em>' . qa_lang('badges/badge_list_pre') . '</em><br />';
     $qa_content['custom2'] = '<table cellspacing="20">';
     $c = 2;
     $result = qa_db_read_all_assoc(qa_db_query_sub('SELECT user_id,badge_slug  FROM ^userbadges'));
     $count = array();
     foreach ($result as $r) {
         if (qa_opt('badge_' . $r['badge_slug'] . '_enabled') == '0') {
             continue;
         }
         if (isset($count[$r['badge_slug']][$r['user_id']])) {
             $count[$r['badge_slug']][$r['user_id']]++;
         } else {
             $count[$r['badge_slug']][$r['user_id']] = 1;
         }
         $totalawarded++;
         if (isset($count[$r['badge_slug']]['count'])) {
             $count[$r['badge_slug']]['count']++;
         } else {
             $count[$r['badge_slug']]['count'] = 1;
         }
     }
     foreach ($badges as $slug => $info) {
         if (qa_opt('badge_' . $slug . '_enabled') == '0') {
             continue;
         }
         $badge_name = qa_badge_name($slug);
         if (!qa_opt('badge_' . $slug . '_name')) {
             qa_opt('badge_' . $slug . '_name', $badge_name);
         }
         $name = qa_opt('badge_' . $slug . '_name');
         $var = qa_opt('badge_' . $slug . '_var');
         $desc = qa_badge_desc_replace($slug, $var, false);
         $type = qa_get_badge_type($info['type']);
         $types = $type['slug'];
         $typen = $type['name'];
         $qa_content['custom' . ++$c] = '<tr><td class="badge-entry"><div class="badge-entry-badge"><span class="badge-' . $types . '" title="' . $typen . '">' . $name . '</span>&nbsp;<span class="badge-entry-desc">' . $desc . '</span>' . (isset($count[$slug]) ? '&nbsp;<span title="' . $count[$slug]['count'] . ' ' . qa_lang('badges/awarded') . '" class="badge-count-link" onclick="jQuery(\'#badge-users-' . $slug . '\').slideToggle()">x' . $count[$slug]['count'] . '</span>' : '') . '</div>';
         // source users
         if (qa_opt('badge_show_source_users') && isset($count[$slug])) {
             $users = array();
             require_once QA_INCLUDE_DIR . 'qa-app-users.php';
             $qa_content['custom' . $c] .= '<div style="display:none" id="badge-users-' . $slug . '" class="badge-users">';
             foreach ($count[$slug] as $uid => $ucount) {
                 if ($uid == 'count') {
                     continue;
                 }
                 if (QA_FINAL_EXTERNAL_USERS) {
                     $handles = qa_get_public_from_userids(array($uid));
                     $handle = @$handles[$uid];
                 } else {
                     $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($uid, true));
                     $handle = @$useraccount['handle'];
                 }
                 if (!$handle) {
                     continue;
                 }
                 $users[] = '<a href="' . qa_path_html('user/' . $handle) . '">' . $handle . ($ucount > 1 ? ' x' . $ucount : '') . '</a>';
             }
             $qa_content['custom' . $c] .= implode('<br/>', $users) . '</div>';
         }
         $qa_content['custom' . $c] .= '</td></tr>';
     }
     $qa_content['custom' . ++$c] = '<tr><td class="badge-entry"><span class="total-badges">' . count($badges) . ' ' . qa_lang('badges/badges_total') . '</span>' . ($totalawarded > 0 ? ', <span class="total-badge-count">' . $totalawarded . ' ' . qa_lang('badges/awarded_total') . '</span>' : '') . '</td></tr></table>';
     if (isset($qa_content['navigation']['main']['custom-2'])) {
         $qa_content['navigation']['main']['custom-2']['selected'] = true;
     }
     return $qa_content;
 }