Example #1
0
 public function index_action()
 {
     if ($_GET['tag']) {
         $this->crumb(AWS_APP::lang()->_t('标签') . ': ' . $_GET['tag'], '/favorite/tag-' . $_GET['tag']);
     }
     //边栏可能感兴趣的人或话题
     if (TPL::is_output('block/sidebar_recommend_users_topics.tpl.htm', 'favorite/index')) {
         $recommend_users_topics = $this->model('module')->recommend_users_topics($this->user_id);
         TPL::assign('sidebar_recommend_users_topics', $recommend_users_topics);
     }
     if ($action_list = $this->model('favorite')->get_item_list($_GET['tag'], $this->user_id, calc_page_limit($_GET['page'], get_setting('contents_per_page')))) {
         foreach ($action_list as $key => $val) {
             $item_ids[] = $val['item_id'];
         }
         TPL::assign('list', $action_list);
     } else {
         if (!$_GET['page'] or $_GET['page'] == 1) {
             $this->model('favorite')->remove_favorite_tag(null, null, $_GET['tag'], $this->user_id);
         }
     }
     if ($item_ids) {
         $favorite_items_tags = $this->model('favorite')->get_favorite_items_tags_by_item_id($this->user_id, $item_ids);
         TPL::assign('favorite_items_tags', $favorite_items_tags);
     }
     TPL::assign('favorite_tags', $this->model('favorite')->get_favorite_tags($this->user_id));
     TPL::assign('pagination', AWS_APP::pagination()->initialize(array('base_url' => get_js_url('/favorite/tag-' . $_GET['tag']), 'total_rows' => $this->model('favorite')->count_favorite_items($this->user_id, $_GET['tag']), 'per_page' => get_setting('contents_per_page')))->create_links());
     TPL::output('favorite/index');
 }
 public function search_topics($q, $page, $limit = 20)
 {
     if (is_array($q)) {
         $q = implode('', $q);
     }
     if ($result = $this->fetch_all('topic', "topic_title LIKE '" . $this->quote($q) . "%' AND merged_id = 0", null, calc_page_limit($page, $limit))) {
         foreach ($result as $key => $val) {
             if (!$val['url_token']) {
                 $result[$key]['url_token'] = urlencode($val['topic_title']);
             }
         }
     }
     return $result;
 }
Example #3
0
 public function favorite_list_action()
 {
     if ($_GET['tag']) {
         $this->crumb(AWS_APP::lang()->_t('标签') . ': ' . $_GET['tag'], '/favorite/tag-' . $_GET['tag']);
     }
     if ($action_list = $this->model('favorite')->get_item_list($_GET['tag'], $this->user_id, calc_page_limit($_GET['page'], get_setting('contents_per_page')))) {
         foreach ($action_list as $key => $val) {
             $item_ids[] = $val['item_id'];
         }
         TPL::assign('list', $action_list);
     } else {
         if (!$_GET['page'] or $_GET['page'] == 1) {
             $this->model('favorite')->remove_favorite_tag(null, null, $_GET['tag'], $this->user_id);
         }
     }
     TPL::output('m/ajax/favorite_list');
 }
Example #4
0
 public function fetch_answers_list_by_topic_ids($topic_ids, $page, $limit)
 {
     if (!is_array($topic_ids)) {
         return false;
     }
     array_walk_recursive($topic_ids, 'intval_string');
     $result_cache_key = 'reader_list_by_topic_ids_' . md5(implode('_', $topic_ids) . $page . $limit);
     if (!($result = AWS_APP::cache()->get($result_cache_key))) {
         $topic_relation_where[] = '`topic_id` IN(' . implode(',', $topic_ids) . ')';
         $topic_relation_where[] = "`type` = 'question'";
         if ($topic_relation_query = $this->query_all("SELECT item_id FROM " . get_table('topic_relation') . " WHERE " . implode(' AND ', $topic_relation_where))) {
             foreach ($topic_relation_query as $key => $val) {
                 $question_ids[$val['item_id']] = $val['item_id'];
             }
         }
         if (!$question_ids) {
             return false;
         }
         $result = $this->fetch_all('answer', 'question_id IN (' . implode(',', $question_ids) . ') AND add_time > ' . (time() - 86400 * intval(get_setting('reader_questions_last_days'))) . ' AND agree_count >= ' . intval(get_setting('reader_questions_agree_count')), 'add_time DESC', calc_page_limit($page, $limit));
         AWS_APP::cache()->set($result_cache_key, $result, get_setting('cache_level_low'));
     }
     return $result;
 }
