Exemplo n.º 1
0
 /**
  * 检查是否已经安装
  * @param type $moduleName
  * @return boolean 有安装false,没安装true
  */
 public function isInstall($moduleName)
 {
     if (is_object(ShuipFCMS()->Module)) {
         return ShuipFCMS()->Module->isInstall($moduleName) ? false : true;
     } else {
         return \Libs\System\Module::getInstance()->isInstall($moduleName) ? false : true;
     }
 }
Exemplo n.º 2
0
/**
 * 输出tags内容
 * @param type $field 字段名
 * @param type $value 字段内容
 * @return type
 */
function tags($field, $value)
{
    if (empty($value)) {
        return array();
    }
    //把Tags进行分割成数组
    $tags = strpos($value, ',') !== false ? explode(',', $value) : explode(' ', $value);
    $return = array();
    foreach ($tags as $k => $v) {
        $url = ShuipFCMS()->Url->tags($v);
        $return[$k] = array('url' => $url['url'], 'tag' => $v);
    }
    return $return;
}
Exemplo n.º 3
0
 /**
  * 移动文件到指定目录
  * @param type $tmpdir 需要移动的文件路径
  * @param type $newdir 目标路径
  * @param type $pack 需要删除的安装包
  * @return boolean
  */
 public function movedFile($tmpdir, $newdir, $pack)
 {
     //删除文件包
     unlink($this->getPackFile($pack));
     $list = $this->rglob($tmpdir . '*', GLOB_BRACE);
     if (empty($list)) {
         $this->error = '移动文件到指定目录错误,原因:文件列表为空!';
         return false;
     }
     //权限检查
     if ($this->competence($tmpdir, $newdir) !== true) {
         return false;
     }
     //批量迁移文件
     foreach ($list as $file) {
         $newd = str_replace($tmpdir, $newdir, $file);
         //目录
         $dirname = dirname($newd);
         if (file_exists($dirname) == false && mkdir($dirname, 0777, TRUE) == false) {
             $this->error = "创建文件夹{$dirname}失败!";
             return false;
         }
         //检查缓存包中的文件如果文件或者文件夹存在,但是不可写提示错误
         if (file_exists($file) && is_writable($file) == false) {
             $this->error = "文件或者目录{$file},不可写!";
             return false;
         }
         //检查目标文件是否存在,如果文件或者文件夹存在,但是不可写提示错误
         if (file_exists($newd) && is_writable($newd) == false) {
             $this->error = "文件或者目录{$newd},不可写!";
             return false;
         }
         //检查缓存包对应的文件是否文件夹,如果是,则创建文件夹
         if (is_dir($file)) {
             //文件夹不存在则创建
             if (file_exists($newd) == false && mkdir($newd, 0777, TRUE) == false) {
                 $this->error = "创建文件夹{$newd}失败!";
                 return false;
             }
         } else {
             //========文件处理!=============
             if (file_exists($newd)) {
                 //删除旧文件(winodws 环境需要)
                 if (!unlink($newd)) {
                     $this->error = "无法删除{$newd}文件!";
                     return false;
                 }
             }
             //生成新文件,也就是把下载的,生成到新的路径中去
             if (!rename($file, $newd)) {
                 $this->error = "无法生成{$newd}文件!";
                 return false;
             }
         }
     }
     //删除临时目录
     ShuipFCMS()->Dir->delDir($tmpdir);
     return true;
 }
