Protect uploads - Version 0.3

Version Description

Nothing for now

Download this release

Release Info

Developer alticreation
Plugin Icon 128x128 Protect uploads
Version 0.3
Comparing to
See all releases

Code changes from version 0.2 to 0.3

admin/assets/css/protect-uploads-admin.css CHANGED
@@ -1,80 +1,23 @@
1
- #wrap.protect-uploads h2 {
2
- font-size: 30px;
3
- }
4
- #wrap.protect-uploads h2 span, #wrap.protect-uploads h2 span * {
5
- font-size: 14px;
6
- color: #888;
7
- }
8
- #wrap.protect-uploads .description {
9
- color: #666;
10
- }
11
- #wrap.protect-uploads .small {
12
- font-size: .8em;
13
- font-style: none !important;
14
- }
15
- #wrap.protect-uploads .alert {
16
- font-size: .9em;
17
- color: #238ECB;
18
- }
19
- #wrap.protect-uploads .error {
20
- color: #E23C0C;
21
- }
22
- #wrap.protect-uploads .valid {
23
- color: #7ad03a;
24
- }
25
- #wrap.protect-uploads .valid.note {
26
- margin-left: 25px;
27
- background: #fff;
28
  display: inline-block;
29
- padding:10px;
30
- }
31
- #wrap.protect-uploads .valid.note span {
32
- color: #919191;
33
- }
34
- #wrap.protect-uploads label span.dashicons-image-crop:before {
35
- font-size: 16px !important;
36
- color: #aaa;
37
  }
38
- #wrap.protect-uploads th label span.dashicons {
39
- color: #238ECB;
40
- margin: 0 5px 10px 0;
41
- }
42
- #wrap.protect-uploads td label {
43
- margin-bottom: 15px !important;
44
- }
45
- #wrap.protect-uploads td label p.description {
46
- margin-left: 25px;
47
- }
48
- #wrap.protect-uploads img.protect-uploads {
49
- border: 1px solid #ccc;
50
- padding: 5px;
51
- }
52
- #wrap.protect-uploads .protect-uploads-footer {
53
- border-left: 0 !important;
54
- margin-left: 0 !important;
55
- overflow: hidden;
56
- padding: 15px !important;
57
- margin-top: 30px;
58
- }
59
- #wrap.protect-uploads .protect-uploads-footer .logo {
60
- float: left;
61
- margin-right: 20px;
62
- }
63
- #wrap.protect-uploads .protect-uploads-footer .share a {
64
- display: inline-block;
65
- padding: 5px 10px;
66
- background: #238ECB;
67
- color: #fff;
68
- margin: 0 5px 0 0;
69
  }
70
 
71
  /* container left and right */
72
- #wrap.protect-uploads .protect-uploads-main-container {
73
  float: left;
74
  width: 66%;
75
  }
76
- #wrap.protect-uploads .protect-uploads-sidebar {
77
  float: left;
78
  width: 31%;
79
  margin-left: 2%;
 
 
 
 
80
  }
1
+ .protect-uploads-error {
2
+ border: 2px solid #dc3232;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  display: inline-block;
4
+ padding: 10px;
 
 
 
 
 
 
 
5
  }
6
+ .protect-uploads-success {
7
+ border: 1px solid #46b450;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  }
9
 
10
  /* container left and right */
11
+ .protect-uploads .protect-uploads-main-container {
12
  float: left;
13
  width: 66%;
14
  }
15
+ .protect-uploads .protect-uploads-sidebar {
16
  float: left;
17
  width: 31%;
18
  margin-left: 2%;
19
+ }
20
+
21
+ .protect-uploads-disabled {
22
+ opacity: 0.75 !important;
23
  }
admin/assets/js/protect-uploads-admin.js DELETED
@@ -1,3 +0,0 @@
1
- /*
2
- nothing for now
3
- */
 
 
 
admin/class-protect-uploads-admin.php CHANGED
@@ -1,312 +1,316 @@
1
  <?php
2
 
3
- class Alti_ProtectUploads_Admin {
 
4
 
5
  private $plugin_name;
6
  private $version;
7
  private $messages = array();
8
 
9
- /**
10
- * constructor
11
- * @param string $plugin_name
12
- * @param string $version
13
- */
14
- public function __construct( $plugin_name, $version ) {
15
  $this->plugin_name = $plugin_name;
16
  $this->version = $version;
17
  }
18
 
19
- public function get_plugin_name() {
 
20
  return $this->plugin_name;
21
  }
22
 
23
- /**
24
- * Add submenu to left page in admin
25
- */
26
- public function add_submenu_page() {
27
- add_submenu_page( 'upload.php', $this->plugin_name, 'Protect Uploads <span class="dashicons dashicons-shield-alt" style="font-size:15px;"></span>', 'manage_options', $this->plugin_name . '-settings-page', array($this, 'render_settings_page') );
28
  }
29
 
30
- /**
31
- * Render settings page for plugin
32
- */
33
- public function render_settings_page() {
34
- require plugin_dir_path( __FILE__ ) . 'views/' . $this->plugin_name . '-admin-settings-page.php';
35
  }
36
 
37
- /**
38
- * prepare enqueue styles for wordpress hook
39
- */
40
- public function enqueue_styles() {
41
- wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'assets/css/protect-uploads-admin.css', array(), $this->version, 'all' );
42
  }
43
 
44
- /**
45
- * prepare enqueue scripts for wordpress hook
46
- */
47
- public function enqueue_scripts() {
48
- wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'assets/js/protect-uploads-admin.js', array( 'jquery' ), $this->version, false );
49
  }
50
 
51
- /**
52
- * add a settings link to plugin page.
53
- * @param string $links array of links
54
- */
55
- public function add_settings_link( $links ) {
56
- $settings_link = '<a href="upload.php?page=' . $this->plugin_name . '-settings-page">' . __( 'Settings' ) . '</a>';
57
- array_unshift($links, $settings_link);
58
- return $links;
59
- }
60
-
61
- /**
62
- * get uploads dir
63
- * @return string return path
64
- */
65
- public function get_uploads_dir() {
66
  $uploads_dir = wp_upload_dir();
67
  return $uploads_dir['basedir'];
68
  }
69
 
70
- /**
71
- * get uploads folder url
72
- * @return string return full url
73
- */
74
- public function get_uploads_url() {
75
  $uploads_dir = wp_upload_dir();
76
  return $uploads_dir['baseurl'];
77
  }
78
 
79
- public function get_uploads_subdirectories() {
 
80
 
81
- $directories = scandir( self::get_uploads_dir() );
82
- $subs = array( self::get_uploads_dir() );
83
 
84
  foreach ($directories as $directory) {
85
 
86
- if(is_dir(self::get_uploads_dir() . '/' . $directory) && !preg_match('/^\.*$/', $directory)) {
87
  $subs[] = self::get_uploads_dir() . '/' . $directory;
88
- $subDirectories = scandir( self::get_uploads_dir() . '/' . $directory );
89
  foreach ($subDirectories as $subDirectory) {
90
- if(is_dir(self::get_uploads_dir() . '/' . $directory . '/' . $subDirectory) && !preg_match('/^\.*$/', $subDirectory)) $subs[] = self::get_uploads_dir() . '/' . $directory . '/' . $subDirectory;
91
  }
92
  }
93
-
94
  }
95
  return $subs;
96
-
97
  }
98
 
99
- /**
100
- * saving form
101
- */
102
- public function save_form( $form ) {
103
- if( $form['protection'] == 'index_php' ) { $this->remove_htaccess(); $this->create_index(); }
104
- if( $form['protection'] == 'htaccess' ) { $this->remove_index(); $this->create_htaccess(); }
105
- if( $form['protection'] == 'remove' ) { $this->remove_index(); $this->remove_htaccess(); }
 
 
 
 
 
106
  }
107
 
 
 
 
 
 
108
 
