Exemplo n.º 1
0
 protected function _initialize()
 {
     parent::_initialize();
     import('Url');
     $this->Url = get_instance_of('Url');
     load("@.iconvfunc");
 }
Exemplo n.º 2
0
 /**
  * 架构函数
  * @param array $options 配置参数
  * @access public
  */
 function __construct($options = array())
 {
     //网站配置
     $this->config = F("Config");
     $options = array_merge(array('userid' => AppframeAction::$Cache['uid'] ? AppframeAction::$Cache['uid'] : 0, 'groupid' => 8, 'isadmin' => 0, 'catid' => 0, 'module' => 'contents ', 'watermarkenable' => $this->config['watermarkenable'], 'thumb' => false, 'time' => time(), 'dateFormat' => 'Y/m'), $options);
     $this->options = $options;
     //附件访问地址
     $this->options['sitefileurl'] = $this->config['sitefileurl'];
     //附件存放路径
     $this->options['uploadfilepath'] = C('UPLOADFILEPATH');
     //允许上传的附件大小
     if (empty($this->options['uploadmaxsize'])) {
         $this->options['uploadmaxsize'] = $this->options['isadmin'] ? (int) $this->config['uploadmaxsize'] * 1024 : (int) $this->config['qtuploadmaxsize'] * 1024;
     }
     //允许上传的附件类型
     if (empty($this->options['uploadallowext'])) {
         $this->options['uploadallowext'] = $this->options['isadmin'] ? explode("|", $this->config['uploadallowext']) : explode("|", $this->config['qtuploadallowext']);
     }
     //上传目录
     $this->options['savePath'] = D('Attachment')->getFilePath($this->options['module'], $this->options['dateFormat'], $this->options['time']);
     //如果生成缩略图是否移除原图
     $this->options['thumbRemoveOrigin'] = false;
     import('UploadFile');
     $this->handler = get_instance_of('UploadFile');
     //设置上传类型
     $this->handler->allowExts = $this->options['uploadallowext'];
     //设置上传大小
     $this->handler->maxSize = $this->options['uploadmaxsize'];
     //设置本次上传目录,不存在时生成
     $this->handler->savePath = $this->options['savePath'];
 }
Exemplo n.º 3
0
 protected function _initialize()
 {
     parent::_initialize();
     import('Url');
     $this->url = get_instance_of('Url');
     /**
      * 查询城市
      * */
 }
Exemplo n.º 4
0
 public function _initialize()
 {
     //关闭由于启用域名绑定造成的前台域名出错
     define("APP_SUB_DOMAIN_NO", 1);
     parent::_initialize();
     import('Url');
     $this->url = get_instance_of('Url');
     define('HTML', true);
     C('HTML_FILE_SUFFIX', "");
 }
Exemplo n.º 5
0
 /**
 +----------------------------------------------------------
 * 加载过滤器
 * 
 +----------------------------------------------------------
 * @static
 * @access public 
 +----------------------------------------------------------
 * @param string $filterNames  过滤器名称
 * @param string $method  执行的方法名称
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 static function load($filterNames, $method = 'execute')
 {
     $filterPath = dirname(__FILE__) . '/Filter/';
     $filters = explode(',', $filterNames);
     $load = false;
     foreach ($filters as $key => $val) {
         if (strpos($val, '.')) {
             $filterClass = strtolower(substr(strrchr($val, '.'), 1));
             import($val);
         } else {
             $filterClass = 'Filter' . $val;
             require_cache($filterPath . $filterClass . '.class.php');
         }
         if (class_exists($filterClass)) {
             $filter = get_instance_of($filterClass);
             $filter->{$method}();
         }
     }
     return;
 }
Exemplo n.º 6
0
 /**
  * 连接
  * @access public
  * @param array $options  配置数组
  * @return object
  */
 public static function connect($options = array())
 {
     //判断模块是否安装
     if (false == isModuleInstall('Member')) {
         return get_instance_of('PassportService');
     }
     //网站配置
     $config = F("Member_Config");
     if ($config['interface']) {
         $type = $config['interface'];
     } else {
         $type = 'Local';
     }
     //附件存储方案
     $type = trim($type);
     $class = 'Passport' . ucwords($type);
     import("Driver.Passport.{$class}", LIB_PATH);
     if (class_exists($class)) {
         $Atta = new $class($options);
     } else {
         throw_exception('无法加载通行证:' . $type);
     }
     return $Atta;
 }
