/**
 * {@internal Missing Short Description}}
 *
 * @since 1.4.0
 *
 * @return unknown
 */
function hacklogra_upyun_media_upload_handler()
{
    global $is_iphone;
    $errors = array();
    $id = 0;
    if (isset($_GET['code']) && isset($_GET['message']) && isset($_GET['url']) && isset($_GET['time'])) {
        $id = hacklogra_upyun::handle_form_api_upload($_REQUEST['post_id'], $post_data = array());
        unset($_FILES);
        if (is_wp_error($id)) {
            $errors['upload_error'] = $id;
            $id = false;
        }
    }
    if (!empty($_POST['insertonlybutton'])) {
        $src = $_POST['src'];
        if (!empty($src) && !strpos($src, '://')) {
            $src = "http://{$src}";
        }
        if (isset($_POST['media_type']) && 'image' != $_POST['media_type']) {
            $title = esc_html(stripslashes($_POST['title']));
            if (empty($title)) {
                $title = esc_html(basename($src));
            }
            if ($title && $src) {
                $html = "<a href='" . esc_url($src) . "'>{$title}</a>";
            }
            $type = 'file';
            if (($ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $src)) && ($ext_type = wp_ext2type($ext)) && ('audio' == $ext_type || 'video' == $ext_type)) {
                $type = $ext_type;
            }
            $html = apply_filters($type . '_send_to_editor_url', $html, esc_url_raw($src), $title);
        } else {
            $align = '';
            $alt = esc_attr(stripslashes($_POST['alt']));
            if (isset($_POST['align'])) {
                $align = esc_attr(stripslashes($_POST['align']));
                $class = " class='align{$align}'";
            }
            if (!empty($src)) {
                $html = "<img src='" . esc_url($src) . "' alt='{$alt}'{$class} />";
            }
            $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);
        }
        return media_send_to_editor($html);
    }
    if (!empty($_POST)) {
        $return = media_upload_form_handler();
        if (is_string($return)) {
            return $return;
        }
        if (is_array($return)) {
            $errors = $return;
        }
    }
    if (isset($_POST['save'])) {
        $errors['upload_notice'] = __('Saved.');
        return media_upload_gallery();
    }
    if (isset($_GET['tab']) && $_GET['tab'] == 'type_url') {
        $type = 'image';
        if (isset($_GET['type']) && in_array($_GET['type'], array('video', 'audio', 'file'))) {
            $type = $_GET['type'];
        }
        return wp_iframe('media_upload_type_url_form', $type, $errors, $id);
    }
    if ($is_iphone) {
        return wp_iframe('media_upload_type_url_form', 'image', $errors, $id);
    } else {
        return wp_iframe(array('hacklogra_upyun', 'media_upload_type_form_upyun'), 'file', $errors, $id);
    }
}
 /**
  * set up rest connection
  * @static
  * @param $args
  * @return bool
  */
 public static function setup_rest($args = null)
 {
     //if object not inited.
     if (null == self::$fs) {
         $credentials = array('api_domain' => self::$rest_server, 'timeout' => self::$rest_timeout, 'bucketname' => self::$bucketname, 'username' => self::$rest_user, 'password' => self::decrypt(self::$rest_pwd), 'form_api_secret' => self::$form_api_secret, 'form_api_allowed_ext' => self::$form_api_allowed_ext, 'form_api_content_max_length' => self::$form_api_content_max_length, 'form_api_timeout' => self::$form_api_timeout, 'anti_leech_token' => self::$anti_leech_token, 'anti_leech_timeout' => self::$anti_leech_timeout);
         if (null != $args) {
             $credentials = array_merge($credentials, $args);
         }
         self::$fs = new UpYun($credentials);
         if (!self::$fs) {
             return FALSE;
         }
     }
     return true;
 }