* @copyright: Copyright (c) 2010, Bunzia Alexander * @version: 1.0 * @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL * @package HiLo CMS */ /* * управление статичными страничками на сайте * */ class admin_stat_pages{ private $error = false; private $act = 'index'; private $JsHttpRequest = false; public function __construct(){ global $MAIN_PAGE; define('M_PATH',MAIN_SOURCE_PATH.'/modules/'.$MAIN_PAGE -> dirname() ); define('M_URL',MAIN_SOURCE_URL.'/modules/'.$MAIN_PAGE -> dirname() ); define('A_CHARSET', $MAIN_PAGE -> charset() ); include_once(M_PATH.'/inc/url.php'); include_once(M_PATH.'/inc/class.stat_pages.php'); //include_once(M_PATH.'/inc/class.modules.php'); include_once(MAIN_SOURCE_PATH.'/modules/admin/lang/'.MAIN_LANG.'/lang.php'); include_once(MAIN_SOURCE_PATH.'/inc/class.html.php'); include(MAIN_SOURCE_PATH.'/ext/ajax/JsHttpRequest.php'); $this -> JsHttpRequest = new JsHttpRequest( A_CHARSET ); $this -> act = !empty($_REQUEST['act']) ? $_REQUEST['act'] : $this -> act; $GLOBALS['_RESULT']['id_request'] = !empty($_REQUEST['id_request']) ? $_REQUEST['id_request'] : 0; } public function get(){ //sleep(2); $func = $this -> act; if ( !method_exists($this ,$func) ){ sys_error(ERROR_404); } return $this -> $func(); } // выводим заданную страницу private function ajax_view(){ sys_block_disable(); $p = new stat_pages_q('f'); $p -> include_tmpl('t','t.t_path'); $url = preg_replace('#^/#','',$_REQUEST['url']); if (! $p -> where_url($url) ){ sys_error(ERROR_404); } //$p -> set_debug(1); $p -> get('f.*,f.p_id as check_access',false); $row = $p -> row(); if ( !is_array($row)){ exit(); } if ( !$row['check_access'] ){ exit(); } // меняем вывод блоков //$MAIN_PAGE -> set_tmpl_id($row['t_id']); // меняем вывод шаблона //$MAIN_PAGE -> set_tmpl($row['t_path']); $GLOBALS['_RESULT']['content'] = $row['p_content']; $GLOBALS['_RESULT']['title'] =$row['p_meta_title']; exit(); } // выводим заданную страницу private function view(){ global $MAIN_PAGE; $p = new stat_pages_q('f'); $p -> include_tmpl('t','t.t_path'); $url = preg_replace('#^/#','',$_REQUEST['url']); if (! $p -> where_url($url) ){ sys_error(ERROR_404); } //$p -> set_debug(1); $p -> get('f.*,f.p_id as check_access',false); $row = $p -> row(); if ( !is_array($row)){ sys_error(ERROR_404); } if ( !$row['check_access'] ){ sys_error(ERROR_403); } // меняем вывод блоков $MAIN_PAGE -> set_tmpl_id($row['t_id']); // меняем вывод шаблона $MAIN_PAGE -> set_tmpl($row['t_path']); $MAIN_PAGE -> set_meta_title($row['p_meta_title']); $MAIN_PAGE -> set_meta_keywords($row['p_meta_desc']); $MAIN_PAGE -> set_meta_description($row['p_meta_keywords']); // выдаём контент if( $row['p_type_content']=='HTML' ){ return $row['p_content']; }elseif( $row['p_type_content']=='PHP' ){ return eval($row['p_type_content']); }elseif( $row['p_type_content']=='TMPL'){ // блоки генерим заранее, чтобы на них можно было ссылаться в шаблоне sys_blocks_enable(); $t = new PHPTAL(); $t -> setSource($row['p_content']); return $t -> execute(); } } // главная, формирует список шаблонов private function index(){ global $MAIN_USER; if ( !$MAIN_USER -> is_admin() ){ sys_error(ERROR_403); } $t = new PHPTAL( M_PATH.'/tmpl/control_stat_pages/main.html' ); $t -> URL_ADMIN_STAT_PAGES = sys_url(URL_ADMIN_STAT_PAGES); $t -> URL_ADMIN = sys_url(URL_ADMIN); $p = new stat_pages_q('f'); $p -> include_tmpl('t','t.t_name as tmpl_name'); $p -> orderby_id('DESC'); $p -> get('f.*',false); $rows= array(); while( $row = $p -> row() ){ $rows[] = arr_to_obj($row); } // редактор $e = html_control::editor('ck'); $e -> set_name('p_content'); $e -> set_value(''); $e -> set_attr('cols',10); $t -> editor = $e -> show(); // вывод $t -> rows = $rows; return $t -> execute(); } /* AJAX */ private function ajax_reload(){ global $MAIN_USER; if ( !$MAIN_USER -> is_admin() ){ sys_error(ERROR_403); } sys_block_disable(); $t = new PHPTAL( M_PATH.'/tmpl/control_stat_pages/inc/tmpl_row.html' ); $t -> execute = true; // выбираем страницы $p = new stat_pages_q('f'); $p -> include_tmpl('t','t.t_name as tmpl_name'); $p -> orderby_id('DESC'); $p -> get('f.*',false); $rows= array(); while( $row = $p -> row() ){ $rows[]=$row; } $t -> rows = $rows; $GLOBALS['_RESULT']['content'] = $t -> execute(); exit(); } // удаляем private function ajax_delete(){ global $MAIN_USER; if ( !$MAIN_USER -> is_admin() ){ sys_error(ERROR_403); } sys_block_disable(); $m = stat_pages::load_id($_REQUEST['id']); if ( false===$m ){ die( A_EMPTY_ID ); } $m -> delete(); exit(); } // форма редактирвоания $_REQUEST['id'] private function ajax_edit(){ global $MAIN_USER; if ( !$MAIN_USER -> is_admin() ){ sys_error(ERROR_403); } sys_block_disable(); // получаем из базы страницу $_REQUEST['id'] $p = new stat_pages_q('p'); if ( !$p -> where_id($_REQUEST['id']) ){ $row = array(); }else{ $p -> get('*, p_type_content AS type_content_tmpl, p_type_content AS type_content_php, p_type_content AS type_content_html, p_id as groups'); $row = $p -> row(); } // подключаем редактор $row['editor'] = 'p_content'; // список шаблонов include_once(MAIN_SOURCE_PATH.'/modules/admin/inc/class.tmpl.php'); $p = new tmpl_q('f'); $p -> orderby_tid('DESC'); $p -> get('f.t_id, f.t_name'); $s = new select_box(); $s -> selected_id($row['t_id']); $s -> empty_record(false); while( list($t_id,$t_name) = $p -> row() ){ $s -> set($t_id,$t_name ); } $row['tmpl_list']=$s -> get(); // группы $g = new group_select_box(); $row['group_list']=$g -> group_list($row['groups']); // формируем страницу $t = new PHPTAL( M_PATH.'/tmpl/control_stat_pages/edit.html' ); $t -> row = $row ; $GLOBALS['_RESULT']['content'] = $t -> execute(); $GLOBALS['_RESULT']['title'] = M_ADMIN_SP_ADD_EDIT_PAGE; exit(); } // сохранение формы редактирования private function ajax_save(){ global $MAIN_USER; if ( !$MAIN_USER -> is_admin() ){ sys_error(ERROR_403); } sys_block_disable(); // загружаем из базы $p = stat_pages::load_id($_REQUEST['id']); if ( false===$p ){ define('create',1); $p = stat_pages::create(); } // обновляем её $p -> set('p_url',$_REQUEST['p_url']); $p -> set('t_id',$_REQUEST['t_id']); $p -> set('p_content',$_REQUEST['p_content']); $p -> set('p_meta_title',$_REQUEST['p_meta_title']); $p -> set('p_meta_keywords',$_REQUEST['p_meta_keywords']); $p -> set('p_meta_desc',$_REQUEST['p_meta_desc']); $p -> set('p_type_content',$_REQUEST['p_type_content']); //$p -> set_debug(1); if ( create==1 ){ $id = $p -> insert(); }else{ $id = $p -> update(); } if ( false===$id ){ die( $p -> error() ); } // обновляем права доступа к страничке stat_pages::set_groups($id,$_REQUEST['access']); // обновляем морду $GLOBALS['_RESULT']['msg'] = M_ADMIN_SP_SAVE; exit(); } } ?>