Subject: Limiting rss stories in portal block

Posted on: 11/08/03 05:42pm
By: Anonymous

hi. I\'ve switched from postnuke and I\'m really happy with geeklog so far. However, I\'ve noticed that there isn\'t a way to limit the number of rss stories that show up in a portal block as I was able to do with postnuke. Is there even a way to hack a file to achieve this? I\'m not that technically inclined to figure it out myself but if someone can tell me what to do, I\'d like to try it. I just upgraded from 1.3.7 to 1.3.8 by the way. Thanks.

Re:Limiting rss stories in portal block

Posted on: 11/08/03 06:05pm
By: squatty

Here\'s a quick hack to limit the number of links.... Replace the code in lib-common.php COM_rdfImport with the following:

if( !$rdferror )
        {
            $blockcontent = COM_makeList( $RDFheadlines );
            // Limit News Links to 5
            $RDFHeadlines = array_splice($RDFheadlines,5);              
            $blockcontent = preg_replace( \"/(

Re:Limiting rss stories in portal block

Posted on: 11/08/03 06:06pm
By: squatty

Well, that didn't work.

Change this:
$RDFheadlines = array();

To this:
$RDFHeadlines = array_splice($RDFheadlines,5);

Set the '5' to the number of links you want to display.

Re:Limiting rss stories in portal block

Posted on: 11/08/03 06:23pm
By: Anonymous

hmm... thanks for the quick response.. it didn\'t work though. I tried both, including only changing that one line. Still didn\'t work. Is it working for you?

Re:Limiting rss stories in portal block

Posted on: 11/08/03 06:33pm
By: Anonymous

hey squatty, in your second post, were you still referring to the same section in the COM_rdfImport function from your first post? Because I\'m noticing that the line: $RDFheadlines = array(); shows up in earlier in that same function like this: $RDFinsideitem = false; $RDFtag = \'\'; $RDFtitle = \'\'; $RDFlink = \'\'; $RDFheadlines = array(); and it also shows up like that in COM_rdfCheck, thus confusing me. Did you mean for me to change every instance where that line shows up, or only a specific instance in a specific function? Thanks for all your help.

Re:Limiting rss stories in portal block

Posted on: 11/08/03 07:04pm
By: squatty

Yes, it does work for me. You only need to update the code in COM_rdfImport. That\'s where the display and store logic is. Be sure to delete any saved feeds in your DB. The update will only show if the feed is out of date (and thus needs to be updated) or if it is new. The code in my lib-common looks like this: if( !$rdferror ) { $RDFHeadlines = array_splice($RDFheadlines,5); $blockcontent = COM_makeList( $RDFheadlines ); ---SNIP---- If that doesn\'t work, try this.

Re:Limiting rss stories in portal block

Posted on: 11/08/03 08:23pm
By: Anonymous

Not sure why but it still doesn\'t work for me. Sorry for not completely understanding this but what does this mean exactly?: \" Be sure to delete any saved feeds in your DB. The update will only show if the feed is out of date (and thus needs to be updated) or if it is new.\" Do you mean I should delete lib-common.php from the server and re-upload it? I just don\'t know enough to know what the \"feed\" you\'re referring to is. Also, does the news plugin work in a side block? And just in case I\'m doing something silly, I\'ll paste a section from my lib-common.php: function COM_rdfImport( $bid, $rdfurl ) { global $_TABLES, $RDFinsideitem, $RDFtag, $RDFtitle, $RDFlink, $RDFheadlines; $RDFinsideitem = false; $RDFtag = \'\'; $RDFtitle = \'\'; $RDFlink = \'\'; $RDFheadlines = array(); $update = date( \"Y-m-d H:i:s\" ); $result = DB_change( $_TABLES[\'blocks\'], \'rdfupdated\', \"$update\", \'bid\', $bid ); clearstatcache(); $rdferror = false; $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, \'COM_rdfStartElement\', \'COM_rdfEndElement\'); xml_set_character_data_handler( $xml_parser, \'COM_rdfCharacterData\' ); if( $fp = @fopen( $rdfurl, \'r\' )) { $startoffeed = true; while( $data = fread( $fp, 4096 )) { if( $startoffeed ) { $data = ltrim( $data ); $startoffeed = false; } if( !xml_parse( $xml_parser, $data, feof( $fp ))) { $errmsg = sprintf( \"Parse error in %s: %s at line %d\", $rdfurl, xml_error_string( xml_get_error_code( $xml_parser )), xml_get_current_line_number( $xml_parser ) ); COM_errorLog( $errmsg, 1 ); $rdferror = true; $result = DB_change( $_TABLES[\'blocks\'], \'content\', addslashes ($errmsg), \'bid\', \"$bid\" ); break; } } fclose( $fp ); xml_parser_free( $xml_parser ); if( !$rdferror ) { $RDFHeadlines = array_splice($RDFheadlines,5); $blockcontent = COM_makeList( $RDFheadlines ); $blockcontent = preg_replace( \"/(

Re:Limiting rss stories in portal block

Posted on: 11/08/03 08:32pm
By: Anonymous

... continued from above post:

\015\012)|(\015)|(\012)/", "", $blockcontent );
$result = DB_change( $_TABLES['blocks'], 'content', "$blockcontent", 'bid', $bid);
}
}
else
{
$rdferror = true;
COM_errorLog( "Can not reach $rdfurl", 1 );

$result = DB_change(
$_TABLES['blocks'],
'content',
"GeekLog can not reach the supplied RDF file at $update. "
. "Please double check the URL provided. Make sure your url is correctly entered and it begins with "
. "http://. GeekLog will try in one hour to fetch the file again.",
'bid',
"$bid"
);
}
}

