<!-- /user.3rdPartyAuth -->
<!-- user.avatar -->
+ <option name="avatar_default_type">
+ <categoryname>user.avatar</categoryname>
+ <optiontype>select</optiontype>
+ <defaultvalue>initials</defaultvalue>
+ <selectoptions>initials:wcf.acp.option.avatar_default_type.initials
+silhouette:wcf.acp.option.avatar_default_type.silhouette</selectoptions>
+ </option>
<option name="gravatar_default_type">
<categoryname>user.avatar</categoryname>
<optiontype>select</optiontype>
*/
public $size = UserAvatar::AVATAR_SIZE;
+ /**
+ * content of the `src` attribute
+ * @var string
+ */
+ protected $src = '';
+
+ /**
+ * DefaultAvatar constructor.
+ *
+ * @param string $username username for use with the 'initials' avatar type
+ */
+ public function __construct($username = '') {
+ if (defined('AVATAR_DEFAULT_TYPE') && AVATAR_DEFAULT_TYPE === 'initials' && !empty($username)) {
+ $words = explode(' ', $username);
+ $count = count($words);
+ if ($count > 1) {
+ // combine the first character of each the first and the last word
+ $text = mb_strtoupper(mb_substr($words[0], 0, 1) . mb_substr($words[$count - 1], 0, 1));
+ }
+ else {
+ // use the first two characters
+ $text = mb_strtoupper(mb_substr($username, 0, 2));
+ }
+
+ $backgroundColor = substr(sha1($username), 0, 6);
+
+ $perceptiveLuminance = $this->getPerceptiveLuminance(
+ hexdec($backgroundColor[0] . $backgroundColor[1]),
+ hexdec($backgroundColor[2] . $backgroundColor[3]),
+ hexdec($backgroundColor[4] . $backgroundColor[5])
+ );
+
+ $textColor = ($perceptiveLuminance < 0.3) ? '000' : 'fff';
+
+ // the <path> is basically a shorter version of a <rect>
+ $svg = <<<SVG
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#{$backgroundColor}" d="M0 0h16v16H0z"/><text x="8" y="8" fill="#{$textColor}" text-anchor="middle" alignment-baseline="central" font-family="Arial" font-size="7">{$text}</text></svg>
+SVG;
+
+ $this->src = "data:image/svg+xml;base64," . base64_encode($svg);
+ }
+ else {
+ $this->src = WCF::getPath().'images/avatars/avatar-default.svg';
+ }
+ }
+
/**
* @inheritDoc
*/
public function getURL($size = null) {
- return WCF::getPath().'images/avatars/avatar-default.svg';
+ return $this->src;
}
/**
public function getCropImageTag($size = null) {
return '';
}
+
+ /**
+ * Returns the perceived luminance of the given color.
+ *
+ * @param integer $r
+ * @param integer $g
+ * @param integer $b
+ * @return float luminance expressed in a float in the range of 0 and 1
+ */
+ protected function getPerceptiveLuminance($r, $g, $b) {
+ return 1 - (0.299 * $r + 0.587 * $g + 0.114 * $b) / 255;
+ }
}
<item name="wcf.acp.option.use_page_title_on_landing_page"><![CDATA[Titel der Seite als Überschrift auf Startseite anzeigen]]></item>
<item name="wcf.acp.option.head_code"><![CDATA[Head-Code]]></item>
<item name="wcf.acp.option.head_code.description"><![CDATA[Der hier angegebene Code wird im Head-Tag jeder Seite ausgegeben. Der Head-Code eignet sich z.B. sehr gut für die Einbindung von zusätzlichen Meta-Tags.]]></item>
+ <item name="wcf.acp.option.avatar_default_type"><![CDATA[Standard Avatar-Typ]]></item>
+ <item name="wcf.acp.option.avatar_default_type.initials"><![CDATA[Initialen]]></item>
+ <item name="wcf.acp.option.avatar_default_type.silhouette"><![CDATA[Silhouette]]></item>
</category>
<category name="wcf.acp.package">
<item name="wcf.acp.option.use_page_title_on_landing_page"><![CDATA[Use page title on landing page]]></item>
<item name="wcf.acp.option.head_code"><![CDATA[Head Code]]></item>
<item name="wcf.acp.option.head_code.description"><![CDATA[The entered code will be appended to the head tag of your site. You can use it to add additional meta tags.]]></item>
+ <item name="wcf.acp.option.avatar_default_type"><![CDATA[Default Avatar Type]]></item>
+ <item name="wcf.acp.option.avatar_default_type.initials"><![CDATA[Initials]]></item>
+ <item name="wcf.acp.option.avatar_default_type.silhouette"><![CDATA[Silhouette]]></item>
</category>
<category name="wcf.acp.package">