collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 478
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

Installation errors? Mod incompatibilities? Upgrade problems? Make your way over to the Install and Upgrade Support board for all your solutions!

Author Topic: rss Block but not the Original  (Read 7112 times)

0 Members and 1 Guest are viewing this topic.

Offline Nabil

  • Full Member
  • ***
  • Posts: 110
  • SMF Version: 1.1.7
  • SP Version: 2.2.1
rss Block but not the Original
« on: December 30, 2008, 02:09:15 PM »
hi ,
I want to add a php block with rss display function , I actually not using the Original rss block with Simple Portal, because I want to change the way it looks , add some div styles, display it with different colors than the Original , so what is the function I should use in the php block in order to display rss feeds from Websites, I know that this function I mean the rss function is there in the Sportal1-1.php in the Source folder , but I'm not sure how to use it for my custom php block , does anyone know how ?
any help will be appreciated . 

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: rss Block but not the Original
« Reply #1 on: February 03, 2009, 07:51:38 AM »
You can use built-in functions to fetch the data and modify the look as you wish. You can use these codes in a PHP block:

Code: [Select]
$feed = 'FEEDURL';

$rss_data = array();
$rss_current = "";
$rss_counter = 0;
$rss_main = '';

$xml_parser = xml_parser_create();

xml_set_element_handler($xml_parser, "sp_startElement", "sp_endElement");

xml_set_character_data_handler($xml_parser, "sp_characterData");

if (!($fp = @fopen($feed, "r")))
return;

while ($data = fread($fp, 4096))
{
if (!xml_parse($xml_parser, $data, feof($fp)))
{
$xmlerr = (sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)), 
xml_get_current_line_number($xml_parser)));

break;
}
}

fclose($fp);

xml_parser_free($xml_parser);

if (!empty($xmlerr))
{
echo $xmlerr;

return;
}

if (empty($rss_data))
return;

if (!empty($rss_data['IMAGE']))
echo '<a href="', $rss_data['LINK'], '" target="_blank"><img src="', $rss_data['IMAGE']['URL'], '" align="middle" alt="', $rss_data['IMAGE']['TITLE'], '" /></a>', $rss_data['TITLE'], '<br /><br />';
else
echo $rss_data['TITLE'], '<br />';

echo '<em>', $rss_data['DESCRIPTION'], '</em><br />';

if (isset($rss_data['ITEMS']))
{
if (count($rss_data['ITEMS']) > 0)
{
for($i = 0; $i < count($rss_data['ITEMS']); $i++)
{
echo '<span style="font-weight: bold;"><a href="', $rss_data['ITEMS'][$i]['LINK'], '" target="_blank">', $rss_data['ITEMS'][$i]['TITLE'], '</a></span><br />';
echo html_entity_decode($rss_data['ITEMS'][$i]['DESCRIPTION']) . '<br />';
if ($i != count($rss_data['ITEMS']) - 1)
echo '<hr />';
}
}
else
return;
}

The part you should modify is this:

Code: [Select]
if (!empty($rss_data['IMAGE']))
echo '<a href="', $rss_data['LINK'], '" target="_blank"><img src="', $rss_data['IMAGE']['URL'], '" align="middle" alt="', $rss_data['IMAGE']['TITLE'], '" /></a>', $rss_data['TITLE'], '<br /><br />';
else
echo $rss_data['TITLE'], '<br />';

echo '<em>', $rss_data['DESCRIPTION'], '</em><br />';

if (isset($rss_data['ITEMS']))
{
if (count($rss_data['ITEMS']) > 0)
{
for($i = 0; $i < count($rss_data['ITEMS']); $i++)
{
echo '<span style="font-weight: bold;"><a href="', $rss_data['ITEMS'][$i]['LINK'], '" target="_blank">', $rss_data['ITEMS'][$i]['TITLE'], '</a></span><br />';
echo html_entity_decode($rss_data['ITEMS'][$i]['DESCRIPTION']) . '<br />';
if ($i != count($rss_data['ITEMS']) - 1)
echo '<hr />';
}
}
else
return;
}

Also the $feed variable at the top of course.
And slowly, you come to realize... It's all as it should be...

Offline 130860

  • Super Handsome Language Coordinator
  • Comrade
  • *
  • Posts: 1769
  • Gender: Male
  • You and I are not the same class of pirate!
  • SMF Version: 2 RC3
  • SP Version: 2.3.2
Re: rss Block but not the Original
« Reply #2 on: February 03, 2009, 10:50:07 AM »
Thank you for posting this !! I was looking for something like that  ;P

thanks !!!     :applause:

Offline Nabil

  • Full Member
  • ***
  • Posts: 110
  • SMF Version: 1.1.7
  • SP Version: 2.2.1
