예제 #1
0
 /**
  * Tests the JAccess::getAuthorisedViewLevels method.
  *
  * @return  void
  *
  * @since   11.1
  * @covers  JAccess::getAuthorisedViewLevels
  */
 public function testGetAuthorisedViewLevels()
 {
     usleep(100);
     $access = new JAccess();
     $array1 = array(0 => 1, 1 => 3);
     $this->assertThat($access->getAuthorisedViewLevels(42), $this->equalTo($array1), 'Line:' . __LINE__ . ' Super user gets Public, Special (levels 1,3)');
     $array2 = array(0 => 1);
     $this->assertThat($access->getAuthorisedViewLevels(50), $this->equalTo($array2), 'Line:' . __LINE__ . ' User 50 gets Public (level 1)');
     $array3 = array(0 => 1, 1 => 4);
     $this->assertThat($access->getAuthorisedViewLevels(99), $this->equalTo($array3), 'Line:' . __LINE__ . ' User 99 gets Level 4');
 }
예제 #2
0
 /**
  * Tests the JAccess::getAuthorisedViewLevels method.
  *
  * @return  void
  *
  * @since   11.1
  */
 public function testGetAuthorisedViewLevels()
 {
     if (defined('DB_NOT_AVAILABLE')) {
         $this->markTestSkipped('The database is not available');
     }
     $access = new JAccess();
     $array1 = array(0 => 1, 1 => 3);
     $this->assertThat($access->getAuthorisedViewLevels(42), $this->equalTo($array1), 'Line:' . __LINE__ . ' Super user gets Public, Special (levels 1,3)');
     $array2 = array(0 => 1);
     $this->assertThat($access->getAuthorisedViewLevels(50), $this->equalTo($array2), 'Line:' . __LINE__ . ' User 50 gets Public (level 1)');
     $array3 = array(0 => 1, 1 => 4);
     $this->assertThat($access->getAuthorisedViewLevels(99), $this->equalTo($array3), 'Line:' . __LINE__ . ' User 99 gets Level 4');
 }
예제 #3
0
 /**
  * Tests the JAccess::getAuthorisedViewLevels method.
  *
  * @return  void
  *
  * @since   11.1
  */
 public function testGetAuthorisedViewLevels()
 {
     // Run the parent::setUp() method here to save time (since we only need to run it once)
     parent::setUp();
     if (defined('DB_NOT_AVAILABLE')) {
         $this->markTestSkipped('The database is not available');
     }
     $access = new JAccess();
     $array1 = array(0 => 1, 1 => 3);
     $this->assertThat($access->getAuthorisedViewLevels(42), $this->equalTo($array1), 'Line:' . __LINE__ . ' Super user gets Public, Special (levels 1,3)');
     $array2 = array(0 => 1);
     $this->assertThat($access->getAuthorisedViewLevels(50), $this->equalTo($array2), 'Line:' . __LINE__ . ' User 50 gets Public (level 1)');
     $array3 = array(0 => 1, 1 => 4);
     $this->assertThat($access->getAuthorisedViewLevels(99), $this->equalTo($array3), 'Line:' . __LINE__ . ' User 99 gets Level 4');
 }
예제 #4
0
 public static function getList(&$params)
 {
     // Get the dbo
     $db = JFactory::getDbo();
     // Get an instance of the generic articles model
     $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams();
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('count', 10));
     $model->setState('filter.published', 1);
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     $model->setState('filter.category_id', $params->get('catid', array(), 'title'));
     // Ordering
     $model->setState('list.ordering', $params->get('article_ordering', 'a.ordering'));
     $model->setState('list.direction', $params->get('article_ordering_direction', 'ASC'));
     $items = $model->getItems();
     return $items;
 }
예제 #5
0
 /**
  * Creates the page's display
  *
  * @since 1.0
  */
 function display($tpl = null)
 {
     $user = JFactory::getUser();
     $aid = JAccess::getAuthorisedViewLevels($user->id);
     // Get model
     $model = $this->getModel();
     // Get category and set category parameters as VIEW's parameters (category parameters are merged with component/page/author parameters already)
     $category = $this->get('Category');
     $params = $category->parameters;
     // Get various data from the model
     $items = $this->get('Data');
     // Get field values
     $_vars = null;
     FlexicontentFields::getItemFields($items, $_vars, $_view = 'category', $aid);
     // Zero unneeded search index text
     foreach ($items as $item) {
         $item->search_index = '';
     }
     // Use &test=1 to test / preview item data of first item
     if (JRequest::getCmd('test', 0)) {
         $item = reset($items);
         echo "<pre>";
         print_r($item);
         exit;
     }
     // Output items in JSON FORMAT
     echo @json_encode($items);
 }
