Вход Регистрация
Файл: adultscript-2.0.3-pro/files/modules/profile/profile.php
Строк: 277
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VModule_profile
{
    protected 
$db;
    protected 
$cache;
    protected 
$tpl;
    
    protected 
$user;
    protected 
$username;

    protected 
$is_friend        false;
    protected 
$is_blocked       false;
    protected 
$is_self          false;
    protected 
$is_subscribed    false;
    protected 
$is_loggedin      false;
    protected 
$is_moderator     false;
    protected 
$can_comment      false;
    protected 
$can_message      false;    
    
    public function 
__construct()
    {
        
$this->db        VF::factory('database');
        
$this->tpl        VF::factory('template');
        
$this->cache    VF::factory('cache');
        
        
$this->username    VUri::request(1);
    }
    
    public function 
render()
    {
        
$segment     VUri::request(2);
        
$components    = array(
            
'videos'            => array(
                
'public'        => 1,
                
'private'        => 1,
                
'favorites'        => 1,
                
'history'        => 1
            
),
            
'photos'            => array(
                
'favorites'        => 1,
                
'public'        => 1,
                
'private'        => 1
            
),
            
'connections'        => 1,
            
'comments'            => 1,
            
'activity'            => 1,
            
'info'                => 1,
            
'friends'            => 1,
            
'subscribers'        => 1,
            
'subscriptions'        => 1
        
);
        
        if (isset(
$components[$segment])) {
            if (
is_array($components[$segment])) {
                
$subsegment    VUri::request(3);
                if (isset(
$components[$segment][$subsegment])) {
                    
$component    $segment.'_'.$subsegment;
                } else {
                    
$component    $segment;
                }
            } else {
                
$component    $segment;
            }
        } else {
            
$component    'profile';
        }
        
        try {
            
$component_class    'VComponent_profile_'.$component;
            require 
MODULES_DIR.'/profile/components/'.$component.'.php';
            
            
VLanguage::load('frontend.user');
                
            
$obj = new $component_class();
            
$obj->render();
        } catch (
Exception $e) {
            throw new 
VException($e);
        }
    }
    
    protected function 
profile($username)
    {
        
$cache_id 'user_'.$username;
        if (!
$this->user $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT u.user_id, u.group_id, u.username, u.email, u.name, u.avatar, u.gender, u.relation, u.interested, u.birth_date,
                                     u.city, u.country, u.zip, u.rating, u.rated_by, u.login_date, u.join_date, u.online, u.popularity,
                                     ua.total_video_views, ua.total_viewed_videos, ua.total_profile_views, up.*, upp.*
                              FROM #__user AS u
                              LEFT JOIN #__user_activity AS ua ON (ua.user_id = u.user_id)
                              LEFT JOIN #__user_profile AS up ON (up.user_id = u.user_id)
                              LEFT JOIN #__user_preferences AS upp ON (upp.user_id = u.user_id)
                              WHERE u.username = '"
.$this->db->escape($username)."'
                              AND u.status = '1'
                              LIMIT 1"
);
            if (
$this->db->affected_rows()) {
                
$this->user $this->db->fetch_assoc();
                
$this->cache->store($cache_id$this->user3600);
            } else {
                
VModule::load('404'true);
            }
        }
            
        
$allow      true;
        
$user_id    = (VAuth::loggedin()) ? (int) $_SESSION['user_id'] : 0;
        
$owner_id   = (int) $this->user['user_id'];
        
$is_friend  = ($user_id) ? $this->is_friend($owner_id$user_id) : FALSE;
        
        if (
$this->user['profile'] == 'no') {
            
$allow      false;
            
$template   'error_disabled';
        } elseif (
$this->user['profile'] == 'friends' && !$user_id) {
            
$allow      false;
            
$template   'error_friend';
        } elseif (
$user_id) {
            if (
$user_id !== $owner_id) {
                if (
$this->is_blocked($owner_id$user_id)) {
                    
$allow      false;
                    
$template   'error_blocked';
                }
                
                if (
$this->user['profile'] == 'no') {
                    
$allow      false;
                    
$template   'error_disabled';
                } elseif (
$this->user['profile'] == 'friends') {
                    
$this->is_friend $this->is_friend($owner_id$user_id);
                    if (
$is_friend == 'pending' OR $is_friend == 'denied' OR !$is_friend) {
                        
$allow      false;
                        
$template   'error_friend';
                    }
                }
            } else {
                
$this->is_self true;
            }
        }
        
        if (!
$allow) {
            
$tpl VF::factory('template');

            
$tpl->menu      'home';
            
$tpl->username  $username;
            
$tpl->load(array('header'$template'footer'));
            
$tpl->display();

            return 
false;
        }
        
        
$this->is_subscribed    $this->is_subscribed($owner_id$user_id);
        
$this->is_loggedin      = ($user_id) ? true false;
        
$this->is_moderator     = (VAuth::group('Moderator')) ? true false;
        
$this->is_blocked       $this->has_block($user_id$owner_id);
        
$this->is_friend        $is_friend;

        return 
true;
    }

    protected function 
