parent
6c1142f338
commit
9610250d13
@ -1,9 +1,56 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//модель для блога
|
||||||
class blog_model
|
class blog_model
|
||||||
{
|
{
|
||||||
|
public $table = "text_content";
|
||||||
|
|
||||||
|
function __construct($table=false)
|
||||||
|
{
|
||||||
|
//custom table in db
|
||||||
|
if ($table!==false) $this->table = $table;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_it($id)
|
||||||
|
{
|
||||||
|
$res = LE::$DB->query_single("SELECT * FROM `".$this->table."` WHERE `id`=".$id);
|
||||||
|
$res['data'] = json_decode($res['data'],1);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_list($inp=false)
|
||||||
|
{
|
||||||
|
return LE::$DB->query_arr("SELECT * FROM `".$this->table."`",'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save_it($id,$data=[])
|
||||||
|
{
|
||||||
|
$data['id']=PRE::INT($id);
|
||||||
|
|
||||||
|
return LE::$DB->SAVE($this->table,$data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rem_it($id=0)
|
||||||
|
{
|
||||||
|
$id=PRE::INT($id);
|
||||||
|
if (!$id>0) return false;
|
||||||
|
$res = LE::$DB->DEL($this->table,$id);
|
||||||
|
return ($res>0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function check_dest_folder($f)
|
||||||
|
{
|
||||||
|
if (!is_dir($f))
|
||||||
|
if(mkdir($f,0777,true)===false)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_img()
|
||||||
|
{
|
||||||
|
if (!isset($_FILES['upload'])) return false;
|
||||||
|
$dest = WEBDIR.'pub_data/upload/img/';
|
||||||
|
if (!$this->check_dest_folder($dest)) return false;
|
||||||
|
return LE_FS::SAVE_POST(['f_name'=>'upload','path'=>$dest]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,94 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class CONTR extends LE_MOD_CONTROLLER {
|
class CONTR extends LE_MOD_CONTROLLER {
|
||||||
|
|
||||||
protected function check_dest_folder($f)
|
|
||||||
{
|
|
||||||
if (!is_dir($uploaddir))
|
|
||||||
if(mkdir($uploaddir,0777,true)===false)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
protected function _ajx_add_img($data)
|
protected function _ajx_add_img($data)
|
||||||
{
|
{
|
||||||
if (!isset($_FILES['upload'])) return false;
|
if( ($filename = $this->model->add_img()) !==false )
|
||||||
$dest = WEBDIR.'pub_data/upload/img/';
|
return ['url'=>'/pub_data/upload/img/'.$filename, 'as_is'=>1];
|
||||||
if (!$this->check_dest_folder($dest)) return false;
|
return false;
|
||||||
$filename = LE_FS::SAVE_POST(['f_name'=>'upload','path'=>$dest]);
|
|
||||||
return ['url'=>'/pub_data/upload/img/'.$filename, 'as_is'=>1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _ajx_save_content($data)
|
protected function _ajx_save_content($data)
|
||||||
{
|
{
|
||||||
$id = PRE::INT($data['id']);
|
$id = PRE::INT($data['id']);
|
||||||
|
|
||||||
$html_cont = $data['html_cont'];
|
$html_cont = $data['html_cont'];
|
||||||
preg_match('!(<h1>(.*?)<\/h1>)?(.*)!simu',$html_cont,$out);
|
preg_match('!(<h1>(.*?)<\/h1>)?(.*)!simu',$html_cont,$out);
|
||||||
$html_cont = $out[3];
|
return $this->model->save_it($id,['html'=>$out[3],'head'=>trim($out[2])]);
|
||||||
$html_head = trim($out[2]);
|
|
||||||
//return;
|
|
||||||
|
|
||||||
$save_data = ['id'=>$id,'html'=>$html_cont,'head'=>$html_head];
|
|
||||||
|
|
||||||
$id = LE::$DB->SAVE('text_content',$save_data);
|
|
||||||
|
|
||||||
return $id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _ajx_remove_it($inp)
|
protected function _ajx_remove_it($inp)
|
||||||
{
|
{
|
||||||
if (!isset($inp['id'])) return false;
|
if (!isset($inp['id'])) return false;
|
||||||
|
return $this->model->rem_it($inp['id']);
|
||||||
$id=PRE::INT($inp['id']);
|
|
||||||
if (!$id>0) return false;
|
|
||||||
$res = LE::$DB->DEL('text_content',$id);
|
|
||||||
return ($res>0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _inp_default($inp)
|
protected function _inp_default($inp)
|
||||||
{
|
{
|
||||||
$res = LE::$DB->query_arr("SELECT * FROM `text_content`",'id');
|
$data = $this->model->get_list();
|
||||||
|
$to_tpl['cont_list'] = $data;
|
||||||
$to_tpl['cont_list'] = $res;
|
return LE::$TPL->fetch('blog/list',$to_tpl);
|
||||||
return LE::$TPL->fetch('blog/list',$to_tpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _inp_edit($inp)
|
protected function _inp_edit($inp)
|
||||||
{
|
{
|
||||||
$id = PRE::INT($inp);
|
$id = PRE::INT($inp)+0;
|
||||||
if ($id>0)
|
$res = ($id>0) ? $this->model->get_it($id) : ['html'=>'','head'=>'','data'=>[]];
|
||||||
{
|
|
||||||
$res = LE::$DB->query_single("SELECT * FROM `text_content` WHERE `id`=".$id);
|
$to_tpl = [ 'data'=>$res['data'], 'id'=>$id, 'html_cont'=>$res['html'], 'head'=>$res['head']];
|
||||||
$it_data = json_decode($res['data'],1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$res = ['html'=>'','head'=>''];
|
|
||||||
$it_data = [];
|
|
||||||
$id=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$to_tpl = [
|
|
||||||
'data'=>$it_data,
|
|
||||||
'id'=>$id,
|
|
||||||
'html_cont'=>$res['html'],
|
|
||||||
'head'=>$res['head']
|
|
||||||
];
|
|
||||||
|
|
||||||
return LE::$TPL->fetch('blog/edit_item',$to_tpl);
|
return LE::$TPL->fetch('blog/edit_item',$to_tpl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
include CLSDIR."blog.php";
|
include CLSDIR."blog.php";
|
||||||
$blog_model = new blog_model;
|
$blog_model = new blog_model;
|
||||||
|
|
||||||
|
LE::$TPL->mod_cont .= (new CONTR($le_mod_loader->url,$blog_model))->start();
|
||||||
$controller = new CONTR($le_mod_loader->url,$blog_model);
|
|
||||||
|
|
||||||
|
|
||||||
LE::$TPL->mod_cont .= $controller->start();
|
|
Loading…
Reference in new issue