Redux_Filesystem

The Gravity Forms Advanced File Uploader Redux Filesystem class.

Defined (1)

The class is defined in the following location(s).

/inc/ReduxFramework/ReduxCore/inc/class.redux_filesystem.php  
  1. class Redux_Filesystem { 
  2. private $parent = null; 
  3.  
  4. private $creds = array(); 
  5.  
  6. public $fs_object = null; 
  7.  
  8. public function __construct( $parent ) { 
  9. $parent->filesystem = $this; 
  10. $this->parent = $parent; 
  11.  
  12. public function ftp_form() { 
  13. if ( isset( $this->parent->ftp_form ) && ! empty( $this->parent->ftp_form ) ) { 
  14. echo '<div class="wrap"><div class="error"><p>'; 
  15. echo __( 'Unable to modify required files. Please ensure that', 'redux-framework' ); 
  16. echo ' <code>' . Redux_Helpers::cleanFilePath( trailingslashit( WP_CONTENT_DIR ) ) . '/uploads/</code> '; 
  17. echo __( 'has the proper read/write permissions or enter your FTP information below.', 'redux-framework' ); 
  18. echo '</p></div><h2></h2>' . $this->parent->ftp_form . '</div>'; 
  19.  
  20. function filesystem_init( $form_url, $method = '', $context = false, $fields = null ) { 
  21. global $wp_filesystem; 
  22. if ( ! empty( $this->creds ) ) { 
  23. return true; 
  24.  
  25. ob_start(); 
  26.  
  27. /** first attempt to get credentials */ 
  28. if ( false === ( $this->creds = request_filesystem_credentials( $form_url, $method, false, $context ) ) ) { 
  29. $this->creds = array(); 
  30. $this->parent->ftp_form = ob_get_contents(); 
  31. ob_end_clean(); 
  32.  
  33. /** 
  34. * if we comes here - we don't have credentials 
  35. * so the request for them is displaying 
  36. * no need for further processing 
  37. **/ 
  38.  
  39. return false; 
  40.  
  41. /** now we got some credentials - try to use them*/ 
  42. if ( ! WP_Filesystem( $this->creds ) ) { 
  43. $this->creds = array(); 
  44. /** incorrect connection data - ask for credentials again, now with error message */ 
  45. request_filesystem_credentials( $form_url, '', true, $context ); 
  46. $this->parent->ftp_form = ob_get_contents(); 
  47. ob_end_clean(); 
  48.  
  49. return false; 
  50.  
  51.  
  52. return true; 
  53.  
  54. public function execute( $action, $file = '', $params = '' ) { 
  55.  
  56. if ( ! empty ( $params ) ) { 
  57. extract( $params ); 
  58.  
  59. // Setup the filesystem with creds 
  60. require_once( ABSPATH . '/wp-admin/includes/template.php' ); 
  61. require_once( ABSPATH . '/wp-admin/includes/file.php' ); 
  62.  
  63. if ( $this->parent->args['menu_type'] == 'submenu' ) { 
  64. $page_parent = $this->parent->args['page_parent']; 
  65. $base = $page_parent . '?page=' . $this->parent->args['page_slug']; 
  66. } else { 
  67. $base = 'admin.php?page=' . $this->parent->args['page_slug']; 
  68.  
  69. $url = wp_nonce_url( $base, 'redux-options' ); 
  70.  
  71. $this->filesystem_init( $url, 'direct', dirname( $file ) ); 
  72.  
  73. return $this->do_action( $action, $file, $params ); 
  74.  
  75. public function do_action( $action, $file = '', $params = '' ) { 
  76.  
  77. if ( ! empty ( $params ) ) { 
  78. extract( $params ); 
  79.  
  80. global $wp_filesystem; 
  81.  
  82. if ( defined( 'FS_CHMOD_FILE' ) ) { 
  83. $chmod = FS_CHMOD_FILE; 
  84. } else { 
  85. $chmod = 0644; 
  86.  
  87. //$target_dir = $wp_filesystem->find_folder( dirname( $file ) ); 
  88.  
  89. // Do unique stuff 
  90. if ( $action == 'mkdir' && ! isset( $this->filesystem->killswitch ) ) { 
  91. wp_mkdir_p( $file ); 
  92.  
  93. $res = file_exists( $file ); 
  94. if ( defined( 'FS_CHMOD_DIR' ) ) { 
  95. $chmod = FS_CHMOD_DIR; 
  96. } else { 
  97. $chmod = 0755; 
  98. if ( ! $res ) { 
  99. mkdir( $file, $chmod, true ); 
  100. $res = file_exists( $file ); 
  101. } elseif ( $action == 'copy' && ! isset( $this->filesystem->killswitch ) ) { 
  102. if ( isset( $this->parent->ftp_form ) && ! empty( $this->parent->ftp_form ) ) { 
  103. $res = copy( $file, $destination ); 
  104. if ( $res ) { 
  105. chmod( $destination, $chmod ); 
  106. } else { 
  107. $res = $wp_filesystem->copy( $file, $destination, $overwrite, $chmod ); 
  108. } elseif ( $action == 'put_contents' && ! isset( $this->filesystem->killswitch ) ) { 
  109. if ( isset( $this->parent->ftp_form ) && ! empty( $this->parent->ftp_form ) ) { 
  110. $res = file_put_contents( $file, $content ); 
  111. if ( $res ) { 
  112. chmod( $file, $chmod ); 
  113. } else { 
  114. $res = $wp_filesystem->put_contents( $file, $content, FS_CHMOD_FILE ); 
  115. } elseif ( $action == 'get_contents' ) { 
  116. if ( isset( $this->parent->ftp_form ) && ! empty( $this->parent->ftp_form ) ) { 
  117. $res = file_get_contents( $file ); 
  118. } else { 
  119. $res = $wp_filesystem->get_contents( $file ); 
  120. } elseif ( $action == 'object' ) { 
  121. $res = $wp_filesystem; 
  122. if ( isset( $res ) && ! $res ) { 
  123. $this->killswitch = true; 
  124.  
  125. if ( ! $res ) { 
  126. add_action( "redux/page/{$parent->args['opt_name']}/form/before", array( $this, 'ftp_form' ) ); 
  127.  
  128. return $res;