109
- /**
110
- *
111
- */
112
- public function create_index() {
113
  // check if index php does not exists
114
- if(!file_exists( self::get_uploads_dir() .'/index.php' )) {
115
 
116
- $indexContent = "<!-- \n Generated by " . $this->get_plugin_name() . " \n http://www.alticreation.com/en/protect-uploads/ \n date:" . date('d/m/Y') . "\n--><?php // Silence is golden";
117
  $i = 0;
118
  foreach (self::get_uploads_subdirectories() as $subDirectory) {
119
 
120
- if( !file_put_contents( $subDirectory.'/'.'index.php', $indexContent ) ) {
121
- $this->messages['file'][] = array(
122
- 'message' => __('Impossible to create or modified the index.php file in '. $subDirectory, $this->get_plugin_name()),
123
- 'type' => 'error',
124
- 'id' => '1'
125
- );
126
- }
127
- else {
128
- update_option( $this->get_plugin_name().'-protection', 'index_php' );
129
  $i++;
130
  }
131
-
132
  }
133
 
134
- if($i == count(self::get_uploads_subdirectories())) {
135
- $this->messages['file'][] = array(
136
- 'message' => __('The index.php file has been created in main folder and subfolders (two levels max).', $this->get_plugin_name()),
137
- 'type' => 'updated'
138
- );
139
  }
140
-
141
  }
142
  // if index php already exists
143
  else {
144
- $this->messages['file'][] = array(
145
- 'message' => 'The index.php file already exists',
146
- 'type' => 'error',
147
- 'id' => '2'
148
- );
149
  }
150
  }
151
 
152
- /**
153
- *
154
- */
155
- public function create_htaccess() {
156
- // prepare htaccess Content
157
  $date = date('Y-m-d H:i.s');
158
  $phpv = phpversion();
159
 
160
  $htaccessContent = "\n# BEGIN " . $this->get_plugin_name() . " Plugin\n";
161
  $htaccessContent .= "\tOptions -Indexes\n";
162
- $htaccessContent .= "# [date={$date}] [php={$phpv}] [plugin_name=" . $this->plugin_name . "] [version={$this->version}]\n";
163
  $htaccessContent .= "# END " . $this->get_plugin_name() . " Plugin\n";
164
 
165
- // check if htaccess does not exists
166
- if(!file_exists( self::get_uploads_dir() .'/.htaccess' )) {
167
- // if htaccess is successfuly written
168
- if( !file_put_contents( self::get_uploads_dir().'/'.'.htaccess', $htaccessContent ) ) {
169
- $this->messages['file'][] = array(
170
- 'message' => __('Impossible to create or modified the htaccess file.', $this->get_plugin_name()),
171
- 'type' => 'error',
172
- 'id' => '1'
173
- );
174
- }
175
- // if htaccess has not been written
176
- else {
177
- update_option( $this->get_plugin_name().'-protection', 'htaccess');
178
- $this->messages['file'][] = array(
179
- 'message' => __('The htaccess file has been created.', $this->get_plugin_name()),
180
- 'type' => 'updated'
181
- );
182
  }
183
-
184
  }
185
- // if htaccess already exists
186
- if(file_exists( self::get_uploads_dir() .'/.htaccess') && preg_match( '/(# BEGIN protect-uploads Plugin)(.*?)(# END protect-uploads Plugin)/is', file_get_contents( self::get_uploads_dir() .'/.htaccess' ) ) == 0) {
187
  // if content added to existing htaccess
188
- if( file_put_contents( self::get_uploads_dir() .'/.htaccess', $htaccessContent, FILE_APPEND | LOCK_EX ) ) {
189
- update_option( $this->get_plugin_name().'-protection', 'htaccess');
190
- $this->messages['file'][] = array(
191
- 'message' => __('Existing htaccess has been updated.', $this->get_plugin_name()),
192
- 'type' => 'updated'
193
- );
194
-
195
- }
196
- else {
197
- $this->messages['file'][] = array(
198
- 'message' => 'The existing htaccess file couldn\'t be updated. Please check file permissions.',
199
- 'type' => 'error',
200
- 'id' => '2'
201
- );
202
  }
203
  }
204
  }
205
 
206
- /**
207
- * remove index file
208
- */
209
- public function remove_index() {
210
-
211
  $i = 0;
212
- foreach( self::get_uploads_subdirectories() as $subDirectory ) {
213
- if(file_exists( $subDirectory .'/index.php' )) {
214
- unlink( $subDirectory .'/index.php' );
215
  $i++;
216
  }
217
-
218
  }
219
- if( $i == count(self::get_uploads_subdirectories()) ) {
220
- $this->messages['file'][] = array(
221
- 'message' => __('The index.php file(s) have(has) been deleted.', $this->get_plugin_name()),
222
- 'type' => 'updated'
223
- );
224
- update_option( $this->get_plugin_name().'-protection', 'remove');
225
  }
226
-
227
-
228
  }
229
 
230
- /**
231
- * remove htaccess
232
- */
233
- public function remove_htaccess() {
234
-
235
- if(file_exists( self::get_uploads_dir() .'/.htaccess' )) {
236
- update_option( $this->get_plugin_name().'-protection', 'remove');
237
 
238
- $htaccessContent = file_get_contents(self::get_uploads_dir() .'/.htaccess');
239
- $htaccessContent = preg_replace( '/(# BEGIN protect-uploads Plugin)(.*?)(# END protect-uploads Plugin)/is', '', $htaccessContent );
240
- file_put_contents( self::get_uploads_dir() .'/.htaccess', $htaccessContent, LOCK_EX );
241
 
242
  // if htaccess is empty, we remove it.
243
- if( strlen(preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", file_get_contents(self::get_uploads_dir() .'/.htaccess'))) == 0) {
244
- unlink( self::get_uploads_dir() .'/.htaccess' );
245
  }
246
 
247
 
248
  //
249
- $this->messages['file'][] = array(
250
- 'message' => __('The htaccess file has been updated.', $this->get_plugin_name()),
251
- 'type' => 'updated'
252
- );
253
  }
 
254
 
 
 
 
 
 
 
 
 
 
 
255
  }
256
 
257
- /**
258
- * check if apache is active
259
- * @return message messages
260
- */
261
- public function get_current_protection() {
262
- // check if header is 200 (ok)
263
- $uploads_headers = @get_headers( self::get_uploads_url() . '/' );
264
- if(!is_array($uploads_headers)) $uploads_headers[0] = '';
265
- if( preg_match('/200/i', $uploads_headers[0] )) {
266
- // because
267
- if( !file_exists( self::get_uploads_dir() .'/index.php' ) ) {
268
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  }
270
- else {
271
  return true;
 
 
 
 
 
272
  }
273
  }
274
- // check if header is 403 (forbidden)
275
- if( preg_match('/403/i', $uploads_headers[0] )) {
276
  return true;
277
  }
 
 
 
 
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  }
280
 
281
- /**
282
- * check if apache is active
283
- * @return message messages
284
- */
285
- public function check_apache() {
286
-
287
- if( !function_exists('apache_get_modules')) {
288
- $this->messages['apache'][] = array(
289
- 'message' => __('The Protect Uploads plugin cannot work without Apache. Yourself or your web host has to activate this module.', $this->plugin_name),
290
- 'type' => 'error',
291
- 'id' => '3'
292
- );
293
  }
294
  }
295
 
296
 
 
 
 
 
 
 
 
 
297
 
298
- /**
299
- * display messages manager
300
- * @return array push array messages in to partial view
301
- */
302
- public function display_messages() {
303
 
304
  foreach ($this->messages as $name => $messages) {
305
  foreach ($messages as $message) {
306
- require plugin_dir_path( dirname( __FILE__ ) ) . 'admin/views/includes/protect-uploads-admin-message.php';
307
  }
308
  }
309
-
310
  }
311
-
312
- }
1
  <?php
2
 
