diff --git a/docs/Sysconfig-Keys.md b/docs/Sysconfig-Keys.md index 0eedab924..079045d28 100644 --- a/docs/Sysconfig-Keys.md +++ b/docs/Sysconfig-Keys.md @@ -75,7 +75,8 @@ * `event_end_notification_title`: Title to be used for a notification when the event ends * `event_end_notification_body`: The body that will be used to send a notification to all players when the event ends * `plus_writeups`: Number to add to the headshots to allow for writeup activations (eg. a value of `2` means that the player can have `player_headshots+2` writeups active at most). A value of `0` means that the player can have only as many writeups active as its own number of headshots. - +* `avatar_generator`: If set to `Identicon` it will use that instead of Robohash +* `avatar_robohash_set`: Choose the set for when robohash is configured * `mail_verification_token_validity`: How long will the mail verification tokens be active for. Can take intervals supported by php and `INTERVAL`, eg. 10 day, meaning 10 days from now * `password_reset_token_validity`: How long will the password reset tokens be active for. Can take intervals supported by php and `INTERVAL`, eg. 10 day, meaning 10 days from now diff --git a/frontend/commands/GeneratorController.php b/frontend/commands/GeneratorController.php index 7ebf43b99..55a201d18 100644 --- a/frontend/commands/GeneratorController.php +++ b/frontend/commands/GeneratorController.php @@ -233,7 +233,7 @@ public function actionAvatar($active = true, $atomic = true) $dst_img = \Yii::getAlias('@app/web/images/avatars/' . $player->profile->id . '.png'); if ($player->profile->avatar === 'default.png' || !$player->profile->avatar || !file_exists($dst_img)) { echo "Generating " . $player->username . " profile avatar image.\n"; - $robohash = new \app\models\Robohash($player->profile->id, 'set1'); + $robohash = new \app\components\generators\AvatarGenerator($player->profile->id); $image = $robohash->generate_image(); if (get_resource_type($image) === 'gd') { imagepng($image, $dst_img); diff --git a/frontend/components/generators/AvatarGenerator.php b/frontend/components/generators/AvatarGenerator.php new file mode 100644 index 000000000..49022b7b7 --- /dev/null +++ b/frontend/components/generators/AvatarGenerator.php @@ -0,0 +1,42 @@ +text = $text; + $this->set = $set; + $this->color = $color; + $this->width = self::IMAGE_WIDTH; + $this->height = self::IMAGE_WIDTH; + if (\Yii::$app->sys->avatar_generator === 'Identicon') { + $this->generator = new \app\components\generators\Identicon($this->text, $this->set); + } else { + $this->generator = new \app\components\generators\Robohash($this->text, $this->set); + } + } + + public function generate_image() + { + return $this->generator->generate_image(); + } +} diff --git a/frontend/components/generators/Identicon.php b/frontend/components/generators/Identicon.php new file mode 100644 index 000000000..05d44fc10 --- /dev/null +++ b/frontend/components/generators/Identicon.php @@ -0,0 +1,27 @@ +text = $text; + $this->set = $set; + $this->color = $color; + $this->width = self::IMAGE_WIDTH; + $this->height = self::IMAGE_WIDTH; + $this->model=new \Identicon\Identicon(); + } + + public function generate_image() + { + return $this->model->getImageResource($this->text,self::IMAGE_WIDTH,$this->color); + } + +} \ No newline at end of file diff --git a/frontend/models/Robohash.php b/frontend/components/generators/Robohash.php similarity index 98% rename from frontend/models/Robohash.php rename to frontend/components/generators/Robohash.php index caa034845..d1b42e33f 100644 --- a/frontend/models/Robohash.php +++ b/frontend/components/generators/Robohash.php @@ -4,7 +4,7 @@ // https://github.com/hush2/php-robohash.git // Extra sets and images from https://github.com/e1ven/Robohash.git -namespace app\models; +namespace app\components\generators; use yii\base\Widget; use yii\helpers\Html; @@ -40,7 +40,8 @@ public function __construct($text,$set=null,$color=null) { $this->image_dir = \Yii::getAlias('@app/web/images/robohash/'); $this->text=$text; - $this->set=$set; + if($set===null) + $this->set=\Yii::$app->sys->avatar_robohash_set; $this->color=$color; $this->width = self::IMAGE_WIDTH; $this->height = self::IMAGE_WIDTH; diff --git a/frontend/composer.json b/frontend/composer.json index 466f5f630..b1b0b351f 100644 --- a/frontend/composer.json +++ b/frontend/composer.json @@ -17,9 +17,8 @@ "yiisoft/yii2-bootstrap4": "^2.0", "overals/yii2-whois": "~1.0.0", "stripe/stripe-php": "^12.0", - "yiisoft/yii2-symfonymailer": "^4.0.0" - }, - "require-dev": { + "yiisoft/yii2-symfonymailer": "^4.0.0", + "yzalis/identicon": "^2.0" }, "config": { "platform-check": false, diff --git a/frontend/models/Player.php b/frontend/models/Player.php index 4a7dd4597..bce213acc 100644 --- a/frontend/models/Player.php +++ b/frontend/models/Player.php @@ -195,10 +195,10 @@ public function generatePasswordResetToken() { if (($model = PlayerToken::findOne(['player_id' => $this->id, 'type' => 'password_reset'])) === null) { $model = new PlayerToken(); - $validity=(\Yii::$app->sys->password_reset_token_validity===false) ? '10 day':\Yii::$app->sys->password_reset_token_validity; + $validity = (\Yii::$app->sys->password_reset_token_validity === false) ? '10 day' : \Yii::$app->sys->password_reset_token_validity; $model->player_id = $this->id; $model->type = 'password_reset'; - $model->expires_at = \Yii::$app->formatter->asDatetime(new \DateTime('NOW + '.$validity), 'php:Y-m-d H:i:s'); + $model->expires_at = \Yii::$app->formatter->asDatetime(new \DateTime('NOW + ' . $validity), 'php:Y-m-d H:i:s'); $model->token = str_replace('_', '-', Yii::$app->security->generateRandomString(30)); $model->save(); } @@ -208,10 +208,10 @@ public function generateEmailVerificationToken() { if (($model = PlayerToken::findOne(['player_id' => $this->id, 'type' => 'email_verification'])) === null) { $model = new PlayerToken(); - $validity=(\Yii::$app->sys->mail_verification_token_validity===false) ? '10 day':\Yii::$app->sys->mail_verification_token_validity; + $validity = (\Yii::$app->sys->mail_verification_token_validity === false) ? '10 day' : \Yii::$app->sys->mail_verification_token_validity; $model->player_id = $this->id; $model->type = 'email_verification'; - $model->expires_at = \Yii::$app->formatter->asDatetime(new \DateTime('NOW + '.$validity), 'php:Y-m-d H:i:s'); + $model->expires_at = \Yii::$app->formatter->asDatetime(new \DateTime('NOW + ' . $validity), 'php:Y-m-d H:i:s'); $model->token = str_replace('_', '-', Yii::$app->security->generateRandomString(30)); $model->save(); } @@ -370,7 +370,8 @@ public function genAvatar() } if (file_exists($avatarPNG)) return; - $robohash = new \app\models\Robohash($_pID, 'set1'); + + $robohash = new \app\components\generators\AvatarGenerator($_pID); $image = $robohash->generate_image(); if ((gettype($image) === "object" && get_class($image) === "GdImage") || ((int) phpversion() === 7 && gettype($image) === 'resource')) { imagepng($image, $avatarPNG); diff --git a/frontend/themes/material/profile/_profile_settings.php b/frontend/themes/material/profile/_profile_settings.php index 1ee89afd6..cb633bcd0 100644 --- a/frontend/themes/material/profile/_profile_settings.php +++ b/frontend/themes/material/profile/_profile_settings.php @@ -6,7 +6,6 @@ use yii\helpers\Html; use yii\helpers\ArrayHelper; use app\models\Country; -use app\models\Avatar; $this->_fluid="-fluid"; ?>