示例#1
0
 /**
  * 添加帖子
  * 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, '提示信息:你所在的用户组状态异常!');
         }
     }
 }
示例#2
0
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                $sFilePath2 = $sServerDir . "origin/" . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '201';
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath2);
                    $t = new ThumbHandler();
                    $t->setSrcImg($sFilePath2);
                    $t->setDstImg($sFilePath);
                    $t->createImg(400, 400);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        $oldumask = umask(0);
                        chmod($sFilePath, $permissions);
                        umask($oldumask);
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}
示例#3
0
    }
    if ($checkExt) {
        $info = 'E|图片格式不正确,格式必须为jpg、png、gif之一。';
    } else {
        if ($f_size > 2000 * 1024) {
            $info = 'E|文件大小不能超过2M。';
        } else {
            $random = rand(100, 999);
            $f_fullname = time() . $random . "." . $f_ext;
            $f_path = "userfiles/license/" . $f_fullname;
            $f_path_s = "userfiles/license/small/" . $f_fullname;
            if (copy($f_tmpName, "../" . $f_path)) {
                if ($f_ext == "jpg") {
                    $t = new ThumbHandler();
                    $t->setSrcImg("../" . $f_path);
                    //$t->setCutType(1);
                    $t->setDstImg("../" . $f_path_s);
                    $t->createImg(200, 150);
                    $f_path = $f_path_s;
                } else {
                    copy("../" . $f_path, "../" . $f_path_s);
                }
                $info = "S|" . $f_fullname;
            } else {
                $info = 'E|图片保存的目标文件夹不存在或无写权限。';
            }
        }
    }
    @unlink($_FILES[$fileElementName]);
}
echo $info;
	$t3->setMaskTxtPct(20);
	$t3->setDstImg(dirname(__FILE__).'/'.'out.jpg');	
	$t3->setMaskOffsetX(83);
	$t3->setMaskOffsetY(111);
	$t3->setMaskWord($con3);
	$t3->createImg(100);
	
	// 第四个水印
	// $uinfo = OpenSDK_Tencent_Weibo::call('user/info');
	$t4 = new ThumbHandler();
	$t4->setSrcImg(dirname(__FILE__).'/'.'out.jpg');
	$t4->setMaskFont("upload/simkai.ttf");
	$t4->setMaskFontSize(14);
	$t4->setMaskFontColor("#FF0000");
	$t4->setMaskTxtPct(20);
	$t4->setDstImg(dirname(__FILE__).'/'.'out.jpg');	
	$t4->setMaskOffsetX(150-$w/2);
	$t4->setMaskOffsetY(308);
	$t4->setMaskWord($userinfo);
	$t4->createImg(100);

	
}
//发送图片微博
if(file_exists('out.jpg')){
	if(isset($_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN]) && isset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET])){
	
		$result = OpenSDK_Tencent_Weibo::call('t/add_pic', array(
				'content' => "{$con}",//这里读取内容
				'clientip' => '123.119.32.253',
			), 'POST', array(
示例#5
0
 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);
             }
         }
     }
 }
示例#6
0
 /**
  * 添加评论/回复
  * 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, '提示信息:参数错误!');
         }
     }
 }
示例#7
0
 function watermark($pic_path, $options = array())
 {
     $sys_config = jconf::get();
     if (!$sys_config['watermark_enable']) {
         return false;
     }
     if (!is_image($pic_path)) {
         return false;
     }
     $ims = @getimagesize($pic_path);
     if (in_array($ims['mime'], array('image/gif'))) {
         return false;
     }
     $new_pic_path = $options['new_pic_path'];
     if ('' == $new_pic_path) {
         $new_pic_path = $pic_path;
     }
     $image_quality = (int) $options['image_thumb_quality'];
     if ($image_quality < 1 || $image_quality > 100) {
         $image_quality = 100;
     }
     require_once ROOT_PATH . 'include/ext/thumb.class.php';
     $_thumb = new ThumbHandler();
     $_thumb->setSrcImg($pic_path);
     $_thumb->setDstImg($new_pic_path);
     $_thumb->setImgCreateQuality($image_quality);
     $_thumb->setMaskPosition($sys_config['watermark_position']);
     $_thumb->setMaskFontColor($sys_config['watermark_contents_color']);
     $_thumb->setMaskFontSize(max((int) $sys_config['watermark_contents_size'], 12));
     $watermark = $options['watermark'];
     if ('' == trim($watermark)) {
         $member_info = $options['member_info'];
         if (!$member_info) {
             $uid = (int) $options['uid'];
             $member_info = $uid > 0 ? jsg_member_info($uid) : array();
         }
         $username = $member_info['username'] ? $member_info['username'] : MEMBER_NAME;
         $nickname = $member_info['nickname'] ? $member_info['nickname'] : MEMBER_NICKNAME;
         if ($sys_config['watermark_contents'] && is_array($sys_config['watermark_contents'])) {
             if (in_array('nickname', $sys_config['watermark_contents']) && in_array('url', $sys_config['watermark_contents'])) {
                 $_thumb->setMaskOffsetY(40);
                 $_thumb->setMaskWord($sys_config['site_url'] . "/" . $username);
                 $_thumb->createImg(100);
                 $_thumb->setMaskOffsetY(10);
                 $options['watermark'] = '@' . $nickname;
                 return $this->watermark($pic_path, $options);
             } else {
                 if (in_array('nickname', $sys_config['watermark_contents'])) {
                     $watermark = '@' . $nickname;
                 } else {
                     $watermark = $sys_config['site_url'] . "/" . $username;
                 }
             }
         } else {
             $watermark = $sys_config['site_url'] . "/" . $username;
         }
     }
     if (is_file($watermark)) {
         $_thumb->setMaskImgPct(100);
         $_thumb->setMaskImg($watermark);
     } else {
         $mask_word = (string) $watermark;
         if ($sys_config['watermark_contents'] && in_array('nickname', $sys_config['watermark_contents']) && is_file(RELATIVE_ROOT_PATH . 'images/jsg.ttf')) {
             $_thumb->setMaskFont(RELATIVE_ROOT_PATH . 'images/jsg.ttf');
             $mask_word = array_iconv($sys_config['charset'], 'utf-8', $mask_word);
         } elseif (preg_match('~[\\x7f-\\xff][\\x7f-\\xff]~', $mask_word)) {
             $mask_word = $sys_config['site_url'];
         }
         $_thumb->setMaskWord($mask_word);
     }
     return $_thumb->createImg(100);
 }
 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);
 }
示例#9
0
        $src_y = $this->getImgHeight($src);
        $new_im = imagecreatetruecolor($src_x, $src_y);
        for ($y = 0; $y < $src_y; $y++) {
            imagecopy($new_im, $src, 0, $src_y - $y - 1, 0, $y, $src_x, 1);
        }
        $this->h_src = $new_im;
    }
    /**
     * 水平翻转
     *
     * @param    string     $src    图片源
     */
    function _flipH($src)
    {
        $src_x = $this->getImgWidth($src);
        $src_y = $this->getImgHeight($src);
        $new_im = imagecreatetruecolor($src_x, $src_y);
        for ($x = 0; $x < $src_x; $x++) {
            imagecopy($new_im, $src, $src_x - $x - 1, 0, $x, 0, 1, $src_y);
        }
        $this->h_src = $new_im;
    }
}
$t = new ThumbHandler();
// 基本使用
$t->setSrcImg("./bg_login.jpg");
$t->setMaskWord("test");
$t->setDstImgBorder(10, "#dddddd");
$t->setDstImg("./new_test.jpg");
// 指定缩放比例
$t->createImg(170, 170);
示例#10
0
文件: attach.php 项目: a195474368/ejw
 public static function file_upload($field, $index = -1, $type, $config)
 {
     global $_G;
     //本地文件名称
     $local = $index > -1 && is_int($index) ? $_FILES[$field]["name"][$index] : $_FILES[$field]["name"];
     //错误信息
     $error = $index > -1 && is_int($index) ? $_FILES[$field]["error"][$index] : $_FILES[$field]["error"];
     //没有上传文件或出错
     if (!$local || $error) {
         return 1;
     }
     //文件大小
     $size = $index > -1 && is_int($index) ? $_FILES[$field]["size"][$index] : $_FILES[$field]["size"];
     //临时名称
     $temp = $index > -1 && is_int($index) ? $_FILES[$field]["tmp_name"][$index] : $_FILES[$field]["tmp_name"];
     //当前文件类型
     $mime = fileext($local);
     //不被允许的类型
     if (!in_array($mime, $type)) {
         return 2;
     }
     //搜索所在分类
     foreach ($_G['upload'] as $item => $array) {
         //定位到分类
         if (in_array($mime, $array)) {
             //文件分类
             $cate = $item;
             break;
         }
     }
     //文件类型不在上传配置中
     if (!$cate) {
         return 3;
     }
     //根文件夹
     $folder = VI_ROOT . 'attach/' . $cate;
     //创建子文件夹
     if (!file_exists($folder)) {
         create_dir($folder);
     }
     //限制文件大小
     if (is_int($config["size"]) && $size > $config["size"]) {
         return 4;
     }
     /*******保存文件_开始*******/
     //创建目录
     $path = create_dir($folder . "/" . date("Y/md/"));
     //生成文件名
     $name = $path . date("H-i-s-") . mt_rand() . "." . $mime;
     //移动文件失败
     if (!copy(realpath($temp), $name)) {
         return 5;
     }
     /*******保存文件_结束*******/
     //图片则计算尺寸
     $width = $height = 0;
     if ($cate == "image") {
         //返回图片尺寸
         list($width, $height) = getimagesize($name);
         //包含类
         require_once VI_ROOT . 'source/class/thumb.php';
         //生成缩略图
         if (is_array($config["thumb"])) {
             //缩略图
             $t = new ThumbHandler();
             //源图片地址
             $t->setSrcImg($name);
             //输出文件名
             $t->setDstImg(str_replace("." . $mime, "-thumb." . $mime, $name));
             //生成图片
             $t->createImg($config["thumb"][0], $config["thumb"][1]);
         }
         //生成组图
         if (is_array($config["group"])) {
             foreach ($config["group"] as $g) {
                 if (is_array($g)) {
                     //缩略图
                     $t = new ThumbHandler();
                     //源图片地址
                     $t->setSrcImg($name);
                     //输出文件名
                     $t->setDstImg(str_replace("." . $mime, "-" . $g[0] . "-" . $g[1] . "." . $mime, $name));
                     //生成图片
                     $t->createImg($g[0], $g[1]);
                 }
             }
         }
         //生成裁切图
         if (is_array($config["crop"])) {
             //缩略图
             $t = new ThumbHandler();
             //源图片地址
             $t->setSrcImg($name);
             //输出文件名
             $t->setDstImg($name);
             //生成图片
             $t->createImg($config["crop"][0], $config["crop"][1]);
         }
     }
     //exit(  );
     //合并路径
     $file = url_merge(str_replace(VI_ROOT, "", VI_BASE . $name));
     //echo $file;
     //exit($file);
     //写入数据库
     $sql = "INSERT INTO `sys:attach`(name,input,dateline,type,size,ip,width,height,remote) values('" . $file . "','" . $field . "'," . time() . ",'" . $mime . "',{$size},'" . GetIP() . "',{$width},{$height},0)";
     System::$db->execute($sql);
     //返回文件名
     return $file;
 }