Exemplo n.º 4
0
 /**
  * 排行榜 (top) 
  * 参数名	 是否必须	 默认值	 说明
  * num	 否	 10	 返回数量
  * order	 否	 hits DESC	 排序类型
  */
 public function top($data)
 {
     //缓存时间
     $cache = (int) $data['cache'];
     $cacheID = to_guid_string($data);
     if ($cache && ($return = S($cacheID))) {
         return $return;
     }
     $num = $data['num'] ? $data['num'] : 10;
     $order = array("hits" => "DESC");
     if ($data['order']) {
         $order = $data['order'];
     }
     $where = array();
     //设置SQL where 部分
     if (isset($data['where']) && $data['where']) {
         $where['_string'] = $data['where'];
     }
     $return = $this->db->where($where)->order($order)->limit($num)->select();
     //增加访问路径
     foreach ($return as $k => $v) {
         $url = ShuipFCMS()->Url->tags($v);
         $return[$k]['url'] = $url['url'];
     }
     if ($cache) {
         S($cacheID, $return, $cache);
     }
     return $return;
 }
 public function public_step_3()
 {
     if (\Libs\System\RBAC::authenticate('install') !== true) {
         $this->errors('您没有该项权限!');
     }
     $module = I('get.module');
     S('Cloud', NULL);
     if ($this->Module->install($module)) {
         ShuipFCMS()->Dir->delDir(APP_PATH . "{$module}/Install/");
         $this->success('模块安装成功!');
     } else {
         $error = $this->Module->error;
         //删除目录
         ShuipFCMS()->Dir->delDir(APP_PATH . $module);
         $this->error($error ? $error : '模块安装失败!');
     }
 }
Exemplo n.º 6
0
 /**
  * 相关文章标签
  * 参数名	 是否必须	 默认值	 说明
  * catid	 否	 null	 调用栏目ID
  * where	 否	 null	 sql语句的where部分
  * nid	 否	 null	 排除id 一般是 $id,排除当前文章
  * relation	 否	 $relation	 无需更改
  * keywords	 否	 null	 内容页面取值:$rs[keywords]
  * num	 是	 null	 数据调用数量
  * @param $data
  */
 public function relation($data)
 {
     //缓存时间
     $cache = (int) $data['cache'];
     $cacheID = to_guid_string($data);
     if ($cache && ($key_array = S($cacheID))) {
         return $key_array;
     }
     $getLastSql = array();
     $catid = intval($data['catid']);
     if (!$catid) {
         return false;
     }
     if (!$this->set_modelid($catid)) {
         return false;
     }
     //调用数量
     $data['num'] = (int) $data['num'];
     if (!$data['num']) {
         $data['num'] = 10;
     }
     $where = array();
     //设置SQL where 部分
     if (isset($data['where']) && $data['where']) {
         $where['_string'] = $data['where'];
     }
     $where['status'] = array("EQ", 99);
     $order = $data['order'];
     $limit = $data['nid'] ? $data['num'] + 1 : $data['num'];
     //数据
     $key_array = array();
     $number = 0;
     //是否经过ContentOutput处理
     if ($data['output']) {
         ShuipFCMS()->ContentOutput->setModelid($this->modelid);
     }
     //根据手动添加的相关文章
     if ($data['relation']) {
         //跨模型
         if (strpos($data['relation'], ',')) {
             $relations = explode('|', $data['relation']);
             $newRela = array();
             $i = 1;
             foreach ($relations as $rs) {
                 if ($i >= $limit) {
                     break;
                 }
                 if (strpos($rs, ',')) {
                     $rs = explode(',', $rs);
                 } else {
                     $rs = array($this->modelid, $rs);
                 }
                 $newRela[$rs[0]][] = $rs[1];
                 $i++;
             }
             $_key_array = array();
             foreach ($newRela as $modelid => $catidList) {
                 $where['id'] = array('IN', $catidList);
                 $_list = \Content\Model\ContentModel::getInstance($modelid)->relation($data['moreinfo'] ? true : false)->where($where)->order($order)->select();
                 if (!empty($_list)) {
                     $_key_array = array_merge($_key_array, $_list);
                 }
                 $getLastSql[] = \Content\Model\ContentModel::getInstance($modelid)->getLastSql();
             }
         } else {
             $relations = explode('|', $data['relation']);
             $relations = array_diff($relations, array(null));
             $where['id'] = array('IN', $relations);
             $_key_array = $this->db->relation($data['moreinfo'] ? true : false)->where($where)->limit($limit)->order($order)->select();
             $getLastSql[] = $this->db->getLastSql();
         }
         foreach ($_key_array as $r) {
             $key = $r['catid'] . '_' . $r['id'];
             $key_array[$key] = $r;
             //调用副表的数据
             if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
                 $this->db->dataMerger($key_array[$key]);
             }
             if ($data['output']) {
                 $_original = $key_array[$key];
                 $key_array[$key] = ShuipFCMS()->ContentOutput->get($key_array[$key]);
                 $key_array[$key]['_original'] = $_original;
             }
         }
         $number = count($key_array);
         //删除id条件
         if (isset($where['id'])) {
             unset($where['id']);
         }
     }
     //根据关键字,进行标题匹配
     if ($data['keywords'] && $limit > $number) {
         //根据关键字的相关文章
         $limit = $limit - $number <= 0 ? 0 : $limit - $number;
         $keywords_arr = $data['keywords'];
         if ($keywords_arr && !is_array($keywords_arr)) {
             if (strpos($data['keywords'], ',') === false) {
                 $keywords_arr = explode(' ', $data['keywords']);
             } else {
                 $keywords_arr = explode(',', $data['keywords']);
             }
         }
         $i = 1;
         foreach ($keywords_arr as $_k) {
             $_k = str_replace('%', '', $_k);
             $where['keywords'] = array("LIKE", '%' . $_k . '%');
             $_r = $this->db->relation($data['moreinfo'] ? true : false)->where($where)->limit($limit)->order($order)->select();
             $getLastSql[] = $this->db->getLastSql();
             //数据重组
             $r = array();
             foreach ($_r as $rs) {
                 $r[$rs['id']] = $rs;
                 //调用副表的数据
                 if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
                     $this->db->dataMerger($r[$rs['id']]);
                 }
                 if ($data['output']) {
                     $_original = $r[$rs['id']];
                     $r[$rs['id']] = ShuipFCMS()->ContentOutput->get($r[$rs['id']]);
                     $r[$rs['id']]['_original'] = $_original;
                 }
             }
             $number += count($r);
             foreach ($r as $id => $v) {
                 $key = $v['catid'] . '_' . $v['id'];
                 if ($i <= $data['num'] && !in_array($id, $key_array)) {
                     $key_array[$key] = $v;
                 }
                 $i++;
             }
             if ($data['num'] < $number) {
                 break;
             }
         }
         unset($where['keywords']);
     }
     //去除排除信息
     if ($data['nid']) {
         $key = $data['catid'] . '_' . $data['nid'];
         unset($key_array[$key]);
     }
     //结果进行缓存
     if ($cache) {
         S($cacheID, $key_array, $cache);
     }
     if (APP_DEBUG) {
         $msg = "Content标签->relation:参数:catid={$catid} ,modelid={$modelid} ,order={$data['order']}\n";
         $msg .= "SQL:" . implode("\n", $getLastSql);
         \Think\Log::record($msg, \Think\Log::DEBUG);
     }
     return $key_array;
 }
