/**
 * Check whether a user is on probation.
 * @param int $userid
 * @return boolean TRUE if the user is on probation, FALSE if the user is not on probation
 */
function is_probationary_user($userid = null)
{
    global $USER;
    // Check whether a new user threshold is in place or not.
    if (!is_using_probation()) {
        return false;
    }
    // Get the user's information
    if ($userid == null) {
        $user = $USER;
    } else {
        $user = new User();
        $user->find_by_id($userid);
    }
    // Admins and staff get a free pass
    if ($user->get('admin') || $user->get('staff') || $user->is_institutional_admin() || $user->is_institutional_staff()) {
        return false;
    }
    // We actually store new user points in reverse. When your account is created, you get $newuserthreshold points, and
    // we decrease those when you do something good, and when it hits 0 you're no longer a new user.
    $userspoints = get_field('usr', 'probation', 'id', $user->get('id'));
    if ($userspoints > 0) {
        return true;
    } else {
        return false;
    }
}
Example #2
0
 /**
  * Determine whether a user can write comments on this view
  *
  * If the view doesn't have the allowcomments property set,
  * then we must look at the view_access records to determine
  * whether the user can leave comments.
  *
  * In view_access, allowcomments indicates that the user can
  * comment, however if approvecomments is also set on a particular
  * access record, then all comments can only be private until the
  * view owner decides to make them public.
  *
  * Returns false, 'private', or true
  */
 public function user_comments_allowed(User $user)
 {
     global $SESSION;
     if (!$user->is_logged_in() && !get_config('anonymouscomments')) {
         return false;
     }
     if ($this->get('allowcomments')) {
         return $this->get('approvecomments') ? 'private' : true;
     }
     $userid = $user->get('id');
     $access = self::user_access_records($this->id, $userid);
     $publicviews = get_config('allowpublicviews');
     $publicprofiles = get_config('allowpublicprofiles');
     // a group view won't have an 'owner'
     if ($publicviews && ($ownerobj = $this->get_owner_object())) {
         $owner = new User();
         $owner->find_by_id($ownerobj->id);
         $publicviews = $owner->institution_allows_public_views();
     }
     $allowcomments = false;
     $approvecomments = true;
     $mnettoken = get_cookie('mviewaccess:' . $this->id);
     $usertoken = get_cookie('viewaccess:' . $this->id);
     $cid = $this->collection_id();
     $ctoken = $cid ? get_cookie('caccess:' . $cid) : null;
     if ($access) {
         foreach ($access as $a) {
             if ($a->accesstype == 'public') {
                 if (!$publicviews && (!$publicprofiles || $this->type != 'profile')) {
                     continue;
                 }
             } else {
                 if ($a->token && $a->token != $mnettoken && (!$publicviews || $a->token != $usertoken && $a->token != $ctoken)) {
                     continue;
                 } else {
                     if (!$user->is_logged_in()) {
                         continue;
                     } else {
                         if ($a->accesstype == 'friends') {
                             $owner = $this->get('owner');
                             if (!get_field_sql('
                     SELECT COUNT(*) FROM {usr_friend} f WHERE (usr1=? AND usr2=?) OR (usr1=? AND usr2=?)', array($owner, $userid, $userid, $owner))) {
                                 continue;
                             }
                         }
                     }
                 }
             }
             $objectionable = $this->is_objectionable();
             if ($a->allowcomments && ($objectionable && ($user->get('admin') || $user->is_institutional_admin()) || !$objectionable)) {
                 $allowcomments = $allowcomments || $a->allowcomments;
                 $approvecomments = $approvecomments && $a->approvecomments;
             }
             if (!$approvecomments) {
                 return true;
             }
         }
     }
     if ($allowcomments) {
         return $approvecomments ? 'private' : true;
     }
     return false;
 }