예제 #6
0
파일: html.php 프로젝트: ForAEdesWeb/AEW27
 /**
  * Prepare data hook.
  *
  * @return  void
  */
 protected function prepareData()
 {
     require_once JPATH_SITE . '/components/com_content/helpers/route.php';
     $app = JFactory::getApplication();
     $data = $this->getData();
     $data->params = JComponentHelper::getParams('com_content');
     $data->user = $user = JUser::getInstance($app->input->getUsername('username'));
     JModelLegacy::addIncludePath(\Windwalker\Helper\PathHelper::getSite('com_content') . '/models');
     $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     $model->setState('params', $data->params);
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.published', 1);
     $model->setState('filter.access', $access);
     $model->setState('filter.author_id', (int) $user->id);
     $model->setState('list.ordering', 'a.created');
     $model->setState('list.direction', 'DESC');
     $model->setState('list.limit', 10);
     $data->items = $model->getItems();
     $data->pagination = $model->getPagination();
     foreach ($data->items as &$item) {
         $item->slug = $item->id . ':' . $item->alias;
         $item->catslug = $item->catid . ':' . $item->category_alias;
         $item->params = $data->params;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the article
             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language));
         } else {
             $item->link = JRoute::_('index.php?option=com_users&view=login');
         }
         $item->parent_slug = $item->parent_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id;
         // No link for ROOT category
         if ($item->parent_alias == 'root') {
             $item->parent_slug = null;
         }
         $item->event = new stdClass();
         $dispatcher = JEventDispatcher::getInstance();
         // Old plugins: Ensure that text property is available
         if (!isset($item->text)) {
             $item->text = $item->introtext;
         }
         $app->input->set('option', 'com_content');
         $app->input->set('view', 'category');
         $app->input->set('layout', 'blog');
         JPluginHelper::importPlugin('content');
         $dispatcher->trigger('onContentPrepare', array('com_content.category', &$item, &$item->params, 0));
         // Old plugins: Use processed text as introtext
         $item->introtext = $item->text;
         $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.category', &$item, &$item->params, 0));
         $item->event->afterDisplayTitle = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.category', &$item, &$item->params, 0));
         $item->event->beforeDisplayContent = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.category', &$item, &$item->params, 0));
         $item->event->afterDisplayContent = trim(implode("\n", $results));
         $app->input->set('option', 'com_userxtd');
         $app->input->set('view', 'content');
         $app->input->set('layout', 'default');
     }
     $this->setTitle();
 }
 /**
  * Tests the JAccess::getAuthorisedViewLevels method.
  *
  * @return  void
  *
  * @since   11.1
  */
 public function testGetAuthorisedViewLevels()
 {
     usleep(100);
     $access = new JAccess();
     $array1 = array(0 => 1, 1 => 1, 2 => 2, 3 => 3);
     $this->assertThat($access->getAuthorisedViewLevels(42), $this->equalTo($array1), 'Line:' . __LINE__ . ' Super user gets Public (levels 1)');
 }
예제 #8
0
 public static function getList(&$params)
 {
     // Get the dbo
     $db = JFactory::getDbo();
     // Get an instance of the generic tracks model
     $model = JModelLegacy::getInstance('Sections', 'PlayjoomModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams();
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('count', 5));
     // Access filter
     $access = !JComponentHelper::getParams('com_playjoom')->get('show_noauth', 1);
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $ordering = 'a.access_datetime';
     $dir = 'DESC';
     $model->setState('list.ordering', $ordering);
     $model->setState('list.direction', $dir);
     $items = $model->getItems();
     //create item link
     foreach ($items as &$item) {
         //Check for Trackcontrol
         if (JPluginHelper::isEnabled('playjoom', 'trackcontrol') == false) {
             $item->link = null;
         } else {
             $item->link = JRoute::_('index.php?option=com_playjoom&view=broadcast&id=' . $item->id);
         }
         $item->accessinfo = modLastPlayedHelper::GetTimeInfoList($item->access_datetime, $params, 'access');
     }
     return $items;
 }
 /**
  * Get a list of the latest articles from the article model
  *
  * @param   \Joomla\Registry\Registry  &$params  object holding the models parameters
  *
  * @return  mixed
  *
  * @since 1.6
  */
 public static function getList(&$params)
 {
     // Get an instance of the generic articles model
     $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams();
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('count', 5));
     $model->setState('filter.published', 1);
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     $model->setState('filter.category_id', $params->get('catid', array()));
     // Filter by language
     $model->setState('filter.language', $app->getLanguageFilter());
     // Set ordering
     $ordering = $params->get('ordering', 'a.publish_up');
     $model->setState('list.ordering', $ordering);
     if (trim($ordering) == 'rand()') {
         $model->setState('list.ordering', JFactory::getDbo()->getQuery(true)->Rand());
     } else {
         $direction = $params->get('direction', 1) ? 'DESC' : 'ASC';
         $model->setState('list.direction', $direction);
         $model->setState('list.ordering', $ordering);
     }
     // Retrieve Content
     $items = $model->getItems();
     foreach ($items as &$item) {
         $item->readmore = strlen(trim($item->fulltext));
         $item->slug = $item->id . ':' . $item->alias;
         $item->catslug = $item->catid . ':' . $item->category_alias;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the article
             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language));
             $item->linkText = JText::_('MOD_ARTICLES_NEWS_READMORE');
         } else {
             $item->link = new JUri(JRoute::_('index.php?option=com_users&view=login', false));
             $item->link->setVar('return', base64_encode(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language)));
             $item->linkText = JText::_('MOD_ARTICLES_NEWS_READMORE_REGISTER');
         }
         $item->introtext = JHtml::_('content.prepare', $item->introtext, '', 'mod_articles_news.content');
         if (!$params->get('image')) {
             $item->introtext = preg_replace('/<img[^>]*>/', '', $item->introtext);
         }
         $results = $app->triggerEvent('onContentAfterTitle', array('com_content.article', &$item, &$params, 1));
         $item->afterDisplayTitle = trim(implode("\n", $results));
         $results = $app->triggerEvent('onContentBeforeDisplay', array('com_content.article', &$item, &$params, 1));
         $item->beforeDisplayContent = trim(implode("\n", $results));
         $results = $app->triggerEvent('onContentAfterDisplay', array('com_content.article', &$item, &$params, 1));
         $item->afterDisplayContent = trim(implode("\n", $results));
     }
     return $items;
 }
예제 #10
0
 /**
  * Returns the roles of the user
  *
  * @return int The role id
  */
 public function getRoles()
 {
     $data = $this->getData();
     $roles = KObjectConfig::unbox($data->roles);
     if (empty($roles)) {
         $this->getSession()->set('user.roles', JAccess::getAuthorisedViewLevels($this->getId()));
     }
     return parent::getRoles();
 }