Example #5
0
 public function index_action()
 {
     if ($_GET['notification_id']) {
         $this->model('notify')->read_notification($_GET['notification_id'], $this->user_id);
     }
     if (is_mobile()) {
         HTTP::redirect('/m/question/' . $_GET['id']);
     }
     if ($_GET['column'] == 'log' and !$this->user_id) {
         HTTP::redirect('/question/' . $_GET['id']);
     }
     if (!($question_info = $this->model('question')->get_question_info_by_id($_GET['id']))) {
         H::redirect_msg(AWS_APP::lang()->_t('问题不存在或已被删除'), '/question/');
     }
     if (!$_GET['sort'] or $_GET['sort'] != 'ASC') {
         $_GET['sort'] = 'DESC';
     } else {
         $_GET['sort'] = 'ASC';
     }
     if (get_setting('unfold_question_comments') == 'Y') {
         $_GET['comment_unfold'] = 'all';
     }
     $question_info['redirect'] = $this->model('question')->get_redirect($question_info['question_id']);
     if ($question_info['redirect']['target_id']) {
         $target_question = $this->model('question')->get_question_info_by_id($question_info['redirect']['target_id']);
     }
     if (is_digits($_GET['rf']) and $_GET['rf']) {
         if ($from_question = $this->model('question')->get_question_info_by_id($_GET['rf'])) {
             $redirect_message[] = AWS_APP::lang()->_t('从问题 %s 跳转而来', '<a href="' . get_js_url('/question/' . $_GET['rf'] . '?rf=false') . '">' . $from_question['question_content'] . '</a>');
         }
     }
     if ($question_info['redirect'] and !$_GET['rf']) {
         if ($target_question) {
             HTTP::redirect('/question/' . $question_info['redirect']['target_id'] . '?rf=' . $question_info['question_id']);
         } else {
             $redirect_message[] = AWS_APP::lang()->_t('重定向目标问题已被删除, 将不再重定向问题');
         }
     } else {
         if ($question_info['redirect']) {
             if ($target_question) {
                 $message = AWS_APP::lang()->_t('此问题将跳转至') . ' <a href="' . get_js_url('/question/' . $question_info['redirect']['target_id'] . '?rf=' . $question_info['question_id']) . '">' . $target_question['question_content'] . '</a>';
                 if ($this->user_id and ($this->user_info['permission']['is_administortar'] or $this->user_info['permission']['is_moderator'] or !$this->question_info['lock'] and $this->user_info['permission']['redirect_question'])) {
                     $message .= '&nbsp; (<a href="javascript:;" onclick="AWS.ajax_request(G_BASE_URL + \'/question/ajax/redirect/\', \'item_id=' . $question_info['question_id'] . '\');">' . AWS_APP::lang()->_t('撤消重定向') . '</a>)';
                 }
                 $redirect_message[] = $message;
             } else {
                 $redirect_message[] = AWS_APP::lang()->_t('重定向目标问题已被删除, 将不再重定向问题');
             }
         }
     }
     if ($question_info['has_attach']) {
         $question_info['attachs'] = $this->model('publish')->get_attach('question', $question_info['question_id'], 'min');
         $question_info['attachs_ids'] = FORMAT::parse_attachs($question_info['question_detail'], true);
     }
     if ($question_info['category_id'] and get_setting('category_enable') == 'Y') {
         $question_info['category_info'] = $this->model('system')->get_category_info($question_info['category_id']);
     }
     $question_info['user_info'] = $this->model('account')->get_user_info_by_uid($question_info['published_uid'], true);
     if ($_GET['column'] != 'log') {
         $this->model('question')->calc_popular_value($question_info['question_id']);
         $this->model('question')->update_views($question_info['question_id']);
         if (is_digits($_GET['uid'])) {
             $answer_list_where[] = 'uid = ' . intval($_GET['uid']);
             $answer_count_where = 'uid = ' . intval($_GET['uid']);
         } else {
             if ($_GET['uid'] == 'focus' and $this->user_id) {
                 if ($friends = $this->model('follow')->get_user_friends($this->user_id, false)) {
                     foreach ($friends as $key => $val) {
                         $follow_uids[] = $val['uid'];
                     }
                 } else {
                     $follow_uids[] = 0;
                 }
                 $answer_list_where[] = 'uid IN(' . implode($follow_uids, ',') . ')';
                 $answer_count_where = 'uid IN(' . implode($follow_uids, ',') . ')';
                 $answer_order_by = 'add_time ASC';
             } else {
                 if ($_GET['sort_key'] == 'add_time') {
                     $answer_order_by = $_GET['sort_key'] . " " . $_GET['sort'];
                 } else {
                     $answer_order_by = "agree_count " . $_GET['sort'] . ", against_count ASC, add_time ASC";
                 }
             }
         }
         if ($answer_count_where) {
             $answer_count = $this->model('answer')->get_answer_count_by_question_id($question_info['question_id'], $answer_count_where);
         } else {
             $answer_count = $question_info['answer_count'];
         }
         if (isset($_GET['answer_id']) and (!$this->user_id or $_GET['single'])) {
             $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . intval($_GET['answer_id']));
         } else {
             if (!$this->user_id and !$this->user_info['permission']['answer_show']) {
                 if ($question_info['best_answer']) {
                     $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . intval($question_info['best_answer']));
                 } else {
                     $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, null, 'agree_count DESC');
                 }
             } else {
                 if ($answer_list_where) {
                     $answer_list_where = implode(' AND ', $answer_list_where);
                 }
                 $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], calc_page_limit($_GET['page'], 100), $answer_list_where, $answer_order_by);
             }
         }
         // 最佳回复预留
         $answers[0] = '';
         if (!is_array($answer_list)) {
             $answer_list = array();
         }
         $answer_ids = array();
         $answer_uids = array();
         foreach ($answer_list as $answer) {
             $answer_ids[] = $answer['answer_id'];
             $answer_uids[] = $answer['uid'];
             if ($answer['has_attach']) {
                 $has_attach_answer_ids[] = $answer['answer_id'];
             }
         }
         if (!in_array($question_info['best_answer'], $answer_ids) and intval($_GET['page']) < 2) {
             $answer_list = array_merge($this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . $question_info['best_answer']), $answer_list);
         }
         if ($answer_ids) {
             $answer_agree_users = $this->model('answer')->get_vote_user_by_answer_ids($answer_ids);
             $answer_vote_status = $this->model('answer')->get_answer_vote_status($answer_ids, $this->user_id);
             $answer_users_rated_thanks = $this->model('answer')->users_rated('thanks', $answer_ids, $this->user_id);
             $answer_users_rated_uninterested = $this->model('answer')->users_rated('uninterested', $answer_ids, $this->user_id);
             $answer_attachs = $this->model('publish')->get_attachs('answer', $has_attach_answer_ids, 'min');
         }
         foreach ($answer_list as $answer) {
             if ($answer['has_attach']) {
                 $answer['attachs'] = $answer_attachs[$answer['answer_id']];
                 $answer['insert_attach_ids'] = FORMAT::parse_attachs($answer['answer_content'], true);
             }
             $answer['user_rated_thanks'] = $answer_users_rated_thanks[$answer['answer_id']];
             $answer['user_rated_uninterested'] = $answer_users_rated_uninterested[$answer['answer_id']];
             $answer['answer_content'] = $this->model('question')->parse_at_user(FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode($answer['answer_content']))));
             $answer['agree_users'] = $answer_agree_users[$answer['answer_id']];
             $answer['agree_status'] = $answer_vote_status[$answer['answer_id']];
             if ($question_info['best_answer'] == $answer['answer_id'] and intval($_GET['page']) < 2) {
                 $answers[0] = $answer;
             } else {
                 $answers[] = $answer;
             }
         }
         if (!$answers[0]) {
             unset($answers[0]);
         }
         if (get_setting('answer_unique') == 'Y') {
             if ($this->model('answer')->has_answer_by_uid($question_info['question_id'], $this->user_id)) {
                 TPL::assign('user_answered', 1);
             } else {
                 TPL::assign('user_answered', 0);
             }
         }
         TPL::assign('answers', $answers);
         TPL::assign('answer_count', $answer_count);
     }
     if ($this->user_id) {
         TPL::assign('question_thanks', $this->model('question')->get_question_thanks($question_info['question_id'], $this->user_id));
         TPL::assign('invite_users', $this->model('question')->get_invite_users($question_info['question_id']));
         TPL::assign('user_follow_check', $this->model('follow')->user_follow_check($this->user_id, $question_info['published_uid']));
         if ($this->user_info['draft_count'] > 0) {
             TPL::assign('draft_content', $this->model('draft')->get_data($question_info['question_id'], 'answer', $this->user_id));
         }
     }
     $question_info['question_detail'] = FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode($question_info['question_detail'])));
     TPL::assign('question_info', $question_info);
     TPL::assign('question_focus', $this->model('question')->has_focus_question($question_info['question_id'], $this->user_id));
     $question_topics = $this->model('topic')->get_topics_by_item_id($question_info['question_id'], 'question');
     if (sizeof($question_topics) == 0 and $this->user_id) {
         $related_topics = $this->model('question')->get_related_topics($question_info['question_content']);
         TPL::assign('related_topics', $related_topics);
     }
     TPL::assign('question_topics', $question_topics);
     TPL::assign('question_related_list', $this->model('question')->get_related_question_list($question_info['question_id'], $question_info['question_content']));
     TPL::assign('question_related_links', $this->model('related')->get_related_links('question', $question_info['question_id']));
     if ($this->user_id) {
         if ($question_topics) {
             foreach ($question_topics as $key => $val) {
                 $question_topic_ids[] = $val['topic_id'];
             }
         }
         if ($helpful_users = $this->model('topic')->get_helpful_users_by_topic_ids($question_topic_ids, 17)) {
             foreach ($helpful_users as $key => $val) {
                 if ($val['user_info']['uid'] == $this->user_id) {
                     unset($helpful_users[$key]);
                 } else {
                     $helpful_users[$key]['has_invite'] = $this->model('question')->has_question_invite($question_info['question_id'], $val['user_info']['uid'], $this->user_id);
                     $helpful_users[$key]['experience'] = end($helpful_users[$key]['experience']);
                 }
             }
             TPL::assign('helpful_users', $helpful_users);
         }
     }
     $this->crumb($question_info['question_content'], '/question/' . $question_info['question_id']);
     if ($_GET['column'] == 'log') {
         $this->crumb(AWS_APP::lang()->_t('日志'), '/question/id-' . $question_info['question_id'] . '__column-log');
     } else {
         TPL::assign('human_valid', human_valid('answer_valid_hour'));
         if ($this->user_id) {
             TPL::assign('pagination', AWS_APP::pagination()->initialize(array('base_url' => get_js_url('/question/id-' . $question_info['question_id'] . '__sort_key-' . $_GET['sort_key'] . '__sort-' . $_GET['sort'] . '__uid-' . $_GET['uid']), 'total_rows' => $answer_count, 'per_page' => 100))->create_links());
         }
     }
     TPL::set_meta('keywords', implode(',', $this->model('system')->analysis_keyword($question_info['question_content'])));
     TPL::set_meta('description', $question_info['question_content'] . ' - ' . cjk_substr(str_replace("\r\n", ' ', strip_tags($question_info['question_detail'])), 0, 128, 'UTF-8', '...'));
     if (get_setting('advanced_editor_enable') == 'Y') {
         import_editor_static_files();
     }
     if (get_setting('upload_enable') == 'Y') {
         // fileupload
         TPL::import_js('js/fileupload.js');
     }
     TPL::assign('attach_access_key', md5($this->user_id . time()));
     TPL::assign('redirect_message', $redirect_message);
     $recommend_posts = $this->model('posts')->get_recommend_posts_by_topic_ids($question_topic_ids);
     if ($recommend_posts) {
         foreach ($recommend_posts as $key => $value) {
             if ($value['question_id'] and $value['question_id'] == $question_info['question_id']) {
                 unset($recommend_posts[$key]);
                 break;
             }
         }
         TPL::assign('recommend_posts', $recommend_posts);
     }
     // 答题选项
     if (intval($question_info['quiz_id']) > 0) {
         $question_quiz = $this->model('quiz')->get_question_quiz_info_by_id($question_info['quiz_id']);
         TPL::import_js('js/quiz.js');
         TPL::import_css('css/quiz.css');
         TPL::import_js('js/app/question.js');
         TPL::assign('question_quiz', $question_quiz);
     }
     TPL::output('question/index');
 }
