1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-31 02:00:14 +02:00

News Carousel upgraded with config options. Fixes #672 #759

This commit is contained in:
Cameron
2016-04-15 13:20:46 -07:00
parent 042172096c
commit d86ca55647
5 changed files with 162 additions and 105 deletions

View File

@@ -1,88 +1,65 @@
<?php
/**
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
*
* News Carousel Menu
* Copyright (C) 2008-2016 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
*
* Carousel Menu
*/
if (!defined('e107_INIT')) { exit; }
$tp = e107::getParser();
e107::js('footer-inline',"
clickEvent = false;
$('#news-carousel').on('click', '#news-carousel-nav a', function() {
clickEvent = true;
$('#news-carousel-nav li').removeClass('active');
$(this).parent().addClass('active');
}).on('slid.bs.carousel', function(e) {
if(!clickEvent) {
var count = $('#news-carousel-nav').children().length -1;
var current = $('#news-carousel-nav li.active');
current.removeClass('active').next().addClass('active');
var id = parseInt(current.data('slide-to'));
if(count == id) {
$('#news-carousel-nav li').first().addClass('active');
}
}
clickEvent = false;
});"
);
if(is_string($parm))
{
parse_str($parm, $parms);
}
else
{
$parms = $parm;
}
if(isset($parms['caption'][e_LANGUAGE]))
{
$parms['caption'] = $parms['caption'][e_LANGUAGE];
}
$NEWS_MENU_TEMPLATE['carousel']['start'] = '
<div id="news-carousel" class="carousel slide" data-ride="carousel">
<div class="row">
<!-- Wrapper for slides -->
<div id="news-carousel-images" class="col-md-8">
<div class="carousel-inner">';
$limit = vartrue($parms['count'],5);
$tp = e107::getParser();
$template = e107::getTemplate('news', 'news_menu', 'carousel');
$NEWS_MENU_TEMPLATE['carousel']['end'] = '
</div><!-- End Carousel Inner -->
</div>
<div id="news-carousel-titles" class="col-md-4 ">
<ul id="news-carousel-nav" class="nav nav-inverse nav-stacked pull-right ">{NAV}</ul>
</div>
</div><!-- End Carousel -->
</div>
';
$NEWS_MENU_TEMPLATE['carousel']['item'] = '<!-- Start Item -->
<div class="item {ACTIVE}">
{NEWSIMAGE}
<div class="carousel-caption">
<small>{NEWSDATE}</small>
<h1>{NEWSTITLE}</h1>
</div>
</div><!-- End Item -->';;
$navTemplate = '<li data-target="#news-carousel" data-slide-to="{COUNT}" class="{ACTIVE}"><a href="#">{NEWSSUMMARY}</a></li>';
$nobody_regexp = "'(^|,)(".str_replace(",", "|", e_UC_NOBODY).")(,|$)'";
$nobody_regexp = "'(^|,)(".str_replace(",", "|", e_UC_NOBODY).")(,|$)'";
$query = "
$query = "
SELECT n.*, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon,
nc.category_meta_keywords, nc.category_meta_description
FROM #news AS n
LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") AND n.news_start < ".time()."
AND (n.news_end=0 || n.news_end>".time().") AND FIND_IN_SET(5,n.news_render_type)
AND (n.news_end=0 || n.news_end>".time().") ";
if(!empty($parms['category']))
{
$query .= " AND n.news_category = ".intval($parms['category']);
}
if(vartrue($parms['source']) == 'assigned')
{
$query .= " AND FIND_IN_SET(5,n.news_render_type) ";
}
if(vartrue($parms['source']) == 'sticky')
{
$query .= " AND n.news_sticky = 1 ";
}
$query .= " AND n.news_thumbnail != '' ";
$query .= "
ORDER BY n.news_sticky DESC, n.news_datestamp DESC
LIMIT 5";
LIMIT ".$limit;
$data = $sql->retrieve($query,true);
if(count($data) < 1)
if(empty($data))
{
e107::getMessage()->addDebug( "No News items found with 'carousel' as the template ")->render();
return;
@@ -90,43 +67,68 @@ if(count($data) < 1)
$count = 0;
$tp->setThumbSize(800,0);
// $tp->setThumbSize(800,0);
$sc = e107::getScBatch('news');
$text = '';
foreach($data as $row)
{
$tmp = explode(",",$row['news_thumbnail']); // fix for multiple
if($video = $tp->toVideo($tmp[0],array('thumb'=>'tag', 'w'=>800)))
{
$imgTag = $video;
}
else
{
$img = $tp->thumbUrl($tmp[0]);
$imgTag = '<img class="img-responsive" src="'.$img.'">';
}
$sc->setScVar('news_item', $row);
$vars = array(
'NEWSTITLE' => $tp->toHtml($row['news_title'],false, 'TITLE'),
'NEWSSUMMARY' => vartrue($row['news_summary'],$row['news_title']),
'NEWSDATE' => $tp->toDate($row['news_datestamp'],'dd MM, yyyy'),
'ACTIVE' => ($count == 0) ? 'active' : '',
'COUNT' => $count,
'NEWSIMAGE' => '<a href="'.e107::getUrl()->create('news/view/item',$row).'">'.$imgTag.'</a>'
'{ACTIVE}' => ($count == 0) ? 'active' : '',
'{COUNT}' => $count,
);
$text .= $tp->simpleParse($NEWS_MENU_TEMPLATE['carousel']['item'], $vars);
$nav[] = $tp->simpleParse($navTemplate, $vars);
$parsed = str_replace(array_keys($vars), $vars, $template['item']);
$navTemplate = str_replace(array_keys($vars), $vars,$template['nav']);
$nav[] = $tp->parseTemplate($navTemplate , true, $sc);
$parsed = $tp->parseTemplate($parsed,true, $sc);
$text .= $parsed;
$count++;
}
$header = $NEWS_MENU_TEMPLATE['carousel']['start'];
$header = $template['start'];
$footer = str_replace("{NAV}", implode("\n",$nav), $NEWS_MENU_TEMPLATE['carousel']['end']);
e107::getRender()->tablerender('',$header.$text.$footer,'news-carousel'); //TODO Tablerender().
$footer = str_replace("{NAV}", implode("\n",$nav), $template['end']);
if(!empty($parms['caption']))
{
e107::getRender()->tablerender($parms['caption'], ($header.$text.$footer) ,'news-carousel'); //TODO Tablerender().
}
else
{
echo $header.$text.$footer;
}
e107::js('footer-inline',"
clickEvent = false;
$('#news-carousel').on('click', '#news-carousel-nav a', function() {
clickEvent = true;
$('#news-carousel-nav li').removeClass('active');
$(this).parent().addClass('active');
}).on('slid.bs.carousel', function(e) {
if(!clickEvent) {
var count = $('#news-carousel-nav').children().length -1;
var current = $('#news-carousel-nav li.active');
current.removeClass('active').next().addClass('active');
var id = parseInt(current.data('slide-to'));
if(count == id) {
$('#news-carousel-nav li').first().addClass('active');
}
}
clickEvent = false;
});"
);