3
+ class Alti_ProtectUploads_Admin
4
+ {
5
 
6
  private $plugin_name;
7
  private $version;
8
  private $messages = array();
9
 
10
+ public function __construct($plugin_name, $version)
11
+ {
 
 
 
 
12
  $this->plugin_name = $plugin_name;
13
  $this->version = $version;
14
  }
15
 
16
+ public function get_plugin_name()
17
+ {
18
  return $this->plugin_name;
19
  }
20
 
21
+ public function add_submenu_page()
22
+ {
23
+ add_submenu_page('upload.php', $this->plugin_name, 'Protect Uploads <span class="dashicons dashicons-shield-alt" style="font-size:15px;"></span>', 'manage_options', $this->plugin_name . '-settings-page', array($this, 'render_settings_page'));
 
 
24
  }
25
 
26
+ public function render_settings_page()
27
+ {
28
+ require plugin_dir_path(__FILE__) . 'views/' . $this->plugin_name . '-admin-settings-page.php';
 
 
29
  }
30
 
31
+ public function enqueue_styles()
32
+ {
33
+ wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'assets/css/protect-uploads-admin.css', array(), $this->version, 'all');
 
 
34
  }
35
 
36
+ public function add_settings_link($links)
37
+ {
38
+ $settings_link = '<a href="upload.php?page=' . $this->plugin_name . '-settings-page">' . __('Settings') . '</a>';
39
+ array_unshift($links, $settings_link);
40
+ return $links;
41
  }
42
 
43
+ public function get_uploads_dir()
44
+ {
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  $uploads_dir = wp_upload_dir();
46
  return $uploads_dir['basedir'];
47
  }
48
 
49
+ public function get_uploads_url()
50
+ {
 
 
 
51
  $uploads_dir = wp_upload_dir();
52
  return $uploads_dir['baseurl'];
53
  }
54
 
55
+ public function get_uploads_subdirectories()
56
+ {
57
 
58
+ $directories = scandir(self::get_uploads_dir());
59
+ $subs = array(self::get_uploads_dir());
60
 
61
  foreach ($directories as $directory) {
62
 
63
+ if (is_dir(self::get_uploads_dir() . '/' . $directory) && !preg_match('/^\.*$/', $directory)) {
64
  $subs[] = self::get_uploads_dir() . '/' . $directory;
65
+ $subDirectories = scandir(self::get_uploads_dir() . '/' . $directory);
66
  foreach ($subDirectories as $subDirectory) {
67
+ if (is_dir(self::get_uploads_dir() . '/' . $directory . '/' . $subDirectory) && !preg_match('/^\.*$/', $subDirectory)) $subs[] = self::get_uploads_dir() . '/' . $directory . '/' . $subDirectory;
68
  }
69
  }
 
70
  }
71
  return $subs;
 
72
  }
73
 
74
+ public function save_form($form)
75
+ {
76
+ if ($form['protection'] == 'index_php') {
77
+ $this->create_index();
78
+ }
79
+ if ($form['protection'] == 'htaccess') {
80
+ $this->create_htaccess();
81
+ }
82
+ if ($form['protection'] == 'remove') {
83
+ $this->remove_index();
84
+ $this->remove_htaccess();
85
+ }
86
  }
87
 
88
+ // used to check if the current htaccess has been generated by the plugin
89
+ public function get_htaccess_identifier()
90
+ {
91
+ return "[plugin_name=" . $this->plugin_name . "]";
92
+ }
93
 
94
+ public function create_index()
95
+ {
 
 
96
  // check if index php does not exists
97
+ if (self::check_protective_file('index.php') === false) {
98
 
99
+ $indexContent = "<?php // Silence is golden \n // " . self::get_htaccess_identifier() . " \n // https://www.alticreation.com/en/protect-uploads/ \n // date:" . date('d/m/Y') . "\n // .";
100
  $i = 0;
101
  foreach (self::get_uploads_subdirectories() as $subDirectory) {
102
 
103
+ if (!file_put_contents($subDirectory . '/' . 'index.php', $indexContent)) {
104
+ self::register_message('Impossible to create or modified the index.php file in ' . $subDirectory, 'error');
105
+ } else {
 
 
 
 
 
 
106
  $i++;
107
  }
 
108
  }
109
 
110
+ if ($i == count(self::get_uploads_subdirectories())) {
111
+ self::register_message('The index.php file has been created in main folder and subfolders (two levels max).');
 
 
 
112
  }
 
113
  }
114
  // if index php already exists
115
  else {
116
+ self::register_message('The index.php file already exists', 'error');
 
 
 
 
117
  }
118
  }
119
 
120
+ public function create_htaccess()
121
+ {
122
+ // Content for htaccess file
 
 
123
  $date = date('Y-m-d H:i.s');
124
  $phpv = phpversion();
125
 
126
  $htaccessContent = "\n# BEGIN " . $this->get_plugin_name() . " Plugin\n";
127
  $htaccessContent .= "\tOptions -Indexes\n";
128
+ $htaccessContent .= "# [date={$date}] [php={$phpv}] " . self::get_htaccess_identifier() . " [version={$this->version}]\n";
129
  $htaccessContent .= "# END " . $this->get_plugin_name() . " Plugin\n";
130
 
131
+ // if htaccess does NOT exist yet
132
+ if (self::check_protective_file('.htaccess') === false) {
133
+ // try to create and save the new htaccess file
134
+ if (!file_put_contents(self::get_uploads_dir() . '/' . '.htaccess', $htaccessContent)) {
135
+ self::register_message('Impossible to create or modified the htaccess file.', 'error');
136
+ } else {
137
+ self::register_message('The htaccess file has been created.');
 
 
 
 
 
 
 
 
 
 
138
  }
 
139
  }
140
+ else {
 
141
  // if content added to existing htaccess
142
+ if (file_put_contents(self::get_uploads_dir() . '/.htaccess', $htaccessContent, FILE_APPEND | LOCK_EX)) {
143
+ self::register_message('The htaccess file has been updated.');
144
+ } else {
145
+ self::register_message('The existing htaccess file couldn\'t be updated. Please check file permissions.', 'error');
 
 
 
 
 
 
 
 
 
 
146
  }
147
  }
148
  }
149
 
150
+ public function remove_index()
151
+ {
 
 
 
152
  $i = 0;
153
+ foreach (self::get_uploads_subdirectories() as $subDirectory) {
154
+ if (file_exists($subDirectory . '/index.php')) {
155
+ unlink($subDirectory . '/index.php');
156
  $i++;
157
  }
 
158
  }
159
+ if ($i == count(self::get_uploads_subdirectories())) {
160
+ self::register_message('The index.php file(s) have(has) been deleted.');
 
 
 
 
161
  }
 
 
162
  }
163
 