Example #6
0
 public function people_square_action()
 {
     if (!$_GET['page']) {
         $_GET['page'] = 1;
     }
     $this->crumb(AWS_APP::lang()->_t('用户列表'), '/m/people/');
     if ($_GET['feature_id']) {
         if ($helpful_users = $this->model('topic')->get_helpful_users_by_topic_ids($this->model('feature')->get_topics_by_feature_id($_GET['feature_id']), get_setting('contents_per_page'), 4)) {
             foreach ($helpful_users as $key => $val) {
                 $users_list[$key] = $val['user_info'];
                 $users_list[$key]['experience'] = $val['experience'];
                 foreach ($val['experience'] as $exp_key => $exp_val) {
                     $users_list[$key]['total_agree_count'] += $exp_val['agree_count'];
                 }
             }
         }
     } else {
         $where = array();
         if ($_GET['group_id']) {
             $where[] = 'group_id = ' . intval($_GET['group_id']);
         }
         $users_list = $this->model('account')->get_users_list(implode('', $where), calc_page_limit($_GET['page'], get_setting('contents_per_page')), true, false, 'reputation DESC');
         $where[] = 'forbidden = 0 AND group_id <> 3';
         TPL::assign('pagination', AWS_APP::pagination()->initialize(array('base_url' => get_js_url('/m/people/group_id-' . $_GET['group_id']), 'total_rows' => $this->model('account')->get_user_count(implode(' AND ', $where)), 'per_page' => get_setting('contents_per_page'), 'num_links' => 1))->create_links());
     }
     if ($users_list) {
         foreach ($users_list as $key => $val) {
             if ($val['reputation']) {
                 $reputation_users_ids[] = $val['uid'];
                 $users_reputations[$val['uid']] = $val['reputation'];
             }
             $uids[] = $val['uid'];
         }
         if (!$_GET['feature_id']) {
             $reputation_topics = $this->model('people')->get_users_reputation_topic($reputation_users_ids, $users_reputations, 4);
             foreach ($users_list as $key => $val) {
                 $users_list[$key]['reputation_topics'] = $reputation_topics[$val['uid']];
             }
         }
         if ($uids and $this->user_id) {
             $users_follow_check = $this->model('follow')->users_follow_check($this->user_id, $uids);
         }
         foreach ($users_list as $key => $val) {
             $users_list[$key]['focus'] = $users_follow_check[$val['uid']];
         }
         TPL::assign('users_list', array_values($users_list));
     }
     if (!$_GET['group_id']) {
         TPL::assign('feature_list', $this->model('feature')->get_enabled_feature_list());
     }
     TPL::assign('custom_group', $this->model('account')->get_user_group_list(0, 1));
     TPL::output('m/people_square');
 }
 public function index_action()
 {
     if (!($question_info = $this->model('question')->get_question_info_by_id($_GET['id']))) {
         H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('问题不存在或已被删除')));
     }
     if (!$_GET['sort'] or $_GET['sort'] != 'ASC') {
         $_GET['sort'] = 'DESC';
     } else {
         $_GET['sort'] = 'ASC';
     }
     if (get_setting('unfold_question_comments') == 'Y') {
         $_GET['comment_unfold'] = 'all';
     }
     $question_info['redirect'] = $this->model('question')->get_redirect($question_info['question_id']);
     if ($question_info['redirect']['target_id']) {
         $target_question = $this->model('question')->get_question_info_by_id($question_info['redirect']['target_id']);
     }
     if (is_digits($_GET['rf']) and $_GET['rf']) {
         if ($from_question = $this->model('question')->get_question_info_by_id($_GET['rf'])) {
             $redirect_message[] = AWS_APP::lang()->_t('从问题 %s 跳转而来', '<a href="' . get_js_url('/question/' . $_GET['rf'] . '?rf=false') . '">' . $from_question['question_content'] . '</a>');
         }
     }
     if ($question_info['redirect'] and !$_GET['rf']) {
         if ($target_question) {
             HTTP::redirect('/question/' . $question_info['redirect']['target_id'] . '?rf=' . $question_info['question_id']);
         } else {
             $redirect_message[] = AWS_APP::lang()->_t('重定向目标问题已被删除, 将不再重定向问题');
         }
     } else {
         if ($question_info['redirect']) {
             if ($target_question) {
                 $message = AWS_APP::lang()->_t('此问题将跳转至') . ' <a href="' . get_js_url('/question/' . $question_info['redirect']['target_id'] . '?rf=' . $question_info['question_id']) . '">' . $target_question['question_content'] . '</a>';
                 if ($this->user_id and ($this->user_info['permission']['is_administortar'] or $this->user_info['permission']['is_moderator'] or !$this->question_info['lock'] and $this->user_info['permission']['redirect_question'])) {
                     $message .= '&nbsp; (<a href="javascript:;" onclick="AWS.ajax_request(G_BASE_URL + \'/question/ajax/redirect/\', \'item_id=' . $question_info['question_id'] . '\');">' . AWS_APP::lang()->_t('撤消重定向') . '</a>)';
                 }
                 $redirect_message[] = $message;
             } else {
                 $redirect_message[] = AWS_APP::lang()->_t('重定向目标问题已被删除, 将不再重定向问题');
             }
         }
     }
     $question_info['user_info'] = $this->model('account')->get_user_info_by_uid($question_info['published_uid'], true);
     if ($_GET['column'] != 'log') {
         $this->model('question')->calc_popular_value($question_info['question_id']);
         $this->model('question')->update_views($question_info['question_id']);
         if (is_digits($_GET['uid'])) {
             $answer_list_where[] = 'uid = ' . intval($_GET['uid']);
             $answer_count_where = 'uid = ' . intval($_GET['uid']);
         } else {
             if ($_GET['uid'] == 'focus' and $this->user_id) {
                 if ($friends = $this->model('follow')->get_user_friends($this->user_id, false)) {
                     foreach ($friends as $key => $val) {
                         $follow_uids[] = $val['uid'];
                     }
                 } else {
                     $follow_uids[] = 0;
                 }
                 $answer_list_where[] = 'uid IN(' . implode($follow_uids, ',') . ')';
                 $answer_count_where = 'uid IN(' . implode($follow_uids, ',') . ')';
                 $answer_order_by = 'add_time ASC';
             } else {
                 if ($_GET['sort_key'] == 'add_time') {
                     $answer_order_by = $_GET['sort_key'] . " " . $_GET['sort'];
                 } else {
                     $answer_order_by = "agree_count " . $_GET['sort'] . ", against_count ASC, add_time ASC";
                 }
             }
         }
         if ($answer_count_where) {
             $answer_count = $this->model('answer')->get_answer_count_by_question_id($question_info['question_id'], $answer_count_where);
         } else {
             $answer_count = $question_info['answer_count'];
         }
         if (isset($_GET['answer_id']) and (!$this->user_id or $_GET['single'])) {
             $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . intval($_GET['answer_id']));
         } else {
             if (!$this->user_id and !$this->user_info['permission']['answer_show']) {
                 if ($question_info['best_answer']) {
                     $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . intval($question_info['best_answer']));
                 } else {
                     $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, null, 'agree_count DESC');
                 }
             } else {
                 if ($answer_list_where) {
                     $answer_list_where = implode(' AND ', $answer_list_where);
                 }
                 $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], calc_page_limit($_GET['page'], 100), $answer_list_where, $answer_order_by);
             }
         }
         // 最佳回复预留
         $answers[0] = '';
         if (!is_array($answer_list)) {
             $answer_list = array();
         }
         $answer_ids = array();
         $answer_uids = array();
         foreach ($answer_list as $answer) {
             $answer_ids[] = $answer['answer_id'];
             $answer_uids[] = $answer['uid'];
             if ($answer['has_attach']) {
                 $has_attach_answer_ids[] = $answer['answer_id'];
             }
         }
         if (!in_array($question_info['best_answer'], $answer_ids) and intval($_GET['page']) < 2) {
             $answer_list = array_merge($this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . $question_info['best_answer']), $answer_list);
         }
         if ($answer_ids) {
             $answer_vote_status = $this->model('answer')->get_answer_vote_status($answer_ids, $this->user_id);
             $answer_users_rated_thanks = $this->model('answer')->users_rated('thanks', $answer_ids, $this->user_id);
             $answer_users_rated_uninterested = $this->model('answer')->users_rated('uninterested', $answer_ids, $this->user_id);
         }
         foreach ($answer_list as $answer) {
             $answer['user_rated_thanks'] = $answer_users_rated_thanks[$answer['answer_id']];
             $answer['user_rated_uninterested'] = $answer_users_rated_uninterested[$answer['answer_id']];
             $answer['answer_content'] = cjk_substr(strip_ubb($answer['answer_content']), 0, 100);
             //$answer['agree_users'] = $answer_agree_users[$answer['answer_id']];
             $answer['agree_status'] = $answer_vote_status[$answer['answer_id']];
             $answer['user_info']['avatar_file'] = get_avatar_url($answer['uid']);
             if ($question_info['best_answer'] == $answer['answer_id'] and intval($_GET['page']) < 2) {
                 $answers[0] = $answer;
             } else {
                 $answers[] = $answer;
             }
         }
         if (!$answers[0]) {
             unset($answers[0]);
         }
         $question_info['user_answered'] = 0;
         //如果系统设置了用户只能回答一次
         if (get_setting('answer_unique') == 'Y') {
             if ($this->model('answer')->has_answer_by_uid($question_info['question_id'], $this->user_id)) {
                 $question_info['user_answered'] = 1;
             } else {
                 $question_info['user_answered'] = 0;
             }
         }
     }
     $question_info['user_follow_check'] = 0;
     $question_info['user_question_focus'] = 0;
     $question_info['user_thanks'] = 0;
     if ($this->user_id) {
         if ($this->model('question')->get_question_thanks($question_info['question_id'], $this->user_id)) {
             $question_info['user_thanks'] = 1;
         }
         //当前用户是否已关注该问题作者
         if ($this->model('follow')->user_follow_check($this->user_id, $question_info['published_uid'])) {
             $question_info['user_follow_check'] = 1;
         }
         if ($this->model('question')->has_focus_question($question_info['question_id'], $this->user_id)) {
             $question_info['user_question_focus'] = 1;
         }
     }
     $question_info['question_detail'] = FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode($question_info['question_detail'])));
     $question_topics = $this->model('topic')->get_topics_by_item_id($question_info['question_id'], 'question');
     $question_info['answer_count'] = $answer_count;
     //clean
     $question_key = array('question_id', 'question_content', 'question_detail', 'add_time', 'update_time', 'answer_count', 'view_count', 'agree_count', 'focus_count', 'against_count', 'thanks_count', 'comment_count', 'user_info', 'user_answered', 'user_thanks', 'user_follow_check', 'user_question_focus');
     $user_key = array('uid', 'user_name', 'namecard_pic', 'signature');
     $topics_key = array('topic_id', 'topic_title');
     foreach ($question_info as $k => $v) {
         if (!in_array($k, $question_key)) {
             unset($question_info[$k]);
         }
     }
     //作者信息
     if (!empty($question_info['user_info'])) {
         foreach ($question_info['user_info'] as $k => $v) {
             if (!in_array($k, $user_key)) {
                 unset($question_info['user_info'][$k]);
             }
         }
         $question_info['user_info']['avatar_file'] = get_avatar_url($question_info['user_info']['uid'], 'mid');
     }
     if (!empty($answers)) {
         foreach ($answers as $key => $value) {
             if (!empty($value['user_info'])) {
                 foreach ($value['user_info'] as $k => $v) {
                     if (!in_array($k, $user_key)) {
                         unset($answers[$key]['user_info'][$k]);
                     }
                 }
                 $answers[$key]['user_info']['avatar_file'] = get_avatar_url($answers[$key]['user_info']['uid'], 'mid');
             }
             $answers[$key]['answer_content'] = strip_tags($value['answer_content']);
         }
     }
     if (!empty($question_topics)) {
         foreach ($question_topics as $key => $val) {
             foreach ($val as $k => $v) {
                 if (!in_array($k, $topics_key)) {
                     unset($question_topics[$key][$k]);
                 }
             }
         }
     }
     //$question_info['answers'] = $answers;
     H::ajax_json_output(AWS_APP::RSM(array('question_info' => $question_info, 'question_topics' => $question_topics, 'answers' => array_values($answers)), 1, null));
 }
