Changeset 908442
- Timestamp:
- 05/05/2014 07:54:17 PM (12 years ago)
- Location:
- simple-permissions
- Files:
-
- 2 edited
- 3 copied
-
tags/1.0.2 (copied) (copied from simple-permissions/trunk)
-
tags/1.0.2/readme.txt (copied) (copied from simple-permissions/trunk/readme.txt) (3 diffs)
-
tags/1.0.2/simple-permissions.php (copied) (copied from simple-permissions/trunk/simple-permissions.php) (17 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/simple-permissions.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-permissions/tags/1.0.2/readme.txt
r901673 r908442 5 5 Requires at least: 3.5.2 6 6 Tested up to: 3.8.3 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 35 35 == Changelog == 36 36 37 = 1.0.2 = 38 * Fixed big bug that prevented editing of posts that had no permissions set. 39 37 40 = 1.0.1 = 38 41 * Fixed issue with some extra whitespace killing feeds … … 43 46 == Upgrade Notice == 44 47 48 = 1.0.2 = 49 * Everyone should update. -
simple-permissions/tags/1.0.2/simple-permissions.php
r901673 r908442 2 2 /** 3 3 * @package Simple-Permissions 4 * @version 1.0. 14 * @version 1.0.2 5 5 */ 6 6 /* … … 9 9 Description: Create simple permission groups for reading or editing posts. 10 10 Author: Michael George 11 Version: 1.0. 111 Version: 1.0.2 12 12 13 13 This program is free software; you can redistribute it and/or modify … … 124 124 //Returns array (group/user id int, group/user name str, permission str) 125 125 function spGetPermissions( $post_id ) { 126 //echo "In spGetPermissions with post id: $post_id.<br>";127 126 $devOptions = $this->spGetAdminOptions(); 128 127 $readGroups = get_post_meta( $post_id, 'simplePermissions_readGroupIDs' ); 129 128 $writeGroups = get_post_meta( $post_id, 'simplePermissions_writeGroupIDs' ); 130 //print_r( $readGroups );131 //print_r( get_post_meta( $post_id, 'simplePermissions_readGroupIDs', true ) );132 129 133 130 $returnValue = array(); … … 150 147 } 151 148 if ( ! count( $returnValue ) > 0 ) { 152 $returnValue[] = array( "id" => 0, "name" => "public", "permission" => " read" );149 $returnValue[] = array( "id" => 0, "name" => "public", "permission" => "write" ); 153 150 } 154 151 … … 163 160 // [2] Associated object ID 164 161 function spUserCanDo( $allcaps, $cap, $args ) { 165 //echo "<!-- in spUserCanDo -->\r";166 $protectedOperations = array('delete_page'162 $protectedOperations = array( 163 'delete_page' 167 164 ,'delete_post' 168 ,'edit_comment'169 165 ,'edit_page' 170 166 ,'edit_post' … … 190 186 191 187 //set the cap to false until we prove it's true 192 unset( $allcaps[$cap[0]] ); 193 194 $permissions = $this->spGetPermissions( $args[2] ); 188 foreach ( $cap as $thiscap ) { 189 unset( $allcaps[$thiscap] ); 190 } 191 192 $groupPermissions = $this->spGetPermissions( $args[2] ); 195 193 $devOptions = $this->spGetAdminOptions(); 196 $groupPermissions = array();197 foreach ( $permissions as $permission ) {198 $groupPermissions[] = $permission;199 }200 194 201 195 if ( count( $groupPermissions ) > 0 ) { 202 196 foreach ( $groupPermissions as $perm ) { 203 if ( in_array( $ args[1], $devOptions['groups'][$perm['id']]['members'] ) ) {197 if ( in_array( $perm['id'], array( 0, 1 ) ) || in_array( $args[1], $devOptions['groups'][$perm['id']]['members'] ) ) { 204 198 if ( preg_match( '/^read_/', $args[0] ) ) { 205 199 //if just reading, as long as a perm is there, it's okay 206 $allcaps[$cap[0]] = true; 200 foreach ( $cap as $thiscap ) { 201 if ( preg_match( '/^read_/', $thiscap ) ) { 202 $allcaps[$thiscap] = true; 203 } 204 } 207 205 return $allcaps; 208 206 } else { 209 207 if ( $perm['permission'] == 'write' ) { 210 208 //has to be there and be 'write' 211 $allcaps[$cap[0]] = true; 209 foreach ( $cap as $thiscap ) { 210 $allcaps[$thiscap] = true; 211 } 212 212 return $allcaps; 213 213 } … … 218 218 //no group permissions, so it must be public from this end, let wordpress handle it 219 219 //this really shouldn't happen as spGetPermissions should return "public" at least 220 $allcaps[$cap[0]] = true; 220 foreach ( $cap as $thiscap ) { 221 $allcaps[$thiscap] = true; 222 } 221 223 return $allcaps; 222 224 } 223 //echo "<!-- through groupPermissions in spUserCanDo -->\r";224 225 return $allcaps; 225 226 } … … 233 234 $is404Check = true; 234 235 $devOptions = $this->spGetAdminOptions(); 235 //echo "<!-- requesturi: http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] . "-->\r";236 236 $postid = url_to_postid( "http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] ); 237 //echo "<!-- request postid = $postid -->\r";238 237 if ( $postid != 0 ) { 239 238 $redirecturl = get_permalink( $devOptions['redirectPageID'] ); 240 //echo "<!-- redirecturl = $redirecturl -->\r";241 239 if ( $redirecturl !== false ) { 242 240 $is404Check = false; … … 255 253 $newjoin = " LEFT JOIN sp_metaTableName AS sp_mt1 ON (sp_postTableName.ID = sp_mt1.post_id AND sp_mt1.meta_key = 'simplePermissions_readGroupIDs') "; 256 254 $newjoin .= " LEFT JOIN sp_metaTableName AS sp_mt2 ON (sp_postTableName.ID = sp_mt2.post_id AND sp_mt2.meta_key = 'simplePermissions_writeGroupIDs')"; 257 //echo "<br>newjoin: $newjoin<br>\r";258 255 $join .= $newjoin; 259 256 $join = str_replace( 'sp_metaTableName', $wpdb->postmeta, $join ); 260 257 $join = str_replace( 'sp_postTableName', $wpdb->posts, $join ); 261 258 } 262 //echo "<br>Join: $join<br>\r";263 259 return $join; 264 260 } … … 281 277 $groupMemberships[] = 1; //Logged in users group 282 278 } else { 283 $userID = 0;284 279 $groupMemberships[] = 0; //Public group 285 280 } … … 295 290 $where .= $newwhere; 296 291 } 297 //echo "<br>Where: $where<br>\r";298 292 return $where; 299 293 } … … 421 415 } else { 422 416 $memberCount = count( $group['members'] ); 423 //echo "<!-- members: $memberCount -->";424 417 if ( $memberCount > 3 ) { 425 418 for ( $i = 0; $i < 3; $i++ ) { … … 553 546 foreach ( explode( "&", substr( $url, $pos + 1 ) ) as $q ) { 554 547 list( $key, $val ) = explode( "=", $q ); 555 //echo "<!-- key: $key value: $val -->\r";556 548 if ( $key != $arg ) { 557 549 // keep track of the parts that don't have arg3 as the key … … 567 559 $url = strstr( $url, '?', true ); 568 560 } 569 //echo "<!-- result from spDelArgFromURL: $url -->\r";570 561 return $url; 571 562 } … … 585 576 global $svvsd_simplePermissions; 586 577 $permissions = $svvsd_simplePermissions->spGetPermissions( $post->ID ); 587 //print_r( $permissions );588 //echo "<br><br>";589 578 $devOptions = $svvsd_simplePermissions->spGetAdminOptions(); 590 579 usort( $devOptions['groups'], "spCompareByName" ); … … 599 588 if ( readCheckbox.checked === false ) { 600 589 readCheckbox.checked = true; 590 } 591 var grpNum = cb.name.split("_")[2]; 592 if ( grpNum == 0 || grpNum == 1 ) { 593 var readWarning = document.getElementById( "sp_readabilityWarning" ); 594 readWarning.style.display = 'block'; 601 595 } 602 596 } else if ( ! cb.checked && cb.name.indexOf("read") != -1 ) { … … 643 637 echo "<td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_write' id='simplePermissions_grp_" . $group['id'] . "_write' onclick='sp_handleCheckboxClick(this);' " . ( $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td></tr>\r"; 644 638 } else if ( $group['id'] == 1 ) { 645 $loggedIn = "\t\t<tr><td style='padding: 3px; max-width: 200px; word-break: break-all;'>" . $group['name'] . "</td><td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_read' id='simplePermissions_grp_" . $group['id'] . "_read' onclick='sp_handleCheckboxClick(this);'" . ( $permission == 'read' ? " checked" : "" ) . " style='margin-left: 15px;'></td><td></td></tr>\r"; 639 $loggedIn = "\t\t<tr><td style='padding: 3px; max-width: 200px; word-break: break-all;'>" . $group['name'] . "</td><td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_read' id='simplePermissions_grp_" . $group['id'] . "_read' onclick='sp_handleCheckboxClick(this);'" . ( $permission == 'read' || $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td>\r"; 640 $loggedIn .= "<td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_write' id='simplePermissions_grp_" . $group['id'] . "_write' onclick='sp_handleCheckboxClick(this);' " . ( $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td></tr>\r"; 646 641 } else if ( $group['id'] == 0 ) { 647 $public = "\t\t<tr><td style='padding: 3px; max-width: 200px; word-break: break-all;'>" . $group['name'] . "</td><td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_read' id='simplePermissions_grp_" . $group['id'] . "_read' onclick='sp_handleCheckboxClick(this);'" . ( $permission == 'read' ? " checked" : "" ) . " style='margin-left: 15px;'></td><td></td></tr>\r"; 642 $public = "\t\t<tr><td style='padding: 3px; max-width: 200px; word-break: break-all;'>" . $group['name'] . "</td><td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_read' id='simplePermissions_grp_" . $group['id'] . "_read' onclick='sp_handleCheckboxClick(this);'" . ( $permission == 'read' || $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td>\r"; 643 $public .= "<td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_write' id='simplePermissions_grp_" . $group['id'] . "_write' onclick='sp_handleCheckboxClick(this);' " . ( $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td></tr>\r"; 648 644 } 649 645 } -
simple-permissions/trunk/readme.txt
r901673 r908442 5 5 Requires at least: 3.5.2 6 6 Tested up to: 3.8.3 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 35 35 == Changelog == 36 36 37 = 1.0.2 = 38 * Fixed big bug that prevented editing of posts that had no permissions set. 39 37 40 = 1.0.1 = 38 41 * Fixed issue with some extra whitespace killing feeds … … 43 46 == Upgrade Notice == 44 47 48 = 1.0.2 = 49 * Everyone should update. -
simple-permissions/trunk/simple-permissions.php
r901673 r908442 2 2 /** 3 3 * @package Simple-Permissions 4 * @version 1.0. 14 * @version 1.0.2 5 5 */ 6 6 /* … … 9 9 Description: Create simple permission groups for reading or editing posts. 10 10 Author: Michael George 11 Version: 1.0. 111 Version: 1.0.2 12 12 13 13 This program is free software; you can redistribute it and/or modify … … 124 124 //Returns array (group/user id int, group/user name str, permission str) 125 125 function spGetPermissions( $post_id ) { 126 //echo "In spGetPermissions with post id: $post_id.<br>";127 126 $devOptions = $this->spGetAdminOptions(); 128 127 $readGroups = get_post_meta( $post_id, 'simplePermissions_readGroupIDs' ); 129 128 $writeGroups = get_post_meta( $post_id, 'simplePermissions_writeGroupIDs' ); 130 //print_r( $readGroups );131 //print_r( get_post_meta( $post_id, 'simplePermissions_readGroupIDs', true ) );132 129 133 130 $returnValue = array(); … … 150 147 } 151 148 if ( ! count( $returnValue ) > 0 ) { 152 $returnValue[] = array( "id" => 0, "name" => "public", "permission" => " read" );149 $returnValue[] = array( "id" => 0, "name" => "public", "permission" => "write" ); 153 150 } 154 151 … … 163 160 // [2] Associated object ID 164 161 function spUserCanDo( $allcaps, $cap, $args ) { 165 //echo "<!-- in spUserCanDo -->\r";166 $protectedOperations = array('delete_page'162 $protectedOperations = array( 163 'delete_page' 167 164 ,'delete_post' 168 ,'edit_comment'169 165 ,'edit_page' 170 166 ,'edit_post' … … 190 186 191 187 //set the cap to false until we prove it's true 192 unset( $allcaps[$cap[0]] ); 193 194 $permissions = $this->spGetPermissions( $args[2] ); 188 foreach ( $cap as $thiscap ) { 189 unset( $allcaps[$thiscap] ); 190 } 191 192 $groupPermissions = $this->spGetPermissions( $args[2] ); 195 193 $devOptions = $this->spGetAdminOptions(); 196 $groupPermissions = array();197 foreach ( $permissions as $permission ) {198 $groupPermissions[] = $permission;199 }200 194 201 195 if ( count( $groupPermissions ) > 0 ) { 202 196 foreach ( $groupPermissions as $perm ) { 203 if ( in_array( $ args[1], $devOptions['groups'][$perm['id']]['members'] ) ) {197 if ( in_array( $perm['id'], array( 0, 1 ) ) || in_array( $args[1], $devOptions['groups'][$perm['id']]['members'] ) ) { 204 198 if ( preg_match( '/^read_/', $args[0] ) ) { 205 199 //if just reading, as long as a perm is there, it's okay 206 $allcaps[$cap[0]] = true; 200 foreach ( $cap as $thiscap ) { 201 if ( preg_match( '/^read_/', $thiscap ) ) { 202 $allcaps[$thiscap] = true; 203 } 204 } 207 205 return $allcaps; 208 206 } else { 209 207 if ( $perm['permission'] == 'write' ) { 210 208 //has to be there and be 'write' 211 $allcaps[$cap[0]] = true; 209 foreach ( $cap as $thiscap ) { 210 $allcaps[$thiscap] = true; 211 } 212 212 return $allcaps; 213 213 } … … 218 218 //no group permissions, so it must be public from this end, let wordpress handle it 219 219 //this really shouldn't happen as spGetPermissions should return "public" at least 220 $allcaps[$cap[0]] = true; 220 foreach ( $cap as $thiscap ) { 221 $allcaps[$thiscap] = true; 222 } 221 223 return $allcaps; 222 224 } 223 //echo "<!-- through groupPermissions in spUserCanDo -->\r";224 225 return $allcaps; 225 226 } … … 233 234 $is404Check = true; 234 235 $devOptions = $this->spGetAdminOptions(); 235 //echo "<!-- requesturi: http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] . "-->\r";236 236 $postid = url_to_postid( "http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] ); 237 //echo "<!-- request postid = $postid -->\r";238 237 if ( $postid != 0 ) { 239 238 $redirecturl = get_permalink( $devOptions['redirectPageID'] ); 240 //echo "<!-- redirecturl = $redirecturl -->\r";241 239 if ( $redirecturl !== false ) { 242 240 $is404Check = false; … … 255 253 $newjoin = " LEFT JOIN sp_metaTableName AS sp_mt1 ON (sp_postTableName.ID = sp_mt1.post_id AND sp_mt1.meta_key = 'simplePermissions_readGroupIDs') "; 256 254 $newjoin .= " LEFT JOIN sp_metaTableName AS sp_mt2 ON (sp_postTableName.ID = sp_mt2.post_id AND sp_mt2.meta_key = 'simplePermissions_writeGroupIDs')"; 257 //echo "<br>newjoin: $newjoin<br>\r";258 255 $join .= $newjoin; 259 256 $join = str_replace( 'sp_metaTableName', $wpdb->postmeta, $join ); 260 257 $join = str_replace( 'sp_postTableName', $wpdb->posts, $join ); 261 258 } 262 //echo "<br>Join: $join<br>\r";263 259 return $join; 264 260 } … … 281 277 $groupMemberships[] = 1; //Logged in users group 282 278 } else { 283 $userID = 0;284 279 $groupMemberships[] = 0; //Public group 285 280 } … … 295 290 $where .= $newwhere; 296 291 } 297 //echo "<br>Where: $where<br>\r";298 292 return $where; 299 293 } … … 421 415 } else { 422 416 $memberCount = count( $group['members'] ); 423 //echo "<!-- members: $memberCount -->";424 417 if ( $memberCount > 3 ) { 425 418 for ( $i = 0; $i < 3; $i++ ) { … … 553 546 foreach ( explode( "&", substr( $url, $pos + 1 ) ) as $q ) { 554 547 list( $key, $val ) = explode( "=", $q ); 555 //echo "<!-- key: $key value: $val -->\r";556 548 if ( $key != $arg ) { 557 549 // keep track of the parts that don't have arg3 as the key … … 567 559 $url = strstr( $url, '?', true ); 568 560 } 569 //echo "<!-- result from spDelArgFromURL: $url -->\r";570 561 return $url; 571 562 } … … 585 576 global $svvsd_simplePermissions; 586 577 $permissions = $svvsd_simplePermissions->spGetPermissions( $post->ID ); 587 //print_r( $permissions );588 //echo "<br><br>";589 578 $devOptions = $svvsd_simplePermissions->spGetAdminOptions(); 590 579 usort( $devOptions['groups'], "spCompareByName" ); … … 599 588 if ( readCheckbox.checked === false ) { 600 589 readCheckbox.checked = true; 590 } 591 var grpNum = cb.name.split("_")[2]; 592 if ( grpNum == 0 || grpNum == 1 ) { 593 var readWarning = document.getElementById( "sp_readabilityWarning" ); 594 readWarning.style.display = 'block'; 601 595 } 602 596 } else if ( ! cb.checked && cb.name.indexOf("read") != -1 ) { … … 643 637 echo "<td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_write' id='simplePermissions_grp_" . $group['id'] . "_write' onclick='sp_handleCheckboxClick(this);' " . ( $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td></tr>\r"; 644 638 } else if ( $group['id'] == 1 ) { 645 $loggedIn = "\t\t<tr><td style='padding: 3px; max-width: 200px; word-break: break-all;'>" . $group['name'] . "</td><td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_read' id='simplePermissions_grp_" . $group['id'] . "_read' onclick='sp_handleCheckboxClick(this);'" . ( $permission == 'read' ? " checked" : "" ) . " style='margin-left: 15px;'></td><td></td></tr>\r"; 639 $loggedIn = "\t\t<tr><td style='padding: 3px; max-width: 200px; word-break: break-all;'>" . $group['name'] . "</td><td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_read' id='simplePermissions_grp_" . $group['id'] . "_read' onclick='sp_handleCheckboxClick(this);'" . ( $permission == 'read' || $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td>\r"; 640 $loggedIn .= "<td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_write' id='simplePermissions_grp_" . $group['id'] . "_write' onclick='sp_handleCheckboxClick(this);' " . ( $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td></tr>\r"; 646 641 } else if ( $group['id'] == 0 ) { 647 $public = "\t\t<tr><td style='padding: 3px; max-width: 200px; word-break: break-all;'>" . $group['name'] . "</td><td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_read' id='simplePermissions_grp_" . $group['id'] . "_read' onclick='sp_handleCheckboxClick(this);'" . ( $permission == 'read' ? " checked" : "" ) . " style='margin-left: 15px;'></td><td></td></tr>\r"; 642 $public = "\t\t<tr><td style='padding: 3px; max-width: 200px; word-break: break-all;'>" . $group['name'] . "</td><td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_read' id='simplePermissions_grp_" . $group['id'] . "_read' onclick='sp_handleCheckboxClick(this);'" . ( $permission == 'read' || $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td>\r"; 643 $public .= "<td><input type='checkbox' name='simplePermissions_grp_" . $group['id'] . "_write' id='simplePermissions_grp_" . $group['id'] . "_write' onclick='sp_handleCheckboxClick(this);' " . ( $permission == 'write' ? " checked" : "" ) . " style='margin-left: 15px;'></td></tr>\r"; 648 644 } 649 645 }
Note: See TracChangeset
for help on using the changeset viewer.