예제 #11
0
 public static function getList(&$params)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     // Get an instance of the generic articles model
     $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     // Set application parameters in model
     $appParams = JFactory::getApplication()->getParams();
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('count', 5));
     $model->setState('filter.published', 1);
     $model->setState('list.select', 'a.fulltext, a.id, a.title, a.alias, a.title_alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured,' . ' LENGTH(a.fulltext) AS readmore');
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     $model->setState('filter.category_id', $params->get('catid', array()));
     // Filter by language
     $model->setState('filter.language', $app->getLanguageFilter());
     // Set ordering
     $ordering = $params->get('ordering', 'a.publish_up');
     $model->setState('list.ordering', $ordering);
     if (trim($ordering) == 'rand()') {
         $model->setState('list.direction', '');
     } else {
         $model->setState('list.direction', 'DESC');
     }
     //	Retrieve Content
     $items = $model->getItems();
     foreach ($items as &$item) {
         $item->readmore = trim($item->fulltext) != '';
         $item->slug = $item->id . ':' . $item->alias;
         $item->catslug = $item->catid . ':' . $item->category_alias;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the article
             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid));
             $item->linkText = JText::_('MOD_ARTICLES_NEWS_READMORE');
         } else {
             $item->link = JRoute::_('index.php?option=com_user&view=login');
             $item->linkText = JText::_('MOD_ARTICLES_NEWS_READMORE_REGISTER');
         }
         $item->introtext = JHtml::_('content.prepare', $item->introtext);
         //new
         if (!$params->get('image')) {
             $item->introtext = preg_replace('/<img[^>]*>/', '', $item->introtext);
         }
         $results = $app->triggerEvent('onContentAfterDisplay', array('com_content.article', &$item, &$params, 1));
         $item->afterDisplayTitle = trim(implode("\n", $results));
         $results = $app->triggerEvent('onContentBeforeDisplay', array('com_content.article', &$item, &$params, 1));
         $item->beforeDisplayContent = trim(implode("\n", $results));
     }
     return $items;
 }
예제 #12
0
파일: helper.php 프로젝트: madcsaba/li-de
 static function getData($params)
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $result = array();
     $use_all_items = $params->get('use_all_items', 0);
     $app = JFactory::getApplication();
     $language = $app->getLanguageFilter();
     // Access
     $access = !JComponentHelper::getParams('com_jdownloads')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $groups = implode(',', $authorised);
     // get at first the categories
     $query->select('id')->from('#__jdownloads_categories');
     $query->where('published = 1');
     if (!$use_all_items) {
         $query->where('access IN (' . $groups . ')');
     }
     $query->where("id > '1'");
     // remove 'root' cat
     $db->setQuery($query);
     $cats = $db->loadColumn();
     $result['cats'] = (int) count($cats);
     $cats_id_list = implode(',', $cats);
     // get the Downloads
     $query->clear();
     $query->select('COUNT(file_id)')->from('#__jdownloads_files');
     $query->where('published = 1');
     if (!$use_all_items) {
         $query->where('access IN (' . $groups . ')');
     }
     $query->where('cat_id = 1 OR cat_id IN (' . $cats_id_list . ')');
     $db->setQuery($query);
     $result['files'] = (int) $db->loadResult();
     // get the Downloads
     $query->clear();
     $query->select('SUM(downloads)')->from('#__jdownloads_files');
     $query->where('published = 1');
     if (!$use_all_items) {
         $query->where('access IN (' . $groups . ')');
     }
     $query->where('cat_id = 1 OR cat_id IN (' . $cats_id_list . ')');
     $db->setQuery($query);
     $result['hits'] = (int) $db->loadResult();
     $query->clear();
     $query->select('SUM(views)')->from('#__jdownloads_files');
     $query->where('published = 1');
     if (!$use_all_items) {
         $query->where('access IN (' . $groups . ')');
     }
     $query->where('cat_id = 1 OR cat_id IN (' . $cats_id_list . ')');
     $db->setQuery($query);
     $result['views'] = (int) $db->loadResult();
     return $result;
 }
예제 #13
0
파일: helper.php 프로젝트: madcsaba/li-de
 static function getList($params)
 {
     $db = JFactory::getDbo();
     // Get an instance of the generic downloads model
     $model = JModelLegacy::getInstance('categories', 'jdownloadsModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams('com_jdownloads');
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     //$model->setState('list.limit', (int) $params->get('sum_view', 5));
     $model->setState('filter.published', 1);
     // Access filter
     $access = !JComponentHelper::getParams('com_jdownloads')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     // Category display decisions
     $catid = $params->get('catid');
     $catoption = intval($params->get('catoption', 1));
     if ($catid) {
         $catid = implode(',', $catid);
         if ($catoption == 1) {
             $catid = '1,' . $catid;
         }
         $cat_condition = 'c.id ' . ($catoption ? ' IN ' : ' NOT IN ') . '(' . $catid . ') ';
         $model->setState('filter.category_id', $cat_condition);
     } else {
         $model->setState('filter.category_id', '');
     }
     $level = intval($params->get('maxlevel', 0));
     $model->setState('filter.level', $level);
     // Filter by language
     $model->setState('filter.language', $app->getLanguageFilter());
     // Set sort ordering
     $ordering = 'c.lft';
     $dir = 'ASC';
     $model->setState('list.ordering', $ordering);
     $model->setState('list.direction', $dir);
     $items = $model->getItems(true);
     // with childrens
     foreach ($items as &$item) {
         $item->catslug = $item->id . ':' . $item->alias;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the download
             $item->link = '-';
         } else {
             $item->link = JRoute::_('index.php?option=com_users&view=login');
         }
     }
     return $items;
 }
예제 #14
0
 public static function getContentList(&$params)
 {
     // Get an instance of the generic articles model
     $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams();
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('count', 5));
     $model->setState('filter.published', 1);
     $model->setState('filter.featured', $params->get('featured', "show"));
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     $model->setState('filter.category_id', $params->get('categoryId', array()));
     // Filter by language
     $model->setState('filter.language', $app->getLanguageFilter());
     // Ordering
     $ordering = $params->get('ordering', 'a.ordering');
     $model->setState('list.ordering', $ordering);
     if (trim($ordering) == 'rand()') {
         $model->setState('list.direction', '');
     } else {
         $model->setState('list.direction', $params->get('sort_order', "ASC"));
     }
     $items = $model->getItems();
     foreach ($items as &$item) {
         $item->content = $params->get('show_img') == '0' || $params->get('reformat_content') == '1' ? modKlixoArticlesSliderHelper::stripTags($item->introtext) : $item->introtext;
         $item->slug = $item->id . ':' . $item->alias;
         $item->catslug = $item->catid . ':' . $item->category_alias;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the article
             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
         } else {
             $item->link = JRoute::_('index.php?option=com_users&view=login');
         }
         if (!isset($item->sub_title)) {
             $item->sub_title = modKlixoArticlesSliderHelper::cutStr($item->title, $params->get('limittitle', 25));
         }
         if (!isset($item->sub_content)) {
             if ($params->get('reformat_content') == 1) {
                 $item->sub_content = modKlixoArticlesSliderHelper::cutStr($item->content, $params->get('limit_description'));
             } else {
                 $item->sub_content = $item->content;
             }
         }
     }
     return $items;
 }
