function doaddcomment($uid, $post, $api = false) { $data['uid'] = $uid; $data['reply_comment_id'] = intval($post['reply_comment_id']); $data['weibo_id'] = intval($post['weibo_id']); $data['content'] = $post['content']; $data['ctime'] = time(); $miniInfo = D('Weibo')->where('weibo_id=' . $data['weibo_id'])->find(); if ($data['reply_comment_id']) { $replyInfo = $this->where('comment_id=' . $data['reply_comment_id'])->find(); $data['reply_uid'] = $replyInfo['uid']; } else { $data['reply_uid'] = $miniInfo['uid']; $notify['reply_type'] = 'weibo'; } if ($comment_id = $this->addcomment($data)) { //微博回复积分操作 if ($data['uid'] != $data['reply_uid']) { X('Credit')->setUserCredit($data['uid'], 'reply_weibo')->setUserCredit($data['reply_uid'], 'replied_weibo'); } $data['comment'] = $miniInfo['comment'] + 1; $return['data'] = $data; $return['html'] = '<div class="position_list" id="comment_list_c_' . $comment_id . '"> <a href="' . U('home/space/index', array('uid' => $this->mid)) . '" class="pic"> <img class="pic30" src="' . getUserFace($uid, 's') . '" /></a> <p class="list_c"><a href="#">' . getUserName($uid) . '</a> ' . getUserGroupIcon($uid) . ' : ' . formatComment($data['content'], true) . ' (刚刚)</p> <div class="alR clear"><a href="javascript:void(0)" onclick="ui.confirm(this,\'确认要删除此评论?\')" callback="delComment(' . $comment_id . ')">删除</a> <a href="javascript:void(0)" onclick="reply(\'' . getUserName($uid) . '\',' . $data['weibo_id'] . ')">回复</a></div> </div>'; if ($post['transpond'] != 0) { if ($miniInfo['transpond_id'] != 0) { $transpondData['content'] = $data['content'] . " //@" . getUserName($miniInfo['uid']) . ":" . $miniInfo['content']; $transpondData['transpond_id'] = $miniInfo['transpond_id']; $transpondInfo = M('weibo')->where('weibo_id=' . $miniInfo['transpond_id'])->find(); $transpondData['transpond_uid'] = $transpondInfo['uid']; } else { $transpondData['content'] = $data['content']; $transpondData['transpond_id'] = $miniInfo['weibo_id']; $transpondData['transpond_uid'] = $miniInfo['uid']; } $id = D('Weibo', 'weibo')->doSaveWeibo($uid, $transpondData, $post['from']); if ($id) { //当转发的微博uid 与 回复人的uid不一致时发布@到我 if ($transpondData['transpond_uid'] != $data['reply_uid']) { D('Weibo', 'weibo')->notifyToAtme($id, $transpondData['content'], $transpondData['transpond_uid']); } else { D('Weibo', 'weibo')->notifyToAtme($id, $transpondData['content'], $transpondData['transpond_uid'], false); } } } //添加统计 Model('UserCount')->addCount($data['reply_uid'], 'comment'); if ($api) { return true; } else { return json_encode($return); } } else { return '0'; } }
/** * 解析模板 */ private function _parseTemplate($i_data) { if (false == ($i_data['data'] = unserialize($i_data['data']))) { $i_data['data'] = unserialize(stripslashes($i_data['data'])); } $replace["{actor}"] = '<a href="' . U("home/space/index", array("uid" => $i_data['from'])) . '" target="_blank">' . getUserName($i_data['from']) . '</a>' . getUserGroupIcon($i_data['from']); if ($i_data) { extract($i_data['data'], EXTR_OVERWRITE); } unset($i_data['data']); extract($i_data, EXTR_OVERWRITE); $template_type = explode('_', $i_data['type']); $template = (require SITE_PATH . '/apps/' . $template_type[0] . '/Language/cn/notify.php'); $return['title'] = str_replace(array_keys($replace), array_values($replace), $template[$i_data['type']]['title']); $return['body'] = str_replace(array_keys($replace), array_values($replace), $template[$i_data['type']]['body']); $return['other'] = str_replace(array_keys($replace), array_values($replace), $template[$i_data['type']]['other']); return $return; }
/** * 解析模板 */ private function _parseTemplate($i_data) { if (false == ($i_data['data'] = unserialize($i_data['data']))) { $i_data['data'] = unserialize(stripslashes($i_data['data'])); } $replace["{actor}"] = getUserSpace($i_data['from'], 'fn', '_blank', '{uname}') . getUserGroupIcon($i_data['from']); if ($i_data) { extract($i_data['data'], EXTR_OVERWRITE); } unset($i_data['data']); extract($i_data, EXTR_OVERWRITE); $template_type = explode('_', $i_data['type']); $template = (require SITE_PATH . '/apps/' . $template_type[0] . '/Language/cn/notify.php'); $return['title'] = str_replace(array_keys($replace), array_values($replace), $template[$i_data['type']]['title']); $return['body'] = str_replace(array_keys($replace), array_values($replace), $template[$i_data['type']]['body']); $return['other'] = str_replace(array_keys($replace), array_values($replace), $template[$i_data['type']]['other']); return $return; }
public function sendToWeibo() { $_REQUEST['with_new_weibo'] = intval($_REQUEST['with_new_weibo']); $_REQUEST['type'] = t($_REQUEST['type']); $_REQUEST['appid'] = intval($_REQUEST['appid']); $_REQUEST['comment'] = $_REQUEST['comment']; $_REQUEST['to_id'] = intval($_REQUEST['to_id']); $_REQUEST['author_uid'] = intval($_REQUEST['author_uid']); $_REQUEST['title'] = t(html_entity_decode($_REQUEST['title'], ENT_QUOTES)); $_REQUEST['url'] = urldecode($_REQUEST['url']); $_REQUEST['table'] = t($_REQUEST['table']); $_REQUEST['id_field'] = t($_REQUEST['id_field']); $_REQUEST['comment_count_field'] = t($_REQUEST['comment_count_field']); $app_alias = getAppAlias($_REQUEST['type']); // 被回复内容 $former_comment = array(); if ($_REQUEST['to_id'] > 0) { $former_comment = M('comment')->where("`id`='{$_REQUEST['to_id']}'")->find(); } // 插入新数据 $map['type'] = $_REQUEST['type']; // 应用名 $map['appid'] = $_REQUEST['appid']; $map['appuid'] = $_REQUEST['author_uid']; $map['uid'] = $this->mid; $map['comment'] = t(getShort($_REQUEST['comment'], $GLOBALS['ts']['site']['length'])); $map['cTime'] = time(); $map['toId'] = $_REQUEST['to_id']; $map['status'] = 0; // 0: 未读 1:已读 $map['quietly'] = 0; $map['to_uid'] = $former_comment['uid'] ? $former_comment['uid'] : $_REQUEST['author_uid']; $map['data'] = serialize(array('title' => keyWordFilter($_REQUEST['title']), 'url' => $_REQUEST['url'], 'table' => $_REQUEST['table'], 'id_field' => $_REQUEST['id_field'], 'comment_count_field' => $_REQUEST['comment_count_field'])); $res = M('comment')->add($map); // 避免命名冲突 unset($map['data']); if ($res) { // 发表分享 if ($_REQUEST['with_new_weibo']) { $from_data = array('app_type' => 'local_app', 'app_name' => $_REQUEST['type'], 'title' => $_REQUEST['title'], 'url' => $_REQUEST['url']); $from_data = serialize($from_data); D('Weibo', 'weibo')->publish($this->mid, array('content' => html_entity_decode($_REQUEST['comment'] . ($_REQUEST['to_id'] > 0 ? ' //@' . getUserName($former_comment['uid']) . ' :' . $former_comment['comment'] : ''), ENT_QUOTES)), 0, 0, '', '', $from_data); } // 组装结果集 $result = $map; $result['data']['uavatar'] = getUserSpace($this->mid, 'null', '_blank', '{uavatar}'); $result['data']['uspace'] = getUserSpace($this->mid, 'null', '_blank', '{uname}'); //$result['data']['comment'] = $_REQUEST['comment']; $result['data']['ctime'] = L('just_now'); $result['data']['uname'] = getUserName($this->mid); $result['data']['comment'] = formatComment(t($_REQUEST['comment'])); $result['data']['id'] = $res; $result['data']['userGroupIcon'] = getUserGroupIcon($this->mid); $result['data']['del_state'] = 1; return json_encode($result); } else { echo -1; } }
public function doAddComment() { $_POST['with_new_weibo'] = intval($_POST['with_new_weibo']); $_POST['type'] = t($_POST['type']); $_POST['appid'] = intval($_POST['appid']); $_POST['comment'] = $_POST['comment']; $_POST['to_id'] = intval($_POST['to_id']); $_POST['author_uid'] = intval($_POST['author_uid']); $_POST['title'] = t(html_entity_decode($_POST['title'], ENT_QUOTES)); $_POST['url'] = urldecode($_POST['url']); $_POST['table'] = t($_POST['table']); $_POST['id_field'] = t($_POST['id_field']); $_POST['comment_count_field'] = t($_POST['comment_count_field']); $app_alias = getAppAlias($_POST['type']); // 被回复内容 $former_comment = array(); if ($_POST['to_id'] > 0) { $former_comment = M('comment')->where("`id`='{$_POST['to_id']}'")->find(); } // 插入新数据 $map['type'] = $_POST['type']; // 应用名 $map['appid'] = $_POST['appid']; $map['appuid'] = $_POST['author_uid']; $map['uid'] = $this->mid; $map['comment'] = t(getShort($_POST['comment'], $GLOBALS['ts']['site']['length'])); $map['cTime'] = time(); $map['toId'] = $_POST['to_id']; $map['status'] = 0; // 0: 未读 1:已读 $map['quietly'] = 0; $map['to_uid'] = $former_comment['uid'] ? $former_comment['uid'] : $_POST['author_uid']; $map['data'] = serialize(array('title' => $_POST['title'], 'url' => $_POST['url'], 'table' => $_POST['table'], 'id_field' => $_POST['id_field'], 'comment_count_field' => $_POST['comment_count_field'])); $res = M('comment')->add($map); // 避免命名冲突 unset($map['data']); if ($res) { // 应用回调: 增加应用的评论计数 $this->__doAddCallBack($_POST['appid'], $_POST['table'], $_POST['id_field'], $_POST['comment_count_field']); //积分处理 $setCredit = X('Credit'); if ($map['toId'] > 0 && $this->mid != $map['to_uid']) { $setCredit->setUserCredit($this->mid, 'reply_comment')->setUserCredit($map['to_uid'], 'replied_comment'); } else { if ($this->mid != $map['to_uid']) { $setCredit->setUserCredit($this->mid, 'add_comment')->setUserCredit($map['to_uid'], 'is_commented'); } } // 发表微博 if ($_POST['with_new_weibo']) { $from_data = array('app_type' => 'local_app', 'app_name' => $_POST['type'], 'title' => $_POST['title'], 'url' => $_POST['url']); $from_data = serialize($from_data); D('Weibo', 'weibo')->publish($this->mid, array('content' => html_entity_decode($_POST['comment'] . ($_POST['to_id'] > 0 ? ' //@' . getUserName($former_comment['uid']) . ' :' . $former_comment['comment'] : ''), ENT_QUOTES)), 0, 0, '', '', $from_data); } /* // 给被回复人发送通知 if ($former_comment['uid']) { $data = array( 'app_alias' => $app_alias, 'url' => $_POST['url'], 'title' => $_POST['title'], 'content' => $_POST['comment'], 'my_content'=> $former_comment['comment'], ); service('Notify')->send($former_comment['uid'], 'home_replyComment', $data, $this->mid); unset($data); } // 给作者发送通知 ( 当被回复人和作者为同一人时, 只发一个通知. 优先被回复. ) if ($_POST['author_uid'] > 0 && $_POST['author_uid'] != $former_comment['uid']) { $data = array( 'app_alias' => $app_alias, 'url' => $_POST['url'], 'title' => $_POST['title'], 'content' => $_POST['comment'], ); service('Notify')->send($_POST['author_uid'], 'home_addComment', $data, $this->mid); unset($data); } */ // 组装结果集 $result = $map; $result['data']['uavatar'] = getUserSpace($this->mid, 'null', '_blank', '{uavatar}'); $result['data']['uspace'] = getUserSpace($this->mid, 'null', '_blank', '{uname}'); //$result['data']['comment'] = $_POST['comment']; $result['data']['ctime'] = L('just_now'); $result['data']['uname'] = getUserName($this->mid); $result['data']['comment'] = formatComment(t($_POST['comment'])); $result['data']['id'] = $res; $result['data']['userGroupIcon'] = getUserGroupIcon($this->mid); $result['data']['del_state'] = 1; echo json_encode($result); } else { echo -1; } }