is_blocked($user_id$block_id)
    {
        if (
$user_id) {
            
$this->db->query("SELECT blocked_id
                              FROM #__user_blocks
                              WHERE user_id = "
.$user_id."
                              AND blocked_id = "
.$block_id."
                              LIMIT 1"
);
            if (
$this->db->affected_rows()) {
                return 
true;
            }
        }
        
        return 
false;
    }
    
    protected function 
has_block($user_id$block_id)
    {
        if (
$user_id) {
            
$this->db->query("SELECT blocked_id
                              FROM #__user_blocks
                              WHERE user_id = "
.$user_id."
                              AND blocked_id = "
.$block_id."
                              LIMIT 1"
);
            if (
$this->db->affected_rows()) {
                return 
true;
            }
        }
        
        return 
false;
    }
    
    protected function 
is_friend($user_id$friend_id)
    {
        if (
$friend_id) {
            
$this->db->query("SELECT user_id, status
                              FROM #__user_friends
                              WHERE user_id = "
.$user_id."
                              AND friend_id = "
.$friend_id."
                              LIMIT 1"
);
            if (
$this->db->affected_rows()) {
                return 
$this->db->fetch_field('status');
            }
        }
        
        return 
false;
    }
    protected function 
is_subscribed($user_id$subscriber_id)
    {
        if (
$subscriber_id) {
            
$this->db->query("SELECT user_id
                              FROM #__user_subscriptions
                              WHERE user_id = "
.$user_id."
                              AND subscriber_id = "
.$subscriber_id."
                              LIMIT 1"
);
            if (
$this->db->affected_rows()) {
                return 
true;
            }
        }
        
        return 
false;
    }
    
    protected function 
show($type)
    {
        if (
$this->is_self === true OR
            
$type == 'all' OR $type == 'approve') {
            return 
true;
        }
        
        if (
$type == 'no') {
            return 
false;
        }
        
        if (
$type == 'friends') {
            return (
$this->is_friend == 'approved') ? TRUE FALSE;
        }
    }

   protected function 
get_videos_count($user_id$type='public')
    {
        
$this->db->query("SELECT COUNT(*) AS total_videos
                          FROM #__video AS v
                          WHERE v.user_id = "
.$user_id."
                          AND v.type = '"
.$this->db->escape($type)."'
                          AND v.status = 1"
);

        
$total_videos $this->db->fetch_field('total_videos');

        return (
$total_videos == '0') ? FALSE $total_videos;
    }
    
    protected function 
get_videos($user_id$type='public'$limit=8)
    {
        
$cache_id 'user_videos_'.$type.'_'.$user_id;
        if (!
$videos $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT v.video_id, v.title, v.slug, v.rating, v.rated_by, v.duration, v.thumb,
                                     v.thumbs, v.add_time, v.total_views, v.ext, v.likes, v.hd
                              FROM #__video AS v
                              WHERE v.user_id = "
.$user_id."
                              AND v.type = '"
.$this->db->escape($type)."'
                              AND v.status = 1
                              ORDER BY v.video_id
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$videos $this->db->fetch_rows();
                
$this->cache->store($cache_id$videos3600);
            } else {
                
$videos NULL;
            }
        }
        
        return (
$videos) ? $videos NULL;
    }
   protected function 
get_favorites_count($user_id)
    {
        
$this->db->query("SELECT COUNT(*) AS total_videos
                          FROM #__video_favorites
                          WHERE user_id = "
.$user_id);

        
$total_videos $this->db->fetch_field('total_videos');

        return (
$total_videos == '0') ? FALSE $total_videos;
    }
    
    protected function 
