SimplePortal

Support => English Support => Topic started by: SMiller on January 11, 2015, 10:00:10 PM

Title: Adjust RSS Feed block height?
Post by: SMiller on January 11, 2015, 10:00:10 PM
Block type "RSS Feed"
Show title checked
Show content checked
Items to show: 5
Character limit: 180
Not Collapsible unchecked
Active checked
Show block on Portal
Is a Right-Block.
Default Title Class: catbg
Default Body Class: windowbg


It has a vertical scroll bar, which I don't want. I want it to show the entire contents of its block.

Is there any way to set it's height?

Thanks.
 ;D
Title: Re: Adjust RSS Feed block height?
Post by: ♦ Ninja ZX-10RR ♦ on January 12, 2015, 06:51:28 AM
You have to insert the css height value that you want into the "Custom body style" box :)
Otherwise you can refer here if you want more complex results: http://simpleportal.net/index.php?topic=13732.0
Title: Re: Adjust RSS Feed block height?
Post by: SMiller on January 12, 2015, 11:19:12 PM
Thanks Ninja...

but strangely, if I define a height for the RSS Feed type block... it only expands the height of the background, and the scroll bar maintains it's default (way too small for my needs) size. So only the top half of the block is the scrolling text, the bottom half is just empty background. See attached pic. Grr.
:(

ps. and it only lets me use px. I can't set the height by auto or %. Not a biggie, but hey.
Title: Re: Adjust RSS Feed block height?
Post by: Chen Zhen on January 13, 2015, 01:24:20 AM
SMiller,

Instead of using a rss feed block, create a custom PHP block containing the following code:

Code: [Select]
// specs
$feed = 'http://mahjongtime.com/rss.aspx'; // rss feed url
$items = 5; // number of items to display
$max_chars = 500; // 0 for no description (only titles)

// rss class
class rss {
var $feed;

function rss($feed) {
$this->feed = $feed;
}

function parse($max_chars = 0) {
global $settings;
$rss = simplexml_load_file($this->feed);
$rss_split = array();
foreach ($rss->channel->item as $item) {
$title = (string) $item->title; // Title
$link   = (string) $item->link; // Url Link
$description = (string) $item->description; //Description
$description = !empty($max_chars) && strlen($description) > $max_chars ? substr($description, 0, ($max_chars - 3)) . '...' : (!empty($max_chars) ? $description : '');
$rss_split[] = '
<div style="border-bottom: 1px solid #DDD;padding: 3px;">
<span style="padding-top: 5px;">
<img src="' . $settings['default_theme_url'] . '/images/sp/post.png" alt="post" />
<a style="font-weight: bold;" href="'.$link.'" target="_blank" title="">' . $title . '</a>
</span>
<br />
<span>
' . $description . '
</span>
</div>';
}

return $rss_split;
}

function display($numrows, $max_chars = 0) {
$rss_split = $this->parse($max_chars);
$i = 0;
$rss_data = '
<div style="float:left; width:100%; padding:1px;">
<div style="text-align:left; padding:0px;">';
while ($i < $numrows) {
$rss_data .= $rss_split[$i];
$i++;
}

$trim = str_replace('', '', $this->feed);
$user = str_replace('&lang=en-us&format=rss_200','',$trim);
$rss_data.= '
</div>
</div>';
return $rss_data;
}
}

echo '<div>';
$feedlist = new rss($feed);
echo $feedlist->display(abs($items), abs($max_chars));
echo '</div>';

... change the specs to what you prefer.

Regards.
Title: Re: Adjust RSS Feed block height?
Post by: ♦ Ninja ZX-10RR ♦ on January 13, 2015, 02:01:35 AM
I would have gone a different way but I guess that will work, too ;D
My way would have been to recode the block's css with the method described by SiNaN and put padding-bottom to force the content to stay lower than it is now. I am 99,99% sure it should work too since I did more or less the same things, myself. Either way as long as you are happy with the results, will be good :)
Title: Re: Adjust RSS Feed block height?
Post by: SMiller on January 13, 2015, 11:50:00 AM
Instead of using a rss feed block, create a custom PHP block containing the following code:

Thanks Chen Zhen. I copy/pasted your entire code into a custom php block verbatim, and even double-checked the rss url, but it shows up as an empty block with just a title.

Maybe a minor syntax error or ?
Title: Re: Adjust RSS Feed block height?
Post by: Chen Zhen on January 13, 2015, 11:42:11 PM
SMiller,

  That last code block was working for me without issue both on a local & live install.
No matter, try the PHP code below:

Code: [Select]
// specs
$feed = 'http://mahjongtime.com/rss.aspx'; // rss feed url
$items = 5; // number of items to display
$max_chars = 500; // 0 for no description (only titles)
$allow_tags = '<a>'; // allow HTML tags for rss post data (ie. hyperlinks)? format example: $allow_tags = '<a><p><div>';

// rss class
if (!class_exists('sportal_rss'))
{
class sportal_rss
{
var $feed;

function sportal_rss($xml)
{
$this->feed = $xml;
}

function sportal_parse($no_strip, $max_chars = 0)
{
global $settings;
$rss = simplexml_load_string($this->feed);
$rss_split = array();
foreach ($rss->channel->item as $item)
{
$title = (string)$item->title;
$link   = (string)$item->link;
$description = strip_tags((string)$item->description, $no_strip);
$description = !empty($max_chars) && strlen($description) > $max_chars ? substr($description, 0, ($max_chars - 3)) . '...' : (!empty($max_chars) ? $description : '');
$rss_split[] = '
<div style="border-bottom: 1px solid #DDD;padding: 3px;">
<span style="padding-top: 5px;">
<img src="' . $settings['default_theme_url'] . '/images/sp/post.png" alt="post" />
<a style="font-weight: bold;" href="' . preg_replace('/\s+/', '', $link) . '" target="_blank" title="">' . $title . '</a>
</span>
<br />
<span>
' . $description . '
</span>
</div>';
}

return $rss_split;
}

function sportal_display($no_strip, $numrows, $max_chars = 0)
{
$rss_split = $this->sportal_parse($no_strip, $max_chars);
$i = 0;
$rss_data = '
<div style="float:left; width:100%; padding:1px;">
<div style="text-align:left; padding:0px;">';
while ($i < $numrows)
{
$rss_data .= $rss_split[$i];
$i++;
}

$trim = str_replace('', '', $this->feed);
$user = str_replace('&lang=en-us&format=rss_200', '', $trim);
$rss_data.= '
</div>
</div>';
return $rss_data;
}
}
}

global $sourcedir, $modSettings, $context;
require_once($sourcedir . '/Subs-Package.php');
list($sportal_xml, $block_id, $no_strip) = array('', strtolower(preg_replace('~[^a-z0-9_]+~i', '_', $feed)), $allow_tags);
libxml_use_internal_errors();
if (($sportal_xml = cache_get_data('portalRss' . $block_id, 90)) == null)
{
$xml = fetch_web_data($feed) ? fetch_web_data($feed) : false;
$feedlist = new sportal_rss($xml);
$sportal_xml = '<div>' . $feedlist->sportal_display($no_strip, abs($items), abs($max_chars)) . '</div>';
if (!empty($modSettings['cache_enable']))
cache_put_data('portalRss' . $block_id, $sportal_xml, 90);
}

echo !empty($sportal_xml) ? $sportal_xml : '<div>Failed to recover XML/rss stream.</div>';

Changes:


Title: Re: Adjust RSS Feed block height?
Post by: ♦ Ninja ZX-10RR ♦ on January 14, 2015, 07:38:19 AM
Heck, just a congratz for that Chen Zhen!
Title: Re: Adjust RSS Feed block height?
Post by: SMiller on January 14, 2015, 10:30:51 AM
No matter, try the PHP code below:

Nailed it! Works awesomely. Thanks Chen Zhen for taking the time, and all that extra effort.

 :applause:

 :mouse:
Title: Re: Adjust RSS Feed block height?
Post by: Radius on April 20, 2015, 02:58:13 AM
Hello everybody,
I put the first php code in this topic of Chen Zhen. It works perfectly. But how can I make pictures bigger? Or at least can be in the middle?
Title: Re: Adjust RSS Feed block height?
Post by: ♦ Ninja ZX-10RR ♦ on April 20, 2015, 01:10:04 PM
Please give me your site URL ;)
Title: Re: Adjust RSS Feed block height?
Post by: Chen Zhen on April 20, 2015, 01:58:10 PM

