Пример #1
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 & 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'));
}
Пример #2
0
/**
 * Maybe enable pretty permalinks on install.
 *
 * If after enabling pretty permalinks don't work, fallback to query-string permalinks.
 *
 * @since 0.0.1
 *
 * @global HQ_Rewrite hq_rewrite HiveQueen rewrite component.
 *
 * @return bool Whether pretty permalinks are enabled. False otherwise.
 */
function hq_install_maybe_enable_pretty_permalinks()
{
    global $hq_rewrite;
    // Bail if a permalink structure is already enabled.
    if (get_option('permalink_structure')) {
        return true;
    }
    /*
     * The Permalink structures to attempt.
     *
     * The first is designed for mod_rewrite or nginx rewriting.
     *
     * The second is PATHINFO-based permalinks for web server configurations
     * without a true rewrite module enabled.
     */
    $permalink_structures = array('/%year%/%monthnum%/%day%/%postname%/', '/index.php/%year%/%monthnum%/%day%/%postname%/');
    foreach ((array) $permalink_structures as $permalink_structure) {
        $hq_rewrite->set_permalink_structure($permalink_structure);
        /*
         * Flush rules with the hard option to force refresh of the web-server's
         * rewrite config file (e.g. .htaccess or web.config).
         */
        $hq_rewrite->flush_rules(true);
        // Test against a real HiveQueen Post, or if none were created, a random 404 page.
        $test_url = get_permalink(1);
        if (!$test_url) {
            $test_url = home_url('/hivequeen-check-for-rewrites/');
        }
        /*
         * Send a request to the site, and check whether
         * the 'x-pingback' header is returned as expected.
         *
         * Uses hq_remote_get() instead of hq_remote_head() because web servers
         * can block head requests.
         */
        $response = hq_remote_get($test_url, array('timeout' => 5));
        $x_pingback_header = hq_remote_retrieve_header($response, 'x-pingback');
        $pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo('pingback_url');
        if ($pretty_permalinks) {
            return true;
        }
    }
    /*
     * If it makes it this far, pretty permalinks failed.
     * Fallback to query-string permalinks.
     */
    $hq_rewrite->set_permalink_structure('');
    $hq_rewrite->flush_rules(true);
    return false;
}
Пример #3
0
         * If the network is 50 sites or less, it will run every time. Otherwise,
         * it will throttle itself to reduce load.
         *
         * @since 0.0.1
         *
         * @param bool true Whether to perform the Multisite upgrade routine. Default true.
         */
    } elseif (apply_filters('do_mu_upgrade', true)) {
        $c = get_blog_count();
        /*
         * If there are 50 or fewer sites, run every time. Otherwise, throttle to reduce load:
         * attempt to do no more than threshold value, with some +/- allowed.
         */
        if ($c <= 50 || $c > 50 && mt_rand(0, (int) ($c / 50)) == 1) {
            require_once ABSPATH . HQINC . '/http.php';
            $response = hq_remote_get(admin_url('upgrade.php?step=1'), array('timeout' => 120, 'httpversion' => '1.1'));
            /** This action is documented in hq-admin/network/upgrade.php */
            do_action('after_mu_upgrade', $response);
            unset($response);
        }
        unset($c);
    }
}
require_once ABSPATH . 'hq-admin/includes/admin.php';
auth_redirect();
// Schedule trash collection
if (!hq_next_scheduled('hq_scheduled_delete') && !defined('HQ_INSTALLING')) {
    hq_schedule_event(time(), 'daily', 'hq_scheduled_delete');
}
set_screen_options();
$date_format = get_option('date_format');
Пример #4
0
/**
 * Populate network settings.
 *
 * @since 0.0.1
 *
 * @global hqdb       $hqdb
 * @global object     $current_site
 * @global int        $hq_db_version
 * @global HQ_Rewrite $hq_rewrite
 *
 * @param int $network_id ID of network to populate.
 * @return bool|HQ_Error True on success, or HQ_Error on warning (with the install otherwise successful,
 *                       so the error code must be checked) or failure.
 */
