Esempio n. 1
0
 public function add_comment()
 {
     if (empty($this->uid)) {
         show_message('请登录后再发表', site_url('user/login/'));
     }
     if ($this->form_validation->run() === TRUE) {
         if (time() - $this->input->post('lastpost') < $this->config->item('timespan')) {
             $callback['error'] = '发帖最小间隔时间是' . $this->config->item('timespan') . '秒!';
             echo json_encode($callback);
             exit;
         }
         //数据提交
         $data = array('content' => $this->input->post('comment'), 'topic_id' => $this->input->post('topic_id'), 'uid' => $this->uid, 'replytime' => time());
         //if (!isset($data['content']{4})) exit;
         $this->load->helper('format_content');
         $data['content'] = format_content($data['content']);
         //数据返回
         $query = $this->db->select('comments')->get_where('topics', array('topic_id' => $data['topic_id']))->row_array();
         $callback = array('content' => $data['content'], 'topic_id' => $data['topic_id'], 'uid' => $data['uid'], 'replytime' => $this->myclass->friendly_date($data['replytime']), 'username' => $this->input->post('username'), 'avatar' => $this->input->post('avatar'), 'layer' => @$query['comments'] + 1);
         //无编辑器时的处理
         //if($this->config->item('show_editor')=='off'){
         //$data['content'] = filter_check($data['content']);
         //$data['content'] = format_content($data['content']);
         //}
         //@会员功能
         $comment = $data['content'];
         $pattern = "/@([^@^\\s^:]{1,})([\\s\\:\\,\\;]{0,1})/";
         preg_match_all($pattern, $comment, $matches);
         $matches[1] = array_unique($matches[1]);
         foreach ($matches[1] as $u) {
             if ($u) {
                 //var_dump($u);
                 $res = $this->user_m->get_user_msg('', $u);
                 if ($res['uid']) {
                     $search[] = '@' . $u;
                     $replace[] = '<a target="_blank" href="' . site_url('user/profile/' . $res['uid']) . '" >@' . $u . '</a>';
                     if ($this->uid != $res['uid']) {
                         //@提醒someone
                         $this->load->model('notifications_m');
                         $this->notifications_m->notice_insert($data['topic_id'], $this->uid, $res['uid'], 1);
                         //更新接收人的提醒数
                         $this->db->set('notices', 'notices+1', FALSE)->where('uid', $res['uid'])->update('users');
                     }
                 }
             }
         }
         $data['content'] = str_replace(@$search, @$replace, $comment);
         //入库
         $this->load->model('comment_m');
         $this->comment_m->add_comment($data);
         //更新用户的回复数/最后发贴时间
         $this->db->set('replies', 'replies+1', FALSE)->set('lastpost', time(), false)->where('uid', $this->uid)->update('users');
         //返回callback
         $user = $this->db->select('lastpost')->where('uid', $this->uid)->get('users')->row_array();
         $callback['lastpost'] = @$user['lastpost'];
         echo json_encode($callback);
         //更新回复数,最后回复用户,最后回复时间,更新时间,ord时间
         $this->load->model('topic_m');
         $this->topic_m->set_top($this->input->post('topic_id'), $this->input->post('is_top'), 1);
         //已更新时间
         $this->db->set('ruid', $this->session->userdata('uid'), FALSE)->set('comments', 'comments+1', FALSE)->set('lastreply', time(), FALSE)->where('topic_id', $this->input->post('topic_id'))->update('topics');
         ////回复提醒作者
         $topic = $this->db->select('uid')->where('topic_id', $data['topic_id'])->get('topics')->row_array();
         if ($this->uid != $topic['uid']) {
             $this->load->model('notifications_m');
             $this->notifications_m->notice_insert($data['topic_id'], $this->uid, $topic['uid'], 0);
             //更新作者的提醒数
             $this->db->set('notices', 'notices+1', FALSE)->where('uid', $topic['uid'])->update('users');
         }
         //更新统计
         $this->db->set('value', 'value+1', false)->where('item', 'total_comments')->update('site_stats');
         $stats = $this->db->where('item', 'today_topics')->get('site_stats')->row_array();
         if (!is_today(@$stats['update_time'])) {
             $this->db->set('value', @$stats['value'], false)->set('update_time', time(), false)->where('item', 'yesterday_topics')->update('site_stats');
             $value = 1;
         } else {
             $value = 'value+1';
         }
         $this->db->set('value', $value, false)->set('update_time', time(), false)->where('item', 'today_topics')->update('site_stats');
         //更新会员积分
         $this->config->load('userset');
         $this->user_m->update_credit($this->uid, $this->config->item('credit_reply'));
         $this->user_m->update_credit($topic['uid'], $this->config->item('credit_reply_by'));
         //更新数据库缓存
         $this->db->cache_delete('/default', 'index');
     }
     //		$this->load->library('myclass');
     //		$this->myclass->notice('window.history.go(-1);');
 }