Example #8
0
 public function get_hot_topics($days = null, $page = null, $per_page = null, $count = false)
 {
     $time = is_digits($days) ? ' AND `add_time` > ' . (time() - $days * 24 * 60 * 60) : '';
     if ($count) {
         $result = $this->query_row('SELECT count(DISTINCT `topic_id`) AS `count` FROM `' . $this->get_table('topic_relation') . '` WHERE `type` = "ticket"' . $time);
         return $result['count'];
     }
     $limit = ($page and $per_page) ? ' LIMIT ' . calc_page_limit($page, $per_page) : '';
     $hot_topics_query = $this->query_all('SELECT `topic_id`, count(*) AS `count` FROM `' . $this->get_table('topic_relation') . '` WHERE `type` = "ticket"' . $time . ' GROUP BY `topic_id` ORDER BY `count` DESC' . $limit);
     if ($hot_topics_query) {
         foreach ($hot_topics_query as $hot_topic) {
             $topic_ids[] = $hot_topic['topic_id'];
         }
         $tickets_query = $this->query_all('SELECT `topic_id`, `item_id` FROM `' . $this->get_table('topic_relation') . '` WHERE `topic_id` IN (' . implode(', ', $topic_ids) . ')');
         foreach ($tickets_query as $val) {
             $ticket_ids[] = $val['item_id'];
             $topic_ticket[$val['topic_id']][] = $val['item_id'];
         }
         $hot_topics_list = $this->model('topic')->get_topics_by_ids($topic_ids);
         $tickets_list = $this->get_tickets_list(array('ids' => $ticket_ids));
         $hot_topics = array();
         foreach ($hot_topics_query as $val) {
             $hot_topics[$val['topic_id']] = $hot_topics_list[$val['topic_id']];
             $hot_topics[$val['topic_id']]['tickets_count'] = $val['count'];
             $hot_topics[$val['topic_id']]['unassigned_tickets_count'] = 0;
             $hot_topics[$val['topic_id']]['pending_tickets_count'] = 0;
             $hot_topics[$val['topic_id']]['closed_tickets_count'] = 0;
             foreach ($tickets_list as $ticket_info) {
                 if (in_array($ticket_info['id'], $topic_ticket[$val['topic_id']])) {
                     if ($ticket_info['status'] == 'closed') {
                         $hot_topics[$val['topic_id']]['closed_tickets_count']++;
                     } else {
                         if ($ticket_info['service']) {
                             $hot_topics[$val['topic_id']]['pending_tickets_count']++;
                         } else {
                             $hot_topics[$val['topic_id']]['unassigned_tickets_count']++;
                         }
                     }
                 }
             }
         }
     }
     return $hot_topics;
 }
Example #9
0
 function load_answers_action()
 {
     // 获取问题
     if (!($question_info = $this->model('question')->get_question_info_by_id($_GET['question_id']))) {
         return;
     }
     $this->model('question')->calc_popular_value($question_info['question_id']);
     $this->model('question')->update_views($question_info['question_id']);
     if (!$_GET['sort'] or $_GET['sort'] != 'ASC') {
         $_GET['sort'] = 'DESC';
     } else {
         $_GET['sort'] = 'ASC';
     }
     if (is_digits($_GET['uid'])) {
         $answer_list_where[] = 'uid = ' . intval($_GET['uid']);
         $answer_count_where = 'uid = ' . intval($_GET['uid']);
     } else {
         if ($_GET['uid'] == 'focus' and $this->user_id) {
             if ($friends = $this->model('follow')->get_user_friends($this->user_id, false)) {
                 foreach ($friends as $key => $val) {
                     $follow_uids[] = $val['uid'];
                 }
             } else {
                 $follow_uids[] = 0;
             }
             $answer_list_where[] = 'uid IN(' . implode($follow_uids, ',') . ')';
             $answer_count_where = 'uid IN(' . implode($follow_uids, ',') . ')';
             $answer_order_by = 'add_time ASC';
         } else {
             if ($_GET['sort_key'] == 'popularity') {
                 $answer_order_by = "agree_count " . $_GET['sort'] . ", against_count ASC, add_time ASC";
             } else {
                 $answer_order_by = "add_time " . $_GET['sort'];
             }
         }
     }
     if ($answer_count_where) {
         $answer_count = $this->model('answer')->get_answer_count_by_question_id($question_info['question_id'], $answer_count_where);
     } else {
         $answer_count = $question_info['answer_count'];
     }
     if (isset($_GET['answer_id']) and (!$this->user_id or $_GET['single'])) {
         $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . intval($_GET['answer_id']));
     } else {
         if (!$this->user_id and !$this->user_info['permission']['answer_show']) {
             if ($question_info['best_answer']) {
                 $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . intval($question_info['best_answer']));
             } else {
                 $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, null, 'agree_count DESC');
             }
         } else {
             if ($answer_list_where) {
                 $answer_list_where = implode(' AND ', $answer_list_where);
             }
             $answer_list = $this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], calc_page_limit($_GET['page'], 100), $answer_list_where, $answer_order_by);
         }
     }
     // 最佳回复预留
     $answers[0] = '';
     if (!is_array($answer_list)) {
         $answer_list = array();
     }
     $answer_ids = array();
     $answer_uids = array();
     foreach ($answer_list as $answer) {
         $answer_ids[] = $answer['answer_id'];
         $answer_uids[] = $answer['uid'];
         if ($answer['has_attach']) {
             $has_attach_answer_ids[] = $answer['answer_id'];
         }
     }
     if (!in_array($question_info['best_answer'], $answer_ids) and intval($_GET['page']) < 2) {
         $answer_list = array_merge($this->model('answer')->get_answer_list_by_question_id($question_info['question_id'], 1, 'answer_id = ' . $question_info['best_answer']), $answer_list);
     }
     if ($answer_ids) {
         $answer_agree_users = $this->model('answer')->get_vote_user_by_answer_ids($answer_ids);
         $answer_vote_status = $this->model('answer')->get_answer_vote_status($answer_ids, $this->user_id);
         $answer_users_rated_thanks = $this->model('answer')->users_rated('thanks', $answer_ids, $this->user_id);
         $answer_users_rated_uninterested = $this->model('answer')->users_rated('uninterested', $answer_ids, $this->user_id);
         $answer_attachs = $this->model('publish')->get_attachs('answer', $has_attach_answer_ids, 'min');
     }
     foreach ($answer_list as $answer) {
         if ($answer['has_attach']) {
             $answer['attachs'] = $answer_attachs[$answer['answer_id']];
             $answer['insert_attach_ids'] = FORMAT::parse_attachs($answer['answer_content'], true);
         }
         $answer['user_rated_thanks'] = $answer_users_rated_thanks[$answer['answer_id']];
         $answer['user_rated_uninterested'] = $answer_users_rated_uninterested[$answer['answer_id']];
         $answer['answer_content'] = $this->model('question')->parse_at_user(FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode($answer['answer_content']))));
         $answer['agree_users'] = $answer_agree_users[$answer['answer_id']];
         $answer['agree_status'] = $answer_vote_status[$answer['answer_id']];
         if ($question_info['best_answer'] == $answer['answer_id'] and intval($_GET['page']) < 2) {
             $answers[0] = $answer;
         } else {
             $answers[] = $answer;
         }
         // 获取回答评论列表
         $comments = $this->model('answer')->get_answer_comments($answer['answer_id']);
         $user_infos = $this->model('account')->get_user_info_by_uids(fetch_array_value($comments, 'uid'));
         foreach ($comments as $key => $val) {
             $comments[$key]['message'] = FORMAT::parse_links($this->model('question')->parse_at_user($comments[$key]['message']));
             $comments[$key]['user_name'] = $user_infos[$val['uid']]['user_name'];
             $comments[$key]['url_token'] = $user_infos[$val['uid']]['url_token'];
         }
         $answer_comments[$answer['answer_id']] = $comments;
     }
     if (!$answers[0]) {
         unset($answers[0]);
     }
     if ($this->model('answer')->has_answer_by_uid($question_info['question_id'], $this->user_id)) {
         $user_answered = true;
     } else {
         $user_answered = false;
     }
     // 评论附件
     TPL::assign('attach_access_key', md5($this->user_id . time()));
     TPL::assign('user_answered', $user_answered);
     TPL::assign('answers', $answers);
     TPL::assign('comments', $answer_comments);
     TPL::assign('answer_count', $answer_count);
     TPL::output('question/ajax/answer_list');
 }