Radius,

Try this code (replace your feed url):
Code: [Select]
// specs
$feed = 'http://mahjongtime.com/rss.aspx'; // rss feed url
$items = 5; // number of items to display
$max_chars = 500; // 0 for no description (only titles)
$allow_tags = '<a><img>'; // allow HTML tags for rss post data (ie. hyperlinks)? format example: $allow_tags = '<a><p><div>';

// regex for image style attributes
$img_style = 'display: block; margin-left: auto; margin-right: auto;';
$regex_search = array("~style=[\'\"][^\"|^\']*[\'\"]~", "~<img~");
$regex_replace = array('', '<img style="' . $img_style . '"');

// rss class
if (!class_exists('sportal_rss'))
{
class sportal_rss
{
var $feed;

function sportal_rss($xml)
{
$this->feed = $xml;
}

function sportal_parse($no_strip, $max_chars = 0)
{
global $settings;
$rss = simplexml_load_string($this->feed);
$rss_split = array();
foreach ($rss->channel->item as $item)
{
$title = (string)$item->title;
$link   = (string)$item->link;
$description = strip_tags((string)$item->description, $no_strip);
$description = !empty($img_style) && !empty($regex_search) && !empty($regex_replace) ? preg_replace($regex_search, $regex_replace, $description) : $description;
$description = !empty($max_chars) && strlen($description) > $max_chars ? substr($description, 0, ($max_chars - 3)) . '...' : (!empty($max_chars) ? $description : '');
$rss_split[] = '
<div style="border-bottom: 1px solid #DDD;padding: 3px;">
<span style="padding-top: 5px;">
<img src="' . $settings['default_theme_url'] . '/images/sp/post.png" alt="post" />
<a style="font-weight: bold;" href="' . preg_replace('/\s+/', '', $link) . '" target="_blank" title="">' . $title . '</a>
</span>
<br />
<span>
' . $description . '
</span>
</div>';
}

return $rss_split;
}

function sportal_display($no_strip, $numrows, $max_chars = 0)
{
$rss_split = $this->sportal_parse($no_strip, $max_chars);
$i = 0;
$rss_data = '
<div style="float:left; width:100%; padding:1px;">
<div style="text-align:left; padding:0px;">';
while ($i < $numrows)
{
$rss_data .= $rss_split[$i];
$i++;
}

$trim = str_replace('', '', $this->feed);
$user = str_replace('&lang=en-us&format=rss_200', '', $trim);
$rss_data.= '
</div>
</div>';
return $rss_data;
}
}
}

