function run_import($settings = array(), $use_post_data = true, $return_data = false, $db_data = false) { $default_settings = array('data_sources' => array('layouts-views' => array('method' => 'add'), 'theme-settings' => array('method' => 'skip'))); $settings = ITUtility::merge_defaults($settings, $default_settings); if ($use_post_data) { $post_data = ITForm::get_post_data(true); $settings = ITUtility::merge_defaults($post_data, $settings); } it_classes_load('it-file-utility.php'); $info = $this->get_info(); $errors = array(); $results = array(); $attachments = $this->get_attachments(); $new_attachments = array(); foreach ((array) $attachments as $id => $file) { $attachment = ITFileUtility::add_to_media_library($file); $new_attachments[$id] = $attachment; } foreach ((array) $info['data_sources'] as $var => $data_source) { if (isset($this->_data_sources[$var])) { if (is_callable(array($this->_data_sources[$var], 'run_import'))) { if (!isset($settings['data_sources'][$var])) { $settings['data_sources'][$var] = array(); } else { if (isset($settings['data_sources'][$var]['method']) && 'skip' == $settings['data_sources'][$var]['method']) { continue; } } $db_settings = isset($db_data[$var]) ? $db_data[$var] : false; $result = $this->_data_sources[$var]->run_import($info['data_sources'][$var], $this->get_data($var), $settings['data_sources'][$var], $new_attachments, $return_data, $db_settings); if ($return_data) { $results[$var] = $result; } if (false === $result) { $errors[] = "{$var}:failed_run_import"; } } else { $errors[] = "{$var}:missing_run_import"; } } } if ($return_data) { return $results; } if (!empty($errors)) { return $errors; } return true; }
function _save() { it_classes_load('it-file-utility.php'); $data = ITForm::get_post_data(); if (ITFileUtility::file_uploaded('uploaded_favicon')) { if (preg_match('/\\.ico$/', $_FILES['uploaded_favicon']['name'])) { $path = ITFileUtility::get_writable_directory('builder-favicon'); $name = ITUtility::get_random_string(array(6, 10)) . '.ico'; if (copy($_FILES['uploaded_favicon']['tmp_name'], "{$path}/{$name}")) { $data['favicon']['file'] = "{$path}/{$name}"; $data['favicon']['url'] = ITFileUtility::get_url_from_file("{$path}/{$name}"); @chmod("{$path}/{$name}", 0644); } else { $this->_errors[] = new WP_Error('unable-to-save-favicon', __('Unable to save the supplied Favicon image file. Pleave verify that the wp-content/uploads directory can be written to.', 'it-l10n-Builder-Cohen')); } } else { $file = ITFileUtility::create_favicon('builder-favicon', $_FILES['uploaded_favicon']['tmp_name']); if (false != $file) { $url = ITFileUtility::get_url_from_file($file); $data['favicon'] = array('file' => $file, 'url' => $url); $original_extension = strtolower(preg_replace('/.+\\.([^.]+)$/', '\\1', $_FILES['uploaded_favicon']['name'])); $original_file = preg_replace('/\\.ico/', "-original.{$original_extension}", $file); $original_url = ITFileUtility::get_url_from_file($original_file); if (copy($_FILES['uploaded_favicon']['tmp_name'], $original_file)) { $data['favicon']['original_file'] = $original_file; $data['favicon']['original_url'] = $original_url; if (false !== ($file_data = @file_get_contents($original_file))) { if (false !== ($im = @imagecreatefromstring($file_data))) { list($width, $height) = getimagesize($original_file); $new_im = imagecreatetruecolor(16, 16); imagecolortransparent($new_im, imagecolorallocatealpha($new_im, 0, 0, 0, 127)); imagealphablending($new_im, false); imagesavealpha($new_im, true); if (false !== imagecopyresampled($new_im, $im, 0, 0, 0, 0, 16, 16, $width, $height)) { $resized_file = preg_replace('/(\\.[^.]+)$/', '-resized\\1', $original_file); $result = imagepng($new_im, $resized_file); if (true == $result) { $data['favicon']['original_resized_file'] = $resized_file; $data['favicon']['original_resized_url'] = ITFileUtility::get_url_from_file($resized_file); } } } unset($file_data); } } } else { $this->_errors[] = new WP_Error('unable-to-create-favicon', __('Unable to generate a Favicon image from the supplied file. Please verify that the file is a valid JPG, JPEG, PNG, GIF, or ICO image.', 'it-l10n-Builder-Cohen')); } } } $this->_options = array_merge($this->_options, $data); $this->_parent->_save(); }
function _export() { ITForm::check_nonce('export_data'); if (empty($_POST['name'])) { $redirect = "{$this->_parent->_self_link}&export_error=name#import-export-export"; wp_redirect($redirect); exit; } $post_data = ITForm::get_post_data(); require_once dirname(__FILE__) . '/class.builder-import-export.php'; $exporter = new BuilderImportExport(); $export = $exporter->get_export($post_data['name'], $post_data['data_sources']); $guid = $export['guid']; unset($export['guid']); $this->_exports['exports'][$guid] = $export; $this->_storage->save($this->_exports); $redirect = "{$this->_parent->_self_link}&exported={$guid}"; wp_redirect($redirect); exit; }
/** * Save settings. * * @since 1.0 */ function save_settings() { $defaults = it_exchange_get_option('addon_itelic'); $new_values = wp_parse_args(\ITForm::get_post_data(), $defaults); // Check nonce if (!wp_verify_nonce($_POST['_wpnonce'], 'it-exchange-itelic-settings')) { $this->error_message = __('Error. Please try again', Plugin::SLUG); return; } /** * Filter the settings errors before saving. * * @since 1.0 * * @param string[] $errors Errors * @param array $new_values Mixed */ $errors = apply_filters('it_exchange_add_on_itelic_validate_settings', $this->get_form_errors($new_values), $new_values); if (!$errors && it_exchange_save_option('addon_itelic', $new_values)) { $this->status_message = __('Settings saved.', Plugin::SLUG); } else { if ($errors) { $errors = implode('<br />', $errors); $this->error_message = $errors; } else { $this->error_message = __('Settings not saved.', Plugin::SLUG); } } }