Plugin Directory

Changeset 908442


Ignore:
Timestamp:
05/05/2014 07:54:17 PM (12 years ago)
Author:
george_michael
Message:

fixed major bug. tagged 1.0.2

Location:
simple-permissions
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • simple-permissions/tags/1.0.2/readme.txt

    r901673 r908442  
    55Requires at least: 3.5.2
    66Tested up to: 3.8.3
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Changelog ==
    3636
     37= 1.0.2 =
     38* Fixed big bug that prevented editing of posts that had no permissions set.
     39
    3740= 1.0.1 =
    3841* Fixed issue with some extra whitespace killing feeds
     
    4346== Upgrade Notice ==
    4447
     48= 1.0.2 =
     49* Everyone should update.
  • simple-permissions/tags/1.0.2/simple-permissions.php

    r901673 r908442  
    22/**
    33 * @package Simple-Permissions
    4  * @version 1.0.1
     4 * @version 1.0.2
    55 */
    66/*
     
    99Description: Create simple permission groups for reading or editing posts.
    1010Author: Michael George
    11 Version: 1.0.1
     11Version: 1.0.2
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    124124        //Returns array (group/user id int, group/user name str, permission str)
    125125        function spGetPermissions( $post_id ) {
    126             //echo "In spGetPermissions with post id: $post_id.<br>";
    127126            $devOptions = $this->spGetAdminOptions();
    128127            $readGroups = get_post_meta( $post_id, 'simplePermissions_readGroupIDs' );
    129128            $writeGroups = get_post_meta( $post_id, 'simplePermissions_writeGroupIDs' );
    130             //print_r( $readGroups );
    131             //print_r( get_post_meta( $post_id, 'simplePermissions_readGroupIDs', true ) );
    132129
    133130            $returnValue = array();
     
    150147            }
    151148            if ( ! count( $returnValue ) > 0 ) {
    152                 $returnValue[] = array( "id" => 0, "name" => "public", "permission" => "read" );
     149                $returnValue[] = array( "id" => 0, "name" => "public", "permission" => "write" );
    153150            }
    154151
     
    163160        //                      [2] Associated object ID
    164161        function spUserCanDo( $allcaps, $cap, $args ) {
    165             //echo "<!-- in spUserCanDo -->\r";
    166             $protectedOperations = array( 'delete_page'
     162            $protectedOperations = array(
     163                                        'delete_page'
    167164                                        ,'delete_post'
    168                                         ,'edit_comment'
    169165                                        ,'edit_page'
    170166                                        ,'edit_post'
     
    190186
    191187            //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] );
    195193            $devOptions = $this->spGetAdminOptions();
    196             $groupPermissions = array();
    197             foreach ( $permissions as $permission ) {
    198                 $groupPermissions[] = $permission;
    199             }
    200194
    201195            if ( count( $groupPermissions ) > 0 ) {
    202196                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'] ) ) {
    204198                        if ( preg_match( '/^read_/', $args[0] ) ) {
    205199                            //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                            }
    207205                            return $allcaps;
    208206                        } else {
    209207                            if ( $perm['permission'] == 'write' ) {
    210208                                //has to be there and be 'write'
    211                                 $allcaps[$cap[0]] = true;
     209                                foreach ( $cap as $thiscap ) {
     210                                    $allcaps[$thiscap] = true;
     211                                }
    212212                                return $allcaps;
    213213                            }
     
    218218                //no group permissions, so it must be public from this end, let wordpress handle it
    219219                //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                }
    221223                return $allcaps;
    222224            }
    223             //echo "<!-- through groupPermissions in spUserCanDo -->\r";
    224225            return $allcaps;
    225226        }
     
    233234                $is404Check = true;
    234235                $devOptions = $this->spGetAdminOptions();
    235                 //echo "<!-- requesturi: http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] . "-->\r";
    236236                $postid = url_to_postid( "http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] );
    237                 //echo "<!-- request postid = $postid -->\r";
    238237                if ( $postid != 0 ) {
    239238                    $redirecturl = get_permalink( $devOptions['redirectPageID'] );
    240                     //echo "<!-- redirecturl = $redirecturl -->\r";
    241239                    if ( $redirecturl !== false ) {
    242240                        $is404Check = false;
     
    255253                $newjoin = " LEFT JOIN sp_metaTableName AS sp_mt1 ON (sp_postTableName.ID = sp_mt1.post_id AND sp_mt1.meta_key = 'simplePermissions_readGroupIDs') ";
    256254                $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";
    258255                $join .= $newjoin;
    259256                $join = str_replace( 'sp_metaTableName', $wpdb->postmeta, $join );
    260257                $join = str_replace( 'sp_postTableName', $wpdb->posts, $join );
    261258            }
    262             //echo "<br>Join: $join<br>\r";
    263259            return $join;
    264260        }
     
    281277                    $groupMemberships[] = 1; //Logged in users group
    282278                } else {
    283                     $userID = 0;
    284279                    $groupMemberships[] = 0; //Public group
    285280                }
     
    295290                $where .= $newwhere;
    296291            }
    297             //echo "<br>Where: $where<br>\r";
    298292            return $where;
    299293        }
     
    421415                        } else {
    422416                            $memberCount = count( $group['members'] );
    423                             //echo "<!-- members: $memberCount -->";
    424417                            if ( $memberCount > 3 ) {
    425418                                for ( $i = 0; $i < 3; $i++ ) {
     
    553546        foreach ( explode( "&", substr( $url, $pos + 1 ) ) as $q ) {
    554547            list( $key, $val ) = explode( "=", $q );
    555             //echo "<!-- key: $key value: $val -->\r";
    556548            if ( $key != $arg ) {
    557549                // keep track of the parts that don't have arg3 as the key
     
    567559        $url = strstr( $url, '?', true );
    568560    }
    569     //echo "<!-- result from spDelArgFromURL: $url -->\r";
    570561    return $url;
    571562}
     
    585576    global $svvsd_simplePermissions;
    586577    $permissions = $svvsd_simplePermissions->spGetPermissions( $post->ID );
    587     //print_r( $permissions );
    588     //echo "<br><br>";
    589578    $devOptions = $svvsd_simplePermissions->spGetAdminOptions();
    590579    usort( $devOptions['groups'], "spCompareByName" );
     
    599588                if ( readCheckbox.checked === false ) {
    600589                    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';
    601595                }
    602596        } else if ( ! cb.checked && cb.name.indexOf("read") != -1 ) {
     
    643637            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";
    644638        } 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";
    646641        } 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";
    648644        }
    649645    }
  • simple-permissions/trunk/readme.txt

    r901673 r908442  
    55Requires at least: 3.5.2
    66Tested up to: 3.8.3
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Changelog ==
    3636
     37= 1.0.2 =
     38* Fixed big bug that prevented editing of posts that had no permissions set.
     39
    3740= 1.0.1 =
    3841* Fixed issue with some extra whitespace killing feeds
     
    4346== Upgrade Notice ==
    4447
     48= 1.0.2 =
     49* Everyone should update.
  • simple-permissions/trunk/simple-permissions.php

    r901673 r908442  
    22/**
    33 * @package Simple-Permissions
    4  * @version 1.0.1
     4 * @version 1.0.2
    55 */
    66/*
     
    99Description: Create simple permission groups for reading or editing posts.
    1010Author: Michael George
    11 Version: 1.0.1
     11Version: 1.0.2
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    124124        //Returns array (group/user id int, group/user name str, permission str)
    125125        function spGetPermissions( $post_id ) {
    126             //echo "In spGetPermissions with post id: $post_id.<br>";
    127126            $devOptions = $this->spGetAdminOptions();
    128127            $readGroups = get_post_meta( $post_id, 'simplePermissions_readGroupIDs' );
    129128            $writeGroups = get_post_meta( $post_id, 'simplePermissions_writeGroupIDs' );
    130             //print_r( $readGroups );
    131             //print_r( get_post_meta( $post_id, 'simplePermissions_readGroupIDs', true ) );
    132129
    133130            $returnValue = array();
     
    150147            }
    151148            if ( ! count( $returnValue ) > 0 ) {
    152                 $returnValue[] = array( "id" => 0, "name" => "public", "permission" => "read" );
     149                $returnValue[] = array( "id" => 0, "name" => "public", "permission" => "write" );
    153150            }
    154151
     
    163160        //                      [2] Associated object ID
    164161        function spUserCanDo( $allcaps, $cap, $args ) {
    165             //echo "<!-- in spUserCanDo -->\r";
    166             $protectedOperations = array( 'delete_page'
     162            $protectedOperations = array(
     163                                        'delete_page'
    167164                                        ,'delete_post'
    168                                         ,'edit_comment'
    169165                                        ,'edit_page'
    170166                                        ,'edit_post'
     
    190186
    191187            //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] );
    195193            $devOptions = $this->spGetAdminOptions();
    196             $groupPermissions = array();
    197             foreach ( $permissions as $permission ) {
    198                 $groupPermissions[] = $permission;
    199             }
    200194
    201195            if ( count( $groupPermissions ) > 0 ) {
    202196                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'] ) ) {
    204198                        if ( preg_match( '/^read_/', $args[0] ) ) {
    205199                            //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                            }
    207205                            return $allcaps;
    208206                        } else {
    209207                            if ( $perm['permission'] == 'write' ) {
    210208                                //has to be there and be 'write'
    211                                 $allcaps[$cap[0]] = true;
     209                                foreach ( $cap as $thiscap ) {
     210                                    $allcaps[$thiscap] = true;
     211                                }
    212212                                return $allcaps;
    213213                            }
     
    218218                //no group permissions, so it must be public from this end, let wordpress handle it
    219219                //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                }
    221223                return $allcaps;
    222224            }
    223             //echo "<!-- through groupPermissions in spUserCanDo -->\r";
    224225            return $allcaps;
    225226        }
     
    233234                $is404Check = true;
    234235                $devOptions = $this->spGetAdminOptions();
    235                 //echo "<!-- requesturi: http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] . "-->\r";
    236236                $postid = url_to_postid( "http" . ( isset($_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ? "s" : "" ) . "://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] );
    237                 //echo "<!-- request postid = $postid -->\r";
    238237                if ( $postid != 0 ) {
    239238                    $redirecturl = get_permalink( $devOptions['redirectPageID'] );
    240                     //echo "<!-- redirecturl = $redirecturl -->\r";
    241239                    if ( $redirecturl !== false ) {
    242240                        $is404Check = false;
     
    255253                $newjoin = " LEFT JOIN sp_metaTableName AS sp_mt1 ON (sp_postTableName.ID = sp_mt1.post_id AND sp_mt1.meta_key = 'simplePermissions_readGroupIDs') ";
    256254                $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";
    258255                $join .= $newjoin;
    259256                $join = str_replace( 'sp_metaTableName', $wpdb->postmeta, $join );
    260257                $join = str_replace( 'sp_postTableName', $wpdb->posts, $join );
    261258            }
    262             //echo "<br>Join: $join<br>\r";
    263259            return $join;
    264260        }
     
    281277                    $groupMemberships[] = 1; //Logged in users group
    282278                } else {
    283                     $userID = 0;
    284279                    $groupMemberships[] = 0; //Public group
    285280                }
     
    295290                $where .= $newwhere;
    296291            }
    297             //echo "<br>Where: $where<br>\r";
    298292            return $where;
    299293        }
     
    421415                        } else {
    422416                            $memberCount = count( $group['members'] );
    423                             //echo "<!-- members: $memberCount -->";
    424417                            if ( $memberCount > 3 ) {
    425418                                for ( $i = 0; $i < 3; $i++ ) {
     
    553546        foreach ( explode( "&", substr( $url, $pos + 1 ) ) as $q ) {
    554547            list( $key, $val ) = explode( "=", $q );
    555             //echo "<!-- key: $key value: $val -->\r";
    556548            if ( $key != $arg ) {
    557549                // keep track of the parts that don't have arg3 as the key
     
    567559        $url = strstr( $url, '?', true );
    568560    }
    569     //echo "<!-- result from spDelArgFromURL: $url -->\r";
    570561    return $url;
    571562}
     
    585576    global $svvsd_simplePermissions;
    586577    $permissions = $svvsd_simplePermissions->spGetPermissions( $post->ID );
    587     //print_r( $permissions );
    588     //echo "<br><br>";
    589578    $devOptions = $svvsd_simplePermissions->spGetAdminOptions();
    590579    usort( $devOptions['groups'], "spCompareByName" );
     
    599588                if ( readCheckbox.checked === false ) {
    600589                    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';
    601595                }
    602596        } else if ( ! cb.checked && cb.name.indexOf("read") != -1 ) {
     
    643637            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";
    644638        } 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";
    646641        } 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";
    648644        }
    649645    }
Note: See TracChangeset for help on using the changeset viewer.