Beispiel #1
0
function load_image_to_edit($post_id, $mime_type, $size = 'full')
{
    $filepath = get_attached_file($post_id);
    if ($filepath && file_exists($filepath)) {
        if ('full' != $size && ($data = image_get_intermediate_size($post_id, $size))) {
            $filepath = path_join(dirname($filepath), $data['file']);
        }
    } elseif (WP_Http_Fopen::test()) {
        $filepath = wp_get_attachment_url($post_id);
    }
    $filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size);
    if (empty($filepath)) {
        return false;
    }
    switch ($mime_type) {
        case 'image/jpeg':
            $image = imagecreatefromjpeg($filepath);
            break;
        case 'image/png':
            $image = imagecreatefrompng($filepath);
            break;
        case 'image/gif':
            $image = imagecreatefromgif($filepath);
            break;
        default:
            $image = false;
            break;
    }
    if (is_resource($image)) {
        $image = apply_filters('load_image_to_edit', $image, $post_id, $size);
        if (function_exists('imagealphablending') && function_exists('imagesavealpha')) {
            imagealphablending($image, false);
            imagesavealpha($image, true);
        }
    }
    return $image;
}
Beispiel #2
0
 /**
  * Tests the WordPress HTTP objects for an object to use and returns it.
  *
  * Tests all of the objects and returns the object that passes. Also caches
  * that object to be used later.
  *
  * The order for the GET/HEAD requests are Streams, HTTP Extension, Fopen,
  * and finally Fsockopen. fsockopen() is used last, because it has the most
  * overhead in its implementation. There isn't any real way around it, since
  * redirects have to be supported, much the same way the other transports
  * also handle redirects.
  *
  * There are currently issues with "localhost" not resolving correctly with
  * DNS. This may cause an error "failed to open stream: A connection attempt
  * failed because the connected party did not properly respond after a
  * period of time, or established connection failed because connected host
  * has failed to respond."
  *
  * @since 2.7.0
  * @access private
  *
  * @param array $args Request args, default us an empty array
  * @return object|null Null if no transports are available, HTTP transport object.
  */
 function &_getTransport($args = array())
 {
     static $working_transport, $blocking_transport, $nonblocking_transport;
     if (is_null($working_transport)) {
         if (true === WP_Http_ExtHttp::test($args)) {
             $working_transport['exthttp'] = new WP_Http_ExtHttp();
             $blocking_transport[] =& $working_transport['exthttp'];
         } else {
             if (true === WP_Http_Curl::test($args)) {
                 $working_transport['curl'] = new WP_Http_Curl();
                 $blocking_transport[] =& $working_transport['curl'];
             } else {
                 if (true === WP_Http_Streams::test($args)) {
                     $working_transport['streams'] = new WP_Http_Streams();
                     $blocking_transport[] =& $working_transport['streams'];
                 } else {
                     if (true === WP_Http_Fopen::test($args)) {
                         $working_transport['fopen'] = new WP_Http_Fopen();
                         $blocking_transport[] =& $working_transport['fopen'];
                     } else {
                         if (true === WP_Http_Fsockopen::test($args)) {
                             $working_transport['fsockopen'] = new WP_Http_Fsockopen();
                             $blocking_transport[] =& $working_transport['fsockopen'];
                         }
                     }
                 }
             }
         }
         foreach (array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport) {
             if (isset($working_transport[$transport])) {
                 $nonblocking_transport[] =& $working_transport[$transport];
             }
         }
     }
     do_action('http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport);
     if (isset($args['blocking']) && !$args['blocking']) {
         return $nonblocking_transport;
     } else {
         return $blocking_transport;
     }
 }
Beispiel #3
0
 /**
  * Tests the WordPress HTTP objects for an object to use and returns it.
  *
  * Tests all of the objects and returns the object that passes. Also caches
  * that object to be used later.
  *
  * The order for the GET/HEAD requests are Streams, HTTP Extension, Fopen,
  * and finally Fsockopen. fsockopen() is used last, because it has the most
  * overhead in its implementation. There isn't any real way around it, since
  * redirects have to be supported, much the same way the other transports
  * also handle redirects.
  *
  * There are currently issues with "localhost" not resolving correctly with
  * DNS. This may cause an error "failed to open stream: A connection attempt
  * failed because the connected party did not properly respond after a
  * period of time, or established connection failed because connected host
  * has failed to respond."
  *
  * @since 2.7
  * @access private
  *
  * @param array $args Request args, default us an empty array
  * @return object|null Null if no transports are available, HTTP transport object.
  */
 function &_getTransport($args = array())
 {
     static $working_transport, $blocking_transport, $nonblocking_transport;
     if (is_null($working_transport)) {
         if (true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true)) {
             $working_transport['exthttp'] = new WP_Http_ExtHttp();
             $blocking_transport[] =& $working_transport['exthttp'];
         } else {
             if (true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true)) {
                 $working_transport['curl'] = new WP_Http_Curl();
                 $blocking_transport[] =& $working_transport['curl'];
             } else {
                 if (true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true)) {
                     $working_transport['streams'] = new WP_Http_Streams();
                     $blocking_transport[] =& $working_transport['streams'];
                 } else {
                     if (true === WP_Http_Fopen::test() && apply_filters('use_fopen_transport', true)) {
                         $working_transport['fopen'] = new WP_Http_Fopen();
                         $blocking_transport[] =& $working_transport['fopen'];
                     } else {
                         if (true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true)) {
                             $working_transport['fsockopen'] = new WP_Http_Fsockopen();
                             $blocking_transport[] =& $working_transport['fsockopen'];
                         }
                     }
                 }
             }
         }
         foreach (array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport) {
             if (isset($working_transport[$transport])) {
                 $nonblocking_transport[] =& $working_transport[$transport];
             }
         }
     }
     if (isset($args['blocking']) && !$args['blocking']) {
         return $nonblocking_transport;
     } else {
         return $blocking_transport;
     }
 }