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