/**
  * 生成缓存,以栏目ID为数组下标,以排序字段listorder ASC排序
  */
 public function category_cache()
 {
     $models = F("Model");
     $data = $this->order("listorder ASC")->select();
     $categorys = array();
     foreach ($data as $r) {
         unset($r['module']);
         $setting = unserialize($r['setting']);
         //栏目生成Html
         $r['ishtml'] = $setting['ishtml'];
         //内容页生成Html
         $r['content_ishtml'] = $setting['content_ishtml'];
         //栏目页URL规则
         $r['category_ruleid'] = $setting['category_ruleid'];
         //内容也URL规则
         $r['show_ruleid'] = $setting['show_ruleid'];
         //工作流
         //            $r['workflowid'] = $setting['workflowid'];
         $r['isdomain'] = '0';
         //判断栏目地址是否为(http|https),也就是是否绑定了域名,或者外部链接栏目
         if (!preg_match('/^(http|https):\\/\\//', $r['url'])) {
             //本站域名后面不能带/
             $Domain = urlDomain(CONFIG_SITEURL);
             if ($Domain) {
                 $r['url'] = substr($Domain, 0, -1) . $r['url'];
             }
         }
         $categorys[$r['catid']] = $r;
     }
     F("Category", $categorys);
     unset($data, $models, $array);
     return true;
 }
 public function d()
 {
     //当前客户端标识
     $aut = md5($this->userid . $this->groupid . substr($_SERVER['HTTP_USER_AGENT'], 0, 254));
     //key
     $key = I('get.key', '', 'trim');
     if (!empty($key)) {
         $key = str_replace(array("%*2F", " "), array("/", "+"), $key);
     }
     //格式:aut|栏目ID|信息id|下载编号|字段
     $key = explode("|", authcode($key, "DECODE"));
     //栏目ID
     $this->catid = $key[1];
     //信息ID
     $this->id = $key[2];
     //编号
     $k = $key[3];
     //字段名称
     $f = $key[4];
     //模型ID
     $modelid = getCategory($this->catid, 'modelid');
     $Model_field = F("Model_field_" . $modelid);
     //判断字段类型
     if (!in_array($Model_field[$f]['formtype'], array('downfiles', 'downfile'))) {
         $this->error('下载地址错误!');
     }
     //主表名称
     if ((int) $Model_field[$f]['issystem'] == 1) {
         $tablename = ucwords(getModel($modelid, 'tablename'));
     } else {
         $tablename = ucwords(getModel($modelid, 'tablename')) . "_data";
     }
     //字段配置
     $setting = unserialize($Model_field[$f]['setting']);
     if ($aut == $key[0] && $setting) {
         //取得下载字段内容
         $downfiles = M($tablename)->where(array("id" => $this->id))->getField($f);
         $dowUnserialize = unserialize($downfiles);
         //判断是否可以反序列化
         if ($dowUnserialize) {
             $info = $dowUnserialize[$k];
             //判断会有组
             if ((int) $info['groupid'] > 0 || (int) $info['point'] > 0) {
                 if (!$this->userid) {
                     $this->error("请登陆后再下载!", U("Member/Index/login", "forward=" . urlencode(get_url())));
                 }
                 if ((int) $info['groupid'] > 0 && (int) $this->groupid != (int) $info['groupid']) {
                     $this->error("您所在的会有组不能下载该附件!");
                 }
                 if ((int) $info['point'] > 0) {
                     $point = 0 - $info['point'];
                     $status = service("Passport")->user_integral($this->userid, $point);
                     if ($status == -1) {
                         $this->error("您当前的积分不足,无法下载!");
                     } else {
                         if ($status == false) {
                             $this->error("系统出现错误,请联系管理员!");
                         }
                     }
                     //下载记录----暂时木有这功能,后期增加
                 }
             }
             //下载地址
             $fileurl = $info['fileurl'];
         } else {
             //下载地址
             $fileurl = $downfiles;
             $info = array();
             $info['filename'] = basename($fileurl);
             $info['filename'] = str_replace('.' . fileext($info['filename']), '', $info['filename']);
         }
         //下载统计+1
         if (!empty($setting['statistics'])) {
             $statistics = trim($setting['statistics']);
             M(ucwords(getModel($modelid, 'tablename')))->where(array("id" => $this->id))->setInc($statistics);
         }
         if (!urlDomain(CONFIG_SITEURL)) {
             $urlDomain = urlDomain(get_url());
             //当前页面地址域名
         } else {
             $urlDomain = urlDomain(CONFIG_SITEURL);
         }
         //不管附件地址是远程地址,还是不带域名的地址,都进行替换
         $fileurl = str_replace($urlDomain, "", $fileurl);
         //远程文件
         if (strpos($fileurl, ':/')) {
             header("Location: {$fileurl}");
             exit;
         }
         //取得文件后缀
         $houz = "." . fileext(basename($fileurl));
         $fileurl = SITE_PATH . '/' . $fileurl;
         if (file_exists($fileurl)) {
             $this->downfiles($fileurl, urldecode($info['filename'] . $houz));
         } else {
             $this->error("需要下载的文件不存在!");
         }
     } else {
         $this->error("下载地址不正确!");
     }
 }
