7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
10 * @author 株式会社 毎日メディアサービス
11 * @copyright Copyright 2010 株式会社 毎日メディアサービス.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: m_chachaProfileWidgetContainer.php 3306 2010-06-28 07:07:39Z fishbone $
14 * @link http://www.m-media.co.jp
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/m_chachaBaseWidgetContainer.php');
18 class m_chachaProfileWidgetContainer extends m_chachaBaseWidgetContainer
20 const DEFAULT_PAGE_TITLE = 'プロフィール';
21 const MEMBER_ID_LENGTH = 5; // 会員IDの桁数
26 function __construct()
29 parent::__construct();
34 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
35 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
37 * @param RequestManager $request HTTPリクエスト処理クラス
38 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
39 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
41 function _setTemplate($request, &$param)
43 return 'profile.tmpl.html';
48 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
50 * @param RequestManager $request HTTPリクエスト処理クラス
51 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
54 function _assign($request, &$param)
56 $act = $request->trimValueOf('act');
57 $postTicket = $request->trimValueOf('ticket'); // POST確認用
58 $memberId = $request->trimValueOf(self::URL_PARAM_MEMBER_ID); // 会員ID
61 // ユーザIDでユーザのプロフィールを参照。ユーザIDがない場合は自分自身のプロフィールを表示。
63 $canEdit = false; // データ編集可能かどうか
64 $isNew = false; // 新規登録かどうか
67 $clientId = $this->_mobileId;
69 // 会員情報が登録されている場合は更新。登録されていない場合は新規登録。
70 $clientMemberId = ''; // 現在の端末の会員ID
71 $ret = $this->_db->getMemberInfoByDeviceId($clientId, $row);
72 if ($ret) $clientMemberId = $row['mb_id'];
73 if (empty($memberId)){
74 if (empty($clientMemberId)){
75 $isNew = true; // 新規登録処理
77 $memberId = $clientMemberId;
79 $canEdit = true; // データ編集可能かどうか
80 } else if ($memberId == $clientMemberId){ // 自分自身のデータのとき
81 $canEdit = true; // データ編集可能かどうか
84 $name = $request->mobileTrimValueOf('name'); // ユーザ名
85 $email = $request->mobileTrimValueOf('email'); // Eメール
86 $url = $request->mobileTrimValueOf('url'); // URL
87 $avatar = ''; // アバターファイル名
88 $showEmail = ($request->trimValueOf('show_email') == 'on') ? 1 : 0; // Eメールアドレスを公開するかどうか
90 $reloadData = false; // データの再読み込み
91 if ($act == 'add'){ // 新規追加のとき
92 if (!empty($postTicket) && $postTicket == $request->getSessionValue(M3_SESSION_POST_TICKET)){ // 正常なPOST値のとき
94 $this->checkInput($name, 'ニックネーム');
95 $this->checkMailAddress($email, 'Eメール', true/*空OK*/);
96 $this->checkInput($clientId, '端末ID');
98 if ($this->_db->isExistsMemberName($name)) $this->setUserErrorMsg('このニックネームはすでに存在しています');
101 if ($this->getMsgCount() == 0){
103 $memberId = $this->createMemberId();
104 if (empty($memberId)){
105 $this->setAppErrorMsg('IDが作成できません');
109 $userInfo = $this->gEnv->getCurrentUserInfo();
110 if (!is_null($userInfo) && $userInfo->userType == UserInfo::USER_TYPE_NORMAL) $userId = $this->gEnv->getCurrentUserId();
112 $ret = $this->_db->addMember($clientId, $memberId, $userId, $name, $email, $url, ''/*アバターファイル名*/, $showEmail);
114 $this->setGuidanceMsg('登録完了しました');
115 $reloadData = true; // データの再読み込み
117 $isNew = false; // 更新処理画面を表示
122 $request->unsetSessionValue(M3_SESSION_POST_TICKET); // セッション値をクリア
123 } else if ($act == 'update'){ // 設定更新のとき
124 if (!empty($postTicket) && $postTicket == $request->getSessionValue(M3_SESSION_POST_TICKET)){ // 正常なPOST値のとき
126 if (!$canEdit) $this->setUserErrorMsg('更新権限がありません');
129 $this->checkInput($name, 'ニックネーム');
130 $this->checkMailAddress($email, 'Eメール', true/*空OK*/);
131 $this->checkInput($clientId, '端末ID');
133 $ret = $this->_db->getMemberInfoByDeviceId($clientId, $row);
135 if ($name != $row['mb_name'] && $this->_db->isExistsMemberName($name)) $this->setUserErrorMsg('このニックネームはすでに存在しています');
139 if ($this->getMsgCount() == 0){
140 $ret = $this->_db->updateMember($clientId, $name, $email, $url, $avatar, $showEmail, $newSerial);
142 $this->setGuidanceMsg('更新完了しました');
143 $reloadData = true; // データの再読み込み
147 $request->unsetSessionValue(M3_SESSION_POST_TICKET); // セッション値をクリア
149 $reloadData = true; // データの再読み込み
154 $ret = $this->_db->getMemberInfoById($memberId, $row);
156 $name = $row['mb_name']; // ユーザ名
157 $email = $row['mb_email']; // Eメール
158 $url = $row['mb_url']; // URL
159 $showEmail = $row['mb_show_email']; // Eメールを公開するかどうか
160 } else if (!empty($memberId)){
161 $this->setUserErrorMsg('登録されていないユーザです');
162 $memberId = ''; // 会員ID初期化
163 $canEdit = false; // データ編集不可
168 //if (!empty($memberId)) $mypageUrl = $this->convertUrlToHtmlEntity($this->getUrl($this->_currentPageUrl . '&' . self::URL_PARAM_MEMBER_ID . '=' . $memberId, true));
169 if (!empty($memberId)) $mypageUrl = $this->convertUrlToHtmlEntity($this->getUrl($this->gEnv->createCurrentPageUrlForMobile(self::URL_PARAM_MEMBER_ID . '=' . $memberId)));
172 if ($canEdit){ // 編集可の場合
174 if ($isNew){ // 新規登録のとき
176 if ($this->getMsgCount() == 0) $this->setGuidanceMsg('ユーザ登録して下さい');
178 $this->tmpl->setAttribute('add_area', 'visibility', 'visible');// 新規登録ボタン表示
179 $this->tmpl->addVar('_widget', 'act', 'add'); // 新規登録
181 $this->tmpl->setAttribute('update_area', 'visibility', 'visible');// 更新ボタン表示
182 $this->tmpl->addVar('_widget', 'act', 'update'); // 更新
185 $this->tmpl->setAttribute('name_input_area', 'visibility', 'visible'); // 名前編集
186 $this->tmpl->setAttribute('name_required_area', 'visibility', 'visible'); // 「必須」メッセージ
187 $this->tmpl->setAttribute('email_area', 'visibility', 'visible'); // Eメール入力
188 $this->tmpl->setAttribute('url_area', 'visibility', 'visible'); // URL入力
189 $this->tmpl->setAttribute('show_email_area', 'visibility', 'visible'); // Eメール公開
192 $mypageName = '';// マイページURL
194 if (!empty($mypageUrl)){
195 $mypageName = '投稿[3]';
196 $mypageLink = '<a href="' . $mypageUrl . '" accesskey="3">投稿[3]</a><br />';
198 $this->tmpl->addVar("_widget", "mypage_name", $mypageName);
199 $this->tmpl->addVar("_widget", "mypage_link", $mypageLink);
200 //$this->tmpl->setAttribute('top_link_area', 'visibility', 'visible');
201 //$this->tmpl->addVar("_widget", "mypage_url", $mypageUrl); // マイページURL
204 $this->tmpl->addVar("name_input_area", "name", $name); // ユーザ名
205 $this->tmpl->addVar("show_email_area", "email", $email); // Eメール
206 $this->tmpl->addVar("url_area", "url", $url); // URL
207 if ($showEmail) $this->tmpl->addVar("show_email_area", "show_email", 'checked'); // Eメールを公開するかどうか
208 $this->tmpl->addVar('_widget', 'current_url', $this->gEnv->createCurrentPageUrlForMobile('task=' . self::TASK_PROFILE));
211 $postTicket = md5(time() . $this->gAccess->getAccessLogSerialNo());
212 $request->setSessionValue(M3_SESSION_POST_TICKET, $postTicket); // セッションに保存
213 $this->tmpl->addVar("_widget", "ticket", $postTicket); // 画面に書き出し
215 if (!empty($memberId)){
217 $this->tmpl->setAttribute('name_area', 'visibility', 'visible'); // 名前表示
218 if ($showEmail) $this->tmpl->setAttribute('email_area', 'visibility', 'visible');
221 $this->tmpl->addVar("name_area", "name", $name); // ユーザ名
222 $this->tmpl->addVar("name_area", "mypage_url", $mypageUrl); // マイページURL
223 $this->tmpl->addVar("email_area", "email", $email); // Eメール
225 if (!empty($url)) $urlStr = '<a href="' . $this->convertUrlToHtmlEntity($url) . '">' . $this->convertToDispString($url) . '</a>';
226 $this->tmpl->addVar("_widget", "url", $urlStr); // URL
230 $this->tmpl->addVar("_widget", "page_title", self::DEFAULT_PAGE_TITLE); // ページタイトル
233 if (!empty($mypageUrl)) $memberIdStr = '<a href="' . $mypageUrl . '">' . $this->convertToDispString($memberId) . '</a>';
234 $this->tmpl->addVar("_widget", "id", $memberIdStr); // マイブログページへのリンク
237 $avatarImageUrl = $this->getAvatarUrl($memberId);// アバター画像URL
238 $imageTag = '<img src="' . $this->getUrl($avatarImageUrl) . '" width="' . self::AVATAR_SIZE . '" height="' . self::AVATAR_SIZE .'" />';
239 $this->tmpl->addVar("_widget", "avatar_img", $imageTag); // 画像
244 * @return string 会員ID
246 function createMemberId()
250 for ($i = 0; $i < self::CREATE_CODE_RETRY_COUNT; $i++){
252 $memberId = $this->_createRandString('123456789', self::MEMBER_ID_LENGTH);
255 $ret = $this->_db->isExistsMemberId($memberId);
263 * @param string $mime MIMEコンテンツタイプ
264 * @return string 画像の種別
266 function getImageType($mime)
269 if ($mime == 'image/gif') return 'gif';
270 if ($mime == 'image/jpeg') return 'jpeg';
271 if ($mime == 'image/jpg') return 'jpeg';
272 if ($mime == 'image/pjpeg') return 'jpeg';
273 if ($mime == 'image/png') return 'png';
280 * @param string $type MIMEコンテンツタイプ
281 * @param string $path 拡張子
282 * @param int $size サムネールの縦横サイズ
283 * @return object 画像オブジェクト
285 function createThumb($type, $path, $size)
290 $img = @imagecreatefromjpeg($path);
293 $img = @imagecreatefromgif($path);
296 $img = @imagecreatefrompng($path);
302 // size for thumbnail
303 $width = imagesx($img);
304 $height = imagesy($img);
306 if ($width > $height){
307 $n_height = $height * ($size / $width);
310 $n_width = $width * ($size / $height);
316 if ($n_width < $size) $x = round(($size - $n_width) / 2);
317 if ($n_height < $size) $y = round(($size - $n_height) / 2);
319 // imagecreatetruecolor
320 $thumb = imagecreatetruecolor($size, $size);
322 $bgcolor = imagecolorallocate($thumb, 255, 255, 255);
323 imagefill($thumb, 0, 0, $bgcolor);
325 // imagecopyresized (imagecopyresampled)
326 if (function_exists("imagecopyresampled")){
327 if (!imagecopyresampled($thumb, $img, $x, $y, 0, 0, $n_width, $n_height, $width, $height)){
328 if (!imagecopyresized($thumb, $img, $x, $y, 0, 0, $n_width, $n_height, $width, $height)) return false;
331 if (!imagecopyresized($thumb, $img, $x, $y, 0, 0, $n_width, $n_height, $width, $height)) return false;
338 * @param string $type MIMEコンテンツタイプ
339 * @param object $image 画像オブジェクト
340 * @param string $path ファイル保存の場合のパス
341 * @return bool true=成功、false=失敗
343 function outputThumb($type, &$image, $path = null)
349 $ret = imagejpeg($image);
352 $ret = imagegif($image);
355 $ret = imagepng($image);
361 $ret = imagejpeg($image, $path);
364 $ret = imagegif($image, $path);
367 $ret = imagepng($image, $path);
372 imagedestroy($image);