Re:Limiting rss stories in portal block

Posted on: 11/08/03 08:51pm
By: squatty

Do you mean I should delete lib-common.php from the server and re-upload it? I just don\'t know enough to know what the \"feed\" you\'re referring to is.
No, your lib-common.php updates look correct. What I mean by \"delete the feed\" is delete your portal block. Then create a new portal block with the same RSS/RDF URL. The code will not work on your existing block. The data (\"feed\") is already saved with the full set of links.
Also, does the news plugin work in a side block?
Yes, the news plugin looks the same as a portal block. With the exception that a user can select one of many RSS/RDF feeds to display in the block. The site admin configures which RSS/RDF feeds a user can select from. You can see the plugin in action on my site: www.squatty.com.

Re:Limiting rss stories in portal block

Posted on: 12/08/03 03:20am
By: Anonymous

You know what? Silly me. It works now. The update on lib-common worked. I just opened the site in a different browser and there it was. I guess it was just a browser cache thing or something. Thanks squatty! Back to being a happy geeklogger.

Limiting rss stories in portal block

Posted on: 07/07/04 08:59pm
By: RickW

I want to do this same thing... and I was just about to change that line that squatty pointed out... then I realized this is going to be global to all portal blocks. I need to customize them though.

So my Virus Alerts rss feed will be whatever the feed gives me, then some of my other news based feeds will only be 3 links, then one other article feed will be limited to 5 links... etc...

Any solution ideas? Maybe something to be added in the next build?

Limiting rss stories in portal block

Posted on: 16/11/04 02:05pm
By: Kutulu

[QUOTE BY= squatty] Well, that didn't work.

Change this:
$RDFheadlines = array();

To this:
$RDFHeadlines = array_splice($RDFheadlines,5);

Set the '5' to the number of links you want to display. [/QUOTE]

Worked like a champ! You da man Squatty!

Limiting rss stories in portal block

Posted on: 07/12/04 11:03pm
By: RickW

[QUOTE BY= squatty] Well, that didn't work.

Change this:
$RDFheadlines = array();

To this:
$RDFHeadlines = array_splice($RDFheadlines,5);

Set the '5' to the number of links you want to display. [/QUOTE]

I just tried to do this, but that didn't work for me. I still get the same number of RSS links.

Limiting rss stories in portal block

Posted on: 11/12/04 01:48pm
By: Dirk

In Geeklog 1.3.10, if you have a look at function COM_rdfImport in lib-common.php, you'll see this line:
$maxheadlines = 0; // set to something > 0 to limit max. number of headlines

Guess what it does ...

bye, Dirk

Limiting rss stories in portal block

Posted on: 11/12/04 02:06pm
By: RickW

[QUOTE BY= Dirk] In Geeklog 1.3.10, if you have a look at function COM_rdfImport in lib-common.php, you'll see this line:
$maxheadlines = 0; // set to something > 0 to limit max. number of headlines


Guess what it does ...

bye, Dirk[/QUOTE]

Yay, an early christmas present.

I haven't switched over to 1.3.10 yet because I want to give it some time to make sure all of the after-release bugs and security holes are worked out since a lot of new features were added. Plus I'm waiting to see what Blaine cooks up for his next forum release, I'll probably upgrade both at the same time...

Limiting rss stories in portal block

Posted on: 16/02/05 11:40am
By: frisco3

I used this option today and it worked great! Just a FYI though, I did have to recreate the block from scratch after I changed the setting in lib_common. Not a big deal, but it wasn't working otherwise. I changed the 10 headline RSS to a 5 headline RSS from Yahoo News. This rocks!

Brian Brown
www.iburlington.com

Limiting rss stories in portal block

Posted on: 16/02/05 01:51pm
By: Dirk

Simply saving the block again would have done the trick, too. The RSS feeds are stored in the database and only refreshed once per hour. By saving the block again, you force it to refresh.

bye, Dirk

Limiting rss stories in portal block

Posted on: 04/03/05 04:25pm
By: Anonymous

hey
spent days trying to figure this out...to no avail.

until today!