Exemplo n.º 7
0
 public static function getInstance()
 {
     $args = func_get_args();
     return get_instance_of(__CLASS__, 'factory', $args);
 }
Exemplo n.º 8
0
 /**
 +----------------------------------------------------------
 * 解析标签库的标签
 * 需要调用对应的标签库文件解析类
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $tagLib  标签库名称
 * @param string $tag  标签名
 * @param string $attr  标签属性
 * @param string $content  标签内容
 +----------------------------------------------------------
 * @return string|false
 +----------------------------------------------------------
 */
 public function parseXmlTag($tagLib, $tag, $attr, $content)
 {
     //if (MAGIC_QUOTES_GPC) {
     $attr = stripslashes($attr);
     $content = stripslashes($content);
     //}
     if (ini_get('magic_quotes_sybase')) {
         $attr = str_replace('\\"', '\'', $attr);
     }
     $tLib = get_instance_of('TagLib' . ucwords(strtolower($tagLib)));
     if ($tLib->valid()) {
         $parse = '_' . $tag;
         $content = trim($content);
         return $tLib->{$parse}($attr, $content);
     }
 }
Exemplo n.º 9
0
 public static function getInstance()
 {
     return get_instance_of(__CLASS__);
 }
Exemplo n.º 10
0
 /**
  * 取得缓存类实例
  * @static
  * @access public
  * @return mixed
  */
 static function getInstance()
 {
     $param = func_get_args();
     return get_instance_of(__CLASS__, 'connect', $param);
 }
Exemplo n.º 11
0
 /**
    +----------------------------------------------------------
    * 解析标签库的标签
    * 需要调用对应的标签库文件解析类
    +----------------------------------------------------------
    * @access public
    +----------------------------------------------------------
    * @param string $tagLib  标签库名称
    * @param string $tag  标签名
    * @param string $attr  标签属性
    * @param string $content  标签内容
    +----------------------------------------------------------
    * @return string|false
    +----------------------------------------------------------
 */
 public function parseXmlTag($tagLib, $tag, $attr, $content)
 {
     $attr = stripslashes($attr);
     $content = stripslashes($content);
     if (ini_get('magic_quotes_sybase')) {
         $attr = str_replace('\\"', '\'', $attr);
     }
     if (!empty(self::$nowTags['alias'])) {
         $tLib = get_instance_of('Tag' . ucwords(strtolower(self::$nowTags['alias'])));
         $tLib->setOther($tag);
     } else {
         $tLib = get_instance_of('Tag' . ucwords(strtolower($tag)));
     }
     return $tLib->parse($attr, $content);
 }