Re: rss Block but not the Original
« Reply #3 on: February 03, 2009, 01:59:10 PM »
Thanks Blue Dream , that was an old Topic , I'm already
using rss with my ad Mod http://simpleportal.net/index.php?topic=1219.0

by using the rss block but giving it for example #adNews
to avoid the block frames

Offline yield

  • Semi Newbie
  • *
  • Posts: 8
Re: rss Block but not the Original
« Reply #4 on: February 22, 2009, 12:40:44 PM »
Hi! I was looking for a way to just show the feeds headers/titles and not the full text -- which may be clickable/expandable.

Is it possible to achieve that with any setup on the code posted by Blue Dream?

Thanks

Offline Robbo

  • Beer is good!
  • Comrade
  • *
  • Posts: 223
  • Gender: Male
    • Australian Savage (Game Community)
  • SMF Version: 2 RC1.2
  • SP Version: None
Re: rss Block but not the Original
« Reply #5 on: February 22, 2009, 06:59:34 PM »
Hi! I was looking for a way to just show the feeds headers/titles and not the full text -- which may be clickable/expandable.

Is it possible to achieve that with any setup on the code posted by Blue Dream?

Thanks

Copy this into a PHP block. I haven't tested it very much but it should be fine (could look prettier).

People with JavaScript disabled will have all descriptions expanded.

