public function getItem($pk = null) { $app = JFactory::getApplication(); $session = JFactory::getSession(); $db = JFactory::getDBO(); $params = JComponentHelper::getParams('com_tracker'); $user_profile = null; if (JRequest::getVar('id', '', 'get', 'int')) { $userID = JRequest::getVar('id', '', 'get', 'int'); } else { $userID = $session->get('user')->id; } // In case the user is new, check the database and add it to the #__tracker_users TrackerHelper::get_new_users(); // Load the user from the database (and check if the id exists) $query = $db->getQuery(true); $query->clear(); $query->select('id'); $query->from('#__users'); $query->where('id = ' . (int) $userID); $query->limit('0,1'); $db->setQuery($query); $user_profileID = $db->loadResult(); if ($user_profileID != 0) { $user_profile = JFactory::getUser($user_profileID); // load the logged in user // Get the user tracker information $query = $db->getQuery(true); $query->clear(); $query->select('*'); $query->from('#__tracker_users'); $query->where('id = ' . (int) $user_profile->id); $query->limit('0,1'); $db->setQuery($query); $user_profile->tracker_info = $db->loadNextObject(); if ($params->get('enable_countries')) { // If the user doesn't have the country defined, get the default country for component parameters if ($user_profile->tracker_info->countryID == 0) { $user_profile->tracker_info->countryID == $params->get('defaultcountry'); } $query = $db->getQuery(true); // Get the user country $query->select('name, image'); $query->from('#__tracker_countries'); $query->where('id = ' . (int) $user_profile->tracker_info->countryID); $query->limit('0,1'); $db->setQuery($query); $user_profile->country_info = $db->loadNextObject(); } if ($params->get('enable_thankyou')) { // Get the number of times the user was thanked $query->clear(); $query->select('COUNT(u.id) as total_thanks'); $query->from('`#__tracker_torrent_thanks` AS ttt'); $query->join('LEFT', '`#__tracker_torrents` AS tt ON tt.fid = ttt.torrentID'); $query->join('LEFT', '`#__users` AS u ON u.id = tt.uploader'); $query->where('u.id = ' . (int) $user_profile->id); $db->setQuery($query); $user_profile->total_thanks = $db->loadResult(); // Get the number of thanks the user gave $query->clear(); $query->select('COUNT(uid) as thanker'); $query->from('#__tracker_torrent_thanks'); $query->where('uid = ' . (int) $user_profile->id); $db->setQuery($query); $user_profile->thanker = $db->loadResult(); } // Get the user last IP and tracker activity $query->clear(); $query->select('ipa, mtime'); $query->from('#__tracker_announce_log'); $query->where('uid = ' . (int) $user_profile->id); $query->order('id DESC'); $query->limit('0,1'); $db->setQuery($query); $user_profile->announce = $db->loadNextObject(); if (!$user_profile->announce) { $user_profile->lastseen = JText::_('COM_TRACKER_LAST_TRACKER_ACTIVITY_NEVER'); $user_profile->announce = new stdClass(); $user_profile->announce->ipa = JText::_('COM_TRACKER_NO_LAST_IP'); } else { $user_profile->lastseen = date('Y-m-d H:i:s', $user_profile->announce->mtime) . ' - ' . TrackerHelper::last_activity(date('Y-m-d H:i:s', $user_profile->announce->mtime), 1, 1); $user_profile->announce->ipa = long2ip($user_profile->announce->ipa); } // Get the user group $query->clear(); $query->select('*'); $query->from('#__tracker_groups'); $query->where('id = ' . (int) $user_profile->tracker_info->groupID); $query->order('id DESC'); $query->limit('0,1'); $db->setQuery($query); $user_profile->group_info = $db->loadNextObject(); if ($params->get('enable_donations')) { // Get the user donations $query->clear(); $query->select('sum(donated) as donated, sum(credited) as credited'); $query->from('#__tracker_donations'); $query->where('uid = ' . (int) $user_profile->id); $query->where('state = 1'); $db->setQuery($query); $user_profile->user_donations = $db->loadNextObject(); } // ---------------------------------------- Snatched Torrents // Get total number of snatches $query->clear(); $query->select('count(fu.fid)'); $query->from('#__tracker_files_users AS fu'); $query->join('LEFT', '#__tracker_torrents as t on t.fid = fu.fid'); $query->where('fu.uid = ' . (int) $user_profile->id); $query->where('fu.completed > 0'); $query->where('t.uploader <> ' . (int) $user_profile->id); $db->setQuery($query); if ($user_profile->total_snatch = $db->loadResult()) { // Get the user snatched torrents $query->clear(); $query->select('DISTINCT(fu.fid), t.name, t.leechers, t.seeders, t.completed, fu.downloaded, fu.uploaded'); $query->from('#__tracker_files_users AS fu'); $query->join('LEFT', '#__tracker_torrents as t on t.fid = fu.fid'); $query->where('fu.uid = ' . (int) $user_profile->id); $query->where('fu.completed > 0'); $query->where('t.uploader <> ' . (int) $user_profile->id); $query->order('fu.fid DESC'); $db->setQuery($query); $user_profile->user_snatches = $db->loadObjectList(); } // ---------------------------------------- Uploaded Torrents # Get total number of uploaded torrents $query->clear(); $query->select('count(t.fid)'); $query->from('#__tracker_torrents AS t'); $query->join('LEFT', '#__users as u on u.id = t.uploader'); $query->where('t.uploader = ' . (int) $user_profile->id); $query->where('t.name <> \'\''); $query->order('t.fid DESC'); $db->setQuery($query); if ($user_profile->total_uploads = $db->loadResult()) { # Get the user uploaded torrents $query->clear(); $query->select('t.fid, t.name, t.leechers, t.seeders, t.completed'); $query->from('#__tracker_torrents AS t'); $query->join('LEFT', '#__users AS u ON u.id = t.uploader'); $query->where('t.uploader = ' . (int) $user_profile->id); $query->where('t.name <> \'\''); // Show the anonymous uploaded torrent if the user is the owner. If it's another user it keeps the anonymous torrents hidden if ($user_profile->id != $session->get('user')->id || TrackerHelper::user_permissions('edit_torrents', $user_profile->tracker_info->groupID) == 0) { $query->where('t.uploader_anonymous = 0'); } $query->order('t.fid DESC'); $db->setQuery($query); $user_profile->user_uploads = $db->loadObjectList(); } // ---------------------------------------- Seeded Torrents # Get the user seeded torrents $query->clear(); $query->select('count(fu.fid)'); $query->from('#__tracker_files_users AS fu'); $query->join('LEFT', '#__tracker_torrents as t on fu.fid = t.fid'); $query->where('fu.uid = ' . (int) $user_profile->id); $query->where('fu.left = 0'); $query->where('fu.active = 1'); $query->where('t.name <> \'\''); $query->order('fu.fid DESC'); $db->setQuery($query); if ($user_profile->total_seeds = $db->loadResult()) { # Get the user seeded torrents $query->clear(); $query->select('DISTINCT(fu.fid), t.name, t.leechers, t.seeders, t.completed'); $query->from('#__tracker_files_users AS fu'); $query->join('LEFT', '#__tracker_torrents as t on fu.fid = t.fid'); $query->where('fu.uid = ' . (int) $user_profile->id); $query->where('fu.left = 0'); $query->where('fu.active = 1'); $query->where('t.name <> \'\''); $query->order('fu.fid DESC'); $db->setQuery($query); $user_profile->user_seeds = $db->loadObjectList(); } // ---------------------------------------- Leeched and Ran # Get the leeched and run torrents $query->clear(); $query->select('count(fu.fid)'); $query->from('#__tracker_files_users AS fu'); $query->join('LEFT', '#__tracker_torrents as t on fu.fid = t.fid'); $query->where('fu.uid = ' . (int) $user_profile->id); $query->where('fu.left = 0'); $query->where('fu.active = 0'); $query->where('fu.uploaded = 0'); $query->where('fu.downloaded > 0'); $query->where('t.name <> \'\''); $query->order('fu.fid DESC'); $db->setQuery($query); if ($user_profile->total_hitandran = $db->loadResult()) { # Get the leeched and run torrents $query->clear(); $query->select('DISTINCT(fu.fid), t.name, t.leechers, t.seeders, t.completed, fu.downloaded, fu.uploaded'); $query->from('#__tracker_files_users AS fu'); $query->join('LEFT', '#__tracker_torrents as t on fu.fid = t.fid'); $query->where('fu.uid = ' . (int) $user_profile->id); $query->where('fu.left = 0'); $query->where('fu.active = 0'); $query->where('fu.uploaded = 0'); $query->where('fu.downloaded > 0'); $query->where('t.name <> \'\''); $query->order('fu.fid DESC'); $db->setQuery($query); $user_profile->user_hitruns = $db->loadObjectList(); } } else { $user_profile->id = 0; return $user_profile; } return $user_profile; }
protected function getListQuery() { $db = $this->getDbo(); $query = $db->getQuery(true); $params = JComponentHelper::getParams('com_tracker'); // In case the user is new, check the database and add it to the #__tracker_users TrackerHelper::get_new_users(); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*, (a.downloaded/a.uploaded) as ratio ')); $query->from('`#__tracker_users` AS a'); // Join the user table $query->select(' u.name as name, u.username as username, u.email as email, u.block as block'); $query->join('LEFT', '`#__users` AS u ON u.id = a.id'); if ($params->get('enable_countries')) { // Join over the countries table $query->select(' c.image AS countryImage, c.name AS countryName'); $query->join('LEFT', '`#__tracker_countries` AS c on c.id = a.countryID'); } if ($params->get('enable_donations')) { // Join over the donations table $query->select(' (SELECT SUM(d.donated) FROM `#__tracker_donations` AS d WHERE d.uid = a.id) as donated '); $query->select(' (SELECT SUM(d.credited) FROM `#__tracker_donations` AS d WHERE d.uid = a.id) as credited '); } // Join over the groups table $query->select('g.name as group_name'); $query->join('LEFT', '`#__tracker_groups` AS g on g.id = a.groupID'); // Filter by group $group = $this->getState('filter.group'); if ($group) { $query->where('a.groupID = ' . (int) $group); } if ($params->get('enable_countries')) { // Filter by country $country = $this->getState('filter.country'); if ($country) { $country = $db->Quote('%' . $db->getEscaped($country, true) . '%'); $query->where('c.id = ' . (int) $country); } } // Filter by state (user blocked or not) $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('u.block = ' . (int) $state); } else { if ($state === '') { $query->where('(u.block IN (0, 1))'); } } // Filter by search in title $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $db->Quote('%' . $db->getEscaped($search, true) . '%'); $query->where('u.name LIKE ' . $search . ' OR u.username LIKE ' . $search); } } // Add the list ordering clause. $query->order($db->getEscaped($this->getState('list.ordering', 'a.id')) . ' ' . $db->getEscaped($this->getState('list.direction', 'ASC'))); return $query; }