Exemplo n.º 12
0
 public function remove()
 {
     if (IS_POST && isset($_POST['fromtype'])) {
         $catid = I('get.catid', '', 'intval');
         if (!$catid) {
             $this->error("请指定栏目!");
         }
         //移动类型
         $fromtype = I('post.fromtype', '', 'intval');
         //需要移动的信息ID集合
         $ids = $_POST['ids'];
         //需要移动的栏目ID集合
         $fromid = $_POST['fromid'];
         //目标栏目
         $tocatid = I('post.tocatid', '', 'intval');
         if (!$tocatid) {
             $this->error("目标栏目不正确!");
         }
         import('Content');
         $Content = get_instance_of('Content');
         switch ($fromtype) {
             //信息移动
             case 0:
                 if ($ids) {
                     if ($tocatid == $catid) {
                         $this->error("目标栏目和当前栏目是同一个栏目!");
                     }
                     $modelid = getCategory($tocatid, 'modelid');
                     if (!$modelid) {
                         $this->error("该模型不存在!");
                     }
                     $this->contentModel = ContentModel::getInstance($modelid);
                     import('Url');
                     $this->url = get_instance_of('Url');
                     //表名
                     $tablename = ucwords($this->model[$modelid]['tablename']);
                     if (!$ids) {
                         $this->error("请选择需要移动信息!");
                     }
                     $ids = array_filter(explode('|', $_POST['ids']), "intval");
                     //删除静态文件
                     foreach ($ids as $sid) {
                         $data = $this->contentModel->where(array('catid' => $catid, 'id' => $sid))->find();
                         $Content->deleteHtml($catid, $sid, $data['inputtime'], $data['prefix'], $data);
                         $data['catid'] = $tocatid;
                         $urls = $this->url->show($data);
                         $this->contentModel->where(array('catid' => $catid, 'id' => $sid))->save(array("catid" => $tocatid, 'url' => $urls['url']));
                     }
                     $this->success("移动成功!", U("Createhtml/update_urls"));
                 } else {
                     $this->error("请选择需要移动的信息!");
                 }
                 break;
                 //栏目移动
             //栏目移动
             case 1:
                 if (!$fromid) {
                     $this->error("请选择需要移动的栏目!");
                 }
                 $where = array();
                 $where['catid'] = array("IN", $fromid);
                 $modelid = getCategory($catid, 'modelid');
                 if (!$modelid) {
                     $this->error("该模型不存在!");
                 }
                 $tablename = ucwords($this->model[$modelid]['tablename']);
                 //进行栏目id更改
                 if (M($tablename)->where($where)->save(array("catid" => $tocatid, 'url' => ''))) {
                     $this->success("移动成功,请使用《批量更新URL》更新新的地址!!", U("Createhtml/update_urls"));
                 } else {
                     $this->error("移动失败");
                 }
                 break;
             default:
                 $this->error("请选择移动类型!");
                 break;
         }
     } else {
         $ids = I('request.ids', '', '');
         $ids = is_array($ids) ? implode("|", $ids) : $ids;
         $catid = I('get.catid', '', 'intval');
         if (!$catid) {
             $this->error("请指定栏目!");
         }
         $modelid = getCategory($catid, 'modelid');
         import("Tree");
         $tree = new Tree();
         $tree->icon = array('  │ ', '  ├─ ', '  └─ ');
         $tree->nbsp = '  ';
         $categorys = array();
         $categorysList = F("Category");
         foreach ($categorysList as $cid => $r) {
             if ($r['type']) {
                 continue;
             }
             if ($modelid && $modelid != $r['modelid']) {
                 continue;
             }
             $r['disabled'] = $r['child'] ? 'disabled' : '';
             $r['selected'] = $cid == $catid ? 'selected' : '';
             $categorys[$cid] = $r;
         }
         $str = "<option value='\$catid' \$selected \$disabled>\$spacer \$catname</option>";
         $tree->init($categorys);
         $string .= $tree->get_tree(0, $str);
         $str = "<option value='\$catid'>\$spacer \$catname</option>";
         $source_string = '';
         $tree->init($categorys);
         $source_string .= $tree->get_tree(0, $str);
         $this->assign("ids", $ids);
         $this->assign("string", $string);
         $this->assign("source_string", $source_string);
         $this->assign("catid", $catid);
         $this->display();
     }
 }
Exemplo n.º 13
0
function TagLib($name, $params = array())
{
    $class = $name . 'TagLib';
    import("TagLib.{$class}", LIB_PATH);
    return get_instance_of($class, '', $params);
}
Exemplo n.º 14
0
 /**
  * 上下篇生成
  * @param type $catid
  * @param type $id 
  */
 public function related_content($catid, $id, $action = "edit")
 {
     if (!$catid || !$id) {
         return;
     }
     $modelid = getCategory($catid, 'modelid');
     $db = ContentModel::getInstance($modelid);
     $where = array();
     $where['catid'] = $catid;
     $where['status'] = array("EQ", "99");
     $where['id'] = array("LT", $id);
     $data[] = $db->relation(true)->where($where)->order(array("id" => "DESC"))->find();
     if ($action == "edit") {
         $where['id'] = array("GT", $id);
         $data[] = $db->relation(true)->where($where)->find();
     }
     import('Html');
     $html = get_instance_of('Html');
     foreach ($data as $r) {
         if ($r['islink'] || empty($r['id'])) {
             continue;
         }
         $db->dataMerger($r);
         $setting = getCategory($r['catid'], 'setting');
         $content_ishtml = $setting['content_ishtml'];
         if (!$content_ishtml) {
             continue;
         }
         $html->show($r, 1, 'edit');
     }
     return true;
 }
