/**
 * init current user logined
 */
function hw_init_current_userlogin()
{
    global $iflychat_userinfo;
    //init user
    if (qa_is_logged_in()) {
        $handle = qa_get_logged_in_handle();
        //user name
        $userid = qa_get_logged_in_userid();
        //user id
        $user = qa_db_select_with_pending(qa_db_user_account_selectspec($handle, false));
        //get user avatar src
        $avatar_src = hw_get_user_avatar_src($user['flags'], $user['email'], $user['avatarblobid']);
        if (empty($avatar_src)) {
            $avatar_src = 'https://iflychat.com/sites/all/modules/drupalchat/themes/light/images/default_avatar.png';
        }
        //set detail current user to chat
        $iflychat_userinfo = new iFlyChatUserDetails($handle, $userid);
        $iflychat_userinfo->setIsAdmin(TRUE);
        $iflychat_userinfo->setAvatarUrl($avatar_src);
        $iflychat_userinfo->setProfileLink(qa_opt('site_url') . 'user/' . $handle);
        $iflychat_userinfo->setRoomRoles(array());
        $iflychat_userinfo->setRelationshipSet(FALSE);
        //$iflychat_userinfo->setAllRoles(array('1'=>'admin'));
    }
}
예제 #2
0
    function head_custom()
    {
        qa_html_theme_base::head_custom();
        if (qa_opt('priv_active') && qa_opt('priv_check') && qa_get_logged_in_handle()) {
            $userid = qa_get_logged_in_userid();
            $notices = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^usermeta WHERE user_id=# AND meta_key=$ ', $userid, 'priv_notify'), true);
            if ($notices) {
                $all = explode('^', $notices);
                if (!$all[1]) {
                    // no new
                    return;
                }
                $n = explode(',', $all[1]);
                $this->notify = '<div class="notify-container">';
                $text = count($n) > 1 ? str_replace('#', count($n), qa_opt('priv_notify_text_multi')) : str_replace('^privilege', qa_lang('profile/' . $n[0]), qa_opt('priv_notify_text'));
                $text = str_replace('^profile', qa_path_html('user/' . qa_get_logged_in_handle(), array('tab' => 'privileges'), qa_opt('site_url')), $text);
                $this->notify .= '<div class="priv-notify notify">' . $text . '<div class="notify-close" onclick="jQuery(this).parent().sildeUp(\'fast\')">x</div></div>';
                $this->notify .= '</div>';
                // remove notification flag
                qa_db_query_sub('UPDATE ^usermeta SET meta_value=$ WHERE meta_key=$ AND user_id=#', ($all[0] ? $all[0] . ',' : '') . $all[1] . '^', 'priv_notify', $userid);
                /*					
                					$this->output("
                					<script>
                						jQuery('document').ready(function() { jQuery('.notify-container').delay(10000).fadeOut(); });
                					</script>");
                */
                $this->output('
					<style>', qa_opt('priv_css'), '</style>');
            }
        }
    }
예제 #3
0
 function theme_switch_form()
 {
     // displays signature form in user profile
     global $qa_request;
     $handle = preg_replace('/^[^\\/]+\\/([^\\/]+).*/', "\$1", $qa_request);
     $userid = $this->getuserfromhandle($handle);
     if (!$userid) {
         return;
     }
     if (qa_get_logged_in_handle() && qa_get_logged_in_handle() == $handle) {
         if (qa_clicked('theme_switch_save')) {
             qa_db_query_sub('INSERT INTO ^usermeta (user_id,meta_key,meta_value) VALUES (#,$,$) ON DUPLICATE KEY UPDATE meta_value=$', $userid, 'custom_theme', qa_post_text('theme_choice'), qa_post_text('theme_choice'));
             qa_redirect($this->request, array('ok' => qa_lang_html('admin/options_saved')));
         } else {
             if (qa_clicked('theme_switch_user_reset')) {
                 qa_db_query_sub('DELETE FROM ^usermeta WHERE user_id=# AND meta_key=$', $userid, 'custom_theme');
                 qa_redirect($this->request, array('ok' => qa_lang_html('admin/options_reset')));
             }
         }
         require_once QA_INCLUDE_DIR . 'qa-app-admin.php';
         $ok = qa_get('ok') ? qa_get('ok') : null;
         $theme_choice = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^usermeta WHERE user_id=# AND meta_key=$', $userid, 'custom_theme'), true);
         $themes = qa_admin_theme_options();
         $fields['themes'] = array('label' => qa_opt('theme_switch_text'), 'tags' => 'NAME="theme_choice"', 'type' => 'select', 'options' => qa_admin_theme_options(), 'value' => @$themes[$theme_choice]);
         $form = array('ok' => $ok && !isset($error) ? $ok : null, 'style' => 'tall', 'title' => '<a name="theme_text"></a>' . qa_opt('theme_switch_title'), 'tags' => 'action="' . qa_self_html() . '#theme_text" method="POST"', 'fields' => $fields, 'buttons' => array(array('label' => qa_lang_html('admin/reset_options_button'), 'tags' => 'NAME="theme_switch_user_reset"'), array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="theme_switch_save"')));
         return $form;
     }
 }
예제 #4
0
 public function dele_single_article($articleid = 0)
 {
     $username = qa_get_logged_in_handle();
     $article = $this->article_model->select_single_article($articleid);
     $userlevel = $this->user_model->get_user_level($username);
     if ($username == null) {
         echo '发生了错误1';
         exit;
     }
     //判断权限
     $power = -1;
     if ($userlevel != null) {
         $power = $userlevel['level'];
     }
     if ($power < 0) {
         echo '你没有权限发表文章';
         exit;
     }
     if ($article != null) {
         $newid = $this->article_model->update_article_by_array($articleid, array("status"), array(-1));
     }
     if ($newid == null) {
         $newid = 0;
     }
     echo $newid;
 }
예제 #5
0
 public function index($id = null)
 {
     $username = qa_get_logged_in_handle();
     if ($username == '') {
         exit;
     }
     $user = $this->user_model->get_user_config($username);
     if ($user == null) {
         exit;
     }
     $userlevel = $this->user_model->get_user_level($username);
     $data = $this->defaultpage_model->all_items();
     $data = array_merge($data, array('blog_title' => $user['blogtitle'], 'blog_subtitle' => $user['blogsubtitle'], 'img_article_operation_btns1' => base_url($this->config->item('app_src') . 'views/theme/' . $this->config->item('theme') . '/img/article_operation_btns1.gif'), 'article_submit' => site_url('action/add_article/add_single_by_post'), 'save_posted_page' => site_url('action/save_article/save_single_by_post'), 'aritile_site_url' => site_url('article/index')));
     if ($id == null) {
         $data['ar_saveid'] = '0';
         $data['ar_draft_title'] = '';
         $data['ar_draft_content'] = '';
         $data['ar_draft_tags'] = '';
     } else {
         $artl = $this->article_model->select_single_article($id);
         if ($artl != null and ($artl['username'] == $username or $userlevel['level'] >= 4)) {
             $data['ar_saveid'] = $id;
             $data['ar_draft_title'] = htmlspecialchars($artl['caption'], ENT_QUOTES, 'UTF-8');
             $data['ar_draft_content'] = htmlspecialchars($artl['content'], ENT_QUOTES, 'UTF-8');
             $data['ar_draft_tags'] = htmlspecialchars($artl['tags'], ENT_QUOTES, 'UTF-8');
         } else {
             echo 'no permits!';
             exit;
         }
     }
     $this->parser->parse('theme/default/templete/header', $data);
     $this->parser->parse('theme/default/templete/head', $data);
     $this->parser->parse('theme/default/templete/createarticle', $data);
     $this->parser->parse('theme/default/templete/foot', $data);
 }
예제 #6
0
 function logged_in()
 {
     if (isset($this->content['loggedin']['data']) && qa_opt('buddypress_integration_enable') && qa_opt('buddypress_display_names')) {
         $handle = qa_get_logged_in_handle();
         $name = bp_core_get_user_displayname($handle);
         $this->content['loggedin']['data'] = str_replace('>' . $handle . '<', ' title="@' . $handle . '">' . $name . '<', $this->content['loggedin']['data']);
     }
     qa_html_theme_base::logged_in();
 }
function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $childposts = null)
{
    $rules = qa_page_q_post_rules_base($post, $parentpost, $siblingposts, $childposts);
    qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^postmeta (
			meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
			post_id bigint(20) unsigned NOT NULL,
			meta_key varchar(255) DEFAULT \'\',
			meta_value longtext,
			PRIMARY KEY (meta_id),
			KEY post_id (post_id),
			KEY meta_key (meta_key)
			) ENGINE=MyISAM  DEFAULT CHARSET=utf8');
    $expert = qa_db_read_one_value(qa_db_query_sub("SELECT meta_value FROM ^postmeta WHERE meta_key='is_expert_question' AND post_id=#", $post['postid']), true);
    if ($expert) {
        if (!qa_permit_value_error(qa_opt('expert_question_roles'), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags())) {
            $is_expert = true;
        }
        $users = qa_opt('expert_question_users');
        $users = explode("\n", $users);
        $handle = qa_get_logged_in_handle();
        foreach ($users as $idx => $user) {
            if ($user == $handle) {
                $is_expert = true;
                break;
            }
            if (strpos($user, '=')) {
                $user = explode('=', $user);
                if ($user[0] == $handle) {
                    $catnames = explode(',', $user[1]);
                    $cats = qa_db_read_all_values(qa_db_query_sub('SELECT categoryid FROM ^categories WHERE title IN ($)', $catnames));
                    $is_expert = $cats;
                }
            }
        }
        if (isset($is_expert) && !$rules['viewable']) {
            // experts that aren't allowed to change hidden questions
            if (is_array($is_expert)) {
                $in_cats = qa_db_read_one_value(qa_db_query_sub("SELECT COUNT(postid) FROM ^posts WHERE categoryid IN (#) AND postid=#", $is_expert, $post['postid']), true);
                if ($in_cats) {
                    $rules['viewable'] = true;
                }
            } else {
                $rules['viewable'] = true;
            }
        }
        $rules['reshowable'] = false;
        $rules['answerbutton'] = true;
        $rules['commentbutton'] = true;
        $rules['commentable'] = true;
    }
    return $rules;
}
예제 #8
0
    function qw_notification_btn()
    {
        //if (true){ // check options
        $userid = qa_get_logged_in_userid();
        if (isset($userid)) {
            $handle = qa_get_logged_in_handle();
            $this->output('
					<div class="user-actions pull-right">
						<div class="activity-bar">
							<div class="button dropdown">
								<a href="' . qa_path_html('user/' . $handle . '/activity') . '" class=" icon-bullhorn dropdown-toggle activitylist" data-toggle="dropdown" id="activitylist"></a>
								<div class="dropdown-menu activity-dropdown-list pull-right" id="activity-dropdown-list">
									<div class="bar">
										<span>' . qa_lang_html('dude/notifications') . '</span>
										<a class="mark-activity" href="#" data-id="' . qa_get_logged_in_userid() . '">' . qa_lang('dude/mark_all_as_read') . '</a>
									</div>
									<div class="append">
										<div class="ajax-list"></div>
										<span class="loading"></span>
										<div class="no-activity icon-chart-bar">' . qa_lang('dude/no-activity') . '</div>
									</div>
									
									<a class="event-footer" href="' . qa_path_html('notifications', null, QW_BASE_URL) . '">' . qa_lang('dude/see_all') . '</a>
									
								</div>
							</div>
						</div>
						
						<div class="message-bar">
							<div class="button dropdown">
								<a href="' . qa_path_html('user/' . $handle . '/message') . '" class=" icon-envelope-alt dropdown-toggle messagelist" data-toggle="dropdown" id="messagelist"></a>
								<div class="dropdown-menu message-dropdown-list pull-right" id="message-dropdown-list">
									<div class="bar">
										<span>' . qa_lang_html('dude/messages') . '</span>
										<a class="mark-messages" href="#">' . qa_lang('dude/mark_all_as_read') . '</a>
									</div>
									<div class="append">
										<div class="ajax-list"></div>
										<span class="loading"></span>
										<div class="no-activity icon-chart-bar">' . qa_lang('dude/no-activity') . '</div>
									</div>
									
									<a class="event-footer" href="' . qa_path_html('user/' . $handle . '/wall', null, QW_BASE_URL) . '">' . qa_lang('dude/see_all') . '</a>
									
								</div>
							</div>
						</div>
					</div>
				');
        }
        //}
    }
예제 #9
0
 function head_custom()
 {
     qa_html_theme_base::head_custom();
     if (@$this->template == 'user' && qa_opt('signatures_enable')) {
         $formats = qa_list_modules('editor');
         $editorname = $formats[qa_opt('signatures_format')];
         $handle = preg_replace('/^[^\\/]+\\/([^\\/]+).*/', "\$1", $this->request);
         if (qa_get_logged_in_handle() == $handle && (!$editorname || $editorname == 'Markdown Editor')) {
             $this->output_raw('<script src="' . QA_HTML_THEME_LAYER_URLTOROOT . 'textLimitCount.js" type="text/javascript"></script>');
             $this->output_raw("\n<script>\n\tvar signature_max_length = " . (qa_opt('signatures_length') ? qa_opt('signatures_length') : 1000) . ";\n\tjQuery('document').ready(function(){\n\t\ttextLimiter(jQuery('textarea[name=\"signature_text\"]'),{\n\t\tmaxLength: signature_max_length,\n\t\telCount: 'elCount'\n\t  });\n\t});\n</script>");
         }
     }
 }
예제 #10
0
 public function index($articleid = 1)
 {
     $atcl = $this->article_model->select_single_article($articleid);
     if ($atcl == null) {
         exit;
     }
     if ($atcl['status'] == 1) {
         //如果不是文章作者,且不是管理员
         if (qa_get_logged_in_handle() != $atcl['username'] or $this->user_model->get_user_level(qa_get_logged_in_handle()) < 4) {
             echo 'no permints!';
             exit;
         }
     }
     if ($atcl['status'] < 0) {
         //如果不是管理员
         if ($this->user_model->get_user_level(qa_get_logged_in_handle()) < 4) {
             echo 'no permints!';
             exit;
         }
     }
     $username = $atcl['username'];
     $user = $this->user_model->get_user_config($username);
     $articles_meta = $this->article_model->get_article_list_by_author($username);
     $comments_meta = $this->comment_model->get_comments_by_to_user($username);
     $messages_meta = $this->message_model->get_messages_by_to_user($username);
     $articles = array();
     $comments = array();
     $messages = array();
     foreach ($articles_meta as $key => $article) {
         $articles[$key]['title'] = $article['caption'];
         $articles[$key]['content'] = mb_substr($article['content'], 0, 200);
         $articles[$key]['date'] = date('Y-m-d g:i', strtotime($article['createtime']));
     }
     foreach ($comments_meta as $key => $comment) {
         $comments[$key]['comment'] = mb_substr($comment['content'], 0, 17) . '...';
     }
     foreach ($messages_meta as $key => $message) {
         $messages_meta[$key]['comment'] = mb_substr($message['content'], 0, 17) . '...';
     }
     $data = $this->defaultpage_model->all_items();
     $data = array_merge($data, array('blog_title' => $user['blogtitle'], 'blog_subtitle' => $user['blogsubtitle'], 'user_photo' => $this->user_model->get_qa_avartar_html($username), 'user_profile' => $this->config->item('qaroot_src') . '?qa=user/' . $username));
     $atcl['createtime'] = date('Y-m-d g:i', strtotime($atcl['createtime']));
     $data['articles'] = array($atcl);
     //var_dump($data['articles']);
     $data['comments'] = $comments;
     $data['messages'] = $messages;
     $this->parser->parse('theme/default/templete/header', $data);
     $this->parser->parse('theme/default/templete/head', $data);
     $this->parser->parse('theme/default/templete/article', $data);
     $this->parser->parse('theme/default/templete/foot', $data);
 }
예제 #11
0
 function doctype()
 {
     parent::doctype();
     if (QA_FINAL_EXTERNAL_USERS) {
         return;
     }
     // check if logged in
     $handle = qa_get_logged_in_handle();
     if (isset($handle)) {
         if (qa_request() == '' && count($_GET) > 0) {
             // Check if we need to associate another provider
             $this->process_login();
         }
         // see if the account pages are accessed
         $tmpl = array('account', 'favorites');
         $user_pages = array('user', 'user-wall', 'user-activity', 'user-questions', 'user-answers');
         $logins_page = qa_request() == 'logins' && !qa_get('confirm');
         $urlhandle = qa_request_part(1);
         if (in_array($this->template, $tmpl) || $logins_page || in_array($this->template, $user_pages) && $handle == $urlhandle) {
             // add a navigation item
             $this->content['navigation']['sub']['logins'] = array('label' => qa_lang_html('plugin_open/my_logins_nav'), 'url' => qa_path_html('logins'), 'selected' => $logins_page);
             return;
         }
     } else {
         $title = qa_lang_html('plugin_open/login_title');
         $descr = qa_lang_html('plugin_open/login_description');
         // hide login/register links from navigation on any page
         if (qa_opt('open_login_hideform') == '1') {
             unset($this->content['navigation']['user']['login']);
             unset($this->content['navigation']['user']['register']);
         }
         // then check if login/register pages are accessed
         $tmpl = array('register', 'login');
         if (!in_array($this->template, $tmpl)) {
             return;
         }
         // hide regular login/register form on those pages only
         if (qa_opt('open_login_hideform') == '1') {
             $this->content['title'] = $title;
             $this->content['form'] = null;
         }
         // add some custom text
         if (!empty($this->content['custom'])) {
             $content = str_ireplace('<BR>', '', $this->content['custom']);
             $this->content['custom'] = "<div><p>{$descr}</p>{$content}</div>";
             if ($this->content['form'] != null) {
                 $this->content['custom'] = "<br /><br /><h1>{$title}</h1>{$this->content['custom']}";
             }
         }
     }
 }
예제 #12
0
 function logged_in()
 {
     if (qa_is_logged_in()) {
         // output user avatar to login bar
         $this->output('<div class="qa-logged-in-avatar">', QA_FINAL_EXTERNAL_USERS ? qa_get_external_avatar_html(qa_get_logged_in_userid(), 24, true) : qa_get_user_avatar_html(qa_get_logged_in_flags(), qa_get_logged_in_email(), qa_get_logged_in_handle(), qa_get_logged_in_user_field('avatarblobid'), qa_get_logged_in_user_field('avatarwidth'), qa_get_logged_in_user_field('avatarheight'), 24, true), '</div>');
     }
     qa_html_theme_base::logged_in();
     if (qa_is_logged_in()) {
         // adds points count after logged in username
         $userpoints = qa_get_logged_in_points();
         $pointshtml = $userpoints == 1 ? qa_lang_html_sub('main/1_point', '1', '1') : qa_lang_html_sub('main/x_points', qa_html(number_format($userpoints)));
         $this->output('<span class="qa-logged-in-points">', '(' . $pointshtml . ')', '</span>');
     }
 }
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     // only show for logged in users
     if (qa_get_logged_in_handle() == null) {
         return;
     }
     require_once QA_INCLUDE_DIR . 'qa-db.php';
     require_once QA_INCLUDE_DIR . 'qa-db.php';
     require_once QA_INCLUDE_DIR . 'mp-db-users.php';
     $userid = qa_get_logged_in_userid();
     $categoryid = mp_get_categoryid();
     // check each property
     $nameSQL = qa_db_read_one_value(qa_db_query_sub('select count(content) from ^userprofile p where p.userid =# and content="" and title=#', $userid, 'name'));
     $aboutSQL = qa_db_read_one_value(qa_db_query_sub('select count(content) from ^userprofile p where p.userid =# and content="" and title=#', $userid, 'about'));
     $websiteSQL = qa_db_read_one_value(qa_db_query_sub('select count(content) from ^userprofile p where p.userid =# and content="" and title=#', $userid, 'website'));
     $questionSQL = qa_db_read_one_value(qa_db_query_sub('select count(userid) from ^posts p where p.userid =# and categoryid=# and type=#', $userid, $categoryid, 'Q'));
     $answerSQL = qa_db_read_one_value(qa_db_query_sub('select count(userid) from ^posts p where p.userid =# and categoryid=# and type=#', $userid, $categoryid, 'A'));
     $perc = 0;
     if ($nameSQL == 0) {
         $perc++;
     }
     if ($aboutSQL == 0) {
         $perc++;
     }
     if ($websiteSQL == 0) {
         $perc++;
     }
     if ($questionSQL > 0) {
         $perc++;
     }
     if ($answerSQL > 0) {
         $perc++;
     }
     $themeobject->output('<DIV CLASS="mp-widget-profile-view"><DIV CLASS="mp-widget-profile-title">Profile Progress - ' . $perc * 100 / 5 . '%</DIV>');
     $data = '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">Name</SPAN>' . ($nameSQL ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>';
     // value of 0 is complete
     $data .= '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">About</SPAN>' . ($aboutSQL ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>';
     // value of 0 is complete
     $data .= '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">Website</SPAN>' . ($websiteSQL ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>';
     // value of 0 is complete
     $data .= '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">Posted a question</SPAN>' . ($questionSQL <= 0 ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>';
     // value > 0 is complete
     $data .= '<DIV CLASS="mp-widget-profile-list-item"><SPAN CLASS="mp-widget-profile-list-title">Posted an answer</SPAN>' . ($answerSQL <= 0 ? '<SPAN CLASS="mp-widget-profile-list-bad"></SPAN>' : '<SPAN CLASS="mp-widget-profile-list-good"></SPAN>') . '</DIV>';
     // value > 0 is complete
     $data .= '<br /><center><a CLASS="qa-page-link" href="' . qa_path_html('account') . '">Edit Profile</a></center><br />';
     $themeobject->output($data);
     $themeobject->output('</DIV>');
 }
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-users.php';
     $allowEdit = !qa_user_permit_error('fb_share_permit_edit');
     $parts = explode('/', qa_self_html());
     if ($allowEdit && $parts[2] == qa_get_logged_in_handle()) {
         $appid = qa_opt('fb_app_id');
         $secret = qa_opt('fb_app_secret');
         $fb = new Facebook\Facebook(['app_id' => $appid, 'app_secret' => $secret, 'default_graph_version' => 'v2.4']);
         $helper = $fb->getRedirectLoginHelper();
         $permissions = ['email', 'publish_actions'];
         $callback = 'http://nathorr.com/qeta/fb-share/' . qa_get_logged_in_handle() . '/';
         $loginUrl = $helper->getLoginUrl($callback, $permissions);
         echo '<a href="' . $loginUrl . '"><img src="http://oi57.tinypic.com/f1xlbt.jpg"></a>';
     }
 }
예제 #15
0
function set_duodaa_user()
{
    $user = array();
    $user['username'] = qa_get_logged_in_handle();
    if (!$user['username']) {
        //header("Content-type: text/html; charset=utf-8");
        //unset($user['username']);
        $user['nologin'] = 1;
        $user['nologinzh'] = '没有登录';
        //echo json_encode($user);
    } else {
        $user['nologin'] = 0;
        $user['points'] = qa_get_logged_in_points();
    }
    return $user;
}
예제 #16
0
 public function draft()
 {
     $username = qa_get_logged_in_handle();
     if ($username == null) {
         echo 'please login!';
         exit;
     }
     $user = $this->user_model->get_user_config($username);
     if ($user == null) {
         echo 'no permits!';
         exit;
     }
     $data = $this->defaultpage_model->all_items();
     $articles_meta = $this->article_model->get_article_list_by_author($username, 1000, 1);
     $comments_meta = $this->comment_model->get_comments_by_to_user($username);
     $messages_meta = $this->message_model->get_messages_by_to_user($username);
     $articles = array();
     $comments = array();
     $messages = array();
     foreach ($articles_meta as $key => $article) {
         $articles[$key]['articleid'] = $article['ID'];
         $articles[$key]['title'] = $article['caption'];
         $articles[$key]['content'] = mb_substr($article['content'], 0, 200);
         $articles[$key]['date'] = date('Y-m-d g:i', strtotime($article['createtime']));
         $articles[$key]['articlelink'] = site_url('article/index/' . $article['ID']);
         $articles[$key]['ar_operation_items'] = $this->ui_model->ar_operation_items($article);
         unset($articles[$key]['ar_operation_items'][0]);
         unset($articles[$key]['ar_operation_items'][1]);
     }
     foreach ($comments_meta as $key => $comment) {
         $comments[$key]['comment'] = mb_substr($comment['content'], 0, 17) . '...';
     }
     foreach ($messages_meta as $key => $message) {
         $messages[$key]['message'] = mb_substr($message['content'], 0, 17) . '...';
     }
     $data = $this->defaultpage_model->all_items();
     //var_dump($user);
     $data = array_merge($data, array('blog_title' => $user['blogtitle'], 'blog_subtitle' => $user['blogsubtitle'], 'user_photo' => $this->user_model->get_qa_avartar_html($username), 'user_profile' => $this->config->item('qaroot_src') . '?qa=user/' . $username));
     $data['articles'] = $articles;
     $data['comments'] = $comments;
     $data['messages'] = $messages;
     $data['dele_posted_page'] = site_url('action/dele_article/dele_single_article');
     $this->parser->parse('theme/default/templete/header', $data);
     $this->parser->parse('theme/default/templete/head', $data);
     $this->parser->parse('theme/default/templete/user', $data);
     $this->parser->parse('theme/default/templete/foot', $data);
 }
    function doctype()
    {
        if (qa_get_logged_in_userid() && qa_opt('user_act_list_active') && qa_opt('user_act_list_new') && ($this->template != 'user' || qa_get_logged_in_handle() != $this->_user_handle())) {
            qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^usermeta (
				meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
				user_id bigint(20) unsigned NOT NULL,
				meta_key varchar(255) DEFAULT NULL,
				meta_value longtext,
				PRIMARY KEY (meta_id),
				UNIQUE (user_id,meta_key)
				) ENGINE=MyISAM  DEFAULT CHARSET=utf8');
            $last_visit = qa_db_read_one_value(qa_db_query_sub('SELECT UNIX_TIMESTAMP(meta_value) FROM ^usermeta WHERE user_id=# AND meta_key=$', qa_get_logged_in_userid(), 'visited_profile'), true);
            if ($last_visit) {
                $events = qa_db_read_one_value(qa_db_query_sub('SELECT COUNT(event) FROM ^eventlog WHERE userid=# AND DATE_SUB(CURDATE(),INTERVAL # DAY) <= datetime AND FROM_UNIXTIME(#) <= datetime AND event LIKE \'in_%\'' . (qa_opt('user_act_list_max') ? ' LIMIT ' . (int) qa_opt('user_act_list_max') : ''), qa_get_logged_in_userid(), qa_opt('user_act_list_age'), $last_visit));
                if ($events) {
                    $tooltip = str_replace('#', $events, qa_opt('user_act_list_new_text'));
                    // pluralizing
                    preg_match('/\\S+\\/\\S+/', qa_opt('user_act_list_new_text'), $voicea);
                    $voices = explode('/', $voicea[0]);
                    foreach ($voices as $voice) {
                        if (!preg_match('/[0-9]/', substr($voice, -1))) {
                            $tooltip = preg_replace('/\\S+\\/\\S+/', $voice, $tooltip);
                            break;
                        } else {
                            if ((int) substr($voice, -1) >= $events) {
                                $tooltip = preg_replace('/\\S+\\/\\S+/', substr($voice, 0, -1), $tooltip);
                                break;
                            }
                        }
                    }
                    $this->content['loggedin']['suffix'] = @$this->content['loggedin']['suffix'] . ' <a class="qa-history-new-event-link" title="' . $tooltip . '" href="' . qa_path_html('user/' . qa_get_logged_in_handle(), array('tab' => 'history'), qa_opt('site_url')) . '"><span class="qa-history-new-event-count">' . $events . '</span></a>';
                }
            }
        }
        if (qa_opt('user_act_list_active') && $this->template == 'user' && (qa_get_logged_in_handle() === $this->_user_handle() || qa_opt('user_act_list_show'))) {
            if (!isset($this->content['navigation']['sub'])) {
                $this->content['navigation']['sub'] = array('profile' => array('url' => qa_path_html('user/' . $this->_user_handle(), null, qa_opt('site_url')), 'label' => $this->_user_handle(), 'selected' => !qa_get('tab') ? true : false), 'history' => array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => 'history'), qa_opt('site_url')), 'label' => qa_opt('user_act_list_tab'), 'selected' => qa_get('tab') == 'history' ? true : false));
            } else {
                $this->content['navigation']['sub']['history'] = array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => 'history'), qa_opt('site_url')), 'label' => qa_opt('user_act_list_tab'), 'selected' => qa_get('tab') == 'history' ? true : false);
            }
        }
        qa_html_theme_base::doctype();
    }
