Making Curl Work with Linkman for Allow_URL_fopen

software development

#1

Hi I’m trying to edit linkman so it works with CURL instead of going through the tedious task of allowing url_fopen on all of my sites.

I understand there’s an alternative for get_file_contents: http://wiki.dreamhost.com/index.php/CURL#Alternative_for_file_get_contents.28.29

But how would you edit the script so it uses this alternative?


/* Get HTML code of the reciprocal link URL */
$html = @file_get_contents($recurl) or problem(‘Can’t open remote URL!’);
$html = strtolower($html);
$site_url = strtolower($settings[‘site_url’]);

/* Block links with the meta “robots” noindex or nofollow tags? /
if ($settings[‘block_meta_rob’]==1 && preg_match(’/<meta([^>]+)(noindex|nofollow)(.
)>/siU’,$html,$meta))
{
problem(
‘Please don’t place the reciprocal link to a page with the meta robots noindex or nofollow tag:
’.
htmlspecialchars($meta[0])
);
}

$found = 0;
$nofollow = 0;

if (preg_match_all(’/<a\s[^>]href=(["’]??)([^" >]?)\1([^>]*)>/siU’, $html, $matches, PREG_SET_ORDER)) {
foreach($matches as $match)
{
if ($match[2] == $settings[‘site_url’] || $match[2] == $settings[‘site_url’].’/’)
{
$found = 1;
if (strstr($match[3],‘nofollow’))
{
$nofollow = 1;
}
break;
}
}
}

if ($found == 0)
{
problem(
‘Our URL (’.$settings[‘site_url’].
) wasn’t found on your reciprocal links page (’.
$recurl.’
)!

Please make sure you place this exact URL on your
links page before submitting your link!’
);
}

/* Block links with rel=“nofollow” attribute? */
if ($settings[‘block_nofollow’] && $nofollow == 1)
{
problem(‘Please don’t use rel=“nofollow” link attribute for the reciprocal link!’);
}


#2

In theory, all you would need to do is replace this line:$html = @file_get_contents($recurl) or problem('Can\'t open remote URL!');with this:$ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, $recurl); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $html = curl_exec($ch); curl_close($ch);
si-blog
Max discount on any plan with promocode SCJESSEYTOTAL


#3

Thanks for the reply, unfortunately it didn’t work for me :frowning:

Any other suggestions would be appreciated.

Best regards,
Al


#4

In that case, I recommend contacting the developers.

si-blog
Max discount on any plan with promocode SCJESSEYTOTAL