164
+ public function remove_htaccess()
165
+ {
166
+ if (file_exists(self::get_uploads_dir() . '/.htaccess')) {
 
 
 
 
167
 
168
+ $htaccessContent = file_get_contents(self::get_uploads_dir() . '/.htaccess');
169
+ $htaccessContent = preg_replace('/(# BEGIN protect-uploads Plugin)(.*?)(# END protect-uploads Plugin)/is', '', $htaccessContent);
170
+ file_put_contents(self::get_uploads_dir() . '/.htaccess', $htaccessContent, LOCK_EX);
171
 
172
  // if htaccess is empty, we remove it.
173
+ if (strlen(preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", file_get_contents(self::get_uploads_dir() . '/.htaccess'))) == 0) {
174
+ unlink(self::get_uploads_dir() . '/.htaccess');
175
  }
176
 
177
 
178
  //
179
+ self::register_message('The htaccess file has been updated.');
 
 
 
180
  }
181
+ }
182
 
183
+ public function get_protective_files_array()
184
+ {
185
+ $uploads_files = ['index.php', 'index.html', '.htaccess'];
186
+ $response = [];
187
+ foreach ($uploads_files as $file) {
188
+ if (file_exists(self::get_uploads_dir() . '/' . $file)) {
189
+ $response[] = $file;
190
+ }
191
+ }
192
+ return $response;
193
  }
194
 
195
+ public function check_protective_file($file)
196
+ {
197
+ if (in_array($file, self::get_protective_files_array())) {
198
+ return true;
199
+ } else {
200
+ return false;
201
+ }
202
+ }
203
+
204
+ public function get_uploads_root_response_code()
205
+ {
206
+ $uploads_headers = get_headers(self::get_uploads_url() . '/');
207
+ $response = null;
208
+ if (is_array($uploads_headers)) {
209
+ if (preg_match('/200/', $uploads_headers[0])) $response = 200;
210
+ if (preg_match('/403/', $uploads_headers[0])) $response = 403;
211
+ }
212
+ return $response;
213
+ }
214
+
215
+ public function get_htaccess_content()
216
+ {
217
+ return file_get_contents(self::get_uploads_dir() . '/.htaccess');
218
+ }
219
+
220
+ public function check_htaccess_is_self_generated()
221
+ {
222
+ if (self::check_protective_file('.htaccess') && preg_match('/' . self::get_htaccess_identifier() . '/', self::get_htaccess_content())) {
223
+ return true;
224
+ } else {
225
+ return false;
226
+ }
227
+ }
228
+
229
+ // heart? <3
230
+ public function check_uploads_is_protected()
231
+ {
232
+ foreach (self::get_protective_files_array() as $file) {
233
+ if ($file === 'index.html') {
234
+ return true;
235
+ break;
236
  }
237
+ if ($file === 'index.php') {
238
  return true;
239
+ break;
240
+ }
241
+ if ($file === '.htaccess' && self::get_uploads_root_response_code() === 200) {
242
+ return false;
243
+ break;
244
  }
245
  }
246
+ if (self::get_uploads_root_response_code() === 403) {
 
247
  return true;
248
  }
249
+ else {
250
+ return false;
251
+ }
252
+ }
253
 
254
+ public function check_protective_file_removable() {
255
+ if( self::check_protective_file('index.html') ) {
256
+ return false;
257
+ }
258
+ elseif( self::check_protective_file('.htaccess') === false && self::get_uploads_root_response_code() === 403 ) {
259
+ return false;
260
+ }
261
+ else {
262
+ return true;
263
+ }
264
+ }
265
+
266
+ public function get_uploads_protection_message_array()
267
+ {
268
+ $response = [];
269
+ foreach (self::get_protective_files_array() as $file) {
270
+ if ($file === '.htaccess' && self::get_uploads_root_response_code() === 403) {
271
+ $response[] = '<span class="dashicons dashicons-yes"></span> ' . __('.htaccess file is present and access to uploads directory returns 403 code.', $this->plugin_name);
272
+ }
273
+ if ($file === 'index.php') {
274
+ $response[] = '<span class="dashicons dashicons-yes"></span> ' . __('index.php file is present.', $this->plugin_name);
275
+ }
276
+ if ($file === 'index.html') {
277
+ $response[] = '<span class="dashicons dashicons-yes"></span> ' . __('index.html file is present.', $this->plugin_name);
278
+ }
279
+ }
280
+ if (self::check_protective_file('.htaccess') === true && self::get_uploads_root_response_code() === 200) {
281
+ $response[] = '<span class="dashicons dashicons-search"></span> ' . __('.htaccess file is present but not protecting uploads directory.', $this->plugin_name);
282
+ }
283
+ if (self::check_protective_file('.htaccess') === false && self::get_uploads_root_response_code() === 403) {
284
+ $response[] = '<span class="dashicons dashicons-yes"></span> ' . __('Access to uploads directory is protected (403) with a global .htaccess or another global declaration.', $this->plugin_name);
285
+ }
286
+ return $response;
287
  }
288
 
289
+ public function check_apache()
290
+ {
291
+
292
+ if (!function_exists('apache_get_modules')) {
293
+ self::register_message('The Protect Uploads plugin cannot work without Apache. Yourself or your web host has to activate this module.');
 
 
 
 
 
 
 
294
  }
295
  }
296
 
297
 
298
+ public function register_message($message, $type = 'updated', $id = 0)
299
+ {
300
+ $this->messages['apache'][] = array(
301
+ 'message' => __($message, $this->plugin_name),
302
+ 'type' => $type,
303
+ 'id' => $id
304
+ );
305
+ }
306
 
307
+ public function display_messages()
308
+ {
 
 
 
309
 
310
  foreach ($this->messages as $name => $messages) {
311
  foreach ($messages as $message) {
312
+ return '<div id="message" class="' . $message['type'] . '"><p>' . $message['message'] . '</p></div>';
313
  }
314
  }
 
315
  }
316
+ }
 
admin/views/includes/protect-uploads-admin-message.php DELETED
@@ -1,11 +0,0 @@
1
- <div id="message" class="<?php echo $message['type']; ?>">
2
- <p>
3
- <?php echo $message['message']; ?>
4
- <?php if( !empty($message['id']) ) {
5
- ?>
6
- <div>
7
- <i>[<?php _e('Error code', $this->plugin_name); ?> : <?php echo sprintf('%03d', $message['id']); ?></i>] <a target="_blank" href="http://alticreation.com/en/protect-uploads#error<?php echo sprintf('%03d', $message['id']); ?>"><?php _e('Go to Protect Uploads documentation', $this->plugin_name); ?></a>
8
- </div>
9
- <?php } ?>
10
- </p>
11
- </div>
 
 
 
 
 
 
 
 
 
 
 
admin/views/includes/protect-uploads-admin-sidebar.php CHANGED
@@ -24,6 +24,7 @@ $paypal_svg = '
24
  margin: 5px 0 5px -5px;
25
  clear: both;
26
  overflow: hidden;
 
27
  }
28
 
