/** * 为Feed添加评论 * * * @param string token , 必填 * @param string fid - 必填 * @param string text - 必填 * @return feed array * @author EasyChen */ public function feed_add_comment($text = false, $fid = false) { if (!$text) { $content = $text = z(t(v('text'))); } if (!not_empty($content)) { return self::send_error(LR_API_ARGS_ERROR, __('INPUT_CHECK_BAD_ARGS', 'TEXT')); } if (!$fid) { $fid = intval(v('fid')); } if (intval($fid) < 1) { return self::send_error(LR_API_ARGS_ERROR, __('INPUT_CHECK_BAD_ARGS', 'FID')); } $finfo = get_line("SELECT * FROM `feed` WHERE `id` = '" . intval($fid) . "' LIMIT 1"); if (is_mobile_request()) { $device = 'mobile'; } else { $device = 'web'; } $sql = "INSERT INTO `comment` ( `fid` , `uid` , `content` , `timeline` , `device` ) \n\t\tVALUES ( '" . intval($fid) . "' , '" . intval($_SESSION['uid']) . "' , '" . s($content) . "' , NOW() , '" . s($device) . "' ) "; run_sql($sql); if (db_errno() != 0) { return self::send_error(LR_API_DB_ERROR, __('API_MESSAGE_DATABASE_ERROR') . mysql_error()); } else { $lid = last_id(); // feed表comment_count计数增加 $count = get_var("SELECT COUNT(*) FROM `comment` WHERE `fid` = '" . intval($fid) . "' ", db()); $sql = "UPDATE `feed` SET `comment_count` = '" . intval($count) . "' WHERE `id` = '" . intval($fid) . "' LIMIT 1"; run_sql($sql); // 向Feed作者发通知 if ($finfo['uid'] != uid()) { send_notice($finfo['uid'], __('API_TEXT_COMMENT_FEED_OWNED', array(uname(), $finfo['content'], $content)), 2, array('fid' => intval($fid), 'count' => $count)); } // 向参与了该Feed讨论的同学发送通知 $sql = "SELECT `uid` FROM `comment` WHERE `fid`= '" . intval($fid) . "' "; if ($uitems = get_data($sql)) { foreach ($uitems as $uitem) { if ($uitem['uid'] != uid() && $uitem['uid'] != $finfo['uid']) { $myuids[] = $uitem['uid']; } } } if (isset($myuids)) { $myuids = array_unique($myuids); foreach ($myuids as $muid) { send_notice($muid, __('API_TEXT_COMMENT_FEED_IN', array(uname(), $finfo['content'], $content)), 2, array('fid' => intval($fid), 'count' => $count)); } } // 向被@的同学,发送通知 if ($ats = find_at($content)) { $sql = "SELECT `id` FROM `user` WHERE "; foreach ($ats as $at) { $at = z(t($at)); if ($gname = get_group_names()) { if (in_array(strtoupper($at), $gname)) { if ($ndata = get_group_unames($at)) { foreach ($ndata as $nname) { $names[] = $nname; } } } else { $names[] = $at; } } else { $names[] = $at; } } foreach ($names as $at) { $at = z(t($at)); if (mb_strlen($at, 'UTF-8') < 2) { continue; } $wsql[] = " `name` = '" . s(t($at)) . "' "; if (c('at_short_name')) { if (mb_strlen($at, 'UTF-8') == 2) { $wsql[] = " `name` LIKE '_" . s($at) . "' "; } } } if (isset($wsql) && is_array($wsql)) { $sql = $sql . join(' OR ', $wsql); if ($udata = get_data($sql)) { foreach ($udata as $uitem) { $myuids[] = $uitem['id']; } if (isset($myuids) && is_array($myuids)) { $myuids = array_unique($myuids); foreach ($myuids as $muid) { if ($muid != uid() && $muid != $finfo['uid']) { send_notice($muid, __('API_TEXT_AT_IN_CAST_COMMENT', array(uname(), $finfo['content'], $content)), 2, array('fid' => intval($fid), $count)); } } } } } } if ($comment = get_line("SELECT * FROM `comment` WHERE `id` = '" . intval($lid) . "' LIMIT 1", db())) { $comment['user'] = get_user_info_by_id($_SESSION['uid']); return self::send_result($comment); } else { if (db_errno() != 0) { return self::send_error(LR_API_DB_ERROR, __('API_MESSAGE_DATABASE_ERROR') . mysql_error()); } else { return self::send_error(LR_API_DB_EMPTY_RESULT, __('API_MESSAGE_EMPTY_RESULT_DATA')); } } } }
function board_todo_batch_add() { $board_id = intval(v('board_id')); $list_id = intval(v('list_id')); $todos = explode("\r\n", v('todos')); //读取board信息 if (!($board = get_line("select * from board where id='{$board_id}'"))) { return apiController::send_error(6014, 'board not exists'); } //判断操作权限 if (!has_board_permission(uid(), $board['visible'], $board['visible_value'])) { return apiController::send_error(6015, 'no permission'); } $is_public = 'private' == $board['visible'] ? 0 : 1; $tids = array(); $ret = array(); foreach ($todos as $todo) { $uids = array(); if (!empty($todo)) { //分析@ if ($ats = find_at($todo)) { //循环分析@取UID foreach ($ats as $at) { $wsql = array(); if (mb_strlen($at, 'UTF-8') >= 2) { $wsql[] = " `name` = '" . s(t($at)) . "' "; } if (c('at_short_name')) { if (mb_strlen($at, 'UTF-8') == 2) { $wsql[] = " `name` LIKE '_" . s($at) . "' "; } } if (!empty($wsql)) { if ($get_uid = get_var("SELECT `id` FROM `user` WHERE (`level` > 0 AND `is_closed` != 1 ) AND ( " . join(' OR ', $wsql) . " ) ")) { $uids[] = $get_uid; } } } } //如果TODO以#号结尾,则为公有TODO, $is_this_public = '#' == substr($todo, -1) ? 1 : $is_public; //用户UID if (empty($uids)) { $uids = array(uid()); } else { $is_this_public = 1; } // 如果@了人,固定为公有的TODO //添加todu foreach ($uids as $uid) { $result = json_decode(send_request('todo_add', array('text' => $todo, 'is_public' => $is_this_public, 'uid' => $uid), token()), true); } if (0 == $result['err_code']) { $tids[] = $result['data']['tid']; $ret[$result['data']['id']] = $result['data']['content']; } else { return apiController::send_error(6016, 'todo[' . $todo . '] add failed,' . $result['err_msg']); } } } if (!empty($tids)) { run_sql("update board_list set todos=concat_ws(',',todos,'" . implode(',', $tids) . "') where id='{$list_id}'"); } return apiController::send_result($ret); }