function populate_network($network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false)
{
    global $hqdb, $current_site, $hq_db_version, $hq_rewrite;
    $errors = new HQ_Error();
    if ('' == $domain) {
        $errors->add('empty_domain', __('You must provide a domain name.'));
    }
    if ('' == $site_name) {
        $errors->add('empty_sitename', __('You must provide a name for your network of sites.'));
    }
    // Check for network collision.
    if ($network_id == $hqdb->get_var($hqdb->prepare("SELECT id FROM {$hqdb->site} WHERE id = %d", $network_id))) {
        $errors->add('siteid_exists', __('The network already exists.'));
    }
    $site_user = get_user_by('email', $email);
    if (!is_email($email)) {
        $errors->add('invalid_email', __('You must provide a valid e-mail address.'));
    }
    if ($errors->get_error_code()) {
        return $errors;
    }
    // Set up site tables.
    $template = get_option('template');
    $stylesheet = get_option('stylesheet');
    $allowed_themes = array($stylesheet => true);
    if ($template != $stylesheet) {
        $allowed_themes[$template] = true;
    }
    if (HQ_DEFAULT_THEME != $stylesheet && HQ_DEFAULT_THEME != $template) {
        $allowed_themes[HQ_DEFAULT_THEME] = true;
    }
    if (1 == $network_id) {
        $hqdb->insert($hqdb->site, array('domain' => $domain, 'path' => $path));
        $network_id = $hqdb->insert_id;
    } else {
        $hqdb->insert($hqdb->site, array('domain' => $domain, 'path' => $path, 'id' => $network_id));
    }
    hq_cache_delete('networks_have_paths', 'site-options');
    //TODO: no multisite
    //if ( !is_multisite() ) {
    $site_admins = array($site_user->user_login);
    $users = get_users(array('fields' => array('ID', 'user_login')));
    if ($users) {
        foreach ($users as $user) {
            if (is_super_admin($user->ID) && !in_array($user->user_login, $site_admins)) {
                $site_admins[] = $user->user_login;
            }
        }
    }
    //} else {
    //	$site_admins = get_site_option( 'site_admins' );
    //}
    /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */
    $welcome_email = __('Howdy USERNAME,

Your new SITE_NAME site has been successfully set up at:
BLOG_URL

You can log in to the administrator account with the following information:

Username: USERNAME
Password: PASSWORD
Log in here: BLOG_URLhq-login.php

We hope you enjoy your new site. Thanks!

--The Team @ SITE_NAME');
    $misc_exts = array('jpg', 'jpeg', 'png', 'gif', 'mov', 'avi', 'mpg', '3gp', '3g2', 'midi', 'mid', 'pdf', 'doc', 'ppt', 'odt', 'pptx', 'docx', 'pps', 'ppsx', 'xls', 'xlsx', 'key');
    $audio_exts = hq_get_audio_extensions();
    $video_exts = hq_get_video_extensions();
    $upload_filetypes = array_unique(array_merge($misc_exts, $audio_exts, $video_exts));
    $sitemeta = array('site_name' => $site_name, 'admin_email' => $site_user->user_email, 'admin_user_id' => $site_user->ID, 'registration' => 'none', 'upload_filetypes' => implode(' ', $upload_filetypes), 'blog_upload_space' => 100, 'fileupload_maxk' => 1500, 'site_admins' => $site_admins, 'allowedthemes' => $allowed_themes, 'illegal_names' => array('www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files'), 'hqmu_upgrade_site' => $hq_db_version, 'welcome_email' => $welcome_email, 'first_post' => __('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!'), 'siteurl' => get_option('siteurl') . '/', 'add_new_users' => '0', 'upload_space_check_disabled' => '1', 'subdomain_install' => intval($subdomain_install), 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 'ms_files_rewriting' => '0', 'initial_db_version' => get_option('initial_db_version'), 'active_sitewide_plugins' => array(), 'HQLANG' => get_locale());
    if (!$subdomain_install) {
        $sitemeta['illegal_names'][] = 'blog';
    }
    /**
     * Filter meta for a network on creation.
     *
     * @since 0.0.1
     *
     * @param array $sitemeta   Associative array of network meta keys and values to be inserted.
     * @param int   $network_id ID of network to populate.
     */
    $sitemeta = apply_filters('populate_network_meta', $sitemeta, $network_id);
    $insert = '';
    foreach ($sitemeta as $meta_key => $meta_value) {
        if (is_array($meta_value)) {
            $meta_value = serialize($meta_value);
        }
        if (!empty($insert)) {
            $insert .= ', ';
        }
        $insert .= $hqdb->prepare("( %d, %s, %s)", $network_id, $meta_key, $meta_value);
    }
    $hqdb->query("INSERT INTO {$hqdb->sitemeta} ( site_id, meta_key, meta_value ) VALUES " . $insert);
    /*
     * When upgrading from single to multisite, assume the current site will
     * become the main site of the network. When using populate_network()
     * to create another network in an existing multisite environment, skip
     * these steps since the main site of the new network has not yet been
     * created.
     */
    //TODO: no multisite
    //if ( ! is_multisite() ) {
    $current_site = new stdClass();
    $current_site->domain = $domain;
    $current_site->path = $path;
    $current_site->site_name = ucfirst($domain);
    $hqdb->insert($hqdb->blogs, array('site_id' => $network_id, 'blog_id' => 1, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')));
    $current_site->blog_id = $blog_id = $hqdb->insert_id;
    update_user_meta($site_user->ID, 'source_domain', $domain);
    update_user_meta($site_user->ID, 'primary_blog', $blog_id);
    if ($subdomain_install) {
        $hq_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
    } else {
        $hq_rewrite->set_permalink_structure('/blog/%year%/%monthnum%/%day%/%postname%/');
    }
    flush_rewrite_rules();
    if (!$subdomain_install) {
        return true;
    }
    $vhost_ok = false;
    $errstr = '';
    $hostname = substr(md5(time()), 0, 6) . '.' . $domain;
    // Very random hostname!
    $page = hq_remote_get('http://' . $hostname, array('timeout' => 5, 'httpversion' => '1.1'));
    if (is_hq_error($page)) {
        $errstr = $page->get_error_message();
    } elseif (200 == hq_remote_retrieve_response_code($page)) {
        $vhost_ok = true;
    }
    if (!$vhost_ok) {
        $msg = '<p><strong>' . __('Warning! Wildcard DNS may not be configured correctly!') . '</strong></p>';
        $msg .= '<p>' . sprintf(__('The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.'), $hostname);
        if (!empty($errstr)) {
            $msg .= ' ' . sprintf(__('This resulted in an error message: %s'), '<code>' . $errstr . '</code>');
        }
        $msg .= '</p>';
        $msg .= '<p>' . __('To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a <code>*</code> hostname record pointing at your web server in your DNS configuration tool.') . '</p>';
        $msg .= '<p>' . __('You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.') . '</p>';
        return new HQ_Error('no_wildcard_dns', $msg);
    }
    //}
    return true;
}