| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: User Private Files |
| 4 |
* Description: This plugin allows users to manage their uploaded files and access to them. |
| 5 |
* Version: 2.1.5 |
| 6 |
* Author: User Private Files |
| 7 |
* Author URI: https://userprivatefiles.com/?utm_source=wp-plugin-author&utm_medium=wporg |
| 8 |
* License: GPLv2 or later |
| 9 |
* Text Domain: user-private-files |
| 10 |
* Domain Path: /languages |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly |
| 14 |
if ( ! defined('ABSPATH') ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
include_once dirname( __FILE__ ) . '/upvf_actdeact.php'; |
| 19 |
register_activation_hook( __FILE__, array( 'Upvf_Actdeact', 'upvf_plugin_activate' ) ); |
| 20 |
register_deactivation_hook( __FILE__, array( 'Upvf_Actdeact', 'upvf_plugin_deactivate') ); |
| 21 |
|
| 22 |
add_action( 'admin_init', 'upvf_admin_init_plugin', 1 ); |
| 23 |
if (!function_exists('upvf_admin_init_plugin')) { |
| 24 |
function upvf_admin_init_plugin(){ |
| 25 |
// check if htaccess is writable |
| 26 |
$htaccess = ABSPATH.".htaccess"; |
| 27 |
if ( ! is_writeable( $htaccess ) ) { |
| 28 |
add_action( 'admin_notices', function(){ |
| 29 |
$upload_dir = wp_upload_dir(); |
| 30 |
$manual_htcode = "RewriteRule ^".basename(content_url()) . "/" . wp_basename( $upload_dir['baseurl'] )."/upf-docs/(.*)$ ".home_url()."?file=$1 [QSA,L]"; |
| 31 |
echo '<div class="notice notice-warning is-dismissible"> |
| 32 |
<p>Your htaccess file is not writable. Please change permission and reactivate the plugin OR edit the htaccess file manually and enter this code at the bottom. Please ignore if already added!</p> |
| 33 |
<p><code>'.$manual_htcode.'</code></p> |
| 34 |
</div>'; |
| 35 |
} ); |
| 36 |
add_action('admin_head', function(){ ?> |
| 37 |
<script> |
| 38 |
let hta_access = 0; |
| 39 |
jQuery(document).ready(function(){ |
| 40 |
jQuery('#deactivate-user-private-files').on('click', function(){ |
| 41 |
alert('Your htaccess file is not writable. Please check and remove the code from htaccess (if manually added)'); |
| 42 |
}); |
| 43 |
}) |
| 44 |
</script> |
| 45 |
<?php }); |
| 46 |
} |
| 47 |
// check if plugin created uploads folder or not |
| 48 |
$upload_dir = wp_upload_dir(); |
| 49 |
$upf_dir_path = $upload_dir['basedir'] . "/upf-docs"; |
| 50 |
$created_dir = wp_mkdir_p($upf_dir_path); |
| 51 |
if(!$created_dir){ |
| 52 |
add_action('admin_head', function(){ |
| 53 |
echo '<div class="notice notice-warning is-dismissible"><p>Plugin was unable to create directory in uploads. Please create a "upf-docs" directory/folder under your uploads directory</p></div>'; |
| 54 |
}); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
add_action( 'init', 'upvf_init_plugin', 1 ); |
| 60 |
if (!function_exists('upvf_init_plugin')) { |
| 61 |
function upvf_init_plugin(){ |
| 62 |
define ( 'UPVF_PLUGIN_DIR', plugin_dir_path(__FILE__ ) ); |
| 63 |
global $upf_plugin_url; |
| 64 |
$upf_plugin_url = plugin_dir_url( __FILE__ ); |
| 65 |
add_action( 'wp_enqueue_scripts', 'upf_styles_scripts' ); |
| 66 |
add_action( 'admin_enqueue_scripts', 'upfp_admin_script' ); |
| 67 |
|
| 68 |
// Including other functions |
| 69 |
include(plugin_dir_path(__FILE__ ) . 'templates/classic-post-new.php'); |
| 70 |
include(plugin_dir_path(__FILE__ ) . 'templates/classic-render.php'); |
| 71 |
include(plugin_dir_path(__FILE__ ) . 'inc/classic-user-functions.php'); |
| 72 |
|
| 73 |
// PRO Design |
| 74 |
include(plugin_dir_path(__FILE__ ) . 'admin/settings.php'); |
| 75 |
include(plugin_dir_path(__FILE__ ) . 'inc/class-upf-template-loader.php'); |
| 76 |
global $upvf_template_loader; |
| 77 |
$upvf_template_loader = new UPF_Template_Loader(); |
| 78 |
include(plugin_dir_path(__FILE__ ) . 'inc/shortcodes.php'); |
| 79 |
include(plugin_dir_path(__FILE__ ) . 'inc/functions-file.php'); |
| 80 |
include(plugin_dir_path(__FILE__ ) . 'inc/functions-folder.php'); |
| 81 |
include(plugin_dir_path(__FILE__ ) . 'filters.php'); |
| 82 |
include(plugin_dir_path(__FILE__ ) . 'actions.php'); |
| 83 |
|
| 84 |
load_plugin_textdomain( 'user-private-files', false, 'user-private-files' ); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
// Include file permission functions |
| 89 |
add_filter( 'template_include', 'upvf_check_perm' ); |
| 90 |
if (!function_exists('upvf_check_perm')) { |
| 91 |
function upvf_check_perm( $original_template ) { |
| 92 |
if(isset($_GET[ 'file' ])){ |
| 93 |
$template = dirname( __FILE__ ) . '/dl-file.php'; |
| 94 |
if ( file_exists( $template ) ) { |
| 95 |
include $template; |
| 96 |
} |
| 97 |
return $template; |
| 98 |
} else { |
| 99 |
return $original_template; |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
// Back-end assets |
| 105 |
if (!function_exists('upfp_admin_script')) { |
| 106 |
function upfp_admin_script(){ |
| 107 |
wp_enqueue_style( |
| 108 |
'upf-admin-style', |
| 109 |
plugin_dir_url( __FILE__ ) . 'css/admin/admin_free.css' |
| 110 |
); |
| 111 |
wp_enqueue_script( |
| 112 |
'upf-admin-script', |
| 113 |
plugins_url('js/admin/admin-upf_free.js',__FILE__ ), |
| 114 |
array('jquery') |
| 115 |
); |
| 116 |
wp_enqueue_style( |
| 117 |
'upf-multiple_choose-style', |
| 118 |
plugin_dir_url(__FILE__) . 'css/admin/chosen.min.css', |
| 119 |
); |
| 120 |
wp_enqueue_script( |
| 121 |
'upf-multiple_choose-script2', |
| 122 |
plugins_url('js/lib/chosen.jquery.min.js',__FILE__ ), |
| 123 |
array('jquery'), |
| 124 |
); |
| 125 |
wp_enqueue_style( |
| 126 |
'upf-adm-font-awesome', |
| 127 |
plugin_dir_url(__FILE__) . 'css/fa.min.css', |
| 128 |
array(), |
| 129 |
); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if (!function_exists('upf_styles_scripts')) { |
| 134 |
function upf_styles_scripts(){ |
| 135 |
|
| 136 |
wp_register_style( |
| 137 |
'upf-classic-style', |
| 138 |
plugin_dir_url( __FILE__ ) . 'css/classic-style.css' |
| 139 |
); |
| 140 |
wp_register_script( |
| 141 |
'upf-classic-script', |
| 142 |
plugins_url('js/classic-main.js',__FILE__ ), |
| 143 |
array('jquery') |
| 144 |
); |
| 145 |
wp_localize_script( |
| 146 |
'upf-classic-script', |
| 147 |
'ajax_upf_classic_obj', |
| 148 |
array( |
| 149 |
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 150 |
'upvf_plugin_url' => plugin_dir_url( __FILE__ ), |
| 151 |
'nonce' => wp_create_nonce('upf_classic_ajax_nonce'), |
| 152 |
'restURL' => rest_url(), |
| 153 |
'restNonce' => wp_create_nonce('wp_rest') |
| 154 |
) |
| 155 |
); |
| 156 |
|
| 157 |
wp_register_style( |
| 158 |
'upf-style', |
| 159 |
plugin_dir_url( __FILE__ ) . 'css/style.css' |
| 160 |
); |
| 161 |
|
| 162 |
// FA local since kit is limited to views per month |
| 163 |
wp_register_style( |
| 164 |
'upf-font-awesome', |
| 165 |
plugin_dir_url(__FILE__) . 'css/fa.min.css' |
| 166 |
); |
| 167 |
|
| 168 |
wp_register_style( |
| 169 |
'upf-google-font', |
| 170 |
'https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&display=swap', |
| 171 |
array(), |
| 172 |
'null' |
| 173 |
); |
| 174 |
|
| 175 |
wp_register_script( |
| 176 |
'upf-waitforimages-script', |
| 177 |
plugins_url('js/waitforimages.min.js',__FILE__ ), |
| 178 |
array('jquery') |
| 179 |
); |
| 180 |
wp_register_script( |
| 181 |
'upf-script', |
| 182 |
plugins_url('js/file.js',__FILE__ ), |
| 183 |
array('jquery') |
| 184 |
); |
| 185 |
wp_register_script( |
| 186 |
'upvf-frnt-script', |
| 187 |
plugins_url('js/folder.js',__FILE__ ), |
| 188 |
array('jquery') |
| 189 |
); |
| 190 |
wp_register_script( |
| 191 |
'upvf-bulk-script', |
| 192 |
plugins_url('js/bulk-action.js',__FILE__ ), |
| 193 |
array('jquery') |
| 194 |
); |
| 195 |
|
| 196 |
wp_localize_script( |
| 197 |
'upf-script', |
| 198 |
'ajax_upf_obj', |
| 199 |
array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 200 |
'upvf_plugin_url' => plugin_dir_url( __FILE__ ), |
| 201 |
'nonce' => wp_create_nonce('upfp_ajax_nonce'), |
| 202 |
'max_upload_size' => wp_max_upload_size(), |
| 203 |
'max_err' => __("Uploaded file exceeds the maximum upload size for this site", "user-private-files") |
| 204 |
) |
| 205 |
); |
| 206 |
wp_localize_script( |
| 207 |
'upvf-frnt-script', |
| 208 |
'ajax_upvf_frnt_obj', |
| 209 |
array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 210 |
'upvf_plugin_url' => plugin_dir_url( __FILE__ ), |
| 211 |
'nonce' => wp_create_nonce('upfp_ajax_nonce') |
| 212 |
) |
| 213 |
); |
| 214 |
wp_localize_script( |
| 215 |
'upvf-bulk-script', |
| 216 |
'ajax_upvf_bulk_obj', |
| 217 |
array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 218 |
'nonce' => wp_create_nonce('upfp_ajax_nonce') |
| 219 |
) |
| 220 |
); |
| 221 |
|
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
if(is_admin()){ |
| 226 |
// Plugin Configuration Page |
| 227 |
add_action( 'plugins_loaded', 'upvf_set_admin_menu' ); |
| 228 |
if (!function_exists('upvf_set_admin_menu')) { |
| 229 |
function upvf_set_admin_menu(){ |
| 230 |
add_action('admin_menu', 'upvf_admin_config', 999); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
if (!function_exists('upvf_admin_config')) { |
| 235 |
function upvf_admin_config() { |
| 236 |
add_menu_page('User Private Files', 'User Private Files', 'manage_options', 'upvf-free', 'upvf_config_callback', 'dashicons-superhero'); |
| 237 |
add_submenu_page('upvf-free', 'Settings', 'Settings', 'manage_options', 'upvf-free', 'upvf_config_callback', 1); |
| 238 |
add_submenu_page('upvf-free', 'Admin File Manager', 'Admin File Manager', 'manage_options', 'upvf-free-files', 'upvf_config_backend_fm_callback', 2); |
| 239 |
add_submenu_page('upvf-free', 'Activity Logs', 'Activity Logs', 'manage_options', 'upvf-free-activities', 'upvf_config_activities_log_callback', 2); |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|