public function upload()
 {
     if (!panel()->user()->isAdmin() and !$this->user->isCurrent()) {
         throw new Exception(l('users.avatar.error.permission'));
     }
     $root = $this->exists() ? $this->root() : $this->user->avatarRoot('{safeExtension}');
     $upload = new Upload($root, array('accept' => function ($upload) {
         if ($upload->type() != 'image') {
             throw new Error(l('users.avatar.error.type'));
         }
     }));
     if (!$upload->file()) {
         throw $upload->error();
     }
     thumb::$defaults['root'] = dirname($upload->file()->root());
     $thumb = new Thumb($upload->file(), array('filename' => $upload->file()->filename(), 'overwrite' => true, 'width' => 256, 'height' => 256, 'crop' => true));
     kirby()->trigger('panel.avatar.upload', $this);
 }
Esempio n. 2
0
 public function upload()
 {
     if (!panel()->user()->isAdmin() and !$this->user->isCurrent()) {
         throw new Exception(l('users.avatar.error.permission'));
     }
     $root = $this->exists() ? $this->root() : $this->user->avatarRoot('{safeExtension}');
     $upload = new Upload($root, array('accept' => function ($upload) {
         if ($upload->type() != 'image') {
             throw new Error(l('users.avatar.error.type'));
         }
     }));
     if (!$upload->file()) {
         throw $upload->error();
     }
     // flush the cache in case if the user data is
     // used somewhere on the site (i.e. for profiles)
     kirby()->cache()->flush();
     kirby()->trigger('panel.avatar.upload', $this);
 }