예제 #15
0
파일: helper.php 프로젝트: joebushi/joomla
 public static function getList(&$params)
 {
     // Get an instance of the generic articles model
     $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     // Set application parameters in model
     $appParams = JFactory::getApplication()->getParams();
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('count', 5));
     $model->setState('filter.published', 1);
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     if ($catid = $params->get('catid')) {
         $model->setState('filter.category_id', $catid);
     }
     // User filter
     $userId = JFactory::getUser()->get('id');
     switch ($params->get('user_id')) {
         case 'by_me':
             $model->setState('filter.author_id', $userId);
             break;
         case 'not_me':
             $model->setState('filter.author_id', $userId);
             $model->setState('filter.author_id.include', false);
             break;
     }
     // Set ordering
     $order_map = array('m_dsc' => 'a.modified DESC, a.created', 'c_dsc' => 'a.created');
     $ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.created');
     $dir = 'DESC';
     $model->setState('list.ordering', $ordering);
     $model->setState('list.direction', $dir);
     $items = $model->getItems();
     foreach ($items as &$item) {
         $item->slug = $item->id . ':' . $item->alias;
         $item->catslug = $item->catid . ':' . $item->category_alias;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the article
             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
         } else {
             $item->link = JRoute::_('index.php?option=com_user&view=login');
         }
         $item->introtext = JHtml::_('content.prepare', $item->introtext);
     }
     return $items;
 }
예제 #16
0
    static function getList($params)
    {
        // Get an instance of the generic articles model
        $model = JModel::getInstance('Category', 'WeblinksModel', array('ignore_request' => true));
        // Set application parameters in model
        $app = JFactory::getApplication();
        $appParams = $app->getParams();
        $model->setState('params', $appParams);
        // Set the filters based on the module params
        $model->setState('list.start', 0);
        $model->setState('list.limit', (int) $params->get('count', 5));
        $model->setState('filter.state', 1);
        $model->setState('filter.archived', 0);
        $model->setState('filter.approved', 1);
        // Access filter
        $access = !JComponentHelper::getParams('com_weblinks')->get('show_noauth');
        $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
        $model->setState('filter.access', $access);
        $ordering = $params->get('ordering', 'ordering');
        $model->setState('list.ordering', $ordering == 'order' ? 'ordering' : $ordering);
        $model->setState('list.direction', $params->get('direction', 'asc'));
        $catid = (int) $params->get('catid', 0);
        $model->setState('category.id', $catid);
        $model->setState('list.select', 'a.*, c.published AS c_published,
		CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,
		CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as catslug,
		DATE_FORMAT(a.date, "%Y-%m-%d") AS created');
        $model->setState('filter.c.published', 1);
        // Filter by language
        $model->setState('filter.language', $app->getLanguageFilter());
        $items = $model->getItems();
        /*
         * This was in the previous code before we changed over to using the
         * weblinkscategory model but I don't see any models using checked_out filters
         * in their getListQuery() methods so I believe we should not be adding this now
         */
        /*
        $query->where('(a.checked_out = 0 OR a.checked_out = '.$user->id.')');
        */
        for ($i = 0, $count = count($items); $i < $count; $i++) {
            $item =& $items[$i];
            if ($item->params->get('count_clicks', $params->get('count_clicks')) == 1) {
                $item->link = JRoute::_('index.php?option=com_weblinks&task=weblink.go&catid=' . $item->catslug . '&id=' . $item->slug);
            } else {
                $item->link = $item->url;
            }
        }
        return $items;
    }
예제 #17
0
 /**
  * Get the files the user has access to, filtering or not by the externalRef.
  *
  * @param  int    $userId
  * @param  string $externalRef
  * @return array
  */
 public static function getAuthorizedFilesForUser($userId, $externalRef = '')
 {
     // Flush any JAccess cache
     JAccess::clearStatics();
     $authorizedViewLevels = JAccess::getAuthorisedViewLevels($userId);
     $authorizedViewLevels = implode(',', $authorizedViewLevels);
     // Get the files the user has access to and external ref has the suffix .pro
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select('*')->from('#__osdownloads_documents')->where("access IN ({$authorizedViewLevels})");
     if ($externalRef !== '') {
         $query->where('external_ref LIKE "' . $externalRef . '"');
     }
     $db->setQuery($query);
     return $db->loadObjectList();
 }
예제 #18
0
 /**
  * Fetch the user for the given user identifier from the backend
  *
  * @param string $identifier A unique user identifier, (i.e a username or email address)
  * @return KUserInterface|null Returns a UserInterface object or NULL if the user could not be found.
  */
 public function fetch($identifier)
 {
     $table = JUser::getTable();
     if ($table->load($identifier)) {
         $user = JUser::getInstance(0);
         $user->setProperties($table->getProperties());
         $params = new JRegistry();
         $params->loadString($table->params);
         $user->setParameters($params);
         $data = array('id' => $user->id, 'email' => $user->email, 'name' => $user->name, 'username' => $user->username, 'password' => $user->password, 'salt' => '', 'groups' => JAccess::getGroupsByUser($user->id), 'roles' => JAccess::getAuthorisedViewLevels($user->id), 'authentic' => !$user->guest, 'enabled' => !$user->block, 'expired' => (bool) $user->activation, 'attributes' => $user->getParameters()->toArray());
         $user = $this->create($data);
     } else {
         $user = null;
     }
     return $user;
 }
예제 #19
0
파일: helper.php 프로젝트: petroborys/sp
 public static function getList(&$params)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDbo();
     $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     $appParams = JFactory::getApplication()->getParams();
     $model->setState('params', $appParams);
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('articles_num', 3));
     $model->setState('filter.published', 1);
     $model->setState('list.select', 'a.fulltext, a.id, a.title, a.alias, a.introtext, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by, a.publish_up, a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured');
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     $model->setState('filter.category_id', $params->get('category_id', array()));
     $model->setState('filter.language', $app->getLanguageFilter());
     $ordering = $params->get('ordering', 'a.publish_up');
     $model->setState('list.ordering', $ordering);
     if (trim($ordering) == 'rand()') {
         $model->setState('list.direction', '');
     } else {
         $model->setState('list.direction', 'DESC');
     }
     $items = $model->getItems();
     foreach ($items as &$item) {
         $item->readmore = strlen(trim($item->fulltext));
         $item->slug = $item->id . ':' . $item->alias;
         $item->catslug = $item->catid . ':' . $item->category_alias;
         if ($access || in_array($item->access, $authorised)) {
             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid));
             $item->linkText = JText::_('Read more');
         } else {
             $item->link = JRoute::_('index.php?option=com_users&view=login');
             $item->linkText = JText::_('Register to Read More');
         }
         $item->introtext = JHtml::_('content.prepare', $item->introtext, '', 'mod_as_artslider.content');
         if (!$params->get('show_image')) {
             $item->introtext = preg_replace('/<img[^>]*>/', '', $item->introtext);
         }
         $results = $app->triggerEvent('onContentAfterDisplay', array('com_content.article', &$item, &$params, 1));
         $item->afterDisplayTitle = trim(implode("\n", $results));
         $results = $app->triggerEvent('onContentBeforeDisplay', array('com_content.article', &$item, &$params, 1));
         $item->beforeDisplayContent = trim(implode("\n", $results));
     }
     return $items;
 }
