Няма описание

IndexAction.class.php 22KB

    <?php class IndexAction extends Action { var $ss; function _initialize(){ //获取配置文件 $s = M('sysconfig')->order('id asc')->select(); foreach ($s as $v) {$seo[$v['varname']] = $v['value'];} if($seo['webstatus']=='0'){$this->redirect('Home/public/close');} $this->assign('seo', $seo); $this->ss=$seo; if($_SESSION['msg_id'] != ''){ $admin = M("msg") -> where("id = ".$_SESSION['msg_id']."") -> find(); $this -> assign("admin",$admin); } } //清空缓存程序 function qingkong(){ if(isset($_GET['portal'])){ $dirs = array('./data/portal'); } if(isset($_GET['all'])){ $dirs = array('./_runtime'); }else{ //缓存目录 $dirs = array('./Runtime'); } //清理缓存 foreach($dirs as $value) { $this->rmdirr($value); @mkdir($value,0777,true); } } function rmdirr($dirname) { if (!file_exists($dirname)) { return false; } if (is_file($dirname) || is_link($dirname)) { return unlink($dirname); } $dir = dir($dirname); while (false !== $entry = $dir->read()) { if ($entry == '.' || $entry == '..') { continue; } $this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry); } $dir->close(); //return rmdir($dirname); } function xinghao(){ $title = $_POST['title']; $zhuce = M("zhuces") -> where("fid = 1 and title = '".$title."'") -> order("px desc,id desc") -> find(); $rs = M("manu_product_map") -> where("manu_id = '".$zhuce['id']."'") -> select(); $id = "0"; foreach($rs as $key=>$ra){ $id = $id.",".$ra['product_id']; } $zhuces = M("zhuces") -> where("fid = 2 and id in(".$id.")") -> order("px desc,id desc") -> select(); foreach($zhuces as $key=>$rb){ $rc.= "<li onclick=xinghaoen($('.xinghaoen').index($(this))); class='xinghaoen'>".$rb['title']."</li>"; } echo $rc; } //add by xull 20170111 function getcity(){ $id = $_POST['id']; $citys = M("citys") -> where("pid = ".$id) -> order("id asc") -> select(); $rc = ''; foreach($citys as $row){ $rc.= "<li data='".$row['id']."'>".$row['name']."</li>"; } echo $rc; } function index(){ //清空缓存文件 $sysconfig = M("sysconfig") -> where("id = 40") -> find(); if($sysconfig['value'] < time()){ $data['value'] = time()*1 + 24*60*60*30; M("sysconfig") -> where("id = 40") -> save($data); $this -> qingkong(); } //幻灯片 $banner = M("banner") -> where("fid = 1") -> order("px desc,id desc") -> select(); $this -> assign("banner",$banner); //LRC俱乐部会员作品展示 $zuopin1 = M("nav") -> order("px desc,id desc") -> limit(3) -> select(); foreach($zuopin1 as $key=>$rs){ $url = explode("/",$rs['pic']); $thumbPath = "/data/www/tamron/html/data/suoluo/".$url['4']; if(!file_exists($thumbPath)){ $orcPath = "/data/www/tamron/html/data/slide/".$url['3']."/".$url['4']; $pic = $this -> imgZoom("290x290w",$orcPath,$thumbPath); if($pic != ""){ $zuopin1[$key]['pic'] = "/data/suoluo/".$url['4']; } }else{ $zuopin1[$key]['pic'] = "/data/suoluo/".$url['4']; } } $this -> assign("zuopin1",$zuopin1); $zuopin2 = M("nav") -> order("px desc,id desc") -> limit("3,4") -> select(); foreach($zuopin2 as $key=>$rs){ $url = explode("/",$rs['pic']); $thumbPath = "/data/www/tamron/html/data/suoluo/".$url['4']; $pic = "/data/suoluo/".$url['4']; if(file_exists($pic) == ""){ $orcPath = "/data/www/tamron/html/data/slide/".$url['3']."/".$url['4']; $pic = $this -> imgZoom("290x290w",$orcPath,$thumbPath); if($pic != ""){ $zuopin2[$key]['pic'] = "/data/suoluo/".$url['4']; } }else{ echo $zuopin2[$key]['pic'] = "/data/suoluo/".$url['4']; } } $this -> assign("zuopin2",$zuopin2); $zuopin3 = M("nav") -> order("px desc,id desc") -> limit("7,3") -> select(); foreach($zuopin3 as $key=>$rs){ $url = explode("/",$rs['pic']); $thumbPath = "/data/www/tamron/html/data/suoluo/".$url['4']; if(!file_exists($thumbPath)){ $orcPath = "/data/www/tamron/html/data/slide/".$url['3']."/".$url['4']; $pic = $this -> imgZoom("290x290w",$orcPath,$thumbPath); if($pic != ""){ $zuopin3[$key]['pic'] = "/data/suoluo/".$url['4']; } }else{ $zuopin3[$key]['pic'] = "/data/suoluo/".$url['4']; } } $this -> assign("zuopin3",$zuopin3); //LRC俱乐部会员活动 $activity = M("activity") -> where("isindex = 1") -> order("px desc,id desc") -> limit(3) -> select(); $this -> assign("activity",$activity); //留言展示 $liuyan = M("msg_liuyan") -> where("zt = 2") -> order("id desc") -> select(); foreach($liuyan as $k=>$r){ $msg = M("msg") -> where("id = ".$r['msg_id']."") -> find(); $liuyan[$k]['msg_name'] = $msg['user']; } $this -> assign("liuyan",$liuyan); //课堂 $ketang = M("ketang") -> where("isindex = 1") -> order("px desc,id desc") -> limit(7) -> select(); $this -> assign("ketang",$ketang); $this -> assign("msg",'首页'); $this->display(); } public static $convert = 'convert'; //static $convert = '/usr/bin/convert'; /** * @todo 裁切指定尺寸图片 */ public function imgZoom($sizeStr, $orcPath, $thumbPath) { if (!$sizeStr || !$orcPath || !$thumbPath) return false; if (!preg_match("/\d+x\d+/", $sizeStr, $match)) return false; $quality = 100; #图片的压缩品质 $size = $match[0]; $lastChar = substr($sizeStr, -1, 1); #获得最后一个字符,从而进一步处理 if ("c" == $lastChar) { #正方形的压缩 $flag = $this->makeThumbPicBySquare(array( 'srcPath' => $orcPath, #要转换的图片路径 'desPath' => $thumbPath, #生成的图片路径 'size' => $size, #要压缩的尺寸 'isCenter' => 1, #是否居中 'quality' => $quality, #图片品质 'stripExif' => 1, #是否去掉Exif信息 )); } elseif ("w" == $lastChar) { #限制宽的压缩 $flag = $this->makeThumbPicByWidth(array( 'srcPath' => $orcPath, #要转换的图片路径 'desPath' => $thumbPath, #生成的图片路径 'size' => $size, #要压缩的尺寸 'quality' => $quality, #图片品质 'stripExif' => 1, #是否去掉Exif信息 )); } elseif ("h" == $lastChar) { #限制高的压缩 $flag = $this->makeThumbPicByHeight(array( 'srcPath' => $orcPath, #要转换的图片路径 'desPath' => $thumbPath, #生成的图片路径 'size' => $size, #要压缩的尺寸 'quality' => $quality, #图片品质 'stripExif' => 1, #是否去掉Exif信息 )); } else { #普通的压缩模式 $flag = $this->makeThumbPicBySize(array( 'srcPath' => $orcPath, #要转换的图片路径 'desPath' => $thumbPath, #生成的图片路径 'size' => $size, #要压缩的尺寸 'quality' => $quality, #图片品质 'stripExif' => 1, #是否去掉Exif信息 )); } return $flag ? $thumbPath : false; } /** * 压缩图片 定宽定高 */ private function makeThumbPicBySize($paramArr) { $options = array( 'srcPath' => '', #源文件路径 'desPath' => '', #目标文件路径 'size' => '', #要压缩的图片尺寸,如100x80 'quality' => 100, #图片品质 'stripExif' => true, #是否去掉Exif信息 拍摄相机信息等,除非显示拍摄相机的需求,否则无用 ); if (is_array($paramArr)) $options = array_merge($options, $paramArr); extract($options); $sign = false; $info = self::getImgInfo(array('path' => $srcPath)); $sizeArr = explode('x', $size); $scaleW = $sizeArr[0] / $info['width']; //对比宽度 $scaleH = $sizeArr[1] / $info['height']; if ($scaleW < 1 || $scaleH < 1) { $sys = "convert -resize {$size} {$srcPath} {$desPath}"; system($sys); $sign = file_exists($desPath); #对图片进行优化 self::optimizeJpg(array('srcPath' => $desPath, 'stripExif' => $stripExif)); } else { //当要压的图比想要的缩略图还小时,不压了 $sign = copy($srcPath, $desPath); } return $sign; } /** * 压缩图片,定宽 */ private function makeThumbPicByWidth($paramArr) { $options = array( 'srcPath' => '', #源文件路径 'desPath' => '', #目标文件路径 'size' => '', #要压缩的图片尺寸,如100x80 'quality' => 100, #图片品质 'stripExif' => true, #是否去掉Exif信息 拍摄相机信息等,除非显示拍摄相机的需求,否则无用 ); if (is_array($paramArr)) $options = array_merge($options, $paramArr); extract($options); $sign = false; $info = self::getImgInfo(array('path' => $srcPath)); $sizeArr = explode('x', $size); $scale = $sizeArr[0] / $info['width']; //对比宽度 if ($scale < 1) { $sys = "convert -geometry " . $sizeArr[0] . "x -quality $quality +profile '*' $srcPath $desPath"; system($sys); $sign = file_exists($desPath); #对图片进行优化 self::optimizeJpg(array('srcPath' => $desPath, 'stripExif' => $stripExif)); } else { //当要压的图比想要的缩略图还小时,不压了 $sign = copy($srcPath, $desPath); } return $sign; } /** * 压缩图片,定高 */ private function makeThumbPicByHeight($paramArr) { $options = array( 'srcPath' => '', #源文件路径 'desPath' => '', #目标文件路径 'size' => '', #要压缩的图片尺寸,如100x80 'quality' => 100, #图片品质 'stripExif' => true, #是否去掉Exif信息 拍摄相机信息等,除非显示拍摄相机的需求,否则无用 ); if (is_array($paramArr)) $options = array_merge($options, $paramArr); extract($options); $sign = false; $info = self::getImgInfo(array('path' => $srcPath)); $sizeArr = explode('x', $size); $scale = $sizeArr[1] / $info['height']; //对比高度 if ($scale < 1) { $sys = "convert -geometry x" . $sizeArr[1] . " -quality $quality +profile '*' $srcPath $desPath"; system($sys); $sign = file_exists($desPath); #对图片进行优化 self::optimizeJpg(array('srcPath' => $desPath, 'stripExif' => $stripExif)); } else { //当要压的图比想要的缩略图还小时,不压了 $sign = copy($srcPath, $desPath); } return $sign; } /** * 取方图 */ private function makeThumbPicBySquare($paramArr) { $options = array( 'srcPath' => '', #源文件路径 'desPath' => '', #目标文件路径 'size' => '', #要压缩的图片尺寸,如100x80 'position' => 0, #是否从中部中截取 'offset' => -1, #裁图 'quality' => 100, #图片品质 'stripExif' => true, #是否去掉Exif信息 拍摄相机信息等,除非显示拍摄相机的需求,否则无用 ); if (is_array($paramArr)) $options = array_merge($options, $paramArr); extract($options); if (!$srcPath || !$size || !$desPath) return false; $posArr = array('leftUp', 'middleUp', 'rightUp', 'leftMiddle', 'middleMiddle', 'rightMiddle', 'leftBottom', 'middleBottom', 'rightBottom'); $pos = $position == 0 ? 'middleMiddle' : $posArr[$position - 1]; if (!$pos) $pos = 'middleMiddle'; #获得图片的信息 $info = self::getImgInfo(array('path' => $srcPath)); $imgHeight = $info["height"]; $imgWidth = $info["width"]; list($zoomWidth, $zoomHeight) = explode("x", $size); #要压缩的尺寸 $srcSize = $imgWidth . 'x' . $imgHeight; $newSize = $size; $newSizeArr = explode('x', $newSize); if ($imgWidth < $zoomWidth || $imgHeight < $zoomHeight) { //这里比较特殊 copy($srcPath, $desPath); return true; } $scale = min($zoomWidth / $imgWidth, $zoomHeight / $imgHeight); #原图比例 $srcCate = $imgWidth / $imgHeight; #目标图比例 $newSrcCate = $zoomWidth / $zoomHeight; #截取位置 $offset = $offset; $beishu = 1; #切割 if ($offset >= 0) { if ($imgWidth >= $zoomWidth && $imgHeight >= $zoomHeight) { if ($imgWidth <= $imgHeight) { $sHeight = round($zoomWidth * $imgHeight / $imgWidth); $newSize = $zoomWidth . 'x' . $zoomHeight; if ($imgHeight >= $offset) { $sys = ' -resize ' . $zoomWidth . 'x' . $sHeight . ' -crop ' . $newSize . '+0+' . $offset . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } } } if ($sys) { exec(self::$convert . $sys, $rtn); #对图片进行优化 self::optimizeJpg(array('srcPath' => $desPath, 'stripExif' => $stripExif)); } else { return false; } return true; } if ($scale < 1) { if ($srcCate > 1) { #原图宽大于高 #压缩的宽度 $ywidth = round(($zoomHeight / $imgHeight) * $imgWidth); if ($ywidth >= $zoomWidth && $zoomHeight != $imgHeight) { $imgInfo = array($ywidth, $zoomHeight); $imgPostion = self::getCoordinatesPostion(array('imgArr' => $imgInfo, 'imgHandArr' => array($zoomWidth, $zoomHeight), 'type' => $pos)); $sys = ' -resize ' . $ywidth . 'x' . $zoomHeight . ' -crop ' . $newSize . '+' . $imgPostion['0'] . '+' . $imgPostion['1'] . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } else if ($zoomHeight != $imgHeight) { $yhight = round(($zoomWidth / $imgWidth) * $imgHeight); $imgInfo = array($zoomWidth, $yhight); $imgPostion = self::getCoordinatesPostion(array('imgArr' => $imgInfo, 'imgHandArr' => array($zoomWidth, $zoomHeight), 'type' => $pos)); $sys = ' -resize ' . $zoomWidth . 'x' . $yhight . ' -crop ' . $newSize . '+' . $imgPostion['0'] . '+' . $imgPostion['1'] . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } else { $imgInfo = array($imgWidth, $imgHeight); $imgPostion = self::getCoordinatesPostion(array('imgArr' => $imgInfo, 'imgHandArr' => array($zoomWidth, $zoomHeight), 'type' => $pos)); $sys = ' -resize ' . $srcSize . ' -crop ' . $newSize . '+' . $imgPostion['0'] . '+' . $imgPostion['1'] . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } } else if ($srcCate < 1) { #原图宽小于高 $yheight = round(($zoomWidth / $imgWidth) * $imgHeight); if ($yheight >= $zoomHeight && $zoomWidth != $imgWidth) { $imgInfo = array($zoomWidth, $yheight); $imgPostion = self::getCoordinatesPostion(array('imgArr' => $imgInfo, 'imgHandArr' => array($zoomWidth, $zoomHeight), 'type' => $pos)); $sys = ' -resize ' . $zoomWidth . 'x' . $yheight . ' -crop ' . $newSize . '+' . $imgPostion['0'] . '+' . $imgPostion['1'] . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } else if ($zoomHeight != $imgHeight) { $ywidth = round(($zoomHeight / $imgHeight) * $imgWidth); $imgInfo = array($ywidth, $zoomHeight); $imgPostion = self::getCoordinatesPostion(array('imgArr' => $imgInfo, 'imgHandArr' => array($zoomWidth, $zoomHeight), 'type' => $pos)); $sys = ' -resize ' . $ywidth . 'x' . $zoomHeight . ' -crop ' . $newSize . '+' . $imgPostion['0'] . '+' . $imgPostion['1'] . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } else { $imgInfo = array($imgWidth, $imgHeight); $imgPostion = self::getCoordinatesPostion(array('imgArr' => $imgInfo, 'imgHandArr' => array($zoomWidth, $zoomHeight), 'type' => $pos)); $sys = ' -resize ' . $srcSize . ' -crop ' . $newSize . '+' . $imgPostion['0'] . '+' . $imgPostion['1'] . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } } else { #原图宽等于高 $ywidth = round(($zoomHeight / $imgHeight) * $imgWidth); $yheight = round(($zoomWidth / $imgWidth) * $imgHeight); if ($newSrcCate > 1) { $imgInfo = array($zoomWidth, $zoomWidth); $imgPostion = self::getCoordinatesPostion(array('imgArr' => $imgInfo, 'imgHandArr' => array($zoomWidth, $zoomHeight), 'type' => $pos)); $sys = ' -resize ' . $zoomWidth . 'x' . $yheight . ' -crop ' . $newSize . '+' . $imgPostion['0'] . '+' . $imgPostion['1'] . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } else if ($newSrcCate < 1) { $imgInfo = array($zoomHeight, $zoomHeight); $imgPostion = self::getCoordinatesPostion(array('imgArr' => $imgInfo, 'imgHandArr' => array($zoomWidth, $zoomHeight), 'type' => $pos)); $sys = ' -resize ' . $ywidth . 'x' . $zoomHeight . ' -crop ' . $newSize . '+' . $imgPostion['0'] . '+' . $imgPostion['1'] . ' -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } else { $sys = ' -resize ' . $zoomWidth . 'x' . $zoomHeight . ' -crop ' . $newSize . '+0+0 -quality ' . $quality . ' ' . $srcPath . ' ' . $desPath; } } exec(self::$convert . $sys, $rtn); #对图片进行优化 self::optimizeJpg(array('srcPath' => $desPath, 'stripExif' => $stripExif)); } else { copy($srcPath, $desPath); } return true; } /** * 获得图片的详细信息(仅限图片) * 服务器必须安装ImageMagick */ public static function getImgInfo($paramArr) { $options = array( 'path' => '', #地址 ); if (is_array($paramArr)) $options = array_merge($options, $paramArr); extract($options); // $imagesize = getimagesize($path); // $data = array( // 'width' => $imagesize[0], // 'height' => $imagesize[1], // ); // return $data; //以下的暂时跑不通 php.ini禁用系统函数了 #exec("identify -verbose ${path}",$rtnArr); #参数说明,请详细见:http://www.imagemagick.org/script/escape.php @exec('identify -format "%b|%m|%w|%h|%r|%q " ' . $path, $rtnArr); $data = array(); if ($rtnArr && isset($rtnArr[0])) { list($data['size'], $ext, $data['width'], $data['height'], $data['colorsp'], $data['depth']) = explode("|", $rtnArr[0]); #扩展名处理 $ext = strtolower($ext); if ($ext == "jpeg") $ext = "jpg"; $data['ext'] = $ext; } return $data; } /** * 进行优化图片,对图片进行压缩 */ public static function optimizeJpg($paramArr) { $options = array( 'srcPath' => '', #源文件路径 'stripExif' => true, #是否去掉Exif信息 ); if (is_array($paramArr)) $options = array_merge($options, $paramArr); extract($options); $ext = substr($srcPath, strrpos($srcPath, ".") + 1); if ("jpg" != strtolower($ext)) return false; $cmdSubStr = $stripExif ? " --strip-exif " : ""; exec("/usr/local/bin/jpegoptim --strip-com ".$cmdSubStr." --strip-iptc --max=100 ".$srcPath."", $rtn); return true; } /** * 获取坐标 * @param imgArr 需要处理的图像数组 array(0=>width,1=>height) * @param imgHandArr 处理之后的图像大小数组 array(0=>width,1=>height) * @param type 截图类型 */ public static function getCoordinatesPostion($paramArr) { $options = array( 'imgArr' => '', #imgArr 需要处理的图像数组 array(0=>width,1=>height) 'imgHandArr' => '', #imgHandArr 处理之后的图像大小数组 array(0=>width,1=>height) 'type' => 'middleMiddle' #截取位置 ); if (is_array($paramArr)) $options = array_merge($options, $paramArr); extract($options); if (!is_array($imgArr) || !is_array($imgHandArr)) return false; switch ($type) { case 'leftUp': return array(0, 0); break; case 'middleUp': $startX = round(($imgArr[0] - $imgHandArr[0]) / 2); return array($startX, 0); break; case 'rightUp': $startX = $imgArr[0] - $imgHandArr[0]; return array($startX, 0); break; case 'leftMiddle': $startY = round(($imgArr[1] - $imgHandArr[1]) / 2); return array(0, $startY); break; case 'middleMiddle': $startX = round(($imgArr[0] - $imgHandArr[0]) / 2); $startY = round(($imgArr[1] - $imgHandArr[1]) / 2); return array($startX, $startY); break; case 'rightMiddle': $startX = $imgArr[0] - $imgHandArr[0]; $startY = round(($imgArr[1] - $imgHandArr[1]) / 2); return array($startX, $startY); break; case 'leftBottom': $startY = $imgArr[1] - $imgHandArr[1]; return array(0, $startY); break; case 'middleBottom': $startX = round(($imgArr[0] - $imgHandArr[0]) / 2); $startY = $imgArr[1] - $imgHandArr[1]; return array($startX, $startY); break; case 'rightBottom': $startX = $imgArr[0] - $imgHandArr[0]; $startY = $imgArr[1] - $imgHandArr[1]; return array($startX, $startY); break; } } } ?>