if( !$rdferror )
        {
            $RDFheadlines = array_splice($RDFheadlines,5);
            $blockcontent = COM_makeList( $RDFheadlines );
            $blockcontent = preg_replace( "/(1512)|(15)|(12)/", '',
                                          $blockcontent );



the default FOR ME had this:

if( !$rdferror )
        {
            $blockcontent = COM_makeList( $RDFheadlines );           
            $RDFheadlines = array_splice($RDFheadlines,5);
            $blockcontent = preg_replace( "/(1512)|(15)|(12)/", '',
                                          $blockcontent );




The FIRST ONE is right.
notice the ORDER of the $blockcontent and $rdfheadlines...!!!
i changed it...as was mentioned...but because it was being changed AFTER it would not work.

Yah, this is probably simple for most ppl...but it was a big deal for me!

Hope this helps someone who may run into a similar problem!

Limiting rss stories in portal block

Posted on: 04/03/05 04:36pm
By: Anonymous

okay, seems like there are some issues.

i thought i had it going...but...it only does it on the first block properly (yes, i've killed the blocks, added new ones, etc)

AND

it limits it to the LAST url in the RSS feed. ie., it shows the OLDEST ones...not the NEWEST ones!

Limiting rss stories in portal block

Posted on: 04/03/05 04:39pm
By: Anonymous

[QUOTE BY= drali] okay, seems like there are some issues.

i thought i had it going...but...it only does it on the first block properly (yes, i've killed the blocks, added new ones, etc)

AND

it limits it to the LAST url in the RSS feed. ie., it shows the OLDEST ones...not the NEWEST ones![/QUOTE]

i found that it actually GETS RID OF the specified number from the RSS feed.

ie, the 'array splice' thing doesnt limit the feed entries...it gets rid of that number of entries.

any ideas?

Limiting rss stories in portal block

Posted on: 04/03/05 06:13pm
By: Anonymous

$RDFheadlines = array_splice($RDFheadlines, 0, -5);


okay, using that...i think i got it to grab the right headlines.

BUT...it works oddly on some feeds (i think depending on how they are published)

for some feeds..there are still many more entries...and on some feeds...wired news for instance....there are only 2 that now show up on my block.

dah...slowly, slowly.

Limiting rss stories in portal block

Posted on: 04/03/05 06:41pm
By: Anonymous


        if( !$rdferror )
        {
            $RDFheadlines = array_slice($RDFheadlines,0,5);
            $blockcontent = COM_makeList( $RDFheadlines );
            $blockcontent = preg_replace( "/(\015\012)|(\015)|(\012)/", '',
                                          $blockcontent );
            $result = DB_change( $_TABLES['blocks'], 'content', $blockcontent,
                                 'bid', $bid);


OKAY

i think i finally have it.

instead of array SPLICE
use array SLICE

(no P)

that seems to work perfectly now.

(well, until i find out i'm missing somethign again.)

i hope this helps SOMEONE in the future.

Limiting rss stories in portal block

Posted on: 10/11/05 06:14am
By: 1000ideen

If I change this from 0 to 3 I'm receiving an error

$maxheadlines = 0; // set to something > 0 to limit max. number of headlines



Parse error: parse error in /srv/www/htdocs/web393/html/lib-common.php on line 3712

Warning: main(lib-story.php): failed to open stream: No such file or directory in /srv/www/htdocs/web393/html/index.php on line 38

Fatal error: main(): Failed opening required 'lib-story.php' (include_path='.:/usr/share/php') in /srv/www/htdocs/web393/html/index.php on line 38

Then I tried drali's code and it worked. Is this still a bug in 1.3.11sr2 ? You had been talking about 1.3.10 before.

Basically I think that there should be an editable limit in lines displayed in a block. This is also desireable for some more variables. These

$_CONF['newstoriesinterval'] $_CONF['newcommentsinterval'] $_CONF['newlinksinterval'] should rather have a limit in lines displayed than days, hours etc. This may be true for some more things like events etc.

Limiting rss stories in portal block

Posted on: 10/11/05 01:41pm
By: Dirk

[QUOTE BY= 1000ideen] Parse error: parse error in /srv/www/htdocs/web393/html/lib-common.php on line 3712[/QUOTE]
Check that line then ...


[QUOTE BY= 1000ideen] Basically I think that there should be an editable limit in lines displayed in a block.[/QUOTE]
Already in CVS and will be in 1.3.12.

bye, Dirk

Limiting rss stories in portal block

Posted on: 14/11/05 09:44pm
By: johnjr

I've got

$maxheadlines = 10; // set to something > 0 to limit max. number of headlines


but, I'm still getting more than 10 'headlines' from RSS feeds (in particular from the National Weather Service - 58 'headlines').

Any ideas as to why this isn't limiting the feeds to 10?

John

Limiting rss stories in portal block

Posted on: 15/11/05 06:59am
By: 1000ideen

I can`t tell you why but if you want to limit the length then use drali`s code above. It works with me.

Limiting rss stories in portal block

Posted on: 15/11/05 11:57pm
By: johnjr

If I have to hack the code to make it work, I will. But, I would much rather use the functions that are already built into the code.

Dirk, got a good answer for me, as to why this setting doesn't work?

John

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=23300