Advertisement
uzielweb

Get and filter articles from current blog or featured view for Joomla

Feb 6th, 2021
1,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.09 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package Joomla.Site
  4.  * @subpackage  mod_intercode_leading_items
  5.  *
  6.  * @copyright
  7.  * @license GNU/Public
  8.  */
  9. defined('_JEXEC') or die;
  10. $baseurl = JUri::base();
  11. $app = JFactory::getApplication();
  12. // Obtém o Item de Menu atualmente ativo
  13. $currentMenuItem = $app->getMenu()->getActive();
  14. // Obtém os parâmetros do Item de Menu atualmente ativo
  15. $menuparams = $currentMenuItem->params;
  16. // Agora você pode pegar um parâmetro em particular
  17. // pega todas as subcategorias
  18. $currentCategory = $currentMenuItem->query['id'];
  19.  
  20. $categories = JCategories::getInstance('Article', $options);
  21. $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
  22. $model->getState();
  23. // Set application parameters in model
  24. $app = JFactory::getApplication();
  25. $appParams = $app->getParams();
  26. $model->setState('params', $appParams);
  27. // Set the filters based on the module params
  28. $model->setState('list.start', 0);
  29. $model->setState('list.limit', $menuparams->get('num_leading_articles'));
  30. $model->setState('filter.category_id', $currentCategory);
  31. $model->setState('filter.published', 1);
  32. $model->setState('filter.subcategories', true);
  33. $subCategoryLevels = $menuparams->get('maxLevel') == '0' ? '-1' : '';
  34.  
  35. $model->setState('filter.max_category_levels', $subCategoryLevels);
  36. // Permissions
  37. $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
  38. $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
  39. $model->setState('filter.access', $access);
  40. // Featured Item
  41. // Get article from featured set
  42. if ($params->get('featured') == '1'){
  43.     $model->setState('filter.featured', 'only');
  44. }
  45.  
  46. // Ordering
  47. $orderDate = $menuparams->get('order_date') ;
  48. if ($menuparams->get('order_date') == 'published'){
  49.     $orderDate = 'a.publish_up';
  50. }
  51. $model->setState('list.ordering', $orderDate);
  52. $model->setState('list.direction', 'DESC');
  53. $items = $model->getItems();
  54.  
  55. ?>
  56.  
  57. <div class="lead-items intercode-leading-items intercode-leading-items<?php echo $moduleclass_sfx ?> row">
  58.     <?php foreach ($items as $item) :?>
  59.     <div class="lead-item col-md-4">
  60.         <?php
  61.     $images = json_decode($item->images);
  62.     $intromage =  $images->image_intro;
  63.     ?>
  64.         <?php if ($intromage) :?>
  65.         <div class="item-image">
  66.             <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($item->id)); ?>">
  67.                 <img src="<?php echo JUri::base().$intromage;?>" />
  68.             </a>
  69.         </div>
  70.         <?php endif;?>
  71.         <div class="article-info">
  72.             <div class="category">
  73.                 <a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($item->catid)); ?>">
  74.                     <?php
  75.      $category = JTable::getInstance('category');
  76.      $category->load($item->catid);
  77.      echo $category->title;?>
  78.                 </a>
  79.             </div>
  80.         </div>
  81.         <div class="page-header">
  82.             <h2 itemprop="name" class="lead-title">
  83.                 <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($item->id)); ?>">
  84.                     <?php echo $item->title;?>
  85.                 </a>
  86.             </h2>
  87.         </div>
  88.         <div class="lead-text">
  89.             <?php
  90. //Limite de caracteres
  91. $maxLimit = $params->get('max_chars');
  92. $text = $item->introtext.$item->textfull;
  93. $text = preg_replace("/\r\n|\r|\n/", " ", $text);
  94. // Em seguida, troca os marcadores <br /> com \n
  95. $text = preg_replace("/<BR[^>]*>/i", " ", $text);
  96. // Troca os marcadores <p> com \n\n
  97. $text = preg_replace("/<P[^>]*>/i", " ", $text);
  98. // Remove todos os marcadores
  99. $text = strip_tags($text);
  100. // Trunca o texto pelo limite de caracteres
  101. $text = substr($text, 0, $maxLimit);
  102. //$text = String::truncate($text, $maxLimit, '...', true);
  103. // Deixa visível a última palavra que, no caso, foi cortada no meio
  104. $text = preg_replace("/[.,!?:;]? [^ ]*$/", " ", $text);
  105. // Adiciona reticências ao fim do texto
  106. $text = trim($text) . '...' ;
  107. // Troca \n com <br />
  108. $text = str_replace("\n", " ", $text);
  109. echo $text;
  110. ?>
  111.         </div>
  112.     </div>
  113.     <?php endforeach;?>
  114. </div>
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement