| @@ -2,11 +2,11 @@ | ||
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: User Access Manager |
| 4 | 4 | Plugin URI: http://www.gm-alex.de/projects/wordpress/plugins/user-access-manager/ |
| 5 | 5 | Author URI: http://www.gm-alex.de/ |
| 6 | -Version: 0.9.1.2 | |
| 6 | +Version: 0.8.0.2 | |
| 7 | 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> | |
| 8 | +Description: Manage the access to your posts and pages. <strong>Note:</strong> <em>If you activate the plugin your upload dir will protect by a '.htaccess' with a random password and all old downloads insert in a previous post/page will not work anymore. You have to update your posts/pages. If you use already a '.htaccess' file to protect your files the plugin will <strong>overwrite</strong> the '.htaccess'. You can disabel the file locking and set up an other password for the '.htaccess' file at the UAM setting page.</em> | |
| 9 | 9 | |
| 10 | 10 | Copyright 2008 Alexander Schneider (email : alexanderschneider85 [at] gmail DOT com) |
| 11 | 11 | |
| 12 | 12 | This program is free software; you can redistribute it and/or modify |
| @@ -35,10 +35,11 @@ | ||
| 35 | 35 | define('DB_ACCESSGROUP_TO_ROLE', $wpdb->prefix.'uam_accessgroup_to_role'); |
| 36 | 36 | |
| 37 | 37 | //PATH |
| 38 | 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 | 39 | |
| 40 | +//###Lang### | |
| 41 | + | |
| 41 | 42 | if (!class_exists("UserAccessManager")) |
| 42 | 43 | { |
| 43 | 44 | class UserAccessManager |
| 44 | 45 | { |
| @@ -45,9 +46,8 @@ | ||
| 45 | 46 | var $adminOptionsName = "uamAdminOptions"; |
| 46 | 47 | var $atAdminPanel = false; |
| 47 | 48 | var $restrictedPost = array(); |
| 48 | 49 | var $postAccess = array(); |
| 49 | - var $postUserGroup = array(); | |
| 50 | 50 | var $uam_db_version = "1.1"; |
| 51 | 51 | var $adminOptions; |
| 52 | 52 | |
| 53 | 53 | function UserAccessManager() |
| @@ -68,11 +68,9 @@ | ||
| 68 | 68 | define('TXT_POST_TITLE_DESC', __('Displayed text as post title if user has no access', 'user-access-manager')); |
| 69 | 69 | define('TXT_DISPLAY_POST_TITLE', __('Hide post titel', 'user-access-manager')); |
| 70 | 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 | 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 <!--more--> tag', 'user-access-manager')); | |
| 74 | - define('TXT_SHOW_POST_CONTENT_BEFORE_MORE_DESC', sprintf(__('Shows the post content before the <!--more--> tag and after that the defined text at "%s". If no <!--more--> is set he defined text at "%s" will shown.', 'user-access-manager'), TXT_POST_CONTENT, TXT_POST_CONTENT)); | |
| 72 | + define('TXT_POST_CONTENT_DESC', __('Content displayed if user has no access', 'user-access-manager')); | |
| 75 | 73 | define('TXT_HIDE_POST', __('Hide complete posts', 'user-access-manager')); |
| 76 | 74 | define('TXT_HIDE_POST_DESC', __('Selecting "Yes" will hide posts if the user has no access.', 'user-access-manager')); |
| 77 | 75 | define('TXT_POST_COMMENT_CONTENT', __('Post commtent text', 'user-access-manager')); |
| 78 | 76 | define('TXT_POST_COMMENT_CONTENT_DESC', __('Displayed text as post comment text if user has no access', 'user-access-manager')); |
| @@ -87,9 +85,9 @@ | ||
| 87 | 85 | define('TXT_PAGE_TITLE_DESC', __('Displayed text as page title if user has no access', 'user-access-manager')); |
| 88 | 86 | define('TXT_DISPLAY_PAGE_TITLE', __('Hide page titel', 'user-access-manager')); |
| 89 | 87 | define('TXT_DISPLAY_PAGE_TITLE_DESC', sprintf(__('Selecting "Yes" will show the text which is defined at "%s" if user has no access.', 'user-access-manager'), TXT_POST_TITLE)); |
| 90 | 88 | 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')); | |
| 89 | + define('TXT_PAGE_CONTENT_DESC', __('Content displayed if user has no access', 'user-access-manager')); | |
| 92 | 90 | define('TXT_HIDE_PAGE', __('Hide complete pages', 'user-access-manager')); |
| 93 | 91 | define('TXT_HIDE_PAGE_DESC', __('Selecting "Yes" will hide pages if the user has no access. Pages will also hide in the navigation.', 'user-access-manager')); |
| 94 | 92 | |
| 95 | 93 | define('TXT_FILE_SETTING', __('File settings', 'user-access-manager')); |
| @@ -110,10 +108,8 @@ | ||
| 110 | 108 | define('TXT_FOPEN', __('fopen', 'user-access-manager')); |
| 111 | 109 | |
| 112 | 110 | define('TXT_OTHER_SETTING', __('Other settings', 'user-access-manager')); |
| 113 | 111 | 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 | 112 | define('TXT_HIDE_EMPTY_CATEGORIES', __('Hide empty categories', 'user-access-manager')); |
| 117 | 113 | define('TXT_HIDE_EMPTY_CATEGORIES_DESC', __('Selecting "Yes" will hide empty categories which are containing only empty childs or no childs.', 'user-access-manager')); |
| 118 | 114 | define('TXT_REDIRECT', __('Redirect user', 'user-access-manager')); |
| 119 | 115 | define('TXT_REDIRECT_DESC', __('Setup what happen if a user visit a post/page with no access.', 'user-access-manager')); |
| @@ -206,14 +202,8 @@ | ||
| 206 | 202 | define('TXT_COLLAPS', __('collaps', 'user-access-manager')); |
| 207 | 203 | define('TXT_COLLAPS_ALL', __('collaps all', 'user-access-manager')); |
| 208 | 204 | define('TXT_ALL', __('all', 'user-access-manager')); |
| 209 | 205 | define('TXT_ONLY_GROUP_USERS', __('only group users', 'user-access-manager')); |
| 210 | - | |
| 211 | - define('TXT_SETUP', __('Setup', 'user-access-manager')); | |
| 212 | - define('TXT_RESET_UAM', __('Reset User Access Manager', 'user-access-manager')); | |
| 213 | - define('TXT_RESET_UAM_DESC', __('Warning: The reset of the User Access Manager can not be undone. All settings and user groups will permanently lost.', 'user-access-manager')); | |
| 214 | - define('TXT_RESET', __('reset', 'user-access-manager')); | |
| 215 | - define('TXT_UAM_RESET_SUC', __('User Access Manager was reset successfully', 'user-access-manager')); | |
| 216 | 206 | } |
| 217 | 207 | |
| 218 | 208 | function install() |
| 219 | 209 | { |
| @@ -301,11 +291,8 @@ | ||
| 301 | 291 | global $wpdb; |
| 302 | 292 | $uam_db_version = $this->uam_db_version; |
| 303 | 293 | $installed_ver = get_option( "uam_db_version" ); |
| 304 | 294 | |
| 305 | - if(empty($installed_ver)) | |
| 306 | - $this->install(); | |
| 307 | - | |
| 308 | 295 | if($installed_ver != $uam_db_version) |
| 309 | 296 | { |
| 310 | 297 | if($installed_ver == '1.0') |
| 311 | 298 | { |
| @@ -316,14 +303,11 @@ | ||
| 316 | 303 | update_option("uam_db_version", $uam_db_version); |
| 317 | 304 | } |
| 318 | 305 | } |
| 319 | 306 | } |
| 320 | - if($wpdb->get_var("show tables like '".DB_ACCESSGROUP."'") == DB_ACCESSGROUP) | |
| 307 | + if($wpdb->get_var("show columns from ".DB_ACCESSGROUP." like 'ip_range'") != 'ip_range') | |
| 321 | 308 | { |
| 322 | - if($wpdb->get_var("show columns from ".DB_ACCESSGROUP." like 'ip_range'") != 'ip_range') | |
| 323 | - { | |
| 324 | - $wpdb->query("ALTER TABLE ".DB_ACCESSGROUP." ADD ip_range MEDIUMTEXT NULL DEFAULT ''"); | |
| 325 | - } | |
| 309 | + $wpdb->query("ALTER TABLE ".DB_ACCESSGROUP." ADD ip_range MEDIUMTEXT NULL DEFAULT ''"); | |
| 326 | 310 | } |
| 327 | 311 | } |
| 328 | 312 | |
| 329 | 313 | function uninstall() |
| @@ -329,10 +313,8 @@ | ||
| 329 | 313 | function uninstall() |
| 330 | 314 | { |
| 331 | 315 | global $wpdb; |
| 332 | 316 | $wpdb->query("DROP TABLE ".DB_ACCESSGROUP.", ".DB_ACCESSGROUP_TO_POST.", ".DB_ACCESSGROUP_TO_USER.", ".DB_ACCESSGROUP_TO_CATEGORY.", ".DB_ACCESSGROUP_TO_ROLE); |
| 333 | - delete_option($this->adminOptionsName); | |
| 334 | - delete_option("uam_db_version"); | |
| 335 | 317 | $this->delete_htaccess_files(); |
| 336 | 318 | } |
| 337 | 319 | |
| 338 | 320 | function deactivate() |
| @@ -508,11 +490,9 @@ | ||
| 508 | 490 | 'not_locked_file_types' => 'gif,jpg,jpeg,png', |
| 509 | 491 | 'blog_admin_hint' => 'true', |
| 510 | 492 | 'blog_admin_hint_text' => '[L]', |
| 511 | 493 | 'core_mod' => 'false', |
| 512 | - 'hide_empty_categories' => 'true', | |
| 513 | - 'protect_feed' => 'true', | |
| 514 | - 'show_post_content_before_more' => 'false'); | |
| 494 | + 'hide_empty_categories' => 'true'); | |
| 515 | 495 | |
| 516 | 496 | $uamOptions = get_option($this->adminOptionsName); |
| 517 | 497 | if (!empty($uamOptions)) { |
| 518 | 498 | foreach ($uamOptions as $key => $option) |
| @@ -540,12 +520,8 @@ | ||
| 540 | 520 | if (isset($_POST['uam_post_title'])) |
| 541 | 521 | { |
| 542 | 522 | $uamOptions['post_title'] = $_POST['uam_post_title']; |
| 543 | 523 | } |
| 544 | - if (isset($_POST['uam_show_post_content_before_more'])) | |
| 545 | - { | |
| 546 | - $uamOptions['show_post_content_before_more'] = $_POST['uam_show_post_content_before_more']; | |
| 547 | - } | |
| 548 | 524 | if (isset($_POST['uam_post_content'])) |
| 549 | 525 | { |
| 550 | 526 | $uamOptions['post_content'] = $_POST['uam_post_content']; |
| 551 | 527 | } |
| @@ -580,12 +556,8 @@ | ||
| 580 | 556 | if (isset($_POST['uam_hide_page'])) |
| 581 | 557 | { |
| 582 | 558 | $uamOptions['hide_page'] = $_POST['uam_hide_page']; |
| 583 | 559 | } |
| 584 | - if (isset($_POST['uam_protect_feed'])) | |
| 585 | - { | |
| 586 | - $uamOptions['protect_feed'] = $_POST['uam_protect_feed']; | |
| 587 | - } | |
| 588 | 560 | if (isset($_POST['uam_hide_empty_categories'])) |
| 589 | 561 | { |
| 590 | 562 | $uamOptions['hide_empty_categories'] = $_POST['uam_hide_empty_categories']; |
| 591 | 563 | } |
| @@ -829,25 +801,8 @@ | ||
| 829 | 801 | <div class="updated"><p><strong><?php echo TXT_ACCESS_GROUP_EDIT_SUC; ?></strong></p></div> |
| 830 | 802 | <?php |
| 831 | 803 | } |
| 832 | 804 | } |
| 833 | - | |
| 834 | - if($post_action == 'reset_uam') | |
| 835 | - { | |
| 836 | - if(isset($_POST['uam_reset'])) | |
| 837 | - $reset = $_POST['uam_reset']; | |
| 838 | - else | |
| 839 | - $reset = null; | |
| 840 | - | |
| 841 | - if($reset == 'true') | |
| 842 | - { | |
| 843 | - $this->uninstall(); | |
| 844 | - $this->install(); | |
| 845 | - ?> | |
| 846 | - <div class="updated"><p><strong><?php echo TXT_UAM_RESET_SUC; ?></strong></p></div> | |
| 847 | - <?php | |
| 848 | - } | |
| 849 | - } | |
| 850 | 805 | |
| 851 | 806 | if($cur_admin_page == 'uam_settings') |
| 852 | 807 | { |
| 853 | 808 | ?> |
| @@ -907,25 +862,8 @@ | ||
| 907 | 862 | </td> |
| 908 | 863 | </tr> |
| 909 | 864 | <tr valign="top"> |
| 910 | 865 | <th scope="row"> |
| 911 | - <?php echo TXT_SHOW_POST_CONTENT_BEFORE_MORE; ?> | |
| 912 | - </th> | |
| 913 | - <td> | |
| 914 | - <label for="uam_show_post_content_before_more_yes"> | |
| 915 | - <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"'; }?> /> | |
| 916 | - <?php echo TXT_YES; ?> | |
| 917 | - </label> | |
| 918 | - <label for="uam_show_post_content_before_more_no"> | |
| 919 | - <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"'; }?>/> | |
| 920 | - <?php echo TXT_NO; ?> | |
| 921 | - </label> | |
| 922 | - <br /> | |
| 923 | - <?php echo TXT_SHOW_POST_CONTENT_BEFORE_MORE_DESC; ?> | |
| 924 | - </td> | |
| 925 | - </tr> | |
| 926 | - <tr valign="top"> | |
| 927 | - <th scope="row"> | |
| 928 | 866 | <?php echo TXT_POST_CONTENT; ?> |
| 929 | 867 | </th> |
| 930 | 868 | <td> |
| 931 | 869 | <textarea name="uam_post_content" style="width: 80%; height: 100px;"><?php echo apply_filters('format_to_edit',$uamOptions['post_content']); ?></textarea> |
| @@ -1130,25 +1068,8 @@ | ||
| 1130 | 1068 | <table class="form-table"> |
| 1131 | 1069 | <tbody> |
| 1132 | 1070 | <tr> |
| 1133 | 1071 | <th> |
| 1134 | - <?php echo TXT_PROTECT_FEED; ?> | |
| 1135 | - </th> | |
| 1136 | - <td> | |
| 1137 | - <label for="uam_protect_feed_yes"> | |
| 1138 | - <input type="radio" id="uam_protect_feed_yes" name="uam_protect_feed" value="true" <?php if ($uamOptions['protect_feed'] == "true") { echo 'checked="checked"'; }?> /> | |
| 1139 | - <?php echo TXT_YES; ?> | |
| 1140 | - </label> | |
| 1141 | - <label for="uam_protect_feed_no"> | |
| 1142 | - <input type="radio" id="uam_protect_feed_no" name="uam_protect_feed" value="false" <?php if ($uamOptions['protect_feed'] == "false") { echo 'checked="checked"'; }?>/> | |
| 1143 | - <?php echo TXT_NO; ?> | |
| 1144 | - </label> | |
| 1145 | - <br /> | |
| 1146 | - <?php echo TXT_PROTECT_FEED_DESC; ?> | |
| 1147 | - </td> | |
| 1148 | - </tr> | |
| 1149 | - <tr> | |
| 1150 | - <th> | |
| 1151 | 1072 | <?php echo TXT_HIDE_EMPTY_CATEGORIES; ?> |
| 1152 | 1073 | </th> |
| 1153 | 1074 | <td> |
| 1154 | 1075 | <label for="uam_hide_empty_categories_yes"> |
| @@ -1455,40 +1376,8 @@ | ||
| 1455 | 1376 | <?php $this->get_print_edit_group(); ?> |
| 1456 | 1377 | </div> |
| 1457 | 1378 | <?php |
| 1458 | 1379 | } |
| 1459 | - elseif($cur_admin_page == 'uam_setup') | |
| 1460 | - { | |
| 1461 | - ?> | |
| 1462 | - <div class=wrap> | |
| 1463 | - <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>"> | |
| 1464 | - <input type="hidden" value="reset_uam" name="action"/> | |
| 1465 | - <h2><?php echo TXT_SETUP; ?></h2> | |
| 1466 | - <table class="form-table"> | |
| 1467 | - <tbody> | |
| 1468 | - <tr valign="top"> | |
| 1469 | - <th scope="row"> | |
| 1470 | - <?php echo TXT_RESET_UAM; ?> | |
| 1471 | - </th> | |
| 1472 | - <td> | |
| 1473 | - <label for="uam_reset_yes"> | |
| 1474 | - <input type="radio" id="uam_reset_yes" class="uam_reset_yes" name="uam_reset" value="true" /> | |
| 1475 | - <?php echo TXT_YES; ?> | |
| 1476 | - </label> | |
| 1477 | - <label for="uam_reset_no"> | |
| 1478 | - <input type="radio" id="uam_reset_no" class="uam_reset_no" name="uam_reset" value="false" checked="checked" /> | |
| 1479 | - <?php echo TXT_NO; ?> | |
| 1480 | - </label> <input type="submit" class="button" name="uam_reset_submit" value="<?php echo TXT_RESET; ?>" /> | |
| 1481 | - <br /> | |
| 1482 | - <p style="color:red; font-size: 12px; font-weight: bold;"><?php echo TXT_RESET_UAM_DESC; ?></p> | |
| 1483 | - </td> | |
| 1484 | - </tr> | |
| 1485 | - </tbody> | |
| 1486 | - </table> | |
| 1487 | - </form> | |
| 1488 | - </div> | |
| 1489 | - <?php | |
| 1490 | - } | |
| 1491 | 1380 | }//End function printAdminPage() |
| 1492 | 1381 | |
| 1493 | 1382 | function get_print_edit_group($group_id = null) |
| 1494 | 1383 | { |
| @@ -1828,11 +1717,8 @@ | ||
| 1828 | 1717 | function get_usergroups_for_post($ID) |
| 1829 | 1718 | { |
| 1830 | 1719 | global $wpdb; |
| 1831 | 1720 | |
| 1832 | - if(isset($this->postUserGroup[$ID])) | |
| 1833 | - return $this->postUserGroup[$ID]; | |
| 1834 | - | |
| 1835 | 1721 | $access = $this->get_access($ID); |
| 1836 | 1722 | |
| 1837 | 1723 | $post_usergroups = array(); |
| 1838 | 1724 | |
| @@ -1865,9 +1751,9 @@ | ||
| 1865 | 1751 | if(isset($cur_usergroup->posts)) |
| 1866 | 1752 | $posts = $cur_usergroup->posts; |
| 1867 | 1753 | |
| 1868 | 1754 | $lock_post = & get_post($cur_id); |
| 1869 | - $posts[$lock_post->ID] = $lock_post->ID; | |
| 1755 | + $posts[] = $lock_post->ID; | |
| 1870 | 1756 | $cur_usergroup->posts = $posts; |
| 1871 | 1757 | } |
| 1872 | 1758 | else |
| 1873 | 1759 | { |
| @@ -1905,9 +1791,9 @@ | ||
| 1905 | 1791 | if(isset($cur_usergroup->categorie)) |
| 1906 | 1792 | $categories = $cur_usergroup->categories; |
| 1907 | 1793 | |
| 1908 | 1794 | $lock_cat = & get_category($cur_id); |
| 1909 | - $categories[$lock_cat->term_id] = $lock_cat->term_id; | |
| 1795 | + $categories[] = $lock_cat->term_id; | |
| 1910 | 1796 | $cur_usergroup->categories = $categories; |
| 1911 | 1797 | |
| 1912 | 1798 | $post_usergroups[$usergroup['ID']] = $cur_usergroup; |
| 1913 | 1799 | } |
| @@ -1917,10 +1803,8 @@ | ||
| 1917 | 1803 | } |
| 1918 | 1804 | } |
| 1919 | 1805 | } |
| 1920 | 1806 | |
| 1921 | - $this->postUserGroup[$ID] = $post_usergroups; | |
| 1922 | - | |
| 1923 | 1807 | return $post_usergroups; |
| 1924 | 1808 | } |
| 1925 | 1809 | |
| 1926 | 1810 | function get_usergroup_info($groupid) |
| @@ -1939,8 +1823,13 @@ | ||
| 1939 | 1823 | FROM ".DB_ACCESSGROUP_TO_USER." |
| 1940 | 1824 | WHERE group_id = ".$groupid." |
| 1941 | 1825 | ORDER BY user_id", ARRAY_A); |
| 1942 | 1826 | |
| 1827 | + $db_posts = $wpdb->get_results(" SELECT * | |
| 1828 | + FROM ".DB_ACCESSGROUP_TO_POST." | |
| 1829 | + WHERE group_id = ".$groupid." | |
| 1830 | + ORDER BY post_id", ARRAY_A); | |
| 1831 | + | |
| 1943 | 1832 | $db_categories = $wpdb->get_results(" SELECT * |
| 1944 | 1833 | FROM ".DB_ACCESSGROUP_TO_CATEGORY." |
| 1945 | 1834 | WHERE group_id = ".$groupid." |
| 1946 | 1835 | ORDER BY category_id", ARRAY_A); |
| @@ -1953,52 +1842,32 @@ | ||
| 1953 | 1842 | FROM $wpdb->users |
| 1954 | 1843 | ORDER BY user_nicename", ARRAY_A); |
| 1955 | 1844 | |
| 1956 | 1845 | |
| 1957 | - $args = array( 'numberposts' => -1, | |
| 1958 | - 'post_type' => 'any'); | |
| 1959 | - | |
| 1960 | - $posts = get_posts($args); | |
| 1961 | - | |
| 1962 | - if(isset($posts)) | |
| 1846 | + if(isset($db_posts)) | |
| 1963 | 1847 | { |
| 1964 | - foreach($posts as $post) | |
| 1965 | - { | |
| 1966 | - $groupinfo = $this->get_usergroups_for_post($post->ID); | |
| 1848 | + foreach($db_posts as $db_post) | |
| 1849 | + { | |
| 1850 | + $cur_id = $db_post['post_id']; | |
| 1851 | + $cur_post = & get_post($cur_id); | |
| 1967 | 1852 | |
| 1968 | - if(isset($groupinfo[$groupid])) | |
| 1853 | + if(isset($cur_post->post_type)) | |
| 1969 | 1854 | { |
| 1970 | - if($post->post_type == 'post') | |
| 1855 | + if($cur_post->post_type == 'post') | |
| 1971 | 1856 | { |
| 1972 | - $info->posts[$post->ID] = $post; | |
| 1857 | + $info->posts[$cur_id] = $cur_post; | |
| 1973 | 1858 | } |
| 1974 | - elseif($post->post_type == 'page') | |
| 1859 | + elseif($cur_post->post_type == 'page') | |
| 1975 | 1860 | { |
| 1976 | - $info->pages[$post->ID] = $post; | |
| 1861 | + $info->pages[$cur_id] = $cur_post; | |
| 1977 | 1862 | } |
| 1978 | - elseif($post->post_type == 'attachment') | |
| 1863 | + elseif($cur_post->post_type == 'attachment') | |
| 1979 | 1864 | { |
| 1980 | - $info->files[$post->ID] = $post; | |
| 1865 | + $info->files[$cur_id] = $cur_post; | |
| 1981 | 1866 | } |
| 1982 | 1867 | } |
| 1983 | 1868 | } |
| 1984 | 1869 | } |
| 1985 | - | |
| 1986 | - $args = array( 'numberposts' => -1, | |
| 1987 | - 'post_type' => 'attachment'); | |
| 1988 | - | |
| 1989 | - $files = get_posts($args); | |
| 1990 | - | |
| 1991 | - if(isset($files)) | |
| 1992 | - { | |
| 1993 | - foreach($files as $file) | |
| 1994 | - { | |
| 1995 | - $groupinfo = $this->get_usergroups_for_post($file->ID); | |
| 1996 | - | |
| 1997 | - if(isset($groupinfo[$groupid])) | |
| 1998 | - $info->files[$file->ID] = $file; | |
| 1999 | - } | |
| 2000 | - } | |
| 2001 | 1870 | |
| 2002 | 1871 | if(isset($db_categories)) |
| 2003 | 1872 | { |
| 2004 | 1873 | foreach($db_categories as $db_categorie) |
| @@ -2062,8 +1931,142 @@ | ||
| 2062 | 1931 | } |
| 2063 | 1932 | } |
| 2064 | 1933 | } |
| 2065 | 1934 | |
| 1935 | + | |
| 1936 | + if(isset($info->categories)) | |
| 1937 | + { | |
| 1938 | + foreach($info->categories as $group_category) | |
| 1939 | + { | |
| 1940 | + $cur_posts = get_posts('category='.$group_category->term_id); | |
| 1941 | + if(isset($cur_posts)) | |
| 1942 | + { | |
| 1943 | + foreach($cur_posts as $cur_post) | |
| 1944 | + { | |
| 1945 | + if($uamOptions['lock_recursive'] == 'false') | |
| 1946 | + { | |
| 1947 | + $cur_categories = get_the_category($cur_post->ID); | |
| 1948 | + foreach($cur_categories as $cur_cat) | |
| 1949 | + { | |
| 1950 | + if($cur_cat->term_id == $group_category->term_id) | |
| 1951 | + { | |
| 1952 | + $add = true; | |
| 1953 | + break; | |
| 1954 | + } | |
| 1955 | + } | |
| 1956 | + } | |
| 1957 | + | |
| 1958 | + if(isset($add) || $uamOptions['lock_recursive'] == 'true') | |
| 1959 | + { | |
| 1960 | + if(isset($info->posts[$cur_post->ID])) | |
| 1961 | + $cur_post = $info->posts[$cur_post->ID]; | |
| 1962 | + | |
| 1963 | + $cur_post->recursive_lock_by_category[$group_category->term_id] = $group_category->term_id; | |
| 1964 | + $info->posts[$cur_post->ID] = $cur_post; | |
| 1965 | + } | |
| 1966 | + } | |
| 1967 | + } | |
| 1968 | + | |
| 1969 | + $cur_files = get_posts('category='.$group_category->term_id.'&post_type=attachment'); | |
| 1970 | + if(isset($cur_files)) | |
| 1971 | + { | |
| 1972 | + foreach($cur_files as $cur_file) | |
| 1973 | + { | |
| 1974 | + if($uamOptions['lock_recursive'] == 'false') | |
| 1975 | + { | |
| 1976 | + $cur_categories = get_the_category($cur_post->ID); | |
| 1977 | + foreach($cur_categories as $cur_cat) | |
| 1978 | + { | |
| 1979 | + if($cur_cat->term_id == $group_category->term_id) | |
| 1980 | + { | |
| 1981 | + $add = true; | |
| 1982 | + break; | |
| 1983 | + } | |
| 1984 | + } | |
| 1985 | + } | |
| 1986 | + | |
| 1987 | + if(isset($add) || $uamOptions['lock_recursive'] == 'true') | |
| 1988 | + { | |
| 1989 | + if(isset($info->files[$cur_file->ID])) | |
| 1990 | + $cur_file = $info->files[$cur_file->ID]; | |
| 1991 | + | |
| 1992 | + $cur_file->recursive_lock_by_category[$group_category->term_id] = $group_category->term_id; | |
| 1993 | + $info->files[$cur_file->ID] = $cur_file; | |
| 1994 | + } | |
| 1995 | + } | |
| 1996 | + } | |
| 1997 | + } | |
| 1998 | + } | |
| 1999 | + | |
| 2000 | + if(isset($info->posts)) | |
| 2001 | + { | |
| 2002 | + foreach($info->posts as $group_post) | |
| 2003 | + { | |
| 2004 | + if($uamOptions['lock_recursive'] == 'true') | |
| 2005 | + { | |
| 2006 | + $cur_posts = get_posts('post_parent='.$group_post->ID); | |
| 2007 | + if(isset($cur_posts)) | |
| 2008 | + { | |
| 2009 | + foreach($cur_posts as $cur_post) | |
| 2010 | + { | |
| 2011 | + if(isset($info->posts[$cur_post->ID])) | |
| 2012 | + $cur_post = $info->posts[$cur_post->ID]; | |
| 2013 | + | |
| 2014 | + $cur_post->recursive_lock_by_post[$group_post->ID] = $group_post->ID; | |
| 2015 | + $info->posts[$cur_post->ID] = $cur_post; | |
| 2016 | + } | |
| 2017 | + } | |
| 2018 | + } | |
| 2019 | + $cur_files = get_posts('post_parent='.$group_post->ID.'&post_type=attachment'); | |
| 2020 | + if(isset($cur_files)) | |
| 2021 | + { | |
| 2022 | + foreach($cur_files as $cur_file) | |
| 2023 | + { | |
| 2024 | + if(isset($info->files[$cur_file->ID])) | |
| 2025 | + $cur_file = $info->files[$cur_file->ID]; | |
| 2026 | + | |
| 2027 | + $cur_file->recursive_lock_by_post[$group_post->ID] = $group_post->ID; | |
| 2028 | + $info->files[$cur_file->ID] = $cur_file; | |
| 2029 | + } | |
| 2030 | + } | |
| 2031 | + } | |
| 2032 | + } | |
| 2033 | + | |
| 2034 | + if(isset($info->pages)) | |
| 2035 | + { | |
| 2036 | + foreach($info->pages as $group_page) | |
| 2037 | + { | |
| 2038 | + if($uamOptions['lock_recursive'] == 'true') | |
| 2039 | + { | |
| 2040 | + $cur_pages = get_pages('child_of='.$group_page->ID); | |
| 2041 | + if(isset($cur_pages)) | |
| 2042 | + { | |
| 2043 | + foreach($cur_pages as $cur_page) | |
| 2044 | + { | |
| 2045 | + if(isset($info->posts[$cur_post->ID])) | |
| 2046 | + $cur_post = $info->posts[$cur_post->ID]; | |
| 2047 | + | |
| 2048 | + $cur_post->recursive_lock_by_post[$group_page->ID] = $group_page->ID; | |
| 2049 | + $info->pages[$cur_page->ID] = $cur_page; | |
| 2050 | + } | |
| 2051 | + } | |
| 2052 | + } | |
| 2053 | + | |
| 2054 | + $cur_files = get_posts('post_parent='.$group_page->ID.'&post_type=attachment'); | |
| 2055 | + if(isset($cur_files)) | |
| 2056 | + { | |
| 2057 | + foreach($cur_files as $cur_file) | |
| 2058 | + { | |
| 2059 | + if(isset($info->files[$cur_file->ID])) | |
| 2060 | + $cur_file = $info->files[$cur_file->ID]; | |
| 2061 | + | |
| 2062 | + $cur_file->recursive_lock_by_post[$group_post->ID] = $group_post->ID; | |
| 2063 | + $info->files[$cur_file->ID] = $cur_file; | |
| 2064 | + } | |
| 2065 | + } | |
| 2066 | + } | |
| 2067 | + } | |
| 2068 | + | |
| 2066 | 2069 | return $info; |
| 2067 | 2070 | } |
| 2068 | 2071 | |
| 2069 | 2072 | function get_usergroup_info_html($group_id, $style = null) |
| @@ -2306,43 +2309,12 @@ | ||
| 2306 | 2309 | } |
| 2307 | 2310 | |
| 2308 | 2311 | function save_postdata($post_id) |
| 2309 | 2312 | { |
| 2310 | - global $current_user, $wpdb; | |
| 2311 | - $cur_userdata = get_userdata($current_user->ID); | |
| 2313 | + global $wpdb; | |
| 2314 | + if(isset($_POST['accessgroups'])) | |
| 2315 | + $accessgroups = $_POST['accessgroups']; | |
| 2312 | 2316 | |
| 2313 | - if(empty($cur_userdata->{$wpdb->prefix."capabilities"}['administrator'])) | |
| 2314 | - { | |
| 2315 | - $uamOptions = $this->getAdminOptions(); | |
| 2316 | - | |
| 2317 | - $cur_categories = wp_get_post_categories($post_id); | |
| 2318 | - | |
| 2319 | - $allowded_categories = get_categories(); | |
| 2320 | - | |
| 2321 | - foreach($cur_categories as $category) | |
| 2322 | - { | |
| 2323 | - foreach($allowded_categories as $allowded_category) | |
| 2324 | - { | |
| 2325 | - if($allowded_category->term_id == $category) | |
| 2326 | - { | |
| 2327 | - $post_categories[] = $allowded_category->term_id; | |
| 2328 | - break; | |
| 2329 | - } | |
| 2330 | - } | |
| 2331 | - } | |
| 2332 | - | |
| 2333 | - if(!isset($post_categories)) | |
| 2334 | - { | |
| 2335 | - $last_category = array_pop($allowded_categories); | |
| 2336 | - $post_categories[] = $last_category->term_id; | |
| 2337 | - } | |
| 2338 | - | |
| 2339 | - wp_set_post_categories($post_id, $post_categories); | |
| 2340 | - } | |
| 2341 | - | |
| 2342 | - if(isset($_POST['accessgroups'])) | |
| 2343 | - $accessgroups = $_POST['accessgroups']; | |
| 2344 | - | |
| 2345 | 2317 | $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_POST." WHERE post_id = $post_id"); |
| 2346 | 2318 | if(isset($accessgroups)) |
| 2347 | 2319 | { |
| 2348 | 2320 | foreach($accessgroups as $accessgroup) |
| @@ -2697,41 +2669,8 @@ | ||
| 2697 | 2669 | |
| 2698 | 2670 | $wpdb->query("DELETE FROM ".DB_ACCESSGROUP_TO_CATEGORY." WHERE category_id = $category_id"); |
| 2699 | 2671 | } |
| 2700 | 2672 | |
| 2701 | - function get_login_bar() | |
| 2702 | - { | |
| 2703 | - if(!is_user_logged_in()) | |
| 2704 | - { | |
| 2705 | - if(!is_single()) | |
| 2706 | - { | |
| 2707 | - $output = '<a href="'.get_bloginfo('wpurl').'/wp-login.php?redirect_to='.urlencode($_SERVER['REQUEST_URI']).'">'.__('Login', 'user-access-manager').'</a>'; | |
| 2708 | - } | |
| 2709 | - else | |
| 2710 | - { | |
| 2711 | - if(! isset ($user_login)) | |
| 2712 | - $user_login = ''; | |
| 2713 | - // login form | |
| 2714 | - $output = '<form action="'.get_bloginfo('wpurl').'/wp-login.php" method="post" >'; | |
| 2715 | - $output .= '<p><label for="user_login">'.__('Username:', 'user-access-manager').'<input name="log" value="'.wp_specialchars(stripslashes($user_login), 1).'" class="input" id="user_login" type="text" /></label></p>'; | |
| 2716 | - $output .= '<p><label for="user_pass">'.__('Password:', 'user-access-manager').'<input name="pwd" class="imput" id="user_pass" type="password" /></label></p>'; | |
| 2717 | - $output .= '<p class="forgetmenot"><label for="rememberme"><input name="rememberme" class="checkbox" id="rememberme" value="forever" type="checkbox" /> '. __('Remember me', 'user-access-manager').'</label></p>'; | |
| 2718 | - $output .= '<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="'.__('Login', 'user-access-manager').' »" />'; | |
| 2719 | - $output .= '<input type="hidden" name="redirect_to" value="' . $_SERVER['REQUEST_URI'] . '" />'; | |
| 2720 | - $output .= '</form>'; | |
| 2721 | - | |
| 2722 | - $output .= '<p>'; | |
| 2723 | - if (get_option('users_can_register')) | |
| 2724 | - $output .= '<a href="'.get_bloginfo('wpurl').'/wp-login.php?action=register">'.__('Register', 'user-access-manager').'</a></br>'; | |
| 2725 | - $output .= '<a href="'.get_bloginfo('wpurl').'/wp-login.php?action=lostpassword" title="'. __('Password Lost and Found', 'user-access-manager').'">'. __('Lost your password?', 'user-access-manager').'</a>'; | |
| 2726 | - $output .= '</p>'; | |
| 2727 | - } | |
| 2728 | - | |
| 2729 | - return $output; | |
| 2730 | - } | |
| 2731 | - return null; | |
| 2732 | - } | |
| 2733 | - | |
| 2734 | 2673 | function get_access($post_id = null) |
| 2735 | 2674 | { |
| 2736 | 2675 | global $wpdb; |
| 2737 | 2676 | |
| @@ -3058,63 +2997,47 @@ | ||
| 3058 | 2997 | { |
| 3059 | 2998 | $show_posts = null; |
| 3060 | 2999 | $uamOptions = $this->getAdminOptions(); |
| 3061 | 3000 | |
| 3062 | - if(!is_feed() || ($uamOptions['protect_feed'] == 'true' && is_feed())) | |
| 3001 | + foreach($posts as $post) | |
| 3063 | 3002 | { |
| 3064 | - foreach($posts as $post) | |
| 3003 | + if( ($uamOptions['hide_post'] == 'true' && $post->post_type == "post") || ($uamOptions['hide_page'] == 'true' && $post->post_type == "page") || $this->atAdminPanel) | |
| 3065 | 3004 | { |
| 3066 | - if( ($uamOptions['hide_post'] == 'true' && $post->post_type == "post") || ($uamOptions['hide_page'] == 'true' && $post->post_type == "page") || $this->atAdminPanel) | |
| 3005 | + if($this->check_access($post->ID)) | |
| 3067 | 3006 | { |
| 3068 | - if($this->check_access($post->ID)) | |
| 3007 | + $post->post_title .= $this->admin_output($post->ID); | |
| 3008 | + $show_posts[] = $post; | |
| 3009 | + } | |
| 3010 | + } | |
| 3011 | + else | |
| 3012 | + { | |
| 3013 | + if(!$this->check_access($post->ID)) | |
| 3014 | + { | |
| 3015 | + if($post->post_type == "post") | |
| 3069 | 3016 | { |
| 3070 | - $post->post_title .= $this->admin_output($post->ID); | |
| 3071 | - $show_posts[] = $post; | |
| 3017 | + if($uamOptions['hide_post_title'] == 'true') | |
| 3018 | + $post->post_title = $uamOptions['post_title']; | |
| 3019 | + | |
| 3020 | + $post->post_content = $uamOptions['post_content']; | |
| 3021 | + | |
| 3022 | + if($uamOptions['allow_comments_locked'] == 'false') | |
| 3023 | + $post->comment_status = 'close'; | |
| 3072 | 3024 | } |
| 3073 | - } | |
| 3074 | - else | |
| 3075 | - { | |
| 3076 | - if(!$this->check_access($post->ID)) | |
| 3025 | + elseif($post->post_type == "page") | |
| 3077 | 3026 | { |
| 3078 | - if($post->post_type == "post") | |
| 3079 | - { | |
| 3080 | - $uam_post_content = $uamOptions['post_content']; | |
| 3081 | - $uam_post_content = str_replace("[LOGIN_FORM]", $this->get_login_bar(), $uam_post_content); | |
| 3082 | - | |
| 3083 | - if($uamOptions['hide_post_title'] == 'true') | |
| 3084 | - $post->post_title = $uamOptions['post_title']; | |
| 3085 | - | |
| 3086 | - if($uamOptions['show_post_content_before_more'] == 'true' && preg_match('/<!--more(.*?)?-->/', $post->post_content, $matches)) | |
| 3087 | - { | |
| 3088 | - $post->post_content = explode($matches[0], $post->post_content, 2); | |
| 3089 | - $post->post_content = $post->post_content[0]." ".$uam_post_content; | |
| 3090 | - } | |
| 3091 | - else | |
| 3092 | - { | |
| 3093 | - $post->post_content = $uam_post_content; | |
| 3094 | - } | |
| 3095 | - | |
| 3096 | - if($uamOptions['allow_comments_locked'] == 'false') | |
| 3097 | - $post->comment_status = 'close'; | |
| 3098 | - } | |
| 3099 | - elseif($post->post_type == "page") | |
| 3100 | - { | |
| 3101 | - if($uamOptions['hide_page_title'] == 'true') | |
| 3102 | - $post->post_title = $uamOptions['page_title']; | |
| 3103 | - | |
| 3104 | - $uam_post_content = $uamOptions['page_content']; | |
| 3105 | - $uam_post_content = str_replace("[LOGIN_FORM]", $this->get_login_bar(), $uam_post_content); | |
| 3106 | - | |
| 3107 | - $post->post_content = $uam_post_content; | |
| 3108 | - } | |
| 3027 | + if($uamOptions['hide_page_title'] == 'true') | |
| 3028 | + $post->post_title = $uamOptions['page_title']; | |
| 3029 | + | |
| 3030 | + $post->post_content = $uamOptions['page_content']; | |
| 3109 | 3031 | } |
| 3110 | - $post->post_title .= $this->admin_output($post->ID); | |
| 3111 | - $show_posts[] = $post; | |
| 3112 | 3032 | } |
| 3033 | + $post->post_title .= $this->admin_output($post->ID); | |
| 3034 | + $show_posts[] = $post; | |
| 3113 | 3035 | } |
| 3036 | + } | |
| 3037 | + | |
| 3038 | + $posts = $show_posts; | |
| 3114 | 3039 | |
| 3115 | - $posts = $show_posts; | |
| 3116 | - } | |
| 3117 | 3040 | return $posts; |
| 3118 | 3041 | } |
| 3119 | 3042 | |
| 3120 | 3043 | function show_comment($comments = array()) |
| @@ -3123,9 +3046,9 @@ | ||
| 3123 | 3046 | $uamOptions = $this->getAdminOptions(); |
| 3124 | 3047 | |
| 3125 | 3048 | foreach($comments as $comment) |
| 3126 | 3049 | { |
| 3127 | - if($uamOptions['hide_post_comment'] == 'true' || $uamOptions['hide_post'] == 'true' ||$this->atAdminPanel) | |
| 3050 | + if($uamOptions['hide_post_comment'] == 'true' || $this->atAdminPanel) | |
| 3128 | 3051 | { |
| 3129 | 3052 | if($this->check_access($comment->comment_post_ID)) |
| 3130 | 3053 | { |
| 3131 | 3054 | $show_comments[] = $comment; |
| @@ -3184,53 +3107,75 @@ | ||
| 3184 | 3107 | function show_category($categories = array()) |
| 3185 | 3108 | { |
| 3186 | 3109 | global $current_user, $wpdb; |
| 3187 | 3110 | $cur_userdata = get_userdata($current_user->ID); |
| 3188 | - | |
| 3111 | + | |
| 3189 | 3112 | if(empty($cur_userdata->{$wpdb->prefix."capabilities"}['administrator'])) |
| 3190 | 3113 | { |
| 3191 | 3114 | $uamOptions = $this->getAdminOptions(); |
| 3192 | - | |
| 3193 | - if($this->atAdminPanel) | |
| 3115 | + if($uamOptions['hide_post'] == 'true' || $uamOptions['hide_page'] == 'true' || $this->atAdminPanel) | |
| 3194 | 3116 | { |
| 3195 | - $accesscategories = $wpdb->get_results("SELECT agtc.category_id | |
| 3196 | - FROM ".DB_ACCESSGROUP_TO_USER." agtu, ".DB_ACCESSGROUP_TO_CATEGORY." agtc | |
| 3197 | - WHERE agtu.user_id = ".$current_user->ID." | |
| 3198 | - AND agtu.group_id = agtc.group_id", ARRAY_A); | |
| 3117 | + $args = array( 'numberposts' => -1); | |
| 3118 | + $posts = get_posts($args); | |
| 3199 | 3119 | |
| 3200 | - if(isset($accesscategories)) | |
| 3120 | + foreach($categories as $category) | |
| 3201 | 3121 | { |
| 3202 | - foreach($accesscategories as $accesscategory) | |
| 3203 | - { | |
| 3204 | - foreach($categories as $category) | |
| 3122 | + $count = 0; | |
| 3123 | + | |
| 3124 | + if(isset($posts)) | |
| 3125 | + { | |
| 3126 | + foreach($posts as $cur_post) | |
| 3205 | 3127 | { |
| 3206 | - if($accesscategory['category_id'] == $category->term_id) | |
| 3128 | + $post_cat_ids = array(); | |
| 3129 | + $post_cats = get_the_category($cur_post->ID); | |
| 3130 | + foreach($post_cats as $post_cat) | |
| 3207 | 3131 | { |
| 3208 | - $show_categories[$category->term_id] = $category; | |
| 3209 | - | |
| 3210 | - if(isset($empty_categories[$category->term_id])) | |
| 3211 | - unset($empty_categories[$category->term_id]); | |
| 3132 | + $post_cat_ids[] = $post_cat->term_id; | |
| 3212 | 3133 | } |
| 3213 | - else | |
| 3134 | + | |
| 3135 | + if(in_array($category->term_id, $post_cat_ids) ) | |
| 3214 | 3136 | { |
| 3215 | - if(empty($show_categories[$category->term_id])) | |
| 3216 | - $empty_categories[$category->term_id] = $category; | |
| 3137 | + if( ($uamOptions['hide_post'] == 'true' && $cur_post->post_type == "post") || ($uamOptions['hide_page'] == 'true' && $cur_post->post_type == "page") ) | |
| 3138 | + { | |
| 3139 | + if($this->check_access($cur_post->ID)) | |
| 3140 | + $count++; | |
| 3141 | + } | |
| 3142 | + else | |
| 3143 | + { | |
| 3144 | + $count++; | |
| 3145 | + } | |
| 3217 | 3146 | } |
| 3218 | 3147 | } |
| 3219 | 3148 | } |
| 3220 | 3149 | |
| 3221 | - if(isset($empty_categories) && $uamOptions['lock_recursive'] == 'true') | |
| 3150 | + if($count != 0 || $uamOptions['hide_empty_categories'] == 'false') | |
| 3222 | 3151 | { |
| 3223 | - foreach($empty_categories as $empty_category) | |
| 3152 | + $category->count = $count; | |
| 3153 | + $cur_show_categories[$category->term_id] = $category; | |
| 3154 | + } | |
| 3155 | + elseif($category->taxonomy == "link_category" || $category->taxonomy == "post_tag") | |
| 3156 | + { | |
| 3157 | + $show_categories[] = $category; | |
| 3158 | + } | |
| 3159 | + elseif($count == 0) | |
| 3160 | + { | |
| 3161 | + $empty_categories[$category->term_id] = $category; | |
| 3162 | + } | |
| 3163 | + } | |
| 3164 | + | |
| 3165 | + if($uamOptions['hide_empty_categories'] == 'true') | |
| 3166 | + { | |
| 3167 | + if(isset($cur_show_categories)) | |
| 3168 | + { | |
| 3169 | + foreach($cur_show_categories as $cur_show_category) | |
| 3224 | 3170 | { |
| 3225 | - $cur_cat = $empty_category; | |
| 3226 | - while($cur_cat->parent != 0 && isset($show_categories)) | |
| 3171 | + $show_categories[$cur_show_category->term_id] = $cur_show_category; | |
| 3172 | + | |
| 3173 | + $cur_cat = $cur_show_category; | |
| 3174 | + while($cur_cat->parent != 0 && isset($empty_categories)) | |
| 3227 | 3175 | { |
| 3228 | - if(isset($show_categories[$cur_cat->parent])) | |
| 3229 | - { | |
| 3230 | - $show_categories[$empty_category->term_id] = $empty_category; | |
| 3231 | - break; | |
| 3232 | - } | |
| 3176 | + if(empty($show_categories[$cur_cat->parent])) | |
| 3177 | + $show_categories[$cur_cat->parent] = $empty_categories[$cur_cat->parent]; | |
| 3233 | 3178 | |
| 3234 | 3179 | $cur_id = $cur_cat->parent; |
| 3235 | 3180 | $cur_cat = & get_category($cur_id); |
| 3236 | 3181 | } |
| @@ -3242,107 +3187,8 @@ | ||
| 3242 | 3187 | $categories = $show_categories; |
| 3243 | 3188 | else |
| 3244 | 3189 | $categories = null; |
| 3245 | 3190 | } |
| 3246 | - else | |
| 3247 | - { | |
| 3248 | - if($uamOptions['hide_post'] == 'true' || $uamOptions['hide_page'] == 'true') | |
| 3249 | - { | |
| 3250 | - $args = array( 'numberposts' => -1); | |
| 3251 | - $posts = get_posts($args); | |
| 3252 | - | |
| 3253 | - foreach($categories as $category) | |
| 3254 | - { | |
| 3255 | - $count = 0; | |
| 3256 | - | |
| 3257 | - if(isset($posts)) | |
| 3258 | - { | |
| 3259 | - foreach($posts as $cur_post) | |
| 3260 | - { | |
| 3261 | - $post_cat_ids = array(); | |
| 3262 | - $post_cats = get_the_category($cur_post->ID); | |
| 3263 | - foreach($post_cats as $post_cat) | |
| 3264 | - { | |
| 3265 | - $post_cat_ids[] = $post_cat->term_id; | |
| 3266 | - } | |
| 3267 | - | |
| 3268 | - if(in_array($category->term_id, $post_cat_ids) ) | |
| 3269 | - { | |
| 3270 | - if( ($uamOptions['hide_post'] == 'true' && $cur_post->post_type == "post") || ($uamOptions['hide_page'] == 'true' && $cur_post->post_type == "page")) | |
| 3271 | - { | |
| 3272 | - if($this->check_access($cur_post->ID)) | |
| 3273 | - $count++; | |
| 3274 | - } | |
| 3275 | - else | |
| 3276 | - { | |
| 3277 | - $count++; | |
| 3278 | - } | |
| 3279 | - } | |
| 3280 | - } | |
| 3281 | - } | |
| 3282 | - | |
| 3283 | - if(($count != 0 || ($uamOptions['hide_empty_categories'] == 'false' && !$this->atAdminPanel ))) | |
| 3284 | - { | |
| 3285 | - $category->count = $count; | |
| 3286 | - $cur_show_categories[$category->term_id] = $category; | |
| 3287 | - } | |
| 3288 | - elseif($category->taxonomy == "link_category" || $category->taxonomy == "post_tag") | |
| 3289 | - { | |
| 3290 | - $show_categories[$category->term_id] = $category; | |
| 3291 | - } | |
| 3292 | - elseif($count == 0) | |
| 3293 | - { | |
| 3294 | - $category->count = $count; | |
| 3295 | - $empty_categories[$category->term_id] = $category; | |
| 3296 | - } | |
| 3297 | - } | |
| 3298 | - | |
| 3299 | - if($uamOptions['hide_empty_categories'] == 'true') | |
| 3300 | - { | |
| 3301 | - if(isset($cur_show_categories)) | |
| 3302 | - { | |
| 3303 | - foreach($cur_show_categories as $cur_show_category) | |
| 3304 | - { | |
| 3305 | - $cur_count = $cur_show_category->count; | |
| 3306 | - $show_categories[$cur_show_category->term_id] = $cur_show_category; | |
| 3307 | - | |
| 3308 | - $cur_cat = $cur_show_category; | |
| 3309 | - while($cur_cat->parent != 0 && isset($empty_categories)) | |
| 3310 | - { | |
| 3311 | - if(empty($show_categories[$cur_cat->parent])) | |
| 3312 | - { | |
| 3313 | - if(isset( $empty_categories[$cur_cat->parent])) | |
| 3314 | - { | |
| 3315 | - $cur_empty_cat = $empty_categories[$cur_cat->parent]; | |
| 3316 | - $cur_empty_cat->count = $cur_count; | |
| 3317 | - $show_categories[$cur_cat->parent] = $cur_empty_cat; | |
| 3318 | - } | |
| 3319 | - } | |
| 3320 | - | |
| 3321 | - $cur_id = $cur_cat->parent; | |
| 3322 | - $cur_cat = & get_category($cur_id); | |
| 3323 | - } | |
| 3324 | - } | |
| 3325 | - } | |
| 3326 | - } | |
| 3327 | - else | |
| 3328 | - { | |
| 3329 | - if(isset($cur_show_categories)) | |
| 3330 | - { | |
| 3331 | - foreach($cur_show_categories as $cur_show_category) | |
| 3332 | - { | |
| 3333 | - $show_categories[$cur_show_category->term_id] = $cur_show_category; | |
| 3334 | - } | |
| 3335 | - } | |
| 3336 | - } | |
| 3337 | - | |
| 3338 | - if(isset($show_categories)) | |
| 3339 | - $categories = $show_categories; | |
| 3340 | - else | |
| 3341 | - $categories = null; | |
| 3342 | - } | |
| 3343 | - } | |
| 3344 | - | |
| 3345 | 3191 | } |
| 3346 | 3192 | |
| 3347 | 3193 | return $categories; |
| 3348 | 3194 | } |
| @@ -3369,50 +3215,22 @@ | ||
| 3369 | 3215 | function show_next_previous_post($sql) |
| 3370 | 3216 | { |
| 3371 | 3217 | $uamOptions = $this->getAdminOptions(); |
| 3372 | 3218 | |
| 3373 | - if($uamOptions['hide_post'] == 'true') | |
| 3219 | + $posts = get_posts(); | |
| 3220 | + if(isset($posts)) | |
| 3374 | 3221 | { |
| 3375 | - $posts = get_posts(); | |
| 3376 | - if(isset($posts)) | |
| 3222 | + foreach($posts as $post) | |
| 3377 | 3223 | { |
| 3378 | - foreach($posts as $post) | |
| 3379 | - { | |
| 3380 | - if(!$this->check_access($post->ID)) | |
| 3381 | - $excluded_posts[] = $post->ID; | |
| 3382 | - } | |
| 3383 | - if(isset($excluded_posts)) | |
| 3384 | - { | |
| 3385 | - $excluded_posts_str = implode(",", $excluded_posts); | |
| 3386 | - $sql .= "AND ID NOT IN($excluded_posts_str)"; | |
| 3387 | - } | |
| 3388 | - } | |
| 3389 | - } | |
| 3390 | - | |
| 3391 | - return $sql; | |
| 3392 | - } | |
| 3393 | - | |
| 3394 | - function show_post_sql($sql) | |
| 3395 | - { | |
| 3396 | - $uamOptions = $this->getAdminOptions(); | |
| 3397 | - | |
| 3398 | - if(($uamOptions['hide_post'] == 'true' && !is_feed()) || (is_feed() && $uamOptions['protect_feed'] == 'true')) | |
| 3399 | - { | |
| 3400 | - $posts = get_posts(); | |
| 3401 | - if(isset($posts)) | |
| 3224 | + if(!$this->check_access($post->ID)) | |
| 3225 | + $excluded_posts[] = $post->ID; | |
| 3226 | + } | |
| 3227 | + if(isset($excluded_posts)) | |
| 3402 | 3228 | { |
| 3403 | - foreach($posts as $post) | |
| 3404 | - { | |
| 3405 | - if(!$this->check_access($post->ID)) | |
| 3406 | - $excluded_posts[] = $post->ID; | |
| 3407 | - } | |
| 3408 | - if(isset($excluded_posts)) | |
| 3409 | - { | |
| 3410 | - $excluded_posts_str = implode(",", $excluded_posts); | |
| 3411 | - $sql .= "AND ID NOT IN($excluded_posts_str)"; | |
| 3412 | - } | |
| 3413 | - } | |
| 3414 | - } | |
| 3229 | + $excluded_posts_str = implode(",", $excluded_posts); | |
| 3230 | + $sql .= "AND ID NOT IN($excluded_posts_str)"; | |
| 3231 | + } | |
| 3232 | + } | |
| 3415 | 3233 | |
| 3416 | 3234 | return $sql; |
| 3417 | 3235 | } |
| 3418 | 3236 | |
| @@ -3491,11 +3309,12 @@ | ||
| 3491 | 3309 | $cur_post = & get_post($cur_id); |
| 3492 | 3310 | |
| 3493 | 3311 | if($cur_post->post_type == 'attachment' && $this->check_access($cur_post->ID)) |
| 3494 | 3312 | { |
| 3495 | - $file = str_replace(get_option('siteurl').'/', "", $cur_post->guid); | |
| 3313 | + $cur_url = explode("?", "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); | |
| 3314 | + $file = str_replace($cur_url[0], "", $cur_post->guid); | |
| 3496 | 3315 | $filename = basename($file); |
| 3497 | - | |
| 3316 | + | |
| 3498 | 3317 | if(file_exists($file)) |
| 3499 | 3318 | { |
| 3500 | 3319 | $len = filesize($file); |
| 3501 | 3320 | header('content-type: '.$cur_post->post_mime_type); |
| @@ -3534,9 +3353,10 @@ | ||
| 3534 | 3353 | } |
| 3535 | 3354 | } |
| 3536 | 3355 | elseif(wp_attachment_is_image($cur_id)) |
| 3537 | 3356 | { |
| 3538 | - $file = UAM_URLPATH .'gfx/no_access_pic.png'; | |
| 3357 | + $cur_url = explode("?", "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); | |
| 3358 | + $file = str_replace($cur_url[0], "", UAM_URLPATH .'gfx/no_access_pic.png'); | |
| 3539 | 3359 | $filename = basename($file); |
| 3540 | 3360 | |
| 3541 | 3361 | if(file_exists($file)) |
| 3542 | 3362 | { |
| @@ -3573,9 +3393,9 @@ | ||
| 3573 | 3393 | $file_types = explode(",", $file_types); |
| 3574 | 3394 | |
| 3575 | 3395 | if(in_array($type, $file_types) || $uamOptions['lock_file_types'] == 'all') |
| 3576 | 3396 | { |
| 3577 | - $cur_guid = get_bloginfo('url'); | |
| 3397 | + $cur_guid = get_option('siteurl'); | |
| 3578 | 3398 | |
| 3579 | 3399 | $URL = $cur_guid.'?getfile='.$cur_post->ID; |
| 3580 | 3400 | } |
| 3581 | 3401 | } |
| @@ -3592,9 +3412,9 @@ | ||
| 3592 | 3412 | //Initialize the admin panel |
| 3593 | 3413 | if(!function_exists("UserAccessManager_AP")) { |
| 3594 | 3414 | function UserAccessManager_AP() |
| 3595 | 3415 | { |
| 3596 | - global $userAccessManager, $wp_version, $current_user, $wpdb; | |
| 3416 | + global $userAccessManager, $wp_version; | |
| 3597 | 3417 | |
| 3598 | 3418 | $userAccessManager->atAdminPanel = true; |
| 3599 | 3419 | |
| 3600 | 3420 | if (!isset($userAccessManager)) |
| @@ -3602,29 +3422,21 @@ | ||
| 3602 | 3422 | return; |
| 3603 | 3423 | } |
| 3604 | 3424 | if (function_exists('add_menu_page')) |
| 3605 | 3425 | { |
| 3606 | - add_menu_page('User Access Manager', 'UAM', 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage'), UAM_URLPATH."gfx/icon.png"); | |
| 3426 | + add_menu_page('User Access Manager', 'Access Manager', 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage'), UAM_URLPATH."/gfx/icon.png"); | |
| 3607 | 3427 | } |
| 3608 | 3428 | if (function_exists('add_submenu_page')) |
| 3609 | 3429 | { |
| 3610 | 3430 | add_submenu_page('uam_usergroup', TXT_MANAGE_GROUP, TXT_MANAGE_GROUP, 9, 'uam_usergroup', array(&$userAccessManager, 'printAdminPage')); |
| 3611 | 3431 | add_submenu_page('uam_usergroup', TXT_SETTINGS, TXT_SETTINGS, 9, 'uam_settings', array(&$userAccessManager, 'printAdminPage')); |
| 3612 | - add_submenu_page('uam_usergroup', TXT_SETUP, TXT_SETUP, 9, 'uam_setup', array(&$userAccessManager, 'printAdminPage')); | |
| 3613 | 3432 | } |
| 3614 | 3433 | if( function_exists( 'add_meta_box' )) |
| 3615 | 3434 | { |
| 3616 | - get_currentuserinfo(); | |
| 3617 | - $cur_userdata = get_userdata($current_user->ID); | |
| 3618 | - | |
| 3619 | - if(isset($cur_userdata->{$wpdb->prefix."capabilities"}['administrator'])) | |
| 3620 | - { | |
| 3621 | - add_meta_box( 'uma_post_access', 'Access', array(&$userAccessManager, 'edit_post_content'), 'post', 'side' ); | |
| 3622 | - add_meta_box( 'uma_post_access', 'Access', array(&$userAccessManager, 'edit_post_content'), 'page', 'side' ); | |
| 3623 | - } | |
| 3435 | + add_meta_box( 'uma_post_access', 'Access', array(&$userAccessManager, 'edit_post_content'), 'post', 'side' ); | |
| 3436 | + add_meta_box( 'uma_post_access', 'Access', array(&$userAccessManager, 'edit_post_content'), 'page', 'side' ); | |
| 3624 | 3437 | } |
| 3625 | 3438 | |
| 3626 | - | |
| 3627 | 3439 | //Admin actions |
| 3628 | 3440 | |
| 3629 | 3441 | $userAccessManager->update(); |
| 3630 | 3442 | |
| @@ -3649,9 +3461,8 @@ | ||
| 3649 | 3461 | add_action('wp_print_styles', array(&$userAccessManager, 'add_styles') ); |
| 3650 | 3462 | |
| 3651 | 3463 | |
| 3652 | 3464 | //Admin filters |
| 3653 | - | |
| 3654 | 3465 | add_filter('manage_posts_columns', array(&$userAccessManager, 'add_post_columns_header')); |
| 3655 | 3466 | add_filter('manage_pages_columns', array(&$userAccessManager, 'add_post_columns_header')); |
| 3656 | 3467 | |
| 3657 | 3468 | $uamOptions = $userAccessManager->getAdminOptions(); |
| @@ -3676,9 +3487,9 @@ | ||
| 3676 | 3487 | if(isset($userAccessManager)) |
| 3677 | 3488 | { |
| 3678 | 3489 | add_action('init', array(&$userAccessManager, 'init')); |
| 3679 | 3490 | $uamOptions = $userAccessManager->getAdminOptions(); |
| 3680 | - | |
| 3491 | + | |
| 3681 | 3492 | //install |
| 3682 | 3493 | if(function_exists('register_activation_hook')) |
| 3683 | 3494 | register_activation_hook(__FILE__, array(&$userAccessManager, 'install')); |
| 3684 | 3495 | |
| @@ -3688,9 +3499,9 @@ | ||
| 3688 | 3499 | register_deactivation_hook(__FILE__, array(&$userAccessManager, 'uninstall')); |
| 3689 | 3500 | |
| 3690 | 3501 | if(function_exists('register_deactivation_hook')) |
| 3691 | 3502 | register_deactivation_hook(__FILE__, array(&$userAccessManager, 'deactivate')); |
| 3692 | - | |
| 3503 | + | |
| 3693 | 3504 | //Actions |
| 3694 | 3505 | add_action('admin_menu', 'UserAccessManager_AP'); |
| 3695 | 3506 | |
| 3696 | 3507 | if($uamOptions['redirect'] != 'false' || isset($_GET['getfile'])) |
| @@ -3705,7 +3516,7 @@ | ||
| 3705 | 3516 | add_filter('get_next_post_where', array(&$userAccessManager, 'show_next_previous_post')); |
| 3706 | 3517 | add_filter('get_previous_post_where', array(&$userAccessManager, 'show_next_previous_post')); |
| 3707 | 3518 | add_filter('get_previous_post_where', array(&$userAccessManager, 'show_next_previous_post')); |
| 3708 | 3519 | add_filter('the_title', array(&$userAccessManager, 'show_title'), 10, 2); |
| 3709 | - add_filter('posts_where', array(&$userAccessManager, 'show_post_sql')); | |
| 3710 | 3520 | } |
| 3711 | -?> | |
| 3521 | + | |
| 3522 | +?> | |