get_video_favorites($user_id$limit=8)
    {
        
$cache_id 'user_favorite_videos'.$user_id;
        if (!
$videos $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT v.video_id, v.title, v.slug, v.rating, v.rated_by, v.duration, v.thumb,
                                     v.thumbs, v.add_time, v.total_views, v.ext, v.likes, v.hd, u.username
                              FROM #__video_favorites AS vf
                              LEFT JOIN #__video AS v ON (v.video_id = vf.video_id AND v.status = 1)
                              LEFT JOIN #__user AS u ON (u.user_id = v.user_id)
                              WHERE vf.user_id = "
.$user_id."
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$videos $this->db->fetch_rows();
                
$this->cache->store($cache_id$videos3600);
            } else {
                
$videos NULL;
            }
        }
        
        return (
$videos) ? $videos NULL;
    }
    
    protected function 
get_video_ratings($user_id$limit=8)
    {
        
// need to fix the video rating system...
        
return NULL;

        
$cache_id 'user_rated_videos_'.$user_id;
        if (!
$videos $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT v.video_id, v.title, v.slug, v.rating, v.rated_by, v.duration, v.thumb,
                                     v.thumbs, v.add_time, u.username
                              FROM #__video_rating AS vr
                              LEFT JOIN #__video AS v ON (v.video_id = vr.video_id AND v.status = 1)
                              LEFT JOIN #__user AS u ON (u.user_id = v.user_id)
                              WHERE vr.voter_id = "
.$user_id."
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$videos $this->db->fetch_rows();
                
$this->cache->store($cache_id$videos3600);
            } else {
                
$videos NULL;
            }
        }
        
        return (
$videos) ? $videos NULL;
    }
    
    protected function 
get_history_count($user_id)
    {
        
$this->db->query("SELECT COUNT(DISTINCT video_id) AS total_videos
                          FROM #__video_history
                          WHERE user_id = "
.$user_id);

        
$total_videos $this->db->fetch_field('total_videos');

        return (
$total_videos == '0') ? FALSE $total_videos;
    }

   protected function 
get_video_history($user_id$limit=8)
    {
        
$cache_id 'user_video_history_'.$user_id;
        if (!
$videos $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT DISTINCT v.video_id, v.title, v.slug, v.rating, v.rated_by, v.duration, v.thumb,
                                              v.thumbs, v.add_time, v.total_views, v.ext, u.username, v.likes, v.hd
                              FROM #__video_history AS vh
                              LEFT JOIN #__video AS v ON (v.video_id = vh.video_id AND v.status = 1)
                              LEFT JOIN #__user AS u ON (u.user_id = v.user_id)
                              WHERE vh.user_id = "
.$user_id."
                              ORDER BY vh.view_time DESC
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$videos $this->db->fetch_rows();
                
$this->cache->store($cache_id$videos3600);
            } else {
                
$videos NULL;
            }
        }
        
        return (
$videos) ? $videos NULL;
    }
    
    protected function 
get_friends_count($user_id)
    {
        
$this->db->query("SELECT COUNT(*) AS total_friends
                          FROM #__user_friends
                          WHERE user_id = "
.$user_id."
                          AND status = 'approved'"
);

        
$total_friends $this->db->fetch_field('total_friends');

        return (
$total_friends == '0') ? FALSE $total_friends;
    }
    
    protected function 
get_friends($user_id$limit=6)
    {
        
$cache_id 'user_friends_'.$user_id.'_'.$limit;
        if (!
$friends $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT u.user_id, u.username, u.gender, u.online, u.avatar
                              FROM #__user_friends AS uf
                              INNER JOIN #__user AS u ON (u.user_id = uf.friend_id AND u.status = '1')
                              WHERE uf.user_id = "
.$user_id."
                              AND uf.status = 'approved'
                              ORDER BY uf.add_date DESC
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$friends $this->db->fetch_rows();
                
$this->cache->store($cache_id$friends3600);
            } else {
                
$friends NULL;
            }
        }
        
        return (
$friends) ? $friends NULL;
    }
    
    protected function 
get_subscriptions_count($user_id)
    {
        
$this->db->query("SELECT COUNT(*) AS total_subscriptions
                          FROM #__user_subscriptions
                          WHERE subscriber_id = "
.$user_id);

        
$total_subscriptions $this->db->fetch_field('total_subscriptions');

        return (
$total_subscriptions == '0') ? FALSE $total_subscriptions;
    }
    
    protected function 
