It has been a real frustration for me in getting the script work. I have below my rss2joomla.php file - please advise if I got variables right (my database info are fake) or anything wrong in the configuartion that the script is not working.
I do not get any error (just a blank screen which I gather is a good sign) when call the script from the browser. I have pear and rss.php installed on my server.
I am really at loss why I do not get anything entered in content and my database. I will apprecaite any help. This will help few other members who got exactly the same problem
// Sample RSS feeds to Joomla / Mambo importing script, hacked together by Max Soukhomlinov,
maxs@intellectit.com.au//
// This script requires XML_RSS and PHP Pear Libraries
//
// There is an issue on some shared hosting sites that this will fail if ran via cron however if browsed to, it works just fine.
// this has to do with permissions, your hosting website uid does not have same rights as apache uid (under which script is executed when your browse to it)
// I am at the moment trying to work out a solution to it, if you can think of something that will help, please drop me a line.
// Happy importing :-)
//
/** the PEAR XML_RSS object/class is required */
require '/usr/share/pear/XML/RSS.php';
/** DATABASE Configuration */
define("DB_HOSTNAME","localhost"); //Insert your DB server name here
define("DB_USERNAME","myusername"); //DB username here
define("DB_PASSWD","mypassword"); // DB password here
define("DB_DATABASE","mydatabase"); //DB name here
/** pull list of remote RSS feeds, via a remote RSS feed. */
$rss_feed = & new XML_RSS('http://rss.cnn.com/rss/cnn_topstories.rss'); //Insert your URL here
//$rss_feed = & new XML_RSS('feed.xml'); //Used this for testing with local file, a bit quicker
// Change to your email address, if you do not want notifications, rem out line 187.
$admin_email =
'admin.accb@gmail.com';
// Should not need to change anything from here onwards unless you know some basic php
// The advanced options are: A) Alter title formatting (lines 68 and 84);
// B) Alter introtext/maintext formatting (lines 85 and 86);
// C) Change formatting of notification email (lines 92-97 for per new item formatting and 164-182 for main body formatting).
// Next two lines are for duration runtime, which is reported via email
$starttime = explode(' ', microtime());
$starttime = $starttime[1] + $starttime[0];
// Function for shortening articles based on maximum length
function str_stop($string, $max_length){
if (strlen($string) > $max_length){
$string = substr($string, 0, $max_length);
$pos = strrpos($string, " ");
if($pos === false) {return substr($string, 0, $max_length)."...";}
return substr($string, 0, $pos)."...";
}else{return $string;}
}
/** create the database connection object */
$obj_db = @mysql_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWD) or die (mysql_error());
/** select the intended database */
@mysql_select_db(DB_DATABASE,$obj_db) or die (mysql_error());
$rss_feed->parse();
$num_articles=0; //Variable used to count number of new articles, displayed in an email below
// Here we make sure that feed articles do not already exist in DB
// this uses title names, make sure to use the same title formatting here as you will use further down
// state = 1 not trashed
foreach ($rss_feed->getItems() as $item) {
$obj_query = @mysql_query("
SELECT
COUNT(id) AS link_match
FROM
jos_content
WHERE
title = '". str_stop(addslashes($item['title']),100) ."'
AND
state = '1'
",$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) {
$num_articles = $num_articles +1;
/**
* REFORMATTING CODE
**/
$titletext = str_stop(addslashes($item['title']),100);
$introtext = str_stop(addslashes($item['description']), 280); //Shorten description to 280 chars...
$maintext = addslashes($item['description']);
$publishdate = date('Y-m-d H:i:s', strtotime($item['pubdate'])); //Convert feed article publish date to mambo publish date
$publishdate_readable = date('d-m-Y, H:i', strtotime($item['pubdate'])); // I didnt like the standard date format, this is for email field
// the following used to notify admin of new articles (via email), this is parsed with each article
$feed_summary .= '
'. $publishdate_readable .' |
'. $titletext .' |
'. $introtext .' |
'. $maintext .' |
';
/**
* INSERT DATA
*/
// VERY IMPORTANT, changes will be required here for sure!
// THE attribs below are specific to my site but you can blank it all if you wish (default parameters)
// with attribs, make sure to type each on new line (ie line break as shown below otherwise mambo will not understand it)
// Ordering number, be fault it will be #99, i am yet to implement an auto detection as mambo/joomla does on its own
// for now all articles will be #99 so when publishing sort them by published date
@mysql_query("
INSERT INTO jos_content (
title,
introtext,
`fulltext`,
state,
sectionid,
mask,
catid,
created,
created_by,
checked_out,
publish_up,
attribs,
version,
access,
ordering
) VALUES (
'". $titletext ."',
'". $introtext ."',
'". $maintext ."',
'1',
'7',
'0',
'38',
'". $publishdate ."',
'62',
'0',
'". $publishdate ."',
'introtext=0
createdate=1',
'1',
'0',
'99'
)
",$obj_db) or die(mysql_error());
}
}
if ($obj_db) {
@mysql_close($obj_db);
}
// if we have downloaded new feeds, lets create a report for the admin
if ($feed_summary)
{
// runtime check, to tell admin on how long this script has been running, might be handy to know
$mtime = explode(' ', microtime()); $totaltime = $mtime[0] + $mtime[1] - $starttime;
/** EMAIL variables */
$email_subject = 'Your subject here';
$email_body = '
Date |
Heading |
Intro text |
Full text |
|---|
'. $feed_summary .'
This message was automatically generated by the rss importing process on your website.
Script: '. getcwd() .'/yourscriptnamehere.php
RSS Feed source: http://www.theregister.co.uk/headlines.rss
Current date: '. date(r) .'
Script execution time: '. round($totaltime,3) .' seconds. |
';
$from = "MIME-Version: 1.0\n";
$from .= "Content-type: text/html; charset=iso-8859-1\n";
$from .= "From: From Address name
Who is online |
Users browsing this forum: No registered users and 7 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|