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'); }
/** * シングルトンオブジェクトを取得する * @access public * @return CommonMessages インスタンス */ public static function getInstance() { if (CommonMessages::$singleton == null) { CommonMessages::$singleton = new CommonMessages(); } return CommonMessages::$singleton; }
protected function checkSession() { $userid = (int) LoginSession::get()->check(); if (!$userid) { throw new VoiceException(CommonMessages::get()->msg('NO_SESSION')); } $this->userid = $userid; }
public static function get() { if (!self::$instance) { self::$instance = new self(); self::$instance->load(self::$lang); } return self::$instance; }
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); }
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; }
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; }
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'); }
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; }
/** * 初期処理 * @access public * @param Object $contextt context * @return boolean 処理結果 */ public function initialize($context) { parent::initialize($context); /* 初期値をセットする */ $this->controller = $context->getController(); $this->request = $context->getRequest(); $this->user = $context->getUser(); $this->moduleName = $context->getModuleName(); $this->actionName = $context->getActionName(); $this->messages =& CommonMessages::getInstance(); /* フォーム登録リストのフォームをsmartyにすべてセットする */ $o_smarty =& $this->getEngine(); $o_smarty->register_object("style", $this, array("request", "checkErrorElement")); $this->quickformSmarty = new HTML_QuickForm_Renderer_ArraySmarty($this->getEngine()); $formList = $this->request->getAttribute('formList'); foreach ($formList as $formName) { $this->setForm($formName); } /* メッセージをsmartyにセットする */ if ($this->request->hasAttribute('messages')) { $messages =& $this->request->getAttribute('messages'); $messages = array_unique($messages); $this->setAttributeByRef('messages', $messages); } /* エラーメッセージをsmartyにセットする */ if ($this->request->hasErrors()) { $errors =& $this->request->getErrors(); $errors = array_unique($errors); $this->setAttributeByRef('errors', $errors); } // 共通の CSS をセット array_push($this->css_file_array, ACS_SELECTION_CSS_DIR . 'default.css'); $this->setAttribute('include_css_array', $this->css_file_array); // 共通の JS をセット array_push($this->js_file_array, ACS_JS_DIR . 'swap.js'); $this->setAttribute('include_script_array', $this->js_file_array); return true; }
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); }
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; } }
function __construct($id, $array = null) { $message = CommonMessages::get()->msg($id); parent::__construct($message, $array); }
/** * 初期処理 * @access public * @param Object $context context * @return boolean 処理結果 */ public function initialize($context) { parent::initialize($context); // アクションの共通処理を実装する /* 初期値をセットする */ $this->controller = $context->getController(); $this->request = $context->getRequest(); $this->user = $context->getUser(); $this->moduleName = $context->getModuleName(); $this->actionName = $context->getActionName(); $this->messages =& CommonMessages::getInstance(); /* requestオブジェクトにフォーム登録リストをセットする */ $this->request->setAttributeByRef('formList', $this->formList); $request =& $context->getRequest(); $user =& $context->getUser(); // セッションからユーザIDが取得できず、POSTでユーザIDが取得可能な場合 $user_id = $user->getAttribute('login_user_id'); $justLogin = false; if (($user_id == NULL || $user_id == "") && ($_POST['userid'] != NULL && $_POST['userid'] != "")) { $input_user_id = $_POST['userid']; $input_passwd = $_POST['passwd']; // エラーチェック(.htpasswd、LDAPの順) $user_id = ACSSystem::check_passwd($input_user_id, $input_passwd); if ($user_id) { $justLogin = true; $getLogoutDateEverytime = ACSSystemConfig::get_keyword_value(ACSMsg::get_mst('system_config_group', 'D08'), 'GET_LOGOUT_DATE_EVERYTIME'); $user->setAttribute('getLogoutDateEverytime', $getLogoutDateEverytime); } } // 言語設定の実行 if ($request->getparameter('acsmsg')) { ACSMsg::set_lang($request->getparameter('acsmsg')); ACSMsg::set_lang_cookie($request->getparameter('acsmsg')); } // 権限クリア $user->clearCredentials(); // 認証済みを登録 $user->setAuthenticated(true); // $acs_user_info_rowを設定する // $acs_user_info_row = array(); if ($user_id) { $acs_user_info_row = ACSUser::get_user_info_row_by_user_id($user_id); // ユーザ情報が無い if ($user_id && !$acs_user_info_row['user_id']) { $acs_user_info_row['user_id'] = $user_id; $acs_user_info_row['user_community_id'] = ACS_PUBLIC_USER_COMMUNITY_ID; $acs_user_info_row['is_acs_user'] = false; } else { $acs_user_info_row['is_acs_user'] = true; // 権限登録 $user->addCredential('ACS_USER'); } // ログインユーザ(認証を通過したユーザ)かどうか $acs_user_info_row['is_login_user'] = true; // システム管理者かどうか if ($acs_user_info_row['administrator_flag'] == 't') { // 権限登録 $user->addCredential('SYSTEM_ADMIN_USER'); } // LDAPユーザかどうか (ファイル認証ユーザでなければLDAPユーザとみなす) $acs_user_info_row['is_ldap_user'] = !ACSSystem::is_htpasswd_user($user_id); // LDAP認証以外の場合、パスワード変更権限を付与 if ($acs_user_info_row['is_ldap_user']) { $user->addCredential('LDAP_USER'); } else { $user->addCredential('NOT_LDAP_USER'); } // 未登録のLDAPユーザの場合は氏名を調べる if (!$acs_user_info_row['is_acs_user'] && $acs_user_info_row['is_ldap_user']) { $ldap_user_info_row = ACSLDAP::get_ldap_user_info_row($acs_user_info_row['user_id']); $acs_user_info_row['user_name'] = $ldap_user_info_row['user_name']; } // フレンズIDの配列を取得する $acs_user_info_row['friends_id_array'] = ACSUser::get_friends_id_array($acs_user_info_row['user_community_id']); // 各機能ごとで必要な権限を判別・設定する // マイページ所有者、コミュニティ管理者、メンバの設定など if ($this->moduleName == 'User') { $id = $request->getParameter('id'); if (!$id) { $id = $acs_user_info_row['user_community_id']; } // マイページ所有者かどうか if ($acs_user_info_row['user_community_id'] == $request->getParameter('id')) { $user->addCredential('USER_PAGE_OWNER'); // 友人かどうか } elseif (!ACSUser::is_friends($id, $acs_user_info_row['user_community_id'])) { $user->addCredential('NOT_FRIENDS'); } } elseif ($this->moduleName == 'Community') { $community_id = $request->getParameter('community_id'); // コミュニティIDの指定がある場合のみ、権限設定を行う if ($community_id) { $is_community_member = ACSCommunity::is_community_member($acs_user_info_row['user_community_id'], $community_id); $is_community_admin = ACSCommunity::is_community_admin($acs_user_info_row['user_community_id'], $community_id); // コミュニティメンバかどうか if ($is_community_member) { $user->addCredential('COMMUNITY_MEMBER'); // コミュニティ管理者かどうか if ($is_community_admin) { $user->addCredential('COMMUNITY_ADMIN'); } // コミュニティメンバではない } else { $user->addCredential('NOT_COMMUNITY_MEMBER'); } } } $user->setAttribute('login_user_id', $user_id); } else { $acs_user_info_row['user_name'] = ACS_PUBLIC_USER_NAME; $acs_user_info_row['user_community_id'] = ACS_PUBLIC_USER_COMMUNITY_ID; $acs_user_info_row['is_acs_user'] = false; $acs_user_info_row['is_login_user'] = false; // 権限設定 $user->addCredential('PUBLIC_USER'); } $user->setAttribute('acs_user_info_row', $acs_user_info_row); // ログイン情報作成 if ($justLogin) { ACSUser::set_login_date($user); } // アクセス毎のログアウト時間更新 $getLogoutDateEverytime = $user->getAttribute('getLogoutDateEverytime'); if ($getLogoutDateEverytime != NULL && $getLogoutDateEverytime == "1") { ACSUser::acs_login_date($user); } if ($acs_user_info_row['is_acs_user'] && $acs_user_info_row['open_level_name'] == ACSMsg::get_mst('open_level_master', 'D01')) { // OK } elseif ($acs_user_info_row['is_acs_user'] && $acs_user_info_row['open_level_name'] == ACSMsg::get_mst('open_level_master', 'D03') || !$acs_user_info_row['is_acs_user'] && $acs_user_info_row['is_ldap_user']) { // マイページ全体が非公開のユーザ or 未登録のLDAPユーザ // マイページのプロフィール編集可能な権限を付与する $user->addCredential('USER_PAGE_OWNER'); if ($this->moduleName == DEFAULT_MODULE && ($this->actionName == 'EditProfile' || $this->actionName == 'SetOpenLevelForProfile')) { // 未登録のLDAPユーザの場合、プロフィール設定画面へのアクセスを許可 } else { $edit_profile_url = $this->getControllerPath(DEFAULT_MODULE, 'EditProfile'); header("Location: {$edit_profile_url}"); } } elseif (!$acs_user_info_row['is_acs_user'] && $acs_user_info_row['is_login_user'] && !$acs_user_info_row['is_ldap_user']) { echo "Forbidden"; exit; } // form で enctype="multipart/form-data" の指定が合った場合の対処 // エンコーディングを変換する if (count($_FILES) && !ini_get('mbstring.encoding_translation')) { $request->params = ACSLib::convert_post_data_encoding($request->params); } // 共通アクセス制御 // $access_control_info = $this->get_access_control_info($controller, $request, $user); $valid_flag = true; if ($access_control_info) { $valid_flag = false; if ($access_control_info['role_array'] && $access_control_info['contents_row_array']) { foreach ($access_control_info['contents_row_array'] as $contents_row) { if ($contents_row['community_type_name'] == ACSMsg::get_mst('community_type_master', 'D40')) { if (ACSAccessControl::is_valid_user_for_community($acs_user_info_row, $access_control_info['role_array'], $contents_row)) { $valid_flag = true; } else { $valid_flag = false; break; } } elseif ($contents_row['community_type_name'] == ACSMsg::get_mst('community_type_master', 'D10')) { if (ACSAccessControl::is_valid_user_for_user_community($acs_user_info_row, $access_control_info['role_array'], $contents_row)) { $valid_flag = true; } else { $valid_flag = false; break; } } } } } if (!$valid_flag) { $this->controller->forward(SECURE_MODULE, SECURE_ACTION); exit; } // 各機能固有の権限判別を取得 if ($this->get_execute_privilege($controller, $request, $user)) { $user->addCredential('EXECUTE'); } //return parent::initialize($controller); return true; }