예제 #18
0
 public function __construct()
 {
     //var $admins;
     parent::__construct();
     $this->load->model('user_model');
     $this->load->model('article_model');
     $this->load->model('comment_model');
     $this->load->model('message_model');
     $this->load->model('defaultpage_model');
     $this->load->library('parser');
     $this->load->helper('url');
     $this->load->helper('text');
     $this->admins = array('math001', 'duodaamaster');
     $this->username = qa_get_logged_in_handle();
     if (!in_array($this->username, $this->admins)) {
         echo 'no permits!';
         exit;
     }
 }
예제 #19
0
 public function save_single_by_post()
 {
     //$actor = qa_get_logged_in_handle();
     $username = qa_get_logged_in_handle();
     $caption = htmlspecialchars($this->input->post('title'), ENT_QUOTES, 'UTF-8');
     $content = strip_tags($this->input->post('content'), ALLOW_CONTENT_TAGS);
     $tags = htmlspecialchars($this->input->post('tags'), ENT_QUOTES, 'UTF-8');
     $createtime = date('Y-m-d G:i:s');
     $articleid = $this->input->post('ar_saveid');
     $article = $this->article_model->select_single_article($articleid);
     $userlevel = $this->user_model->get_user_level($username);
     //echo 333;
     if ($username == null) {
         echo '发生了错误1';
         exit;
     } elseif ($caption == null) {
         echo '发生了错误2';
         exit;
     } else {
         if ($content == null) {
             echo '发生了错误3';
             exit;
         }
     }
     //判断权限
     $power = -1;
     if ($userlevel != null) {
         $power = $userlevel['level'];
     }
     if ($power < 0) {
         echo '你没有权限发表文章';
         exit;
     }
     if ($article != null) {
         $newid = $this->article_model->update_article($articleid, $article['username'], $caption, $content, $tags, $createtime, $status = 1);
     }
     if ($newid == null) {
         $newid = $this->article_model->insert_article($username, $caption, $content, $tags, $createtime, 1);
     }
     echo $newid;
 }
 function process_request($request)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-format.php';
     require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
     require_once QA_INCLUDE_DIR . 'qa-db-post-create.php';
     require_once QA_INCLUDE_DIR . 'mp-db-users.php';
     // report that we entered this page
     qa_report_event('page_enter', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array('params' => $_SERVER['QUERY_STRING']));
     // create the editor and update its content
     qa_get_post_content('editor', 'content', $ineditor, $incontent, $informat, $intext);
     $editorname = isset($ineditor) ? $ineditor : qa_opt('editor_for_qs');
     $editor = qa_load_editor(@$incontent, @$informat, $editorname);
     // retrieve variable data
     $innotify = qa_post_text('notify') ? true : false;
     // handle creation of annoucement
     if (qa_post_text('docreate')) {
         //retrieve data
         $title = qa_post_text('title');
         $content = $incontent;
         $format = $informat;
         // validate data
         // handle create work
         // actual create process is in file mp-app-posts.php
         $postid = qa_post_create('AN', null, $title, $content, $format, mp_get_categoryid(), null, qa_get_logged_in_userid(), $innotify);
         // redirect page
         qa_redirect('mp-announcements-page');
         // our work is done here
     }
     $qa_content = qa_content_prepare();
     // if the user is not logged in, request user to login
     if (!qa_get_logged_in_userid()) {
         $qa_content['error'] = qa_insert_login_links('Please ^1log in^2 or ^3register^4 first.', $request);
         return $qa_content;
     }
     $qa_content['title'] = 'Create Announcement';
     $qa_content['form_newannouncement'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('title' => array('label' => qa_lang_html('announcements/a_title_label'), 'tags' => 'NAME="title"', 'value' => qa_html(qa_post_text('title')), 'error' => qa_html(@$errors['title'])), 'content' => array_merge($editor->get_field($qa_content, @$incontent, @$informat, 'content', 12, false), array('label' => qa_lang_html('announcements/a_content_label'), 'error' => qa_html(@$errors['content']))), 'notify' => array('label' => 'Send email notification to all registered students', 'tags' => 'NAME="notify"', 'type' => 'checkbox', 'value' => qa_html($innotify))), 'buttons' => array('ok' => array('tags' => 'NAME="docreate"', 'label' => 'Create Announcement', 'value' => '1')), 'hidden' => array('hiddenfield' => '1', 'editor' => qa_html($editorname)));
     // create the sub menu for navigation
     $qa_content['navigation']['sub'] = mp_announcements_sub_navigation();
     $qa_content['navigation']['sub']['create']['selected'] = true;
     return $qa_content;
 }
예제 #21
0
 public function ar_operation_items($article = null)
 {
     $username = qa_get_logged_in_handle();
     $ar_owner = $article['username'];
     $user = $this->user_model->get_user_config($username);
     $userlevel = $this->user_model->get_user_level($username);
     if ($ar_owner == null) {
         echo '文章读取错误!';
         exit;
     }
     $items[0] = array('text' => '阅读全文', 'link' => site_url('article/index/' . $article['ID']));
     $items[1] = array('text' => '评论', 'link' => '#');
     if ($ar_owner == $username or $userlevel >= 4) {
         $items[2] = array('text' => '修改', 'link' => site_url('createarticle/index/' . $article['ID']));
         $items[3] = array('text' => '删除', 'link' => '#');
     }
     $comment_count = count($this->comment_model->get_comments_by_article_id($article['ID']));
     if ($comment_count > 0) {
         $items[1]['text'] .= '(' . $comment_count . ')';
     }
     return $items;
 }
 function process_request($request)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-users.php';
     $appid = qa_opt('fb_app_id');
     $secret = qa_opt('fb_app_secret');
     $fb = new Facebook\Facebook(['app_id' => $appid, 'app_secret' => $secret, 'default_graph_version' => 'v2.4']);
     $qa_content = qa_content_prepare();
     $qa_content['title'] = 'Facebook Sharing Page';
     $helper = $fb->getRedirectLoginHelper();
     try {
         $accessToken = $helper->getAccessToken();
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         echo $e->getMessage();
         exit;
     }
     if (isset($accessToken)) {
         $_SESSION['fb_access_token'] = (string) $accessToken;
         $res = $fb->post('/me/feed', array('link' => 'http://nathorr.com/qeta/user/' . qa_get_logged_in_handle() . '/', 'name' => qa_opt('fb_shared_message_title'), 'picture' => qa_opt('fb_shared_message_picture'), 'description' => qa_opt('fb_shared_message_description'), 'message' => 'I have scored ' . qa_get_logged_in_points() . ' points and achieved some nice badges in Nathorr Q&A, check it out!'), $accessToken);
         $post = $res->getGraphObject();
         $qa_content['custom'] = '<a href="http://nathorr.com/qeta/user/' . qa_get_logged_in_handle() . '">Successfully shared, return by clicking here.</a>';
         return $qa_content;
     } else {
         if ($helper->getError()) {
             var_dump($helper->getError());
             echo '<br><br>';
             var_dump($helper->getErrorCode());
             echo '<br><br>';
             var_dump($helper->getErrorReason());
             echo '<br><br>';
             var_dump($helper->getErrorDescription());
             echo '<br><br>';
             echo '<a href="http://nathorr.com/qeta/user/' . qa_get_logged_in_handle() . '/">Something went wrong, return by clicking here.</a>';
             exit;
         }
     }
     http_response_code(400);
     exit;
 }