Code: [Select]
    $feed = '';

    $rss_data = array();
    $rss_current = "";
    $rss_counter = 0;
    $rss_main = '';

    $xml_parser = xml_parser_create();

    xml_set_element_handler($xml_parser, "sp_startElement", "sp_endElement");

    xml_set_character_data_handler($xml_parser, "sp_characterData");

    if (!($fp = @fopen($feed, "r")))
    {
        echo 'Invalid feed URL.';
        return;
    }

    while ($data = fread($fp, 4096))
    {
        if (!xml_parse($xml_parser, $data, feof($fp)))
        {
            $xmlerr = (sprintf("XML error: %s at line %d",
            xml_error_string(xml_get_error_code($xml_parser)),
            xml_get_current_line_number($xml_parser)));

            break;
        }
    }

    fclose($fp);
   
    xml_parser_free($xml_parser);

    if (!empty($xmlerr))
    {
        echo $xmlerr;
        return;
    }

    if (empty($rss_data))
    {
        echo 'No items to show.';
        return;
    }

    echo '<center>';
    if (!empty($rss_data['IMAGE']))
        echo '<a href="', $rss_data['LINK'], '" target="_blank"><img src="', $rss_data['IMAGE']['URL'], '" align="middle" alt="', $rss_data['IMAGE']['TITLE'], '" /></a>', $rss_data['TITLE'], '<br /><br />';
    else
        echo '<b>', $rss_data['TITLE'], '</b><br />';

    echo '<em>', $rss_data['DESCRIPTION'], '</em><br /><hr /></center><br />';

    if (isset($rss_data['ITEMS']))
    {
        echo '
        <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
            function toggleDescription(id)
            {
                id = \'rss_descr_\' + id;
                if(document.getElementById(id).style.display == \'none\')
                    document.getElementById(id).style.display = \'\';
                else
                    document.getElementById(id).style.display = \'none\';
            }
        // ]]></script>';
       
        $max = count($rss_data['ITEMS']);
        if ($max > 0)
        {
            for($i = 0; $i < $max; $i++)
            {
                echo '<div id="test"></div>
                    <span style="font-weight: bold;"><a href="javascript:toggleDescription(', $i, ')">', $rss_data['ITEMS'][$i]['TITLE'], '</a></span><br /><br />';
                echo '
                    <div id="rss_descr_', $i, '">
                        ', html_entity_decode($rss_data['ITEMS'][$i]['DESCRIPTION']) . '<br /><br />
                        <a class="smalltext" href="', $rss_data['ITEMS'][$i]['LINK'], '" target="_blank"><b>view link »</b></a>';
                if ($i != $max - 1)
                    echo '<hr />';
                echo '
                    </div>
                    <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
                        toggleDescription(', $i, ');
                    // ]]></script>';
               
            }
        }
    }

Offline yield

  • Semi Newbie
  • *
  • Posts: 8
Re: rss Block but not the Original
« Reply #6 on: February 22, 2009, 08:43:35 PM »
Hello Robbo! Thank you very much for replying to my request.

I put that into a php block, filled the feed url at $feed variable, but then all I got is this message: "No items to show. "

However, if I paste the same feed url into the default rss block, I got a few items, but with a huge amount of text --hence my request.

Any idea of what's wrong here?

Thanks

Offline Robbo

  • Beer is good!
  • Comrade
  • *
  • Posts: 223
  • Gender: Male
    • Australian Savage (Game Community)
  • SMF Version: 2 RC1.2
  • SP Version: None
Re: rss Block but not the Original
« Reply #7 on: February 22, 2009, 09:09:31 PM »
My bad.

Add at the top...

Code: [Select]
global $rss_data, $rss_current, $rss_counter, $rss_main;

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: rss Block but not the Original
« Reply #8 on: February 23, 2009, 12:18:38 AM »
You'll be able to limit items and body in next version. And making body collapsable sounds like fun, I'll try that.
And slowly, you come to realize... It's all as it should be...

Offline yield

  • Semi Newbie
  • *
  • Posts: 8
Re: rss Block but not the Original
« Reply #9 on: February 23, 2009, 07:24:18 PM »
Hi!

Thank again Robbo, it works now! :D

I know very few of html and nothing of php/javascript, but I managed to do some modifications (throught trial and error):
- removed the rss title (because that will be the block name);
- inserted class="smalltext" to make text smaller, it was occupying too much space.

Well, but I still got a problem (sorry being so boring!): I'd like to display two different feeds (news and events), but when both blocks are active, the text shows up expanded by default on both blocks, and impossible to collapse on the second block. Is it some problem with the variables names being the same? Which ones are needed to change?

Blue Dream, that would be very nice! Can't wait for next version :) Also, I guess I forgot to thank you for your reply on my first thread: thank you!

Offline Robbo

  • Beer is good!
  • Comrade
  • *
  • Posts: 223
  • Gender: Male
    • Australian Savage (Game Community)
  • SMF Version: 2 RC1.2
  • SP Version: None
Re: rss Block but not the Original
« Reply #10 on: February 24, 2009, 07:29:31 AM »
Yeah it is a problem with the description ids being the same. I never thought of multiple ids.

Use this code instead. I made the changes you said you did so you should be able to just copy it over (backup just incase).

Code: [Select]
    global $rss_data, $rss_current, $rss_counter, $rss_main;

    // This needs to be unique to each block
    $id = 1;
   
    // Your feed url
    $feed = 'http://simpleportal.net/index.php?type=rss2;action=.xml;board=8.0;sa=news';

    $rss_data = array();
    $rss_current = "";
    $rss_counter = 0;
    $rss_main = '';

    $xml_parser = xml_parser_create();

    xml_set_element_handler($xml_parser, "sp_startElement", "sp_endElement");

    xml_set_character_data_handler($xml_parser, "sp_characterData");

    if (!($fp = @fopen($feed, "r")))
    {
        echo 'Invalid feed URL.';
        return;
    }

    while ($data = fread($fp, 4096))
    {
        if (!xml_parse($xml_parser, $data, feof($fp)))
        {
            $xmlerr = (sprintf("XML error: %s at line %d",
            xml_error_string(xml_get_error_code($xml_parser)),
            xml_get_current_line_number($xml_parser)));

            break;
        }
    }

    fclose($fp);
   
    xml_parser_free($xml_parser);

    if (!empty($xmlerr))
    {
        echo $xmlerr;
        return;
    }

    if (empty($rss_data))
    {
        echo 'No items to show.';
        return;
    }

    if (isset($rss_data['ITEMS']))
    {
        echo '
        <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
            function toggleDescription(id)
            {
                id = \'rss_descr_\' + id;
                if(document.getElementById(id).style.display == \'none\')
                    document.getElementById(id).style.display = \'\';
                else
                    document.getElementById(id).style.display = \'none\';
            }
        // ]]></script>';
       
        $max = count($rss_data['ITEMS']);
        if ($max > 0)
        {
            for($i = 0; $i < $max; $i++)
            {
                echo '
                    <span style="font-weight: bold;" class="smalltext"><a href="javascript:toggleDescription(\'', $id, '_', $i, '\')">', $rss_data['ITEMS'][$i]['TITLE'], '</a></span><br />';
                echo '
                    <div id="rss_descr_', $id, '_', $i, '" class="smalltext">
                        ', html_entity_decode($rss_data['ITEMS'][$i]['DESCRIPTION']) . '<br /><br />
                        <a href="', $rss_data['ITEMS'][$i]['LINK'], '" target="_blank"><b>view link »</b></a>';
                if ($i != $max - 1)
                    echo '<hr />';
                echo '
                    </div>
                    <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
                        toggleDescription(\'', $id, '_', $i, '\');
                    // ]]></script>';
               
            }
        }
    }

At the top you will see an id, simply make that different for each block and it should work fine.

Offline yield

  • Semi Newbie
  • *
  • Posts: 8
Re: rss Block but not the Original
« Reply #11 on: February 24, 2009, 09:29:55 AM »
Robbo, now it's working flawlessly! Thank you very much  ;D

I did two more changes:

1. removed the "view link" hyperlink at the end of every item. I noticed that it would point to a topic when using SP feed, but with the feed I'm using it will point to an inexistent url (not a problem);
2. added a little dot before titles, to make it easier to distinguish each title.

Best regards