Ejemplo n.º 1
0
 public function testzip_dir()
 {
     //execute the method and verify the if zipped file exist
     $cache_dir = rtrim($GLOBALS['sugar_config']['cache_dir'], '/\\');
     $file = $cache_dir . '/zipTest.zip';
     if (file_exists($file)) {
         unlink($file);
     }
     zip_dir($cache_dir . '/modules', $file);
     $this->assertFileExists($file);
     unlink($file);
 }
Ejemplo n.º 2
0
function processBackupForm()
{
    global $backup_dir;
    global $backup_zip;
    global $input_disabled;
    global $run;
    global $mod_strings;
    $errors = array();
    // process "run" commands
    if (isset($_REQUEST['run']) && $_REQUEST['run'] != "") {
        $run = $_REQUEST['run'];
        $backup_dir = $_REQUEST['backup_dir'];
        $backup_zip = $_REQUEST['backup_zip'];
        if ($run == "confirm") {
            if ($backup_dir == "") {
                $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_ERROR'];
            }
            if ($backup_zip == "") {
                $errors[] = $mod_strings['LBL_BACKUP_FILENAME_ERROR'];
            }
            if (sizeof($errors) > 0) {
                return $errors;
            }
            if (!is_dir($backup_dir)) {
                if (!mkdir_recursive($backup_dir)) {
                    $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_EXISTS'];
                }
            }
            if (!is_writable($backup_dir)) {
                $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_NOT_WRITABLE'];
            }
            if (is_file("{$backup_dir}/{$backup_zip}")) {
                $errors[] = $mod_strings['LBL_BACKUP_FILE_EXISTS'];
            }
            if (is_dir("{$backup_dir}/{$backup_zip}")) {
                $errors[] = $mod_strings['LBL_BACKUP_FILE_AS_SUB'];
            }
            if (sizeof($errors) == 0) {
                $run = "confirmed";
                $input_disabled = "readonly";
            }
        } else {
            if ($run == "confirmed") {
                ini_set("memory_limit", "-1");
                ini_set("max_execution_time", "0");
                zip_dir(".", "{$backup_dir}/{$backup_zip}");
                $run = "done";
            }
        }
    }
    return $errors;
}
Ejemplo n.º 3
0
    /**
     * @see SugarView::display()
     */
    public function display()
    {
        require_once 'include/utils/zip_utils.php';
        $form_action = "index.php?module=Administration&action=Backups";
        $backup_dir = "";
        $backup_zip = "";
        $run = "confirm";
        $input_disabled = "";
        global $mod_strings;
        $errors = array();
        // process "run" commands
        if (isset($_REQUEST['run']) && $_REQUEST['run'] != "") {
            $run = $_REQUEST['run'];
            $backup_dir = $_REQUEST['backup_dir'];
            $backup_zip = $_REQUEST['backup_zip'];
            if ($run == "confirm") {
                if ($backup_dir == "") {
                    $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_ERROR'];
                }
                if ($backup_zip == "") {
                    $errors[] = $mod_strings['LBL_BACKUP_FILENAME_ERROR'];
                }
                if (sizeof($errors) > 0) {
                    return $errors;
                }
                if (!is_dir($backup_dir)) {
                    if (!mkdir_recursive($backup_dir)) {
                        $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_EXISTS'];
                    }
                }
                if (!is_writable($backup_dir)) {
                    $errors[] = $mod_strings['LBL_BACKUP_DIRECTORY_NOT_WRITABLE'];
                }
                if (is_file("{$backup_dir}/{$backup_zip}")) {
                    $errors[] = $mod_strings['LBL_BACKUP_FILE_EXISTS'];
                }
                if (is_dir("{$backup_dir}/{$backup_zip}")) {
                    $errors[] = $mod_strings['LBL_BACKUP_FILE_AS_SUB'];
                }
                if (sizeof($errors) == 0) {
                    $run = "confirmed";
                    $input_disabled = "readonly";
                }
            } else {
                if ($run == "confirmed") {
                    ini_set("memory_limit", "-1");
                    ini_set("max_execution_time", "0");
                    zip_dir(".", "{$backup_dir}/{$backup_zip}");
                    $run = "done";
                }
            }
        }
        if (sizeof($errors) > 0) {
            foreach ($errors as $error) {
                print "<font color=\"red\">{$error}</font><br>";
            }
        }
        if ($run == "done") {
            $size = filesize("{$backup_dir}/{$backup_zip}");
            print $mod_strings['LBL_BACKUP_FILE_STORED'] . " {$backup_dir}/{$backup_zip} ({$size} bytes).<br>\n";
            print "<a href=\"index.php?module=Administration&action=index\">" . $mod_strings['LBL_BACKUP_BACK_HOME'] . "</a>\n";
        } else {
            ?>
        
            <?php 
            echo getClassicModuleTitle("Administration", array("<a href='index.php?module=Administration&action=index'>" . translate('LBL_MODULE_NAME', 'Administration') . "</a>", $mod_strings['LBL_BACKUPS_TITLE']), false);
            echo $mod_strings['LBL_BACKUP_INSTRUCTIONS_1'];
            ?>
            <br>
            <?php 
            echo $mod_strings['LBL_BACKUP_INSTRUCTIONS_2'];
            ?>
<br>
            <form action="<?php 
            print $form_action;
            ?>
" method="post">
            <table>
            <tr>
                <td><?php 
            echo $mod_strings['LBL_BACKUP_DIRECTORY'];
            ?>
<br><i><?php 
            echo $mod_strings['LBL_BACKUP_DIRECTORY_WRITABLE'];
            ?>
</i></td>
                <td><input size="100" type="input" name="backup_dir" <?php 
            print $input_disabled;
            ?>
 value="<?php 
            print $backup_dir;
            ?>
"/></td>
            </tr>
            <tr>
                <td><?php 
            echo $mod_strings['LBL_BACKUP_FILENAME'];
            ?>
</td>
                <td><input type="input" name="backup_zip" <?php 
            print $input_disabled;
            ?>
 value="<?php 
            print $backup_zip;
            ?>
"/></td>
            </tr>
            </table>
            <input type=hidden name="run" value="<?php 
            print $run;
            ?>
" />
        
        <?php 
            switch ($run) {
                case "confirm":
                    ?>
                    <input type="submit" value="<?php 
                    echo $mod_strings['LBL_BACKUP_CONFIRM'];
                    ?>
" />
        <?php 
                    break;
                case "confirmed":
                    ?>
                    <?php 
                    echo $mod_strings['LBL_BACKUP_CONFIRMED'];
                    ?>
<br>
                    <input type="submit" value="<?php 
                    echo $mod_strings['LBL_BACKUP_RUN_BACKUP'];
                    ?>
" />
        <?php 
                    break;
            }
            ?>
        
            </form>
        
        <?php 
        }
        // end if/else of $run options
        $GLOBALS['log']->info("Backups");
    }
