File: /www/wwwroot/bs.kntsleep.com/system/admin/tight/tight.class.php
<?php
/*
* Copyright (c) Huyin Information Technology Co., Ltd. All Rights Reserved.
* BOSSCMS Content Management System (https://www.bosscms.net/)
*/
defined('IS_OK') or exit('Access Forbidden');
into::basic_class('admin');
class tight extends admin
{
public function init()
{
global $G;
$G['cover'] = $this->cover();
$data = array();
$path = ROOT_PATH.'system/web/common/tight/';
$tight = dir::readall($path);
$G['tight'] = json::decode($G['config']['tight']);
foreach($tight as $v){
$sign = str_replace('.json','',$v);
$data[$sign] = array(
'name' => $G['tight'][$sign],
'sign' => $sign
);
ksort($data);
}
foreach($G['tight'] as $k=>$v){
if(!$data[$k]){
$data[$k] = array(
'name' => $v,
'sign' => $k
);
dir::create("{$path}{$k}.json",'[]');
}
}
echo $this->theme('tight/tight', $data);
}
public function edit()
{
global $G;
/* boss_CMS */
$G['cover'] = $this->cover('tag');
$data = array();
if(isset($G['get']['id'])){
$data = array(
'name' => arrExist(json::decode($G['config']['tight']),$G['get']['id']),
'sign' => $G['get']['id']
);
}
echo $this->theme('tight/edit', $data);
}
public function add()
{
global $G;
$G['cover'] = $this->cover('tight',$G['get']['id']?'M':'A');
if(preg_match('/^\w+$/',$G['post']['sign'])){
$path = ROOT_PATH.'system/web/common/tight/';
$data = json::decode($G['config']['tight']);
if(preg_match('/^\w+$/',$G['get']['id'])){
if($G['get']['id'] != $G['post']['sign']){
unset($data[$G['get']['id']]);
dir::move("{$path}{$G['get']['id']}.json","{$path}{$G['post']['sign']}.json");
}
}else{
if(!is_file("{$path}{$G['post']['sign']}.json")){
dir::create("{$path}{$G['post']['sign']}.json");
}
}
$data[$G['post']['sign']] = $G['post']['name'];
mysql::select_set(array('name'=>'tight','value'=>json::enfilter($data),'parent'=>'0','type'=>'0'),'config',array('value'));
alert('修改成功', url::mpf('tight','tight','edit',array('success'=>'ok')));
}else{
alert('没有提交信息');
}
}
public function import()
{
global $G;
$G['cover'] = $this->cover('tight','R');
$data = array();
into::basic_json('tight');
foreach($G['tight'] as $k=>$v){
$data[] = array(
'name' => $v['name'],
'sign' => $k
);
}
echo $this->theme('tight/import', $data);
}
public function put()
{
global $G;
$this->cover('tight','M');
if($G['post']['id']){
$data = json::decode($G['config']['tight']);
into::basic_json('tight');
foreach($G['post']['id'] as $id){
if(preg_match('/^\w+$/',$id) && $G['tight'][$id]){
dir::create(ROOT_PATH.'system/web/common/tight/'.$id.'.json',json::encode($G['tight'][$id]['content']));
$data[$id] = $G['post']['name_'.$id];
}
}
mysql::select_set(array('name'=>'tight','value'=>json::enfilter($data),'parent'=>'0','type'=>'0'),'config',array('value'));
alert('导入成功', url::mpf('tight','tight','init',array('success'=>'ok')));
}
alert('没有提交信息');
}
public function delete()
{
global $G;
$this->cover('tight','D');
if(isset($G['post']['url']) && isset($G['get']['id'])){
$del = array();
$arr = explode(',',$G['get']['id']);
foreach($arr as $id){
if(preg_match('/^\w+$/',$id)){
$del[$id] = $id;
}
}
if($del){
$error=array();
$path = ROOT_PATH.'system/web/common/tight/';
$data = json::decode($G['config']['tight']);
foreach($del as $sign){
dir::delete("{$path}{$sign}.json");
unset($data[$sign]);
}
mysql::select_set(array('name'=>'tight','value'=>json::enfilter($data),'parent'=>'0','type'=>'0'),'config',array('value'));
alert('删除成功', url::mpf('tight','tight','init',array('id'=>null)));
}else{
alert('没有删除对象id');
}
}
alert('没有提交信息');
}
}
?>