Exemple #1
0
 public function __construct($uid)
 {
     $this->ftype = array('jpg' => 2000, 'png' => 2000, 'jpeg' => 2000);
     $this->mime = array('image/jpeg', 'image/png', 'image/jpg');
     $this->uid = $uid;
     $this->udir = Pw::getUserDir($this->uid);
 }
 public function __construct(PwUserBo $user)
 {
     $this->ftype = array('jpg' => 2000, 'png' => 2000, 'jpeg' => 2000);
     $this->user = $user;
     $this->udir = Pw::getUserDir($this->user->uid);
     $this->mime = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif');
 }
 /**
  * 获取用户头像
  *
  * @param $uid
  * @param $size big middle small
  * @return string
  */
 public function getAction()
 {
     $uid = $this->getInput('uid', 'get');
     $size = $this->getInput('size', 'get');
     !$size && ($size = 'middle');
     $file = $uid . (in_array($size, array('middle', 'small')) ? '_' . $size : '') . '.jpg';
     $result = $this->attachUrl . '/avatar/' . Pw::getUserDir($uid) . '/' . $file;
     $this->output($result);
 }
 /**
  * 头像转移
  */
 public function avatarAction()
 {
     $end_uid = $this->getMaxUid();
     ini_set('max_execution_time', 0);
     $time_start = microtime(true);
     list($ftp, $attachDir) = $this->_getFtp();
     $defauleDir = rtrim(Wind::getRealDir('PUBLIC:res.images.face', true), '/');
     list($start_uid, $end) = $this->_getStartAndLimit(intval($this->getInput('uid', 'get')), $end_uid, $ftp ? true : false);
     while ($start_uid < $end) {
         $res = $this->_getOldAvatarPath($attachDir, $start_uid);
         $big = $res['big'];
         $middle = $res['middle'];
         $small = $res['small'];
         if (!$this->checkFile($middle)) {
             $big = $defauleDir . '/face_big.jpg';
             $middle = $defauleDir . '/face_middle.jpg';
             $small = $defauleDir . '/face_small.jpg';
         }
         $_toPath = '/avatar/' . Pw::getUserDir($start_uid) . '/';
         $to_big = $_toPath . $start_uid . '.jpg';
         $to_middle = $_toPath . $start_uid . '_middle.jpg';
         $to_small = $_toPath . $start_uid . '_small.jpg';
         if ($ftp) {
             $ftp->mkdirs($_toPath);
             $ftp->upload($big, $to_big);
             $ftp->upload($middle, $to_middle);
             $ftp->upload($small, $to_small);
         } else {
             WindFolder::mkRecur($attachDir . $_toPath);
             copy($big, $attachDir . $to_big);
             copy($middle, $attachDir . $to_middle);
             copy($small, $attachDir . $to_small);
         }
         $start_uid++;
     }
     if ($end < $end_uid) {
         $this->setOutput($end, 'uid');
         $this->setOutput($this->getInput('token', 'get'), 'token');
         $this->setTemplate('upgrade_avatar');
     } else {
         $this->showMessage('升级成功!');
     }
 }
Exemple #5
0
 public function getAvatar($uid, $size = 'middle')
 {
     $file = $uid . (in_array($size, array('middle', 'small')) ? '_' . $size : '') . '.jpg';
     return Wekit::app('windid')->config->site->avatarUrl . '/avatar/' . Pw::getUserDir($uid) . '/' . $file;
 }
Exemple #6
0
 /**
  * 初始化用户头像
  * @param int $uid
  * @param string $url 腾讯头像地址
  */
 function restore_avatar($uid, $url)
 {
     $store = Wind::getComponent('storage');
     Wind::import('SRV:upload.PwUpload');
     Wind::import('LIB:image.PwImage');
     $fileDir = sprintf('avatar/%s/', Pw::getUserDir($uid));
     $_avatar = array('.jpg' => 200, '_middle.jpg' => 120, '_small.jpg' => 50);
     $file = tempnam(sys_get_temp_dir(), 'avatar');
     $img = httpget($url);
     file_put_contents($file, $img);
     $img = new PwImage($file);
     $thumb = new PwImageThumb($img);
     foreach ($_avatar as $des => $size) {
         $toPath = $store->getAbsolutePath($uid . $des, $fileDir);
         PwUpload::createFolder(dirname($toPath));
         if ($size < 100) {
             $thumb->setWidth($size);
             $thumb->setHeight($size);
             $thumb->setDstFile($toPath);
             $thumb->execute();
         } else {
             copy($file, $toPath);
         }
     }
     Wind::import('SRV:upload.action.PwAvatarUpload');
     Wind::import('SRV:upload.PwUpload');
     PwSimpleHook::getInstance('update_avatar')->runDo($uid);
     @unlink($file);
     return true;
 }
 private function _defaultAvatar($uid, $type = 'face')
 {
     Wind::import('LIB:upload.PwUpload');
     $_avatar = array('.jpg' => '_big.jpg', '_middle.jpg' => '_middle.jpg', '_small.jpg' => '_small.jpg');
     $defaultBanDir = Wind::getRealDir('ROOT:') . 'res/images/face/';
     $fileDir = 'avatar/' . Pw::getUserDir($uid) . '/';
     $attachPath = Wind::getRealDir('ROOT:') . 'windid/attachment/';
     foreach ($_avatar as $des => $org) {
         $toPath = $attachPath . $fileDir . $uid . $des;
         $fromPath = $defaultBanDir . $type . $org;
         PwUpload::createFolder(dirname($toPath));
         PwUpload::copyFile($fromPath, $toPath);
     }
     return true;
 }