예제 #20
0
파일: helper.php 프로젝트: madcsaba/li-de
 static function getList($params)
 {
     $db = JFactory::getDbo();
     // Get an instance of the generic downloads model
     $model = JModelLegacy::getInstance('downloads', 'jdownloadsModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams('com_jdownloads');
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('sum_view', 5));
     $model->setState('filter.published', 1);
     // Access filter
     $access = !JComponentHelper::getParams('com_jdownloads')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     $catid = $params->get('cat_id', array());
     if (empty($catid)) {
         $model->setState('filter.category_id', '');
     } else {
         $model->setState('filter.category_id', $catid);
     }
     // User filter
     $userId = JFactory::getUser()->get('id');
     // Filter by language
     $model->setState('filter.language', $app->getLanguageFilter());
     // Set sort ordering
     $ordering = 'a.date_added';
     $dir = 'DESC';
     $model->setState('list.ordering', $ordering);
     $model->setState('list.direction', $dir);
     $items = $model->getItems();
     foreach ($items as &$item) {
         $item->slug = $item->file_id . ':' . $item->file_alias;
         $item->catslug = $item->cat_id . ':' . $item->category_alias;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the download
             $item->link = '-';
         } else {
             $item->link = JRoute::_('index.php?option=com_users&view=login');
         }
     }
     return $items;
 }
예제 #21
0
 /**
  * Get a list of popular articles from the articles model
  *
  * @param   \Joomla\Registry\Registry  &$params  object holding the models parameters
  *
  * @return mixed
  */
 public static function getList(&$params)
 {
     // Get an instance of the generic articles model
     $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams();
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('count', 5));
     $model->setState('filter.published', 1);
     $model->setState('filter.featured', $params->get('show_front', 1) == 1 ? 'show' : 'hide');
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     $model->setState('filter.category_id', $params->get('catid', array()));
     // Date filter
     $date_filtering = $params->get('date_filtering', 'off');
     if ($date_filtering !== 'off') {
         $model->setState('filter.date_filtering', $date_filtering);
         $model->setState('filter.date_field', $params->get('date_field', 'a.created'));
         $model->setState('filter.start_date_range', $params->get('start_date_range', '1000-01-01 00:00:00'));
         $model->setState('filter.end_date_range', $params->get('end_date_range', '9999-12-31 23:59:59'));
         $model->setState('filter.relative_date', $params->get('relative_date', 30));
     }
     // Filter by language
     $model->setState('filter.language', $app->getLanguageFilter());
     // Ordering
     $model->setState('list.ordering', 'a.hits');
     $model->setState('list.direction', 'DESC');
     $items = $model->getItems();
     foreach ($items as &$item) {
         $item->slug = $item->id . ':' . $item->alias;
         $item->catslug = $item->catid . ':' . $item->category_alias;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the article
             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language));
         } else {
             $item->link = JRoute::_('index.php?option=com_users&view=login');
         }
     }
     return $items;
 }
예제 #22
0
 function getObjectInfo($id, $language = null)
 {
     $db = JFactory::getDBO();
     $article = null;
     $link = null;
     require_once JPATH_ROOT . '/components/com_content/helpers/route.php';
     $query = $db->getQuery(true);
     // Select the required fields from the table.
     $query->select('a.id, a.title, a.created_by, a.access, a.alias, a.catid, a.language');
     $query->from('#__content AS a');
     // Join over the categories.
     $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias');
     $query->join('LEFT', '#__categories AS c ON c.id = a.catid');
     $query->where('a.id = ' . (int) $id);
     $db->setQuery($query);
     $article = $db->loadObject();
     if (!empty($article)) {
         $user = JFactory::getUser();
         $article->slug = $article->alias ? $article->id . ':' . $article->alias : $article->id;
         $article->catslug = $article->category_alias ? $article->catid . ':' . $article->category_alias : $article->catid;
         $authorised = JAccess::getAuthorisedViewLevels($user->get('id'));
         $checkAccess = in_array($article->access, $authorised);
         if ($checkAccess) {
             $link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->language));
         } else {
             $returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->language));
             $menu = JFactory::getApplication()->getMenu();
             $active = $menu->getActive();
             $ItemId = $active->id;
             $link = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $ItemId);
             $uri = new JURI($link);
             $uri->setVar('return', base64_encode($returnURL));
             $link = $uri->toString();
         }
     }
     $info = new JCommentsObjectInfo();
     if (!empty($article)) {
         $info->category_id = $article->catid;
         $info->title = $article->title;
         $info->access = $article->access;
         $info->userid = $article->created_by;
         $info->link = $link;
     }
     return $info;
 }
