roxcoder

latest post addon site.php

Dec 3rd, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.67 KB | None | 0 0
  1. <?php
  2. defined ('_JEXEC') or die('resticted aceess');
  3.  
  4. //Load Helix
  5. $helix3_path = JPATH_PLUGINS.'/system/helix3/core/helix3.php';
  6.  
  7. if (file_exists($helix3_path)) {
  8.     require_once($helix3_path);
  9.     helix3::addCSS('owl.carousel.css, owl.transitions.css, slide-animate.css') // CSS Files
  10.         ->addJS('owl.carousel.min.js, addon.lp_slider.js, jquery.prettySocial.min.js'); // JS Files
  11. }
  12.  
  13.  
  14. // Required pagebuilder article helper
  15. require_once JPATH_COMPONENT . '/helpers/articles.php';
  16.  
  17. AddonParser::addAddon('sp_latest_post','sp_latest_posts_addon');
  18.  
  19.  
  20. function sp_latest_posts_addon($atts){
  21.  
  22.     extract(spAddonAtts(array(
  23.         "title"                 => '',
  24.         "heading_selector"      => 'h3',
  25.         "theme"                 => 'default',
  26.         "art_order"             => 'latest',
  27.         "see_all"               => 0,
  28.         "item_limit"            => '',
  29.         "leading_item"          => '1',
  30.         "sub_leading_item"      => '2',
  31.         "intro_text_limit"      => '100',
  32.         "column_no"             => '3',
  33.         "category_id"               => '',
  34.         "cat_color"             => '',
  35.         "before_title"          => '',
  36.         "cat_rand_color"        => 1,
  37.         "item_shadow"           => 'rand',
  38.         "show_cat"              => '1',
  39.         "class"                 => '',
  40.         ), $atts));
  41.  
  42.  
  43.     $doc = JFactory::getDocument();
  44.     $items = SppagebuilderHelperArticles::getArticles($item_limit, $art_order, $category_id);
  45.  
  46.     //variables
  47.     // create unique class
  48.     $uniq_class = trim(str_replace(' ', '-', strtolower($title)));
  49.     // if before icon is icon then generate icon or title first text
  50.     $before_title = ($before_title) ? '<i class="fa ' . $before_title . '"></i>' : $title[0];
  51.  
  52.     //start structure
  53.     $output  = '<div class="sppb-addon sppb-addon-latest-posts ' . $class . ' ' . $art_order . ' ' . $theme . ' ' . $uniq_class . '">';
  54.     // has icon color
  55.     $icon_color = ($cat_color) ? 'background-color:' . $cat_color  . ';' : '' ;
  56.  
  57.     // generate item shadow hover style
  58.     if ($cat_color && $item_shadow =='fixed') {
  59.         $shadow_color = '.sppb-addon-latest-posts.img_overlay.sp-gradien-on-hover.'.$theme.'.'.$uniq_class.' .latest-posts> .sppb-row .latest-post .overlay:before{ background-image: -webkit-linear-gradient(to bottom,rgba(0,0,0,0.1) 30%, ' . $cat_color  . ' 70%) !important; background-image: linear-gradient(to bottom,rgba(0,0,0,0.1) 30%,' . $cat_color  . ' 70%) !important; }';
  60.         $doc->addStyleDeclaration($shadow_color);
  61.     }
  62.  
  63.     // title
  64.     if ($title) {
  65.         $output .= '<div class="sppb-section-title sppb-text-center">';
  66.             $output .= '<' . $heading_selector . ' class="sppb-title-heading"> <span class="spns-cat-icon" style="' . $icon_color . '">' . $before_title . '</span>' . $title . '</' . $heading_selector . '>';
  67.         $output .= '</div>'; // END :: title
  68.     }
  69.  
  70.     //$cat_url = '';
  71.     if ($see_all && $category_id !='all' && $category_id) {
  72.         $cat_url = JRoute::_(ContentHelperRoute::getCategoryRoute($category_id, $category_id));
  73.         $output .= '<div class="sppb-addon-section-right">';
  74.         $output .= '<a href="' . $cat_url . '">' . JText::_('COM_SPPAGEBUILDER_ADDON_LP_SEE_ALL') . '</a>';
  75.         $output .= '</div>';
  76.     }
  77.  
  78.  
  79.     $output .= '<div class="sppb-addon-content">';
  80.     $output .= '<div class="latest-posts clearfix">';
  81.  
  82.     $i= 0;
  83.     if ($i < ($sub_leading_item+$leading_item)){
  84.         $art_column_no = $sub_leading_item+$leading_item;
  85.     }else{
  86.         $art_column_no = $column_no;
  87.     }
  88.  
  89.     foreach(array_chunk($items, $art_column_no) as $items) {
  90.         $output .= '<div class="sppb-row">';
  91.  
  92.         foreach ($items as $key => $item) {
  93.            
  94.             // rand color generate
  95.             $cat_icon_colors = array('#ed1c24', '#f26522', '#2e3192', '#00c8ff', '#ed145b', '#0072bc', '#0076a3', '#00a651', '#8dc63f', '#662d91');
  96.             $rand_color = $cat_icon_colors[array_rand($cat_icon_colors)];
  97.  
  98.             if ($cat_rand_color) {
  99.                 $rand_color = 'style="background-color: ' . $rand_color . ';"';
  100.             }else{
  101.                 $rand_color ='';
  102.             }
  103.  
  104.             //before title icon
  105.             $ft_color = ($cat_color && $item_shadow =='fixed') ? 'style="background-color: ' . $cat_color . ';"' : $rand_color ;
  106.  
  107.             // if leading items then carousel
  108.             if ( ($i == 0) && ($i < $leading_item) ) {
  109.                 $output .= '<div id="slide-art-leading" class="owl-carousel col-sm-8">';
  110.             }
  111.  
  112.             // Leading and normal item variable load
  113.             $art_slide = '';
  114.             $image     = '';
  115.             if ($i < $leading_item) {
  116.                 $image = (isset($item->image_thumbnail) && $item->image_medium) ? $item->image_medium : '' ;
  117.                 //$image    = $item->image_medium;
  118.                 $item_column_no = '';
  119.                 $matchheight = '';
  120.                 $item_type = 'leading_item';
  121.                 $art_slide = 'sppb-art-slide-item item';
  122.                 // sub leading
  123.             }elseif ($i < ($sub_leading_item+$leading_item)) {
  124.                 //$image    = $item->image_thumbnail;
  125.                 $image = (isset($item->image_thumbnail) && $item->image_thumbnail) ? $item->image_thumbnail : '' ;
  126.                 $item_column_no = 4;
  127.                 $item_type = 'sub_leading_item';
  128.                 $matchheight = 'match-height';
  129.             }else{
  130.                 $matchheight = 'match-height';
  131.                 $image = (isset($item->image_thumbnail) && $item->image_thumbnail) ? $item->image_thumbnail : '' ;
  132.                 //$image    = $item->image_thumbnail;
  133.                 $item_column_no = round(12/$column_no);
  134.                 $item_type = 'intro_item';
  135.             }
  136.  
  137.             $images = json_decode($item->images);
  138.             $no_image = '';
  139.             $no_image_style='';
  140.  
  141.             if (isset($image) && !empty($image)) {
  142.                 $image = $image;
  143.             }elseif (isset($images->image_intro) && !empty($images->image_intro)) {
  144.                 $image = $images->image_intro;
  145.             } elseif (isset($images->image_fulltext) && !empty($images->image_fulltext)) {
  146.                 $image = $images->image_fulltext;
  147.             }else{
  148.                 $no_image ='no-image';
  149.                 $no_image_style = ($cat_color) ? 'style="background-color: '. $cat_color .';"' : '' ;
  150.             }
  151.  
  152.             $output .= '<div class="latest-post sppb-col-sm-' . $item_column_no . ' ' . $item_type . ' '. $art_slide . ' ' . $no_image . '">';
  153.                 $output .= '<div class="latest-post-inner" ' . $no_image_style . '>';
  154.                 $output .= '<div class="overlay"></div>';
  155.                 $output .= '<div class="img-wrapper ' . $matchheight . '">';
  156.                     if ($image) {
  157.                         $output .= '<img class="img-responsive latest-post-image" src="' . $image .'">';
  158.                     }
  159.                 $output .= '</div>';
  160.  
  161.                 // social share
  162.                 //$social_share = '<div class="sppb-post-share-social-icon"><i class="fa fa-users"></div>';
  163.                 $output .= '<div class="sppb-post-share-social">';
  164.                     $output .= '<a href="#" data-type="facebook" data-url="'. $_SERVER['SERVER_NAME'] . $item->link .'" data-title="'. $item->title .'" data-media="' . $image .'" class="prettySocial fa fa-facebook"></a>';
  165.  
  166.                     $output .= '<a href="#" data-type="twitter" data-url="'. $_SERVER['SERVER_NAME'] . $item->link .'" data-description="'. $item->title .'" data-media="' . $image .'" data-via="joomshaper" class="prettySocial fa fa-twitter"></a>';
  167.  
  168.                     $output .= '<a href="#" data-type="googleplus" data-url="'. $item->link .'" data-description="'. $item->title .'" data-media="' . $image .'" class="prettySocial fa fa-google-plus"></a>';
  169.                    
  170.                     $output .= '<a href="#" data-type="pinterest" data-url="'. $item->link .'" data-description="'. $item->title .'" data-media="' . $image .'" class="prettySocial fa fa-pinterest"></a>';
  171.  
  172.                     $output .= '<a href="#" data-type="linkedin" data-url="'. $item->link .'" data-title="'. $item->title .'" data-description="'. $item->title .'" data-via="joomshaper" data-media="" class="prettySocial fa fa-linkedin"></a>';
  173.                 $output .= '<div class="share-icon"><i class="fa fa-share-alt"></i></div>';
  174.                 $output .= '</div>';
  175.  
  176.                     $output .= '<div class="latest-post-infos">';
  177.                         $item->cat_link = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catid));
  178.                         if ($show_cat && ($show_cat !='')) {
  179.                             $output .='<a href="' . $item->cat_link . '">';
  180.                         $output .='<p class="spns-slide-cat"><span class="spns-cat-icon" ' . $ft_color . ' > ' . mb_substr($item->category, 0, 1) . '</span>' . $item->category . '</p>';
  181.                             $output .='</a>';
  182.                         }
  183.  
  184.                         $output .= '<h4 class="entry-title"><a href="' . $item->link . '">' . $item->title . '</a></h4>';
  185.                         //$output .= '<p class="intro-text" >' . truncate($item->introtext, $length=100) . '</p>';
  186.                         //$output .= '<p class="intro-text" >' . JHtml::_('string.truncate', strip_tags($item->introtext), $intro_text_limit) . '</p>';
  187.                            
  188.                         //$output .= '<div class="post-author"> <span class="entry-author"> ' . JText::_('COM_SPPAGEBUILDER_ADDON_SF_POSTED_BY'). ' ' . $item->user . '</span> </div>';
  189.                     $output .= '</div>'; // .latest-post-infos
  190.                 $output .= '</div>'; //atest-post-inner
  191.             $output .= '</div>'; //.latest-post .col-sm
  192.            
  193.             // if leading items end then carousel close
  194.             if ( ( $i != 0 ) && ( $i == $leading_item - 1) ) {
  195.                 $output .= '</div>'; //.carousel
  196.             }
  197.             $i ++;
  198.         }
  199.  
  200.         $output .= '</div>'; //.sppb-row
  201.     }
  202.  
  203.     $output .= '</div>'; //.latest-posts
  204.     $output .= '</div>'; //.sppb-addon-content
  205.     $output .= '</div>'; //.sppb-addon-latest-posts
  206.  
  207.     return $output;
  208.  
  209. }
Advertisement
Add Comment
Please, Sign In to add comment