public function index_action() { $_GET['per_page'] = $_GET['per_page'] ? intval($_GET['per_page']) : get_setting('contents_per_page'); $result = $this->model('search')->search(cjk_substr($_GET['q'], 0, 64), $_GET['type'], $_GET['page'], $_GET['per_page'], $_GET['topic_ids'], $_GET['is_recommend']); if (!$result) { $result = array(); } if ($_GET['is_question_id'] and is_digits($_GET['q'])) { $question_info = $this->model('question')->get_question_info_by_id($_GET['q']); if ($question_info) { $result[] = $this->model('search')->prase_result_info($question_info); } } if ($result) { $key_arr = array('type', 'search_id', 'name', 'detail'); foreach ($result as $key => $val) { foreach ($val as $k => $v) { if (!in_array($k, $key_arr)) { unset($result[$key][$k]); } } } } H::ajax_json_output(AWS_APP::RSM(array('total_rows' => count($result), 'rows' => $result), 1, null)); }
function refresh_access_token($id, $sina_token) { if (!is_digits($id) or empty($sina_token['access_token'])) { return false; } return $this->update('users_sina', array('access_token' => $sina_token['access_token'], 'expires_time' => time() + $sina_token['expires_in']), 'id = ' . $id); }
public function set_slide_sort($id, $order) { if (!is_digits($id) or !is_digits($order) or $order < 0 or $order > 99) { return false; } return $this->update('slide', array('order' => intval($order)), 'id = ' . intval($id)); }
public function index_action() { if (is_digits($_GET['id'])) { $feature_info = $this->model('feature')->get_feature_by_id($_GET['id']); } else { $feature_info = $this->model('feature')->get_feature_by_url_token($_GET['id']); } if (!$feature_info) { header('HTTP/1.1 404 Not Found'); H::redirect_msg(AWS_APP::lang()->_t('专题不存在'), '/'); } if (!$feature_info['enabled']) { H::redirect_msg(AWS_APP::lang()->_t('专题未启用'), '/'); } if ($feature_info['url_token'] != $_GET['id'] and !$_GET['sort_type'] and !$_GET['is_recommend']) { HTTP::redirect('/feature/' . $feature_info['url_token']); } if (!($topic_list = $this->model('topic')->get_topics_by_ids($this->model('feature')->get_topics_by_feature_id($feature_info['id'])))) { H::redirect_msg(AWS_APP::lang()->_t('专题下必须包含一个以上话题'), '/'); } if ($feature_info['seo_title']) { TPL::assign('page_title', $feature_info['seo_title']); } else { $this->crumb($feature_info['title'], '/feature/' . $feature_info['url_token']); } TPL::assign('sidebar_hot_topics', $topic_list); TPL::assign('feature_info', $feature_info); TPL::import_js('js/app/feature.js'); TPL::output('feature/detail'); }
public function index_action() { if (isset($_GET['notification_id'])) { $this->model('notify')->read_notification($_GET['notification_id'], $this->user_id); } if (is_mobile()) { HTTP::redirect('/m/people/' . $_GET['id']); } if (is_digits($_GET['id'])) { if (!($user = $this->model('account')->get_user_info_by_uid($_GET['id'], TRUE))) { $user = $this->model('account')->get_user_info_by_username($_GET['id'], TRUE); } } else { if ($user = $this->model('account')->get_user_info_by_username($_GET['id'], TRUE)) { } else { $user = $this->model('account')->get_user_info_by_url_token($_GET['id'], TRUE); } } if (!$user) { header('HTTP/1.1 404 Not Found'); H::redirect_msg(AWS_APP::lang()->_t('用户不存在'), '/'); } if ($user['forbidden'] and !$this->user_info['permission']['is_administortar'] and !$this->user_info['permission']['is_moderator']) { header('HTTP/1.1 404 Not Found'); H::redirect_msg(AWS_APP::lang()->_t('该用户已被封禁'), '/'); } if (urldecode($user['url_token']) != $_GET['id']) { HTTP::redirect('/people/' . $user['url_token']); } $this->model('people')->update_views($user['uid']); TPL::assign('user', $user); $job_info = $this->model('account')->get_jobs_by_id($user['job_id']); TPL::assign('job_name', $job_info['job_name']); if ($user['weibo_visit']) { if ($users_sina = $this->model('openid_weibo_oauth')->get_weibo_user_by_uid($user['uid'])) { TPL::assign('sina_weibo_url', 'http://www.weibo.com/' . $users_sina['id']); } } TPL::assign('education_experience_list', $this->model('education')->get_education_experience_list($user['uid'])); $jobs_list = $this->model('work')->get_jobs_list(); if ($work_experience_list = $this->model('work')->get_work_experience_list($user['uid'])) { foreach ($work_experience_list as $key => $val) { $work_experience_list[$key]['job_name'] = $jobs_list[$val['job_id']]; } } TPL::assign('work_experience_list', $work_experience_list); TPL::assign('user_follow_check', $this->model('follow')->user_follow_check($this->user_id, $user['uid'])); $this->crumb(AWS_APP::lang()->_t('%s 的个人主页', $user['user_name']), 'people/' . $user['url_token']); TPL::import_css('css/user.css'); TPL::assign('reputation_topics', $this->model('people')->get_user_reputation_topic($user['uid'], $user['reputation'], 12)); TPL::assign('fans_list', $this->model('follow')->get_user_fans($user['uid'], 5)); TPL::assign('friends_list', $this->model('follow')->get_user_friends($user['uid'], 5)); TPL::assign('focus_topics', $this->model('topic')->get_focus_topic_list($user['uid'], 10)); TPL::assign('user_actions_questions', $this->model('actions')->get_user_actions($user['uid'], 5, ACTION_LOG::ADD_QUESTION, $this->user_id)); TPL::assign('user_actions_answers', $this->model('actions')->get_user_actions($user['uid'], 5, ACTION_LOG::ANSWER_QUESTION, $this->user_id)); TPL::assign('user_actions', $this->model('actions')->get_user_actions($user['uid'], 5, implode(',', array(ACTION_LOG::ADD_QUESTION, ACTION_LOG::ANSWER_QUESTION, ACTION_LOG::ADD_REQUESTION_FOCUS, ACTION_LOG::ADD_AGREE, ACTION_LOG::ADD_TOPIC, ACTION_LOG::ADD_TOPIC_FOCUS, ACTION_LOG::ADD_ARTICLE)), $this->user_id)); TPL::output('people/index'); }
public function send($email, $subject, $message, $link = null, $link_title = null, $server = 'master') { if (is_digits($email)) { if (!($user_info = $this->model('account')->get_user_info_by_uid($email))) { return false; } $user_name = $user_info['user_name']; $email = $user_info['email']; } return AWS_APP::mail()->send($email, $subject, $this->get_mail_template($user_name, $subject, $message, $link, $link_title), get_setting('site_name'), $user_name, $server); }
public function get_article_info_by_id($article_id) { if (!is_digits($article_id)) { return false; } static $articles; if (!$articles[$article_id]) { $articles[$article_id] = $this->fetch_row('article', 'id = ' . $article_id); } return $articles[$article_id]; }
function get_joined_digits(&$v, &$ids) { $ids = explode(',', $v); if (count($ids) === 0) { return false; } foreach ($ids as $id) { if (!is_digits($id)) { return false; } } return true; }
public function search_action() { $result = $this->model('search')->search(cjk_substr($_GET['q'], 0, 64), $_GET['type'], 1, $_GET['limit'], $_GET['topic_ids'], $_GET['is_recommend']); if (!$result) { $result = array(); } if ($_GET['is_question_id'] and is_digits($_GET['q'])) { $question_info = $this->model('question')->get_question_info_by_id($_GET['q']); if ($question_info) { $result[] = $this->model('search')->prase_result_info($question_info); } } H::ajax_json_output($result); }
function list_users(&$msg, &$data) { get_user_data_modal($user_modal); $user_id = P('id'); $options = array('data modal' => $user_modal, 'left join' => array(array('qwp_role', 'r', 'r.id=u.role')), 'where' => 'u.id<>1 and role<>1'); if ($user_id) { $data = array(); if ($user_id != '1' && is_digits($user_id)) { $options['where'] .= ' and u.id=' . $user_id; qwp_db_get_data(array('qwp_user', 'u'), $data, null, $options); } } else { $options['default order'] = array('role', array('id', 'desc')); $options['search condition'] = array('condition' => array('fields' => array('u.name' => 'like', 'avatar' => 'set_avatar_condition', 'gender' => array('s' => array('<>', 'x'))), 'condition' => array('op' => 'or', 'fields' => array('phone' => 'like', 'account' => 'like', 'email' => 'like', 'name' => 'like')))); $options['search converter'] = 'convert_search_data'; qwp_db_retrieve_data(array('qwp_user', 'u'), $data, $options); } }
public static function save_action($uid, $associate_id, $action_type, $action_id, $action_content = null, $action_attch = null, $add_time = null, $anonymous = null, $addon_data = null) { if (!$uid or !$associate_id) { return false; } if (is_digits($action_attch)) { $action_attch_insert = $action_attch; } else { $action_attch_insert = '-1'; $action_attch_update = $action_attch; } if (!$add_time) { $add_time = time(); } $history_id = AWS_APP::model()->insert('user_action_history', array('uid' => intval($uid), 'associate_type' => $action_type, 'associate_action' => $action_id, 'associate_id' => $associate_id, 'associate_attached' => $action_attch_insert, 'add_time' => $add_time, 'anonymous' => intval($anonymous))); AWS_APP::model()->insert('user_action_history_data', array('history_id' => $history_id, 'associate_content' => htmlspecialchars($action_content), 'associate_attached' => htmlspecialchars($action_attch_update), 'addon_data' => $addon_data ? serialize($addon_data) : '')); self::associate_fresh_action($history_id, $associate_id, $action_type, $action_id, $uid, $anonymous, $add_time); return $history_id; }
public function update_third_party_login($id = null, $action, $name, $url, $token, $enabled = null, $account_id = null, $rank = null) { if ($action == 'update' and !is_digits($id) or $action == 'add' and !is_digits($account_id)) { return false; } $to_save_rule = array(); if ($name) { $to_save_rule['name'] = $name; } if ($url) { $to_save_rule['url'] = $url; } if ($token) { $to_save_rule['token'] = $token; } if ($enabled !== null) { if ($enabled == 1) { $to_save_rule['enabled'] = '1'; } else { $to_save_rule['enabled'] = '0'; } } if (is_digits($account_id)) { $to_save_rule['account_id'] = $account_id; } if (is_digits($rank) and $rank >= 0 and $rank <= 99) { $to_save_rule['rank'] = $rank; } switch ($action) { case 'add': return $this->insert('weixin_third_party_login', $to_save_rule); break; case 'update': return $this->update('weixin_third_party_login', $to_save_rule, 'id = ' . $id); break; default: return false; break; } }
/** * * 增加问题内容 * @param string $question_content //问题内容 * @param string $question_detail //问题说明 * * @return boolean true|false */ public function save_question($question_content, $question_detail, $published_uid, $question_difficulty, $quiz_id, $anonymous = 0, $ip_address = null, $from = null) { if (!$ip_address) { $ip_address = fetch_ip(); } $now = time(); $to_save_question = array('question_content' => htmlspecialchars($question_content), 'question_detail' => htmlspecialchars($question_detail), 'add_time' => $now, 'update_time' => $now, 'published_uid' => intval($published_uid), 'difficulty' => intval($question_difficulty), 'quiz_id' => intval($quiz_id), 'anonymous' => intval($anonymous), 'ip' => ip2long($ip_address)); if ($from and is_array($from)) { foreach ($from as $type => $from_id) { if (!is_digits($from_id)) { continue; } $to_save_question[$type . '_id'] = $from_id; } } $question_id = $this->insert('question', $to_save_question); if ($question_id) { $this->shutdown_update('users', array('question_count' => $this->count('question', 'published_uid = ' . intval($published_uid))), 'uid = ' . intval($published_uid)); $this->model('search_fulltext')->push_index('question', $question_content, $question_id); } return $question_id; }
function remove_assoc($from, $type, $id) { if (!$from or !$type or !is_digits($id)) { return false; } return $this->query('UPDATE ' . $this->get_table($from) . ' SET `' . $type . '_id` = NULL WHERE `' . $type . '_id` = ' . $id); }
public function check_username_char($user_name) { if (is_digits($user_name)) { return AWS_APP::lang()->_t('用户名不能为纯数字'); } if (strstr($user_name, '-')) { return AWS_APP::lang()->_t('用户名不能包含 -'); } $length = strlen(convert_encoding($user_name, 'UTF-8', 'GB2312')); $length_min = intval(get_setting('username_length_min')); $length_max = intval(get_setting('username_length_max')); if ($length < $length_min || $length > $length_max) { $flag = true; } switch (get_setting('username_rule')) { default: break; case 1: if (!preg_match('/^[\\x{4e00}-\\x{9fa5}_a-zA-Z0-9]+$/u', $user_name) or $flag) { return AWS_APP::lang()->_t('请输入大于 %s 字节的用户名, 允许汉字、字母与数字', $length_min . ' - ' . $length_max); } break; case 2: if (!preg_match("/^[a-zA-Z0-9_]+\$/i", $user_name) or $flag) { return AWS_APP::lang()->_t('请输入 %s 个字母、数字或下划线', $length_min . ' - ' . $length_max); } break; case 3: if (!preg_match("/^[\\x{4e00}-\\x{9fa5}]+\$/u", $user_name) or $flag) { return AWS_APP::lang()->_t('请输入 %s 个汉字', ceil($length_min / 2) . ' - ' . floor($length_max / 2)); } break; } return false; }
public function index_square_action() { $this->crumb(AWS_APP::lang()->_t('问题'), '/question/'); // 导航 if (TPL::is_output('block/content_nav_menu.tpl.htm', 'question/square')) { TPL::assign('content_nav_menu', $this->model('menu')->get_nav_menu_list('question')); } //边栏可能感兴趣的人 if (TPL::is_output('block/sidebar_recommend_users_topics.tpl.htm', 'question/square')) { TPL::assign('sidebar_recommend_users_topics', $this->model('module')->recommend_users_topics($this->user_id)); } //边栏热门用户 if (TPL::is_output('block/sidebar_hot_users.tpl.htm', 'question/square')) { TPL::assign('sidebar_hot_users', $this->model('module')->sidebar_hot_users($this->user_id, 5)); } //边栏热门话题 if (TPL::is_output('block/sidebar_hot_topics.tpl.htm', 'question/square')) { TPL::assign('sidebar_hot_topics', $this->model('module')->sidebar_hot_topics($_GET['category'])); } //边栏专题 if (TPL::is_output('block/sidebar_feature.tpl.htm', 'question/square')) { TPL::assign('feature_list', $this->model('module')->feature_list()); } if ($_GET['category']) { if (is_digits($_GET['category'])) { $category_info = $this->model('system')->get_category_info($_GET['category']); } else { $category_info = $this->model('system')->get_category_info_by_url_token($_GET['category']); } } if ($category_info) { TPL::assign('category_info', $category_info); $this->crumb($category_info['title'], '/question/category-' . $category_info['id']); $meta_description = $category_info['title']; if ($category_info['description']) { $meta_description .= ' - ' . $category_info['description']; } TPL::set_meta('description', $meta_description); } if ($_GET['feature_id']) { $feature_info = $this->model('feature')->get_feature_by_id($_GET['feature_id']); TPL::assign('feature_info', $feature_info); } if ($feature_info['id']) { $topic_ids = $this->model('feature')->get_topics_by_feature_id($feature_info['id']); } if (!$_GET['sort_type']) { $_GET['sort_type'] = 'new'; } if ($_GET['sort_type'] == 'hot') { $question_list = $this->model('posts')->get_hot_posts('question', $category_info['id'], $topic_ids, $_GET['day'], $_GET['page'], get_setting('contents_per_page')); } else { $question_list = $this->model('posts')->get_posts_list('question', $_GET['page'], get_setting('contents_per_page'), $_GET['sort_type'], $topic_ids, $category_info['id'], $_GET['answer_count'], $_GET['day'], $_GET['is_recommend']); } if ($question_list) { foreach ($question_list as $key => $val) { if ($val['answer_count']) { $question_list[$key]['answer_users'] = $this->model('question')->get_answer_users_by_question_id($val['question_id'], 2, $val['published_uid']); } } } TPL::assign('pagination', AWS_APP::pagination()->initialize(array('base_url' => get_js_url('/question/sort_type-' . preg_replace("/[\\(\\)\\.;']/", '', $_GET['sort_type']) . '__category-' . $category_info['id'] . '__day-' . intval($_GET['day']) . '__is_recommend-' . $_GET['is_recommend']) . '__feature_id-' . $feature_info['id'], 'total_rows' => $this->model('posts')->get_posts_list_total(), 'per_page' => get_setting('contents_per_page')))->create_links()); TPL::assign('posts_list', $question_list); TPL::assign('question_list_bit', TPL::output('explore/ajax/list', false)); TPL::output('question/square'); }
public function topic_action() { if (is_digits($_GET['id'])) { if (!($topic_info = $this->model('topic')->get_topic_by_id($_GET['id']))) { $topic_info = $this->model('topic')->get_topic_by_title($_GET['id']); } } else { if (!($topic_info = $this->model('topic')->get_topic_by_title($_GET['id']))) { $topic_info = $this->model('topic')->get_topic_by_url_token($_GET['id']); } } if (!$topic_info) { H::redirect_msg(AWS_APP::lang()->_t('话题不存在'), '/m/'); } if ($topic_info['merged_id']) { if ($this->model('topic')->get_topic_by_id($topic_info['merged_id'])) { HTTP::redirect('/m/topic/' . $topic_info['merged_id'] . '?rf=' . $topic_info['topic_id']); } else { $this->model('topic')->remove_merge_topic($topic_info['topic_id'], $topic_info['merged_id']); } } if (urldecode($topic_info['url_token']) != $_GET['id']) { HTTP::redirect('/m/topic/' . $topic_info['url_token'] . '?rf=' . $_GET['rf']); } if (is_digits($_GET['rf']) and $_GET['rf']) { if ($from_topic = $this->model('topic')->get_topic_by_id($_GET['rf'])) { $redirect_message[] = AWS_APP::lang()->_t('话题 (%s) 已与当前话题合并', $from_topic['topic_title']); } } if ($merged_topics = $this->model('topic')->get_merged_topic_ids($topic_info['topic_id'])) { foreach ($merged_topics as $key => $val) { $merged_topic_ids[] = $val['source_id']; } $contents_topic_id = $topic_info['topic_id'] . ',' . implode(',', $merged_topic_ids); if ($merged_topics_info = $this->model('topic')->get_topics_by_ids($merged_topic_ids)) { foreach ($merged_topics_info as $key => $val) { $contents_topic_title[] = $val['topic_title']; } } $contents_topic_title = $topic_info['topic_title'] . ',' . implode(',', $contents_topic_title); } else { $contents_topic_id = $topic_info['topic_id']; $contents_topic_title = $topic_info['topic_title']; } TPL::assign('contents_topic_id', $contents_topic_id); TPL::assign('contents_topic_title', $contents_topic_title); if ($this->user_id) { $topic_info['has_focus'] = $this->model('topic')->has_focus_topic($this->user_id, $topic_info['topic_id']); } TPL::assign('topic_info', $topic_info); $this->crumb(AWS_APP::lang()->_t('话题'), '/m/topic/'); $this->crumb($topic_info['topic_title'], '/m/topic/' . $topic_info['topic_title']); TPL::assign('redirect_message', $redirect_message); TPL::assign('best_answer_users', $this->model('topic')->get_best_answer_users_by_topic_id($topic_info['topic_id'], 5)); TPL::output('m/topic'); }
<?php if (!defined('IN_ANWSION')) { die; } if (!is_digits($_GET['page'])) { $_GET['page'] = 1; } $user_list = $this->model('account')->fetch_page('users', null, 'uid ASC', $_GET['page'], 300); if ($user_list) { foreach ($user_list as $user_info) { $article_count = $this->model('article')->count('article', 'uid = ' . $user_info['uid']); $this->model('account')->update('users', array('article_count' => $article_count), 'uid = ' . $user_info['uid']); } H::redirect_msg(AWS_APP::lang()->_t('正在升级数据库') . ', ' . AWS_APP::lang()->_t('批次: %s', $_GET['page']), '/upgrade/script/page-' . ($_GET['page'] + 1)); }
public function update_receiving_email_config($id = null, $action, $receiving_email_config = array()) { if ($action == 'update' and !is_digits($id)) { return false; } switch ($action) { case 'add': return $this->insert('receiving_email_config', $receiving_email_config); break; case 'update': return $this->update('receiving_email_config', $receiving_email_config, 'id = ' . $id); break; default: return false; break; } }
public function remove_weixin_account($account_id) { if (!is_digits($account_id) or $account_id === 0 or $account_id === '0') { return false; } $this->delete('weixin_accounts', 'id = ' . $account_id); $reply_rules_info = $this->fetch_all('weixin_reply_rule', 'account_id = ' . $account_id); if ($reply_rules_info) { $this->delete('weixin_reply_rule', 'account_id = ' . $account_id); foreach ($reply_rules_info as $reply_rule_info) { if ($reply_rule_info['image_file']) { unlink(get_setting('upload_dir') . '/weixin/' . $reply_rule_info['image_file']); unlink(get_setting('upload_dir') . '/weixin/square_' . $reply_rule_info['image_file']); } } } $this->model('openid_weixin_third')->remove_third_party_api_by_account_id($account_id); }
/** * 检查字符串或数组内的字符串是否为纯数字(十进制数字,不包括负数和小数) * * @param string or array * @return boolean */ function is_digits($num) { if (!$num and $num !== '0') { return false; } if (is_array($num)) { foreach ($num as $val) { if (!is_digits($val)) { return false; } } return true; } return Zend_Validate::is($num, 'Digits'); }
public function update_attach($weibo_msg_id, $item_type, $item_id, $attach_access_key) { if (!is_digits($weibo_msg_id) or !is_digits($item_id) or !$attach_access_key) { return false; } $update_result = $this->update('attach', array('item_type' => $item_type, 'item_id' => $item_id), 'item_type = "weibo_msg" AND item_id = ' . $weibo_msg_id . ' AND access_key = "' . $this->quote($attach_access_key) . '"'); $this->shutdown_update($item_type, array('has_attach' => 1), $item_type . '_id = ' . $item_id); return $update_result; }
public function get_facebook_user_by_uid($uid) { if (!is_digits($uid)) { return false; } static $facebook_user_info; if (!$facebook_user_info[$uid]) { $facebook_user_info[$uid] = $this->fetch_row('users_facebook', 'uid = ' . $uid); } return $facebook_user_info[$uid]; }
public function get_google_user_by_uid($uid) { if (!is_digits($uid)) { return false; } static $google_user_info; if (!$google_user_info[$uid]) { $google_user_info[$uid] = $this->fetch_row('users_google', 'uid = ' . $uid); } return $google_user_info[$uid]; }
/** * * 阅读段信息 * @param int $notification_id 信息id * * @return array信息内容数组 */ public function read_notification($notification_id, $uid = null) { $notification_ids = explode(',', $notification_id); array_walk_recursive($notification_ids, 'intval_string'); if (count($notification_ids) == 1 and intval($notification_id) > 0) { $notify_info = $this->get_notification_by_id($notification_id, $uid); $unread_notifys = $this->get_unread_notification($uid); if (!$notify_info or !$unread_notifys) { return false; } $unread_extends = array(); foreach ($unread_notifys as $key => $val) { $unread_extends[$val['model_type']][$val['source_id']][] = $val; } $notifications = $unread_extends[$notify_info['model_type']][$notify_info['source_id']]; $notification_ids = array(); if (!$notifications) { $notification_ids[] = $notification_id; } else { foreach ($notifications as $key => $val) { $notification_ids[] = $val['notification_id']; } } } if ($notification_ids) { foreach ($notification_ids as $key => $val) { if (!is_digits($val)) { return false; } $notification_ids[$key] = intval($val); } $this->update('notification', array('read_flag' => 1), 'recipient_uid = ' . intval($uid) . ' AND notification_id IN (' . implode(',', $notification_ids) . ')'); $this->model('account')->update_notification_unread($uid); return true; } }
public function get_posts_list_by_topic_ids($post_type, $topic_type, $topic_ids, $category_id = null, $answer_count = null, $order_by = 'post_id DESC', $is_recommend = false, $page = 1, $per_page = 10) { if (!is_array($topic_ids)) { return false; } array_walk_recursive($topic_ids, 'intval_string'); $result_cache_key = 'posts_list_by_topic_ids_' . md5(implode(',', $topic_ids) . $answer_count . $category_id . $order_by . $is_recommend . $page . $per_page . $post_type . $topic_type); $found_rows_cache_key = 'posts_list_by_topic_ids_found_rows_' . md5(implode(',', $topic_ids) . $answer_count . $category_id . $is_recommend . $per_page . $post_type . $topic_type); $topic_relation_where[] = '`topic_id` IN(' . implode(',', $topic_ids) . ')'; if ($topic_type) { $topic_relation_where[] = "`type` = '" . $this->quote($topic_type) . "'"; } if ($topic_relation_query = $this->query_all("SELECT `item_id`, `type` FROM " . get_table('topic_relation') . " WHERE " . implode(' AND ', $topic_relation_where))) { foreach ($topic_relation_query as $key => $val) { $post_ids[$val['type']][$val['item_id']] = $val['item_id']; } } if (!$post_ids) { return false; } foreach ($post_ids as $key => $val) { $post_id_where[] = "(post_id IN (" . implode(',', $val) . ") AND post_type = '" . $this->quote($key) . "')"; } if ($post_id_where) { $where[] = '(' . implode(' OR ', $post_id_where) . ')'; } if (is_digits($answer_count)) { if ($answer_count == 0) { $where[] = "answer_count = " . $answer_count; } else { if ($answer_count > 0) { $where[] = "answer_count >= " . $answer_count; } } } if ($is_recommend) { $where[] = 'is_recommend = 1'; } if ($post_type) { $where[] = "post_type = '" . $this->quote($post_type) . "'"; } if ($category_id) { $where[] = 'category_id IN(' . implode(',', $this->model('system')->get_category_with_child_ids('question', $category_id)) . ')'; } if (!($result = AWS_APP::cache()->get($result_cache_key))) { $result = $this->fetch_page('posts_index', implode(' AND ', $where), $order_by, $page, $per_page); AWS_APP::cache()->set($result_cache_key, $result, get_setting('cache_level_high')); } if (!($found_rows = AWS_APP::cache()->get($found_rows_cache_key))) { $found_rows = $this->found_rows(); AWS_APP::cache()->set($found_rows_cache_key, $found_rows, get_setting('cache_level_high')); } $this->posts_list_total = $found_rows; return $result; }
public function save_receiving_email_config_action() { if ($_POST['id']) { $receiving_email_config = $this->model('edm')->get_receiving_email_config_by_id($_POST['id']); if (!$receiving_email_config) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('该账号不存在'))); } } $_POST['server'] = trim($_POST['server']); if (!$_POST['server']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入服务器地址'))); } if (!$_POST['protocol'] or !in_array($_POST['protocol'], array('pop3', 'imap'))) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请选择协议'))); } if ($_POST['port'] and (!is_digits($_POST['port']) or $_POST['port'] < 0 or $_POST['port'] > 65535)) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入有效的端口号(0 ~ 65535)'))); } if (!$_POST['uid']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请选择此账号对应的用户'))); } $user_info = $this->model('account')->get_user_info_by_uid($_POST['uid']); if (!$user_info) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('所选用户不存在'))); } $receiving_email_config = array('server' => $_POST['server'], 'protocol' => $_POST['protocol'], 'ssl' => $_POST['ssl'] == '1' ? '1' : '0', 'username' => trim($_POST['username']), 'password' => trim($_POST['password']), 'uid' => $user_info['uid']); if ($_POST['port']) { $receiving_email_config['port'] = $_POST['port']; } if ($_POST['id']) { $this->model('edm')->update_receiving_email_config($_POST['id'], 'update', $receiving_email_config); H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('保存设置成功'))); } else { $config_id = $this->model('edm')->update_receiving_email_config(null, 'add', $receiving_email_config); H::ajax_json_output(AWS_APP::RSM(array('url' => get_js_url('/admin/edm/receiving/id-' . $config_id)), 1, null)); } }
public function get_weibo_user_by_uid($uid) { if (!is_digits($uid)) { return false; } static $weibo_user_info; if (!$weibo_user_info[$uid]) { $weibo_user_info[$uid] = $this->fetch_row('users_sina', 'uid = ' . $uid); } return $weibo_user_info[$uid]; }
public function response_message($input_message) { switch ($input_message['msgType']) { case 'event': if (substr($input_message['eventKey'], 0, 8) == 'COMMAND_') { if ($input_message['eventKey'] == 'COMMAND_MORE') { $input_message['content'] = 'yes'; $input_message['msgType'] = 'text'; $response = $this->response_message($input_message); } else { if (strstr($input_message['eventKey'], '__')) { $event_key = explode('__', substr($input_message['eventKey'], 8)); $content = $event_key[0]; $param = $event_key[1]; } else { $content = substr($input_message['eventKey'], 8); } $response = $this->message_parser(array('content' => $content, 'fromUsername' => $input_message['fromUsername'], 'param' => $param)); } $response_message = $response['message']; $action = $response['action']; } else { if (substr($input_message['eventKey'], 0, 11) == 'REPLY_RULE_') { if ($reply_rule = $this->get_reply_rule_by_id(substr($input_message['eventKey'], 11))) { $response_message = $this->create_response_by_reply_rule_keyword($reply_rule['keyword']); } else { $response_message = '菜单指令错误'; } } else { switch (strtolower($input_message['event'])) { case 'subscribe': if (substr($input_message['eventKey'], 0, 8) == 'qrscene_') { $this->query('UPDATE ' . get_table('weixin_qr_code') . ' SET subscribe_num = subscribe_num + 1 WHERE scene_id = ' . intval(substr($input_message['eventKey'], 8))); } if ($this->account_info['weixin_subscribe_message_key']) { $response_message = $this->create_response_by_reply_rule_keyword($this->account_info['weixin_subscribe_message_key']); } break; case 'location': if ($this->user_id) { $this->update('users_weixin', array('latitude' => $input_message['latitude'], 'longitude' => $input_message['longitude'], 'location_update' => time()), 'uid = ' . $this->user_id); } break; case 'masssendjobfinish': $msg_id = $input_message['msgID']; $msg_details = array('create_time' => intval($input_message['createTime']), 'filter_count' => intval($input_message['filterCount'])); if ($input_message['status'] == 'send success' or $input_message['status'] == 'sendsuccess') { $msg_details['status'] = 'success'; } else { if ($input_message['status'] == 'send fail' or $input_message['status'] == 'sendfail') { $msg_details['status'] = 'fail'; } else { if (substr($input_message['status'], 0, 3) == 'err') { $msg_details['status'] = 'wrong'; $msg_details['error_num'] = intval(substr($input_message['status'], 4, 9)); } } } if (is_digits($msg_id)) { $this->update('weixin_msg', $msg_details, 'msg_id = ' . $msg_id); } break; } } } break; case 'location': if ($near_by_questions = $this->model('people')->get_near_by_users($input_message['location_X'], $input_message['location_y'], $this->user_id, 5)) { foreach ($near_by_questions 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); } } else { $response_message = '你的附近暂时没有主题'; } break; case 'voice': if ($input_message['recognition']) { $input_message['content'] = $input_message['recognition']; $input_message['msgType'] = 'text'; $response_message = $this->response_message($input_message); } else { $response_message = '无法识别语音或相关功能未启用'; } break; case 'image': if (get_setting('weixin_account_role') != 'subscription' and get_setting('weixin_account_role') != 'service') { break; } if ($input_message['mediaID'] and $input_message['picUrl']) { AWS_APP::cache()->set('weixin_pic_url_' . md5($input_message['mediaID']), $input_message['picUrl'], 259200); $response_message = '您想提交图片到社区么?<a href="' . $this->model('openid_weixin_weixin')->redirect_url('/m/publish/weixin_media_id-' . base64_encode($input_message['mediaID'])) . '">点击进入提交页面</a>'; } else { $response_message = '无法识别图片'; } break; default: if ($response_message = $this->create_response_by_reply_rule_keyword($input_message['content'])) { // response by reply rule keyword... } else { if ($response = $this->model('openid_weixin_third')->send_message_to_third_party($this->account_info['id'], $this->post_data)) { exit($response); } else { if ($response = $this->message_parser($input_message)) { // Success... $response_message = $response['message']; $action = $response['action']; } else { if ($this->is_language($input_message['content'], 'ok')) { $response = $this->process_last_action($input_message['fromUsername']); $response_message = $response['message']; $action = $response['action']; } else { if ($this->is_language($input_message['content'], 'cancel')) { $this->delete('weixin_message', "weixin_id = '" . $this->quote($input_message['fromUsername']) . "'"); $response_message = '好的, 还有什么可以帮您的吗?'; } else { if (!($response_message = $this->create_response_by_reply_rule_keyword($this->account_info['weixin_no_result_message_key']))) { $response_message = '您的主题: ' . $input_message['content'] . ', 目前没有人提到过, <a href="' . $this->model('openid_weixin_weixin')->redirect_url('/m/publish/') . '">点此提问</a>'; } } } } } } break; } $response = is_array($response_message) ? $this->create_image_response($input_message, $response_message, $action) : $this->create_txt_response($input_message, $response_message, $action); if ($input_message['encryption']) { $response = $this->encrypt_msg($response); } exit($response); }
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 .= ' (<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)); }