Example #10
0
 public function square_action()
 {
     if (!$_GET['id'] and !$this->user_id) {
         $_GET['id'] = 'hot';
     }
     if (!$_GET['per_page']) {
         $_GET['per_page'] = 10;
     }
     switch ($_GET['id']) {
         default:
         case 'focus':
             if ($topics_list = $this->model('topic')->get_focus_topic_list($this->user_id, calc_page_limit($_GET['page'], $_GET['per_page']))) {
                 $topics_list_total_rows = $this->user_info['topic_focus_count'];
                 foreach ($topics_list as $key => $val) {
                     $topics_list[$key]['action_list'] = $this->model('posts')->get_posts_list('question', 1, 3, 'new', explode(',', $val['topic_id']));
                 }
             }
             $topic_key = array('topic_id', 'topic_title', 'topic_description', 'topic_pic');
             if (!empty($topics_list)) {
                 foreach ($topics_list as $k => $v) {
                     foreach ($v as $k_k => $v_v) {
                         if (!in_array($k_k, $topic_key)) {
                             unset($topics_list[$k][$k_k]);
                         }
                         if ($k_k = "topic_pic") {
                             $topics_list[$k][$k_k] = str_replace('_32_32', '_100_100', $topics_list[$k][$k_k]);
                         }
                     }
                 }
             }
             H::ajax_json_output(AWS_APP::RSM(array('total_rows' => $topics_list_total_rows, 'rows' => $topics_list), 1, null));
             break;
         case 'hot':
             if (!($topics_list = AWS_APP::cache()->get('square_hot_topic_list_' . intval($_GET['page'])))) {
                 if ($topics_list = $this->model('topic')->get_topic_list(null, 'discuss_count DESC', $_GET['per_page'], $_GET['page'])) {
                     $topics_list_total_rows = $this->model('topic')->found_rows();
                     AWS_APP::cache()->set('square_hot_topic_list_total_rows', $topics_list_total_rows, get_setting('cache_level_low'));
                     foreach ($topics_list as $key => $val) {
                         $topics_list[$key]['action_list'] = $this->model('posts')->get_posts_list('question', 1, 3, 'new', explode(',', $val['topic_id']));
                     }
                 }
                 AWS_APP::cache()->set('square_hot_topic_list_' . intval($_GET['page']), $topics_list, get_setting('cache_level_low'));
             } else {
                 $topics_list_total_rows = AWS_APP::cache()->get('square_hot_topic_list_total_rows');
             }
             $topic_key = array('topic_id', 'topic_title', 'topic_description', 'topic_pic');
             if (!empty($topics_list)) {
                 foreach ($topics_list as $k => $v) {
                     foreach ($v as $k_k => $v_v) {
                         if (!in_array($k_k, $topic_key)) {
                             unset($topics_list[$k][$k_k]);
                         }
                         if ($k_k = "topic_pic") {
                             $topics_list[$k][$k_k] = str_replace('_32_32', '_100_100', $topics_list[$k][$k_k]);
                         }
                     }
                 }
             }
             H::ajax_json_output(AWS_APP::RSM(array('total_rows' => $topics_list_total_rows, 'rows' => $topics_list), 1, null));
             break;
         case 'today':
             if ($today_topics = rtrim(get_setting('today_topics'), ',')) {
                 if (!($today_topic = AWS_APP::cache()->get('square_today_topic_' . md5($today_topics)))) {
                     if ($today_topic = $this->model('topic')->get_topic_by_title(array_random(explode(',', $today_topics)))) {
                         $today_topic['best_answer_users'] = $this->model('topic')->get_best_answer_users_by_topic_id($today_topic['topic_id'], 5);
                         $today_topic['questions_list'] = $this->model('posts')->get_posts_list('question', 1, 3, 'new', explode(',', $today_topic['topic_id']));
                         AWS_APP::cache()->set('square_today_topic_' . md5($today_topics), $today_topic, strtotime('Tomorrow') - time());
                     }
                 }
             }
             $topic_key = array('topic_id', 'topic_title', 'topic_description', 'topic_pic');
             if (!empty($topics_list)) {
                 foreach ($topics_list as $k => $v) {
                     foreach ($v as $k_k => $v_v) {
                         if (!in_array($k_k, $topic_key)) {
                             unset($topics_list[$k][$k_k]);
                         }
                         if ($k_k = "topic_pic") {
                             $topics_list[$k][$k_k] = str_replace('_32_32', '_100_100', $topics_list[$k][$k_k]);
                         }
                     }
                 }
             }
             H::ajax_json_output(AWS_APP::RSM(array('total_rows' => $topics_list_total_rows, 'rows' => $topics_list), 1, null));
             break;
             break;
     }
 }
