PluginProbe
User Access Manager / 0.6.2
User Access Manager v0.6.2
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / user-access-manager.php

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

1,337 lines 45.2 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.62
7 Author: Alexander Schneider
8 Description: Manage the access to your posts and pages. <strong>Note:</strong> <em>If you activate the plugin your upload dir will protect by a '.htaccess' with a random password and all old downloads insert in a previous post/page will not work anymore. You have to update your posts/pages. If you use already a '.htaccess' file to protect your files the plugin will not overwrite the '.htaccess'.</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 */
27
28 //DB
29 global $wpdb;
30 define(DB_ACCESSGROUP, $wpdb->prefix.'uam_accessgroups');
31 define(DB_ACCESSGROUP_TO_POST, $wpdb->prefix.'uam_accessgroup_to_post');
32 define(DB_ACCESSGROUP_TO_USER, $wpdb->prefix.'uam_accessgroup_to_user');
33
34 //Lang
35 define(TXT_FULL_ACCESS, 'Full access');
36 define(TXT_FULL_ACCESS_ADMIN, 'Full access (Administrator)');
37 define(TXT_NO_GROUP, 'No group');
38 define(TXT_SET_ACCESS, 'Set access');
39 define(TXT_UPDATE_SETTINGS, 'Settings updated.');
40 define(TXT_GROUP_ADDED, 'Group was added successfully.');
41 define(TXT_RESET_POST,'Post(s) was reset successfully.');
42 define(TXT_RESET_PAGE,'Page(s) was reset successfully.');
43 define(TXT_RESET_USER,'User(s) was reset successfully.');
44 define(TXT_ACCESS_CHANGED,'Access was changed successfully.');
45 define(TXT_DEL_GROUP, 'Group(s) was deleted successfully.');
46 define(TXT_MANAGE_POST, 'Manage post access');
47 define(TXT_MANAGE_PAGE, 'Manage page access');
48 define(TXT_MANAGE_USER, 'Manage user access');
49 define(TXT_RESET_ACCESS, 'Reset access');
50 define(TXT_DATE, 'Date');
51 define(TXT_TITLE, 'Title');
52 define(TXT_GROUP_ACCESS, 'Group access');
53 define(TXT_FULL_ACCESS, 'Full access');
54 define(TXT_USERNAME, 'Username');
55 define(TXT_NAME, 'Name');
56 define(TXT_MAIL, 'E-mail');
57 define(TXT_ACCESS, 'Access');
58 define(TXT_MANAGE_USER_NOTE, '<strong>Note:</strong> An administrator has allways access to all posts/pages.');
59 define(TXT_DESCRIPTION, 'Description');
60 define(TXT_POSTS, 'Posts');
61 define(TXT_PAGES, 'Pages');
62 define(TXT_USERS, 'Users');
63 define(TXT_DELETE, 'Delete');
64 define(TXT_MANAGE_GROUP, 'Manage user access groups');
65 define(TXT_ADD_GROUP, 'Add access group');
66 define(TXT_GROUP_NAME, 'Access group name');
67 define(TXT_GROUP_NAME_DESC, 'The name is used to identify the access user group.');
68 define(TXT_GROUP_DESC, 'Access group description');
69 define(TXT_GROUP_DESC_DESC, 'The description of the group.');
70 define(TXT_SETTINGS, 'Settings');
71 define(TXT_TITLE_STR, 'Displayed text as title if user has no access');
72 define(TXT_DISPLAY_TITLE, 'Display titel if user has no access');
73 define(TXT_DISPLAY_TITLE_DESC, 'Selecting "No" will show the text which is defined at "'.TXT_TITLE_STR.'"');
74 define(TXT_DISPLAY_CONTENT, 'Content displayed if user has no access');
75 define(TXT_HIDE_POST, 'Hide complete posts/pages');
76 define(TXT_HIDE_POST_DESC, 'Selecting "Yes" will hide posts/pages if the user has no access.');
77 define(TXT_HIDE_PAGE_NAVI, 'Hide pages in Navigation');
78 define(TXT_HIDE_PAGE_NAVI_DESC, 'Selecting "Yes" will hide pages in the navigation if the user has no access.');
79 define(TXT_REDIRECT, 'Redirect if user has no access');
80 define(TXT_REDIRECT_DESC, 'Setup what happen if a user visit a post/page with no access.');
81 define(TXT_REDIRECT_TO_BOLG, 'To blog startpage');
82 define(TXT_REDIRECT_TO_PAGE, 'Custom page: ');
83 define(TXT_REDIRECT_TO_URL, 'Custom URL: ');
84 define(TXT_LOCK_RECURSIVE, 'Lock recursive');
85 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.');
86 define(TXT_DOWNLOAD_TYPE, 'Download type');
87 define(TXT_DOWNLOAD_TYPE_DESC, 'Selecting the type for downloading. <strong>Note:</strong> For using fopen you need "safe_mode = off".');
88 define(TXT_NORMAL, 'Normal');
89 define(TXT_FOPEN, 'fopen');
90 define(TXT_UPDATE_SETTING, 'Update settings');
91 define(TXT_UPDATE_GROUP, 'Update group');
92 define(TXT_YES, 'Yes');
93 define(TXT_NO, 'No');
94 define(TXT_ADD, 'Add');
95 define(TXT_SET_POST_ACCESS, 'Set post access');
96 define(TXT_SET_PAGE_ACCESS, 'Set page access');
97 define(TXT_GROUPS, 'Access Groups');
98 define(TXT_CREATE_GROUP_FIRST, 'Please create a access group first.');
99 define(TXT_SET_USER_ACCESS, 'Set user access');
100
101
102 if (!class_exists("UserAccessManager"))
103 {
104 class UserAccessManager
105 {
106 var $adminOptionsName = "uamAdminOptions";
107
108 function UserAccessManager()
109 { //constructor
110
111 }
112
113 function init()
114 {
115 $this->getAdminOptions();
116 }
117
118 function install()
119 {
120 // Make .htaccess file to protect data
121
122 // get url
123 $wud = wp_upload_dir();
124 $url = $DOCUMENT_ROOT.$wud['basedir']."/";
125
126 if(!file_exists($url.".htaccess"))
127 {
128 $areaname = "WP-Files";
129 $user = "admin";
130
131
132 # create password
133 $array = array();
134
135 $length = 10;
136 $capitals = true;
137
138 if($length < 8)
139 $length = mt_rand(8,20);
140
141 # numbers
142 for($i=48;$i<58;$i++)
143 $array[] = chr($i);
144
145 # small
146 for($i=97;$i<122;$i++)
147 $array[] = chr($i);
148
149 # capitals
150 if($capitals)
151 for($i=65;$i<90;$i++)
152 $array[] = chr($i);
153
154 # specialchar:
155 if($specialSigns)
156 {
157 for($i=33;$i<47;$i++)
158 $array[] = chr($i);
159 for($i=59;$i<64;$i++)
160 $array[] = chr($i);
161 for($i=91;$i<96;$i++)
162 $array[] = chr($i);
163 for($i=123;$i<126;$i++)
164 $array[] = chr($i);
165 }
166
167 mt_srand((double)microtime()*1000000);
168 $password = '';
169
170 for ($i=1; $i<=$length; $i++)
171 {
172 $rnd = mt_rand( 0, count($array)-1 );
173 $password .= $array[$rnd];
174 }
175
176 // make .htaccess and .htpasswd
177 $htaccess_txt = "AuthType Basic"."\n";
178 $htaccess_txt .= "AuthName \"".$areaname."\""."\n";
179 $htaccess_txt .= "AuthUserFile ".$url.".htpasswd"."\n";
180 $htaccess_txt .= "require valid-user"."\n";
181 $htpasswd_txt .= "$user:".md5($passwort)."\n";
182
183 // save files
184 $htaccess= fopen($url.".htaccess", "w");
185 $htpasswd= fopen($url.".htpasswd", "w");
186 fputs($htaccess, $htaccess_txt);
187 fputs($htpasswd, $htpasswd_txt);
188 fclose($htaccess);
189 fclose($htpasswd);
190 }
191
192 global $wpdb;
193 $uam_db_version = "1.0";
194 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
195
196 $charset_collate = '';
197
198 if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
199 {
200 if ( ! empty($wpdb->charset) )
201 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
202 if ( ! empty($wpdb->collate) )
203 $charset_collate .= " COLLATE $wpdb->collate";
204 }
205
206 if($wpdb->get_var("show tables like '".DB_ACCESSGROUP."'") != DB_ACCESSGROUP)
207 {
208 $sql = "CREATE TABLE " . DB_ACCESSGROUP . " (
209 ID int(11) NOT NULL auto_increment,
210 groupname tinytext NOT NULL,
211 groupdesc text NOT NULL,
212 PRIMARY KEY (ID)
213 ) $charset_collate;";
214
215 dbDelta($sql);
216 }
217
218 if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_POST."'") != DB_ACCESSGROUP_TO_POST)
219 {
220 $sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_POST . " (
221 post_id int(11) NOT NULL,
222 group_id int(11) NOT NULL,
223 PRIMARY KEY (post_id,group_id)
224 ) $charset_collate;";
225
226 dbDelta($sql);
227 }
228
229 if($wpdb->get_var("show tables like '".DB_ACCESSGROUP_TO_USER."'") != DB_ACCESSGROUP_TO_USER)
230 {
231 $sql = "CREATE TABLE " . DB_ACCESSGROUP_TO_USER . " (
232 user_id int(11) NOT NULL,
233 group_id int(11) NOT NULL,
234 PRIMARY KEY (user_id,group_id)
235 ) $charset_collate;";
236
237 dbDelta($sql);
238 }
239
240 add_option("uam_db_version", $uam_db_version);
241 }
242
243 function uninstall()
244 {
245 global $wpdb;
246 $wpdb->query("DROP TABLE ".DB_ACCESSGROUP.", ".DB_ACCESSGROUP_TO_POST.", ".DB_ACCESSGROUP_TO_USER);
247 }
248
249 //Returns an array of admin options
250 function getAdminOptions()
251 {
252 $uamAdminOptions = array( 'hide_title' => 'false',
253 'post_title' => 'No rights!',
254 'post_content' => 'Sorry no rights!',
255 'hide_post' => 'false',
256 'hide_page' => 'false',
257 'redirect' => 'false',
258 'uam_redirect_custom_page' => '',
259 'uam_redirect_custom_url' => '',
260 'lock_recursive' => 'true',
261 'download_type' => 'fopen');
262
263 $uamOptions = get_option($this->adminOptionsName);
264 if (!empty($uamOptions)) {
265 foreach ($uamOptions as $key => $option)
266 $uamAdminOptions[$key] = $option;
267 }
268 update_option($this->adminOptionsName, $uamAdminOptions);
269 return $uamAdminOptions;
270 }
271
272 //Prints out the admin page
273 function printAdminPage()
274 {
275 global $wpdb;
276 $uamOptions = $this->getAdminOptions();
277
278 if (isset($_POST['update_uam_settings']))
279 {
280 if (isset($_POST['uam_hide_title']))
281 {
282 $uamOptions['hide_title'] = $_POST['uam_hide_title'];
283 }
284 if (isset($_POST['uam_post_title']))
285 {
286 $uamOptions['post_title'] = $_POST['uam_post_title'];
287 }
288 if (isset($_POST['uam_post_content']))
289 {
290 $uamOptions['post_content'] = $_POST['uam_post_content'];
291 }
292 if (isset($_POST['uam_hide_post']))
293 {
294 $uamOptions['hide_post'] = $_POST['uam_hide_post'];
295 }
296 if (isset($_POST['uam_hide_page']))
297 {
298 $uamOptions['hide_page'] = $_POST['uam_hide_page'];
299 }
300 if (isset($_POST['uam_redirect']))
301 {
302 $uamOptions['redirect'] = $_POST['uam_redirect'];
303 }
304 if (isset($_POST['uam_redirect_custom_page']))
305 {
306 $uamOptions['redirect_custom_page'] = $_POST['uam_redirect_custom_page'];
307 }
308 if (isset($_POST['uam_redirect_custom_url']))
309 {
310 $uamOptions['redirect_custom_url'] = $_POST['uam_redirect_custom_url'];
311 }
312 if (isset($_POST['uam_lock_recursive']))
313 {
314 $uamOptions['lock_recursive'] = $_POST['uam_lock_recursive'];
315 }
316 if (isset($_POST['uam_download_type']))
317 {
318 $uamOptions['download_type'] = $_POST['uam_download_type'];
319 }
320 update_option($this->adminOptionsName, $uamOptions);
321 ?>
322 <div class="updated"><p><strong><?php _e(TXT_UPDATE_SETTINGS, "UserAccessManager");?></strong></p></div>
323 <?php
324 }
325
326 $cur_admin_page = $_GET['page'];
327 $action = $_GET['action'];
328
329 if($_POST['action'] == 'addgroup')
330 {
331 $wpdb->query("INSERT INTO ".DB_ACCESSGROUP." (ID, groupname, groupdesc) VALUES(NULL, '".$_POST['access_group_name']."', '".$_POST['access_group_description']."')");
332 ?>
333 <div class="updated"><p><strong><?php _e(TXT_GROUP_ADDED, "UserAccessManager");?></strong></p></div>
334 <?php
335 }
336
337 if($_POST['action'] == 'delgroup')
338 {
339 $del_ids = $_POST['delete'];
340 if($del_ids)
341 {
342 foreach($del_ids as $del_id)
343 {
344 $wpdb->query("DELETE FROM ".DB_ACCESSGROUP." WHERE ID = $del_id LIMIT 1");
345 $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE group_id = $del_id LIMIT 1");
346 $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE group_id = $del_id LIMIT 1");
347 }
348 ?>
349 <div class="updated"><p><strong><?php _e(TXT_DEL_GROUP, "UserAccessManager");?></strong></p></div>
350 <?php
351 }
352 }
353
354 if($_POST['action'] == 'resetposts')
355 {
356 $reset_ids = $_POST['reset'];
357 if($reset_ids)
358 {
359 foreach($reset_ids as $reset_id)
360 {
361 $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE post_id = $reset_id");
362 }
363 if($cur_admin_page == 'uam_posts')
364 {
365 ?>
366 <div class="updated"><p><strong><?php _e(TXT_RESET_POST, "UserAccessManager");?></strong></p></div>
367 <?php
368 }
369 elseif($cur_admin_page == 'uam_pages')
370 {
371 ?>
372 <div class="updated"><p><strong><?php _e(TXT_RESET_PAGE, "UserAccessManager");?></strong></p></div>
373 <?php
374 }
375 }
376 }
377
378 if($_POST['action'] == 'resetusers')
379 {
380 $reset_ids = $_POST['reset'];
381 if($reset_ids)
382 {
383 foreach($reset_ids as $reset_id)
384 {
385 $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE user_id = $reset_id");
386 }
387 ?>
388 <div class="updated"><p><strong><?php _e(TXT_RESET_USER, "UserAccessManager");?></strong></p></div>
389 <?php
390 }
391 }
392
393 if($_POST['action'] == 'addgroup_to_post')
394 {
395 $accessgroups = $_POST['accessgroups'];
396 $post_id = $_POST['post_id'];
397 $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE post_id = $post_id");
398 if($accessgroups)
399 {
400 foreach($accessgroups as $accessgroup)
401 {
402 $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_POST." (post_id,group_id) VALUES(".$post_id.", ".$accessgroup.")");
403 }
404 }
405 ?>
406 <div class="updated"><p><strong><?php _e(TXT_ACCESS_CHANGED, "UserAccessManager");?></strong></p></div>
407 <?php
408 }
409
410 if($_POST['action'] == 'addgroup_to_user')
411 {
412 $accessgroups = $_POST['accessgroups'];
413 $user_id = $_POST['user_id'];
414 $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_USER." WHERE user_id = $user_id");
415 if($accessgroups)
416 {
417 foreach($accessgroups as $accessgroup)
418 {
419 $wpdb->query("INSERT INTO ".DB_ACCESSGROUP_TO_USER." (user_id, group_id) VALUES(".$user_id.", ".$accessgroup.")");
420 }
421 }
422 ?>
423 <div class="updated"><p><strong><?php _e(TXT_ACCESS_CHANGED, "UserAccessManager");?></strong></p></div>
424 <?php
425 }
426
427 if($_POST['action'] == 'update_group')
428 {
429 $wpdb->query(" UPDATE ".DB_ACCESSGROUP."
430 SET groupname = '".$_POST['access_group_name']."', groupdesc = '".$_POST['access_group_description']."'
431 WHERE ID = ".$_POST['access_group_id']);
432 ?>
433 <div class="updated"><p><strong><?php _e("Access group edit successfully.", "UserAccessManager");?></strong></p></div>
434 <?php
435 }
436
437 if(($cur_admin_page == 'uam_posts' || $cur_admin_page == 'uam_pages') AND !$action)
438 {
439 switch ($cur_admin_page)
440 {
441 case "uam_posts" :
442 $posts = get_posts();
443 break;
444 case "uam_pages" :
445 $posts = get_pages('sort_column=menu_order');
446 break;
447 }
448
449 ?>
450 <div class=wrap>
451 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
452 <input type="hidden" value="resetposts" name="action"/>
453 <?php
454 if($cur_admin_page == 'uam_posts')
455 {
456 ?>
457 <h2><?php _e(TXT_MANAGE_POST, "UserAccessManager"); ?></h2>
458 <?php
459 }
460 elseif($cur_admin_page == 'uam_pages')
461 {
462 ?>
463 <h2><?php _e(TXT_MANAGE_PAGE, "UserAccessManager"); ?></h2>
464 <?php
465 }
466 ?>
467 <div class="tablenav">
468 <div class="alignleft">
469 <input type="submit" class="button-secondary delete" name="resetit" value="<?php _e(TXT_RESET_ACCESS, "UserAccessManager"); ?>"/>
470 </div>
471 <br class="clear"/>
472 </div>
473 <br class="clear"/>
474 <table class="widefat">
475 <thead>
476 <tr class="thead">
477 <th scope="col"></th>
478 <th scope="col"><?php _e(TXT_DATE, "UserAccessManager"); ?></th>
479 <th scope="col"><?php _e(TXT_TITLE, "UserAccessManager"); ?></th>
480 <th scope="col"><?php _e(TXT_GROUP_ACCESS, "UserAccessManager"); ?></th>
481 </tr>
482 </thead>
483 <tbody>
484 <?php
485 if($posts)
486 {
487 foreach($posts as $post)
488 {
489 $deepness = 0;
490 if($post->post_parent != 0)
491 {
492 $cur_post = $post;
493 $cur_id = $post->ID;
494 while($cur_post->post_parent != 0)
495 {
496 $deepness++;
497 $cur_parent_id = $cur_post->post_parent;
498 $cur_post = & get_post($cur_parent_id);
499 }
500 }
501 ?>
502 <tr class="alternate author-self status-publish" id="post-<?php echo $post->ID; ?>">
503 <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $post->ID; ?>" name="reset[]"/></th>
504 <td><abbr title="<?php echo $post->post_date; ?>"><?php echo $post->post_date; ?></abbr></td>
505 <td>
506 <strong class="row-title"><?php for($i=0; $i < $deepness; $i++){ echo "— "; } echo $post->post_title; ?></strong>
507 </td>
508 <td>
509 <a href="?page=<?php echo $cur_admin_page; ?>&action=post_to_group&id=<?php echo $post->ID; ?>">
510 <?php
511 $usergroups = $wpdb->get_results(" SELECT ag.groupname
512 FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_POST." agtp
513 WHERE agtp.post_id = ".$post->ID."
514 AND ag.ID = agtp.group_id
515 GROUP BY ag.groupname", ARRAY_A);
516
517 if($usergroups)
518 {
519 foreach($usergroups as $usergroup)
520 {
521 echo $usergroup['groupname']."<br />";
522 }
523 }
524 else
525 {
526 _e(TXT_FULL_ACCESS, "UserAccessManager");
527 }
528 ?>
529 </a>
530 </td>
531 </tr>
532 <?php
533 }
534 }
535 ?>
536 </tbody>
537 </table>
538 </form>
539 </div>
540 <?php
541 }
542 elseif($cur_admin_page == 'uam_users' AND !$action)
543 {
544 $users = $wpdb->get_results(" SELECT ID
545 FROM $wpdb->users
546 ORDER BY ID", ARRAY_A);
547 ?>
548 <div class=wrap>
549 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
550 <input type="hidden" value="resetusers" name="action"/>
551 <h2><?php _e(TXT_MANAGE_USER, "UserAccessManager"); ?></h2>
552 <div class="tablenav">
553 <div class="alignleft">
554 <input type="submit" class="button-secondary delete" name="resetit" value="<?php _e(TXT_RESET_ACCESS, "UserAccessManager"); ?>"/>
555 </div>
556 <br class="clear"/>
557 </div>
558 <br class="clear"/>
559 <table class="widefat">
560 <thead>
561 <tr class="thead">
562 <th scope="col"></th>
563 <th scope="col"><?php _e(TXT_USERNAME, "UserAccessManager"); ?></th>
564 <th scope="col"><?php _e(TXT_NAME, "UserAccessManager"); ?></th>
565 <th scope="col"><?php _e(TXT_MAIL, "UserAccessManager"); ?></th>
566 <th scope="col"><?php _e(TXT_ACCESS, "UserAccessManager"); ?></th>
567 </tr>
568 </thead>
569 <tbody>
570 <?php
571 if($users)
572 {
573 foreach($users as $user)
574 {
575 $cur_user = get_userdata($user['ID']);
576 ?>
577 <tr class="alternate" id="user-<?php echo $cur_user->ID; ?>">
578 <th class="check-column" scope="row">
579 <?php
580 if($cur_user->wp_capabilities['administrator'] == 0)
581 {
582 ?>
583 <input type="checkbox" value="<?php echo $cur_user->ID; ?>" name="reset[]"/>
584 <?php
585 }
586 ?>
587 </th>
588 <td><strong><?php echo $cur_user->nickname; ?></strong></td>
589 <td><?php echo $cur_user->user_firstname." ".$cur_user->user_lastname; ?></td>
590 <td><?php echo $cur_user->user_email; ?></td>
591 <td>
592 <?php
593 if($cur_user->wp_capabilities['administrator'] == 1)
594 {
595 _e(TXT_FULL_ACCESS_ADMIN, "UserAccessManager");
596 }
597 else
598 {
599 ?>
600 <a href="?page=<?php echo $cur_admin_page; ?>&action=user_to_group&id=<?php echo $cur_user->ID; ?>">
601 <?php
602 $usergroups = $wpdb->get_results(" SELECT ag.groupname
603 FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_USER." agtp
604 WHERE agtp.user_id = ".$cur_user->ID."
605 AND ag.ID = agtp.group_id
606 GROUP BY ag.groupname", ARRAY_A);
607
608 if($usergroups)
609 {
610 foreach($usergroups as $usergroup)
611 {
612 echo $usergroup['groupname']."<br />";
613 }
614 }
615 else
616 {
617 _e(TXT_NO_GROUP, "UserAccessManager");
618 }
619 ?>
620 </a>
621 <?php
622 }
623 ?>
624 </td>
625 </tr>
626 <?php
627 }
628 }
629 ?>
630 </tbody>
631 </table>
632 </form>
633 </div>
634 <div class="wrap">
635 <p>
636 <?php _e(TXT_MANAGE_USER_NOTE, "UserAccessManager"); ?>
637 </p>
638 </div>
639 <?php
640 }
641 elseif($cur_admin_page == 'uam_usergroup' AND !$action)
642 {
643 $accessgroups = $wpdb->get_results("SELECT *
644 FROM ".DB_ACCESSGROUP."
645 ORDER BY ID", ARRAY_A);
646 ?>
647 <div class=wrap>
648 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
649 <input type="hidden" value="delgroup" name="action"/>
650 <h2><?php _e(TXT_MANAGE_GROUP, "UserAccessManager"); ?></h2>
651 <div class="tablenav">
652 <div class="alignleft">
653 <input type="submit" class="button-secondary delete" name="deleteit" value="<?php _e(TXT_DELETE, "UserAccessManager"); ?>"/>
654 </div>
655 <br class="clear"/>
656 </div>
657 <br class="clear"/>
658 <table class="widefat">
659 <thead>
660 <tr class="thead">
661 <th scope="col"></th>
662 <th scope="col"><?php _e(TXT_NAME, "UserAccessManager"); ?></th>
663 <th scope="col"><?php _e(TXT_DESCRIPTION, "UserAccessManager"); ?></th>
664 <th scope="col"><?php _e(TXT_POSTS, "UserAccessManager"); ?></th>
665 <th scope="col"><?php _e(TXT_PAGES, "UserAccessManager"); ?></th>
666 <th scope="col"><?php _e(TXT_USERS, "UserAccessManager"); ?></th>
667 </tr>
668 </thead>
669 <tbody>
670 <?php
671 if($accessgroups)
672 {
673 foreach($accessgroups as $accessgroup)
674 {
675 $users = $wpdb->get_results(" SELECT *
676 FROM ".DB_ACCESSGROUP_TO_USER."
677 WHERE group_id = ".$accessgroup['ID']."
678 ORDER BY user_id", ARRAY_A);
679 $posts = $wpdb->get_results(" SELECT *
680 FROM ".DB_ACCESSGROUP_TO_POST."
681 WHERE group_id = ".$accessgroup['ID']."
682 ORDER BY post_id", ARRAY_A);
683 ?>
684 <tr class="alternate" id="group-<?php echo $accessgroup['ID']; ?>">
685 <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $accessgroup['ID']; ?>" name="delete[]"/></th>
686 <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>
687 <td><?php echo $accessgroup['groupdesc']; ?></td>
688 <td>
689 <?php
690 if($posts)
691 {
692 foreach($posts as $post)
693 {
694 $cur_id = $post['post_id'];
695 $cur_post = & get_post($cur_id);
696 if($cur_post->post_type == 'post')
697 echo "- ".$cur_post->post_title."<br />";
698 }
699 }
700 ?>
701 </td>
702 <td>
703 <?php
704 if($posts)
705 {
706 foreach($posts as $post)
707 {
708 $cur_id = $post['post_id'];
709 $cur_post = & get_post($cur_id);
710 if($cur_post->post_type == 'page')
711 echo "- ".$cur_post->post_title."<br />";
712 }
713 }
714 ?>
715 </td>
716 <td>
717 <?php
718 if($users)
719 {
720 foreach($users as $user)
721 {
722 $cur_user = get_userdata($user['user_id']);
723 echo "- ".$cur_user->nickname."<br />";
724 }
725 }
726 ?>
727 </td>
728 </tr>
729 <?php
730 }
731 }
732 ?>
733 </tbody>
734 </table>
735 </form>
736 </div>
737 <div class="wrap">
738 <h2><?php _e(TXT_ADD_GROUP, "UserAccessManager"); ?></h2>
739 <div id="ajax-response"/>
740 <form class="add:the-list: validate" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" id="addgroup" name="addgroup">
741 <input type="hidden" value="addgroup" name="action"/>
742 <table class="form-table">
743 <tbody>
744 <tr class="form-field form-required">
745 <th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_NAME, "UserAccessManager"); ?>e</label></th>
746 <td><input type="text" aria-required="true" size="40" value="" id="access_group_name" name="access_group_name"/><br/>
747 <?php _e(TXT_GROUP_NAME_DESC, "UserAccessManager"); ?></td>
748
749 </tr>
750 <tr class="form-field form-required">
751 <th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_DESC, "UserAccessManager"); ?></label></th>
752 <td><input type="text" aria-required="true" size="40" value="" id="access_group_description" name="access_group_description"/><br/>
753 <?php _e(TXT_GROUP_DESC_DESC, "UserAccessManager"); ?></td>
754 </tr>
755 </tbody>
756 </table>
757 <p class="submit"><input type="submit" value="<?php _e(TXT_ADD, "UserAccessManager"); ?>" name="submit" class="button"/></p>
758 </form>
759 </div>
760 <?php
761 }
762 elseif($cur_admin_page == 'uam_settings' AND !$action)
763 {
764 ?>
765 <div class=wrap>
766 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
767 <h2><?php _e(TXT_SETTINGS, "UserAccessManager"); ?></h2>
768 <h3><?php _e(TXT_DISPLAY_TITLE, "UserAccessManager"); ?></h3>
769 <p><?php _e(TXT_DISPLAY_TITLE_DESC, "UserAccessManager"); ?></p>
770 <p>
771 <label for="uam_hide_title_yes">
772 <input type="radio" id="uam_hide_title_yes" name="uam_hide_title" value="true" <?php if ($uamOptions['hide_title'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> />
773 <?php _e(TXT_YES, "UserAccessManager"); ?>
774 </label>&nbsp;&nbsp;&nbsp;&nbsp;
775 <label for="uam_hide_title_no">
776 <input type="radio" id="uam_hide_title_no" name="uam_hide_title" value="false" <?php if ($uamOptions['hide_title'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/>
777 <?php _e(TXT_NO, "UserAccessManager"); ?>
778 </label>
779 </p>
780 <h3><?php _e(TXT_TITLE_STR, "UserAccessManager"); ?></h3>
781 <p>
782 <input name="uam_post_title" value="<?php _e($uamOptions['post_title'], 'UserAccessManager') ?>" />
783 </p>
784 <h3><?php _e(TXT_DISPLAY_CONTENT, "UserAccessManager"); ?></h3>
785 <textarea name="uam_post_content" style="width: 80%; height: 100px;"><?php _e(apply_filters('format_to_edit',$uamOptions['post_content']), 'UserAccessManager') ?></textarea>
786 <h3><?php _e(TXT_HIDE_POST, "UserAccessManager"); ?></h3>
787 <p><?php _e(TXT_HIDE_POST_DESC, "UserAccessManager"); ?></p>
788 <p>
789 <label for="uam_hide_post_yes">
790 <input type="radio" id="uam_hide_post_yes" name="uam_hide_post" value="true" <?php if ($uamOptions['hide_post'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> />
791 <?php _e(TXT_YES, "UserAccessManager"); ?>
792 </label>&nbsp;&nbsp;&nbsp;&nbsp;
793 <label for="uam_hide_post_no">
794 <input type="radio" id="uam_hide_post_no" name="uam_hide_post" value="false" <?php if ($uamOptions['hide_post'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/>
795 <?php _e(TXT_NO, "UserAccessManager"); ?>
796 </label>
797 </p>
798 <h3><?php _e(TXT_HIDE_PAGE_NAVI, "UserAccessManager"); ?></h3>
799 <p><?php _e(TXT_HIDE_PAGE_NAVI_DESC, "UserAccessManager"); ?></p>
800 <p>
801 <label for="uam_hide_page_yes">
802 <input type="radio" id="uam_hide_page_yes" name="uam_hide_page" value="true" <?php if ($uamOptions['hide_page'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> />
803 <?php _e(TXT_YES, "UserAccessManager"); ?>
804 </label>&nbsp;&nbsp;&nbsp;&nbsp;
805 <label for="uam_hide_page_no">
806 <input type="radio" id="uam_hide_page_no" name="uam_hide_page" value="false" <?php if ($uamOptions['hide_page'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/>
807 <?php _e(TXT_NO, "UserAccessManager"); ?>
808 </label>
809 </p>
810 <h3><?php _e(TXT_REDIRECT, "UserAccessManager"); ?></h3>
811 <p><?php _e(TXT_REDIRECT_DESC, "UserAccessManager"); ?></p>
812 <p>
813 <label for="uam_redirect_no">
814 <input type="radio" id="uam_redirect_no" name="uam_redirect" value="false" <?php if ($uamOptions['redirect'] == "false") { _e('checked="checked"', "UserAccessManager"); }?> />
815 <?php _e(TXT_NO, "UserAccessManager"); ?>
816 </label>&nbsp;&nbsp;&nbsp;&nbsp;
817 <label for="uam_redirect_blog">
818 <input type="radio" id="uam_redirect_blog" name="uam_redirect" value="blog" <?php if ($uamOptions['redirect'] == "blog") { _e('checked="checked"', "UserAccessManager"); }?> />
819 <?php _e(TXT_REDIRECT_TO_BOLG, "UserAccessManager"); ?>
820 </label>&nbsp;&nbsp;&nbsp;&nbsp;
821 <label for="uam_redirect_custom_page">
822 <input type="radio" id="uam_redirect_custom_p" name="uam_redirect" value="custom_page" <?php if ($uamOptions['redirect'] == "custom_page") { _e('checked="checked"', "UserAccessManager"); }?>/>
823 <?php _e(TXT_REDIRECT_TO_PAGE, "UserAccessManager"); ?>
824 </label><input name="uam_redirect_custom_page" value="<?php _e($uamOptions['redirect_custom_page'], 'UserAccessManager') ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
825 <label for="uam_redirect_custom_url">
826 <input type="radio" id="uam_redirect_custom_u" name="uam_redirect" value="custom_url" <?php if ($uamOptions['redirect'] == "custom_url") { _e('checked="checked"', "UserAccessManager"); }?>/>
827 <?php _e(TXT_REDIRECT_TO_URL, "UserAccessManager"); ?>
828 </label><input name="uam_redirect_custom_url" value="<?php _e($uamOptions['redirect_custom_url'], 'UserAccessManager') ?>" />
829 </p>
830 <h3><?php _e(TXT_LOCK_RECURSIVE, "UserAccessManager"); ?></h3>
831 <p><?php _e(TXT_LOCK_RECURSIVE_DESC, "UserAccessManager"); ?></p>
832 <p>
833 <label for="uam_lock_recursive_yes">
834 <input type="radio" id="uam_lock_recursive_yes" name="uam_lock_recursive" value="true" <?php if ($uamOptions['lock_recursive'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> />
835 <?php _e(TXT_YES, "UserAccessManager"); ?>
836 </label>&nbsp;&nbsp;&nbsp;&nbsp;
837 <label for="uam_lock_recursive_no">
838 <input type="radio" id="uam_lock_recursive_no" name="uam_lock_recursive" value="false" <?php if ($uamOptions['lock_recursive'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/>
839 <?php _e(TXT_NO, "UserAccessManager"); ?>
840 </label>
841 </p>
842 <h3><?php _e(TXT_DOWNLOAD_TYPE, "UserAccessManager"); ?></h3>
843 <p><?php _e(TXT_DOWNLOAD_TYPE_DESC, "UserAccessManager"); ?></p>
844 <p>
845 <label for="uam_download_type_normal">
846 <input type="radio" id="uam_download_type_normal" name="uam_download_type" value="normal" <?php if ($uamOptions['download_type'] == "normal") { _e('checked="checked"', "UserAccessManager"); }?> />
847 <?php _e(TXT_NORMAL, "UserAccessManager"); ?>
848 </label>&nbsp;&nbsp;&nbsp;&nbsp;
849 <label for="uam_download_type_fopen">
850 <input type="radio" id="uam_download_type_fopen" name="uam_download_type" value="fopen" <?php if ($uamOptions['download_type'] == "fopen") { _e('checked="checked"', "UserAccessManager"); }?>/>
851 <?php _e(TXT_FOPEN, "UserAccessManager"); ?>
852 </label>
853 </p>
854 <div class="submit">
855 <input type="submit" name="update_uam_settings" value="<?php _e(TXT_UPDATE_SETTING, 'UserAccessManager') ?>" />
856 </div>
857 </form>
858 </div>
859 <?php
860 }
861 elseif($action == 'post_to_group')
862 {
863 $post_id = $_GET['id'];
864 $accessgroups = $wpdb->get_results("SELECT *
865 FROM ".DB_ACCESSGROUP."
866 ORDER BY groupname", ARRAY_A);
867
868 ?>
869 <div class=wrap>
870 <form method="post" action="<?php echo reset(explode("?", $_SERVER["REQUEST_URI"]))."?page=".$_GET['page']; ?>">
871 <input type="hidden" value="addgroup_to_post" name="action"/>
872 <input type="hidden" value="<?php echo $post_id; ?>" name="post_id"/>
873 <?php
874 if($cur_admin_page == 'uam_posts')
875 {
876 echo "<h2>";
877 _e(TXT_SET_POST_ACCESS, "UserAccessManager");
878 echo "</h2>";
879 }
880 elseif($cur_admin_page == 'uam_pages')
881 {
882 echo "<h2>";
883 _e(TXT_SET_PAGE_ACCESS, "UserAccessManager");
884 echo "</h2>";
885 }
886 ?>
887 <div class="postbox">
888 <h3><?php _e(TXT_GROUPS, "UserAccessManager"); ?></h3>
889 <div class="inside">
890 <?php
891 if($accessgroups)
892 {
893 foreach($accessgroups as $accessgroup)
894 {
895 $checked = $wpdb->get_results(" SELECT *
896 FROM ".DB_ACCESSGROUP_TO_POST."
897 WHERE post_id = ".$post_id."
898 AND group_id = ".$accessgroup['ID'], ARRAY_A)
899 ?>
900 <p>
901 <label class="selectit" for="comment_status">
902 <input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/>
903 <?php echo $accessgroup['groupname'] ?>
904 </label>
905 </p>
906 <?php
907 }
908 }
909 else
910 {
911 echo "<p>";
912 _e(TXT_CREATE_GROUP_FIRST, "UserAccessManager");
913 echo "</p>";
914 }
915 ?>
916 </div>
917 </div>
918 <p class="submit"><input type="submit" value="<?php _e(TXT_SET_ACCESS, "UserAccessManager"); ?>" name="submit" class="button"/></p>
919 </form>
920 </div>
921 <?php
922 }
923 elseif($action == 'user_to_group')
924 {
925 $user_id = $_GET['id'];
926 $accessgroups = $wpdb->get_results("SELECT *
927 FROM ".DB_ACCESSGROUP."
928 ORDER BY groupname", ARRAY_A);
929
930 ?>
931 <div class=wrap>
932 <form method="post" action="<?php echo reset(explode("?", $_SERVER["REQUEST_URI"]))."?page=".$_GET['page']; ?>">
933 <input type="hidden" value="addgroup_to_user" name="action"/>
934 <input type="hidden" value="<?php echo $user_id; ?>" name="user_id"/>
935 <h2><?php _e(TXT_SET_USER_ACCESS, "UserAccessManager"); ?></h2>
936 <div class="postbox">
937 <h3><?php _e(TXT_GROUPS, "UserAccessManager"); ?></h3>
938 <div class="inside">
939 <?php
940 if($accessgroups)
941 {
942 foreach($accessgroups as $accessgroup)
943 {
944 $checked = $wpdb->get_results(" SELECT *
945 FROM ".DB_ACCESSGROUP_TO_USER."
946 WHERE user_id = ".$user_id."
947 AND group_id = ".$accessgroup['ID'], ARRAY_A)
948 ?>
949 <p>
950 <label class="selectit" for="comment_status">
951 <input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/>
952 <?php echo $accessgroup['groupname'] ?>
953 </label>
954 </p>
955 <?php
956 }
957 }
958 else
959 {
960 echo "<p>";
961 _e(TXT_CREATE_GROUP_FIRST, "UserAccessManager");
962 echo "</p>";
963 }
964 ?>
965 </div>
966 </div>
967 <p class="submit"><input type="submit" value="<?php _e(TXT_SET_ACCESS, "UserAccessManager"); ?>" name="submit" class="button"/></p>
968 </form>
969 </div>
970 <?php
971 }
972 elseif($action == 'edit_group')
973 {
974 $group_id = $_GET['id'];
975 $accessgroup = $wpdb->get_row(" SELECT *
976 FROM ".DB_ACCESSGROUP."
977 WHERE ID = ".$group_id."
978 LIMIT 1", ARRAY_A);
979 ?>
980 <div class=wrap>
981 <form method="post" action="<?php echo reset(explode("?", $_SERVER["REQUEST_URI"]))."?page=".$_GET['page']; ?>">
982 <input type="hidden" value="update_group" name="action"/>
983 <input type="hidden" value="<?php echo $group_id; ?>" name="access_group_id"/>
984 <table class="form-table">
985 <tbody>
986 <tr class="form-field form-required">
987 <th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_NAME, "UserAccessManager"); ?></label></th>
988 <td><input type="text" aria-required="true" size="40" value="<?php echo $accessgroup["groupname"];?>" id="access_group_name" name="access_group_name"/><br/>
989 <?php _e(TXT_GROUP_NAME_DESC, "UserAccessManager"); ?></td>
990 </tr>
991 <tr class="form-field form-required">
992 <th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_DESC, "UserAccessManager"); ?></label></th>
993 <td><input type="text" aria-required="true" size="40" value="<?php echo $accessgroup["groupdesc"];?>" id="access_group_description" name="access_group_description"/><br/>
994 <?php _e(TXT_GROUP_DESC_DESC, "UserAccessManager"); ?></td>
995 </tr>
996 </tbody>
997 </table>
998 <p class="submit"><input type="submit" value="<?php _e(TXT_UPDATE_GROUP, "UserAccessManager"); ?>" name="submit" class="button"/></p>
999 </form>
1000 </div>
1001 <?php
1002 }
1003 }//End function printAdminPage()
1004
1005 function check_access($post_id = null)
1006 {
1007 global $wpdb, $current_user;
1008
1009 $cur_id = $post_id;
1010 $cur_post = & get_post($cur_id);
1011
1012 $uamOptions = $this->getAdminOptions();
1013
1014 if($uamOptions['lock_recursive'] == 'true')
1015 {
1016 $cur_id = $cur_post->ID;
1017 while($cur_id != 0)
1018 {
1019 $restricted_access = $wpdb->get_results(" SELECT *
1020 FROM ".DB_ACCESSGROUP_TO_POST."
1021 WHERE post_id = ".$cur_post->ID, ARRAY_A);
1022 if($restricted_access)
1023 {
1024 break;
1025 }
1026 else
1027 {
1028 $cur_id = $cur_post->post_parent;
1029 $cur_post = & get_post($cur_id);
1030 }
1031 }
1032 }
1033 elseif($uamOptions['lock_recursive'] == 'false')
1034 {
1035 if( $cur_post->post_type != 'attachment')
1036 {
1037 $restricted_access = $wpdb->get_results(" SELECT *
1038 FROM ".DB_ACCESSGROUP_TO_POST."
1039 WHERE post_id = ".$cur_post->ID, ARRAY_A);
1040 }
1041 else
1042 {
1043 $restricted_access = $wpdb->get_results(" SELECT *
1044 FROM ".DB_ACCESSGROUP_TO_POST."
1045 WHERE post_id = ".$cur_post->post_parent, ARRAY_A);
1046 }
1047 }
1048
1049 if($restricted_access)
1050 {
1051 if (is_user_logged_in())
1052 {
1053 $cur_userdata = get_userdata($current_user->ID);
1054
1055 if($cur_userdata->wp_capabilities['administrator'] != 1)
1056 {
1057 $user_access = $wpdb->get_results(" SELECT *
1058 FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP_TO_USER." atu
1059 WHERE atp.post_id = ".$cur_post->ID."
1060 AND atp.group_id = atu.group_id
1061 AND atu.user_id = ".$current_user->ID, ARRAY_A);
1062
1063 if($user_access)
1064 return true;
1065 else
1066 return false;
1067 }
1068 else
1069 {
1070 return true;
1071 }
1072 }
1073 else
1074 {
1075 return false;
1076 }
1077 }
1078 else
1079 {
1080 return true;
1081 }
1082 }
1083
1084 function show_title($title = '')
1085 {
1086 $cur_id = null;
1087 $cur_post = & get_post($cur_id);
1088
1089 $uamOptions = $this->getAdminOptions();
1090
1091 // little hack nessesary because on single post it works on all
1092 if(!$this->check_access() && $title == $cur_post->post_title && $uamOptions['hide_title'] == 'true')
1093 $title = $uamOptions['post_title'];
1094
1095 return $title;
1096 }
1097
1098 function show_content($content = '')
1099 {
1100 $uamOptions = $this->getAdminOptions();
1101
1102 if(!$this->check_access())
1103 $content = $uamOptions['post_content'];
1104
1105 return $content;
1106 }
1107
1108 function show_post($posts = array())
1109 {
1110 $no_posts = count($posts);
1111
1112 for($i=0; $i < $no_posts; $i++)
1113 {
1114 if($this->check_access($posts[$i]->ID))
1115 $show_posts[] = $posts[$i];
1116 }
1117
1118 $posts = $show_posts;
1119
1120 return $posts;
1121 }
1122
1123 function exclude_page($page)
1124 {
1125 $pages = get_pages();
1126
1127 $excluded_pages = array(-1);
1128
1129 foreach($pages as $page)
1130 {
1131 if(!$this->check_access($page->ID))
1132 {
1133 $excluded_pages[] = $page->ID;
1134 }
1135 }
1136
1137 $page = $excluded_pages;
1138
1139 return $page;
1140 }
1141
1142 function redirect_user()
1143 {
1144 global $wp_query;
1145
1146 if(!$this->check_access() && $uamOptions['redirect'] != 'false')
1147 {
1148 $uamOptions = $this->getAdminOptions();
1149
1150 if($uamOptions['redirect'] == 'blog' || $uamOptions['redirect'] == 'custom_page')
1151 {
1152 $host = $_SERVER['HTTP_HOST'];
1153 $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
1154
1155 if($uamOptions['redirect'] == 'blog')
1156 $extra = '';
1157 elseif($uamOptions['redirect'] == 'custom_page')
1158 $extra = $uamOptions['redirect_custom_page'];
1159
1160 $url = "http://".$host.$uri."/".$extra;
1161 }
1162 elseif( $uamOptions['redirect'] == 'custom_url')
1163 {
1164 $url = $uamOptions['redirect_custom_url'];
1165 }
1166
1167
1168 $cur_posts = $wp_query->get_posts();
1169
1170 $post_to_show = false;
1171
1172 foreach($cur_posts as $cur_post)
1173 {
1174 if($this->check_access())
1175 {
1176 $post_to_show = true;
1177 break;
1178 }
1179 }
1180
1181 if($url != "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"] && !$post_to_show)
1182 {
1183 header("Location: $url");
1184 exit;
1185 }
1186 }
1187 elseif(isset($_GET['getfile']))
1188 {
1189 $cur_id = $_GET['getfile'];
1190 $cur_post = & get_post($cur_id);
1191
1192 if ($cur_post->post_type == 'attachment' && $this->check_access($cur_post->ID))
1193 {
1194 $allowed_ext = array ( // archives
1195 'zip' => 'application/zip',
1196 'rar' => 'application/rar',
1197
1198 // documents
1199 'pdf' => 'application/pdf',
1200 'doc' => 'application/msword',
1201 'xls' => 'application/vnd.ms-excel',
1202 'ppt' => 'application/vnd.ms-powerpoint',
1203
1204 // executables
1205 'exe' => 'application/octet-stream',
1206
1207 // images
1208 'gif' => 'image/gif',
1209 'png' => 'image/png',
1210 'jpg' => 'image/jpeg',
1211 'jpeg' => 'image/jpeg',
1212
1213 // audio
1214 'mp3' => 'audio/mpeg',
1215 'wav' => 'audio/x-wav',
1216
1217 // video
1218 'mpeg' => 'video/mpeg',
1219 'mpg' => 'video/mpeg',
1220 'mpe' => 'video/mpeg',
1221 'mov' => 'video/quicktime',
1222 'avi' => 'video/x-msvideo'
1223 );
1224
1225 $file = str_replace("http://".$_SERVER['HTTP_HOST']."/", "", $cur_post->guid);
1226 $filename = basename($file);
1227 $fileext = strtolower(substr(strrchr($filename,"."),1));
1228
1229 if (file_exists($file))
1230 {
1231 $len = filesize($file);
1232 header('content-type: '.$allowed_ext[$fileext]);
1233 header('content-length: '.$len);
1234 header('content-disposition: attachment; filename='.basename($file));
1235
1236 if($uamOptions['download_type'] == 'fopen')
1237 {
1238 $fp=fopen($file, 'rb');
1239
1240 while ( ! feof($fp) )
1241 {
1242 set_time_limit(30);
1243 $buffer = fread($fp, 1024);
1244 echo $buffer;
1245 }
1246 exit;
1247 }
1248 else
1249 {
1250 readfile($file);
1251 exit;
1252 }
1253 }
1254 else
1255 {
1256 echo 'Error: File not found';
1257 }
1258 }
1259 }
1260 }
1261
1262 function get_file($URL, $ID)
1263 {
1264 $cur_id = $ID;
1265 $cur_post = & get_post($cur_id);
1266 $parent_id = $cur_post->post_parent;
1267 $cur_parent = & get_post($parent_id);
1268 if(strpos($cur_parent->guid, "?"))
1269 $char = "&";
1270 else
1271 $char = "?";
1272
1273 $URL = $cur_parent->guid.$char.'getfile='.$cur_post->ID;
1274
1275 return $URL;
1276 }
1277 }
1278
1279 } //End Class DevloungePluginSeries
1280
1281 if (class_exists("UserAccessManager"))
1282 {
1283 $userAccessManager = new UserAccessManager();
1284 }
1285
1286 //Initialize the admin panel
1287 if (!function_exists("UserAccessManager_AP")) {
1288 function UserAccessManager_AP()
1289 {
1290 global $userAccessManager;
1291 if (!isset($userAccessManager))
1292 {
1293 return;
1294 }
1295 if (function_exists('add_menu_page'))
1296 {
1297 add_menu_page('User Access Manager', 'Access Manager', 9, 'uam_posts', array(&$userAccessManager, 'printAdminPage'));
1298 }
1299 if (function_exists('add_submenu_page'))
1300 {
1301 add_submenu_page('uam_posts', TXT_MANAGE_POST, TXT_MANAGE_POST, 9, 'uam_posts', array(&$userAccessManager, 'printAdminPage'));
1302 add_submenu_page('uam_posts', TXT_MANAGE_PAGE, TXT_MANAGE_PAGE, 9, 'uam_pages', array(&$userAccessManager, 'printAdminPage'));
1303 add_submenu_page('uam_posts', TXT_MANAGE_USER, TXT_MANAGE_USER, 9, 'uam_users', array(&$userAccessManager, 'printAdminPage'));
1304 add_submenu_page('uam_posts', TXT_MANAGE_GROUP, TXT_MANAGE_GROUP, 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage'));
1305 add_submenu_page('uam_posts', TXT_SETTING, TXT_SETTINGS, 9, 'uam_settings', array(&$userAccessManager, 'printAdminPage'));
1306 }
1307 }
1308 }
1309
1310 //Actions and Filters
1311 if (isset($userAccessManager))
1312 {
1313 $uamOptions = $userAccessManager->getAdminOptions();
1314
1315 //install
1316 register_activation_hook(__FILE__, array(&$userAccessManager, 'install'));
1317 register_uninstall_hook(__FILE__, array(&$userAccessManager, 'uninstall'));
1318
1319 //Actions
1320 add_action('admin_menu', 'UserAccessManager_AP');
1321
1322 if($uamOptions['redirect'] != 'false' || isset($_GET['getfile']))
1323 add_action('template_redirect', array(&$userAccessManager, 'redirect_user'), 1);
1324
1325 //Filters
1326 add_filter('the_title', array(&$userAccessManager, 'show_title'), 1);
1327 add_filter('the_content', array(&$userAccessManager, 'show_content'), 1);
1328 add_filter('wp_get_attachment_url', array(&$userAccessManager, 'get_file'), 1, 2);
1329
1330 if($uamOptions['hide_page'] == 'true')
1331 add_filter('wp_list_pages_excludes', array(&$userAccessManager, 'exclude_page'), 1);
1332
1333 if($uamOptions['hide_post'] == 'true')
1334 add_filter('the_posts', array(&$userAccessManager, 'show_post'), 1);
1335 }
1336
1337 ?>