global $sourcedir, $modSettings, $context;
require_once($sourcedir . '/Subs-Package.php');
list($sportal_xml, $block_id, $no_strip) = array('', strtolower(preg_replace('~[^a-z0-9_]+~i', '_', $feed)), $allow_tags);
libxml_use_internal_errors();
if (($sportal_xml = cache_get_data('portalRss' . $block_id, 90)) == null)
{
$xml = fetch_web_data($feed) ? fetch_web_data($feed) : false;
$feedlist = new sportal_rss($xml);
$sportal_xml = '<div>' . $feedlist->sportal_display($no_strip, abs($items), abs($max_chars)) . '</div>';
if (!empty($modSettings['cache_enable']))
cache_put_data('portalRss' . $block_id, $sportal_xml, 90);
}

echo !empty($sportal_xml) ? $sportal_xml : '<div>Failed to recover XML/rss stream.</div>';

The images should be centred with that code. If you want specific image dimensions then adjust the $img_style attributes.

Regards.
Title: Re: Adjust RSS Feed block height?
Post by: Radius on April 20, 2015, 04:48:30 PM

Radius,

Try this code (replace your feed url):
code


Thanks for the quick reply, but now it's worse
Title: Re: Adjust RSS Feed block height?
Post by: ♦ Ninja ZX-10RR ♦ on April 20, 2015, 06:15:59 PM
Please give me your site URL ;)
At least we can both have a look in live :)
Title: Re: Adjust RSS Feed block height?
Post by: Chen Zhen on April 20, 2015, 07:13:12 PM
Radius,

  My apologies as I did not test the previous block code that I posted. It could never work because I did not pass the newer assigned variables to the 2 functions being used.

  Here is a revised block that uses a combo of dom & regex to achieve what you requested.

Code: [Select]
// specs
$feed = 'http://rss.canoe.ca/Slam/Hockey/home.xml'; // rss feed url
$items = 5; // number of items to display
$max_chars = 500; // 0 for no description (only titles)
$allow_tags = '<a><img>'; // allow HTML tags for rss post data (ie. hyperlinks)? format example: $allow_tags = '<a><p><div>';

// image style attributes
$img_style ='display: block; margin-left: auto; margin-right: auto;';

// replace img style with dom & regex
if (!function_exists('replace_img_style'))
{
function replace_img_style($html, $new_style)
{
$doc = new DOMDocument();
$doc->loadHTML(htmlentities($html));

$tags = $doc->getElementsByTagName('img');
if(count($tags) > 0)
{
$tag = $tags->item(0);
$html = preg_replace(array("~style=[\'\"][^\"|^\']*[\'\"]~", '~<img~'), array('', '<img style="' . $new_style . '"'), $html);
}

return $html;
}
}