get_subscriptions($user_id$limit=4)
    {
        
$cache_id 'user_subscriptions_'.$user_id.'_'.$limit;
        if (!
$subscriptions $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT u.user_id, u.username, u.gender, u.online, u.avatar
                              FROM #__user_subscriptions AS us
                              INNER JOIN #__user AS u ON (u.user_id = us.user_id AND u.status = '1')
                              WHERE us.subscriber_id = "
.$user_id."
                              ORDER BY us.add_date DESC
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$subscriptions $this->db->fetch_rows();
                
$this->cache->store($cache_id$subscriptions3600);
            } else {
                
$subscriptions NULL;
            }
        }
        
        return (
$subscriptions) ? $subscriptions NULL;
    }
    
    protected function 
get_subscribers_count($user_id)
    {
        
$this->db->query("SELECT COUNT(*) AS total_subscribers
                          FROM #__user_subscriptions
                          WHERE user_id = "
.$user_id);

        
$total_subscribers $this->db->fetch_field('total_subscribers');

        return (
$total_subscribers == '0') ? FALSE $total_subscribers;
    }

    protected function 
get_subscribers($user_id$limit=4)
    {
        
$cache_id 'user_subscribers_'.$user_id.'_'.$limit;
        if (!
$subscribers $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT u.user_id, u.username, u.gender, u.online, u.avatar
                              FROM #__user_subscriptions AS us
                              INNER JOIN #__user AS u ON (u.user_id = us.subscriber_id AND u.status = '1')
                              WHERE us.user_id = "
.$user_id."
                              ORDER BY us.add_date DESC
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$subscribers $this->db->fetch_rows();
                
$this->cache->store($cache_id$subscribers3600);
            } else {
                
$subscribers NULL;
            }
        }
        
        return (
$subscribers) ? $subscribers NULL;
    }

    protected function 
get_albums_count($user_id$type='public')
    {
        
$this->db->query("SELECT COUNT(*) AS total_albums
                          FROM #__photo_albums
                          WHERE user_id = "
.$user_id."
                          AND type = '"
.$type."'
                          AND status = '1'"
);

        
$total_albums $this->db->fetch_field('total_albums');

        return (
$total_albums == '0') ? FALSE $total_albums;
    }

    protected function 
get_albums($user_id$type='public'$limit=8)
    {
        
$cache_id 'user_albums_'.$user_id.'_'.$type.'_'.$limit;
        if (!
$albums $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT album_id, title, slug, likes, rating, rated_by,
                                     total_views, total_photos, add_time, type
                              FROM #__photo_albums
                              WHERE user_id = "
.$user_id."
                              AND type = '"
.$type."'
                              AND status = '1'
                              ORDER BY album_id DESC
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$albums $this->db->fetch_rows();
                
$this->cache->store($cache_id$albums3600);
            } else {
                
$albums NULL;
            }
        }
        
        return (
$albums) ? $albums NULL;
    }
    
    protected function 
get_photo_favorites_count($user_id)
    {
        
$this->db->query("SELECT COUNT(*) AS total_photos
                          FROM #__photo_favorites
                          WHERE user_id = "
.$user_id);

        
$total_photos $this->db->fetch_field('total_photos');

        return (
$total_photos == '0') ? FALSE $total_photos;
    }
    
    protected function 
get_photo_favorites($user_id$limit=8)
    {
        
$cache_id 'photo_favorites_'.$user_id.'_'.$limit;
        if (!
$photos $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT p.photo_id, p.caption, p.total_views, p.total_comments, p.likes, p.rating, p.rated_by, a.type
                              FROM #__photo_favorites AS pf
                              INNER JOIN #__photo AS p ON (p.photo_id = pf.photo_id AND p.status = '1')
                              INNER JOIN #__photo_albums AS a ON (a.album_id = p.album_id AND a.status = '1')
                              WHERE pf.user_id = "
.$user_id."
                              LIMIT "
.$limit);
            if (
$this->db->affected_rows()) {
                
$photos $this->db->fetch_rows();
                
$this->cache->store($cache_id$photos3600);
            } else {
                
$photos NULL;
            }
        }
        
        return (
$photos) ? $photos NULL;
    }
}
Онлайн: 1
Реклама