예제 #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;
 }
 protected function _add($data)
 {
     // 入库
     $table = $this->db->dbprefix($this->table);
     $data[1]['tableid'] = 0;
     $this->link->insert($table, $data[1]);
     //
     if (($id = $this->link->insert_id()) && ($user = dr_member_info($this->cdata['uid']))) {
         // 无限分表
         $tableid = floor($id / 50000);
         $this->link->where('id', $id)->update($table, array('tableid' => $tableid));
         if (!$this->link->query("SHOW TABLES LIKE '" . $table . '_data_' . $tableid . "'")->row_array()) {
             // 附表不存在时创建附表
             $sql = $this->link->query("SHOW CREATE TABLE `" . $table . "_data_0`")->row_array();
             $this->link->query(str_replace(array($sql['Table'], 'CREATE TABLE '), array($table . '_data_' . $tableid, 'CREATE TABLE IF NOT EXISTS '), $sql['Create Table']));
         }
         $data[0]['id'] = $id;
         $data[0]['cid'] = $data[1]['cid'];
         $data[0]['uid'] = $data[1]['uid'];
         $this->db->replace($table . '_data_' . $tableid, $data[0]);
         // 通知功能
         $murl = dr_member_url(APP_DIR . '/' . $this->router->class . '/listc', array('cid' => $this->cdata['id']));
         $title = dr_lang('mod-106', $this->cdata['title'], $this->form['name']);
         // 邮件提醒
         if ($this->form['setting']['email']) {
             $this->sendmail_queue($user['email'], $title, dr_lang('mod-107', $this->cdata['title'], $this->form['name'], $murl, $murl));
         }
         // 短信提醒
         if ($this->form['setting']['sms'] && $user['phone']) {
             $this->member_model->sendsms($user['phone'], $title);
         }
         // 添加提醒
         $this->member_model->add_notice($this->cdata['uid'], 3, '<a href="' . $murl . '">' . $title . '</a>');
         // 更新模块表的统计值
         $this->link->where('id', $this->cid)->set($this->fid . '_total', $this->fid . '_total + 1', FALSE)->update(SITE_ID . '_' . APP_DIR);
     }
     return $id;
 }
예제 #3
0
 protected function _add($data)
 {
     // 入库
     $this->link->insert($this->table, $data);
     if (($id = $this->link->insert_id()) && ($user = dr_member_info($this->cdata['uid']))) {
         $murl = dr_member_url(APP_DIR . '/' . $this->router->class . '/listc', array('cid' => $this->cdata['id']));
         $title = dr_lang('mod-106', $this->cdata['title'], $this->form['name']);
         // 邮件提醒
         if ($this->form['setting']['email']) {
             $this->sendmail_queue($user['email'], $title, dr_lang('mod-107', $this->cdata['title'], $this->form['name'], $murl, $murl));
         }
         // 短信提醒
         if ($this->form['setting']['sms'] && $user['phone']) {
             $this->member_model->sendsms($user['phone'], $title);
         }
         // 添加提醒
         $this->member_model->add_notice($this->cdata['uid'], 3, '<a href="' . $murl . '">' . $title . '</a>');
     }
     return $id;
 }
예제 #4
0
 public function member()
 {
     $uid = (int) $this->input->get('uid');
     $row = $this->db->where('fid', $this->uid)->where('uid', $uid)->get('sns_follow')->row_array();
     $this->template->assign(array('uid' => $uid, 'follow' => $row ? $row['isdouble'] : -1, 'membersns' => dr_sns_info($uid), 'memberinfo' => dr_member_info($uid)));
     if ($this->callback) {
         ob_start();
         $this->template->display('sns_member.html');
         $html = ob_get_contents();
         ob_clean();
         exit($this->callback . '(' . json_encode(array('html' => $html)) . ')');
     } else {
         $this->template->display('sns_member.html');
     }
 }
예제 #5
0
파일: Sns.php 프로젝트: xxjuan/php-coffee
 public function member()
 {
     $uid = (int) $this->input->post('uid');
     $row = $this->db->where('fid', $this->uid)->where('uid', $uid)->get('sns_follow')->row_array();
     $this->template->assign(array('uid' => $uid, 'follow' => $row ? $row['isdouble'] : -1, 'membersns' => dr_sns_info($uid), 'memberinfo' => dr_member_info($uid)));
     $this->template->display('sns_member.html');
 }