| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: May 2004
Posts: 1,814
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | |
| |
| | #2 (permalink) |
| NamePros Member Join Date: Jul 2006
Posts: 94
![]() ![]() ![]() | Your script tries fopen() first. If that fails, it tries fsockopen(). Finally if both fail, it will try curl. Now since you want to convert fopen() to curl, I'm assuming you have fopen() disabled on your server and it gives an error when executed. You don't really have to "convert" cause the curl code is already in there. Just remove the fopen() and fsockopen() Here's the code with fopen() and fsockopen() removed. Hope it works. Code: <?php
if (!defined('SMF'))
die('Hacking attempt...');
// Globals
$feedcount = 0;
$maxitemcount = 0;
$tag = '';
$insideitem = false;
function verify_rss_url($url)
{
global $txt;
// Rss Data storage
$finalrss = '';
$failed = true;
// Use cURL
if($failed == true)
{
if(function_exists("curl_init"))
{
$failed = false;
// Last but not least try cUrl
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL, and return output
$output = curl_exec($ch);
// close curl resource, and free up system resources
curl_close($ch);
return $output;
}
}
// XML Parser functions to verify the XML Feed
if($failed == false)
{
$depth = array();
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement2", "endElement2");
if (!xml_parse($xml_parser, $finalrss)) {
fatal_error(sprintf($txt['feedposter_err_xmlerror'],
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)), false);
}
xml_parser_free($xml_parser);
}
else
{
// We were not able to download the feed :(
fatal_error($txt['feedposter_err_nodownload'], false);
}
}
function startElement2($parser, $name, $attrs)
{
global $depth;
$depth[$parser]++;
}
function endElement2($parser, $name)
{
global $depth;
$depth[$parser]--;
}
function UpdateRSSFeedBots()
{
global $db_prefix, $context, $sourcedir, $feedcount, $func, $maxitemcount, $insideitem, $tag, $modSettings;
// First get all the enabled bots
$context['feeds'] = array();
$request = db_query("
SELECT
ID_FEED, ID_BOARD, feedurl, title, postername, updatetime, enabled, html,
ID_MEMBER, locked, articlelink, topicprefix, numbertoimport, importevery
FROM {$db_prefix}feedbot
WHERE enabled = 1", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{
$context['feeds'][] = array(
'ID_FEED' => $row['ID_FEED'],
'ID_BOARD' => $row['ID_BOARD'],
'feedurl' => $row['feedurl'],
'title' => $row['title'],
'postername' => $row['postername'],
'enabled' => $row['enabled'],
'html' => $row['html'],
'ID_MEMBER' => $row['ID_MEMBER'],
'locked' => $row['locked'],
'articlelink' => $row['articlelink'],
'topicprefix' => $row['topicprefix'],
'numbertoimport' => $row['numbertoimport'],
'importevery' => $row['importevery'],
'updatetime' => $row['updatetime']
);
}
mysql_free_result($request);
// For the createPost function
require_once($sourcedir . '/Subs-Post.php');
// Check if a field expired
foreach ($context['feeds'] as $key => $feed)
{
$current_time = time();
// If the feedbot time to next import has expired
if (($current_time + mktime(0, $feed['importevery'])) > $feed['updatetime'])
//if( 1 == 1)
{
$feeddata = GetRSSData($feed['feedurl']);
if ($feeddata != false)
{
// Process the XML
$xml_parser = xml_parser_create();
$context['feeditems'] = array();
$feedcount = 0;
$maxitemcount = $feed['numbertoimport'];
$tag = '';
$insideitem = false;
$context['feeditems'][0] = array();
$context['feeditems'][0][] = array();
$context['feeditems'][0]['title'] = '';
$context['feeditems'][0]['description'] = '';
$context['feeditems'][0]['link'] = '';
xml_set_element_handler($xml_parser, "startElement1", "endElement1");
xml_set_character_data_handler($xml_parser, "characterData1");
if (!xml_parse($xml_parser, $feeddata))
{
// Error reading xml data
xml_parser_free($xml_parser);
}
else
{
// Data must be valid lets extra some information from it
// RSS Feeds are a list of items that might contain title, description, and link
// Free the xml parser memory
xml_parser_free($xml_parser);
// Loop though all the items
for ($i = 0; $i < ($maxitemcount); $i++)
{
// Check feed Log
// Generate the hash for the log
if(!isset($context['feeditems'][$i]['title']) || !isset($context['feeditems'][$i]['description']) || !isset($context['feeditems'][$i]['link']))
continue;
$itemhash = md5($context['feeditems'][$i]['title'] . $context['feeditems'][$i]['description']);
$request = db_query("
SELECT
feedtime
FROM {$db_prefix}feedbot_log
WHERE feedhash = '$itemhash'", __FILE__, __LINE__);
mysql_freeresult($request);
// If no has has found that means no duplicate entry
if (db_affected_rows() == 0)
{
// Create the Post
$msg_title = $func['htmlspecialchars'](($feed['html'] ? $context['feeditems'][$i]['title'] : strip_tags($context['feeditems'][$i]['title'])), ENT_QUOTES);
$msg_body = $func['htmlspecialchars'](($feed['html'] ? $context['feeditems'][$i]['description'] . "\n\n" . $context['feeditems'][$i]['link'] : strip_tags($context['feeditems'][$i]['description'] . "\n\n" . $context['feeditems'][$i]['link'])), ENT_QUOTES);
$msgOptions = array(
'id' => 0,
'subject' => $feed['topicprefix'] . $msg_title,
'body' => '' . $msg_title . "\n\n" . $msg_body,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
);
$topicOptions = array(
'id' => 0,
'board' => $feed['ID_BOARD'],
'poll' => null,
'lock_mode' => $feed['locked'],
'sticky_mode' => null,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => $feed['ID_MEMBER'],
'name' => $feed['postername'],
'email' => '',
'update_post_count' => (($feed['ID_MEMBER'] == 0) ? 0 : 1),
);
createPost($msgOptions, $topicOptions, $posterOptions);
// Add Feed Log
$fid = $feed['ID_FEED'];
$ftime = time();
db_query("
INSERT INTO {$db_prefix}feedbot_log
(ID_FEED, feedhash, feedtime)
VALUES
($fid,'$itemhash',$ftime)", __FILE__, __LINE__);
}
}
} // End valid XML check
} // End get feed data
} // End expire check
} // End for each feed
}
function GetRSSData($url)
{
$url_array = parse_url($url);
if(function_exists("curl_init"))
{
// Last but not least try cUrl
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL, and return output
$output = curl_exec($ch);
// close curl resource, and free up system resources
curl_close($ch);
return $output;
}
// Failure return false
return false;
}
function startElement1($parser, $name, $attrs)
{
global $insideitem, $tag;
if ($insideitem)
{
$tag = $name;
}
elseif ($name == "ITEM")
{
$insideitem = true;
}
}
function endElement1($parser, $name)
{
global $insideitem, $tag, $feedcount, $context;
if ($name == "ITEM")
{
$feedcount++;
$context['feeditems'][$feedcount] = array();
$context['feeditems'][$feedcount][] = array();
$context['feeditems'][$feedcount]['title'] = '';
$context['feeditems'][$feedcount]['description'] = '';
$context['feeditems'][$feedcount]['link'] = '';
$insideitem = false;
}
}
function characterData1($parser, $data)
{
global $insideitem, $tag, $feedcount, $context, $maxitemcount;
if ($insideitem && $feedcount < $maxitemcount)
{
switch ($tag)
{
case "TITLE":
$context['feeditems'][$feedcount]['title'] .= $data;
break;
case "DESCRIPTION":
$context['feeditems'][$feedcount]['description'] .= $data;
break;
case "LINK":
$context['feeditems'][$feedcount]['link'] .= $data;
break;
}
}
}
?>
__________________ Don't let you stop you ;) |
| |
| | #3 (permalink) |
| i love automation Join Date: Nov 2007 Location: xrvel.com
Posts: 1,620
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You can use my simple curl : http://www.tugasku.com/download/sour....class.php.txt It is pretty easy to use
__________________ |
| |
| | #5 (permalink) | ||||
| Senior Member Join Date: Jul 2005
Posts: 1,492
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
__________________ ||||newsiness.com||||'""|""\__,_ | _[lol]___[lol]____ l ||__|__|) |(@)(@)"""""""**|(@)(@)**|(@) 100% Free Online Flash games | ||||
| |
| | #6 (permalink) |
| NamePros Member Join Date: Jul 2006
Posts: 94
![]() ![]() ![]() | If you want to keep the fopen() code in the script, you could just comment it out. Add // before the lines you want to remove. Or enclose the code as a multiline comment using /* code */
__________________ Don't let you stop you ;) |
| |
| | #7 (permalink) | ||||
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft | ||||
| |
| | #9 (permalink) | ||||
| New Member Join Date: Jan 2008
Posts: 5
![]() | In this case
| ||||
| |
| | #10 (permalink) | ||||
| Danltn.com Join Date: May 2007 Location: Danltn.com / Nottingham, UK
Posts: 1,201
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Dan
__________________ | ||||
| |
| | #11 (permalink) | ||||
| i love automation Join Date: Nov 2007 Location: xrvel.com
Posts: 1,620
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Kurniawan.
__________________
Last edited by xrvel; 01-07-2008 at 08:43 PM.
| ||||
| |