PluginProbe
User Access Manager / 0.9
User Access Manager v0.9
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
user-access-manager / user-access-manager.php

user-access-manager.php in User Access Manager 0.9, at user-access-manager.php

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