Ignore:
Timestamp:
May 20, 2011, 10:22:18 PM (13 years ago)
Author:
Eric
Message:

r10957 merged from trunk to branch 2.20

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserAdvManager/branches/2.20/include/functions.inc.php

    r10707 r10958  
    752752 * Triggered on user_comment_check
    753753 *
    754  * checks if author is mandatory and set on comments post
     754 * checks if author is mandatory and set on comments post when comments for all is set
     755 *
     756 * cheks if author is in an allowed group to post comment when comments for all is not set
    755757 *
    756758 * @param : comment action, comment
     
    762764{
    763765  load_language('plugin.lang', UAM_PATH);
    764   global $infos, $conf, $template;
     766  global $infos, $conf, $user;
    765767
    766768  $conf_UAM = unserialize($conf['UserAdvManager']);
    767769
    768 // User creation OR update
    769   if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest')
     770// Does not allow empty author name on comments for all
     771  if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and $comm['author'] == 'guest' and $conf['comments_forall'])
    770772  {
    771773    $comment_action = 'reject';
    772774
    773775    array_push($infos, l10n('UAM_Empty Author'));
     776  }
     777
     778
     779// Do not allow comments if user is not in an allowed group
     780  if (isset($conf_UAM[36]) and $conf_UAM[36] == 'true' and !$conf['comments_forall'])
     781  {
     782    if (!UAM_CheckAuthor($comm['author']))
     783    {
     784      $comment_action = 'reject';
     785
     786      array_push($infos, l10n('UAM_Not_Allowed_Author'));
     787    }
    774788  }
    775789
     
    25262540
    25272541/**
     2542 * Called from UAM_CheckEmptyCommentAuthor()
     2543 * Checks if comment's author name is in the allowed group
     2544 *
     2545 * @author   : author's name
     2546 *
     2547 * @returns  : Boolean (true is user is allowed to post / false if not allowed)
     2548 *
     2549 */
     2550function UAM_CheckAuthor($author)
     2551{
     2552  global $conf;
     2553 
     2554        // Get UAM configuration
     2555  $conf_UAM = unserialize($conf['UserAdvManager']);
     2556 
     2557  if (isset($conf_UAM[37]) and $conf_UAM[37] <> -1)
     2558  {
     2559    $query = '
     2560SELECT u.id,
     2561       u.username,
     2562       ug.user_id,
     2563       ug.group_id
     2564FROM '.USERS_TABLE.' AS u
     2565  INNER JOIN '.USER_GROUP_TABLE.' AS ug
     2566    ON u.id = ug.user_id
     2567WHERE u.username LIKE "'.$author.'"
     2568  AND ug.group_id = '.$conf_UAM[37].'
     2569;';
     2570
     2571    $count = pwg_db_num_rows(pwg_query($query));
     2572
     2573    if (is_null($count) or $count == 0)
     2574    {
     2575      return false;
     2576    }
     2577    else
     2578      return true;
     2579  }
     2580}
     2581
     2582
     2583/**
    25282584 * Useful for debugging - 4 vars can be set
    25292585 * Output result to log.txt file
Note: See TracChangeset for help on using the changeset viewer.