roxcoder

Untitled

Dec 20th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.07 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package SP Page Builder
  4.  * @author JoomShaper http://www.joomshaper.com
  5.  * @copyright Copyright (c) 2010 - 2016 JoomShaper
  6.  * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
  7.  */
  8.  
  9. //no direct accees
  10. defined('_JEXEC') or die('resticted aceess');
  11. require_once JPATH_ROOT . '/components/com_sppagebuilder/helpers/articles.php';
  12.  
  13. // class SppagebuilderAddonLatest_post extends SppagebuilderAddons {
  14. //     public function render() {
  15. //       $class      = (isset($this->addon->settings->class) && $this->addon->settings->class) ? $this->addon->settings->class : '';
  16. //       $title      = (isset($this->addon->settings->title) && $this->addon->settings->title) ? $this->addon->settings->title : '';
  17. //       $heading_selector = (isset($this->addon->settings->heading_selector) && $this->addon->settings->heading_selector) ? $this->addon->settings->heading_selector : 'h3';
  18. //       $limit      = (isset($this->addon->settings->item_limit) && $this->addon->settings->item_limit) ? $this->addon->settings->item_limit : '';
  19. //       $ordering   = (isset($this->addon->settings->ordering) && $this->addon->settings->ordering) ? $this->addon->settings->ordering : '';
  20. //       $catid      = (isset($this->addon->settings->ordering) && $this->addon->settings->ordering) ? $this->addon->settings->ordering : '';
  21. //       $post_type  = (isset($this->addon->settings->post_type) && $this->addon->settings->post_type) ? $this->addon->settings->post_type : '';
  22.  
  23. //       $items = SppagebuilderHelperArticles::getArticles($limit, $ordering, $catid, TRUE, $post_type);
  24.  
  25. //       // Start output
  26. //          $output   = '';
  27. //       $output .= '<div class="sppb-addon sppb-addon-latest-posts ' . $class . '">';
  28. //       $output .= '<div class="sppb-addon-content">';
  29. //       $output .= '<div class="latest-posts clearfix">';
  30.  
  31. //       $output .= '<div class="sppb-row">';
  32.  
  33. //       // Animation Delay
  34. //       $delay = 200;
  35.  
  36. //       foreach ($items as $item) {
  37.  
  38. //           $image = '';
  39.  
  40. //           if(isset($item->image_thumbnail) && $item->image_thumbnail) {
  41. //               $image = $item->image_thumbnail;
  42. //           } elseif (isset($item->image_intro) && !empty($item->image_intro)) {
  43. //               $image = $item->image_intro;
  44. //           } elseif (isset($item->image_fulltext) && !empty($item->image_fulltext)) {
  45. //               $image = $item->image_fulltext;
  46. //           }
  47.  
  48. //           $output .= '<div class="latest-post sppb-col-sm-12 sppb-wow fadeInUp" data-sppb-wow-delay="' . $delay . 'ms">';
  49.  
  50. //           $output .= '<div class="sppb-latest-post" style="background-image: url(' . Juri::root() . $image . ');">';
  51. //           $output .= '<div class="sppb-row">';
  52. //           if ($image) {
  53. //               $output .= '<div class="latest-post-inner sppb-col-xs-offset-3 sppb-col-xs-9">';
  54. //           } else {
  55. //               $output .= '<div class="latest-post-inner sppb-col-sm-12">';
  56. //           }
  57. //           $output .= '<div class="latest-post-content">';
  58. //           $output .= '<p class="date"> ' . JHtml::_('date', $item->created, 'DATE_FORMAT_LC3') . '</p>';
  59. //           $output .= '<' . $heading_selector . ' class="entry-title"><a href="' . $item->link . '">' . $item->title . '</a></' . $heading_selector . '>';
  60. //           $output .= '<p class="info">';
  61. //           $output .= '<span class="author" itemprop="genre" data-toggle="tooltip" title=" ' . JText::_('COM_SPPAGEBUILDER_ADDON_LP_AUTHOR') . ' "><i class="fa fa-user"></i> ' . $item->username . '</span>';
  62. //           $output .= '<span class="category" itemprop="itemTags" data-toggle="tooltip" title=" ' . JText::_('COM_SPPAGEBUILDER_ADDON_LP_CATEGORY') . '"><i class="fa fa-folder-open-o"></i> ' . $item->category . '</span>';
  63. //           // $output .= '<span class="Tags">'.JText::_('SPBB_TAGS').': <a href="#">adventure</a>, <a href="#">courage</a></span>';
  64. //           // $output .= '<span class="Comments">'.JText::_('COMMENTS').' (2)</span>';
  65. //           $output .= '</p>';
  66. //           $output .= '</div>';
  67. //           $output .= '</div>';
  68. //           $output .= '</div>';
  69. //           $output .= '</div>'; //spbb-row
  70. //           $output .= '</div>'; //.sppb-latest-post
  71. //           $delay += 100;
  72. //       }
  73. //       $output .= '</div>'; //.sppb-row
  74.  
  75. //       $output .= '</div>';
  76. //       $output .= '</div>';
  77. //       $output .= '</div>';
  78.  
  79. //       return $output;
  80. //     }
  81. // }
  82.  
  83.  
  84. AddonParser::addAddon('sp_latest_post', 'sp_latest_posts_addon');
  85. function get_categories($parent = 1) {
  86.     $db = JFactory::getDbo();
  87.     $query = $db->getQuery(true);
  88.  
  89.     $query
  90.             ->select('*')
  91.             ->from($db->quoteName('#__categories'))
  92.             ->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'))
  93.             ->where($db->quoteName('published') . ' = ' . $db->quote(1))
  94.             ->where($db->quoteName('parent_id') . ' = ' . $db->quote($parent))
  95.             ->order($db->quoteName('created_time') . ' DESC');
  96.  
  97.     $db->setQuery($query);
  98.  
  99.     $cats = $db->loadObjectList();
  100.  
  101.     $categories = array($parent);
  102.  
  103.     foreach ($cats as $key => $cat) {
  104.         $categories[] = $cat->id;
  105.     }
  106.  
  107.     return $categories;
  108. }
  109.  
  110. function sp_latest_posts_addon($atts) {
  111.  
  112.     extract(spAddonAtts(array(
  113.         "title" => '',
  114.         "heading_selector" => 'h3',
  115.         "title_fontsize" => '',
  116.         "title_text_color" => '',
  117.         "title_margin_top" => '',
  118.         "title_margin_bottom" => '',
  119.         "item_limit" => '',
  120.         "category" => '',
  121.         "class" => '',
  122.                     ), $atts));
  123.  
  124.     //Add js
  125.     $app = JFactory::getApplication();
  126.     $doc = JFactory::getDocument();
  127.  
  128.     // Database Query
  129.     require_once JPATH_SITE . '/components/com_content/helpers/route.php';
  130.  
  131.     // Access filter
  132.     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
  133.     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
  134.  
  135.  
  136.     $db = JFactory::getDbo();
  137.     $query = $db->getQuery(true);
  138.  
  139.     $query
  140.             ->select('a.*')
  141.             ->from($db->quoteName('#__content', 'a'))
  142.             ->select($db->quoteName('b.alias', 'category_alias'))
  143.             ->select($db->quoteName('b.title', 'category'))
  144.             ->join('LEFT', $db->quoteName('#__categories', 'b') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('b.id') . ')')
  145.             ->where($db->quoteName('b.extension') . ' = ' . $db->quote('com_content'))
  146.             ->where($db->quoteName('a.state') . ' = ' . $db->quote(1));
  147.     if ($category) {
  148.         $query->where($db->quoteName('a.catid') . " IN (" . implode(',', get_categories($category)) . ")");
  149.     }
  150.     $query->where($db->quoteName('a.access') . " IN (" . implode(',', $authorised) . ")")
  151.             ->order($db->quoteName('a.created') . ' DESC')
  152.             ->setLimit($item_limit);
  153.  
  154.  
  155.     $db->setQuery($query);
  156.  
  157.     $items = $db->loadObjectList();
  158.  
  159.     // End Database Query
  160.  
  161.     $output = '<div class="sppb-addon sppb-addon-latest-posts ' . $class . '">';
  162.     $output .= '<div class="sppb-addon-content">';
  163.     $output .= '<div class="latest-posts clearfix">';
  164.  
  165.     $output .= '<div class="sppb-row">';
  166.  
  167.     // Animation Delay
  168.     $delay = 200;
  169.  
  170.     foreach ($items as $item) {
  171.  
  172.         $item->slug = $item->id . ':' . $item->alias;
  173.         $item->catslug = $item->catid . ':' . $item->category_alias;
  174.         $item->catsname = $item->category_alias;
  175.         $item->user = JFactory::getUser($item->created_by)->name;
  176.  
  177.         if ($access || in_array($item->access, $authorised)) {
  178.             // We know that user has the privilege to view the article
  179.             $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language));
  180.         } else {
  181.             $item->link = JRoute::_('index.php?option=com_users&view=login');
  182.         }
  183.  
  184.         $images = json_decode($item->images);
  185.  
  186.         $image = '';
  187.  
  188.         if (isset($images->image_intro) && !empty($images->image_intro)) {
  189.             $image = $images->image_intro;
  190.         } elseif (isset($images->image_fulltext) && !empty($images->image_fulltext)) {
  191.             $image = $images->image_fulltext;
  192.         }
  193.  
  194.         $output .= '<div class="latest-post sppb-col-sm-12 sppb-wow fadeInUp" data-sppb-wow-delay="' . $delay . 'ms">';
  195.  
  196.         $output .= '<div class="sppb-latest-post" style="background-image: url(' . Juri::root() . $image . ');">';
  197.         $output .= '<div class="sppb-row">';
  198.         if ($image) {
  199.             $output .= '<div class="latest-post-inner sppb-col-xs-offset-3 sppb-col-xs-9">';
  200.         } else {
  201.             $output .= '<div class="latest-post-inner sppb-col-sm-12">';
  202.         }
  203.         $output .= '<div class="latest-post-content">';
  204.         $output .= '<p class="date"> ' . JHtml::_('date', $item->created, 'DATE_FORMAT_LC3') . '</p>';
  205.         $output .= '<' . $heading_selector . ' class="entry-title"><a href="' . $item->link . '">' . $item->title . '</a></' . $heading_selector . '>';
  206.         $output .= '<p class="introtext">' . $item->introtext .'</p>';
  207.         $output .= '<p class="info">';
  208.         $output .= '<span class="author" itemprop="genre" data-toggle="tooltip" title=" ' . JText::_('COM_SPPAGEBUILDER_ADDON_LP_AUTHOR') . ' "><i class="fa fa-user"></i> ' . $item->user . '</span>';
  209.         $output .= '<span class="category" itemprop="itemTags" data-toggle="tooltip" title=" ' . JText::_('COM_SPPAGEBUILDER_ADDON_LP_CATEGORY') . '"><i class="fa fa-folder-open-o"></i> ' . $item->category . '</span>';
  210.         // $output .= '<span class="Tags">'.JText::_('SPBB_TAGS').': <a href="#">adventure</a>, <a href="#">courage</a></span>';
  211.         // $output .= '<span class="Comments">'.JText::_('COMMENTS').' (2)</span>';
  212.         $output .= '</p>';
  213.         $output .= '</div>';
  214.         $output .= '</div>';
  215.         $output .= '</div>';
  216.         $output .= '</div>'; //spbb-row
  217.         $output .= '</div>'; //.sppb-latest-post
  218.         $delay += 100;
  219.     }
  220.     $output .= '</div>'; //.sppb-row
  221.  
  222.     $output .= '</div>';
  223.     $output .= '</div>';
  224.     $output .= '</div>';
  225.  
  226.     return $output;
  227. }
Advertisement
Add Comment
Please, Sign In to add comment