public function process_event($event, $userid, $handle, $cookieid, $params) { switch ($event) { case 'q_post': $this->send_hipchat_notification($this->build_new_question_message(isset($handle) ? $handle : qa_lang('main/anonymous'), $params['title'], qa_q_path($params['postid'], $params['title'], true))); break; case 'a_post': $parentpost = qa_post_get_full($params['parentid']); $this->send_hipchat_notification($this->build_new_answer_message(isset($handle) ? $handle : qa_lang('main/anonymous'), $parentpost['title'], qa_path(qa_q_request($params['parentid'], $parentpost['title']), null, qa_opt('site_url'), null, qa_anchor('A', $params['postid'])))); break; } }
function getPostType($postid) { $arr = qa_post_get_full($postid); switch ($arr['type']) { case 'Q': return "question"; break; case 'A': return "answer"; break; case "C": return "comment"; break; default: return null; break; } }
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(); }
<link rel="stylesheet" type="text/css" href="css/editor.css"> <script type="text/javascript" src="js/zh.js"></script> <script type="text/javascript" src="js/styles.js"></script> </head> <body class="qa-template-ask qa-body-js-on"> <?php isset($_GET['postid']) ? $postid = $_GET['postid'] : ($postid = ''); isset($_GET['action']) ? $action = $_GET['action'] : ($action = ''); isset($_GET['type']) ? $type = $_GET['type'] : ($type = 'ques'); //type为bk则为添加或修改百科详情 $ques = null; $quesuser = qa_get_logged_in_userid(); $update = false; //是否在更改帖子 if ($postid && $type == 'ques') { $ques = qa_post_get_full($postid); } if ($ques['userid'] == $quesuser) { $update = true; } if ($postid && $type == 'baike') { $ques = getPost($postid); $update = true; } // $update=true; ?> <?php require 'header.php'; ?> <!--side fixed end-->
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; }
function process_event($event, $userid, $handle, $cookieid, $params) { // call_this_method(); //here we can call the scheuler $loggeduserid = qa_get_logged_in_userid(); $dolog = true; $postid = @$params['postid']; // grab all preferences for notifying users $all_preferences = qw_get_all_notification_settings(); switch ($event) { case 'a_post': // user's question had been answered if ($loggeduserid != $params['parent']['userid']) { $effecteduserid = $params['parent']['userid']; $question = $this->GetQuestion($params); $params['qtitle'] = $question['title']; $params['qid'] = $question['postid']; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; case 'c_post': // user's answer had been commented $question = $this->GetQuestion($params); $params['qtitle'] = $question['title']; $params['qid'] = $question['postid']; $thread = $params['thread']; $already_notified = ""; unset($params['thread']); if ($loggeduserid != $params['parent']['userid']) { $effecteduserid = $params['parent']['userid']; $this->AddEvent($postid, $userid, $params['parent']['userid'], $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } $already_notified = $effecteduserid; } if (count($thread) > 0) { $user_array = array(); foreach ($thread as $t) { if ($loggeduserid != $t['userid']) { $user_array[] = $t['userid']; } } $user_array = array_unique($user_array, SORT_REGULAR); foreach ($user_array as $user) { if ($user == $already_notified) { continue; } $this->AddEvent($postid, $userid, $user, $params, $event); $effecteduserid = $user; //for this scenario the $user_array contains all user ids in the current commented thread if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } } break; case 'q_reshow': require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $post = qa_post_get_full($postid); if ($loggeduserid != $post['userid']) { $effecteduserid = $post['userid']; $question = $this->GetQuestion($params); $params['qtitle'] = $question['title']; $params['qid'] = $question['postid']; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; case 'a_reshow': require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $post = qa_post_get_full($postid); if ($loggeduserid != $post['userid']) { $effecteduserid = $post['userid']; $question = $this->GetQuestion($params); $params['qtitle'] = $question['title']; $params['qid'] = $question['postid']; unset($params['oldanswer']); unset($params['content']); unset($params['text']); $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; case 'c_reshow': require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $post = qa_post_get_full($postid); if ($loggeduserid != $post['userid']) { unset($params['oldcomment']); $effecteduserid = $post['userid']; $question = $this->GetQuestion($params); $params['qtitle'] = $question['title']; $params['qid'] = $question['postid']; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; /* case 'a_unselect': require_once QA_INCLUDE_DIR.'qa-app-posts.php'; $post = qa_post_get_full($postid); $effecteduserid = $post['userid']; qa_db_query_sub( "DELETE FROM ^ra_userevent WHERE effecteduserid=$ AND event=$ AND postid=$", $effecteduserid, 'a_select', $postid ); if (qw_check_pref_for_event($effecteduserid , $event , $all_preferences )) { qw_do_action('user_event_'.$event, $postid,$userid, $effecteduserid, $params, $event); } break; */ /* case 'a_unselect': require_once QA_INCLUDE_DIR.'qa-app-posts.php'; $post = qa_post_get_full($postid); $effecteduserid = $post['userid']; qa_db_query_sub( "DELETE FROM ^ra_userevent WHERE effecteduserid=$ AND event=$ AND postid=$", $effecteduserid, 'a_select', $postid ); if (qw_check_pref_for_event($effecteduserid , $event , $all_preferences )) { qw_do_action('user_event_'.$event, $postid,$userid, $effecteduserid, $params, $event); } break; */ case 'a_select': require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $post = qa_post_get_full($postid); if ($loggeduserid != $post['userid']) { $effecteduserid = $post['userid']; $question = $this->GetQuestion($params); $params['qtitle'] = $question['title']; $params['qid'] = $question['postid']; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; case 'q_vote_up': $this->UpdateVote('q_vote_up', $postid, $userid, $params, 'q_vote_up', 1); $dolog = false; break; case 'a_vote_up': $this->UpdateVote('a_vote_up', $postid, $userid, $params, 'a_vote_up', 1); $dolog = false; break; case 'q_vote_down': $this->UpdateVote('q_vote_down', $postid, $userid, $params, 'q_vote_down', -1); $dolog = false; break; case 'a_vote_down': $this->UpdateVote('a_vote_down', $postid, $userid, $params, 'a_vote_down', -1); $dolog = false; break; case 'q_vote_nil': $this->UpdateVote('q_vote_nil', $postid, $userid, $params, 'q_vote_nil', 0); $dolog = false; break; case 'a_vote_nil': $this->UpdateVote('a_vote_nil', $postid, $userid, $params, 'a_vote_nil', 0); $dolog = false; break; case 'q_approve': case 'a_approve': case 'c_approve': case 'q_reject': case 'a_reject': case 'c_reject': require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $post = qa_post_get_full($postid); if ($loggeduserid != $post['userid']) { $effecteduserid = $post['userid']; $question = $this->GetQuestion($params); $params['qtitle'] = $question['title']; $params['qid'] = $question['postid']; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; case 'q_favorite': $this->UpdateVote('q_favorite', $postid, $userid, $params, 'favorite', 1); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } $dolog = false; break; /* case 'q_unfavorite': $this->UpdateVote('q_unfavorite', $postid,$userid, $params, 'unfavorite', -1); $dolog=false; break; */ /* case 'q_unfavorite': $this->UpdateVote('q_unfavorite', $postid,$userid, $params, 'unfavorite', -1); $dolog=false; break; */ case 'q_post': $already_notified = ""; if ($params['parent']['type'] == 'A') { $effecteduserid = $params['parent']['userid']; if ($loggeduserid != $effecteduserid) { $event = 'related'; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } $already_notified = $effecteduserid; } } // for social postings if (qw_check_pref_for_event(@$effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_q_post_social', $postid, $userid, null, $params, 'q_post'); } $categoryid = isset($params['categoryid']) ? $params['categoryid'] : ''; $tags = isset($params['tags']) ? $params['tags'] : ''; $user_datas = $this->qw_get_users_details_notify_email($userid, $tags, $categoryid); if (count($user_datas)) { foreach ($user_datas as $user_data) { $effecteduserid = $user_data['userid']; $event = $user_data['event']; if ($effecteduserid != $already_notified) { // $this->AddEvent($postid,$userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } } } break; case 'u_favorite': if ($loggeduserid != $params['userid']) { $this->UpdateUserFavorite($postid, $userid, $params, 'u_favorite', 1); $effecteduserid = $params['userid']; if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } $dolog = false; } break; /* case 'u_unfavorite': $this->UpdateUserFavorite($postid,$userid, $params, 'u_unfavorite', -1); $dolog=false; break; */ /* case 'u_unfavorite': $this->UpdateUserFavorite($postid,$userid, $params, 'u_unfavorite', -1); $dolog=false; break; */ case 'u_message': if ($loggeduserid != $params['userid']) { $effecteduserid = $params['userid']; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; case 'u_wall_post': if ($loggeduserid != $params['userid']) { $effecteduserid = $params['userid']; $params['message'] = $params['content']; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; case 'u_level': $old_level = $params['oldlevel']; $new_level = $params['level']; if ($new_level > $old_level) { //add the event only if the level increases $effecteduserid = $params['userid']; $this->AddEvent($postid, $userid, $effecteduserid, $params, $event); if (qw_check_pref_for_event($effecteduserid, $event, $all_preferences)) { qw_do_action('user_event_' . $event, $postid, $userid, $effecteduserid, $params, $event); } } break; default: $dolog = false; } }
function qa_post_parent_to_question($parent) { if ($parent['basetype'] == 'Q') { $question = $parent; } else { $question = qa_post_get_full($parent['parentid'], 'Q'); } return $question; }
function qa_admin_single_click($entityid, $action) { $userid = qa_get_logged_in_userid(); if (!QA_FINAL_EXTERNAL_USERS && ($action == 'userapprove' || $action == 'userblock')) { // approve/block moderated users require_once QA_INCLUDE_DIR . 'db/selects.php'; $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($entityid, true)); if (isset($useraccount) && qa_get_logged_in_level() >= QA_USER_LEVEL_MODERATOR) { switch ($action) { case 'userapprove': if ($useraccount['level'] <= QA_USER_LEVEL_APPROVED) { // don't demote higher level users require_once QA_INCLUDE_DIR . 'app/users-edit.php'; qa_set_user_level($useraccount['userid'], $useraccount['handle'], QA_USER_LEVEL_APPROVED, $useraccount['level']); return true; } break; case 'userblock': require_once QA_INCLUDE_DIR . 'app/users-edit.php'; qa_set_user_blocked($useraccount['userid'], $useraccount['handle'], true); return true; break; } } } else { // something to do with a post require_once QA_INCLUDE_DIR . 'app/posts.php'; $post = qa_post_get_full($entityid); if (isset($post)) { $queued = substr($post['type'], 1) == '_QUEUED'; switch ($action) { case 'approve': if ($queued && !qa_user_post_permit_error('permit_moderate', $post)) { qa_post_set_hidden($entityid, false, $userid); return true; } break; case 'reject': if ($queued && !qa_user_post_permit_error('permit_moderate', $post)) { qa_post_set_hidden($entityid, true, $userid); return true; } break; case 'hide': if (!$queued && !qa_user_post_permit_error('permit_hide_show', $post)) { qa_post_set_hidden($entityid, true, $userid); return true; } break; case 'reshow': if ($post['hidden'] && !qa_user_post_permit_error('permit_hide_show', $post)) { qa_post_set_hidden($entityid, false, $userid); return true; } break; case 'delete': if ($post['hidden'] && !qa_user_post_permit_error('permit_delete_hidden', $post)) { qa_post_delete($entityid); return true; } break; case 'clearflags': require_once QA_INCLUDE_DIR . 'app/votes.php'; if (!qa_user_post_permit_error('permit_hide_show', $post)) { qa_flags_clear_all($post, $userid, qa_get_logged_in_handle(), null); return true; } break; } } } return false; }
/** * Fetches the child posts of the question and delete them recursively * * @param $postid */ function ami_dhp_post_delete_recursive($postid) { require_once QA_INCLUDE_DIR . 'qa-app-admin.php'; require_once QA_INCLUDE_DIR . 'qa-db-admin.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; global $ami_dhp_posts_deleted; if (is_null($ami_dhp_posts_deleted)) { $ami_dhp_posts_deleted = array(); } if (in_array($postid, $ami_dhp_posts_deleted)) { return; } $oldpost = qa_post_get_full($postid, 'QAC'); if (!$oldpost['hidden']) { qa_post_set_hidden($postid, true, null); $oldpost = qa_post_get_full($postid, 'QAC'); } switch ($oldpost['basetype']) { case 'Q': $answers = qa_post_get_question_answers($postid); $commentsfollows = qa_post_get_question_commentsfollows($postid); $closepost = qa_post_get_question_closepost($postid); if (count($answers)) { foreach ($answers as $answer) { ami_dhp_post_delete_recursive($answer['postid']); } } if (count($commentsfollows)) { foreach ($commentsfollows as $commentsfollow) { ami_dhp_post_delete_recursive($commentsfollow['postid']); } } if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) { qa_question_delete($oldpost, null, null, null, $closepost); $ami_dhp_posts_deleted[] = $oldpost['postid']; } break; case 'A': $question = qa_post_get_full($oldpost['parentid'], 'Q'); $commentsfollows = qa_post_get_answer_commentsfollows($postid); if (count($commentsfollows)) { foreach ($commentsfollows as $commentsfollow) { ami_dhp_post_delete_recursive($commentsfollow['postid']); } } if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) { qa_answer_delete($oldpost, $question, null, null, null); $ami_dhp_posts_deleted[] = $oldpost['postid']; } break; case 'C': $parent = qa_post_get_full($oldpost['parentid'], 'QA'); $question = qa_post_parent_to_question($parent); if (!in_array($oldpost['postid'], $ami_dhp_posts_deleted)) { qa_comment_delete($oldpost, $question, $parent, null, null, null); $ami_dhp_posts_deleted[] = $oldpost['postid']; } break; } }
function updateQues($postid, $title = null, $content = null, $areaclass = null, $conclass = null, $tags = null, $istop = -1, $ishot = -1) { $post = qa_post_get_full($postid); if ($istop == 1) { //如果设置了置顶,则将同类其它的帖子取消置顶 setTopQuestion($postid); } elseif ($istop == 0) { unsetTopQuestion($postid); } if ($ishot == 1) { setHotQA($postid); } elseif ($ishot == 0) { unsetHotQA($postid); } if (!isset($title)) { $title = $post['title']; } if (!isset($content)) { $content = $post['content']; } if (!isset($areaclass)) { $title = @$post['areaclass']; } if (!isset($conclass)) { $content = @$post['conclass']; } $query = 'UPDATE ^posts set title=$, content=$, areaclass=$, conclass=$,tags=$'; $query .= ' where postid= $'; // echo $query.'<br />'; // for ($i=0; $i < func_num_args(); $i++) { // $arg = func_get_arg($i); // echo $arg.'<br />'; // } $arr = qa_db_query_sub($query, $title, $content, $areaclass, $conclass, $tags, $postid); return qa_db_last_insert_id(); }
function questioninfo($qid) { $q = qa_post_get_full($qid); return $q; }