PageRenderTime 45ms CodeModel.GetById 16ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/Web/wp-content/plugins/user-access-manager/user-access-manager.php

https://bitbucket.org/jimjenkins5/blog
PHP | 341 lines | 218 code | 56 blank | 67 comment | 39 complexity | 6478779aec2c0bab248f62143dab47ee MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1<?php
  2/**
  3 * Plugin Name: User Access Manager
  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
  7 * Author: Alexander Schneider
  8 * Description: Manage the access to your posts, pages, categories and files.
  9 * 
 10 * user-access-manager.php
 11 *
 12 * PHP versions 5
 13 * 
 14 * @category  UserAccessManager
 15 * @package   UserAccessManager
 16 * @author    Alexander Schneider <alexanderschneider85@gmail.com>
 17 * @copyright 2008-2010 Alexander Schneider
 18 * @license   http://www.gnu.org/licenses/gpl-2.0.html  GNU General Public License, version 2
 19 * @version   SVN: $Id$
 20 * @link      http://wordpress.org/extend/plugins/user-access-manager/
 21*/
 22
 23//Paths
 24load_plugin_textdomain(
 25	'user-access-manager', 
 26	false, 
 27	'user-access-manager/lang'
 28);
 29
 30define(
 31	'UAM_URLPATH', 
 32    WP_PLUGIN_URL.'/user-access-manager/'
 33);
 34
 35if (defined('UAM_LOCAL_DEBUG')) {
 36    //ONLY FOR MY LOCAL DEBUG
 37    define(
 38        'UAM_REALPATH',
 39        '/'.plugin_basename(dirname(__FILE__)).'/'
 40    );
 41} else {
 42    define(
 43        'UAM_REALPATH',
 44        WP_PLUGIN_DIR.'/'.plugin_basename(dirname(__FILE__)).'/'
 45    );
 46}
 47
 48
 49//Defines
 50require_once 'includes/database.define.php';
 51require_once 'includes/language.define.php';
 52
 53
 54//Check requirements
 55$stop = false;
 56
 57//Check php version
 58$phpVersion = phpversion();
 59
 60if (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
 75global $wp_version;
 76
 77if (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.
 92if ($stop) {
 93    return;
 94}
 95
 96
 97//Classes
 98require_once 'class/UserAccessManager.class.php';
 99require_once 'class/UamUserGroup.class.php';
100require_once 'class/UamAccessHandler.class.php';
101
102if (class_exists("UserAccessManager")) {
103    $userAccessManager = new UserAccessManager();
104}
105
106//Initialize the admin panel
107if (!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'));
167            }
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}
203
204if (!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        }
280    }
281}
282
283if (!function_exists("userAccessManagerUninstall")) {
284    function userAccessManagerUninstall() {
285        $userAccessManager = new UserAccessManager();
286        $userAccessManager->uninstall();
287    }
288}
289
290if (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}