예제 #23
0
파일: helper.php 프로젝트: quyip8818/joomla
 public static function getList($params)
 {
     // Get the dbo
     $db = JFactory::getDbo();
     // Get an instance of the generic articles model
     $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams();
     $model->setState('params', $appParams);
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) $params->get('count', 5));
     $model->setState('filter.published', 1);
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     $model->setState('filter.category_id', $params->get('catid', array()));
     // User filter
     $userId = JFactory::getUser()->get('id');
     // Filter by language
     $model->setState('filter.language', $app->getLanguageFilter());
     //  Featured switch
     $model->setState('filter.featured', 'show');
     // Set ordering
     $order_map = array('m_dsc' => 'a.modified DESC, a.created', 'mc_dsc' => 'CASE WHEN (a.modified = ' . $db->quote($db->getNullDate()) . ') THEN a.created ELSE a.modified END', 'c_dsc' => 'a.created', 'p_dsc' => 'a.publish_up', 'ordering' => "a.ordering");
     $ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.publish_up');
     $dir = 'DESC';
     $model->setState('list.ordering', $ordering);
     $model->setState('list.direction', $dir);
     $items = $model->getItems();
     foreach ($items as $item) {
         $item->slug = $item->id . ':' . $item->alias;
         $item->catslug = $item->catid . ':' . $item->category_alias;
         if ($access || in_array($item->access, $authorised)) {
             // We know that user has the privilege to view the article
             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
         } else {
             $item->link = JRoute::_('index.php?option=com_users&view=login');
         }
     }
     return $items;
 }
예제 #24
0
 /**
  * Creates the page's display
  *
  * @since 1.0
  */
 function display($tpl = null)
 {
     $user = JFactory::getUser();
     $aid = JAccess::getAuthorisedViewLevels($user->id);
     // Get model
     $model = $this->getModel();
     // Indicate to model that current view IS item form
     $model->isForm = false;
     $cid = $model->_cid ? $model->_cid : $model->get('catid');
     // Get current category id
     // Decide version to load
     $version = JRequest::getVar('version', 0, 'request', 'int');
     // Load specific item version (non-zero), 0 version: is unversioned data, -1 version: is latest version (=default for edit form)
     $preview = JRequest::getVar('preview', 0, 'request', 'int');
     // Preview versioned data FLAG ... if previewing and version is not set then ... we load version -1 (=latest version)
     $version = $preview && !$version ? -1 : $version;
     // Allow iLayout from HTTP request, this will be checked during loading item parameters
     $model->setItemLayout('__request__');
     // Indicate to model to merge menu parameters if menu matches
     $model->mergeMenuParams = true;
     // Try to load existing item, an 404 error will be raised if item is not found. Also value 2 for check_view_access
     // indicates to raise 404 error for ZERO primary key too, instead of creating and returning a new item object
     // Get the item, loading item data and doing parameters merging
     $item = $model->getItem(null, $check_view_access = 2, $no_cache = $version || $preview, $force_version = $version || $preview ? $version : 0);
     // ZERO means unversioned data
     // Get item parameters as VIEW's parameters (item parameters are merged parameters in order: component/category/layout/type/item/menu/access)
     $params =& $item->parameters;
     // Get field values
     $items = array($item);
     $_vars = null;
     FlexicontentFields::getItemFields($items, $_vars, $_view = FLEXI_ITEMVIEW, $aid);
     // Zero unneeded search index text
     foreach ($items as $item) {
         $item->search_index = '';
     }
     $item->search_index = '';
     // Use &test=1 to test / preview item data
     if (JRequest::getCmd('test', 0)) {
         echo "<pre>";
         print_r($item);
         exit;
     }
     // Output item in JSON FORMAT
     echo @json_encode($item);
 }
예제 #25
0
 public static function getPoll($id = null)
 {
     $app = JFactory::getApplication();
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select($db->quoteName(array('sppolls_poll_id', 'title', 'slug', 'polls')));
     $query->from($db->quoteName('#__sppolls_polls'));
     if ($app->getLanguageFilter()) {
         $query->where('language IN (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ')');
     }
     $query->where($db->quoteName('access') . " IN (" . implode(',', $authorised) . ")");
     $query->where($db->quoteName('enabled') . ' = ' . $db->quote(1));
     if ($id) {
         $query->where($db->quoteName('sppolls_poll_id') . " = " . $db->quote($id));
     }
     $query->order('created_on DESC');
     $db->setQuery($query);
     return $db->loadObject();
 }
예제 #26
0
 /**
  * Default component view
  *
  * @return  void
  */
 public function displayTask()
 {
     $authlevel = \JAccess::getAuthorisedViewLevels(User::get('id'));
     $access_level = 3;
     //author_level
     if (in_array($access_level, $authlevel) && User::get('id')) {
         $model = new Models\Feeds();
         $this->view->feeds = $model->loadAll();
         $this->view->title = Lang::txt('COM_FEEDAGGREGATOR');
         $this->view->display();
     } else {
         if (User::get('id')) {
             App::redirect(Route::url('index.php?option=com_feedaggregator'), Lang::txt('COM_FEEDAGGREGATOR_NOT_AUTH'), 'warning');
         } else {
             if (User::isguest()) {
                 $rtrn = Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->_option . '&task=' . $this->_task), 'server');
                 App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn)), Lang::txt('COM_FEEDAGGREGATOR_LOGIN_NOTICE'), 'warning');
             }
         }
     }
 }
