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

Improved control over news images and video. Separate css classes added for each. eg. news-image-1 , news-video-3

This commit is contained in:
Cameron
2014-02-04 06:21:05 -08:00
parent 182233238f
commit 8d689f2d94
4 changed files with 107 additions and 56 deletions

View File

@@ -61,9 +61,14 @@ class news_shortcodes extends e_shortcode
function sc_newsbody($parm) function sc_newsbody($parm)
{ {
$tp = e107::getParser(); $tp = e107::getParser();
e107::getBB()->setClass("news"); e107::getBB()->setClass("news"); // For automatic bbcode image resizing.
$news_body = $tp->toHTML($this->news_item['news_body'], true, 'BODY, fromadmin', $this->news_item['news_author']);
if($this->news_item['news_extended'] && (isset($_POST['preview']) || $this->param['current_action'] == 'extend') && $parm != 'noextend') if($parm != 'extended')
{
$news_body = $tp->toHTML($this->news_item['news_body'], true, 'BODY, fromadmin', $this->news_item['news_author']);
}
if($this->news_item['news_extended'] && (isset($_POST['preview']) || $this->param['current_action'] == 'extend') && ($parm != 'noextend' || $parm != 'body'))
{ {
$news_body .= $tp->toHTML($this->news_item['news_extended'], true, 'BODY, fromadmin', $this->news_item['news_author']); $news_body .= $tp->toHTML($this->news_item['news_extended'], true, 'BODY, fromadmin', $this->news_item['news_author']);
} }
@@ -160,7 +165,10 @@ class news_shortcodes extends e_shortcode
/** /**
* Render a news navigation link * Render a news navigation link
* @param $parm array * @param $parm array
* @example {NEWSNAVLINK: list=all} * @example {NEWSNAVLINK: list=all} // A list of all items - usually headings and thumbnails
* @example {NEWSNAVLINK: list=category} // A list of all items - usually headings and thumbnails from the current category.
* @example {NEWSNAVLINK: items=category} // News items for current category.
* @example {NEWSNAVLINK: text=myCaption} // Default News item view. ie. news.php
*/ */
function sc_newsnavlink($parm='') //TODO add more options. function sc_newsnavlink($parm='') //TODO add more options.
{ {
@@ -169,18 +177,14 @@ class news_shortcodes extends e_shortcode
{ {
$url = e107::getUrl()->create('news/list/all'); $url = e107::getUrl()->create('news/list/all');
} }
elseif(varset($parm['items']) == 'all') // default page of news items, one after the other. (depending on news prefs) elseif(varset($parm['list']) == 'category')
{
$url = e107::getUrl()->create('news/list/items');
}
elseif(varset($parm['items']) == 'category') // news items for current category.
{
$url = e107::getUrl()->create('news/list/category', $this->news_item);
}
elseif(varset($parm['list']) == 'category') // A list of all items - usually headings and thumbnails from the current category.
{ {
$url = e107::getUrl()->create('news/list/short', $this->news_item); //default for now. $url = e107::getUrl()->create('news/list/short', $this->news_item); //default for now.
} }
elseif(varset($parm['items']) == 'category')
{
$url = e107::getUrl()->create('news/list/category', $this->news_item);
}
else else
{ {
$url = e107::getUrl()->create('news/list/items'); // default for now. $url = e107::getUrl()->create('news/list/items'); // default for now.
@@ -410,23 +414,16 @@ class news_shortcodes extends e_shortcode
*/ */
function sc_newsthumbnail($parm = '') //TODO Add support {NEWSTHUMBNAIL: x=y} format function sc_newsthumbnail($parm = '') //TODO Add support {NEWSTHUMBNAIL: x=y} format
{ {
$newsThumb = $this->handleMultiple($parm); $tmp = $this->handleMultiple($parm);
$newsThumb = $tmp['file'];
$class = 'news-thumbnail-'.$tmp['count'];
if(!$newsThumb && $parm != 'placeholder') if(!$newsThumb && $parm != 'placeholder')
{ {
return ''; return '';
} }
if(empty($parm)) // get {SETIMAGE} values when no parm provided.
{
$parm = '|aw='.e107::getParser()->thumbWidth().'&ah='.e107::getParser()->thumbHeight();
}
if($vThumb = e107::getParser()->toVideo($newsThumb, array('thumb'=>'src'))) if($vThumb = e107::getParser()->toVideo($newsThumb, array('thumb'=>'src')))
{ {
$src = $vThumb; $src = $vThumb;
@@ -436,6 +433,11 @@ class news_shortcodes extends e_shortcode
{ {
$parms = eHelper::scDualParams($parm); $parms = eHelper::scDualParams($parm);
if(empty($parms[2])) // get {SETIMAGE} values when no parm provided.
{
$parms[2] = array('aw' => e107::getParser()->thumbWidth(), 'ah'=> e107::getParser()->thumbHeight());
}
if(isset($parms[2]['legacy']) && $parms[2]['legacy']==true) // Legacy mode - swap out thumbnails for actual images and update paths. if(isset($parms[2]['legacy']) && $parms[2]['legacy']==true) // Legacy mode - swap out thumbnails for actual images and update paths.
{ {
@@ -471,15 +473,15 @@ class news_shortcodes extends e_shortcode
break; break;
case 'tag': case 'tag':
return "<img class='news_image' src='".$src."' alt='' style='".$this->param['thumbnail']."' />"; return "<img class='news_image ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' />";
break; break;
case 'img': case 'img':
return "<a href='".$_src."' rel='external image'><img class='news_image' src='".$src."' alt='' style='".$this->param['thumbnail']."' /></a>"; return "<a href='".$_src."' rel='external image'><img class='news_image ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' /></a>";
break; break;
default: default:
return "<a href='".e107::getUrl()->create('news/view/item', $this->news_item)."'><img class='news_image img-responsive img-rounded' src='".$src."' alt='' style='".$this->param['thumbnail']."' /></a>"; return "<a href='".e107::getUrl()->create('news/view/item', $this->news_item)."'><img class='news_image img-responsive img-rounded ".$class."' src='".$src."' alt='' style='".$this->param['thumbnail']."' /></a>";
break; break;
} }
} }
@@ -521,9 +523,10 @@ class news_shortcodes extends e_shortcode
function sc_newsvideo($parm='') function sc_newsvideo($parm='')
{ {
$item = $this->handleMultiple($parm); $tmp = $this->handleMultiple($parm,'video');
$file = $tmp['file'];
if($video = e107::getParser()->toVideo($item)) if($video = e107::getParser()->toVideo($file, array('class'=> 'news-video-'.$tmp['count'])))
{ {
return $video; return $video;
} }
@@ -531,14 +534,31 @@ class news_shortcodes extends e_shortcode
} }
function handleMultiple($parm) function handleMultiple($parm,$type='image')
{ {
if(!vartrue($this->news_item['news_thumbnail']) ) if(!vartrue($this->news_item['news_thumbnail']) )
{ {
return; return;
} }
$tp = e107::getParser();
$media = explode(",", $this->news_item['news_thumbnail']); $media = explode(",", $this->news_item['news_thumbnail']);
$list = array();
foreach($media as $file)
{
if($tp->isVideo($file))
{
$list['video'][] = $file;
}
else
{
$list['image'][] = $file;
}
}
if(is_string($parm) || !vartrue($parm['item'])) if(is_string($parm) || !vartrue($parm['item']))
{ {
@@ -550,7 +570,10 @@ class news_shortcodes extends e_shortcode
} }
return varset($media[$item]); $file = varset($list[$type][$item]);
$count = $item;
return array('file'=>$file, 'count'=>varset($parm['item'],1));
} }
@@ -574,12 +597,16 @@ class news_shortcodes extends e_shortcode
$parm = array('type'=> $parm); $parm = array('type'=> $parm);
} }
$srcPath = $this->handleMultiple($parm); $tmp = $this->handleMultiple($parm);
$srcPath = $tmp['file'];
if($video = e107::getParser()->toVideo($this->news_item['news_thumbnail'])) $class = "news_image news-image img-responsive img-rounded";
$class .= ' news-image-'.$tmp['count'];
if($tp->isVideo($this->news_item['news_thumbnail']))
{ {
return; return;
} }
else else
{ {
@@ -611,7 +638,7 @@ class news_shortcodes extends e_shortcode
return; return;
} }
$class = "news_image news-image img-responsive img-rounded";
switch(vartrue($parm['type'])) switch(vartrue($parm['type']))
{ {

View File

@@ -2815,6 +2815,19 @@ class e_parser
/**
* Check if a file is an video or not.
* @param $file string
* @return boolean
*/
function isVideo($file)
{
$ext = pathinfo($file,PATHINFO_EXTENSION);
return ($ext == 'youtube') ? true : false;
}
/** /**
* Display a Video file. * Display a Video file.
@@ -2829,6 +2842,7 @@ class e_parser
if($type == 'youtube') if($type == 'youtube')
{ {
$video = '<iframe width="560" height="315" src="//www.youtube.com/embed/'.$id.'" style="border:0px" allowfullscreen></iframe>'; $video = '<iframe width="560" height="315" src="//www.youtube.com/embed/'.$id.'" style="border:0px" allowfullscreen></iframe>';
$thumbSrc = "https://i1.ytimg.com/vi/".$id."/0.jpg"; $thumbSrc = "https://i1.ytimg.com/vi/".$id."/0.jpg";
@@ -2847,7 +2861,7 @@ class e_parser
return '<div class="video-responsive video-thumbnail thumbnail">'.$video.'</div>'; return '<div class="video-responsive video-thumbnail thumbnail">'.$video.'</div>';
} }
return '<div class="'.vartrue($parm['class'],'video-responsive').'">'.$video.'</div>'; return '<div class="video-responsive '.vartrue($parm['class']).'">'.$video.'</div>';
} }
if($type == 'mp4') //TODO FIXME if($type == 'mp4') //TODO FIXME

View File

@@ -121,30 +121,39 @@ $NEWS_TEMPLATE['view']['item'] = '
<div class="col-md-8 text-right options">{GLYPH=tags} &nbsp;{NEWSTAGS} &nbsp; {GLYPH=folder-open} &nbsp;{NEWSCATEGORY} </div> <div class="col-md-8 text-right options">{GLYPH=tags} &nbsp;{NEWSTAGS} &nbsp; {GLYPH=folder-open} &nbsp;{NEWSCATEGORY} </div>
</div> </div>
<hr> <hr>
{NEWSIMAGE: item=1&placeholder=1} {NEWSIMAGE: item=1}
{NEWSVIDEO: item=1}
<hr> <hr>
<p class="lead">{NEWSSUMMARY}</p> <p class="lead">{NEWSSUMMARY}</p>
<hr> <hr>
<div class="body"> <div class="body">
{NEWSVIDEO: item=1} <!-- if it exists in position 1 -->
{NEWSBODY} {NEWSVIDEO: item=2}
{NEWSVIDEO: item=3}
{NEWSBODY=body}
<br /> <br />
<div class="row"> {SETIMAGE: w=600&h=600}
<div class="col-md-3">{NEWSIMAGE: item=2}</div>
<div class="col-md-3">{NEWSIMAGE: item=3}</div> <div class="row news-images-1">
<div class="col-md-3">{NEWSIMAGE: item=4}</div> <div class="col-md-6">{NEWSIMAGE: item=2}</div>
<div class="col-md-3">{NEWSIMAGE: item=5}</div> <div class="col-md-6">{NEWSIMAGE: item=3}</div>
</div>
<div class="row news-images-2">
<div class="col-md-6">{NEWSIMAGE: item=4}</div>
<div class="col-md-6">{NEWSIMAGE: item=5}</div>
</div> </div>
{NEWSVIDEO: item=2} <!-- if it exists in position 2 --> {NEWSVIDEO: item=4}
{EXTENDED}
{NEWSVIDEO: item=3}
{NEWSVIDEO: item=4}
{NEWSVIDEO: item=5} {NEWSVIDEO: item=5}
<div class="body-extended">
{NEWSBODY=extended}
</div>
</div> </div>
<hr> <hr>

View File

@@ -320,6 +320,7 @@ if ($action == 'cat' || $action == 'all' || vartrue($_GET['tag']))
$text .= "<div class='center news-list-footer'><a class='btn btn-default' href='".e107::getUrl()->create('news/list/all')."'>".LAN_NEWS_84."</a></div>"; $text .= "<div class='center news-list-footer'><a class='btn btn-default' href='".e107::getUrl()->create('news/list/all')."'>".LAN_NEWS_84."</a></div>";
ob_start(); ob_start();
$ns->tablerender($NEWSLISTTITLE, $text, 'news'); $ns->tablerender($NEWSLISTTITLE, $text, 'news');
$cache_data = ob_get_flush(); $cache_data = ob_get_flush();