Exemplo n.º 15
0
 /**
  * 移除文件
  * @param type $tmpdir 目录
  * @param type $list 需要删除的文件列表
  * @return type
  */
 public function clean_file($tmpdir, $list)
 {
     $Dir = get_instance_of('Dir');
     //过滤空白数组
     $list = array_filter($list);
     //批量转换编码
     foreach ($list as $file) {
         $object = $tmpdir . $file;
         //忽略不存在的文件
         if (file_exists($object) === FALSE) {
             continue;
         }
         //删除目录
         if (is_dir($object)) {
             $Dir->delDir($object);
         }
         //删除文件出错
         if (is_file($object) && unlink($object) === FALSE) {
             //记录在案
             $this->lastfile = $object;
             //错误信息
             $this->error = "无法删除{$object}文件!";
             return -10006;
         }
     }
     return true;
 }
Exemplo n.º 16
0
 private function market()
 {
     //是否开启安全通信
     if ($this->connect() == false) {
         exit(serialize(array('error' => -10010, 'status' => 'fail')));
     }
     //获取命令,命令是以序列化的方式
     $command = unserialize($this->execute);
     switch ($command['execute']) {
         //测试命令
         case 'testing':
             exit(serialize(array('string' => $command['string'], 'status' => 'success')));
             break;
             //模块处理
         //模块处理
         case 'module':
             //模块路径
             $modulePath = APP_PATH . C('APP_GROUP_PATH') . '/' . $command['appid'] . '/';
             //IO操作类
             $Dir = get_instance_of('Dir');
             //操作
             switch ($command['method']) {
                 //模块安装
                 case 'install':
                     //缺少必要参数
                     if (empty($command['appid']) || empty($command['package'])) {
                         exit(serialize(array('error' => -10011, 'appid' => $command['appid'], 'package' => $command['package'], 'status' => 'fail')));
                     }
                     //检查模块是否存在
                     if (D('Module')->exists($command['appid'])) {
                         exit(serialize(array('error' => -10012, 'appid' => $command['appid'], 'status' => 'fail')));
                     }
                     //创建模块目录
                     if (mkdir($modulePath, 0777, TRUE) === FALSE) {
                         //====表明已经存在目录,尝试检测权限
                         //测试读写权限
                         $status = $this->Cloud->valid_perm($modulePath);
                         if (count($status)) {
                             exit(serialize(array('error' => -10007, 'catalog' => $status, 'status' => 'fail')));
                         } else {
                             exit(serialize(array('error' => -10013, 'catalog' => $modulePath, 'status' => 'fail')));
                         }
                     } else {
                         //测试读写权限
                         $status = $this->Cloud->valid_perm($modulePath);
                         if (count($status)) {
                             exit(serialize(array('error' => -10007, 'catalog' => $status, 'status' => 'fail')));
                         }
                     }
                     //安装模块
                     $status = $this->Cloud->install_module($command['package'], $command['hash'], $command['appid'], $command['option']);
                     //安装成功
                     if ($status > 0) {
                         exit(serialize(array('appid' => $command['appid'], 'status' => 'success')));
                     } else {
                         //删除模块目录
                         $Dir->delDir($modulePath);
                         exit(serialize(array('error' => $status, 'errorinfo' => $this->Cloud->getError(), 'appid' => $command['appid'], 'status' => 'fail', 'lastfile' => $this->Cloud->lastfile, 'info' => $this->Cloud->getError())));
                     }
                     break;
                     //模块升级
                 //模块升级
                 case 'upgrade':
                     //缺少必要参数
                     if (!$command['appid'] || !$command['package']) {
                         exit(serialize(array('error' => -10011, 'appid' => $command['appid'], 'package' => $command['package'], 'status' => 'fail')));
                     }
                     //无效模块,也就是检查模块是否存在
                     if (D('Module')->exists($command['appid']) === FALSE) {
                         exit(serialize(array('error' => -10014, 'appid' => $command['appid'], 'status' => 'fail')));
                     }
                     //测试读写权限
                     $status = $this->Cloud->valid_perm($modulePath);
                     if (count($status)) {
                         exit(serialize(array('error' => -10007, 'catalog' => $status, 'status' => 'fail')));
                     }
                     //升级模块
                     $status = $this->Cloud->upgrade_module($command['package'], $command['hash'], $command['appid'], $command['option']);
                     //升级成功
                     if ($status > 0) {
                         exit(serialize(array('appid' => $command['appid'], 'status' => 'success')));
                     } else {
                         exit(serialize(array('error' => $status, 'errorinfo' => $this->Cloud->getError(), 'appid' => $command['appid'], 'status' => 'fail', 'lastfile' => $this->Cloud->lastfile)));
                     }
                     break;
                     //模块搜索
                 //模块搜索
                 case 'listing':
                     $module = array();
                     $moduleList = M('Module')->select();
                     if (empty($moduleList)) {
                         $moduleList = array();
                     }
                     foreach ($moduleList as $key => $app) {
                         unset($app['setting']);
                         $module[$app['module']] = $app;
                     }
                     exit(serialize(array('module' => $module, 'status' => 'success')));
                     break;
             }
             break;
             //插件处理
         //插件处理
         case 'addons':
             //检测是否有安装插件管理模块
             $appCache = F('App');
             if (!isset($appCache['Addons'])) {
                 exit(serialize(array('error' => -10015, 'status' => 'fail')));
             }
             //插件路径
             $addonPath = D('Addons/Addons')->getAddonsPath() . $command['name'] . '/';
             //操作
             switch ($command['method']) {
                 //插件安装
                 case 'install':
                     //缺少必要参数
                     if (empty($command['name']) || empty($command['package'])) {
                         exit(serialize(array('error' => -10011, 'name' => $command['name'], 'package' => $command['package'], 'status' => 'fail')));
                     }
                     //检查插件是否存在
                     if (D('Addons/Addons')->exists($command['name'])) {
                         exit(serialize(array('error' => -10016, 'name' => $command['name'], 'status' => 'fail')));
                     }
                     //创建插件目录
                     if (mkdir($addonPath, 0777, TRUE) === FALSE) {
                         //====表明已经存在目录,尝试检测权限
                         //测试读写权限
                         $status = $this->Cloud->valid_perm($addonPath);
                         if (count($status)) {
                             exit(serialize(array('error' => -10007, 'catalog' => $status, 'status' => 'fail')));
                         } else {
                             exit(serialize(array('error' => -10013, 'catalog' => $addonPath, 'status' => 'fail')));
                         }
                     } else {
                         //测试读写权限
                         $status = $this->Cloud->valid_perm($addonPath);
                         if (count($status)) {
                             exit(serialize(array('error' => -10007, 'catalog' => $status, 'status' => 'fail')));
                         }
                     }
                     //安装模块
                     $status = $this->Cloud->install_addons($command['package'], $command['hash'], $command['name'], $command['option']);
                     //安装成功
                     if ($status > 0) {
                         exit(serialize(array('name' => $command['name'], 'status' => 'success')));
                     } else {
                         //删除模块目录
                         $Dir->delDir($modulePath);
                         exit(serialize(array('error' => $status, 'errorinfo' => $this->Cloud->getError(), 'name' => $command['name'], 'status' => 'fail', 'lastfile' => $this->Cloud->lastfile)));
                     }
                     break;
                     //插件升级
                 //插件升级
                 case 'upgrade':
                     //缺少必要参数
                     if (!$command['name'] || !$command['package']) {
                         exit(serialize(array('error' => -10011, 'name' => $command['name'], 'package' => $command['package'], 'status' => 'fail')));
                     }
                     //无效模块,也就是检查模块是否存在
                     if (D('Addons/Addons')->exists($command['name']) === FALSE) {
                         exit(serialize(array('error' => -10017, 'name' => $command['name'], 'status' => 'fail')));
                     }
                     //测试读写权限
                     $status = $this->Cloud->valid_perm($addonPath);
                     if (count($status)) {
                         exit(serialize(array('error' => -10007, 'catalog' => $status, 'status' => 'fail')));
                     }
                     //升级插件
                     $status = $this->Cloud->upgrade_addons($command['package'], $command['hash'], $command['name'], $command['option']);
                     //升级成功
                     if ($status > 0) {
                         exit(serialize(array('name' => $command['name'], 'status' => 'success')));
                     } else {
                         exit(serialize(array('error' => $status, 'errorinfo' => $this->Cloud->getError(), 'name' => $command['name'], 'status' => 'fail', 'lastfile' => $this->Cloud->lastfile)));
                     }
                     break;
                     //插件搜索
                 //插件搜索
                 case 'listing':
                     $addon = array();
                     $addonList = M('Addons')->select();
                     if (empty($addonList)) {
                         $addonList = array();
                     }
                     foreach ($addonList as $key => $info) {
                         unset($info['config'], $info['description']);
                         $addon[$info['name']] = $info;
                     }
                     exit(serialize(array('addon' => $addon, 'status' => 'success')));
                     break;
             }
             break;
     }
 }
