News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

RSS Injector available

Started by confusion, December 24, 2005, 04:04:48 PM

Previous topic - Next topic

o_1281


garg

thank you for working on this :) I was looking for this.

The thread is getting a bit confusing. Does any one know which link is working? Thanks.

Gosu Schwarz

Everyone have patience! I want this mod too but the longer we wait the better it will be.

L.G.S

I used the original code from the first few pages, but now the links which helped me do not work so I cannot reuse it :(
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


forumposters

When you follow the original link to the supposed rss injector mod, there's nothing there. 

L.G.S

On page two somebody reposted it and it worked
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


forumposters

Are you sure?  I just followed the link on page 2 to the .rar file and it's broken.

L.G.S

FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


lordmenace

I don't think he's going to release it. He's had a working copy for a while AND has it installed on a live board. That was weeks ago. He's not giving it uop so let's just stop asking.

L.G.S

'd be happy if someone could just repost how to do the original script properly, because I'm in need of something like this real fast..
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


herrin

I don't know if it'll help anyone, but I hacked a quick one together using simplepie RSS.

I'm using it very successfully at hxxp:www.lordifans.com/forum/index.php?action=collapse;c=6;sa=expand#6 [nonactive]

Download the RSS from here hxxp:simplepie.org/ [nonactive] and forget about the PEAR XML/RSS.

I don't have time to support it but feel free to use it.  I'm not responsible if it breaks your server or your smf installation.

<?php
//
// SMF RSS Injector by Jerry Bell - [email protected]
// Based on the Joomla RSS import script by Max Soukhomlinov, [email protected]
// 
// 
//
// This script is quick and dirty. Please remember to abide by the RSS content providers' terms of use.  

// Modified to use simplepie by Shawn Herrin [email protected]
/** the simplepie RSS library is required */
require("./includes/simplepie/simplepie.inc");

/** DATABASE Configuration */
define("DB_HOSTNAME",""); //Insert your DB server name here
define("DB_USERNAME",""); //DB username here
define("DB_PASSWD","*"); // DB password here
define("DB_DATABASE",""); //DB name here
$sSql "";
$userid 3//Set this to the SMF userid you want the messages posted from
$boardid 21;//Set this to the id of the board you want to post the messages in
$sUrl "http://yourdomain.com/feed";
$feed = new SimplePie();
$feed->feed_url($sUrl);

$feed->init();
$feed->handle_content_type();

$obj_db mysql_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWD) or die (mysql_error());
mysql_select_db(DB_DATABASE,$obj_db) or die (mysql_error());

