All_in_One_SEO_Pack_File_Editor

Class All_in_One_SEO_Pack_File_Editor.

Defined (1)

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

/modules/aioseop_file_editor.php  
  1. class All_in_One_SEO_Pack_File_Editor extends All_in_One_SEO_Pack_Module { 
  2.  
  3. /** 
  4. * All_in_One_SEO_Pack_File_Editor constructor. 
  5. */ 
  6. function __construct() { 
  7. $this->name = __( 'File Editor', 'all-in-one-seo-pack' ); // Human-readable name of the plugin 
  8. $this->prefix = 'aiosp_file_editor_'; // option prefix 
  9. $this->file = __FILE__; // the current file 
  10. parent::__construct(); 
  11. $this->current_tab = 'robots'; 
  12. if ( isset( $_REQUEST['tab'] ) ) { 
  13. $this->current_tab = $_REQUEST['tab']; 
  14.  
  15. $help_text = array( 
  16. 'robotfile' => __( 'Robots.txt editor', 'all-in-one-seo-pack' ),  
  17. 'htaccfile' => __( '.htaccess editor', 'all-in-one-seo-pack' ),  
  18. ); 
  19. $this->default_options = array( 
  20. 'robotfile' => array( 
  21. 'name' => __( 'Edit Robots.txt', 'all-in-one-seo-pack' ),  
  22. 'save' => false,  
  23. 'default' => '',  
  24. 'type' => 'textarea',  
  25. 'cols' => 70,  
  26. 'rows' => 25,  
  27. 'label' => 'top',  
  28. ),  
  29. 'htaccfile' => array( 
  30. 'name' => __( 'Edit .htaccess', 'all-in-one-seo-pack' ),  
  31. 'save' => false,  
  32. 'default' => '',  
  33. 'type' => 'textarea',  
  34. 'cols' => 70,  
  35. 'rows' => 25,  
  36. 'label' => 'top',  
  37. ),  
  38. ); 
  39.  
  40. if ( ! empty( $help_text ) ) { 
  41. foreach ( $help_text as $k => $v ) { 
  42. $this->default_options[ $k ]['help_text'] = $v; 
  43. $this->tabs = array( 
  44. 'robots' => array( 'name' => __( 'robots.txt' ) ),  
  45. 'htaccess' => array( 'name' => __( '.htaccess' ) ),  
  46. ); 
  47.  
  48. $this->layout = array( 
  49. 'robots' => array( 
  50. 'name' => __( 'Edit robots.txt', 'all-in-one-seo-pack' ),  
  51. 'options' => array( 'robotfile' ),  
  52. 'tab' => 'robots',  
  53. ),  
  54. 'htaccess' => array( 
  55. 'name' => __( 'Edit .htaccess', 'all-in-one-seo-pack' ),  
  56. 'options' => array( 'htaccfile' ),  
  57. 'tab' => 'htaccess',  
  58. ),  
  59. ); 
  60.  
  61. $this->update_options(); // load initial options / set defaults 
  62.  
  63. function settings_page_init() { 
  64. add_filter( $this->prefix . 'display_options', array( $this, 'filter_options' ), 10, 2 ); 
  65. add_filter( $this->prefix . 'submit_options', array( $this, 'filter_submit' ), 10, 2 ); 
  66.  
  67. function add_page_hooks() { 
  68. parent::add_page_hooks(); 
  69. add_action( $this->prefix . 'settings_update', array( $this, 'do_file_editor' ), 10, 2 ); 
  70.  
  71. /** 
  72. * @param $submit 
  73. * @param $location 
  74. * @return mixed 
  75. */ 
  76. function filter_submit( $submit, $location ) { 
  77. unset( $submit['Submit_Default'] ); 
  78. $submit['Submit']['type'] = 'hidden'; 
  79. if ( 'robots' === $this->current_tab ) { 
  80. $submit['Submit_File_Editor'] = array( 
  81. 'type' => 'submit',  
  82. 'class' => 'button-primary',  
  83. 'value' => __( 'Update robots.txt', 'all-in-one-seo-pack' ) . ' »',  
  84. ); 
  85. } elseif ( 'htaccess' === $this->current_tab ) { 
  86. $submit['Submit_htaccess'] = array( 
  87. 'type' => 'submit',  
  88. 'class' => 'button-primary',  
  89. 'value' => __( 'Update .htaccess', 'all-in-one-seo-pack' ) . ' »',  
  90. ); 
  91.  
  92. return $submit; 
  93.  
  94. /** 
  95. * @param $options 
  96. * @param $location 
  97. * @return mixed 
  98. */ 
  99. function filter_options( $options, $location ) { 
  100. $prefix = $this->get_prefix( $location ); 
  101. if ( 'robots' === $this->current_tab ) { 
  102. $options = $this->load_files( $options, array( 'robotfile' => 'robots.txt' ), $prefix ); 
  103. } elseif ( 'htaccess' === $this->current_tab ) { 
  104. $options = $this->load_files( $options, array( 'htaccfile' => '.htaccess' ), $prefix ); 
  105.  
  106. return $options; 
  107.  
  108. /** 
  109. * @param $options This seems to be unused. 
  110. * @param $location 
  111. */ 
  112. function do_file_editor( $options, $location ) { 
  113. $prefix = $this->get_prefix( $location ); 
  114. if ( 'robots' === $this->current_tab && isset( $_POST['Submit_File_Editor'] ) && $_POST['Submit_File_Editor'] ) { 
  115. $this->save_files( array( 'robotfile' => 'robots.txt' ), $prefix ); 
  116. } elseif ( 'htaccess' === $this->current_tab && isset( $_POST['Submit_htaccess'] ) && $_POST['Submit_htaccess'] ) { 
  117. $this->save_files( array( 'htaccfile' => '.htaccess' ), $prefix );