function drupalgap_sdk_form_submit in DrupalGap 7
Same name and namespace in other branches
- 7.2 drupalgap.module \drupalgap_sdk_form_submit()
File
- ./drupalgap.module, line 441
- A module to provide a bridge between Drupal websites and PhoneGap mobile
applications.
Code
function drupalgap_sdk_form_submit($form, &$form_state) {
global $base_url;
$dir = check_plain($form_state['values']['dir']);
$file = "drupalgap-sdk.zip";
$source = "https://github.com/signalpoint/DrupalGap/archive/7.0.2.zip";
$name = "DrupalGap-7.0.2";
if (file_put_contents($file, file_get_contents($source)) === false) {
return;
}
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive();
$res = $zip
->open($file);
if ($res === TRUE) {
$zip
->extractTo($path);
$zip
->close();
}
else {
drupal_set_message("Failed to unzip the {$file} file!", 'error');
}
if (!rename($name, $dir)) {
drupal_set_message("Failed to move unzipped files to the {$dir} directory!", 'error');
return;
}
$settings = file_get_contents("{$dir}/app/default.settings.js");
$settings = str_replace("Drupal.settings.site_path = '';", "Drupal.settings.site_path = '{$base_url}';", $settings);
if (file_put_contents("{$dir}/app/settings.js", $settings) === false) {
drupal_set_message(t('Failed to create the settings.js file!'), 'error');
}
if (!unlink($file)) {
drupal_set_message(t("Tried deleting the %file file, but failed", array(
'%file' => $file,
)), 'warning');
}
variable_set('drupalgap_sdk_installed', 1);
variable_set('drupalgap_sdk_dir', $dir);
drupal_set_message(t('The DrupalGap SDK was installed successfully! You may now test it below...'));
}