PluginProbe
User Access Manager / 1.2.6.2
User Access Manager v1.2.6.2
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | user-access-manager.php +305 -3475 0.8.0.21.2.6.2 View file →
@@ -1,3522 +1,352 @@
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: 0.8.0.2
7 -Author: Alexander Schneider
8 -Description: Manage the access to your posts and pages. <strong>Note:</strong> <em>If you activate the plugin your upload dir will protect by a '.htaccess' with a random password and all old downloads insert in a previous post/page will not work anymore. You have to update your posts/pages. If you use already a '.htaccess' file to protect your files the plugin will <strong>overwrite</strong> the '.htaccess'. You can disabel the file locking and set up an other password for the '.htaccess' file at the UAM setting page.</em>
9 -
10 -Copyright 2008 Alexander Schneider (email : alexanderschneider85 [at] gmail DOT com)
11 -
12 - This program is free software; you can redistribute it and/or modify
13 - it under the terms of the GNU General Public License as published by
14 - the Free Software Foundation; either version 2 of the License, or
15 - (at your option) any later version.
16 -
17 - This program is distributed in the hope that it will be useful,
18 - but WITHOUT ANY WARRANTY; without even the implied warranty of
19 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 - GNU General Public License for more details.
21 -
22 - You should have received a copy of the GNU General Public License
23 - along with this program; if not, write to the Free Software
24 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 -
26 -Uses an Image by: Everaldo Coelho - http://www.everaldo.com/
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.6.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-2013 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/
27 21 */
28 22
29 -//DB
30 -global $wpdb;
31 -define('DB_ACCESSGROUP', $wpdb->prefix.'uam_accessgroups');
32 -define('DB_ACCESSGROUP_TO_POST', $wpdb->prefix.'uam_accessgroup_to_post');
33 -define('DB_ACCESSGROUP_TO_USER', $wpdb->prefix.'uam_accessgroup_to_user');
34 -define('DB_ACCESSGROUP_TO_CATEGORY', $wpdb->prefix.'uam_accessgroup_to_category');
35 -define('DB_ACCESSGROUP_TO_ROLE', $wpdb->prefix.'uam_accessgroup_to_role');
23 +//Paths
24 +load_plugin_textdomain('user-access-manager', false, 'user-access-manager/lang');
25 +define('UAM_URLPATH', plugins_url('', __FILE__).'/');
36 26
37 -//PATH
38 -define('UAM_URLPATH', WP_CONTENT_URL.'/plugins/'.plugin_basename( dirname(__FILE__)).'/' );
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 +}
39 32
40 -//###Lang###
41 33
42 -if (!class_exists("UserAccessManager"))
43 -{
44 - class UserAccessManager
45 - {
46 - var $adminOptionsName = "uamAdminOptions";
47 - var $atAdminPanel = false;
48 - var $restrictedPost = array();
49 - var $postAccess = array();
50 - var $uam_db_version = "1.1";
51 - var $adminOptions;
52 -
53 - function UserAccessManager()
54 - { //constructor
55 -
56 - }
57 -
58 - function init()
59 - {
60 - echo load_plugin_textdomain('user-access-manager', 'wp-content/plugins/user-access-manager');
61 -
62 - //---Lang Settings---
63 - define('TXT_SETTINGS', __('Settings', 'user-access-manager'));
64 -
65 - define('TXT_POST_SETTING', __('Post settings', 'user-access-manager'));
66 - define('TXT_POST_SETTING_DESC', __('Set up the behaviour of locked posts', 'user-access-manager'));
67 - define('TXT_POST_TITLE', __('Post title', 'user-access-manager'));
68 - define('TXT_POST_TITLE_DESC', __('Displayed text as post title if user has no access', 'user-access-manager'));
69 - define('TXT_DISPLAY_POST_TITLE', __('Hide post titel', 'user-access-manager'));
70 - define('TXT_DISPLAY_POST_TITLE_DESC', sprintf(__('Selecting "Yes" will show the text which is defined at "%s" if user has no access.', 'user-access-manager'), TXT_POST_TITLE));
71 - define('TXT_POST_CONTENT', __('Post content', 'user-access-manager'));
72 - define('TXT_POST_CONTENT_DESC', __('Content displayed if user has no access', 'user-access-manager'));
73 - define('TXT_HIDE_POST', __('Hide complete posts', 'user-access-manager'));
74 - define('TXT_HIDE_POST_DESC', __('Selecting "Yes" will hide posts if the user has no access.', 'user-access-manager'));
75 - define('TXT_POST_COMMENT_CONTENT', __('Post commtent text', 'user-access-manager'));
76 - define('TXT_POST_COMMENT_CONTENT_DESC', __('Displayed text as post comment text if user has no access', 'user-access-manager'));
77 - define('TXT_DISPLAY_POST_COMMENT', __('Hide post comments', 'user-access-manager'));
78 - define('TXT_DISPLAY_POST_COMMENT_DESC', sprintf(__('Selecting "Yes" will show the text which is defined at "%s" if user has no access.', 'user-access-manager'), TXT_POST_COMMENT_CONTENT) );
79 - define('TXT_ALLOW_COMMENTS_LOCKED', __('Allow comments', 'user-access-manager'));
80 - define('TXT_ALLOW_COMMENTS_LOCKED_DESC', __('Selecting "yes" allows users to comment on locked posts', 'user-access-manager'));
81 -
82 - define('TXT_PAGE_SETTING', __('Page settings', 'user-access-manager'));
83 - define('TXT_PAGE_SETTING_DESC', __('Set up the behaviour of locked pages', 'user-access-manager'));
84 - define('TXT_PAGE_TITLE', __('Page title', 'user-access-manager'));
85 - define('TXT_PAGE_TITLE_DESC', __('Displayed text as page title if user has no access', 'user-access-manager'));
86 - define('TXT_DISPLAY_PAGE_TITLE', __('Hide page titel', 'user-access-manager'));
87 - define('TXT_DISPLAY_PAGE_TITLE_DESC', sprintf(__('Selecting "Yes" will show the text which is defined at "%s" if user has no access.', 'user-access-manager'), TXT_POST_TITLE));
88 - define('TXT_PAGE_CONTENT', __('Page content', 'user-access-manager'));
89 - define('TXT_PAGE_CONTENT_DESC', __('Content displayed if user has no access', 'user-access-manager'));
90 - define('TXT_HIDE_PAGE', __('Hide complete pages', 'user-access-manager'));
91 - define('TXT_HIDE_PAGE_DESC', __('Selecting "Yes" will hide pages if the user has no access. Pages will also hide in the navigation.', 'user-access-manager'));
92 -
93 - define('TXT_FILE_SETTING', __('File settings', 'user-access-manager'));
94 - define('TXT_FILE_SETTING_DESC', __('Set up the behaviour of files', 'user-access-manager'));
95 - define('TXT_LOCK_FILE', __('Lock files', 'user-access-manager'));
96 - define('TXT_LOCK_FILE_DESC', __('If you select "Yes" all files will locked by a .htaccess file and only users with access can download files.', 'user-access-manager'));
97 - define('TXT_SELECTED_FILE_TYPES', __('Filetypes to lock: ', 'user-access-manager'));
98 - define('TXT_NOT_SELECTED_FILE_TYPES', __('Filetypes not to lock: ', 'user-access-manager'));
99 - define('TXT_DOWNLOAD_FILE_TYPE', __('Locked file types', 'user-access-manager'));
100 - define('TXT_DOWNLOAD_FILE_TYPE_DESC', __('Lock all files, type in file types which you will lock if the post/page is locked or define file types which will not be locked. <b>Note:</b> If you have no problems use all to get the maximum security.', 'user-access-manager'));
101 - define('TXT_FILE_PASS_TYPE', __('.htaccess password', 'user-access-manager'));
102 - define('TXT_FILE_PASS_TYPE_DESC', __('Set up the password for the .htaccess access. This password is only needed if you need a direct access to your files.', 'user-access-manager'));
103 - define('TXT_RANDOM_PASS', __('Use a random generated pass word.', 'user-access-manager'));
104 - define('TXT_CURRENT_LOGGEDIN_ADMIN_PASS', __('Use the password of the current logged in admin.', 'user-access-manager'));
105 - define('TXT_DOWNLOAD_TYPE', __('Download type', 'user-access-manager'));
106 - define('TXT_DOWNLOAD_TYPE_DESC', __('Selecting the type for downloading. <strong>Note:</strong> For using fopen you need "safe_mode = off".', 'user-access-manager'));
107 - define('TXT_NORMAL', __('Normal', 'user-access-manager'));
108 - define('TXT_FOPEN', __('fopen', 'user-access-manager'));
109 -
110 - define('TXT_OTHER_SETTING', __('Other settings', 'user-access-manager'));
111 - define('TXT_OTHER_SETTING_DESC', __('Here you will find all other settings', 'user-access-manager'));
112 - define('TXT_HIDE_EMPTY_CATEGORIES', __('Hide empty categories', 'user-access-manager'));
113 - define('TXT_HIDE_EMPTY_CATEGORIES_DESC', __('Selecting "Yes" will hide empty categories which are containing only empty childs or no childs.', 'user-access-manager'));
114 - define('TXT_REDIRECT', __('Redirect user', 'user-access-manager'));
115 - define('TXT_REDIRECT_DESC', __('Setup what happen if a user visit a post/page with no access.', 'user-access-manager'));
116 - define('TXT_REDIRECT_TO_BOLG', __('To blog startpage', 'user-access-manager'));
117 - define('TXT_REDIRECT_TO_PAGE', __('Custom page: ', 'user-access-manager'));
118 - define('TXT_REDIRECT_TO_URL', __('Custom URL: ', 'user-access-manager'));
119 - define('TXT_LOCK_RECURSIVE', __('Lock recursive', 'user-access-manager'));
120 - define('TXT_LOCK_RECURSIVE_DESC', __('Selecting "Yes" will lock all child posts/pages of a post/page if a user has no access to the parent page. Note: Setting this option to "No" could result in display errors relating to the hierarchy.', 'user-access-manager'));
121 - define('TXT_BLOG_ADMIN_HINT_TEXT', __('Admin hint text', 'user-access-manager'));
122 - define('TXT_BLOG_ADMIN_HINT_TEXT_DESC', __('The text which will shown behinde the post/page.', 'user-access-manager'));
123 - define('TXT_BLOG_ADMIN_HINT', __('Show admin hint at Posts', 'user-access-manager'));
124 - define('TXT_BLOG_ADMIN_HINT_DESC', sprintf(__('Selecting "Yes" will show the defined text at "%s" behinde the post/page to an logged in admin to show him which posts/pages are locked if he visits his blog.', 'user-access-manager'), TXT_BLOG_ADMIN_HINT_TEXT));
125 - define('TXT_CORE_MOD', __('Core modifications installed?', 'user-access-manager'));
126 - define('TXT_CORE_MOD_DESC', __('If you installed the core modifications activated this option.', 'user-access-manager'));
127 -
128 - define('TXT_YES', __('Yes', 'user-access-manager'));
129 - define('TXT_NO', __('No', 'user-access-manager'));
130 -
131 - define('TXT_UPDATE_SETTING', __('Update settings', 'user-access-manager'));
132 - define('TXT_UPDATE_SETTINGS', __('Settings updated.', 'user-access-manager'));
133 -
134 - //---Access groups---
135 -
136 - define('TXT_MANAGE_GROUP', __('Manage user access groups', 'user-access-manager'));
137 - define('TXT_GROUP_ROLE', __('Role affiliation', 'user-access-manager'));
138 - define('TXT_NAME', __('Name', 'user-access-manager'));
139 - define('TXT_DESCRIPTION', __('Description', 'user-access-manager'));
140 - define('TXT_READ_ACCESS', __('Read access', 'user-access-manager'));
141 - define('TXT_WRITE_ACCESS', __('Write access', 'user-access-manager'));
142 - define('TXT_POSTS', __('Posts', 'user-access-manager'));
143 - define('TXT_PAGES', __('Pages', 'user-access-manager'));
144 - define('TXT_FILES', __('Files', 'user-access-manager'));
145 - define('TXT_CATEGORY', __('Categories', 'user-access-manager'));
146 - define('TXT_USERS', __('Users', 'user-access-manager'));
147 - define('TXT_DELETE', __('Delete', 'user-access-manager'));
148 - define('TXT_UPDATE_GROUP', __('Update group', 'user-access-manager'));
149 - define('TXT_ADD', __('Add', 'user-access-manager'));
150 - define('TXT_ADD_GROUP', __('Add access group', 'user-access-manager'));
151 - define('TXT_GROUP_NAME', __('Access group name', 'user-access-manager'));
152 - define('TXT_GROUP_NAME_DESC', __('The name is used to identify the access user group.', 'user-access-manager'));
153 - define('TXT_GROUP_DESC', __('Access group description', 'user-access-manager'));
154 - define('TXT_GROUP_DESC_DESC', __('The description of the group.', 'user-access-manager'));
155 - define('TXT_GROUP_IP_RANGE', __('IP range', 'user-access-manager'));
156 - define('TXT_GROUP_IP_RANGE_DESC', __('Type in the IP ranges of users which are join these groups by there IP address without loggin. Set ranges like "BEGIN"-"END", seperate ranges by using ";", single IPs are also allowded. Example: 192.168.0.1-192.168.0.10;192.168.0.20-192.168.0.30', 'user-access-manager'));
157 - define('TXT_GROUP_READ_ACCESS', __('Read access', 'user-access-manager'));
158 - define('TXT_GROUP_READ_ACCESS_DESC', __('The read access.', 'user-access-manager'));
159 - define('TXT_GROUP_WRITE_ACCESS', __('Write access', 'user-access-manager'));
160 - define('TXT_GROUP_WRITE_ACCESS_DESC', __('The write access.', 'user-access-manager'));
161 - define('TXT_GROUP_ADDED', __('Group was added successfully.', 'user-access-manager'));
162 - define('TXT_DEL_GROUP', __('Group(s) was deleted successfully.', 'user-access-manager'));
163 - define('TXT_NONE', __('none', 'user-access-manager'));
164 - define('TXT_ACCESS_GROUP_EDIT_SUC', __('Access group edit successfully.', 'user-access-manager'));
165 - define('TXT_CONTAIN_POSTS', __('Contains %1$s of %2$s posts', 'user-access-manager'));
166 - define('TXT_CONTAIN_PAGES', __('Contains %1$s of %2$s pages', 'user-access-manager'));
167 - define('TXT_CONTAIN_FILES', __('Contains %1$s of %2$s files', 'user-access-manager'));
168 - define('TXT_CONTAIN_CATEGORIES', __('Contains %1$s of %2$s categories', 'user-access-manager'));
169 - define('TXT_CONTAIN_USERS', __('Contains %1$s of %2$s users', 'user-access-manager'));
170 - define('TXT_IP_RANGE', __('IP range', 'user-access-manager'));
171 -
172 - //---Misc---
173 - define('TXT_FULL_ACCESS', __('Full access', 'user-access-manager'));
174 - define('TXT_FULL_ACCESS_ADMIN', __('Full access (Administrator)', 'user-access-manager'));
175 - define('TXT_NO_GROUP', __('No group', 'user-access-manager'));
176 - define('TXT_SET_ACCESS', __('Set access', 'user-access-manager'));
177 -
178 - define('TXT_DATE', __('Date', 'user-access-manager'));
179 - define('TXT_TITLE', __('Title', 'user-access-manager'));
180 - define('TXT_GROUP_ACCESS', __('Group access', 'user-access-manager'));
181 - define('TXT_USERNAME', __('Username', 'user-access-manager'));
182 -
183 - define('TXT_MAIL', __('E-mail', 'user-access-manager'));
184 - define('TXT_ACCESS', __('Access', 'user-access-manager'));
185 - define('TXT_ADMIN_HINT', __('<strong>Note:</strong> An administrator has allways access to all posts/pages.', 'user-access-manager'));
186 -
187 - define('TXT_SET_POST_ACCESS', __('Set post access', 'user-access-manager'));
188 - define('TXT_SET_PAGE_ACCESS', __('Set page access', 'user-access-manager'));
189 - define('TXT_GROUPS', __('Access Groups', 'user-access-manager'));
190 - define('TXT_CREATE_GROUP_FIRST', __('Please create a access group first.', 'user-access-manager'));
191 - define('TXT_SET_USER_ACCESS', __('Set user access', 'user-access-manager'));
192 -
193 - define('TXT_SET_UP_USERGROUPS', __('Set up usergroups', 'user-access-manager'));
194 -
195 - define('TXT_ITSELF', __('itself', 'user-access-manager'));
196 - define('TXT_INFO', __('Info', 'user-access-manager'));
197 - define('TXT_GROUP_INFO', __('Group infos', 'user-access-manager'));
198 - define('TXT_GROUP_LOCK_INFO', __('Locked by', 'user-access-manager'));
199 - define('TXT_IS_ADMIN', __('User is Admin. Full access.', 'user-access-manager'));
200 - define('TXT_EXPAND', __('expand', 'user-access-manager'));
201 - define('TXT_EXPAND_ALL', __('expand all', 'user-access-manager'));
202 - define('TXT_COLLAPS', __('collaps', 'user-access-manager'));
203 - define('TXT_COLLAPS_ALL', __('collaps all', 'user-access-manager'));
204 - define('TXT_ALL', __('all', 'user-access-manager'));
205 - define('TXT_ONLY_GROUP_USERS', __('only group users', 'user-access-manager'));
206 - }
207 -
208 - function install()
209 - {
210 - $this->create_htaccess();
211 - $this->create_htpasswd();
212 -
213 - global $wpdb;
214 - $uam_db_version = $this->uam_db_version;
215 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
216 -
217 - $charset_collate = '';
34 +//Defines
35 +require_once 'includes/database.define.php';
36 +require_once 'includes/language.define.php';
218 37
219 - if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
220 - {
221 - if ( ! empty($wpdb->charset) )
222 - $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
223 - if ( ! empty($wpdb->collate) )
224 - $charset_collate .= " COLLATE $wpdb->collate";
225 - }
226 -
227 - if($wpdb->get_var("show tables like '".DB_ACCESSGROUP."'") != DB_ACCESSGROUP)
228 - {
229 - $sql = "CREATE TABLE " . DB_ACCESSGROUP . " (
230 - ID int(11) NOT NULL auto_increment,
231 - groupname tinytext NOT NULL,
232 - groupdesc text NOT NULL,
233 - read_access tinytext NOT NULL,
234 - write_access tinytext NOT NULL,
235 - ip_range mediumtext NULL,
236 - PRIMARY KEY (ID)
237 - ) $charset_collate;";
238 -
239 - dbDelta($sql);
240 - }
241 -
242 - if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_POST."'") != DB_ACCESSGROUP_TO_POST)
243 - {
244 - $sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_POST . " (
245 - post_id int(11) NOT NULL,
246 - group_id int(11) NOT NULL,
247 - PRIMARY KEY (post_id,group_id)
248 - ) $charset_collate;";
249 -
250 - dbDelta($sql);
251 - }
252 -
253 - if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_USER."'") != DB_ACCESSGROUP_TO_USER)
254 - {
255 - $sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_USER . " (
256 - user_id int(11) NOT NULL,
257 - group_id int(11) NOT NULL,
258 - PRIMARY KEY (user_id,group_id)
259 - ) $charset_collate;";
260 -
261 - dbDelta($sql);
262 - }
263 -
264 - if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_CATEGORY."'") != DB_ACCESSGROUP_TO_CATEGORY)
265 - {
266 - $sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_CATEGORY . " (
267 - category_id int(11) NOT NULL,
268 - group_id int(11) NOT NULL,
269 - PRIMARY KEY (category_id,group_id)
270 - ) $charset_collate;";
271 -
272 - dbDelta($sql);
273 - }
274 -
275 - if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_ROLE."'") != DB_ACCESSGROUP_TO_ROLE)
276 - {
277 - $sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_ROLE . " (
278 - role_name varchar(255) NOT NULL,
279 - group_id int(11) NOT NULL,
280 - PRIMARY KEY (role_name,group_id)
281 - ) $charset_collate;";
282 -
283 - dbDelta($sql);
284 - }
285 -
286 - add_option("uam_db_version", $uam_db_version);
287 - }
288 -
289 - function update()
290 - {
291 - global $wpdb;
292 - $uam_db_version = $this->uam_db_version;
293 - $installed_ver = get_option( "uam_db_version" );
294 -
295 - if($installed_ver != $uam_db_version)
296 - {
297 - if($installed_ver == '1.0')
298 - {
299 - if($wpdb->get_var("show tables like '".DB_ACCESSGROUP."'") == DB_ACCESSGROUP)
300 - {
301 - $wpdb->query("ALTER TABLE ".DB_ACCESSGROUP." ADD read_access TINYTEXT NOT NULL DEFAULT '', ADD write_access TINYTEXT NOT NULL DEFAULT '', ADD ip_range MEDIUMTEXT NULL DEFAULT ''");
302 - $wpdb->query("UPDATE ".DB_ACCESSGROUP." SET read_access = 'group', write_access = 'group'");
303 - update_option("uam_db_version", $uam_db_version);
304 - }
305 - }
306 - }
307 - if($wpdb->get_var("show columns from ".DB_ACCESSGROUP." like 'ip_range'") != 'ip_range')
308 - {
309 - $wpdb->query("ALTER TABLE ".DB_ACCESSGROUP." ADD ip_range MEDIUMTEXT NULL DEFAULT ''");
310 - }
311 - }
312 -
313 - function uninstall()
314 - {
315 - global $wpdb;
316 - $wpdb->query("DROP TABLE ".DB_ACCESSGROUP.", ".DB_ACCESSGROUP_TO_POST.", ".DB_ACCESSGROUP_TO_USER.", ".DB_ACCESSGROUP_TO_CATEGORY.", ".DB_ACCESSGROUP_TO_ROLE);
317 - $this->delete_htaccess_files();
318 - }
319 -
320 - function deactivate()
321 - {
322 - $this->delete_htaccess_files();
323 - }
324 -
325 - function create_htaccess()
326 - {
327 - // Make .htaccess file to protect data
328 -
329 - // get url
330 - $wud = wp_upload_dir();
331 - if(empty($wud['error']))
332 - {
333 - $url = $wud['basedir']."/";
334 -
335 - $areaname = "WP-Files";
336 -
337 - $uamOptions = $this->getAdminOptions();
338 38
339 - if($uamOptions['lock_file_types'] == 'selected')
340 - $file_types = $uamOptions['locked_file_types'];
341 - elseif($uamOptions['lock_file_types'] == 'not_selected')
342 - $file_types = $uamOptions['not_locked_file_types'];
39 +//Check requirements
40 +$blStop = false;
343 41
344 - if(isset($file_types))
345 - $file_types = str_replace(",", "|", $file_types);
346 -
347 - // make .htaccess and .htpasswd
348 -
349 - $htaccess_txt = "";
350 -
351 - if($uamOptions['lock_file_types'] == 'selected')
352 - $htaccess_txt .= "<FilesMatch '\.(".$file_types.")'>\n";
353 -
354 - if($uamOptions['lock_file_types'] == 'not_selected')
355 - $htaccess_txt .= "<FilesMatch '^\.(".$file_types.")'>\n";
42 +//Check php version
43 +$sPhpVersion = phpversion();
356 44
357 - $htaccess_txt .= "AuthType Basic"."\n";
358 - $htaccess_txt .= "AuthName \"".$areaname."\""."\n";
359 - $htaccess_txt .= "AuthUserFile ".$url.".htpasswd"."\n";
360 - $htaccess_txt .= "require valid-user"."\n";
361 -
362 - if($uamOptions['lock_file_types'] == 'selected' || $uamOptions['lock_file_types'] == 'not_selected')
363 - $htaccess_txt .= "</FilesMatch>\n";
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 + )
54 + );
55 +
56 + $blStop = true;
57 +}
364 58
365 - // save files
366 - $htaccess = fopen($url.".htaccess", "w");
367 - fwrite($htaccess, $htaccess_txt);
368 - fclose($htaccess);
369 - }
370 - }
371 -
372 - function create_htpasswd($create_new = false)
373 - {
374 - global $current_user;
375 -
376 - $uamOptions = $this->getAdminOptions();
377 -
378 - // get url
379 - $wud = wp_upload_dir();
380 -
381 - if(empty($wud['error']))
382 - {
383 - $url = $wud['basedir']."/";
384 - $cur_userdata = get_userdata($current_user->ID);
385 -
386 - $user = $cur_userdata->user_login;
387 -
388 - if(!file_exists($url.".htpasswd") || $create_new)
389 - {
390 - if($uamOptions['file_pass_type'] == 'random')
391 - {
392 - # create password
393 - $array = array();
394 -
395 - $length = 10;
396 - $capitals = true;
397 - $specialSigns = false;
398 -
399 - if($length < 8)
400 - $length = mt_rand(8,20);
401 -
402 - # numbers
403 - for($i=48;$i<58;$i++)
404 - $array[] = chr($i);
405 -
406 - # small
407 - for($i=97;$i<122;$i++)
408 - $array[] = chr($i);
409 -
410 - # capitals
411 - if($capitals)
412 - for($i=65;$i<90;$i++)
413 - $array[] = chr($i);
414 -
415 - # specialchar:
416 - if($specialSigns)
417 - {
418 - for($i=33;$i<47;$i++)
419 - $array[] = chr($i);
420 - for($i=59;$i<64;$i++)
421 - $array[] = chr($i);
422 - for($i=91;$i<96;$i++)
423 - $array[] = chr($i);
424 - for($i=123;$i<126;$i++)
425 - $array[] = chr($i);
426 - }
427 -
428 - mt_srand((double)microtime()*1000000);
429 - $password = '';
430 -
431 - for ($i=1; $i<=$length; $i++)
432 - {
433 - $rnd = mt_rand( 0, count($array)-1 );
434 - $password .= $array[$rnd];
435 - $password = md5($password);
436 - }
437 - }
438 - elseif($uamOptions['file_pass_type'] == 'admin')
439 - {
440 - $password = $cur_userdata->user_pass;
441 - }
442 -
443 - // make .htpasswd
444 - $htpasswd_txt = "$user:".$password."\n";
445 -
446 - // save file
447 - $htpasswd = fopen($url.".htpasswd", "w");
448 - fwrite($htpasswd, $htpasswd_txt);
449 - fclose($htpasswd);
450 - }
451 - }
452 - }
453 -
454 - function delete_htaccess_files()
455 - {
456 - $wud = wp_upload_dir();
457 - if(empty($wud['error']))
458 - {
459 - $url = $wud['basedir']."/";
460 - unlink($url.".htaccess");
461 - unlink($url.".htpasswd");
462 - }
463 - }
464 -
465 - //Returns an array of admin options
466 - function getAdminOptions()
467 - {
468 - if($this->atAdminPanel || empty($this->adminOptions))
469 - {
470 - $uamAdminOptions = array( 'hide_post_title' => 'false',
471 - 'post_title' => __('No rights!', 'user-access-manager'),
472 - 'hide_post_comment' => 'false',
473 - 'post_comment_content' => __('Sorry no rights to view comments!', 'user-access-manager'),
474 - 'allow_comments_locked' => 'false',
475 - 'post_content' => 'Sorry no rights!',
476 - 'hide_post' => 'false',
477 - 'hide_page_title' => 'false',
478 - 'page_title' => 'No rights!',
479 - 'page_content' => __('Sorry you have no rights to view this page!', 'user-access-manager'),
480 - 'hide_page' => 'false',
481 - 'redirect' => 'false',
482 - 'redirect_custom_page' => '',
483 - 'redirect_custom_url' => '',
484 - 'lock_recursive' => 'true',
485 - 'lock_file' => 'true',
486 - 'file_pass_type' => 'random',
487 - 'lock_file_types' => 'all',
488 - 'download_type' => 'fopen',
489 - 'locked_file_types' => 'zip,rar,tar,gz,bz2',
490 - 'not_locked_file_types' => 'gif,jpg,jpeg,png',
491 - 'blog_admin_hint' => 'true',
492 - 'blog_admin_hint_text' => '[L]',
493 - 'core_mod' => 'false',
494 - 'hide_empty_categories' => 'true');
495 -
496 - $uamOptions = get_option($this->adminOptionsName);
497 - if (!empty($uamOptions)) {
498 - foreach ($uamOptions as $key => $option)
499 - $uamAdminOptions[$key] = $option;
500 - }
501 - update_option($this->adminOptionsName, $uamAdminOptions);
502 - $this->adminOptions = $uamAdminOptions;
503 - }
504 - return $this->adminOptions;
505 - }
506 -
507 - //Prints out the admin page
508 - function printAdminPage()
509 - {
510 - global $wpdb;
511 -
512 - $uamOptions = $this->getAdminOptions();
513 -
514 - if (isset($_POST['update_uam_settings']))
515 - {
516 - if (isset($_POST['uam_hide_post_title']))
517 - {
518 - $uamOptions['hide_post_title'] = $_POST['uam_hide_post_title'];
519 - }
520 - if (isset($_POST['uam_post_title']))
521 - {
522 - $uamOptions['post_title'] = $_POST['uam_post_title'];
523 - }
524 - if (isset($_POST['uam_post_content']))
525 - {
526 - $uamOptions['post_content'] = $_POST['uam_post_content'];
527 - }
528 - if (isset($_POST['uam_hide_post']))
529 - {
530 - $uamOptions['hide_post'] = $_POST['uam_hide_post'];
531 - }
532 - if (isset($_POST['uam_hide_post_comment']))
533 - {
534 - $uamOptions['hide_post_comment'] = $_POST['uam_hide_post_comment'];
535 - }
536 - if (isset($_POST['uam_post_comment_content']))
537 - {
538 - $uamOptions['post_comment_content'] = $_POST['uam_post_comment_content'];
539 - }
540 - if (isset($_POST['uam_allow_comments_locked']))
541 - {
542 - $uamOptions['allow_comments_locked'] = $_POST['uam_allow_comments_locked'];
543 - }
544 - if (isset($_POST['uam_hide_page_title']))
545 - {
546 - $uamOptions['hide_page_title'] = $_POST['uam_hide_page_title'];
547 - }
548 - if (isset($_POST['uam_page_title']))
549 - {
550 - $uamOptions['page_title'] = $_POST['uam_page_title'];
551 - }
552 - if (isset($_POST['uam_page_content']))
553 - {
554 - $uamOptions['page_content'] = $_POST['uam_page_content'];
555 - }
556 - if (isset($_POST['uam_hide_page']))
557 - {
558 - $uamOptions['hide_page'] = $_POST['uam_hide_page'];
559 - }
560 - if (isset($_POST['uam_hide_empty_categories']))
561 - {
562 - $uamOptions['hide_empty_categories'] = $_POST['uam_hide_empty_categories'];
563 - }
564 - if (isset($_POST['uam_redirect']))
565 - {
566 - $uamOptions['redirect'] = $_POST['uam_redirect'];
567 - }
568 - if (isset($_POST['uam_redirect_custom_page']))
569 - {
570 - $uamOptions['redirect_custom_page'] = $_POST['uam_redirect_custom_page'];
571 - }
572 - if (isset($_POST['uam_redirect_custom_url']))
573 - {
574 - $uamOptions['redirect_custom_url'] = $_POST['uam_redirect_custom_url'];
575 - }
576 - if (isset($_POST['uam_lock_recursive']))
577 - {
578 - $uamOptions['lock_recursive'] = $_POST['uam_lock_recursive'];
579 - }
580 - if (isset($_POST['uam_blog_admin_hint']))
581 - {
582 - $uamOptions['blog_admin_hint'] = $_POST['uam_blog_admin_hint'];
583 - }
584 - if (isset($_POST['uam_blog_admin_hint_text']))
585 - {
586 - $uamOptions['blog_admin_hint_text'] = $_POST['uam_blog_admin_hint_text'];
587 - }
588 - if (isset($_POST['uam_core_mod']))
589 - {
590 - $uamOptions['core_mod'] = $_POST['uam_core_mod'];
591 - }
592 - if (isset($_POST['uam_lock_file']))
593 - {
594 - if($_POST['uam_lock_file'] == 'false')
595 - {
596 - if($uamOptions['lock_file'] != $_POST['uam_lock_file'])
597 - $this->delete_htaccess_files();
598 - }
599 - else
600 - {
601 - if($uamOptions['lock_file'] != $_POST['uam_lock_file'])
602 - $lock_file_changed = true;
603 - }
604 - $uamOptions['lock_file'] = $_POST['uam_lock_file'];
605 - }
606 -
607 - if (isset($_POST['uam_file_pass_type']))
608 - {
609 - if($uamOptions['file_pass_type'] != $_POST['uam_file_pass_type'])
610 - $file_pass_changed = true;
611 - else
612 - $file_pass_changed = false;
613 -
614 - $uamOptions['file_pass_type'] = $_POST['uam_file_pass_type'];
615 - }
616 - if (isset($_POST['uam_download_type']))
617 - {
618 - $uamOptions['download_type'] = $_POST['uam_download_type'];
619 - }
620 - if (isset($_POST['uam_locked_file_types']))
621 - {
622 - if($uamOptions['locked_file_types'] != $_POST['uam_locked_file_types'])
623 - $locked_file_types_changed = true;
624 - else
625 - $locked_file_types_changed = false;
626 -
627 - $uamOptions['locked_file_types'] = $_POST['uam_locked_file_types'];
628 - }
629 - if (isset($_POST['uam_not_locked_file_types']))
630 - {
631 - if($uamOptions['not_locked_file_types'] != $_POST['uam_not_locked_file_types'])
632 - $not_locked_file_types_changed = true;
633 - else
634 - $not_locked_file_types_changed = false;
635 -
636 - $uamOptions['not_locked_file_types'] = $_POST['uam_not_locked_file_types'];
637 - }
638 - if (isset($_POST['uam_lock_file_types']))
639 - {
640 - if($uamOptions['lock_file_types'] != $_POST['uam_lock_file_types'])
641 - $locked_file_types_changed = true;
642 -
643 - $uamOptions['lock_file_types'] = $_POST['uam_lock_file_types'];
644 - }
645 -
646 - update_option($this->adminOptionsName, $uamOptions);
647 -
648 - if(($locked_file_types_changed || $not_locked_file_types_changed || isset($lock_file_changed) || $file_pass_changed) && $uamOptions['lock_file'] != 'false')
649 - {
650 - $this->create_htaccess();
651 - $this->create_htpasswd(true);
652 - }
653 - ?>
654 - <div class="updated"><p><strong><?php echo TXT_UPDATE_SETTINGS; ?></strong></p></div>
655 - <?php
656 - }
657 -
658 - if(isset($_GET['page']))
659 - $cur_admin_page = $_GET['page'];
660 -
661 - if(isset($_GET['action']))
662 - $action = $_GET['action'];
663 - else
664 - $action = null;
665 -
666 - if(isset($_POST['action']))
667 - $post_action = $_POST['action'];
668 - else
669 - $post_action = null;
670 -
671 - if($post_action == 'delgroup')
672 - {
673 - if(isset($_POST['delete']))
674 - $del_ids = $_POST['delete'];
675 -
676 - if(isset($del_ids))
677 - {
678 - foreach($del_ids as $del_id)
679 - {
680 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP." WHERE ID = $del_id LIMIT 1");
681 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE group_id = $del_id");
682 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE group_id = $del_id");
683 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_CATEGORY." WHERE group_id = $del_id");
684 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_ROLE." WHERE group_id = $del_id");
685 - }
686 - ?>
687 - <div class="updated"><p><strong><?php echo TXT_DEL_GROUP; ?></strong></p></div>
688 - <?php
689 - }
690 - }
691 -
692 - if($post_action == 'update_group' || $post_action == 'addgroup')
693 - {
694 - if($post_action == 'addgroup')
695 - {
696 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP." (ID, groupname, groupdesc, read_access, write_access, ip_range) VALUES(NULL, '".$_POST['access_group_name']."', '".$_POST['access_group_description']."', '".$_POST['read_access']."', '".$_POST['write_access']."', '".$_POST['ip_range']."')");
697 -
698 - $group_id = $wpdb->insert_id;
699 - }
700 - elseif($post_action == 'update_group')
701 - {
702 - $wpdb->query(" UPDATE ".DB_ACCESSGROUP."
703 - SET groupname = '".$_POST['access_group_name']."', groupdesc = '".$_POST['access_group_description']."', read_access = '".$_POST['read_access']."', write_access = '".$_POST['write_access']."', ip_range = '".$_POST['ip_range']."'
704 - WHERE ID = ".$_POST['access_group_id']);
705 -
706 - $group_id = $_POST['access_group_id'];
707 -
708 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_ROLE." WHERE group_id = ".$group_id);
709 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE group_id = ".$group_id);
710 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_CATEGORY." WHERE group_id = ".$group_id);
711 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE group_id = ".$group_id);
712 - }
713 -
714 - if(isset($_POST['roles']))
715 - $roles = $_POST['roles'];
716 - else
717 - $roles = null;
718 -
719 - if($roles)
720 - {
721 - foreach($roles as $role)
722 - {
723 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_ROLE." (group_id, role_name) VALUES('".$group_id."', '".$role."')");
724 - }
725 - }
726 -
727 - if(isset($_POST['post']))
728 - $posts = $_POST['post'];
729 - else
730 - $posts = null;
731 -
732 - if($posts)
733 - {
734 - foreach($posts as $post)
735 - {
736 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_POST." (group_id, post_id) VALUES('".$group_id."', '".$post."')");
737 - }
738 - }
739 -
740 - if(isset($_POST['page']))
741 - $pages = $_POST['page'];
742 - else
743 - $pages = null;
744 -
745 - if($pages)
746 - {
747 - foreach($pages as $page)
748 - {
749 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_POST." (group_id, post_id) VALUES('".$group_id."', '".$page."')");
750 - }
751 - }
752 -
753 - if(isset($_POST['file']))
754 - $files = $_POST['file'];
755 - else
756 - $files = null;
757 -
758 - if($files)
759 - {
760 - foreach($files as $file)
761 - {
762 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_POST." (group_id, post_id) VALUES('".$group_id."', '".$file."')");
763 - }
764 - }
765 -
766 - if(isset($_POST['category']))
767 - $categories = $_POST['category'];
768 - else
769 - $categories = null;
770 -
771 - if($categories)
772 - {
773 - foreach($categories as $category)
774 - {
775 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_CATEGORY." (group_id, category_id) VALUES('".$group_id."', '".$category."')");
776 - }
777 - }
778 -
779 - if(isset($_POST['user']))
780 - $users = $_POST['user'];
781 - else
782 - $users = null;
783 -
784 - if($users)
785 - {
786 - foreach($users as $user)
787 - {
788 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_USER." (group_id, user_id) VALUES('".$group_id."', '".$user."')");
789 - }
790 - }
791 -
792 - if($post_action == 'addgroup')
793 - {
794 - ?>
795 - <div class="updated"><p><strong><?php echo TXT_GROUP_ADDED; ?></strong></p></div>
796 - <?php
797 - }
798 - elseif($post_action == 'update_group')
799 - {
800 - ?>
801 - <div class="updated"><p><strong><?php echo TXT_ACCESS_GROUP_EDIT_SUC; ?></strong></p></div>
802 - <?php
803 - }
804 - }
805 -
806 - if($cur_admin_page == 'uam_settings')
807 - {
808 - ?>
809 - <div class=wrap>
810 - <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
811 - <h2><?php echo TXT_SETTINGS; ?></h2>
812 - <h3><?php echo TXT_POST_SETTING; ?></h3>
813 - <p><?php echo TXT_POST_SETTING_DESC; ?></p>
814 - <table class="form-table">
815 - <tbody>
816 - <tr valign="top">
817 - <th scope="row">
818 - <?php echo TXT_HIDE_POST; ?>
819 - </th>
820 - <td>
821 - <label for="uam_hide_post_yes">
822 - <input type="radio" id="uam_hide_post_yes" class="uam_hide_post" name="uam_hide_post" value="true" <?php if ($uamOptions['hide_post'] == "true") { echo 'checked="checked"'; }?> />
823 - <?php echo TXT_YES; ?>
824 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
825 - <label for="uam_hide_post_no">
826 - <input type="radio" id="uam_hide_post_no" class="uam_hide_post" name="uam_hide_post" value="false" <?php if ($uamOptions['hide_post'] == "false") { echo 'checked="checked"'; }?>/>
827 - <?php echo TXT_NO; ?>
828 - </label>
829 - <br />
830 - <?php echo TXT_HIDE_POST_DESC; ?>
831 - </td>
832 - </tr>
833 - </tbody>
834 - </table>
835 - <table class="form-table" id="uam_post_settings">
836 - <tbody>
837 - <tr valign="top">
838 - <th scope="row">
839 - <?php echo TXT_DISPLAY_POST_TITLE; ?>
840 - </th>
841 - <td>
842 - <label for="uam_hide_post_title_yes">
843 - <input type="radio" id="uam_hide_post_title_yes" name="uam_hide_post_title" value="true" <?php if ($uamOptions['hide_post_title'] == "true") { echo 'checked="checked"'; }?> />
844 - <?php echo TXT_YES; ?>
845 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
846 - <label for="uam_hide_post_title_no">
847 - <input type="radio" id="uam_hide_post_title_no" name="uam_hide_post_title" value="false" <?php if ($uamOptions['hide_post_title'] == "false") { echo 'checked="checked"'; }?>/>
848 - <?php echo TXT_NO; ?>
849 - </label>
850 - <br />
851 - <?php echo TXT_DISPLAY_POST_TITLE_DESC; ?>
852 - </td>
853 - </tr>
854 - <tr valign="top">
855 - <th scope="row">
856 - <?php echo TXT_POST_TITLE; ?>
857 - </th>
858 - <td>
859 - <input name="uam_post_title" value="<?php echo $uamOptions['post_title']; ?>" />
860 - <br />
861 - <?php echo TXT_POST_TITLE_DESC; ?>
862 - </td>
863 - </tr>
864 - <tr valign="top">
865 - <th scope="row">
866 - <?php echo TXT_POST_CONTENT; ?>
867 - </th>
868 - <td>
869 - <textarea name="uam_post_content" style="width: 80%; height: 100px;"><?php echo apply_filters('format_to_edit',$uamOptions['post_content']); ?></textarea>
870 - <br />
871 - <?php echo TXT_POST_CONTENT_DESC; ?>
872 - </td>
873 - </tr>
874 - <tr valign="top">
875 - <th scope="row">
876 - <?php echo TXT_DISPLAY_POST_COMMENT; ?>
877 - </th>
878 - <td>
879 - <label for="uam_hide_post_comment_yes">
880 - <input type="radio" name="uam_hide_post_comment" value="true" <?php if ($uamOptions['hide_post_comment'] == "true") { echo 'checked="checked"'; }?> />
881 - <?php echo TXT_YES; ?>
882 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
883 - <label for="uam_hide_post_comment_no">
884 - <input type="radio"name="uam_hide_post_comment" value="false" <?php if ($uamOptions['hide_post_comment'] == "false") { echo 'checked="checked"'; }?>/>
885 - <?php echo TXT_NO; ?>
886 - </label>
887 - <br />
888 - <?php echo TXT_DISPLAY_POST_COMMENT_DESC; ?>
889 - </td>
890 - </tr>
891 - <tr valign="top">
892 - <th scope="row">
893 - <?php echo TXT_POST_COMMENT_CONTENT; ?>
894 - </th>
895 - <td>
896 - <input name="uam_post_comment_content" value="<?php echo $uamOptions['post_comment_content']; ?>" />
897 - <br />
898 - <?php echo TXT_POST_COMMENT_CONTENT_DESC; ?>
899 - </td>
900 - </tr>
901 - <tr valign="top">
902 - <th scope="row">
903 - <?php echo TXT_ALLOW_COMMENTS_LOCKED; ?>
904 - </th>
905 - <td>
906 - <label for="uam_allow_comments_locked_yes">
907 - <input type="radio" name="uam_allow_comments_locked" value="true" <?php if ($uamOptions['allow_comments_locked'] == "true") { echo 'checked="checked"'; }?> />
908 - <?php echo TXT_YES; ?>
909 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
910 - <label for="uam_allow_comments_locked_no">
911 - <input type="radio"name="uam_allow_comments_locked" value="false" <?php if ($uamOptions['allow_comments_locked'] == "false") { echo 'checked="checked"'; }?>/>
912 - <?php echo TXT_NO; ?>
913 - </label>
914 - <br />
915 - <?php echo TXT_ALLOW_COMMENTS_LOCKED_DESC; ?>
916 - </td>
917 - </tr>
918 - </tbody>
919 - </table>
920 - <h3><?php echo TXT_PAGE_SETTING; ?></h3>
921 - <p><?php echo TXT_PAGE_SETTING_DESC; ?></p>
922 - <table class="form-table">
923 - <tbody>
924 - <tr>
925 - <th>
926 - <?php echo TXT_HIDE_PAGE; ?>
927 - </th>
928 - <td>
929 - <label for="uam_hide_page_yes">
930 - <input type="radio" id="uam_hide_page_yes" class="uam_hide_page" name="uam_hide_page" value="true" <?php if ($uamOptions['hide_page'] == "true") { echo 'checked="checked"'; }?> />
931 - <?php echo TXT_YES; ?>
932 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
933 - <label for="uam_hide_page_no">
934 - <input type="radio" id="uam_hide_page_no" class="uam_hide_page" name="uam_hide_page" value="false" <?php if ($uamOptions['hide_page'] == "false") { echo 'checked="checked"'; }?>/>
935 - <?php echo TXT_NO; ?>
936 - </label>
937 - <br />
938 - <?php echo TXT_HIDE_PAGE_DESC; ?>
939 - </td>
940 - </tr>
941 - </tbody>
942 - </table>
943 - <table class="form-table" id="uam_page_settings">
944 - <tbody>
945 - <tr valign="top">
946 - <th scope="row">
947 - <?php echo TXT_DISPLAY_PAGE_TITLE; ?>
948 - </th>
949 - <td>
950 - <label for="uam_hide_page_title_yes">
951 - <input type="radio" id="uam_hide_page_title_yes" name="uam_hide_page_title" value="true" <?php if ($uamOptions['hide_page_title'] == "true") { echo 'checked="checked"'; }?> />
952 - <?php echo TXT_YES; ?>
953 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
954 - <label for="uam_hide_page_title_no">
955 - <input type="radio" id="uam_hide_page_title_no" name="uam_hide_page_title" value="false" <?php if ($uamOptions['hide_page_title'] == "false") { echo 'checked="checked"'; }?>/>
956 - <?php echo TXT_NO; ?>
957 - </label>
958 - <br />
959 - <?php echo TXT_DISPLAY_PAGE_TITLE_DESC; ?>
960 - </td>
961 - </tr>
962 - <tr>
963 - <th>
964 - <?php echo TXT_PAGE_TITLE; ?>
965 - </th>
966 - <td>
967 - <input name="uam_page_title" value="<?php echo $uamOptions['page_title']; ?>" />
968 - <br />
969 - <?php echo TXT_PAGE_TITLE_DESC; ?>
970 - </td>
971 - </tr>
972 - <tr>
973 - <th>
974 - <?php echo TXT_PAGE_CONTENT; ?>
975 - </th>
976 - <td>
977 - <textarea name="uam_page_content" style="width: 80%; height: 100px;"><?php echo apply_filters('format_to_edit',$uamOptions['page_content']); ?></textarea>
978 - <br />
979 - <?php echo TXT_PAGE_CONTENT_DESC; ?>
980 - </td>
981 - </tr>
982 - </tbody>
983 - </table>
984 - <h3><?php echo TXT_FILE_SETTING; ?></h3>
985 - <p><?php echo TXT_FILE_SETTING_DESC; ?></p>
986 - <table class="form-table">
987 - <tbody>
988 - <tr>
989 - <th>
990 - <?php echo TXT_LOCK_FILE; ?>
991 - </th>
992 - <td>
993 - <label for="uam_lock_file_yes">
994 - <input type="radio" id="uam_lock_file_yes" class="uam_lock_file" name="uam_lock_file" value="true" <?php if ($uamOptions['lock_file'] == "true") { echo 'checked="checked"'; }?> />
995 - <?php echo TXT_YES; ?>
996 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
997 - <label for="uam_lock_file_no">
998 - <input type="radio" id="uam_lock_file_no" class="uam_lock_file" name="uam_lock_file" value="false" <?php if ($uamOptions['lock_file'] == "false") { echo 'checked="checked"'; }?>/>
999 - <?php echo TXT_NO; ?>
1000 - </label>
1001 - <br />
1002 - <?php echo TXT_LOCK_FILE_DESC; ?>
1003 - </td>
1004 - </tr>
1005 - </tbody>
1006 - </table>
1007 - <table class="form-table" id="uam_file_settings">
1008 - <tbody>
1009 - <tr>
1010 - <th>
1011 - <?php echo TXT_DOWNLOAD_FILE_TYPE; ?>
1012 - </th>
1013 - <td>
1014 - <label for="uam_lock_file_types_all">
1015 - <input type="radio" id="uam_lock_file_types_all" name="uam_lock_file_types" value="all" <?php if ($uamOptions['lock_file_types'] == "all") { echo 'checked="checked"'; }?> />
1016 - <?php echo TXT_ALL; ?>
1017 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1018 - <label for="uam_lock_file_types_selected">
1019 - <input type="radio" id="uam_lock_file_types_selected" name="uam_lock_file_types" value="selected" <?php if ($uamOptions['lock_file_types'] == "selected") { echo 'checked="checked"'; }?> />
1020 - <?php echo TXT_SELECTED_FILE_TYPES; ?>
1021 - </label><input name="uam_locked_file_types" value="<?php echo $uamOptions['locked_file_types']; ?>" />
1022 - <label for="uam_lock_file_types_not_selected">
1023 - <input type="radio" id="uam_lock_file_types_not_selected" name="uam_lock_file_types" value="not_selected" <?php if ($uamOptions['lock_file_types'] == "not_selected") { echo 'checked="checked"'; }?> />
1024 - <?php echo TXT_NOT_SELECTED_FILE_TYPES; ?>
1025 - </label><input name="uam_not_locked_file_types" value="<?php echo $uamOptions['not_locked_file_types']; ?>" />
1026 - <br />
1027 - <?php echo TXT_DOWNLOAD_FILE_TYPE_DESC; ?>
1028 - </td>
1029 - </tr>
1030 - <tr>
1031 - <th>
1032 - <?php echo TXT_FILE_PASS_TYPE; ?>
1033 - </th>
1034 - <td>
1035 - <label for="uam_file_pass_type_admin">
1036 - <input type="radio" id="uam_file_pass_type_admin" name="uam_file_pass_type" value="admin" <?php if ($uamOptions['file_pass_type'] == "admin") { echo 'checked="checked"'; }?> />
1037 - <?php echo TXT_CURRENT_LOGGEDIN_ADMIN_PASS; ?>
1038 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1039 - <label for="uam_file_pass_type_random">
1040 - <input type="radio" id="uam_file_pass_type_random" name="uam_file_pass_type" value="random" <?php if ($uamOptions['file_pass_type'] == "random") { echo 'checked="checked"'; }?>/>
1041 - <?php echo TXT_RANDOM_PASS; ?>
1042 - </label>
1043 - <br />
1044 - <?php echo TXT_FILE_PASS_TYPE_DESC; ?>
1045 - </td>
1046 - </tr>
1047 - <tr>
1048 - <th>
1049 - <?php echo TXT_DOWNLOAD_TYPE; ?>
1050 - </th>
1051 - <td>
1052 - <label for="uam_download_type_normal">
1053 - <input type="radio" id="uam_download_type_normal" name="uam_download_type" value="normal" <?php if ($uamOptions['download_type'] == "normal") { echo 'checked="checked"'; }?> />
1054 - <?php echo TXT_NORMAL; ?>
1055 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1056 - <label for="uam_download_type_fopen">
1057 - <input type="radio" id="uam_download_type_fopen" name="uam_download_type" value="fopen" <?php if ($uamOptions['download_type'] == "fopen") { echo 'checked="checked"'; }?>/>
1058 - <?php echo TXT_FOPEN; ?>
1059 - </label>
1060 - <br />
1061 - <?php echo TXT_DOWNLOAD_TYPE_DESC; ?>
1062 - </td>
1063 - </tr>
1064 - </tbody>
1065 - </table>
1066 - <h3><?php echo TXT_OTHER_SETTING; ?></h3>
1067 - <p><?php echo TXT_OTHER_SETTING_DESC; ?></p>
1068 - <table class="form-table">
1069 - <tbody>
1070 - <tr>
1071 - <th>
1072 - <?php echo TXT_HIDE_EMPTY_CATEGORIES; ?>
1073 - </th>
1074 - <td>
1075 - <label for="uam_hide_empty_categories_yes">
1076 - <input type="radio" id="uam_hide_empty_categories_yes" name="uam_hide_empty_categories" value="true" <?php if ($uamOptions['hide_empty_categories'] == "true") { echo 'checked="checked"'; }?> />
1077 - <?php echo TXT_YES; ?>
1078 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1079 - <label for="uam_hide_empty_categories_no">
1080 - <input type="radio" id="uam_hide_empty_categories_no" name="uam_hide_empty_categories" value="false" <?php if ($uamOptions['hide_empty_categories'] == "false") { echo 'checked="checked"'; }?>/>
1081 - <?php echo TXT_NO; ?>
1082 - </label>
1083 - <br />
1084 - <?php echo TXT_HIDE_EMPTY_CATEGORIES_DESC; ?>
1085 - </td>
1086 - </tr>
1087 - <tr>
1088 - <th>
1089 - <?php echo TXT_REDIRECT; ?>
1090 - </th>
1091 - <td>
1092 - <label for="uam_redirect_no">
1093 - <input type="radio" id="uam_redirect_no" name="uam_redirect" value="false" <?php if ($uamOptions['redirect'] == "false") { echo 'checked="checked"'; }?> />
1094 - <?php echo TXT_NO; ?>
1095 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1096 - <label for="uam_redirect_blog">
1097 - <input type="radio" id="uam_redirect_blog" name="uam_redirect" value="blog" <?php if ($uamOptions['redirect'] == "blog") { echo 'checked="checked"'; }?> />
1098 - <?php echo TXT_REDIRECT_TO_BOLG; ?>
1099 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1100 - <label for="uam_redirect_custom_page">
1101 - <input type="radio" id="uam_redirect_custom_p" name="uam_redirect" value="custom_page" <?php if ($uamOptions['redirect'] == "custom_page") { echo 'checked="checked"'; }?>/>
1102 - <?php echo TXT_REDIRECT_TO_PAGE; ?>
1103 - </label><select name="uam_redirect_custom_page">
1104 - <?php
1105 - $pages = get_pages('sort_column=menu_order');
1106 -
1107 - if(isset($pages))
1108 - {
1109 - foreach($pages as $page)
1110 - {
1111 - echo '<option value="'.$page->ID;
1112 -
1113 - if($uamOptions['redirect_custom_page'] == $page->ID)
1114 - echo ' selected = "selected"';
59 +//Check wordpress version
60 +global $wp_version;
1115 61
1116 - echo '>'.$page->post_title.'</option>';
1117 - }
1118 - }
1119 - ?></select>&nbsp;&nbsp;&nbsp;&nbsp;
1120 - <label for="uam_redirect_custom_url">
1121 - <input type="radio" id="uam_redirect_custom_u" name="uam_redirect" value="custom_url" <?php if ($uamOptions['redirect'] == "custom_url") { echo 'checked="checked"'; }?>/>
1122 - <?php echo TXT_REDIRECT_TO_URL; ?>
1123 - </label><input name="uam_redirect_custom_url" value="<?php echo $uamOptions['redirect_custom_url']; ?>" />
1124 - <br />
1125 - <?php echo TXT_REDIRECT_DESC; ?>
1126 - </td>
1127 - </tr>
1128 - <tr>
1129 - <th>
1130 - <?php echo TXT_LOCK_RECURSIVE; ?>
1131 - </th>
1132 - <td>
1133 - <label for="uam_lock_recursive_yes">
1134 - <input type="radio" id="uam_lock_recursive_yes" name="uam_lock_recursive" value="true" <?php if ($uamOptions['lock_recursive'] == "true") { echo 'checked="checked"'; }?> />
1135 - <?php echo TXT_YES; ?>
1136 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1137 - <label for="uam_lock_recursive_no">
1138 - <input type="radio" id="uam_lock_recursive_no" name="uam_lock_recursive" value="false" <?php if ($uamOptions['lock_recursive'] == "false") { echo 'checked="checked"'; }?>/>
1139 - <?php echo TXT_NO; ?>
1140 - </label>
1141 - <br />
1142 - <?php echo TXT_LOCK_RECURSIVE_DESC; ?>
1143 - </td>
1144 - </tr>
1145 - <tr>
1146 - <th>
1147 - <?php echo TXT_BLOG_ADMIN_HINT; ?>
1148 - </th>
1149 - <td>
1150 - <label for="uam_blog_admin_hint_yes">
1151 - <input type="radio" id="uam_blog_admin_hint_yes" name="uam_blog_admin_hint" value="true" <?php if ($uamOptions['blog_admin_hint'] == "true") { echo 'checked="checked"'; }?> />
1152 - <?php echo TXT_YES; ?>
1153 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1154 - <label for="uam_blog_admin_hint_no">
1155 - <input type="radio" id="uam_blog_admin_hint_no" name="uam_blog_admin_hint" value="false" <?php if ($uamOptions['blog_admin_hint'] == "false") { echo 'checked="checked"'; }?>/>
1156 - <?php echo TXT_NO; ?>
1157 - </label>
1158 - <br />
1159 - <?php echo TXT_BLOG_ADMIN_HINT_DESC; ?>
1160 - </td>
1161 - </tr>
1162 - <tr>
1163 - <th>
1164 - <?php echo TXT_BLOG_ADMIN_HINT_TEXT; ?>
1165 - </th>
1166 - <td>
1167 - <input name="uam_blog_admin_hint_text" value="<?php echo $uamOptions['blog_admin_hint_text']; ?>" />
1168 - <br />
1169 - <?php echo TXT_BLOG_ADMIN_HINT_TEXT_DESC; ?>
1170 - </td>
1171 - </tr>
1172 - <?php
1173 - global $wp_version;
1174 -
1175 - if($wp_version < 2.8)
1176 - {
1177 - ?>
1178 - <tr>
1179 - <th>
1180 - <?php echo TXT_CORE_MOD; ?>
1181 - </th>
1182 - <td>
1183 - <label for="uam_core_mod_yes">
1184 - <input type="radio" id="uam_core_mod_yes" name="uam_core_mod" value="true" <?php if ($uamOptions['core_mod'] == "true") { echo 'checked="checked"'; }?> />
1185 - <?php echo TXT_YES; ?>
1186 - </label>&nbsp;&nbsp;&nbsp;&nbsp;
1187 - <label for="uam_core_mod_no">
1188 - <input type="radio" id="uam_core_mod_no" name="uam_core_mod" value="false" <?php if ($uamOptions['core_mod'] == "false") { echo 'checked="checked"'; }?>/>
1189 - <?php echo TXT_NO; ?>
1190 - </label>
1191 - <br />
1192 - <?php echo TXT_CORE_MOD_DESC; ?>
1193 - </td>
1194 - </tr>
1195 - <?php
1196 - }
1197 - ?>
1198 - </tbody>
1199 - </table>
1200 - <div class="submit">
1201 - <input type="submit" name="update_uam_settings" value="<?php echo TXT_UPDATE_SETTING; ?>" />
1202 - </div>
1203 - </form>
1204 - </div>
1205 - <?php
1206 - }
1207 - elseif($action == 'edit_group' && isset($_GET['id']))
1208 - {
1209 - $group_id = $_GET['id'];
1210 - $accessgroup = $wpdb->get_row(" SELECT *
1211 - FROM ".DB_ACCESSGROUP."
1212 - WHERE ID = ".$group_id."
1213 - LIMIT 1", ARRAY_A);
1214 - ?>
1215 - <div class="wrap">
1216 - <?php $this->get_print_edit_group($group_id); ?>
1217 - </div>
1218 - <?php
1219 - }
1220 - elseif($cur_admin_page == 'uam_usergroup')
1221 - {
1222 - $accessgroups = $wpdb->get_results("SELECT *
1223 - FROM ".DB_ACCESSGROUP."
1224 - ORDER BY ID", ARRAY_A);
1225 - ?>
1226 - <div class=wrap>
1227 - <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
1228 - <input type="hidden" value="delgroup" name="action"/>
1229 - <h2><?php echo TXT_MANAGE_GROUP; ?></h2>
1230 - <div class="tablenav">
1231 - <div class="alignleft">
1232 - <input type="submit" class="button-secondary delete" name="deleteit" value="<?php echo TXT_DELETE; ?>"/>
1233 - <input type="hidden" id="TXT_COLLAPS_ALL" name="deleteit" value="<?php echo TXT_COLLAPS_ALL; ?>"/>
1234 - <input type="hidden" id="TXT_EXPAND_ALL" name="deleteit" value="<?php echo TXT_EXPAND_ALL; ?>"/>
1235 - </div>
1236 - <br class="clear"/>
1237 - </div>
1238 - <br class="clear"/>
1239 - <table class="widefat">
1240 - <thead>
1241 - <tr class="thead">
1242 - <th scope="col"></th>
1243 - <th scope="col"><?php echo TXT_NAME; ?></th>
1244 - <th scope="col"><?php echo TXT_DESCRIPTION; ?></th>
1245 - <th scope="col"><?php echo TXT_READ_ACCESS; ?></th>
1246 - <th scope="col"><?php echo TXT_WRITE_ACCESS; ?></th>
1247 - <th scope="col"><?php echo TXT_IP_RANGE; ?></th>
1248 - <th scope="col"><?php echo TXT_POSTS; ?></th>
1249 - <th scope="col"><?php echo TXT_PAGES; ?></th>
1250 - <th scope="col"><?php echo TXT_FILES; ?></th>
1251 - <th scope="col"><?php echo TXT_CATEGORY; ?></th>
1252 - <th scope="col"><?php echo TXT_USERS; ?></th>
1253 - <th></th>
1254 - </tr>
1255 - </thead>
1256 - <tbody>
1257 - <?php
1258 - if(isset($accessgroups))
1259 - {
1260 - foreach($accessgroups as $accessgroup)
1261 - {
1262 - $group_info = $this->get_usergroup_info($accessgroup['ID']);
1263 - ?>
1264 - <tr class="alternate" id="group-<?php echo $accessgroup['ID']; ?>">
1265 - <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $accessgroup['ID']; ?>" name="delete[]"/></th>
1266 - <td><strong><a href="?page=<?php echo $cur_admin_page; ?>&action=edit_group&id=<?php echo $accessgroup['ID']; ?>"><?php echo $accessgroup['groupname']; ?></a></strong></td>
1267 - <td><?php echo $accessgroup['groupdesc']; ?></td>
1268 - <td><?php if($accessgroup['read_access'] == "all"){ echo TXT_ALL;}elseif($accessgroup['read_access'] == "group"){ echo TXT_ONLY_GROUP_USERS;} ?></td>
1269 - <td><?php if($accessgroup['write_access'] == "all"){ echo TXT_ALL;}elseif($accessgroup['write_access'] == "group"){ echo TXT_ONLY_GROUP_USERS;} ?></td>
1270 - <td><?php if(isset($accessgroup['ip_range'])){ echo $accessgroup['ip_range']; }else{ echo TXT_NONE; }?></td>
1271 - <td>
1272 - <?php
1273 - if(isset($group_info->posts))
1274 - {
1275 - $expandcontent = null;
1276 - foreach($group_info->posts as $post)
1277 - {
1278 - $expandcontent .= "<li>".$post->post_title."</li>";
1279 - }
1280 - echo "<a class='uam_info_link'>".count($group_info->posts)." ".TXT_POSTS."</a>";;
1281 - echo "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul>";
1282 - }
1283 - else
1284 - {
1285 - echo TXT_NONE;
1286 - }
1287 - ?>
1288 - </td>
1289 - <td>
1290 - <?php
1291 - if(isset($group_info->pages))
1292 - {
1293 - $expandcontent = null;
1294 - foreach($group_info->pages as $page)
1295 - {
1296 - $expandcontent .= "<li>".$page->post_title."</li>";
1297 - }
1298 - echo "<a class='uam_info_link'>".count($group_info->pages)." ".TXT_PAGES."</a>";
1299 - echo "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul>";
1300 - }
1301 - else
1302 - {
1303 - echo TXT_NONE;
1304 - }
1305 - ?>
1306 - </td>
1307 - <td>
1308 - <?php
1309 - if(isset($group_info->files))
1310 - {
1311 - $expandcontent = null;
1312 - foreach($group_info->files as $file)
1313 - {
1314 - $expandcontent .= "<li>".$file->post_title."</li>";
1315 - }
1316 - echo "<a class='uam_info_link'>".count($group_info->files)." ".TXT_FILES."</a>";
1317 - echo "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul>";
1318 - }
1319 - else
1320 - {
1321 - echo TXT_NONE;
1322 - }
1323 - ?>
1324 - </td>
1325 - <td>
1326 - <?php
1327 - if(isset($group_info->categories))
1328 - {
1329 - $expandcontent = null;
1330 - foreach($group_info->categories as $categorie)
1331 - {
1332 - $expandcontent .= "<li>".$categorie->cat_name."</li>";
1333 - }
1334 - echo "<a class='uam_info_link'>".count($group_info->categories)." ".TXT_CATEGORY."</a>";
1335 - echo "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul>";
1336 - }
1337 - else
1338 - {
1339 - echo TXT_NONE;
1340 - }
1341 - ?>
1342 - </td>
1343 - <td>
1344 - <?php
1345 - if(isset($group_info->users))
1346 - {
1347 - $expandcontent = null;
1348 - foreach($group_info->users as $user)
1349 - {
1350 - $expandcontent .= "<li>".$user->nickname."</li>";
1351 - }
1352 - echo "<a class='uam_info_link'>".count($group_info->users)." ".TXT_USERS."</a>";
1353 - echo "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul>";
1354 - }
1355 - else
1356 - {
1357 - echo TXT_NONE;
1358 - }
1359 - ?>
1360 - </td>
1361 - <td>
1362 - <a class="uam_info_link_all" href="#"><?php echo TXT_EXPAND_ALL; ?></a>
1363 - </td>
1364 - </tr>
1365 - <?php
1366 - }
1367 - }
1368 - ?>
1369 - </tbody>
1370 - </table>
1371 - </form>
1372 - </div>
1373 - <div class="wrap">
1374 - <h2><?php echo TXT_ADD_GROUP; ?></h2>
1375 - <div id="ajax-response"/>
1376 - <?php $this->get_print_edit_group(); ?>
1377 - </div>
1378 - <?php
1379 - }
1380 - }//End function printAdminPage()
1381 -
1382 - function get_print_edit_group($group_id = null)
1383 - {
1384 - global $wpdb;
1385 - $uamOptions = $this->getAdminOptions();
1386 -
1387 - if(isset($group_id))
1388 - $group_info = $this->get_usergroup_info($group_id);
1389 - ?>
1390 - <form method="post" action="<?php echo reset(explode("?", $_SERVER["REQUEST_URI"]))."?page=".$_GET['page']; ?>">
1391 - <input type="hidden" id="TXT_COLLAPS" name="deleteit" value="<?php echo TXT_COLLAPS; ?>"/>
1392 - <input type="hidden" id="TXT_EXPAND" name="deleteit" value="<?php echo TXT_EXPAND; ?>"/>
1393 - <?php
1394 - if(isset($group_id))
1395 - {
1396 - ?>
1397 - <input type="hidden" value="update_group" name="action"/>
1398 - <input type="hidden" value="<?php echo $group_id; ?>" name="access_group_id"/>
1399 - <?php
1400 - }
1401 - else
1402 - {
1403 - ?>
1404 - <input type="hidden" value="addgroup" name="action"/>
1405 - <?php
1406 - }
1407 - ?>
1408 - <input type="hidden" value="<?php echo $uamOptions['lock_recursive']; ?>" name="uam_lock_recursive" id="uam_set_lock_recursive"/>
1409 - <table class="form-table">
1410 - <tbody>
1411 - <tr class="form-field form-required">
1412 - <th valign="top" scope="row"><?php echo TXT_GROUP_NAME; ?></th>
1413 - <td><input type="text" size="40" value="<?php if(isset($group_id)){echo $group_info->group["groupname"]; }?>" id="access_group_name" name="access_group_name"/><br/>
1414 - <?php echo TXT_GROUP_NAME_DESC; ?></td>
1415 - </tr>
1416 - <tr class="form-field form-required">
1417 - <th valign="top" scope="row"><?php echo TXT_GROUP_DESC; ?></th>
1418 - <td><input type="text" size="40" value="<?php if(isset($group_id)){ echo $group_info->group["groupdesc"]; }?>" id="access_group_description" name="access_group_description"/><br/>
1419 - <?php echo TXT_GROUP_DESC_DESC; ?></td>
1420 - </tr>
1421 - <tr class="form-field form-required">
1422 - <th valign="top" scope="row"><?php echo TXT_GROUP_IP_RANGE; ?></th>
1423 - <td><input type="text" size="40" value="<?php if(isset($group_id)){ echo $group_info->group["ip_range"]; }?>" id="ip_range" name="ip_range"/><br/>
1424 - <?php echo TXT_GROUP_IP_RANGE_DESC; ?></td>
1425 - </tr>
1426 - <tr class="form-field form-required">
1427 - <th valign="top" scope="row"><?php echo TXT_GROUP_READ_ACCESS; ?></th>
1428 - <td><select name="read_access">
1429 - <option value="group" <?php if(isset($group_id)){ if($group_info->group["read_access"] == "group"){ echo 'selected="selected"'; }} ?> ><?php echo TXT_ONLY_GROUP_USERS ?></option>
1430 - <option value="all" <?php if(isset($group_id)){ if($group_info->group["read_access"] == "all"){ echo 'selected="selected"'; }} ?> ><?php echo TXT_ALL ?></option>
1431 - </select><br />
1432 - <?php echo TXT_GROUP_READ_ACCESS_DESC; ?></td>
1433 - </tr>
1434 - <tr class="form-field form-required">
1435 - <th valign="top" scope="row"><?php echo TXT_GROUP_WRITE_ACCESS; ?></th>
1436 - <td><select name="write_access">
1437 - <option value="group" <?php if(isset($group_id)){ if($group_info->group["write_access"] == "group"){ echo 'selected="selected"'; }} ?> ><?php echo TXT_ONLY_GROUP_USERS ?></option>
1438 - <option value="all" <?php if(isset($group_id)){ if($group_info->group["write_access"] == "all"){ echo 'selected="selected"'; }} ?> ><?php echo TXT_ALL ?></option>
1439 - </select><br />
1440 - <?php echo TXT_GROUP_WRITE_ACCESS_DESC; ?></td>
1441 - </tr>
1442 - <tr>
1443 - <th valign="top" scope="row"><?php echo TXT_GROUP_ROLE; ?></th>
1444 - <td>
1445 - <ul class='uam_role'>
1446 - <?php
1447 - global $wp_roles;
1448 -
1449 - foreach($wp_roles->role_names as $role => $name)
1450 - {
1451 - if($role != "administrator")
1452 - {
1453 - ?>
1454 - <li class="selectit">
1455 - <input id="role-<?php echo $role; ?>" type="checkbox" <?php if(isset($group_info->posts[$role])){ echo 'checked="checked"'; } ?> value="<?php echo $role; ?>" name="roles[]"/>
1456 - <label for="role-<?php echo $role; ?>"><?php echo $role ?></label>
1457 - </li>
1458 - <?php
1459 - }
1460 - }
1461 - ?>
1462 - </ul>
1463 - </td>
1464 - </tr>
1465 - <tr>
1466 - <?php
1467 - $args = array('numberposts' => -1);
1468 - $posts = get_posts($args);
1469 - ?>
1470 - <th valign="top" scope="row"><?php echo TXT_POSTS; if(count($posts) > 0){ echo " <label>(<a class='selectit uam_group_stuff_link'>".TXT_EXPAND."</a>)</label>"; }?></th>
1471 - <td>
1472 - <?php
1473 - if(isset($group_info->posts))
1474 - $posts_in_group = count($group_info->posts);
1475 - else
1476 - $posts_in_group = 0;
1477 -
1478 - echo "<strong>".sprintf(TXT_CONTAIN_POSTS, "<span class='uam_element_count'>".$posts_in_group."</span>", count($posts))."</strong>";
1479 -
1480 - if(isset($posts))
1481 - {
1482 - echo "<ul class='uam_group_stuff'>";
1483 - foreach($posts as $post)
1484 - {
1485 - $cur_categories = get_the_category($post->ID);
1486 - ?>
1487 - <li class="selectit <?php foreach($cur_categories as $cur_cat){ echo "cat-".$cur_cat->term_id." "; }?>">
1488 - <input id="post-<?php echo $post->ID; ?>" type="checkbox" value="<?php echo $post->ID;?>" <?php if(isset($group_info->posts[$post->ID])){ echo 'checked="checked"'; } ?> name="post[]"/>
1489 - <label for="post-<?php echo $post->ID; ?>"><strong><?php echo $post->post_title; ?></strong> - <?php echo $post->post_date; ?></label>
1490 - <?php
1491 -
1492 - ?>
1493 - </li>
1494 - <?php
1495 - }
1496 - echo "</ul>";
1497 - }
1498 - ?>
1499 - </td>
1500 - </tr>
1501 - <tr>
1502 - <?php
1503 - $pages = get_pages('sort_column=menu_order');
1504 - ?>
1505 - <th valign="top" scope="row"><?php echo TXT_PAGES; if(count($pages) > 0){ echo " <label>(<a class='selectit uam_group_stuff_link'>".TXT_EXPAND."</a>)</label>"; } ?></th>
1506 - <td>
1507 - <?php
1508 - if(isset($group_info->pages))
1509 - $pages_in_group = count($group_info->pages);
1510 - else
1511 - $pages_in_group = 0;
1512 -
1513 - echo "<strong>".sprintf(TXT_CONTAIN_PAGES, "<span class='uam_element_count'>".$pages_in_group."</span>", count($pages))."</strong>";
1514 -
1515 - if(isset($pages))
1516 - {
1517 - echo "<ul class='uam_group_stuff'>";
1518 - $deepness = 0;
1519 -
1520 - foreach($pages as $page)
1521 - {
1522 - $old_deepness = $deepness;
1523 - $deepness = 0;
1524 -
1525 - if($page->post_parent != 0)
1526 - {
1527 - $cur_page = $page;
1528 - $cur_id = $page->ID;
1529 - while($cur_page->post_parent != 0)
1530 - {
1531 - $deepness++;
1532 - $cur_parent_id = $cur_page->post_parent;
1533 - $cur_page = & get_post($cur_parent_id);
1534 - }
1535 - }
1536 -
1537 - if($old_deepness > $deepness)
1538 - {
1539 - $count = abs($old_deepness - $deepness);
1540 - for($i = 0; $i < $count; $i++)
1541 - echo "</ul>";
1542 - }
1543 - elseif($old_deepness < $deepness)
1544 - {
1545 - $count = abs($old_deepness - $deepness);
1546 - for($i = 0; $i < $count; $i++)
1547 - echo "<ul class='uam_group_stuff_child'>";
1548 - }
1549 -
1550 - ?>
1551 - <li class="selectit">
1552 - <input id="post-<?php echo $page->ID; ?>" type="checkbox" value="<?php echo $page->ID;?>" <?php if(isset($group_info->pages[$page->ID])){ echo 'checked="checked"'; } ?> name="page[]"/>
1553 - <label for="post-<?php echo $page->ID; ?>"><strong><?php echo $page->post_title; ?></strong> - <?php echo $page->post_date; ?></label>
1554 - </li>
1555 - <?php
1556 - }
1557 - echo "</ul>";
1558 - }
1559 - ?>
1560 - </td>
1561 - </tr>
1562 - <tr>
1563 - <?php
1564 - $args = array( 'numberposts' => -1,
1565 - 'post_type' => 'attachment');
1566 - $files = get_posts($args);
1567 - ?>
1568 - <th valign="top" scope="row"><?php echo TXT_FILES; if(count($files) > 0){ echo " <label>(<a class='selectit uam_group_stuff_link'>".TXT_EXPAND."</a>)</label>"; }?></th>
1569 - <td>
1570 - <?php
1571 - if(isset($group_info->files))
1572 - $files_in_group = count($group_info->files);
1573 - else
1574 - $files_in_group = 0;
1575 -
1576 - echo "<strong>".sprintf(TXT_CONTAIN_FILES, "<span class='uam_element_count'>".$files_in_group."</span>", count($files))."</strong>";
1577 -
1578 - if(isset($files))
1579 - {
1580 - echo "<ul class='uam_group_stuff'>";
1581 - foreach($files as $file)
1582 - {
1583 - $cur_categories = get_the_category($file->ID);
1584 - ?>
1585 - <li class="selectit <?php foreach($cur_categories as $cur_cat){ echo "cat-".$cur_cat->term_id." "; } echo "parent_post-".$file->post_parent." ";?>">
1586 - <input id="post-<?php echo $file->ID; ?>" type="checkbox" value="<?php echo $file->ID;?>" <?php if(isset($group_info->files[$file->ID])){ echo 'checked="checked"'; } ?> name="file[]"/>
1587 - <label for="post-<?php echo $file->ID; ?>"><strong><?php echo $file->post_title; ?></strong> - <?php echo $file->post_date; ?></label>
1588 - </li>
1589 - <?php
1590 - }
1591 - echo "</ul>";
1592 - }
1593 - ?>
1594 - </td>
1595 - </tr>
1596 - <tr>
1597 - <?php
1598 - $categories = get_categories();
1599 - ?>
1600 - <th valign="top" scope="row"><?php echo TXT_CATEGORY; if(count($categories) > 0){ echo " <label>(<a class='selectit uam_group_stuff_link'>".TXT_EXPAND."</a>)</label>"; } ?></th>
1601 - <td>
1602 - <?php
1603 - if(isset($group_info->categories))
1604 - $categories_in_group = count($group_info->categories);
1605 - else
1606 - $categories_in_group = 0;
1607 -
1608 - echo "<strong>".sprintf(TXT_CONTAIN_CATEGORIES, "<span class='uam_element_count'>".$categories_in_group."</span>", count($categories))."</strong>";
1609 -
1610 - function print_elements($group_id, $group_info = null, $category = 0, $deepness = 0)
1611 - {
1612 - global $wpdb;
1613 -
1614 - $args = array('child_of' => $category);
1615 - $categories = get_categories($args);
1616 -
1617 - if(isset($categories))
1618 - {
1619 - $first_round = true;
1620 - foreach($categories as $cat)
1621 - {
1622 -
1623 - if($cat->parent == $category)
1624 - {
1625 - if($first_round == true)
1626 - {
1627 - if($category == 0)
1628 - echo "<ul class='uam_group_stuff uam_category'>";
1629 - else
1630 - echo "<ul class='uam_group_stuff_child uam_category'>";
1631 -
1632 - $first_round = false;
1633 - }
1634 - ?>
1635 - <li class="selectit">
1636 - <input id="category-<?php echo $cat->term_id; ?>" type="checkbox" name="category[]" value="<?php echo $cat->term_id;?>" <?php if(isset($group_info[$cat->term_id])){ echo 'checked="checked"'; } ?> />
1637 - <label for="category-<?php echo $cat->term_id; ?>"><strong><?php echo $cat->cat_name; ?></strong></label>
1638 - </li>
1639 - <?php
1640 - print_elements($group_id, $group_info, $cat->term_id, $deepness++);
1641 - }
1642 - }
1643 - if($first_round == false)
1644 - {
1645 - echo "</ul>";
1646 - }
1647 - }
1648 - }
1649 -
1650 - $callFkt = "print_elements";
1651 -
1652 - if(isset($group_info->categories))
1653 - echo $callFkt($group_id, $group_info->categories);
1654 - else
1655 - echo $callFkt($group_id);
1656 - ?>
1657 - </td>
1658 - </tr>
1659 - <tr>
1660 - <?php
1661 - $users = $wpdb->get_results(" SELECT ID
1662 - FROM $wpdb->users
1663 - ORDER BY ID", ARRAY_A);
1664 - ?>
1665 - <th valign="top" scope="row"><?php echo TXT_USERS; if(count($users) > 0){ echo " <label>(<a class='selectit uam_group_stuff_link'>".TXT_EXPAND."</a>)</label>"; } ?></th>
1666 - <td>
1667 - <?php
1668 - if(isset($group_info))
1669 - $users_in_group = count($group_info->users);
1670 - else
1671 - $users_in_group = 0;
1672 -
1673 - echo "<strong>".sprintf(TXT_CONTAIN_USERS, "<span class='uam_element_count'>".$users_in_group."</span>", count($users))."</strong>";
1674 -
1675 - if(isset($users))
1676 - {
1677 - echo "<ul class='uam_group_stuff'>";
1678 - foreach($users as $user)
1679 - {
1680 - $cur_user = get_userdata($user['ID']);
1681 - $user_capabilities = array_keys($cur_user->{$wpdb->prefix."capabilities"})
1682 - ?>
1683 - <li class="selectit <?php foreach($user_capabilities as $user_capability){ echo "usercap_".$user_capability." "; } ?>">
1684 - <?php
1685 - if(empty($cur_user->{$wpdb->prefix."capabilities"}['administrator']))
1686 - {
1687 - ?>
1688 - <input id="user-<?php echo $cur_user->ID; ?>" type="checkbox" value="<?php echo $cur_user->ID; ?>" <?php if(isset($group_info->users[$cur_user->ID])){ echo 'checked="checked"'; } ?> name="user[]"/>
1689 - <label for="user-<?php echo $cur_user->ID; ?>"><strong><?php echo $cur_user->nickname; ?></strong> - <?php echo $cur_user->user_firstname." ".$cur_user->user_lastname; ?>
1690 - <?php
1691 - }
1692 - else
1693 - {
1694 - ?>
1695 - <input id="user-<?php echo $cur_user->ID; ?>" type="checkbox" value="<?php echo $cur_user->ID; ?>" checked="checked" disabled="disabled" name="user[]"/>
1696 - <label for="user-<?php echo $cur_user->ID; ?>"><strong><?php echo $cur_user->nickname; ?></strong> - <?php echo $cur_user->user_firstname." ".$cur_user->user_lastname; ?>
1697 - <?php
1698 - echo "(".TXT_IS_ADMIN.")";
1699 - }
1700 - ?>
1701 -
1702 - </li>
1703 - <?php
1704 - }
1705 - echo "</ul>";
1706 - }
1707 - ?>
1708 - </td>
1709 - </tr>
1710 - </tbody>
1711 - </table>
1712 - <p class="submit"><input type="submit" value="<?php if(isset($group_id)) { echo TXT_UPDATE_GROUP; }else{ echo TXT_ADD_GROUP;} ?>" name="submit" class="button"/></p>
1713 - </form>
1714 - <?php
1715 - }
1716 -
1717 - function get_usergroups_for_post($ID)
1718 - {
1719 - global $wpdb;
1720 -
1721 - $access = $this->get_access($ID);
1722 -
1723 - $post_usergroups = array();
1724 -
1725 - if(isset($access->restricted_by_posts) || isset($access->restricted_by_categories))
1726 - {
1727 - if(isset($access->restricted_by_posts))
1728 - {
1729 - foreach($access->restricted_by_posts as $cur_id)
1730 - {
1731 - $usergroups = $wpdb->get_results(" SELECT ag.ID, ag.groupname
1732 - FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_POST." agtp
1733 - WHERE agtp.post_id = ".$cur_id."
1734 - AND ag.ID = agtp.group_id
1735 - GROUP BY ag.groupname", ARRAY_A);
1736 -
1737 - if(isset($usergroups))
1738 - {
1739 - foreach($usergroups as $usergroup)
1740 - {
1741 - $cur_usergroup = null;
1742 -
1743 - if(isset($post_usergroups[$usergroup['ID']]))
1744 - $cur_usergroup = $post_usergroups[$usergroup['ID']];
1745 -
1746 - $cur_usergroup->ID = $usergroup['ID'];
1747 - $cur_usergroup->name = $usergroup['groupname'];
1748 -
1749 - if($cur_id != $ID)
1750 - {
1751 - if(isset($cur_usergroup->posts))
1752 - $posts = $cur_usergroup->posts;
1753 -
1754 - $lock_post = & get_post($cur_id);
1755 - $posts[] = $lock_post->ID;
1756 - $cur_usergroup->posts = $posts;
1757 - }
1758 - else
1759 - {
1760 - $cur_usergroup->itself = true;
1761 - }
1762 -
1763 - $post_usergroups[$usergroup['ID']] = $cur_usergroup;
1764 - }
1765 - }
1766 - }
1767 - }
1768 -
1769 - if(isset($access->restricted_by_categories))
1770 - {
1771 - foreach($access->restricted_by_categories as $cur_id)
1772 - {
1773 - $usergroups = $wpdb->get_results(" SELECT ag.ID, ag.groupname
1774 - FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_CATEGORY." agtc
1775 - WHERE agtc.category_id = ".$cur_id."
1776 - AND ag.ID = agtc.group_id
1777 - GROUP BY ag.groupname", ARRAY_A);
1778 -
1779 - if(isset($usergroups))
1780 - {
1781 - foreach($usergroups as $usergroup)
1782 - {
1783 - $cur_usergroup = null;
1784 -
1785 - if(isset($post_usergroups[$usergroup['ID']]))
1786 - $cur_usergroup = $post_usergroups[$usergroup['ID']];
1787 -
1788 - $cur_usergroup->ID = $usergroup['ID'];
1789 - $cur_usergroup->name = $usergroup['groupname'];
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 + )
71 + );
72 +
73 + $blStop = true;
74 +}
1790 75
1791 - if(isset($cur_usergroup->categorie))
1792 - $categories = $cur_usergroup->categories;
1793 -
1794 - $lock_cat = & get_category($cur_id);
1795 - $categories[] = $lock_cat->term_id;
1796 - $cur_usergroup->categories = $categories;
76 +//If we have a error stop plugin.
77 +if ($blStop) {
78 + return;
79 +}
1797 80
1798 - $post_usergroups[$usergroup['ID']] = $cur_usergroup;
1799 - }
1800 - }
1801 81
1802 -
1803 - }
1804 - }
1805 - }
1806 -
1807 - return $post_usergroups;
1808 - }
1809 -
1810 - function get_usergroup_info($groupid)
1811 - {
1812 - global $wpdb;
1813 -
1814 - $uamOptions = $this->getAdminOptions();
1815 -
1816 - $cur_group = $wpdb->get_results(" SELECT *
1817 - FROM ".DB_ACCESSGROUP."
1818 - WHERE ID = ".$groupid, ARRAY_A);
1819 -
1820 - $info->group = $cur_group[0];
1821 -
1822 - $db_users = $wpdb->get_results(" SELECT *
1823 - FROM ".DB_ACCESSGROUP_TO_USER."
1824 - WHERE group_id = ".$groupid."
1825 - ORDER BY user_id", ARRAY_A);
1826 -
1827 - $db_posts = $wpdb->get_results(" SELECT *
1828 - FROM ".DB_ACCESSGROUP_TO_POST."
1829 - WHERE group_id = ".$groupid."
1830 - ORDER BY post_id", ARRAY_A);
1831 -
1832 - $db_categories = $wpdb->get_results(" SELECT *
1833 - FROM ".DB_ACCESSGROUP_TO_CATEGORY."
1834 - WHERE group_id = ".$groupid."
1835 - ORDER BY category_id", ARRAY_A);
1836 -
1837 - $db_roles = $wpdb->get_results(" SELECT *
1838 - FROM ".DB_ACCESSGROUP_TO_ROLE."
1839 - WHERE group_id = ".$groupid, ARRAY_A);
1840 -
1841 - $wp_users = $wpdb->get_results(" SELECT ID, user_nicename
1842 - FROM $wpdb->users
1843 - ORDER BY user_nicename", ARRAY_A);
1844 -
82 +//Classes
83 +require_once 'class/UserAccessManager.class.php';
84 +require_once 'class/UamUserGroup.class.php';
85 +require_once 'class/UamAccessHandler.class.php';
1845 86
1846 - if(isset($db_posts))
1847 - {
1848 - foreach($db_posts as $db_post)
1849 - {
1850 - $cur_id = $db_post['post_id'];
1851 - $cur_post = & get_post($cur_id);
1852 -
1853 - if(isset($cur_post->post_type))
1854 - {
1855 - if($cur_post->post_type == 'post')
1856 - {
1857 - $info->posts[$cur_id] = $cur_post;
1858 - }
1859 - elseif($cur_post->post_type == 'page')
1860 - {
1861 - $info->pages[$cur_id] = $cur_post;
1862 - }
1863 - elseif($cur_post->post_type == 'attachment')
1864 - {
1865 - $info->files[$cur_id] = $cur_post;
1866 - }
1867 - }
1868 - }
1869 - }
87 +if (class_exists("UserAccessManager")) {
88 + $oUserAccessManager = new UserAccessManager();
89 +}
1870 90
1871 - if(isset($db_categories))
1872 - {
1873 - foreach($db_categories as $db_categorie)
1874 - {
1875 - $cur_category = get_category($db_categorie['category_id']);
1876 -
1877 - $info->categories[$db_categorie['category_id']] = $cur_category;
1878 -
1879 - if($uamOptions['lock_recursive'] == 'true')
1880 - {
1881 - $cur_categories = get_categories('child_of='.$db_categorie['category_id']);
1882 - if(isset($cur_categories))
1883 - {
1884 - foreach($cur_categories as $cur_category)
1885 - {
1886 - $cur_category->recursive_lock_by_category[$db_categorie['category_id']] = $db_categorie['category_id'];
1887 - $info->categories[$cur_category->term_id] = $cur_category;
1888 - }
1889 - }
1890 - }
1891 - }
1892 - }
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();
1893 102
1894 - if(isset($db_users))
1895 - {
1896 - $expandcontent = null;
1897 - foreach($db_users as $db_user)
1898 - {
1899 - $info->users[$db_user['user_id']] = get_userdata($db_user['user_id']);
1900 - }
1901 - }
103 + if (!isset($oUserAccessManager)) {
104 + return;
105 + }
1902 106
1903 - if(isset($db_roles))
1904 - {
1905 - foreach($db_roles as $db_role)
1906 - {
1907 - $info->roles[$db_role['role_name']] = $db_role;
1908 - }
1909 - }
1910 -
1911 - if(isset($wp_users))
1912 - {
1913 - foreach($wp_users as $wp_user)
1914 - {
1915 - $cur_userdata = get_userdata($wp_user['ID']);
1916 -
1917 - if(isset($cur_userdata->{$wpdb->prefix."capabilities"}['administrator']))
1918 - {
1919 - $info->users[$wp_user['ID']] = $cur_userdata;
1920 - }
1921 - elseif(isset($db_roles) && empty($cur_userdata->{$wpdb->prefix."capabilities"}['administrator']))
1922 - {
1923 - foreach($db_roles as $db_role)
1924 - {
1925 - if(isset($cur_userdata->{$wpdb->prefix."capabilities"}[$db_role['role_name']]))
1926 - {
1927 - $info->users[$wp_user['ID']] = $cur_userdata;
1928 - break;
1929 - }
1930 - }
1931 - }
1932 - }
1933 - }
1934 -
107 + $oUserAccessManager->setAtAdminPanel();
108 + $aUamOptions = $oUserAccessManager->getAdminOptions();
1935 109
1936 - if(isset($info->categories))
1937 - {
1938 - foreach($info->categories as $group_category)
1939 - {
1940 - $cur_posts = get_posts('category='.$group_category->term_id);
1941 - if(isset($cur_posts))
1942 - {
1943 - foreach($cur_posts as $cur_post)
1944 - {
1945 - if($uamOptions['lock_recursive'] == 'false')
1946 - {
1947 - $cur_categories = get_the_category($cur_post->ID);
1948 - foreach($cur_categories as $cur_cat)
1949 - {
1950 - if($cur_cat->term_id == $group_category->term_id)
1951 - {
1952 - $add = true;
1953 - break;
1954 - }
1955 - }
1956 - }
1957 -
1958 - if(isset($add) || $uamOptions['lock_recursive'] == 'true')
1959 - {
1960 - if(isset($info->posts[$cur_post->ID]))
1961 - $cur_post = $info->posts[$cur_post->ID];
1962 -
1963 - $cur_post->recursive_lock_by_category[$group_category->term_id] = $group_category->term_id;
1964 - $info->posts[$cur_post->ID] = $cur_post;
1965 - }
1966 - }
1967 - }
1968 -
1969 - $cur_files = get_posts('category='.$group_category->term_id.'&post_type=attachment');
1970 - if(isset($cur_files))
1971 - {
1972 - foreach($cur_files as $cur_file)
1973 - {
1974 - if($uamOptions['lock_recursive'] == 'false')
1975 - {
1976 - $cur_categories = get_the_category($cur_post->ID);
1977 - foreach($cur_categories as $cur_cat)
1978 - {
1979 - if($cur_cat->term_id == $group_category->term_id)
1980 - {
1981 - $add = true;
1982 - break;
1983 - }
1984 - }
1985 - }
1986 -
1987 - if(isset($add) || $uamOptions['lock_recursive'] == 'true')
1988 - {
1989 - if(isset($info->files[$cur_file->ID]))
1990 - $cur_file = $info->files[$cur_file->ID];
1991 -
1992 - $cur_file->recursive_lock_by_category[$group_category->term_id] = $group_category->term_id;
1993 - $info->files[$cur_file->ID] = $cur_file;
1994 - }
1995 - }
1996 - }
1997 - }
1998 - }
1999 -
2000 - if(isset($info->posts))
2001 - {
2002 - foreach($info->posts as $group_post)
2003 - {
2004 - if($uamOptions['lock_recursive'] == 'true')
2005 - {
2006 - $cur_posts = get_posts('post_parent='.$group_post->ID);
2007 - if(isset($cur_posts))
2008 - {
2009 - foreach($cur_posts as $cur_post)
2010 - {
2011 - if(isset($info->posts[$cur_post->ID]))
2012 - $cur_post = $info->posts[$cur_post->ID];
2013 -
2014 - $cur_post->recursive_lock_by_post[$group_post->ID] = $group_post->ID;
2015 - $info->posts[$cur_post->ID] = $cur_post;
2016 - }
2017 - }
2018 - }
2019 - $cur_files = get_posts('post_parent='.$group_post->ID.'&post_type=attachment');
2020 - if(isset($cur_files))
2021 - {
2022 - foreach($cur_files as $cur_file)
2023 - {
2024 - if(isset($info->files[$cur_file->ID]))
2025 - $cur_file = $info->files[$cur_file->ID];
2026 -
2027 - $cur_file->recursive_lock_by_post[$group_post->ID] = $group_post->ID;
2028 - $info->files[$cur_file->ID] = $cur_file;
2029 - }
2030 - }
2031 - }
2032 - }
2033 -
2034 - if(isset($info->pages))
2035 - {
2036 - foreach($info->pages as $group_page)
2037 - {
2038 - if($uamOptions['lock_recursive'] == 'true')
2039 - {
2040 - $cur_pages = get_pages('child_of='.$group_page->ID);
2041 - if(isset($cur_pages))
2042 - {
2043 - foreach($cur_pages as $cur_page)
2044 - {
2045 - if(isset($info->posts[$cur_post->ID]))
2046 - $cur_post = $info->posts[$cur_post->ID];
2047 -
2048 - $cur_post->recursive_lock_by_post[$group_page->ID] = $group_page->ID;
2049 - $info->pages[$cur_page->ID] = $cur_page;
2050 - }
2051 - }
2052 - }
2053 -
2054 - $cur_files = get_posts('post_parent='.$group_page->ID.'&post_type=attachment');
2055 - if(isset($cur_files))
2056 - {
2057 - foreach($cur_files as $cur_file)
2058 - {
2059 - if(isset($info->files[$cur_file->ID]))
2060 - $cur_file = $info->files[$cur_file->ID];
2061 -
2062 - $cur_file->recursive_lock_by_post[$group_post->ID] = $group_post->ID;
2063 - $info->files[$cur_file->ID] = $cur_file;
2064 - }
2065 - }
2066 - }
2067 - }
2068 -
2069 - return $info;
2070 - }
2071 -
2072 - function get_usergroup_info_html($group_id, $style = null)
2073 - {
2074 - $link = '<a class="uam_group_info_link">('.TXT_INFO.')</a>';
2075 -
2076 - $group_info = $this->get_usergroup_info($group_id);
110 + if ($oUserAccessManager->isDatabaseUpdateNecessary()) {
111 + $sLink = 'admin.php?page=uam_setup';
2077 112
2078 - $content = "<ul class='uam_group_info'";
2079 -
2080 - if($style != null)
2081 - $content .= " style='".$style."' ";
2082 -
2083 - $content .= "><li class='uam_group_info_head'>".TXT_GROUP_INFO.":</li>";
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 + }
2084 123
2085 - $content .= "<li>".TXT_READ_ACCESS.": ";
2086 - if($group_info->group['read_access'] == "all")
2087 - $content .= TXT_ALL;
2088 - elseif($group_info->group['read_access'] == "group")
2089 - $content .= TXT_ONLY_GROUP_USERS;
2090 - $content .= "</li>";
2091 -
2092 - $content .= "<li>".TXT_WRITE_ACCESS.": ";
2093 - if($group_info->group['write_access'] == "all")
2094 - $content .= TXT_ALL;
2095 - elseif($group_info->group['write_access'] == "group")
2096 - $content .= TXT_ONLY_GROUP_USERS;
2097 - $content .= "</li>";
2098 -
2099 - if(isset($group_info->posts))
2100 - {
2101 - $expandcontent = null;
2102 - foreach($group_info->posts as $post)
2103 - {
2104 - $expandcontent .= "<li>".$post->post_title."</li>";
2105 - }
2106 - $content .= "<li><a class='uam_info_link'>".count($group_info->posts)." ".TXT_POSTS."</a>";
2107 - $content .= "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul></li>";
2108 - }
2109 - else
2110 - {
2111 - $content .= "<li>".TXT_NONE." ".TXT_POSTS."</li>";
2112 - }
124 + get_currentuserinfo();
125 + $oCurUserData = get_userdata($oCurrentUser->ID);
126 + $oUamAccessHandler = $oUserAccessManager->getAccessHandler();
127 + $aTaxonomies = get_taxonomies(array('public' => true, '_builtin' => false));
2113 128
2114 - if(isset($group_info->pages))
2115 - {
2116 - $expandcontent = null;
2117 - foreach($group_info->pages as $page)
2118 - {
2119 - $expandcontent .= "<li>".$page->post_title."</li>";
2120 - }
2121 - $content .= "<li><a class='uam_info_link'>".count($group_info->pages)." ".TXT_PAGES."</a>";
2122 - $content .= "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul></li>";
2123 - }
2124 - else
2125 - {
2126 - $content .= "<li>".TXT_NONE." ".TXT_PAGES."</li>";
2127 - }
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'));
2128 136
2129 - if(isset($group_info->categories))
2130 - {
2131 - $expandcontent = null;
2132 - foreach($group_info->categories as $categorie)
2133 - {
2134 - $expandcontent .= "<li>".$categorie->cat_name."</li>";
2135 - }
2136 - $content .= "<li><a class='uam_info_link'>".count($group_info->categories)." ".TXT_CATEGORY."</a>";
2137 - $content .= "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul></li>";
2138 - }
2139 - else
2140 - {
2141 - $content .= "<li>".TXT_NONE." ".TXT_CATEGORY."</li>";
2142 - }
2143 - if(isset($group_info->users))
2144 - {
2145 - $expandcontent = null;
2146 - foreach($group_info->users as $user)
2147 - {
2148 - $expandcontent .= "<li>".$user->nickname."</li>";
2149 - }
2150 - $content .= "<li><a class='uam_info_link'>".count($group_info->users)." ".TXT_USERS."</a>";
2151 - $content .= "<ul class='uam_info_content expand_deactive'>".$expandcontent."</ul></li>";
2152 - }
2153 - else
2154 - {
2155 - $content .= "<li>".TXT_NONE." ".TXT_USERS."</li>";
2156 - }
2157 - $content .= "</ul>";
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'));
2158 140
2159 - $result->link = $link;
2160 - $result->content = $content;
2161 -
2162 - return $result;
2163 - }
2164 -
2165 - function get_post_info_html($id)
2166 - {
2167 - $usergroups = $this->get_usergroups_for_post($id);
141 + add_action('manage_media_custom_column', array($oUserAccessManager, 'addPostColumn'), 10, 2);
2168 142
2169 - if(isset($usergroups) && $usergroups != null)
2170 - {
2171 - $output = "<ul>";
2172 - foreach($usergroups as $usergroup)
2173 - {
2174 - $output .= "<li><a class='uma_user_access_group'>".$usergroup->name."</a>";
2175 - $output .= "<ul class='uma_user_access_group_from'>";
2176 -
2177 - if(isset($usergroup->itself))
2178 - $output .= "<li>".TXT_ITSELF."</li>";
2179 -
2180 - if(isset($usergroup->posts))
2181 - {
2182 - foreach($usergroup->posts as $cur_id)
2183 - {
2184 - $cur_post = & get_post($cur_id);
2185 - $output .= "<li>$cur_post->post_title [$cur_post->post_type]</li>";
2186 - }
2187 - }
2188 -
2189 - if(isset($usergroup->categories))
2190 - {
2191 - foreach($usergroup->categories as $cur_id)
2192 - {
2193 - $cur_category = & get_category($cur_id);
2194 - $output .= "<li>$cur_category->name [category]</li>";
2195 - }
2196 - }
2197 -
2198 - $output = substr($output, 0, -2);
2199 -
2200 - $output .= "</ul></li>";
2201 - }
2202 - $output .= "</ul>";
2203 - }
2204 - else
2205 - {
2206 - $output = TXT_FULL_ACCESS;
2207 - }
2208 - return $output;
2209 - }
2210 - function add_post_columns_header($defaults)
2211 - {
2212 - $defaults['uam_access'] = __('Access');
2213 - return $defaults;
2214 - }
2215 -
2216 - function get_post_edit_info_html($id , $style = null)
2217 - {
2218 - global $wpdb;
2219 - $accessgroups = $wpdb->get_results("SELECT *
2220 - FROM ".DB_ACCESSGROUP."
2221 - ORDER BY groupname", ARRAY_A);
2222 -
2223 - $recursive_set = $this->get_usergroups_for_post($id);
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'));
2224 146
2225 - if(isset($accessgroups))
2226 - {
2227 - $content = "";
2228 -
2229 - foreach($accessgroups as $accessgroup)
2230 - {
2231 - $checked = $wpdb->get_results(" SELECT *
2232 - FROM ".DB_ACCESSGROUP_TO_POST."
2233 - WHERE post_id = ".$id."
2234 - AND group_id = ".$accessgroup['ID'], ARRAY_A);
2235 -
2236 - $set_recursive = null;
2237 - if(isset($recursive_set[$accessgroup['ID']]))
2238 - $set_recursive = $recursive_set[$accessgroup['ID']];
147 + add_action('edit_user_profile', array($oUserAccessManager, 'showUserProfile'));
148 + add_action('profile_update', array($oUserAccessManager, 'saveUserData'));
2239 149
2240 - $content .= '<p><label for="uam_accesssgroup-'.$accessgroup['ID'].'" class="selectit" style="display:inline;" >';
2241 - $content .= '<input type="checkbox" id="uam_accesssgroup-'.$accessgroup['ID'].'"';
2242 - if(isset($checked) || isset($set_recursive->posts) || isset($set_recursive->categories))
2243 - $content .= 'checked="checked"';
2244 - if(isset($set_recursive->posts) || isset($set_recursive->categories))
2245 - $content .= 'disabled=""';
2246 - $content .= 'value="'.$accessgroup['ID'].'" name="accessgroups[]"/>';
2247 - $content .= $accessgroup['groupname'];
2248 - $content .= "</label>";
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'));
2249 153
2250 - $group_info_html = $this->get_usergroup_info_html($accessgroup['ID'], $style);
154 + add_action('bulk_edit_custom_box', array($oUserAccessManager, 'addBulkAction'));
2251 155
2252 - $content .= $group_info_html->link;
2253 -
2254 - if(isset($set_recursive->posts) || isset($set_recursive->categories))
2255 - $content .= '&nbsp;<a class="uam_group_lock_info_link">[LR]</a>';
2256 -
2257 - $content .= $group_info_html->content;
2258 156
2259 - if(isset($set_recursive->posts) || isset($set_recursive->categories))
2260 - {
2261 - $recursive_info = '<ul class="uam_group_lock_info" ';
2262 - if($style != null)
2263 - $recursive_info .= " style='".$style."' ";
2264 - $recursive_info .= '><li class="uam_group_lock_info_head">'.TXT_GROUP_LOCK_INFO.':</li>';
2265 -
2266 - if(isset($set_recursive->posts))
2267 - {
2268 - foreach($set_recursive->posts as $cur_id)
2269 - {
2270 - $cur_post = & get_post($cur_id);
2271 - $recursive_info .= "<li>$cur_post->post_title [$cur_post->post_type]</li>";
2272 - }
2273 - }
2274 -
2275 - if(isset($set_recursive->categories))
2276 - {
2277 - foreach($set_recursive->categories as $cur_id)
2278 - {
2279 - $cur_category = & get_category($cur_id);
2280 - $recursive_info .= "<li>$cur_category->name [".TXT_CATEGORY."]</li>";
2281 - }
2282 - }
2283 - $recursive_info .= "</ul>";
2284 - $content .= $recursive_info;
2285 - }
2286 - $content .= "</p>";
2287 - }
2288 - }
2289 - else
2290 - {
2291 - $content = "<a href='admin.php?page=uam_usergroup'>";
2292 - $content .= TXT_CREATE_GROUP_FIRST;
2293 - $content .= "</a>";
2294 - }
2295 -
2296 - return $content;
2297 - }
2298 - function add_post_column($column_name, $id)
2299 - {
2300 - if( $column_name == 'uam_access' )
2301 - {
2302 - echo $this->get_post_info_html($id);
2303 - }
2304 - }
2305 -
2306 - function edit_post_content($post)
2307 - {
2308 - echo $this->get_post_edit_info_html($post->ID, "padding:0 0 0 36px;");
2309 - }
2310 -
2311 - function save_postdata($post_id)
2312 - {
2313 - global $wpdb;
2314 - if(isset($_POST['accessgroups']))
2315 - $accessgroups = $_POST['accessgroups'];
2316 -
2317 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE post_id = $post_id");
2318 - if(isset($accessgroups))
2319 - {
2320 - foreach($accessgroups as $accessgroup)
2321 - {
2322 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_POST." (post_id,group_id) VALUES(".$post_id.", ".$accessgroup.")");
2323 - }
2324 - }
2325 - }
2326 -
2327 - function save_attachmentdata($post)
2328 - {
2329 - global $wpdb;
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 + }
166 + }
2330 167
2331 - if(isset($post['ID']))
2332 - {
2333 - $post_id = $post['ID'];
2334 -
2335 - if(isset($_POST['accessgroups']))
2336 - $accessgroups = $_POST['accessgroups'];
2337 -
2338 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE post_id = $post_id");
2339 - if(isset($accessgroups))
2340 - {
2341 - foreach($accessgroups as $accessgroup)
2342 - {
2343 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_POST." (post_id,group_id) VALUES(".$post_id.", ".$accessgroup.")");
2344 - }
2345 - }
2346 - }
2347 -
2348 - return $post;
2349 - }
2350 -
2351 - function remove_postdata($post_id)
2352 - {
2353 - global $wpdb;
2354 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE post_id = $post_id");
2355 - }
2356 -
2357 - function add_user_columns_header($defaults)
2358 - {
2359 - $defaults['uam_access'] = __('Access');
2360 - return $defaults;
2361 - }
2362 -
2363 - function add_user_column($column_name, $id)
2364 - {
2365 - global $wpdb;
2366 -
2367 - if( $column_name == 'uam_access' )
2368 - {
2369 - $usergroups = $wpdb->get_results(" SELECT ag.groupname
2370 - FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_USER." agtp
2371 - WHERE agtp.user_id = ".$id."
2372 - AND ag.ID = agtp.group_id
2373 - GROUP BY ag.groupname", ARRAY_A);
2374 -
2375 - if(isset($usergroups))
2376 - {
2377 - $content .= "<ul>";
2378 - foreach($usergroups as $usergroup)
2379 - {
2380 - $content .= "<li>".$usergroup['groupname']."</li>";
2381 - }
2382 - $content .= "</ul>";
2383 - }
2384 - else
2385 - {
2386 - $content = TXT_NO_GROUP;
2387 - }
2388 - return $content;
2389 - }
2390 - }
2391 -
2392 - function show_user_profile()
2393 - {
2394 - global $wpdb, $current_user;
2395 -
2396 - $user_id = $_GET['user_id'];
2397 - $cur_userdata = get_userdata($current_user->ID);
2398 - $cur_edit_userdata = get_userdata($user_id);
2399 -
2400 - if(isset($cur_userdata->{$wpdb->prefix."capabilities"}['administrator']))
2401 - {
2402 - $accessgroups = $wpdb->get_results("SELECT *
2403 - FROM ".DB_ACCESSGROUP."
2404 - ORDER BY groupname", ARRAY_A);
2405 -
2406 - ?>
2407 - <h3><?php echo TXT_GROUPS; ?></h3>
2408 - <table class="form-table">
2409 - <tbody>
2410 - <tr>
2411 - <th>
2412 - <label for="usergroups"><?php echo TXT_SET_UP_USERGROUPS; ?></label>
2413 - </th>
2414 - <td>
2415 - <?php
2416 - if(empty($cur_edit_userdata->{$wpdb->prefix."capabilities"}['administrator']))
2417 - {
2418 - if(isset($accessgroups))
2419 - {
2420 - foreach($accessgroups as $accessgroup)
2421 - {
2422 - $checked = $wpdb->get_results(" SELECT *
2423 - FROM ".DB_ACCESSGROUP_TO_USER."
2424 - WHERE user_id = ".$user_id."
2425 - AND group_id = ".$accessgroup['ID'], ARRAY_A)
2426 - ?>
2427 - <p style="margin:6px 0;">
2428 - <label for="uam_accesssgroup-<?php echo $accessgroup['ID'];?>" class="selectit" >
2429 - <input type="checkbox" id="uam_accesssgroup-<?php echo $accessgroup['ID'];?>" <?php if(isset($checked)){ echo 'checked="checked"'; } ?> value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/>
2430 - <?php echo $accessgroup['groupname']; ?>
2431 - </label>
2432 - <?php
2433 - $group_info_html = $this->get_usergroup_info_html($accessgroup['ID'], "padding: 0 0 0 32px");
2434 -
2435 - echo $group_info_html->link;
2436 - echo $group_info_html->content;
2437 - echo "</p>";
2438 - }
2439 - }
2440 - else
2441 - {
2442 - echo "<a href='admin.php?page=uam_usergroup'>";
2443 - echo TXT_CREATE_GROUP_FIRST;
2444 - echo "</a>";
2445 - }
2446 - }
2447 - else
2448 - {
2449 - echo TXT_ADMIN_HINT;
2450 - }
2451 - ?>
2452 - </td>
2453 - </tr>
2454 - </tbody>
2455 - </table>
2456 - <?php
2457 - }
2458 - }
2459 -
2460 - function show_media_file($meta = '', $post)
2461 - {
2462 - $content = $meta;
2463 - $content .= '</td></tr><tr><th class="label"><label>'.TXT_SET_UP_USERGROUPS.'</label></th><td class="field">';
2464 - $content .= $this->get_post_edit_info_html($post->ID, "padding:0 0 0 38px;top:-12px;");
2465 -
2466 - return $content;
2467 - }
2468 -
2469 - function save_userdata($user_id)
2470 - {
2471 - global $wpdb, $current_user;
2472 -
2473 - $cur_userdata = get_userdata($current_user->ID);
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'));
2474 172
2475 - if(isset($cur_userdata->{$wpdb->prefix."capabilities"}['administrator']))
2476 - {
2477 - $accessgroups = $_POST['accessgroups'];
2478 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE user_id = $user_id");
2479 - if(isset($accessgroups))
2480 - {
2481 - foreach($accessgroups as $accessgroup)
2482 - {
2483 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_USER." (user_id,group_id) VALUES(".$user_id.", ".$accessgroup.")");
2484 - }
2485 - }
2486 - }
2487 - }
2488 -
2489 - function remove_userdata($user_id)
2490 - {
2491 - global $wpdb, $current_user;
2492 -
2493 - $cur_userdata = get_userdata($current_user->ID);
173 + add_filter('manage_posts_columns', array($oUserAccessManager, 'addPostColumnsHeader'));
174 + add_filter('manage_pages_columns', array($oUserAccessManager, 'addPostColumnsHeader'));
2494 175
2495 - if(isset($cur_userdata->{$wpdb->prefix."capabilities"}['administrator']))
2496 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE user_id = $user_id");
2497 - }
2498 -
2499 - function add_category_columns_header($defaults)
2500 - {
2501 - $defaults['uam_access'] = __('Access');
2502 - return $defaults;
2503 - }
2504 -
2505 - function add_category_column($column_name, $id)
2506 - {
2507 - global $wpdb;
2508 -
2509 - if( $column_name == 'uam_access' )
2510 - {
2511 - $usergroups = $wpdb->get_results(" SELECT ag.groupname
2512 - FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_CATEGORY." agtc
2513 - WHERE agtc.category_id = ".$id."
2514 - AND ag.ID = agtc.group_id
2515 - GROUP BY ag.groupname", ARRAY_A);
2516 -
2517 - if(isset($usergroups))
2518 - {
2519 - $content = "<ul>";
2520 - foreach($usergroups as $usergroup)
2521 - {
2522 - $content .= "<li>".$usergroup['groupname']."</li>";
2523 - }
2524 - $content .= "</ul>";
2525 - }
2526 - else
2527 - {
2528 - $content = TXT_NO_GROUP;
2529 - }
2530 - return $content;
2531 - }
2532 - }
2533 -
2534 - function show_cat_edit_form($cat)
2535 - {
2536 - global $wpdb, $current_user;
176 + add_filter('manage_users_columns', array($oUserAccessManager, 'addUserColumnsHeader'), 10);
177 + add_filter('manage_users_custom_column', array($oUserAccessManager, 'addUserColumn'), 10, 3);
2537 178
2538 - if(isset($cat->cat_ID))
2539 - $cat_id = $cat->cat_ID;
179 + add_filter('manage_edit-category_columns', array($oUserAccessManager, 'addCategoryColumnsHeader'));
180 + add_filter('manage_category_custom_column', array($oUserAccessManager, 'addCategoryColumn'), 10, 3);
181 + }
2540 182
2541 - $accessgroups = $wpdb->get_results("SELECT *
2542 - FROM ".DB_ACCESSGROUP."
2543 - ORDER BY groupname", ARRAY_A);
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 + }
2544 188
2545 - if(isset($_GET['action']))
2546 - $action = $_GET['action'];
2547 - else
2548 - $action = null;
2549 -
2550 - if($action == 'edit')
2551 - {
2552 - ?>
2553 - <table class="form-table">
2554 - <tbody>
2555 - <tr>
2556 - <th>
2557 - <label for="description"><?php echo TXT_SET_UP_USERGROUPS; ?></label>
2558 - </th>
2559 - <td>
2560 - <?php
2561 - if(isset($accessgroups))
2562 - {
2563 - $recursive_set = $this->get_usergroups_for_post($cat_id);
2564 -
2565 - foreach($accessgroups as $accessgroup)
2566 - {
2567 - $checked = $wpdb->get_results(" SELECT *
2568 - FROM ".DB_ACCESSGROUP_TO_CATEGORY."
2569 - WHERE category_id = ".$cat_id."
2570 - AND group_id = ".$accessgroup['ID'], ARRAY_A)
2571 -
2572 - //$set_recursive = $recursive_set[$accessgroup['groupname']];
2573 - ?>
2574 - <p style="margin:6px 0;">
2575 - <label for="uam_accesssgroup-<?php echo $accessgroup['ID'];?>" class="selectit" >
2576 - <input type="checkbox" id="uam_accesssgroup-<?php echo $accessgroup['ID'];?>" <?php if(isset($checked)){ echo 'checked="checked"'; } ?> value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/>
2577 - <?php echo $accessgroup['groupname']; ?>
2578 - </label>
2579 - <?php
2580 - $group_info_html = $this->get_usergroup_info_html($accessgroup['ID'], "padding:0 0 0 32px;");
2581 -
2582 - echo $group_info_html->link;
2583 -
2584 - if(isset($set_recursive->posts) || isset($set_recursive->categories))
2585 - echo '&nbsp;<a class="uam_group_lock_info_link">[LR]</a>';
2586 -
2587 - echo $group_info_html->content;
2588 -
2589 - if(isset($set_recursive->posts) || isset($set_recursive->categories))
2590 - {
2591 - $recursive_info = '<ul class="uam_group_lock_info" style="padding:0 0 0 32px;"><li class="uam_group_lock_info_head">'.TXT_GROUP_LOCK_INFO.':</li>';
2592 - if(isset($set_recursive->posts))
2593 - {
2594 - foreach($set_recursive->posts as $cur_id)
2595 - {
2596 - $cur_post = & get_post($cur_id);
2597 - $recursive_info .= "<li>$cur_post->post_title [$cur_post->post_type]</li>";
2598 - }
2599 - }
2600 -
2601 - if(isset($set_recursive->categories))
2602 - {
2603 - foreach($set_recursive->categories as $cur_id)
2604 - {
2605 - $cur_category = & get_category($cur_id);
2606 - $recursive_info .= "<li>$cur_category->name [".TXT_CATEGORY."]</li>";
2607 - }
2608 - }
2609 - $recursive_info .= "</ul>";
2610 - echo $recursive_info;
2611 - }
2612 - echo "</p>";
2613 - }
2614 - }
2615 - else
2616 - {
2617 - echo "<a href='admin.php?page=uam_usergroup'>";
2618 - echo TXT_CREATE_GROUP_FIRST;
2619 - echo "</a>";
2620 - }
2621 - ?>
2622 - </td>
2623 - </tr>
2624 - </tbody>
2625 - </table>
2626 - <style type="text/css">
2627 - .submit {
2628 - display: none;
2629 - position: relative;
2630 - }
2631 - </style>
2632 - <p class="submit" style="display:block;position:relative;">
2633 - <input class="button-primary" type="submit" value="Update Category" name="submit"/>
2634 - </p>
2635 - <?php
2636 - }
2637 - }
2638 -
2639 - function add_styles()
2640 - {
2641 - wp_enqueue_style('UserAccessManager', UAM_URLPATH."css/uma_admin.css", false, '1.0', 'screen' );
2642 - }
2643 -
2644 - function add_scripts()
2645 - {
2646 - wp_enqueue_script('UserAccessManager', UAM_URLPATH .'js/functions.js', array('jquery'), '1.0' );
2647 - }
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);
2648 197
2649 - function save_categorydata($category_id)
2650 - {
2651 - global $wpdb;
2652 -
2653 - if(isset($_POST['accessgroups']))
2654 - $accessgroups = $_POST['accessgroups'];
2655 -
2656 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_CATEGORY." WHERE category_id = $category_id");
2657 - if(isset($accessgroups))
2658 - {
2659 - foreach($accessgroups as $accessgroup)
2660 - {
2661 - $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_CATEGORY." (category_id,group_id) VALUES(".$category_id.", ".$accessgroup.")");
2662 - }
2663 - }
2664 - }
2665 -
2666 - function remove_categorydata($category_id)
2667 - {
2668 - global $wpdb;
2669 -
2670 - $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_CATEGORY." WHERE category_id = $category_id");
2671 - }
2672 -
2673 - function get_access($post_id = null)
2674 - {
2675 - global $wpdb;
2676 -
2677 - if(isset($this->restrictedPost[$post_id]))
2678 - return $this->restrictedPost[$post_id];
2679 -
2680 - $access = null;
2681 - $cur_id = $post_id;
2682 - $cur_post = & get_post($cur_id);
2683 - if(isset($cur_post->ID))
2684 - $cur_categories = get_the_category($cur_post->ID);
2685 -
2686 - $uamOptions = $this->getAdminOptions();
2687 -
2688 - if($this->atAdminPanel)
2689 - $sqlCheckLocation = "ag.write_access != 'all'";
2690 - else
2691 - $sqlCheckLocation = "ag.read_access != 'all'";
2692 -
2693 - $restricted_by_categories = array();
2694 - $restricted_by_posts = array();
2695 -
2696 - //check categories access
2697 - if(isset($cur_categories))
2698 - {
2699 - foreach($cur_categories as $cur_category)
2700 - {
2701 - if($cur_post->post_type == "post" || $cur_post->post_type == "attachment")
2702 - {
2703 - $restricted_access_by_cat = $wpdb->get_results(" SELECT *
2704 - FROM ".DB_ACCESSGROUP_TO_CATEGORY." atc, ".DB_ACCESSGROUP." ag
2705 - WHERE atc.category_id = ".$cur_category->term_id."
2706 - AND atc.group_id = ag.ID
2707 - AND ".$sqlCheckLocation, ARRAY_A);
2708 - if(isset($restricted_access_by_cat))
2709 - $restricted_by_categories[$cur_category->term_id] = $cur_category->term_id;
2710 -
2711 - if($uamOptions['lock_recursive'] == 'true')
2712 - {
2713 - $cur_id = $cur_category->parent;
2714 - while($cur_id != 0)
2715 - {
2716 - $restricted_access_by_cat = $wpdb->get_results(" SELECT *
2717 - FROM ".DB_ACCESSGROUP_TO_CATEGORY." atc, ".DB_ACCESSGROUP." ag
2718 - WHERE atc.category_id = ".$cur_id."
2719 - AND atc.group_id = ag.ID
2720 - AND ".$sqlCheckLocation, ARRAY_A);
2721 -
2722 - if(isset($cur_category->term_id) && isset($restricted_access_by_cat))
2723 - $restricted_by_categories[$cur_category->term_id] = $cur_category->term_id;
2724 -
2725 - if(isset($cur_category->parent))
2726 - {
2727 - $cur_id = $cur_category->parent;
2728 - $cur_category = & get_category($cur_id);
2729 - }
2730 - else
2731 - {
2732 - $cur_id = 0;
2733 - }
2734 - }
2735 - }
2736 - }
2737 - }
2738 - }
2739 -
2740 - //check posts access
2741 - if(isset($cur_post->ID))
2742 - {
2743 - $restricted_access_by_post = $wpdb->get_results(" SELECT *
2744 - FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP." ag
2745 - WHERE atp.post_id = ".$cur_post->ID."
2746 - AND atp.group_id = ag.ID
2747 - AND ".$sqlCheckLocation, ARRAY_A);
2748 - if(isset($restricted_access_by_post))
2749 - $restricted_by_posts[$cur_post->ID] = $cur_post->ID;
2750 -
2751 - if($uamOptions['lock_recursive'] == 'true')
2752 - {
2753 - if(isset($cur_post->post_parent))
2754 - $cur_id = $cur_post->post_parent;
2755 -
2756 - if($cur_id != 0 && isset($cur_id))
2757 - {
2758 - $restricted_access = $this->get_access($cur_id);
198 + // taxonomies
2759 199
2760 - if(isset($restricted_access->restricted_by_categories))
2761 - $restricted_by_categories = array_unique(array_merge($restricted_by_categories, $restricted_access->restricted_by_categories));
2762 -
2763 - if(isset($restricted_access->restricted_by_posts))
2764 - $restricted_by_posts = array_unique(array_merge($restricted_by_posts, $restricted_access->restricted_by_posts));
2765 - }
2766 - }
2767 - elseif($uamOptions['lock_recursive'] == 'false' && $cur_post->post_type == "attachment")
2768 - {
2769 - if(isset($cur_post->post_parent))
2770 - $cur_id = $cur_post->post_parent;
200 + foreach ($aTaxonomies as $sTaxonomy) {
201 + add_action('delete_'.$sTaxonomy, array($oUserAccessManager, 'removeCategoryData'));
202 + }
203 + }
204 +
205 + $oUserAccessManager->noRightsToEditContent();
206 + }
207 +}
2771 208
2772 - if($cur_id != 0 && isset($cur_id))
2773 - {
2774 - $restricted_access = $this->get_access($cur_id);
2775 -
2776 - if(isset($restricted_access->restricted_by_categories))
2777 - $restricted_by_categories = array_unique(array_merge($restricted_by_categories, $restricted_access->restricted_by_categories));
2778 -
2779 - if(isset($restricted_access->restricted_by_posts))
2780 - $restricted_by_posts = array_unique(array_merge($restricted_by_posts, $restricted_access->restricted_by_posts));
2781 - }
2782 - }
2783 - }
2784 -
2785 - if(isset($restricted_by_categories) && count($restricted_by_categories) != 0)
2786 - $access->restricted_by_categories = $restricted_by_categories;
2787 - if(isset($restricted_by_posts) && count($restricted_by_posts) != 0)
2788 - $access->restricted_by_posts = $restricted_by_posts;
2789 -
2790 - if(empty($access))
2791 - $access = -1;
2792 -
2793 - $this->restrictedPost[$post_id] = $access;
2794 -
2795 - return $access;
2796 - }
2797 -
2798 - function check_access($post_id = null)
2799 - {
2800 - global $wpdb, $current_user;
2801 -
2802 - if(isset($this->postAccess[$post_id]))
2803 - return $this->postAccess[$post_id];
2804 -
2805 - $access = $this->get_access($post_id);
2806 - $cur_user_ip = explode(".", $_SERVER['REMOTE_ADDR']);
2807 -
2808 - if(isset($access->restricted_by_posts) || isset($access->restricted_by_categories))
2809 - {
2810 - if(is_user_logged_in())
2811 - {
2812 - $cur_userdata = get_userdata($current_user->ID);
2813 -
2814 - if(empty($cur_userdata->{$wpdb->prefix."capabilities"}['administrator']))
2815 - {
2816 - if(isset($access->restricted_by_categories))
2817 - {
2818 - foreach($access->restricted_by_categories as $cur_cat_id)
2819 - {
2820 - $user_access = $wpdb->get_results(" SELECT *
2821 - FROM ".DB_ACCESSGROUP_TO_CATEGORY." atc, ".DB_ACCESSGROUP_TO_USER." atu
2822 - WHERE atc.category_id = ".$cur_cat_id."
2823 - AND atc.group_id = atu.group_id
2824 - AND atu.user_id = ".$current_user->ID, ARRAY_A);
2825 - if(isset($user_access))
2826 - {
2827 - $this->postAccess[$post_id] = true;
2828 - return true;
2829 - }
2830 -
2831 - $access_roles = $wpdb->get_results("SELECT atr.role_name
2832 - FROM ".DB_ACCESSGROUP_TO_CATEGORY." atc, ".DB_ACCESSGROUP_TO_ROLE." atr
2833 - WHERE atc.category_id = ".$cur_cat_id."
2834 - AND atc.group_id = atr.group_id", ARRAY_A);
2835 -
2836 - if(isset($access_roles))
2837 - {
2838 - foreach($access_roles as $access_role)
2839 - {
2840 - if(isset($cur_userdata->wp_capabilities[$access_role['role_name']]))
2841 - {
2842 - $this->postAccess[$post_id] = true;
2843 - return true;
2844 - }
2845 - }
2846 - }
2847 -
2848 - $db_ip_ranges = $wpdb->get_var("SELECT ag.ip_range
2849 - FROM ".DB_ACCESSGROUP_TO_CATEGORY." atc, ".DB_ACCESSGROUP." ag
2850 - WHERE atc.category_id = ".$cur_cat_id."
2851 - AND atc.group_id = ag.ID", ARRAY_A);
2852 -
2853 - if($this->check_user_ip($cur_user_ip, $db_ip_ranges))
2854 - {
2855 - $this->postAccess[$post_id] = true;
2856 - return true;
2857 - }
2858 - }
2859 - }
2860 -
2861 - if(isset($access->restricted_by_posts))
2862 - {
2863 - foreach($access->restricted_by_posts as $cur_post_id)
2864 - {
2865 - $user_access = $wpdb->get_results(" SELECT *
2866 - FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP_TO_USER." atu
2867 - WHERE atp.post_id = ".$cur_post_id."
2868 - AND atp.group_id = atu.group_id
2869 - AND atu.user_id = ".$current_user->ID, ARRAY_A);
2870 - if(isset($user_access))
2871 - {
2872 - $this->postAccess[$post_id] = true;
2873 - return true;
2874 - }
2875 -
2876 - $access_roles = $wpdb->get_results("SELECT atr.role_name
2877 - FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP_TO_ROLE." atr
2878 - WHERE atp.post_id = ".$cur_post_id."
2879 - AND atp.group_id = atr.group_id", ARRAY_A);
2880 - if(isset($access_roles))
2881 - {
2882 - foreach($access_roles as $access_role)
2883 - {
2884 - if(isset($cur_userdata->wp_capabilities[$access_role['role_name']]))
2885 - {
2886 - $this->postAccess[$post_id] = true;
2887 - return true;
2888 - }
2889 - }
2890 - }
2891 -
2892 - $db_ip_ranges = $wpdb->get_var("SELECT ag.ip_range
2893 - FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP." ag
2894 - WHERE atp.post_id = ".$cur_post_id."
2895 - AND atp.group_id = ag.ID", ARRAY_A);
2896 -
2897 - if($this->check_user_ip($cur_user_ip, $db_ip_ranges))
2898 - {
2899 - $this->postAccess[$post_id] = true;
2900 - return true;
2901 - }
2902 - }
2903 - }
2904 -
2905 - if(empty($user_access))
2906 - {
2907 - $this->postAccess[$post_id] = false;
2908 - return false;
2909 - }
2910 - }
2911 - else
2912 - {
2913 - $this->postAccess[$post_id] = true;
2914 - return true;
2915 - }
2916 - }
2917 - else
2918 - {
2919 - if(isset($access->restricted_by_categories))
2920 - {
2921 - foreach($access->restricted_by_categories as $cur_cat_id)
2922 - {
2923 - $db_ip_ranges = $wpdb->get_var("SELECT ag.ip_range
2924 - FROM ".DB_ACCESSGROUP_TO_CATEGORY." atc, ".DB_ACCESSGROUP." ag
2925 - WHERE atc.category_id = ".$cur_cat_id."
2926 - AND atc.group_id = ag.ID");
2927 -
2928 - if($this->check_user_ip($cur_user_ip, $db_ip_ranges))
2929 - {
2930 - $this->postAccess[$post_id] = true;
2931 - return true;
2932 - }
2933 - }
2934 - }
2935 -
2936 - if(isset($access->restricted_by_posts))
2937 - {
2938 - foreach($access->restricted_by_posts as $cur_post_id)
2939 - {
2940 - $db_ip_ranges = $wpdb->get_var("SELECT ag.ip_range
2941 - FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP." ag
2942 - WHERE atp.post_id = ".$cur_post_id."
2943 - AND atp.group_id = ag.ID");
2944 -
2945 - if($this->check_user_ip($cur_user_ip, $db_ip_ranges))
2946 - {
2947 - $this->postAccess[$post_id] = true;
2948 - return true;
2949 - }
2950 - }
2951 - }
2952 -
2953 - $this->postAccess[$post_id] = false;
2954 - return false;
2955 - }
2956 - }
2957 - else
2958 - {
2959 - $this->postAccess[$post_id] = true;
2960 - return true;
2961 - }
2962 - }
2963 -
2964 - function check_user_ip($cur_user_ip, $db_ip_ranges)
2965 - {
2966 - if(isset($db_ip_ranges))
2967 - {
2968 - $ip_ranges = explode(";", $db_ip_ranges);
2969 -
2970 - if(isset($ip_ranges))
2971 - {
2972 - foreach($ip_ranges as $ip_range)
2973 - {
2974 - $ip_range = explode("-", $ip_range);
2975 -
2976 - $range_begin = explode(".",$ip_range[0]);
2977 -
2978 - if(isset($ip_range[1]))
2979 - $range_end = explode(".",$ip_range[1]);
2980 - else
2981 - $range_end = explode(".",$ip_range[0]);
2982 -
2983 - if( $range_begin[0] <= $cur_user_ip[0] && $cur_user_ip[0] <= $range_end[0] &&
2984 - $range_begin[1] <= $cur_user_ip[1] && $cur_user_ip[1] <= $range_end[1] &&
2985 - $range_begin[2] <= $cur_user_ip[2] && $cur_user_ip[2] <= $range_end[2] &&
2986 - $range_begin[3] <= $cur_user_ip[3] && $cur_user_ip[3] <= $range_end[3])
2987 - {
2988 - return true;
2989 - }
2990 - }
2991 - }
2992 - }
2993 - return false;
2994 - }
2995 -
2996 - function show_post($posts = array())
2997 - {
2998 - $show_posts = null;
2999 - $uamOptions = $this->getAdminOptions();
3000 -
3001 - foreach($posts as $post)
3002 - {
3003 - if( ($uamOptions['hide_post'] == 'true' && $post->post_type == "post") || ($uamOptions['hide_page'] == 'true' && $post->post_type == "page") || $this->atAdminPanel)
3004 - {
3005 - if($this->check_access($post->ID))
3006 - {
3007 - $post->post_title .= $this->admin_output($post->ID);
3008 - $show_posts[] = $post;
3009 - }
3010 - }
3011 - else
3012 - {
3013 - if(!$this->check_access($post->ID))
3014 - {
3015 - if($post->post_type == "post")
3016 - {
3017 - if($uamOptions['hide_post_title'] == 'true')
3018 - $post->post_title = $uamOptions['post_title'];
3019 -
3020 - $post->post_content = $uamOptions['post_content'];
3021 -
3022 - if($uamOptions['allow_comments_locked'] == 'false')
3023 - $post->comment_status = 'close';
3024 - }
3025 - elseif($post->post_type == "page")
3026 - {
3027 - if($uamOptions['hide_page_title'] == 'true')
3028 - $post->post_title = $uamOptions['page_title'];
3029 -
3030 - $post->post_content = $uamOptions['page_content'];
3031 - }
3032 - }
3033 - $post->post_title .= $this->admin_output($post->ID);
3034 - $show_posts[] = $post;
3035 - }
3036 - }
3037 -
3038 - $posts = $show_posts;
3039 -
3040 - return $posts;
3041 - }
3042 -
3043 - function show_comment($comments = array())
3044 - {
3045 - $show_comments = null;
3046 - $uamOptions = $this->getAdminOptions();
3047 -
3048 - foreach($comments as $comment)
3049 - {
3050 - if($uamOptions['hide_post_comment'] == 'true' || $this->atAdminPanel)
3051 - {
3052 - if($this->check_access($comment->comment_post_ID))
3053 - {
3054 - $show_comments[] = $comment;
3055 - }
3056 - }
3057 - else
3058 - {
3059 - if(!$this->check_access($comment->comment_post_ID))
3060 - {
3061 - $comment->comment_content = $uamOptions['post_comment_content'];
3062 - }
3063 - $show_comments[] = $comment;
3064 - }
3065 -
3066 - }
3067 -
3068 - $comments = $show_comments;
3069 -
3070 - return $comments;
3071 - }
3072 -
3073 - function show_page($pages = array())
3074 - {
3075 - $show_pages = null;
3076 - $uamOptions = $this->getAdminOptions();
3077 -
3078 - foreach($pages as $page)
3079 - {
3080 - if($uamOptions['hide_page'] == 'true' || $this->atAdminPanel)
3081 - {
3082 - if($this->check_access($page->ID))
3083 - {
3084 - $page->post_title .= $this->admin_output($page->ID);
3085 - $show_pages[] = $page;
3086 - }
3087 - }
3088 - else
3089 - {
3090 - if(!$this->check_access($page->ID))
3091 - {
3092 - if($uamOptions['hide_page_title'] == 'true')
3093 - $page->post_title = $uamOptions['page_title'];
3094 -
3095 - $page->post_content = $uamOptions['page_content'];
3096 - }
3097 - $page->post_title .= $this->admin_output($page->ID);
3098 - $show_pages[] = $page;
3099 - }
3100 - }
3101 -
3102 - $pages = $show_pages;
3103 -
3104 - return $pages;
3105 - }
3106 -
3107 - function show_category($categories = array())
3108 - {
3109 - global $current_user, $wpdb;
3110 - $cur_userdata = get_userdata($current_user->ID);
3111 -
3112 - if(empty($cur_userdata->{$wpdb->prefix."capabilities"}['administrator']))
3113 - {
3114 - $uamOptions = $this->getAdminOptions();
3115 - if($uamOptions['hide_post'] == 'true' || $uamOptions['hide_page'] == 'true' || $this->atAdminPanel)
3116 - {
3117 - $args = array( 'numberposts' => -1);
3118 - $posts = get_posts($args);
3119 -
3120 - foreach($categories as $category)
3121 - {
3122 - $count = 0;
3123 -
3124 - if(isset($posts))
3125 - {
3126 - foreach($posts as $cur_post)
3127 - {
3128 - $post_cat_ids = array();
3129 - $post_cats = get_the_category($cur_post->ID);
3130 - foreach($post_cats as $post_cat)
3131 - {
3132 - $post_cat_ids[] = $post_cat->term_id;
3133 - }
3134 -
3135 - if(in_array($category->term_id, $post_cat_ids) )
3136 - {
3137 - if( ($uamOptions['hide_post'] == 'true' && $cur_post->post_type == "post") || ($uamOptions['hide_page'] == 'true' && $cur_post->post_type == "page") )
3138 - {
3139 - if($this->check_access($cur_post->ID))
3140 - $count++;
3141 - }
3142 - else
3143 - {
3144 - $count++;
3145 - }
3146 - }
3147 - }
3148 - }
3149 -
3150 - if($count != 0 || $uamOptions['hide_empty_categories'] == 'false')
3151 - {
3152 - $category->count = $count;
3153 - $cur_show_categories[$category->term_id] = $category;
3154 - }
3155 - elseif($category->taxonomy == "link_category" || $category->taxonomy == "post_tag")
3156 - {
3157 - $show_categories[] = $category;
3158 - }
3159 - elseif($count == 0)
3160 - {
3161 - $empty_categories[$category->term_id] = $category;
3162 - }
3163 - }
3164 -
3165 - if($uamOptions['hide_empty_categories'] == 'true')
3166 - {
3167 - if(isset($cur_show_categories))
3168 - {
3169 - foreach($cur_show_categories as $cur_show_category)
3170 - {
3171 - $show_categories[$cur_show_category->term_id] = $cur_show_category;
3172 -
3173 - $cur_cat = $cur_show_category;
3174 - while($cur_cat->parent != 0 && isset($empty_categories))
3175 - {
3176 - if(empty($show_categories[$cur_cat->parent]))
3177 - $show_categories[$cur_cat->parent] = $empty_categories[$cur_cat->parent];
3178 -
3179 - $cur_id = $cur_cat->parent;
3180 - $cur_cat = & get_category($cur_id);
3181 - }
3182 - }
3183 - }
3184 - }
3185 -
3186 - if(isset($show_categories))
3187 - $categories = $show_categories;
3188 - else
3189 - $categories = null;
3190 - }
3191 - }
3192 -
3193 - return $categories;
3194 - }
3195 -
3196 - function show_title($title, $post = null)
3197 - {
3198 - $uamOptions = $this->getAdminOptions();
3199 -
3200 - if(isset($post))
3201 - $post_id = $post->ID;
3202 - else
3203 - $post_id = null;
3204 -
3205 - if(!$this->check_access($post_id) && $post != null)
3206 - {
3207 - if($post->post_type == "post")
3208 - $title = $uamOptions['post_title'];
3209 - elseif($post->post_type == "page")
3210 - $title = $uamOptions['page_title'];
3211 - }
3212 - return $title;
3213 - }
3214 -
3215 - function show_next_previous_post($sql)
3216 - {
3217 - $uamOptions = $this->getAdminOptions();
3218 -
3219 - $posts = get_posts();
3220 - if(isset($posts))
3221 - {
3222 - foreach($posts as $post)
3223 - {
3224 - if(!$this->check_access($post->ID))
3225 - $excluded_posts[] = $post->ID;
3226 - }
3227 - if(isset($excluded_posts))
3228 - {
3229 - $excluded_posts_str = implode(",", $excluded_posts);
3230 - $sql .= "AND ID NOT IN($excluded_posts_str)";
3231 - }
3232 - }
3233 -
3234 - return $sql;
3235 - }
3236 -
3237 - function admin_output($post_id)
3238 - {
3239 - global $wpdb;
3240 - if(!$this->atAdminPanel)
3241 - {
3242 - $uamOptions = $this->getAdminOptions();
3243 -
3244 - if($uamOptions['blog_admin_hint'] == 'true')
3245 - {
3246 - global $current_user;
3247 - $cur_userdata = get_userdata($current_user->ID);
3248 -
3249 - $output = "";
3250 -
3251 - $access = $this->get_access($post_id);
3252 - if(isset($cur_userdata->{$wpdb->prefix."capabilities"}['administrator']) && (isset($access->restricted_by_posts) || isset($access->restricted_by_categories)))
3253 - {
3254 - $output = "&nbsp;".$uamOptions['blog_admin_hint_text'];
3255 - }
3256 - return $output;
3257 - }
3258 - }
3259 - return null;
3260 - }
3261 -
3262 - function redirect_user()
3263 - {
3264 - global $wp_query;
3265 -
3266 - $uamOptions = $this->getAdminOptions();
3267 -
3268 - if(isset($_GET['getfile']))
3269 - $cur_file_id = $_GET['getfile'];
3270 -
3271 - if( $uamOptions['redirect'] != 'false' && ( ( !$this->check_access() && !$this->atAdminPanel && empty($cur_file_id) ) ||
3272 - ( !$this->check_access($cur_file_id) && !wp_attachment_is_image($cur_file_id) && isset($cur_file_id) )) )
3273 - {
3274 - $cur_id = null;
3275 - $cur_post = & get_post($cur_id);
3276 -
3277 - if($uamOptions['redirect'] == 'blog')
3278 - $url = get_option('siteurl');
3279 - elseif($uamOptions['redirect'] == 'custom_page')
3280 - {
3281 - $post_to_go = & get_post($uamOptions['redirect_custom_page']);
3282 - $url = $post_to_go->guid;
3283 - }
3284 - elseif( $uamOptions['redirect'] == 'custom_url')
3285 - $url = $uamOptions['redirect_custom_url'];
3286 -
3287 - $cur_posts = $wp_query->get_posts();
3288 - if(isset($cur_posts))
3289 - {
3290 - foreach($cur_posts as $cur_post)
3291 - {
3292 - if($this->check_access($cur_post->ID))
3293 - {
3294 - $post_to_show = true;
3295 - break;
3296 - }
3297 - }
3298 - }
3299 -
3300 - if($url != "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"] && empty($post_to_show))
3301 - {
3302 - header("Location: $url");
3303 - exit;
3304 - }
3305 - }
3306 - elseif(isset($_GET['getfile']))
3307 - {
3308 - $cur_id = $_GET['getfile'];
3309 - $cur_post = & get_post($cur_id);
3310 -
3311 - if($cur_post->post_type == 'attachment' && $this->check_access($cur_post->ID))
3312 - {
3313 - $cur_url = explode("?", "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
3314 - $file = str_replace($cur_url[0], "", $cur_post->guid);
3315 - $filename = basename($file);
3316 -
3317 - if(file_exists($file))
3318 - {
3319 - $len = filesize($file);
3320 - header('content-type: '.$cur_post->post_mime_type);
3321 - header('content-length: '.$len);
3322 -
3323 - if(wp_attachment_is_image($cur_id))
3324 - {
3325 - readfile($file);
3326 - exit;
3327 - }
3328 - else
3329 - {
3330 - header('content-disposition: attachment; filename='.basename($file));
3331 - if($uamOptions['download_type'] == 'fopen')
3332 - {
3333 - $fp=fopen($file, 'rb');
3334 -
3335 - while ( ! feof($fp) )
3336 - {
3337 - set_time_limit(30);
3338 - $buffer = fread($fp, 1024);
3339 - echo $buffer;
3340 - }
3341 - exit;
3342 - }
3343 - else
3344 - {
3345 - readfile($file);
3346 - exit;
3347 - }
3348 - }
3349 - }
3350 - else
3351 - {
3352 - echo 'Error: File not found';
3353 - }
3354 - }
3355 - elseif(wp_attachment_is_image($cur_id))
3356 - {
3357 - $cur_url = explode("?", "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
3358 - $file = str_replace($cur_url[0], "", UAM_URLPATH .'gfx/no_access_pic.png');
3359 - $filename = basename($file);
3360 -
3361 - if(file_exists($file))
3362 - {
3363 - $len = filesize($file);
3364 - header('content-type: '.$cur_post->post_mime_type);
3365 - header('content-length: '.$len);
3366 -
3367 - readfile($file);
3368 - exit;
3369 - }
3370 - else
3371 - {
3372 - echo 'Error: File not found';
3373 - }
3374 - }
3375 - }
3376 - }
3377 -
3378 - function get_file($URL, $ID)
3379 - {
3380 - $uamOptions = $this->getAdminOptions();
3381 -
3382 - if($uamOptions['lock_file'] == 'true')
3383 - {
3384 - $cur_id = $ID;
3385 - $cur_post = & get_post($cur_id);
3386 - $cur_parent_id = $cur_post->post_parent;
3387 - $cur_parent = & get_post($cur_parent_id);
3388 -
3389 - $type = explode("/", $cur_post->post_mime_type);
3390 - $type = $type[1];
3391 -
3392 - $file_types = $uamOptions['locked_file_types'];
3393 - $file_types = explode(",", $file_types);
3394 -
3395 - if(in_array($type, $file_types) || $uamOptions['lock_file_types'] == 'all')
3396 - {
3397 - $cur_guid = get_option('siteurl');
3398 -
3399 - $URL = $cur_guid.'?getfile='.$cur_post->ID;
3400 - }
3401 - }
3402 - return $URL;
3403 - }
3404 - }
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', 'read', '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 + }
3405 286 }
3406 287
3407 -if(class_exists("UserAccessManager"))
3408 -{
3409 - $userAccessManager = new UserAccessManager();
288 +if (!function_exists("userAccessManagerUninstall")) {
289 + function userAccessManagerUninstall() {
290 + $oUserAccessManager = new UserAccessManager();
291 + $oUserAccessManager->uninstall();
292 + }
3410 293 }
3411 294
3412 -//Initialize the admin panel
3413 -if(!function_exists("UserAccessManager_AP")) {
3414 - function UserAccessManager_AP()
3415 - {
3416 - global $userAccessManager, $wp_version;
3417 -
3418 - $userAccessManager->atAdminPanel = true;
3419 -
3420 - if (!isset($userAccessManager))
3421 - {
3422 - return;
3423 - }
3424 - if (function_exists('add_menu_page'))
3425 - {
3426 - add_menu_page('User Access Manager', 'Access Manager', 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage'), UAM_URLPATH."/gfx/icon.png");
3427 - }
3428 - if (function_exists('add_submenu_page'))
3429 - {
3430 - add_submenu_page('uam_usergroup', TXT_MANAGE_GROUP, TXT_MANAGE_GROUP, 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage'));
3431 - add_submenu_page('uam_usergroup', TXT_SETTINGS, TXT_SETTINGS, 9, 'uam_settings', array(&$userAccessManager, 'printAdminPage'));
3432 - }
3433 - if( function_exists( 'add_meta_box' ))
3434 - {
3435 - add_meta_box( 'uma_post_access', 'Access', array(&$userAccessManager, 'edit_post_content'), 'post', 'side' );
3436 - add_meta_box( 'uma_post_access', 'Access', array(&$userAccessManager, 'edit_post_content'), 'page', 'side' );
3437 - }
3438 -
3439 - //Admin actions
3440 -
3441 - $userAccessManager->update();
3442 -
3443 - add_action('manage_posts_custom_column', array(&$userAccessManager, 'add_post_column'), 10, 2);
3444 - add_action('manage_pages_custom_column', array(&$userAccessManager, 'add_post_column'), 10, 2);
3445 - add_action('manage_media_custom_column', array(&$userAccessManager, 'add_post_column'), 10, 2);
3446 - add_action('save_post', array(&$userAccessManager, 'save_postdata'));
3447 - add_action('add_attachment', array(&$userAccessManager, 'save_postdata'));
3448 - add_action('attachment_fields_to_save', array(&$userAccessManager, 'save_attachmentdata'));
3449 - add_action('delete_post', array(&$userAccessManager, 'remove_postdata'));
3450 - add_action('delete_attachment', array(&$userAccessManager, 'remove_postdata'));
3451 -
3452 - add_action('edit_user_profile', array(&$userAccessManager, 'show_user_profile'));
3453 - add_action('profile_update', array(&$userAccessManager, 'save_userdata'));
3454 - add_action('delete_user', array(&$userAccessManager, 'remove_userdata'));
3455 -
3456 - add_action('edit_category_form', array(&$userAccessManager, 'show_cat_edit_form'));
3457 - add_action('edit_category', array(&$userAccessManager, 'save_categorydata'));
3458 - add_action('delete_category', array(&$userAccessManager, 'remove_categorydata'));
3459 -
3460 - add_action('wp_print_scripts', array(&$userAccessManager, 'add_scripts') );
3461 - add_action('wp_print_styles', array(&$userAccessManager, 'add_styles') );
3462 -
3463 -
3464 - //Admin filters
3465 - add_filter('manage_posts_columns', array(&$userAccessManager, 'add_post_columns_header'));
3466 - add_filter('manage_pages_columns', array(&$userAccessManager, 'add_post_columns_header'));
3467 -
3468 - $uamOptions = $userAccessManager->getAdminOptions();
3469 -
3470 - if($uamOptions['lock_file'] == 'true')
3471 - {
3472 - add_action('media_meta', array(&$userAccessManager, 'show_media_file'), 10 , 2);
3473 - add_filter('manage_media_columns', array(&$userAccessManager, 'add_post_columns_header'));
3474 - }
3475 -
3476 - if($wp_version >= 2.8 || $uamOptions['core_mod'] == 'true')
3477 - {
3478 - add_filter('manage_users_columns', array(&$userAccessManager, 'add_user_columns_header'), 10);
3479 - add_filter('manage_users_custom_column', array(&$userAccessManager, 'add_user_column'), 10, 2);
3480 - add_filter('manage_categories_columns', array(&$userAccessManager, 'add_category_columns_header'));
3481 - add_filter('manage_categories_custom_column', array(&$userAccessManager, 'add_category_column'), 10, 2);
3482 - }
3483 - }
3484 -}
295 +if (isset($oUserAccessManager)) {
296 + //install
297 + if (function_exists('register_activation_hook')) {
298 + register_activation_hook(__FILE__, array($oUserAccessManager, 'install'));
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 + }
3485 320
3486 -//Actions and Filters
3487 -if(isset($userAccessManager))
3488 -{
3489 - add_action('init', array(&$userAccessManager, 'init'));
3490 - $uamOptions = $userAccessManager->getAdminOptions();
3491 -
3492 - //install
3493 - if(function_exists('register_activation_hook'))
3494 - register_activation_hook(__FILE__, array(&$userAccessManager, 'install'));
3495 -
3496 - if(function_exists('register_uninstall_hook'))
3497 - register_uninstall_hook(__FILE__, array(&$userAccessManager, 'uninstall'));
3498 - elseif(function_exists('register_deactivation_hook'))
3499 - register_deactivation_hook(__FILE__, array(&$userAccessManager, 'uninstall'));
3500 -
3501 - if(function_exists('register_deactivation_hook'))
3502 - register_deactivation_hook(__FILE__, array(&$userAccessManager, 'deactivate'));
3503 -
3504 - //Actions
3505 - add_action('admin_menu', 'UserAccessManager_AP');
3506 -
3507 - if($uamOptions['redirect'] != 'false' || isset($_GET['getfile']))
3508 - add_action('template_redirect', array(&$userAccessManager, 'redirect_user'));
3509 -
3510 - //Filters
3511 - add_filter('wp_get_attachment_url', array(&$userAccessManager, 'get_file'), 10, 2);
3512 - add_filter('the_posts', array(&$userAccessManager, 'show_post'));
3513 - add_filter('comments_array', array(&$userAccessManager, 'show_comment'));
3514 - add_filter('get_pages', array(&$userAccessManager, 'show_page'));
3515 - add_filter('get_terms', array(&$userAccessManager, 'show_category'));
3516 - add_filter('get_next_post_where', array(&$userAccessManager, 'show_next_previous_post'));
3517 - add_filter('get_previous_post_where', array(&$userAccessManager, 'show_next_previous_post'));
3518 - add_filter('get_previous_post_where', array(&$userAccessManager, 'show_next_previous_post'));
3519 - add_filter('the_title', array(&$userAccessManager, 'show_title'), 10, 2);
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 + }
3520 347 }
3521 348
3522 -?>
349 +//Add the cli interface to the known commands
350 +if (defined('WP_CLI') && WP_CLI) {
351 + include __DIR__.'/includes/wp-cli.php';
352 +}