EIOS/inc/blog.php

423 lines
17 KiB
PHP
Raw Permalink Normal View History

2023-12-28 15:39:22 +03:00
<?php
if (isset($_GET['page'])){ //РЕДАКТИРОВАНИЕ БЛОГОВ
if($_GET['page']=='write'){
//НАСТРОИМ ПАПКУ ДЛЯ ЗАГРУЗКИ ФОТО
$_SESSION['niceditor']['path1']='../../upload/blog/'.$_SESSION['user']['id'].'';
$_SESSION['niceditor']['path2']='/upload/blog/'.$_SESSION['user']['id'].'';
//echo '<pre>'.print_r($_SESSION['niceditor'],1).'</pre>';
if (!file_exists($_SESSION['niceditor']['path1'])){
//echo '1';
mkdir($_SESSION['niceditor']['path1'], 0766);
}
if (!file_exists('./upload/blog/'.$_SESSION['user']['id'].'')){
//echo '2';
mkdir('./upload/blog/'.$_SESSION['user']['id'], 0766);
}
if (isset($_POST['blog_add'])){//СОХРАНЕНИЕ ЗАПИСИ
$id = (int)$_POST['id'];
$id_category = (int)$_POST['id_category'];
$title = get_data_fu($_POST['title']);
$text_f = addslashes($_POST['text_f']);
$id_user = $_SESSION['user']['id'];
if (isset($_POST['comment'])) $comment=1; else $comment=0;
if (isset($_POST['zakrep'])) $zakrep=1; else $zakrep=0;
$sql = 'INSERT INTO '.$ST['dbpf'].'_blogs VALUES (0,'.mktime().','.mktime().','.$id_category.','.$id_user.',"'.$title.'","'.$text_f.'",1,0,'.$comment.','.$zakrep.')';
$rez=$DB->QUR_SEL($sql);
if(!$rez['err']){
$form['msg']='Запись добавлена';
unset($_GET['des']);
}else{
$form['err'][]='Ошибка добавления данных!';
}
}
if (isset($_POST['blog_edit'])){//РЕДАКТИРОВАНИЕ ЗАПИСИ
$id = (int)$_POST['id'];
$id_category = (int)$_POST['id_category'];
$title = get_data_fu($_POST['title']);
$text_f = addslashes($_POST['text_f']);
$id_user = $_SESSION['user']['id'];
if (isset($_POST['comment'])) $comment=1; else $comment=0;
if (isset($_POST['zakrep'])) $zakrep=1; else $zakrep=0;
$sql = 'UPDATE '.$ST['dbpf'].'_blogs SET data_u='.mktime().',id_category='.$id_category.',id_user='.$id_user.',title="'.$title.'",text_f="'.$text_f.'",comment='.$comment.', zakrep='.$zakrep.' WHERE id='.$id.' AND id_user='.$_SESSION['user']['id'].'';
$rez=$DB->QUR_SEL($sql);
if(!$rez['err']){
$form['msg']='Запись изменена';
unset($_GET['des']);
}else{
$form['err'][]='Ошибка изменения данных!';
}
}
if (isset($_GET['des'])){//ОБРАБОТКА ДЕЙСТВИЙ не требующих ответа от пользователя
if($_GET['des']=='del'){//Удаление блога
$form['id']=(int)$_GET['id'];
$sql='SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id='.$form['id'].'';
$rez=$DB->QUR_SEL($sql);
if($rez){
if ($rez[1]['id_user']==$_SESSION['user']['id']){//Хозяин записи
if($rez[1]['status']==1)
$DB->QUR('UPDATE '.$ST['dbpf'].'_blogs SET status=0 WHERE id='.$form['id'].' LIMIT 1');
if($rez[1]['status']==0)
$DB->QUR('DELETE FROM '.$ST['dbpf'].'_blogs WHERE id='.$form['id'].' LIMIT 1');
}else{
$DB->QUR('UPDATE '.$ST['dbpf'].'_blogs SET status=0 WHERE id='.$form['id'].' LIMIT 1');
}
}
unset($_GET['des']);
}
if($_GET['des']=='aprove'){//Активация блога
$form['id']=(int)$_GET['id'];
$DB->QUR('UPDATE '.$ST['dbpf'].'_blogs SET status=1 WHERE id='.$form['id'].' LIMIT 1');
unset($_GET['des']);
}
}
if (isset($_GET['des'])){//ОБРАБОТКА ДЕЙСТВИЙ
if ($_GET['des']=='add'){//ФОРМА ДОБАВЛЕНИЯ
$regim='aded';
$blogs=array();//
$form=array();
$form['ftitle']=$ST['page']['name'] = 'Добавление записи';
$form['btn_url']='blog_add';
$form['btn_name']='Добавить запись';
$form['id']=0;
$sql1='SELECT * FROM '.$ST['dbpf'].'_blogs_category ORDER BY pos';
$rez1=$DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
if (in_array($val1['id'],$_SESSION['user']['blog']['id_blog_category'])){
$form['categorys'][]=$val1;
}
}
}
}
if ($_GET['des']=='edit'){//ФОРМА РЕДАТКИРОВАНИЯ
$regim='aded';
$blogs=array();//
$form=array();
$form['ftitle']=$ST['page']['name'] = 'Редактирование записи';
$form['btn_url']='blog_edit';
$form['btn_name']='Редактировать запись';
$form['id']=(int)$_GET['id'];
$sql='SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id='.$form['id'].' AND id_user='.$_SESSION['user']['id'].'';
$rez=$DB->QUR_SEL($sql);
if($rez){
$form['title']=out_data_fu($rez[1]['title']);
$form['text_f']=out_data_fu($rez[1]['text_f']);
$form['comment']=(int)$rez[1]['comment'];
$form['zakrep']=(int)$rez[1]['zakrep'];
$sql1='SELECT * FROM '.$ST['dbpf'].'_blogs_category ORDER BY pos';
$rez1=$DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
if (in_array($val1['id'],$_SESSION['user']['blog']['id_blog_category'])){
if($val1['id']==$rez[1]['id_category']) $val1['sel']=1;
$form['categorys'][]=$val1;
}
}
}
}
}
}else{
$regim='show'; $form=array(); $blogs=array();
//надо определить записи которые необходимо отобразить пользователю!!!
$id_user = $_SESSION['user']['id'];
$id_cat = $_SESSION['user']['blog']['id_blog_category']; $id_cats=array();
foreach($id_cat as $key => $val) $id_cats[]=$val;
if (count($id_cats)) $wh = ' OR (id_category='.implode(' OR id_category=',$id_cats).')';
else $wh='';
$pagi=pagination_blog('SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id_user='.$id_user.$wh.'',10);
$sql1='SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id_user='.$id_user.$wh.' ORDER BY data_c DESC '.$pagi['limit'];
$rez1=$DB->QUR_SEL($sql1); //echo $sql1;
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
$val1['data_c']=date('H:i:s d.m.Y',$val1['data_c']);
$val1['data_u']=date('H:i:s d.m.Y',$val1['data_u']);
$val1['title']=out_data_fu($val1['title']);
$rez=$DB->QUR_SEL('SELECT * FROM '.$ST['dbpf'].'_blogs_category WHERE id='.$val1['id_category'].' LIMIT 1');
if($rez){ $val1['category'] = $rez[1]['name']; } else $val1['category']='не определили';
$blogs[] = $val1;
}
}
$ST['page']['name'] = 'Просмотр блогов';
}
$smarty->assign('form',$form);
$smarty->assign('regim',$regim);
$smarty->assign('pagination',$pagi);
$smarty->assign('blogs',$blogs);//список записей в блоге
$maincontent = $smarty->fetch('tpl_blog_write.html');
}
}
else{//ПРОСМОТР БЛОГА
$blog=array();
$ST['page']['name'] = 'Блоги';
$blog['breadcrumb']=array();//навигационная лента
$blog['breadcrumb'][0]['url']='/';
$blog['breadcrumb'][0]['name']='Главная';
$blog['breadcrumb'][1]['url']='/blog/';
$blog['breadcrumb'][1]['name']='Блог';
$blog['breadcrumb'][1]['active']=1;
{//КАТЕГОРИЯ
$icons=array(0=>'icon-trophy','icon-plane','icon-pushpin','icon-beaker','icon-bullhorn','icon-trophy','icon-umbrella');
$blog['category']=array();
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs_category ORDER BY pos LIMIT 6';
$rez=$DB->QUR_SEL($sql);
if($rez){
$i=0; foreach($rez as $key => $val)if($key){
$blog['category'][$i]['url']='/blog/'.$val['alt_name'].'/';
$blog['category'][$i]['name']=''.out_data_fu($val['name']).'';
$blog['category'][$i]['icon']=$icons[$i];
$i++;
}
}
}
{//ПОСЛЕДНИЕ СООБЩЕНИЯ
$blog['latest']=array();
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs ORDER BY zakrep, data_c DESC LIMIT 5';
$rez=$DB->QUR_SEL($sql);
if($rez){
$i=0; foreach($rez as $key => $val)if($key){
$blog['latest'][$i]['date']=date('H:i:s d.m.Y',$val['data_u']);
$blog['latest'][$i]['url']='/blog/'.$val['id'].'/';
$t=img_get_all(out_data_fu($val['text_f']));
$blog['latest'][$i]['img']=$t[0];
$blog['latest'][$i]['text_s']=strip_tags(out_data_fu($val['text_f']));
$i++;
}
}
}
{//ТЭГИ
$blog['tags']=array();
$blog['tags'][0]['name']='образование'; $blog['tags'][0]['url']='образование';
$blog['tags'][1]['name']='обучение'; $blog['tags'][1]['url']='обучение';
$blog['tags'][2]['name']='тестирование';$blog['tags'][2]['url']='тестирование';
$blog['tags'][3]['name']='студенты'; $blog['tags'][3]['url']='студенты';
$blog['tags'][4]['name']='заочники'; $blog['tags'][4]['url']='заочники';
$blog['tags'][5]['name']='очное'; $blog['tags'][5]['url']='очное';
}
{//АРХИВЫ
$blog['arch']=array();
$blog['arch'][0]['url']='/arch/9-2013/';
$blog['arch'][0]['month']='сент';
$blog['arch'][0]['year']='2013';
$blog['arch'][1]['url']='/arch/10-2013/';
$blog['arch'][1]['month']='окт';
$blog['arch'][1]['year']='2013';
$blog['arch'][2]['url']='/arch/11-2013/';
$blog['arch'][2]['month']='ноя';
$blog['arch'][2]['year']='2013';
}
$mes=array('01'=>'Январь','02'=>'Февраль','03'=>'Март','04'=>'Апрель','05'=>'Май','06'=>'Июнь','07'=>'Июль','08'=>'Август','09'=>'Сентябрь','10'=>'Октябрь','11'=>'Ноябрь','12'=>'Декабрь');
$day=array('0'=>'Воскресенье','1'=>'Понедельник','2'=>'Вторник','3'=>'Среда','4'=>'Четверг','5'=>'Пятница','6'=>'Суббота');
$color=array(0=>'orange',1=>'green',2=>'red',3=>'yellow',4=>'blue');
if(!isset($_GET['id'])&&!isset($_GET['page'])){//Просмотр всех записей
$blog['name']='Все блоги'; $w['id_category']='';
if (isset($_GET['cat'])) {
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs_category WHERE alt_name="'.get_data_fu($_GET['cat']).'"';
$rez=$DB->QUR_SEL($sql);//echo $sql.mysql_error();
if($rez) {
$blog['name']=out_data_fu($rez[1]['name']);
$w['id_category']=$rez[1]['id'];
}
}
$blog['breadcrumb']=array();//навигационная лента
$blog['breadcrumb'][0]['url']='/';
$blog['breadcrumb'][0]['name']='Главная';
$blog['breadcrumb'][1]['url']='/blog/';
$blog['breadcrumb'][1]['name']='Блог';
$blog['breadcrumb'][1]['active']=1;
$WH='';
if($w['id_category']!=''){
if($WH=='') $WH=' AND '; $WH .= 'id_category='.$w['id_category'];
}
$pagi=pagination_blog('SELECT * FROM '.$ST['dbpf'].'_blogs WHERE status=1'.$WH.'',5);
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs WHERE status=1'.$WH.' ORDER BY zakrep DESC, data_c DESC '.$pagi['limit'];
$rez=$DB->QUR_SEL($sql); //print_r($_GET); echo $sql;
if($rez){
$i=0; foreach($rez as $key => $val)if($key){
$blog['posts'][$i]['d_d']=date('d',$val['data_c']);
$blog['posts'][$i]['d_m']=$mes[date('m',$val['data_c'])];
$blog['posts'][$i]['d_day']=$day[date('w',$val['data_c'])];
$blog['posts'][$i]['time']=date('H:i',$val['data_c']);
$blog['posts'][$i]['view']=$val['views'];
if($val['comment']==1) $blog['posts'][$i]['com_kol']=get_comment_kol('blog',$val['id']);
else $blog['posts'][$i]['com_kol']='';
$blog['posts'][$i]['url']=$val['id'];
$blog['posts'][$i]['name']=out_data_fu($val['title']);
$t=get_user($val['id_user']);
$blog['posts'][$i]['author']=out_data_fu($t['fio']);
$blog['posts'][$i]['img']='';
$blog['posts'][$i]['color']=$color[$i];
$val['text_f'] = str_replace('<div>[page]</div>','[page]',$val['text_f']);
$t = explode('[page]',$val['text_f']);
if (count($t)>1){
$blog['posts'][$i]['text_s']=out_data_fu($t[0]);
//$blog['posts'][$i]['text_f']=out_data_fu($t[1]);
}else{
$blog['posts'][$i]['text_s']=out_data_fu($val['text_f']);
}
$i++;
}
}
}
if(isset($_GET['id'])&&!isset($_GET['page'])){//Просмотр одной записи
$blog['name']='Все блоги'; $w['id_category']='';
if (isset($_GET['cat'])) {
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs_category WHERE alt_name="'.get_data_fu($_GET['cat']).'"';
$rez=$DB->QUR_SEL($sql);//echo $sql.mysql_error();
if($rez) {
$blog['name']=out_data_fu($rez[1]['name']);
$w['id_category']=$rez[1]['id'];
}
}
$sql = 'SELECT * FROM '.$ST['dbpf'].'_blogs WHERE id='.(int)$_GET['id'].' LIMIT 1';
$rez=$DB->QUR_SEL($sql);
if($rez){
$DB->QUR('UPDATE '.$ST['dbpf'].'_blogs SET views=views+1 WHERE id='.(int)$_GET['id'].' LIMIT 1');
$i=0; foreach($rez as $key => $val)if($key){
$blog['posts'][$i]['d_d']=date('d',$val['data_c']);
$blog['posts'][$i]['d_m']=$mes[date('m',$val['data_c'])];
$blog['posts'][$i]['d_day']=$day[date('w',$val['data_c'])];
$blog['posts'][$i]['time']=date('H:i',$val['data_c']);
$blog['posts'][$i]['view']=$val['views'];
if($val['comment']==1) $blog['posts'][$i]['com_kol']=get_comment_kol('blog',$val['id']);
else $blog['posts'][$i]['com_kol']='';
$blog['posts'][$i]['url']=$val['id'];
$blog['posts'][$i]['name']=$blog['name']=out_data_fu($val['title']);
$t=get_user($val['id_user']);
$blog['posts'][$i]['author']=out_data_fu($t['fio']);
$blog['posts'][$i]['img']='';
$blog['posts'][$i]['color']=$color[rand(0,3)];
$blog['posts'][$i]['comment']=$val['comment'];
$val['text_f'] = str_replace('<div>[page]</div>','[page]',$val['text_f']);
$t = explode('[page]',$val['text_f']);
if (count($t)>1){
$blog['posts'][$i]['text_s']=out_data_fu($t[0]);
$blog['posts'][$i]['text_f']=out_data_fu($t[1]);
}else{
$blog['posts'][$i]['text_f']=out_data_fu($val['text_f']);
}
if($val['comment']==1) $comm=get_comment('blog',$val['id']); else $comm=array();
$blog['posts'][$i]['comm']=$comm;
$i++;
}
}
/*
$blog['comments'][0]=array();
$blog['comments'][0]['user_avatar']='/img/';
$blog['comments'][0]['user_name']='';
$blog['comments'][0]['time']='';
$blog['comments'][0]['text_f']='';
*/
}
//проверяем заполнял ли анкету человек в течение 14 дней
$id_user = $_SESSION['user']['id'];
$to_date = date("U");
$isOrder = 0;
$sql = 'SELECT * FROM '.$ST['dbpf'].'_anketes WHERE id_user = "'.$id_user.'" ';
$rez = $DB->QUR_SEL($sql);
foreach ($rez as $key => $val) if ($key){
if (abs($val['date_create'] - $to_date) < 14*24*60*60){
$isOrder = 1;
break;
}
}
//проверяем является ли он студентом
if (!isset($_SESSION['user']['student']['id'])) $isOrder = 1;
//проверяем является ли он преподом
if (isset($_SESSION['user']['teacher']['id'])) $isOrder = 1;
//проверяем есть ли сейчас обязательные файлы, которые нужно сейчас посмотреть
$trigger = array();
$sql = 'SELECT * FROM '.$ST['dbpf'].'_triggers WHERE status = 1 ORDER BY id DESC';
$rez = $DB->QUR_SEL($sql);
if ($rez){
//проверяем переходил ли человек по ссылке
$sql_is = 'SELECT * FROM '.$ST['dbpf'].'_transition WHERE id_user = "'.$id_user.'" AND id_trigger = "'.$rez[1]['id'].'" ';
$rez_is = $DB->QUR_SEL($sql_is);
if ($rez_is[0] > 0) $rez[1]['status'] = 0;
$trigger = $rez[1];
}
//print_r($trigger);
/***********************/
$ST['page']['name'] = $blog['name'];
$smarty->assign('blog',$blog);
$smarty->assign('bib',$_SESSION['bib_path']);
$smarty->assign('pagination',$pagi);
/***/
$smarty->assign('is',$isOrder);
$smarty->assign('trigger',$trigger);
$smarty->assign('id_user',$id_user);
$smarty->assign('id_grupp',$_SESSION['user']['student']['id_grupp']);
$maincontent = $smarty->fetch('tpl_blog.html');
//$maincontent = '12';
//echo strlen($maincontent);
}
//ПОЛУЧЕНИЕ КОММЕНТАРИЕВ
function get_comment($table,$id){
GLOBAL $ST,$DB; $out=array();
if (isset($_SESSION['user']['id'])){
if(isset($_POST['comm_post'])){//СОХРАНЯЕМ КОММЕНТА
$text_f=get_data_fu($_POST['text_f']);
if (isset($_POST['par'])) $par=(int)get_data_fu($_POST['par']); else $par=0;
$sql='INSERT INTO '.$ST['dbpf'].'_comments VALUES (0,'.mktime().',"'.$table.'",'.$id.','.$par.','.$_SESSION['user']['id'].',"'.$text_f.'",0)';
$rez=$DB->QUR($sql); //echo $sql.mysql_error();
if(!$rez['err']) $out['msg']='Ваш комментарий добавлен!';
else $out['err']='Ваш комментарий не добавлен!';
}
//ОТОБРАЖАЕМ КОММЕНТЫ
$sql='SELECT * FROM '.$ST['dbpf'].'_comments WHERE wtable="'.$table.'" AND id_item='.$id.' ORDER BY data_c';
$rez=$DB->QUR_SEL($sql);
if($rez){
$out['items']=array();
$i=0;foreach($rez as $key => $val)if($key){
$user = get_user($val['id_user']);
if($user['foto']!='')$out['items'][$i]['user_avatar']='/upload/users/ava/'.$val['id_user'].'_ava_150.jpg';
else $out['items'][$i]['user_avatar']='/tpl/img/no_avatar.png';
$out['items'][$i]['user_name']=out_data_fu($user['fio']);
$out['items'][$i]['time']=get_data($val['data_c'],0,1);
$out['items'][$i]['text_f']=out_data_fu($val['text_f']);
$i++;
}
}
}
return $out;
}
//ПОЛУЧЕНИЕ ТОЛЬКО КОЛИЧЕСТВА
function get_comment_kol($table,$id){
GLOBAL $ST,$DB; $out=array();
$sql='SELECT * FROM '.$ST['dbpf'].'_comments WHERE wtable="'.$table.'" AND id_item='.$id.' ORDER BY data_c';
$rez=$DB->QUR_SEL($sql);
if($rez){
$out=$rez[0];
$out .= ' '.getNumEnding($out, array('комментарий', 'комментария', 'комментариев'));
}else{$out='';}
return $out;
}
?>