Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced file_get_contents with culr_file_get_contents to work when h… #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions wp-quick-install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
$data = json_encode( parse_ini_file( 'data.ini' ) );
}

function curl_file_get_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);

if ($contents) return $contents;
else return FALSE;
}

// We add ../ to directory
$directory = ! empty( $_POST['directory'] ) ? '../' . $_POST['directory'] . '/' : '../';

Expand Down Expand Up @@ -80,14 +92,15 @@
$language = substr( $_POST['language'], 0, 6 );

// Get WordPress data
$wp = json_decode( file_get_contents( WP_API_CORE . $language ) )->offers[0];
$wp = json_decode( curl_file_get_contents( WP_API_CORE . $language ) )->offers[0];
$wp->download = str_replace('http:', 'https:', $wp->download); // Prevent http result: 301 - Moved permanently

/*--------------------------*/
/* We download the latest version of WordPress
/*--------------------------*/

if ( ! file_exists( WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip' ) ) {
file_put_contents( WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip', file_get_contents( $wp->download ) );
file_put_contents( WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip', curl_file_get_contents( $wp->download ) );
}

break;
Expand All @@ -98,7 +111,7 @@
$language = substr( $_POST['language'], 0, 6 );

// Get WordPress data
$wp = json_decode( file_get_contents( WP_API_CORE . $language ) )->offers[0];
$wp = json_decode( curl_file_get_contents( WP_API_CORE . $language ) )->offers[0];

/*--------------------------*/
/* We create the website folder with the files and the WordPress folder
Expand Down Expand Up @@ -151,7 +164,7 @@
$config_file = file( $directory . 'wp-config-sample.php' );

// Managing the security keys
$secret_keys = explode( "\n", file_get_contents( 'https://api.wordpress.org/secret-key/1.1/salt/' ) );
$secret_keys = explode( "\n", curl_file_get_contents( 'https://api.wordpress.org/secret-key/1.1/salt/' ) );

foreach ( $secret_keys as $k => $v ) {
$secret_keys[$k] = substr( $v, 28, 64 );
Expand Down Expand Up @@ -482,15 +495,15 @@
foreach ( $plugins as $plugin ) {

// We retrieve the plugin XML file to get the link to downlad it
$plugin_repo = file_get_contents( "http://api.wordpress.org/plugins/info/1.0/$plugin.json" );
$plugin_repo = curl_file_get_contents( "http://api.wordpress.org/plugins/info/1.0/$plugin.json" );

if ( $plugin_repo && $plugin = json_decode( $plugin_repo ) ) {

$plugin_path = WPQI_CACHE_PLUGINS_PATH . $plugin->slug . '-' . $plugin->version . '.zip';

if ( ! file_exists( $plugin_path ) ) {
// We download the lastest version
if ( $download_link = file_get_contents( $plugin->download_link ) ) {
if ( $download_link = curl_file_get_contents( $plugin->download_link ) ) {
file_put_contents( $plugin_path, $download_link );
} }

Expand Down Expand Up @@ -665,7 +678,7 @@
<option value="en_US">English (United States)</option>
<?php
// Get all available languages
$languages = json_decode( file_get_contents( 'http://api.wordpress.org/translations/core/1.0/?version=4.0' ) )->translations;
$languages = json_decode( curl_file_get_contents( 'http://api.wordpress.org/translations/core/1.0/?version=4.0' ) )->translations;

foreach ( $languages as $language ) {
echo '<option value="' . $language->language . '">' . $language->native_name . '</option>';
Expand Down