PageRenderTime 65ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/wp-table-reloaded/controllers/controller-admin.php

https://github.com/petergibbons/OpenCounterWP
PHP | 1922 lines | 1484 code | 130 blank | 308 comment | 100 complexity | 66101b57c9f2d3a43f2dec20f7d79e9b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Admin Controller for WP-Table Reloaded with functions for the backend
  4. *
  5. * @package WP-Table Reloaded
  6. * @subpackage Admin Controller
  7. * @author Tobias B&auml;thge
  8. * @since 1.6
  9. */
  10. /**
  11. * Include file with the Base Controller Class
  12. */
  13. require_once ( WP_TABLE_RELOADED_ABSPATH . 'controllers/controller-base.php' );
  14. /**
  15. * Define the WP-Table Reloaded Text Domain, used to separate between plugin and core localization
  16. */
  17. define( 'WP_TABLE_RELOADED_TEXTDOMAIN', 'wp-table-reloaded' );
  18. /**
  19. * Admin Controller class, extends Base Controller Class
  20. */
  21. class WP_Table_Reloaded_Controller_Admin extends WP_Table_Reloaded_Controller_Base {
  22. /**
  23. * Nonce for security of links/forms, to prevent "CSRF"
  24. * @var string
  25. */
  26. var $nonce_base = 'wp-table-reloaded-nonce';
  27. /**
  28. * List of allowed actions that a user can perform with tables or the plugin
  29. * @var array
  30. */
  31. var $allowed_actions = array( 'list', 'add', 'edit', 'bulk_edit', 'copy', 'delete', 'import', 'export', 'options', 'uninstall', 'about', 'hide_donate_nag', 'hide_welcome_message' );
  32. // 'ajax_list', 'ajax_preview' also exist, but are handled separately
  33. /**
  34. * current action that is performed in this page load, populated in load_manage_page()
  35. * @var string
  36. */
  37. var $action = 'list';
  38. /**
  39. * List of available translations of WP-Table Reloaded, init in __construct, because of the translations
  40. * @var array
  41. */
  42. var $available_plugin_languages = array();
  43. /**
  44. * Default plugin options and their default values, fresh installs use those, updated installs update their options accordingly
  45. * @var array
  46. */
  47. var $default_options = array(
  48. 'installed_version' => '0',
  49. 'plugin_language' => 'auto',
  50. 'uninstall_upon_deactivation' => false,
  51. 'show_exit_warning' => true,
  52. 'growing_textareas' => true,
  53. 'use_datatables_on_table_list' => true,
  54. 'add_target_blank_to_links' => false,
  55. 'enable_tablesorter' => true,
  56. 'tablesorter_script' => 'datatables', // others are 'datatables-tabletools', 'tablesorter', and 'tablesorter_extended'
  57. 'use_default_css' => true,
  58. 'use_custom_css' => true,
  59. 'custom_css' => '',
  60. 'enable_search' => true,
  61. 'admin_menu_parent_page' => 'tools.php',
  62. 'user_access_plugin' => 'author', // others are 'contributor', 'editor', and 'admin'
  63. 'user_access_plugin_options' => 'author', // others are 'editor', and 'admin'
  64. 'frontend_edit_table_link' => true,
  65. 'install_time' => 0,
  66. 'show_donate_nag' => true,
  67. 'show_welcome_message' => 0, // 0 = no message, 1 = install message, 2 = update message
  68. 'update_message' => array(),
  69. 'last_id' => 0
  70. );
  71. /**
  72. * Default list of tables (empty, because there are no tables right after installation)
  73. * @var array
  74. */
  75. var $default_tables = array();
  76. /**
  77. * Instance of the WP_Table_Reloaded_Helper class, which has additional functions for frontend and backend, stored in separate file for better overview and maintenance
  78. * @var object
  79. */
  80. var $helper;
  81. /**
  82. * Instance of the WP_Table_Reloaded_Export class
  83. * @var object
  84. */
  85. var $export_instance;
  86. /**
  87. * Instance of the WP_Table_Reloaded_Import class
  88. * @var object
  89. */
  90. var $import_instance;
  91. /**
  92. * Hook (i.e. name) WordPress uses for the WP-Table Reloaded page, needed for certain plugin actions and filters, populated in add_manage_page()
  93. * @var string
  94. */
  95. var $hook = '';
  96. /**
  97. * Name of the file, WP-Table Reloaded is accessible under, dependant of whether admin has moved the WP-Table Reloaded menu entry
  98. * @var string
  99. */
  100. var $page_url = '';
  101. /**
  102. * PHP4 class constructor, calls the PHP5 class constructor __construct()
  103. */
  104. function WP_Table_Reloaded_Controller_Admin() {
  105. $this->__construct();
  106. }
  107. /**
  108. * PHP5 class constructor
  109. *
  110. * Initiate Backend functionality, by checking for AJAX calls, eventually answering those or setting up the admin page
  111. */
  112. function __construct() {
  113. register_activation_hook( WP_TABLE_RELOADED__FILE__, array( &$this, 'plugin_activation_hook' ) );
  114. register_deactivation_hook( WP_TABLE_RELOADED__FILE__, array( &$this, 'plugin_deactivation_hook' ) );
  115. $this->helper = $this->create_class_instance( 'WP_Table_Reloaded_Helper', 'helper.class.php' );
  116. // load plugin options and existing tables
  117. $this->init_plugin();
  118. // WordPress 3.1 requires new update check
  119. if ( version_compare( $this->options['installed_version'], WP_TABLE_RELOADED_PLUGIN_VERSION, '<' ) )
  120. add_action( 'init', array( &$this, 'plugin_update' ) );
  121. // init variables to check whether we do valid AJAX
  122. $doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
  123. $valid_ajax_call = ( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] ) ? true : false;
  124. // have to check for possible "export all" request this early,
  125. // because otherwise http-headers will be sent by WP before we can send download headers
  126. if ( !$doing_ajax && $valid_ajax_call && isset( $_POST['export_all'] ) ) {
  127. // can be done in plugins_loaded, as no language support is needed
  128. add_action( 'plugins_loaded', array( &$this, 'do_action_export_all' ) );
  129. $doing_ajax = true;
  130. }
  131. // have to check for possible export file download request this early,
  132. // because otherwise http-headers will be sent by WP before we can send download headers
  133. if ( !$doing_ajax && $valid_ajax_call && isset( $_POST['download_export_file'] ) && 'true' == $_POST['download_export_file'] ) {
  134. // can be done in plugins_loaded, as no language support is needed
  135. add_action( 'plugins_loaded', array( &$this, 'do_action_export' ) );
  136. $doing_ajax = true;
  137. }
  138. // have to check for possible call by editor button to show list of tables
  139. // and possible call to show a table preview in a thickbox on "List Tables" screen
  140. if ( !$doing_ajax && $valid_ajax_call && isset( $_GET['action'] ) && ( 'ajax_list' == $_GET['action'] || 'ajax_preview' == $_GET['action'] ) ) {
  141. // can not be done earlier, because we need language support
  142. add_action( 'init', array( &$this, 'do_action_' . $_GET['action'] ) );
  143. $doing_ajax = true;
  144. }
  145. // we are not doing AJAX, so we call the main plugin handler
  146. if ( !$doing_ajax ) {
  147. add_action( 'admin_menu', array( &$this, 'add_manage_page' ) );
  148. // add JS to add button to editor on admin pages that might have an editor
  149. $pages_with_editor_button = array( 'post.php', 'post-new.php', 'page.php', 'page-new.php' );
  150. foreach ( $pages_with_editor_button as $page )
  151. add_action( 'load-' . $page, array( &$this, 'add_editor_button' ) );
  152. }
  153. // add message to list of plugins, if an update is available / add additional links on Plugins page, for both regular visits and AJAX calls
  154. add_action( 'in_plugin_update_message-' . WP_TABLE_RELOADED_BASENAME, array( &$this, 'add_plugin_update_message' ), 10, 2 );
  155. add_filter( 'plugin_row_meta', array( &$this, 'add_plugin_row_meta' ), 10, 2);
  156. }
  157. /**
  158. * Add admin page to the correct place in the admin menu, and set handler for when page is loaded or shown
  159. */
  160. function add_manage_page() {
  161. // user needs at least this capability to view WP-Table Reloaded config page
  162. // capabilities from http://codex.wordpress.org/Roles_and_Capabilities
  163. $user_group = $this->options['user_access_plugin'];
  164. $capabilities = array(
  165. 'admin' => 'manage_options',
  166. 'editor' => 'publish_pages',
  167. 'author' => 'publish_posts',
  168. 'contributor' => 'edit_posts'
  169. );
  170. $min_capability = isset( $capabilities[ $user_group ] ) ? $capabilities[ $user_group ] : 'manage_options';
  171. $min_capability = apply_filters( 'wp_table_reloaded_min_needed_capability', $min_capability ); // plugins may filter/change this though
  172. $display_name = 'WP-Table Reloaded'; // the name that is displayed in the admin menu on the left
  173. $display_name = apply_filters( 'wp_table_reloaded_plugin_display_name', $display_name ); // can be filtered to something shorter maybe
  174. $admin_menu_page = apply_filters( 'wp_table_reloaded_admin_menu_parent_page', $this->options['admin_menu_parent_page'] );
  175. // backward-compatibility for the filter
  176. if ( 'top-level' == $admin_menu_page )
  177. $admin_menu_page = 'admin.php';
  178. // 'edit-pages.php' was renamed to 'edit.php?post_type=page' in WP 3.0
  179. if ( 'edit-pages.php' == $admin_menu_page )
  180. $admin_menu_page = 'edit.php?post_type=page';
  181. if ( !in_array( $admin_menu_page, $this->possible_admin_menu_parent_pages ) )
  182. $admin_menu_page = 'tools.php';
  183. // Top-Level menu is created in different function, all others are created with the filename as a parameter
  184. if ( 'admin.php' == $admin_menu_page )
  185. $this->hook = add_menu_page( 'WP-Table Reloaded', $display_name, $min_capability, $this->page_slug, array( &$this, 'show_manage_page' ), plugins_url( 'admin/plugin-icon-small.png', WP_TABLE_RELOADED__FILE__ ) );
  186. else
  187. $this->hook = add_submenu_page( $admin_menu_page, 'WP-Table Reloaded', $display_name, $min_capability, $this->page_slug, array( &$this, 'show_manage_page' ) );
  188. $this->page_url = $admin_menu_page;
  189. add_action( 'load-' . $this->hook, array( &$this, 'load_manage_page' ) );
  190. }
  191. /**
  192. * Function is loaded by WordPress, if WP-Table Reloaded's admin menu entry is called,
  193. * Load the scripts, stylesheets and language, all of this will be done before the page is shown by show_manage_page()
  194. */
  195. function load_manage_page() {
  196. // show admin footer message (only on pages of WP-Table Reloaded)
  197. add_filter( 'admin_footer_text', array( &$this->helper, 'add_admin_footer_text' ) );
  198. $this->init_language_support();
  199. // get and check action parameter from passed variables
  200. $default_action = 'list';
  201. $default_action = apply_filters( 'wp_table_reloaded_default_action', $default_action );
  202. $this->allowed_actions = apply_filters( 'wp_table_reloaded_allowed_actions', $this->allowed_actions );
  203. $action = ( !empty( $_REQUEST['action'] ) ) ? $_REQUEST['action'] : $default_action;
  204. // check if action is in allowed actions and if method is callable, if yes, call it
  205. if ( in_array( $action, $this->allowed_actions ) )
  206. $this->action = $action;
  207. add_thickbox();
  208. // load js and css for admin, needs to stand below thickbox script
  209. $this->add_manage_page_js(); // will add script to footer
  210. $this->add_manage_page_css(); // needs to be added to the header
  211. // done after determining the action, because needs action parameter to load correct help string
  212. add_contextual_help( $this->hook, $this->helper->get_contextual_help_string() );
  213. }
  214. /**
  215. * Function is loaded by WordPress, if WP-Table Reloaded's admin menu entry is called,
  216. * responsible for calling the appropriate action handler, output of WP admin menu and header is already done here
  217. */
  218. function show_manage_page() {
  219. $this->available_plugin_languages = array(
  220. 'ar' => __( 'Arabic', WP_TABLE_RELOADED_TEXTDOMAIN ),
  221. 'be_BY' => __( 'Belarusian', WP_TABLE_RELOADED_TEXTDOMAIN ),
  222. 'bg_BG' => __( 'Bulgarian', WP_TABLE_RELOADED_TEXTDOMAIN ),
  223. 'cs_CZ' => __( 'Czech', WP_TABLE_RELOADED_TEXTDOMAIN ),
  224. 'de_DE' => __( 'German', WP_TABLE_RELOADED_TEXTDOMAIN ),
  225. 'en_US' => __( 'English', WP_TABLE_RELOADED_TEXTDOMAIN ),
  226. 'es_ES' => __( 'Spanish', WP_TABLE_RELOADED_TEXTDOMAIN ),
  227. 'fi' => __( 'Finnish', WP_TABLE_RELOADED_TEXTDOMAIN ),
  228. 'fr_FR' => __( 'French', WP_TABLE_RELOADED_TEXTDOMAIN ),
  229. 'he_IL' => __( 'Hebrew', WP_TABLE_RELOADED_TEXTDOMAIN ),
  230. 'hi_IN' => __( 'Hindi', WP_TABLE_RELOADED_TEXTDOMAIN ),
  231. 'id_ID' => __( 'Indonesian', WP_TABLE_RELOADED_TEXTDOMAIN ),
  232. 'it_IT' => __( 'Italian', WP_TABLE_RELOADED_TEXTDOMAIN ),
  233. 'ja' => __( 'Japanese', WP_TABLE_RELOADED_TEXTDOMAIN ),
  234. 'nl_NL' => __( 'Dutch', WP_TABLE_RELOADED_TEXTDOMAIN ),
  235. 'pl_PL' => __( 'Polish', WP_TABLE_RELOADED_TEXTDOMAIN ),
  236. 'pt_BR' => __( 'Brazilian Portuguese', WP_TABLE_RELOADED_TEXTDOMAIN ),
  237. 'pt_PT' => __( 'Portuguese (Portugal)', WP_TABLE_RELOADED_TEXTDOMAIN ),
  238. 'ru_RU' => __( 'Russian', WP_TABLE_RELOADED_TEXTDOMAIN ),
  239. 'sk_SK' => __( 'Slovak', WP_TABLE_RELOADED_TEXTDOMAIN ),
  240. 'sv_SE' => __( 'Swedish', WP_TABLE_RELOADED_TEXTDOMAIN ),
  241. 'ua_UA' => __( 'Ukrainian', WP_TABLE_RELOADED_TEXTDOMAIN ),
  242. 'zh_CN' => __( 'Chinese (Simplified)', WP_TABLE_RELOADED_TEXTDOMAIN ),
  243. // the following are inactive because they are not up-to-date
  244. // 'ga_IR' => __( 'Irish', WP_TABLE_RELOADED_TEXTDOMAIN ),
  245. // 'sq_AL' => __( 'Albanian', WP_TABLE_RELOADED_TEXTDOMAIN ),
  246. // 'tr_TR' => __( 'Turkish', WP_TABLE_RELOADED_TEXTDOMAIN ),
  247. );
  248. asort( $this->available_plugin_languages );
  249. // do WP plugin action (before action is fired) -> can stop further plugin execution by returning true
  250. $overwrite = apply_filters( 'wp_table_reloaded_action_pre_' . $this->action, false );
  251. if ( $overwrite )
  252. return;
  253. // call appropriate action, $this->action is populated in load_manage_page
  254. if ( is_callable( array( &$this, 'do_action_' . $this->action ) ) )
  255. call_user_func( array( &$this, 'do_action_' . $this->action ) );
  256. }
  257. // ###################################################################################################################
  258. // ########################################## ######################################################
  259. // ########################################## ACTIONS ######################################################
  260. // ########################################## ######################################################
  261. // ###################################################################################################################
  262. /**
  263. * "List Tables" action handler
  264. */
  265. function do_action_list() {
  266. $messages = array(
  267. 0 => false,
  268. 1 => sprintf( __( 'Welcome to WP-Table Reloaded %s. If you encounter any questions or problems, please refer to the <a href="%s">FAQ</a>, the <a href="%s">documentation</a>, and the <a href="%s">support</a> section.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->options['installed_version'], 'http://tobias.baethge.com/go/wp-table-reloaded/faq/', 'http://tobias.baethge.com/go/wp-table-reloaded/documentation/', 'http://tobias.baethge.com/go/wp-table-reloaded/support/' ),
  269. 2 => sprintf( __( 'Thank you for upgrading to WP-Table Reloaded %s.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->options['installed_version'] ) . ' ' . __( 'This version includes several bugfixes and a few enhancements.', WP_TABLE_RELOADED_TEXTDOMAIN ) . ' ' . sprintf( __( 'Please read the <a href="%s">release announcement</a> for more information.', WP_TABLE_RELOADED_TEXTDOMAIN ), "http://tobias.baethge.com/go/wp-table-reloaded/release-announcement/{$this->options['installed_version']}/" ) . '<br/>' . sprintf( __( 'If you like the new features and enhancements, I would appreciate a small <a href="%s">donation</a>. Thank you.', WP_TABLE_RELOADED_TEXTDOMAIN ), 'http://tobias.baethge.com/go/wp-table-reloaded/donate/' )
  270. );
  271. $message = ( isset( $messages[ $this->options['show_welcome_message'] ] ) ) ? $messages[ $this->options['show_welcome_message'] ] : false;
  272. if ( $message ) {
  273. $hide_welcome_message_url = $this->get_action_url( array( 'action' => 'hide_welcome_message' ), true );
  274. $this->helper->print_header_message( $message . '<br/><br/>' . sprintf( '<a href="%s" style="font-weight:normal;">%s</a>', $hide_welcome_message_url, __( 'Hide this message', WP_TABLE_RELOADED_TEXTDOMAIN ) ) );
  275. }
  276. if ( $this->may_print_donate_nag() ) {
  277. $donate_url = 'http://tobias.baethge.com/go/wp-table-reloaded/donate/message/';
  278. $donated_true_url = $this->get_action_url( array( 'action' => 'hide_donate_nag', 'user_donated' => true ), true );
  279. $donated_false_url = $this->get_action_url( array( 'action' => 'hide_donate_nag', 'user_donated' => false ), true );
  280. $this->helper->print_header_message(
  281. __( 'Thanks for using this plugin! You\'ve installed WP-Table Reloaded over a month ago.', WP_TABLE_RELOADED_TEXTDOMAIN ) . ' ' . sprintf( _n( 'If it works and you are satisfied with the results of managing your %s table, isn\'t it worth at least one dollar or euro?', 'If it works and you are satisfied with the results of managing your %s tables, isn\'t it worth at least one dollar or euro?', count( $this->tables ), WP_TABLE_RELOADED_TEXTDOMAIN ), count( $this->tables ) ) . '<br/><br/>' .
  282. sprintf( __( '<a href="%s">Donations</a> help me to continue support and development of this <i>free</i> software - things for which I spend countless hours of my free time! Thank you!', WP_TABLE_RELOADED_TEXTDOMAIN ), $donate_url ) . '<br/><br/>' .
  283. sprintf( '<a href="%s" target="_blank">%s</a>', $donate_url, __( 'Sure, no problem!', WP_TABLE_RELOADED_TEXTDOMAIN ) ) . '&nbsp;&nbsp;&middot;&nbsp;&nbsp;' .
  284. sprintf( '<a href="%s" style="font-weight:normal;">%s</a>', $donated_true_url, __( 'I already donated.', WP_TABLE_RELOADED_TEXTDOMAIN ) ) . '&nbsp;&nbsp;&middot;&nbsp;&nbsp;' .
  285. sprintf( '<a href="%s" style="font-weight:normal;">%s</a>', $donated_false_url, __( 'No, thanks. Don\'t ask again.', WP_TABLE_RELOADED_TEXTDOMAIN ) )
  286. );
  287. }
  288. $this->load_view( 'list' );
  289. }
  290. /**
  291. * "Add new Table" action handler
  292. */
  293. function do_action_add() {
  294. if ( isset( $_POST['submit'] ) && isset( $_POST['table'] ) ) {
  295. check_admin_referer( $this->get_nonce( 'add' ) );
  296. $rows = ( 0 < $_POST['table']['rows'] ) ? $_POST['table']['rows'] : 1;
  297. $cols = ( 0 < $_POST['table']['cols'] ) ? $_POST['table']['cols'] : 1;
  298. $table = $this->default_table;
  299. $table['id'] = $this->get_new_table_id();
  300. $table['data'] = $this->helper->create_empty_table( $rows, $cols );
  301. $table['visibility']['rows'] = array_fill( 0, $rows, false );
  302. $table['visibility']['columns'] = array_fill( 0, $cols, false );
  303. $table['name'] = $_POST['table']['name'];
  304. $table['description'] = $_POST['table']['description'];
  305. $this->save_table( $table );
  306. $this->helper->print_header_message( sprintf( __( 'Table &quot;%s&quot; added successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->helper->safe_output( $table['name'] ) ) );
  307. $table_id = $table['id'];
  308. $this->load_view( 'edit', compact( 'table_id' ) );
  309. } else {
  310. $this->load_view( 'add' );
  311. }
  312. }
  313. /**
  314. * "Edit Table" action handler
  315. */
  316. function do_action_edit() {
  317. if ( isset( $_POST['submit'] ) && isset( $_POST['table'] ) ) {
  318. check_admin_referer( $this->get_nonce( 'edit' ) );
  319. $subactions = array_keys( $_POST['submit'] );
  320. $subaction = $subactions[0];
  321. switch( $subaction ) {
  322. case 'update':
  323. case 'save_back':
  324. $table = $_POST['table']; // careful here to not miss any stuff!!! (options, etc.)
  325. // do we want to change the ID?
  326. $new_table_id = ( isset( $_POST['table_id'] ) ) ? $_POST['table_id'] : $table['id'] ;
  327. if ( $new_table_id != $table['id'] && is_numeric( $new_table_id ) && ( 0 < $new_table_id ) ) {
  328. if ( !$this->table_exists( $new_table_id ) ) {
  329. // delete table with old ID
  330. $old_table_id = $table['id'];
  331. $this->delete_table( $old_table_id );
  332. // set new table ID
  333. $table['id'] = $new_table_id;
  334. $message = sprintf( __( "Table edited successfully. This Table now has the ID %s. You'll need to adjust existing shortcodes accordingly.", WP_TABLE_RELOADED_TEXTDOMAIN ), $new_table_id );
  335. } else {
  336. $message = sprintf( __( 'The ID could not be changed from %s to %s, because there already is a Table with that ID.', WP_TABLE_RELOADED_TEXTDOMAIN ), $table['id'], $new_table_id );
  337. }
  338. } else {
  339. $message = __( 'Table edited successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
  340. }
  341. // save table options (checkboxes!), only checked checkboxes are submitted (then as true)
  342. $table['options']['alternating_row_colors'] = isset( $_POST['table']['options']['alternating_row_colors'] );
  343. $table['options']['row_hover'] = isset( $_POST['table']['options']['row_hover'] );
  344. $table['options']['first_row_th'] = isset( $_POST['table']['options']['first_row_th'] );
  345. $table['options']['table_footer'] = isset( $_POST['table']['options']['table_footer'] );
  346. $table['options']['print_name'] = isset( $_POST['table']['options']['print_name'] );
  347. $table['options']['print_description'] = isset( $_POST['table']['options']['print_description'] );
  348. $table['options']['cache_table_output'] = isset( $_POST['table']['options']['cache_table_output'] );
  349. $table['options']['custom_css_class'] = trim( $table['options']['custom_css_class'] ); // more complex sanitize_* functions would change spaces to hyphens...
  350. $table['options']['use_tablesorter'] = isset( $_POST['table']['options']['use_tablesorter'] );
  351. $table['options']['datatables_sort'] = isset( $_POST['table']['options']['datatables_sort'] );
  352. $table['options']['datatables_paginate'] = isset( $_POST['table']['options']['datatables_paginate'] );
  353. $table['options']['datatables_lengthchange'] = isset( $_POST['table']['options']['datatables_lengthchange'] );
  354. $table['options']['datatables_filter'] = isset( $_POST['table']['options']['datatables_filter'] );
  355. $table['options']['datatables_info'] = isset( $_POST['table']['options']['datatables_info'] );
  356. $table['options']['datatables_tabletools'] = isset( $_POST['table']['options']['datatables_tabletools'] );
  357. $table['options']['datatables_paginate_entries'] = ( is_numeric( $table['options']['datatables_paginate_entries'] ) ) ? absint( $table['options']['datatables_paginate_entries'] ) : $this->default_table['options']['datatables_paginate_entries'];
  358. // $table['options']['datatables_customcommands'] is an input type=text field that is always submitted
  359. // $table['options']['print_name|description_position'] are select fields that are always submitted
  360. // save visibility settings (checkboxes!)
  361. foreach ( $table['data'] as $row_idx => $row )
  362. $table['visibility']['rows'][$row_idx] = ( isset( $_POST['table']['visibility']['rows'][$row_idx] ) && ( 'true' == $_POST['table']['visibility']['rows'][$row_idx] ) );
  363. foreach ( $table['data'][0] as $col_idx => $col )
  364. $table['visibility']['columns'][$col_idx] = ( isset( $_POST['table']['visibility']['columns'][$col_idx] ) && ( 'true' == $_POST['table']['visibility']['columns'][$col_idx] ) );
  365. if ( !empty( $table['custom_fields'] ) )
  366. uksort( $table['custom_fields'], 'strnatcasecmp' ); // sort the keys naturally
  367. $this->save_table( $table );
  368. break;
  369. case 'swap_rows':
  370. $table_id = $_POST['table']['id'];
  371. $row_id1 = ( isset( $_POST['swap']['row'][1] ) ) ? $_POST['swap']['row'][1] : -1;
  372. $row_id2 = ( isset( $_POST['swap']['row'][2] ) ) ? $_POST['swap']['row'][2] : -1;
  373. $table = $this->load_table( $table_id );
  374. $rows = count( $table['data'] );
  375. // swap rows $row_id1 and $row_id2
  376. if ( ( 1 < $rows ) && ( -1 < $row_id1 ) && ( -1 < $row_id2 ) && ( $row_id1 != $row_id2 ) ) {
  377. $temp_row = $table['data'][$row_id1];
  378. $table['data'][$row_id1] = $table['data'][$row_id2];
  379. $table['data'][$row_id2] = $temp_row;
  380. $temp_visibility = $table['visibility']['rows'][$row_id1];
  381. $table['visibility']['rows'][$row_id1] = $table['visibility']['rows'][$row_id2];
  382. $table['visibility']['rows'][$row_id2] = $temp_visibility;
  383. }
  384. $this->save_table( $table );
  385. $message = __( 'Rows swapped successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
  386. break;
  387. case 'swap_cols':
  388. $table_id = $_POST['table']['id'];
  389. $col_id1 = ( isset( $_POST['swap']['col'][1] ) ) ? $_POST['swap']['col'][1] : -1;
  390. $col_id2 = ( isset( $_POST['swap']['col'][2] ) ) ? $_POST['swap']['col'][2] : -1;
  391. $table = $this->load_table( $table_id );
  392. $rows = count( $table['data'] );
  393. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  394. // swap rows $col_id1 and $col_id2
  395. if ( ( 1 < $cols ) && ( -1 < $col_id1 ) && ( -1 < $col_id2 ) && ( $col_id1 != $col_id2 ) ) {
  396. foreach ( $table['data'] as $row_idx => $row ) {
  397. $temp_col = $table['data'][$row_idx][$col_id1];
  398. $table['data'][$row_idx][$col_id1] = $table['data'][$row_idx][$col_id2];
  399. $table['data'][$row_idx][$col_id2] = $temp_col;
  400. }
  401. $temp_visibility = $table['visibility']['columns'][$col_id1];
  402. $table['visibility']['columns'][$col_id1] = $table['visibility']['columns'][$col_id2];
  403. $table['visibility']['columns'][$col_id2] = $temp_visibility;
  404. }
  405. $this->save_table( $table );
  406. $message = __( 'Columns swapped successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
  407. break;
  408. case 'sort':
  409. $table_id = $_POST['table']['id'];
  410. $column = ( isset( $_POST['sort']['col'] ) ) ? $_POST['sort']['col'] : -1;
  411. $sort_order = ( isset( $_POST['sort']['order'] ) ) ? $_POST['sort']['order'] : 'ASC';
  412. $table = $this->load_table( $table_id );
  413. $rows = count( $table['data'] );
  414. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  415. // sort array for $column in $sort_order
  416. if ( ( 1 < $rows ) && ( -1 < $column ) ) {
  417. // for sorting: temporarily store row visibility in data, so that it gets sorted, too
  418. foreach ( $table['data'] as $row_idx => $row )
  419. array_splice( $table['data'][$row_idx], $cols, 0, $table['visibility']['rows'][$row_idx] );
  420. $array_to_sort = $table['data'];
  421. if ( isset( $table['options']['first_row_th'] ) && $table['options']['first_row_th'] )
  422. $first_row = array_shift( $array_to_sort );
  423. if ( isset( $table['options']['table_footer'] ) && $table['options']['table_footer'] )
  424. $last_row = array_pop( $array_to_sort );
  425. $sortarray = $this->create_class_instance( 'arraysort', 'arraysort.class.php' );
  426. $sortarray->input_array = $array_to_sort;
  427. $sortarray->column = $column;
  428. $sortarray->order = $sort_order;
  429. $sortarray->sort();
  430. $sorted_array = $sortarray->sorted_array;
  431. if ( isset( $table['options']['first_row_th'] ) && $table['options']['first_row_th'] )
  432. array_unshift( $sorted_array, $first_row );
  433. if ( isset( $table['options']['table_footer'] ) && $table['options']['table_footer'] )
  434. array_push( $sorted_array, $last_row );
  435. $table['data'] = $sorted_array;
  436. // then restore row visibility from sorted data and remove temporary column
  437. foreach ( $table['data'] as $row_idx => $row ) {
  438. $table['visibility']['rows'][$row_idx] = $table['data'][$row_idx][$cols];
  439. array_splice( $table['data'][$row_idx], $cols, 1 );
  440. }
  441. }
  442. $this->save_table( $table );
  443. $message = __( 'Table sorted successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
  444. break;
  445. case 'move_row':
  446. $table_id = $_POST['table']['id'];
  447. $row_id1 = ( isset( $_POST['move']['row'][1] ) ) ? $_POST['move']['row'][1] : -1;
  448. $row_id2 = ( isset( $_POST['move']['row'][2] ) ) ? $_POST['move']['row'][2] : -1;
  449. $move_where = ( isset( $_POST['move']['row']['where'] ) ) ? $_POST['move']['row']['where'] : 'before';
  450. if ( 'after' == $move_where )
  451. $row_id2 = $row_id2 + 1; // move after is the same as move before the next row
  452. $table = $this->load_table( $table_id );
  453. $rows = count( $table['data'] );
  454. // move row $row_id1 before/after $row_id2
  455. if ( ( 1 < $rows ) && ( -1 < $row_id1 ) && ( -1 < $row_id2 ) && ( $row_id1 != $row_id2 ) ) {
  456. if ( $row_id2 > $row_id1 )
  457. $row_id2 = $row_id2 - 1; // if target higher than source, source element is removed, so target index smaller by one
  458. $temp_row = array( $table['data'][$row_id1] );
  459. unset( $table['data'][$row_id1] );
  460. array_splice( $table['data'], $row_id2, 0, $temp_row );
  461. $temp_visibility = $table['visibility']['rows'][$row_id1];
  462. unset( $table['visibility']['rows'][$row_id1] );
  463. array_splice( $table['visibility']['rows'], $row_id2, 0, $temp_visibility );
  464. }
  465. $this->save_table( $table );
  466. $message = __( 'Row moved successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
  467. break;
  468. case 'move_col':
  469. $table_id = $_POST['table']['id'];
  470. $col_id1 = ( isset( $_POST['move']['col'][1] ) ) ? $_POST['move']['col'][1] : -1;
  471. $col_id2 = ( isset( $_POST['move']['col'][2] ) ) ? $_POST['move']['col'][2] : -1;
  472. $move_where = ( isset( $_POST['move']['col']['where'] ) ) ? $_POST['move']['col']['where'] : 'before';
  473. if ( 'after' == $move_where )
  474. $col_id2 = $col_id2 + 1; // move after is the same as move before the next row
  475. $table = $this->load_table( $table_id );
  476. $rows = count( $table['data'] );
  477. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  478. // move col $col_id1 before/after $col_id2
  479. if ( ( 1 < $cols ) && ( -1 < $col_id1 ) && ( -1 < $col_id2 ) && ( $col_id1 != $col_id2 ) ) {
  480. if ( $col_id2 > $col_id1 )
  481. $col_id2 = $col_id2 - 1; // if target higher than source, source element is removed, so target index smaller by one
  482. foreach ( $table['data'] as $row_idx => $row ) {
  483. $temp_col = $table['data'][$row_idx][$col_id1];
  484. unset( $table['data'][$row_idx][$col_id1] );
  485. array_splice( $table['data'][$row_idx], $col_id2, 0, $temp_col );
  486. }
  487. $temp_visibility = $table['visibility']['columns'][$col_id1];
  488. unset( $table['visibility']['columns'][$col_id1] );
  489. array_splice( $table['visibility']['columns'], $col_id2, 0, $temp_visibility );
  490. }
  491. $this->save_table( $table );
  492. $message = __( 'Column moved successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
  493. break;
  494. case 'delete_rows':
  495. $table_id = $_POST['table']['id'];
  496. $delete_rows = ( isset( $_POST['table_select']['rows'] ) ) ? $_POST['table_select']['rows'] : array();
  497. $table = $this->load_table( $table_id );
  498. $rows = count( $table['data'] );
  499. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  500. $message = _n( 'Row could not be deleted.', 'Rows could not be deleted.', count( $delete_rows ), WP_TABLE_RELOADED_TEXTDOMAIN ); // only used if deletion fails below
  501. if ( ( 1 < $rows ) && ( 0 < count( $delete_rows ) ) && ( count( $delete_rows ) < $rows ) ) {
  502. // remove rows and re-index
  503. foreach ( $delete_rows as $row_idx => $value) {
  504. unset( $table['data'][$row_idx] );
  505. unset( $table['visibility']['rows'][$row_idx] );
  506. }
  507. $table['data'] = array_merge( $table['data'] );
  508. $table['visibility']['rows'] = array_merge( $table['visibility']['rows'] );
  509. $message = _n( 'Row deleted successfully.', 'Rows deleted successfully.', count( $delete_rows ), WP_TABLE_RELOADED_TEXTDOMAIN );
  510. }
  511. $this->save_table( $table );
  512. break;
  513. case 'delete_cols':
  514. $table_id = $_POST['table']['id'];
  515. $delete_columns = ( isset( $_POST['table_select']['columns'] ) ) ? $_POST['table_select']['columns'] : array();
  516. $table = $this->load_table( $table_id );
  517. $rows = count( $table['data'] );
  518. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  519. $message = _n( 'Column could not be deleted.', 'Columns could not be deleted.', count( $delete_columns ), WP_TABLE_RELOADED_TEXTDOMAIN ); // only used if deletion fails below
  520. if ( ( 1 < $cols ) && ( 0 < count( $delete_columns ) ) && ( count( $delete_columns ) < $cols ) ) {
  521. foreach ( $table['data'] as $row_idx => $row ) {
  522. // remove columns and re-index
  523. foreach ( $delete_columns as $col_idx => $value) {
  524. unset( $table['data'][$row_idx][$col_idx] );
  525. }
  526. $table['data'][$row_idx] = array_merge( $table['data'][$row_idx] );
  527. }
  528. foreach ( $delete_columns as $col_idx => $value) {
  529. unset( $table['visibility']['columns'][$col_idx] );
  530. }
  531. $table['visibility']['columns'] = array_merge( $table['visibility']['columns'] );
  532. $message = _n( 'Column deleted successfully.', 'Columns deleted successfully.', count( $delete_columns ), WP_TABLE_RELOADED_TEXTDOMAIN );
  533. }
  534. $this->save_table( $table );
  535. break;
  536. case 'insert_rows': // insert row before each selected row
  537. $table_id = $_POST['table']['id'];
  538. $insert_rows = ( isset( $_POST['table_select']['rows'] ) ) ? $_POST['table_select']['rows'] : array();
  539. $table = $this->load_table( $table_id );
  540. $rows = count( $table['data'] );
  541. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  542. // insert rows and re-index
  543. $row_change = 0; // row_change is growing parameter, needed because indices change
  544. $new_row = array( array_fill( 0, $cols, '' ) );
  545. foreach ( $insert_rows as $row_idx => $value) {
  546. $row_id = $row_idx + $row_change;
  547. // init new empty row (with all columns) and insert it before row with key $row_id
  548. array_splice( $table['data'], $row_id, 0, $new_row );
  549. array_splice( $table['visibility']['rows'], $row_id, 0, false );
  550. $row_change++;
  551. }
  552. $this->save_table( $table );
  553. $message = _n( 'Row inserted successfully.', 'Rows inserted successfully.', count( $insert_rows ), WP_TABLE_RELOADED_TEXTDOMAIN );
  554. break;
  555. case 'insert_cols': // insert column before each selected column
  556. $table_id = $_POST['table']['id'];
  557. $insert_columns = ( isset( $_POST['table_select']['columns'] ) ) ? $_POST['table_select']['columns'] : array();
  558. $table = $this->load_table( $table_id );
  559. $rows = count( $table['data'] );
  560. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  561. // insert cols and re-index
  562. $new_col = '';
  563. foreach ( $table['data'] as $row_idx => $row ) {
  564. $col_change = 0; // col_change is growing parameter, needed because indices change
  565. foreach ( $insert_columns as $col_idx => $value) {
  566. $col_id = $col_idx + $col_change;
  567. array_splice( $table['data'][$row_idx], $col_id, 0, $new_col );
  568. $col_change++;
  569. }
  570. }
  571. $col_change = 0; // col_change is growing parameter, needed because indices change
  572. foreach ( $insert_columns as $col_idx => $value) {
  573. $col_id = $col_idx + $col_change;
  574. array_splice( $table['visibility']['columns'], $col_id, 0, false );
  575. $col_change++;
  576. }
  577. $this->save_table( $table );
  578. $message = _n( 'Column inserted successfully.', 'Columns inserted successfully.', count( $insert_columns ), WP_TABLE_RELOADED_TEXTDOMAIN );
  579. break;
  580. case 'append_rows':
  581. $table_id = $_POST['table']['id'];
  582. $number = ( isset( $_POST['insert']['row']['number'] ) && ( 0 < $_POST['insert']['row']['number'] ) ) ? $_POST['insert']['row']['number'] : 1;
  583. $row_id = $_POST['insert']['row']['id'];
  584. $table = $this->load_table( $table_id );
  585. $rows = count( $table['data'] );
  586. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  587. // init new empty row (with all columns) and insert it before row with key $row_id
  588. $new_rows = $this->helper->create_empty_table( $number, $cols, '' );
  589. $new_rows_visibility = array_fill( 0, $number, false );
  590. array_splice( $table['data'], $row_id, 0, $new_rows );
  591. array_splice( $table['visibility']['rows'], $row_id, 0, $new_rows_visibility );
  592. $this->save_table( $table );
  593. $message = _n( 'Row added successfully.', 'Rows added successfully.', $number, WP_TABLE_RELOADED_TEXTDOMAIN );
  594. break;
  595. case 'append_cols':
  596. $table_id = $_POST['table']['id'];
  597. $number = ( isset( $_POST['insert']['col']['number'] ) && ( 0 < $_POST['insert']['col']['number'] ) ) ? $_POST['insert']['col']['number'] : 1;
  598. $col_id = $_POST['insert']['col']['id'];
  599. $table = $this->load_table( $table_id );
  600. // init new empty row (with all columns) and insert it before row with key $col_id
  601. $new_cols = array_fill( 0, $number, '' );
  602. $new_cols_visibility = array_fill( 0, $number, false );
  603. foreach ( $table['data'] as $row_idx => $row )
  604. array_splice( $table['data'][$row_idx], $col_id, 0, $new_cols );
  605. array_splice( $table['visibility']['columns'], $col_id, 0, $new_cols_visibility );
  606. $this->save_table( $table );
  607. $message = _n( 'Column added successfully.', 'Columns added successfully.', $number, WP_TABLE_RELOADED_TEXTDOMAIN );
  608. break;
  609. case 'insert_cf':
  610. $table_id = $_POST['table']['id'];
  611. $table = $this->load_table( $table_id );
  612. $name = ( isset( $_POST['insert']['custom_field'] ) ) ? $_POST['insert']['custom_field'] : '';
  613. if ( empty( $name ) ) {
  614. $message = __( 'Could not add Custom Data Field, because you did not enter a name.', WP_TABLE_RELOADED_TEXTDOMAIN );
  615. break;
  616. }
  617. $reserved_names = array( 'name', 'description', 'last_modified', 'last_editor' );
  618. if ( in_array( $name, $reserved_names ) ) {
  619. $message = __( 'Could not add Custom Data Field, because the name you entered is reserved for other table data.', WP_TABLE_RELOADED_TEXTDOMAIN );
  620. break;
  621. }
  622. // Name can only contain lowercase letters, numbers, _ and - (like permalink slugs)
  623. $clean_name = sanitize_title_with_dashes( $name );
  624. if ( $name != $clean_name ) {
  625. $message = __( 'Could not add Custom Data Field, because the name contained illegal characters.', WP_TABLE_RELOADED_TEXTDOMAIN );
  626. break;
  627. }
  628. if ( isset( $table['custom_fields'][$name] ) ) {
  629. $message = __( 'Could not add Custom Data Field, because a Field with that name already exists.', WP_TABLE_RELOADED_TEXTDOMAIN );
  630. break;
  631. }
  632. $table['custom_fields'][$name] = '';
  633. uksort( $table['custom_fields'], 'strnatcasecmp' ); // sort the keys naturally
  634. $this->save_table( $table );
  635. $message = __( 'Custom Data Field added successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
  636. break;
  637. default:
  638. $this->do_action_list();
  639. return;
  640. }
  641. $this->helper->print_header_message( $message );
  642. if ( 'save_back' == $subaction ) {
  643. $this->do_action_list();
  644. } else {
  645. $table_id = $table['id'];
  646. $this->load_view( 'edit', compact( 'table_id' ) );
  647. }
  648. } elseif ( isset( $_GET['table_id'] ) && $this->table_exists( $_GET['table_id'] ) ) {
  649. $table_id = $_GET['table_id'];
  650. $this->load_view( 'edit', compact( 'table_id' ) );
  651. } else {
  652. $this->do_action_list();
  653. }
  654. }
  655. /**
  656. * "Bulk Edit" action handler
  657. */
  658. function do_action_bulk_edit() {
  659. if ( isset( $_POST['submit'] ) ) {
  660. check_admin_referer( $this->get_nonce( 'bulk_edit' ) );
  661. if ( isset( $_POST['tables'] ) ) {
  662. $subactions = array_keys( $_POST['submit'] );
  663. $subaction = $subactions[0];
  664. switch( $subaction ) {
  665. case 'copy': // see do_action_copy for explanations
  666. foreach ( $_POST['tables'] as $table_id ) {
  667. $table_to_copy = $this->load_table( $table_id );
  668. $new_table = $table_to_copy;
  669. $new_table['id'] = $this->get_new_table_id();
  670. $new_table['name'] = __( 'Copy of', WP_TABLE_RELOADED_TEXTDOMAIN ) . ' ' . $table_to_copy['name'];
  671. unset( $table_to_copy );
  672. $this->save_table( $new_table );
  673. }
  674. $message = _n( 'Table copied successfully.', 'Tables copied successfully.', count( $_POST['tables'] ), WP_TABLE_RELOADED_TEXTDOMAIN );
  675. break;
  676. case 'delete': // see do_action_delete for explanations
  677. foreach ( $_POST['tables'] as $table_id ) {
  678. $this->delete_table( $table_id );
  679. }
  680. $message = _n( 'Table deleted successfully.', 'Tables deleted successfully.', count( $_POST['tables'] ), WP_TABLE_RELOADED_TEXTDOMAIN );
  681. break;
  682. case 'wp_table_import': // see do_action_import for explanations
  683. $this->import_instance = $this->create_class_instance( 'WP_Table_Reloaded_Import', 'import.class.php' );
  684. $this->import_instance->import_format = 'wp_table';
  685. foreach ( $_POST['tables'] as $table_id ) {
  686. $this->import_instance->wp_table_id = $table_id;
  687. $this->import_instance->import_table();
  688. $imported_table = $this->import_instance->imported_table;
  689. $table = array_merge( $this->default_table, $imported_table );
  690. $rows = count( $table['data'] );
  691. $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
  692. $rows = ( 0 < $rows ) ? $rows : 1;
  693. $cols = ( 0 < $cols ) ? $cols : 1;
  694. $table['visibility']['rows'] = array_fill( 0, $rows, false );
  695. $table['visibility']['columns'] = array_fill( 0, $cols, false );
  696. $table['id'] = $this->get_new_table_id();
  697. $this->save_table( $table );
  698. }
  699. $message = _n( 'Table imported successfully.', 'Tables imported successfully.', count( $_POST['tables'] ), WP_TABLE_RELOADED_TEXTDOMAIN );
  700. break;
  701. default:
  702. break;
  703. }
  704. } else {
  705. $message = __( 'You did not select any tables!', WP_TABLE_RELOADED_TEXTDOMAIN );
  706. }
  707. $this->helper->print_header_message( $message );
  708. }
  709. $this->do_action_list();
  710. }
  711. /**
  712. * "Copy" action handler
  713. */
  714. function do_action_copy() {
  715. if ( isset( $_GET['table_id'] ) ) {
  716. check_admin_referer( $this->get_nonce( 'copy' ) );
  717. $table_to_copy = $this->load_table( $_GET['table_id'] );
  718. $new_table = $table_to_copy;
  719. $new_table['id'] = $this->get_new_table_id();
  720. $new_table['name'] = __( 'Copy of', WP_TABLE_RELOADED_TEXTDOMAIN ) . ' ' . $table_to_copy['name'];
  721. unset( $table_to_copy );
  722. $this->save_table( $new_table );
  723. $this->helper->print_header_message( sprintf( __( 'Table &quot;%s&quot; copied successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->helper->safe_output( $new_table['name'] ) ) );
  724. }
  725. $this->do_action_list();
  726. }
  727. /**
  728. * "Delete" action handler, for tables and custom fields
  729. */
  730. function do_action_delete() {
  731. if ( isset( $_GET['table_id'] ) && isset( $_GET['item'] ) ) {
  732. check_admin_referer( $this->get_nonce( 'delete', $_GET['item'] ) );
  733. $table_id = $_GET['table_id'];
  734. $table = $this->load_table( $table_id );
  735. switch( $_GET['item'] ) {
  736. case 'table':
  737. $this->delete_table( $table_id );
  738. $this->helper->print_header_message( sprintf( __( 'Table &quot;%s&quot; deleted successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->helper->safe_output( $table['name'] ) ) );
  739. $this->do_action_list();
  740. break;
  741. case 'custom_field':
  742. $name = ( isset( $_GET['element_id'] ) ) ? $_GET['element_id'] : '';
  743. if ( !empty( $name ) && isset( $table['custom_fields'][$name] ) ) {
  744. unset( $table['custom_fields'][$name] );
  745. $this->save_table( $table );
  746. $message = __( 'Custom Data Field deleted successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
  747. } else {
  748. $message = __( 'Custom Data Field could not be deleted.', WP_TABLE_RELOADED_TEXTDOMAIN );
  749. }
  750. $this->helper->print_header_message( $message );
  751. $this->load_view( 'edit', compact( 'table_id' ) );
  752. break;
  753. default:
  754. $this->helper->print_header_message( __( 'Delete failed.', WP_TABLE_RELOADED_TEXTDOMAIN ) );
  755. $this->do_action_list();
  756. }
  757. } else {
  758. $this->do_action_list();
  759. }
  760. }
  761. /**
  762. * "Import" action handler, for single tables and a Dump File
  763. */
  764. function do_action_import() {
  765. $this->import_instance = $this->create_class_instance( 'WP_Table_Reloaded_Import', 'import.class.php' );
  766. if ( isset( $_POST['submit'] ) && isset( $_POST['import_from'] ) ) {
  767. check_admin_referer( $this->get_nonce( 'import' ) );
  768. $import_error = false;
  769. switch( $_POST['import_from'] ) {
  770. case 'file-upload':

Large files files are truncated, but you can click here to view the full file