From 9610250d1356c83d12d7aa947019431cbc1b8daf Mon Sep 17 00:00:00 2001 From: indeferend Date: Sun, 23 May 2021 18:53:36 +0500 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BD=D0=BE=D1=81=20=D1=84=D1=83?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB=D0=B0=20blog?= =?UTF-8?q?=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLASSES/blog.php | 49 ++++++++++++++++++- CLASSES/core/LE_MOD_CONTROLLER.php | 2 +- MODULES/admin/blog.php | 77 ++++++------------------------ 3 files changed, 63 insertions(+), 65 deletions(-) diff --git a/CLASSES/blog.php b/CLASSES/blog.php index c7eb2d0..1b40831 100644 --- a/CLASSES/blog.php +++ b/CLASSES/blog.php @@ -1,9 +1,56 @@ 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]); + } } \ No newline at end of file diff --git a/CLASSES/core/LE_MOD_CONTROLLER.php b/CLASSES/core/LE_MOD_CONTROLLER.php index cdb15aa..511690a 100644 --- a/CLASSES/core/LE_MOD_CONTROLLER.php +++ b/CLASSES/core/LE_MOD_CONTROLLER.php @@ -117,7 +117,7 @@ abstract class LE_MOD_CONTROLLER //возвращать массив ответа как есть, не оборачивая в data if (isset($res['as_is']) && $res['as_is']) { - unset($res['as_id']); + unset($res['as_is']); $out = $res; } diff --git a/MODULES/admin/blog.php b/MODULES/admin/blog.php index 2f8a081..7148a91 100644 --- a/MODULES/admin/blog.php +++ b/MODULES/admin/blog.php @@ -1,94 +1,45 @@ check_dest_folder($dest)) return false; - $filename = LE_FS::SAVE_POST(['f_name'=>'upload','path'=>$dest]); - return ['url'=>'/pub_data/upload/img/'.$filename, 'as_is'=>1]; + if( ($filename = $this->model->add_img()) !==false ) + return ['url'=>'/pub_data/upload/img/'.$filename, 'as_is'=>1]; + return false; } protected function _ajx_save_content($data) { $id = PRE::INT($data['id']); - $html_cont = $data['html_cont']; preg_match('!(

(.*?)<\/h1>)?(.*)!simu',$html_cont,$out); - $html_cont = $out[3]; - $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; + return $this->model->save_it($id,['html'=>$out[3],'head'=>trim($out[2])]); } protected function _ajx_remove_it($inp) { if (!isset($inp['id'])) return false; - - $id=PRE::INT($inp['id']); - if (!$id>0) return false; - $res = LE::$DB->DEL('text_content',$id); - return ($res>0); + return $this->model->rem_it($inp['id']); } protected function _inp_default($inp) { - $res = LE::$DB->query_arr("SELECT * FROM `text_content`",'id'); - - $to_tpl['cont_list'] = $res; - return LE::$TPL->fetch('blog/list',$to_tpl); + $data = $this->model->get_list(); + $to_tpl['cont_list'] = $data; + return LE::$TPL->fetch('blog/list',$to_tpl); } protected function _inp_edit($inp) { - $id = PRE::INT($inp); - if ($id>0) - { - $res = LE::$DB->query_single("SELECT * FROM `text_content` WHERE `id`=".$id); - $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'] - ]; - + $id = PRE::INT($inp)+0; + $res = ($id>0) ? $this->model->get_it($id) : ['html'=>'','head'=>'','data'=>[]]; + + $to_tpl = [ 'data'=>$res['data'], 'id'=>$id, 'html_cont'=>$res['html'], 'head'=>$res['head']]; return LE::$TPL->fetch('blog/edit_item',$to_tpl); } } - - - include CLSDIR."blog.php"; $blog_model = new blog_model; - -$controller = new CONTR($le_mod_loader->url,$blog_model); - - -LE::$TPL->mod_cont .= $controller->start(); \ No newline at end of file +LE::$TPL->mod_cont .= (new CONTR($le_mod_loader->url,$blog_model))->start(); \ No newline at end of file