Файл: moduls/blog/index.php
Строк: 157
<?php
/**
* @package Prime Social
* @link http://primesocial.ru
* @copyright Copyright (C) 2016 Prime Social
* @author BoB | http://primesocial.ru/about
*/
require_once('../../core/start.php');
check_auth();
switch ($select) {
default:
head('Blog');
/* Tartiblash */
if (!empty($_GET['sort'])) {
if ($_GET['sort'] == 'date') {
unset($_SESSION['sort']);
} elseif ($_GET['sort'] == 'rating') {
$_SESSION['sort'] = 'rating';
} elseif ($_GET['sort'] == 'name') {
$_SESSION['sort'] = 'name';
} else {
NULL;
}
header("Location: ".HOME."/blog/");
}
echo DIV_LI;
echo 'Tartiblash: ' . (empty($_SESSION['sort']) ? '<b>sana</b>' : '<a href="'.HOME.'/blog/?sort=date">sana</a>') . ' | ' .
($_SESSION['sort'] == 'rating' ? '<b>mashhurlik</b>' : '<a href="'.HOME.'/blog/?sort=rating">mashhurlik</a>') . ' | ' .
($_SESSION['sort'] == 'name' ? '<b>nom</b>' : '<a href="'.HOME.'/blog/?sort=name">nom</a>');
echo CLOSE_DIV;
if ($_SESSION['sort'] == 'popular') {
$sort = 'ORDER BY `rating` DESC';
} elseif ($_SESSION['sort'] == 'name') {
$sort = 'ORDER BY `title` DESC';
} else {
$sort = 'ORDER BY `time` DESC';
}
/* */
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".BLOG."");
if ($all == 0) {
echo DIV_BLOCK . 'Bloglar hali ochilmagan' . CLOSE_DIV;
} else {
$n = new Navigator($all,$config['write']['blog'],'');
$sql = DB::$dbs->query("SELECT * FROM ".BLOG." ".$sort." LIMIT {$n->start()}, ".$config['write']['blog']."");
while($blog = $sql -> fetch()) {
echo DIV_BLOCK . ''.icon('pages.png').' <a href="'.HOME.'/blog/'.$blog['id'].'/"><b>' . $blog['title'] . '</b></a>
<span style="float:right;"> ' . userLink($blog['user_id']) . '</span><br />';
echo SubstrMaus(text($blog['blog']), 100);
echo '<br/><span style="font-size:11px;color:#757575;">' . vrem($blog['time']) . '</span>';
echo CLOSE_DIV;
}
echo $n->navi();
}
echo DIV_BLOCK . '<form action="'.HOME.'/blog/new/" method="POST"><input type="submit" value="Yangi blog" /></form>' . CLOSE_DIV;
$array = array('Blog');
nav($array);
break;
case 'add':
head('Blog: Yangi blog');
if ($_POST['add']) {
$title = html($_POST['title']);
$blog = html($_POST['blog']);
if (empty($title) || empty($blog)) {
echo DIV_ERROR . 'Barcha maydonchalarni to`ldiring' . CLOSE_DIV;
} else {
DB::$dbs->query("INSERT INTO ".BLOG." (`title`, `blog`, `user_id`, `time`) VALUES (?,?,?,?)", array($title, $blog, $user['user_id'], time()));
$lastid = DB::$dbs->lastInsertId();
balls_operation(5);
header("Location: ".HOME."/blog/".$lastid."/");
}
}
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo 'Blog nomi: [max. 100]<br /><input type="text" name="title" /><br /><br />';
echo 'Blog matni:<br /><textarea name="blog" cols="30" rows="6"></textarea><br />';
echo '<input type="submit" name="add" value="Yaratish" /></form>';
echo CLOSE_DIV;
bbsmile();
$array = array('Blog');
nav($array);
break;
case 'view':
$id = abs(intval($_GET['id']));
$blog = DB::$dbs->queryFetch("SELECT * FROM ".BLOG." WHERE `id` = ?",array($id));
if (empty($blog)) {
head('Blog: Blog topilmadi');
echo DIV_TITLE . 'Blog topilmadi' . CLOSE_DIV;
echo DIV_BLOCK . 'Xatolik!' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
if (isset($_POST['add'])) {
$comm = html($_POST['comm']);
if (empty($comm)) {
echo DIV_ERROR . 'Bo`sh sharh' . CLOSE_DIV;
} else {
DB::$dbs->query("INSERT INTO ".BLOG_COMM." (`blog_id`, `user_id`, `comm`, `time`) VALUES (?, ?, ?, ?)", array($blog['id'], $user['user_id'], $comm, time()));
$lenta = '<a href="'.HOME.'/id'.$user['user_id'].'"><b>' . $user['nick'] . '</b></a> sizning <a href="'.HOME.'/blog/'.$blog['id'].'/"><b>blogingizga</b> sharh yozdi</a>';
lenta($lenta, $blog['user_id']);
header("Location: ".HOME."/blog/".$blog['id']."/");
}
}
if (!empty($_GET['delcomm'])) {
$comm = DB::$dbs->queryFetch("SELECT * FROM ".BLOG_COMM." WHERE `id` = ? ", array(abs(num($_GET['delcomm']))));
if ($comm['user_id'] == $user['user_id'] || $blog['user_id'] == $user['user_id'] || privilegy('blog_moder')) {
DB::$dbs->query("DELETE FROM ".BLOG_COMM." WHERE `id` = ? ", array(abs(num($_GET['delcomm']))));
}
header("Location: ".HOME."/blog/".$blog['id']."/");
}
if (!empty($_GET['editcomm'])) {
$comm = DB::$dbs->queryFetch("SELECT * FROM ".BLOG_COMM." WHERE `id` = ? ", array(abs(num($_GET['editcomm']))));
if ($comm['user_id'] == $user['user_id'] || privilegy('blog_moder')) {
if (isset($_POST['edit'])) {
$comm = html($_POST['comm']);
if (empty($comm)) {
echo DIV_ERROR . 'Bo`sh sharh' . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".BLOG_COMM." SET `comm` = ? WHERE `id` = ? ", array($comm, abs(num($_GET['editcomm']))));
header("Location: ".HOME."/blog/".$blog['id']."/");
}
}
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo '<b>Sharhni tahrirlash:</b><br /><textarea name="comm">'.$comm['comm'].'</textarea><br />';
echo '<input type="submit" name="edit" value="O`zgartirish"/>';
echo '</form>';
echo CLOSE_DIV;
}
}
if (isset($_GET['delete']) && ($blog['user_id'] == $user['user_id'] || privilegy('blog_moder'))) {
if (!isset($_GET['go'])) {
echo DIV_LI . '<b>O`chirishni tastiqlang:</b> <a href="?delete&go">[O`chirish]</a> <a href="'.HOME.'/blog/'.$blog['id'].'/">[Yo`q]</a>' . CLOSE_DIV;
} else {
DB::$dbs->query("DELETE FROM ".BLOG_COMM." WHERE `blog_id` = ? ", array($blog['id']));
DB::$dbs->query("DELETE FROM ".BLOG_RATING." WHERE `blog_id` = ? ", array($blog['id']));
DB::$dbs->query("DELETE FROM ".BLOG." WHERE `id` = ? ", array($blog['id']));
header("Location: ".HOME."/blog/");
}
}
head('Blogni ko`rish: ' . $blog['title']);
echo DIV_BLOCK . ''.icon('pages.png').' <b>' . $blog['title'] . '</b><p>' .text($blog['blog']) . '</p>' . CLOSE_DIV;
echo DIV_BLOCK . '<b>Kiritilgan vaqti</b>: ' . vrem($blog['time']) . '<br />';
if (DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".BLOG_RATING." WHERE `blog_id` = ? && `user_id` = ? ", array($blog['id'], $user['user_id'])) == FALSE) {
echo '<b>Menga</b>: <a href="'.HOME.'/blog/'.$blog['id'].'/like/">yoqdi</a> /
<a href="'.HOME.'/blog/'.$blog['id'].'/not_like/">yoqmadi</a><br />';
} else {
$like = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".BLOG_RATING." WHERE `blog_id` = ? && `type` = ? ", array($blog['id'], 'like'));
$not_like = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".BLOG_RATING." WHERE `blog_id` = ? && `type` = ? ", array($blog['id'], 'not_like'));
echo '<b>Reyting</b>: ' . (empty($blog['rating']) ? '0' : $blog['rating']) . ' (+'.$like.'/-'.$not_like.')<br />';
}
$comm = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".BLOG_COMM." WHERE `blog_id` = ? ", array($blog['id']));
echo '<b>Sharhlar</b>: '.$comm.' ';
if ($blog['user_id'] == $user['user_id'] || privilegy('blog_moder')) {
echo ' | <a href="'.HOME.'/blog/'.$blog['id'].'/?delete"><u>O`chirish</u></a> |
<a href="'.HOME.'/blog/'.$blog['id'].'/edit/"><u>Tahrirlash</u></a>';
}
echo CLOSE_DIV;
if (empty($comm)) {
echo '<div class="white">Sharhlar yo`q.' . CLOSE_DIV;
} else {
$n = new Navigator($comm,$config['write']['blog_comm'],'select=view&id='.$blog['id']);
$sql = DB::$dbs->query("SELECT * FROM ".BLOG_COMM." WHERE `blog_id` = ? ORDER BY `id` DESC LIMIT {$n->start()}, ".$config['write']['blog_comm']."", array($blog['id']));
while($comm = $sql -> fetch()) {
echo DIV_BLOCK;
echo '<b>' . userLink($comm['user_id']) . '</b> ['.vrem($comm['time']).'] '.(privilegy('blog_moder') || $comm['user_id'] == $user['user_id'] || $blog['user_id'] == $user['user_id'] ? '<a href="'.HOME.'/moduls/blog/index.php?select=view&id='.$blog['id'].'&delcomm='.$comm['id'].'">[o`chr.]</a>' : NULL). (privilegy('blog_moder') || $comm['user_id'] == $user['user_id'] ? ' <a href="'.HOME.'/moduls/blog/index.php?select=view&id='.$blog['id'].'&editcomm='.$comm['id'].'">[o`zg.]</a>' : NULL) .'<br />' . text($comm['comm']);
echo CLOSE_DIV;
}
echo $n->navi();
}
bbsmile();
echo '<div class="white">';
echo '<form action="#" method="POST">';
echo '<textarea name="comm" style="width:95%;"></textarea>';
echo CLOSE_DIV;
echo '<div class="white">';
echo '<input type="submit" name="add" value="Sharh yozish"/>';
echo '</form>';
echo CLOSE_DIV;
$array = array('Blog');
nav($array);
break;
case 'edit':
$id = abs(intval($_GET['id']));
$blog = DB::$dbs->queryFetch("SELECT * FROM ".BLOG." WHERE `id` = ?",array($id));
if (empty($blog)) {
head('Blog: Blog topilmadi');
echo DIV_TITLE . 'Blog topilmadi' . CLOSE_DIV;
echo DIV_BLOCK . 'Xatolik!' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
if ($blog['user_id'] != $user['user_id'] && privilegy('blog_moder') == FALSE) {
head('Blog: Kirishda xatolik');
echo DIV_TITLE . 'Kirishda xatolik' . CLOSE_DIV;
echo DIV_BLOCK . 'Xatolik!' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
head('Blog: Tahrirlash ' . $blog['title']);
if ($_POST['edit']) {
$title = html($_POST['title']);
$blog1 = html($_POST['blog']);
if (empty($title) || empty($blog1)) {
echo DIV_ERROR . 'Barcha maydonchalarni to`ldiring' . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".BLOG." SET `title` = ?, `blog` = ? WHERE `id` = ? ", array($title, $blog1, $blog['id']));
header("Location: ".HOME."/blog/".$blog['id']."/");
}
}
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo 'Blog nomi: [max. 100]<br /><input type="text" name="title" value="'.$blog['title'].'" /><br /><br />';
echo 'Blog matni:<br /><textarea name="blog" cols="30" rows="6">'.$blog['blog'].'</textarea><br />';
echo '<input type="submit" name="edit" value="Tayyor!" /></form>';
echo CLOSE_DIV;
bbsmile();
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/blog">Blog</a> / <a href="'.HOME.'/blog/'.$blog['id'].'/">'.$blog['title'].'</a> / <b>Blogni tahrirlash</b>' . CLOSE_DIV;
break;
case 'rating':
$id = abs(intval($_GET['id']));
$blog = DB::$dbs->queryFetch("SELECT * FROM ".BLOG." WHERE `id` = ?",array($id));
if (empty($blog)) {
head('Blog: Blog topilmadi');
echo DIV_TITLE . 'Blog topilmadi' . CLOSE_DIV;
echo DIV_BLOCK . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifaga</a> / <a href="'.HOME.'/blog">Blog</a> / <b>Blog topilmadi</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
if (DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".BLOG_RATING." WHERE `blog_id` = ? && `user_id` = ? ", array($blog['id'], $user['user_id'])) == TRUE) {
head('Blog: Siz ovoz bergansiz');
echo DIV_TITLE . 'Siz ovoz bergansiz' . CLOSE_DIV;
echo DIV_BLOCK . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifaga</a> / <a href="'.HOME.'/blog">Blog</a> / <b>Ovoz bergansiz</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
if ($_GET['type'] == 'like') {
DB::$dbs->query("INSERT INTO ".BLOG_RATING." (`blog_id`, `user_id`, `type`) VALUES (?, ?, ?)", array($blog['id'], $user['user_id'], 'like'));
DB::$dbs->query("UPDATE ".BLOG." SET `rating` = ? WHERE `id` = ? ", array(($blog['rating'] + 1), $blog['id']));
$lenta = '<a href="'.HOME.'/id'.$user['user_id'].'"><b>' . $user['nick'] . '</b></a> ga sizning <a href="'.HOME.'/blog/'.$blog['id'].'/"><b>blogingiz</b></a> yoqdi';
lenta($lenta, $blog['user_id']);
} else {
DB::$dbs->query("INSERT INTO ".BLOG_RATING." (`blog_id`, `user_id`, `type`) VALUES (?, ?, ?)", array($blog['id'], $user['user_id'], 'not_like'));
DB::$dbs->query("UPDATE ".BLOG." SET `rating` = ? WHERE `id` = ? ", array(($blog['rating'] - 1), $blog['id']));
$lenta = '<a href="'.HOME.'/id'.$user['user_id'].'"><b>' . $user['nick'] . '</b></a> sizning <a href="'.HOME.'/blog/'.$blog['id'].'/"><b>blogingiz</b></a> yoqmadi';
lenta($lenta, $blog['user_id']);
}
header("Location: ".HOME."/blog/".$blog['id']."/");
break;
}
require_once('../../core/stop.php');
?>