
<?php
  
$blog = DB::GET_STRING("SELECT * FROM `BLOGS` WHERE `ID` = '".INTVAL(GET('id'))."' LIMIT 1");
$account = DB::GET_STRING("SELECT * FROM `USERS` WHERE `ID` = '".$blog['USER_ID']."' LIMIT 1");

IF (!$blog['ID']){
  
  ERROR('Неверная директива', 'session');
  REDIRECT('/modules/?path=blogs');

}

/*
---------
Просмотры
---------
*/

IF (ISSET($user)){
  
  IF (DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `BLOGS_EYE` WHERE `USER_ID` = '".$user['ID']."' AND `BLOG_ID` = '".$blog['ID']."' LIMIT 1") == 0){
    
    DB::GET_ADD("INSERT INTO `BLOGS_EYE` (`USER_ID`, `TIME`, `BLOG_ID`) VALUES ('".$user['ID']."', '".TIME()."', '".$blog['ID']."')");
  
  }    

}

/*
-------------
Список лайков
-------------
*/

IF (GET('get') == "like_list"){
  
  REQUIRE (ROOT.'/modules/blogs/plugins/like_list.php');
  
}

/*
---------------------
Редактирование записи
---------------------
*/

IF (GET('get') == "edit"){  
  
  IF (ACCESS('blogs', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
    
    REQUIRE (ROOT.'/modules/blogs/plugins/edit.php');
    
  }
  
}

/*
---------------
Удаление записи
---------------
*/

IF (GET('get') == "blog_delete_ok"){ 
  
  IF (ACCESS('blogs', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
    
    REQUIRE (ROOT.'/modules/blogs/plugins/delete.php');
    
  }
  
}

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/id".$account['ID']."'>".$account['LOGIN']."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=blogs&section=users&id=".$account['ID']."'>".LG('Блог')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".TEXT_ABSOLUTE($blog['NAME'])."";
ECHO "</div>";

//Редактировать комментарий
IF ($blog['USER_ID'] == $user['ID'] || MANAGEMENT == 1 || ACCESS('blogs_comments', NULL, 1)){
  
  REQUIRE (ROOT.'/modules/blogs/plugins/comments_edit_get.php');
  
}

IF (GET('get') == "blog_delete"){ 
  
  IF ($account['ID'] == $user['ID'] || ACCESS('blogs', NULL, 1) || MANAGEMENT == 1){
    
    ECHO "<div class='list'>";
    ECHO "".LG('Вы действительно хотите удалить запись')." <b>".TEXT_ABSOLUTE($blog['NAME'])."</b>?<br /><br />";
    
    ECHO "<a href='/modules/?path=blogs&section=show&id=".$blog['ID']."&get=blog_delete_ok' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить')."</a>";
    ECHO "<a href='/modules/?path=blogs&section=show&id=".$blog['ID']."' class='btn-o'>".LG('Отменить')."</a>";
    
    ECHO "</div>";
  
  }
  
}

IF (MANAGEMENT == 0){
  
  IF (ACCESS('blogs_private_show', NULL, 1) == FALSE){
    
    REQUIRE (ROOT.'/modules/blogs/plugins/private.php');
  
  }

}

IF (ACCESS('blogs', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
  
  ECHO "<div class='list'>";
  
  ECHO "<a href='/modules/?path=blogs&section=show&id=".$blog['ID']."&get=edit' class='btn'>".ICONS('pencil', 15, 'fa-fw')."".LG('Редактировать')."</a>";
  
  ECHO "<a href='/modules/?path=blogs&section=show&id=".$blog['ID']."&get=blog_delete' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить')."</a>";
  
  ECHO "</div>";

}

ECHO "<div class='list-body' style='position: relative; z-index: 0;'>";

ECHO "<div class='list-menu'>";

ECHO "<table style='width: 100%;'><tr>";

ECHO "<td class='comments-avatar'>";
ECHO USER::AVATAR($blog['USER_ID'], 50);
ECHO "</td>";
  
ECHO "<td class='comments-info'>";
ECHO USER::LOGIN($blog['USER_ID'], 0, 1);
  
ECHO "<br /><span class='time'>".STIME($blog['TIME'])."</span>";
ECHO "</td>";
  
ECHO "</tr></table>";

ECHO "<div style='margin-top: 8px; margin-bottom: 8px;'><b>".TEXT_ABSOLUTE($blog['NAME'])."</b></div>";

$data2 = DB::GET_STRING_ALL("SELECT * FROM `ATTACHMENTS` WHERE `USER_ID` = '".$blog['USER_ID']."' AND `ID_POST` = '".$blog['ID']."' AND `BLOGS` = '1' AND `ACT` = '1' ORDER BY `TIME` DESC LIMIT 3");
WHILE ($list2 = $data2->FETCH()){
  
  REQUIRE (ROOT.'/users/attachments/plugins/inc_blogs_list.php');

}

ECHO "<div style='margin-top: 8px; margin-bottom: 8px;'>";

IF (STR($blog['MESSAGE']) > 1000){
  
  ECHO "<div id='blogs".$blog['ID']."' style='margin-top: 5px;'>";
    
  ECHO CROP_TEXT(TEXT($blog['MESSAGE']), 0, 1000);
  
  ECHO "</div>";
    
  ECHO "<div id='blogs2".$blog['ID']."' style='display: none; margin-top: 5px;'>";
    
  ECHO TEXT($blog['MESSAGE']);
    
  ECHO "</div>";
    
  ?><a onclick="show_or_hide('blogs<?=$blog['ID']?>', 'blogs2<?=$blog['ID']?>', 'chevron<?=$blog['ID']?>', 'opacity_message<?=$blog['ID']?>')" load="none"><?
      
  ECHO "<div id='chevron".$blog['ID']."' class='chevron'><i class='fa fa-chevron-down fa-fw'></i></div>";
    
  ECHO "</a>";

}ELSE{
  
  ECHO TEXT($blog['MESSAGE']);

}

ECHO "</div>";

ECHO "</div>";

//Лайки
REQUIRE (ROOT.'/modules/blogs/plugins/likes.php');

ECHO "</div>";

//Комментарии
REQUIRE (ROOT.'/modules/blogs/plugins/comments.php');

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/id".$account['ID']."'>".$account['LOGIN']."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=blogs&section=users&id=".$account['ID']."'>".LG('Блог')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".TEXT_ABSOLUTE($blog['NAME'])."";
ECHO "</div>";
  
?>