function qa_handle_make_valid($handle) { require_once QA_INCLUDE_DIR . 'qa-util-string.php'; require_once QA_INCLUDE_DIR . 'qa-db-maxima.php'; require_once QA_INCLUDE_DIR . 'qa-db-users.php'; if (!strlen($handle)) { $handle = qa_lang('users/registered_user'); } $handle = preg_replace('/[\\@\\+\\/]/', ' ', $handle); for ($attempt = 0; $attempt <= 99; $attempt++) { $suffix = $attempt ? ' ' . $attempt : ''; $tryhandle = qa_substr($handle, 0, QA_DB_MAX_HANDLE_LENGTH - strlen($suffix)) . $suffix; $filtermodules = qa_load_modules_with('filter', 'filter_handle'); foreach ($filtermodules as $filtermodule) { $filtermodule->filter_handle($tryhandle, null); } // filter first without worrying about errors, since our goal is to get a valid one $haderror = false; foreach ($filtermodules as $filtermodule) { $error = $filtermodule->filter_handle($tryhandle, null); // now check for errors after we've filtered if (isset($error)) { $haderror = true; } } if (!$haderror) { $handleusers = qa_db_user_find_by_handle($tryhandle); if (!count($handleusers)) { return $tryhandle; } } } qa_fatal_error('Could not create a valid and unique handle from: ' . $handle); }
function qa_handle_make_valid($handle, $allowuserid = null) { require_once QA_INCLUDE_DIR . 'qa-util-string.php'; require_once QA_INCLUDE_DIR . 'qa-db-maxima.php'; if (!strlen($handle)) { $handle = qa_lang('users/registered_user'); } $handle = preg_replace('/[\\@\\+\\/]/', ' ', $handle); for ($attempt = 0; $attempt <= 99; $attempt++) { $suffix = $attempt ? ' ' . $attempt : ''; $tryhandle = qa_substr($handle, 0, QA_DB_MAX_HANDLE_LENGTH - strlen($suffix)) . $suffix; $handleusers = qa_db_user_find_by_handle($tryhandle); if (!(count($handleusers) && (!isset($allowuserid) || array_search($allowuserid, $handleusers) === false))) { return $tryhandle; } } qa_fatal_error('Could not create a unique handle'); }
function qa_badge_plugin_user_form($userid) { $handles = qa_userids_to_handles(array($userid)); $handle = $handles[$userid]; // displays badge list in user profile $result = qa_db_read_all_assoc(qa_db_query_sub('SELECT badge_slug as slug, object_id AS oid FROM ^userbadges WHERE user_id=#', $userid)); $fields = array(); if (count($result) > 0) { // count badges $bin = qa_get_badge_list(); $badges = array(); foreach ($result as $info) { $slug = $info['slug']; $type = $bin[$slug]['type']; if (isset($badges[$type][$slug])) { $badges[$type][$slug]['count']++; } else { $badges[$type][$slug]['count'] = 1; } if ($info['oid']) { $badges[$type][$slug]['oid'][] = $info['oid']; } } foreach ($badges as $type => $badge) { $typea = qa_get_badge_type($type); $types = $typea['slug']; $typed = $typea['name']; $output = ' <table> <tr> <td class="qa-form-wide-label"> <h3 class="badge-title" title="' . qa_lang('badges/' . $types . '_desc') . '">' . $typed . '</h3> </td> </tr>'; foreach ($badge as $slug => $info) { $badge_name = qa_lang('badges/' . $slug); if (!qa_opt('badge_' . $slug . '_name')) { qa_opt('badge_' . $slug . '_name', $badge_name); } $name = qa_opt('badge_' . $slug . '_name'); $count = $info['count']; if (qa_opt('badge_show_source_posts')) { $oids = @$info['oid']; } else { $oids = null; } $var = qa_opt('badge_' . $slug . '_var'); $desc = qa_badge_desc_replace($slug, $var, $name); // badge row $output .= ' <tr> <td class="badge-container"> <div class="badge-container-badge"> <span class="badge-' . $types . '" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '</span> <span onclick="jQuery(\'.badge-container-sources-' . $slug . '\').slideToggle()" class="badge-count' . (is_array($oids) ? ' badge-count-link" title="' . qa_lang('badges/badge_count_click') : '') . '">x ' . $count . '</span> </div>'; // source row(s) if any if (is_array($oids)) { $output .= ' <div class="badge-container-sources-' . $slug . '" style="display:none">'; foreach ($oids as $oid) { $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $oid)); $title = $post['title']; $anchor = ''; if ($post['parentid']) { $anchor = urlencode(qa_anchor($post['type'], $oid)); $oid = $post['parentid']; $title = qa_db_read_one_value(qa_db_query_sub('SELECT BINARY title as title FROM ^posts WHERE postid=#', $oid), true); } $length = 30; $text = qa_strlen($title) > $length ? qa_substr($title, 0, $length) . '...' : $title; $output .= ' <div class="badge-source"><a href="' . qa_path_html(qa_q_request($oid, $title), NULL, qa_opt('site_url')) . ($anchor ? '#' . $anchor : '') . '">' . qa_html($text) . '</a></div>'; } } $output .= ' </td> </tr>'; } $output .= ' </table>'; $outa[] = $output; } $fields[] = array('value' => '<table class="badge-user-tables"><tr><td class="badge-user-table">' . implode('</td><td class="badge-user-table">', $outa) . '</td></tr></table>', 'type' => 'static'); } $ok = null; $tags = null; $buttons = array(); if ((bool) qa_opt('badge_email_notify') && qa_get_logged_in_handle() == $handle) { // add badge notify checkbox if (qa_clicked('badge_email_notify_save')) { qa_opt('badge_email_notify_id_' . $userid, (bool) qa_post_text('badge_notify_email_me')); $ok = qa_lang('badges/badge_notified_email_me'); } $select = (bool) qa_opt('badge_email_notify_id_' . $userid); $tags = 'id="badge-form" action="' . qa_self_html() . '#signature_text" method="POST"'; $fields[] = array('type' => 'blank'); $fields[] = array('label' => qa_lang('badges/badge_notify_email_me'), 'type' => 'checkbox', 'tags' => 'NAME="badge_notify_email_me"', 'value' => $select); $buttons[] = array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="badge_email_notify_save"'); } return array('ok' => $ok && !isset($error) ? $ok : null, 'style' => 'tall', 'tags' => $tags, 'title' => qa_lang('badges/badges'), 'fields' => $fields, 'buttons' => $buttons); }
public function test__qa_substr() { $test = qa_substr($this->strBasic, 5, 24); $this->assertEquals($test, 'tied an onion to my belt'); }
if (empty($errors)) { qa_redirect('admin/users'); } else { $userfields = qa_db_select_with_pending(qa_db_userfields_selectspec()); // reload after changes foreach ($userfields as $userfield) { if ($userfield['fieldid'] == $editfield['fieldid']) { $editfield = $userfield; } } } } elseif (empty($errors)) { // creating a new user field for ($attempt = 0; $attempt < 1000; $attempt++) { $suffix = $attempt ? '-' . (1 + $attempt) : ''; $newtag = qa_substr(implode('-', qa_string_to_words($inname)), 0, QA_DB_MAX_PROFILE_TITLE_LENGTH - strlen($suffix)) . $suffix; $uniquetag = true; foreach ($userfields as $userfield) { if (qa_strtolower(trim($newtag)) == qa_strtolower(trim($userfield['title']))) { $uniquetag = false; } } if ($uniquetag) { $fieldid = qa_db_userfield_create($newtag, $inname, $inflags); qa_db_userfield_move($fieldid, $inposition); qa_redirect('admin/users'); } } qa_fatal_error('Could not create a unique database tag'); } }
function process_request($request) { // get all variables preg_match($this->reqmatch, $request, $matches); $post_type = $matches[1]; $handle = $matches[2]; $start = (int) qa_get('start'); $pagesize = qa_opt('page_size_qs'); $hidecss = qa_opt($this->cssopt) === '1'; // regular page request $qa_content = qa_content_prepare(); require_once QA_INCLUDE_DIR . 'qa-util-string.php'; // display CSS for stat summary if (!$hidecss) { $qa_content['custom'] = "<style>\n" . ".qa-useract-page-links { margin: 16px 0; color: #555753; font-size: 16px; text-align: center; }\n" . ".qa-useract-page-links > a { font-weight: bold; }\n" . ".qa-useract-stats { margin: 8px 0; text-align: center; }\n" . ".qa-useract-stat { display: inline-block; margin: 0 16px 8px; }\n" . ".qa-useract-count { font-size: 18px; font-weight: bold; }\n" . ".qa-useract-wrapper .qa-q-item-main { width: 658px; }\n" . ".qa-useract-wrapper .qa-a-count { height: auto; border: 1px solid #ebeaca; border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius:8px; }\n" . ".qa-useract-wrapper .qa-a-snippet { margin-top: 2px; color: #555753; }\n" . ".qa-useract-wrapper .qa-q-item-meta { float: none; }\n" . "</style>\n\n"; } // list of questions by this user if ($post_type === 'questions') { $qa_content['title'] = qa_lang_html_sub('useractivity/questions_by', $handle); list($userid, $count, $sel_count) = $this->_questions_stats($handle); // get questions $columns = 'postid, categoryid, type, LEFT(type,1) AS basetype, INSTR(type,"_HIDDEN")>0 AS hidden, acount, selchildid, closedbyid, upvotes, downvotes, netvotes, hotness, flagcount, BINARY title AS title, BINARY tags AS tags, UNIX_TIMESTAMP(created) AS created'; $sql_questions = 'SELECT ' . $columns . ' FROM ^posts WHERE type="Q" AND userid=# ORDER BY created DESC LIMIT #,#'; $result = qa_db_query_sub($sql_questions, $userid, $start, $pagesize); $questions = qa_db_read_all_assoc($result); $htmloptions = qa_post_html_defaults('Q'); $htmloptions['whoview'] = false; $htmloptions['avatarsize'] = 0; // html for stats $qa_content['custom'] .= '<div class="qa-useract-stats">' . ' <div class="qa-useract-stat"><span class="qa-useract-count">' . $count . '</span><br>' . ($count == 1 ? qa_lang_html('useractivity/question') : qa_lang_html('useractivity/questions')) . '</div>' . ' <div class="qa-useract-stat"><span class="qa-useract-count">' . $sel_count . '</span><br>' . ($sel_count == 1 ? qa_lang_html('useractivity/best_answer_given') : qa_lang_html('useractivity/best_answers_given')) . '</div>' . '</div>'; // create html for question list $qa_content['q_list']['qs'] = array(); foreach ($questions as $question) { $qa_content['q_list']['qs'][] = qa_any_to_q_html_fields($question, qa_get_logged_in_userid(), qa_cookie_get(), null, null, $htmloptions); } // pagination $qa_content['page_links'] = qa_html_page_links($request, $start, $pagesize, $count, qa_opt('pages_prev_next'), null); return $qa_content; } else { if ($post_type === 'answers') { $qa_content['title'] = qa_lang_html_sub('useractivity/answers_by', $handle); // userid and answer count $sql_count = 'SELECT u.userid, count(a.postid) AS qs, sum(q.selchildid=a.postid) AS selected ' . 'FROM ^posts a, ^posts q, ^users u ' . 'WHERE a.parentid=q.postid AND u.userid=a.userid AND a.type="A" AND q.type="Q" AND u.handle=$'; $result = qa_db_query_sub($sql_count, $handle); $row = qa_db_read_one_assoc($result); $userid = $row['userid']; $count = $row['qs']; $sel_count = $row['selected']; // get answers $columns = 'q.postid AS qpostid, BINARY q.title AS qtitle, q.selchildid AS qselid, q.netvotes AS qvotes, a.postid AS apostid, BINARY a.content AS acontent, a.netvotes AS avotes, UNIX_TIMESTAMP(a.created) AS acreated, a.format'; $sql_answers = 'SELECT ' . $columns . ' FROM ^posts a, ^posts q WHERE a.parentid=q.postid AND a.type="A" AND q.type="Q" AND a.userid=# ORDER BY a.created DESC LIMIT #,#'; $result = qa_db_query_sub($sql_answers, $userid, $start, $pagesize); $answers = qa_db_read_all_assoc($result); $qa_content['custom'] .= '<div class="qa-useract-stats">' . ' <div class="qa-useract-stat"><span class="qa-useract-count">' . $count . '</span><br>' . ($count == 1 ? qa_lang_html('useractivity/answer') : qa_lang_html('useractivity/answers')) . '</div>' . ' <div class="qa-useract-stat"><span class="qa-useract-count">' . $sel_count . '</span><br>' . ($sel_count == 1 ? qa_lang_html('useractivity/best_answer_received') : qa_lang_html('useractivity/best_answers_received')) . '</div>' . '</div>'; $qa_content['custom_2'] = '<div class="qa-useract-wrapper">'; foreach ($answers as $ans) { // to avoid ugly content, convert answer to HTML then strip the tags and remove any URLs $ans['acontent'] = qa_viewer_html($ans['acontent'], $ans['format']); $ans['acontent'] = strip_tags($ans['acontent']); $ans['acontent'] = preg_replace('#\\shttp://[^\\s]+#', '', $ans['acontent']); $ans['acontent'] = qa_substr($ans['acontent'], 0, 100); if (strlen($ans['acontent']) == 100) { $ans['acontent'] .= '...'; } // question url $ans['qurl'] = qa_path_html(qa_q_request($ans['qpostid'], $ans['qtitle'])); // answer date $ans['acreated'] = qa_when_to_html($ans['acreated'], qa_opt('show_full_date_days')); // html content $qa_content['custom_2'] .= $this->_answer_tmpl($ans); } $qa_content['custom_2'] .= '</div>'; // pagination $qa_content['page_links'] = qa_html_page_links($request, $start, $pagesize, $count, qa_opt('pages_prev_next'), null); return $qa_content; } } }