/** * 添加帖子 * Enter description here ... */ public function add() { $cmd = $this->input->post('cmd'); if ($cmd && $cmd == 'submit') { /*接收到的参数*/ $circle_id = $this->input->post('circle_id'); //圈子ID $create_id = $this->input->post('create_id'); //作者ID $allow_reply = $this->input->post('allow_reply'); //是否允许评论 $content = $this->input->post('content'); //帖子内容 $province = $this->input->post('province'); //定位省份 $city = $this->input->post('city'); //定位城市 $district = $this->input->post('district'); //定位区域 $street = ''; //定位街道 $picnum = $this->input->post('picnum'); //上传的图片数量 $circle = $this->CircleModel->getModel('id=' . $circle_id); //查询去圈子信息 $member = $this->MemberModel->getModel('id=' . $create_id); //匹配内容中的话题 $pattern = '/#(.*)#/'; preg_match($pattern, $content, $matches); if ($matches) { $topic = split(' ', $matches[0]); foreach ($topic as $item) { //循环将话题替代成话题连接 if (!empty($item)) { $content = str_replace($item, '<a style="display:inline;" href="index.php?post&cmd=detail_topic&keyword=' . urlencode(rtrim(substr($item, 1), '#')) . '">' . $item . '</a>', $content); } } } //匹配内容中的@好友 $relation = array(); $pattern = '/@(.*) /'; preg_match($pattern, $content, $matches); if ($matches) { $sis = split(' ', $matches[0]); foreach ($sis as $item) { //循环将话题替代成话题连接 if (!empty($item)) { //根据用户名查询用户信息 $mem = $this->MemberModel->getModel("nick_name='" . substr($item, 1) . "'"); if ($mem) { $content = str_replace($item, '<a style="display:inline;" href="index.php?member&cmd=zone&id=' . $mem['id'] . '">' . $item . '</a>', $content); $relation[] = $mem; } } } } //匹配内容中的[表情] $pattern = '/\\[(.*)\\] /'; preg_match($pattern, $content, $matches); if ($matches) { $icon = split(' ', $matches[0]); foreach ($icon as $item) { //循环将话题替代成话题连接 if (!empty($item)) { $ic = $this->IconsModel->getModel("code='" . $item . "'"); if ($ic) { $content = str_replace($item, '<img src="/uploadfile/images/faces/' . $ic['name'] . '" style="width:25px;height:25px;display:inline;">', $content); } } } } //添加帖子 $dataArray = array('circle_id' => $circle_id, 'content' => ltrim($content), 'allow_reply' => $allow_reply, 'create_id' => $member['id'], 'contains_pic' => $picnum ? '1' : '0', 'province' => $province, 'city' => $city, 'district' => $district, 'street' => $street, 'create_time' => now()); $flag = $this->PostModel->add($dataArray); if ($flag) { if ($picnum) { //上传图片 for ($i = 0; $i < $picnum; $i++) { //循环上传图片 //保存图片 $img = str_replace('data:image/png;base64,', '', $_POST['image_data' . $i]); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $path = "../uploadfile/images/topic/"; $fileName = uniqid() . '.png'; $file = $path . $fileName; $success = file_put_contents($file, $data); if ($success) { /**原图上传完成,生成最大高度/宽度76的小图**/ $t = new ThumbHandler(); // 生成缩略图 $t->setSrcImg($file); $t->setCutType(1); $t->setDstImg($path . "thumb/" . $fileName); // 指定固定宽高 $t->createImg(152, 152); $dataArray = array('post_id' => $flag, 'name' => '/uploadfile/images/topic/' . $fileName, 'thumb' => '/uploadfile/images/topic/thumb/' . $fileName, 'create_time' => now()); $this->PostImageModel->add($dataArray); } } } //查询用户是否完成新手任务 $task = $this->TaskModel->getModel("name='新手任务' AND remark='首次发表一个话题' AND create_id=" . $member['id']); if (!$task) { $dataArray = array('name' => '新手任务', 'remark' => '首次发表一个话题', 'create_id' => $member['id'], 'create_time' => now()); $this->TaskModel->add($dataArray); //新增任务表信息 $dataArray = array('point_type' => 1, 'points' => 20, 'remark' => "完成新手任务,首次发表一个话题", 'ip' => GetIP(), 'create_id' => $member['id'], 'create_time' => now()); $this->PointRecordsModel->add($dataArray); //新增积分记录表 $this->MemberModel->edit(array('points' => $member['points'] + 20), 'id=' . $member['id']); //更新用户积分 } else { //查询用户是否完成今日任务 $task = $this->TaskModel->getModel("(name='每日奖励' AND remark='发表一个话题' AND FROM_UNIXTIME(create_time,'%Y-%m-%d') = '" . date("Y-m-d", now()) . "' AND create_id=" . $member['id'] . ") OR (name='新手任务' AND remark='首次发表一个话题' AND FROM_UNIXTIME(create_time,'%Y-%m-%d') = '" . date("Y-m-d", now()) . "' AND create_id=" . $member['id'] . ")"); if (!$task) { $dataArray = array('name' => '每日奖励', 'remark' => '发表一个话题', 'create_id' => $member['id'], 'create_time' => now()); $this->TaskModel->add($dataArray); //新增任务表信息 $dataArray = array('point_type' => 1, 'points' => 10, 'remark' => "完成新手任务,首次发表一个话题", 'ip' => GetIP(), 'create_id' => $member['id'], 'create_time' => now()); $this->PointRecordsModel->add($dataArray); $this->MemberModel->edit(array('points' => $member['points'] + 10), 'id=' . $member['id']); } } if ($relation) { foreach ($relation as $rela) { //发送短消息 $dataArray = array('parent_id' => 0, 'sub_id' => $flag, 'sub_type' => 1, 'message_type' => 1, 'member_id' => $rela['id'], 'content' => '我在帖子中呼唤你,速速回应~', 'is_read' => 0, 'create_id' => $member['id'], 'create_time' => now()); $re = $this->MessageModel->add($dataArray); //更新留言数据 $this->MemberModel->edit(array('mess_num' => (int) $rela['mess_num'] + 1), 'id=' . $rela['id']); } } //更新圈子话题数量 $this->CircleModel->edit(array('topic_num' => (int) $circle['topic_num'] + 1), 'id=' . $circle_id); //更新话题数量 $this->MemberModel->edit(array('topic_num' => (int) $member['topic_num'] + 1), 'id=' . $member['id']); show_error('index.php/EditorPost/index', 500, '提示信息:帖子发表成功!'); } else { show_error('index.php/EditorPost/add', 500, '提示信息:帖子发表失败!'); } } else { $user = $this->user; //登录用户 $role = $this->RoleModel->getRole('id=' . $user['role_id']); //登录用户角色 if ($role) { $icons = $this->IconsModel->GetList('1=1'); //表情数据 $sis = $this->MemberModel->getList(''); $circle = $this->CircleModel->getList('pid<>0'); //所有圈子数据 $strWhere = ''; //超级管理员可以查看所有系统会员 if ($role['level'] == '1') { $strWhere = 'create_id<>0'; } else { if ($role['level'] == '2') { //管理员可以查看所有系统会员[不包含超级管理员添加的会员] $strWhere = 'create_id<>0 AND create_id<>1'; } else { if ($role['level'] == '3') { //3级管理员可以查看所有下级会员及自己创建的会员 $strWhere = 'create_id=' . $user['id'] . ' OR create_id IN (SELECT id FROM jooli_user WHERE role_id IN (SELECT id FROM jooli_role WHERE pid=' . $role['id'] . '))'; } else { if ($role['level'] == '4') { //4级管理员可以查看所有自己创建的会员 $strWhere = 'create_id=' . $user['id']; } } } } $author = $this->MemberModel->getList($strWhere); $this->load->view('EditorPost/add', array('circle' => $circle, 'icons' => $icons, 'sis' => $sis, 'author' => $author)); } else { show_error('index.php/Index/index', 500, '提示信息:你所在的用户组状态异常!'); } } }
/** * 添加评论/回复 * Enter description here ... */ public function add() { $cmd = $this->input->post('cmd'); if ($cmd && $cmd == 'submit') { /*接收到的参数*/ $parent_id = $this->input->post('pid'); //上级ID,例如:回复的上级ID为回复对象的ID $sub_id = $this->input->post('sub_id'); //评论/回复对象ID $create_id = $this->input->post('create_id'); //评论人 $content = $_POST['content']; //评论/回复内容 $image = $_POST['image_data']; //评论内容的图片数据 $action = $this->input->post('action'); $post = $this->PostModel->getModel('id=' . $sub_id); $creater = $this->MemberModel->getModel('id=' . $create_id); if ($post && $content && $creater) { if ($image) { //保存图片 $img = str_replace('data:image/png;base64,', '', $image); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $path = "../uploadfile/images/comment/"; $fileName = uniqid() . '.png'; $file = $path . $fileName; $success = file_put_contents($file, $data); if ($success) { /**原图上传完成,生成最大高度/宽度76的小图**/ $t = new ThumbHandler(); // 生成缩略图 $t->setSrcImg($file); $t->setCutType(1); $t->setDstImg($path . "thumb/" . $fileName); // 指定固定宽高 $t->createImg(152, 152); $image = $fileName; } } //匹配内容中的话题 $pattern = '/#(.*)#/'; preg_match($pattern, $content, $matches); if ($matches) { $topic = split(' ', $matches[0]); foreach ($topic as $item) { //循环将话题替代成话题连接 if (!empty($item)) { $content = str_replace($item, '<a style="display:inline;" href="index.php?post&cmd=detail_topic&keyword=' . rtrim(substr($item, 1), '#') . '">' . $item . '</a>', $content); } } } //匹配内容中的@好友 $relation = array(); $pattern = '/@(.*) /'; preg_match($pattern, $content, $matches); if ($matches) { $sis = split(' ', $matches[0]); foreach ($sis as $item) { //循环将话题替代成话题连接 if (!empty($item)) { //根据用户名查询用户信息 $mem = $this->MemberModel->getModel("nick_name='" . substr($item, 1) . "'"); if ($mem) { $content = str_replace($item, '<a style="display:inline;" href="index.php?member&cmd=zone&id=' . $mem['id'] . '">' . $item . '</a>', $content); $relation[] = $mem; } } } } //匹配内容中的[表情] $pattern = '/\\[(.*)\\] /'; preg_match($pattern, $content, $matches); if ($matches) { $icon = split(' ', $matches[0]); foreach ($icon as $item) { //循环将话题替代成话题连接 if (!empty($item)) { $ic = $this->IconsModel->getModel("code='" . $item . "'"); if ($ic) { $content = str_replace($item, '<img src="' . $ic['name'] . '" style="width:25px;height:25px;display:inline;">', $content); } } } } $dataArray = array('parent_id' => $parent_id, 'sub_id' => $post['id'], 'sub_type' => 1, 'content' => $content, 'content_pic' => $image ? "/uploadfile/images/comment/" . $image : "", 'thumb' => $image ? "/uploadfile/images/comment/thumb/" . $image : "", 'create_id' => $creater['id'], 'create_time' => now()); $flag = $this->CommentModel->add($dataArray); if ($flag) { if ($parent_id == '0') { $this->PostModel->edit(array('reply_num' => (int) $post['reply_num'] + 1), 'id=' . $post['id']); } //查询用户是否完成新手任务 $task = $this->TaskModel->getModel("name='新手任务' AND remark='首次回复一个话题' AND create_id=" . $creater['id']); if (!$task) { $dataArray = array('name' => '新手任务', 'remark' => '首次回复一个话题', 'create_id' => $creater['id'], 'create_time' => now()); $flag = $this->TaskModel->Add($dataArray); if ($flag) { $dataArray = array('point_type' => 1, 'points' => 20, 'remark' => "完成新手任务,首次回复一个话题", 'ip' => GetIP(), 'create_id' => $creater['id'], 'create_time' => now()); $r = $this->PointRecordsModel->add($dataArray); if ($r) { $this->MemberModel->edit(array('points' => $creater['points'] + 20), 'id=' . $creater['id']); } } } else { //查询用户是否完成今日任务 $task = $this->TaskModel->getModel("(name='每日奖励' AND remark='回复一个话题' AND FROM_UNIXTIME(create_time,'%Y-%m-%d') = '" . date("Y-m-d", now()) . "' AND create_id=" . $creater['id'] . ") OR (name='新手任务' AND remark='首次回复一个话题' AND FROM_UNIXTIME(create_time,'%Y-%m-%d') = '" . date("Y-m-d", now()) . "' AND create_id=" . $creater['id'] . ")"); if (!$task) { $dataArray = array('name' => '每日奖励', 'remark' => '回复一个话题', 'create_id' => $creater['id'], 'create_time' => now()); $flag = $this->TaskModel->add($dataArray); if ($flag) { $dataArray = array('point_type' => 1, 'points' => 5, 'remark' => "完成新手任务,首次发表一个话题", 'ip' => GetIP(), 'create_id' => $creater['id'], 'create_time' => now()); $r = $this->PointRecordsModel->add($dataArray); if ($r) { $this->MemberModel->edit(array('points' => $creater['points'] + 5), 'id=' . $creater['id']); } } } } if ($relation) { foreach ($relation as $rela) { //发送短消息 $dataArray = array('parent_id' => $parent_id, 'sub_id' => $post['id'], 'sub_type' => 1, 'message_type' => 1, 'member_id' => $rela['id'], 'content' => $parent_id == '0' ? '我在评论中呼唤你,速速回应~' : '我在回复中呼唤你,速速回应~', 'is_read' => 0, 'create_id' => $creater['id'], 'create_time' => now()); $re = $this->MessageModel->add($dataArray); } } show_error('index.php/Comment/add?id=' . $post['id'], 500, '提示信息:评论/回复发表成功!'); } else { show_error('index.php/Comment/add?id=' . $post['id'], 500, '提示信息:评论/回复发表失败!'); } } else { show_error('index.php/' . $action . '/index', 500, '提示信息:帖子/回复内容/回复人不存在!'); } } else { $action = 'EditorPost'; if ($this->input->get('action')) { $action = $this->input->get('action'); } $id = $this->input->get('id'); if ($id) { $post = $this->PostModel->getModel('id=' . $id); if ($post) { $creater = $this->MemberModel->getModel('id=' . $post['create_id']); $comments = $this->CommentModel->getList('sub_id=' . $post['id'] . ' AND sub_type=1 AND status=1 AND is_del=0 ORDER BY id DESC'); //帖子的所有评论及回复 $author = $this->MemberModel->getList('create_id<>0'); //所有系统会员作为评论人 $icons = $this->IconsModel->GetList('1=1'); //表情数据 $sis = $this->MemberModel->getList(''); // 可以@整站会员 $result = array(); //评论/回复集合 if ($comments) { $i = 1; foreach ($comments as $comment) { if ($comment['parent_id'] == '0') { $comment['reply'] = null; $comment['creater'] = null; $comment['member'] = $this->MemberModel->getModel('id=' . $comment['create_id']); $comment['sort'] = $i; $result[] = $comment; } else { //查询该条该回复的上一条评论 $comms = $this->CommentModel->GetList('id=' . $comment['parent_id'] . ' AND status=1 AND is_del=0 AND sub_type=1 AND sub_id=' . $post['id'] . ' ORDER BY id DESC'); if ($comms) { //有回复的评论 foreach ($comms as $comm) { $comm['reply'] = $comment; $comm['creater'] = $this->MemberModel->getModel('id=' . $comment['create_id']); //回复人 $comm['member'] = $this->MemberModel->getModel('id=' . $comm['create_id']); //回复对象 $comm['sort'] = $i; $result[] = $comm; } } } $i++; } } $post_image = array(); if ($post['contains_pic']) { $post_image = $this->PostImageModel->getList('post_id=' . $post['id'] . ' LIMIT 9'); } $this->load->view('Comment/add', array('author' => $author, 'action' => $action, 'post' => $post, 'sis' => $sis, 'icons' => $icons, 'creater' => $creater, 'comments' => $result, 'post_image' => $post_image)); } else { show_error('index.php/' . $action . '/index', 500, '提示信息:您操作的帖子不存在或已被删除!'); } } else { show_error('index.php/' . $action . '/index', 500, '提示信息:参数错误!'); } } }
public function generateUserAvatars($model, $size = 60, $path = 'avatar') { $origion = File::model()->generateFileName($model, $path, true); $src = File::model()->generateFileName($model, $path, true, 150); $des = File::model()->generateFileName($model, $path, true, $size); if (!file_exists($des)) { if (!is_dir(dirname($des))) { UtilHelper::createFolder(dirname($des)); } if (file_exists($src)) { $t = new ThumbHandler(); $t->setSrcImg($src); $t->setCutType(1); //指明为手工裁切 // $t->setSrcCutPosition(100, 100);// 源图起点坐标 $t->setRectangleCut($size, $size); // 裁切尺寸 $t->setImgDisplayQuality(90); $t->setDstImg($des); $t->createImg(150, 150); } elseif (file_exists($origion)) { $t = new ThumbHandler(); $t->setSrcImg($origion); $t->setCutType(2); $t->setSrcCutPosition(0, 0); $t->setRectangleCut($size, $size); $t->setImgDisplayQuality(90); $t->setDstImg($des); $width = $t->getSrcImgWidth(); $height = $t->getSrcImgHeight(); if ($width >= $height) { $t->createImg($height, $height); } else { $t->createImg($width, $width); } } } }
public function actionTest3() { // echo Profile::model()->getUserAvatar(Yii::app()->user->id, array(),200); $src = './public/20bfaca64c6da0436293e020e62c6d5e1327747695.png'; $temp = './public/test_temp.jpg'; $des = './public/test_des.jpg'; $desinfo = array('path' => $des, 'width' => 150, 'height' => 150); $t = new UtilThumbHandle($src); $width = $t->getSrcImgWidth(); $scale = $width / 500; $x = 200; $y = 5; $w = 285; $h = 285; $x = round($scale * $x); $y = round($scale * $y); $w = round($scale * $w); $h = round($scale * $h); $t->createImg($desinfo, $x, $y, $w, $h); // $targ_w = $targ_h = 150; // $jpeg_quality = 90; // // $x = 200; // $y = 5; // $w = 285; // $h = 285; // //// $src = 'public/uploads/1z2977e09zwss.jpg'; // $img_r = imagecreatefromjpeg($src); // // $width = imagesx($img_r); // // $scale = $width/500; // // $x = round($scale*$x); // $y = round($scale*$y); // $w = round($scale*$w); // $h = round($scale*$h); // // // // $dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); // imagecopyresampled($dst_r,$img_r,0,0,$x,$y,$targ_w,$targ_h,$w,$h); // // // header('Content-type: image/jpeg'); // imagejpeg($dst_r,null,$jpeg_quality); // // exit; // $t = new ThumbHandler(); // $t->setSrcImg($src); // $t->setCutType(1);//指明为手工裁切 // $t->setSrcCutPosition(0, 0);// 源图起点坐标 // $t->setRectangleCut(500, 200);// 裁切尺寸 // $t->setDstImg($temp); // $t->createImg(500); $width = 500; $t = new ThumbHandler(); $t->setSrcImg($src); $x = 93; $y = 119; $w = 252; $h = 252; $width = $t->getSrcImgWidth(); $scale = $width / 500; $x = round($scale * $x); $y = round($scale * $y); $w = round($scale * $w); $h = round($scale * $h); // $t->setCutType(1);//指明为手工裁切 // $t->setDstImg($temp); // // $w = $t->getSrcImgWidth(); // $h = $t->getSrcImgHeight(); // // //宽度缩放比例 // $num = ($width/$w)*100; // // $t->createImg($num); // // $t->setSrcImg($temp); $t->setCutType(2); $t->setDstImg($des); $t->setImgDisplayQuality(90); $t->setSrcCutPosition($x, $y); $t->setRectangleCut(150, 150); // echo $t->_getImgType($src); $t->createImg($w, $h); // //// unlink($temp); }