Beispiel #1
0
 protected function uploadVoice($vfile, $ifile)
 {
     $vinfo = new VoiceInfo($_REQUEST);
     $this->assign('upinfo', $vinfo);
     $vinfo->checkDetail();
     if ($vfile['error']) {
         throw new VoiceException(CommonMessages::get()->msg('NOT_UPLOAD'));
     }
     if ($vfile['size'] > VOICE_SIZE_MAX_KB * 1024) {
         throw new VoiceException(CommonMessages::get()->msg('VOICE_SIZE_MAX_MB'));
     }
     $infos = $this->voiceDb->getInfosByUser($this->userid);
     $amount = $vfile['size'] / 1024;
     foreach ($infos as $info) {
         $amount += $info->sizeKb;
     }
     if ($amount > PERSONAL_SIZE_LIMIT_KB) {
         throw new VoiceException(CommonMessages::get()->msg('FILE_AMOUNT_MAX_OVER'));
     }
     ///// save voice
     $vinfo = $this->voiceDb->newInfo($this->userid);
     $vinfo->copyDetail($_REQUEST);
     $dst = $this->voiceFile->save($vfile, $vinfo);
     ///// save image
     if ($ifile['size'] > 0) {
         $imageInfo = $this->imageFile->save($this->userid, $ifile);
         $vinfo->imageid = $imageInfo->imageid;
     }
     ///// update record
     $vinfo->dst = $dst;
     $vinfo->sizeKb = $vfile['size'] / 1024;
     $this->voiceDb->updateInfo($vinfo);
     $this->voiceDb->updateDetail($vinfo);
     $this->assign('mode', 'uploaded');
 }
Beispiel #2
0
 protected function checkSession()
 {
     $userid = (int) LoginSession::get()->check();
     if (!$userid) {
         throw new VoiceException(CommonMessages::get()->msg('NO_SESSION'));
     }
     $this->userid = $userid;
 }
Beispiel #3
0
 function handle()
 {
     $path = $this->imageInfo->getFilePath($this->size);
     if (!file_exists($path)) {
         throw new VoiceException(CommonMessages::get()->msg('NO_FILE'));
     }
     $ct = ImageFile::type2ContentType($this->imageInfo->type);
     if ($ct) {
         header("Content-type: {$ct}");
     }
     header('Content-Length: ' . filesize($path));
     readfile($path);
 }
Beispiel #4
0
 private function getPlaylistInfo()
 {
     if ($this->playlistInfo) {
         return $this->playlistInfo;
     }
     if (!is_numeric($this->pid)) {
         throw new VoiceException(CommonMessages::get()->msg('INVALID_PARAMETER'));
     }
     $playlistInfo = $this->playlistDb->getInfo($this->pid);
     if (!$playlistInfo) {
         throw new VoiceException(CommonMessages::get()->msg('NO_PLAYLIST_INFO'));
     }
     $this->playlistInfo = $playlistInfo;
     return $this->playlistInfo;
 }
Beispiel #5
0
 function save(array $src, VoiceInfo $info)
 {
     $pathSrc = $src['tmp_name'];
     $type = $this->validContentTypes[$src['type']];
     if (!$type) {
         throw new VoiceException(CommonMessages::get()->msg('NOT_AUDIO_FILE'), $src);
     }
     //		$dirDst = VOICE_DIR . $info->uploadTime->format('Y/m-d/');
     $dirDst = sprintf("%suser%d/", VOICE_DIR, $info->userid);
     if (!file_exists($dirDst)) {
         mkdir($dirDst, 0777, true);
     }
     $pathDst = $dirDst . $info->voiceid . ".mp3";
     copy($pathSrc, $pathDst);
     return $pathDst;
 }
Beispiel #6
0
 function handleUpdate()
 {
     $user = new UserInfo(array('user_id' => $this->userid, 'password' => $_REQUEST['password']));
     if (!$this->userDb->authorizeUser($user)) {
         throw new VoiceWarning(CommonMessages::get()->msg('AUTH_ERROR'));
     }
     $passNew = $_REQUEST['password_new'];
     $passRetype = $_REQUEST['password_retype'];
     if ($passNew != $passRetype) {
         throw new VoiceWarning(CommonMessages::get()->msg('NOT_MATCH_PASSWORDS'));
     }
     $user = new UserInfo(array('user_id' => $this->userid, 'password' => $passNew));
     $warn = $user->checkPassword();
     if ($warn) {
         throw new VoiceWarning($warn);
     }
     $this->userDb->updateUser($user);
     $this->assign('mode', 'updated');
 }