Example #11
0
 public function index_square_action()
 {
     if (is_mobile()) {
         HTTP::redirect('/m/topic/');
     }
     if ($today_topics = rtrim(get_setting('today_topics'), ',')) {
         if (!($today_topic = AWS_APP::cache()->get('square_today_topic_' . md5($today_topics)))) {
             if ($today_topic = $this->model('topic')->get_topic_by_title(array_random(explode(',', $today_topics)))) {
                 $today_topic['best_answer_users'] = $this->model('topic')->get_best_answer_users_by_topic_id($today_topic['topic_id'], 5);
                 $today_topic['questions_list'] = $this->model('posts')->get_posts_list('question', 1, 3, 'new', explode(',', $today_topic['topic_id']));
                 AWS_APP::cache()->set('square_today_topic_' . md5($today_topics), $today_topic, strtotime('Tomorrow') - time());
             }
         }
         TPL::assign('today_topic', $today_topic);
     }
     switch ($_GET['channel']) {
         case 'focus':
             if ($topics_list = $this->model('topic')->get_focus_topic_list($this->user_id, calc_page_limit($_GET['page'], 20))) {
                 $topics_list_total_rows = $this->user_info['topic_focus_count'];
             }
             TPL::assign('topics_list', $topics_list);
             break;
         default:
         case 'hot':
             switch ($_GET['day']) {
                 case 'month':
                     $order = 'discuss_count_last_month DESC';
                     break;
                 case 'week':
                     $order = 'discuss_count_last_week DESC';
                     break;
                 default:
                     $order = 'discuss_count DESC';
                     break;
             }
             $cache_key = 'square_hot_topic_list' . md5($order) . '_' . intval($_GET['page']);
             if (!($topics_list = AWS_APP::cache()->get($cache_key))) {
                 if ($topics_list = $this->model('topic')->get_topic_list(null, $order, 20, $_GET['page'])) {
                     $topics_list_total_rows = $this->model('topic')->found_rows();
                     AWS_APP::cache()->set('square_hot_topic_list_total_rows', $topics_list_total_rows, get_setting('cache_level_low'));
                 }
                 AWS_APP::cache()->set($cache_key, $topics_list, get_setting('cache_level_low'));
             } else {
                 $topics_list_total_rows = AWS_APP::cache()->get('square_hot_topic_list_total_rows');
             }
             TPL::assign('topics_list', $topics_list);
             break;
         case 'topic':
             if (!($topics_list = AWS_APP::cache()->get('square_parent_topics_topic_list_' . intval($_GET['topic_id']) . '_' . intval($_GET['page'])))) {
                 $topic_ids[] = intval($_GET['topic_id']);
                 if ($child_topic_ids = $this->model('topic')->get_child_topic_ids($_GET['topic_id'])) {
                     $topic_ids = array_merge($child_topic_ids, $topic_ids);
                 }
                 if ($topics_list = $this->model('topic')->get_topic_list('topic_id IN(' . implode(',', $topic_ids) . ') AND merged_id = 0', 'discuss_count DESC', 20, $_GET['page'])) {
                     $topics_list_total_rows = $this->model('topic')->found_rows();
                     AWS_APP::cache()->set('square_parent_topics_topic_list_' . intval($_GET['topic_id']) . '_total_rows', $topics_list_total_rows, get_setting('cache_level_low'));
                 }
                 AWS_APP::cache()->set('square_parent_topics_topic_list_' . intval($_GET['topic_id']) . '_' . intval($_GET['page']), $topics_list, get_setting('cache_level_low'));
             } else {
                 $topics_list_total_rows = AWS_APP::cache()->get('square_parent_topics_topic_list_' . intval($_GET['topic_id']) . '_total_rows');
             }
             TPL::assign('topics_list', $topics_list);
             break;
     }
     TPL::assign('parent_topics', $this->model('topic')->get_parent_topics());
     TPL::assign('new_topics', $this->model('topic')->get_topic_list(null, 'topic_id DESC', 10));
     TPL::assign('pagination', AWS_APP::pagination()->initialize(array('base_url' => get_js_url('/topic/channel-' . $_GET['channel'] . '__topic_id-' . $_GET['topic_id'] . '__day-' . $_GET['day']), 'total_rows' => $topics_list_total_rows, 'per_page' => 20))->create_links());
     $this->crumb(AWS_APP::lang()->_t('话题广场'), '/topic/');
     TPL::output('topic/square');
 }
Example #12
0
 public function get_project_list_by_topic_ids($topic_ids, $order_by = 'add_time DESC', $page = 1, $per_page = 10)
 {
     if (!is_array($topic_ids)) {
         return false;
     }
     array_walk_recursive($topic_ids, 'intval_string');
     $result_cache_key = 'project_list_by_topic_ids_' . implode('_', $topic_ids) . '_' . md5($answer_count . $category_id . $order_by . $is_recommend . $page . $per_page . $post_type);
     $found_rows_cache_key = 'project_list_by_topic_ids_found_rows_' . implode('_', $topic_ids) . '_' . md5($answer_count . $category_id . $is_recommend . $per_page . $post_type);
     $where[] = 'topic_relation.topic_id IN(' . implode(',', $topic_ids) . ')';
     $on_query[] = 'project.id = topic_relation.item_id';
     $on_query[] = "topic_relation.type = 'project'";
     $on_query[] = 'project.approved = 1';
     $on_query[] = "project.status = 'ONLINE'";
     if (!($found_rows = AWS_APP::cache()->get($found_rows_cache_key))) {
         $_found_rows = $this->query_row('SELECT COUNT(DISTINCT project.id) AS count FROM ' . $this->get_table('project') . ' AS project LEFT JOIN ' . $this->get_table('topic_relation') . " AS topic_relation ON " . implode(' AND ', $on_query) . " WHERE " . implode(' AND ', $where));
         $found_rows = $_found_rows['count'];
         AWS_APP::cache()->set($found_rows_cache_key, $found_rows, get_setting('cache_level_high'));
     }
     $this->project_list_total = $found_rows;
     if (!($result = AWS_APP::cache()->get($result_cache_key))) {
         $result = $this->query_all('SELECT project.* FROM ' . $this->get_table('project') . ' AS project LEFT JOIN ' . $this->get_table('topic_relation') . " AS topic_relation ON " . implode(' AND ', $on_query) . " WHERE " . implode(' AND ', $where) . ' GROUP BY project.id ORDER BY project.' . $order_by, calc_page_limit($page, $per_page));
         AWS_APP::cache()->set($result_cache_key, $result, get_setting('cache_level_high'));
     }
     return $result;
 }
Example #13
0
 public function index_square_action()
 {
     if (!$_GET['page']) {
         $_GET['page'] = 1;
     }
     $this->crumb(AWS_APP::lang()->_t('用户列表'), '/people/');
     if ($_GET['topic_id']) {
         if ($helpful_users = $this->model('topic')->get_helpful_users_by_topic_ids($this->model('topic')->get_child_topic_ids($_GET['topic_id']), get_setting('contents_per_page'), 4)) {
             foreach ($helpful_users as $key => $val) {
                 $users_list[$key] = $val['user_info'];
                 $users_list[$key]['experience'] = $val['experience'];
                 foreach ($val['experience'] as $exp_key => $exp_val) {
                     $users_list[$key]['total_agree_count'] += $exp_val['agree_count'];
                 }
             }
         }
     } else {
         $where = array();
         if ($_GET['group_id']) {
             $where[] = 'group_id = ' . intval($_GET['group_id']);
         }
         if ($_GET['sort_type']) {
             switch ($_GET['sort_type']) {
                 case 'passed':
                     $sort_key = 'question_quiz_count_passed DESC';
                     break;
                 case 'poft':
                     $sort_key = 'question_quiz_poft_ratio DESC';
                     break;
                 case 'question_count':
                     $sort_key = 'question_count DESC';
                     break;
                 case 'quiz_count':
                     $sort_key = 'question_quiz_count_total DESC';
                     break;
                 case 'integral':
                     $sort_key = 'integral DESC';
                     break;
                 default:
                     $sort_key = 'question_quiz_success_ratio DESC';
                     break;
             }
         } else {
             $sort_key = 'question_quiz_success_ratio DESC';
         }
         $where[] = 'forbidden = 0 AND group_id >=4 AND group_id < 99';
         $users_list = $this->model('account')->get_users_list(implode('', $where), calc_page_limit($_GET['page'], get_setting('user_rank_list_perpage')), true, false, $sort_key);
         TPL::assign('pagination', AWS_APP::pagination()->initialize(array('base_url' => get_js_url('/people/sort_type-' . $_GET['sort_type'] . '__group_id-' . $_GET['group_id']), 'total_rows' => $this->model('account')->get_user_count(implode(' AND ', $where)), 'per_page' => get_setting('user_rank_list_perpage')))->create_links());
     }
     if ($users_list) {
         foreach ($users_list as $key => $val) {
             if ($val['reputation']) {
                 $reputation_users_ids[] = $val['uid'];
                 $users_reputations[$val['uid']] = $val['reputation'];
             }
             $uids[] = $val['uid'];
         }
         if (!$_GET['topic_id']) {
             $reputation_topics = $this->model('people')->get_users_reputation_topic($reputation_users_ids, $users_reputations, 5);
             foreach ($users_list as $key => $val) {
                 $users_list[$key]['reputation_topics'] = $reputation_topics[$val['uid']];
             }
         }
         if ($uids and $this->user_id) {
             $users_follow_check = $this->model('follow')->users_follow_check($this->user_id, $uids);
             foreach ($users_list as $key => $val) {
                 $users_list[$key]['focus'] = $users_follow_check[$val['uid']];
             }
         }
         TPL::assign('users_list', array_values($users_list));
     }
     if (!$_GET['group_id']) {
         TPL::assign('parent_topics', $this->model('topic')->get_parent_topics());
     }
     TPL::assign('custom_group', $this->model('account')->get_user_group_list(0, 1));
     if ($_GET['sort_type']) {
         TPL::assign('sort_type', $_GET['sort_type']);
     }
     TPL::import_js('js/app/rank.js');
     TPL::output('people/square');
 }
Example #14
0
 public function favorite_action()
 {
     if ($action_list = $this->model('favorite')->get_item_list($_GET['tag'], $this->user_id, calc_page_limit($_GET['page'], get_setting('contents_per_page')))) {
         foreach ($action_list as $key => $val) {
             $item_ids[] = $val['item_id'];
         }
     } else {
         if (!$_GET['page'] or $_GET['page'] == 1) {
             $this->model('favorite')->remove_favorite_tag(null, null, $_GET['tag'], $this->user_id);
         }
     }
     H::ajax_json_output(AWS_APP::RSM(array('total_rows' => count($action_list), 'rows' => $action_list), 1, null));
 }
