| 1 |
<?php |
| 2 |
|
| 3 |
if(!function_exists('wp_docs_get_memphis_dir_option_id')){ |
| 4 |
function wp_docs_get_option_id($option_name){ |
| 5 |
global $wpdb; |
| 6 |
$option_name = esc_sql( $option_name ); |
| 7 |
$query = $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s", |
| 8 |
$option_name |
| 9 |
); |
| 10 |
return $wpdb->get_var($query); |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
function sanitize_wpdocs_data( $input ) { |
| 15 |
|
| 16 |
if(is_array($input)){ |
| 17 |
|
| 18 |
$new_input = array(); |
| 19 |
|
| 20 |
foreach ( $input as $key => $val ) { |
| 21 |
$new_input[ $key ] = (is_array($val)?sanitize_wpdocs_data($val):sanitize_text_field( $val )); |
| 22 |
} |
| 23 |
|
| 24 |
}else{ |
| 25 |
$new_input = sanitize_text_field($input); |
| 26 |
} |
| 27 |
|
| 28 |
if(!is_array($new_input)){ |
| 29 |
|
| 30 |
if(stripos($new_input, '@') && is_email($new_input)){ |
| 31 |
$new_input = sanitize_email($new_input); |
| 32 |
} |
| 33 |
|
| 34 |
if(stripos($new_input, 'http') || wp_http_validate_url($new_input)){ |
| 35 |
$new_input = sanitize_url($new_input); |
| 36 |
} |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
return $new_input; |
| 42 |
} |
| 43 |
|
| 44 |
function wpdocs_admin_enqueue_script() |
| 45 |
{ |
| 46 |
if (isset($_GET['page']) && $_GET['page'] == 'wpdocs') { |
| 47 |
|
| 48 |
global $wpdocs_pro, $wpdocs_options; |
| 49 |
|
| 50 |
wp_enqueue_script('wpdocs_boostrap', plugin_dir_url(dirname(__FILE__)) . 'js/bootstrap.min.js', array('jquery')); |
| 51 |
wp_enqueue_style('wpdocs-boostrap', plugins_url('css/bootstrap.min.css', dirname(__FILE__))); |
| 52 |
wp_enqueue_script('wpdocs_slim', plugin_dir_url(dirname(__FILE__)) . 'js/slimselect.js', array('jquery')); |
| 53 |
wp_enqueue_style('wpdocs-slim', plugins_url('css/slimselect.css', dirname(__FILE__))); |
| 54 |
|
| 55 |
wp_enqueue_style( 'jquery-ui', plugins_url('css/jquery-ui.css', dirname(__FILE__)), array('jquery') ); |
| 56 |
wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 57 |
|
| 58 |
wp_enqueue_script('wpdocs_block_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/jquery.blockUI.js', array('jquery')); |
| 59 |
|
| 60 |
|
| 61 |
wp_enqueue_style('fontawesome', plugins_url('css/fontawesome.min.css', dirname(__FILE__))); |
| 62 |
|
| 63 |
wp_enqueue_media(); |
| 64 |
|
| 65 |
wp_enqueue_style('wpdocs-common', plugins_url('css/common-styles.css', dirname(__FILE__)), array(), date('Ymdhi')); |
| 66 |
wp_enqueue_style('wpdocs-admin', plugins_url('css/admin-styles.css', dirname(__FILE__)), array(), date('Ymdhi')); |
| 67 |
|
| 68 |
wp_enqueue_script('wpdocs_admin_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/admin-scripts.js', array('jquery', 'jquery-ui-dialog'), time()); |
| 69 |
|
| 70 |
if($wpdocs_pro){ |
| 71 |
wp_enqueue_script('wpdocs_pro_scripts', plugin_dir_url(dirname(__FILE__)) . 'pro/wp-docs-admin.js?t='.time(), array('jquery')); |
| 72 |
} |
| 73 |
|
| 74 |
$dir_id_to_titles = array(); |
| 75 |
$all_dirs = wpdocs_list(''); |
| 76 |
if(!empty($all_dirs)){ |
| 77 |
foreach($all_dirs as $all_dir){ |
| 78 |
$dir_id_to_titles[$all_dir['id']] = $all_dir['title']; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
wp_localize_script( |
| 83 |
'wpdocs_admin_scripts', |
| 84 |
'wpdocs_ajax_object', |
| 85 |
array( |
| 86 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 87 |
'url' => admin_url('options-general.php?page=wpdocs'), |
| 88 |
'wpdocs_pro' => $wpdocs_pro, |
| 89 |
'wpdocs_delete_msg' => __('Do you want to delete this directory and data as well?', 'wp-docs'), |
| 90 |
'wpdocs_delete_shortcut_msg' => __('Do you want to delete this shortcut?', 'wp-docs'), |
| 91 |
'target_dir_msg' => __('Select a target directory.', 'wp-docs'), |
| 92 |
'move_error' => __('Sorry! File could not move, please try again.', 'wp-docs'), |
| 93 |
'move_str' => __('Cannot move to the selected directory', 'wp-docs'), |
| 94 |
'copied' => __('Successfully copied!', 'wp-docs'), |
| 95 |
'moved' => __('Successfully moved!', 'wp-docs'), |
| 96 |
'premium_feature' => __('This feature is not available in basic version. Please upgrade.', 'wp-docs'), |
| 97 |
'del_confirm' => __('Do you want to delete this file?', 'wp-docs'), |
| 98 |
'del_confirm_all' => __('Do you want to delete selected files?', 'wp-docs'), |
| 99 |
'import_confirm' => __('Do you want to import all directories and files from Memphis Documents Library?', 'wp-docs'), |
| 100 |
'undo_import_confirm' => __('Do you want to rollback the import?', 'wp-docs'), |
| 101 |
'select_role_str' => __('Select roles to allow upload', 'wp-docs'), |
| 102 |
'rename_confirm' => __('Do you want to rename this directory?', 'wp-docs'), |
| 103 |
'reset_confirm' => __('Do you want to reset all settings and clear directories?', 'wp-docs'), |
| 104 |
'nonce' => wp_create_nonce('wpdocs_update_options_nonce'), |
| 105 |
'empty_settings' => empty($wpdocs_options), |
| 106 |
'wc_os_pg' => (isset($_GET['pg'])?esc_attr($_GET['pg']):'0'), |
| 107 |
'wc_os_tab' => (isset($_GET['t'])?esc_attr($_GET['t']):'0'), |
| 108 |
'all_dirs' => $dir_id_to_titles |
| 109 |
|
| 110 |
) |
| 111 |
); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
add_filter( 'ajax_query_attachments_args', 'wpdocs_filter_media'); |
| 116 |
function wpdocs_filter_media( $query ) { |
| 117 |
// admins get to see everything |
| 118 |
if ( ! current_user_can( 'manage_options' ) ) |
| 119 |
$query['author'] = get_current_user_id(); |
| 120 |
|
| 121 |
return $query; |
| 122 |
} |
| 123 |
|
| 124 |
function wpdocs_get_user_roles(){ |
| 125 |
$ret = array(); |
| 126 |
global $wp_roles; |
| 127 |
if(!empty($wp_roles) && isset($wp_roles->roles) && !empty($wp_roles->roles)){ |
| 128 |
|
| 129 |
foreach($wp_roles->roles as $key=>$arr){ |
| 130 |
$ret[$key] = $arr['name']; |
| 131 |
} |
| 132 |
} |
| 133 |
return $ret; |
| 134 |
} |
| 135 |
|
| 136 |
function wpdocs_get_user_roles_options(array $selected){ |
| 137 |
|
| 138 |
$wpdocs_get_user_roles = wpdocs_get_user_roles(); |
| 139 |
|
| 140 |
$options = ''; |
| 141 |
|
| 142 |
if(!empty($wpdocs_get_user_roles)){ |
| 143 |
|
| 144 |
foreach ($wpdocs_get_user_roles as $role_key => $role_name){ |
| 145 |
|
| 146 |
$selected_option = in_array($role_key, $selected) ? 'selected="selected"' : ''; |
| 147 |
|
| 148 |
$options .= "<option value='$role_key' $selected_option>$role_name</option>"; |
| 149 |
|
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
return $options; |
| 154 |
|
| 155 |
|
| 156 |
} |
| 157 |
|
| 158 |
function wpdocs_allowed_mime_types($mime_types){ |
| 159 |
|
| 160 |
global $wpdocs_options; |
| 161 |
|
| 162 |
|
| 163 |
$dir = (isset($_GET['wpdocs_restriction']) ? esc_attr($_GET['wpdocs_restriction']) : 0); |
| 164 |
|
| 165 |
$is_file = wpdocs_dir_options_by_name('file_upload', false, $dir); |
| 166 |
$allowed_ext = wpdocs_dir_options_by_name('allowed_ext', '', $dir); |
| 167 |
|
| 168 |
|
| 169 |
if($is_file && $allowed_ext){ |
| 170 |
|
| 171 |
|
| 172 |
$allowed_ext = explode(',', $allowed_ext); |
| 173 |
|
| 174 |
$allowed_ext = array_map('trim', $allowed_ext); |
| 175 |
|
| 176 |
$allowe_mime_types = array(); |
| 177 |
|
| 178 |
if(!empty($mime_types)){ |
| 179 |
|
| 180 |
foreach ($mime_types as $mime_key => $mime_value){ |
| 181 |
|
| 182 |
$mime_key_array = explode('|', $mime_key); |
| 183 |
$mime_key_array = array_map('trim', $mime_key_array); |
| 184 |
|
| 185 |
|
| 186 |
if(!empty($allowed_ext)){ |
| 187 |
foreach ($allowed_ext as $ext){ |
| 188 |
|
| 189 |
if(in_array($ext, $mime_key_array)){ |
| 190 |
$allowe_mime_types[$mime_key] = $mime_value; |
| 191 |
} |
| 192 |
|
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
} |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
return $allowe_mime_types; |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
}else{ |
| 208 |
|
| 209 |
return $mime_types; |
| 210 |
|
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
} |
| 217 |
|
| 218 |
function wpdocs_get_current_user_role() { |
| 219 |
global $wp_roles; |
| 220 |
|
| 221 |
$current_user = wp_get_current_user(); |
| 222 |
$roles = $current_user->roles; |
| 223 |
|
| 224 |
$role = array_shift( $roles ); |
| 225 |
|
| 226 |
return isset( $wp_roles->role_names[ $role ] ) ? $role : FALSE; |
| 227 |
} |
| 228 |
|
| 229 |
function wpdocs_can_current_user_upload_file($dir = 0){ |
| 230 |
|
| 231 |
global $wpdocs_options; |
| 232 |
$is_file = wpdocs_dir_options_by_name('file_upload', false, $dir); |
| 233 |
|
| 234 |
|
| 235 |
if(!is_user_logged_in() && !$is_file){return false;} |
| 236 |
|
| 237 |
$current_user_role = wpdocs_get_current_user_role(); |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
// $allowed_role = array_key_exists('allowed_role', $wpdocs_options) ? $wpdocs_options['allowed_role'] : array(); |
| 243 |
$allowed_role = wpdocs_dir_options_by_name('allowed_role', array(), $dir); |
| 244 |
|
| 245 |
|
| 246 |
if(!empty($allowed_role)){ |
| 247 |
|
| 248 |
if(in_array($current_user_role, $allowed_role)){ |
| 249 |
|
| 250 |
$can_current_user_upload = current_user_can('upload_files'); |
| 251 |
|
| 252 |
if(!$can_current_user_upload){ |
| 253 |
|
| 254 |
$user_role = get_role($current_user_role); |
| 255 |
$user_role->add_cap('upload_files'); |
| 256 |
$user_role->add_cap('delete_posts'); |
| 257 |
|
| 258 |
} |
| 259 |
|
| 260 |
return true; |
| 261 |
|
| 262 |
}else{ |
| 263 |
|
| 264 |
return false; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
}else{ |
| 269 |
|
| 270 |
|
| 271 |
return current_user_can('upload_files'); |
| 272 |
|
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
} |
| 278 |
|
| 279 |
add_action('admin_enqueue_scripts', 'wpdocs_admin_enqueue_script'); |
| 280 |
|
| 281 |
add_action('wp_enqueue_scripts', 'wpdocs_wp_enqueue_script'); |
| 282 |
|
| 283 |
|
| 284 |
function wp_docs_recursive_array_search($needle, $haystack) { |
| 285 |
|
| 286 |
if(is_array($haystack) && !empty($haystack)){ |
| 287 |
foreach($haystack as $key=>$value) { |
| 288 |
|
| 289 |
if(!is_array($value) && stripos(' '.$value, $needle)) { |
| 290 |
return array($key); |
| 291 |
} else if (is_array($value) && $subkey = wp_docs_recursive_array_search($needle,$value)) { |
| 292 |
array_unshift($subkey, $key); |
| 293 |
return $subkey; |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
function wpdocs_test($post_content , $short_code = ''){ |
| 301 |
|
| 302 |
global $post; |
| 303 |
$result = array(); |
| 304 |
//get shortcode regex pattern wordpress function |
| 305 |
$pattern = get_shortcode_regex(); |
| 306 |
$result = array(); |
| 307 |
|
| 308 |
if ( preg_match_all( '/'. $pattern .'/s', $post_content, $matches ) ) |
| 309 |
{ |
| 310 |
pree($matches); |
| 311 |
$keys = array(); |
| 312 |
foreach( $matches[0] as $key => $value) { |
| 313 |
// $matches[3] return the shortcode attribute as string |
| 314 |
// replace space with '&' for parse_str() function |
| 315 |
$get = preg_replace('/"\s/', '"&', $matches[3][$key] ); |
| 316 |
parse_str($get, $output); |
| 317 |
|
| 318 |
pree($get); |
| 319 |
pree($output); |
| 320 |
|
| 321 |
//get all shortcode attribute keys |
| 322 |
$keys = array_unique( array_merge( $keys, array_keys($output)) ); |
| 323 |
$result[] = $output; |
| 324 |
|
| 325 |
} |
| 326 |
//var_dump($result); |
| 327 |
if( $keys && $result ) { |
| 328 |
// Loop the result array and add the missing shortcode attribute key |
| 329 |
foreach ($result as $key => $value) { |
| 330 |
// Loop the shortcode attribute key |
| 331 |
foreach ($keys as $attr_key) { |
| 332 |
$result[$key][$attr_key] = isset( $result[$key][$attr_key] ) ? $result[$key][$attr_key] : NULL; |
| 333 |
} |
| 334 |
//sort the array key |
| 335 |
ksort( $result[$key]); |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
//display the result |
| 340 |
} |
| 341 |
|
| 342 |
return $result; |
| 343 |
|
| 344 |
|
| 345 |
} |
| 346 |
|
| 347 |
function wpdocs_wp_enqueue_script() |
| 348 |
{ |
| 349 |
global $post, $wpdocs_pro, $wpdocs_url, $wpdocs_options; |
| 350 |
|
| 351 |
$wpdocs_relevant_page = false; |
| 352 |
$localize_handler = 'wpdocs_front_scripts'; |
| 353 |
//pree($post->post_content); |
| 354 |
//pree(stripos($post->post_content, '[wpdocs]')); |
| 355 |
$details_view_sorting = array_key_exists('details_view_sorting', $wpdocs_options); |
| 356 |
$ajax_based_deep_search = ($wpdocs_pro && array_key_exists('ajax_based_deep_search', $wpdocs_options)); |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
if(!empty($post) && isset($post->post_content)){ |
| 361 |
$meta_data = get_post_meta($post->ID); |
| 362 |
|
| 363 |
|
| 364 |
$wpdocs_inside_meta = wp_docs_recursive_array_search('[wpdocs', $meta_data); |
| 365 |
$wpdocs_inside_meta = is_array($wpdocs_inside_meta)?array_filter($wpdocs_inside_meta):array(); |
| 366 |
|
| 367 |
//pree($wpdocs_inside_meta); |
| 368 |
|
| 369 |
if(stripos(' '.$post->post_content, '[wpdocs') || !empty($wpdocs_inside_meta)){ |
| 370 |
$wpdocs_relevant_page = true; |
| 371 |
} |
| 372 |
} |
| 373 |
//pree($wpdocs_relevant_page); |
| 374 |
if($wpdocs_relevant_page){ |
| 375 |
|
| 376 |
$is_bootstrap = array_key_exists('bootstrap', $wpdocs_options); |
| 377 |
$is_file_upload = array_key_exists('file_upload', $wpdocs_options); |
| 378 |
|
| 379 |
if(is_admin() || ($wpdocs_pro)){ |
| 380 |
|
| 381 |
|
| 382 |
add_filter('upload_mimes', 'wpdocs_allowed_mime_types', 1, 1); |
| 383 |
|
| 384 |
wp_enqueue_media(); |
| 385 |
|
| 386 |
} |
| 387 |
|
| 388 |
if($is_bootstrap){ |
| 389 |
wp_enqueue_script('wpdocs_boostrap', plugin_dir_url(dirname(__FILE__)) . 'js/bootstrap.min.js'); |
| 390 |
wp_enqueue_style('wpdocs-boostrap', plugins_url('css/bootstrap.min.css', dirname(__FILE__))); |
| 391 |
} |
| 392 |
|
| 393 |
$is_ajax_url = false; |
| 394 |
$is_ajax = false; |
| 395 |
|
| 396 |
|
| 397 |
if($wpdocs_pro){ |
| 398 |
|
| 399 |
$is_ajax = array_key_exists('ajax', $wpdocs_options); |
| 400 |
$is_ajax_url = array_key_exists('ajax_url', $wpdocs_options); |
| 401 |
|
| 402 |
wp_enqueue_script('wpdocs_pro_scripts', $wpdocs_url . 'pro/wp-docs-pro.js', array('jquery'), time()); |
| 403 |
$localize_handler = 'wpdocs_pro_scripts'; |
| 404 |
wp_enqueue_script('wpdocs_block_scripts', $wpdocs_url . 'js/jquery.blockUI.js', array('jquery')); |
| 405 |
|
| 406 |
|
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
wp_enqueue_style('fontawesome', plugins_url('css/fontawesome.min.css', dirname(__FILE__))); |
| 412 |
|
| 413 |
|
| 414 |
wp_enqueue_script('wpdocs_front_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/front-scripts.js', array('jquery'), date('Ymdhi')); |
| 415 |
wp_enqueue_style('wpdocs-common', plugins_url('css/common-styles.css', dirname(__FILE__))); |
| 416 |
wp_enqueue_style('wpdocs-front', plugins_url('css/front-styles.css', dirname(__FILE__)), array(), date('Ymdhi')); |
| 417 |
|
| 418 |
$dir_id = (array_key_exists('dir_id', $_GET)?sanitize_wpdocs_data($_GET['dir_id']):0); |
| 419 |
$dir_id = (!$dir_id && array_key_exists('dir', $_GET)?sanitize_wpdocs_data($_GET['dir']):0); |
| 420 |
|
| 421 |
$params_array = array( |
| 422 |
'dir_id' => $dir_id, |
| 423 |
'parent_dir' => get_permalink($post->ID).'/?dir=', |
| 424 |
'wpdocs_pro' => $wpdocs_pro, |
| 425 |
'details_view_sorting' => $details_view_sorting, |
| 426 |
'ajax_based_deep_search' => $ajax_based_deep_search, |
| 427 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 428 |
'this_url' => get_permalink(), |
| 429 |
'del_confirm' => __('Do you want to delete this file?', 'wp-docs'), |
| 430 |
'del_dir_confirm' => __('Do you want to delete this directory?', 'wp-docs'), |
| 431 |
'select_file_alert' => __('Please select a file to delete.', 'wp-docs'), |
| 432 |
'not_belong_dir_string' => __('Sorry, you can not delete this directory.', 'wp-docs'), |
| 433 |
'not_belong_string' => __('Sorry, you can not delete this file.', 'wp-docs'), |
| 434 |
'copied' => __('Successfully copied!', 'wp-docs'), |
| 435 |
'moved' => __('Successfully moved!', 'wp-docs'), |
| 436 |
'block_ui' => __('Please wait...', 'wp-docs'), |
| 437 |
'is_ajax' => $is_ajax, |
| 438 |
'is_ajax_url' => $is_ajax_url, |
| 439 |
'del_from_front' => array_key_exists('del_from_front', $wpdocs_options), |
| 440 |
'nonce' => wp_create_nonce('wpdocs_update_options_nonce'), |
| 441 |
'restriction_load' => isset($_GET['wpdocs_restriction']), |
| 442 |
'restriction_id' => isset($_GET['wpdocs_restriction']) ? $_GET['wpdocs_restriction'] : '', |
| 443 |
'restriction_container' => isset($_GET['wpdocs_container']) ? $_GET['wpdocs_container'] : '', |
| 444 |
'current_user_id' => get_current_user_id(), |
| 445 |
'current_user_role' => wpdocs_get_current_user_role(), |
| 446 |
|
| 447 |
); |
| 448 |
if($params_array['dir_id'] && $params_array['del_from_front']){ |
| 449 |
$params_array['del_from_front'] = wpdocs_can_current_user_upload_file($params_array['dir_id']); |
| 450 |
} |
| 451 |
|
| 452 |
wp_localize_script( |
| 453 |
$localize_handler, |
| 454 |
'wpdocs', |
| 455 |
$params_array |
| 456 |
); |
| 457 |
|
| 458 |
|
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
if (is_admin()) { |
| 463 |
add_action('admin_menu', 'wpdocs_menu'); |
| 464 |
} |
| 465 |
function wpdocs_menu() |
| 466 |
{ |
| 467 |
global $wpdocs_data, $wpdocs_pro; |
| 468 |
|
| 469 |
$title = $wpdocs_data['Name'] . ' ' . ($wpdocs_pro ? ' ' . __('Pro', 'wp-docs') : ''); |
| 470 |
|
| 471 |
add_options_page($title, $title, 'publish_pages', 'wpdocs', 'wpdocs_settings'); |
| 472 |
} |
| 473 |
function wpdocs_settings() |
| 474 |
{ |
| 475 |
global $wpdocs_premium_link, $wpdocs_pro, $wpdocs_url; |
| 476 |
$wpdocs_options = get_option('wpdocs_options', array()); |
| 477 |
$wpdocs_options = is_array($wpdocs_options)?$wpdocs_options:array(); |
| 478 |
include_once('wpdocs_settings.php'); |
| 479 |
} |
| 480 |
|
| 481 |
function wpdocs_list_inner($post_parent='', $recursive=false, $orderby='post_title', $order='ASC', $exclude_post_type=array()){ |
| 482 |
|
| 483 |
global $wpdb, $wpdocs_post_types, $wpdocs_post_status; |
| 484 |
|
| 485 |
$ids = (is_array($post_parent)?$post_parent:explode(',', $post_parent)); |
| 486 |
$ids = array_map('trim', $ids); |
| 487 |
$ids = array_filter($ids, 'is_numeric'); |
| 488 |
$ids = (empty($ids)?array(0):$ids); |
| 489 |
|
| 490 |
$posts_array = array(); |
| 491 |
|
| 492 |
if(!empty($ids)){ |
| 493 |
|
| 494 |
$post_types = $wpdocs_post_types; |
| 495 |
|
| 496 |
if(!empty($exclude_post_type)){ |
| 497 |
$post_types = array_diff_key($post_types, array_flip($exclude_post_type)); |
| 498 |
} |
| 499 |
//pree($exclude_post_type); |
| 500 |
//pree($post_types);//exit; |
| 501 |
|
| 502 |
if($recursive){ |
| 503 |
unset($post_types['shortcut']); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
$query_str = $wpdb->prepare('SELECT ID, post_title, post_type, post_content, post_parent, guid FROM '.$wpdb->posts.' WHERE post_status=%s AND post_type IN ("'.implode('","', $post_types).'") AND post_parent IN ("'.implode(',', $ids).'") ORDER BY '. $orderby.' '.$order, |
| 508 |
$wpdocs_post_status |
| 509 |
); |
| 510 |
|
| 511 |
//pree($query_str); |
| 512 |
|
| 513 |
$posts_array = $wpdb->get_results($query_str); |
| 514 |
|
| 515 |
if($recursive){ |
| 516 |
$post_parent_arr = array(); |
| 517 |
if(!empty($posts_array)){ |
| 518 |
foreach($posts_array as $posts_item){ |
| 519 |
$post_parent_arr[] = $posts_item->ID; |
| 520 |
} |
| 521 |
if(!empty($post_parent)){ |
| 522 |
|
| 523 |
$posts_array = array_merge($posts_array, wpdocs_list_inner($post_parent_arr, $recursive, $orderby, $order, $exclude_post_type)); |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
} |
| 528 |
|
| 529 |
} |
| 530 |
|
| 531 |
return $posts_array; |
| 532 |
} |
| 533 |
function wpdocs_list($post_parent = 0, $orderby='post_title', $order='ASC', $return_type='smart', $exclude_post_type=array()){ |
| 534 |
|
| 535 |
//pree($post_parent);pree($orderby);pree($order);pree($return_type);pree($exclude_post_type); |
| 536 |
|
| 537 |
global $wpdocs_post_types, $wpdocs_post_status; |
| 538 |
|
| 539 |
$ret = $posts_array = array(); |
| 540 |
|
| 541 |
//global $wpdb; |
| 542 |
|
| 543 |
$args = array( |
| 544 |
'posts_per_page' => -1, |
| 545 |
'offset' => 0, |
| 546 |
'category' => '', |
| 547 |
'category_name' => '', |
| 548 |
'orderby' => $orderby, |
| 549 |
'order' => $order, |
| 550 |
'include' => '', |
| 551 |
'exclude' => '', |
| 552 |
'meta_key' => '', |
| 553 |
'meta_value' => '', |
| 554 |
'post_type' => $wpdocs_post_types, |
| 555 |
'post_mime_type' => '', |
| 556 |
'author' => '', |
| 557 |
'author_name' => '', |
| 558 |
'post_status' => $wpdocs_post_status, |
| 559 |
'suppress_filters' => true |
| 560 |
); |
| 561 |
|
| 562 |
if(is_numeric($post_parent)) { |
| 563 |
$args['post_parent'] = $post_parent; |
| 564 |
$posts_array = get_posts($args); |
| 565 |
//pree($wpdb->last_query); |
| 566 |
}else{ |
| 567 |
|
| 568 |
switch($orderby){ |
| 569 |
case 'title': |
| 570 |
case 'post_title': |
| 571 |
$orderby = 'post_title'; |
| 572 |
break; |
| 573 |
case 'date': |
| 574 |
case 'post_date': |
| 575 |
$orderby = 'post_date'; |
| 576 |
break; |
| 577 |
} |
| 578 |
//pree($exclude_post_type); |
| 579 |
$posts_array = wpdocs_list_inner($post_parent, false, $orderby, $order, $exclude_post_type); |
| 580 |
|
| 581 |
|
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
if (!empty($posts_array)) { |
| 586 |
foreach ($posts_array as $posts) { //pree($posts); |
| 587 |
switch($return_type){ |
| 588 |
default: |
| 589 |
case 'smart': |
| 590 |
$guid_pos = strpos($posts->guid, 'p='.$posts->ID); |
| 591 |
$posts->guid = ($guid_pos!='' && $guid_pos>=0?'':$posts->guid); |
| 592 |
$ret[] = array('id' => $posts->ID, 'title' => $posts->post_title, 'type' => $posts->post_type, 'content' => $posts->post_content, 'link' => $posts->guid); |
| 593 |
break; |
| 594 |
case 'object': |
| 595 |
$ret[] = $posts; |
| 596 |
break; |
| 597 |
} |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
//pree($ret); |
| 602 |
|
| 603 |
return $ret; |
| 604 |
} |
| 605 |
|
| 606 |
function wpdocs_create_folder_post($post_parent, $post_title = "New Folder") |
| 607 |
{ |
| 608 |
|
| 609 |
$my_post = array( |
| 610 |
'post_title' => $post_title, |
| 611 |
'post_content' => '', |
| 612 |
'post_status' => 'hidden', |
| 613 |
'post_author' => get_current_user_id(), |
| 614 |
'post_type' => 'wpdocs_folder', |
| 615 |
'post_parent' => (($post_parent > 0 && wpdocs_folder_exists($post_parent)) ? $post_parent : 0), |
| 616 |
'post_category' => array() |
| 617 |
); |
| 618 |
|
| 619 |
$dir_id = wp_insert_post($my_post); |
| 620 |
|
| 621 |
return $dir_id; |
| 622 |
} |
| 623 |
|
| 624 |
add_action('wp_ajax_wpdocs_create_folder', 'wpdocs_create_folder'); |
| 625 |
|
| 626 |
function wpdocs_create_folder() |
| 627 |
{ |
| 628 |
$nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce'])); |
| 629 |
|
| 630 |
if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) ) |
| 631 |
die (__("Sorry, your nonce did not verify.", 'wp-docs')); |
| 632 |
|
| 633 |
$post_parent = sanitize_wpdocs_data($_POST['parent_dir']); |
| 634 |
|
| 635 |
$dir_id = wpdocs_create_folder_post($post_parent); |
| 636 |
|
| 637 |
$list_obj = get_post($dir_id); |
| 638 |
|
| 639 |
$list = array('id'=>$list_obj->ID, 'content'=>$list_obj->post_content, 'title'=>$list_obj->post_title, 'type'=>$list_obj->post_type, 'guid'=>$list_obj->guid); |
| 640 |
|
| 641 |
$is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']); |
| 642 |
|
| 643 |
echo '<li class="ab-dir ab-new" data-id="'.$dir_id.'" data-resource='.base64_encode($dir_id).'" data-linked="'.$list['content'].'" data-guid="'.($is_shortcut?$list['guid']:'').'"><a class="folder fa fa-folder"></a><a class="dtitle" title="'.__('Click here to rename', 'wp-docs').'">'.__('New Folder', 'wp-docs').'</a><span class="wpd_action_span"><a class="wpd-edit" title="'.__('Click here to edit', 'wp-docs').'"></a><span class="wpd_action_span_inner"><a class="wpd-copy" title="'.__('Click here to copy', 'wp-docs').'"></a><a class="wpd-move" title="'.__('Click here to move', 'wp-docs').'"></a></span><a class="wpd-trash" title="'.__('Click here to delete', 'wp-docs').'"></a></span></li>'; |
| 644 |
|
| 645 |
exit; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
if(!function_exists('wpd_get_icon_file_types')){ |
| 650 |
|
| 651 |
function wpd_get_icon_file_types(){ |
| 652 |
|
| 653 |
global $icon_sub_path, $wpdocs_dir; |
| 654 |
|
| 655 |
$ext_img_dir = $wpdocs_dir.$icon_sub_path; |
| 656 |
|
| 657 |
$file_types = file_exists($ext_img_dir) && is_dir($ext_img_dir) ? scandir($ext_img_dir) : array(); |
| 658 |
|
| 659 |
$file_types = array_map(function ($file) use ($ext_img_dir){ |
| 660 |
|
| 661 |
$ignore_array = array('.', '..'); |
| 662 |
if(!in_array($file, $ignore_array) && !is_dir($ext_img_dir.$file)){ |
| 663 |
return current(explode('.', $file)); |
| 664 |
} |
| 665 |
|
| 666 |
}, $file_types); |
| 667 |
|
| 668 |
$file_types = array_filter($file_types); |
| 669 |
|
| 670 |
return $file_types; |
| 671 |
|
| 672 |
} |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
if(!function_exists('wpd_get_item_type_icon_url')){ |
| 677 |
|
| 678 |
function wpd_get_item_type_icon_url($item){ |
| 679 |
|
| 680 |
//pree($item); |
| 681 |
|
| 682 |
global $wpdocs_url, $icon_sub_path, $wpdocs_options, $wpdocs_pro; |
| 683 |
|
| 684 |
$ext_img_url = $wpdocs_url.$icon_sub_path; |
| 685 |
$file_types = wpd_get_icon_file_types(); |
| 686 |
|
| 687 |
$file_url = wp_get_attachment_url($item); |
| 688 |
//pree($file_url);exit; |
| 689 |
|
| 690 |
|
| 691 |
$filename = basename($file_url); |
| 692 |
$filename = explode('?', $filename); |
| 693 |
$filename = (is_array($filename)?current($filename):$filename); |
| 694 |
|
| 695 |
|
| 696 |
$ext = explode('.', $filename); |
| 697 |
$ext = end($ext); |
| 698 |
$icon = in_array($ext, $file_types) ? $ext.'.png' : 'unknown.png'; |
| 699 |
$icon_url = $ext_img_url.$icon; |
| 700 |
|
| 701 |
switch($ext){ |
| 702 |
case 'svg': |
| 703 |
case 'gif': |
| 704 |
case 'bmp': |
| 705 |
case 'jpg': |
| 706 |
case 'jpeg': |
| 707 |
case 'png': |
| 708 |
$thumb_image = array_key_exists('thumb_image', $wpdocs_options); |
| 709 |
|
| 710 |
if($thumb_image){ |
| 711 |
$icon_urls = wp_get_attachment_image_src($item, 'thumbnail', false); |
| 712 |
if(!empty($icon_urls)){ |
| 713 |
$icon_url = current($icon_urls); |
| 714 |
} |
| 715 |
} |
| 716 |
//pree($icon_urls); |
| 717 |
break; |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
return array( |
| 724 |
|
| 725 |
'file_url' => $file_url, |
| 726 |
'ext' => $ext, |
| 727 |
'filename' => $filename, |
| 728 |
'title' => $filename, |
| 729 |
'icon_url' => $icon_url |
| 730 |
); |
| 731 |
|
| 732 |
|
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
add_action('wp_ajax_wpdocs_add_files', 'wpdocs_add_files'); |
| 737 |
|
| 738 |
function wpdocs_add_files(){ |
| 739 |
|
| 740 |
$nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce'])); |
| 741 |
|
| 742 |
if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) ) |
| 743 |
die (__("Sorry, your nonce did not verify.", 'wp-docs')); |
| 744 |
|
| 745 |
|
| 746 |
$dir_id = sanitize_wpdocs_data($_POST['dir_id']); |
| 747 |
$files = sanitize_wpdocs_data($_POST['files']); |
| 748 |
$files = is_array($files) ? $files : array($files); |
| 749 |
|
| 750 |
// delete_post_meta($dir_id, 'wpdocs_items'); |
| 751 |
|
| 752 |
wpdocs_update_files_meta($dir_id, $files); |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
$ret = ''; |
| 757 |
|
| 758 |
if(!empty($files)){ |
| 759 |
$files_list = wpdocs_list_added_items($dir_id); |
| 760 |
|
| 761 |
$ret = $files_list; |
| 762 |
} |
| 763 |
|
| 764 |
echo $ret; |
| 765 |
exit; |
| 766 |
} |
| 767 |
function wpdocs_list_added_items($dir) |
| 768 |
{ |
| 769 |
|
| 770 |
global $wpdocs_options, $icon_sub_path, $wpdocs_url; |
| 771 |
|
| 772 |
$wp_get_upload_dir = wp_get_upload_dir(); |
| 773 |
$wp_uploads_path = $wp_get_upload_dir['basedir']; |
| 774 |
$wp_uploads_url = $wp_get_upload_dir['baseurl']; |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
$wpdocs_items = wpdocs_added_items($dir); //pree($wpdocs_items); |
| 779 |
$files_list = array(); |
| 780 |
$pdf_thumb_selected = (array_key_exists('pdf_thumb', $wpdocs_options)?$wpdocs_options['pdf_thumb']:'default'); |
| 781 |
|
| 782 |
if (!empty($wpdocs_items)) { |
| 783 |
//pree('$wpdocs_items'); |
| 784 |
|
| 785 |
foreach ($wpdocs_items as $item) { |
| 786 |
$class = ''; |
| 787 |
|
| 788 |
$item_data = wpd_get_item_type_icon_url($item); |
| 789 |
extract($item_data); |
| 790 |
|
| 791 |
//pree($item_data); |
| 792 |
//pree($wp_uploads_path);exit; |
| 793 |
|
| 794 |
$icon_str = '<img src="'.$icon_url.'" style="">'; |
| 795 |
|
| 796 |
switch ($ext) { |
| 797 |
case 'png': |
| 798 |
case 'jpg': |
| 799 |
case 'jpeg': |
| 800 |
case 'gif': |
| 801 |
case 'bmp': |
| 802 |
|
| 803 |
//$class .= 'fa-image'; |
| 804 |
|
| 805 |
break; |
| 806 |
|
| 807 |
case 'pdf': |
| 808 |
|
| 809 |
if($pdf_thumb_selected=='first_page_as_thumbnail'){ |
| 810 |
|
| 811 |
$pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $item_data['file_url']); |
| 812 |
|
| 813 |
if(file_exists($pdf_file) && class_exists('imagick')){ |
| 814 |
|
| 815 |
//pree($item_data); |
| 816 |
//$icon_str = '<object style="width: 100px; height: 100px" data="'.$item_data['file_url'].'#page=1" type="application/pdf"></object>'; |
| 817 |
|
| 818 |
$file_url_thumb = str_replace('.pdf', '.png', strtolower($item_data['file_url'])); |
| 819 |
$file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb); |
| 820 |
|
| 821 |
if(!file_exists($file_url_thumb_path) && class_exists('imagick')){ |
| 822 |
|
| 823 |
try { |
| 824 |
$im = new imagick($item_data['file_url']); |
| 825 |
$im->setIteratorIndex(0); |
| 826 |
$im->setImageFormat('png'); |
| 827 |
$im->writeImage($file_url_thumb_path); |
| 828 |
} catch (ImagickException $e) { |
| 829 |
|
| 830 |
if(defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG){ |
| 831 |
error_log("Imagick error: " . $e->getMessage()); |
| 832 |
error_log('file_url: '.$item_data['file_url']); |
| 833 |
error_log('file_url_thumb_path: '.$file_url_thumb_path); |
| 834 |
} |
| 835 |
|
| 836 |
$file_url_thumb = $wpdocs_url.$icon_sub_path.$ext.'.png'; |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
} |
| 841 |
|
| 842 |
$icon_str = '<img src="'.$file_url_thumb.'" style="">'; |
| 843 |
|
| 844 |
} |
| 845 |
|
| 846 |
} |
| 847 |
|
| 848 |
break; |
| 849 |
|
| 850 |
default: |
| 851 |
//$class .= 'fa-file'; |
| 852 |
break; |
| 853 |
} |
| 854 |
$class = ''; |
| 855 |
$files_list[$title] = '<li data-id="' . $item . '" data-dir="'.$dir. '" title="'.esc_attr($filename).'"> |
| 856 |
<a href="' . $file_url . '" target="_blank" class="file ' . $class . '"> '.$icon_str.' </a> |
| 857 |
<a class="ftitle" title="' . $title . '">' . $title . '</a> |
| 858 |
<span class="wpd_action_span"> |
| 859 |
<a href="upload.php?item='.$item.'" target="_blank" class="wpd-edit" title="'.__('Click here to edit', 'wp-docs').'"></a> |
| 860 |
<span class="wpd_action_span_inner"> |
| 861 |
<a class="wpd-copy" title="'.__('Click here to copy', 'wp-docs').'"></a> |
| 862 |
<a class="wpd-move" title="'.__('Click here to move', 'wp-docs').'"></a> |
| 863 |
</span> |
| 864 |
|
| 865 |
<a href="upload.php?search='.esc_attr($filename).'" target="_blank" class="wpd-trash" title="'.__('Click here to delete', 'wp-docs').'"></a> |
| 866 |
</span> |
| 867 |
</li>'; |
| 868 |
} |
| 869 |
} |
| 870 |
|
| 871 |
ksort($files_list); |
| 872 |
|
| 873 |
return implode('', $files_list); |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
if(!function_exists('wpdocs_get_breadcrumb_array')){ |
| 878 |
function wpdocs_get_breadcrumb_array($dir, $breadcrumb=true){ |
| 879 |
|
| 880 |
$breadcrumb_array = array(); |
| 881 |
|
| 882 |
if ($breadcrumb && $dir) { |
| 883 |
$dir_id = $dir; |
| 884 |
|
| 885 |
$dir_parent = wp_get_post_parent_id($dir_id); |
| 886 |
array_push($breadcrumb_array, $dir_id); |
| 887 |
array_push($breadcrumb_array, $dir_parent); |
| 888 |
|
| 889 |
|
| 890 |
if ($dir_parent != 0) { |
| 891 |
do { |
| 892 |
|
| 893 |
$dir_parent = wp_get_post_parent_id($dir_parent); |
| 894 |
array_push($breadcrumb_array, $dir_parent); |
| 895 |
} while ($dir_parent > 0); |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
|
| 900 |
return $breadcrumb_array; |
| 901 |
|
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
if(!function_exists('wpdocs_list_population')){ |
| 906 |
function wpdocs_list_population($list=array(), $file_data=array(), $file_list_row='', $default_orderby='', $default_order=''){ |
| 907 |
$filename = $file_data['filename']; |
| 908 |
$list[$filename] = $file_list_row; |
| 909 |
return $list; |
| 910 |
} |
| 911 |
} |
| 912 |
|
| 913 |
if(!function_exists('wpdocs_sorting')){ |
| 914 |
function wpdocs_sorting($list, $order=''){ |
| 915 |
ksort($list); |
| 916 |
return $list; |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
add_shortcode('wpdocs', 'wpdocs_front_list'); |
| 921 |
|
| 922 |
function wpdocs_front_list($atts=array()) |
| 923 |
{ |
| 924 |
|
| 925 |
if ( |
| 926 |
!empty($_POST) && !wp_doing_ajax() && |
| 927 |
( |
| 928 |
(isset( $_POST['wpdocs_front_list_nonce'] ) && ! wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wpdocs_front_list_nonce_field'])), 'wpdocs_front_list_nonce' ) ) |
| 929 |
) |
| 930 |
) { |
| 931 |
|
| 932 |
print _e('Sorry, your nonce did not verify.', 'wp-docs'); |
| 933 |
exit; |
| 934 |
|
| 935 |
} else { |
| 936 |
|
| 937 |
} |
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
//pree($atts); |
| 943 |
ob_start(); |
| 944 |
global $wpdocs_url, $wpdocs_options, $wpdocs_pro, $wpdocs_post_types, $pdf_thumb_selected, $icon_sub_path; |
| 945 |
|
| 946 |
$pdf_thumb_selected = (array_key_exists('pdf_thumb', $wpdocs_options)?$wpdocs_options['pdf_thumb']:'default'); |
| 947 |
|
| 948 |
$wpdocs_view = get_option('wpdocs_view', array()); |
| 949 |
$wpdocs_view = is_array($wpdocs_view) ? $wpdocs_view : array(); |
| 950 |
|
| 951 |
$is_bootstrap = array_key_exists('bootstrap', $wpdocs_options); |
| 952 |
$is_searchbox = array_key_exists('searchbox', $wpdocs_options); |
| 953 |
|
| 954 |
$details_date = array_key_exists('details_date', $wpdocs_options); |
| 955 |
$details_date_created = array_key_exists('details_date_created', $wpdocs_options); |
| 956 |
$details_view_sorting = array_key_exists('details_view_sorting', $wpdocs_options); |
| 957 |
$ajax_based_deep_search = ($wpdocs_pro && array_key_exists('ajax_based_deep_search', $wpdocs_options)); |
| 958 |
$details_type = array_key_exists('details_type', $wpdocs_options); |
| 959 |
$details_size = array_key_exists('details_size', $wpdocs_options); |
| 960 |
|
| 961 |
$customize_icon_size = array_key_exists('icon_size', $wpdocs_options) ? $wpdocs_options['icon_size'] : ''; |
| 962 |
$customize_icon_size = ($customize_icon_size?$customize_icon_size: 'font-size:100%'); |
| 963 |
$customize_icon_size = explode(':', $customize_icon_size); |
| 964 |
$customize_icon_size = 'font-size:'.end($customize_icon_size); |
| 965 |
|
| 966 |
$customize_font_size = array_key_exists('font_size', $wpdocs_options) ? $wpdocs_options['font_size'] : ''; |
| 967 |
$customize_font_size = ($customize_font_size?$customize_font_size: 'font-size:90%'); |
| 968 |
$customize_font_size = explode(':', $customize_font_size); |
| 969 |
$customize_font_size = 'font-size:'.end($customize_font_size); |
| 970 |
|
| 971 |
$wp_get_upload_dir = wp_get_upload_dir(); |
| 972 |
$wp_uploads_path = $wp_get_upload_dir['basedir']; |
| 973 |
|
| 974 |
$wp_uploads_url = home_url('wp-content/uploads'); |
| 975 |
|
| 976 |
|
| 977 |
if(isset($_POST['wpd_dir_id_ajax'])){ |
| 978 |
|
| 979 |
$dir = ((isset($_POST['wpd_dir_id_ajax']) && wpdocs_folder_exists($_POST['wpd_dir_id_ajax'])) ? $_POST['wpd_dir_id_ajax'] : 0); |
| 980 |
if($_POST['wpd_dir_id_ajax'] == 0 && $_POST['wpd_home_id'] != 0){ |
| 981 |
$dir = sanitize_wpdocs_data($_POST['wpd_home_id']); |
| 982 |
} |
| 983 |
$get_permalink = isset($_POST['wpd_get_permalink']) ? $_POST['wpd_get_permalink'] : '' ; |
| 984 |
|
| 985 |
}else{ |
| 986 |
|
| 987 |
$dir = ((isset($_GET['dir']) && is_numeric($_GET['dir']) && wpdocs_folder_exists($_GET['dir'])) ? sanitize_wpdocs_data($_GET['dir']) : 0); |
| 988 |
$get_permalink = get_permalink(); |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
$dir = ($dir?$dir:((isset($atts['dir']) && $atts['dir']!='' && is_numeric($atts['dir']) && wpdocs_folder_exists($atts['dir']))?sanitize_wpdocs_data($atts['dir']):$dir)); |
| 995 |
$no_breadcrumb = (isset($atts['breadcrumb']) && $atts['breadcrumb']=='false'); |
| 996 |
$default_view = (isset($atts['view']) ? $atts['view'] : 'list'); |
| 997 |
$default_orderby = (isset($atts['orderby']) ? $atts['orderby'] : 'title'); |
| 998 |
$default_order = (isset($atts['order']) ? $atts['order'] : 'ASC'); |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
switch($default_view){ |
| 1003 |
default: |
| 1004 |
case 'list': |
| 1005 |
$default_view = 'list_view'; |
| 1006 |
break; |
| 1007 |
|
| 1008 |
case 'icons': |
| 1009 |
$default_view = 'large_icon_view'; |
| 1010 |
break; |
| 1011 |
|
| 1012 |
case 'details': |
| 1013 |
$default_view = 'detail_view'; |
| 1014 |
break; |
| 1015 |
|
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
if(isset($_POST['wpd_home_id'])){ |
| 1021 |
|
| 1022 |
$home_id = sanitize_wpdocs_data($_POST['wpd_home_id']); |
| 1023 |
|
| 1024 |
}elseif(isset($atts['dir'])){ |
| 1025 |
$home_id = sanitize_wpdocs_data($atts['dir']); |
| 1026 |
}else{ |
| 1027 |
$home_id = 0; |
| 1028 |
} |
| 1029 |
|
| 1030 |
$home_id = preg_replace("/[\'\"\"\"]+/", '', $home_id); |
| 1031 |
|
| 1032 |
$wpdoc_valid = true; |
| 1033 |
|
| 1034 |
$wpdocs_security = get_post_meta($dir, 'wpdocs_security', true); |
| 1035 |
//pree($wpdocs_security); |
| 1036 |
$roles = array(); |
| 1037 |
if($wpdocs_security!=''){ |
| 1038 |
if( is_user_logged_in() ) { |
| 1039 |
$user = wp_get_current_user(); |
| 1040 |
$roles = ( array ) $user->roles; |
| 1041 |
//pree($roles); |
| 1042 |
$wpdoc_valid = (in_array($wpdocs_security, $roles) || current_user_can('administrator')); |
| 1043 |
}else{ |
| 1044 |
$wpdoc_valid = false; |
| 1045 |
} |
| 1046 |
|
| 1047 |
} |
| 1048 |
|
| 1049 |
//pree($wpdoc_valid);exit; |
| 1050 |
|
| 1051 |
$breadcrumb_array = wpdocs_get_breadcrumb_array($dir, !$no_breadcrumb); |
| 1052 |
//pree($breadcrumb_array); |
| 1053 |
//pree($wpdoc_valid); |
| 1054 |
$warning_msg = ''; |
| 1055 |
if(!$wpdoc_valid){ |
| 1056 |
$dir = time()*time(); |
| 1057 |
$warning_msg = '<div class="alert alert-warning fade in alert-dismissible show w-50 mx-auto"> |
| 1058 |
<button type="button" class="close" data-dismiss="alert" aria-label="'.__('Close', 'wp-docs').'"> |
| 1059 |
<span aria-hidden="true" style="font-size:20px">×</span> |
| 1060 |
</button> <strong>'.__('Sorry', 'wp-docs').'!</strong> '.__('You are not allowed to access this content.', 'wp-docs').' |
| 1061 |
</div>'; |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
//pree($dir.' ~ '.$no_breadcrumb); |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
if(is_array($breadcrumb_array) && !empty($breadcrumb_array)){ |
| 1070 |
|
| 1071 |
|
| 1072 |
$array_search = array_search($home_id , $breadcrumb_array); |
| 1073 |
|
| 1074 |
if($array_search === 0){ |
| 1075 |
|
| 1076 |
unset($breadcrumb_array); |
| 1077 |
|
| 1078 |
}else{ |
| 1079 |
|
| 1080 |
$breadcrumb_array[$array_search] = 0; |
| 1081 |
|
| 1082 |
} |
| 1083 |
|
| 1084 |
if(!empty($breadcrumb_array)){ |
| 1085 |
|
| 1086 |
foreach ($breadcrumb_array as $index => $bread){ |
| 1087 |
|
| 1088 |
if($index > $array_search){ |
| 1089 |
unset($breadcrumb_array[$index]); |
| 1090 |
} |
| 1091 |
} |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
$wpdocs_list = wpdocs_list($dir, $default_orderby, $default_order); |
| 1096 |
|
| 1097 |
$files_list = wpdocs_added_items($dir); |
| 1098 |
|
| 1099 |
//pree($files_list); |
| 1100 |
|
| 1101 |
$wpdocs_list_merged_arr = array(); |
| 1102 |
|
| 1103 |
$deep_files_list_arr = array(); |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
//pree($wpdocs_list); |
| 1108 |
//pree($wpdocs_list_merged_arr); |
| 1109 |
//pree($deep_files_list_arr); |
| 1110 |
//pree($files_list); |
| 1111 |
|
| 1112 |
$is_file = wpdocs_dir_options_by_name('file_upload', false, $dir); |
| 1113 |
$is_del_from_front = (is_user_logged_in() && wpdocs_dir_options_by_name('del_from_front', false, $dir)); |
| 1114 |
$is_current_user_files = wpdocs_dir_options_by_name('current_user_files', false, $dir); |
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
if($is_file && $is_current_user_files){ |
| 1119 |
$files_list = wpdocs_added_items_by_user($dir); |
| 1120 |
|
| 1121 |
//pree($files_list); |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
if(!$is_current_user_files && $ajax_based_deep_search && function_exists('get_deep_files_list_arr')){ |
| 1126 |
|
| 1127 |
//pree($wpdocs_list); |
| 1128 |
|
| 1129 |
$deep_list_arr = get_deep_files_list_arr($wpdocs_list); |
| 1130 |
$wpdocs_list_merged_arr = $deep_list_arr['wpdocs_list_merged_arr']; |
| 1131 |
$deep_files_list_arr = $deep_list_arr['deep_files_list_arr']; |
| 1132 |
|
| 1133 |
} |
| 1134 |
|
| 1135 |
?> |
| 1136 |
|
| 1137 |
|
| 1138 |
<div class="container-fluid wpdoc_container" data-dir_restrictions = "<?php echo wpdocs_get_dir_restrictions($dir, 'base64'); ?>" data-del_from_front="<?php echo $is_del_from_front; ?>" data-dir="<?php echo $dir; ?>" data-home="<?php echo $home_id; ?>"> |
| 1139 |
<?php wp_nonce_field( 'wpdocs_front_list_nonce', 'wpdocs_front_list_nonce_field' ); ?> |
| 1140 |
<input type="hidden" class="wpd_home_id" value="<?php echo esc_html($home_id); ?>" /> |
| 1141 |
<input type="hidden" class="wpd_del_file_id" value="" /> |
| 1142 |
<?php |
| 1143 |
|
| 1144 |
$wpdocs_view = array_key_exists($home_id, $wpdocs_view) ? $wpdocs_view[$home_id] : trim($default_view); |
| 1145 |
|
| 1146 |
?> |
| 1147 |
|
| 1148 |
<div class="card mt-3"> |
| 1149 |
<!-- breadcrumb Area --> |
| 1150 |
<nav aria-label="breadcrumb" class="wpdocs-nav position-relative"> |
| 1151 |
<ol class="breadcrumb bg-light" style="border-bottom:1px solid #dee2e6;border-radius: 0; min-height: 40px;"> |
| 1152 |
|
| 1153 |
<?php if (!empty($breadcrumb_array)) { ?> |
| 1154 |
|
| 1155 |
<li class="breadcrumb-item bread_home_url"><a class="wpd_bread_item" href="<?php echo $get_permalink ?>" data-id="0"><?php _e('Home', 'wp-docs'); ?></a></li> |
| 1156 |
<?php |
| 1157 |
|
| 1158 |
foreach (array_reverse($breadcrumb_array) as $bread_key => $bread_value) { |
| 1159 |
$active = ''; |
| 1160 |
$page = ''; |
| 1161 |
$permalink = stripos($get_permalink, '?'); |
| 1162 |
$permalink_c = ($permalink!='' && is_numeric($permalink) && $permalink>=0); |
| 1163 |
$link = '<a class="wpd_bread_item" href="' . $get_permalink . ($permalink_c?'&':'?').'dir=' . $bread_value . '" data-id="'.$bread_value.'" >' . get_the_title($bread_value) . '</a>'; |
| 1164 |
if ($bread_value == 0) { |
| 1165 |
continue; |
| 1166 |
} |
| 1167 |
if ($bread_value == $dir) { |
| 1168 |
$active = 'active'; |
| 1169 |
$page = 'page'; |
| 1170 |
$link = get_the_title($bread_value); |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
?> |
| 1175 |
<li class="breadcrumb-item <?php echo $active ?>" aria-current="<?php echo $page; ?>"><?php echo $link; ?></li> |
| 1176 |
|
| 1177 |
<?php } ?> |
| 1178 |
<?php |
| 1179 |
} |
| 1180 |
|
| 1181 |
?> |
| 1182 |
|
| 1183 |
</ol> |
| 1184 |
|
| 1185 |
<?php if($is_del_from_front):?> |
| 1186 |
|
| 1187 |
<i style="opacity: 0.5;" class="fa fa-trash fa-1x position-absolute wp_docs_del_file <?php echo (is_user_logged_in()?'logged_in':'logged_out'); ?>" title="<?php _e('Click here to delete selected files', 'wp-docs'); ?>"></i> |
| 1188 |
|
| 1189 |
<?php endif; ?> |
| 1190 |
|
| 1191 |
<?php if($wpdocs_pro && $dir != 0 && wpdocs_can_current_user_upload_file($dir) && $is_file):?> |
| 1192 |
|
| 1193 |
<i class="fa fa-upload fa-1x wpdocs-front-add-media position-absolute" id="wpdocs_front_file_add_<?php echo $dir; ?>" title="<?php _e('Click here to add files', 'wp-docs'); ?>"></i> |
| 1194 |
|
| 1195 |
<?php endif; ?> |
| 1196 |
</nav> |
| 1197 |
<?php |
| 1198 |
/* |
| 1199 |
$current_user_id = get_current_user_id(); |
| 1200 |
|
| 1201 |
pree($current_user_id); |
| 1202 |
|
| 1203 |
|
| 1204 |
$args = array( |
| 1205 |
'posts_per_page' => -1, |
| 1206 |
'offset' => 0, |
| 1207 |
'category' => '', |
| 1208 |
'category_name' => '', |
| 1209 |
'orderby' => 'title', |
| 1210 |
'order' => 'ASC', |
| 1211 |
'include' => array($dir), |
| 1212 |
'exclude' => '', |
| 1213 |
'meta_key' => '', |
| 1214 |
'meta_value' => '', |
| 1215 |
'post_type' => 'wpdocs_folder', |
| 1216 |
'post_mime_type' => '', |
| 1217 |
'post_parent' => '',//$post_parent, |
| 1218 |
'author' => $current_user_id, |
| 1219 |
'author_name' => '', |
| 1220 |
'post_status' => 'hidden', |
| 1221 |
'suppress_filters' => true |
| 1222 |
); |
| 1223 |
$posts_array = get_posts($args); |
| 1224 |
pree($posts_array); |
| 1225 |
*/ |
| 1226 |
?> |
| 1227 |
|
| 1228 |
<?php echo $warning_msg?'<div class="card-body">'.$warning_msg.'</div>':''; ?> |
| 1229 |
|
| 1230 |
<?php if($is_searchbox || $ajax_based_deep_search): ?> |
| 1231 |
<div class="wpdocs-searchbox"> |
| 1232 |
<input type="text" placeholder="<?php echo ($ajax_based_deep_search?__('Type here to search...', 'wp-docs'):__('Type here to filter...', 'wp-docs')); ?>" /> |
| 1233 |
</div> |
| 1234 |
<?php endif; ?> |
| 1235 |
|
| 1236 |
<div class="card-body <?php echo $warning_msg?'d-none':''; ?>"> |
| 1237 |
|
| 1238 |
<!-- Large Icon View Area --> |
| 1239 |
<div class="row folder_view large_icon_view <?php echo $wpdocs_view=='large_icon_view'?'':'d-none'; ?>"> |
| 1240 |
<?php |
| 1241 |
|
| 1242 |
//pree($wpdocs_list); |
| 1243 |
|
| 1244 |
$no_dir_found = false; |
| 1245 |
$no_file_found = false; |
| 1246 |
if (!empty($wpdocs_list)) { |
| 1247 |
foreach ($wpdocs_list as $list) { |
| 1248 |
//$wpdocs_child_items = wpdocs_list($list['id']); |
| 1249 |
//$wpdocs_child_files_list = wpdocs_added_items($list['id']); |
| 1250 |
$is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']); |
| 1251 |
?> |
| 1252 |
|
| 1253 |
<div class="col-4 col-md-3 file_wrapper is_dir" style="cursor: pointer;" data-id="<?php echo $list['id']; ?>" data-resource="<?php echo base64_encode($list['id']); ?>" data-linked="<?php echo $list['content']; ?>" data-guid="<?php echo $is_shortcut?$list['link']:''; ?>"> |
| 1254 |
<figure class="figure file_view p-0"> |
| 1255 |
<span class="fa fa-folder text-warning" style="<?php echo $customize_icon_size; ?>"></span> |
| 1256 |
<figcaption class="figure-caption text-center" style="<?php echo $customize_font_size; ?>"><?php echo $list['title']; ?></figcaption> |
| 1257 |
</figure> |
| 1258 |
</div> |
| 1259 |
<?php |
| 1260 |
} |
| 1261 |
} else { |
| 1262 |
$no_dir_found = true; |
| 1263 |
} |
| 1264 |
|
| 1265 |
//pree($wpdocs_list_merged_arr); |
| 1266 |
|
| 1267 |
if (!empty($wpdocs_list_merged_arr)) { |
| 1268 |
|
| 1269 |
foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) { |
| 1270 |
|
| 1271 |
foreach ($wpdocs_merged_list as $list_obj) { |
| 1272 |
|
| 1273 |
$list = array('id'=>$list_obj->ID, 'content'=>$list_obj->post_content, 'title'=>$list_obj->post_title, 'type'=>$list_obj->post_type, 'guid'=>$list_obj->guid); |
| 1274 |
$is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']); |
| 1275 |
|
| 1276 |
?> |
| 1277 |
<div class="col-4 col-md-3 file_wrapper is_dir is_deep" style="cursor: pointer;" data-id="<?php echo $list['id']; ?>" data-resource="<?php echo base64_encode($list['id']); ?>" data-linked="<?php echo $list['content']; ?>" data-guid="<?php echo $is_shortcut?$list['guid']:''; ?>"> |
| 1278 |
<figure class="figure file_view p-0"> |
| 1279 |
<span class="fa fa-folder text-warning" style="<?php echo $customize_icon_size; ?>"></span> |
| 1280 |
<figcaption class="figure-caption text-center" style="<?php echo $customize_font_size; ?>"><?php echo $list['title']; ?></figcaption> |
| 1281 |
</figure> |
| 1282 |
</div> |
| 1283 |
<?php |
| 1284 |
} |
| 1285 |
} |
| 1286 |
} |
| 1287 |
|
| 1288 |
//pree($files_list); |
| 1289 |
|
| 1290 |
|
| 1291 |
if (!empty($files_list)) { |
| 1292 |
$list = array(); |
| 1293 |
foreach ($files_list as $file) { |
| 1294 |
|
| 1295 |
$file_data = wpd_get_item_type_icon_url($file); |
| 1296 |
extract($file_data); |
| 1297 |
|
| 1298 |
//pree($file_data);exit; |
| 1299 |
|
| 1300 |
if(trim($file_url)){ |
| 1301 |
|
| 1302 |
switch ($ext) { |
| 1303 |
case 'png': |
| 1304 |
case 'jpg': |
| 1305 |
case 'jpeg': |
| 1306 |
case 'gif': |
| 1307 |
case 'bmp': |
| 1308 |
|
| 1309 |
//$class .= 'fa-image'; |
| 1310 |
|
| 1311 |
break; |
| 1312 |
|
| 1313 |
case 'pdf': |
| 1314 |
|
| 1315 |
if($pdf_thumb_selected=='first_page_as_thumbnail'){ |
| 1316 |
|
| 1317 |
$pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $file_data['file_url']); |
| 1318 |
|
| 1319 |
if(file_exists($pdf_file) && class_exists('imagick')){ |
| 1320 |
|
| 1321 |
//pree($file_data); |
| 1322 |
//$icon_str = '<object style="width: 100px; height: 100px" data="'.$file_data['file_url'].'#page=1" type="application/pdf"></object>'; |
| 1323 |
|
| 1324 |
$file_url_thumb = str_replace('.pdf', '.png', strtolower($file_data['file_url'])); |
| 1325 |
$file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb); |
| 1326 |
|
| 1327 |
if(!file_exists($file_url_thumb_path) && class_exists('imagick')){ |
| 1328 |
|
| 1329 |
try { |
| 1330 |
$im = new imagick($item_data['file_url']); |
| 1331 |
$im->setIteratorIndex(0); |
| 1332 |
$im->setImageFormat('png'); |
| 1333 |
$im->writeImage($file_url_thumb_path); |
| 1334 |
} catch (ImagickException $e) { |
| 1335 |
|
| 1336 |
if(defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG){ |
| 1337 |
error_log("Imagick error: " . $e->getMessage()); |
| 1338 |
error_log('file_url: '.$item_data['file_url']); |
| 1339 |
error_log('file_url_thumb_path: '.$file_url_thumb_path); |
| 1340 |
} |
| 1341 |
|
| 1342 |
$file_url_thumb = $wpdocs_url.$icon_sub_path.$ext.'.png'; |
| 1343 |
} |
| 1344 |
|
| 1345 |
|
| 1346 |
} |
| 1347 |
|
| 1348 |
|
| 1349 |
$icon_url = $file_url_thumb; |
| 1350 |
|
| 1351 |
} |
| 1352 |
|
| 1353 |
} |
| 1354 |
|
| 1355 |
break; |
| 1356 |
|
| 1357 |
default: |
| 1358 |
//$class .= 'fa-file'; |
| 1359 |
break; |
| 1360 |
} |
| 1361 |
|
| 1362 |
$file_list_row = ' |
| 1363 |
|
| 1364 |
|
| 1365 |
<div title="'.esc_attr($filename).'" class="col-4 col-md-3 is_file text-center is_shallow" style="cursor: pointer;" data-id="'.$file.'"> |
| 1366 |
<figure class="figure file_view p-1"> |
| 1367 |
<a href="'.$file_url.'" target="_blank" class="file" ><img class="my-3" src="'.$icon_url.'" /></a> |
| 1368 |
<figcaption class="figure-caption text-center">'.$title.'</figcaption> |
| 1369 |
</figure> |
| 1370 |
</div> |
| 1371 |
|
| 1372 |
|
| 1373 |
'; |
| 1374 |
$list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby); |
| 1375 |
|
| 1376 |
} |
| 1377 |
|
| 1378 |
} |
| 1379 |
//pree(array_keys($list)); |
| 1380 |
|
| 1381 |
//ksort($list); |
| 1382 |
$list = wpdocs_sorting($list, $default_order); |
| 1383 |
//pree(array_keys($list)); |
| 1384 |
echo implode('', $list); |
| 1385 |
} else { |
| 1386 |
$no_file_found = true; |
| 1387 |
} |
| 1388 |
|
| 1389 |
if (!empty($deep_files_list_arr)) { |
| 1390 |
$list = array(); |
| 1391 |
foreach ($deep_files_list_arr as $file) { |
| 1392 |
|
| 1393 |
$file_data = wpd_get_item_type_icon_url($file); |
| 1394 |
extract($file_data); |
| 1395 |
|
| 1396 |
if(trim($file_url)){ |
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
switch ($ext) { |
| 1401 |
case 'png': |
| 1402 |
case 'jpg': |
| 1403 |
case 'jpeg': |
| 1404 |
case 'gif': |
| 1405 |
case 'bmp': |
| 1406 |
|
| 1407 |
//$class .= 'fa-image'; |
| 1408 |
|
| 1409 |
break; |
| 1410 |
|
| 1411 |
case 'pdf': |
| 1412 |
|
| 1413 |
if($pdf_thumb_selected=='first_page_as_thumbnail'){ |
| 1414 |
|
| 1415 |
$pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $file_data['file_url']); |
| 1416 |
|
| 1417 |
if(file_exists($pdf_file) && class_exists('imagick')){ |
| 1418 |
|
| 1419 |
//pree($file_data); |
| 1420 |
//$icon_str = '<object style="width: 100px; height: 100px" data="'.$file_data['file_url'].'#page=1" type="application/pdf"></object>'; |
| 1421 |
|
| 1422 |
$file_url_thumb = str_replace('.pdf', '.png', strtolower($file_data['file_url'])); |
| 1423 |
$file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb); |
| 1424 |
|
| 1425 |
if(!file_exists($file_url_thumb_path)){ |
| 1426 |
|
| 1427 |
$im = new imagick($file_data['file_url']); |
| 1428 |
$im->setIteratorIndex(0); |
| 1429 |
$im->setImageFormat('png'); |
| 1430 |
$im->writeImage($file_url_thumb_path); |
| 1431 |
|
| 1432 |
} |
| 1433 |
|
| 1434 |
$icon_url = $file_url_thumb; |
| 1435 |
|
| 1436 |
} |
| 1437 |
|
| 1438 |
} |
| 1439 |
|
| 1440 |
break; |
| 1441 |
|
| 1442 |
default: |
| 1443 |
//$class .= 'fa-file'; |
| 1444 |
break; |
| 1445 |
} |
| 1446 |
|
| 1447 |
$file_list_row = ' |
| 1448 |
|
| 1449 |
|
| 1450 |
<div title="'.esc_attr($filename).'" class="col-4 col-md-3 is_file text-center is_deep" style="cursor: pointer;" data-id="'.$file.'"> |
| 1451 |
<figure class="figure file_view p-1"> |
| 1452 |
<a href="'.$file_url.'" target="_blank" class="file" ><img class="my-3" src="'.$icon_url.'" /></a> |
| 1453 |
<figcaption class="figure-caption text-center">'.$title.'</figcaption> |
| 1454 |
</figure> |
| 1455 |
</div> |
| 1456 |
|
| 1457 |
|
| 1458 |
'; |
| 1459 |
$list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby); |
| 1460 |
|
| 1461 |
} |
| 1462 |
|
| 1463 |
} |
| 1464 |
//pree(array_keys($list)); |
| 1465 |
|
| 1466 |
//ksort($list); |
| 1467 |
$list = wpdocs_sorting($list, $default_order); |
| 1468 |
//pree(array_keys($list)); |
| 1469 |
echo implode('', $list); |
| 1470 |
} |
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
if ($no_dir_found && $no_file_found) { |
| 1475 |
|
| 1476 |
?> |
| 1477 |
<div class="alert alert-info text-center mx-auto empty-dir-files"> |
| 1478 |
<strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?> |
| 1479 |
</div> |
| 1480 |
<?php } ?> |
| 1481 |
|
| 1482 |
|
| 1483 |
</div> |
| 1484 |
|
| 1485 |
<!-- List View Area --> |
| 1486 |
<div class="row folder_view list_view <?php echo $wpdocs_view=='list_view'?'':'d-none'; ?>"> |
| 1487 |
<?php |
| 1488 |
$no_dir_found = false; |
| 1489 |
$no_file_found = false; |
| 1490 |
if (!empty($wpdocs_list)) { |
| 1491 |
foreach ($wpdocs_list as $list) { |
| 1492 |
$is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']); |
| 1493 |
?> |
| 1494 |
|
| 1495 |
<div class="col-12 file_wrapper is_dir" style="cursor: pointer;" data-id="<?php echo $list['id']; ?>" data-resource="<?php echo base64_encode($list['id']); ?>" data-linked="<?php echo $list['content']; ?>" data-guid="<?php echo $is_shortcut?$list['link']:''; ?>"> |
| 1496 |
<figure class="figure file_view p-2"> |
| 1497 |
<span class="fa fa-folder text-warning" style="font-size:25px"></span> |
| 1498 |
<small class="text-center"><?php echo $list['title']; ?></small> |
| 1499 |
</figure> |
| 1500 |
</div> |
| 1501 |
<?php |
| 1502 |
} |
| 1503 |
} else { |
| 1504 |
$no_dir_found = true; |
| 1505 |
} |
| 1506 |
|
| 1507 |
if (!empty($wpdocs_list_merged_arr)) { |
| 1508 |
|
| 1509 |
foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) { |
| 1510 |
|
| 1511 |
foreach ($wpdocs_merged_list as $list_obj) { |
| 1512 |
|
| 1513 |
$list = array('id'=>$list_obj->ID, 'content'=>$list_obj->post_content, 'title'=>$list_obj->post_title, 'type'=>$list_obj->post_type, 'guid'=>$list_obj->guid); |
| 1514 |
$is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']); |
| 1515 |
|
| 1516 |
?> |
| 1517 |
<div class="col-12 file_wrapper is_dir is_deep" style="cursor: pointer;" data-id="<?php echo $list['id']; ?>" data-resource="<?php echo base64_encode($list['id']); ?>" data-linked="<?php echo $list['content']; ?>" data-guid="<?php echo $is_shortcut?$list['guid']:''; ?>"> |
| 1518 |
<figure class="figure file_view p-2"> |
| 1519 |
<span class="fa fa-folder text-warning" style="font-size:25px"></span> |
| 1520 |
<small class="text-center"><?php echo $list['title']; ?></small> |
| 1521 |
</figure> |
| 1522 |
</div> |
| 1523 |
<?php |
| 1524 |
} |
| 1525 |
} |
| 1526 |
} |
| 1527 |
|
| 1528 |
|
| 1529 |
if (!empty($files_list)) { |
| 1530 |
$list = array(); |
| 1531 |
foreach ($files_list as $file) { |
| 1532 |
|
| 1533 |
$file_data = wpd_get_item_type_icon_url($file); |
| 1534 |
extract($file_data); |
| 1535 |
|
| 1536 |
|
| 1537 |
if(trim($file_url)){ |
| 1538 |
|
| 1539 |
$file_list_row = ' |
| 1540 |
<div title="'.esc_attr($filename).'" class="col-12 file_wrapper is_file" style="cursor: pointer;" data-id="'.$file.'"> |
| 1541 |
<figure class="figure file_view p-3"> |
| 1542 |
<a href="'.$file_url.'" target="_blank" class="file" ><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></a> |
| 1543 |
<small class="text-center">'.$title.'</small> |
| 1544 |
</figure> |
| 1545 |
</div>'; |
| 1546 |
|
| 1547 |
$list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby); |
| 1548 |
|
| 1549 |
} |
| 1550 |
|
| 1551 |
} |
| 1552 |
//pree($list); |
| 1553 |
//ksort($list); |
| 1554 |
$list = wpdocs_sorting($list, $default_order); |
| 1555 |
echo implode('', $list); |
| 1556 |
} else { |
| 1557 |
$no_file_found = true; |
| 1558 |
} |
| 1559 |
|
| 1560 |
if (!empty($deep_files_list_arr)) { |
| 1561 |
$list = array(); |
| 1562 |
foreach ($deep_files_list_arr as $file) { |
| 1563 |
|
| 1564 |
$file_data = wpd_get_item_type_icon_url($file); |
| 1565 |
extract($file_data); |
| 1566 |
|
| 1567 |
|
| 1568 |
if(trim($file_url)){ |
| 1569 |
|
| 1570 |
$file_list_row = ' |
| 1571 |
<div title="'.esc_attr($filename).'" class="col-12 file_wrapper is_file is_deep" style="cursor: pointer;" data-id="'.$file.'"> |
| 1572 |
<figure class="figure file_view p-3"> |
| 1573 |
<a href="'.$file_url.'" target="_blank" class="file" ><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></a> |
| 1574 |
<small class="text-center">'.$title.'</small> |
| 1575 |
</figure> |
| 1576 |
</div>'; |
| 1577 |
|
| 1578 |
$list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby); |
| 1579 |
|
| 1580 |
} |
| 1581 |
|
| 1582 |
} |
| 1583 |
//pree($list); |
| 1584 |
//ksort($list); |
| 1585 |
$list = wpdocs_sorting($list, $default_order); |
| 1586 |
echo implode('', $list); |
| 1587 |
} |
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
if ($no_dir_found && $no_file_found) { |
| 1592 |
|
| 1593 |
?> |
| 1594 |
<div class="alert alert-info text-center mx-auto empty-dir-files"> |
| 1595 |
<strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?> |
| 1596 |
</div> |
| 1597 |
<?php } ?> |
| 1598 |
|
| 1599 |
|
| 1600 |
</div> |
| 1601 |
<?php |
| 1602 |
|
| 1603 |
?> |
| 1604 |
<?php |
| 1605 |
|
| 1606 |
$d_v_caret = $wpdocs_pro && $details_view_sorting ? '<i class="fa fa-docs-sort" aria-hidden="true"></i>' : ''; |
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
?> |
| 1612 |
<!-- Detail View Area --> |
| 1613 |
<div class="row folder_view detail_view mt-0 <?php echo $wpdocs_view=='detail_view'?'':'d-none'; ?>"> |
| 1614 |
<div class="table-responsive" style="zoom:70%"> |
| 1615 |
<table class="table"> |
| 1616 |
<thead class="thead"> |
| 1617 |
<tr> |
| 1618 |
<th><?php _e('Name', 'wp-docs'); ?> <?php echo $d_v_caret; ?></th> |
| 1619 |
<?php if($details_date_created): ?> <th><?php _e('Created Date', 'wp-docs'); ?> <?php echo $d_v_caret; ?></th><?php endif; ?> |
| 1620 |
<?php if($details_date): ?> <th><?php _e('Modified Date', 'wp-docs'); ?> <?php echo $d_v_caret; ?></th><?php endif; ?> |
| 1621 |
<?php if($details_type): ?> <th><?php _e('Type', 'wp-docs'); ?> <?php echo $d_v_caret; ?></th><?php endif; ?> |
| 1622 |
<?php if($details_size): ?> <th><?php _e('Size', 'wp-docs'); ?> <?php echo $d_v_caret; ?></th><?php endif; ?> |
| 1623 |
</tr> |
| 1624 |
</thead> |
| 1625 |
<?php |
| 1626 |
$no_dir_found = false; |
| 1627 |
$no_file_found = false; |
| 1628 |
if (!empty($wpdocs_list)) { |
| 1629 |
foreach ($wpdocs_list as $list) { |
| 1630 |
$is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']); |
| 1631 |
?> |
| 1632 |
<tr title="<?php echo $list['id']; ?>" class="file_wrapper file_view is_dir" style="cursor: pointer;" data-id="<?php echo $list['id']; ?>" data-resource="<?php echo base64_encode($list['id']); ?>" data-linked="<?php echo $list['content']; ?>" data-guid="<?php echo $is_shortcut?$list['link']:''; ?>"> |
| 1633 |
<td> |
| 1634 |
<figure class="figure "> |
| 1635 |
<span class="fa fa-folder text-warning" style="font-size:25px"></span> |
| 1636 |
<small class="text-center mb-1"><?php echo $list['title']; ?></small> |
| 1637 |
</figure> |
| 1638 |
</td> |
| 1639 |
|
| 1640 |
<?php if($details_date_created): ?> <td data-time="<?php get_post_time('U', false, $list['id']) ?>"><small><?php echo get_the_date(get_option( 'date_format' ), $list['id']) . ' ' . get_the_time(get_option( 'time_format' ), $list['id']) ?></small></td><?php endif; ?> |
| 1641 |
<?php if($details_date): ?> <td data-time="<?php get_post_modified_time('U', false, $list['id']) ?>"><small><?php echo get_the_modified_date(get_option( 'date_format' ), $list['id']) . ' ' . get_the_modified_time(get_option( 'time_format' ), $list['id']) ?></small></td><?php endif; ?> |
| 1642 |
<?php if($details_type): ?> <td><small><?php |
| 1643 |
|
| 1644 |
|
| 1645 |
$directory_post_type = get_post_type($list['id']); |
| 1646 |
|
| 1647 |
|
| 1648 |
if($wpdocs_post_types['shortcut']==$directory_post_type){ |
| 1649 |
echo '<span style="color: #06C;" class="fa fa-link"></span> '.__('Shortcut', 'wp-docs'); |
| 1650 |
}elseif($wpdocs_post_types['dir']==$directory_post_type){ |
| 1651 |
echo __('Directory', 'wp-docs'); |
| 1652 |
}else{ |
| 1653 |
echo $directory_post_type; |
| 1654 |
} |
| 1655 |
|
| 1656 |
|
| 1657 |
?></small></td><?php endif; ?> |
| 1658 |
<?php if($details_size): ?> <td><small></small></td><?php endif; ?> |
| 1659 |
</tr> |
| 1660 |
<?php |
| 1661 |
} |
| 1662 |
} else { |
| 1663 |
$no_dir_found = true; |
| 1664 |
} |
| 1665 |
|
| 1666 |
if (!empty($wpdocs_list_merged_arr)) { |
| 1667 |
|
| 1668 |
foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) { |
| 1669 |
|
| 1670 |
foreach ($wpdocs_merged_list as $list_obj) { |
| 1671 |
|
| 1672 |
$list = array('id'=>$list_obj->ID, 'content'=>$list_obj->post_content, 'title'=>$list_obj->post_title, 'type'=>$list_obj->post_type, 'guid'=>$list_obj->guid); |
| 1673 |
$is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']); |
| 1674 |
|
| 1675 |
?> |
| 1676 |
<tr title="<?php echo $list['id']; ?>" class="file_wrapper file_view is_dir is_deep" style="cursor: pointer;" data-id="<?php echo $list['id']; ?>" data-resource="<?php echo base64_encode($list['id']); ?>" data-linked="<?php echo $list['content']; ?>" data-guid="<?php echo $is_shortcut?$list['guid']:''; ?>"> |
| 1677 |
<td> |
| 1678 |
<figure class="figure "> |
| 1679 |
<span class="fa fa-folder text-warning" style="font-size:25px"></span> |
| 1680 |
<small class="text-center mb-1"><?php echo $list['title']; ?></small> |
| 1681 |
</figure> |
| 1682 |
</td> |
| 1683 |
|
| 1684 |
<?php if($details_date_created): ?> <td data-time="<?php get_post_time('U', false, $list['id']) ?>"><small><?php echo get_the_date(get_option( 'date_format' ), $list['id']) . ' ' . get_the_time(get_option( 'time_format' ), $list['id']) ?></small></td><?php endif; ?> |
| 1685 |
<?php if($details_date): ?> <td data-time="<?php get_post_modified_time('U', false, $list['id']) ?>"><small><?php echo get_the_modified_date(get_option( 'date_format' ), $list['id']) . ' ' . get_the_modified_time(get_option( 'time_format' ), $list['id']) ?></small></td><?php endif; ?> |
| 1686 |
<?php if($details_type): ?> <td><small><?php |
| 1687 |
|
| 1688 |
|
| 1689 |
$directory_post_type = get_post_type($list['id']); |
| 1690 |
|
| 1691 |
if($wpdocs_post_types['shortcut']==$directory_post_type){ |
| 1692 |
echo 'Directory Shortcut'; |
| 1693 |
}elseif($wpdocs_post_types['dir']==$directory_post_type){ |
| 1694 |
echo 'Directory'; |
| 1695 |
}else{ |
| 1696 |
echo $directory_post_type; |
| 1697 |
} |
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
?></small></td><?php endif; ?> |
| 1703 |
<?php if($details_size): ?> <td><small></small></td><?php endif; ?> |
| 1704 |
</tr> |
| 1705 |
<?php |
| 1706 |
} |
| 1707 |
} |
| 1708 |
} |
| 1709 |
|
| 1710 |
|
| 1711 |
if (!empty($files_list)) { |
| 1712 |
$list = array(); |
| 1713 |
foreach ($files_list as $file) { |
| 1714 |
|
| 1715 |
//pree($file);exit; |
| 1716 |
|
| 1717 |
$file_data = wpd_get_item_type_icon_url($file); |
| 1718 |
extract($file_data); |
| 1719 |
//pree($ts); |
| 1720 |
|
| 1721 |
if(trim($icon_url)){ |
| 1722 |
|
| 1723 |
$files_list_row = ' |
| 1724 |
<tr title="'.esc_attr($filename).'" data-url="'.$file_url.'" class="file_view file_link is_file" style="cursor: pointer;" data-id="'.$file.'"> |
| 1725 |
|
| 1726 |
<td> |
| 1727 |
|
| 1728 |
<figure class="figure file_view"> |
| 1729 |
<span class="file"><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></span> |
| 1730 |
<small class="text-center">'.$title.'</small> |
| 1731 |
</figure> |
| 1732 |
</td> |
| 1733 |
'; |
| 1734 |
|
| 1735 |
} |
| 1736 |
|
| 1737 |
$created_time_u = get_post_time('U', false, $file); |
| 1738 |
$modified_time_u = get_post_modified_time('U', false, $file); |
| 1739 |
|
| 1740 |
$file_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url); |
| 1741 |
|
| 1742 |
$file_size = round(@filesize($file_path) / 1024); |
| 1743 |
if($details_date_created): $files_list_row .= '<td data-time="'.$created_time_u.'"><small>'.get_the_date(get_option( 'date_format' ), $file) . ' ' . get_the_time(get_option( 'time_format' ), $file).'</small></td>'; endif; |
| 1744 |
if($details_date): $files_list_row .= '<td data-time="'.$modified_time_u.'"><small>'.get_the_modified_date(get_option( 'date_format' ), $file) . ' ' . get_the_modified_time(get_option( 'time_format' ), $file).'</small></td>'; endif; |
| 1745 |
if($details_type): $files_list_row .= '<td><small>'.get_post_mime_type($file).'</small></td>'; endif; |
| 1746 |
if($details_size): $files_list_row .= '<td data-time="'.$file_size.'"><small>'.$file_size. ' KB'.'</small></td>'; endif; |
| 1747 |
// data-time is used for sorting purpose on front end it will sort by data-time value if it exist if not exist than it will be sorted by td inner text |
| 1748 |
|
| 1749 |
|
| 1750 |
$files_list_row .= '</tr>'; |
| 1751 |
|
| 1752 |
$list = wpdocs_list_population($list, $file_data, $files_list_row, $default_orderby); |
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
} |
| 1757 |
|
| 1758 |
|
| 1759 |
$list = wpdocs_sorting($list, $default_order); |
| 1760 |
echo implode('', $list); |
| 1761 |
|
| 1762 |
} else { |
| 1763 |
$no_file_found = true; |
| 1764 |
} |
| 1765 |
|
| 1766 |
if (!empty($deep_files_list_arr)) { |
| 1767 |
$list = array(); |
| 1768 |
|
| 1769 |
//pree($wp_get_upload_dir); |
| 1770 |
foreach ($deep_files_list_arr as $file) { |
| 1771 |
|
| 1772 |
//pree($file);exit; |
| 1773 |
|
| 1774 |
$file_data = wpd_get_item_type_icon_url($file); |
| 1775 |
extract($file_data); |
| 1776 |
//pree($ts); |
| 1777 |
|
| 1778 |
if(trim($icon_url)){ |
| 1779 |
|
| 1780 |
$files_list_row = ' |
| 1781 |
<tr title="'.esc_attr($filename).'" data-url="'.$file_url.'" class="file_view file_link is_file is_deep" style="cursor: pointer;" data-id="'.$file.'"> |
| 1782 |
|
| 1783 |
<td> |
| 1784 |
|
| 1785 |
<figure class="figure file_view"> |
| 1786 |
<span class="file"><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></span> |
| 1787 |
<small class="text-center">'.$title.'</small> |
| 1788 |
</figure> |
| 1789 |
</td> |
| 1790 |
'; |
| 1791 |
|
| 1792 |
} |
| 1793 |
|
| 1794 |
$created_time_u = get_post_time('U', false, $file); |
| 1795 |
$modified_time_u = get_post_modified_time('U', false, $file); |
| 1796 |
|
| 1797 |
$file_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url); |
| 1798 |
|
| 1799 |
$file_size = round(@filesize($file_path) / 1024); |
| 1800 |
if($details_date_created): $files_list_row .= '<td data-time="'.$created_time_u.'"><small>'.get_the_date(get_option( 'date_format' ), $file) . ' ' . get_the_time(get_option( 'time_format' ), $file).'</small></td>'; endif; |
| 1801 |
if($details_date): $files_list_row .= '<td data-time="'.$modified_time_u.'"><small>'.get_the_modified_date(get_option( 'date_format' ), $file) . ' ' . get_the_modified_time(get_option( 'time_format' ), $file).'</small></td>'; endif; |
| 1802 |
if($details_type): $files_list_row .= '<td><small>'.get_post_mime_type($file).'</small></td>'; endif; |
| 1803 |
if($details_size): $files_list_row .= '<td data-time="'.$file_size.'"><small>'.$file_size. ' KB'.'</small></td>'; endif; |
| 1804 |
// data-time is used for sorting purpose on front end it will sort by data-time value if it exist if not exist than it will be sorted by td inner text |
| 1805 |
|
| 1806 |
|
| 1807 |
$files_list_row .= '</tr>'; |
| 1808 |
|
| 1809 |
$list = wpdocs_list_population($list, $file_data, $files_list_row, $default_orderby); |
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
} |
| 1814 |
|
| 1815 |
|
| 1816 |
$list = wpdocs_sorting($list, $default_order); |
| 1817 |
echo implode('', $list); |
| 1818 |
|
| 1819 |
} |
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
if ($no_dir_found && $no_file_found) { |
| 1824 |
|
| 1825 |
?> |
| 1826 |
<tr> |
| 1827 |
<td class="alert alert-info text-center mx-auto empty-dir-files" colspan="5"> |
| 1828 |
<strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?> |
| 1829 |
</td> |
| 1830 |
</tr> |
| 1831 |
<?php } ?> |
| 1832 |
</table> |
| 1833 |
</div> |
| 1834 |
</div> |
| 1835 |
|
| 1836 |
</div> |
| 1837 |
<div class="card-footer text-right wpdocs-views position-relative"> |
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
<a data-source="large_icon_view" data-toggle="tooltip" data-placement="bottom" title="<?php _e('Thumbnails View', 'wp-docs'); ?>" class="folder_view_btn fa fa-image fa-lg text-danger mr-2"></a> |
| 1842 |
<a data-source="list_view" data-toggle="tooltip" data-placement="bottom" title="<?php _e('List View', 'wp-docs'); ?>" class="folder_view_btn fa fa-bars fa-lg text-danger mr-2"></a> |
| 1843 |
<a data-source="detail_view" data-toggle="tooltip" data-placement="bottom" title="<?php _e('Details Views', 'wp-docs'); ?>" class="folder_view_btn fa fa-list fa-lg text-danger mr-2"></a> |
| 1844 |
</div> |
| 1845 |
</div> |
| 1846 |
<?php if($is_bootstrap): ?> |
| 1847 |
<div class="wpdocs_loader wpd_modal d-none"> |
| 1848 |
<div class="modal_content"> |
| 1849 |
<img src="<?php echo $wpdocs_url.'img/loader.gif' ?>" width="50px" height="50px"> |
| 1850 |
</div> |
| 1851 |
</div> |
| 1852 |
<?php endif; ?> |
| 1853 |
|
| 1854 |
</div> |
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
<?php |
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
$out1 = ob_get_contents(); |
| 1863 |
|
| 1864 |
ob_end_clean(); |
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
return $out1; |
| 1869 |
|
| 1870 |
} |
| 1871 |
|
| 1872 |
|
| 1873 |
function wpdocs_parent_folder($id) |
| 1874 |
{ |
| 1875 |
//pree($id); |
| 1876 |
$parent_id = 0; |
| 1877 |
if (wpdocs_folder_exists($id)) { |
| 1878 |
$post_data = get_post($id); |
| 1879 |
//pree($post_data); |
| 1880 |
$parent_id = $post_data->post_parent; |
| 1881 |
} |
| 1882 |
return ($parent_id); |
| 1883 |
} |
| 1884 |
|
| 1885 |
function wpdocs_added_items_by_user($dir_id) |
| 1886 |
{ |
| 1887 |
$current_user_items = array(); |
| 1888 |
if(!is_user_logged_in()){return array();} |
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
$current_user = get_current_user_id(); |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
if (is_numeric($dir_id) && $dir_id > 0 && wpdocs_folder_exists($dir_id)) { |
| 1897 |
$wpdocs_items = get_post_meta($dir_id, 'wpdocs_items_by_user', true); |
| 1898 |
//pree($wpdocs_items); |
| 1899 |
$wpdocs_items = is_array(maybe_unserialize($wpdocs_items)) ? maybe_unserialize($wpdocs_items) : array(); |
| 1900 |
|
| 1901 |
$current_user_items = array_key_exists($current_user, $wpdocs_items) ? $wpdocs_items[$current_user] : array(); |
| 1902 |
//pree($wpdocs_items); |
| 1903 |
//asort($wpdocs_items); |
| 1904 |
} |
| 1905 |
return $current_user_items; |
| 1906 |
} |
| 1907 |
|
| 1908 |
function wpdocs_added_items($dir_id) |
| 1909 |
{ |
| 1910 |
$wpdocs_items = array(); |
| 1911 |
if (is_numeric($dir_id) && $dir_id > 0 && wpdocs_folder_exists($dir_id)) { |
| 1912 |
$wpdocs_items = get_post_meta($dir_id, 'wpdocs_items', true); |
| 1913 |
//pree($wpdocs_items); |
| 1914 |
$wpdocs_items = is_array(maybe_unserialize($wpdocs_items)) ? maybe_unserialize($wpdocs_items) : array(); |
| 1915 |
//pree($wpdocs_items); |
| 1916 |
//asort($wpdocs_items); |
| 1917 |
} |
| 1918 |
return $wpdocs_items; |
| 1919 |
} |
| 1920 |
|
| 1921 |
function wpdocs_folder_exists($ids='', $user_id=0) |
| 1922 |
{ |
| 1923 |
//pree($id); |
| 1924 |
//pree($ids); |
| 1925 |
$posts_array = array(); |
| 1926 |
|
| 1927 |
$ids = explode(',', $ids); |
| 1928 |
$ids = array_map('trim', $ids); |
| 1929 |
$ids = array_filter($ids, 'is_numeric'); |
| 1930 |
|
| 1931 |
//pree($ids);exit; |
| 1932 |
if (!empty($ids)) { |
| 1933 |
global $wpdocs_post_types, $wpdocs_post_status; |
| 1934 |
$ids = sanitize_wpdocs_data($ids); |
| 1935 |
$args = array( |
| 1936 |
'posts_per_page' => -1, |
| 1937 |
'offset' => 0, |
| 1938 |
'category' => '', |
| 1939 |
'category_name' => '', |
| 1940 |
'orderby' => 'title', |
| 1941 |
'order' => 'ASC', |
| 1942 |
'include' => $ids, |
| 1943 |
'exclude' => '', |
| 1944 |
'meta_key' => '', |
| 1945 |
'meta_value' => '', |
| 1946 |
'post_type' => $wpdocs_post_types, |
| 1947 |
'post_mime_type' => '', |
| 1948 |
'post_parent' => '',//$post_parent, |
| 1949 |
'author' => ($user_id?$user_id:''), |
| 1950 |
'author_name' => '', |
| 1951 |
'post_status' => $wpdocs_post_status, |
| 1952 |
'suppress_filters' => true |
| 1953 |
); |
| 1954 |
//pree($args); |
| 1955 |
$posts_array = get_posts($args); |
| 1956 |
} |
| 1957 |
return (count($posts_array) > 0); |
| 1958 |
} |
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
add_action('wp_ajax_wpdocs_update_folder', 'wpdocs_update_folder'); |
| 1964 |
|
| 1965 |
function wpdocs_update_folder() { |
| 1966 |
|
| 1967 |
|
| 1968 |
if ( ! current_user_can('edit_posts') ) { |
| 1969 |
wp_send_json_error(['msg' => __('Unauthorized access.', 'wp-docs')]); |
| 1970 |
} |
| 1971 |
|
| 1972 |
|
| 1973 |
if ( |
| 1974 |
empty($_POST['nonce']) || |
| 1975 |
! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'wpdocs_update_options_nonce') |
| 1976 |
) { |
| 1977 |
wp_send_json_error(['msg' => __('Sorry, your nonce did not verify.', 'wp-docs')]); |
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
$dir_id = absint($_POST['dir_id'] ?? 0); |
| 1982 |
$resource_id = base64_decode(sanitize_text_field($_POST['resource_id'] ?? '')); |
| 1983 |
$new_name = sanitize_text_field($_POST['new_name'] ?? ''); |
| 1984 |
|
| 1985 |
$ret = ['msg' => '']; |
| 1986 |
|
| 1987 |
if ( $dir_id > 0 && $resource_id == $dir_id && wpdocs_folder_exists($dir_id) ) { |
| 1988 |
|
| 1989 |
global $wpdb, $wpdocs_post_types, $wpdocs_post_status; |
| 1990 |
|
| 1991 |
$updated = $wpdb->query( |
| 1992 |
$wpdb->prepare( |
| 1993 |
"UPDATE $wpdb->posts |
| 1994 |
SET post_title = %s |
| 1995 |
WHERE ID = %d |
| 1996 |
AND post_type IN ('" . implode("','", array_map('esc_sql', $wpdocs_post_types)) . "') |
| 1997 |
AND post_status = %s", |
| 1998 |
htmlspecialchars_decode($new_name), |
| 1999 |
$dir_id, |
| 2000 |
$wpdocs_post_status |
| 2001 |
) |
| 2002 |
); |
| 2003 |
|
| 2004 |
if ( $updated ) { |
| 2005 |
$ret['msg'] = __('Successfully updated.', 'wp-docs'); |
| 2006 |
} else { |
| 2007 |
$ret['msg'] = __('No changes were made. Input seems the same as before.', 'wp-docs'); |
| 2008 |
} |
| 2009 |
} else { |
| 2010 |
$ret['msg'] = __('Invalid folder ID or resource mismatch.', 'wp-docs'); |
| 2011 |
} |
| 2012 |
|
| 2013 |
wp_send_json_success($ret); |
| 2014 |
} |
| 2015 |
|
| 2016 |
|
| 2017 |
add_action('wp_ajax_wpdocs_delete_folder', 'wpdocs_delete_folder'); |
| 2018 |
|
| 2019 |
function wpdocs_delete_folder() |
| 2020 |
{ |
| 2021 |
$nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce'])); |
| 2022 |
|
| 2023 |
if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) ) |
| 2024 |
die (__("Sorry, your nonce did not verify.", 'wp-docs')); |
| 2025 |
|
| 2026 |
$dir_id = sanitize_wpdocs_data($_POST['dir_id']); |
| 2027 |
$resource_id = base64_decode(sanitize_wpdocs_data($_POST['resource_id'])); |
| 2028 |
|
| 2029 |
if($dir_id==$resource_id){ |
| 2030 |
wpdocs_recursive_delete_folder($dir_id); |
| 2031 |
} |
| 2032 |
|
| 2033 |
exit; |
| 2034 |
} |
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
add_action('wp_ajax_wpdocs_delete_files', 'wpdocs_delete_files'); |
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
function wpdocs_recursive_delete_folder($dir_id){ |
| 2043 |
if ($dir_id > 0 && wpdocs_folder_exists($dir_id)) { |
| 2044 |
$wpdocs_list = wpdocs_list($dir_id); |
| 2045 |
if(!empty($wpdocs_list)){ |
| 2046 |
foreach($wpdocs_list as $wpdocs_item){ |
| 2047 |
//pree($wpdocs_item); |
| 2048 |
if(is_numeric($wpdocs_item['id'])){ |
| 2049 |
wpdocs_recursive_delete_folder($wpdocs_item['id']); |
| 2050 |
} |
| 2051 |
} |
| 2052 |
} |
| 2053 |
|
| 2054 |
if(function_exists('wp_docs_relocate_memphis_meta')){ |
| 2055 |
wp_docs_relocate_memphis_meta($dir_id); |
| 2056 |
} |
| 2057 |
|
| 2058 |
wp_delete_post($dir_id, true); |
| 2059 |
} |
| 2060 |
|
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
if(!function_exists('wpdocs_update_files_meta')){ |
| 2066 |
|
| 2067 |
function wpdocs_update_files_meta($dir_id, $files=array()){ |
| 2068 |
|
| 2069 |
if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) { |
| 2070 |
|
| 2071 |
//Items for single user |
| 2072 |
$current_user = get_current_user_id(); |
| 2073 |
$wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true); |
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
$wpdocs_items_by_user = $wpdocs_items_by_user && is_array($wpdocs_items_by_user) ? $wpdocs_items_by_user: array(); |
| 2078 |
|
| 2079 |
|
| 2080 |
$current_user_items = array_key_exists($current_user, $wpdocs_items_by_user) ? $wpdocs_items_by_user[$current_user] : array(); |
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
$current_user_items = array_merge($current_user_items, $files); |
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
$current_user_items = array_unique($current_user_items); |
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
$wpdocs_items_by_user[$current_user] = $current_user_items; |
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
//overall items |
| 2101 |
|
| 2102 |
$wpdocs_items = wpdocs_added_items($dir_id); |
| 2103 |
|
| 2104 |
$wpdocs_items = array_merge($wpdocs_items, $files); |
| 2105 |
|
| 2106 |
$wpdocs_items = array_unique($wpdocs_items); |
| 2107 |
|
| 2108 |
//pree($wpdocs_items); |
| 2109 |
|
| 2110 |
update_post_meta($dir_id, 'wpdocs_items_by_user', $wpdocs_items_by_user); |
| 2111 |
|
| 2112 |
return update_post_meta($dir_id, 'wpdocs_items', $wpdocs_items); |
| 2113 |
} |
| 2114 |
} |
| 2115 |
} |
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
function wpdocs_delete_files() |
| 2120 |
{ |
| 2121 |
|
| 2122 |
$dir_id = sanitize_wpdocs_data($_POST['dir_id']); |
| 2123 |
$files = sanitize_wpdocs_data($_POST['files']); |
| 2124 |
$files = is_array($files) ? $files : array($files); |
| 2125 |
//pree($dir_id);pree($files);exit; |
| 2126 |
if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) { |
| 2127 |
|
| 2128 |
wpdocs_del_items_by_user($dir_id, $files, get_current_user_id()); |
| 2129 |
|
| 2130 |
|
| 2131 |
$wpdocs_items = wpdocs_added_items($dir_id); |
| 2132 |
//pree($wpdocs_items); |
| 2133 |
$wpdocs_items = array_diff($wpdocs_items, $files); |
| 2134 |
//pree($wpdocs_items); |
| 2135 |
$wpdocs_items = array_unique($wpdocs_items); |
| 2136 |
|
| 2137 |
//pree($wpdocs_items); |
| 2138 |
|
| 2139 |
update_post_meta($dir_id, 'wpdocs_items', $wpdocs_items); |
| 2140 |
} |
| 2141 |
|
| 2142 |
|
| 2143 |
exit; |
| 2144 |
} |
| 2145 |
|
| 2146 |
function wpd_admin_footer(){ |
| 2147 |
|
| 2148 |
?> |
| 2149 |
<script type="text/javascript" language="javascript"> |
| 2150 |
|
| 2151 |
</script> |
| 2152 |
|
| 2153 |
<?php |
| 2154 |
|
| 2155 |
} |
| 2156 |
add_action('admin_footer', 'wpd_admin_footer'); |
| 2157 |
|
| 2158 |
add_action('wp_ajax_wpdocs_update_option', 'wpdocs_update_option'); |
| 2159 |
|
| 2160 |
if(!function_exists('wpdocs_update_option')){ |
| 2161 |
function wpdocs_update_option(){ |
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
if(isset($_POST['wpdocs_update_option_nonce'])){ |
| 2166 |
|
| 2167 |
$nonce = sanitize_wpdocs_data(wp_unslash($_POST['wpdocs_update_option_nonce'])); |
| 2168 |
|
| 2169 |
$return = array( |
| 2170 |
|
| 2171 |
'option_update' => false, |
| 2172 |
'dir_move' => false, |
| 2173 |
); |
| 2174 |
|
| 2175 |
if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) ) |
| 2176 |
die (__("Sorry, your nonce did not verify.", 'wp-docs')); |
| 2177 |
|
| 2178 |
if(isset($_POST['wpdocs_options'])){ |
| 2179 |
|
| 2180 |
$wpdocs_options = isset($_POST['wpdocs_options']) ? sanitize_wpdocs_data($_POST['wpdocs_options']) : array(); |
| 2181 |
|
| 2182 |
$wpdocs_dir_id = isset($_POST['wpdocs_dir_id']) ? sanitize_wpdocs_data($_POST['wpdocs_dir_id']) : 0; |
| 2183 |
|
| 2184 |
|
| 2185 |
$sanitized_option = sanitize_wpdocs_data($wpdocs_options); |
| 2186 |
$sanitized_option['allowed_role'] = $sanitized_option['allowed_role'] !== 'empty' ? $sanitized_option['allowed_role'] : array(); |
| 2187 |
|
| 2188 |
|
| 2189 |
if($wpdocs_dir_id == 0){ |
| 2190 |
|
| 2191 |
$update = update_option('wpdocs_options', $sanitized_option); |
| 2192 |
|
| 2193 |
}else{ |
| 2194 |
|
| 2195 |
$update = update_post_meta($wpdocs_dir_id, '_wpdocs_dir_options', $sanitized_option); |
| 2196 |
$child_dir_list = wpdoc_get_dir_children($wpdocs_dir_id); |
| 2197 |
if(!empty($child_dir_list)){ |
| 2198 |
foreach ($child_dir_list as $child_dir) { |
| 2199 |
|
| 2200 |
$update = update_post_meta($child_dir, '_wpdocs_dir_options', $sanitized_option); |
| 2201 |
|
| 2202 |
# code... |
| 2203 |
} |
| 2204 |
} |
| 2205 |
|
| 2206 |
|
| 2207 |
|
| 2208 |
} |
| 2209 |
} |
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
if(isset($_POST['wpdocs_move_selected_dir'])){ |
| 2214 |
|
| 2215 |
$wpdocs_move_selected_dir = sanitize_wpdocs_data($_POST['wpdocs_move_selected_dir']); |
| 2216 |
$action_type = $wpdocs_move_selected_dir['action_type']; |
| 2217 |
|
| 2218 |
|
| 2219 |
$is_file = array_key_exists('is_file', $wpdocs_move_selected_dir) ? $wpdocs_move_selected_dir['is_file']: false; |
| 2220 |
$is_file = $is_file == 'false' ? false: true; |
| 2221 |
|
| 2222 |
|
| 2223 |
if(!$is_file && array_key_exists('dir_selected', $wpdocs_move_selected_dir) && |
| 2224 |
array_key_exists('dir_id', $wpdocs_move_selected_dir)){ |
| 2225 |
|
| 2226 |
switch($action_type){ |
| 2227 |
default: |
| 2228 |
case 'move': |
| 2229 |
|
| 2230 |
|
| 2231 |
$update = wp_update_post( |
| 2232 |
array( |
| 2233 |
'ID' => $wpdocs_move_selected_dir['dir_selected'], |
| 2234 |
'post_parent' => $wpdocs_move_selected_dir['dir_id'] |
| 2235 |
) |
| 2236 |
); |
| 2237 |
|
| 2238 |
if($update == $wpdocs_move_selected_dir['dir_selected']){ |
| 2239 |
$return['dir_move'] = true; |
| 2240 |
} |
| 2241 |
|
| 2242 |
break; |
| 2243 |
|
| 2244 |
case 'copy': |
| 2245 |
$existing_dir = get_post($wpdocs_move_selected_dir['dir_selected']); |
| 2246 |
$existing_dir = (is_object($existing_dir)?(array)$existing_dir:array()); |
| 2247 |
if(!empty($existing_dir) && array_key_exists('ID', $existing_dir) && function_exists('wpdocs_recursive_copy_folder')){ |
| 2248 |
|
| 2249 |
wpdocs_recursive_copy_folder($wpdocs_move_selected_dir['dir_id'], $existing_dir); |
| 2250 |
|
| 2251 |
$return['dir_move'] = true; |
| 2252 |
|
| 2253 |
} |
| 2254 |
|
| 2255 |
|
| 2256 |
break; |
| 2257 |
} |
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
} |
| 2262 |
//exit; |
| 2263 |
|
| 2264 |
if($is_file){ |
| 2265 |
|
| 2266 |
$file_id = $wpdocs_move_selected_dir['files']; |
| 2267 |
|
| 2268 |
$current_dir = $wpdocs_move_selected_dir['file_dir']; |
| 2269 |
|
| 2270 |
$new_dir = $wpdocs_move_selected_dir['dir_id']; |
| 2271 |
|
| 2272 |
$files = wpdocs_added_items($current_dir); |
| 2273 |
|
| 2274 |
$file_id = is_array($file_id) ? $file_id : array($file_id); |
| 2275 |
$files = array_diff($files, $file_id); |
| 2276 |
|
| 2277 |
|
| 2278 |
switch($action_type){ |
| 2279 |
default: |
| 2280 |
case 'move': |
| 2281 |
|
| 2282 |
update_post_meta($current_dir, 'wpdocs_items', $files); |
| 2283 |
|
| 2284 |
break; |
| 2285 |
|
| 2286 |
case 'copy': |
| 2287 |
|
| 2288 |
break; |
| 2289 |
|
| 2290 |
} |
| 2291 |
|
| 2292 |
$update = wpdocs_update_files_meta($new_dir, $file_id); |
| 2293 |
|
| 2294 |
if($update === true){ |
| 2295 |
$return['dir_move'] = true; |
| 2296 |
} |
| 2297 |
|
| 2298 |
} |
| 2299 |
} |
| 2300 |
|
| 2301 |
echo wp_json_encode($return); |
| 2302 |
|
| 2303 |
} |
| 2304 |
|
| 2305 |
wp_die(); |
| 2306 |
|
| 2307 |
} |
| 2308 |
} |
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
if(!function_exists('wpdocs_dir_list_complete')){ |
| 2313 |
|
| 2314 |
function wpdocs_dir_list_complete($dir = 0){ |
| 2315 |
|
| 2316 |
$wpdocs_list = wpdocs_list($dir); |
| 2317 |
|
| 2318 |
if(!empty($wpdocs_list)){ |
| 2319 |
|
| 2320 |
$wp_dir_child = array(); |
| 2321 |
|
| 2322 |
foreach ($wpdocs_list as $index => $wp_dir){ |
| 2323 |
|
| 2324 |
if(!array_key_exists('id', $wp_dir)) continue; |
| 2325 |
$wpdocs_list_child = wpdocs_list($wp_dir['id']); |
| 2326 |
|
| 2327 |
if(!empty($wpdocs_list_child)){ |
| 2328 |
|
| 2329 |
$wp_dir['child_dir'] = wpdocs_dir_list_complete($wp_dir['id']); |
| 2330 |
|
| 2331 |
} |
| 2332 |
|
| 2333 |
$wp_dir_child[] = $wp_dir; |
| 2334 |
|
| 2335 |
|
| 2336 |
} |
| 2337 |
|
| 2338 |
return $wp_dir_child; |
| 2339 |
|
| 2340 |
}else{ |
| 2341 |
|
| 2342 |
return array(); |
| 2343 |
} |
| 2344 |
} |
| 2345 |
} |
| 2346 |
|
| 2347 |
if(!function_exists('wpdocs_dir_list_option')){ |
| 2348 |
|
| 2349 |
function wpdocs_dir_list_option($dir = 0, $str = ' __ ', $level = 0){ |
| 2350 |
|
| 2351 |
|
| 2352 |
$wpdocs_list = wpdocs_list($dir); |
| 2353 |
|
| 2354 |
$option = ''; |
| 2355 |
|
| 2356 |
if(!empty($wpdocs_list)){ |
| 2357 |
|
| 2358 |
|
| 2359 |
foreach ($wpdocs_list as $index => $wp_dir){ |
| 2360 |
|
| 2361 |
if(!array_key_exists('id', $wp_dir)) continue; |
| 2362 |
$wpdocs_list_child = wpdocs_list($wp_dir['id']); |
| 2363 |
|
| 2364 |
$option .= '<option value="'.$wp_dir['id'].'" data-parent="'.$dir.'">'.str_repeat(str_replace(' ', ' ', $str), $level).$wp_dir['title'].'</option>'; |
| 2365 |
|
| 2366 |
|
| 2367 |
if(!empty($wpdocs_list_child)){ |
| 2368 |
|
| 2369 |
|
| 2370 |
$option .= wpdocs_dir_list_option($wp_dir['id'], $str, $level+1); |
| 2371 |
|
| 2372 |
} |
| 2373 |
|
| 2374 |
} |
| 2375 |
|
| 2376 |
|
| 2377 |
} |
| 2378 |
|
| 2379 |
return $option; |
| 2380 |
} |
| 2381 |
} |
| 2382 |
|
| 2383 |
add_action('wpdocs_before_docs_list', 'wpdocs_add_breadcrumb'); |
| 2384 |
|
| 2385 |
if(!function_exists('wpdocs_add_breadcrumb')){ |
| 2386 |
|
| 2387 |
function wpdocs_add_breadcrumb($dir_id, $breadcrumb=true){ |
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
$breadcrumb_array = wpdocs_get_breadcrumb_array($dir_id, $breadcrumb); |
| 2392 |
$get_permalink = admin_url('options-general.php?page=wpdocs'); |
| 2393 |
|
| 2394 |
if (!empty($breadcrumb_array)) { |
| 2395 |
?> |
| 2396 |
|
| 2397 |
<nav aria-label="breadcrumb" class="wpdocs-nav"> |
| 2398 |
<ol class="breadcrumb bg-light" style="border-bottom:1px solid #dee2e6;border-radius: 0;"> |
| 2399 |
|
| 2400 |
<li class="breadcrumb-item bread_home_url"><a class="wpd_bread_item" href="<?php echo $get_permalink ?>" data-id="0"><?php _e('Home', 'wp-docs'); ?></a></li> |
| 2401 |
<?php |
| 2402 |
|
| 2403 |
foreach (array_reverse($breadcrumb_array) as $bread_key => $bread_value) { |
| 2404 |
$active = ''; |
| 2405 |
$page = ''; |
| 2406 |
|
| 2407 |
$link = '<a class="wpd_bread_item" href="' . $get_permalink .'&dir=' . $bread_value . '" data-id="'.$bread_value.'" >' . get_the_title($bread_value) . '</a>'; |
| 2408 |
if ($bread_value == 0) { |
| 2409 |
continue; |
| 2410 |
} |
| 2411 |
if ($bread_value == $dir_id) { |
| 2412 |
$active = 'active'; |
| 2413 |
$page = 'page'; |
| 2414 |
$link = get_the_title($bread_value); |
| 2415 |
} |
| 2416 |
|
| 2417 |
|
| 2418 |
?> |
| 2419 |
<li class="breadcrumb-item <?php echo $active ?>" aria-current="<?php echo $page; ?>"><?php echo $link ?></li> |
| 2420 |
|
| 2421 |
<?php |
| 2422 |
} |
| 2423 |
|
| 2424 |
?> |
| 2425 |
|
| 2426 |
</ol> |
| 2427 |
|
| 2428 |
</nav> |
| 2429 |
|
| 2430 |
<?php |
| 2431 |
|
| 2432 |
} |
| 2433 |
} |
| 2434 |
} |
| 2435 |
|
| 2436 |
add_action('wp_ajax_wpdocs_update_view', 'wpdocs_update_view'); |
| 2437 |
add_action('wp_ajax_nopriv_wpdocs_update_view', 'wpdocs_update_view'); |
| 2438 |
|
| 2439 |
if(!function_exists('wpdocs_update_view')){ |
| 2440 |
function wpdocs_update_view(){ |
| 2441 |
|
| 2442 |
$nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce'])); |
| 2443 |
|
| 2444 |
if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) ) |
| 2445 |
die (__("Sorry, your nonce did not verify.", 'wp-docs')); |
| 2446 |
|
| 2447 |
if(isset($_POST['update_view'])){ |
| 2448 |
|
| 2449 |
$wpdocs_view = get_option('wpdocs_view', array()); |
| 2450 |
$wpdocs_view = is_array($wpdocs_view) ? $wpdocs_view : array(); |
| 2451 |
$parent_dir = sanitize_wpdocs_data($_POST['parent_dir']); |
| 2452 |
|
| 2453 |
$wpdocs_view[$parent_dir] = sanitize_wpdocs_data($_POST['update_view']); |
| 2454 |
update_option('wpdocs_view', $wpdocs_view); |
| 2455 |
|
| 2456 |
} |
| 2457 |
exit; |
| 2458 |
} |
| 2459 |
} |
| 2460 |
function wpdocs_init_session() { |
| 2461 |
if(!session_id()) { |
| 2462 |
session_start(); |
| 2463 |
} |
| 2464 |
} |
| 2465 |
|
| 2466 |
//add_action('init', 'wpdocs_init_session', 1); |
| 2467 |
|
| 2468 |
if(!function_exists('wpdocs_create_dir')){ |
| 2469 |
function wpdocs_create_dir($dir_id, $parent_path){ |
| 2470 |
|
| 2471 |
|
| 2472 |
if(!file_exists($parent_path)){ |
| 2473 |
mkdir($parent_path); |
| 2474 |
} |
| 2475 |
|
| 2476 |
$current_dir_name = 'wpdocs'; |
| 2477 |
|
| 2478 |
if($dir_id != 0){ |
| 2479 |
|
| 2480 |
$current_dir = get_post($dir_id); |
| 2481 |
$current_dir_name = $current_dir->post_title; |
| 2482 |
} |
| 2483 |
|
| 2484 |
$current_dir_temp = $parent_path.'/'.$current_dir_name; |
| 2485 |
|
| 2486 |
if(!is_dir($current_dir_temp)) |
| 2487 |
mkdir($current_dir_temp); |
| 2488 |
|
| 2489 |
return $current_dir_temp; |
| 2490 |
} |
| 2491 |
} |
| 2492 |
|
| 2493 |
if(!function_exists('wpdocs_copy_files')){ |
| 2494 |
function wpdocs_copy_files($wpdocs_items, $current_dir_temp){ |
| 2495 |
|
| 2496 |
//pre($wpdocs_items); |
| 2497 |
|
| 2498 |
$upload_dir = wp_upload_dir(); |
| 2499 |
|
| 2500 |
if(!empty($wpdocs_items)){ |
| 2501 |
foreach ($wpdocs_items as $item_id){ |
| 2502 |
//pre($item_id); |
| 2503 |
//pre(get_post_meta($item_id)); |
| 2504 |
$attached_file = get_post_meta($item_id, '_wp_attached_file', true); |
| 2505 |
//pre($attached_file); |
| 2506 |
|
| 2507 |
$absolute_path = false; |
| 2508 |
|
| 2509 |
if(!$attached_file){ |
| 2510 |
$attached_post = get_post($item_id); |
| 2511 |
$attached_file = $attached_post->guid; |
| 2512 |
$absolute_path = true; |
| 2513 |
} |
| 2514 |
|
| 2515 |
|
| 2516 |
$file_name = basename($attached_file); |
| 2517 |
$file_copy_path = $current_dir_temp.'/'.$file_name; |
| 2518 |
|
| 2519 |
if($absolute_path){ |
| 2520 |
$file_path = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $attached_file); |
| 2521 |
}else{ |
| 2522 |
$file_path = $upload_dir['basedir'].'/'.$attached_file; |
| 2523 |
} |
| 2524 |
|
| 2525 |
//pre($file_path); |
| 2526 |
|
| 2527 |
if(!is_dir($file_path) && file_exists($file_path)){ |
| 2528 |
copy($file_path, $file_copy_path); |
| 2529 |
} |
| 2530 |
} |
| 2531 |
} |
| 2532 |
|
| 2533 |
//exit; |
| 2534 |
|
| 2535 |
} |
| 2536 |
} |
| 2537 |
|
| 2538 |
if(!function_exists('wpdocs_create')){ |
| 2539 |
function wpdocs_create($dir_id, $wpdocs_dir){ |
| 2540 |
|
| 2541 |
//pree($dir_id); |
| 2542 |
|
| 2543 |
$wpdocs_list = wpdocs_list($dir_id); |
| 2544 |
//pre($wpdocs_list); |
| 2545 |
$wpdocs_items = wpdocs_added_items($dir_id); |
| 2546 |
//pre($wpdocs_items); |
| 2547 |
|
| 2548 |
$current_dir_temp = wpdocs_create_dir($dir_id, $wpdocs_dir); |
| 2549 |
|
| 2550 |
//pree($current_dir_temp); |
| 2551 |
//exit; |
| 2552 |
|
| 2553 |
wpdocs_copy_files($wpdocs_items, $current_dir_temp); |
| 2554 |
|
| 2555 |
if(!empty($wpdocs_list)){ |
| 2556 |
foreach ($wpdocs_list as $single_dir){ |
| 2557 |
|
| 2558 |
wpdocs_create($single_dir['id'], $current_dir_temp); |
| 2559 |
} |
| 2560 |
} |
| 2561 |
|
| 2562 |
} |
| 2563 |
|
| 2564 |
} |
| 2565 |
|
| 2566 |
if(!function_exists('wpdocs_generate_zip')){ |
| 2567 |
|
| 2568 |
function wpdocs_generate_zip($source, $destination) |
| 2569 |
{ |
| 2570 |
|
| 2571 |
// Initialize archive object |
| 2572 |
$zip = new ZipArchive(); |
| 2573 |
$zip->open($destination, ZipArchive::CREATE | ZipArchive::OVERWRITE); |
| 2574 |
|
| 2575 |
|
| 2576 |
// Create recursive directory iterator |
| 2577 |
/** @var SplFileInfo[] $files */ |
| 2578 |
$files = new RecursiveIteratorIterator( |
| 2579 |
new RecursiveDirectoryIterator($source), |
| 2580 |
RecursiveIteratorIterator::SELF_FIRST |
| 2581 |
); |
| 2582 |
|
| 2583 |
//pre($files); |
| 2584 |
|
| 2585 |
if (!empty($files)) { |
| 2586 |
foreach ($files as $name => $file) { |
| 2587 |
|
| 2588 |
|
| 2589 |
$file_path = $file->getRealPath(); |
| 2590 |
$relative_path = substr($file_path, strlen($source) + 1); |
| 2591 |
/* |
| 2592 |
if (!$file->isDir()) { |
| 2593 |
// Get real and relative path for current file |
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
// Add current file to archive |
| 2598 |
$zip->addFile($file_path, $relative_path); |
| 2599 |
} |
| 2600 |
*/ |
| 2601 |
|
| 2602 |
if (is_dir($file_path) === true) { |
| 2603 |
$zip->addEmptyDir(str_replace($source . '/', '', $relative_path . '/')); |
| 2604 |
} elseif (is_file($file) === true) { |
| 2605 |
$zip->addFromString(str_replace($source . '/', '', $relative_path), file_get_contents($file_path)); |
| 2606 |
} |
| 2607 |
} |
| 2608 |
} |
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
// Zip archive will be created only after closing object |
| 2613 |
$zip->close(); |
| 2614 |
|
| 2615 |
$ret = str_replace('\\', '/', $destination); |
| 2616 |
|
| 2617 |
$url = str_replace(get_home_path(), get_home_url().'/', $ret); |
| 2618 |
|
| 2619 |
$resp = array( |
| 2620 |
'url' => $url, |
| 2621 |
'path' => $destination, |
| 2622 |
); |
| 2623 |
|
| 2624 |
//pree($resp);exit; |
| 2625 |
|
| 2626 |
return $resp; |
| 2627 |
|
| 2628 |
} |
| 2629 |
|
| 2630 |
} |
| 2631 |
|
| 2632 |
if(!function_exists('wpdocs_download_zip')){ |
| 2633 |
function wpdocs_download_zip($dir_id){ |
| 2634 |
|
| 2635 |
$upload_dir = wp_upload_dir(); |
| 2636 |
$upload_dir = $upload_dir['basedir']; |
| 2637 |
$wpdocs_dir = $upload_dir.'/wpdocs'; |
| 2638 |
$current_dir_temp = wpdocs_create_dir($dir_id, $wpdocs_dir); |
| 2639 |
wpdocs_create($dir_id, $wpdocs_dir); |
| 2640 |
|
| 2641 |
$dest = $wpdocs_dir.'/'.basename($current_dir_temp).'.zip'; |
| 2642 |
|
| 2643 |
//pre($current_dir_temp);pre($dest); |
| 2644 |
//exit; |
| 2645 |
|
| 2646 |
$ret = wpdocs_generate_zip($current_dir_temp, $dest); |
| 2647 |
|
| 2648 |
//pree($ret); |
| 2649 |
if(isset($_GET['debug'])){ |
| 2650 |
exit; |
| 2651 |
} |
| 2652 |
|
| 2653 |
return $ret; |
| 2654 |
|
| 2655 |
} |
| 2656 |
} |
| 2657 |
|
| 2658 |
add_action('init', 'wpdocs_dir_actions'); |
| 2659 |
if(!function_exists('wpdocs_dir_actions')){ |
| 2660 |
function wpdocs_dir_actions(){ |
| 2661 |
|
| 2662 |
if(is_admin() && get_option('wpdocs_memphis_uninstall')){ |
| 2663 |
if(wp_docs_memphis_folder_preserve('mdocs_2', 'mdocs')){ |
| 2664 |
update_option('wpdocs_memphis_uninstall', false); |
| 2665 |
} |
| 2666 |
} |
| 2667 |
|
| 2668 |
if(isset($_GET['wpdocs_dir']) && is_numeric($_GET['wpdocs_dir']) && isset($_GET['wpdocs_wpnonce']) && wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_GET['wpdocs_wpnonce'])), "wpdocs-{$_GET['wpdocs_dir']}" )){ |
| 2669 |
|
| 2670 |
//pree($_GET);exit; |
| 2671 |
|
| 2672 |
if(isset($_GET['download'])){ |
| 2673 |
|
| 2674 |
$wpdocs_clear_clutter = get_option('wpdocs_clear_clutter', array()); |
| 2675 |
$wpdocs_clear_clutter = (is_array($wpdocs_clear_clutter)?$wpdocs_clear_clutter:array()); |
| 2676 |
if(!empty($wpdocs_clear_clutter)){ |
| 2677 |
foreach($wpdocs_clear_clutter as $i=>$wpdocs_clear_clutter_iter){ |
| 2678 |
|
| 2679 |
if(is_array($wpdocs_clear_clutter_iter)){ |
| 2680 |
|
| 2681 |
list($rm_dir, $zip_path) = $wpdocs_clear_clutter_iter; |
| 2682 |
unlink($zip_path); |
| 2683 |
|
| 2684 |
if (is_dir($rm_dir)) { |
| 2685 |
$dir = new RecursiveDirectoryIterator($rm_dir, RecursiveDirectoryIterator::SKIP_DOTS); |
| 2686 |
foreach (new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST ) as $filename => $file) { |
| 2687 |
if (is_file($filename)) |
| 2688 |
unlink($filename); |
| 2689 |
else |
| 2690 |
rmdir($filename); |
| 2691 |
} |
| 2692 |
rmdir($rm_dir); // Now remove myfolder |
| 2693 |
} |
| 2694 |
} |
| 2695 |
|
| 2696 |
unset($wpdocs_clear_clutter[$i]); |
| 2697 |
} |
| 2698 |
update_option('wpdocs_clear_clutter', $wpdocs_clear_clutter); |
| 2699 |
} |
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
$wpdocs_dir = sanitize_wpdocs_data($_GET['wpdocs_dir']); |
| 2704 |
//pree($wpdocs_dir);exit; |
| 2705 |
$zip = wpdocs_download_zip($wpdocs_dir); |
| 2706 |
$rm_dir = str_replace('.zip', '',$zip['path'] ); |
| 2707 |
//pree($rm_dir);exit; |
| 2708 |
//pree($wpdocs_dir);pree($rm_dir);pree($zip);exit; |
| 2709 |
if(file_exists($zip['path'])){ |
| 2710 |
|
| 2711 |
$wpdocs_clear_clutter = get_option('wpdocs_clear_clutter', array()); |
| 2712 |
$wpdocs_clear_clutter = (is_array($wpdocs_clear_clutter)?$wpdocs_clear_clutter:array()); |
| 2713 |
$wpdocs_clear_clutter[] = array($rm_dir, $zip['path']); |
| 2714 |
update_option('wpdocs_clear_clutter', $wpdocs_clear_clutter); |
| 2715 |
|
| 2716 |
//echo $rm_dir;exit; |
| 2717 |
|
| 2718 |
|
| 2719 |
|
| 2720 |
|
| 2721 |
//echo $zip['path'];exit; |
| 2722 |
|
| 2723 |
|
| 2724 |
header("Content-type: application/zip"); |
| 2725 |
header("Content-Disposition: attachment; filename=".basename($zip['path']).""); |
| 2726 |
header("Pragma: no-cache"); |
| 2727 |
header("Expires: 0"); |
| 2728 |
header("Content-length: " . @filesize($zip['path'])); |
| 2729 |
//readfile($zip['path']); |
| 2730 |
|
| 2731 |
wp_redirect($zip['url']);exit; |
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
}else{ |
| 2736 |
wp_redirect(admin_url('options-general.php?page=wpdocs'));exit; |
| 2737 |
} |
| 2738 |
|
| 2739 |
} |
| 2740 |
|
| 2741 |
if(isset($_GET['clear'])){ |
| 2742 |
global $wpdocs_url, $wpdb, $wpdocs_post_types; |
| 2743 |
update_option('wpdocs_options', array()); |
| 2744 |
$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->posts WHERE post_type IN ('".implode("','", $wpdocs_post_types)."')")); |
| 2745 |
wp_redirect(admin_url('options-general.php?page=wpdocs'));exit; |
| 2746 |
} |
| 2747 |
|
| 2748 |
|
| 2749 |
} |
| 2750 |
|
| 2751 |
} |
| 2752 |
|
| 2753 |
} |
| 2754 |
|
| 2755 |
function wpdocs_plugin_links($links) { |
| 2756 |
global $wpdocs_premium_link, $wpdocs_pro; |
| 2757 |
|
| 2758 |
$settings_link = '<a href="options-general.php?page=wpdocs">'.__('Settings', 'wp-docs').'</a>'; |
| 2759 |
|
| 2760 |
if($wpdocs_pro){ |
| 2761 |
array_unshift($links, $settings_link); |
| 2762 |
}else{ |
| 2763 |
|
| 2764 |
$wpdocs_premium_link = '<a href="'.esc_url($wpdocs_premium_link).'" title="'.__('Go Premium', 'wp-docs').'" target="_blank">'.__('Go Premium', 'wp-docs').'</a>'; |
| 2765 |
array_unshift($links, $settings_link, $wpdocs_premium_link); |
| 2766 |
|
| 2767 |
} |
| 2768 |
|
| 2769 |
|
| 2770 |
return $links; |
| 2771 |
} |
| 2772 |
|
| 2773 |
if(!function_exists('wpdocs_get_current_user_items')){ |
| 2774 |
|
| 2775 |
function wpdocs_get_current_user_items($dir_id, $current_user_id){ |
| 2776 |
|
| 2777 |
$current_user_files = array(); |
| 2778 |
|
| 2779 |
if ($dir_id > 0 && wpdocs_folder_exists($dir_id)) { |
| 2780 |
|
| 2781 |
$wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true); |
| 2782 |
$wpdocs_items_by_user = is_array($wpdocs_items_by_user)?$wpdocs_items_by_user:array(); |
| 2783 |
$current_user_files = array_key_exists($current_user_id, $wpdocs_items_by_user) ? $wpdocs_items_by_user[$current_user_id] : array(); |
| 2784 |
|
| 2785 |
} |
| 2786 |
|
| 2787 |
return $current_user_files; |
| 2788 |
|
| 2789 |
} |
| 2790 |
} |
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
if(!function_exists('wpdocs_is_file_belong_to_user')){ |
| 2797 |
|
| 2798 |
function wpdocs_is_file_belong_to_user($dir_id, $files, $current_user_id){ |
| 2799 |
|
| 2800 |
|
| 2801 |
if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) { |
| 2802 |
|
| 2803 |
|
| 2804 |
$current_user_files = wpdocs_get_current_user_items($dir_id, $current_user_id); |
| 2805 |
$current_user_updated_items = array_intersect($current_user_files, $files); |
| 2806 |
|
| 2807 |
return !empty($current_user_updated_items); |
| 2808 |
|
| 2809 |
|
| 2810 |
}else{ |
| 2811 |
|
| 2812 |
return false; |
| 2813 |
|
| 2814 |
} |
| 2815 |
|
| 2816 |
} |
| 2817 |
} |
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
|
| 2824 |
if(!function_exists('wpdocs_del_items_by_user')){ |
| 2825 |
function wpdocs_del_items_by_user($dir_id, $files, $current_user_id){ |
| 2826 |
|
| 2827 |
|
| 2828 |
if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) { |
| 2829 |
|
| 2830 |
|
| 2831 |
$wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true); |
| 2832 |
$current_user_files = wpdocs_get_current_user_items($dir_id, $current_user_id); |
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
$current_user_updated_items = array_diff($current_user_files, $files); |
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
$current_user_updated_items = array_unique($current_user_updated_items); |
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
$wpdocs_items_by_user[$current_user_id] = $current_user_updated_items; |
| 2846 |
|
| 2847 |
|
| 2848 |
|
| 2849 |
$wpdocs_items_by_user = array_filter($wpdocs_items_by_user); |
| 2850 |
|
| 2851 |
|
| 2852 |
return update_post_meta($dir_id, 'wpdocs_items_by_user', $wpdocs_items_by_user); |
| 2853 |
|
| 2854 |
}else{ |
| 2855 |
return false; |
| 2856 |
} |
| 2857 |
|
| 2858 |
} |
| 2859 |
} |
| 2860 |
|
| 2861 |
add_action('wp_ajax_wp_docs_import_memphis_docs', 'wp_docs_import_memphis_docs'); |
| 2862 |
|
| 2863 |
if(!function_exists('wp_docs_import_memphis_docs')){ |
| 2864 |
function wp_docs_import_memphis_docs(){ |
| 2865 |
|
| 2866 |
$result_array = array( |
| 2867 |
'status' => false, |
| 2868 |
); |
| 2869 |
|
| 2870 |
if(!empty($_POST) && isset($_POST['wp_docs_nonce'])){ |
| 2871 |
|
| 2872 |
if (!wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wp_docs_nonce'])), 'wpdocs_update_options_nonce' ) ){ |
| 2873 |
|
| 2874 |
wp_die(__("Sorry, your nonce did not verify.", 'wp-docs')); |
| 2875 |
|
| 2876 |
}else{ |
| 2877 |
|
| 2878 |
$dir_progress = wp_docs_import_memphis_directories(); |
| 2879 |
$file_progress = wp_docs_memphis_import_files(); |
| 2880 |
|
| 2881 |
$result_array['status'] = ($dir_progress || $file_progress); |
| 2882 |
|
| 2883 |
if($result_array['status']){ |
| 2884 |
wp_docs_whiteflag_memphis_htaccess(); |
| 2885 |
} |
| 2886 |
|
| 2887 |
if(!$dir_progress && !$file_progress){ |
| 2888 |
|
| 2889 |
$result_array['remarks'] = __('No directories and files found.', 'wp-docs'); |
| 2890 |
} |
| 2891 |
|
| 2892 |
} |
| 2893 |
|
| 2894 |
} |
| 2895 |
|
| 2896 |
wp_send_json($result_array); |
| 2897 |
} |
| 2898 |
} |
| 2899 |
|
| 2900 |
add_action('wp_ajax_wp_docs_import_memphis_rollback', 'wp_docs_import_memphis_rollback'); |
| 2901 |
|
| 2902 |
if(!function_exists('wp_docs_import_memphis_rollback')){ |
| 2903 |
function wp_docs_import_memphis_rollback(){ |
| 2904 |
|
| 2905 |
$result_array = array( |
| 2906 |
'status' => false, |
| 2907 |
); |
| 2908 |
|
| 2909 |
if(!empty($_POST) && isset($_POST['wp_docs_nonce'])){ |
| 2910 |
|
| 2911 |
if (!wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wp_docs_nonce'])), 'wpdocs_update_options_nonce' ) ){ |
| 2912 |
|
| 2913 |
wp_die(__("Sorry, your nonce did not verify.", 'wp-docs')); |
| 2914 |
|
| 2915 |
}else{ |
| 2916 |
|
| 2917 |
wp_docs_rollback_memphis_import(); |
| 2918 |
$result_array['status'] = true; |
| 2919 |
} |
| 2920 |
|
| 2921 |
} |
| 2922 |
|
| 2923 |
wp_send_json($result_array); |
| 2924 |
} |
| 2925 |
} |
| 2926 |
|
| 2927 |
if(!function_exists('wp_docs_get_memphis_name')){ |
| 2928 |
function wp_docs_get_memphis_name(){ |
| 2929 |
global $wpdb; |
| 2930 |
$name = esc_sql('Memphis Documents'); |
| 2931 |
|
| 2932 |
$query = $wpdb->prepare("SELECT max(ID) FROM $wpdb->posts WHERE post_title LIKE '%$name%'"); |
| 2933 |
|
| 2934 |
$result = $wpdb->get_var($query); |
| 2935 |
if($result){ |
| 2936 |
|
| 2937 |
$post = get_post($result); |
| 2938 |
|
| 2939 |
$title_array = explode(' ', $post->post_title); |
| 2940 |
$last_elment = end($title_array); |
| 2941 |
|
| 2942 |
if(is_numeric($last_elment)){ |
| 2943 |
$last_elment++; |
| 2944 |
}else{ |
| 2945 |
$last_elment = 1; |
| 2946 |
} |
| 2947 |
|
| 2948 |
$name .= ' '.$last_elment; |
| 2949 |
|
| 2950 |
} |
| 2951 |
|
| 2952 |
|
| 2953 |
return $name; |
| 2954 |
} |
| 2955 |
} |
| 2956 |
|
| 2957 |
if(!function_exists('wp_docs_get_memphis_dir_id')){ |
| 2958 |
function wp_docs_get_memphis_dir_id(){ |
| 2959 |
global $wpdb; |
| 2960 |
|
| 2961 |
$name = esc_sql('Memphis Documents'); |
| 2962 |
|
| 2963 |
$dir_id = 0; |
| 2964 |
|
| 2965 |
$query = $wpdb->prepare("SELECT max(ID) FROM $wpdb->posts WHERE post_title LIKE '%$name%'"); |
| 2966 |
|
| 2967 |
$result = $wpdb->get_var($query); |
| 2968 |
if($result){ |
| 2969 |
$dir_id = $result; |
| 2970 |
} |
| 2971 |
|
| 2972 |
|
| 2973 |
return $dir_id; |
| 2974 |
} |
| 2975 |
} |
| 2976 |
|
| 2977 |
if(!function_exists('wp_docs_import_memphis_directories')){ |
| 2978 |
|
| 2979 |
function wp_docs_import_memphis_directories(){ |
| 2980 |
global $wp_docs_is_memphis; |
| 2981 |
|
| 2982 |
$progress_status = false; |
| 2983 |
|
| 2984 |
if(!$wp_docs_is_memphis){ |
| 2985 |
|
| 2986 |
}else{ |
| 2987 |
|
| 2988 |
$memphis_folders_array = get_option('mdocs-cats', array()); |
| 2989 |
|
| 2990 |
if(!empty($memphis_folders_array)){ |
| 2991 |
|
| 2992 |
extract(wp_docs_count_memphis_folder($memphis_folders_array)); |
| 2993 |
|
| 2994 |
if($import_folder_count != $total_folder_count){ |
| 2995 |
|
| 2996 |
$parent_id = wp_docs_get_memphis_dir_id(); |
| 2997 |
if($parent_id == 0){ |
| 2998 |
|
| 2999 |
$parent_id = wpdocs_create_folder_post(0, 'Memphis Documents'); |
| 3000 |
} |
| 3001 |
wp_docs_memphis_create_directory($memphis_folders_array, $parent_id); |
| 3002 |
|
| 3003 |
$progress_status = true; |
| 3004 |
|
| 3005 |
} |
| 3006 |
|
| 3007 |
} |
| 3008 |
|
| 3009 |
} |
| 3010 |
|
| 3011 |
return $progress_status; |
| 3012 |
} |
| 3013 |
|
| 3014 |
} |
| 3015 |
|
| 3016 |
if(!function_exists('wp_docs_memphis_create_directory')){ |
| 3017 |
|
| 3018 |
function wp_docs_memphis_create_directory($directory_list, $base_parent_id){ |
| 3019 |
global $wp_docs_is_memphis, $wpdocs_imported_folder, $memphis_folders_id; |
| 3020 |
if(!$wp_docs_is_memphis){ |
| 3021 |
|
| 3022 |
}else{ |
| 3023 |
|
| 3024 |
|
| 3025 |
if(!empty($directory_list)){ |
| 3026 |
|
| 3027 |
foreach ($directory_list as $key => $single_directory) { |
| 3028 |
# code... |
| 3029 |
|
| 3030 |
$slug = $single_directory['slug']; |
| 3031 |
$name = $single_directory['name']; |
| 3032 |
$child_dir_list = $single_directory['children']; |
| 3033 |
$slug_key = $memphis_folders_id.'_'.$slug; |
| 3034 |
|
| 3035 |
if(in_array($slug_key, $wpdocs_imported_folder)) continue; |
| 3036 |
$current_parent_id = wpdocs_create_folder_post($base_parent_id, $name); |
| 3037 |
if($current_parent_id){ |
| 3038 |
|
| 3039 |
update_post_meta($current_parent_id, '_wpdocs_memphis_slug', $slug_key); |
| 3040 |
$wpdocs_imported_folder[] = $slug_key; |
| 3041 |
if(!empty($child_dir_list)){ |
| 3042 |
wp_docs_memphis_create_directory($child_dir_list, $current_parent_id); |
| 3043 |
} |
| 3044 |
|
| 3045 |
} |
| 3046 |
|
| 3047 |
} |
| 3048 |
|
| 3049 |
update_option('wpdocs_imported_folder', $wpdocs_imported_folder); |
| 3050 |
} |
| 3051 |
|
| 3052 |
} |
| 3053 |
} |
| 3054 |
|
| 3055 |
} |
| 3056 |
|
| 3057 |
|
| 3058 |
if(!function_exists('wp_docs_count_memphis_folder')){ |
| 3059 |
function wp_docs_count_memphis_folder($memphis_folders, $total_folder_count = 0, $import_folder_count = 0){ |
| 3060 |
global $memphis_folders_id, $wpdocs_imported_folder; |
| 3061 |
|
| 3062 |
if(!empty($memphis_folders)){ |
| 3063 |
foreach ($memphis_folders as $key => $folder) { |
| 3064 |
# code... |
| 3065 |
$children = $folder['children']; |
| 3066 |
$slug = $folder['slug']; |
| 3067 |
$slug_key = $memphis_folders_id.'_'.$slug; |
| 3068 |
$total_folder_count++; |
| 3069 |
|
| 3070 |
if(in_array($slug_key, $wpdocs_imported_folder)){ |
| 3071 |
$import_folder_count++; |
| 3072 |
} |
| 3073 |
|
| 3074 |
if(!empty($children)){ |
| 3075 |
extract(wp_docs_count_memphis_folder($children, $total_folder_count, $import_folder_count)); |
| 3076 |
} |
| 3077 |
} |
| 3078 |
} |
| 3079 |
|
| 3080 |
return array('total_folder_count' => $total_folder_count, 'import_folder_count' => $import_folder_count); |
| 3081 |
|
| 3082 |
} |
| 3083 |
} |
| 3084 |
|
| 3085 |
if(!function_exists('wp_docs_count_memphis_files')){ |
| 3086 |
function wp_docs_count_memphis_files(){ |
| 3087 |
|
| 3088 |
global $memphis_files_array, $wpdocs_imported_files, $wpdocs_memphis_list; |
| 3089 |
|
| 3090 |
$total_file_count = (count($memphis_files_array) + count($wpdocs_memphis_list)); |
| 3091 |
|
| 3092 |
return array('total_file_count' => $total_file_count, 'import_file_count' => count($wpdocs_memphis_list)); |
| 3093 |
|
| 3094 |
} |
| 3095 |
} |
| 3096 |
|
| 3097 |
if(!function_exists('wp_docs_memphis_statistics')){ |
| 3098 |
function wp_docs_memphis_statistics(){ |
| 3099 |
global $memphis_folders_array; |
| 3100 |
//pree($memphis_folders_array); |
| 3101 |
extract(wp_docs_count_memphis_folder($memphis_folders_array)); |
| 3102 |
extract(wp_docs_count_memphis_files()); |
| 3103 |
|
| 3104 |
return array( |
| 3105 |
'total_folder' => $total_folder_count, |
| 3106 |
'import_folder' => $import_folder_count, |
| 3107 |
'total_files' => $total_file_count, |
| 3108 |
'import_files' => $import_file_count, |
| 3109 |
); |
| 3110 |
|
| 3111 |
} |
| 3112 |
} |
| 3113 |
|
| 3114 |
if(!function_exists('wp_docs_relocate_memphis_meta')){ |
| 3115 |
function wp_docs_relocate_memphis_meta($dir_id){ |
| 3116 |
global $wpdocs_imported_files, $wpdocs_imported_folder; |
| 3117 |
$wpdocs_items = get_post_meta($dir_id, 'wpdocs_items', true); |
| 3118 |
$wpdocs_items = (is_array($wpdocs_items) ? $wpdocs_items : array()); |
| 3119 |
$dir_slug = get_post_meta($dir_id, '_wpdocs_memphis_slug', true); |
| 3120 |
|
| 3121 |
$wpdocs_imported_files = (is_array($wpdocs_imported_files)?$wpdocs_imported_files:array()); |
| 3122 |
|
| 3123 |
if(!empty($wpdocs_items)){ |
| 3124 |
|
| 3125 |
$wpdocs_imported_files = array_diff($wpdocs_imported_files, $wpdocs_items); |
| 3126 |
} |
| 3127 |
|
| 3128 |
if($dir_slug){ |
| 3129 |
$wpdocs_imported_folder = array_diff($wpdocs_imported_folder, array($dir_slug)); |
| 3130 |
} |
| 3131 |
|
| 3132 |
update_option('wpdocs_imported_folder', $wpdocs_imported_folder); |
| 3133 |
update_option('wpdocs_imported_files', $wpdocs_imported_files); |
| 3134 |
|
| 3135 |
}; |
| 3136 |
} |
| 3137 |
|
| 3138 |
if(!function_exists('wp_docs_memphis_import_files')){ |
| 3139 |
function wp_docs_memphis_import_files(){ |
| 3140 |
global $memphis_folders_id, $memphis_files_array, $wpdocs_imported_files, $wpdocs_memphis_list, $wpdocs_post_types; |
| 3141 |
|
| 3142 |
$before_count = count($wpdocs_imported_files); |
| 3143 |
if(!empty($memphis_files_array)){ |
| 3144 |
|
| 3145 |
foreach($memphis_files_array as $file_index => $file_data){ |
| 3146 |
$attachment_id = $file_data['id']; |
| 3147 |
$attachment_folder = $file_data['cat']; |
| 3148 |
$slug_key = $memphis_folders_id.'_'.$attachment_folder; |
| 3149 |
$files = array($attachment_id); |
| 3150 |
$upload_dir = wp_upload_dir(); |
| 3151 |
$upload_base_url = $upload_dir['baseurl']; |
| 3152 |
|
| 3153 |
if(in_array($attachment_id, $wpdocs_imported_files)){continue;} |
| 3154 |
|
| 3155 |
$dir_arg = array( |
| 3156 |
'post_type' => $wpdocs_post_types, |
| 3157 |
'numberposts' => '-1', |
| 3158 |
'post_status' => 'any', |
| 3159 |
'fields' => 'ids', |
| 3160 |
'meta_query' => array( |
| 3161 |
array( |
| 3162 |
'key' => '_wpdocs_memphis_slug', |
| 3163 |
'value' => $slug_key, |
| 3164 |
'compare' => '=' |
| 3165 |
) |
| 3166 |
) |
| 3167 |
); |
| 3168 |
|
| 3169 |
$dir_list = get_posts($dir_arg); |
| 3170 |
|
| 3171 |
if(!empty($dir_list)){ |
| 3172 |
foreach($dir_list as $dir_id){ |
| 3173 |
update_post_meta($attachment_id, '_wpdocs_memphis_media_file', true); |
| 3174 |
$wpdocs_imported_files[] = $attachment_id; |
| 3175 |
wpdocs_update_files_meta($dir_id, $files); |
| 3176 |
} |
| 3177 |
unset($memphis_files_array[$file_index]); |
| 3178 |
$wpdocs_memphis_list[] = $file_data; |
| 3179 |
} |
| 3180 |
} |
| 3181 |
|
| 3182 |
update_option('mdocs-list', $memphis_files_array); |
| 3183 |
update_option('wpdocs_memphis_list', $wpdocs_memphis_list); |
| 3184 |
update_option('wpdocs_imported_files', $wpdocs_imported_files); |
| 3185 |
} |
| 3186 |
$after_count = count($wpdocs_imported_files); |
| 3187 |
|
| 3188 |
return ($before_count != $after_count); |
| 3189 |
} |
| 3190 |
} |
| 3191 |
|
| 3192 |
|
| 3193 |
add_filter('pre_delete_attachment', 'wpdocs_delete_attachment_callback', 10, 3); |
| 3194 |
|
| 3195 |
if(!function_exists('wpdocs_delete_attachment_callback')){ |
| 3196 |
function wpdocs_delete_attachment_callback($check, $post, $force_delete){ |
| 3197 |
|
| 3198 |
$wpdoc_memphis_media_file = get_post_meta($post->ID, '_wpdocs_memphis_media_file', true); |
| 3199 |
$is_memphis_media = strpos($post->post_content, 'mdocs_media_attachment'); |
| 3200 |
|
| 3201 |
if($wpdoc_memphis_media_file && $is_memphis_media){ |
| 3202 |
$post->post_content = ''; |
| 3203 |
wp_update_post($post); |
| 3204 |
return $post; |
| 3205 |
}else{ |
| 3206 |
return $check; |
| 3207 |
} |
| 3208 |
|
| 3209 |
} |
| 3210 |
} |
| 3211 |
|
| 3212 |
add_action('pre_uninstall_plugin', 'wp_docs_save_attachments_to_del'); |
| 3213 |
|
| 3214 |
if(!function_exists('wp_docs_save_attachments_to_del')){ |
| 3215 |
|
| 3216 |
function wp_docs_save_attachments_to_del($plugin){ |
| 3217 |
|
| 3218 |
global $wpdocs_imported_folder, $wpdocs_imported_files, $wpdocs_memphis_list; |
| 3219 |
|
| 3220 |
$wpdocs_memphis_list = get_option('wpdocs_memphis_list', array()); |
| 3221 |
|
| 3222 |
|
| 3223 |
if($plugin == 'memphis-documents-library/memphis-documents.php'){ |
| 3224 |
if(!empty($wpdocs_memphis_list)){ |
| 3225 |
if(wp_docs_memphis_folder_preserve('mdocs', 'mdocs_2')){ |
| 3226 |
update_option('wpdocs_memphis_uninstall', true); |
| 3227 |
} |
| 3228 |
|
| 3229 |
$wpdocs_imported_folder = array(); |
| 3230 |
$wpdocs_imported_files = array(); |
| 3231 |
$wpdocs_memphis_list = array(); |
| 3232 |
|
| 3233 |
update_option('wpdocs_imported_folder', $wpdocs_imported_folder); |
| 3234 |
update_option('wpdocs_imported_files', $wpdocs_imported_files); |
| 3235 |
update_option('wpdocs_memphis_list', $wpdocs_memphis_list); |
| 3236 |
} |
| 3237 |
|
| 3238 |
|
| 3239 |
} |
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
} |
| 3244 |
|
| 3245 |
} |
| 3246 |
|
| 3247 |
if(!function_exists('wp_docs_memphis_folder_preserve')){ |
| 3248 |
function wp_docs_memphis_folder_preserve($from, $to){ |
| 3249 |
|
| 3250 |
$upload_dir = wp_upload_dir(); |
| 3251 |
$upload_basedir = $upload_dir['basedir']; |
| 3252 |
$memphis_dir = $upload_basedir.'/'.$from; |
| 3253 |
$bak_file = $memphis_dir.'/mdocs-files.bak'; |
| 3254 |
|
| 3255 |
if(file_exists($bak_file)){ |
| 3256 |
|
| 3257 |
try { |
| 3258 |
unlink($bak_file); |
| 3259 |
} catch (\Exception $ex) { |
| 3260 |
//throw $th; |
| 3261 |
} |
| 3262 |
} |
| 3263 |
$status = false; |
| 3264 |
|
| 3265 |
|
| 3266 |
if(file_exists($memphis_dir)){ |
| 3267 |
$status = rename($memphis_dir, $upload_basedir.'/'.$to); |
| 3268 |
} |
| 3269 |
|
| 3270 |
return $status; |
| 3271 |
} |
| 3272 |
} |
| 3273 |
|
| 3274 |
if(!function_exists('wp_docs_whiteflag_memphis_htaccess')){ |
| 3275 |
function wp_docs_whiteflag_memphis_htaccess(){ |
| 3276 |
|
| 3277 |
$upload_dir = wp_upload_dir(); |
| 3278 |
$basedir = $upload_dir['basedir']; |
| 3279 |
|
| 3280 |
$memphis_dir = $basedir.'/mdocs/'; |
| 3281 |
|
| 3282 |
if(is_dir($memphis_dir)){ |
| 3283 |
|
| 3284 |
$memphis_dir_ht = $memphis_dir.'.htaccess'; |
| 3285 |
$memphis_dir_index = $memphis_dir.'index.html'; |
| 3286 |
|
| 3287 |
if(file_exists($memphis_dir_ht)){ |
| 3288 |
if(!file_exists($memphis_dir_index)){ |
| 3289 |
file_put_contents($memphis_dir_index, ''); |
| 3290 |
} |
| 3291 |
/*file_put_contents($memphis_dir_ht, 'Allow from all |
| 3292 |
Options +Indexes |
| 3293 |
');*/ |
| 3294 |
unlink($memphis_dir_ht); |
| 3295 |
} |
| 3296 |
} |
| 3297 |
|
| 3298 |
} |
| 3299 |
} |
| 3300 |
|
| 3301 |
if(!function_exists('wp_docs_rollback_memphis_import')){ |
| 3302 |
function wp_docs_rollback_memphis_import(){ |
| 3303 |
|
| 3304 |
global $memphis_files_array, $wpdocs_imported_folder, $wpdocs_imported_files, $wpdocs_memphis_list, $wpdocs_post_types; |
| 3305 |
|
| 3306 |
|
| 3307 |
$wp_docs_args = array( |
| 3308 |
'post_type' => $wpdocs_post_type['dir'], |
| 3309 |
'post_status' => 'any', |
| 3310 |
'numberposts' => -1, |
| 3311 |
'meta_query' => array( |
| 3312 |
array( |
| 3313 |
'key' => '_wpdocs_memphis_slug', |
| 3314 |
'compare' => 'EXIST' |
| 3315 |
) |
| 3316 |
) |
| 3317 |
); |
| 3318 |
|
| 3319 |
$all_memphis_folder = get_posts($wp_docs_args); |
| 3320 |
|
| 3321 |
if(!empty($all_memphis_folder)){ |
| 3322 |
foreach($all_memphis_folder as $m_folder){ |
| 3323 |
wpdocs_recursive_delete_folder($m_folder->ID); |
| 3324 |
} |
| 3325 |
} |
| 3326 |
|
| 3327 |
if(!empty($wpdocs_memphis_list)){ |
| 3328 |
foreach($wpdocs_memphis_list as $file_index => $file_data){ |
| 3329 |
delete_post_meta($file_data['id'], '_wpdocs_memphis_media_file'); |
| 3330 |
unset($wpdocs_memphis_list[$file_index]); |
| 3331 |
$memphis_files_array[] = $file_data; |
| 3332 |
|
| 3333 |
} |
| 3334 |
} |
| 3335 |
|
| 3336 |
update_option('mdocs-list', $memphis_files_array); |
| 3337 |
update_option('wpdocs_memphis_list', $wpdocs_memphis_list); |
| 3338 |
update_option('wpdocs_imported_files', array()); |
| 3339 |
} |
| 3340 |
} |
| 3341 |
|
| 3342 |
function wpdocs_specific_directory_settings($dir=0, $is_file=false, $is_current_user_files=false, $is_del_from_front=false, $allowed_role=array(), $allowed_ext='', $default_ext=''){ |
| 3343 |
global $wpdocs_pro; |
| 3344 |
$dir_option_class = ''; |
| 3345 |
if($dir){ |
| 3346 |
$dir_option_class = 'wpdocs_dir_options'; |
| 3347 |
$is_file = wpdocs_dir_options_default('file_upload', false, $dir); |
| 3348 |
$is_current_user_files = wpdocs_dir_options_default('current_user_files', false, $dir); |
| 3349 |
$is_del_from_front = (is_user_logged_in() && wpdocs_dir_options_default('del_from_front', false, $dir)); |
| 3350 |
$allowed_role = wpdocs_dir_options_default('allowed_role', array(), $dir); |
| 3351 |
$allowed_ext = wpdocs_dir_options_default('allowed_ext', '', $dir); |
| 3352 |
$default_ext = ''; |
| 3353 |
|
| 3354 |
$breadcrumb = get_the_title($dir); |
| 3355 |
?> |
| 3356 |
<small class="alert alert-success d-block"><i class="fas fa-chevron-right"></i> <?php echo $breadcrumb; ?></small> |
| 3357 |
<?php |
| 3358 |
|
| 3359 |
} |
| 3360 |
?> |
| 3361 |
<label for="wpdocs_options_file"> |
| 3362 |
<input <?php checked($is_file); ?> type="checkbox" class="<?php echo $dir_option_class; ?>" name="wpdocs_options[file_upload]" value="file_upload" id="wpdocs_options_file" /> |
| 3363 |
<?php echo __('File Upload Front-end', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small> <i title="<?php echo __('This icon will appear on front-end for users', 'wp-docs'); ?>" class="fa fa-upload" style="color:#ffc107"></i> |
| 3364 |
<a href="https://www.youtube.com/embed/flFmqpJCwYk" target="_blank"><?php echo __('Video Tutorial', 'wp-docs'); ?></a> |
| 3365 |
</label> |
| 3366 |
|
| 3367 |
|
| 3368 |
|
| 3369 |
<ul class="ml-4 <?php echo $is_file ? '' : 'd-none'?>"> |
| 3370 |
<li> |
| 3371 |
<label for="wpdocs_options_current_user_files"> |
| 3372 |
<input class="<?php echo $dir_option_class; ?>" <?php checked($is_file && $is_current_user_files); ?> type="checkbox" name="wpdocs_options[current_user_files]" value="current_user_files" id="wpdocs_options_current_user_files" /> |
| 3373 |
<?php echo __('Do not make files public uploaded by users', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small> |
| 3374 |
</label> |
| 3375 |
</li> |
| 3376 |
|
| 3377 |
<li> |
| 3378 |
<label for="wpdocs_options_del_from_front"> |
| 3379 |
<input class="<?php echo $dir_option_class; ?>" <?php checked($is_file && $is_del_from_front); ?> type="checkbox" name="wpdocs_options[del_from_front]" value="del_from_front" id="wpdocs_options_del_from_front" /> |
| 3380 |
<?php echo __('User can delete the files from front-end?', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small> <i class="fas fa-trash-alt" style="color:#ffc107"></i> |
| 3381 |
</label> |
| 3382 |
</li> |
| 3383 |
|
| 3384 |
<li> |
| 3385 |
<label for="wpdocs_options_allowed_role"> |
| 3386 |
<?php echo __('Allow user roles which can upload files', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small> <i class="fas fa-users" style="color:#ffc107"></i> |
| 3387 |
</label> |
| 3388 |
|
| 3389 |
|
| 3390 |
|
| 3391 |
<select class="wpdocs_options_allowed_role <?php echo $dir_option_class; ?>" name="wpdocs_options[allowed_role]" data-name="allowed_role" id="wpdocs_options_allowed_role" multiple placeholder="<?php echo __('Select roles to allow upload', 'wp-docs'); ?>"> |
| 3392 |
|
| 3393 |
<?php echo wpdocs_get_user_roles_options($allowed_role) ?> |
| 3394 |
|
| 3395 |
</select> |
| 3396 |
|
| 3397 |
|
| 3398 |
</li> |
| 3399 |
|
| 3400 |
<li> |
| 3401 |
<label for="wpdocs_options_allowed_ext"> |
| 3402 |
<?php echo __('Allowed File Types', 'wp-docs'); ?> <?php echo ($wpdocs_pro?'':'<small>'.__('(Premium)', 'wp-docs').'</small> '); ?> <i class="fas fa-photo-video" style="color:#ffc107"></i> |
| 3403 |
</label> |
| 3404 |
<input type="text" class="form-control <?php echo $dir_option_class; ?>" name="wpdocs_options[allowed_ext]" data-name="allowed_ext" value="<?php echo $allowed_ext; ?>" id="wpdocs_options_allowed_ext" title="<?php _e('Leave blank if you want to allow all type of files', 'wp-docs'); ?>" placeholder="<?php echo $default_ext; ?>" /> |
| 3405 |
|
| 3406 |
</li> |
| 3407 |
|
| 3408 |
</ul> |
| 3409 |
<?php |
| 3410 |
} |
| 3411 |
|
| 3412 |
if(!function_exists('wpdocs_dir_options_by_name')){ |
| 3413 |
function wpdocs_dir_options_by_name($option_name, $default_return = false, $dir = 0){ |
| 3414 |
|
| 3415 |
global $wpdocs_options; |
| 3416 |
|
| 3417 |
$dir_options = array(); |
| 3418 |
|
| 3419 |
if($dir > 0){ |
| 3420 |
$dir_options = get_post_meta($dir, '_wpdocs_dir_options', true); |
| 3421 |
$dir_options = (is_array($dir_options) ? $dir_options : array()); |
| 3422 |
} |
| 3423 |
|
| 3424 |
$key_exist = false; |
| 3425 |
$search_options = array(); |
| 3426 |
|
| 3427 |
if(array_key_exists($option_name, $dir_options)){ |
| 3428 |
$search_options = $dir_options; |
| 3429 |
$key_exist = true; |
| 3430 |
|
| 3431 |
|
| 3432 |
}else if(array_key_exists($option_name, $wpdocs_options)){ |
| 3433 |
|
| 3434 |
$search_options = $wpdocs_options; |
| 3435 |
$key_exist = true; |
| 3436 |
} |
| 3437 |
|
| 3438 |
if($key_exist){ |
| 3439 |
|
| 3440 |
$return_value = $search_options[$option_name]; |
| 3441 |
$return_value = (is_array($default_return) && !is_array($return_value) ? array() : $return_value); |
| 3442 |
$default_return = $return_value; |
| 3443 |
|
| 3444 |
} |
| 3445 |
|
| 3446 |
if($default_return == 'true'){ |
| 3447 |
$default_return = true; |
| 3448 |
}elseif($default_return == 'false'){ |
| 3449 |
$default_return = false; |
| 3450 |
} |
| 3451 |
|
| 3452 |
return $default_return; |
| 3453 |
} |
| 3454 |
} |
| 3455 |
|
| 3456 |
if(!function_exists('wpdocs_dir_options_default')){ |
| 3457 |
function wpdocs_dir_options_default($option_name, $default_return = false, $dir = 0){ |
| 3458 |
|
| 3459 |
global $wpdocs_options; |
| 3460 |
|
| 3461 |
$dir_options = array(); |
| 3462 |
|
| 3463 |
if($dir > 0){ |
| 3464 |
$dir_options = get_post_meta($dir, '_wpdocs_dir_options', true); |
| 3465 |
$dir_options = (is_array($dir_options) ? $dir_options : array()); |
| 3466 |
} |
| 3467 |
|
| 3468 |
$key_exist = false; |
| 3469 |
$search_options = array(); |
| 3470 |
|
| 3471 |
if(array_key_exists($option_name, $dir_options)){ |
| 3472 |
$search_options = $dir_options; |
| 3473 |
$key_exist = true; |
| 3474 |
} |
| 3475 |
|
| 3476 |
if($key_exist){ |
| 3477 |
|
| 3478 |
$return_value = $search_options[$option_name]; |
| 3479 |
$return_value = (is_array($default_return) && !is_array($return_value) ? array() : $return_value); |
| 3480 |
$default_return = $return_value; |
| 3481 |
|
| 3482 |
} |
| 3483 |
|
| 3484 |
if($default_return == 'true'){ |
| 3485 |
$default_return = true; |
| 3486 |
}elseif($default_return == 'false'){ |
| 3487 |
$default_return = false; |
| 3488 |
} |
| 3489 |
|
| 3490 |
return $default_return; |
| 3491 |
} |
| 3492 |
} |
| 3493 |
|
| 3494 |
if(!function_exists('wpdocs_get_dir_restrictions')){ |
| 3495 |
function wpdocs_get_dir_restrictions($dir = 0, $rest_type = 'array'){ |
| 3496 |
|
| 3497 |
$dir_restrictions = array(); |
| 3498 |
|
| 3499 |
if($dir > 0){ |
| 3500 |
$dir_options = get_post_meta($dir, '_wpdocs_dir_options', true); |
| 3501 |
$dir_options = (is_array($dir_options) ? $dir_options : array()); |
| 3502 |
$is_file_upload = array_key_exists('file_upload', $dir_options) && $dir_options['file_upload'] == 'true'; |
| 3503 |
$dir_restrictions = $dir_options; |
| 3504 |
} |
| 3505 |
|
| 3506 |
|
| 3507 |
switch ($rest_type) { |
| 3508 |
case 'array': |
| 3509 |
# code... |
| 3510 |
return $dir_restrictions; |
| 3511 |
break; |
| 3512 |
|
| 3513 |
case 'json': |
| 3514 |
# code... |
| 3515 |
if(!empty($dir_options)){ |
| 3516 |
return wp_json_encode($dir_restrictions); |
| 3517 |
|
| 3518 |
}else{ |
| 3519 |
return ''; |
| 3520 |
} |
| 3521 |
break; |
| 3522 |
|
| 3523 |
case 'base64': |
| 3524 |
# code... |
| 3525 |
|
| 3526 |
if(!empty($dir_options)){ |
| 3527 |
return base64_encode(wp_json_encode($dir_restrictions)); |
| 3528 |
}else{ |
| 3529 |
return ''; |
| 3530 |
} |
| 3531 |
break; |
| 3532 |
|
| 3533 |
} |
| 3534 |
|
| 3535 |
|
| 3536 |
|
| 3537 |
} |
| 3538 |
} |
| 3539 |
|
| 3540 |
|
| 3541 |
add_action('init', function(){ |
| 3542 |
|
| 3543 |
global $wpdocs_current_theme; |
| 3544 |
$wpdocs_current_theme = str_replace(array('-', ' '), '_', strtolower(wp_get_theme())); |
| 3545 |
|
| 3546 |
// return; |
| 3547 |
// wpdoc_get_dir_children(8764); |
| 3548 |
}); |
| 3549 |
|
| 3550 |
if(!function_exists('wpdoc_get_dir_children')){ |
| 3551 |
function wpdoc_get_dir_children($parent_id){ |
| 3552 |
|
| 3553 |
global $wpdocs_post_types; |
| 3554 |
|
| 3555 |
$all_folder_query = new WP_Query(); |
| 3556 |
$all_folder = $all_folder_query->query(array('post_type' => $wpdocs_post_types, 'post_status' => 'any', 'numberposts' => -1)); |
| 3557 |
|
| 3558 |
$all_folders_array = get_page_children( $parent_id, $all_folder ); |
| 3559 |
$all_folders_array = array_map(function($single){return $single->ID;}, $all_folders_array); |
| 3560 |
|
| 3561 |
return $all_folders_array; |
| 3562 |
|
| 3563 |
} |
| 3564 |
} |
| 3565 |
|
| 3566 |
if(!function_exists('wpdoc_humanize')){ |
| 3567 |
function wpdoc_humanize($str){ |
| 3568 |
return ucwords(str_replace(array('-', '_'), ' ', $str)); |
| 3569 |
} |
| 3570 |
} |
| 3571 |
|