29
  .alti_promote_plugin a {
@@ -102,8 +103,8 @@ $paypal_svg = '
102
  <div class="alti-watermark-sidebar">
103
  <div class="alti_promote_widget">
104
  <div class="alti_promote_title">Like this plugin?</div>
105
- <p><span class="dashicons dashicons-arrow-right-alt2"></span><a target="_blank" class="alti_promote_btn" href="https://wordpress.org/support/view/plugin-reviews/<?php echo $get_from; ?>?rate=5#postform"><strong>Rate it</strong></a> to show your support!</p>
106
- <p><span class="dashicons dashicons-arrow-right-alt2"></span><a target="_blank" class="alti_promote_btn" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9S74KTRCZCLRE&item_name=<?php echo $get_from; ?>&no_note=0&no_shipping=1&currency_code=USD"><strong>Donate</strong> <span class="alti_promote_paypal_svg"><?php echo $paypal_svg; ?></span></a> to encourage me updating this plugin!</p>
107
  </div>
108
  <div class="alti_promote_widget">
109
  <div class="alti_promote_title">Discover more useful plugins</div>
@@ -127,7 +128,7 @@ $paypal_svg = '
127
  <?php foreach ($related_plugins as $related_plugin): ?>
128
  <?php if( $related_plugin[0] != $get_from ) { ?>
129
  <div class="alti_promote_plugin">
130
- <a href="plugin-install.php?tab=search&type=term&s=alticreation+<?php echo urlencode($related_plugin[0]); ?>" title="<?php echo $related_plugin[1]; ?>"><img src="https://plugins.svn.wordpress.org/<?php echo $related_plugin[0]; ?>/assets/icon-128x128.png" alt="<?php echo $related_plugin[1]; ?>">
131
  <div class="alti_promote_copy">
132
  <strong><?php echo $related_plugin[1]; ?></strong>
133
  <?php echo $related_plugin[2]; ?>
@@ -139,6 +140,6 @@ $paypal_svg = '
139
  </div>
140
  <div class="alti_promote_widget">
141
  <div class="alti_promote_title">Developed by</div>
142
- <a href="http://www.alticreation.com?utm_source=wp_plugin&utm_medium=logo_sidebar&utm_campaign=<?php echo $get_from; ?>"><img src="http://alticreation.com/logos/alticreation_color_01.png" alt="alticreation"></a>
143
  </div>
144
  </div>
24
  margin: 5px 0 5px -5px;
25
  clear: both;
26
  overflow: hidden;
27
+ font-size: 14px;
28
  }
29
 
30
  .alti_promote_plugin a {
103
  <div class="alti-watermark-sidebar">
104
  <div class="alti_promote_widget">
105
  <div class="alti_promote_title">Like this plugin?</div>
106
+ <p><a target="_blank" class="alti_promote_btn" href="https://wordpress.org/support/view/plugin-reviews/<?php echo $get_from; ?>?rate=5#postform"><strong>Rate it</strong></a> to show your support!</p>
107
+ <p><a target="_blank" class="alti_promote_btn" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9S74KTRCZCLRE&item_name=<?php echo $get_from; ?>&no_note=0&no_shipping=1&currency_code=USD"><strong>Donate</strong> <span class="alti_promote_paypal_svg"><?php echo $paypal_svg; ?></span></a> to encourage me updating this plugin!</p>
108
  </div>
109
  <div class="alti_promote_widget">
110
  <div class="alti_promote_title">Discover more useful plugins</div>
128
  <?php foreach ($related_plugins as $related_plugin): ?>
129
  <?php if( $related_plugin[0] != $get_from ) { ?>
130
  <div class="alti_promote_plugin">
131
+ <a href="plugin-install.php?tab=search&type=term&s=<?php echo urlencode($related_plugin[0]); ?>" title="<?php echo $related_plugin[1]; ?>"><img src="https://plugins.svn.wordpress.org/<?php echo $related_plugin[0]; ?>/assets/icon-128x128.png" alt="<?php echo $related_plugin[1]; ?>">
132
  <div class="alti_promote_copy">
133
  <strong><?php echo $related_plugin[1]; ?></strong>
134
  <?php echo $related_plugin[2]; ?>
140
  </div>
141
  <div class="alti_promote_widget">
142
  <div class="alti_promote_title">Developed by</div>
143
+ <a href="https://www.alticreation.com?utm_source=wp_plugin&utm_medium=logo_sidebar&utm_campaign=<?php echo $get_from; ?>"><img src="http://alticreation.com/logos/alticreation_color_01.png" alt="alticreation"></a>
144
  </div>
145
  </div>
admin/views/protect-uploads-admin-settings-page.php CHANGED
@@ -1,101 +1,126 @@
1
- <div id="wrap" class="<?php echo $this->plugin_name ?>">
2
  <?php
3
- $plugin = new Alti_ProtectUploads_Admin($this->plugin_name, $this->version);
4
- if( isset($_POST['submit']) && check_admin_referer( 'submit_form', 'protect-uploads'. '_nonce' ) ) {
5
- $plugin->save_form( $_POST );
6
- }
7
- $plugin->display_messages();
8
  ?>
9
- <h2>Protect Uploads <span><?php _e('by', $this->plugin_name); ?> <a href="https://www.alticreation.com/en">alticreation.com</a></span></h2>
10
- <p class="description"><?php _e('Prevent users to browse your uploads directory. You\'ll protect your uploads directory to be accessed and content stolen too easily in one batch.', $this->plugin_name); ?></p>
11
  <div class="protect-uploads-main-container">
12
- <form method="POST" enctype="multipart/form-data">
 
13
 
14
- <?php wp_nonce_field( 'submit_form', 'protect-uploads'. '_nonce' ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- <table class="form-table">
17
- <tbody>
18
- <tr>
19
- <th scope="row">
20
- <label for=""><span class="dashicons dashicons-dashboard"></span> <?php _e('Status', $this->plugin_name); ?></label>
21
- </th>
22
- <td>
23
- <fieldset>
24
- <?php if( $this->get_current_protection() === true ) { ?>
25
- <p class="valid"><span class="dashicons dashicons-lock"></span> <?php _e('Uploads directory is protected.', $this->plugin_name); ?></p>
26
- <?php if( get_option( $this->plugin_name . '-protection') == 'remove' ) { ?>
27
- <p class="valid note"><?php _e('Your uploads directory is <strong>already protected</strong> by an htaccess file or an Apache setting set for the whole website. You don\'t need extra protection.<br>The «remove option» behind will have no effect on the current protection.', $this->plugin_name); ?></p>
28
- <?php } ?>
29
- <?php } else { ?>
30
- <p class="error"><span class="dashicons dashicons-shield"></span> <?php _e('Uploads directory is not protected!', $this->plugin_name); ?></p>
31
- <?php } ?>
32
- </fieldset>
33
- </td>
34
- </tr>
35
- <tr>
36
- <th scope="row">
37
- <label for="size"><span class="dashicons dashicons-shield-alt"></span> <?php _e('Protection', $this->plugin_name); ?></label>
38
- </th>
39
- <td>
40
- <fieldset>
41
- <legend class="screen-reader-text">
42
- <span><?php _e('Protection', $this->plugin_name); ?></span>
43
- </legend>
44
- <!-- -->
45
- <label for="protection_1">
46
- <input type="radio" value="index_php" name="protection" id="protection_1" <?php if( get_option( $this->plugin_name . '-protection') == 'index_php' ) { ?>checked<?php } ?>>
47
- <strong><?php _e('add index file', $this->plugin_name); ?></strong>
48
- <p class="description"><?php _e('This will create an index.php file on the root of your uploads directory. This simple trick will hide the content of your whole uploads directory.', $this->plugin_name); ?></p>
49
- </label><br>
50
- <!-- -->
51
- <label for="protection_2">
52
- <input type="radio" value="htaccess" name="protection" id="protection_2" <?php if( get_option( $this->plugin_name . '-protection') == 'htaccess' ) { ?>checked<?php } ?>>
53
- <strong><?php _e('prevent directory listing with htaccess', $this->plugin_name); ?></strong>
54
- <p class="description"><?php _e('Through the htaccess file, it will prevent people to browse your uploads directory and return a 403 code (Forbidden Access).', $this->plugin_name); ?></p>
55
- </label><br>
56
- <!-- -->
57
- <label for="protection_3">
58
- <input type="radio" value="remove" name="protection" id="protection_3" <?php if( get_option( $this->plugin_name . '-protection') == 'remove' || get_option( $this->plugin_name . '-protection') == '' ) { ?>checked<?php } ?>>
59
- <strong><?php _e('remove protection or disabled protection', $this->plugin_name); ?></strong>
60
- <p class="description"><?php _e('Your uploads directory is not protected.', $this->plugin_name); ?></p>
61
- </label><br>
62
- </fieldset>
63
 
64
- </td>
65
- </tr>
66
- <tr>
67
- <th scope="row">
68
- <label for=""><span class="dashicons dashicons-visibility"></span> <?php _e('Check', $this->plugin_name); ?></label>
69
- </th>
70
- <td>
71
- <p><?php _e('Visit your', $this->plugin_name); ?> <a href="<?php echo $this->get_uploads_url(); ?>" target="_blank"><?php _e('uploads directory', $this->plugin_name); ?></a> <?php _e('to check the current protection', $this->plugin_name); ?>.</p>
72
- </td>
73
- </tr>
74
- <tr>
75
- <th scope="row">
76
- <label for=""><span class="dashicons dashicons-welcome-learn-more"></span> <?php _e('Support', $this->plugin_name); ?></label>
77
- </th>
78
- <td>
79
- <p><?php _e('Protect Uploads Plugin <a href="http://www.alticreation.com/en/protect-uploads/" target="_blank">support page</a>.', $this->plugin_name); ?></p>
80
- <p><?php _e('This plugin is compatible with the <span class="dashicons dashicons-awards"></span> <a href="http://www.alticreation.com/en/alti-watermark/" target="_blank">Watermark Plugin</a>.', $this->plugin_name); ?></p>
81
- <p class="small"><?php _e('To do so, you have to: 1. Install the Watermark Plugin 2. Then choose your settings in this page and Update.', $this->plugin_name); ?></p>
82
- </td>
83
- </tr>
84
- <tr>
85
- <th scope="row">
86
- </th>
87
- <td>
88
- <input type="submit" id="submit" value="<?php _e('Update', $this->plugin_name); ?>" name="submit" class="button button-primary">
89
- </td>
90
- </tr>
91
- </tbody>
92
- </table>
93
-
94
- </form>
95
 
96
  </div>
97
 
98
- <?php require_once dirname( __FILE__ ) . '/includes/protect-uploads-admin-sidebar.php'; ?>
99
-
100
- </div>
101
 
 
1
+ <div class="wrap <?php echo $this->plugin_name ?>">
2
  <?php
3
+ $plugin = new Alti_ProtectUploads_Admin($this->plugin_name, $this->version);
4
+ if (isset($_POST['submit']) && isset($_POST['protection']) && check_admin_referer('submit_form', 'protect-uploads' . '_nonce')) {
5
+ $plugin->save_form($_POST);
6
+ }
7
+ echo $plugin->display_messages();
8
  ?>
9
+ <h1>Protect Uploads</h1>
 
10
  <div class="protect-uploads-main-container">
11
+ <form method="POST" enctype="multipart/form-data">
12
+ <?php wp_nonce_field('submit_form', 'protect-uploads' . '_nonce'); ?>
13
 
14
+ <table class="form-table">
15
+ <tbody>
16
+ <tr>
17
+ <th scope="row">
18
+ <label for=""><?php _e('Status', $this->plugin_name); ?></label>
19
+ </th>
20
+ <td>
21
+ <fieldset>
22
+ <p>
23
+ <strong>
24
+ <?php if ($this->check_uploads_is_protected() === true) { ?>
25
+ <span class="dashicons dashicons-yes-alt" style="color:#46b450"></span> <?php _e('Uploads directory is protected.', $this->plugin_name); ?>
26
+ <?php } else { ?>
27
+ <span style="color:#dc3232" class="dashicons dashicons-dismiss"></span> <?php _e('Uploads directory is not protected!', $this->plugin_name); ?>
28
+ <?php } ?>
29
+ </strong>
30
+ </p>
31
+ <p>
32
+ <?php
33
+ $file_messages = $this->get_uploads_protection_message_array();
34
+ foreach ($file_messages as $file_message) {
35
+ ?>
36
+ <?php echo $file_message; ?> <br />
37
+ <?php
38
+ } ?>
39
+ </p>
40
+ </fieldset>
41
+ </td>
42
+ </tr>
43
+ <tr>
44
+ <th scope="row">
45
+ <label for="size"><?php _e('Protection', $this->plugin_name); ?></label>
46
+ </th>
47
+ <td>
48
+ <fieldset>
49
+ <legend class="screen-reader-text">
50
+ <span><?php _e('Protection', $this->plugin_name); ?></span>
51
+ </legend>
52
+ <?php if ($this->check_uploads_is_protected() === false) { ?>
53
+ <!-- -->
54
+ <label for="protection_1">
55
+ <input type="radio" value="index_php" name="protection" id="protection_1">
56
+ <strong><?php _e('Protect with index.php files', $this->plugin_name); ?></strong>
57
+ <p class="description"><?php _e('Create an index.php file on the root of your uploads directory and subfolders (two levels max).', $this->plugin_name); ?></p>
58
+ </label><br />
59
+ <!-- -->
60
+ <label for="protection_2">
61
+ <input type="radio" value="htaccess" name="protection" id="protection_2">
62
+ <strong><?php _e('Protect with .htaccess file', $this->plugin_name); ?></strong>
63
+ <p class="description"><?php _e('Create .htaccess file at root level of uploads directory and returns 403 code (Forbidden Access).', $this->plugin_name); ?></p>
64
+ </label><br />
65
+ <?php } ?>
66
+ <!-- -->
67
+ <?php if ( $this->check_protective_file_removable() && $this->check_uploads_is_protected() ) { ?>
68
+ <label for="protection_3">
69
+ <input type="radio" value="remove" name="protection" id="protection_3">
70
+ <strong><?php _e('Remove protection files', $this->plugin_name); ?></strong>
71
+ <p>
72
+ <?php if ($this->check_protective_file('index.php') === true) {
73
+ echo '<span class="dashicons dashicons-flag"></span> index.php ';
74
+ _e('will be removed', $this->plugin_name);
75
+ } ?>
76
+ <?php if ($this->check_protective_file('.htaccess') === true) {
77
+ echo '<span class="dashicons dashicons-flag"></span> .htaccess ';
78
+ _e('will be removed', $this->plugin_name);
79
+ } ?>
80
+ </p>
81
+ </label><br />
82
+ <?php } ?>
83
+ <?php if ($this->check_protective_file('index.html') === true) { ?>
84
+ <p class="description">
85
+ <span class="dashicons dashicons-search"></span> <?php _e('A index.html file is already here and has not been created by this plugin. It will not be removed. If you want to use this plugin, you first have to remove manually the index.html file.', $this->plugin_name) ?>
86
+ </p>
87
+ <?php } ?>
88
+ </fieldset>
89
 
90
+ </td>
91
+ </tr>
92
+ <tr>
93
+ <th scope="row">
94
+ <label for=""><?php _e('Check', $this->plugin_name); ?></label>
95
+ </th>
96
+ <td>
97
+ <p><?php _e('Visit your', $this->plugin_name); ?> <a href="<?php echo $this->get_uploads_url(); ?>" target="_blank"><strong><?php _e('uploads directory', $this->plugin_name); ?></strong><span style="text-decoration:none;" class="dashicons dashicons-external"></span></a> <?php _e('to check the current protection', $this->plugin_name); ?>.</p>
98
+ </td>
99
+ </tr>
100
+ <tr>
101
+ <th scope="row">
102
+ <label for=""><?php _e('Support', $this->plugin_name); ?></label>
103
+ </th>
104
+ <td>
105
+ <p><?php _e('Protect Uploads Plugin <a href="https://www.alticreation.com/en/protect-uploads/" target="_blank">support page</a>.', $this->plugin_name); ?></p>
106
+ <p><?php _e('This plugin is compatible with the <span class="dashicons dashicons-awards"></span> <a href="https://www.alticreation.com/en/alti-watermark/" target="_blank">Watermark Plugin</a>.', $this->plugin_name); ?></p>
107
+ <p class="description"><?php _e('To do so, you have to: 1. Install the Watermark Plugin 2. Then choose your settings in this page and Update.', $this->plugin_name); ?></p>
108
+ </td>
109
+ </tr>
110
+ <tr>
111
+ <th scope="row">
112
+ </th>
113
+ <td>
114
+ <input type="submit" id="submit" value="<?php _e('Update', $this->plugin_name); ?>" name="submit" class="button button-primary">
115
+ </td>
116
+ </tr>
117
+ </tbody>
118
+ </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
+ </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
  </div>
123
 
124
+ <?php require_once dirname(__FILE__) . '/includes/protect-uploads-admin-sidebar.php'; ?>
 
 
125
 
126
+ </div>
includes/class-protect-uploads-activator.php CHANGED
@@ -1,21 +1,8 @@
1
- <?php
2
- /**
3
- * fired on activation
4
- */
5
- class Alti_ProtectUploads_Activator extends Alti_ProtectUploads {
6
 
7
- /**
8
- * set option for plugin
9
- */
10
- public function run() {
11
-
12
- if( !get_option( $this->get_plugin_name().'-protection' ) ) {
13
- add_option( $this->get_plugin_name().'-protection', 'remove', '', 'yes' );
14
- }
15
- else {
16
- update_option( $this->get_plugin_name().'-protection', 'remove' );
17
- }
18
-
19
  }
20
-
21
- }
1
+ <?php
2
+ class Alti_ProtectUploads_Activator extends Alti_ProtectUploads
3
+ {
 
 
4
 
5
+ public function run()
6
+ {
 
 
 
 
 
 
 
 
 
 
7
  }
8
+ }
 
includes/class-protect-uploads-deactivator.php CHANGED
@@ -1,13 +1,11 @@
1
  <?php
2
- /**
3
- * triggered on deactivate
4
- */
5
- class Alti_ProtectUploads_Deactivator extends Alti_ProtectUploads_Admin {
6
 
7
  public function run() {
8
-
9
- $this->remove_index();
10
- $this->remove_htaccess();
 
11
 
12
  }
13
 
1
  <?php
2
+ class Alti_ProtectUploads_Deactivator extends Alti_ProtectUploads {
 
 
 
3
 
4
  public function run() {
5
+ $plugin = new Alti_ProtectUploads_Admin($this->plugin_name, $this->version);
6
+ $plugin->remove_index();
7
+ $plugin->remove_htaccess();
8
+ delete_option( $this->get_plugin_name().'-protection' );
9
 
10
  }
11
 
includes/class-protect-uploads-i18n.php CHANGED
@@ -1,8 +1,4 @@
1
  <?php
2
-
3
- /**
4
- * Define the internationalization functionality
5
- */
6
  class Alti_ProtectUploads_i18n {
7
 
8
  /**
1
  <?php
 
 
 
 
2
  class Alti_ProtectUploads_i18n {
3
 
4
  /**
includes/class-protect-uploads.php CHANGED
@@ -1,92 +1,73 @@
1
- <?php
2
 
3
- class Alti_ProtectUploads {
 
4
 
5
  protected $version;
6
  protected $plugin_name;
7
  protected $loader;
8
 
9
- /**
10
- * constructor
11
- */
12
- public function __construct() {
13
-
14
- $this->version = '0.1';
15
  $this->plugin_name = 'protect-uploads';
16
-
17
  $this->load_dependencies();
18
  $this->set_locale();
19
  $this->define_admin_hooks();
20
-
21
  }
22
 
23
- /**
24
- * load seperate files needed to trigger actions or filters, translation and admin class only since public class has to be autonomous.
25
- */
26
- private function load_dependencies() {
27
 
28
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-protect-uploads-loader.php';
29
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-protect-uploads-i18n.php';
30
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-protect-uploads-admin.php';
31
-
32
- $this->loader = new Alti_ProtectUploads_Loader();
33
 
 
34
  }
35
 
36
  /**
37
  * set locale for translation ends.
38
  */
39
- private function set_locale() {
 
40
 
41
  $plugin_i18n = new Alti_ProtectUploads_i18n();
42
- $plugin_i18n->set_domain( $this->get_plugin_name() );
43
-
44
- $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
45
 
 
46
  }
47
 
48
  /**
49
  * action and filter for admin side
50
  */
51
- private function define_admin_hooks() {
 
52
 
53
- $plugin_admin = new Alti_ProtectUploads_Admin( $this->get_plugin_name(), $this->get_version() );
54
-
55
- $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_submenu_page' );
56
- $this->loader->add_filter( 'plugin_action_links_' . $this->get_plugin_name() . '/' . $this->get_plugin_name() . '.php', $plugin_admin, 'add_settings_link' );
57
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
58
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
59
 
 
 
 
60
  }
61
 
62
- /**
63
- * run the whole logic of the plugin
64
- */
65
- public function run() {
66
  $this->loader->run();
67
  }
68
 
69
- /**
70
- * get plugin name from constructor
71
- * @return string plugin name
72
- */
73
- public function get_plugin_name() {
74
  return $this->plugin_name;
75
  }
76
 
77
- /**
78
- * get loader
79
- */
80
- public function get_loader() {
81
  return $this->loader;
82
  }
83
 
84
- /**
85
- * get version of plugin from constructor
86
- * @return string current version
87
- */
88
- public function get_version() {
89
  return $this->version;
90
  }
91
-
92
- }
1
+ <?php
2
 
3
+ class Alti_ProtectUploads
4
+ {
5
 
6
  protected $version;
7
  protected $plugin_name;
8
  protected $loader;
9
 
10
+ public function __construct()
11
+ {
12
+ $this->version = '0.3';
 
 
 
13
  $this->plugin_name = 'protect-uploads';
 
14
  $this->load_dependencies();
15
  $this->set_locale();
16
  $this->define_admin_hooks();
 
17
  }
18
 
19
+ private function load_dependencies()
20
+ {
 
 
21
 
22
+ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-protect-uploads-loader.php';
23
+ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-protect-uploads-i18n.php';
24
+ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-protect-uploads-admin.php';
 
 
25
 
26
+ $this->loader = new Alti_ProtectUploads_Loader();
27
  }
28
 
29
  /**
30
  * set locale for translation ends.
31
  */
32
+ private function set_locale()
33
+ {
34
 
35
  $plugin_i18n = new Alti_ProtectUploads_i18n();
36
+ $plugin_i18n->set_domain($this->get_plugin_name());
 
 
37
 
38
+ $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
39
  }
40
 
41
  /**
42
  * action and filter for admin side
43
  */
44
+ private function define_admin_hooks()
45
+ {
46
 
47
+ $plugin_admin = new Alti_ProtectUploads_Admin($this->get_plugin_name(), $this->get_version());
 
 
 
 
 
48
 
49
+ $this->loader->add_action('admin_menu', $plugin_admin, 'add_submenu_page');
50
+ $this->loader->add_filter('plugin_action_links_' . $this->get_plugin_name() . '/' . $this->get_plugin_name() . '.php', $plugin_admin, 'add_settings_link');
51
+ $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
52
  }
53
 
54
+ public function run()
55
+ {
 
 
56
  $this->loader->run();
57
  }
58
 
59
+ public function get_plugin_name()
60
+ {
 
 
 
61
  return $this->plugin_name;
62
  }
63
 
64
+ public function get_loader()
65
+ {
 
 
66
  return $this->loader;
67
  }
68
 
69
+ public function get_version()
70
+ {
 
 
 
71
  return $this->version;
72
  }
73
+ }
 
languages/protect-uploads-es_ES.po CHANGED
@@ -165,16 +165,16 @@ msgstr "Ayuda"
165
 
166
  #: admin/views/protect-uploads-admin-settings-page.php:76
167
  msgid ""
168
- "Protect Uploads Plugin <a href=\"http://www.alticreation.com/en/protect-"
169
  "uploads/\" target=\"_blank\">support page</a>."
170
  msgstr ""
171
- "Ver la <a href=\"http://www.alticreation.com/en/protect-uploads/\" target="
172
  "\"_blank\">pagina de ayuda</a> del plugin."
173
 
174
  #: admin/views/protect-uploads-admin-settings-page.php:77
175
  msgid ""
176
  "This plugin is compatible with the <span class=\"dashicons dashicons-awards"
177
- "\"></span> <a href=\"http://www.alticreation.com/en/alti-watermark/\" target="
178
  "\"_blank\">Watermark Plugin</a>."
179
  msgstr ""
180
  "Este plugin es compatible con el <span class=\"dashicons dashicons-premios "
165
 
166
  #: admin/views/protect-uploads-admin-settings-page.php:76
167
  msgid ""
168
+ "Protect Uploads Plugin <a href=\"https://www.alticreation.com/en/protect-"
169
  "uploads/\" target=\"_blank\">support page</a>."
170
  msgstr ""
171
+ "Ver la <a href=\"https://www.alticreation.com/en/protect-uploads/\" target="
172
  "\"_blank\">pagina de ayuda</a> del plugin."
173
 
174
  #: admin/views/protect-uploads-admin-settings-page.php:77
175
  msgid ""
176
  "This plugin is compatible with the <span class=\"dashicons dashicons-awards"
177
+ "\"></span> <a href=\"https://www.alticreation.com/en/alti-watermark/\" target="
178
  "\"_blank\">Watermark Plugin</a>."
179
  msgstr ""
180
  "Este plugin es compatible con el <span class=\"dashicons dashicons-premios "
languages/protect-uploads-fr_FR.po CHANGED
@@ -165,20 +165,20 @@ msgstr "Support"
165
 
166
  #: admin/views/protect-uploads-admin-settings-page.php:76
167
  msgid ""
168
- "Protect Uploads Plugin <a href=\"http://www.alticreation.com/en/protect-"
169
  "uploads/\" target=\"_blank\">support page</a>."
170
  msgstr ""
171
- "<a href=\"http://www.alticreation.com/en/alti-protect-uploads/\" target="
172
  "\"_blank\">Page de support</a> de l'extension Protect Uploads."
173
 
174
  #: admin/views/protect-uploads-admin-settings-page.php:77
175
  msgid ""
176
  "This plugin is compatible with the <span class=\"dashicons dashicons-awards"
177
- "\"></span> <a href=\"http://www.alticreation.com/en/alti-watermark/\" target="
178
  "\"_blank\">Watermark Plugin</a>."
179
  msgstr ""
180
  "Cette extension est compatible avec <span class=\"dashicons dashicons-awards"
181
- "\"></span> <a href=\"http://www.alticreation.com/en/alti-watermark/\" target="
182
  "\"_blank\">l'extension Watermark</a>."
183
 
184
  #: admin/views/protect-uploads-admin-settings-page.php:78
165
 
166
  #: admin/views/protect-uploads-admin-settings-page.php:76
167
  msgid ""
168
+ "Protect Uploads Plugin <a href=\"https://www.alticreation.com/en/protect-"
169
  "uploads/\" target=\"_blank\">support page</a>."
170
  msgstr ""
171
+ "<a href=\"https://www.alticreation.com/en/alti-protect-uploads/\" target="
172
  "\"_blank\">Page de support</a> de l'extension Protect Uploads."
173
 
174
  #: admin/views/protect-uploads-admin-settings-page.php:77
175
  msgid ""
176
  "This plugin is compatible with the <span class=\"dashicons dashicons-awards"
177
+ "\"></span> <a href=\"https://www.alticreation.com/en/alti-watermark/\" target="
178
  "\"_blank\">Watermark Plugin</a>."
179
  msgstr ""
180
  "Cette extension est compatible avec <span class=\"dashicons dashicons-awards"
181
+ "\"></span> <a href=\"https://www.alticreation.com/en/alti-watermark/\" target="
182
  "\"_blank\">l'extension Watermark</a>."
183
 
184
  #: admin/views/protect-uploads-admin-settings-page.php:78
languages/protect-uploads-it_IT.po CHANGED
@@ -166,20 +166,20 @@ msgstr "Supporto"
166
 
167
  #: admin/views/protect-uploads-admin-settings-page.php:76
168
  msgid ""
169
- "Protect Uploads Plugin <a href=\"http://www.alticreation.com/en/protect-"
170
  "uploads/\" target=\"_blank\">support page</a>."
171
  msgstr ""
172
- "Vedi la nostra <a href=\"http://www.alticreation.com/en/protect-uploads/\" "
173
  "target=\"_blank\">pagina</a> di supporto del plugin. (in inglese)"
174
 
175
  #: admin/views/protect-uploads-admin-settings-page.php:77
176
  msgid ""
177
  "This plugin is compatible with the <span class=\"dashicons dashicons-awards"
178
- "\"></span> <a href=\"http://www.alticreation.com/en/alti-watermark/\" target="
179
  "\"_blank\">Watermark Plugin</a>."
180
  msgstr ""
181
  "Questo plugin è compatibile con <span class=\"dashicons dashicons-awards\"></"
182
- "span> <a href=\"http://www.alticreation.com/en/alti-watermark/\" target="
183
  "\"_blank\">Watermark Plugin</a>."
184
 
185
  #: admin/views/protect-uploads-admin-settings-page.php:78
166
 
167
  #: admin/views/protect-uploads-admin-settings-page.php:76
168
  msgid ""
169
+ "Protect Uploads Plugin <a href=\"https://www.alticreation.com/en/protect-"
170
  "uploads/\" target=\"_blank\">support page</a>."
171
  msgstr ""
172
+ "Vedi la nostra <a href=\"https://www.alticreation.com/en/protect-uploads/\" "
173
  "target=\"_blank\">pagina</a> di supporto del plugin. (in inglese)"
174
 
175
  #: admin/views/protect-uploads-admin-settings-page.php:77
176
  msgid ""
177
  "This plugin is compatible with the <span class=\"dashicons dashicons-awards"
178
+ "\"></span> <a href=\"https://www.alticreation.com/en/alti-watermark/\" target="
179
  "\"_blank\">Watermark Plugin</a>."
180
  msgstr ""
181
  "Questo plugin è compatibile con <span class=\"dashicons dashicons-awards\"></"
182
+ "span> <a href=\"https://www.alticreation.com/en/alti-watermark/\" target="
183
  "\"_blank\">Watermark Plugin</a>."
184
 
185
  #: admin/views/protect-uploads-admin-settings-page.php:78
protect-uploads.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /**
3
  * Plugin Name: Protect Uploads
4
- * Plugin URI: http://www.alticreation.com/en/protect-uploads/
5
  * Description: Protect your uploads directory. Avoid browsing of your uploads directory by adding a htaccess file or an index.php file.
6
- * Version: 0.2
7
  * Author: Alexis Blondin
8
- * Author URI: http://www.alticreation.com
9
  * License: GPL-2.0+
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
  * Text Domain: protect-uploads
1
  <?php
2
  /**
3
  * Plugin Name: Protect Uploads
4
+ * Plugin URI: https://www.alticreation.com/en/protect-uploads/
5
  * Description: Protect your uploads directory. Avoid browsing of your uploads directory by adding a htaccess file or an index.php file.
6
+ * Version: 0.3
7
  * Author: Alexis Blondin
8
+ * Author URI: https://www.alticreation.com
9
  * License: GPL-2.0+
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
  * Text Domain: protect-uploads
readme.txt CHANGED
@@ -1,10 +1,11 @@
1
  === Protect uploads ===
2
  Contributors: alticreation
3
- Donate link: http://www.alticreation.com/en/protect-uploads/
4
  Tags: uploads, protection, images protection, browsing images, uploads folder, image folder, avoid browsing folder, hide uploads, prevent uploads browsing, prevent images browsing, protect library, library
5
  Requires at least: 3.0.1
6
- Tested up to: 4.7.4
7
- Stable tag: 0.2
 
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -23,7 +24,7 @@ Available languages :
23
  * Español
24
  * Italian (thanks to Marko97)
25
 
26
- For support, please visit [protect uploads plugin](http://www.alticreation.com/en/protect-uploads/ "protect uploads plugin for Wordpress by alticreation")
27
 
28
  == Installation ==
29
 
@@ -35,7 +36,7 @@ Note : GD library is needed and being able to create a .htaccess file in uploads
35
  == Frequently Asked Questions ==
36
 
37
  = Support =
38
- You can ask question and read documentation at [protect uploads plugin](http://www.alticreation.com/en/protect-uploads/ "protect uploads plugin for Wordpress by alticreation")
39
 
40
  == Screenshots ==
41
 
@@ -55,3 +56,10 @@ Nothing for now
55
  * Add sidebar for admin page
56
  * Add Italian translation (thanks to Marko97).
57
  * Try to fix the wrong message saying that Protection is disabled eventhough it is actually working.
 
 
 
 
 
 
 
1
  === Protect uploads ===
2
  Contributors: alticreation
3
+ Donate link: https://www.alticreation.com/en/protect-uploads/
4
  Tags: uploads, protection, images protection, browsing images, uploads folder, image folder, avoid browsing folder, hide uploads, prevent uploads browsing, prevent images browsing, protect library, library
5
  Requires at least: 3.0.1
6
+ Tested up to: 5.4.1
7
+ Requires PHP: 5.0
8
+ Stable tag: 0.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
24
  * Español
25
  * Italian (thanks to Marko97)
26
 
27
+ For support, please visit [protect uploads plugin](https://www.alticreation.com/en/protect-uploads/ "protect uploads plugin for Wordpress by alticreation")
28
 
29
  == Installation ==
30
 
36
  == Frequently Asked Questions ==
37
 
38
  = Support =
39
+ You can ask question and read documentation at [protect uploads plugin](https://www.alticreation.com/en/protect-uploads/ "protect uploads plugin for Wordpress by alticreation")
40
 
41
  == Screenshots ==
42
 
56
  * Add sidebar for admin page
57
  * Add Italian translation (thanks to Marko97).
58
  * Try to fix the wrong message saying that Protection is disabled eventhough it is actually working.
59
+
60
+ = 0.3 =
61
+ * Simplify UI admin.
62
+ * check presence of index.html.
63
+ * Remove option value managing current protection status.
64
+ * Reorganizing code and making it more modular and simple.
65
+ * Remove useless pieces.