function init() { if ($this->is_action('su-export')) { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="SEO Ultimate Settings (' . date('Y-m-d') . ').dat"'); $export = array(); $psdata = (array) get_option('seo_ultimate', array()); //Module statuses $export['modules'] = apply_filters('su_modules_export_array', $psdata['modules']); //Module settings $modules = array_keys($psdata['modules']); $module_settings = array(); foreach ($modules as $module) { if (!$this->plugin->call_module_func($module, 'get_settings_key', $key) || !$key) { $key = $module; } $msdata = (array) get_option("seo_ultimate_module_{$key}", array()); if ($msdata) { $module_settings[$key] = $msdata; } } $export['settings'] = apply_filters('su_settings_export_array', $module_settings); //Encode $export = base64_encode(serialize($export)); //Output echo $export; die; } elseif ($this->is_action('su-import')) { if (strlen($_FILES['settingsfile']['name'])) { $file = $_FILES['settingsfile']['tmp_name']; if (is_uploaded_file($file)) { $import = base64_decode(file_get_contents($file)); if (is_serialized($import)) { $import = unserialize($import); //Module statuses $psdata = (array) get_option('seo_ultimate', array()); $psdata['modules'] = array_merge($psdata['modules'], $import['modules']); update_option('seo_ultimate', $psdata); //Module settings $module_settings = apply_filters('su_settings_import_array', $import['settings']); foreach ($module_settings as $key => $module_settings) { $msdata = (array) get_option("seo_ultimate_module_{$key}", array()); $msdata = array_merge($msdata, $module_settings); update_option("seo_ultimate_module_{$key}", $msdata); } $this->queue_message('success', __('Settings successfully imported.', 'seo-ultimate')); } else { $this->queue_message('error', __('The uploaded file is not in the proper format. Settings could not be imported.', 'seo-ultimate')); } } else { $this->queue_message('error', __('The settings file could not be uploaded successfully.', 'seo-ultimate')); } } else { $this->queue_message('warning', __('Settings could not be imported because no settings file was selected. Please click the “Browse” button and select a file to import.', 'seo-ultimate')); } } elseif ($this->is_action('su-reset')) { $psdata = (array) get_option('seo_ultimate', array()); $modules = array_keys($psdata['modules']); foreach ($modules as $module) { if (!$this->plugin->call_module_func($module, 'get_settings_key', $key) || !$key) { $key = $module; } delete_option("seo_ultimate_module_{$key}"); } unset($psdata['modules']); update_option('seo_ultimate', $psdata); $this->load_default_settings(); } elseif ($this->is_action('dj-export')) { header('Content-Disposition: attachment; filename="Deeplink Juggernaut Content Links (' . date('Y-m-d') . ').csv"'); $djlinks = $this->get_setting('links', array(), 'autolinks'); $csv_headers = array('anchor' => 'Anchor', 'to_type' => 'Destination Type', 'to_id' => 'Destination', 'title' => 'Title', 'sitewide_lpa' => 'Site Cap', 'nofollow' => 'Nofollow', 'target' => 'Target'); if (is_array($djlinks) && count($djlinks)) { $djlinks = suarr::key_replace($djlinks, $csv_headers, true, true); } else { $djlinks = array(array_fill_keys($csv_headers, '')); } suio::export_csv($djlinks); die; } elseif ($this->is_action('dj-import')) { if (strlen($_FILES['settingsfile']['name'])) { $file = $_FILES['settingsfile']['tmp_name']; if (is_uploaded_file($file)) { $import = suio::import_csv($file); if ($import === false) { $this->queue_message('error', __('The uploaded file is not in the proper format. Links could not be imported.', 'seo-ultimate')); } else { $import = suarr::key_replace($import, array('Anchor' => 'anchor', 'Destination Type' => 'to_type', 'Destination' => 'to_id', 'URL' => 'to_id', 'Title' => 'title', 'Site Cap' => 'sidewide_lpa', 'Nofollow' => 'nofollow', 'Target' => 'target'), true, true); $import = suarr::value_replace($import, array('No' => false, 'Yes' => true, 'URL' => 'url'), true, false); $djlinks = array(); foreach ($import as $link) { //Validate destination type if ($link['to_type'] != 'url' && !sustr::startswith($link['to_type'], 'posttype_') && !sustr::startswith($link['to_type'], 'taxonomy_')) { $link['to_type'] = 'url'; } //Validate nofollow if (!is_bool($link['nofollow'])) { $link['nofollow'] = false; } //Validate target $link['target'] = ltrim($link['target'], '_'); if (!in_array($link['target'], array('self', 'blank'))) { //Only _self or _blank are supported right now $link['target'] = 'self'; } //Add link! $djlinks[] = $link; } $this->update_setting('links', $djlinks, 'autolinks'); $this->queue_message('success', __('Links successfully imported.', 'seo-ultimate')); } } else { $this->queue_message('error', __('The CSV file could not be uploaded successfully.', 'seo-ultimate')); } } else { $this->queue_message('warning', __('Links could not be imported because no CSV file was selected. Please click the “Browse” button and select a file to import.', 'seo-ultimate')); } } }
/** * Runs a find/replace operation on values in an array. * * @param array $array The array whose values should be replaced * @param array $value_changes An array of (old_value => new_value) * @param bool $recursive Whether or not to do the same for subarrays of $array * @param bool $return_replaced_only If true, then elements *not* replaced will be discarded * * @return array */ static function value_replace($array, $value_changes, $recursive = true, $return_replaced_only = false) { $newarray = array(); foreach ((array) $array as $key => $value) { $oldvalue = $value; if ($recursive && is_array($value)) { $value = suarr::value_replace($value, $value_changes, true); } elseif (isset($value_changes[$value])) { $value = $value_changes[$value]; } if ($value != $oldvalue || !$return_replaced_only) { $newarray[$key] = $value; } } return $newarray; }