<?php
/*
Plugin Name: CURLForce
Plugin URI: http://core.trac.wordpress.org/ticket/11499 
Description: To test CURL, CURL needs to be enforced. Done when activated.
Version: 0.1
Author: hakre
Author URI: http://codex.wordpress.org/User:Hakre
*/
/*  Copyright 2009 by the authors

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/**
 * curlforce plugin class
 * 
 */
class pluginCurlforce
{
	/**
	 * constructor
	 * 
	 * @return this
	 */
	function pluginCurlforce() {
		// configure to use curl only
		add_filter('use_http_extension_transport', array($this, 'transport_disable'), 10, 2);
		add_filter('use_curl_transport',           array($this, 'transport_enable'),  10, 2);
		add_filter('use_streams_transport',        array($this, 'transport_disable'), 10, 2);
		add_filter('use_fopen_transport',          array($this, 'transport_disable'), 10, 2);
		add_filter('use_fsockopen_transport',      array($this, 'transport_disable'), 10, 2);
		
		// validate that only curl is used		
		add_action('http_transport_get_debug', array($this, 'http_transport_get_debug'), 10, 3);			
	}
	
	function transport_disable($flag, $args)
	{
		return false;
	}
	
	function transport_enable($flag, $args)
	{
		return true;
	}
	
	/**
	 * http_transport_get_debug
	 * 
	 * @param array $working_transport     references to objects
	 * @param array $blocking_transport    references to objects
	 * @param array $nonblocking_transport references to objects
	 * @return void
	 * @-wp-action http_transport_get_debug
	 */
	function http_transport_get_debug($working_transport, $blocking_transport, $nonblocking_transport)
	{	 
		do
		{
			if ( get_class($working_transport['curl']) <> 'WP_Http_Curl') 
				continue;
				
			if ( get_class($blocking_transport[0]) <> 'WP_Http_Curl')
				continue;
				
			if ( get_class($nonblocking_transport[0]) <> 'WP_Http_Curl')
				continue;
				
			return; // all ok, all CURL	
			
		} while(false);
		
		throw new Exception('Not enforced on CURL. Check your testcase.');
		
		print 'PHP 4 is outdated.'; 
		die();
		
	}
}

$opluginCurlforce = new pluginCurlforce();
