コード例 #1
0
ファイル: ajax.php プロジェクト: Gradven/what3.1.7
 public function topic_info_action()
 {
     $topic_info = $this->model('topic')->get_topic_by_id($_GET['topic_id']);
     $topic_info['type'] = 'topic';
     $topic_info['topic_description'] = cjk_substr(strip_tags($topic_info['topic_description']), 0, 80, 'UTF-8', '...');
     $topic_info['focus_count'] = $topic_info['focus_count'];
     if ($this->user_id) {
         $topic_info['focus'] = $this->model('topic')->has_focus_topic($this->user_id, $topic_info['topic_id']);
     }
     $topic_info['topic_pic'] = get_topic_pic_url('mid', $topic_info['topic_pic']);
     $topic_info['url'] = get_js_url('/topic/' . $topic_info['url_token']);
     H::ajax_json_output($topic_info);
 }
コード例 #2
0
ファイル: weixin.php プロジェクト: Gradven/what3.1.7
 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));
 }
コード例 #3
0
 public function prase_result_info($result_info)
 {
     if (isset($result_info['last_login'])) {
         $result_type = 'users';
         $search_id = $result_info['uid'];
         $user_info = $this->model('account')->get_user_info_by_uid($result_info['uid'], true);
         $name = $user_info['user_name'];
         $url = get_js_url('/people/' . $user_info['url_token']);
         $detail = array('avatar_file' => get_avatar_url($user_info['uid'], 'mid'), 'signature' => $user_info['signature'], 'reputation' => $user_info['reputation'], 'agree_count' => $user_info['agree_count'], 'thanks_count' => $user_info['thanks_count'], 'fans_count' => $user_info['fans_count']);
     } else {
         if ($result_info['topic_id']) {
             $result_type = 'topics';
             $search_id = $result_info['topic_id'];
             $url = get_js_url('/topic/' . $result_info['url_token']);
             $name = $result_info['topic_title'];
             $detail = array('topic_pic' => get_topic_pic_url('mid', $result_info['topic_pic']), 'topic_id' => $result_info['topic_id'], 'focus_count' => $result_info['focus_count'], 'discuss_count' => $result_info['discuss_count'], 'topic_description' => $result_info['topic_description']);
         } else {
             if ($result_info['question_id']) {
                 $result_type = 'questions';
                 $search_id = $result_info['question_id'];
                 $url = get_js_url('/question/' . $result_info['question_id']);
                 $name = $result_info['question_content'];
                 $detail = array('best_answer' => $result_info['best_answer'], 'answer_count' => $result_info['answer_count'], 'comment_count' => $result_info['comment_count'], 'focus_count' => $result_info['focus_count'], 'agree_count' => $result_info['agree_count']);
             } else {
                 if ($result_info['id']) {
                     $result_type = 'articles';
                     $search_id = $result_info['id'];
                     $url = get_js_url('/article/' . $result_info['id']);
                     $name = $result_info['title'];
                     $detail = array('comments' => $result_info['comments'], 'views' => $result_info['views']);
                 }
             }
         }
     }
     if ($result_type) {
         return array('uid' => $result_info['uid'], 'score' => $result_info['score'], 'type' => $result_type, 'url' => $url, 'search_id' => $search_id, 'name' => $name, 'detail' => $detail);
     }
 }