public function display($tpl = null)
 {
     global $option;
     $app = JFactory::getApplication();
     if (!isset($this->flt)) {
         $this->flt = new stdClass();
     }
     $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int');
     $limitstart = $app->getUserStateFromRequest('osdownloads.request.limitstart', 'limitstart', 0, 'int');
     $this->flt->search = $app->getUserStateFromRequest('osdownloads.email.request.search', 'search', "");
     $this->flt->cate_id = $app->getUserStateFromRequest('osdownloads.email.request.cate_id', 'cate_id');
     $filter_order = $app->getUserStateFromRequest("osdownloads.email.filter_order", 'filter_order', 'email.id', 'cmd');
     $filter_order_Dir = $app->getUserStateFromRequest("osdownloads.email.filter_order_Dir", 'filter_order_Dir', '', 'word');
     $filter_confirmed = $app->getUserStateFromRequest("osdownloads.email.filter_confirmed", 'filter_confirmed', '-1', 'int');
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select("email.*, document.name AS doc_name, cate.title AS cate_name");
     $query->from("#__osdownloads_emails email");
     $query->join("LEFT", "#__osdownloads_documents document ON (email.document_id = document.id)");
     $query->join("LEFT", "#__categories cate ON (cate.id = document.cate_id)");
     if ($this->flt->search) {
         $query->where("email.email LIKE '%{$this->flt->search}%' OR document.name LIKE '%{$this->flt->search}%'");
     }
     if ($this->flt->cate_id) {
         $query->where("cate.id = {$this->flt->cate_id}");
     }
     if ($filter_confirmed >= 0) {
         $query->where('confirmed = ' . $db->quote($filter_confirmed));
     }
     $query->order(" {$filter_order}  {$filter_order_Dir}");
     $db->setQuery($query);
     $db->query();
     $total = $db->getNumRows();
     jimport('joomla.html.pagination');
     $pagination = new JPagination($total, $limitstart, $limit);
     $db->setQuery($query, $pagination->limitstart, $pagination->limit);
     $items = (array) $db->loadObjectList();
     $lists = array();
     $lists['order_Dir'] = $filter_order_Dir;
     $lists['order'] = $filter_order;
     $lists['filter_confirmed'] = $filter_confirmed;
     // Load the extension
     $extension = Alledia\Framework\Factory::getExtension('OSDownloads', 'component');
     $extension->loadLibrary();
     $this->assignRef('lists', $lists);
     $this->assignRef("items", $items);
     $this->assignRef("pagination", $pagination);
     $this->assignRef("extension", $extension);
     $this->assign("isPro", $extension->isPro());
     $this->addToolbar();
     parent::display($tpl);
 }
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $model = $this->getModel();
     $db = JFactory::getDBO();
     $pagination = $model->getPagination();
     $query = $model->getItemsQuery();
     $db->setQuery($query, $pagination->limitstart, $pagination->limit);
     $items = $db->loadObjectList();
     $filterOrder = $app->getUserStateFromRequest("com_osdownloads.document.filter_order", 'filter_order', 'doc.id', '');
     $filterOrderDir = $app->getUserStateFromRequest("com_osdownloads.document.filter_order_Dir", 'filter_order_Dir', 'asc', 'word');
     $lists = array();
     $lists['order_Dir'] = $filterOrderDir;
     $lists['order'] = $filterOrder;
     $filter = new stdClass();
     $filter->search = $app->getUserStateFromRequest('com_osdownloads.document.request.search', 'search');
     $filter->categoryId = $app->getUserStateFromRequest('com_osdownloads.document.request.cate_id', 'flt_cate_id');
     // Load the extension
     $extension = Alledia\Framework\Factory::getExtension('OSDownloads', 'component');
     $extension->loadLibrary();
     // jQuery warning for J2.5 users
     if (version_compare(JVERSION, '3.0', 'lt')) {
         $params = JComponentHelper::getParams('com_osdownloads');
         if (!(bool) $params->get('load_jquery', 0)) {
             $app->enqueueMessage(JText::_('COM_OSDOWNLOADS_JQUERY_REQUIRED_WARNING'), 'warning');
         }
     }
     // Add the agreementLink property
     if (!empty($items)) {
         foreach ($items as &$item) {
             $item->agreementLink = '';
             if ((bool) $item->require_agree) {
                 $item->agreementLink = JRoute::_('index.php?option=com_content&view=article&id=' . (int) $item->agreement_article_id);
             }
         }
     }
     $this->assignRef('lists', $lists);
     $this->assignRef("items", $items);
     $this->assignRef("filter", $filter);
     $this->assignRef("pagination", $pagination);
     $this->assignRef("extension", $extension);
     $this->addToolbar();
     parent::display($tpl);
 }