예제 #23
0
 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();
     }
 }
 function is_expert_user()
 {
     if (!qa_permit_value_error(qa_opt('expert_question_roles'), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags())) {
         return true;
     }
     $users = qa_opt('expert_question_users');
     $users = explode("\n", $users);
     $handle = qa_get_logged_in_handle();
     foreach ($users as $idx => $user) {
         if ($user == $handle) {
             return true;
         }
         if (strpos($user, '=')) {
             $user = explode('=', $user);
             if ($user[0] == $handle) {
                 $catnames = explode(',', $user[1]);
                 $cats = qa_db_read_all_values(qa_db_query_sub('SELECT categoryid FROM ^categories WHERE title IN ($)', $catnames));
                 return $cats;
             }
         }
     }
     return false;
 }
예제 #25
0
            $filtermodule->filter_question($in, $errors, null);
            qa_update_post_text($in, $oldin);
        }
        if (qa_using_categories() && count($categories) && !qa_opt('allow_no_category') && !isset($in['categoryid'])) {
            $errors['categoryid'] = qa_lang_html('question/category_required');
        } elseif (qa_user_permit_error('permit_post_q', null, $userlevel)) {
            $errors['categoryid'] = qa_lang_html('question/category_ask_not_allowed');
        }
        if ($captchareason) {
            require_once 'qa-app-captcha.php';
            qa_captcha_validate_post($errors);
        }
        if (empty($errors)) {
            $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
            // create a new cookie if necessary
            $questionid = qa_question_create($followanswer, $userid, qa_get_logged_in_handle(), $cookieid, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']), $in['notify'], $in['email'], $in['categoryid'], $in['extra'], $in['queued'], $in['name']);
            qa_redirect(qa_q_request($questionid, $in['title']));
            // our work is done here
        }
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare(false, array_keys(qa_category_path($categories, @$in['categoryid'])));
$qa_content['title'] = qa_lang_html(isset($followanswer) ? 'question/ask_follow_title' : 'question/ask_title');
$qa_content['error'] = @$errors['page'];
$editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_qs');
$editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
$field = qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], 'content', 12, false);
$field['label'] = qa_lang_html('question/q_content_label');
$field['error'] = qa_html(@$errors['content']);
$custom = qa_opt('show_custom_ask') ? trim(qa_opt('custom_ask')) : '';
예제 #26
0
function qa_admin_single_click($postid, $action)
{
    require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
    $post = qa_post_get_full($postid);
    if (isset($post)) {
        $userid = qa_get_logged_in_userid();
        $queued = substr($post['type'], 1) == '_QUEUED';
        switch ($action) {
            case 'approve':
                if ($queued && !qa_user_permit_error('permit_moderate')) {
                    qa_post_set_hidden($postid, false, $userid);
                    return true;
                }
                break;
            case 'reject':
                if ($queued && !qa_user_permit_error('permit_moderate')) {
                    qa_post_set_hidden($postid, true, $userid);
                    return true;
                }
                break;
            case 'hide':
                if (!$queued && !qa_user_permit_error('permit_hide_show')) {
                    qa_post_set_hidden($postid, true, $userid);
                    return true;
                }
                break;
            case 'reshow':
                if ($post['hidden'] && !qa_user_permit_error('permit_hide_show')) {
                    qa_post_set_hidden($postid, false, $userid);
                    return true;
                }
                break;
            case 'delete':
                if ($post['hidden'] && !qa_user_permit_error('permit_delete_hidden')) {
                    qa_post_delete($postid);
                    return true;
                }
                break;
            case 'clearflags':
                require_once QA_INCLUDE_DIR . 'qa-app-votes.php';
                if (!qa_user_permit_error('permit_hide_show')) {
                    qa_flags_clear_all($post, $userid, qa_get_logged_in_handle(), null);
                    return true;
                }
                break;
        }
    }
    return false;
}
예제 #27
0
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/
require_once QA_INCLUDE_DIR . 'qa-app-users.php';
require_once QA_INCLUDE_DIR . 'qa-app-cookies.php';
require_once QA_INCLUDE_DIR . 'qa-app-favorites.php';
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
$entitytype = qa_post_text('entitytype');
$entityid = qa_post_text('entityid');
$setfavorite = qa_post_text('favorite');
$userid = qa_get_logged_in_userid();
if (!qa_check_form_security_code('favorite-' . $entitytype . '-' . $entityid, qa_post_text('code'))) {
    echo "QA_AJAX_RESPONSE\n0\n" . qa_lang('misc/form_security_reload');
} elseif (isset($userid)) {
    $cookieid = qa_cookie_get();
    qa_user_favorite_set($userid, qa_get_logged_in_handle(), $cookieid, $entitytype, $entityid, $setfavorite);
    $favoriteform = qa_favorite_form($entitytype, $entityid, $setfavorite, qa_lang($setfavorite ? 'main/remove_favorites' : 'main/add_favorites'));
    $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-favorite', null, null);
    echo "QA_AJAX_RESPONSE\n1\n";
    $themeclass->favorite_inner_html($favoriteform);
}
/*
	Omit PHP closing tag to help avoid accidental output
*/
예제 #28
0
 function qa_set_logged_in_user($userid, $handle = '', $remember = false, $source = null)
 {
     if (qa_to_override(__FUNCTION__)) {
         $args = func_get_args();
         return qa_call_override(__FUNCTION__, $args);
     }
     require_once QA_INCLUDE_DIR . 'app/cookies.php';
     qa_start_session();
     if (isset($userid)) {
         qa_set_session_user($userid, $source);
         // PHP sessions time out too quickly on the server side, so we also set a cookie as backup.
         // Logging in from a second browser will make the previous browser's 'Remember me' no longer
         // work - I'm not sure if this is the right behavior - could see it either way.
         require_once QA_INCLUDE_DIR . 'db/selects.php';
         $userinfo = qa_db_single_select(qa_db_user_account_selectspec($userid, true));
         // if we have logged in before, and are logging in the same way as before, we don't need to change the sessioncode/source
         // this means it will be possible to automatically log in (via cookies) to the same account from more than one browser
         if (empty($userinfo['sessioncode']) || $source !== $userinfo['sessionsource']) {
             $sessioncode = qa_db_user_rand_sessioncode();
             qa_db_user_set($userid, 'sessioncode', $sessioncode);
             qa_db_user_set($userid, 'sessionsource', $source);
         } else {
             $sessioncode = $userinfo['sessioncode'];
         }
         qa_db_user_logged_in($userid, qa_remote_ip_address());
         qa_set_session_cookie($handle, $sessioncode, $remember);
         qa_report_event('u_login', $userid, $userinfo['handle'], qa_cookie_get());
     } else {
         $olduserid = qa_get_logged_in_userid();
         $oldhandle = qa_get_logged_in_handle();
         qa_clear_session_cookie();
         qa_clear_session_user();
         qa_report_event('u_logout', $olduserid, $oldhandle, qa_cookie_get());
     }
 }
