szurubooru/src/Models/Model_User.php

55 lines
1.3 KiB
PHP
Raw Normal View History

2013-10-12 14:53:47 +02:00
<?php
class Model_User extends RedBean_SimpleModel
{
2013-10-14 00:25:40 +02:00
public function getAvatarUrl($size = 32)
2013-10-12 14:53:47 +02:00
{
$subject = !empty($this->email)
? $this->email
: $this->pass_salt . $this->name;
2013-10-12 14:53:47 +02:00
$hash = md5(strtolower(trim($subject)));
$url = 'http://www.gravatar.com/avatar/' . $hash . '?s=' . $size . '&d=retro';
return $url;
}
2013-10-14 00:25:40 +02:00
public function getSetting($key)
{
$settings = json_decode($this->settings, true);
return isset($settings[$key])
? $settings[$key]
: null;
}
public function setSetting($key, $value)
{
$settings = json_decode($this->settings, true);
$settings[$key] = $value;
$settings = json_encode($settings);
if (strlen($settings) > 200)
throw new SimpleException('Too much data');
$this->settings = $settings;
}
public function hasEnabledSafety($safety)
{
return $this->getSetting('safety-' . $safety) !== false;
}
public function enableSafety($safety, $enabled)
{
if (!$enabled)
{
$this->setSetting('safety-' . $safety, false);
$anythingEnabled = false;
foreach (PostSafety::getAll() as $safety)
if (self::hasEnabledSafety($safety))
$anythingEnabled = true;
if (!$anythingEnabled)
$this->setSetting('safety-' . PostSafety::Safe, true);
}
else
{
$this->setSetting('safety-' . $safety, true);
}
}
2013-10-12 14:53:47 +02:00
}