Пример #1
0
 /**
  * 添加微博
  *
  * @param	uid 发布者
  * @param	content 内容
  * @param	attach 附件
  * @param	source 来源
  * @param	repost 转发id
  */
 public function add_sns($uid, $content, $attach, $source = 0, $repost = 0)
 {
     // 判断uid是否存在
     if (!$uid) {
         return FALSE;
     }
     // 查询用户名
     if ($uid == $this->uid) {
         $username = $this->member['username'];
     } else {
         $m = dr_member_info($uid);
         $username = $m['username'];
         unset($m);
     }
     // 来源
     if (!$source) {
         if ($this->agent->is_mobile()) {
             $source = lang('m-247');
         } else {
             $source = lang('m-246');
         }
     }
     // 过滤非法内容
     $content = dr_preg_html($content) . ' ';
     // 提取URL链接
     $content = preg_replace_callback('/((?:https?|mailto|ftp):\\/\\/([^\\x{2e80}-\\x{9fff}\\s<\'\\"“”‘’,。}]*)?)/u', '_format_feed_content_url_length', $content);
     // 提取@
     $user = array();
     if (preg_match_all('/@(.+) /U', $content, $match)) {
         $data = array_unique($match[1]);
         foreach ($data as $t) {
             $m = $this->db->select('uid')->where('username', $t)->get('member')->row_array();
             if ($m) {
                 $user[$t] = $m['uid'];
                 $content = str_replace('@' . $t . ' ', ' <a href="javascript:;" uid="' . $m['uid'] . '" event-node="face_card" target="_blank">@' . $t . '</a> ', $content);
             }
         }
         unset($data, $m);
     }
     // 提取话题
     $topic = array();
     if (preg_match_all('/#(.+)#/U', $content, $match)) {
         $data = array_unique($match[1]);
         foreach ($data as $t) {
             // 查询话题是否存在,不存在就创建
             $row = $this->db->where('name', $t)->get('sns_topic')->row_array();
             if ($row) {
                 $tid = $row['id'];
             } else {
                 $this->db->insert('sns_topic', array('name' => $t, 'uid' => $uid, 'username' => $username, 'count' => 0, 'inputtime' => SYS_TIME));
                 $tid = $this->db->insert_id();
             }
             $topic[] = $tid;
             $content = str_replace('#' . $t . '#', '<a href="[TOPIC-URL-' . $tid . ']" target="_blank">#' . $t . '#</a> ', $content);
         }
         unset($data);
     }
     $content = trim($content);
     if (!$content) {
         return FALSE;
     }
     // 是转发文章
     if ($repost) {
         $row = $this->db->where('id', $repost)->get('sns_feed')->row_array();
         if ($row) {
             $repost = $row['repost_id'] ? $row['repost_id'] : $row['id'];
             // 统计原文转发数量
             $this->db->where('id', $repost)->set('repost', 'repost+1', FALSE)->update('sns_feed');
             // 清除缓存数据
             $this->ci->set_cache_data('sns-feed-' . $repost, '', 1);
         } else {
             $repost = 0;
         }
     }
     $images = $attach ? trim($attach, '|') : '';
     // 插入的数据
     $this->db->insert('sns_feed', array('uid' => $uid, 'username' => $username, 'comment' => 0, 'repost' => 0, 'digg' => 0, 'content' => $content, 'repost_id' => $repost, 'source' => $source, 'images' => $images, 'inputip' => $this->input->ip_address(), 'inputtime' => SYS_TIME));
     $id = $this->db->insert_id();
     // 保存附件
     if ($images) {
         $this->load->model('attachment_model');
         $this->attachment_model->replace_attach($uid, $this->db->dbprefix('sns_feed') . '-' . $id, explode('|', $images));
     }
     // 更新话题关系表
     if ($topic) {
         foreach ($topic as $tid) {
             $this->db->insert('sns_topic_index', array('fid' => $id, 'tid' => $tid));
             $this->db->where('id', $tid)->set('count', 'count+1', FALSE)->update('sns_topic');
         }
     }
     // 给@的人发送提醒
     if ($user) {
         $this->add_notice($user, 2, dr_lang('m-248', $username, dr_sns_feed_url($id)));
     }
     // 给作者发送转发的提醒
     if ($repost) {
         $this->add_notice($row['uid'], 2, dr_lang('m-252', $username, dr_sns_feed_url($id)));
     }
     // 分数奖励
     if ($uid == $this->uid) {
         if ($this->member_rule['feed_experience']) {
             $this->update_score(0, $uid, (int) $this->member_rule['feed_experience'], '', "lang,m-212");
         }
         if ($this->member_rule['feed_score']) {
             $this->update_score(1, $uid, (int) $this->member_rule['feed_score'], '', "lang,m-212");
         }
     }
     return TRUE;
 }
Пример #2
0
 public function comment()
 {
     $id = (int) $this->input->get('id');
     $content = trim(dr_safe_replace($this->callback ? $this->input->get('content') : $this->input->post('content')));
     // 验证字数
     if (($num = (int) $this->get_cache('member', 'setting', 'sns_post_num')) && strlen($content) > $num) {
         if ($this->callback) {
             exit($this->callback . '(' . dr_json(0, lang('m-213')) . ')');
         } else {
             exit(dr_json(0, lang('m-213')));
         }
     }
     // 过滤非法内容
     $content = dr_preg_html($content) . ' ';
     // 提取URL链接
     $content = preg_replace_callback('/((?:https?|mailto|ftp):\\/\\/([^\\x{2e80}-\\x{9fff}\\s<\'\\"“”‘’,。}]*)?)/u', '_format_feed_content_url_length', $content);
     // 提取@
     $user = array();
     if (preg_match_all('/@(.+) /U', $content, $match)) {
         $data = array_unique($match[1]);
         foreach ($data as $t) {
             $m = $this->db->select('uid')->where('username', $t)->get('member')->row_array();
             if ($m) {
                 $user[$t] = $m['uid'];
                 $content = str_replace('@' . $t . ' ', ' <a href="javascript:;" uid="' . $m['uid'] . '" event-node="face_card" target="_blank">@' . $t . '</a> ', $content);
             }
         }
         unset($data, $m);
     }
     $content = trim($content);
     if (!$content) {
         if ($this->callback) {
             exit($this->callback . '(' . dr_json(0, lang('m-250')) . ')');
         } else {
             exit(dr_json(0, lang('m-250')));
         }
     }
     $data = dr_sns_feed($id);
     if (!$data) {
         if ($this->callback) {
             exit($this->callback . '(' . dr_json(0, lang('m-249')) . ')');
         } else {
             exit(dr_json(0, lang('m-249')));
         }
     }
     // 写入评论
     $this->db->insert('sns_comment', array('fid' => $id, 'uid' => $this->uid, 'comment' => $content, 'inputip' => $this->input->ip_address(), 'username' => $this->member['username'], 'inputtime' => SYS_TIME));
     // @给作者
     $this->member_model->add_notice($data['uid'], 2, dr_lang('m-253', $this->member['username'], dr_sns_feed_url($data['uid'], $id)));
     // 给@的人发送提醒
     if ($user) {
         $this->member_model->add_notice($user, 2, dr_lang('m-289', $this->member['username'], dr_sns_feed_url($data['uid'], $id)));
     }
     // 更新动态表
     $this->db->where('id', $id)->set('comment', 'comment+1', FALSE)->update('sns_feed');
     if ($this->callback) {
         exit($this->callback . '(' . dr_json(1, lang('m-254')) . ')');
     } else {
         exit(dr_json(1, lang('m-254')));
     }
 }