if (isset($loginuserid) && !QA_FINAL_EXTERNAL_USERS) {
    $qa_content['favorite'] = qa_favorite_form(QA_ENTITY_USER, $useraccount['userid'], $favorite, qa_lang_sub($favorite ? 'main/remove_x_favorites' : 'users/add_user_x_favorites', $handle));
}
//	General information about the user, only available if we're using internal user management
if (!QA_FINAL_EXTERNAL_USERS) {
    $qa_content['form_profile'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'wide', 'fields' => array('avatar' => array('type' => 'image', 'style' => 'tall', 'label' => '', 'html' => qa_get_user_avatar_html($useraccount['flags'], $useraccount['email'], $useraccount['handle'], $useraccount['avatarblobid'], $useraccount['avatarwidth'], $useraccount['avatarheight'], qa_opt('avatar_profile_size'))), 'removeavatar' => null, 'duration' => array('type' => 'static', 'label' => qa_lang_html('users/member_for'), 'value' => qa_html(qa_time_to_string(qa_opt('db_time') - $useraccount['created']))), 'level' => array('type' => 'static', 'label' => qa_lang_html('users/member_type'), 'tags' => 'NAME="level"', 'value' => qa_html(qa_user_level_string($useraccount['level'])), 'note' => $useraccount['flags'] & QA_USER_FLAGS_USER_BLOCKED && isset($maxlevelassign) ? qa_lang_html('users/user_blocked') : '')));
    if (empty($qa_content['form_profile']['fields']['avatar']['html'])) {
        unset($qa_content['form_profile']['fields']['avatar']);
    }
    //	Private message form
    if (qa_opt('allow_private_messages') && isset($loginuserid) && $loginuserid != $userid && !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES)) {
        $qa_content['form_profile']['fields']['level']['value'] .= strtr(qa_lang_html('profile/send_private_message'), array('^1' => '<A HREF="' . qa_path_html('message/' . $handle) . '">', '^2' => '</A>'));
    }
    //	Show any extra privileges due to user's level or their points
    $showpermits = array();
    $permitoptions = qa_get_permit_options();
    foreach ($permitoptions as $permitoption) {
        if (qa_opt($permitoption) < QA_PERMIT_CONFIRMED) {
            // if it's not available to all users (after they've confirmed their email address)
            if (!qa_permit_error($permitoption, $userid, $useraccount['level'], $useraccount['flags'], $userpoints['points'])) {
                // but this user can
                if ($permitoption == 'permit_retag_cat') {
                    $showpermits[] = qa_lang(qa_using_categories() ? 'profile/permit_recat' : 'profile/permit_retag');
                } else {
                    $showpermits[] = qa_lang('profile/' . $permitoption);
                }
                // then show it as an extra priviliege
            }
        }
    }
    if (count($showpermits)) {
Beispiel #2
0
 function user_priv_form()
 {
     // displays badge list in user profile
     global $qa_request;
     $handle = preg_replace('/^[^\\/]+\\/([^\\/]+).*/', "\$1", $qa_request);
     $userid = $this->priv_getuserfromhandle($handle);
     if (!$userid) {
         return;
     }
     $options = qa_get_permit_options();
     $user = qa_db_select_with_pending(qa_db_user_points_selectspec($userid, true));
     $upoints = (int) $user['points'];
     foreach ($options as $option) {
         if (qa_opt($option) == QA_PERMIT_POINTS) {
             $opoints = (int) qa_opt($option . '_points');
             $popts[$option] = $opoints;
         }
     }
     if (!isset($popts)) {
         return;
     }
     arsort($popts);
     $fields = array();
     foreach ($popts as $key => $val) {
         if ($upoints > $val) {
             $ppoints = 100;
         } else {
             $ppoints = round($upoints / $val * 100);
         }
         // shading
         if (qa_opt('priv_shading') == 0) {
             if ($ppoints <= 50) {
                 $col = round($ppoints / 50 * 255);
                 $col = dechex($col);
                 if (strlen($col) == 1) {
                     $col = '0' . $col;
                 }
                 $col = '#' . 'FF' . $col . '00';
             } else {
                 $col = round(($ppoints - 50) / 50 * 255) * -1 + 255;
                 $col = dechex($col);
                 if (strlen($col) == 1) {
                     $col = '0' . $col;
                 }
                 $col = '#' . $col . 'FF' . '00';
             }
         } else {
             $col = (255 - round($ppoints / 100 * 255)) * 3 / 4;
             $col = dechex($col);
             if (strlen($col) == 1) {
                 $col = '0' . $col;
             }
             $col = '#' . $col . $col . $col;
         }
         // hover text
         if ($ppoints == 100) {
             $hover = str_replace('#', $val, qa_opt('priv_hover_earned'));
         } else {
             $hover = str_replace('#', $val, qa_opt('priv_hover'));
             $hover = str_replace('%', $ppoints, $hover);
         }
         // fudge
         if ($key == 'permit_retag_cat') {
             $name = qa_lang_html(qa_using_categories() ? 'profile/permit_recat' : 'profile/permit_retag');
         } else {
             $name = qa_lang('profile/' . $key);
         }
         if ($name == '[profile/' . $key . ']') {
             global $qa_lang_file_pattern;
             foreach ($qa_lang_file_pattern as $k => $v) {
                 if (qa_lang($k . '/' . $key) != '[' . $k . '/' . $key . ']') {
                     $name = qa_lang($k . '/' . $key);
                     break;
                 }
             }
         }
         $text[] = ($ppoints == 100 ? '<b ' : '<font ') . 'title="' . $hover . '" style="color:' . $col . '; cursor:pointer">' . $name . '</td><td class="qa-form-tall-label">' . ($ppoints == 100 ? '<b ' : '<font ') . 'title="' . $hover . '" style="color:' . $col . '; cursor:pointer">' . $ppoints . '%';
     }
     $fields[] = array('label' => implode('</td></tr><tr class="priv-row"><td class="qa-form-tall-label">', $text), 'type' => 'static');
     $ok = null;
     $tags = null;
     $buttons = array();
     return array('ok' => $ok && !isset($error) ? $ok : null, 'style' => 'tall', 'tags' => $tags, 'title' => qa_opt('priv_title'), 'fields' => $fields, 'buttons' => $buttons);
 }
    function filter_subs($text)
    {
        // text subs
        $subs = array('site_title' => qa_opt('site_title'), 'site_url' => qa_opt('site_url'));
        foreach ($subs as $i => $v) {
            $text = str_replace('^' . $i, $v, $text);
        }
        // function subs
        preg_match_all('/\\^qa_path\\(([^)]+)\\)/', $text, $qa_path, PREG_SET_ORDER);
        foreach ($qa_path as $match) {
            $text = str_replace($match[0], qa_path($match[1]), $text);
        }
        preg_match_all('/\\^qa_opt\\(([^)]+)\\)/', $text, $qa_opt, PREG_SET_ORDER);
        foreach ($qa_opt as $match) {
            // backwards compat
            if (in_array($match[1], array('points_per_q_voted_up', 'points_per_q_voted_down')) && !qa_opt('points_per_q_voted_up')) {
                $match[1] = 'points_per_q_voted';
            } else {
                if (in_array($match[1], array('points_per_a_voted_up', 'points_per_a_voted_down')) && !qa_opt('points_per_a_voted_up')) {
                    $match[1] = 'points_per_a_voted';
                }
            }
            $text = str_replace($match[0], qa_opt($match[1]), $text);
        }
        // if subs
        if (qa_get_logged_in_userid()) {
            $text = preg_replace('/\\^if_logged_in=`([^`]+)`/', '$1', $text);
            $text = preg_replace('/\\^if_not_logged_in=`[^`]+`/', '', $text);
            $handle = qa_get_logged_in_handle();
            $subs = array('profile_url' => qa_path('user/' . $handle), 'handle' => $handle);
            foreach ($subs as $i => $v) {
                $text = str_replace('^' . $i, $v, $text);
            }
        } else {
            global $qa_root_url_relative;
            $userlinks = qa_get_login_links($qa_root_url_relative, null);
            $subs = array('login' => $userlinks['login'], 'register' => $userlinks['register']);
            foreach ($subs as $i => $v) {
                $text = str_replace('^' . $i, $v, $text);
            }
            $text = preg_replace('/\\^if_not_logged_in=`([^`]+)`/', '$1', $text);
            $text = preg_replace('/\\^if_logged_in=`[^`]+`/', '', $text);
        }
        // table subs
        if (strpos($text, '^pointstable') !== false) {
            require_once QA_INCLUDE_DIR . 'qa-db-points.php';
            $optionnames = qa_db_points_option_names();
            $options = qa_get_options($optionnames);
            $table = '
<table class="qa-form-wide-table">
	<tbody>';
            $multi = (int) $options['points_multiple'];
            foreach ($optionnames as $optionname) {
                switch ($optionname) {
                    case 'points_multiple':
                        continue 2;
                    case 'points_per_q_voted_up':
                    case 'points_per_a_voted_up':
                        $prefix = '+';
                        break;
                    case 'points_per_q_voted_down':
                    case 'points_per_a_voted_down':
                        $prefix = '-';
                        break;
                    case 'points_per_q_voted':
                    case 'points_per_a_voted':
                        $prefix = '&#177;';
                        break;
                    case 'points_q_voted_max_gain':
                    case 'points_a_voted_max_gain':
                        $prefix = '+';
                        break;
                    case 'points_q_voted_max_loss':
                    case 'points_a_voted_max_loss':
                        $prefix = '&ndash;';
                        break;
                    case 'points_base':
                        $prefix = '+';
                        break;
                    default:
                        $prefix = '<SPAN STYLE="visibility:hidden;">+</SPAN>';
                        // for even alignment
                        break;
                }
                $points = $optionname != 'points_base' ? (int) $options[$optionname] * $multi : (int) $options[$optionname];
                if ($points != 0 && $points != -10000 && $points != 10000 && strpos($optionname, 'max') === false) {
                    $table .= '
		<tr>
			<td class="qa-form-wide-label">
				' . qa_lang_html('options/' . $optionname) . '
			</td>
			<td class="qa-form-wide-data" style="text-align:right">
				<span class="qa-form-wide-prefix"><span style="width: 1em; display: -moz-inline-stack;">' . $prefix . '</span></span>
				' . qa_html($points) . ($optionname == 'points_multiple' ? '' : '
				<span class="qa-form-wide-note">' . qa_lang_html('admin/points') . '</span>') . '
			</td>
		</tr>';
                }
            }
            $table .= '
	</tbody>
</table>';
            $text = str_replace('^pointstable', $table, $text);
        }
        if (strpos($text, '^privilegestable') !== false) {
            $options = qa_get_permit_options();
            foreach ($options as $option) {
                if (qa_opt($option) == QA_PERMIT_POINTS) {
                    $popts[$option] = (int) qa_opt($option . '_points');
                }
            }
            if (isset($popts)) {
                asort($popts);
                $table = '
	<table class="qa-form-wide-table">
		<tbody>';
                foreach ($popts as $key => $val) {
                    // fudge
                    if ($key == 'permit_retag_cat') {
                        $name = qa_lang_html(qa_using_categories() ? 'profile/permit_recat' : 'profile/permit_retag');
                    } else {
                        $name = qa_lang('profile/' . $key);
                    }
                    if ($name == '[profile/' . $key . ']') {
                        global $qa_lang_file_pattern;
                        foreach ($qa_lang_file_pattern as $k => $v) {
                            if (qa_lang($k . '/' . $key) != '[' . $k . '/' . $key . ']') {
                                $name = qa_lang($k . '/' . $key);
                                break;
                            }
                        }
                    }
                    $table .= '
			<tr>
				<td class="qa-form-wide-label">
					' . $name . '
				</td>
				<td class="qa-form-wide-data" style="text-align:right">
					' . qa_html($val) . '
					<span class="qa-form-wide-note">' . qa_lang_html('admin/points') . '</span>' . '
				</td>
			</tr>';
                }
                $table .= '
		</tbody>
	</table>';
                $text = str_replace('^privilegestable', $table, $text);
            } else {
                $text = str_replace('^privilegestable', '', $text);
            }
        }
        return $text;
    }
 function check_privileges($userid, $event_points)
 {
     $user = qa_db_select_with_pending(qa_db_user_points_selectspec($userid, true));
     $upoints = (int) $user['points'];
     $before_points = (int) $user['points'] - $event_points;
     $permr = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^usermeta WHERE user_id=# AND meta_key=$ ', $userid, 'priv_notify'), true);
     // stale perms
     $stale = array();
     if ($permr) {
         $perms = explode('^', $permr);
         $stale = explode(',', $perms[0]);
     }
     $p_options = qa_get_permit_options();
     $notices = '';
     foreach ($p_options as $option) {
         if (qa_opt($option) == QA_PERMIT_POINTS) {
             $opoints = (int) qa_opt($option . '_points');
             if ($opoints < $upoints && $opoints > $before_points && !in_array($option, $stale)) {
                 $notices = ($notices ? $notices . ',' : '') . $option;
             }
         }
     }
     if ($notices) {
         qa_db_query_sub('INSERT INTO ^usermeta (user_id,meta_key,meta_value) VALUES (#,$,$) ON DUPLICATE KEY UPDATE meta_value=$', $userid, 'priv_notify', '^' . $notices, $permr . ($perms[1] ? ',' : '') . $notices);
         if (qa_opt('priv_email_notify_on')) {
             $this->notify($userid, $notices);
         }
     }
 }