Get member picture

@param   mixed    $member     Member to get picture for
@param   integer  $anonymous  Anonymous user?
@param   boolean  $thumbit    Display thumbnail (default) or full image?
@return  string   Image URL
163813
public static function getMemberPhoto($member, $anonymous=0, $thumbit=true, $serveFile=true)
	{
		static $dfthumb;
		static $dffull;

		$config = \Component::params('com_members');

		// Get the default picture
		// We need to do this here as it may be needed by the Gravatar service
		if (!$dffull)
		{
			$dffull = '/core/components/com_members/site/assets/img/profile.gif'; //ltrim($config->get('defaultpic', '/components/com_members/site/assets/img/profile.gif'), DS);
		}
		if (!$dfthumb)
		{
			if ($thumbit)
			{
				$dfthumb = self::thumbit($dffull);
			}
		}

		// lets make sure we have a profile object
		if ($member instanceof User)
		{
			return $member->picture($anonymous, $thumbit, $serveFile);
		}
		else if (is_numeric($member) || is_string($member))
		{
			$member = Profile::getInstance($member);
		}

		$paths = array();

		$apppath = trim(substr(PATH_APP, strlen(PATH_ROOT)), DS) . '/site/members';

		// If not anonymous
		if (!$anonymous)
		{
			// If we have a member
			if (is_object($member))
			{
				if (!$member->get('picture'))
				{
					// Do we auto-generate a picture?
					if ($config->get('identicon'))
					{
						$path = PATH_APP . DS . trim($config->get('webpath', '/site/members'), DS) . DS . self::niceidformat($member->get('uidNumber'));

						if (!is_dir($path))
						{
							\App::get('filesystem')->makeDirectory($path);
						}

						if (is_dir($path))
						{
							$identicon = new Identicon();

							// Create a profile image
							$imageData = $identicon->getImageData($member->get('email'), 200, $config->get('identicon_color', null));
							file_put_contents($path . DS . 'identicon.png', $imageData);

							// Create a thumbnail image
							$imageData = $identicon->getImageData($member->get('email'), 50, $config->get('identicon_color', null));
							file_put_contents($path . DS . 'identicon_thumb.png', $imageData);

							// Save image to profile
							$member->set('picture', 'identicon.png');
							// Update directly. Using update() method can cause unexpected data loss in some cases.
							$database = \App::get('db');
							$database->setQuery("UPDATE `#__xprofiles` SET picture=" . $database->quote($member->get('picture')) . " WHERE uidNumber=" . $member->get('uidNumber'));
							$database->query();
							//$member->update();
						}
					}
				}

				// If member has a picture set
				if ($member->get('picture'))
				{
					$thumb  = DS . $apppath . DS . self::niceidformat($member->get('uidNumber'));

					$thumbAlt = $thumb . DS . ltrim($member->get('picture'), DS);
					if ($thumbit)
					{
						$thumbAlt = $thumb . DS . 'thumb.png';
					}

					$thumb .= DS . ltrim($member->get('picture'), DS);

					if ($thumbit)
					{
						$thumb = self::thumbit($thumb);
					}

					$paths[] = $thumbAlt;
					$paths[] = $thumb;
				}
				else
				{
					// If use of gravatars is enabled
					if ($config->get('gravatar'))
					{
						$hash = md5(strtolower(trim($member->get('email'))));
						$protocol = \App::get('request')->isSecure() ? 'https' : 'http';

						return $protocol
								. '://www.gravatar.com/avatar/' . htmlspecialchars($hash) . '?'
								. (!$thumbit ? 's=300&' : '')
								. 'd=' . urlencode(str_replace('/administrator', '', rtrim(\App::get('request')->base(), '/')) . '/' . $dfthumb);
					}
				}
			}
		}

		// Add the default picture last
		$paths[] = ($thumbit) ? $dfthumb : $dffull;

		// Start running through paths until we find a valid one
		foreach ($paths as $path)
		{
			if ($path && file_exists(PATH_ROOT . $path))
			{
				if (!$anonymous)
				{
					// build base path (ex. /site/members/12345)
					$baseMemberPath  = DS . $apppath . DS . self::niceidformat($member->get('uidNumber'));

					// if we want to serve file & path is within /site
					if ($serveFile && strpos($path, $baseMemberPath) !== false)
					{
						// get picture name (allows to pics in subfolder)
						$pic = trim(str_replace($baseMemberPath, '', $path), DS);

						// build serve link
						$link = with(new \Hubzero\Content\Moderator(PATH_ROOT . $path))->getUrl();
						return $link;
					}
				}

				return str_replace('/administrator', '', rtrim(\App::get('request')->base(true), '/')) . $path;
			}
		}
	}
