public function parseRequest(&$wp) { global $wpdb, $guiform, $wp; GuiForm_Module_Setup::flushRewrite(); $query = $wp->query_vars[$guiform->permalink['value']]; $this->_id = strpos($query, 'js') !== false ? preg_replace('/\\D/', '', $query) : $query; if (array_key_exists($guiform->permalink['value'], $wp->query_vars) || in_array($guiform->permalink['value'], $wp->query_vars)) { $this->_atts = $_REQUEST['_atts']; $this->_form = $guiform->form($this->_id); if (strpos($query, 'js') !== false) { $this->_atts['js'] = true; header("content-type: application/javascript"); echo self::renderScript(); } else { $this->_atts['js'] = false; echo self::renderForm(); } die; } }
private function validate() { global $guiform; if (isset($_POST['submit'])) { $autosave = $_POST['autosave']; $autosave_time = intval($_POST['autosave_time']); $upload_folder = esc_html($_POST['upload_folder']); $selection = esc_html($_POST['selection']); if (isset($autosave)) { $guiform->updateOption('autosave', 1, 'settings'); } else { $guiform->updateOption('autosave', 0, 'settings'); } if (is_int($autosave_time)) { if ($autosave_time < 120) { $guiform->updateOption('autosave_time', 120, 'settings'); } else { $guiform->updateOption('autosave_time', $autosave_time, 'settings'); } } if (isset($upload_folder)) { if (empty($upload_folder)) { $guiform->updateOption('upload_folder', 'wp-content/uploads/guiform', 'settings'); } else { $dir = ABSPATH; $dir = $dir . '/' . $upload_folder; $current_folder = $guiform->getOption('upload_folder')->value; if ($upload_folder != $current_folder) { if (!file_exists($dir)) { if (!@mkdir($dir, 0700, true)) { echo '<div class="error"><p><strong>' . __("Invalid Upload Folder.", GuiForm_Plugin::NAME) . '</strong></p></div>'; $guiform->updateOption('upload_folder', 'wp-content/uploads/guiform'); } else { $guiform->updateOption('upload_folder', $upload_folder, 'settings'); } $source = ABSPATH . $current_folder; self::copyDirectory($source, $dir); self::deleteDirectory($source); } else { echo '<div class="error"><p><strong>' . __("Directory is already exist.", GuiForm_Plugin::NAME) . '</strong></p></div>'; } } } } $custom = esc_html($_POST['custom']); if ($selection == 'custom' && !empty($custom)) { $permalink = $guiform->getOption('permalink')->value; $permalink['selection'] = 'custom'; $permalink['value'] = esc_html($_POST['custom']); $guiform->updateOption('permalink', $permalink, 'settings'); GuiForm_Module_Setup::flushRewrite(); } else { $permalink['selection'] = 'default'; $permalink['value'] = 'form'; $guiform->updateOption('permalink', $permalink, 'settings'); } if (has_filter('guiform_action_settings_general_save')) { $this->errors = apply_filters('guiform_action_settings_general_save', $_REQUEST); } echo '<div class="updated"><p><strong>' . __("Update settings succesful.", GuiForm_Plugin::NAME) . '</strong></p></div>'; } }
/** * Export form settings to sql file. * * @since 1.0 * @access public * @param $table array * @param $zip boolean */ public function exportFormSql($table = array(), $zip = false) { global $wpdb, $guiform; $forms = array_map('esc_html', $_POST['forms']); $form_column = $wpdb->get_col("SHOW COLUMNS FROM {$wpdb->guiform}"); $form_field .= '`' . implode("`, `", $form_column) . '`'; //cycle through data $return = ""; $return .= "-- " . GuiForm_Plugin::PACKAGE . " SQL Dump \n"; $return .= "-- Plugin Version " . GuiForm_Plugin::VERSION . " \n"; $return .= "-- Site: https://www.guiform.com \n"; $return .= "-- \n"; $return .= "-- Host: " . get_site_url() . " \n"; $return .= "-- Generation Time: " . date('M d, Y \\a\\t h:i a', strtotime("now" - 8)) . "\n"; $return .= "-- MYSQL Version: " . $wpdb->db_version() . " \n"; $return .= "-- PHP Version: " . phpversion() . " \n\n\n"; foreach ($forms as $id) { $form_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->guiform} WHERE id = %d", $id), ARRAY_A); $param = $info = array(); foreach ($wpdb->col_info as $col) { $info[$col->name] = $col; } $param['data'] = $form_row; $param['info'] = $info; $form_row = GuiForm_Module_Setup::isString($param); $return .= "-- ---------------------------------------------------------------- \n"; $return .= "-- \n"; $return .= "-- Dumping form data \n"; $return .= "-- \n"; $return .= "REPLACE INTO `{$wpdb->guiform}` (" . $form_field . ") VALUES\n"; $return .= "(" . implode(", ", $form_row) . ");"; $INSERT = $param = $info = array(); $table = $wpdb->guiform_form . $id; if (isset($_POST['schema'])) { $return .= "\n\n--\n-- "; $return .= "Table structure for table `" . $table . "`\n--\n"; $structure = $wpdb->get_row("SHOW CREATE TABLE {$table}", ARRAY_A); if (isset($_POST['drop_table'])) { $return .= "DROP TABLE IF EXISTS `{$table}`;\n"; } $return .= str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $structure['Create Table']) . ";\n\n"; } $column = $wpdb->get_col("SHOW COLUMNS FROM {$table}"); $result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_A); $return .= "\n\n--\n-- Dumping data for table `" . $table . "`\n--\n"; if (sizeof($result) > 0) { if (isset($_POST['entry'])) { $entry_function = $_POST['entry_function'] == 'insert' ? 'INSERT' : 'REPLACE'; $return .= $entry_function . ' INTO `' . $table . "` ("; $return .= '`' . implode("`, `", $column) . '`'; $return .= ") VALUES \n"; foreach ($wpdb->col_info as $col) { $info[$col->name] = $col; } foreach ($result as $value) { $param['data'] = $value; $param['info'] = $info; $data = GuiForm_Module_Setup::isString($param); $INSERT[] = '(' . implode(", ", $data) . ')'; } $return .= implode(",\n", $INSERT) . ";"; } } else { $return .= "\n\n-- \n"; $return .= "-- " . __('No Record Found.', GuiForm_Plugin::NAME) . "\n"; $return .= "--"; } $return .= "\n\n\n"; } date_default_timezone_set('GMT'); $filename = date("Y-m-d-H-i", strtotime("now" - 8)); $filename = strtolower(str_replace(" ", "-", $filename)); //save file if ($_POST['zip']) { $zip = new ZipArchive(); $zip_name = $filename . '.zip'; $res = $zip->open($zip_name, ZipArchive::CREATE); if ($res === TRUE) { $zip->addFromString('guiform.sql', $return); $zip->close(); } header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename="' . $zip_name . '"'); header('Content-type: application/zip'); header('Content-Length: ' . strlen($return)); header('Expires: 0'); header('Pragma: public'); readfile($zip_name); unlink($zip_name); // $zp = gzopen(ABSPATH. '/' . 'db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql.gz', "w9"); // gzwrite($zp, $return); // gzclose($zp); } else { $content_type = 'text/sql'; header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename=' . $filename . '.sql'); header("Content-Type: {$content_type}; charset=" . get_option('blog_charset'), true); header('Expires: 0'); header('Pragma: public'); echo $return; } exit; }