/**
  * 生成随机头像identicon
  * @param $str 字符串
  * @param int $size 大小
  * @return string uri
  */
 function get_identicon($str, $size = 64)
 {
     require_once APPPATH . 'third_party/identicon/autoload.php';
     $identicon = new \Identicon\Identicon();
     $imageDataUri = $identicon->getImageDataUri($str, $size);
     return $imageDataUri;
 }
Beispiel #2
0
 public function getAvater()
 {
     // 说明: Gravatar 随机头像太丑了 所以使用 Identicon 随机头像
     // TODO 保存头像图片 加缓存
     // return $this->getGravatar();
     $identicon = new \Identicon\Identicon();
     return $identicon->getImageDataUri($this->email, $this->size);
 }
Beispiel #3
0
 /**
  * 添加内容
  */
 public static function add()
 {
     $data = self::baseFrom();
     //自动生成头像
     \Core\Func\CoreFunc::$defaultPath = false;
     require PES_PATH . '/Expand/Identicon/autoload.php';
     $identicon = new \Identicon\Identicon();
     $data['mes']['user_head'] = $identicon->getImageDataUri($_POST['user_mail']);
     if ($data['status'] == false) {
         return self::error($data['mes']);
     }
     $addResult = self::db('user')->insert($data['mes']);
     if (empty($addResult)) {
         return self::error($GLOBALS['_LANG']['USER']['ADD_CONTENT_FAIL']);
     }
     return self::success($addResult);
 }
Beispiel #4
0
 /**
  * 注册帐号
  */
 public function signup()
 {
     if (\Model\Option::findOption('signup')['value'] == '0') {
         $this->error('本系统没有开启注册。');
     }
     $data['user_account'] = $this->isP('account', '请填写帐号');
     $existAccount = \Model\Content::findContent('user', $data['user_account'], 'user_account');
     if (!empty($existAccount)) {
         $this->error('帐号已存在');
     }
     $data['user_password'] = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $this->isP('password', '请填写密码'), 'PRIVATE_KEY');
     $repwd = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $this->isP('repassword', '请填写密码'), 'PRIVATE_KEY');
     if ($data['user_password'] != $repwd) {
         $this->error('两次密码不一致');
     }
     $data['user_mail'] = $this->isP('mail', '请填写帐号');
     $existEmail = \Model\Content::findContent('user', $data['user_mail'], 'user_mail');
     if (!empty($existEmail)) {
         $this->error('邮箱地址已存在');
     }
     \Core\Func\CoreFunc::$defaultPath = false;
     require PES_PATH . '/Expand/Identicon/autoload.php';
     $identicon = new \Identicon\Identicon();
     $imageDataUri = $identicon->getImageDataUri($data['user_mail']);
     $data['user_name'] = $this->isP('name', '请填写帐号');
     $data['user_status'] = '1';
     $data['user_createtime'] = time();
     $data['user_department_id'] = '2';
     //人事部
     $data['user_group_id'] = '2';
     //普通用户
     $data['user_head'] = $imageDataUri;
     $addResult = $this->db('user')->insert($data);
     if (empty($addResult)) {
         $this->error('注册失败');
     }
     unset($data['user_password']);
     $data['user_id'] = $addResult;
     $this->setLogin($data);
     $this->success('注册成功!', $this->url(GROUP . '-Index-index'));
 }
Beispiel #5
0
 public function run()
 {
     if (empty($_GET['id'])) {
         throw new BadRequest();
     }
     $userId = $_GET['id'];
     $user = $this->getEntityManager()->getEntity('User', $userId);
     if (!$user) {
         throw new NotFound();
     }
     if (isset($_GET['attachmentId'])) {
         $id = $_GET['attachmentId'];
         if ($id == 'false') {
             $id = false;
         }
     } else {
         $id = $user->get('avatarId');
     }
     $size = null;
     if (!empty($_GET['size'])) {
         $size = $_GET['size'];
     }
     if (!empty($id)) {
         $this->show($id, $size);
     } else {
         $identicon = new \Identicon\Identicon();
         if (empty($size)) {
             $size = 'small';
         }
         if (!empty($this->imageSizes[$size])) {
             $width = $this->imageSizes[$size][0];
             header('Cache-Control: max-age=360000, must-revalidate');
             header('Content-Type: image/png');
             ob_clean();
             flush();
             $identicon->displayImage($userId, $width, $this->getColor($userId));
             exit;
         }
     }
 }
