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