public function onBeforeMain($tpl = null) { // Prevent phpStorm's whining... if ($tpl) { } // Load the model /** @var Categories $model */ $model = $this->getModel('Categories'); // Assign data to the view, part 1 (we need this later on) $this->categories = $model->get(true)->filter(function ($item) { return Filter::filterItem($item, true); }); $this->vgroups = Filter::getCategoriesPerVisualGroup($this->categories); /** @var Releases $releasesModel */ $releasesModel = $this->getModel(); $releases = $releasesModel->get(true); $this->releases = []; if ($releases->count()) { /** @var Releases $release */ foreach ($releases as $release) { $this->releases[$release->category_id] = $release; } } // Add RSS links /** @var \JApplicationSite $app */ $app = \JFactory::getApplication(); // Pass page params $this->params = $app->getParams(); $this->cparams = \JComponentHelper::getParams('com_ars'); $this->Itemid = $this->input->getInt('Itemid', 0); $this->menu = $app->getMenu()->getActive(); return true; }
public function getItems($streams) { $arsContainer = \FOF30\Container\Container::getInstance('com_ars'); $items = array(); /** @var \Akeeba\ReleaseSystem\Site\Model\Update $model */ $model = $arsContainer->factory->model('Update'); /** @var \Akeeba\ReleaseSystem\Admin\Model\Items $dlModel */ $dlModel = $arsContainer->factory->model('Items'); foreach ($streams as $stream_id) { $items = $model->getItems($stream_id); if (empty($items)) { continue; } $i = array_shift($items); // Is the user authorized to download this item? $iFull = $dlModel->find($i->item_id); if (!\Akeeba\ReleaseSystem\Site\Helper\Filter::filterItem($iFull)) { continue; } // Add this item $newItem = array('id' => $i->item_id, 'release_id' => $i->release_id, 'name' => $i->name, 'version' => $i->version, 'maturity' => $i->maturity); $items[] = (object) $newItem; } return $items; }
public function onBeforeBrowse($tpl = null) { // Prevent phpStorm's whining... if ($tpl) { } // Load the model /** @var Categories $model */ $model = $this->getModel(); // Assign data to the view, part 1 (we need this later on) $this->items = $model->get(true)->filter(function ($item) { return Filter::filterItem($item, true); }); $visualGroups = Filter::getCategoriesPerVisualGroup($this->items); // Add RSS links /** @var \JApplicationSite $app */ $app = \JFactory::getApplication(); /** @var \JRegistry $params */ $params = $app->getParams('com_ars'); // Get the ordering $this->order = $model->getState('filter_order', 'id', 'cmd'); $this->order_Dir = $model->getState('filter_order_Dir', 'DESC', 'cmd'); // Assign data to the view $this->pagination = new \JPagination($model->count(), $model->limitstart, $model->limit); $this->vgroups = $visualGroups; // Pass page params $this->params = $app->getParams(); $this->Itemid = $this->input->getInt('Itemid', 0); $this->menu = $app->getMenu()->getActive(); return true; }
public function onBeforeBrowse($tpl = null) { // Prevent phpStorm's whining... if ($tpl) { } // Load the model /** @var Releases $model */ $model = $this->getModel(); // Assign data to the view, part 1 (we need this later on) $this->items = $model->get()->filter(function ($item) { return Filter::filterItem($item, true); }); // Add breadcrumbs $repoType = $this->items->first()->category->type; Breadcrumbs::addRepositoryRoot($repoType); Breadcrumbs::addCategory($this->items->first()->category->id, $this->items->first()->category->title); // Add RSS links /** @var \JApplicationSite $app */ $app = \JFactory::getApplication(); /** @var \JRegistry $params */ $params = $app->getParams('com_ars'); // Get the ordering $this->order = $model->getState('filter_order', 'id', 'cmd'); $this->order_Dir = $model->getState('filter_order_Dir', 'DESC', 'cmd'); // Assign data to the view $this->pagination = new \JPagination($model->count(), $model->limitstart, $model->limit); $this->category = $this->getModel('Categories'); // Pass page params $this->params = $app->getParams(); $this->Itemid = $this->input->getInt('Itemid', 0); $this->menu = $app->getMenu()->getActive(); return true; }
public function onBeforeBrowse($tpl = null) { // Prevent phpStorm's whining... if ($tpl) { } // Load the model /** @var Items $model */ $model = $this->getModel(); // Assign data to the view, part 1 (we need this later on) $this->items = $model->get(true)->filter(function ($item) { return Filter::filterItem($item, true); }); /** @var \JApplicationSite $app */ $app = \JFactory::getApplication(); $user = $this->container->platform->getUser(); $params = $app->getParams(); // Add Breadcrumbs /** @var Releases $release */ $release = $this->getModel('Releases'); /** @var Categories $category */ $category = $release->category; Breadcrumbs::addRepositoryRoot($category->type); Breadcrumbs::addCategory($category->id, $category->title); Breadcrumbs::addRelease($release->id, $release->version); // DirectLink setup $this->downloadId = Filter::myDownloadID(); $directlink = $params->get('show_directlink', 1) && !$user->guest; $this->directlink = $directlink; // Pass on Direct Link-related stuff if ($directlink) { $directlink_extensions = explode(',', $params->get('directlink_extensions', 'zip,tar,tar.gz,tgz,tbz,tar.bz2')); if (empty($directlink_extensions)) { $directlink_extensions = array(); } else { $temp = array(); foreach ($directlink_extensions as $ext) { $temp[] = '.' . trim($ext); } $directlink_extensions = $temp; } $this->directlink_extensions = $directlink_extensions; $this->directlink_description = $params->get('directlink_description', \JText::_('COM_ARS_CONFIG_DIRECTLINKDESCRIPTION_DEFAULT')); } // Get the ordering $this->order = $model->getState('filter_order', 'id', 'cmd'); $this->order_Dir = $model->getState('filter_order_Dir', 'DESC', 'cmd'); // Assign data to the view $this->pagination = new \JPagination($model->count(), $model->limitstart, $model->limit); $this->release = $this->getModel('Releases'); // Pass page params $this->params = $params; $this->Itemid = $this->input->getInt('Itemid', 0); $this->menu = $app->getMenu()->getActive(); return true; }
private static function process($match) { $ret = ''; $user = JFactory::getUser(); if (!$user->guest) { if (!isset(self::$cache[$user->id])) { self::$cache[$user->id] = \Akeeba\ReleaseSystem\Site\Helper\Filter::myDownloadID(); } $ret = self::$cache[$user->id]; } return $ret; }
public function onBeforeBrowse() { // Only apply on HTML views if (!in_array($this->input->getCmd('format', 'html'), ['html', 'feed'])) { return; } // Get the page parameters /** @var \JApplicationSite $app */ $app = \JFactory::getApplication(); $params = $app->getParams('com_ars'); // Push the page params to the Releases model /** @var Categories $categoryModel */ $categoryModel = $this->getModel('Categories')->orderby_filter($params->get('orderby', 'order'))->access_user($this->container->platform->getUser()->id); /** @var Releases $releasesModel */ $releasesModel = $this->getModel()->orderby_filter($params->get('rel_orderby', 'order'))->access_user($this->container->platform->getUser()->id); // Get the category ID $id = $this->input->getInt('category_id', 0); if (empty($id)) { $id = $params->get('catid', 0); } try { // Try to find the category $categoryModel->find($id); // Make sure subscription level filtering allows access if (!Filter::filterItem($categoryModel) || !$categoryModel->published) { throw new \Exception('Filtering failed'); } } catch (\Exception $e) { $noAccessURL = \JComponentHelper::getParams('com_ars')->get('no_access_url', ''); if ($categoryModel->id && $categoryModel->redirect_unauth && $categoryModel->show_unauth_links) { $noAccessURL = $categoryModel->redirect_unauth; } if (!empty($noAccessURL)) { \JFactory::getApplication()->redirect($noAccessURL); return; } throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } // Filter the releases by this category $releasesModel->category($categoryModel->id)->published(1); /** @var BleedingEdge $bleedingEdgeModel */ $bleedingEdgeModel = $this->container->factory->model('BleedingEdge'); $bleedingEdgeModel->scanCategory($categoryModel); // Push the models to the view $this->getView()->setDefaultModel($releasesModel); $this->getView()->setModel('Categories', $categoryModel); }
<?php /** * @package AkeebaReleaseSystem * @copyright Copyright (c)2010-2014 Nicholas K. Dionysopoulos * @license GNU General Public License version 3, or later * @version $Id$ */ defined('_JEXEC') or die; if (!defined('FOF30_INCLUDED') && !@(include_once JPATH_LIBRARIES . '/fof30/include.php')) { return; } // Do not run if Akeeba Subscriptions is not enabled JLoader::import('joomla.application.component.helper'); if (!JComponentHelper::isEnabled('com_ars')) { return; } if (!class_exists('Akeeba\\ReleaseSystem\\Site\\Helper\\Filter')) { // This has the side-effect of initialising our auto-loader \FOF30\Container\Container::getInstance('com_ars'); } $dlid = \Akeeba\ReleaseSystem\Site\Helper\Filter::myDownloadID(); if (!is_null($dlid)) { require JModuleHelper::getLayoutPath('mod_arsdlid', $params->get('layout', 'default')); }
<?php defined('_JEXEC') or die; /** @var \Akeeba\ReleaseSystem\Site\View\Releases\Html $this */ use Akeeba\ReleaseSystem\Site\Helper\Filter; use Akeeba\ReleaseSystem\Site\Helper\Router; use Akeeba\ReleaseSystem\Admin\Helper\Format; $released = JFactory::getDate($item->created); $release_url = Router::_('index.php?option=com_ars&view=Items&release_id=' . $item->id . '&Itemid=' . $Itemid); $authorisedViewLevels = $this->getContainer()->platform->getUser()->getAuthorisedViewLevels(); if (!Filter::filterItem($item, false, $authorisedViewLevels) && !empty($item->redirect_unauth)) { $release_url = $item->redirect_unauth; } switch ($item->maturity) { case 'stable': $maturityClass = 'label-success'; break; case 'rc': $maturityClass = 'label-info'; break; case 'beta': $maturityClass = 'label-warning'; break; case 'alpha': $maturityClass = 'label-important'; break; default: $maturityClass = 'label-inverse'; break; } ?>
* @copyright Copyright (c)2010-2015 Nicholas K. Dionysopoulos * @license GNU General Public License version 3, or later */ defined('_JEXEC') or die; /** @var \Akeeba\ReleaseSystem\Site\View\Update\Xml $this */ use Akeeba\ReleaseSystem\Site\Helper\Router; use Akeeba\ReleaseSystem\Site\Helper\Filter; $rootURL = rtrim(JURI::base(), '/'); $subpathURL = JURI::base(true); if (!empty($subpathURL) && $subpathURL != '/') { $rootURL = substr($rootURL, 0, -1 * strlen($subpathURL)); } $tag = "<" . "?xml version=\"1.0\" encoding=\"utf-8\"" . "?" . ">"; $dlid = trim($this->input->getCmd('dlid', '')); if (!empty($dlid)) { $dlid = Filter::reformatDownloadID($dlid); } if (!empty($dlid)) { $dlid = '&dlid=' . $dlid; } else { $dlid = ''; } $streamTypeMap = array('components' => 'component', 'libraries' => 'library', 'modules' => 'module', 'packages' => 'package', 'plugins' => 'plugin', 'files' => 'file', 'templates' => 'template'); @ob_end_clean(); //@header('Content-type: application/xml'); echo $tag; ?> <!-- Update stream generated automatically by Akeeba Release System on <?php echo gmdate('Y-m-d H:i:s'); ?> -->
<?php defined('_JEXEC') or die; /** @var \Akeeba\ReleaseSystem\Site\View\Latest\Html $this */ use Akeeba\ReleaseSystem\Site\Helper\Filter; use Akeeba\ReleaseSystem\Site\Helper\Router; use Akeeba\ReleaseSystem\Admin\Helper\Format; use Akeeba\ReleaseSystem\Admin\Helper\Select; $download_url = Router::_('index.php?option=com_ars&view=Item&task=download&format=raw&id=' . $item->id . '&Itemid=' . $this->Itemid); if (!Filter::filterItem($item, false, $this->getContainer()->platform->getUser()->getAuthorisedViewLevels()) && !empty($item->redirect_unauth)) { $download_url = $item->redirect_unauth; } ?> <tr> <td> <a href="{{ htmlentities($download_url) }}" rel="nofollow"> {{{ $item->title }}} </a> </td> <td width="25%"> <a href="{{ htmlentities($download_url) }}" rel="nofollow" class="btn btn-small"> <span class="icon icon-download"></span> @lang('LBL_ITEM_DOWNLOAD') </a> </td> <td width="20%" class="small"> @unless(!$this->cparams->get('show_downloads', 1)) @lang('LBL_ITEMS_HITS') @sprintf(($item->hits == 1 ? 'LBL_RELEASES_TIME' : 'LBL_RELEASES_TIMES'), $item->hits)
/** * Log in a user if necessary * * @return boolean True if a user was logged in */ public function loginUser() { // No need to log in a user if the user is already logged in if (!$this->container->platform->getUser()->guest) { return false; } // This is Joomla!'s login and user helpers \JPluginHelper::importPlugin('user'); JLoader::import('joomla.user.helper'); // Get the query parameters $dlid = $this->input->getString('dlid', null); $credentials = array(); $credentials['username'] = $this->input->getUsername('username', ''); $credentials['password'] = $this->input->get('password', '', 'raw', 3); // Initialise $user_id = 0; // First attempt to log in by download ID if (!empty($dlid)) { try { $user_id = Filter::getUserFromDownloadID($dlid)->id; } catch (\Exception $exc) { $user_id = 0; } } // If the dlid failed, used he legacy username/password pair if ($user_id === 0 && !empty($credentials['username']) && !empty($credentials['password'])) { \JLoader::import('joomla.user.authentication'); $options = array('remember' => false); $authenticate = \JAuthentication::getInstance(); $response = $authenticate->authenticate($credentials, $options); if ($response->status == \JAuthentication::STATUS_SUCCESS) { $user_id = \JUserHelper::getUserId($response->username); } } // Log in the user if ($user_id !== 0) { // Mark the user login so we can log him out later on $this->haveLoggedInAUser = true; // This line returns an empty JUser object $newUserObject = new \JUser(); // This line FORCE RELOADS the user record. $newUserObject->load($user_id); // Mark the user as logged in $newUserObject->block = 0; $newUserObject->set('guest', 0); // Register the needed session variables $session = \JFactory::getSession(); $session->set('user', $newUserObject); $db = $this->container->db; // Check to see the the session already exists. $app = \JFactory::getApplication(); $app->checkSession(); // Update the user related fields for the Joomla sessions table. $query = $db->getQuery(true)->update($db->qn('#__session'))->set(array($db->qn('guest') . ' = ' . $db->q($newUserObject->get('guest')), $db->qn('username') . ' = ' . $db->q($newUserObject->get('username')), $db->qn('userid') . ' = ' . (int) $newUserObject->get('id')))->where($db->qn('session_id') . ' = ' . $db->q($session->getId())); $db->setQuery($query); $db->execute(); // Hit the user last visit field $newUserObject->setLastVisit(); } return $this->haveLoggedInAUser; }
private function parseStreamLink($content) { static $dlid = ''; $user = JFactory::getUser(); if (empty($dlid) && !$user->guest) { $dlid = \Akeeba\ReleaseSystem\Site\Helper\Filter::myDownloadID(); } $url = 'index.php?option=com_ars&view=update&task=Item&format=raw&id=' . (int) $content; if (!empty($dlid)) { $url .= '&dlid=' . $dlid; } $link = JRoute::_($url, false); return $link; }
/** * Downloads the latest version of a software given its update stream ID * * @throws \RuntimeException */ public function download() { $id = $this->input->getInt('id', 0); if ($id == 0) { // Do we have a menu item parameter? /** @var \JApplicationSite $app */ $app = JFactory::getApplication(); $params = $app->getParams('com_ars'); $id = $params->get('streamid', 0); } /** @var UpdateModel $model */ $model = $this->getModel(); $view = $this->getView(); $view->items = $model->getItems($id); $view->published = $model->getPublished($id); $items = $view->items; if (!$view->published) { // This stream isn't published. Go away! GO. AWAY. die; } if (empty($items)) { // No items to display. What are you doing here? Are you lost? Go away! die; } // Get the download item $downloadItem = array_shift($items); // Get the download model /** @var Download $downloadModel */ $downloadModel = $this->container->factory->model('Download')->tmpInstance(); /** @var Items $item */ $item = $this->container->factory->model('Items')->tmpInstance(); try { if ($downloadItem->item_id <= 0) { throw new \Exception('No item'); } $item->find($downloadItem->item_id); } catch (\Exception $e) { throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } // Log in a user if I have to $downloadModel->loginUser(); // Get the log table /** @var Logs $log */ $log = $this->container->factory->model('Logs')->tmpInstance(); if (!Filter::filterItem($item)) { $log->create(['authorized' => 0, 'item_id' => $downloadItem->item_id]); throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } $item->save(['hits' => ++$item->hits]); $log->create(['item_id' => $downloadItem->item_id, 'authorized' => 1]); $downloadModel->doDownload($item); JFactory::getApplication()->close(); }
public function download() { $id = $this->input->getInt('id', null); // Get the page parameters $app = \JFactory::getApplication(); $params = \JComponentHelper::getParams('com_ars'); /** @var Download $model */ $model = $this->getModel('Download'); // Log in a user if I have to $model->loginUser(); // Get the log table /** @var Logs $log */ $log = $this->getModel('Logs'); /** @var Items $item */ $item = $this->getModel(); // The item must exist and be accessible try { // Try to find the item $item->find($id); // Make sure subscription level filtering allows access if (!Filter::filterItem($item, false, $this->container->platform->getUser()->getAuthorisedViewLevels())) { throw new \Exception('Filtering failed'); } } catch (\Exception $e) { $this->logFailedDownloadAttempt($item->id ? $id : 0); $noAccessURL = \JComponentHelper::getParams('com_ars')->get('no_access_url', ''); if ($item->id && $item->redirect_unauth && $item->show_unauth_links) { $noAccessURL = $item->redirect_unauth; } if (!empty($noAccessURL)) { \JFactory::getApplication()->redirect($noAccessURL); return; } throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } try { // The release must be accessible $release = $item->release; // Make sure subscription level filtering allows access if (!$release->id || !Filter::filterItem($release, false, $this->container->platform->getUser()->getAuthorisedViewLevels())) { throw new \Exception('Filtering failed'); } } catch (\Exception $e) { $this->logFailedDownloadAttempt($id); $noAccessURL = \JComponentHelper::getParams('com_ars')->get('no_access_url', ''); if (isset($release) && $release->id && $release->redirect_unauth && $release->show_unauth_links) { $noAccessURL = $release->redirect_unauth; } if (!empty($noAccessURL)) { \JFactory::getApplication()->redirect($noAccessURL); return; } throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } // The category must be accessible try { $category = $release->category; // Make sure subscription level filtering allows access if (!$category->id || !Filter::filterItem($category, false, $this->container->platform->getUser()->getAuthorisedViewLevels())) { throw new \Exception('Filtering failed'); } } catch (\Exception $e) { $this->logFailedDownloadAttempt($id); $noAccessURL = \JComponentHelper::getParams('com_ars')->get('no_access_url', ''); if (isset($category) && $category->id && $category->redirect_unauth && $category->show_unauth_links) { $noAccessURL = $category->redirect_unauth; } if (!empty($noAccessURL)) { \JFactory::getApplication()->redirect($noAccessURL); return; } throw new \RuntimeException(\JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } // Hit the item $item->save(['hits' => ++$item->hits]); // Log the download $log->create(array('item_id' => $id, 'authorized' => 1)); // Download the item $model->doDownload($item); $app->close(); }