This repository was archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmdocs-settings.php
More file actions
382 lines (374 loc) · 18.1 KB
/
mdocs-settings.php
File metadata and controls
382 lines (374 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
define('MDOCS_CATS', 'mdocs-cats.txt');
define('MDOCS_LIST', 'mdocs-list.txt');
define('MDOCS_DIR','/mdocs/');
define('MDOC_PATH',plugin_dir_path(__FILE__));
define('MDOC_URL',plugin_dir_url(__FILE__));
define('MDOCS_TIME_OFFSET', get_option('gmt_offset')*60*60);
define('MDOCS_ROBOTS','http://www.kingofnothing.net/memphis/robots/memphis-robots.txt');
define('MDOCS_UPDATE', '<div class="mdocs-updated">'.__('Updated','mdocs').'</div>');
define('MDOCS_NEW', '<div class="mdocs-new">'.__('New','mdocs').'</div>');
define('MDOCS_UPDATE_SMALL', '<span class="mdocs-updated-small">'.__('Updated','mdocs').'</span>');
define('MDOCS_NEW_SMALL', '<span class="mdocs-new-small">'.__('New','mdocs').'</span>');
define('MDOCS_CURRENT_TIME', date('Y-m-d H:i:s', time()+MDOCS_TIME_OFFSET));
//define('MDOCS_VERSION', );
$add_error = false;
$mdocs_img_types = array('jpeg','jpg','png','gif');
$mdocs_input_text_bg_colors = array('#f1f1f1','#e5eaff','#efffe7','#ffecdc','#ffe9fe','#ff5000','#00ff20');
function mdocs_register_settings() {
//CREATE REPOSITORY DIRECTORY
$upload_dir = wp_upload_dir();
$is_read_write = mdocs_check_read_write();
if($is_read_write) {
//BACKUP FILE CREATE
$backup_list = json_encode(get_option('mdocs-list'));
$current_list = get_option('mdocs-list');
if($current_list != null) file_put_contents($upload_dir['basedir'].MDOCS_DIR.'mdocs-files.bak', $backup_list);
elseif(file_exists($upload_dir['basedir'].MDOCS_DIR.'mdocs-files.bak') && !isset($_GET['restore-default'])) {
$backup_list = json_decode(file_get_contents($upload_dir['basedir'].MDOCS_DIR.'mdocs-files.bak'),true);
update_option('mdocs-list', $backup_list);
//mdocs_errors(MDOCS_ERROR_7,'error');
}
if(!isset($_GET['restore-default'])) {
// PATCHES
// 2.6.6
register_setting('mdocs-patch-vars', 'mdocs-v2-6-6-patch-var-1');
add_action('mdocs-v2-6-6-patch-var-1',false && is_array(get_option('mdocs-list')));
if(get_option('mdocs-v2-6-6-patch-var-1') == false && is_array(get_option('mdocs-list'))) {
$this_query = new WP_Query('category_name=mdocs-media&posts_per_page=-1');
foreach($this_query->posts as $index => $post) set_post_type($post->ID,'mdocs-posts');
update_option('mdocs-v2-6-6-patch-var-1',true);
}
// 2.6.7
register_setting('mdocs-patch-vars', 'mdocs-v2-6-7-patch-var-1');
add_action('mdocs-v2-6-7-patch-var-1',false);
if(get_option('mdocs-v2-6-7-patch-var-1') == false && is_array(get_option('mdocs-list'))) {
$mdocs_cat = get_category_by_slug('mdocs-media');
wp_delete_category($mdocs_cat->cat_ID);
update_option('mdocs-v2-6-7-patch-var-1',true);
}
// 2.5
register_setting('mdocs-patch-vars', 'mdocs-v2-5-patch-var-1');
add_action('mdocs-v2-5-patch-var-1',false);
if(get_option('mdocs-v2-5-patch-var-1') == false && is_array(get_option('mdocs-list'))) {
$num_cats = 1;
foreach( get_option('mdocs-cats') as $index => $cat ){ $num_cats++;}
update_option('mdocs-num-cats',$num_cats);
add_action( 'admin_notices', 'mdocs_v2_5_admin_notice_v1' );
update_option('mdocs-v2-5-patch-var-1',true);
} else update_option('mdocs-v2-5-patch-var-1',true);
// 2.4
register_setting('mdocs-patch-vars', 'mdocs-v2-4-patch-var-1');
add_option('mdocs-v2-4-patch-var-1',false);
if(get_option('mdocs-v2-4-patch-var-1') == false && is_array(get_option('mdocs-list'))) {
$mdocs_cats = get_option('mdocs-cats');
$new_mdocs_cats = array();
foreach($mdocs_cats as $index => $cat) array_push($new_mdocs_cats, array('slug' => $index,'name' => $cat, 'parent' => '', 'children' => array(), 'depth' => 0));
update_option('mdocs-cats', $new_mdocs_cats);
update_option('mdocs-v2-4-patch-var-1', true);
add_action( 'admin_notices', 'mdocs_v2_4_admin_notice_v1' );
} else update_option('mdocs-v2-4-patch-var-1', true);
// 2.3
register_setting('mdocs-patch-vars', 'mdocs-v2-3-1-patch-var-1');
add_option('mdocs-v2-3-1-patch-var-1',false);
if(get_option('mdocs-v2-3-1-patch-var-1') == false && is_array(get_option('mdocs-list'))) {
$htaccess = $upload_dir['basedir'].'/mdocs/.htaccess';
$fh = fopen($htaccess, 'w');
update_option('mdocs-htaccess', "Deny from all\nOptions +Indexes\nAllow from .google.com");
$mdocs_htaccess = get_option('mdocs-htaccess');
fwrite($fh, $mdocs_htaccess);
fclose($fh);
chmod($htaccess, 0660);
update_option('mdocs-v2-3-1-patch-var-1', true);
add_action( 'admin_notices', 'mdocs_v2_2_1_admin_notice_v1' );
} else update_option('mdocs-v2-3-1-patch-var-1', true);
//2.1
register_setting('mdocs-settings', 'mdocs-2-1-patch-1');
add_option('mdocs-2-1-patch-1',false);
if(get_option('mdocs-2-1-patch-1') == false && is_array(get_option('mdocs-list'))) {
$the_list = get_option('mdocs-list');
foreach(get_option('mdocs-list') as $index => $the_mdoc) {
if(!is_array($the_mdoc['ratings'])) {
$the_mdoc['ratings'] = array();
$the_mdoc['rating'] = 0;
$the_list[$index] = $the_mdoc;
}
if(!key_exists('rating', $the_list)) {
$the_mdoc['rating'] = 0;
$the_list[$index] = $the_mdoc;
}
}
mdocs_save_list($mdocs);
update_option('mdocs-2-1-patch-1', true);
} else update_option('mdocs-2-1-patch-1', true);
} else {
update_option('mdocs-v2-6-6-patch-var-1',true);
update_option('mdocs-v2-6-7-patch-var-1',true);
update_option('mdocs-v2-5-patch-var-1',true);
update_option('mdocs-v2-4-patch-var-1', true);
update_option('mdocs-v2-3-1-patch-var-1', true);
update_option('mdocs-2-1-patch-1', true);
@unlink($upload_dir['basedir'].MDOCS_DIR.'mdocs-files.bak');
}
// Creating File Structure
if(!is_dir($upload_dir['basedir'].'/mdocs/') && $upload_dir['error'] === false) mkdir($upload_dir['basedir'].'/mdocs/');
elseif(!is_dir($upload_dir['basedir'].'/mdocs/') && $upload_dir['error'] !== false) mdocs_errors(__('Unable to create the directory "mdocs" which is needed by Memphis Documents Library. Is its parent directory writable by the server?','mdocs'),'error');
//CREATE MDOCS POST CATEGORY
//if(get_category_by_slug( 'mdocs_media' ) == false) wp_create_category('mdocs-media');
//CREATE MDOCS PAGE
$query = new WP_Query('pagename=mdocuments-library');
if(empty($query->posts) && empty($query->queried_object) ) {
$mdocs_page = array(
'post_title' => __('Documents','mdocs'),
'post_name' => 'mdocuments-library',
'post_content' => '[mdocs]',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page',
'comment_status' => 'closed'
);
$mdocs_post_id = wp_insert_post( $mdocs_page );
}
//REGISTER SAVED VARIABLES
mdocs_init_settings();
$upload_dir = wp_upload_dir();
if(!file_exists($upload_dir['basedir'].'/mdocs/.htaccess')) {
if(!file_exists($upload_dir['basedir'].'/mdocs/')) mkdir($upload_dir['basedir'].'/mdocs/');
$htaccess = $upload_dir['basedir'].'/mdocs/.htaccess';
$fh = fopen($htaccess, 'w');
$mdocs_htaccess = get_option('mdocs-htaccess');
fwrite($fh, $mdocs_htaccess);
fclose($fh);
chmod($htaccess, 0660);
}
} else mdocs_errors(__('Unable to create the directory "mdocs" which is needed by Memphis Documents Library. Its parent directory is not readable/writable by the server?','mdocs'),'error');
}
function mdocs_init_settings() {
add_filter('upload_mimes', 'mdocs_custom_mime_types');
$temp_cats = array();
$temp_cats[0] = array('base_parent' => '', 'index' => 0, 'parent_index' => 0, 'slug' => 'mdocuments', 'name' => 'Documents', 'parent' => '', 'children' => array(), 'depth' => 0,);
register_setting('mdocs-settings', 'mdocs-cats');
add_option('mdocs-cats',$temp_cats);
if(is_string(get_option('mdocs-cats'))) update_option('mdocs-cats',$temp_cats);
register_setting('mdocs-settings', 'mdocs-list');
add_option('mdocs-list',array());
register_setting('mdocs-settings', 'mdocs-num-cats');
add_option('mdocs-num-cats',1);
register_setting('mdocs-settings', 'mdocs-total-cats');
add_option('mdocs-total-cats',0);
register_setting('mdocs-settings', 'mdocs-zip');
add_option('mdocs-zip','mdocs-export.zip');
register_setting('mdocs-top-downloads', 'mdocs-top-downloads');
add_option('mdocs-top-downloads',10);
register_setting('mdocs-top-downloads', 'mdocs-top-rated');
add_option('mdocs-top-rated',10);
register_setting('mdocs-top-downloads', 'mdocs-last-updated');
add_option('mdocs-last-updated',10);
//GLOBAL VARIABLES
register_setting('mdocs-global-settings', 'mdocs-list-type');
add_option('mdocs-list-type','small');
register_setting('mdocs-global-settings', 'mdocs-list-type-dashboard');
add_option('mdocs-list-type-dashboard','small');
register_setting('mdocs-global-settings', 'mdocs-hide-all-files-non-members');
add_option('mdocs-hide-all-files-non-members', false);
register_setting('mdocs-global-settings', 'mdocs-hide-all-posts-non-members');
add_option('mdocs-hide-all-posts-non-members', false);
register_setting('mdocs-global-settings', 'mdocs-hide-all-posts-non-members-default');
add_option('mdocs-hide-all-posts-non-members-default', false);
register_setting('mdocs-global-settings', 'mdocs-hide-all-files');
add_option('mdocs-hide-all-files', false);
register_setting('mdocs-global-settings', 'mdocs-hide-all-posts');
add_option('mdocs-hide-all-posts', false);
register_setting('mdocs-global-settings', 'mdocs-hide-all-posts-default');
add_option('mdocs-hide-all-posts-default', false);
register_setting('mdocs-global-settings', 'mdocs-show-downloads');
add_option('mdocs-show-downloads', true);
register_setting('mdocs-global-settings', 'mdocs-show-author');
add_option('mdocs-show-author', true);
register_setting('mdocs-global-settings', 'mdocs-show-version');
add_option('mdocs-show-version', true);
register_setting('mdocs-global-settings', 'mdocs-show-update');
add_option('mdocs-show-update', true);
register_setting('mdocs-global-settings', 'mdocs-show-social');
add_option('mdocs-show-social', true);
register_setting('mdocs-global-settings', 'mdocs-show-ratings');
add_option('mdocs-show-ratings', true);
register_setting('mdocs-global-settings', 'mdocs-show-share');
add_option('mdocs-show-share', true);
register_setting('mdocs-global-settings', 'mdocs-download-color-normal');
add_option('mdocs-download-color-normal', '#d14836');
register_setting('mdocs-global-settings', 'mdocs-download-color-hover');
add_option('mdocs-download-color-hover', '#c34131');
register_setting('mdocs-global-settings', 'mdocs-download-text-color-normal');
add_option('mdocs-download-text-color-normal', '#ffffff');
register_setting('mdocs-global-settings', 'mdocs-download-text-color-hover');
add_option('mdocs-download-text-color-hover', '#ffffff');
register_setting('mdocs-global-settings', 'mdocs-show-new-banners');
add_option('mdocs-show-new-banners', true);
register_setting('mdocs-global-settings', 'mdocs-time-to-display-banners');
add_option('mdocs-time-to-display-banners', 14);
register_setting('mdocs-global-settings', 'mdocs-doc-preview');
add_option('mdocs-doc-preview', false);
register_setting('mdocs-global-settings', 'mdocs-sort-type');
add_option('mdocs-sort-type','modified');
register_setting('mdocs-global-settings', 'mdocs-sort-style');
add_option('mdocs-sort-style','desc');
register_setting('mdocs-global-settings', 'mdocs-default-content');
add_option('mdocs-default-content','description');
register_setting('mdocs-global-settings', 'mdocs-show-description');
add_option('mdocs-show-description',true);
register_setting('mdocs-global-settings', 'mdocs-show-preview');
add_option('mdocs-show-preview', true);
register_setting('mdocs-global-settings', 'mdocs-htaccess');
add_option('mdocs-htaccess', "Deny from all\nOptions +Indexes\nAllow from .google.com");
register_setting('mdocs-global-settings', 'mdocs-allowed-mime-types');
add_option('mdocs-allowed-mime-types', array());
if(is_string(get_option('mdocs-allowed-mime-types'))) update_option('mdocs-allowed-mime-types',array());
register_setting('mdocs-global-settings', 'mdocs-removed-mime-types');
add_option('mdocs-removed-mime-types', array());
if(is_string(get_option('mdocs-removed-mime-types'))) update_option('mdocs-removed-mime-types',array());
register_setting('mdocs-global-settings', 'mdocs-view-private');
add_option('mdocs-view-private', array());
//Update View Private Users
mdocs_update_view_private_users();
}
function mdocs_update_view_private_users() {
$mdocs_roles = get_option('mdocs-view-private');
$wp_roles = get_editable_roles();
foreach($wp_roles as $index => $wp_role) {
if(isset($mdocs_roles[$index])) {
$add_role = get_role( $index );
$add_role->add_cap( 'read_private_pages' );
$add_role->add_cap( 'read_private_posts' );
} else {
$add_role = get_role( $index );
$add_role->remove_cap( 'read_private_pages' );
$add_role->remove_cap( 'read_private_posts' );
}
}
}
function mdocs_init_view_private() {
$roles = get_editable_roles();
$view_private = array();
$mdocs_roles = get_option('mdocs-view-private');
foreach($roles as $index => $role) {
if(isset($role['capabilities']['read_private_pages'])) $mdocs_roles[$index] = $role['capabilities']['read_private_pages'];
else $mdocs_roles[$index] = false;
}
return $mdocs_roles;
}
//ADD CONTENT TO DOCUMENTS PAGE
//[mdocs]
function mdocs_shortcode($att, $content=null) { return mdocs_the_list($att); }
add_shortcode( 'mdocs', 'mdocs_shortcode' );
//[mdocs_post_page]
function mdocs_post_page_shortcode($att, $content=null) {
return mdocs_post_page($att);
}
add_shortcode( 'mdocs_post_page', 'mdocs_post_page_shortcode' );
function mdocs_admin_script() {
if(isset($_GET['page']) && $_GET['page'] == 'memphis-documents.php') {
wp_enqueue_script("jquery");
//JQUERY UI
wp_register_style( 'mdocs-jquery-ui-style', '//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css');
wp_enqueue_style( 'mdocs-jquery-ui-style' );
wp_enqueue_script( 'mdocs-jquery-ui-script', '//code.jquery.com/ui/1.10.3/jquery-ui.js' );
//MEMPHIS DOCS
wp_register_style( 'mdocs-admin-style', MDOC_URL.'/style.css');
wp_enqueue_style( 'mdocs-admin-style' );
wp_register_script( 'mdocs-admin-script', MDOC_URL.'/mdocs-script.js');
wp_enqueue_script('mdocs-admin-script');
mdocs_inline_css('mdocs-admin-style');
//FONT-AWESOME STYLE
wp_register_style( 'mdocs-font-awesome2-style', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
wp_enqueue_style( 'mdocs-font-awesome2-style' );
//WORDPRESS IRIS COLOR PICKER
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'mdocs-color-picker', plugins_url('mdocs-script.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
mdocs_js_handle('mdocs-admin-script');
}
}
function mdocs_script() {
global $post;
if(get_post_type($post) == 'mdocs-posts' || has_shortcode( $post->post_content, 'mdocs' )) {
wp_enqueue_script("jquery");
//JQUERY UI
wp_register_style( 'mdocs-jquery-ui-style', '//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css');
wp_enqueue_style( 'mdocs-jquery-ui-style' );
wp_enqueue_script( 'mdocs-jquery-ui-script', '//code.jquery.com/ui/1.10.3/jquery-ui.js' );
//MEMPHIS DOCS
wp_register_script( 'mdocs-script', MDOC_URL.'mdocs-script.js');
wp_enqueue_script('mdocs-script');
wp_register_style( 'mdocs-style', MDOC_URL.'style.css');
wp_enqueue_style( 'mdocs-style' );
mdocs_inline_css('mdocs-style');
//FONT-AWESOME STYLE
wp_register_style( 'mdocs-font-awesome2-style', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
wp_enqueue_style( 'mdocs-font-awesome2-style' );
mdocs_js_handle('mdocs-script');
}
}
function mdocs_inline_css($style_name) {
$set_inline_style = mdocs_get_inline_css();
wp_add_inline_style( $style_name, $set_inline_style );
}
function mdocs_document_ready_wp() {
global $post;
if(get_post_type($post) == 'mdocs-posts' || has_shortcode( $post->post_content, 'mdocs' )) {
?>
<script type="application/x-javascript">
jQuery( document ).ready(function() {
mdocs_wp('<?php echo MDOC_URL; ?>', '<?php echo ABSPATH; ?>');
});
</script>
<?php
}
}
function mdocs_document_ready_admin() {
if(!is_network_admin() && isset($_GET['page']) && $_GET['page'] == 'memphis-documents.php') {
?>
<script type="application/x-javascript">
jQuery( document ).ready(function() {
mdocs_admin('<?php echo MDOC_URL; ?>', '<?php echo ABSPATH; ?>');
});
</script>
<?php
}
}
function mdocs_ie_compat() { ?><meta http-equiv="X-UA-Compatible" content="IE=11; IE=10; IE=9; IE=8; IE=7; IE=EDGE" /><?php }
function mdocs_send_headers() {
//SET SORT VALUES SITE
if(isset($_POST['mdocs-sort-type'])) setcookie('mdocs-sort-type-site', $_POST['mdocs-sort-type']);
if(isset($_POST['mdocs-sort-range'])) setcookie('mdocs-sort-range-site', $_POST['mdocs-sort-range']);
//$get_browser = new mdocs_browser_compatibility();
//$browser = $get_browser->get_browser();
//if($browser['name'] == 'Internet Explorer') mdocs_ie_compat();
}
function mdocs_send_headers_dashboard() {
//SET SORT VALUES DASHBOARD
if(isset($_POST['mdocs-sort-type'])) setcookie('mdocs-sort-type-dashboard', $_POST['mdocs-sort-type']);
if(isset($_POST['mdocs-sort-range'])) setcookie('mdocs-sort-range-dashboard', $_POST['mdocs-sort-range']);
//mdocs_ie_compat();
}
function mdocs_v2_2_1_admin_notice_v1() {
?>
<div class="update-nag">
<p><?php _e('Your Memphis <b>.htaccess</b> file has been updated to allow google.com access to the system. This step is necessary to allow documents to be previewed.','mdocs'); ?></p>
</div>
<?php
}
function mdocs_v2_4_admin_notice_v1() {
?>
<div class="update-nag">
<p><?php _e('Your Memphis <b>Categories</b> have been updated to handle subcategories this should not effect your current file system in anyway. If there is any issues please post a comment in the support forum of this plugin. It is recommended to re-export your files again due to the new way categories are structured.','mdocs'); ?></p>
</div
<?php
}
function mdocs_v2_5_admin_notice_v1() {
?>
<div class="update-nag">
<p><?php _e('Your Memphis <b>Categories</b> have been counted to handle subcategories this should not effect your current file system in anyway. If there is any issues please post a comment in the support forum of this plugin. It is recommended to re-export your files again due to the new way categories are structured.','mdocs'); ?></p>
</div
<?php
}
?>