Файл: wboard/source/system/controller/remove.php
Строк: 52
<?php
/**
* Wboard
* Remove post or thread
* @author Screamer
* @copyright 2013
*/
class Module_Remove extends Module
{
/**
* Remove thread or post
* @param (string) $board Name of board
* @param (int) $thread ID of thread
* @param (int) $id ID of post
* @return (void)
*/
public function index($board = '', $thread = '', $id = '')
{
if ($this->is_root) {
$board = htmlspecialchars($board);
$thread = intval($thread);
$id = intval($id);
$path = $this->path . 'files' . DIRECTORY_SEPARATOR . 'boards' . DIRECTORY_SEPARATOR . $board . DIRECTORY_SEPARATOR;
$file = $path . 'res' . DIRECTORY_SEPARATOR . $thread . '.json';
if (is_file($file)) {
$data = json_decode(file_get_contents($file), TRUE);
foreach ($data as $key => $post) {
if (($id == 0 || $post['id'] == $id) && !empty($post['img'])) {
// Remove images
unlink($path . $post['img']['file']);
unlink($path . $post['img']['preview']);
}
if ($id != 0 && ($post['id'] == $id)) {
// Remove post
unset($data[$key]);
break;
}
}
if ($id != 0) {
file_put_contents($file, json_encode($data));
// Remove post
$this->model->remove_bump($board, $thread, (strtotime($post['time']) - 3600 * 3)); // TODO: set timeshift from settings
} else {
// Remove thread
unlink($file);
$this->model->remove_thread($board, $thread);
}
}
$this->redirect($board . ($id == 0 ? '' : '/' . $thread));
}
$this->redirect('w_action/err'); // Acces denied
}
/**
* Remove board
* @param (string) $name Name of board
* @return (void)
*/
public function board($name = '')
{
$board = $this->model->get_board($name);
if (is_array($board) && $this->is_root) {
$name = htmlspecialchars($name);
if (!empty($_POST)) {
if (isset($_POST['ok'])) {
// Remove files
$this->helper->delete_directory($this->path . 'files' . DIRECTORY_SEPARATOR . 'boards' . DIRECTORY_SEPARATOR . $board['name']);
// Remove board from database
$this->model->remove_board($board['name']);
// Redirect to mainpage
$this->redirect();
} else {
// Cancel; Redirect to board
$this->redirect($name);
}
}
// Confirm message
$this->tpl->title = $this->lng->remove_board . ' - /' . $name . '/';
$this->tpl->set_output($this->tpl->load('_form_confirm', array('message' => $this->lng->remove_board_confirm)));
} else {
// Board is not exists or access denied
$this->redirect('w_action/err');
}
}
}