Exemplo n.º 17
0
 /**
  * 根据id批量生成内容页 
  */
 public function batch_show()
 {
     if (IS_POST) {
         $catid = intval($_GET['catid']);
         if (!$catid) {
             $this->error("栏目ID不能为空!");
         }
         $modelid = getCategory($catid, 'modelid');
         $setting = getCategory($catid, 'setting');
         $content_ishtml = $setting['content_ishtml'];
         if ($content_ishtml) {
             //主表名
             $table_name = ucwords($this->model[$modelid]['tablename']);
             if (empty($table_name)) {
                 $this->error("模型不存在!");
             }
             $this->db = ContentModel::getInstance($modelid);
             if (empty($_POST['ids'])) {
                 $this->error("您没有勾选信息!");
             }
             import('Html');
             $this->html = get_instance_of('Html');
             $ids = implode(',', $_POST['ids']);
             $where = array();
             $where['catid'] = array("EQ", $catid);
             $where['id'] = array("IN", $ids);
             $where['status'] = array("EQ", 99);
             $rs = $this->db->relation(true)->where($where)->select();
             foreach ($rs as $r) {
                 $this->db->dataMerger($r);
                 if ($r['islink']) {
                     continue;
                 }
                 if ($r['status'] != 99) {
                     continue;
                 }
                 $this->html->show($r, 0, 'edit');
             }
             $this->success("生成成功!");
         } else {
             $this->error("该栏目无需生成!");
         }
     } else {
         $catid = intval($_GET['catid']);
         if (!$catid) {
             $this->error("栏目ID不能为空!");
         }
         $modelid = getCategory($catid, 'modelid');
         $setting = getCategory($catid, 'setting');
         $content_ishtml = $setting['content_ishtml'];
         if ($content_ishtml) {
             //主表名
             $table_name = ucwords($this->model[$modelid]['tablename']);
             if (empty($table_name)) {
                 $this->error("模型不存在!");
             }
             $this->db = ContentModel::getInstance($modelid);
             if (empty($_GET['ids'])) {
                 $this->error("您没有勾选信息!");
             }
             import('Html');
             $this->html = get_instance_of('Html');
             $ids = (int) $_GET['ids'];
             $where = array();
             $where['catid'] = array("EQ", $catid);
             $where['id'] = array("EQ", $ids);
             $where['status'] = array("EQ", 99);
             $r = $this->db->relation(true)->where($where)->find();
             //数据处理,把关联查询的结果集合并
             $this->db->dataMerger($r);
             if ($r['status'] != 99) {
                 $this->error("该信息未审核!无需生成");
             }
             if ($r['islink']) {
                 $this->error("链接文章无需生成!");
             } else {
                 $this->html->show($r, 0, 'edit');
             }
             $this->success("生成成功!");
         } else {
             $this->error("该栏目无需生成!");
         }
     }
 }
Exemplo n.º 18
0
 /**
 +----------------------------------------------------------
 * 解析标签库的标签
 * 需要调用对应的标签库文件解析类
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $tagLib  标签库名称
 * @param string $tag  标签名
 * @param string $attr  标签属性
 * @param string $content  标签内容
 +----------------------------------------------------------
 * @return string|false
 +----------------------------------------------------------
 */
 public function parseXmlTag($tagLib, $tag, $attr, $content)
 {
     //if (MAGIC_QUOTES_GPC) {
     $attr = stripslashes($attr);
     $content = stripslashes($content);
     //}
     $tLib = get_instance_of('TagLib' . ucwords(strtolower($tagLib)));
     if ($tLib->valid()) {
         $parse = '_' . $tag;
         $content = trim($content);
         return $tLib->{$parse}($attr, $content);
     }
 }
Exemplo n.º 19
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;
     }
     import('UploadFile');
     $this->handlerLocal = get_instance_of('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("|", 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')->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();
                 Log::write('文件[' . $filePath . ']上传到FTP失败!');
                 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;
 }