function transform_timestamp($timestamp)
{
    $cache = explode(' ', $timestamp);
    if (count($cache) > 1) {
        if (is_today(transform_date($cache[0], 'eng_to_dt'))) {
            $stamp = $cache[1];
        } else {
            $stamp = $cache[1] . ' ' . transform_date($cache[0], 'eng_to_dt');
        }
    } else {
        $stamp = False;
    }
    return $stamp;
}
Esempio n. 3
0
 public function del($topic_id, $node_id, $uid)
 {
     $data['title'] = '删除贴子';
     //权限修改判断
     if ($this->auth->is_admin() || $this->auth->is_master($node_id)) {
         //$this->myclass->notice('alert("确定要删除此话题吗!");');
         //删除贴子及它的回复
         if ($this->topic_m->del_topic($topic_id, $node_id, $uid)) {
             $this->load->model('comment_m');
             $this->comment_m->del_comments_by_topic_id($topic_id, $uid);
             //更新统计
             $this->db->set('value', 'value-1', false)->where('item', 'total_topics')->update('site_stats');
             $stats = $this->db->where('item', 'today_topics')->get('site_stats')->row_array();
             $value = is_today(@$stats['update_time']) ? 'value-1' : 0;
             $this->db->set('value', $value, false)->set('update_time', time(), false)->where('item', 'today_topics')->update('site_stats');
             //更新会员积分
             $this->config->load('userset');
             $this->load->model('user_m');
             $this->user_m->update_credit($uid, $this->config->item('credit_del'));
             //更新数据库缓存
             $this->db->cache_delete('/default', 'index');
             show_message('删除贴子成功!', site_url('/node/show/' . $node_id));
         }
     } else {
         show_message('您无权删除此贴', site_url('/topic/show/' . $topic_id));
     }
 }
Esempio n. 4
0
function future_date($datetime)
{
    $days = array('', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
    $months = array('', 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre');
    $timestamp = datetime2timestamp($datetime);
    $heure = ' à ' . date('G', $timestamp) . 'H';
    $mn = date('i', $timestamp);
    if ($mn == '00') {
        $mn = '';
    }
    if ($heure == ' à 0H') {
        $heure = '';
        $mn = '';
    }
    if (is_today($timestamp)) {
        return 'aujourd\'hui ' . $heure . $mn;
    } else {
        if (is_tomorrow($timestamp)) {
            return 'demain ' . $heure . $mn;
        } else {
            if (is_tomorrow2($timestamp)) {
                return 'après demain ' . $heure . $mn;
            } else {
                return $days[date('N', $timestamp)] . '  ' . date('j', $timestamp) . ' ' . $months[date('n', $timestamp)] . ' ' . $heure . $mn;
            }
        }
    }
}
Esempio n. 5
0
function get_day_down_file($stat_time, $stat_type = 'd_day', $cate_id = 0, $uid = 0, $num = 10)
{
    global $db, $tpf;
    $sql_uid = $uid ? " and dd.userid='{$uid}'" : '';
    $q = $db->query("select fl.file_id,file_name,file_extension,file_time,file_size from {$tpf}files fl," . get_table_day_down() . " dd where dd.{$stat_type}='{$stat_time}' and fl.file_id=dd.file_id and in_share=1 and cate_id='{$cate_id}' and is_del=0 {$sql_uid} order by dd.down_count desc limit {$num}");
    $file = array();
    while ($rs = $db->fetch_array($q)) {
        $tmp_ext = $rs['file_extension'] ? '.' . $rs['file_extension'] : "";
        $rs['file_name'] = filter_word($rs['file_name'] . $tmp_ext);
        $rs['a_viewfile'] = urr("viewfile", "file_id={$rs['file_id']}");
        $rs['file_time'] = is_today($rs['file_time']) ? '<span class="txtred" style="float:right">' . date('m/d', $rs['file_time']) . '</span>' : '<span class="txtgray" style="float:right">' . date('m/d', $rs['file_time']) . '</span>';
        $rs['file_icon'] = file_icon($rs['file_extension']);
        $rs[file_size] = '<span class="txtgray" style="float:right">' . get_size($rs[file_size]) . '</span>';
        $file[] = $rs;
    }
    $db->free($q);
    unset($rs);
    return $file;
}