KodExplorer/app/controller/app.class.php

140 lines
3.2 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 app extends Controller{
2016-12-21 08:01:06 +00:00
function __construct() {
parent::__construct();
2017-08-23 19:40:27 +00:00
$this->sql=new FileCache(USER_SYSTEM.'apps.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
/**
* 用户首页展示
*/
public function index() {
2017-08-23 19:40:27 +00:00
$this->display(TEMPLATE.'app/index.html');
2016-12-21 08:01:06 +00:00
}
2015-03-22 20:54:54 +00:00
2017-08-23 19:40:27 +00:00
public function initApp(){
2016-12-21 08:01:06 +00:00
$list = $this->sql->get();
2017-08-23 19:40:27 +00:00
$newUserApp = $this->config['settingSystem']['newUserApp'];
$default = explode(',',$newUserApp);
2016-12-21 08:01:06 +00:00
$info = array();
foreach ($default as $key) {
$info[$key] = $list[$key];
}
2017-04-07 13:11:01 +00:00
$desktop = iconv_system(HOME.DESKTOP_FOLDER.'/');
2017-08-23 19:40:27 +00:00
if($GLOBALS['isRoot'] == 1){
2017-04-07 13:11:01 +00:00
$desktop = iconv_system(MYHOME.DESKTOP_FOLDER.'/');
}
2016-12-21 08:01:06 +00:00
mk_dir($desktop);
2016-12-30 15:55:50 +00:00
if(!path_writeable($desktop)){
2016-12-21 08:01:06 +00:00
return;
}
foreach ($info as $key => $data) {
if (!is_array($data)) {
continue;
}
2016-12-30 15:55:50 +00:00
$path = $desktop.iconv_system($key).'.oexe';
2016-12-21 08:01:06 +00:00
unset($data['name']);
unset($data['desc']);
unset($data['group']);
file_put_contents($path, json_encode($data));
2016-12-30 15:55:50 +00:00
}
2016-12-21 08:01:06 +00:00
}
2015-03-22 20:54:54 +00:00
2016-12-21 08:01:06 +00:00
/**
* 用户app 添加、编辑
*/
2017-08-23 19:40:27 +00:00
public function userApp() {
2016-12-21 08:01:06 +00:00
$path = _DIR($this->in['path']);
2016-12-23 03:47:43 +00:00
if (isset($this->in['action']) &&
$this->in['action'] == 'add'){
2016-12-21 08:01:06 +00:00
$path .= '.oexe';
}
if (!checkExt($path)) {
2017-08-23 19:40:27 +00:00
show_json(LNG('error'));exit;
2016-12-21 08:01:06 +00:00
}
2016-12-23 03:47:43 +00:00
$data = $this->_init();
2017-08-23 19:40:27 +00:00
unset($data['name']);
unset($data['path']);
unset($data['desc']);
unset($data['group']);
2016-12-21 08:01:06 +00:00
$res = file_put_contents($path, json_encode($data));
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 get() {
$list = array();
if (!isset($this->in['group']) || $this->in['group']=='all') {
$list = $this->sql->get();
}else{
$list = $this->sql->get(array('group',$this->in['group']));
}
$list = array_reverse($list);
show_json($list);
}
2015-03-22 20:54:54 +00:00
2016-12-21 08:01:06 +00:00
/**
* 添加
*/
public function add() {
$res=$this->sql->set(rawurldecode($this->in['name']),$this->_init());
2017-08-23 19:40:27 +00:00
if($res) show_json(LNG('success'));
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 edit() {
//查找到一条记录,修改为该数组
$this->sql->remove(rawurldecode($this->in['old_name']));
if($this->sql->set(rawurldecode($this->in['name']),$this->_init())){
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_repeat'),false);
2016-12-21 08:01:06 +00:00
}
/**
* 删除
*/
public function del() {
if($this->sql->remove(rawurldecode($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
2017-08-23 19:40:27 +00:00
public function getUrlTitle(){
$html = url_request($this->in['url']);
2016-12-21 08:01:06 +00:00
$result = match($html,"<title>(.*)<\/title>");
if (strlen($result)>50) {
$result = mb_substr($result,0,50,'utf-8');
}
if (!$result || strlen($result) == 0) {
$result = $this->in['url'];
$result = str_replace(array('http://','&','/'),array('','@','-'), $result);
}
show_json($result);
}
2015-03-22 20:54:54 +00:00
2016-12-21 08:01:06 +00:00
private function _init(){
2016-12-23 03:47:43 +00:00
$data = rawurldecode($this->in['data']);
$arr = json_decode($data,true);
if(!is_array($arr)){
2017-08-23 19:40:27 +00:00
show_json(LNG('error'),false);
2016-12-23 03:47:43 +00:00
}
return $arr;
2016-12-21 08:01:06 +00:00
}
2015-03-22 20:54:54 +00:00
}