KodExplorer/app/controller/fav.class.php

83 lines
1.8 KiB
PHP
Raw Normal View History

2015-03-22 20:54:54 +00:00
<?php
/*
2017-08-23 19:40:27 +00:00
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
2015-03-22 20:54:54 +00:00
* @copyright warlee 2014.(Shanghai)Co.,Ltd
2017-08-23 19:40:27 +00:00
* @license http://kodcloud.com/tools/license/license.txt
2015-03-22 20:54:54 +00:00
*/
class fav extends Controller{
2016-12-21 08:01:06 +00:00
private $sql;
function __construct(){
parent::__construct();
2017-08-23 19:40:27 +00:00
$this->sql=new FileCache(USER.'data/fav.php');
2016-12-21 08:01:06 +00:00
}
2015-03-22 20:54:54 +00:00
2016-12-21 08:01:06 +00:00
/**
* 获取收藏夹json
*/
public function get() {
show_json($this->sql->get());
}
2015-03-22 20:54:54 +00:00
2016-12-21 08:01:06 +00:00
/**
* 添加
*/
public function add() {
$name = $this->in['name'];
$path = $this->in['path'];
if($this->sql->get($name)){//已存在则自动重命名
$index = 0;
while ($this->sql->get($name.'('.$index.')')) {
$index ++;
}
$name = $name.'('.$index.')';
}
$res=$this->sql->set(
$name,
array(
'name' => $name,
'path' => $path,
'ext' => $this->in['ext'],
'type' => $this->in['type']
)
);
2017-08-23 19:40:27 +00:00
show_json(LNG('success'));
2016-12-21 08:01:06 +00:00
}
2015-03-22 20:54:54 +00:00
2016-12-21 08:01:06 +00:00
/**
* 编辑
*/
public function edit() {
$this->in['name'] = $this->in['name'];
$this->in['path'] = $this->in['path'];
2017-08-23 19:40:27 +00:00
$this->in['nameTo'] = $this->in['nameTo'];
$newFav = $this->sql->get($this->in['name']);
if(!isset($newFav['type'])){
$newFav['type'] = 'folder';
2016-12-21 08:01:06 +00:00
}
//查找到一条记录,修改为该数组
2017-08-23 19:40:27 +00:00
$toArray=array(
'name'=>$this->in['nameTo'],
'path'=>$this->in['pathTo'],
'type'=>$newFav['type']
2016-12-21 08:01:06 +00:00
);
$this->sql->remove($this->in['name']);
2017-08-23 19:40:27 +00:00
if($this->sql->set($this->in['nameTo'],$toArray)){
show_json(LNG('success'));
2016-12-21 08:01:06 +00:00
}
2017-08-23 19:40:27 +00:00
show_json(LNG('error_repeat'),false);
2016-12-21 08:01:06 +00:00
}
2015-03-22 20:54:54 +00:00
2016-12-21 08:01:06 +00:00
/**
* 删除
*/
public function del() {
$this->in['name'] = $this->in['name'];
if($this->sql->remove($this->in['name'])){
2017-08-23 19:40:27 +00:00
show_json(LNG('success'));
2016-12-21 08:01:06 +00:00
}
2017-08-23 19:40:27 +00:00
show_json(LNG('error'),false);
2016-12-21 08:01:06 +00:00
}
2015-03-22 20:54:54 +00:00
}