Example #15
0
 public function message_parser($input_message, $param = null)
 {
     $message_code = strtoupper(trim($input_message['content']));
     if (cjk_strlen($message_code) < 2) {
         return false;
     }
     if (!$param) {
         $param = 1;
     }
     switch ($message_code) {
         default:
             if (cjk_strlen($input_message['content']) > 1 and substr($input_message['content'], 0, 1) == '@') {
                 if ($user_info = $this->model('account')->get_user_info_by_username(substr($input_message['content'], 1), true)) {
                     $response_message[] = array('title' => $user_info['signature'], 'link' => get_js_url('/m/people/' . $user_info['url_token']), 'image_file' => get_avatar_url($user_info['uid'], ''));
                     if ($user_actions = $this->model('actions')->get_user_actions($user_info['uid'], calc_page_limit($param, 4), 101)) {
                         foreach ($user_actions as $key => $val) {
                             $response_message[] = array('title' => $val['question_info']['question_content'], 'link' => get_js_url('/m/question/' . $val['question_info']['question_id']), 'image_file' => get_avatar_url($val['question_info']['published_uid'], 'max'));
                         }
                     }
                 }
             } else {
                 if ($topic_info = $this->model('topic')->get_topic_by_title($input_message['content'])) {
                     $response_message[] = array('title' => $topic_info['topic_title'], 'link' => get_js_url('/m/topic/' . $topic_info['url_token']), 'image_file' => get_topic_pic_url('', $topic_info['topic_pic']));
                     if ($topic_posts = $this->model('posts')->get_posts_list(null, $param, 4, 'new', array($topic_info['topic_id']))) {
                         foreach ($topic_posts as $key => $val) {
                             if ($val['uid']) {
                                 $image_file = get_avatar_url($val['uid'], 'max');
                                 $title = $val['title'];
                                 $link = get_js_url('/m/article/' . $val['id']);
                             } else {
                                 $image_file = get_avatar_url($val['published_uid'], 'max');
                                 $title = $val['question_content'];
                                 $link = get_js_url('/m/question/' . $val['question_id']);
                             }
                             $response_message[] = array('title' => $title, 'link' => $link, 'image_file' => $image_file);
                         }
                     }
                 } else {
                     if ($search_result = $this->model('search')->search_questions($input_message['content'], null, $param, 5)) {
                         foreach ($search_result as $key => $val) {
                             if (!$response_message) {
                                 $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                             } else {
                                 $image_file = get_avatar_url($val['published_uid'], 'max');
                             }
                             $response_message[] = array('title' => $val['question_content'], 'link' => get_js_url('/m/question/' . $val['question_id']), 'image_file' => $image_file);
                         }
                     }
                 }
             }
             break;
         case 'NEW_ARTICLE':
             if ($input_message['param']) {
                 $child_param = explode('_', $input_message['param']);
                 switch ($child_param[0]) {
                     case 'FEATURE':
                         $topic_ids = $this->model('feature')->get_topics_by_feature_id($child_param[1]);
                         break;
                 }
             }
             if ($topic_ids) {
                 $article_list = $this->model('article')->get_articles_list_by_topic_ids($param, 5, 'add_time DESC', $topic_ids);
             } else {
                 $article_list = $this->model('article')->get_articles_list(null, $param, 5, 'add_time DESC');
             }
             foreach ($article_list as $key => $val) {
                 if (!$response_message) {
                     if (!($image_file = $this->get_client_list_image_by_command('COMMAND_' . $message_code))) {
                         $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                     }
                 } else {
                     $image_file = get_avatar_url($val['uid'], 'max');
                 }
                 $response_message[] = array('title' => $val['title'], 'link' => get_js_url('/m/article/' . $val['id']), 'image_file' => $image_file);
             }
             break;
         case 'HOT_QUESTION':
             if ($input_message['param']) {
                 $child_param = explode('_', $input_message['param']);
                 switch ($child_param[0]) {
                     case 'CATEGORY':
                         $category_id = intval($child_param[1]);
                         break;
                     case 'FEATURE':
                         $topic_ids = $this->model('feature')->get_topics_by_feature_id($child_param[1]);
                         break;
                 }
             }
             if ($question_list = $this->model('posts')->get_hot_posts('question', $category_id, $topic_ids, 7, $param, 5)) {
                 foreach ($question_list as $key => $val) {
                     if (!$response_message) {
                         if (!($image_file = $this->get_client_list_image_by_command('COMMAND_' . $message_code))) {
                             $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                         }
                     } else {
                         $image_file = get_avatar_url($val['published_uid'], 'max');
                     }
                     $response_message[] = array('title' => $val['question_content'], 'link' => get_js_url('/m/question/' . $val['question_id']), 'image_file' => $image_file);
                 }
             } else {
                 $response_message = '暂无问题';
             }
             break;
         case 'NEW_QUESTION':
             if ($input_message['param']) {
                 $child_param = explode('_', $input_message['param']);
                 switch ($child_param[0]) {
                     case 'CATEGORY':
                         $category_id = intval($child_param[1]);
                         break;
                     case 'FEATURE':
                         $topic_ids = $this->model('feature')->get_topics_by_feature_id($child_param[1]);
                         break;
                 }
             }
             if ($question_list = $this->model('posts')->get_posts_list('question', $param, 5, 'new', $topic_ids, $category_id)) {
                 foreach ($question_list as $key => $val) {
                     if (!$response_message) {
                         if (!($image_file = $this->get_client_list_image_by_command('COMMAND_' . $message_code))) {
                             $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                         }
                     } else {
                         if ($val['uid']) {
                             $image_file = get_avatar_url($val['uid'], 'max');
                         } else {
                             $image_file = get_avatar_url($val['published_uid'], 'max');
                         }
                     }
                     if ($val['uid']) {
                         $title = $val['title'];
                         $link = get_js_url('/m/article/' . $val['id']);
                     } else {
                         $title = $val['question_content'];
                         $link = get_js_url('/m/question/' . $val['question_id']);
                     }
                     $response_message[] = array('title' => $title, 'link' => $link, 'image_file' => $image_file);
                 }
             } else {
                 $response_message = '暂无问题';
             }
             break;
         case 'NEW_POSTS':
             if ($input_message['param']) {
                 $child_param = explode('_', $input_message['param']);
                 switch ($child_param[0]) {
                     case 'CATEGORY':
                         $category_id = intval($child_param[1]);
                         break;
                     case 'FEATURE':
                         $topic_ids = $this->model('feature')->get_topics_by_feature_id($child_param[1]);
                         break;
                 }
             }
             if ($question_list = $this->model('posts')->get_posts_list(null, $param, 5, 'new', $topic_ids, $category_id)) {
                 foreach ($question_list as $key => $val) {
                     if (!$response_message) {
                         if (!($image_file = $this->get_client_list_image_by_command('COMMAND_' . $message_code))) {
                             $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                         }
                     } else {
                         if ($val['uid']) {
                             $image_file = get_avatar_url($val['uid'], 'max');
                         } else {
                             $image_file = get_avatar_url($val['published_uid'], 'max');
                         }
                     }
                     if ($val['uid']) {
                         $title = $val['title'];
                         $link = get_js_url('/m/article/' . $val['id']);
                     } else {
                         $title = $val['question_content'];
                         $link = get_js_url('/m/question/' . $val['question_id']);
                     }
                     $response_message[] = array('title' => $title, 'link' => $link, 'image_file' => $image_file);
                 }
             } else {
                 $response_message = '暂无内容';
             }
             break;
         case 'NO_ANSWER_QUESTION':
             if ($input_message['param']) {
                 $child_param = explode('_', $input_message['param']);
                 switch ($child_param[0]) {
                     case 'CATEGORY':
                         $category_id = intval($child_param[1]);
                         break;
                     case 'FEATURE':
                         $topic_ids = $this->model('feature')->get_topics_by_feature_id($child_param[1]);
                         break;
                 }
             }
             if ($question_list = $this->model('posts')->get_posts_list('question', $param, 5, 'unresponsive', $topic_ids, $category_id)) {
                 foreach ($question_list as $key => $val) {
                     if (!$response_message) {
                         if (!($image_file = $this->get_client_list_image_by_command('COMMAND_' . $message_code))) {
                             $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                         }
                     } else {
                         if ($val['uid']) {
                             $image_file = get_avatar_url($val['uid'], 'max');
                         } else {
                             $image_file = get_avatar_url($val['published_uid'], 'max');
                         }
                     }
                     if ($val['uid']) {
                         $title = $val['title'];
                         $link = get_js_url('/m/article/' . $val['id']);
                     } else {
                         $title = $val['question_content'];
                         $link = get_js_url('/m/question/' . $val['question_id']);
                     }
                     $response_message[] = array('title' => $title, 'link' => $link, 'image_file' => $image_file);
                 }
             } else {
                 $response_message = '暂无问题';
             }
             break;
         case 'RECOMMEND_QUESTION':
             if ($input_message['param']) {
                 $child_param = explode('_', $input_message['param']);
                 switch ($child_param[0]) {
                     case 'CATEGORY':
                         $category_id = intval($child_param[1]);
                         break;
                     case 'FEATURE':
                         $topic_ids = $this->model('feature')->get_topics_by_feature_id($child_param[1]);
                         break;
                 }
             }
             if ($question_list = $this->model('posts')->get_posts_list('question', $param, 5, null, $topic_ids, $category_id, null, null, true)) {
                 foreach ($question_list as $key => $val) {
                     if (!$response_message) {
                         if (!($image_file = $this->get_client_list_image_by_command('COMMAND_' . $message_code))) {
                             $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                         }
                     } else {
                         if ($val['uid']) {
                             $image_file = get_avatar_url($val['uid'], 'max');
                         } else {
                             $image_file = get_avatar_url($val['published_uid'], 'max');
                         }
                     }
                     if ($val['uid']) {
                         $title = $val['title'];
                         $link = get_js_url('/m/article/' . $val['id']);
                     } else {
                         $title = $val['question_content'];
                         $link = get_js_url('/m/question/' . $val['question_id']);
                     }
                     $response_message[] = array('title' => $title, 'link' => $link, 'image_file' => $image_file);
                 }
             } else {
                 $response_message = '暂无问题';
             }
             break;
         case 'HOME_ACTIONS':
             if ($this->user_id) {
                 if ($home_actions = $this->model('actions')->home_activity($this->user_id, calc_page_limit($param, 5))) {
                     foreach ($home_actions as $key => $val) {
                         if (!$response_message) {
                             if (!($image_file = $this->get_client_list_image_by_command('COMMAND_' . $message_code))) {
                                 $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                             }
                         } else {
                             $image_file = get_avatar_url($val['user_info']['uid'], 'max');
                         }
                         if ($val['associate_action'] == ACTION_LOG::ANSWER_QUESTION or $val['associate_action'] == ACTION_LOG::ADD_AGREE) {
                             $link = get_js_url('/m/question/' . $val['question_info']['question_id'] . '?answer_id=' . $val['answer_info']['answer_id'] . '&single=TRUE');
                         } else {
                             $link = $val['link'];
                         }
                         $response_message[] = array('title' => $val['title'], 'link' => $link, 'image_file' => $image_file);
                     }
                 } else {
                     $response_message = '暂时没有最新动态';
                 }
             } else {
                 $response_message = $this->bind_message;
             }
             break;
         case 'NOTIFICATIONS':
             if ($this->user_id) {
                 if ($notifications = $this->model('notify')->list_notification($this->user_id, 0, calc_page_limit($param, 5))) {
                     $response_message = '最新通知:';
                     foreach ($notifications as $key => $val) {
                         $response_message .= "\n\n• " . $val['message'];
                     }
                     $response_message .= "\n\n请输入 '更多' 显示其他相关内容";
                 } else {
                     $this->delete('weixin_message', "weixin_id = '" . $this->quote($input_message['fromUsername']) . "'");
                     if ($param > 1) {
                         $response_message = '没有更多新通知了';
                     } else {
                         $response_message = '暂时没有新通知';
                     }
                 }
             } else {
                 $response_message = $this->bind_message;
             }
             break;
         case 'MY_QUESTION':
             if ($this->user_id) {
                 if ($user_actions = $this->model('actions')->get_user_actions($this->user_id, calc_page_limit($param, 5), 101)) {
                     foreach ($user_actions as $key => $val) {
                         if (!$response_message) {
                             if (!($image_file = $this->get_client_list_image_by_command('COMMAND_' . $message_code))) {
                                 $image_file = AWS_APP::config()->get('weixin')->default_list_image;
                             }
                         } else {
                             $image_file = get_avatar_url($val['question_info']['published_uid'], 'max');
                         }
                         $response_message[] = array('title' => $val['question_info']['question_content'], 'link' => get_js_url('/m/question/' . $val['question_info']['question_id']), 'image_file' => $image_file);
                     }
                 } else {
                     $this->delete('weixin_message', "weixin_id = '" . $this->quote($input_message['fromUsername']) . "'");
                     if ($param > 1) {
                         $response_message = '没有更多提问了';
                     } else {
                         $response_message = '你还没有进行提问';
                     }
                 }
             } else {
                 $response_message = $this->bind_message;
             }
             break;
     }
     if (!$response_message) {
         return false;
     }
     return array('message' => $response_message, 'action' => $message_code . '-' . ($param + 1));
 }