Example #3
0
 /**
  * ShuipFCMS官网会员帐号信息
  * @return type
  */
 private function getIdentity()
 {
     return json_encode(array('username' => C('CLOUD_USERNAME'), 'password' => C('CLOUD_PASSWORD'), 'domain' => urlDomain(get_url())));
 }
Example #4
0
 /**
  * 远程保存
  * @param $value 传入下载内容
  * @param $watermark 是否加入水印
  * @param $ext 下载扩展名
  */
 public function download($value, $watermark = null, $ext = 'gif|jpg|jpeg|bmp|png')
 {
     //检查是否有开启CURL
     if (!function_exists('curl_init')) {
         return $value;
     }
     $this->handlerLocal = new \UploadFile();
     //水印开关
     if (is_null($watermark)) {
         if ($this->config['watermarkenable']) {
             $watermark = true;
         }
     }
     $curl = curl_init();
     //正则匹配是否有符合数据
     if (!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\\.({$ext}))\\2/i", $value, $matches)) {
         return $value;
     }
     $remotefileurls = array();
     //过滤域名
     $NoDomain = explode("|", $this->config['fileexclude']);
     //当前程序所在域名地址
     $NoDomain[] = urlDomain(get_url());
     //附件地址
     $upload_url = urlDomain($this->options['sitefileurl']);
     foreach ($matches[3] as $matche) {
         //过滤远程地址
         if (strpos($matche, '://') === false) {
             continue;
         }
         //过滤后台设置的域名,和本站域名
         if (in_array(urlDomain($matche), $NoDomain)) {
             continue;
         }
         $remotefileurls[] = $matche;
     }
     $oldpath = $newpath = array();
     foreach ($remotefileurls as $k => $file) {
         if (strpos($file, '://') === false || strpos($file, $upload_url) !== false) {
             continue;
         }
         //取得文件扩展
         $file_fileext = fileext($file);
         //取得文件名
         $file_name = basename($file);
         //保存文件名
         $filename = $this->handlerLocal->getSaveName(array('name' => $file_name, 'extension' => $file_fileext, 'savename' => $this->options['savePath']));
         // 设置你需要抓取的URL
         curl_setopt($curl, CURLOPT_URL, cn_urlencode($file));
         // 设置header
         curl_setopt($curl, CURLOPT_HEADER, 0);
         // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         //超时设置
         curl_setopt($curl, CURLOPT_TIMEOUT, 10);
         // 运行cURL,请求网页
         $filedata = curl_exec($curl);
         //保存图片
         $status = $this->build_file($filedata, $this->options['savePath'] . $filename);
         if ($status) {
             //加水印
             if ($watermark) {
                 $this->water($this->options['savePath'] . $filename, "", $this->options['savePath'] . $filename);
             }
             $oldpath[] = $file;
             $newpath[] = str_replace($this->options['uploadfilepath'], $this->options['sitefileurl'], $this->options['savePath'] . $filename);
             $info = array("name" => $file_name, "type" => "", "size" => filesize($this->options['savePath'] . $filename), "key" => "", "extension" => $file_fileext, "savepath" => $this->options['savePath'], "savename" => $filename, "hash" => md5(str_replace($this->options['uploadfilepath'], "", $this->options['savePath'] . $filename)));
             $info['url'] = $this->options['sitefileurl'] . str_replace($this->options['uploadfilepath'], '', $info['savepath'] . $info['savename']);
             $aid = D('Attachment/Attachment')->fileInfoAdd($info, $this->options['module'], $this->options['catid'], $this->options['thumb'], $this->options['isadmin'], $this->options['userid'], $this->options['time']);
             //上传到FTP
             $filePath = $info['savepath'] . $info['savename'];
             if ($this->FTPuplode($filePath, $filePath)) {
                 //上传成功
                 if ($this->options['isupftpdel']) {
                     try {
                         unlink($info[$i]['savepath'] . $info[$i]['savename']);
                     } catch (Exception $exc) {
                     }
                 }
             } else {
                 $this->error = $this->handler->get_error();
                 try {
                     unlink($info[$i]['savepath'] . $info[$i]['savename']);
                 } catch (Exception $exc) {
                 }
             }
             //设置标识
             $this->upload_json($aid, $info['url'], $filename);
         }
     }
     // 关闭URL请求
     curl_close($curl);
     $value = str_replace($oldpath, $newpath, $value);
     return $value;
 }
 /**
  * 远程保存
  * @param $value 传入下载内容
  * @param $watermark 是否加入水印
  * @param $ext 下载扩展名
  */
 public function download($value, $watermark = '', $ext = 'gif|jpg|jpeg|bmp|png')
 {
     //检查是否有开启CURL
     if (!function_exists('curl_init')) {
         return $value;
     }
     if ($watermark == '') {
         if ($this->Config['watermarkenable']) {
             $watermark = true;
         }
     }
     $curl = curl_init();
     //正则匹配是否有符合数据
     if (!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\\.({$ext}))\\2/i", $value, $matches)) {
         return $value;
     }
     $remotefileurls = array();
     //过滤域名
     $NoDomain = explode("|", CONFIG_FILEEXCLUDE);
     //当前程序所在域名地址
     $NoDomain[] = urlDomain(get_url());
     //附件地址
     $upload_url = urlDomain(CONFIG_SITEFILEURL);
     foreach ($matches[3] as $matche) {
         //过滤远程地址
         if (strpos($matche, '://') === false) {
             continue;
         }
         //过滤后台设置的域名,和本站域名
         if (in_array(urlDomain($matche), $NoDomain)) {
             continue;
         }
         $remotefileurls[] = $matche;
     }
     //保存目录
     $FilePath = $this->FilePath();
     $oldpath = $newpath = array();
     import('UploadFile');
     $upload = new UploadFile();
     foreach ($remotefileurls as $k => $file) {
         if (strpos($file, '://') === false || strpos($file, $upload_url) !== false) {
             continue;
         }
         //取得文件扩展
         $file_fileext = fileext($file);
         //取得文件名
         $file_name = basename($file);
         //保存文件名
         $filename = uniqid() . "." . $file_fileext;
         // 设置你需要抓取的URL
         curl_setopt($curl, CURLOPT_URL, $file);
         // 设置header
         curl_setopt($curl, CURLOPT_HEADER, 0);
         // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         //超时设置
         curl_setopt($curl, CURLOPT_TIMEOUT, 10);
         // 运行cURL,请求网页
         $filedata = curl_exec($curl);
         //保存图片
         $status = $this->build_file($filedata, $FilePath . "/" . $filename);
         if ($status) {
             //加水印
             if ($watermark) {
                 $this->water($FilePath . "/" . $filename, "", $FilePath . "/" . $filename);
             }
             $oldpath[] = $file;
             $newpath[] = str_replace($this->path, CONFIG_SITEFILEURL, $FilePath . "/" . $filename);
             $info = array("name" => $file_name, "type" => "", "size" => filesize($FilePath . "/" . $filename), "key" => "", "extension" => $file_fileext, "savepath" => $FilePath, "savename" => "/" . $filename, "hash" => md5(str_replace($this->path, "", $FilePath . "/" . $filename)));
             $aid = $this->FileData($info);
             //设置标识
             $this->upload_json($aid, $this->filehttp, $filename);
             //FTP
             if ($this->Ftpstatus) {
                 // 远程存放地址
                 $remote = $this->Config['ftpuppat'] . str_replace(SITE_PATH . "/", "", $FilePath . "/" . $filename);
                 if ($upload->FTPuplode($FilePath . "/" . $filename, $remote)) {
                     //删除
                     unlink($FilePath . "/" . $filename);
                 }
             }
         }
     }
     // 关闭URL请求
     curl_close($curl);
     $value = str_replace($oldpath, $newpath, $value);
     return $value;
 }
 public function d()
 {
     //当前客户端标识
     $aut = md5($this->userid . $this->groupid . substr($_SERVER['HTTP_USER_AGENT'], 0, 254));
     //key
     $key = I('get.key', '', 'trim');
     if (!empty($key)) {
         $key = str_replace(array('+', '%23', '%2F', '%3F', '%26', '%3D', '%2B'), array(' ', '#', '/', '?', '&', '=', '+'), $key);
     }
     $key = \Libs\Util\Encrypt::authcode($key, "DECODE");
     if (empty($key)) {
         $this->error('下载地址非法!');
     }
     //格式:aut|栏目ID|信息id|下载编号|字段
     $key = explode("|", $key);
     //栏目ID
     $this->catid = $key[1];
     //信息ID
     $this->id = $key[2];
     //编号
     $k = $key[3];
     //字段名称
     $f = $key[4];
     //模型ID
     $modelid = getCategory($this->catid, 'modelid');
     $ModelField = cache('ModelField');
     $Model_field = $ModelField[$modelid];
     //判断字段类型
     if (!in_array($Model_field[$f]['formtype'], array('downfiles', 'downfile'))) {
         $this->error('下载地址错误!');
     }
     //主表名称
     if ((int) $Model_field[$f]['issystem'] == 1) {
         $tablename = ucwords(getModel($modelid, 'tablename'));
     } else {
         $tablename = ucwords(getModel($modelid, 'tablename')) . "_data";
     }
     //字段配置
     $setting = unserialize($Model_field[$f]['setting']);
     if ($aut == $key[0] && $setting) {
         //取得下载字段内容
         $downfiles = M($tablename)->where(array("id" => $this->id))->getField($f);
         $dowUnserialize = unserialize($downfiles);
         //判断是否可以反序列化
         if ($dowUnserialize) {
             $info = $dowUnserialize[$k];
             //判断会有组
             if ((int) $info['groupid'] > 0 || (int) $info['point'] > 0) {
                 if (!$this->userid) {
                     $this->error("请登陆后再下载!", U("Member/Index/login", "forward=" . urlencode(get_url())));
                 }
                 if ((int) $info['groupid'] > 0 && (int) $this->groupid != (int) $info['groupid']) {
                     $this->error("您所在的会有组不能下载该附件!");
                 }
                 if ((int) $info['point'] > 0) {
                     $point = 0 - $info['point'];
                     $status = service("Passport")->userIntegration($this->userid, $point);
                     if ($status !== true) {
                         $this->error(service("Passport")->getError() ?: '积分扣除失败!');
                     }
                     //下载记录
                     $content_download_log = array('id' => $this->id, 'catid' => $this->catid, 'field' => $f, 'userid' => $this->userid, 'groupid' => $this->groupid, 'info' => $info);
                     tag('content_download_log', $content_download_log);
                 }
             }
             //下载地址
             $fileurl = $info['fileurl'];
         } else {
             //下载地址
             $fileurl = $downfiles;
             $info = array();
             $info['filename'] = basename($fileurl);
             $info['filename'] = str_replace('.' . fileext($info['filename']), '', $info['filename']);
         }
         //下载统计+1
         if (!empty($setting['statistics'])) {
             $statistics = trim($setting['statistics']);
             M(ucwords(getModel($modelid, 'tablename')))->where(array("id" => $this->id))->setInc($statistics);
         }
         $urlDomain = urlDomain(self::$Cache['Cache']['siteurl']);
         if (!$urlDomain) {
             $urlDomain = urlDomain(get_url());
             //当前页面地址域名
         }
         //不管附件地址是远程地址,还是不带域名的地址,都进行替换
         $fileurl = str_replace($urlDomain, "", $fileurl);
         //远程文件
         if (strpos($fileurl, ':/')) {
             header("Location: {$fileurl}");
             exit;
         }
         //取得文件后缀
         $houz = "." . fileext(basename($fileurl));
         $fileurl = SITE_PATH . $fileurl;
         if (file_exists($fileurl)) {
             $this->downfiles($fileurl, urldecode($info['filename'] . $houz));
         } else {
             $this->error("需要下载的文件不存在!");
         }
     } else {
         $this->error("下载地址不正确!");
     }
 }