Beispiel #6
0
 /**
  * 导入数据库
  */
 public function import()
 {
     $title = $this->isP('title', '请填写系统的标题');
     $urlModel = $this->isP('urlModel', '请选择URL模式', FALSE);
     $data['user_account'] = $this->isP('account', '请填写管理员帐号');
     $data['user_password'] = \Core\Func\CoreFunc::generatePwd($data['user_account'] . $this->isP('passwd', '请填写管理员密码'), 'PRIVATE_KEY');
     $data['user_name'] = $this->isP('name', '请填写管理员名称');
     $data['user_mail'] = $this->isP('mail', '请填写管理员邮箱');
     //读取数据库文件
     $sqlFile = file_get_contents(PES_PATH . '/Install/InstallDb/team.sql');
     if (empty($sqlFile)) {
         $this->error('无法读取安装SQL文件');
     }
     //配置PDO信息
     $config = \Core\Func\CoreFunc::loadConfig();
     try {
         $db = new \PDO("mysql:host={$config['DB_HOST']};port={$config['DB_PORT']};dbname={$config['DB_NAME']}", $config['DB_USER'], $config['DB_PWD']);
     } catch (\PDOException $e) {
         $this->error($e->getMessage());
     }
     //安装数据库文件
     $db->exec($sqlFile);
     \Core\Func\CoreFunc::$defaultPath = false;
     require PES_PATH . '/Expand/Identicon/autoload.php';
     $identicon = new \Identicon\Identicon();
     $imageDataUri = $identicon->getImageDataUri($data['user_mail']);
     $data['user_head'] = $imageDataUri;
     $data['user_department_id'] = $data['user_status'] = $data['user_group_id'] = '1';
     //写入管理员帐号
     $this->db('user')->insert($data);
     //更新系统配置
     \Model\Option::update('sitetitle', $title);
     \Model\Option::update('urlModel', $urlModel);
     //更新根目录的index.php
     $readWriteFile = file_get_contents(PES_PATH . '/Install/Write/index.php');
     $fopen = fopen(PES_PATH . '/index.php', 'w+');
     fwrite($fopen, $readWriteFile);
     fclose($fopen);
     //标记程序已安装和移除安装数据库文件
     unlink(PES_PATH . '/Install/index.php');
     unlink(PES_PATH . '/Install/InstallDb/team.sql');
     fclose(fopen(PES_PATH . '/Install/install.txt', 'w+'));
     fclose(fopen(PES_PATH . '/Install/index.html', 'w+'));
     $this->success('安装完成!');
 }
Beispiel #7
0
    }
    if ($defaultMode == '404') {
        err(404, 'File does not exist');
    } else {
        if ($defaultMode == 'redirect') {
            header('Location: ' . $default);
            exit;
        } else {
            if ($defaultMode == 'local') {
                $imgFile = $varDir . $targetSize . '/' . $default;
                if (!file_exists($imgFile)) {
                    err(500, 'Default file is missing');
                }
            } else {
                if ($defaultMode == 'identicon') {
                    $identicon = new \Identicon\Identicon();
                    $identicon->displayImage($reqHash, $reqSize);
                    exit;
                } else {
                    err(500, 'Invalid defaultMode');
                }
            }
        }
    }
}
$stat = stat($imgFile);
$etag = sprintf('%x-%x-%x', $stat['ino'], $stat['size'], $stat['mtime'] * 1000000);
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
    header('Etag: "' . $etag . '"');
    header('HTTP/1.0 304 Not Modified');
    exit;
Beispiel #8
0
 /**
  * Create a new avatar fir this user. Overwrites the old one if it exists.
  *
  * @return bool
  */
 public function createAvatar()
 {
     $identicon = new \Identicon\Identicon();
     \File::put($this->avatarPath, $identicon->getImageData($this->id, 164, null, "#ffffff"));
     return file_exists($this->avatarPath);
 }
Beispiel #9
0
 public function getIdenticon($size = 30)
 {
     $identicon = new \Identicon\Identicon();
     return $identicon->getImageDataUri($this->email . $this->name, $size);
 }
Beispiel #10
0
 /**
  * use a default icon in case of errors while processing uploaded files
  */
 public function useDefaultImage()
 {
     $identicon = new \Identicon\Identicon();
     $this->avatar = $identicon->getImageDataUri($this->user->email);
 }
Beispiel #11
0
 /**
  * 生成头像图标
  * @param $size
  * @return string
  */
 protected function getIdenticon($size)
 {
     $identicon = new \Identicon\Identicon();
     return $identicon->getImageDataUri($this->email, $size);
 }
<?php

Route::group(['prefix' => config('kregel.identicon.route'), 'as' => 'identicon::'], function () {
    Route::get('p/{base_text}/{size?}/{text_hexcolors?}/{bg_color?}', ['as' => 'main', 'uses' => function ($base_text, $size = 64, $color = null, $backgroundColor = null) {
        $idencticon = new \Identicon\Identicon();
        return response($idencticon->getImageData($base_text, $size, $color, $backgroundColor), 200, ['Content-type' => 'image/png']);
    }]);
    Route::get('i/{base_text}/{size?}/{text_hexcolors?}/{bg_color?}', ['as' => 'text', 'uses' => function ($base_text, $size = 64, $color = null, $backgroundColor = null) {
        $idencticon = new Kregel\Identicon\Initials\Generator();
        return response($idencticon->getImageData($base_text, $size, $color, $backgroundColor), 200, ['Content-type' => 'image/png']);
    }]);
});
 public function getIdenticonImageDataUri($size = 32)
 {
     $identicon = new \Identicon\Identicon();
     return $identicon->getImageDataUri($this->getSecretHash(), $size);
 }