PageRenderTime 70ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/all-in-one-wp-migration/lib/controller/class-ai1wm-import-controller.php

https://gitlab.com/vanafroo/landingpage
PHP | 125 lines | 78 code | 15 blank | 32 comment | 16 complexity | c44272ca7f8c6d311b644bbdbf02beca MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright (C) 2014-2016 ServMask Inc.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
  19. * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
  20. * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
  21. * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
  22. * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
  23. * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
  24. */
  25. class Ai1wm_Import_Controller {
  26. public static function index() {
  27. Ai1wm_Template::render( 'import/index' );
  28. }
  29. public static function import( $params = array() ) {
  30. global $wp_filter;
  31. // Set error handler
  32. @set_error_handler( 'Ai1wm_Handler::error' );
  33. // Set params
  34. if ( empty( $params ) ) {
  35. $params = ai1wm_urldecode( $_REQUEST );
  36. }
  37. // Set priority
  38. $priority = 10;
  39. if ( isset( $params['priority'] ) ) {
  40. $priority = (int) $params['priority'];
  41. }
  42. // Set secret key
  43. $secret_key = null;
  44. if ( isset( $params['secret_key'] ) ) {
  45. $secret_key = $params['secret_key'];
  46. }
  47. // Verify secret key by using the value in the database, not in cache
  48. if ( $secret_key !== get_option( AI1WM_SECRET_KEY ) ) {
  49. Ai1wm_Status::error(
  50. sprintf( __( 'Unable to authenticate your request with secret_key = "%s"', AI1WM_PLUGIN_NAME ), $secret_key ),
  51. __( 'Unable to import', AI1WM_PLUGIN_NAME )
  52. );
  53. exit;
  54. }
  55. // Get hook
  56. if ( isset( $wp_filter['ai1wm_import'] ) && ( $filters = $wp_filter['ai1wm_import'] ) && ksort( $filters ) ) {
  57. while ( $hooks = current( $filters ) ) {
  58. if ( $priority == key( $filters ) ) {
  59. foreach ( $hooks as $hook ) {
  60. try {
  61. $params = call_user_func_array( $hook['function'], array( $params ) );
  62. }
  63. catch ( Ai1wm_Import_Retry_Exception $exception ) {
  64. status_header( $exception->getCode() );
  65. echo json_encode( array( 'message' => $exception->getMessage() ) );
  66. exit;
  67. }
  68. catch ( Exception $e ) {
  69. Ai1wm_Status::error( $e->getMessage(), __( 'Unable to import', AI1WM_PLUGIN_NAME ) );
  70. exit;
  71. }
  72. }
  73. // Set completed
  74. $completed = true;
  75. if ( isset( $params['completed'] ) ) {
  76. $completed = (bool) $params['completed'];
  77. }
  78. // Log request
  79. if ( empty( $params['priority'] ) || is_file( ai1wm_import_path( $params ) ) ) {
  80. Ai1wm_Log::import( $params );
  81. }
  82. // Do request
  83. if ( $completed === false || ( $next = next( $filters ) ) && ( $params['priority'] = key( $filters ) ) ) {
  84. return Ai1wm_Http::get( admin_url( 'admin-ajax.php?action=ai1wm_import' ), $params );
  85. }
  86. }
  87. next( $filters );
  88. }
  89. }
  90. }
  91. public static function buttons() {
  92. return array(
  93. apply_filters( 'ai1wm_import_file', Ai1wm_Template::get_content( 'import/button-file' ) ),
  94. apply_filters( 'ai1wm_import_url', Ai1wm_Template::get_content( 'import/button-url' ) ),
  95. apply_filters( 'ai1wm_import_ftp', Ai1wm_Template::get_content( 'import/button-ftp' ) ),
  96. apply_filters( 'ai1wm_import_dropbox', Ai1wm_Template::get_content( 'import/button-dropbox' ) ),
  97. apply_filters( 'ai1wm_import_gdrive', Ai1wm_Template::get_content( 'import/button-gdrive' ) ),
  98. apply_filters( 'ai1wm_import_s3', Ai1wm_Template::get_content( 'import/button-s3' ) ),
  99. apply_filters( 'ai1wm_import_onedrive', Ai1wm_Template::get_content( 'import/button-onedrive' ) ),
  100. apply_filters( 'ai1wm_import_box', Ai1wm_Template::get_content( 'import/button-box' ) ),
  101. );
  102. }
  103. public static function max_chunk_size() {
  104. return min(
  105. ai1wm_parse_size( ini_get( 'post_max_size' ), AI1WM_MAX_CHUNK_SIZE ),
  106. ai1wm_parse_size( ini_get( 'upload_max_filesize' ), AI1WM_MAX_CHUNK_SIZE ),
  107. ai1wm_parse_size( AI1WM_MAX_CHUNK_SIZE )
  108. );
  109. }
  110. }