// rss class
if (!class_exists('sportal_rss'))
{
class sportal_rss
{
var $feed;

function sportal_rss($xml)
{
$this->feed = $xml;
}

function sportal_parse($no_strip, $max_chars = 0, $img_style)
{
global $settings;
$rss = simplexml_load_string($this->feed);
$rss_split = array();
foreach ($rss->channel->item as $item)
{
$title = (string)$item->title;
$link   = (string)$item->link;
$description = strip_tags((string)$item->description, $no_strip);
$description = replace_img_style($description, $img_style);
$description = !empty($max_chars) && strlen($description) > $max_chars ? substr($description, 0, ($max_chars - 3)) . '...' : (!empty($max_chars) ? $description : '');
$rss_split[] = '
<div style="border-bottom: 1px solid #DDD;padding: 3px;">
<span style="padding-top: 5px;">
<img src="' . $settings['default_theme_url'] . '/images/sp/post.png" alt="post" />
<a style="font-weight: bold;" href="' . preg_replace('/\s+/', '', $link) . '" target="_blank" title="">' . $title . '</a>
</span>
<br />
<span>
' . $description . '
</span>
</div>';
}

return $rss_split;
}

function sportal_display($img_style, $no_strip, $numrows, $max_chars = 0)
{
$rss_split = $this->sportal_parse($no_strip, $max_chars, $img_style);
$i = 0;
$rss_data = '
<div style="float:left; width:100%; padding:1px;">
<div style="text-align:left; padding:0px;">';
while ($i < $numrows)
{
$rss_data .= $rss_split[$i];
$i++;
}

$trim = str_replace('', '', $this->feed);
$user = str_replace('&lang=en-us&format=rss_200', '', $trim);
$rss_data.= '
</div>
</div>';
return $rss_data;
}
}
}

global $sourcedir, $modSettings, $context;
require_once($sourcedir . '/Subs-Package.php');
list($sportal_xml, $block_id, $no_strip) = array('', strtolower(preg_replace('~[^a-z0-9_]+~i', '_', $feed)), $allow_tags);
libxml_use_internal_errors();
if (($sportal_xml = cache_get_data('portalRss' . $block_id, 90)) == null)
{
$xml = fetch_web_data($feed) ? fetch_web_data($feed) : false;
$feedlist = new sportal_rss($xml);
$sportal_xml = '<div>' . $feedlist->sportal_display($img_style, $no_strip, abs($items), abs($max_chars)) . '</div>';
if (!empty($modSettings['cache_enable']))
cache_put_data('portalRss' . $block_id, $sportal_xml, 90);
}

echo !empty($sportal_xml) ? $sportal_xml : '<div>Failed to recover XML/rss stream.</div>';

Regards.
Title: Re: Adjust RSS Feed block height?
Post by: Radius on April 21, 2015, 03:04:40 AM
Thanks Chen Zhen. Now the pictures are in the middle.
Please help me a little bit more. Tell me please how to resize pictures with $img_style attributes? Just give me an example.
And another question: if I stop RSS feed from the source, admin panel in SMF begins to fill with errors, can you advise me something? In error log writes: public_html/Themes/default/languages/Aeva.english.php
but my theme is not default.....
Anyway, if this question is not for you, just let me know.
Title: Re: Adjust RSS Feed block height?
Post by: Chen Zhen on April 21, 2015, 05:25:43 AM

Radius,

Adjust height/width as necessary

Code: [Select]
$img_style ='display: block; margin-left: auto; margin-right: auto;width: 200px;height: 160px;';



The errors appear to have something to do with the Aeva modification.
Can you please post the image of the error log without hiding so much of the info?
Just block the first 2 directory paths but leave the rest so I can see what possible file & lines is causing an error.

Regards.
Title: Re: Adjust RSS Feed block height?
Post by: ♦ Ninja ZX-10RR ♦ on April 21, 2015, 07:38:17 AM
Given that Aeva has a *SERIOUS* security issue and that it has been removed from the official site, I *STRONGLY* advise you to uninstall it as soon as possible unless you want to risk to get hacked. :(
Ref: http://www.simplemachines.org/community/index.php?topic=200401.msg3779235#msg3779235
Title: Re: Adjust RSS Feed block height?
Post by: Radius on April 21, 2015, 10:40:26 AM
Given that Aeva has a *SERIOUS* security issue and that it has been removed from the official site, I *STRONGLY* advise you to uninstall it as soon as possible unless you want to risk to get hacked. :(
Ref: http://www.simplemachines.org/community/index.php?topic=200401.msg3779235#msg3779235

Thanks, I did not know that there is a risk in this module

@Chen Zhen Thank you very much for your help!

Title: Re: Adjust RSS Feed block height?
Post by: ♦ Ninja ZX-10RR ♦ on April 21, 2015, 11:22:36 AM
You're welcome, I suggest you to install one of the many galleries around ;)
SimplePortal 2.3.8 © 2008-2024, SimplePortal