Пример #1
0
/**
 * Retrieve translations from HiveQueen Translation API.
 *
 * @since 0.0.1
 *
 * @param string       $type Type of translations. Accepts 'plugins', 'themes', 'core'.
 * @param array|object $args Translation API arguments. Optional.
 * @return object|HQ_Error On success an object of translations, HQ_Error on failure.
 */
function translations_api($type, $args = null)
{
    include ABSPATH . HQINC . '/version.php';
    // include an unmodified $hq_version
    if (!in_array($type, array('plugins', 'themes', 'core'))) {
        return new HQ_Error('invalid_type', __('Invalid translation type.'));
    }
    /**
     * Allows a plugin to override the HiveQueen.org Translation Install API entirely.
     *
     * @since 0.0.1
     *
     * @param bool|array  $result The result object. Default false.
     * @param string      $type   The type of translations being requested.
     * @param object      $args   Translation API arguments.
     */
    $res = apply_filters('translations_api', false, $type, $args);
    if (false === $res) {
        $url = $http_url = 'http://api.wordpress.org/translations/' . $type . '/1.0/';
        if ($ssl = hq_http_supports(array('ssl'))) {
            $url = set_url_scheme($url, 'https');
        }
        $options = array('timeout' => 3, 'body' => array('hq_version' => $hq_version, 'locale' => get_locale(), 'version' => $args['version']));
        if ('core' !== $type) {
            $options['body']['slug'] = $args['slug'];
            // Plugin or theme slug
        }
        $request = hq_remote_post($url, $options);
        if ($ssl && is_hq_error($request)) {
            trigger_error(__('An unexpected error occurred. Something may be wrong with HiveQueen.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://github.com/gcorral/hivequeen">support</a>.') . ' ' . __('(HiveQueen could not establish a secure connection to HiveQueen.org. Please contact your server administrator.)'), headers_sent() || HQ_DEBUG ? E_USER_WARNING : E_USER_NOTICE);
            $request = hq_remote_post($http_url, $options);
        }
        if (is_hq_error($request)) {
            $res = new HQ_Error('translations_api_failed', __('An unexpected error occurred. Something may be wrong with HiveQueen.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://github.com/gcorral/hivequeen">support</a>.'), $request->get_error_message());
        } else {
            $res = json_decode(hq_remote_retrieve_body($request), true);
            if (!is_object($res) && !is_array($res)) {
                $res = new HQ_Error('translations_api_failed', __('An unexpected error occurred. Something may be wrong with HiveQueen.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://github.com/gcorral/hivequeen">support</a>.'), hq_remote_retrieve_body($request));
            }
        }
    }
    /**
     * Filter the Translation Install API response results.
     *
     * @since 0.0.1
     *
     * @param object|HQ_Error $res  Response object or HQ_Error.
     * @param string          $type The type of translations being requested.
     * @param object          $args Translation API arguments.
     */
    return apply_filters('translations_api_result', $res, $type, $args);
}
Пример #2
0
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 0.0.1
 *
 * @param string $url URL to ping.
 * @param int $deprecated Not Used.
 * @return false|string False on failure, string containing URI on success.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not an URL. This should never happen.
        return false;
    }
    //Do not search for a pingback server on our own uploads
    $uploads_dir = hq_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = hq_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_hq_error($response)) {
        return false;
    }
    if (hq_remote_retrieve_header($response, 'x-pingback')) {
        return hq_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', hq_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
    $response = hq_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_hq_error($response)) {
        return false;
    }
    $contents = hq_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = $quote == '"' ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}
Пример #3
0
/**
 * Returns a list from HiveQueen.org of popular importer plugins.
 *
 * @since 0.0.1
 *
 * @return array Importers with metadata for each.
 */
function hq_get_popular_importers()
{
    include ABSPATH . HQINC . '/version.php';
    // include an unmodified $hq_version
    $locale = get_locale();
    $popular_importers = get_site_transient('popular_importers_' . $locale);
    if (!$popular_importers) {
        $url = add_query_arg('locale', get_locale(), 'http://api.wordpress.org/core/importers/1.1/');
        $options = array('user-agent' => 'HiveQueen/' . $hq_version . '; ' . home_url());
        $response = hq_remote_get($url, $options);
        $popular_importers = json_decode(hq_remote_retrieve_body($response), true);
        if (is_array($popular_importers)) {
            set_site_transient('popular_importers_' . $locale, $popular_importers, 2 * DAY_IN_SECONDS);
        } else {
            $popular_importers = false;
        }
    }
    if (is_array($popular_importers)) {
        // If the data was received as translated, return it as-is.
        if ($popular_importers['translated']) {
            return $popular_importers['importers'];
        }
        foreach ($popular_importers['importers'] as &$importer) {
            $importer['description'] = translate($importer['description']);
            if ($importer['name'] != 'HiveQueen') {
                $importer['name'] = translate($importer['name']);
            }
        }
        return $popular_importers['importers'];
    }
    return array('blogger' => array('name' => __('Blogger'), 'description' => __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'), 'plugin-slug' => 'blogger-importer', 'importer-id' => 'blogger'), 'hqcat2tag' => array('name' => __('Categories and Tags Converter'), 'description' => __('Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.'), 'plugin-slug' => 'hqcat2tag-importer', 'importer-id' => 'hq-cat2tag'), 'livejournal' => array('name' => __('LiveJournal'), 'description' => __('Install the LiveJournal importer to import posts from LiveJournal using their API.'), 'plugin-slug' => 'livejournal-importer', 'importer-id' => 'livejournal'), 'movabletype' => array('name' => __('Movable Type and TypePad'), 'description' => __('Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.'), 'plugin-slug' => 'movabletype-importer', 'importer-id' => 'mt'), 'opml' => array('name' => __('Blogroll'), 'description' => __('Install the blogroll importer to import links in OPML format.'), 'plugin-slug' => 'opml-importer', 'importer-id' => 'opml'), 'rss' => array('name' => __('RSS'), 'description' => __('Install the RSS importer to import posts from an RSS feed.'), 'plugin-slug' => 'rss-importer', 'importer-id' => 'rss'), 'tumblr' => array('name' => __('Tumblr'), 'description' => __('Install the Tumblr importer to import posts &amp; media from Tumblr using their API.'), 'plugin-slug' => 'tumblr-importer', 'importer-id' => 'tumblr'), 'hivequeen' => array('name' => 'HiveQueen', 'description' => __('Install the HiveQueen importer to import posts, pages, comments, custom fields, categories, and tags from a HiveQueen export file.'), 'plugin-slug' => 'wordpress-importer', 'importer-id' => 'wordpress'));
}
Пример #4
0
/**
 * HTTP request for URI to retrieve content.
 *
 * @since 0.0.1
 *
 * @see hq_safe_remote_get()
 *
 * @param string $uri URI/URL of web page to retrieve.
 * @return false|string HTTP content. False on failure.
 */
function hq_remote_fopen($uri)
{
    $parsed_url = @parse_url($uri);
    if (!$parsed_url || !is_array($parsed_url)) {
        return false;
    }
    $options = array();
    $options['timeout'] = 10;
    $response = hq_safe_remote_get($uri, $options);
    if (is_hq_error($response)) {
        return false;
    }
    return hq_remote_retrieve_body($response);
}