function qa_page_q_edit_c_submit($comment, $question, $parent, &$in, &$errors)
{
    $commentid = $comment['postid'];
    $prefix = 'c' . $commentid . '_';
    $in = array();
    if ($comment['isbyuser']) {
        $in['name'] = qa_post_text($prefix . 'name');
        $in['notify'] = qa_post_text($prefix . 'notify') ? true : false;
        $in['email'] = qa_post_text($prefix . 'email');
    }
    if (!qa_user_post_permit_error('permit_edit_silent', $comment)) {
        $in['silent'] = qa_post_text($prefix . 'silent');
    }
    qa_get_post_content($prefix . 'editor', $prefix . 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
    // here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters
    $errors = array();
    if (!qa_check_form_security_code('edit-' . $commentid, qa_post_text($prefix . 'code'))) {
        $errors['content'] = qa_lang_html('misc/form_security_again');
    } else {
        $in['queued'] = qa_opt('moderate_edited_again') && qa_user_moderation_reason(qa_user_level_for_post($comment));
        $filtermodules = qa_load_modules_with('filter', 'filter_comment');
        foreach ($filtermodules as $filtermodule) {
            $oldin = $in;
            $filtermodule->filter_comment($in, $errors, $question, $parent, $comment);
            qa_update_post_text($in, $oldin);
        }
        if (empty($errors)) {
            $userid = qa_get_logged_in_userid();
            $handle = qa_get_logged_in_handle();
            $cookieid = qa_cookie_get();
            if (!isset($in['silent'])) {
                $in['silent'] = false;
            }
            $setnotify = $comment['isbyuser'] ? qa_combine_notify_email($comment['userid'], $in['notify'], $in['email']) : $comment['notify'];
            qa_comment_set_content($comment, $in['content'], $in['format'], $in['text'], $setnotify, $userid, $handle, $cookieid, $question, $parent, @$in['name'], $in['queued'], $in['silent']);
            return true;
        }
    }
    return false;
}
예제 #30
0
function qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, &$in, &$errors)
{
    $parentid = $parent['postid'];
    $prefix = 'c' . $parentid . '_';
    $in = array('name' => qa_post_text($prefix . 'name'), 'notify' => qa_post_text($prefix . 'notify') !== null, 'email' => qa_post_text($prefix . 'email'), 'queued' => qa_user_moderation_reason(qa_user_level_for_post($parent)) !== false);
    qa_get_post_content($prefix . 'editor', $prefix . 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
    $errors = array();
    if (!qa_check_form_security_code('comment-' . $parent['postid'], qa_post_text($prefix . 'code'))) {
        $errors['content'] = qa_lang_html('misc/form_security_again');
    } else {
        $filtermodules = qa_load_modules_with('filter', 'filter_comment');
        foreach ($filtermodules as $filtermodule) {
            $oldin = $in;
            $filtermodule->filter_comment($in, $errors, $question, $parent, null);
            qa_update_post_text($in, $oldin);
        }
        if ($usecaptcha) {
            qa_captcha_validate_post($errors);
        }
        if (empty($errors)) {
            $testwords = implode(' ', qa_string_to_words($in['content']));
            foreach ($commentsfollows as $comment) {
                if ($comment['basetype'] == 'C' && $comment['parentid'] == $parentid && !$comment['hidden']) {
                    if (implode(' ', qa_string_to_words($comment['content'])) == $testwords) {
                        $errors['content'] = qa_lang_html('question/duplicate_content');
                    }
                }
            }
        }
        if (empty($errors)) {
            $userid = qa_get_logged_in_userid();
            $handle = qa_get_logged_in_handle();
            $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
            // create a new cookie if necessary
            $commentid = qa_comment_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'], $question, $parent, $commentsfollows, $in['queued'], $in['name']);
            return $commentid;
        }
    }
    return null;
}