public static function add(array $DATA_ = NULL) { $url = $DATA_['uri']; $name = @$DATA_['name']; $post_id = @$DATA_['post_id']; apply_filters('em_object_get_image_type', 'event', false, isset($this) ? $this : self); //Handle the attachment as a WP Post $attachment = ''; $tmpfname = tempnam(ESS_IO::tmp(), "ESS_IMG_" . $post_id . "_"); $h = fopen($tmpfname, "w"); if ($h && strlen($url) > 5) { fwrite($h, file_get_contents($url)); $image_ = getimagesize($tmpfname); switch ($image_['mime']) { case "image/gif": $mime = "gif"; break; case "image/jpeg": $mime = "jpg"; break; case "image/png": $mime = "png"; break; case "image/bmp": $mime = "bmp"; break; } $file = array('tmp_name' => $tmpfname, 'name' => basename($tmpfname), 'type' => $image_[2], 'mime' => $mime, 'width' => $image_[0], 'height' => $image_[1], 'size' => filesize($tmpfname), 'error' => 0); //var_dump( $file ); if (file_exists($file['tmp_name']) && ESS_Images::image_validator($file)) { require_once ABSPATH . "wp-admin" . '/includes/file.php'; require_once ABSPATH . "wp-admin" . '/includes/image.php'; $attachment = ESS_Images::handle_upload($file); if ($attachment) { //echo "DEBUG: <b>". __CLASS__.":".__LINE__."</b>"; //var_dump( $attachment ); $attachment_id = wp_insert_attachment(array('post_mime_type' => $image_['mime'], 'post_title' => $name, 'post_content' => '', 'post_status' => 'inherit'), $attachment['file'], $post_id); $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $attachment['file']); wp_update_attachment_metadata($attachment_id, $attachment_metadata); update_post_meta($post_id, '_thumbnail_id', $attachment_id); update_post_meta($post_id, '_start_ts', date('U')); update_post_meta($post_id, '_end_ts', intval(date('U') + 60 * 60 * 24 * 365)); @fclose($h); if (file_exists($tmpfname)) { @unlink($tmpfname); } return apply_filters('em_object_image_upload', $attachment_id, $this); } } @fclose($h); if (file_exists($tmpfname)) { @unlink($tmpfname); } } return apply_filters('em_object_image_upload', false, $this); }
public static function get_curl_result($target_url, $feed_url = '') { $ch = @curl_init(); $post_data = array('REMOTE_ADDR' => @$_SERVER['REMOTE_ADDR'], 'SERVER_ADMIN' => @$_SERVER['SERVER_ADMIN'], 'PROTOCOL' => stripos(@$_SERVER['SERVER_PROTOCOL'], 'https') === TRUE ? 'https://' : 'http://', 'HTTP_HOST' => @$_SERVER['HTTP_HOST'], 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], 'feed' => urlencode($feed_url)); if ($ch != FALSE) { curl_setopt($ch, CURLOPT_URL, $target_url); curl_setopt($ch, CURLOPT_COOKIEJAR, ESS_IO::tmp() . '/cookies'); curl_setopt($ch, CURLOPT_REFERER, @$_SERVER['REQUEST_URI']); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); $result = curl_exec($ch); //d( $target_url, $feed_url, urlencode( $feed_url ), $result ); return $result; } else { if (ini_get('allow_url_fopen')) { $opts = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded", 'content' => http_build_query($post_data), 'timeout' => 60 * 20)); $result = @file_get_contents($target_url, FALSE, stream_context_create($opts), -1, 40000); //d( $result ); return $result; } else { $file = $target_url . "?"; foreach ($post_data as $att => $value) { $file .= $att . "=" . urlencode($value) . "&"; } $result = @exec("wget -q \"" . $file . "\""); if ($result == FALSE) { global $ESS_Notices; $ESS_Notices->add_error(__("PHP cURL must be installed on your server or PHP parameter 'allow_url_fopen' must be set to TRUE: ", 'dbem') . ESS_Elements::get_curl_lib_link()); } else { return $result; } } } return FALSE; }