function qa_get_request_content() { if (qa_opt('news_plugin_active')) { $requestlower = strtolower(qa_request()); if ($requestlower && $requestlower === 'my-profile') { $userid = qa_get_logged_in_userid(); if (!$userid) { qa_redirect(); } $handles = qa_userids_to_handles(array($userid)); $handle = $handles[$userid]; qa_redirect(qa_path('user/' . $handle)); } else { if ($requestlower && $requestlower === qa_opt('news_plugin_request')) { // send on cron if (qa_opt('news_plugin_send') && qa_get('cron') == qa_opt('news_plugin_cron_rand') && time() >= qa_opt('news_plugin_send_last') + 23 * 60 * 60) { // minumum cron interval is 23 hours qa_news_plugin_createNewsletter(true); return false; } else { if (qa_get('cron') == qa_opt('news_plugin_cron_rand')) { if (!qa_opt('news_plugin_send')) { error_log('Q2A Newsletter Recreate Error: sending newsletter not allowed via admin/plugins'); } else { error_log('Q2A Newsletter Recreate Error: cron request before minimum time elapsed'); } echo "false\n"; return false; } } include qa_opt('news_plugin_loc'); return false; } else { if (qa_opt('news_plugin_pdf') && $requestlower && $requestlower === qa_opt('news_plugin_request_pdf')) { $pdf = file_get_contents(qa_opt('news_plugin_loc_pdf')); header('Content-Description: File Transfer'); header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // force download dialog header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream', false); header('Content-Type: application/download', false); header('Content-Type: application/pdf', false); // use the Content-Disposition header to supply a recommended filename header('Content-Disposition: attachment; filename="' . basename(qa_opt('news_plugin_loc_pdf')) . '";'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . strlen($pdf)); echo $pdf; return false; } } } } return qa_get_request_content_base(); }
function logged_in() { if (qa_get_logged_in_userid()) { if ($this->template == "question") { $qnum = qa_request_part("0"); qa_db_query_sub("UPDATE ^userevents SET lastview = NOW() WHERE questionid = {$qnum} AND userid = " . qa_get_logged_in_userid()); } $questions = qa_db_read_all_assoc(qa_db_query_sub("SELECT DISTINCT(questionid), lastpostid FROM ^userevents WHERE lastview < updated OR lastview IS NULL")); $count = count($questions); $notifyclass = "qa-notification-none"; if ($count > 0) { $notifyclass = "qa-notification-new"; } $this->output(' <span class="qa-notification-counter ' . $notifyclass . '">' . $count . '</span> '); $this->output('<div class="qa-notification-dialog">'); foreach ($questions as $question) { $q = qa_post_get_full($question["questionid"]); $post = qa_post_get_full($question["lastpostid"]); $type = ""; if ($post["type"] == "A") { $type = "answer"; } else { if ($post["type"] == "C") { $type = "comment"; } } if ($post["userid"] == NULL) { $user = "******"; } else { $user = qa_userids_to_handles(array($post["userid"])); $user = $user[$post["userid"]]; } $this->output('<div class="qa-notification-dialog-entry">', '<a href="' . qa_q_path($question["questionid"], $q["title"]) . '">' . $q["title"] . '</a>', '<div>New ' . $type . ' by ' . $user . ': "' . substr($post["content"], 0, 100) . '"</div>', '</div>'); } $this->output('</div>'); } qa_html_theme_base::logged_in(); }
function qa_userid_to_handle($userid) { $handles = qa_userids_to_handles(array($userid)); return empty($handles) ? null : $handles[$userid]; }
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); }
function qa_get_request_content() { $qa_content = qa_get_request_content_base(); // displays signature form in user profile $qa_request = strtolower(qa_request()); $reqs = explode('/', $qa_request); if ($reqs[0] == 'user') { // permissions if (isset($qa_content['form_profile']['fields']['permits'])) { $ov = $qa_content['form_profile']['fields']['permits']['value']; $ov = str_replace('[profile/signature_allow]', qa_lang('signature_plugin/signature_allow'), $ov); $ov = str_replace('[profile/signature_edit_allow]', qa_lang('signature_plugin/signature_edit_allow'), $ov); $qa_content['form_profile']['fields']['permits']['value'] = $ov; } $qa_content['user_signature_form'] = array(); $userid = @$qa_content['raw']['userid']; if (!$userid) { return $qa_content; } $handles = qa_userids_to_handles(array($userid)); $handle = $handles[$userid]; if (qa_get_logged_in_handle() == $handle && !qa_user_permit_error('signature_allow') || !qa_user_permit_error('signature_edit_allow')) { $ok = null; $formats = qa_list_modules('editor'); $format = qa_opt('signatures_format'); $editorname = $formats[$format]; if (!strlen($editorname)) { $editorname = qa_lang_html('admin/basic_editor'); } $editor = qa_load_editor('', '', $editorname); qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^usersignatures (' . 'userid INT(11) NOT NULL,' . 'signature VARCHAR (1000) DEFAULT \'\',' . 'format VARCHAR (20) DEFAULT \'\',' . 'id INT(11) NOT NULL AUTO_INCREMENT,' . 'UNIQUE (userid),' . 'PRIMARY KEY (id)' . ') ENGINE=MyISAM DEFAULT CHARSET=utf8'); if (qa_clicked('signature_save')) { if (strlen(qa_post_text('signature_text')) > qa_opt('signatures_length')) { $error = 'Max possible signature length is 1000 characters'; } else { $readdata = $editor->read_post('signature_text'); $informat = $readdata['format']; $incontent = qa_post_text('signature_text'); qa_db_query_sub('INSERT INTO ^usersignatures (userid,signature,format) VALUES (#,$,$) ON DUPLICATE KEY UPDATE signature=$,format=$', $userid, $incontent, $informat, $incontent, $informat); $ok = 'Signature Saved.'; } } $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature AS signature,format FROM ^usersignatures WHERE userid=#', $userid), true); $field = qa_editor_load_field($editor, $qa_content, $content['signature'], $content['format'], 'signature_text', 12, false); $field['label'] = qa_lang_html('signature_plugin/signature'); $fields['content'] = $field; if (!$editorname || $editorname == 'Markdown Editor') { $fields['elCount'] = array('label' => '<div id="elCount">' . qa_opt('signatures_length') . '</div>', 'type' => 'static'); } $form = array('ok' => $ok && !isset($error) ? $ok : null, 'error' => @$error, 'style' => 'tall', 'title' => '<a name="signature_text"></a>' . qa_lang_html('signature_plugin/signature'), 'tags' => 'action="' . qa_self_html() . '#signature_text" method="POST"', 'fields' => $fields, 'buttons' => array(array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="signature_save"')), 'hidden' => array('editor' => qa_html($editorname), 'dosavesig' => '1')); $qa_content['user_signature_form'] = $form; } else { if (qa_opt('signatures_profile_enable')) { $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature as signature, format FROM ^usersignatures WHERE userid=#', $userid), true); if (!$content) { return $qa_content; } $informat = $content['format']; $viewer = qa_load_viewer($content['signature'], $informat); global $options; $signature = qa_viewer_html($content['signature'], $informat, array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow'])); $fields[] = array('label' => qa_opt('signatures_header') . $signature . qa_opt('signatures_footer'), 'type' => 'static'); $qa_content['user_signature_form'] = array('title' => 'Signature', 'fields' => $fields, 'style' => 'tall'); } } } return $qa_content; }
function qa_get_user_name($uid) { $handles = qa_userids_to_handles(array($uid)); $handle = $handles[$uid]; if (QA_FINAL_EXTERNAL_USERS) { $user_info = get_userdata($uid); if ($user_info->display_name) { $name = $user_info->display_name; } } else { $name = qa_db_read_one_value(qa_db_query_sub('SELECT title AS name FROM ^userprofile ' . 'WHERE userid=# AND title=$', $uid, 'name'), true); } if (!@$name) { $name = $handle; } return strlen($handle) ? '<A HREF="' . qa_path_html('user/' . $handle) . '" CLASS="qa-user-link">' . qa_html($name) . '</A>' : 'Anonymous'; }
function ra_user_badges_list($userid) { if (!qa_opt('badge_active')) { return; } $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)); 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 = ''; //$output = '<h3 class="badge-title" title="'.qa_lang('badges/'.$types.'_desc').'">'.$typed.'</h3>'; foreach ($badge as $slug => $info) { $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'); $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, false); // badge row $output .= '<div class="badge-container-badge"> <span class="user-badge ' . $types . ' icon-badge" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '</span> <span class="badge-count">x ' . $count . '</span>' . (is_array($oids) ? '<i class="icon-chevron-down"></i>' : ''); // source row(s) if any if (is_array($oids)) { $output .= ' <div class="badge-sources ' . $slug . '"><ul>'; 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 = $title; $output .= '<li><a href="' . qa_path_html(qa_q_request($oid, $title), NULL, qa_opt('site_url')) . ($anchor ? '#' . $anchor : '') . '">' . qa_html($text) . '</a></li>'; } $output .= '</ul></div>'; } $output .= '</div>'; } $outa[] = $output; } $fields = '<div class="badge-user-block widget"><h3 class="widget-title">' . _ra_lang('Badges') . '</h3><div class="widget-inner">' . implode('', $outa) . '</div></div>'; } return $fields; }
function process_request($request) { require_once 'data_user.php'; require_once 'data_question.php'; $requests = explode('/', $request); $username = isset($requests[1]) ? $requests[1] : '0'; //第一个设置是用户名 $password = isset($requests[2]) ? $requests[2] : '0'; //第二个设置是密码 $request_type = isset($requests[3]) ? $requests[3] : '0'; //第三个是设置请求类型 // login - 登录 // logout - 登出 // qlist - 问题列表 //q - 问题 $para_1 = isset($requests[4]) ? $requests[4] : '0'; $para_2 = isset($requests[5]) ? $requests[5] : '0'; //$usr=duodaa_login($username,$password); switch ($request_type) { case '0': $json_data = '{}'; //$request_type='login'; break; case 'q': $q = questioninfo(3248); var_dump($q); exit; break; case 'login': $usr = duodaa_login($username, $password); $usr1["error"] = $usr["error"]; if ($usr1["error"] == "") { $usr1["userid"] = $usr["userid"]; $usr1["handle"] = $usr["handle"]; } $json_data = $this->to_JSON($usr1); break; case 'qlist': $list_type = $para_1; switch ($list_type) { case '0': $qlist_tmp = duodaa_qlist(); $qlist = array(); foreach ($qlist_tmp as $key => $qinfo) { $qlist[$key]["postid"] = $qinfo["postid"]; $qlist[$key]["title"] = $qinfo["title"]; $qlist[$key]["userid"] = $qinfo["userid"]; // $qlist[$key]["handle"]=qa_userids_to_handles(array($qinfo["userid"]))[0]; $temphandle = qa_userids_to_handles(array($qinfo["userid"])); $qlist[$key]["handle"] = $temphandle[$qinfo["userid"]]; $qlist[$key]["update_time"] = $qinfo["update_time"]; } break; case 'myquestion': $usr = duodaa_login($username, $password); if ($usr['error'] == '') { $qlist = duodaa_qlist($usr['userid']); } else { $qlist = array(); } break; case 'myanswers': $usr = duodaa_login($username, $password); if ($usr['error'] == '') { $qlist = duodaa_qlist($usr['userid']); } else { $qlist = array(); } break; } // var_dump($qlist); $json_data = $this->to_JSON($qlist); break; default: // $json_data= '{"a":"a"}'; break; } header("Access-Control-Allow-Origin: *"); header("Content-type:text/html;charset=utf-8"); //echo('<meta http-equiv="Access-Control-Allow-Origin" content="*">'); echo $json_data; return null; }
function user_buddypress_form($content) { // displays badge list in user profile global $qa_request; $userid = $content['raw']['userid']; $handles = qa_userids_to_handles(array($userid)); $handle = $handles[$userid]; if (!$handle) { return; } global $bp; if (qa_opt('buddypress_enable_profile')) { $idx = 1; if (bp_has_profile(array('user_id' => $userid))) { while (bp_profile_groups()) { bp_the_profile_group(); if (bp_profile_group_has_fields()) { $fields[] = array('label' => '<span class="qa-bp-profile-group-title">' . bp_get_the_profile_group_name() . '</span>', 'type' => 'static', 'value' => qa_get_logged_in_userid() === $userid ? ' <a class="qa-bp-profile-group-edit" href="' . bp_loggedin_user_domain() . $bp->profile->slug . '/edit/group/' . $idx++ . '">' . qa_lang_html('question/edit_button') . '</a>' : ''); while (bp_profile_fields()) { bp_the_profile_field(); if (bp_field_has_data()) { $fields[] = array('label' => bp_get_the_profile_field_name(), 'type' => 'static', 'value' => preg_replace('|</*p>|', '', bp_get_the_profile_field_value())); } } } } } $ok = null; $tags = null; $buttons = array(); $title = '<a href="' . bp_core_get_user_domain($userid) . $bp->profile->slug . '/">' . qa_opt('buddypress_integration_title') . '</a>'; $content = array_merge(array('form-buddypress-list' => array('ok' => $ok && !isset($error) ? $ok : null, 'style' => 'wide', 'tags' => $tags, 'title' => $title, 'fields' => $fields, 'buttons' => $buttons)), $content); } if (qa_opt('buddypress_integration_priv_message') && qa_get_logged_in_userid() && $userid != qa_get_logged_in_userid()) { $content = array_merge(array('form-buddypress-message' => array('fields' => array('field' => array('label' => '<a href="' . wp_nonce_url($bp->loggedin_user->domain . $bp->messages->slug . '/compose/?r=' . $handle) . '">' . qa_lang('misc/private_message_title') . '</a>', 'type' => 'static')), 'style' => 'wide')), $content); } return $content; }