jimport('joomla.utilities.utility');
jimport('joomla.event.dispatcher');
jimport('joomla.utilities.arrayhelper');
// Bootstrap the CMS libraries.
if (!defined('JPATH_PLATFORM')) {
    define('JPATH_PLATFORM', JPATH_BASE . '/libraries');
}
if (!defined('JDEBUG')) {
    define('JDEBUG', false);
}
require_once JPATH_LIBRARIES . '/cms.php';
// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';
// Instantiate some needed objects
JFactory::getApplication('site');
// Bootstrap OSDownloads
define('OSDOWNLOADS_SRC', realpath(__DIR__ . '/../../src'));
if (!is_dir(OSDOWNLOADS_SRC)) {
    throw new Exception('Could not find the OSDownloads folder: ' . OSDOWNLOADS_SRC);
}
// Specialized initialisation for OSDownloads testing
define('OSDOWNLOADS_LOADED', 1);
define('OSDOWNLOADS_ADMIN', OSDOWNLOADS_SRC . '/admin');
define('OSDOWNLOADS_SITE', OSDOWNLOADS_SRC . '/site');
define('OSDOWNLOADS_MEDIA', OSDOWNLOADS_SRC . '/media');
define('OSDOWNLOADS_LIBRARY', OSDOWNLOADS_ADMIN . '/library');
// Setup OSDownloads
require_once OSDOWNLOADS_ADMIN . '/include.php';
// Load the component libraries
$extension = Alledia\Framework\Factory::getExtension('OSDownloads', 'component');
$extension->loadLibrary();
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $params = clone $app->getParams('com_osdownloads');
     $categoryIDs = (array) $params->get("category_id");
     $includeChildFiles = (bool) $params->get('include_child_files', 0);
     $showChildCategories = (bool) $params->get('show_child_categories', 1);
     // Load the extension
     $extension = Alledia\Framework\Factory::getExtension('OSDownloads', 'component');
     $extension->loadLibrary();
     $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int');
     $limitstart = $app->getUserStateFromRequest('osdownloads.request.limitstart', 'limitstart', 0, 'int');
     // Paths
     $paths = array();
     $id = JRequest::getVar("id", null, 'default', 'int');
     if (empty($id)) {
         if (count($categoryIDs) == 1) {
             $id = $categoryIDs[0];
         }
     }
     if (!empty($id)) {
         $this->buildPath($paths, $id);
         $categoryIDs = (array) $id;
     }
     $categoryIDsStr = implode(',', $categoryIDs);
     $model = JModelLegacy::getInstance('OSDownloadsModelItem');
     $query = $model->getItemQuery();
     $query->select('cat.access as cat_access');
     if ($includeChildFiles) {
         $query->where("(cate_id IN ({$categoryIDsStr}) OR cat.parent_id IN ({$categoryIDsStr}))");
     } else {
         $query->where("cate_id IN ({$categoryIDsStr})");
     }
     $query->order('doc.ordering');
     $db->setQuery($query);
     // Pagination
     $db->setQuery($query);
     $db->query();
     $total = $db->getNumRows();
     jimport('joomla.html.pagination');
     $pagination = new JPagination($total, $limitstart, $limit);
     // Items
     $db->setQuery($query, $pagination->limitstart, $pagination->limit);
     $items = $db->loadObjectList();
     $user = JFactory::getUser();
     $groups = $user->getAuthorisedViewLevels();
     if (!isset($items) || count($items) && !in_array($items[0]->cat_access, $groups)) {
         JError::raiseWarning(404, JText::_("COM_OSDOWNLOADS_THIS_CATEGORY_ISNT_AVAILABLE"));
         return;
     }
     // Categories
     $extraWhere = '';
     if ($showChildCategories) {
         $extraWhere = " OR c.parent_id IN ({$categoryIDsStr}) ";
     }
     $groupsStr = implode(',', $groups);
     $query = "SELECT *\n                  FROM `#__categories` AS c\n                  WHERE extension='com_osdownloads'\n                    AND published = 1\n                    AND (id IN ({$categoryIDsStr})\n                        {$extraWhere}\n                    )\n                  ORDER BY c.lft ASC";
     $db->setQuery($query);
     $categories = $db->loadObjectList();
     // Category filter
     $showCategoryFilter = $params->get('show_category_filter', false);
     $this->buildBreadcrumbs($paths);
     $this->assignRef("categories", $categories);
     $this->assignRef("showCategoryFilter", $showCategoryFilter);
     $this->assignRef("items", $items);
     $this->assignRef("paths", $paths);
     $this->assignRef("pagination", $pagination);
     $this->assign("isPro", $extension->isPro());
     parent::display($tpl);
 }