if (
$feed->data
{    
$max $feed->get_item_quantity(20);
for ($x 0$x $max$x++) 
    {
    
$item $feed->get_item($x);
        
    
$sSql "SELECT
                COUNT(ID_MSG) AS link_match
             FROM smf_messages 
             WHERE subject = '"
addslashes($item->get_title()) ."'";
        
    
$obj_query mysql_query($sSql$obj_db) or die(mysql_error());

        
$int_count mysql_fetch_assoc($obj_query) or die(mysql_error());

        
mysql_free_result($obj_query);
        
        if (
$int_count['link_match'] == 0
        { 
$titletext addslashes($item->get_title());

$maintext "<p>" $item->get_date('j M Y') . "</p><p>" addslashes($item->get_description()) . "</p><p><a href=\"" $item->get_permalink() . "\">" $item->get_permalink() . "</a></p>";
        


        
echo("*******************************************************************<br />");
echo("title: " $titletext "<br />");
        
echo("*******************************************************************<br />");
$sSql "INSERT INTO smf_topics
(
ID_BOARD,
ID_MEMBER_STARTED,
ID_MEMBER_UPDATED

VALUES 
(
'
$boardid',
'
$userid',
'
$userid'
)"
;
mysql_query($sSql,$obj_db) or die(mysql_error());

$topic mysql_insert_id();

$postertime date('U');

//Insert the actual message
    $sSql "INSERT INTO smf_messages
     (
subject,
body,
  ID_MEMBER,
ID_BOARD,
ID_TOPIC,
posterTime

     VALUES 
     (
'"
$titletext ."',
'"
$maintext ."',
'
$userid',
'
$boardid',
'
$topic',
'
$postertime'
)"
;
mysql_query($sSql$obj_db) or die(mysql_error());

$messageid mysql_insert_id();

//Go back and set ID_FIRST_MSG and ID_LAST_MSG in the topics table
$sSql "UPDATE smf_topics
SET ID_FIRST_MSG = '
$messageid', 
ID_LAST_MSG = '
$messageid'
WHERE ID_TOPIC = '
$topic'";

mysql_query($sSql$obj_db) or die(mysql_error());

//Increment total posts for board
    $sSql "UPDATE smf_boards
SET numPosts = numPosts + 1, 
numTopics = numTopics + 1
WHERE ID_BOARD = '
$boardid'";
mysql_query($sSql$obj_db) or die(mysql_error());

//Increment Total Messages
$sSql "UPDATE smf_settings
SET value = value + 1
WHERE variable = 'totalMessages'"
;
mysql_query($sSql,$obj_db) or die(mysql_error());

//Increment Total Topics
    $sSql "UPDATE smf_settings
SET value = value + 1
WHERE variable = 'totalTopics'"
;
mysql_query($sSql$obj_db) or die(mysql_error());

// Increment post count for user record
    $sSql "UPDATE smf_members
                        SET posts = posts + 1
                                WHERE ID_MEMBER = '
$userid'";
mysql_query($sSql$obj_db) or die(mysql_error());
        }
        else 
        {
        
echo("There is already a match<br />");
        } 
    }
}

if (
$obj_db) {
    @
mysql_close($obj_db);
}
?>



Azashub

#211
It's really interesting and thank you for the job!
But as a total noob can you just explain a bit more what we must do?

1. download the tool at simplepie.org
2. install the needed files on the server in a simplepie directory
3. create a php file and copy/paste (and of course adapt) your script
4. where do you save this php file?
5. what is the name of this php file?

Anyhow your work is exactly what I'm looking for!

L.G.S

#212
Great script, it works but I have 2 questions:

when I run it, I get this:
Warning: ./cache/http%3A%2F%2Fnews.google.com%2F%3Fned%3Dus%26topic%3Dt%26output%3Drss.spc is not writeable in /home/tscar/public_html/board/RSS/simplepie.inc on line 1252


And how would I be able to limit the width the post can go, because it is seriously screwing up my post display.

Edit:

Also how do I stop the topics coming up as new topics since last visit? When my members go on the forum they cannot remove them from the list by marking all read and the on/off button always stays on for new posts.
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


Azashub

Ok so we only need to run the adapted scipt, but.... how can you update the board automatically? I mean, when a new feed is coming, you have to run the script once again to add the newest news, no?

Also, all the feeds are added in an ascending manner, the top news is the latest news, the bottom news is the newest.

L.G.S

Are you asking me?

To do them automatically you need to set up a cron job.

Your last part does not make sense, you say the top news is the latest, and the bottom is the newest, although these things are one and the same.
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


Azashub

I mean when I ran the script it creates me 20 new topics.

-> The topic in the top of the board section was the oldest news of the feed.
-> The topic in the bottom of the board section was the newest news of the feed.

Normally, the newest topics are on top...not on bottom. That's what I mean  :-\

L.G.S

I'm not sure then, it works fine for me.
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


TLM

Some sad news on my part of my injector people want.

The hd where it was stored died in my recent move, so I lost the admin panel.  But the code for the injector and its db lived else where, so that is still alive.  I am contimplating on if I should just release the code now and come back later with a full mod when I have time or not.

herrin

Quote from: L.G.S on August 31, 2006, 07:09:50 AM
Great script, it works but I have 2 questions:

when I run it, I get this:
Warning: ./cache/http%3A%2F%2Fnews.google.com%2F%3Fned%3Dus%26topic%3Dt%26output%3Drss.spc is not writeable in /home/tscar/public_html/board/RSS/simplepie.inc on line 1252


And how would I be able to limit the width the post can go, because it is seriously screwing up my post display.

Edit:

Also how do I stop the topics coming up as new topics since last visit? When my members go on the forum they cannot remove them from the list by marking all read and the on/off button always stays on for new posts.

Ok, I forgot about that caching thing.  You have two options.  Create a ./cache directory in the same dir that you are running the script from and change it's permissions to be writable.  OR add the following line right after the $feed->feed_url($sUrl); line

$feed->enable_caching(false);


As far as stopping the topics from coming up as new, I have no idea.  I don't know SMF at all.

As far as the making the titles shorter, try this.

Save the following code to your server in the same directory as your news script as smart_trim.php.
<?php

#################################################
####
#### smart_trim
#### This function trims a string to a specified length.
#### Words are separated by space characters, and they are not
#### chopped if possible.
#### 
#### @package smart_trim
#### @author  Michael Gauthier <[email protected]>
#### silverorange
#### labs.silverorange.com
#### 
#### Copyright (c) 2003, silverorange Inc.
#### All rights reserved.
#### 
#### Redistribution and use in source and binary forms, with or without modification,
#### are permitted provided that the following conditions are met:
#### 
####     * Redistributions of source code must retain the above copyright notice, this
####       list of conditions and the following disclaimer.
####     * Redistributions in binary form must reproduce the above copyright notice,
####       this list of conditions and the following disclaimer in the documentation
####       and/or other materials provided with the distribution.
####     * Neither the name of silverorange Inc. nor the names of its contributors may
####       be used to endorse or promote products derived from this software without
####       specific prior written permission.
#### 
#### THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#### ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#### WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#### IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
#### INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#### BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#### DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
#### LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
#### OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
#### OF THE POSSIBILITY OF SUCH DAMAGE.
#### 
#################################################

/**
 * Trim the string.
 *
 * @param  string  $text        The line to trim.
 * @param  integer $max_len     The maximum length of the trimmed line.
 *                              This ignores the length of the characters
 *                              that indicate trimming has occured.
 * @param  boolean $trim_middle Trimming takes place in the middle of the line
 *                              iff true. Otherwise, the line is trimmed at the
 *                              end. Defaults to false.
 * @param  string  $trim_chars  Characters to use to indicate trimming has
 *                              occured. Defaults to '...'.
 *
 * @return string               The trimmed line of text.
 */
function smart_trim($text$max_len$trim_middle false$trim_chars '...')
{
$text trim($text);

if (strlen($text) < $max_len) {

return $text;

} elseif ($trim_middle) {

$hasSpace strpos($text' ');
if (!$hasSpace) {
/**
 * The entire string is one word. Just take a piece of the
 * beginning and a piece of the end.
 */
$first_half substr($text0$max_len 2);
$last_half substr($text, -($max_len strlen($first_half)));
} else {
/**
 * Get last half first as it makes it more likely for the first
 * half to be of greater length. This is done because usually the
 * first half of a string is more recognizable. The last half can
 * be at most half of the maximum length and is potentially
 * shorter (only the last word).
 */
$last_half substr($text, -($max_len 2));
$last_half trim($last_half);
$last_space strrpos($last_half' ');
if (!($last_space === false)) {
$last_half substr($last_half$last_space 1);
}
$first_half substr($text0$max_len strlen($last_half));
$first_half trim($first_half);
if (substr($text$max_len strlen($last_half), 1) == ' ') {
/**
 * The first half of the string was chopped at a space.
 */
$first_space $max_len strlen($last_half);
} else {
$first_space strrpos($first_half' ');
}
if (!($first_space === false)) {
$first_half substr($text0$first_space);
}
}

return $first_half.$trim_chars.$last_half;

} else {

$trimmed_text substr($text0$max_len);
$trimmed_text trim($trimmed_text);
if (substr($text$max_len1) == ' ') {
/**
 * The string was chopped at a space.
 */
$last_space $max_len;
} else {
/**
 * In PHP5, we can use 'offset' here -Mike
 */
$last_space strrpos($trimmed_text' ');
}
if (!($last_space === false)) {
$trimmed_text substr($trimmed_text0$last_space);
}
return remove_trailing_punctuation($trimmed_text).$trim_chars;

}

}

/**
 * Strip trailing punctuation from a line of text.
 *
 * @param  string $text The text to have trailing punctuation removed from.
 *
 * @return string       The line of text with trailing punctuation removed.
 */
function remove_trailing_punctuation($text)
{
return preg_replace("'[^a-zA-Z_0-9]+$'s"''$text);
}
?>



Add include ("smart_trim.php"); to the top of your news script

Then in your news script just change the line

$titletext = addslashes($item->get_title());

to

$titletext = smart_trim(addslashes($item->get_title()), 50, false, "...");

Where 50 is the max length of the title and ... is the characters to append to the end of the cut.

Additionally, change the following query as well.

    $sSql = "SELECT
                COUNT(ID_MSG) AS link_match
            FROM smf_messages
            WHERE subject = '". addslashes($item->get_title()) ."'";


to


    $sSql = "SELECT
                COUNT(ID_MSG) AS link_match
            FROM smf_messages
            WHERE subject = '". smart_trim(addslashes($item->get_title()), 50, false, "...") ."'";


I don't know if this works, I didn't do it on mine, just hoping to offer an option.

L.G.S

Thanks for the help,

but, I meant the post itself, not the title. The content of the post stretches the page and makes sigs unreadable.

What exactly does creating the cache directory do?
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


Advertisement: