Файл: adultscript-2.0.3-pro/files/admin/modules/photo/photo.php
Строк: 82
<?php
defined('_VALID') or die('Restricted Access!');
class VModule_Admin_photo
{
protected $db;
private $components = array(
'upload' => 1,
'archive' => 1,
'ftp' => 1,
'add' => 1,
'edit' => 1,
'manage' => 1,
'config' => 1,
'view' => 1,
'views' => 1,
'photo' => 1,
'photo_edit' => 1,
'photo_views' => 1,
'photo_ratings' => 1,
'photo_flags' => 1,
'photo_comments' => 1,
'category' => 1,
'category_add' => 1,
'category_edit' => 1,
'flags' => 1,
'flagged' => 1,
'server' => 1,
'server_add' => 1,
'server_edit' => 1,
'server_test' => 1
);
public function __construct()
{
$this->db = VF::factory('database');
}
public function render()
{
$component = (VUri::request(1)) ? VUri::request(1) : 'manage';
if (VUri::request(2) != '') {
$subcomponent = TRUE;
$component = VUri::request(2);
}
if (isset($this->components[$component]) && $this->components[$component] === 1) {
$component = (isset($subcomponent)) ? 'upload_'.$component : $component;
$component_class = 'VComponent_Admin_photo_'.$component;
try {
require ADMIN_DIR.'/modules/photo/components/'.$component.'.php';
$obj = new $component_class();
$obj->render();
} catch (Exception $e) {
throw new VException($e);
}
} else {
die('Invalid admin photo component specified!');
}
}
protected function get_photo_categories()
{
$this->db->query("SELECT cat_id, name, description, total_albums
FROM #__photo_categories
ORDER BY name ASC");
return $this->db->fetch_rows();
}
protected function delete_album($album_id)
{
$album_id = (int) $album_id;
$this->db->query("SELECT user_id
FROM #__photo_albums
WHERE album_id = ".$album_id."
LIMIT 1");
if (!$this->db->affected_rows()) {
return TRUE;
}
$album = $this->db->fetch_assoc();
$user_id = (int) $album['user_id'];
$this->db->query("SELECT photo_id, ext
FROM #__photo
WHERE album_id = ".$album_id);
if ($total_photos = $this->db->affected_rows()) {
$photos = $this->db->fetch_rows();
$tables = array('photo', 'photo_comments', 'photo_favorites', 'photo_flags', 'photo_rating');
foreach ($photos as $photo) {
$photo_id = (int) $photo['photo_id'];
foreach ($tables as $table) {
$this->db->query("DELETE FROM #__".$table." WHERE photo_id = ".$photo_id);
}
VFile::delete(MEDIA_DIR.'/photos/'.$photo_id.'.jpg');
VFile::delete(MEDIA_DIR.'/photos/orig/'.$photo_id.'.'.$photo['ext']);
VFile::delete(MEDIA_DIR.'/photos/thumbs/'.$photo_id.'.jpg');
}
}
$this->db->query("SELECT cat_id
FROM #__photo_category
WHERE album_id = ".$album_id);
if ($this->db->affected_rows()) {
$categories = $this->db->fetch_rows();
foreach ($categories as $category) {
$this->db->query("UPDATE #__photo_categories
SET total_albums = total_albums-1
WHERE cat_id = ".(int) $category['cat_id']."
LIMIT 1");
}
}
$this->db->query("UPDATE #__user_activity
SET total_albums = total_albums-1,
total_photos = total_photos-".$total_photos."
WHERE user_id = ".$user_id."
LIMIT 1");
$this->db->query("SELECT model_id
FROM #__model_albums
WHERE album_id = ".$album_id);
if ($this->db->affected_rows()) {
$models = $this->db->fetch_rows();
foreach ($models as $model) {
$this->db->query("UPDATE #__model
SET total_albums = total_albums-1
WHERE model_id = ".(int) $model['model_id']."
LIMIT 1");
}
}
$tables = array('photo_albums', 'model_albums', 'photo_album_views', 'photo_tags', 'photo_category');
foreach ($tables as $table) {
$this->db->query("DELETE FROM #__".$table." WHERE album_id = ".$album_id);
}
VFile::delete(MEDIA_DIR.'/photos/covers/'.$album_id.'.jpg');
}
protected function delete_photo($photo_id, $album_id=FALSE)
{
$this->db->query("SELECT album_id, ext FROM #__photo WHERE photo_id = ".$photo_id." LIMIT 1");
if (!$this->db->affected_rows()) {
return;
}
$album_id = (int) $this->db->fetch_field('album_id');
$ext = $this->db->fetch_field('ext');
$tables = array('photo', 'photo_comments', 'photo_favorites', 'photo_flags', 'photo_rating');
foreach ($tables as $table) {
$this->db->query("DELETE FROM #__".$table." WHERE photo_id = ".$photo_id);
}
VFile::delete(MEDIA_DIR.'/photos/'.$photo_id.'.jpg');
VFile::delete(MEDIA_DIR.'/photos/orig/'.$photo_id.'.'.$ext);
VFile::delete(MEDIA_DIR.'/photos/thumbs/'.$photo_id.'.jpg');
$this->db->query("UPDATE #__photo_albums SET total_photos = total_photos-1 WHERE album_id = ".$album_id." LIMIT 1");
}
}
?>