Example #16
0
 public function index_square_action()
 {
     $per_page = 18;
     // 今日话题
     if ($today_topic = $this->model('topic')->get_topic_by_title(array_random(explode(',', $today_topics)))) {
         $today_topic['best_answer_users'] = $this->model('topic')->get_best_answer_users_by_topic_id($today_topic['topic_id'], 5);
         $today_topic['questions_list'] = $this->model('posts')->get_posts_list('question', 1, 3, 'new', explode(',', $today_topic['topic_id']));
     }
     TPL::assign('today_topic', $today_topic);
     // 专题列表
     switch ($_GET['channel']) {
         case 'focus':
             if ($topics_list = $this->model('topic')->get_focus_topic_list($this->user_id, calc_page_limit($_GET['page'], $per_page))) {
                 $topics_list_total_rows = $this->user_info['topic_focus_count'];
             }
             break;
         default:
         case 'hot':
             switch ($_GET['day']) {
                 case 'month':
                     $order = 'discuss_count_last_month DESC';
                     break;
                 case 'week':
                     $order = 'discuss_count_last_week DESC';
                     break;
                 default:
                     $order = 'discuss_count DESC';
                     break;
             }
             $topics_list = $this->model('topic')->get_child_topic_list(null, $order, $per_page, $_GET['page']);
             $topics_list_total_rows = $this->model('topic')->found_rows();
             break;
         case 'topic':
             $topic_ids[] = intval($_GET['topic_id']);
             if ($child_topic_ids = $this->model('topic')->get_child_topic_ids($_GET['topic_id'])) {
                 $topic_ids = array_merge($child_topic_ids, $topic_ids);
             }
             if ($topics_list = $this->model('topic')->get_child_topic_list('topic_id IN(' . implode(',', $topic_ids) . ') AND merged_id = 0', 'discuss_count DESC', $per_page, $_GET['page'])) {
                 $topics_list_total_rows = $this->model('topic')->found_rows();
             }
             break;
     }
     # get topic foucs info
     foreach ($topics_list as $key => $value) {
         $topics_list[$key]['has_focus'] = $this->model('topic')->has_focus_topic($this->user_id, $value['topic_id']);
     }
     TPL::assign('topics_list', $topics_list);
     TPL::assign('parent_topics', $this->model('topic')->get_parent_topics());
     TPL::assign('pagination', AWS_APP::pagination()->initialize(array('base_url' => get_js_url('/topic/channel-' . $_GET['channel'] . '__topic_id-' . $_GET['topic_id'] . '__day-' . $_GET['day']), 'total_rows' => $topics_list_total_rows, 'per_page' => $per_page))->create_links());
     $this->crumb(AWS_APP::lang()->_t('专题'), '/topic/');
     TPL::output('topic/square');
 }
 public function get_favor_tag_action()
 {
     $user_favor_tags = $this->model('favorite')->get_favorite_tags($_GET['user_id']);
     foreach ($user_favor_tags as $key => $val) {
         $user_favor_tags[$key]['is_aready_add'] = 0;
         if ($action_list = $this->model('favorite')->get_item_list($val['title'], $_GET['user_id'], calc_page_limit($_GET['page'], get_setting('contents_per_page')))) {
             foreach ($action_list as $key1 => $val2) {
                 $item_ids[] = $val2['item_id'];
             }
             foreach ($action_list as $key3 => $val3) {
                 if ($val3['item_id'] == $_GET['answer_id']) {
                     $user_favor_tags[$key]['is_aready_add'] = 1;
                     break;
                 }
             }
             $user_favor_tags[$key]['favor_item'] = $action_list;
             $user_favor_tags[$key]['favor_item_count'] = sizeof($action_list);
             // TPL::assign('list', $action_list);
         } else {
             if (!$_GET['page'] or $_GET['page'] == 1) {
                 //	$this->model('favorite')->remove_favorite_tag(null, null, $_GET['tag'], $this->user_id);
                 $user_favor_tags[$key]['favor_item_count'] = 0;
                 $this->model('favorite')->remove_favorite_tag(null, null, $_GET['tag'], $_GET['user_id']);
             }
         }
     }
     echo json_encode($array = array("value" => $user_favor_tags));
 }