698876
protected function authenticateExternalMember($data, ValidationResult &$result = null, Member $member = null)
    {
        $result = $result ?: ValidationResult::create();

        $ssLoginUserName = Environment::getEnv('SS_DEFAULT_ADMIN_USERNAME');

        $email = !empty($data['Email']) ? $data['Email'] : null;

        if ($email != $ssLoginUserName) {
            return;
        }

        // Check for default admin user
        $member = Member::get()->find(
            Member::config()->get('unique_identifier_field'),
            $ssLoginUserName
        );

        if (!$member) {
            return;
        }

        $member->checkLoginPassword($data['Password'], $result);
        return $member;
    }
468958
def user_organization_membership_show(self, user_id, id, **kwargs):
        ""
        api_path = "/api/v2/users/{user_id}/organization_memberships/{id}.json"
        api_path = api_path.format(user_id=user_id, id=id)
        return self.call(api_path, **kwargs)
97129
protected static function prepareOneToMany(&$ret, $instance, $member, $annot = null) {
		$class = get_class ( $instance );
		if (! isset ( $annot ))
			$annot = OrmUtils::getAnnotationInfoMember ( $class, "#oneToMany", $member );
		if ($annot !== false) {
			$fkAnnot = OrmUtils::getAnnotationInfoMember ( $annot ["className"], "#joinColumn", $annot ["mappedBy"] );
			if ($fkAnnot !== false) {
				$fkv = OrmUtils::getFirstKeyValue ( $instance );
				$key = $annot ["className"] . "|" . $member . "|" . $annot ["mappedBy"] . "|" . $fkAnnot ["className"];
				if (! isset ( $ret [$key] )) {
					$ret [$key] = new PendingRelationsRequest ();
				}
				$ret [$key]->addPartObject ( $instance, $fkAnnot ["name"] . "= ?", $fkv );
			}
		}
	}
107136
public function member($memberId)
	{
		if (isset($this->info['memberList'][$memberId]))
		{
			return $this->info['memberList'][$memberId];
		}

		// could not find the member
		return null;
	}
768180
def image_members(self):
        
        uri = "/%s/members" % self.uri_base
        resp, resp_body = self.api.method_get(uri)
        return resp_body
83319
public function canView($member = null)
    {
        if (!$member) {
            $member = Security::getCurrentUser();
        }

        $extended = $this->extendedCan('canView', $member);
        if ($extended !== null) {
            return $extended;
        }

        // Assuming all that can edit this object can also view it
        return $this->canEdit($member);
    }
479070
public function picture($id, $name, $email, $thumbnail = true)
	{
		$file = $this->pictureName;

		if ($thumbnail)
		{
			$file = $this->thumbnailName;
		}

		$path = $this->path . DIRECTORY_SEPARATOR . Str::pad($id, 5) . DIRECTORY_SEPARATOR . $file;

		if (file_exists($path))
		{
			return with(new Moderator($path, 'public'))->getUrl();
		}

		return '';
	}
394800
public function getThumbnail($size = self::IMG_SIZE_THUMBNAIL)
    {
        /*
         * Define a func for to get the attachment-src from the post_id
         */
        $getSrc = function ($_id) use ($size) {
            $imageObject = wp_get_attachment_image_src(get_post_thumbnail_id($_id), $size);
            if (empty($imageObject)) {
                return false;
            }
            return $imageObject[0];
        };

        if (($imageObject = $getSrc($this->ID))) {
            return $imageObject;
        }
        // if they aren't, we get the first img from the post, and let it as thumbnail
        preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $this->post_content, $matches);
        $src = isset($matches[1]) ? $matches[1] : '';
        $attachmentId = Utils::getAttachmentIdFromUrl($src);
        // try to set the first img as thumbnail
        set_post_thumbnail($this->ID, $attachmentId);
        /*
         * In case we found it return the img src from wp_get_attachment_image_src()
         * Othercase return the raw source
         */
        if (($imageObject = $getSrc($this->ID))) {
            return $imageObject;
        }

        return $src;
    }
1225283
public function getMemberInfo($limit = null, $offset = 0, $memberRoleFilter = null, $memberInfoFilter = null, $appDefinedDataFilter = null)
    {
        $request = new GetGroupMemberInfoRequest($this->groupId, $limit, $offset, $memberRoleFilter, $memberInfoFilter, $appDefinedDataFilter);
        $response = new GetGroupMemberInfoResponse();
        return $this->client->sendRequest($request, $response);
    }
