Вход Регистрация
Файл: adultscript-2.0.3-pro/files/mobile/components/users.php
Строк: 333
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_mobile_users extends VMobile
{
    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($profile false)
    {
        
parent::__construct();
        
        if (
$profile) {
            
$this->profile();
        }
    }

    public function 
render()
    {
        
$segment        VUri::request(2);
        
$component        'profile';
        
$components        = array(
            
'profile' => 1,
            
'videos' => 1,
            
'connections' => 1,
            
'info' => 1
            
'comments' => 1,
            
'friends' => 1,
            
'subscribers' => 1,
            
'subscriptions' => 1
        
);
        
$components_video    = array(
            
'favorites' => 1,
            
'public' => 1,
            
'private' => 1,
            
'history' => 1,
            
'ratings' => 1,
            
'playlists' => 1,
            
'rated' => 1
        
);
        
        
$photo_components = array();
        if (
VModule::enabled('photo')) {
            
$components['photos'] = 1;
            
$components_photo   = array(
                
'public' => 1,
                
'private' => 1,
                
'favorites' => 1,
                
'history' => 1,
                
'rated' => 1
            
);
        }        
        
        if (isset(
$components[$segment])) {
            
$component        $segment;
            
$segment        VUri::request(3);
            if (
$segment != '' && !ctype_digit($segment)) {
                if (
$component == 'videos' && isset($components_video[$segment])) {
                    
$component    'videos_'.$segment;
                } elseif (
$component == 'photos' && isset($components_photo[$segment])) {
                    
$component    'photos_'.$segment;
                } else {
                    
$this->notfound();
                }
            }
        }
        
        
$component_class    'VComponent_mobile_users_'.$component;

        try {
            require 
BASE_DIR.'/mobile/components/users_'.$component.'.php';
            
            
VLanguage::load('profile.profile');

            
$obj = new $component_class();
            
$obj->render();
        } catch (
Exception $e) {
            throw new 
VException($e);
        }        
    }
    
    protected function 
profile()
    {
        
$username    VUri::request(1);

        if (
$username != '') {
              
$cache_id 'user_'.$username;
              if (!
$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.*, u.reported
                                  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->username    $this->user['username'];
                      
$this->cache->store($cache_id$this->user3600);
                  }
              }
        }
        
        if (!
$this->user) {
            
$this->notfound('Invalid username!');
        }
        
        
$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   'users_error_disabled';
        } elseif (
$this->user['profile'] == 'friends' && !$user_id) {
            
$allow      false;
            
$template   'users_error_friend';
        } elseif (
$user_id) {
            if (
$user_id !== $owner_id) {
                if (
$this->is_blocked($owner_id$user_id)) {
                    
$allow      false;
                    
$template   'users_error_blocked';
                }
                
                if (
$this->user['profile'] == 'no') {
                    
$allow      false;
                    
$template   'users_error_disabled';
                } elseif (
$this->user['profile'] == 'friends') {
//                  $this->is_friend = $this->is_friend($owner_id, $user_id);
                    
if ($is_friend == 'pending' OR $is_friend == 'denfied' OR !$is_friend) {
                        
$allow      false;
                        
$template   'users_error_friend';
                    }
                }
            } else {
                
$this->is_self true;
            }
        }

        if (!
$allow) {
            
$this->tpl->menu      'home';
            
$this->tpl->username  $username;
            
$this->tpl->load(array('header'$template'footer'));
            
$this->tpl->display();
            
VF::close();
        }
        
        
$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;
    }

    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 
update_views($user_id)
    {
          
$this->db->query("
              UPDATE #__user_activity
              SET total_profile_views = total_profile_views+1
              WHERE user_id = "
.$user_id."
              LIMIT 1"
          
);
    }
    
    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
                              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, 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
                              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, 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.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;
    }
    
    protected function 
get_comments($user_id$limit=10)
    {
        
$total_comments $this->db->get_field("SELECT COUNT(*) AS total_comments
                                                FROM #__user_comments
                                                WHERE user_id = "
.$user_id."
                                                AND status = '1'"
'total_comments');
        
$pagination     VPagination::get(1$total_comments10);

        
$cache_id 'user_comments_'.$user_id;
        if (!
$comments $this->cache->get($cache_id3600)) {
            
$this->db->query("SELECT uc.comment_id, uc.parent_id, uc.user_id, uc.poster_id, uc.comment, uc.add_time,
                                     u.username, u.gender, u.avatar
                              FROM #__user_comments AS uc
                              LEFT JOIN #__user AS u ON (u.user_id = uc.poster_id)
                              WHERE uc.user_id = "
.$user_id."
                              AND uc.status = '1'
                              ORDER BY uc.comment_id DESC
                              LIMIT 5"
);
            if (
$this->db->affected_rows()) {
                
$comments $this->db->fetch_rows();
                
$this->cache->store($cache_id$comments3600);
            } else {
                
$comments = array();
            }
        }
        
        return array(
            
'comments'      => $comments,
            
'pagination'    => $pagination
        
);
    }
}
Онлайн: 3
Реклама