Spam Karma 2, Dreamhost and cURL
This blog is protected by the most excellent Spam Karma plugin and is hosted on the most excellent host, Dreamhost.
There’s one small problem with this set-up, though. Spam Karma uses the allow_url_fopen() functionality of PHP, which Dreamhost has disabled for security reasons.
What follows is a replacement function that rewrites one function using cURL to achieve the same goals, thus allowing full SK2 functionality on Dreamhost.
In the file sk2_functions.php, replace function sk2_get_url_content with this:
function sk2_get_url_content($url, $level = 0, $convert_case = false)
{
if ($level > 8)
return "";
$buffer = "";
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL, $url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if ($level >= 0)
if (preg_match_all("/< (script|iframe) [^>]*src=”([^”]*)”[^>]*>/”, $buffer, $matches))
{
foreach ($matches[2] as $match)
{
$buffer .= “**embedded:$match**”;
$new_url = $match;
if (! strncmp($new_url, “http”, 7))
$new_url = $url . “/” . $new_url;
$buffer .= “***\n” . sk2_get_url_content($new_url, $level+1);
}
}
return $buffer;
}
Note that the timeout is pretty tight, I don’t like waiting. So, if you have a slower connection (or more patience) you might want to increase the value of CURLOPT_CONNECTTIMEOUT.
Also, in the file sk2_referrer_check_plugin.php there are checks for allow_url_fopen(), which we can now safely comment out:
function filter_this(&$cmt_object)
{
if (! $cmt_object->is_trackback())
return;
/*
jason [at] ushmitsudoki [dot] com - 20050427
won't be needing to check this anymore
if( ! ini_get('allow_url_fopen'))
{
$this->log_msg("allow_url_fopen is disabled on this PHP install: sk2_referrer_check_plugin cannot run.” , 5);
return;
}
*/
and one more edit in the same file:
function output_plugin_UI()
{
echo "
- “;
parent::output_plugin_UI(false); // call default constructor
/*
jason [at] ushmitsudoki [dot] com - 20050427
won’t be needing to check this anymore
if(! ini_get(’allow_url_fopen’))
echo “
-
allow_url_fopenis disabled on this PHP install: TB Referrer Check plugin cannot run. You should disable it.
“;
*/
echo “
Finally, I’m not a WordPress, PHP, or SpamKarma developer, so use this at your own peril. Corrections and comments welcome.