Exemplo n.º 7
0
 /**
  * 删除自定义列表
  * @param type $id 自定义列表ID
  * @return boolean
  */
 public function deleteCustomlist($id)
 {
     if (empty($id)) {
         $this->error = '请指定需要删除的自定义列表!';
         return false;
     }
     //查询出信息
     $info = $this->where(array('id' => $id))->find();
     if (empty($info)) {
         $this->error = '该自定义列表不存在!';
         return false;
     }
     //删除生成的静态文件
     //计算总数
     $countArray = $this->query($info['totalsql']);
     if (!empty($countArray)) {
         $count = $countArray[0]['total'];
         //分页总数
         $paging = ceil($count / $info['lencord']);
         for ($i = 1; $i <= $paging; $i++) {
             $customlistUrl = ShuipFCMS()->Url->createListUrl($info, $i);
             if ($customlistUrl) {
                 //生成路径
                 $htmlpath = SITE_PATH . $customlistUrl["path"];
                 //删除
                 unlink($htmlpath);
             }
         }
     }
     if ($this->where(array('id' => $id))->delete() !== false) {
         return true;
     } else {
         $this->error = '删除失败!';
         return false;
     }
 }
 public function public_upgrade_3()
 {
     if (\Libs\System\RBAC::authenticate('upgrade') !== true) {
         $this->errors('您没有该项权限!');
     }
     $name = I('get.name');
     S('Cloud', NULL);
     if (D('Addons/Addons')->upgradeAddon($name)) {
         ShuipFCMS()->Dir->delDir(PROJECT_PATH . "Addon/{$name}/Upgrade/");
         $this->success('插件升级成功!');
     } else {
         $error = $this->Module->error;
         $this->error($error ? $error : '插件升级失败!');
     }
 }