Ignore:
Timestamp:
May 26, 2011, 7:00:46 PM (13 years ago)
Author:
Eric
Message:

Add new feature : Users in a specified group can post comments without admin validation when "Comments for all" is enabled and admin validation is enabled.
New version 2.2.1 hard coded for publication

Location:
extensions/Comments_Access_Manager/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/Comments_Access_Manager/include/functions.inc.php

    r11017 r11069  
    5252  }
    5353
    54 
    55 // Do not allow comments if user is not in an allowed group
    56   if (isset($conf_CM[2]) and $conf_CM[2] == 'true' and !$conf['comments_forall'] and !is_admin())
    57   {
    58     if (!CM_CheckAuthor($comm['author']))
    59     {
    60       $comment_action = 'reject';
    61 
     54// Rules on comments NOT for all
     55  if (!$conf['comments_forall'] and !is_admin())
     56  {
     57    if ((isset($conf_CM[2]) and $conf_CM[2] == 'true') and (isset($conf_CM[4]) and $conf_CM[4] == 'false') and !CM_CheckAuthor($comm['author'])) // Comments authorized group set - Auto validation group unset
     58    {
     59      $comment_action = 'reject'; // Comment rejected if author is not in the allowed group
    6260      array_push($infos, l10n('CM_Not_Allowed_Author'));
     61    }
     62    elseif ((isset($conf_CM[2]) and $conf_CM[2] == 'false') and (isset($conf_CM[4]) and $conf_CM[4] == 'true') and $conf['comments_validation']) // Comments authorized group unset - Auto validation group set
     63    {
     64      if (CM_CheckValidGroup($comm['author']))
     65      {
     66        $comment_action = 'validate'; // Comment is validated if author is not in the validated group
     67      }
     68      else
     69      {
     70        $comment_action = 'moderate'; // Comment needs moderation if author is not in the validated group
     71      }
     72    }
     73    elseif ((isset($conf_CM[2]) and $conf_CM[2] == 'true') and (isset($conf_CM[4]) and $conf_CM[4] == 'true') and $conf['comments_validation']) // Comments authorized group set - Auto validation group set
     74    {
     75      if (!CM_CheckAuthor($comm['author']))
     76      {
     77        $comment_action = 'reject'; // Comment rejected if author is not in the allowed group
     78        array_push($infos, l10n('CM_Not_Allowed_Author'));
     79      }
     80      elseif (CM_CheckValidGroup($comm['author']))
     81      {
     82        $comment_action = 'validate'; // Comment is validated if author is not in the validated group
     83      }
     84      else
     85        $comment_action = 'moderate'; // Comment needs moderation if author is not in the validated group
    6386    }
    6487  }
     
    110133
    111134/**
     135 * Checks if comment's author name is in the admin's pre-validated group
     136 * avoid admins to validate comments for the members of this group
     137 *
     138 * @author   : author's name
     139 *
     140 * @returns  : Boolean (true if user's comment doesn't need validation / false if user's comment is moderated)
     141 *
     142 */
     143function CM_CheckValidGroup($author)
     144{
     145  global $conf;
     146 
     147        // Get CM configuration
     148  $conf_CM = unserialize($conf['CommentsManager']);
     149 
     150  if (isset($conf_CM[5]) and $conf_CM[5] <> -1)
     151  {
     152    $query = '
     153SELECT u.id,
     154       u.username,
     155       ug.user_id,
     156       ug.group_id
     157FROM '.USERS_TABLE.' AS u
     158  INNER JOIN '.USER_GROUP_TABLE.' AS ug
     159    ON u.id = ug.user_id
     160WHERE u.username LIKE "'.$author.'"
     161  AND ug.group_id = '.$conf_CM[5].'
     162;';
     163
     164    $count = pwg_db_num_rows(pwg_query($query));
     165
     166    if (is_null($count) or $count == 0)
     167    {
     168      return false;
     169    }
     170    else
     171      return true;
     172  }
     173}
     174
     175
     176/**
    112177 * Get the plugin version and name
    113178 *
  • extensions/Comments_Access_Manager/include/upgradedb.inc.php

    r11017 r11069  
    7474  }
    7575}
     76
     77
     78/* upgrade from 2.2.0 to 2.2.1 */
     79/* *************************** */
     80function upgradeCM_220_221()
     81{
     82  global $conf;
     83
     84  // Upgrading options
     85  $query = '
     86SELECT value
     87  FROM '.CONFIG_TABLE.'
     88WHERE param = "CommentsManager"
     89;';
     90
     91  $result = pwg_query($query);
     92  $conf_CM = pwg_db_fetch_assoc($result);
     93   
     94  $Newconf_CM = unserialize($conf_CM['value']);
     95 
     96  $Newconf_CM[4] = 'false';
     97  $Newconf_CM[5] = '-1';
     98 
     99  $update_conf = serialize($Newconf_CM);
     100
     101  conf_update_param('CommentsManager', pwg_db_real_escape_string($update_conf));
     102}
    76103?>
Note: See TracChangeset for help on using the changeset viewer.