Example #7
0
 public function imagescrop()
 {
     $picurl = I('get.picurl');
     if ($picurl) {
         $picurl = str_replace(urlDomain($picurl), '/', $picurl);
     }
     $module = I('get.module', MODULE_NAME);
     $this->assign('picurl', $picurl);
     $this->assign('module', $module);
     $this->display('imagescrop');
 }
 /**
  * 修复栏目数据 
  */
 protected function repair()
 {
     $this->categorys = $categorys = array();
     //栏目数据
     $categorysdata = M("Category")->select();
     foreach ($categorysdata as $v) {
         $categorys[$v['catid']] = $v;
     }
     unset($categorysdata);
     $this->categorys = $categorys;
     $this->get_categorys($categorys);
     if (is_array($this->categorys)) {
         foreach ($this->categorys as $catid => $cat) {
             //外部栏目无需修复
             if ($cat['type'] == 2) {
                 continue;
             }
             //获取父栏目ID列表
             $arrparentid = $this->get_arrparentid($catid);
             //栏目配置信息反序列化
             $setting = unserialize($cat['setting']);
             //获取子栏目ID列表
             $arrchildid = $this->get_arrchildid($catid);
             //检查所有父id 子栏目id 等相关数据是否正确,不正确更新
             if ($categorys[$catid]['arrparentid'] != $arrparentid || $categorys[$catid]['arrchildid'] != $arrchildid) {
                 M("Category")->where(array('catid' => $catid))->save(array('arrparentid' => $arrparentid, 'arrchildid' => $arrchildid));
             }
             //获取父栏目路径
             $parentdir = $this->get_parentdir($catid);
             //获取栏目名称
             $catname = iconv('utf-8', 'gbk', $cat['catname']);
             //返回拼音
             $letters = gbk_to_pinyin($catname);
             $letter = strtolower(implode('', $letters));
             //检查排序是否正确
             $listorder = $cat['listorder'] ? $cat['listorder'] : $catid;
             //静态和动态处理
             if ($setting['ishtml']) {
                 //生成静态时
                 $url = $this->update_url($catid);
                 if (!preg_match('/^(http|https):\\/\\//i', $url)) {
                     //20120618
                     //把地址拆成两部分,一部分域名,一部分网站所在目录
                     // 如果CONFIG_SITEURL是类似“/ed/”栏目URL直接是CONFIG_SITEURL+栏目生成目录
                     //如果CONFIG_SITEURL是类似“http://www.85zu.com/”栏目URL直接是CONFIG_SITEURL去除域名部分+栏目生成目录
                     $Domain = urlDomain(CONFIG_SITEURL);
                     if ($Domain) {
                         $url = "/" . str_replace($Domain, "", CONFIG_SITEURL) . $url;
                     } else {
                         $url = CONFIG_SITEURL . $url;
                     }
                 }
             } else {
                 //不生成静态时
                 $url = $this->update_url($catid);
             }
             //更新URL
             if ($cat['url'] != $url) {
                 M("Category")->where(array('catid' => $catid))->save(array('url' => $url));
             }
             if ($categorys[$catid]['parentdir'] != $parentdir || $categorys[$catid]['letter'] != $letter || $categorys[$catid]['listorder'] != $listorder) {
                 M("Category")->where(array('catid' => $catid))->save(array('parentdir' => $parentdir, 'letter' => $letter, 'listorder' => $listorder));
             }
         }
     }
     //删除在非正常显示的栏目
     foreach ($this->categorys as $catid => $cat) {
         if ($cat['parentid'] != 0 && !isset($this->categorys[$cat['parentid']])) {
             M("Category")->where(array('catid' => $catid))->delete();
         }
     }
     return true;
 }
 /**
  * 文件下载 
  */
 public function d()
 {
     $aut = md5(get_client_ip() . substr($_SERVER['HTTP_USER_AGENT'], 0, 254));
     $_GET['key'] = str_replace(array("%*2F", " "), array("/", "+"), $_GET['key']);
     //格式:aut|栏目ID|信息id|下载编号|字段
     $key = explode("|", authcode($_GET['key'], "DECODE"));
     //栏目ID
     $catid = $key[1];
     //信息ID
     $id = $key[2];
     //编号
     $k = $key[3];
     //字段名称
     $f = $key[4];
     $Category = F('Category');
     $Model = F('Model');
     //模型ID
     $modelid = $Category[$catid]['modelid'];
     $Model_field = F("Model_field_" . $modelid);
     //主表名称
     if ((int) $Model_field[$f]['issystem'] == 1) {
         $tablename = ucwords($Model[$modelid]['tablename']);
     } else {
         $tablename = ucwords($Model[$modelid]['tablename']) . "_data";
     }
     if ($aut == $key[0]) {
         $downfiles = M($tablename)->where(array("id" => $id))->getField($f);
         $downfiles = unserialize($downfiles);
         $info = $downfiles[$k];
         //判断会有组
         if ((int) $info['groupid'] > 0 || (int) $info['point'] > 0) {
             if (!AppframeAction::$Cache['uid']) {
                 $this->error("请登陆后再下载!", U("Member/Index/login", "forward=" . urlencode(get_url())));
             }
             if ((int) $info['groupid'] > 0 && (int) AppframeAction::$Cache['User']['groupid'] != (int) $info['groupid']) {
                 $this->error("您所在的会有组不能下载该附件!");
             }
             if ((int) $info['point'] > 0) {
                 $point = 0 - $info['point'];
                 $status = service("Passport")->user_integral(AppframeAction::$Cache['uid'], $point);
                 if ($status == -1) {
                     $this->error("您当前的积分不足,无法下载!");
                 } else {
                     if ($status == false) {
                         $this->error("系统出现错误,请联系管理员!");
                     }
                 }
                 //下载记录----暂时木有这功能,后期增加
             }
         }
         $fileurl = $info['fileurl'];
         if (!urlDomain(CONFIG_SITEURL)) {
             $urlDomain = urlDomain(get_url());
             //当前页面地址域名
         } else {
             $urlDomain = urlDomain(CONFIG_SITEURL);
         }
         //不管附件地址是远程地址,还是不带域名的地址,都进行替换
         $fileurl = str_replace($urlDomain, "", $fileurl);
         //远程文件
         if (strpos($fileurl, ':/')) {
             header("Location: {$fileurl}");
             exit;
         }
         //取得文件后缀
         $houz = "." . fileext(basename($fileurl));
         $fileurl = SITE_PATH . '/' . $fileurl;
         if (file_exists($fileurl)) {
             $this->downfiles($fileurl, urldecode($info['filename'] . $houz));
         } else {
             $this->error("需要下载的文件不存在!");
         }
     } else {
         $this->error("下载地址不正确!");
     }
 }
 public function public_imagescrop()
 {
     $picurl = I('get.picurl');
     $catid = I('get.catid', $this->catid, 'intval');
     if (!$catid) {
         $this->error('栏目不存在!');
     }
     if ($picurl) {
         $picurl = str_replace(urlDomain($picurl), '/', $picurl);
     }
     $module = I('get.module', MODULE_NAME);
     $this->assign('picurl', $picurl);
     $this->assign('catid', $catid);
     $this->assign('module', $module);
     $this->display('imagescrop');
 }