dirname() ); define('M_URL',MAIN_SOURCE_URL.'/modules/'.$MAIN_PAGE -> dirname() ); $this -> act = !empty($_REQUEST['act']) ? $_REQUEST['act'] : $this -> act; include_once(M_PATH.'/inc/class.snippets.php'); include_once(MAIN_SOURCE_PATH.'/inc/class.html.php'); } public function get(){ $func = $this -> act; if ( !method_exists($this ,$func) ){ sys_error(ERROR_404); } return $this -> $func(); } private function ajax_main(){ $p = new snippetsQuery('p'); echo 'Редактировать страницу'; exit(); } private function ajax_snippet_edit(){ sys_block_disable(); $p = new snippetsQuery('p'); $p -> where_func($_GET['f_func']); $p -> where_module($_GET['m_path']); $p -> get('*'); $row = $p -> row(); $t = new PHPTAL(); $t -> setSnippet('admin','ajax_edit_fast_snippet');// M_PATH.'/tmpl/control_snippets/edit_short.html' ); $t -> row = $row ; $e = html_control::editor('codemirror'); $e -> set_name('desc'); $e -> set_attr('cols',10); $t -> editor = $e -> show(); echo 'Редактировать шаблон execute().']]>'; exit(); } private function ajax_snippet_save(){ sys_block_disable(); $p = snippets::load_id($_POST['id']); //var_dump($_POST); //$p -> set_debug(1); //foreach( $_POST['form'] as $k=>$v ){ // $p -> set($k,$v); //} $p -> set('snippet',$_POST['snippet']); $id = $p -> update(); exit(); } private function make_md5($path){ $path = !empty($path) ? $path : MAIN_PATH.$_GET['path']; $this -> inc_make_md5($path); exit(); } private function inc_make_md5($path){ //echo $path .'
'; if ($handle = opendir($path)) { self::inc_insert_dir($path); $rows = array(); while (false !== ($file = readdir($handle))) { $row = array(); if ( is_dir ($path.$file) ){ if ( $file=='.' || $file=='..' ){ continue; } echo $path.$file.'
'; $this -> inc_make_md5($path.$file.'/'); continue; }else{ echo $path.$file.'
'; $row['is_dir'] = 0; $row['hash'] = md5_file( $path.$file ); } $row['file'] = $path.$file; $row['time'] = MAIN_TIME; self::inc_insert_dir($path.$file,$row); } self::inc_insert_dir($path, array('time'=>MAIN_TIME,'is_dir'=>1) ); closedir($handle); } } static function inc_insert_dir($path,$row=array() ){ global $MAIN_DB; $path = str_replace(MAIN_PATH,'',$path); $row['file'] = $path; $sql_set = array(); foreach( $row as $k=>$v ){ $sql_set[]='`'.$k.'` = "'.$v.'"'; } $sql_set = implode(',',$sql_set); $sql = "SELECT COUNT(*) FROM ".$MAIN_DB -> prefix("system_md5")." WHERE file='$path'"; list($count)= $MAIN_DB -> fetch_array( $MAIN_DB -> query($sql) ); if ( $count>0 ){ $sql = "UPDATE ".$MAIN_DB -> prefix("system_md5")." SET ".$sql_set." WHERE file='$path'"; }else{ $sql = "INSERT INTO ".$MAIN_DB -> prefix("system_md5")." SET ".$sql_set." "; } $MAIN_DB -> query($sql); } /*************** * * запускаем проверку целосности системы * запускать нужно через крон. * отчёты о изменениях отправляются администратору на мыло * *************/ private function check_md5(){ //set_time_limit(3000); $p = !empty($_GET['path']) ? MAIN_PATH.$_GET['path'] : MAIN_PATH; $this -> inc_scan_md5($p); // пишите письма var_dump($this->result); echo 'end'; exit(); } // сканируем каталог path и все подкаталоги на наличие изменений в файлах private function inc_scan_md5($path=MAIN_PATH){ echo $path.'
'; if ($handle = opendir($path)) { echo '1'; $rows = array(); while (false !== ($file = readdir($handle))) { $row = array(); if ( is_dir ($path.$file) ){ if ( $file=='.' || $file=='..' ){ continue; } echo $path.$file.'
'; $this -> inc_scan_md5($path.$file.'/'); continue; } echo $path.$file.'
'; $row['is_dir'] = 0; $row['hash'] = md5_file( $path.$file ); $row['file'] = $path.$file; $row['time'] = MAIN_TIME; $row['path'] = $path; $r = self::inc_check_dir($path.$file,$row); if ( !empty($r) ){ $this->result[]= $r; } } closedir($handle); } } static function inc_check_dir($path,$row=array()){ global $MAIN_DB; $path = str_replace(MAIN_PATH,'',$path); $result = array(); $sql = "SELECT * FROM ".$MAIN_DB -> prefix("system_md5")." WHERE file='$path' "; $data = $MAIN_DB -> fetch_array( $MAIN_DB -> query($sql) ); if ( !$data ){ $sql = "SELECT exseption FROM ".$MAIN_DB -> prefix("system_md5")." WHERE file='".$row['path']."' "; list($exs) = $MAIN_DB -> fetch_array( $MAIN_DB -> query($sql) ); if ( $exs ){ return false; } //self::inc_insert_dir($path,$row); // найден новый файл return 'Найден новый объект "'.$path.'"'; } if ( $row['hash']!=$data['hash'] && $data['exseption']!=1 ){ //$sql = "UPDATE ".$MAIN_DB -> prefix("system_md5")." SET hash='".$row['hash']."' WHERE file='$path' "; //$MAIN_DB -> query($sql); return 'Объект "'.$path.'" изменился'; } return false; } } ?>