class-simple-job-board-settings-upload-file-extensions.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php if (!defined('ABSPATH')) { exit; } // Exit if accessed directly
  2. /**
  3. * Simple_Job_Board_Settings_Upload_File_Extensions Class
  4. *
  5. * This file used to define the settings for the resume extensions. Allowable
  6. * extensions for resume are doc, docx, rtf, txt, odt.
  7. *
  8. * @link https://wordpress.org/plugins/simple-job-board
  9. * @since 2.2.3
  10. * @since 2.4.0 Revised Inputs & Outputs Sanitization & Escaping
  11. *
  12. * @package Simple_Job_Board
  13. * @subpackage Simple_Job_Board/admin/settings
  14. * @author PressTigers <support@presstigers.com>
  15. */
  16. class Simple_Job_Board_Settings_Upload_File_Extensions {
  17. /**
  18. * Initialize the class and set its properties.
  19. *
  20. * @since 2.2.3
  21. */
  22. public function __construct() {
  23. // Filter -> Add Settings Uploaded File Extensions Tab
  24. add_filter('sjb_settings_tab_menus', array($this, 'sjb_add_settings_tab'), 80);
  25. // Action -> Add Settings Uploaded File Extensions Section
  26. add_action('sjb_settings_tab_section', array($this, 'sjb_add_settings_section'), 80);
  27. // Action -> Save Settings Uploaded File Extensions Section
  28. add_action('sjb_save_setting_sections', array($this, 'sjb_save_settings_section'));
  29. }
  30. /**
  31. * Add Settings Uploaded File Extensions Tab.
  32. *
  33. * @since 2.2.3
  34. *
  35. * @param array $tabs Settings Tab
  36. * @return array $tabs Merge array of Settings Tab with "Upload File Extensions" Tab.
  37. */
  38. public function sjb_add_settings_tab($tabs) {
  39. $tabs['upload_file_ext'] = esc_html__( 'Upload File Extensions', 'simple-job-board' );
  40. return $tabs;
  41. }
  42. /**
  43. * Add Settings Uploaded File Extensions Section.
  44. *
  45. * @since 2.2.3
  46. */
  47. public function sjb_add_settings_section() {
  48. ?>
  49. <!-- Upload File Extensions -->
  50. <div id="settings-upload_file_ext" class="sjb-admin-settings" style="display: none;">
  51. <?php
  52. /**
  53. * Action -> Add new section before file upload settings .
  54. *
  55. * @since 2.2.0
  56. */
  57. do_action('sjb_file_upload_settings_before');
  58. ?>
  59. <form method="post" id="upload-file-form">
  60. <h4 class="first"><?php echo esc_html__('Upload File Extensions', 'simple-job-board'); ?></h4>
  61. <div class="sjb-section">
  62. <div class="sjb-content">
  63. <?php
  64. /**
  65. * Action -> Add new fields at start of upload section first field.
  66. *
  67. * @since 2.2.0
  68. */
  69. do_action('sjb_file_upload_settings_start');
  70. ?>
  71. <select multiple="multiple" name="file_extensions[]" id="upload-file-select" size="6">
  72. <?php
  73. /**
  74. * Action -> Add new extension at the start of list.
  75. *
  76. * @since 2.2.0
  77. */
  78. do_action('sjb_file_extension_options_start');
  79. ?>
  80. <option <?php
  81. $selected = ( 'no' === get_option('job_board_all_extensions_check') ) ? ( FALSE !== get_option('job_board_upload_file_ext') ) ? (in_array('pdf', get_option('job_board_upload_file_ext')) ? 'selected' : '' ) : '' : 'selected';
  82. echo $selected
  83. ?> value="pdf"><?php echo esc_html__('pdf', 'simple-job-board'); ?></option>
  84. <option <?php
  85. $selected = ( 'no' === get_option('job_board_all_extensions_check') ) ? ( FALSE !== get_option('job_board_upload_file_ext') ) ? (in_array('doc', get_option('job_board_upload_file_ext')) ? 'selected' : '' ) : '' : 'selected';
  86. echo $selected
  87. ?> value="doc"><?php echo esc_html__('doc', 'simple-job-board'); ?></option>
  88. <option <?php
  89. $selected = ( 'no' === get_option('job_board_all_extensions_check') ) ? ( FALSE !== get_option('job_board_upload_file_ext') ) ? (in_array('docx', get_option('job_board_upload_file_ext')) ? 'selected' : '' ) : '' : 'selected';
  90. echo $selected
  91. ?> value="docx"><?php echo esc_html__('docx', 'simple-job-board'); ?></option>
  92. <option <?php
  93. $selected = ( 'no' === get_option('job_board_all_extensions_check') ) ? ( FALSE !== get_option('job_board_upload_file_ext') ) ? (in_array('odt', get_option('job_board_upload_file_ext')) ? 'selected' : '' ) : '' : 'selected';
  94. echo $selected
  95. ?> value="odt"><?php echo esc_html__('odt', 'simple-job-board'); ?></option>
  96. <option <?php
  97. $selected = ( 'no' === get_option('job_board_all_extensions_check') ) ? ( FALSE !== get_option('job_board_upload_file_ext') ) ? (in_array('rtf', get_option('job_board_upload_file_ext')) ? 'selected' : '' ) : '' : 'selected';
  98. echo $selected
  99. ?> value="rtf"><?php echo esc_html__('rtf', 'simple-job-board'); ?></option>
  100. <option <?php
  101. $selected = ( 'no' === get_option('job_board_all_extensions_check') ) ? ( FALSE !== get_option('job_board_upload_file_ext') ) ? (in_array('txt', get_option('job_board_upload_file_ext')) ? 'selected' : '' ) : '' : 'selected';
  102. echo $selected
  103. ?> value="txt"><?php echo esc_html__('txt', 'simple-job-board'); ?></option>
  104. <?php
  105. /**
  106. * Action -> Add new extension at the end of list.
  107. *
  108. * @since 2.2.0
  109. */
  110. do_action('sjb_file_extension_options_end');
  111. ?>
  112. </select>
  113. <div class="sjb-form-group"><?php echo esc_html__('Press and hold down the Ctrl key to select multiple extensions.', 'simple-job-board'); ?></div>
  114. <div class="sjb-form-group">
  115. <input type="checkbox" name="all_file_extensions" id="all-file-ext" value="all extension" <?php if ('yes' === get_option('job_board_all_extensions_check')) echo 'checked="checked"'; ?> />
  116. <label><?php echo esc_html__('Enable all Extensions', 'simple-job-board'); ?></label>
  117. <input type='hidden' name="empty_file_extensions" value="empty_file_extensions" />
  118. </div>
  119. <div class="sjb-form-group">
  120. <i class="fa fa-info-circle" aria-hidden="true"></i> <label><?php echo esc_html__( 'Secruity rules have been updated since SJB version 2.4.3.', 'simple-job-board' ); ?></label>
  121. </div>
  122. <?php
  123. /**
  124. * Action -> Add new fields at the end of upload section.
  125. *
  126. * @since 2.2.0
  127. */
  128. do_action('sjb_file_upload_settings_end');
  129. ?>
  130. </div>
  131. </div>
  132. <input type="hidden" value="1" name="admin_notices" />
  133. <input type="submit" name="upload_file_form_submit" id="upload-file-form-submit" class="button button-primary" value="<?php echo esc_html__('Save Changes', 'simple-job-board'); ?>" />
  134. </form>
  135. </div>
  136. <?php
  137. }
  138. /**
  139. * Save Settings Upload File Extension Section.
  140. *
  141. * This function is used to save the uploaded file extensions settings. User
  142. * can set the security of uploaded file by enabling/disabling it's
  143. * extension & anti-hotlinking rules.
  144. *
  145. * @since 2.2.3
  146. */
  147. public function sjb_save_settings_section() {
  148. $file_extensions = filter_input( INPUT_POST, 'file_extensions', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
  149. $empty_file_extensions = filter_input( INPUT_POST, 'empty_file_extensions' );
  150. $all_file_extensions = filter_input( INPUT_POST, 'all_file_extensions' );
  151. $files_hotlinking = filter_input( INPUT_POST, 'files_hotlinking' );
  152. // Save File Extension on Form Submission
  153. if ( !empty( $file_extensions ) || !empty( $empty_file_extensions ) ) {
  154. // Empty Checkboxes Status
  155. $file_extension = $anti_hotlinking = 'no';
  156. // Save Extentions Settigns
  157. if ( !empty( $file_extensions ) ) {
  158. // Save Extentions in WP Options || Add Options if not Exist
  159. ( FALSE !== get_option('job_board_upload_file_ext') ) ?
  160. update_option('job_board_upload_file_ext', $file_extensions ) :
  161. add_option('job_board_upload_file_ext', $file_extensions, '', 'no');
  162. }
  163. // Enable All File Extensions
  164. if ( isset( $all_file_extensions ) ) {
  165. update_option('job_board_all_extensions_check', 'yes');
  166. $file_extension = 'yes';
  167. }
  168. // Enable File Anti-hotlinking Rules
  169. if ( isset( $files_hotlinking ) ) {
  170. update_option('job_board_anti_hotlinking', 'yes');
  171. $anti_hotlinking = 'yes';
  172. $sjbrObj = new Simple_Job_Board_Rewrite();
  173. $sjbrObj->job_board_rewrite();
  174. }
  175. // Disable File Extensions
  176. if ( 'no' === $file_extension ) {
  177. update_option('job_board_all_extensions_check', 'no');
  178. }
  179. // Disable Anti-Hotlinking Rules
  180. if ( 'no' === $anti_hotlinking ) {
  181. update_option('job_board_anti_hotlinking', 'no');
  182. $sjbrObj = new Simple_Job_Board_Rewrite();
  183. $sjbrObj->job_board_rewrite();
  184. }
  185. }
  186. }
  187. }