summaryrefslogtreecommitdiffstats
path: root/lib/avatar.php
blob: 2b087c48b65fc9bbb165be0faba7da39334dae66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
 * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

class OC_Avatar {
	/**
	 * @brief gets the users avatar
	 * @param $user string username
	 * @param $size integer size in px of the avatar, defaults to 64
	 * @return mixed link to the avatar, false if avatars are disabled
	*/
	public static function get ($user, $size = 64) {
		$mode = OC_Config::getValue("avatar", "local");
		if ($mode === "none") {
			// avatars are disabled
			return false;
		} elseif ($mode === "gravatar") {
			$email = OC_Preferences::getValue($user, 'settings', 'email');
			if ($email !== null) {
				$emailhash = md5(strtolower(trim($email)));
				$url = "http://www.gravatar.com/avatar/".$emailhash."?s=".$size;
				return $url;
			} else {
				return \OC_Avatar::getDefaultAvatar($size);
			}
		} elseif ($mode === "local") {
			if (false) {
				//
			} else {
				return \OC_Avatar::getDefaultAvatar($size);
			}
		}
	}


	/**
	 * @brief sets the users local avatar
	 * @param $user string user to set the avatar for
	 * @param $path string path where the avatar is
	 * @return true on success
	*/
	public static function setLocalAvatar ($user, $path) {
		if (OC_Config::getValue("avatar", "local") === "local") {
			//
		}
	}

	/**
	 * @brief gets the default avatar
	 * @return link to the default avatar
	*/
	public static function getDefaultAvatar ($size) {
		return OC_Helper::imagePath("core", "defaultavatar.png");
	}
}