Make WordPress Core

Ticket #11499: 11499-curlforce.php

File 11499-curlforce.php, 2.7 KB (added by hakre, 17 years ago)

Testplugin - Enforce CURL usage

Line 
1<?php
2/*
3Plugin Name: CURLForce
4Plugin URI: http://core.trac.wordpress.org/ticket/11499
5Description: To test CURL, CURL needs to be enforced. Done when activated.
6Version: 0.1
7Author: hakre
8Author URI: http://codex.wordpress.org/User:Hakre
9*/
10/* Copyright 2009 by the authors
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25*/
26
27/**
28 * curlforce plugin class
29 *
30 */
31class pluginCurlforce
32{
33 /**
34 * constructor
35 *
36 * @return this
37 */
38 function pluginCurlforce() {
39 // configure to use curl only
40 add_filter('use_http_extension_transport', array($this, 'transport_disable'), 10, 2);
41 add_filter('use_curl_transport', array($this, 'transport_enable'), 10, 2);
42 add_filter('use_streams_transport', array($this, 'transport_disable'), 10, 2);
43 add_filter('use_fopen_transport', array($this, 'transport_disable'), 10, 2);
44 add_filter('use_fsockopen_transport', array($this, 'transport_disable'), 10, 2);
45
46 // validate that only curl is used
47 add_action('http_transport_get_debug', array($this, 'http_transport_get_debug'), 10, 3);
48 }
49
50 function transport_disable($flag, $args)
51 {
52 return false;
53 }
54
55 function transport_enable($flag, $args)
56 {
57 return true;
58 }
59
60 /**
61 * http_transport_get_debug
62 *
63 * @param array $working_transport references to objects
64 * @param array $blocking_transport references to objects
65 * @param array $nonblocking_transport references to objects
66 * @return void
67 * @-wp-action http_transport_get_debug
68 */
69 function http_transport_get_debug($working_transport, $blocking_transport, $nonblocking_transport)
70 {
71 do
72 {
73 if ( get_class($working_transport['curl']) <> 'WP_Http_Curl')
74 continue;
75
76 if ( get_class($blocking_transport[0]) <> 'WP_Http_Curl')
77 continue;
78
79 if ( get_class($nonblocking_transport[0]) <> 'WP_Http_Curl')
80 continue;
81
82 return; // all ok, all CURL
83
84 } while(false);
85
86 throw new Exception('Not enforced on CURL. Check your testcase.');
87
88 print 'PHP 4 is outdated.';
89 die();
90
91 }
92}
93
94$opluginCurlforce = new pluginCurlforce();