Ejemplo n.º 4
0
function finishDiag()
{
    //BEGIN ZIP ALL FILES AND EXTRACT IN CACHE ROOT
    global $cacheDir;
    global $curdatetime;
    global $sod_guid;
    global $mod_strings;
    chdir($cacheDir);
    zip_dir(".", "../diagnostic" . $curdatetime . ".zip");
    //END ZIP ALL FILES AND EXTRACT IN CACHE ROOT
    chdir(RETURN_FROM_DIAG_DIR);
    deleteDir($cacheDir);
    print "<a href=\"index.php?module=Administration&action=DiagnosticDownload&guid={$sod_guid}&time={$curdatetime}&to_pdf=1\">" . $mod_strings['LBL_DIAGNOSTIC_DOWNLOADLINK'] . "</a><BR>";
    print "<a href=\"index.php?module=Administration&action=DiagnosticDelete&file=diagnostic" . $curdatetime . "&guid=" . $sod_guid . "\">" . $mod_strings['LBL_DIAGNOSTIC_DELETELINK'] . "</a><br>";
}
Ejemplo n.º 5
0
 /**
  * @depends testZipADirectory
  */
 public function testExtractTwoIndividualFilesFromAnArchive()
 {
     zip_dir($this->testdir . '/testarchive', $this->testdir . '/testarchive.zip');
     unzip_file($this->testdir . '/testarchive.zip', array('testfile2.txt', 'testfile3.txt'), $this->testdir . '/testarchiveoutput');
     $this->assertFalse(file_exists($this->testdir . '/testarchiveoutput/testfile1.txt'));
     $this->assertTrue(file_exists($this->testdir . '/testarchiveoutput/testfile2.txt'));
     $this->assertTrue(file_exists($this->testdir . '/testarchiveoutput/testfile3.txt'));
 }
 function exportProject($package, $export = true, $clean = true)
 {
     $tmppath = "custom/modulebuilder/projectTMP/";
     if (file_exists($this->getPackageDir())) {
         if (mkdir_recursive($tmppath)) {
             copy_recursive($this->getPackageDir(), $tmppath . "/" . $this->name);
             $manifest = $this->getManifest(true, $export) . $this->exportProjectInstall($package, $export);
             $fp = sugar_fopen($tmppath . '/manifest.php', 'w');
             fwrite($fp, $manifest);
             fclose($fp);
             if (file_exists('modules/ModuleBuilder/MB/LICENSE.txt')) {
                 copy('modules/ModuleBuilder/MB/LICENSE.txt', $tmppath . '/LICENSE.txt');
             } else {
                 if (file_exists('LICENSE.txt')) {
                     copy('LICENSE.txt', $tmppath . '/LICENSE.txt');
                 }
             }
             $readme_contents = $this->readme;
             $readmefp = sugar_fopen($tmppath . '/README.txt', 'w');
             fwrite($readmefp, $readme_contents);
             fclose($readmefp);
         }
     }
     require_once 'include/utils/zip_utils.php';
     $date = date('Y_m_d_His');
     $zipDir = "custom/modulebuilder/packages/ExportProjectZips";
     if (!file_exists($zipDir)) {
         mkdir_recursive($zipDir);
     }
     $cwd = getcwd();
     chdir($tmppath);
     zip_dir('.', $cwd . '/' . $zipDir . '/project_' . $this->name . $date . '.zip');
     chdir($cwd);
     if ($clean && file_exists($tmppath)) {
         rmdir_recursive($tmppath);
     }
     if ($export) {
         header('Location:' . $zipDir . '/project_' . $this->name . $date . '.zip');
     }
     return $zipDir . '/project_' . $this->name . $date . '.zip';
 }