예제 #27
0
 /**
  * Gets access levels of CMS for $user_id
  * 
  * @param  int      $user_id
  * @param  boolean  $recurse		(DEPRECATED 1.8)
  * @param  boolean  $cb1xNumbering  (SINCE 1.8)      DEFAULT: FALSE: (if $cb1xNumbering with CB 1.x's definition for standard levels 0,1,2)
  * @return array of int
  */
 function get_object_access($user_id, $recurse = false, $cb1xNumbering = true)
 {
     global $_CB_database;
     if (checkJversion() == 2) {
         $levels = $this->_acl->getAuthorisedViewLevels((int) $user_id);
         // Keep backwards levels compatible: J1.6's 1 is CB 1.7-'s 0, 2 is 1, 3 is 2:
         if ($cb1xNumbering) {
             foreach ($levels as $k => $v) {
                 if ($v <= 3) {
                     --$levels[$k];
                 }
             }
         }
     } else {
         if (checkJversion() == 1) {
             $user =& JFactory::getUser($user_id ? (int) $user_id : null);
             $level = $user->get('aid', 0);
         } else {
             $user = new mosUser($_CB_database);
             $user->load((int) $user_id);
             $level = $user->gid;
         }
         $query = 'SELECT ' . $_CB_database->NameQuote('id') . "\n FROM " . $_CB_database->NameQuote('#__groups') . "\n WHERE " . $_CB_database->NameQuote('id') . " <= " . (int) $level . "\n ORDER BY " . $_CB_database->NameQuote('id');
         $_CB_database->setQuery($query);
         $levels = $_CB_database->loadResultArray();
         if (!$cb1xNumbering) {
             for ($i = 0, $n = count($levels); $i < $n; $i++) {
                 if (in_array($levels[$i], array(0, 1, 2))) {
                     ++$levels[$i];
                     // J1.5's 0 is CB's 1, 1 is 2, 2 is 3.
                 }
             }
         }
         // This makes sense only on J<1.6, thus it's only here:
         if (!$recurse) {
             $levels = array_slice($levels, -1);
         }
     }
     return array_unique(cbArrayToInts($levels));
 }
예제 #28
0
 static function getArticle(&$item, $params)
 {
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     // Get an instance of the generic articles model
     $articles = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     // Set application parameters in model
     $app = JFactory::getApplication();
     $appParams = $app->getParams();
     $articles->setState('params', $appParams);
     $articles->setState('filter.published', 1);
     $articles->setState('filter.article_id', $item->slidearticleid);
     $items2 = $articles->getItems();
     $item->article = $items2[0];
     $item->article->text = JHTML::_('content.prepare', $item->article->introtext);
     $item->article->text = self::truncate($item->article->text, $params->get('articlelength', '150'));
     // $item->article->text = JHTML::_('string.truncate',$item->article->introtext,'150');
     // set the item link to the article depending on the user rights
     if ($access || in_array($item->article->access, $authorised)) {
         // We know that user has the privilege to view the article
         $item->slug = $item->article->id . ':' . $item->article->alias;
         $item->catslug = $item->article->catid ? $item->article->catid . ':' . $item->article->category_alias : $item->article->catid;
         $item->article->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
     } else {
         $app = JFactory::getApplication();
         $menu = $app->getMenu();
         $menuitems = $menu->getItems('link', 'index.php?option=com_users&view=login');
         if (isset($menuitems[0])) {
             $Itemid = $menuitems[0]->id;
         } elseif (JRequest::getInt('Itemid') > 0) {
             $Itemid = JRequest::getInt('Itemid');
         }
         $item->article->link = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $Itemid);
     }
     return $item;
 }
예제 #29
0
 /**
  * Method to get data of filters
  * 
  * @access public
  * @return object
  * @since 1.5
  */
 static function &getFilters($filt_param = 'filters', $usage_param = 'use_filters', &$params = null, $check_access = true)
 {
     // Parameter that controls using these filters
     $filters = array();
     if ($usage_param != '__ALL_FILTERS__' && $params && !$params->get($usage_param, 0)) {
         return $filters;
     }
     // Get Filter IDs, false means do retrieve any filter
     $filter_ids = $params ? $params->get($filt_param, array()) : array();
     if ($filter_ids === false) {
         return $filters;
     }
     // Check if array or comma separated list
     if (!is_array($filter_ids)) {
         $filter_ids = preg_split("/\\s*,\\s*/u", $filter_ids);
         if (empty($filter_ids[0])) {
             unset($filter_ids[0]);
         }
     }
     // Sanitize the given filter_ids ... just in case
     $filter_ids = array_filter($filter_ids, 'is_numeric');
     // array_flip to get unique filter ids as KEYS (due to flipping) ... and then array_keys to get filter_ids in 0,1,2, ... array
     $filter_ids = array_keys(array_flip($filter_ids));
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     // None selected filters means ALL
     $and_scope = $usage_param != '__ALL_FILTERS__' && count($filter_ids) ? ' AND fi.id IN (' . implode(',', $filter_ids) . ')' : '';
     // Use ACCESS Level, usually this is only for shown filters
     $and_access = '';
     if ($check_access) {
         if (FLEXI_J16GE) {
             $aid_arr = JAccess::getAuthorisedViewLevels($user->id);
             $aid_list = implode(",", $aid_arr);
             $and_access = ' AND fi.access IN (0,' . $aid_list . ') ';
         } else {
             $aid = (int) $user->get('aid');
             if (FLEXI_ACCESS) {
                 $readperms = FAccess::checkUserElementsAccess($user->gmid, 'read');
                 if (isset($readperms['field']) && count($readperms['field'])) {
                     $and_access = ' AND ( fi.access <= ' . $aid . ' OR fi.id IN (' . implode(",", $readperms['field']) . ') )';
                 } else {
                     $and_access = ' AND fi.access <= ' . $aid;
                 }
             } else {
                 $and_access = ' AND fi.access <= ' . $aid;
             }
         }
     }
     // Create and execute SQL query for retrieving filters
     $query = 'SELECT fi.*' . ' FROM #__flexicontent_fields AS fi' . ' WHERE fi.published = 1' . ' AND fi.isfilter = 1' . $and_access . $and_scope . ' ORDER BY fi.ordering, fi.name';
     $db->setQuery($query);
     $filters = $db->loadObjectList('id');
     if (!$filters) {
         $filters = array();
         // need to do this because we return reference, but false here will also mean an error
         return $filters;
     }
     // Order filters according to given order
     $filters_tmp = array();
     if ($params->get('filters_order', 0) && !empty($filter_ids) && $usage_param != '__ALL_FILTERS__') {
         foreach ($filter_ids as $filter_id) {
             if (empty($filters[$filter_id])) {
                 continue;
             }
             $filter = $filters[$filter_id];
             $filters_tmp[$filter->name] = $filter;
         }
     } else {
         foreach ($filters as $filter) {
             $filters_tmp[$filter->name] = $filter;
         }
     }
     $filters = $filters_tmp;
     // Create filter parameters, language filter label, etc
     foreach ($filters as $filter) {
         $filter->parameters = FLEXI_J16GE ? new JRegistry($filter->attribs) : new JParameter($filter->attribs);
         $filter->label = JText::_($filter->label);
     }
     // Return found filters
     return $filters;
 }
