Files
AtomicOld/simpla/ArticlesAdmin.php
2026-02-14 19:34:54 +03:00

104 lines
3.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Simpla CMS
*
* @copyright 2011 Denis Pikusov
* @link http://simplacms.ru
* @author Denis Pikusov
*
*/
require_once('api/Simpla.php');
class ArticlesAdmin extends Simpla
{ private $allowed_image_extentions = array('png', 'gif', 'jpg', 'jpeg', 'ico');
public function fetch()
{
$filter = array();
// Категории
$categories = $this->articles->get_categories_tree();
$this->design->assign('categories', $categories);
// Текущая категория
$category_id = $this->request->get('category_id', 'integer');
if($category_id && $category = $this->articles->get_category($category_id)) {
$filter['category_id'] = $category->children;
$this->design->assign('category', $category);
}
// Обработка действий
if($this->request->method('post'))
{
// Действия с выбранными
$ids = $this->request->post('check');
if(is_array($ids))
switch($this->request->post('action'))
{
case 'disable':
{
$this->articles->update_article($ids, array('visible'=>0));
break;
}
case 'enable':
{
$this->articles->update_article($ids, array('visible'=>1));
break;
}
case 'delete':
{
foreach($ids as $id)
$this->articles->delete_article($id);
break;
}
}
}
// Удаление изображения
if($this->request->post('delete_image'))
{
$this->articles->delete_image($post->id);
}
// Загрузка изображения
$image = $this->request->files('image');
if(!empty($image['name']) && in_array(strtolower(pathinfo($image['name'], PATHINFO_EXTENSION)), $this->allowed_image_extentions))
{
if ($image_name = $this->image->upload_image($image['tmp_name'], $image['name']))
{
$this->articles->delete_image($post->id);
$this->articles->update_articles($post->id, array('image'=>$image_name));
}
else
{
$this->design->assign('error', 'error uploading image');
}
}
$post = $this->articles->get_articles(intval($post->id));
$filter['page'] = max(1, $this->request->get('page', 'integer'));
$filter['limit'] = 20;
// Поиск
$keyword = $this->request->get('keyword', 'string');
if(!empty($keyword))
{
$filter['keyword'] = $keyword;
$this->design->assign('keyword', $keyword);
}
$articles = $this->articles->get_articles($filter);
$articles_count = $this->articles->count_articles($filter);
$this->design->assign('articles_count', $articles_count);
$this->design->assign('pages_count', ceil($articles_count/$filter['limit']));
$this->design->assign('current_page', $filter['page']);
$this->design->assign('articles', $articles);
return $this->design->fetch('articles.tpl');
}
}