Beispiel #7
0
 function save($userid, array $src)
 {
     $pathSrc = $src['tmp_name'];
     $type = $this->validContentTypes[$src['type']];
     if (!$type) {
         throw new VoiceException(CommonMessages::get()->msg('NOT_IMAGE_FILE'));
     }
     switch ($type) {
         case 'jpg':
             $img = imagecreatefromjpeg($pathSrc);
             break;
         case 'png':
             $img = imagecreatefrompng($pathSrc);
             break;
     }
     $srcSize = array('height' => imagesy($img), 'width' => imagesx($img));
     $info = $this->imageDb->newInfo(new ImageInfo(array('user_id' => $userid, 'type' => $type)));
     if (!$info) {
         throw new VoiceException(CommonMessages::get()->msg('UNKNOWN'));
     }
     foreach (array(ImageInfo::ICON_SIZE, ImageInfo::WALL_SIZE) as $blockSize) {
         $path = $info->getFilePath($blockSize);
         $dirDst = dirname($path);
         if (!is_dir($dirDst)) {
             mkdir($dirDst, 0777, true);
         }
         $reSize = $this->calcMaxSize($blockSize, $srcSize);
         $dst = imagecreatetruecolor($reSize['width'], $reSize['height']);
         imagecopyresampled($dst, $img, 0, 0, 0, 0, $reSize['width'], $reSize['height'], $srcSize['width'], $srcSize['height']);
         switch ($type) {
             case 'jpg':
                 imagejpeg($dst, $path, 80);
                 break;
             case 'png':
                 imagepng($dst, $path, 80);
                 break;
         }
         imagedestroy($dst);
     }
     return $info;
 }
Beispiel #8
0
 protected function handle()
 {
     ///// current
     $vid = $this->playlistInfo->voiceids[$this->index];
     if (!$vid) {
         $this->index = 0;
         $vid = $this->playlistInfo->getVoiceId(0);
     }
     $vinfo = $this->voiceDb->getInfo($vid);
     if (!$vinfo) {
         throw new VoiceException(CommonMessages::get()->msg('NO_VOICE_INFO'));
     }
     $this->voiceDb->getDetail($vinfo);
     $this->assign('status', 'ok');
     $this->assign('current_voice', $vinfo->toArray());
     ///// previous
     if ($this->index > 0) {
         $pid = $this->playlistInfo->getVoiceId($this->index - 1);
         if ($pid) {
             $pinfo = $this->voiceDb->getInfo($pid);
         }
         if ($pinfo) {
             $this->assign('previous_voice', $pinfo->toArray());
         }
     }
     ///// next
     $nid = $this->playlistInfo->getVoiceId($this->index + 1);
     if ($nid) {
         $ninfo = $this->voiceDb->getInfo($nid);
     }
     if ($ninfo) {
         $this->assign('next_voice', $ninfo->toArray());
     }
     $memory = array('mode' => 'playlist', 'playlist_id' => $this->playlistInfo->playlistid, 'index' => $this->index);
     $this->assign('memory', $memory);
 }
Beispiel #9
0
 function handle()
 {
     $command = $_REQUEST['command'];
     switch ($this->mode) {
         case self::MODE_NOT_LOGINED:
             if ($command != 'login') {
                 break;
             }
             $this->user = $this->db->authorizeUser($this->user);
             if (!$this->user->userid) {
                 throw new VoiceException(CommonMessages::get()->msg('LOGIN_ERROR'));
             }
             LoginSession::get()->make($this->user->userid);
             $this->assignHash(LoginSession::get()->getSessionArray());
             $this->assign('logined', true);
             break;
         case self::MODE_LOGINED:
             if ($command == 'logout') {
                 LoginSession::get()->clear();
                 $this->assign('logined', false);
             }
             break;
     }
 }
Beispiel #10
0
 function __construct($id, $array = null)
 {
     $message = CommonMessages::get()->msg($id);
     parent::__construct($message, $array);
 }