Ejemplo n.º 7
0
function process($post_data, $download = true, $delete = true)
{
    $new_view_form = '';
    $edit_view_form = '';
    $column_default = '';
    $columns = '';
    $sortable_columns = '';
    $form_submit_fields = '';
    $form_fields = '';
    $form_single_default = '';
    $form_validation = '';
    $database_schema = '';
    foreach ($post_data['fields'] as $key => $field) {
        if (!empty($field)) {
            $field_label = ucwords(strtolower(str_replace('_', ' ', $field)));
            $field_type = $post_data['fields_type'][$key];
            $required = isset($post_data['fields_required'][$key]) ? "required=\"required\"" : "";
            switch ($field_type) {
                case 'text':
                    $new_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <input type=\"text\" name=\"{$field}\" id=\"{$field}\" class=\"regular-text\" value=\"\" {$required} />\n                        </td>\n                        </tr>\n";
                    $edit_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <input type=\"text\" name=\"{$field}\" id=\"{$field}\" class=\"regular-text\" value=\"<?php echo esc_attr( \$item->{$field} ); ?>\" {$required} />\n                        </td>\n                        </tr>\n";
                    break;
                case 'textarea':
                    $new_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <textarea name=\"{$field}\" id=\"{$field}\"  rows=\"5\" cols=\"30\" {$required}></textarea>\n                        </td>\n                        </tr>\n";
                    $edit_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <textarea name=\"{$field}\" id=\"{$field}\"  rows=\"5\" cols=\"30\" {$required}><?php echo esc_attr( \$item->{$field} ); ?></textarea>\n                        </td>\n                        </tr>\n";
                    break;
                case 'number':
                    $new_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <input type=\"number\" name=\"{$field}\" id=\"{$field}\" class=\"regular-text\" value=\"\" {$required} />\n                        </td>\n                        </tr>\n";
                    $edit_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <input type=\"number\" name=\"{$field}\" id=\"{$field}\" class=\"regular-text\" value=\"<?php echo esc_attr( \$item->{$field} ); ?>\" {$required} />\n                        </td>\n                        </tr>\n";
                    break;
                case 'email':
                    $new_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <input type=\"email\" name=\"{$field}\" id=\"{$field}\" class=\"regular-text\" value=\"\" {$required} />\n                        </td>\n                        </tr>\n";
                    $edit_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <input type=\"email\" name=\"{$field}\" id=\"{$field}\" class=\"regular-text\" value=\"<?php echo esc_attr( \$item->{$field} ); ?>\" {$required} />\n                        </td>\n                        </tr>\n";
                    break;
                case 'select':
                    $new_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <select name=\"{$field}\">\n                            <option>Your Option</option>\n                        </select>\n                        </td>\n                        </tr>\n";
                    $edit_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <input name=\"users_can_register\" type=\"checkbox\" id=\"users_can_register\">\n                        </td>\n                        </tr>\n";
                    break;
                case 'checkbox':
                    $new_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <label for=\"{$field}\">\n                        <input name=\"{$field}\" type=\"checkbox\" id=\"{$field}\" value=\"1\">\n                        Confirm</label>\n                        </td>\n                        </tr>\n";
                    $edit_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <label for=\"{$field}\">\n                        <input name=\"{$field}\" type=\"checkbox\" id=\"{$field}\" value=\"1\">\n                        Confirm</label>\n                        </td>\n                        </tr>\n";
                    break;
                case 'radio':
                    $new_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <label for=\"{$field}\">\n                        <input type=\"radio\" name=\"{$field}\" value=\"yes\">\n                        <input type=\"radio\" name=\"{$field}\" value=\"no\">\n                        Confirm</label>\n                        </td>\n                        </tr>\n";
                    $edit_view_form .= "<tr class=\"row-{$field}\">\n                        <th scope=\"row\">\n                        <label for=\"{$field}\"><?php _e( '" . $field_label . "', '%%textdomain%%' ); ?></label>\n                        </th>\n                        <td>\n                        <input type=\"text\" name=\"{$field}\" id=\"{$field}\" class=\"regular-text\" value=\"<?php echo esc_attr( \$item->{$field} ); ?>\" {$required} />\n                        </td>\n                        </tr>\n";
                    break;
            }
            $column_default .= "case '{$field}':\n";
            $columns .= "'{$field}'    => __( '{$field_label}', '%%textdomain%%' ),\n";
            $sortable_columns .= "'{$field}' => array( '{$field}', true ),\n";
            if ($field_type == 'textarea') {
                $form_submit_fields .= "\${$field}       = isset( \$_POST['{$field}'] ) ? wp_kses_post( \$_POST['{$field}'] ) : '';\n";
                // Database schema generate
                $database_schema .= "{$field} text NOT NULL,\n";
            } else {
                $form_submit_fields .= "\${$field}       = isset( \$_POST['{$field}'] ) ? sanitize_text_field( \$_POST['{$field}'] ) : '';\n";
                // Database schema generate
                $database_schema .= "{$field} varchar(255) DEFAULT '' NOT NULL,\n";
            }
            $form_fields .= "'{$field}'      => \${$field},\n";
            $form_single_default .= "'{$field}'      => '',\n";
            if (isset($post_data['fields_required'][$key])) {
                $form_validation .= "if ( ! \${$field} ) {\n                    \$errors[] = __( 'Error: {$field_label} is required', '%%textdomain%%' );\n                }";
            }
        }
    }
    if ($post_data['type_of_crud_generator'] == 'plugin') {
        $data['plugin_name'] = strtolower($post_data['plugin_name']);
        $data['plugin_name_u'] = str_replace(' ', '_', $data['plugin_name']);
        $data['plugin_name_dash'] = str_replace(' ', '-', $data['plugin_name']);
        $data['plugin_name_cap'] = ucwords($data['plugin_name']);
        $data['plugin_name_cap_u'] = str_replace(' ', '_', $data['plugin_name_cap']);
        $data['plugin_url'] = $post_data['plugin_url'];
        $data['plugin_description'] = $post_data['plugin_description'];
        $data['plugin_version'] = $post_data['plugin_version'];
        $data['plugin_author'] = $post_data['plugin_author'];
        $data['plugin_author_url'] = $post_data['plugin_author_url'];
        $data['crud_singular'] = strtolower($post_data['crud_singular']);
        $data['crud_singular_cap'] = ucwords($data['crud_singular']);
        $data['crud_plural'] = $data['crud_singular'] . 's';
        $data['crud_plural_cap'] = ucwords($data['crud_plural']);
        $data['plugin_page'] = strtolower($data['plugin_name_dash']);
        $data['textdomain'] = $post_data['textdomain'];
        $data['prefix'] = $post_data['prefix'];
        // Deleting existing plugin or module files
        if (file_exists($data['plugin_name_dash'] . '.zip')) {
            unlink($data['plugin_name_dash'] . '.zip');
        }
        $dir = dirname(__FILE__) . '/plugins/';
        $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($ri as $file) {
            $file->isDir() ? rmdir($file) : unlink($file);
        }
        // Getting contents from stubs file
        $plugin_main_file = file_get_contents(dirname(__FILE__) . '/stubs/plugin-name.stub');
        $plugin_uninstall_file = file_get_contents(dirname(__FILE__) . '/stubs/uninstall.stub');
        $crud_admin_menu_file = file_get_contents(dirname(__FILE__) . '/stubs/class-crud-admin-menu.stub');
        $crud_wp_list_file = file_get_contents(dirname(__FILE__) . '/stubs/class-crud-list.stub');
        $crud_list_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-list.stub');
        $crud_new_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-new.stub');
        $crud_edit_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-edit.stub');
        $crud_single_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-single.stub');
        // Replacing database schema
        $plugin_main_file = str_replace("%%database_schema%%", $database_schema, $plugin_main_file);
        // Replacing wp_list_table file data
        $crud_wp_list_file = str_replace("%%column_default%%", $column_default, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%columns%%", $columns, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%sortable_columns%%", $sortable_columns, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%form_submit_fields%%", $form_submit_fields, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%form_fields%%", $form_fields, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%form_single_default%%", $form_single_default, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%form_validation%%", $form_validation, $crud_wp_list_file);
        // Repacing form html
        $crud_new_view_file = str_replace("%%new_view_form%%", $new_view_form, $crud_new_view_file);
        $crud_edit_view_file = str_replace("%%edit_view_form%%", $edit_view_form, $crud_edit_view_file);
        // Replacing user defined keyword
        foreach ($data as $key => $value) {
            $plugin_main_file = str_replace("%%{$key}%%", $value, $plugin_main_file);
            $plugin_uninstall_file = str_replace("%%{$key}%%", $value, $plugin_uninstall_file);
            $crud_admin_menu_file = str_replace("%%{$key}%%", $value, $crud_admin_menu_file);
            $crud_wp_list_file = str_replace("%%{$key}%%", $value, $crud_wp_list_file);
            $crud_list_view_file = str_replace("%%{$key}%%", $value, $crud_list_view_file);
            $crud_new_view_file = str_replace("%%{$key}%%", $value, $crud_new_view_file);
            $crud_edit_view_file = str_replace("%%{$key}%%", $value, $crud_edit_view_file);
            $crud_single_view_file = str_replace("%%{$key}%%", $value, $crud_single_view_file);
        }
        // Checking/Creating plugin directory
        $plugin_dir = dirname(__FILE__) . '/plugins/' . $data['plugin_name_dash'] . '/';
        if (!is_dir($plugin_dir)) {
            mkdir($plugin_dir, 0777);
        }
        // Creating plugin main file
        file_put_contents($plugin_dir . $data['plugin_name_dash'] . '.php', $plugin_main_file);
        // Creating plugin uninstall file
        file_put_contents($plugin_dir . 'uninstall.php', $plugin_uninstall_file);
        // Creating plugin main file
        if (!is_dir($plugin_dir . 'includes/')) {
            mkdir($plugin_dir . 'includes/', 0777);
        }
        $crud_dir = $plugin_dir . 'includes/' . $data['crud_singular'] . '/';
        if (!is_dir($crud_dir)) {
            mkdir($crud_dir, 0777);
        }
        file_put_contents($crud_dir . 'class-' . $data['crud_singular'] . '-admin-menu.php', $crud_admin_menu_file);
        // Creating plugin main file
        file_put_contents($crud_dir . 'class-' . $data['crud_plural'] . '-list.php', $crud_wp_list_file);
        if (!is_dir($crud_dir . 'views/')) {
            mkdir($crud_dir . 'views/', 0777);
        }
        // Creating plugin main file
        file_put_contents($crud_dir . 'views/' . $data['crud_singular'] . '-list.php', $crud_list_view_file);
        // Creating plugin main file
        file_put_contents($crud_dir . 'views/' . $data['crud_singular'] . '-new.php', $crud_new_view_file);
        // Creating plugin main file
        file_put_contents($crud_dir . 'views/' . $data['crud_singular'] . '-edit.php', $crud_edit_view_file);
        // Creating plugin main file
        file_put_contents($crud_dir . 'views/' . $data['crud_singular'] . '-single.php', $crud_single_view_file);
        zip_dir($plugin_dir, $data['plugin_name_dash'] . '.zip', $download);
    } else {
        $data['crud_singular'] = strtolower($post_data['crud_singular']);
        $data['crud_singular_cap'] = ucwords($data['crud_singular']);
        $data['crud_plural'] = $data['crud_singular'] . 's';
        $data['crud_plural_cap'] = ucwords($data['crud_plural']);
        $data['plugin_name_dash'] = str_replace(' ', '-', $data['crud_singular']);
        $data['plugin_name_cap'] = ucwords($data['crud_singular']);
        $data['plugin_page'] = strtolower($data['plugin_name_dash']);
        $data['textdomain'] = $post_data['textdomain'];
        $data['prefix'] = $post_data['prefix'];
        // Deleting existing plugin or module files
        if (file_exists($data['plugin_name_dash'] . '.zip')) {
            unlink($data['plugin_name_dash'] . '.zip');
        }
        $dir = dirname(__FILE__) . '/plugins/';
        $di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($ri as $file) {
            $file->isDir() ? rmdir($file) : unlink($file);
        }
        // Getting contents from stubs file
        $crud_admin_menu_file = file_get_contents(dirname(__FILE__) . '/stubs/class-crud-admin-menu.stub');
        $crud_wp_list_file = file_get_contents(dirname(__FILE__) . '/stubs/class-crud-list.stub');
        $crud_list_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-list.stub');
        $crud_new_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-new.stub');
        $crud_edit_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-edit.stub');
        $crud_single_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-single.stub');
        // Replacing wp_list_table file data
        $crud_wp_list_file = str_replace("%%column_default%%", $column_default, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%columns%%", $columns, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%sortable_columns%%", $sortable_columns, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%form_submit_fields%%", $form_submit_fields, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%form_fields%%", $form_fields, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%form_single_default%%", $form_single_default, $crud_wp_list_file);
        $crud_wp_list_file = str_replace("%%form_validation%%", $form_validation, $crud_wp_list_file);
        // Repacing form html
        $crud_new_view_file = str_replace("%%new_view_form%%", $new_view_form, $crud_new_view_file);
        $crud_edit_view_file = str_replace("%%edit_view_form%%", $edit_view_form, $crud_edit_view_file);
        // Replacing user defined keyword
        foreach ($data as $key => $value) {
            $crud_admin_menu_file = str_replace("%%{$key}%%", $value, $crud_admin_menu_file);
            $crud_wp_list_file = str_replace("%%{$key}%%", $value, $crud_wp_list_file);
            $crud_list_view_file = str_replace("%%{$key}%%", $value, $crud_list_view_file);
            $crud_new_view_file = str_replace("%%{$key}%%", $value, $crud_new_view_file);
            $crud_edit_view_file = str_replace("%%{$key}%%", $value, $crud_edit_view_file);
            $crud_single_view_file = str_replace("%%{$key}%%", $value, $crud_single_view_file);
        }
        $crud_dir = dirname(__FILE__) . '/plugins/' . $data['crud_singular'] . '/';
        if (!is_dir($crud_dir)) {
            mkdir($crud_dir, 0777);
        }
        file_put_contents($crud_dir . 'class-' . $data['crud_singular'] . '-admin-menu.php', $crud_admin_menu_file);
        // Creating plugin main file
        file_put_contents($crud_dir . 'class-' . $data['crud_plural'] . '-list.php', $crud_wp_list_file);
        if (!is_dir($crud_dir . 'views/')) {
            mkdir($crud_dir . 'views/', 0777);
        }
        // Creating plugin main file
        file_put_contents($crud_dir . 'views/' . $data['crud_singular'] . '-list.php', $crud_list_view_file);
        // Creating plugin main file
        file_put_contents($crud_dir . 'views/' . $data['crud_singular'] . '-new.php', $crud_new_view_file);
        // Creating plugin main file
        file_put_contents($crud_dir . 'views/' . $data['crud_singular'] . '-edit.php', $crud_edit_view_file);
        // Creating plugin main file
        file_put_contents($crud_dir . 'views/' . $data['crud_singular'] . '-single.php', $crud_single_view_file);
        zip_dir($crud_dir, $data['plugin_name_dash'] . '.zip', $download);
    }
    return true;
}
Ejemplo n.º 8
0
 /**
 *	creates the zip of a package
 *		-in the future remove zip_utils dependency
 *
 **/
 function zip()
 {
     require_once 'include/utils/zip_utils.php';
     chdir($this->packageDir);
     if (!file_exists('../zips/')) {
         mkdir('../zips/', 0777, true);
     }
     zip_dir('.', '../zips/package' . $this->date . '.zip');
 }
Ejemplo n.º 9
0
        }
        if (is_file("{$backup_dir}/{$backup_zip}")) {
            $errors[] = $mod_strings['LBL_BACKUP_FILE_EXISTS'];
        }
        if (is_dir("{$backup_dir}/{$backup_zip}")) {
            $errors[] = $mod_strings['LBL_BACKUP_FILE_AS_SUB'];
        }
        if (sizeof($errors) == 0) {
            $run = "confirmed";
            $input_disabled = "readonly";
        }
    } else {
        if ($run == "confirmed") {
            ini_set("memory_limit", "-1");
            ini_set("max_execution_time", "0");
            zip_dir(".", "{$backup_dir}/{$backup_zip}");
            $run = "done";
        }
    }
}
if (sizeof($errors) > 0) {
    foreach ($errors as $error) {
        print "<font color=\"red\">{$error}</font><br>";
    }
}
if ($run == "done") {
    $size = filesize("{$backup_dir}/{$backup_zip}");
    print $mod_strings['LBL_BACKUP_FILE_STORED'] . " {$backup_dir}/{$backup_zip} ({$size} bytes).<br>\n";
    print "<a href=\"index.php?module=Administration&action=index\">" . $mod_strings['LBL_BACKUP_BACK_HOME'] . "</a>\n";
} else {
    ?>