예제 #30
0
 /**
  *
  * Get list articles
  * @param object $params
  * @return array
  */
 public function getAticles($params)
 {
     // Get the dbo
     $db = JFactory::getDbo();
     // Get an instance of the generic articles model
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     } else {
         if (version_compare(JVERSION, '2.5', 'ge')) {
             $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
         } else {
             $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
         }
     }
     // Set application parameters in model
     $appParams = JFactory::getApplication()->getParams();
     $model->setState('params', $appParams);
     $model->setState('list.select', 'a.fulltext, a.id, a.title, a.alias, a.introtext, a.state, a.images, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured, a.ordering, c.alias AS category_alias, ' . ' LENGTH(a.fulltext) AS readmore');
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) trim($params->get('count', 5)));
     if ((int) trim($params->get('count', 5)) == 0) {
         $model->setState('filter.published', 10);
     } else {
         $model->setState('filter.published', 1);
     }
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     if ($params->get('category')) {
         $model->setState('filter.category_id', $params->get('category'));
     }
     $featured = $params->get('show_featured', 1);
     if (!$featured) {
         $model->setState('filter.featured', 'hide');
     } elseif ($featured == 2) {
         $model->setState('filter.featured', 'only');
     }
     // Set ordering
     $ordering = $params->get('type', 'latest');
     if ($ordering == 'latest') {
         // Set ordering
         $order_map = array('m_dsc' => 'a.modified DESC, a.created', 'mc_dsc' => 'CASE WHEN (a.modified = ' . $db->quote($db->getNullDate()) . ') THEN a.created ELSE a.modified END', 'c_dsc' => 'a.created', 'p_dsc' => 'a.publish_up');
         $ordering = JArrayHelper::getValue($order_map, $params->get('ordering', 'm_dsc'), 'a.publish_up');
     } else {
         $ordering = 'a.hits';
     }
     $dir = 'DESC';
     if ($ordering !== 'latest' && $params->get('timerange')) {
         $model->setState('filter.date_filtering', 'relative');
         $model->setState('filter.relative_date', $params->get('timerange'));
     }
     $model->setState('list.ordering', $ordering);
     $model->setState('list.direction', $dir);
     $items = $model->getItems();
     if ($items) {
         $i = 0;
         $showHits = $params->get('show_hits', 0);
         $showHits = $showHits == "1" ? true : false;
         $showimg = $params->get('show_image', 1);
         $w = (int) $params->get('width', 80);
         $h = (int) $params->get('height', 96);
         $showdate = $params->get('show_date', 1);
         $thumbnailMode = $params->get('thumbnail_mode', 'crop');
         $aspect = $params->get('use_ratio', '1');
         $crop = $thumbnailMode == 'crop' ? true : false;
         $lists = array();
         $jaimage = JAImage::getInstance();
         foreach ($items as &$item) {
             $item->slug = $item->id . ':' . $item->alias;
             $item->catslug = $item->catid . ':' . $item->category_alias;
             if ($access || in_array($item->access, $authorised)) {
                 // We know that user has the privilege to view the article
                 $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
             } else {
                 $item->link = JRoute::_('index.php?option=com_user&view=login');
             }
             $item->introtext = JHtml::_('content.prepare', $item->introtext);
             $item->text = htmlspecialchars($item->title);
             if ($showdate) {
                 $item->date = $item->modified == null || $item->modified == "" || $item->modified == "0000-00-00 00:00:00" ? $item->created : $item->modified;
             }
             $item->image = '';
             if ($showimg) {
                 $imageSource = $jaimage->parseImage($item);
                 if ($imageSource) {
                     if ($thumbnailMode != 'none') {
                         $imageURL = $jaimage->resize($imageSource, $w, $h, $crop, $aspect);
                         if ($imageURL) {
                             if ($imageURL == $imageSource) {
                                 $width = $w ? "width=\"{$w}\"" : "";
                                 $height = $h ? "height=\"{$h}\"" : "";
                                 $item->image = "<img src=\"{$imageURL}\" alt=\"{$item->text}\" title=\"{$item->text}\" {$width} {$height} />";
                             } else {
                                 $item->image = "<img src=\"{$imageURL}\" alt=\"{$item->text}\" title=\"{$item->text}\" />";
                             }
                         } else {
                             $item->image = '';
                         }
                     } else {
                         $width = $w ? "width=\"{$w}\"" : "";
                         $height = $h ? "height=\"{$h}\"" : "";
                         $item->image = "<img src=\"{$imageSource}\" alt=\"{$item->text}\" title=\"{$item->text}\" {$width} {$height} />";
                     }
                 }
             }
             $item->creater = isset($item->author) ? $item->author : $item->created_by_alias;
             if ($showHits) {
                 $item->hits = isset($item->hits) ? $item->hits : 0;
             } else {
                 $item->hits = null;
             }
         }
     }
     return $items;
 }