Files
AtomicOld/simpla/ActionsPostAdmin.php

91 lines
2.9 KiB
PHP
Raw Normal View History

2026-02-14 19:34:54 +03:00
<?PHP
require_once('api/Simpla.php');
class ActionsPostAdmin extends Simpla
{
private $allowed_image_extentions = array('png', 'gif', 'jpg', 'jpeg', 'ico');
public function fetch()
{
if($this->request->method('post'))
{
$post->id = $this->request->post('id', 'integer');
$post->name = $this->request->post('name');
$post->date = date('Y-m-d', strtotime($this->request->post('date')));
$post->visible = $this->request->post('visible', 'boolean');
$post->url = $this->request->post('url', 'string');
$post->meta_title = $this->request->post('meta_title');
$post->meta_keywords = $this->request->post('meta_keywords');
$post->meta_description = $this->request->post('meta_description');
$post->annotation = $this->request->post('annotation');
$post->text = $this->request->post('body');
// Не допустить одинаковые URL разделов.
if(($a = $this->actions->get_post($post->url)) && $a->id!=$post->id)
{
$this->design->assign('message_error', 'url_exists');
}
else
{
if(empty($post->id))
{
$post->id = $this->actions->add_post($post);
$post = $this->actions->get_post($post->id);
$this->design->assign('message_success', 'added');
}
else
{
$this->actions->update_post($post->id, $post);
$post = $this->actions->get_post($post->id);
$this->design->assign('message_success', 'updated');
}
// Удаление изображения
if($this->request->post('delete_image'))
{
$this->actions->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->actions->delete_image($post->id);
$this->actions->update_post($post->id, array('image'=>$image_name));
$post->image = $image_name;
}
else
{
$this->design->assign('error', 'error uploading image');
}
}
$post = $this->actions->get_post(intval($post->id));
}
}
else
{
$post->id = $this->request->get('id', 'integer');
$post = $this->actions->get_post(intval($post->id));
if(!$post->id) $post->visible = 1;
}
if(empty($post->date))
$post->date = date($this->settings->date_format, time());
$this->design->assign('post', $post);
$this->db->query("SELECT * FROM __action_photo WHERE action_id='" . $post->id . "' ORDER BY position, id DESC");
$photos = $this->db->results();
foreach($photos as $ph) $ph->img = Img::get('files/post/' . $ph->img, array('width'=>120, 'height'=>120));
$this->design->assign('action_photos', $photos);
return $this->design->fetch('actions_post.tpl');
}
}