PluginProbe
User Access Manager / 0.6
User Access Manager v0.6
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, at user-access-manager.php

1,324 lines 45.0 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.6
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_post = get_post($cur_id = $cur_post->post_parent);
498 }
499 }
500 ?>
501 <tr class="alternate author-self status-publish" id="post-<?php echo $post->ID; ?>">
502 <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $post->ID; ?>" name="reset[]"/></th>
503 <td><abbr title="<?php echo $post->post_date; ?>"><?php echo $post->post_date; ?></abbr></td>
504 <td>
505 <strong class="row-title"><?php for($i=0; $i < $deepness; $i++){ echo "— "; } echo $post->post_title; ?></strong>
506 </td>
507 <td>
508 <a href="?page=<?php echo $cur_admin_page; ?>&action=post_to_group&id=<?php echo $post->ID; ?>">
509 <?php
510 $usergroups = $wpdb->get_results(" SELECT ag.groupname
511 FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_POST." agtp
512 WHERE agtp.post_id = ".$post->ID."
513 AND ag.ID = agtp.group_id
514 GROUP BY ag.groupname", ARRAY_A);
515
516 if($usergroups)
517 {
518 foreach($usergroups as $usergroup)
519 {
520 echo $usergroup['groupname']."<br />";
521 }
522 }
523 else
524 {
525 _e(TXT_FULL_ACCESS, "UserAccessManager");
526 }
527 ?>
528 </a>
529 </td>
530 </tr>
531 <?php
532 }
533 }
534 ?>
535 </tbody>
536 </table>
537 </form>
538 </div>
539 <?php
540 }
541 elseif($cur_admin_page == 'uam_users' AND !$action)
542 {
543 $users = $wpdb->get_results(" SELECT ID
544 FROM $wpdb->users
545 ORDER BY ID", ARRAY_A);
546 ?>
547 <div class=wrap>
548 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
549 <input type="hidden" value="resetusers" name="action"/>
550 <h2><?php _e(TXT_MANAGE_USER, "UserAccessManager"); ?></h2>
551 <div class="tablenav">
552 <div class="alignleft">
553 <input type="submit" class="button-secondary delete" name="resetit" value="<?php _e(TXT_RESET_ACCESS, "UserAccessManager"); ?>"/>
554 </div>
555 <br class="clear"/>
556 </div>
557 <br class="clear"/>
558 <table class="widefat">
559 <thead>
560 <tr class="thead">
561 <th scope="col"></th>
562 <th scope="col"><?php _e(TXT_USERNAME, "UserAccessManager"); ?></th>
563 <th scope="col"><?php _e(TXT_NAME, "UserAccessManager"); ?></th>
564 <th scope="col"><?php _e(TXT_MAIL, "UserAccessManager"); ?></th>
565 <th scope="col"><?php _e(TXT_ACCESS, "UserAccessManager"); ?></th>
566 </tr>
567 </thead>
568 <tbody>
569 <?php
570 if($users)
571 {
572 foreach($users as $user)
573 {
574 $cur_user = get_userdata($user['ID']);
575 ?>
576 <tr class="alternate" id="user-<?php echo $cur_user->ID; ?>">
577 <th class="check-column" scope="row">
578 <?php
579 if($cur_user->wp_capabilities['administrator'] == 0)
580 {
581 ?>
582 <input type="checkbox" value="<?php echo $cur_user->ID; ?>" name="reset[]"/>
583 <?php
584 }
585 ?>
586 </th>
587 <td><strong><?php echo $cur_user->nickname; ?></strong></td>
588 <td><?php echo $cur_user->user_firstname." ".$cur_user->user_lastname; ?></td>
589 <td><?php echo $cur_user->user_email; ?></td>
590 <td>
591 <?php
592 if($cur_user->wp_capabilities['administrator'] == 1)
593 {
594 _e(TXT_FULL_ACCESS_ADMIN, "UserAccessManager");
595 }
596 else
597 {
598 ?>
599 <a href="?page=<?php echo $cur_admin_page; ?>&action=user_to_group&id=<?php echo $cur_user->ID; ?>">
600 <?php
601 $usergroups = $wpdb->get_results(" SELECT ag.groupname
602 FROM ".DB_ACCESSGROUP." ag, ".DB_ACCESSGROUP_TO_USER." agtp
603 WHERE agtp.user_id = ".$cur_user->ID."
604 AND ag.ID = agtp.group_id
605 GROUP BY ag.groupname", ARRAY_A);
606
607 if($usergroups)
608 {
609 foreach($usergroups as $usergroup)
610 {
611 echo $usergroup['groupname']."<br />";
612 }
613 }
614 else
615 {
616 _e(TXT_NO_GROUP, "UserAccessManager");
617 }
618 ?>
619 </a>
620 <?php
621 }
622 ?>
623 </td>
624 </tr>
625 <?php
626 }
627 }
628 ?>
629 </tbody>
630 </table>
631 </form>
632 </div>
633 <div class="wrap">
634 <p>
635 <?php _e(TXT_MANAGE_USER_NOTE, "UserAccessManager"); ?>
636 </p>
637 </div>
638 <?php
639 }
640 elseif($cur_admin_page == 'uam_usergroup' AND !$action)
641 {
642 $accessgroups = $wpdb->get_results("SELECT *
643 FROM ".DB_ACCESSGROUP."
644 ORDER BY ID", ARRAY_A);
645 ?>
646 <div class=wrap>
647 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
648 <input type="hidden" value="delgroup" name="action"/>
649 <h2><?php _e(TXT_MANAGE_GROUP, "UserAccessManager"); ?></h2>
650 <div class="tablenav">
651 <div class="alignleft">
652 <input type="submit" class="button-secondary delete" name="deleteit" value="<?php _e(TXT_DELETE, "UserAccessManager"); ?>"/>
653 </div>
654 <br class="clear"/>
655 </div>
656 <br class="clear"/>
657 <table class="widefat">
658 <thead>
659 <tr class="thead">
660 <th scope="col"></th>
661 <th scope="col"><?php _e(TXT_NAME, "UserAccessManager"); ?></th>
662 <th scope="col"><?php _e(TXT_DESCRIPTION, "UserAccessManager"); ?></th>
663 <th scope="col"><?php _e(TXT_POSTS, "UserAccessManager"); ?></th>
664 <th scope="col"><?php _e(TXT_PAGES, "UserAccessManager"); ?></th>
665 <th scope="col"><?php _e(TXT_USERS, "UserAccessManager"); ?></th>
666 </tr>
667 </thead>
668 <tbody>
669 <?php
670 if($accessgroups)
671 {
672 foreach($accessgroups as $accessgroup)
673 {
674 $users = $wpdb->get_results(" SELECT *
675 FROM ".DB_ACCESSGROUP_TO_USER."
676 WHERE group_id = ".$accessgroup['ID']."
677 ORDER BY user_id", ARRAY_A);
678 $posts = $wpdb->get_results(" SELECT *
679 FROM ".DB_ACCESSGROUP_TO_POST."
680 WHERE group_id = ".$accessgroup['ID']."
681 ORDER BY post_id", ARRAY_A);
682 ?>
683 <tr class="alternate" id="group-<?php echo $accessgroup['ID']; ?>">
684 <th class="check-column" scope="row"><input type="checkbox" value="<?php echo $accessgroup['ID']; ?>" name="delete[]"/></th>
685 <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>
686 <td><?php echo $accessgroup['groupdesc']; ?></td>
687 <td>
688 <?php
689 if($posts)
690 {
691 foreach($posts as $post)
692 {
693 $cur_post = get_post($post['post_id']);
694 if($cur_post->post_type == 'post')
695 echo "- ".$cur_post->post_title."<br />";
696 }
697 }
698 ?>
699 </td>
700 <td>
701 <?php
702 if($posts)
703 {
704 foreach($posts as $post)
705 {
706 $cur_post = get_post($post['post_id']);
707 if($cur_post->post_type == 'page')
708 echo "- ".$cur_post->post_title."<br />";
709 }
710 }
711 ?>
712 </td>
713 <td>
714 <?php
715 if($users)
716 {
717 foreach($users as $user)
718 {
719 $cur_user = get_userdata($user['user_id']);
720 echo "- ".$cur_user->nickname."<br />";
721 }
722 }
723 ?>
724 </td>
725 </tr>
726 <?php
727 }
728 }
729 ?>
730 </tbody>
731 </table>
732 </form>
733 </div>
734 <div class="wrap">
735 <h2><?php _e(TXT_ADD_GROUP, "UserAccessManager"); ?></h2>
736 <div id="ajax-response"/>
737 <form class="add:the-list: validate" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post" id="addgroup" name="addgroup">
738 <input type="hidden" value="addgroup" name="action"/>
739 <table class="form-table">
740 <tbody>
741 <tr class="form-field form-required">
742 <th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_NAME, "UserAccessManager"); ?>e</label></th>
743 <td><input type="text" aria-required="true" size="40" value="" id="access_group_name" name="access_group_name"/><br/>
744 <?php _e(TXT_GROUP_NAME_DESC, "UserAccessManager"); ?></td>
745
746 </tr>
747 <tr class="form-field form-required">
748 <th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_DESC, "UserAccessManager"); ?></label></th>
749 <td><input type="text" aria-required="true" size="40" value="" id="access_group_description" name="access_group_description"/><br/>
750 <?php _e(TXT_GROUP_DESC_DESC, "UserAccessManager"); ?></td>
751 </tr>
752 </tbody>
753 </table>
754 <p class="submit"><input type="submit" value="<?php _e(TXT_ADD, "UserAccessManager"); ?>" name="submit" class="button"/></p>
755 </form>
756 </div>
757 <?php
758 }
759 elseif($cur_admin_page == 'uam_settings' AND !$action)
760 {
761 ?>
762 <div class=wrap>
763 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
764 <h2><?php _e(TXT_SETTINGS, "UserAccessManager"); ?></h2>
765 <h3><?php _e(TXT_DISPLAY_TITLE, "UserAccessManager"); ?></h3>
766 <p><?php _e(TXT_DISPLAY_TITLE_DESC, "UserAccessManager"); ?></p>
767 <p>
768 <label for="uam_hide_title_yes">
769 <input type="radio" id="uam_hide_title_yes" name="uam_hide_title" value="true" <?php if ($uamOptions['hide_title'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> />
770 <?php _e(TXT_YES, "UserAccessManager"); ?>
771 </label>&nbsp;&nbsp;&nbsp;&nbsp;
772 <label for="uam_hide_title_no">
773 <input type="radio" id="uam_hide_title_no" name="uam_hide_title" value="false" <?php if ($uamOptions['hide_title'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/>
774 <?php _e(TXT_NO, "UserAccessManager"); ?>
775 </label>
776 </p>
777 <h3><?php _e(TXT_TITLE_STR, "UserAccessManager"); ?></h3>
778 <p>
779 <input name="uam_post_title" value="<?php _e($uamOptions['post_title'], 'UserAccessManager') ?>" />
780 </p>
781 <h3><?php _e(TXT_DISPLAY_CONTENT, "UserAccessManager"); ?></h3>
782 <textarea name="uam_post_content" style="width: 80%; height: 100px;"><?php _e(apply_filters('format_to_edit',$uamOptions['post_content']), 'UserAccessManager') ?></textarea>
783 <h3><?php _e(TXT_HIDE_POST, "UserAccessManager"); ?></h3>
784 <p><?php _e(TXT_HIDE_POST_DESC, "UserAccessManager"); ?></p>
785 <p>
786 <label for="uam_hide_post_yes">
787 <input type="radio" id="uam_hide_post_yes" name="uam_hide_post" value="true" <?php if ($uamOptions['hide_post'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> />
788 <?php _e(TXT_YES, "UserAccessManager"); ?>
789 </label>&nbsp;&nbsp;&nbsp;&nbsp;
790 <label for="uam_hide_post_no">
791 <input type="radio" id="uam_hide_post_no" name="uam_hide_post" value="false" <?php if ($uamOptions['hide_post'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/>
792 <?php _e(TXT_NO, "UserAccessManager"); ?>
793 </label>
794 </p>
795 <h3><?php _e(TXT_HIDE_PAGE_NAVI, "UserAccessManager"); ?></h3>
796 <p><?php _e(TXT_HIDE_PAGE_NAVI_DESC, "UserAccessManager"); ?></p>
797 <p>
798 <label for="uam_hide_page_yes">
799 <input type="radio" id="uam_hide_page_yes" name="uam_hide_page" value="true" <?php if ($uamOptions['hide_page'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> />
800 <?php _e(TXT_YES, "UserAccessManager"); ?>
801 </label>&nbsp;&nbsp;&nbsp;&nbsp;
802 <label for="uam_hide_page_no">
803 <input type="radio" id="uam_hide_page_no" name="uam_hide_page" value="false" <?php if ($uamOptions['hide_page'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/>
804 <?php _e(TXT_NO, "UserAccessManager"); ?>
805 </label>
806 </p>
807 <h3><?php _e(TXT_REDIRECT, "UserAccessManager"); ?></h3>
808 <p><?php _e(TXT_REDIRECT_DESC, "UserAccessManager"); ?></p>
809 <p>
810 <label for="uam_redirect_no">
811 <input type="radio" id="uam_redirect_no" name="uam_redirect" value="false" <?php if ($uamOptions['redirect'] == "false") { _e('checked="checked"', "UserAccessManager"); }?> />
812 <?php _e(TXT_NO, "UserAccessManager"); ?>
813 </label>&nbsp;&nbsp;&nbsp;&nbsp;
814 <label for="uam_redirect_blog">
815 <input type="radio" id="uam_redirect_blog" name="uam_redirect" value="blog" <?php if ($uamOptions['redirect'] == "blog") { _e('checked="checked"', "UserAccessManager"); }?> />
816 <?php _e(TXT_REDIRECT_TO_BOLG, "UserAccessManager"); ?>
817 </label>&nbsp;&nbsp;&nbsp;&nbsp;
818 <label for="uam_redirect_custom_page">
819 <input type="radio" id="uam_redirect_custom_p" name="uam_redirect" value="custom_page" <?php if ($uamOptions['redirect'] == "custom_page") { _e('checked="checked"', "UserAccessManager"); }?>/>
820 <?php _e(TXT_REDIRECT_TO_PAGE, "UserAccessManager"); ?>
821 </label><input name="uam_redirect_custom_page" value="<?php _e($uamOptions['redirect_custom_page'], 'UserAccessManager') ?>" />&nbsp;&nbsp;&nbsp;&nbsp;
822 <label for="uam_redirect_custom_url">
823 <input type="radio" id="uam_redirect_custom_u" name="uam_redirect" value="custom_url" <?php if ($uamOptions['redirect'] == "custom_url") { _e('checked="checked"', "UserAccessManager"); }?>/>
824 <?php _e(TXT_REDIRECT_TO_URL, "UserAccessManager"); ?>
825 </label><input name="uam_redirect_custom_url" value="<?php _e($uamOptions['redirect_custom_url'], 'UserAccessManager') ?>" />
826 </p>
827 <h3><?php _e(TXT_LOCK_RECURSIVE, "UserAccessManager"); ?></h3>
828 <p><?php _e(TXT_LOCK_RECURSIVE_DESC, "UserAccessManager"); ?></p>
829 <p>
830 <label for="uam_lock_recursive_yes">
831 <input type="radio" id="uam_lock_recursive_yes" name="uam_lock_recursive" value="true" <?php if ($uamOptions['lock_recursive'] == "true") { _e('checked="checked"', "UserAccessManager"); }?> />
832 <?php _e(TXT_YES, "UserAccessManager"); ?>
833 </label>&nbsp;&nbsp;&nbsp;&nbsp;
834 <label for="uam_lock_recursive_no">
835 <input type="radio" id="uam_lock_recursive_no" name="uam_lock_recursive" value="false" <?php if ($uamOptions['lock_recursive'] == "false") { _e('checked="checked"', "UserAccessManager"); }?>/>
836 <?php _e(TXT_NO, "UserAccessManager"); ?>
837 </label>
838 </p>
839 <h3><?php _e(TXT_DOWNLOAD_TYPE, "UserAccessManager"); ?></h3>
840 <p><?php _e(TXT_DOWNLOAD_TYPE_DESC, "UserAccessManager"); ?></p>
841 <p>
842 <label for="uam_download_type_normal">
843 <input type="radio" id="uam_download_type_normal" name="uam_download_type" value="normal" <?php if ($uamOptions['download_type'] == "normal") { _e('checked="checked"', "UserAccessManager"); }?> />
844 <?php _e(TXT_NORMAL, "UserAccessManager"); ?>
845 </label>&nbsp;&nbsp;&nbsp;&nbsp;
846 <label for="uam_download_type_fopen">
847 <input type="radio" id="uam_download_type_fopen" name="uam_download_type" value="fopen" <?php if ($uamOptions['download_type'] == "fopen") { _e('checked="checked"', "UserAccessManager"); }?>/>
848 <?php _e(TXT_FOPEN, "UserAccessManager"); ?>
849 </label>
850 </p>
851 <div class="submit">
852 <input type="submit" name="update_uam_settings" value="<?php _e(TXT_UPDATE_SETTING, 'UserAccessManager') ?>" />
853 </div>
854 </form>
855 </div>
856 <?php
857 }
858 elseif($action == 'post_to_group')
859 {
860 $post_id = $_GET['id'];
861 $accessgroups = $wpdb->get_results("SELECT *
862 FROM ".DB_ACCESSGROUP."
863 ORDER BY groupname", ARRAY_A);
864
865 ?>
866 <div class=wrap>
867 <form method="post" action="<?php echo reset(explode("?", $_SERVER["REQUEST_URI"]))."?page=".$_GET['page']; ?>">
868 <input type="hidden" value="addgroup_to_post" name="action"/>
869 <input type="hidden" value="<?php echo $post_id; ?>" name="post_id"/>
870 <?php
871 if($cur_admin_page == 'uam_posts')
872 {
873 echo "<h2>";
874 _e(TXT_SET_POST_ACCESS, "UserAccessManager");
875 echo "</h2>";
876 }
877 elseif($cur_admin_page == 'uam_pages')
878 {
879 echo "<h2>";
880 _e(TXT_SET_PAGE_ACCESS, "UserAccessManager");
881 echo "</h2>";
882 }
883 ?>
884 <div class="postbox">
885 <h3><?php _e(TXT_GROUPS, "UserAccessManager"); ?></h3>
886 <div class="inside">
887 <?php
888 if($accessgroups)
889 {
890 foreach($accessgroups as $accessgroup)
891 {
892 $checked = $wpdb->get_results(" SELECT *
893 FROM ".DB_ACCESSGROUP_TO_POST."
894 WHERE post_id = ".$post_id."
895 AND group_id = ".$accessgroup['ID'], ARRAY_A)
896 ?>
897 <p>
898 <label class="selectit" for="comment_status">
899 <input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/>
900 <?php echo $accessgroup['groupname'] ?>
901 </label>
902 </p>
903 <?php
904 }
905 }
906 else
907 {
908 echo "<p>";
909 _e(TXT_CREATE_GROUP_FIRST, "UserAccessManager");
910 echo "</p>";
911 }
912 ?>
913 </div>
914 </div>
915 <p class="submit"><input type="submit" value="<?php _e(TXT_SET_ACCESS, "UserAccessManager"); ?>" name="submit" class="button"/></p>
916 </form>
917 </div>
918 <?php
919 }
920 elseif($action == 'user_to_group')
921 {
922 $user_id = $_GET['id'];
923 $accessgroups = $wpdb->get_results("SELECT *
924 FROM ".DB_ACCESSGROUP."
925 ORDER BY groupname", ARRAY_A);
926
927 ?>
928 <div class=wrap>
929 <form method="post" action="<?php echo reset(explode("?", $_SERVER["REQUEST_URI"]))."?page=".$_GET['page']; ?>">
930 <input type="hidden" value="addgroup_to_user" name="action"/>
931 <input type="hidden" value="<?php echo $user_id; ?>" name="user_id"/>
932 <h2><?php _e(TXT_SET_USER_ACCESS, "UserAccessManager"); ?></h2>
933 <div class="postbox">
934 <h3><?php _e(TXT_GROUPS, "UserAccessManager"); ?></h3>
935 <div class="inside">
936 <?php
937 if($accessgroups)
938 {
939 foreach($accessgroups as $accessgroup)
940 {
941 $checked = $wpdb->get_results(" SELECT *
942 FROM ".DB_ACCESSGROUP_TO_USER."
943 WHERE user_id = ".$user_id."
944 AND group_id = ".$accessgroup['ID'], ARRAY_A)
945 ?>
946 <p>
947 <label class="selectit" for="comment_status">
948 <input type="checkbox" <?php if($checked){ echo 'checked="checked"'; } ?>value="<?php echo $accessgroup['ID']; ?>" name="accessgroups[]"/>
949 <?php echo $accessgroup['groupname'] ?>
950 </label>
951 </p>
952 <?php
953 }
954 }
955 else
956 {
957 echo "<p>";
958 _e(TXT_CREATE_GROUP_FIRST, "UserAccessManager");
959 echo "</p>";
960 }
961 ?>
962 </div>
963 </div>
964 <p class="submit"><input type="submit" value="<?php _e(TXT_SET_ACCESS, "UserAccessManager"); ?>" name="submit" class="button"/></p>
965 </form>
966 </div>
967 <?php
968 }
969 elseif($action == 'edit_group')
970 {
971 $group_id = $_GET['id'];
972 $accessgroup = $wpdb->get_row(" SELECT *
973 FROM ".DB_ACCESSGROUP."
974 WHERE ID = ".$group_id."
975 LIMIT 1", ARRAY_A);
976 ?>
977 <div class=wrap>
978 <form method="post" action="<?php echo reset(explode("?", $_SERVER["REQUEST_URI"]))."?page=".$_GET['page']; ?>">
979 <input type="hidden" value="update_group" name="action"/>
980 <input type="hidden" value="<?php echo $group_id; ?>" name="access_group_id"/>
981 <table class="form-table">
982 <tbody>
983 <tr class="form-field form-required">
984 <th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_NAME, "UserAccessManager"); ?></label></th>
985 <td><input type="text" aria-required="true" size="40" value="<?php echo $accessgroup["groupname"];?>" id="access_group_name" name="access_group_name"/><br/>
986 <?php _e(TXT_GROUP_NAME_DESC, "UserAccessManager"); ?></td>
987 </tr>
988 <tr class="form-field form-required">
989 <th valign="top" scope="row"><label for="group_name"><?php _e(TXT_GROUP_DESC, "UserAccessManager"); ?></label></th>
990 <td><input type="text" aria-required="true" size="40" value="<?php echo $accessgroup["groupdesc"];?>" id="access_group_description" name="access_group_description"/><br/>
991 <?php _e(TXT_GROUP_DESC_DESC, "UserAccessManager"); ?></td>
992 </tr>
993 </tbody>
994 </table>
995 <p class="submit"><input type="submit" value="<?php _e(TXT_UPDATE_GROUP, "UserAccessManager"); ?>" name="submit" class="button"/></p>
996 </form>
997 </div>
998 <?php
999 }
1000 }//End function printAdminPage()
1001
1002 function check_access($post_id = null)
1003 {
1004 global $wpdb, $current_user;
1005
1006 $cur_post = get_post($post_id);
1007
1008 $uamOptions = $this->getAdminOptions();
1009
1010 if($uamOptions['lock_recursive'] == 'true')
1011 {
1012 $cur_id = $cur_post->ID;
1013 while($cur_id != 0)
1014 {
1015 $restricted_access = $wpdb->get_results(" SELECT *
1016 FROM ".DB_ACCESSGROUP_TO_POST."
1017 WHERE post_id = ".$cur_post->ID, ARRAY_A);
1018 if($restricted_access)
1019 break;
1020 else
1021 $cur_post = get_post($cur_id = $cur_post->post_parent);
1022 }
1023 }
1024 elseif($uamOptions['lock_recursive'] == 'false')
1025 {
1026 if( $cur_post->post_type != 'attachment')
1027 {
1028 $restricted_access = $wpdb->get_results(" SELECT *
1029 FROM ".DB_ACCESSGROUP_TO_POST."
1030 WHERE post_id = ".$cur_post->ID, ARRAY_A);
1031 }
1032 else
1033 {
1034 $restricted_access = $wpdb->get_results(" SELECT *
1035 FROM ".DB_ACCESSGROUP_TO_POST."
1036 WHERE post_id = ".$cur_post->post_parent, ARRAY_A);
1037 }
1038 }
1039
1040 if($restricted_access)
1041 {
1042 if (is_user_logged_in())
1043 {
1044 $cur_userdata = get_userdata($current_user->ID);
1045
1046 if($cur_userdata->wp_capabilities['administrator'] != 1)
1047 {
1048 $user_access = $wpdb->get_results(" SELECT *
1049 FROM ".DB_ACCESSGROUP_TO_POST." atp, ".DB_ACCESSGROUP_TO_USER." atu
1050 WHERE atp.post_id = ".$cur_post->ID."
1051 AND atp.group_id = atu.group_id
1052 AND atu.user_id = ".$current_user->ID, ARRAY_A);
1053
1054 if($user_access)
1055 return true;
1056 else
1057 return false;
1058 }
1059 else
1060 {
1061 return true;
1062 }
1063 }
1064 else
1065 {
1066 return false;
1067 }
1068 }
1069 else
1070 {
1071 return true;
1072 }
1073 }
1074
1075 function show_title($title = '')
1076 {
1077 $cur_post = get_post($dummy_id = null);
1078
1079 $uamOptions = $this->getAdminOptions();
1080
1081 // little hack nessesary because on single post it works on all
1082 if(!$this->check_access() && $title == $cur_post->post_title && $uamOptions['hide_title'] == 'true')
1083 $title = $uamOptions['post_title'];
1084
1085 return $title;
1086 }
1087
1088 function show_content($content = '')
1089 {
1090 $uamOptions = $this->getAdminOptions();
1091
1092 if(!$this->check_access())
1093 $content = $uamOptions['post_content'];
1094
1095 return $content;
1096 }
1097
1098 function show_post($posts = array())
1099 {
1100 $no_posts = count($posts);
1101
1102 for($i=0; $i < $no_posts; $i++)
1103 {
1104 if($this->check_access($posts[$i]->ID))
1105 $show_posts[] = $posts[$i];
1106 }
1107
1108 $posts = $show_posts;
1109
1110 return $posts;
1111 }
1112
1113 function exclude_page($page)
1114 {
1115 $pages = get_pages();
1116
1117 $excluded_pages = array(-1);
1118
1119 foreach($pages as $page)
1120 {
1121 if(!$this->check_access($page->ID))
1122 {
1123 $excluded_pages[] = $page->ID;
1124 }
1125 }
1126
1127 $page = $excluded_pages;
1128
1129 return $page;
1130 }
1131
1132 function redirect_user()
1133 {
1134 global $wp_query;
1135
1136 if(!$this->check_access() && $uamOptions['redirect'] != 'false')
1137 {
1138 $uamOptions = $this->getAdminOptions();
1139
1140 if($uamOptions['redirect'] == 'blog' || $uamOptions['redirect'] == 'custom_page')
1141 {
1142 $host = $_SERVER['HTTP_HOST'];
1143 $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
1144
1145 if($uamOptions['redirect'] == 'blog')
1146 $extra = '';
1147 elseif($uamOptions['redirect'] == 'custom_page')
1148 $extra = $uamOptions['redirect_custom_page'];
1149
1150 $url = "http://".$host.$uri."/".$extra;
1151 }
1152 elseif( $uamOptions['redirect'] == 'custom_url')
1153 {
1154 $url = $uamOptions['redirect_custom_url'];
1155 }
1156
1157
1158 $cur_posts = $wp_query->get_posts();
1159
1160 $post_to_show = false;
1161
1162 foreach($cur_posts as $cur_post)
1163 {
1164 if($this->check_access())
1165 {
1166 $post_to_show = true;
1167 break;
1168 }
1169 }
1170
1171 if($url != "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"] && !$post_to_show)
1172 {
1173 header("Location: $url");
1174 exit;
1175 }
1176 }
1177 elseif(isset($_GET['getfile']))
1178 {
1179 $cur_post = get_post($_GET['getfile']);
1180
1181 if ($cur_post->post_type == 'attachment' && $this->check_access($cur_post->ID))
1182 {
1183 $allowed_ext = array ( // archives
1184 'zip' => 'application/zip',
1185 'rar' => 'application/rar',
1186
1187 // documents
1188 'pdf' => 'application/pdf',
1189 'doc' => 'application/msword',
1190 'xls' => 'application/vnd.ms-excel',
1191 'ppt' => 'application/vnd.ms-powerpoint',
1192
1193 // executables
1194 'exe' => 'application/octet-stream',
1195
1196 // images
1197 'gif' => 'image/gif',
1198 'png' => 'image/png',
1199 'jpg' => 'image/jpeg',
1200 'jpeg' => 'image/jpeg',
1201
1202 // audio
1203 'mp3' => 'audio/mpeg',
1204 'wav' => 'audio/x-wav',
1205
1206 // video
1207 'mpeg' => 'video/mpeg',
1208 'mpg' => 'video/mpeg',
1209 'mpe' => 'video/mpeg',
1210 'mov' => 'video/quicktime',
1211 'avi' => 'video/x-msvideo'
1212 );
1213
1214 $file = str_replace("http://".$_SERVER['HTTP_HOST']."/", "", $cur_post->guid);
1215 $filename = basename($file);
1216 $fileext = strtolower(substr(strrchr($filename,"."),1));
1217
1218 if (file_exists($file))
1219 {
1220 $len = filesize($file);
1221 header('content-type: '.$allowed_ext[$fileext]);
1222 header('content-length: '.$len);
1223 header('content-disposition: attachment; filename='.basename($file));
1224
1225 if($uamOptions['download_type'] == 'fopen')
1226 {
1227 $fp=fopen($file, 'rb');
1228
1229 while ( ! feof($fp) )
1230 {
1231 set_time_limit(30);
1232 $buffer = fread($fp, 1024);
1233 echo $buffer;
1234 }
1235 exit;
1236 }
1237 else
1238 {
1239 readfile($file);
1240 exit;
1241 }
1242 }
1243 else
1244 {
1245 echo 'Error: File not found';
1246 }
1247 }
1248 }
1249 }
1250
1251 function get_file($URL, $attachment_ID = null)
1252 {
1253 $cur_post = get_post($ID = null);
1254 $cur_parent = get_post($cur_post->post_parent);
1255 if(strpos($cur_parent->guid, "?"))
1256 $char = "&";
1257 else
1258 $char = "?";
1259
1260 $URL = $cur_parent->guid.$char.'getfile='.$cur_post->ID;
1261
1262 return $URL;
1263 }
1264 }
1265
1266 } //End Class DevloungePluginSeries
1267
1268 if (class_exists("UserAccessManager"))
1269 {
1270 $userAccessManager = new UserAccessManager();
1271 }
1272
1273 //Initialize the admin panel
1274 if (!function_exists("UserAccessManager_AP")) {
1275 function UserAccessManager_AP()
1276 {
1277 global $userAccessManager;
1278 if (!isset($userAccessManager))
1279 {
1280 return;
1281 }
1282 if (function_exists('add_menu_page'))
1283 {
1284 add_menu_page('User Access Manager', 'Access Manager', 9, 'uam_posts', array(&$userAccessManager, 'printAdminPage'));
1285 }
1286 if (function_exists('add_submenu_page'))
1287 {
1288 add_submenu_page('uam_posts', TXT_MANAGE_POST, TXT_MANAGE_POST, 9, 'uam_posts', array(&$userAccessManager, 'printAdminPage'));
1289 add_submenu_page('uam_posts', TXT_MANAGE_PAGE, TXT_MANAGE_PAGE, 9, 'uam_pages', array(&$userAccessManager, 'printAdminPage'));
1290 add_submenu_page('uam_posts', TXT_MANAGE_USER, TXT_MANAGE_USER, 9, 'uam_users', array(&$userAccessManager, 'printAdminPage'));
1291 add_submenu_page('uam_posts', TXT_MANAGE_GROUP, TXT_MANAGE_GROUP, 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage'));
1292 add_submenu_page('uam_posts', TXT_SETTING, TXT_SETTINGS, 9, 'uam_settings', array(&$userAccessManager, 'printAdminPage'));
1293 }
1294 }
1295 }
1296
1297 //Actions and Filters
1298 if (isset($userAccessManager))
1299 {
1300 $uamOptions = $userAccessManager->getAdminOptions();
1301
1302 //install
1303 register_activation_hook(__FILE__, array(&$userAccessManager, 'install'));
1304 register_uninstall_hook(__FILE__, array(&$userAccessManager, 'uninstall'));
1305
1306 //Actions
1307 add_action('admin_menu', 'UserAccessManager_AP');
1308
1309 if($uamOptions['redirect'] != 'false' || isset($_GET['getfile']))
1310 add_action('template_redirect', array(&$userAccessManager, 'redirect_user'), 1);
1311
1312 //Filters
1313 add_filter('the_title', array(&$userAccessManager, 'show_title'), 1);
1314 add_filter('the_content', array(&$userAccessManager, 'show_content'), 1);
1315 add_filter('wp_get_attachment_url', array(&$userAccessManager, 'get_file'), 1);
1316
1317 if($uamOptions['hide_page'] == 'true')
1318 add_filter('wp_list_pages_excludes', array(&$userAccessManager, 'exclude_page'), 1);
1319
1320 if($uamOptions['hide_post'] == 'true')
1321 add_filter('the_posts', array(&$userAccessManager, 'show_post'), 1);
1322 }
1323
1324 ?>