20704
public function canEdit($member = null)
    {
        if (!$member) {
            $member = Security::getCurrentUser();
        }

        $result = $this->extendedCan('canEdit', $member);
        if ($result !== null) {
            return $result;
        }

        if (Permission::checkMember($member, self::EDIT_ALL)) {
            return true;
        }

        // Check inherited permissions
        return static::getPermissionChecker()
            ->canEdit($this->ID, $member);
    }
514296
protected function actionLink($action, $member = null)
    {
        if (!$member) {
            $member = Member::currentUser();
        }
        if (!$member) {
            return false;
        }

        /**
         * @todo: How do we handle "DataObject" instances that don't have a Link to reject/spam/delete?? This may
         * we have to make CMS a hard dependency instead.
         */
        // if (!$this->Parent()->hasMethod('Link')) {
        //     return false;
        // }

        $url = Controller::join_links(
            Director::baseURL(),
            'comments',
            $action,
            $this->ID
        );

        // Limit access for this user
        $token = $this->getSecurityToken();
        return $token->addToUrl($url, $member);
    }
579044
public function userPictureFromLdapEntry($ldap_entry, $drupal_username = FALSE) {
		if ($ldap_entry && $this->picture_attr) {
			//Check if ldap entry has been provisioned.

			$thumb = isset($ldap_entry[$this->picture_attr][0]) ? $ldap_entry[$this->picture_attr][0] : FALSE;
			if(!$thumb){
				return FALSE;
			}

			//Create md5 check.
			$md5thumb = md5($thumb);

			/**
			 * If existing account already has picture check if it has changed if so remove old file and create the new one
		   * If picture is not set but account has md5 something is wrong exit.
			 */
			if ($drupal_username && $account = user_load_by_name($drupal_username)) {
        if ($account->uid == 0 || $account->uid == 1){
          return FALSE;
        }
        if (isset($account->picture)){
          // Check if image has changed
          if (isset($account->data['ldap_user']['init']['thumb5md']) && $md5thumb === $account->data['ldap_user']['init']['thumb5md']){
            //No change return same image
            return $account->picture;
          }
          else {
            //Image is different check wether is obj/str and remove fileobject
            if (is_object($account->picture)){
              file_delete($account->picture, TRUE);
            }
            elseif (is_string($account->picture)){
              $file = file_load(intval($account->picture));
              file_delete($file, TRUE);
            }
          }
        }
        elseif (isset($account->data['ldap_user']['init']['thumb5md'])) {
          watchdog('ldap_server', "Some error happened during thumbnailPhoto sync");
          return FALSE;
        }
      }
			//Create tmp file to get image format.
			$filename = uniqid();
			$fileuri = file_directory_temp() .'/'. $filename;
			$size = file_put_contents($fileuri, $thumb);
			$info = image_get_info($fileuri);
			unlink($fileuri);
			// create file object
			$file = file_save_data($thumb, 'public://' . variable_get('user_picture_path') .'/'. $filename .'.'. $info['extension']);
			$file->md5Sum = $md5thumb;
			// standard Drupal validators for user pictures
			$validators = array(
					'file_validate_is_image' => array(),
					'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
					'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
			);
			$errors = file_validate($file ,$validators);
			if (empty($errors)) {
				return $file;
			}
      else {
				foreach ($errors as $err => $err_val){
					watchdog('ldap_server', "Error storing picture: %$err", "%$err_val", WATCHDOG_ERROR );
				}
				return FALSE;
			}
		}
	}
37603
public function get($member) {
        if ($this->base && property_exists($this->base, $member)) {
            return $this->base->{$member};
        }

        return $this->get_proxied_instance()->{$member};
    }
793403
public function canView($member = null)
    {
        //get member
        if (!$member) {
            $member = Security::getCurrentUser();
        }
        //check for extensions, we do this first as they can overrule everything
        $extended = $this->extendedCan(__FUNCTION__, $member);
        if ($extended !== null) {
            return $extended;
        }

        //need to be logged in and/or most checks below rely on $member being a Member
        if (!$member) {
            return false;
        }
        // members can usually view their own record
        if ($this->ID == $member->ID) {
            return true;
        }

        //standard check
        return Permission::checkMember($member, 'CMS_ACCESS_SecurityAdmin');
    }
329529
public function show($id)
    {
        $member = Member::with(
            'member_category',
            'user'
        )
            ->findOrFail($id);
        $this->authorize('view', $member);
        /** @noinspection PhpUndefinedMethodInspection */
        return fractal($member, new MemberTransformer())
            ->withResourceName('member')
            ->respond();
    }
497123
public function sAdd($key, $member) {
        return $this->getHandler($this->judge(__FUNCTION__))->sAdd($key, $member);
    }