Example #1
0
/**
 *  DUPLICATOR_CREATE_INSTALLERFILE
 *  Prep the Installer file for use. use %string% token for replacing 
 *  @param string $uniquename	The unique name this installer file will be associated with
 */
function duplicator_create_installerFile($uniquename, $table_id)
{
    duplicator_log("INSTALLER FILE: Preping for use");
    global $wpdb;
    $result = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}duplicator` WHERE ID = {$table_id}", ARRAY_A);
    $result_row = $result[0];
    $settings = unserialize($result_row['settings']);
    $notes = empty($settings['notes']) ? 'No notes found for package.' : $settings['notes'];
    $template = duplicator_safe_path(DUPLICATOR_PLUGIN_PATH . 'files/installer.template.php');
    $installerCore = duplicator_safe_path(DUPLICATOR_SSDIR_PATH) . "/{$uniquename}_installer.php";
    $err_msg = "ERROR: Unable to read/write installer.  \nERROR INFO: Please check permission and owner on file and parent folder. \nInstaller File=<{$installerCore}>";
    get_option('duplicator_options') == "" ? "" : ($duplicator_opts = unserialize(get_option('duplicator_options')));
    $replace_items = array("fwrite_url_old" => get_option('siteurl'), "fwrite_package_name" => "{$uniquename}_package.zip", "fwrite_package_notes" => $notes, "fwrite_secure_name" => "{$uniquename}", "fwrite_url_new" => $duplicator_opts['url_new'], "fwrite_dbhost" => $duplicator_opts['dbhost'], "fwrite_dbname" => $duplicator_opts['dbname'], "fwrite_dbuser" => $duplicator_opts['dbuser'], "fwrite_dbpass" => '', "fwrite_ssl_admin" => $duplicator_opts['ssl_admin'], "fwrite_ssl_login" => $duplicator_opts['ssl_login'], "fwrite_cache_wp" => $duplicator_opts['cache_wp'], "fwrite_cache_path" => $duplicator_opts['cache_path'], "fwrite_wp_tableprefix" => $wpdb->prefix, "fwrite_blogname" => @addslashes(get_option('blogname')), "fwrite_wproot" => DUPLICATOR_WPROOTPATH, "fwrite_duplicator_version" => DUPLICATOR_VERSION);
    if (file_exists($template) && is_readable($template)) {
        $install_str = duplicator_parse_template($template, $replace_items);
        if (empty($install_str)) {
            duplicator_error("{$err_msg} \n duplicator_create_installerFile=>file-empty-read");
        }
        //INSTALLER FILE
        if (!file_exists($installerCore)) {
            $fp2 = fopen($installerCore, 'x+') or duplicator_error("{$err_msg} \n duplicator_create_installerFile=>file-open-error-x");
        } else {
            $fp2 = fopen($installerCore, 'w') or duplicator_error("{$err_msg} \n duplicator_create_installerFile=>file-open-error-w");
        }
        if (!fwrite($fp2, $install_str, strlen($install_str))) {
            duplicator_error("{$err_msg} \n duplicator_create_installerFile=>file-write-error");
        }
        @fclose($fp2);
    } else {
        duplicator_error("ERROR: Installer Template missing or unreadable. \nERROR INFO: Template [{$template}]");
    }
    duplicator_log("INSTALLER FILE: Complete [{$installerCore}]");
}
Example #2
0
/**
 *  DUPLICATOR_CREATE_INSTALLERFILE
 *  Prep the Installer file for use. use %string% token for replacing 
 *  @param string $uniquename	The unique name this installer file will be associated with
 */
function duplicator_create_installerFile($uniquename)
{
    duplicator_log("MAKING INSTALLER FILE");
    global $wpdb;
    $template = duplicator_safe_path(DUPLICATOR_PLUGIN_PATH . 'files/installer.template.php');
    $installerRescue = duplicator_safe_path(DUPLICATOR_PLUGIN_PATH . 'files/installer.rescue.php');
    $installerCore = duplicator_safe_path(DUPLICATOR_SSDIR_PATH) . "/{$uniquename}_installer.php";
    $err_msg = "\n!!!WARNING!!! unable to read/write installer\nSee file:{$installerCore} \nPlease check permission and owner on file and parent folder.";
    get_option('duplicator_options') == "" ? "" : ($duplicator_opts = unserialize(get_option('duplicator_options')));
    $replace_items = array("fwrite_url_old" => get_option('siteurl'), "fwrite_package_name" => "{$uniquename}_package.zip", "fwrite_secure_name" => "{$uniquename}", "fwrite_url_new" => $duplicator_opts['url_new'], "fwrite_dbhost" => $duplicator_opts['dbhost'], "fwrite_dbname" => $duplicator_opts['dbname'], "fwrite_dbuser" => $duplicator_opts['dbuser'], "fwrite_wp_tableprefix" => $wpdb->prefix, "fwrite_blogname" => @addslashes(get_option('blogname')), "fwrite_wproot" => DUPLICATOR_WPROOTPATH, "fwrite_rescue_flag" => "");
    if (file_exists($template) && is_readable($template)) {
        $install_str = duplicator_parse_template($template, $replace_items);
        if (empty($install_str)) {
            die(duplicator_log("WARNING: fun__create_installerFile=>file-empty-read" . $err_msg));
        }
        //RESCUE FILE
        $replace_items["fwrite_rescue_flag"] = '(rescue file)';
        $rescue_str = duplicator_parse_template($template, $replace_items);
        $fp = fopen($installerRescue, !file_exists($installerRescue) ? 'x+' : 'w');
        @fwrite($fp, $rescue_str, strlen($rescue_str));
        @fclose($fp);
        $rescue_str = null;
        //INSTALLER FILE
        if (!file_exists($installerCore)) {
            $fp2 = fopen($installerCore, 'x+') or die(duplicator_log("WARNING: fun__create_installerFile=>file-open-error-x" . $err_msg));
        } else {
            $fp2 = fopen($installerCore, 'w') or die(duplicator_log("WARNING: fun__create_installerFile=>file-open-error-w" . $err_msg));
        }
        if (fwrite($fp2, $install_str, strlen($install_str))) {
            duplicator_log("INSTALLER MADE: {$installerCore}");
        } else {
            duplicator_log("WARNING: fun__create_installerFile=>file-create-error" . $err_msg);
        }
        @fclose($fp2);
    } else {
        die(duplicator_log("WARNING: fun__create_installerFile=>Template missing or unreadable: '{$template}'"));
    }
    duplicator_log("INSTALLER FILE COMPLETED");
}