Файл: adultscript-2.0.3-pro/files/admin/modules/photo/components/edit.php
Строк: 102
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_photo_edit extends VModule_Admin_photo
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$pcfg = VF::cfg('module.photo');
$album = array();
$errors = array();
$messages = array();
$categories = $this->get_photo_categories();
$album_id = (isset($_GET['id'])) ? (int) trim($_GET['id']) : 0;
$this->db->query("SELECT a.album_id, a.user_id, a.cover,
GROUP_CONCAT(DISTINCT pc.cat_id) AS categories,
GROUP_CONCAT(t.name) AS tags
FROM #__photo_albums AS a
LEFT JOIN #__photo_category AS pc ON (pc.album_id = a.album_id)
LEFT JOIN #__photo_tags AS t ON (t.album_id = a.album_id)
WHERE a.album_id = ".$album_id."
GROUP BY a.album_id
LIMIT 1");
if ($this->db->affected_rows()) {
$o_data = $this->db->fetch_assoc();
$o_user_id = (int) $o_data['user_id'];
$o_cover = (int) $o_data['cover'];
$o_categories = explode(',', $o_data['categories']);
sort($o_categories);
$o_tags = $o_data['tags'];
if (isset($_POST['submit-edit'])) {
$filter = VF::factory('filter');
$username = $filter->get('username');
$title = $filter->get('title');
$description = $filter->get('description');
$tags = $filter->get('tags');
$category = (array) $_POST['categories'];
$type = $filter->get('type');
$flagged = (int) trim($_POST['flagged']);
$locked = (int) trim($_POST['locked']);
$status = (int) trim($_POST['status']);
$total_photos = (int) trim($_POST['total_photos']);
$total_views = (int) trim($_POST['total_views']);
$total_comments = (int) trim($_POST['total_comments']);
$total_favorites = (int) trim($_POST['total_favorites']);
$rating = (float) trim($_POST['rating']);
$rated_by = (int) trim($_POST['rated_by']);
$add_date = $filter->get('add_date');
$view_date = $filter->geT('view_date');
$cover = (int) trim($_POST['cover']);
$password = (isset($_POST['password'])) ? trim($_POST['password']) : '';
if ($username == '') {
$errors[] = 'Album username field cannot be left blank!';
} else {
$this->db->query("SELECT user_id FROM #__user WHERE username = '".$this->db->escape($username)."' LIMIT 1");
if ($this->db->affected_rows()) {
$user_id = (int) $this->db->fetch_field('user_id');
} else {
$errors[] = 'Invalid username! Are you sure this user exists on this system!?';
}
}
if ($title == '') {
$errors[] = 'Album title field cannot be left blank!';
} elseif (!VValid::length($title, $pcfg['title_min_length'], $pcfg['title_max_length'])) {
$errors[] = 'Album title must contain at least '.$pcfg['title_min_length'].' and no more than '.$pcfg['title_max_length'];
}
if ($tags == '') {
$errors[] = 'Album tags field cannot be left blank!';
} else {
$tags = prepare_tags($tags);
if ($tags == '') {
$errors[] = 'Album tags can contain only letters, numbers, spaces and must be separated by commas!';
}
}
if (!$category) {
$errors[] = 'Please select at least one category for this album!';
} else {
$cats = array();
foreach ($categories as $cat) {
$cats[$cat['cat_id']] = 1;
}
foreach ($category as $cat) {
if (!isset($cats[$cat])) {
$error = TRUE;
break;
}
}
if (isset($error)) {
$errors[] = 'Invalid category checked! What exactly did you click!?';
} else {
sort($category);
}
}
if ($add_date != '0000-00-00 00:00:00' && (!strtotime($add_date) OR strlen($add_date) !== 19)) {
$errors[] = 'Invalid add date entry! Allowed format: yyyy-mm-dd hh::mm:ss!';
}
if ($view_date != '0000-00-00 00:00:00' && (!strtotime($view_date) OR strlen($view_date) !== 19)) {
$errors[] = 'Invalid add date entry! Allowed format: yyyy-mm-dd hh::mm:ss!';
}
if (!$errors) {
$slug = prepare_string($title, TRUE);
$this->db->query("UPDATE #__photo_albums
SET user_id = ".$user_id.",
title = '".$this->db->escape($title)."',
slug = '".$this->db->escape($slug)."',
description = '".$this->db->escape($description)."',
type = '".$this->db->escape($type)."',
total_photos = ".$total_photos.",
total_views = ".$total_views.",
total_comments = ".$total_comments.",
total_favorites = ".$total_favorites.",
rating = ".$rating.",
rated_by = ".$rated_by.",
add_date = '".$this->db->escape($add_date)."',
view_date = '".$this->db->escape($view_date)."',
cover = ".$cover.",
flagged = '".$flagged."',
locked = '".$locked."',
status = '".$status."'
WHERE album_id = ".$album_id."
LIMIT 1");
if ($password != '') {
$this->db->query("UPDATE #__photo_albums
SET password = '".$this->db->escape(VHash::encrypt($password))."'
WHERE album_id = ".$album_id."
LIMIT 1");
}
if ($o_user_id !== $user_id) {
$this->db->query("UPDATE #__user_activity SET total_albums = total_albums-1 WHERE user_id = ".$o_user_id." LIMIT 1");
$this->db->query("UPDATE #__user_activity SET total_albums = total_albums+1 WHERE user_id = ".$user_id." LIMIT 1");
}
if ($o_tags != $tags) {
$this->db->query("DELETE FROM #__photo_tags WHERE album_id = ".$album_id);
$tags = explode(',', $tags);
foreach ($tags as $tag) {
$this->db->query("INSERT INTO #__photo_tags SET name = '".$this->db->escape($tag)."', album_id = ".$album_id);
}
}
if ($o_categories != $category) {
foreach ($o_categories as $cat) {
if (!in_array($cat, $category)) {
$this->db->query("DELETE FROM #__photo_category WHERE album_id = ".$album_id." AND cat_id = ".$cat." LIMIT 1");
$this->db->query("UPDATE #__photo_categories SET total_albums = total_albums-1 WHERE cat_id = ".$cat." LIMIT 1");
}
}
foreach ($category as $cat) {
if (!in_array($cat, $o_categories)) {
$this->db->query("INSERT INTO #__photo_category SET cat_id = ".$cat.", album_id = ".$album_id);
$this->db->query("UPDATE #__photo_categories SET total_albums = total_albums+1 WHERE cat_id = ".$cat." LIMIT 1");
}
}
}
if ($cover !== $o_cover) {
$src = MEDIA_DIR.'/photos/thumbs/'.$cover.'.jpg';
$dst = MEDIA_DIR.'/photos/covers/'.$album_id.'.jpg';
$image = VF::factory('image');
$image->load($src);
if ($image->src['height'] < $pcfg['cover_height']) {
$this->db->query("SELECT ext FROM #__photo WHERE photo_id = ".$cover." LIMIT 1");
$ext = $this->db->fetch_field('ext');
$src = MEDIA_DIR.'/photos/orig/'.$cover.'.'.$ext;
$image->clear();
$image->load($src);
$cover_max_width = ($pcfg['cover_width'] + 30);
$cover_max_height = ($pcfg['cover_height'] + 50);
if ($image->src['width'] > $cover_max_width && $image->src['height'] > $cover_max_height) {
$dst_tmp = TMP_DIR.'/images/'.$cover.'.jpg';
$image->set_option('jpeg_quality', 100);
$image->resize($cover_max_width, $cover_max_height, 'MAX_HEIGHT', $dst_tmp);
$src = $dst_tmp;
}
}
$image->clear();
$image->load($src);
$image->crop_from_center($pcfg['cover_width'], $pcfg['cover_height'], $dst);
if (isset($dst_tmp)) {
VFile::delete($dst_tmp);
}
}
$messages[] = 'Album updated!';
}
}
$this->db->query("SELECT a.album_id, a.user_id, a.title, a.slug, a.description,
a.total_photos, a.total_views, a.total_comments, a.total_favorites,
a.rating, a.rated_by, a.status, a.type, a.add_date, a.view_date, a.locked,
a.cover, a.flagged, a.password, u.username,
GROUP_CONCAT(DISTINCT pc.cat_id) AS categories,
GROUP_CONCAT(t.name) AS tags
FROM #__photo_albums AS a
LEFT JOIN #__user AS u ON (u.user_id = a.user_id)
LEFT JOIN #__photo_category AS pc ON (pc.album_id = a.album_id)
LEFT JOIN #__photo_tags AS t ON (t.album_id = a.album_id)
WHERE a.album_id = ".$album_id."
GROUP BY a.album_id
LIMIT 1");
$album = $this->db->fetch_assoc();
$this->db->query("SELECT photo_id, caption
FROM #__photo
WHERE album_id = ".$album_id."
ORDER BY photo_id DESC");
$photos = $this->db->fetch_rows();
}
$tpl = VF::factory('template');
$tpl->menu = 'photo';
$tpl->submenu = 'manage';
$tpl->meta_title = 'Admin::Photo::Album::Edit';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->album = $album;
$tpl->album_id = $album_id;
$tpl->photos = $photos;
$tpl->categories = $categories;
$tpl->load(array('header', 'photo_album_edit', 'footer'));
$tpl->display();
}
}