PageRenderTime 30ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/seo-ultimate/modules/settings/settings-data.php

https://gitlab.com/Gashler/sg
PHP | 292 lines | 218 code | 54 blank | 20 comment | 27 complexity | bfa3c10daf80a38250ee9cfae661068c MD5 | raw file
  1. <?php
  2. /**
  3. * Settings Data Manager Module
  4. *
  5. * @since 2.1
  6. */
  7. if (class_exists('SU_Module')) {
  8. class SU_SettingsData extends SU_Module {
  9. static function get_parent_module() { return 'settings'; }
  10. static function get_child_order() { return 20; }
  11. static function is_independent_module() { return false; }
  12. static function get_module_title() { return __('Settings Data Manager', 'seo-ultimate'); }
  13. function get_module_subtitle() { return __('Manage Settings Data', 'seo-ultimate'); }
  14. function get_admin_page_tabs() {
  15. return array(
  16. array('title' => __('Import', 'seo-ultimate'), 'id' => 'su-import', 'callback' => 'import_tab')
  17. , array('title' => __('Export', 'seo-ultimate'), 'id' => 'su-export', 'callback' => 'export_tab')
  18. , array('title' => __('Reset', 'seo-ultimate'), 'id' => 'su-reset', 'callback' => 'reset_tab')
  19. );
  20. }
  21. function portable_options() {
  22. return array('settings', 'modules');
  23. }
  24. function init() {
  25. if ($this->is_action('su-export')) {
  26. header('Content-Type: application/octet-stream');
  27. header('Content-Disposition: attachment; filename="SEO Ultimate Settings ('.date('Y-m-d').').dat"');
  28. $export = array();
  29. $psdata = (array)get_option('seo_ultimate', array());
  30. //Module statuses
  31. $export['modules'] = apply_filters('su_modules_export_array', $psdata['modules']);
  32. //Module settings
  33. $modules = array_keys($psdata['modules']);
  34. $module_settings = array();
  35. foreach($modules as $module) {
  36. if (!$this->plugin->call_module_func($module, 'get_settings_key', $key) || !$key)
  37. $key = $module;
  38. $msdata = (array)get_option("seo_ultimate_module_$key", array());
  39. if ($msdata) $module_settings[$key] = $msdata;
  40. }
  41. $export['settings'] = apply_filters('su_settings_export_array', $module_settings);
  42. //Encode
  43. $export = base64_encode(serialize($export));
  44. //Output
  45. echo $export;
  46. die();
  47. } elseif ($this->is_action('su-import')) {
  48. if (strlen($_FILES['settingsfile']['name'])) {
  49. $file = $_FILES['settingsfile']['tmp_name'];
  50. if (is_uploaded_file($file)) {
  51. $import = base64_decode(file_get_contents($file));
  52. if (is_serialized($import)) {
  53. $import = unserialize($import);
  54. //Module statuses
  55. $psdata = (array)get_option('seo_ultimate', array());
  56. $psdata['modules'] = array_merge($psdata['modules'], $import['modules']);
  57. update_option('seo_ultimate', $psdata);
  58. //Module settings
  59. $module_settings = apply_filters('su_settings_import_array', $import['settings']);
  60. foreach ($module_settings as $key => $module_settings) {
  61. $msdata = (array)get_option("seo_ultimate_module_$key", array());
  62. $msdata = array_merge($msdata, $module_settings);
  63. update_option("seo_ultimate_module_$key", $msdata);
  64. }
  65. $this->queue_message('success', __('Settings successfully imported.', 'seo-ultimate'));
  66. } else
  67. $this->queue_message('error', __('The uploaded file is not in the proper format. Settings could not be imported.', 'seo-ultimate'));
  68. } else
  69. $this->queue_message('error', __('The settings file could not be uploaded successfully.', 'seo-ultimate'));
  70. } else
  71. $this->queue_message('warning', __('Settings could not be imported because no settings file was selected. Please click the &#8220;Browse&#8221; button and select a file to import.', 'seo-ultimate'));
  72. } elseif ($this->is_action('su-reset')) {
  73. $psdata = (array)get_option('seo_ultimate', array());
  74. $modules = array_keys($psdata['modules']);
  75. foreach ($modules as $module) {
  76. if (!$this->plugin->call_module_func($module, 'get_settings_key', $key) || !$key)
  77. $key = $module;
  78. delete_option("seo_ultimate_module_$key");
  79. }
  80. unset($psdata['modules']);
  81. update_option('seo_ultimate', $psdata);
  82. $this->load_default_settings();
  83. } elseif ($this->is_action('dj-export')) {
  84. header('Content-Disposition: attachment; filename="Deeplink Juggernaut Content Links ('.date('Y-m-d').').csv"');
  85. $djlinks = $this->get_setting('links', array(), 'autolinks');
  86. $csv_headers = array(
  87. 'anchor' => 'Anchor'
  88. , 'to_type' => 'Destination Type'
  89. , 'to_id' => 'Destination'
  90. , 'title' => 'Title'
  91. , 'sitewide_lpa' => 'Site Cap'
  92. , 'nofollow' => 'Nofollow'
  93. , 'target' => 'Target'
  94. );
  95. if (is_array($djlinks) && count($djlinks))
  96. $djlinks = suarr::key_replace($djlinks, $csv_headers, true, true);
  97. else
  98. $djlinks = array(array_fill_keys($csv_headers, ''));
  99. suio::export_csv($djlinks);
  100. die();
  101. } elseif ($this->is_action('dj-import')) {
  102. if (strlen($_FILES['settingsfile']['name'])) {
  103. $file = $_FILES['settingsfile']['tmp_name'];
  104. if (is_uploaded_file($file)) {
  105. $import = suio::import_csv($file);
  106. if ($import === false)
  107. $this->queue_message('error', __('The uploaded file is not in the proper format. Links could not be imported.', 'seo-ultimate'));
  108. else {
  109. $import = suarr::key_replace($import, array(
  110. 'Anchor' => 'anchor'
  111. , 'Destination Type' => 'to_type'
  112. , 'Destination' => 'to_id'
  113. , 'URL' => 'to_id'
  114. , 'Title' => 'title'
  115. , 'Site Cap' => 'sidewide_lpa'
  116. , 'Nofollow' => 'nofollow'
  117. , 'Target' => 'target'
  118. ), true, true);
  119. $import = suarr::value_replace($import, array(
  120. 'No' => false
  121. , 'Yes' => true
  122. , 'URL' => 'url'
  123. ), true, false);
  124. $djlinks = array();
  125. foreach ($import as $link) {
  126. //Validate destination type
  127. if ($link['to_type'] != 'url'
  128. && !sustr::startswith($link['to_type'], 'posttype_')
  129. && !sustr::startswith($link['to_type'], 'taxonomy_'))
  130. $link['to_type'] = 'url';
  131. //Validate nofollow
  132. if (!is_bool($link['nofollow']))
  133. $link['nofollow'] = false;
  134. //Validate target
  135. $link['target'] = ltrim($link['target'], '_');
  136. if (!in_array($link['target'], array('self', 'blank'))) //Only _self or _blank are supported right now
  137. $link['target'] = 'self';
  138. //Add link!
  139. $djlinks[] = $link;
  140. }
  141. $this->update_setting('links', $djlinks, 'autolinks');
  142. $this->queue_message('success', __('Links successfully imported.', 'seo-ultimate'));
  143. }
  144. } else
  145. $this->queue_message('error', __('The CSV file could not be uploaded successfully.', 'seo-ultimate'));
  146. } else
  147. $this->queue_message('warning', __('Links could not be imported because no CSV file was selected. Please click the &#8220;Browse&#8221; button and select a file to import.', 'seo-ultimate'));
  148. }
  149. }
  150. function import_tab() {
  151. $this->print_messages();
  152. $hook = $this->plugin->key_to_hook($this->get_module_or_parent_key());
  153. //SEO Ultimate
  154. $this->admin_subheader(__('Import SEO Ultimate Settings File', 'seo-ultimate'));
  155. echo "\n<p>";
  156. _e('You can use this form to upload and import an SEO Ultimate settings file stored on your computer. (These files can be created using the Export tool.) Note that importing a file will overwrite your existing settings with those in the file.', 'seo-ultimate');
  157. echo "</p>\n";
  158. echo "<form enctype='multipart/form-data' method='post' action='?page=$hook&amp;action=su-import#su-import'>\n";
  159. echo "\t<input name='settingsfile' type='file' /> ";
  160. $confirm = __('Are you sure you want to import this settings file? This will overwrite your current settings and cannot be undone.', 'seo-ultimate');
  161. echo "<input type='submit' class='button-primary' value='".__('Import Settings File', 'seo-ultimate')."' onclick=\"javascript:return confirm('$confirm')\" />\n";
  162. wp_nonce_field($this->get_nonce_handle('su-import'));
  163. echo "</form>\n";
  164. if ($this->plugin->module_exists('content-autolinks')) {
  165. //Deeplink Juggernaut
  166. $this->admin_subheader(__('Import Deeplink Juggernaut CSV File', 'seo-ultimate'));
  167. echo "\n<p>";
  168. _e('You can use this form to upload and import a Deeplink Juggernaut CSV file stored on your computer. (These files can be created using the Export tool.) Note that importing a file will overwrite your existing links with those in the file.', 'seo-ultimate');
  169. echo "</p>\n";
  170. echo "<form enctype='multipart/form-data' method='post' action='?page=$hook&amp;action=dj-import#su-import'>\n";
  171. echo "\t<input name='settingsfile' type='file' /> ";
  172. $confirm = __('Are you sure you want to import this CSV file? This will overwrite your current Deeplink Juggernaut links and cannot be undone.', 'seo-ultimate');
  173. echo "<input type='submit' class='button-primary' value='".__('Import CSV File', 'seo-ultimate')."' onclick=\"javascript:return confirm('$confirm')\" />\n";
  174. wp_nonce_field($this->get_nonce_handle('dj-import'));
  175. echo "</form>\n";
  176. }
  177. //Import from other plugins
  178. $importmodules = array();
  179. foreach ($this->plugin->modules as $key => $x_module) {
  180. $module =& $this->plugin->modules[$key];
  181. if (is_a($module, 'SU_ImportModule')) {
  182. $importmodules[$key] =& $module;
  183. }
  184. }
  185. if (count($importmodules)) {
  186. $this->admin_subheader(__('Import from Other Plugins', 'seo-ultimate'));
  187. echo "\n<p>";
  188. _e('You can import settings and data from these plugins. Clicking a plugin&#8217;s name will take you to the importer page, where you can customize parameters and start the import.', 'seo-ultimate');
  189. echo "</p>\n";
  190. echo "<table class='table table-bordered'>\n";
  191. $class = '';
  192. foreach ($importmodules as $key => $x_module) {
  193. $module =& $importmodules[$key];
  194. $title = $module->get_op_title();
  195. $desc = $module->get_import_desc();
  196. $url = $module->get_admin_url();
  197. $class = ($class) ? '' : 'alternate';
  198. echo "\t<tr class='$class'><td><a href='$url'>$title</a></td><td>$desc</td></tr>\n";
  199. }
  200. echo "</table>\n";
  201. }
  202. }
  203. function export_tab() {
  204. //SEO Ultimate
  205. $this->admin_subheader(__('Export SEO Ultimate Settings File', 'seo-ultimate'));
  206. echo "\n<p>";
  207. _e('You can use this export tool to download an SEO Ultimate settings file to your computer.', 'seo-ultimate');
  208. echo "</p>\n<p>";
  209. _e('A settings file includes the data of every checkbox and textbox of every installed module. It does NOT include site-specific data like logged 404s or post/page title/meta data (this data would be included in a standard database backup, however).', 'seo-ultimate');
  210. echo "</p>\n<p>";
  211. $url = $this->get_nonce_url('su-export');
  212. echo "<a href='$url' class='button-primary'>".__('Download Settings File', 'seo-ultimate')."</a>";
  213. echo "</p>\n";
  214. if ($this->plugin->module_exists('content-autolinks')) {
  215. //Deeplink Juggernaut
  216. $this->admin_subheader(__('Export Deeplink Juggernaut CSV File', 'seo-ultimate'));
  217. echo "\n<p>";
  218. _e('You can use this export tool to download a CSV file (comma-separated values file) that contains your Deeplink Juggernaut links. Once you download this file to your computer, you can edit it using your favorite spreadsheet program. When you&#8217;re done editing, you can re-upload the file using the Import tool.', 'seo-ultimate');
  219. echo "</p>\n<p>";
  220. $url = $this->get_nonce_url('dj-export');
  221. echo "<a href='$url' class='button-primary'>".__('Download CSV File', 'seo-ultimate')."</a>";
  222. echo "</p>\n";
  223. }
  224. }
  225. function reset_tab() {
  226. if ($this->is_action('su-reset'))
  227. $this->print_message('success', __('All settings have been erased and defaults have been restored.', 'seo-ultimate'));
  228. echo "\n<p>";
  229. _e('You can erase all your SEO Ultimate settings and restore them to &#8220;factory defaults&#8221; by clicking the button below.', 'seo-ultimate');
  230. echo "</p>\n<p>";
  231. $url = $this->get_nonce_url('su-reset');
  232. $confirm = __('Are you sure you want to erase all module settings? This cannot be undone.', 'seo-ultimate');
  233. echo "<a href='$url#su-reset' class='button-primary' onclick=\"javascript:return confirm('$confirm')\">".__('Restore Default Settings', 'seo-ultimate')."</a>";
  234. echo "</p>\n";
  235. }
  236. }
  237. }
  238. ?>