| @@ -1,81 +1,341 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: User Access Manager |
| 4 | - * Plugin URI: https://wordpress.org/plugins/user-access-manager/ | |
| 5 | - * Author URI: https://twitter.com/GM_Alex | |
| 6 | - * Version: 2.3.20 | |
| 7 | - * Requires PHP: 8.0 | |
| 4 | + * Plugin URI: http://www.gm-alex.de/projects/wordpress/plugins/user-access-manager/ | |
| 5 | + * Author URI: http://www.gm-alex.de/ | |
| 6 | + * Version: 1.2.2 | |
| 8 | 7 | * Author: Alexander Schneider |
| 9 | 8 | * Description: Manage the access to your posts, pages, categories and files. |
| 10 | - * Text Domain: user-access-manager | |
| 11 | - * | |
| 9 | + * | |
| 12 | 10 | * user-access-manager.php |
| 13 | 11 | * |
| 14 | - * The user access manager main file. | |
| 15 | - * | |
| 16 | 12 | * PHP versions 5 |
| 17 | - * | |
| 13 | + * | |
| 14 | + * @category UserAccessManager | |
| 15 | + * @package UserAccessManager | |
| 18 | 16 | * @author Alexander Schneider <[email protected]> |
| 19 | - * @copyright 2008-2017 Alexander Schneider | |
| 17 | + * @copyright 2008-2010 Alexander Schneider | |
| 20 | 18 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 21 | - * @version SVN: $id$ | |
| 19 | + * @version SVN: $Id$ | |
| 22 | 20 | * @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 23 | - */ | |
| 21 | +*/ | |
| 24 | 22 | |
| 25 | -function initUam() { | |
| 26 | - $basePath = __DIR__ . DIRECTORY_SEPARATOR; | |
| 23 | +//Paths | |
| 24 | +load_plugin_textdomain( | |
| 25 | + 'user-access-manager', | |
| 26 | + false, | |
| 27 | + 'user-access-manager/lang' | |
| 28 | +); | |
| 27 | 29 | |
| 28 | - //Load language | |
| 29 | - require_once $basePath . 'includes' . DIRECTORY_SEPARATOR . 'language.php'; | |
| 30 | - $locale = apply_filters('plugin_locale', get_locale(), 'user-access-manager'); | |
| 31 | - load_textdomain( | |
| 32 | - 'user-access-manager', | |
| 33 | - WP_LANG_DIR . DIRECTORY_SEPARATOR . 'user-access-manager' . DIRECTORY_SEPARATOR . 'user-access-manager-' . $locale . '.mo' | |
| 30 | +define( | |
| 31 | + 'UAM_URLPATH', | |
| 32 | + WP_PLUGIN_URL.'/user-access-manager/' | |
| 33 | +); | |
| 34 | + | |
| 35 | +if (defined('UAM_LOCAL_DEBUG')) { | |
| 36 | + //ONLY FOR MY LOCAL DEBUG | |
| 37 | + define( | |
| 38 | + 'UAM_REALPATH', | |
| 39 | + '/'.plugin_basename(dirname(__FILE__)).'/' | |
| 34 | 40 | ); |
| 35 | - load_plugin_textdomain( | |
| 36 | - 'user-access-manager', | |
| 37 | - false, | |
| 38 | - plugin_basename(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'languages' | |
| 41 | +} else { | |
| 42 | + define( | |
| 43 | + 'UAM_REALPATH', | |
| 44 | + WP_PLUGIN_DIR.'/'.plugin_basename(dirname(__FILE__)).'/' | |
| 39 | 45 | ); |
| 46 | +} | |
| 40 | 47 | |
| 41 | - //--- Check requirements --- | |
| 42 | 48 | |
| 43 | - //Check php version | |
| 44 | - if (version_compare((string)phpversion(), '7.2') === -1) { | |
| 45 | - add_action( | |
| 46 | - 'admin_notices', | |
| 47 | - function () { | |
| 48 | - echo '<div id="message" class="error"><p><strong>' | |
| 49 | - . sprintf(TXT_UAM_PHP_VERSION_TO_LOW, phpversion()) | |
| 50 | - . '</strong></p></div>'; | |
| 51 | - } | |
| 52 | - ); | |
| 49 | +//Defines | |
| 50 | +require_once 'includes/database.define.php'; | |
| 51 | +require_once 'includes/language.define.php'; | |
| 53 | 52 | |
| 54 | - return; | |
| 55 | - } | |
| 56 | 53 | |
| 57 | - //Check WordPress version | |
| 58 | - global $wp_version; | |
| 54 | +//Check requirements | |
| 55 | +$stop = false; | |
| 59 | 56 | |
| 60 | - if (version_compare((string)$wp_version, '4.6') === -1) { | |
| 61 | - add_action( | |
| 62 | - 'admin_notices', | |
| 63 | - function () use ($wp_version) { | |
| 64 | - echo '<div id="message" class="error"><p><strong>' | |
| 65 | - . sprintf(TXT_UAM_WORDPRESS_VERSION_TO_LOW, $wp_version) | |
| 66 | - . '</strong></p></div>'; | |
| 57 | +//Check php version | |
| 58 | +$phpVersion = phpversion(); | |
| 59 | + | |
| 60 | +if (version_compare($phpVersion, "5.0") === -1) { | |
| 61 | + add_action( | |
| 62 | + 'admin_notices', | |
| 63 | + create_function( | |
| 64 | + '', | |
| 65 | + 'echo \'<div id="message" class="error"><p><strong>'. | |
| 66 | + sprintf(TXT_UAM_PHP_VERSION_TO_LOW, $phpVersion). | |
| 67 | + '</strong></p></div>\';' | |
| 68 | + ) | |
| 69 | + ); | |
| 70 | + | |
| 71 | + $stop = true; | |
| 72 | +} | |
| 73 | + | |
| 74 | +//Check wordpress version | |
| 75 | +global $wp_version; | |
| 76 | + | |
| 77 | +if (version_compare($wp_version, "3.0") === -1) { | |
| 78 | + add_action( | |
| 79 | + 'admin_notices', | |
| 80 | + create_function( | |
| 81 | + '', | |
| 82 | + 'echo \'<div id="message" class="error"><p><strong>'. | |
| 83 | + sprintf(TXT_UAM_WORDPRESS_VERSION_TO_LOW, $wp_version). | |
| 84 | + '</strong></p></div>\';' | |
| 85 | + ) | |
| 86 | + ); | |
| 87 | + | |
| 88 | + $stop = true; | |
| 89 | +} | |
| 90 | + | |
| 91 | +//If we have a error stop plugin. | |
| 92 | +if ($stop) { | |
| 93 | + return; | |
| 94 | +} | |
| 95 | + | |
| 96 | + | |
| 97 | +//Classes | |
| 98 | +require_once 'class/UserAccessManager.class.php'; | |
| 99 | +require_once 'class/UamUserGroup.class.php'; | |
| 100 | +require_once 'class/UamAccessHandler.class.php'; | |
| 101 | + | |
| 102 | +if (class_exists("UserAccessManager")) { | |
| 103 | + $userAccessManager = new UserAccessManager(); | |
| 104 | +} | |
| 105 | + | |
| 106 | +//Initialize the admin panel | |
| 107 | +if (!function_exists("userAccessManagerAP")) { | |
| 108 | + /** | |
| 109 | + * Creates the filters and actions for the admin panel | |
| 110 | + * | |
| 111 | + * @return null; | |
| 112 | + */ | |
| 113 | + function userAccessManagerAP() | |
| 114 | + { | |
| 115 | + global $userAccessManager, | |
| 116 | + $current_user; | |
| 117 | + | |
| 118 | + if (!isset($userAccessManager)) { | |
| 119 | + return; | |
| 120 | + } | |
| 121 | + | |
| 122 | + $userAccessManager->setAtAdminPanel(); | |
| 123 | + $uamOptions = $userAccessManager->getAdminOptions(); | |
| 124 | + | |
| 125 | + if ($userAccessManager->isDatabaseUpdateNecessary()) { | |
| 126 | + $link = 'admin.php?page=uam_setup'; | |
| 127 | + | |
| 128 | + add_action( | |
| 129 | + 'admin_notices', | |
| 130 | + create_function( | |
| 131 | + '', | |
| 132 | + 'echo \'<div id="message" class="error"><p><strong>'. | |
| 133 | + sprintf(TXT_UAM_NEED_DATABASE_UPDATE, $link). | |
| 134 | + '</strong></p></div>\';' | |
| 135 | + ) | |
| 136 | + ); | |
| 137 | + } | |
| 138 | + | |
| 139 | + get_currentuserinfo(); | |
| 140 | + $curUserdata = get_userdata($current_user->ID); | |
| 141 | + $uamAccessHandler = $userAccessManager->getAccessHandler(); | |
| 142 | + | |
| 143 | + if ($uamAccessHandler->checkUserAccess() | |
| 144 | + || $uamOptions['authors_can_add_posts_to_groups'] == 'true' | |
| 145 | + ) { | |
| 146 | + //Admin actions | |
| 147 | + if (function_exists('add_action')) { | |
| 148 | + add_action('admin_print_styles', array(&$userAccessManager, 'addStyles')); | |
| 149 | + add_action('wp_print_scripts', array(&$userAccessManager, 'addScripts')); | |
| 150 | + | |
| 151 | + add_action('manage_posts_custom_column', array(&$userAccessManager, 'addPostColumn'), 10, 2); | |
| 152 | + add_action('manage_pages_custom_column', array(&$userAccessManager, 'addPostColumn'), 10, 2); | |
| 153 | + add_action('save_post', array(&$userAccessManager, 'savePostData')); | |
| 154 | + | |
| 155 | + add_action('manage_media_custom_column', array(&$userAccessManager, 'addPostColumn'), 10, 2); | |
| 156 | + | |
| 157 | + //Actions are only called when the attachment content is modified so we can't use it. | |
| 158 | + //add_action('add_attachment', array(&$userAccessManager, 'savePostData')); | |
| 159 | + //add_action('edit_attachment', array(&$userAccessManager, 'savePostData')); | |
| 160 | + | |
| 161 | + add_action('edit_user_profile', array(&$userAccessManager, 'showUserProfile')); | |
| 162 | + add_action('profile_update', array(&$userAccessManager, 'saveUserData')); | |
| 163 | + | |
| 164 | + add_action('edit_category_form', array(&$userAccessManager, 'showCategoryEditForm')); | |
| 165 | + add_action('create_category', array(&$userAccessManager, 'saveCategoryData')); | |
| 166 | + add_action('edit_category', array(&$userAccessManager, 'saveCategoryData')); | |
| 67 | 167 | } |
| 68 | - ); | |
| 168 | + | |
| 169 | + //Admin filters | |
| 170 | + if (function_exists('add_filter')) { | |
| 171 | + //The filter we use instead of add|edit_attachment action, reason see top | |
| 172 | + add_filter('attachment_fields_to_save', array(&$userAccessManager, 'saveAttachmentData')); | |
| 173 | + | |
| 174 | + add_filter('manage_posts_columns', array(&$userAccessManager, 'addPostColumnsHeader')); | |
| 175 | + add_filter('manage_pages_columns', array(&$userAccessManager, 'addPostColumnsHeader')); | |
| 176 | + | |
| 177 | + add_filter('manage_users_columns', array(&$userAccessManager, 'addUserColumnsHeader'), 10); | |
| 178 | + add_filter('manage_users_custom_column', array(&$userAccessManager, 'addUserColumn'), 10, 3); | |
| 179 | + | |
| 180 | + add_filter('manage_edit-category_columns', array(&$userAccessManager, 'addCategoryColumnsHeader')); | |
| 181 | + add_filter('manage_category_custom_column', array(&$userAccessManager, 'addCategoryColumn'), 10, 3); | |
| 182 | + } | |
| 183 | + | |
| 184 | + if ($uamOptions['lock_file'] == 'true') { | |
| 185 | + add_action('media_meta', array(&$userAccessManager, 'showMediaFile'), 10, 2); | |
| 186 | + add_filter('manage_media_columns', array(&$userAccessManager, 'addPostColumnsHeader')); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + | |
| 190 | + //Clean up at deleting should be always done. | |
| 191 | + if (function_exists('add_action')) { | |
| 192 | + add_action('update_option_permalink_structure', array(&$userAccessManager, 'updatePermalink')); | |
| 193 | + add_action('wp_dashboard_setup', array(&$userAccessManager, 'setupAdminDashboard')); | |
| 194 | + add_action('delete_post', array(&$userAccessManager, 'removePostData')); | |
| 195 | + add_action('delete_attachment', array(&$userAccessManager, 'removePostData')); | |
| 196 | + add_action('delete_user', array(&$userAccessManager, 'removeUserData')); | |
| 197 | + add_action('delete_category', array(&$userAccessManager, 'removeCategoryData'), 10, 2); | |
| 198 | + } | |
| 199 | + | |
| 200 | + $userAccessManager->noRightsToEditContent(); | |
| 201 | + } | |
| 202 | +} | |
| 69 | 203 | |
| 70 | - return; | |
| 204 | +if (!function_exists("userAccessManagerAPMenu")) { | |
| 205 | + /** | |
| 206 | + * Creates the menu at the admin panel | |
| 207 | + * | |
| 208 | + * @return null; | |
| 209 | + */ | |
| 210 | + function userAccessManagerAPMenu() | |
| 211 | + { | |
| 212 | + global $userAccessManager, | |
| 213 | + $current_user; | |
| 214 | + | |
| 215 | + if (!isset($userAccessManager)) { | |
| 216 | + return; | |
| 217 | + } | |
| 218 | + | |
| 219 | + $uamOptions = $userAccessManager->getAdminOptions(); | |
| 220 | + | |
| 221 | + if (ini_get('safe_mode') | |
| 222 | + && $uamOptions['download_type'] == 'fopen' | |
| 223 | + ) { | |
| 224 | + add_action( | |
| 225 | + 'admin_notices', | |
| 226 | + create_function( | |
| 227 | + '', | |
| 228 | + 'echo \'<div id="message" class="error"><p><strong>'. | |
| 229 | + TXT_UAM_FOPEN_WITHOUT_SAVEMODE_OFF. | |
| 230 | + '</strong></p></div>\';' | |
| 231 | + ) | |
| 232 | + ); | |
| 233 | + } | |
| 234 | + | |
| 235 | + $curUserdata = get_userdata($current_user->ID); | |
| 236 | + $uamAccessHandler = $userAccessManager->getAccessHandler(); | |
| 237 | + | |
| 238 | + if ($uamAccessHandler->checkUserAccess()) { | |
| 239 | + //TODO | |
| 240 | + /** | |
| 241 | + * --- BOF --- | |
| 242 | + * Not the best way to handle full user access capabilities seems | |
| 243 | + * to be the right way, but it is way difficult. | |
| 244 | + */ | |
| 245 | + | |
| 246 | + //Admin main menu | |
| 247 | + if (function_exists('add_menu_page')) { | |
| 248 | + add_menu_page('User Access Manager', 'UAM', 'read', 'uam_usergroup', array(&$userAccessManager, 'printAdminPage'), 'div'); | |
| 249 | + } | |
| 250 | + | |
| 251 | + //Admin sub menus | |
| 252 | + if (function_exists('add_submenu_page')) { | |
| 253 | + add_submenu_page('uam_usergroup', TXT_UAM_MANAGE_GROUP, TXT_UAM_MANAGE_GROUP, 'read', 'uam_usergroup', array(&$userAccessManager, 'printAdminPage')); | |
| 254 | + add_submenu_page('uam_usergroup', TXT_UAM_SETTINGS, TXT_UAM_SETTINGS, 'read', 'uam_settings', array(&$userAccessManager, 'printAdminPage')); | |
| 255 | + add_submenu_page('uam_usergroup', TXT_UAM_SETUP, TXT_UAM_SETUP, 'read', 'uam_setup', array(&$userAccessManager, 'printAdminPage')); | |
| 256 | + add_submenu_page('uam_usergroup', TXT_UAM_ABOUT, TXT_UAM_ABOUT, 'read', 'uam_about', array(&$userAccessManager, 'printAdminPage')); | |
| 257 | + | |
| 258 | + do_action('uam_add_submenu'); | |
| 259 | + } | |
| 260 | + /** | |
| 261 | + * --- EOF --- | |
| 262 | + */ | |
| 263 | + } | |
| 264 | + | |
| 265 | + if ($uamAccessHandler->checkUserAccess() | |
| 266 | + || $uamOptions['authors_can_add_posts_to_groups'] == 'true' | |
| 267 | + ) { | |
| 268 | + //Admin meta boxes | |
| 269 | + if (function_exists('add_meta_box')) { | |
| 270 | + $postableTypes = $uamAccessHandler->getPostableTypes(); | |
| 271 | + | |
| 272 | + foreach ($postableTypes as $postableType) { | |
| 273 | + add_meta_box('uma_post_access', 'Access', array(&$userAccessManager, 'editPostContent'), $postableType, 'side'); | |
| 274 | + } | |
| 275 | + | |
| 276 | + /*add_meta_box('uma_post_access', 'Access', array(&$userAccessManager, 'editPostContent'), 'post', 'side'); | |
| 277 | + add_meta_box('uma_post_access', 'Access', array(&$userAccessManager, 'editPostContent'), 'page', 'side');*/ | |
| 278 | + } | |
| 279 | + } | |
| 71 | 280 | } |
| 281 | +} | |
| 72 | 282 | |
| 73 | - //Defines | |
| 74 | - require_once $basePath . 'includes' . DIRECTORY_SEPARATOR . 'version.php'; | |
| 75 | - require_once $basePath.'vendor/autoload.php'; | |
| 76 | - require_once $basePath.'init.php'; | |
| 77 | - global $userAccessManager; | |
| 78 | - $userAccessManager = initUserAccessManger(); | |
| 283 | +if (!function_exists("userAccessManagerUninstall")) { | |
| 284 | + function userAccessManagerUninstall() { | |
| 285 | + $userAccessManager = new UserAccessManager(); | |
| 286 | + $userAccessManager->uninstall(); | |
| 287 | + } | |
| 79 | 288 | } |
| 80 | 289 | |
| 81 | -add_action('init', 'initUam', 0); | |
| 290 | +if (isset($userAccessManager)) { | |
| 291 | + //install | |
| 292 | + if (function_exists('register_activation_hook')) { | |
| 293 | + register_activation_hook(__FILE__, array(&$userAccessManager, 'install')); | |
| 294 | + } | |
| 295 | + | |
| 296 | + //uninstall | |
| 297 | + if (function_exists('register_uninstall_hook')) { | |
| 298 | + register_uninstall_hook(__FILE__, 'userAccessManagerUninstall'); | |
| 299 | + } elseif (function_exists('register_deactivation_hook')) { | |
| 300 | + //Fallback | |
| 301 | + register_deactivation_hook(__FILE__, array(&$userAccessManager, 'uninstall')); | |
| 302 | + } | |
| 303 | + | |
| 304 | + //deactivation | |
| 305 | + if (function_exists('register_deactivation_hook')) { | |
| 306 | + register_deactivation_hook(__FILE__, array(&$userAccessManager, 'deactivate')); | |
| 307 | + } | |
| 308 | + | |
| 309 | + //Redirect | |
| 310 | + $uamOptions = $userAccessManager->getAdminOptions(); | |
| 311 | + | |
| 312 | + if ($uamOptions['redirect'] != 'false' || isset($_GET['uamgetfile'])) { | |
| 313 | + add_filter('wp_headers', array(&$userAccessManager, 'redirect'), 10, 2); | |
| 314 | + } | |
| 315 | + | |
| 316 | + //Actions | |
| 317 | + if (function_exists('add_action')) { | |
| 318 | + add_action('wp_print_scripts', array(&$userAccessManager, 'addScripts')); | |
| 319 | + add_action('wp_print_styles', array(&$userAccessManager, 'addStyles')); | |
| 320 | + add_action('admin_init', 'userAccessManagerAP'); | |
| 321 | + add_action('admin_menu', 'userAccessManagerAPMenu'); | |
| 322 | + } | |
| 323 | + | |
| 324 | + //Filters | |
| 325 | + if (function_exists('add_filter')) { | |
| 326 | + add_filter('wp_get_attachment_thumb_url', array(&$userAccessManager, 'getFileUrl'), 10, 2); | |
| 327 | + add_filter('wp_get_attachment_url', array(&$userAccessManager, 'getFileUrl'), 10, 2); | |
| 328 | + add_filter('the_posts', array(&$userAccessManager, 'showPost')); | |
| 329 | + add_filter('posts_where_paged', array(&$userAccessManager, 'showPostSql')); | |
| 330 | + add_filter('wp_get_nav_menu_items', array(&$userAccessManager, 'showCustomMenu')); | |
| 331 | + add_filter('comments_array', array(&$userAccessManager, 'showComment')); | |
| 332 | + add_filter('get_pages', array(&$userAccessManager, 'showPage')); | |
| 333 | + add_filter('get_terms', array(&$userAccessManager, 'showTerms'), 10, 2); | |
| 334 | + add_filter('get_next_post_where', array(&$userAccessManager, 'showNextPreviousPost')); | |
| 335 | + add_filter('get_previous_post_where', array(&$userAccessManager, 'showNextPreviousPost')); | |
| 336 | + add_filter('post_link', array(&$userAccessManager, 'cachePostLinks'), 10, 2); | |
| 337 | + add_filter('edit_post_link', array(&$userAccessManager, 'showGroupMembership'), 10, 2); | |
| 338 | + add_filter('parse_query', array(&$userAccessManager, 'parseQuery')); | |
| 339 | + add_filter('getarchives_where', array(&$userAccessManager, 'showPostSql')); | |
| 340 | + } | |
| 341 | +} | |