(メッセージはありません)
@@ -63,7 +63,7 @@ | ||
63 | 63 | * @param int $commentNo コメント番号(0の場合はコンテンツへのリンク) |
64 | 64 | * @param string URL(エラーの場合は空文字列) |
65 | 65 | */ |
66 | - function createCommentUrl($contentType, $contentsId, $commentNo = 0) | |
66 | + static function createCommentUrl($contentType, $contentsId, $commentNo = 0) | |
67 | 67 | { |
68 | 68 | global $gEnvManager; |
69 | 69 | $url = ''; |
@@ -80,37 +80,50 @@ | ||
80 | 80 | $url = $gEnvManager->getDefaultSmartphoneUrl(); |
81 | 81 | break; |
82 | 82 | } |
83 | - | |
83 | + $contentParam = self::createContentParam($contentType, $contentsId); | |
84 | + if (empty($contentParam)) return ''; | |
85 | + $url .= '?' . $contentParam; | |
86 | + | |
87 | + if (!empty($commentNo)) $url .= '#' . commentCommonDef::COMMENT_PERMA_HEAD . $commentNo; // コメントパーマリンク | |
88 | + return $url; | |
89 | + } | |
90 | + /** | |
91 | + * コンテンツパラメータを作成 | |
92 | + * | |
93 | + * @param string $contentType コンテンツタイプ | |
94 | + * @param string $contentsId 共通コンテンツID | |
95 | + * @param string パラメータ文字列 | |
96 | + */ | |
97 | + static function createContentParam($contentType, $contentsId) | |
98 | + { | |
99 | + $param = ''; | |
84 | 100 | switch ($contentType){ |
85 | 101 | case M3_VIEW_TYPE_CONTENT: // 汎用コンテンツ |
86 | - $url .= '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentsId; | |
102 | + $param = M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentsId; | |
87 | 103 | break; |
88 | 104 | case M3_VIEW_TYPE_PRODUCT: // 商品情報(Eコマース) |
89 | - $url .= '?' . M3_REQUEST_PARAM_PRODUCT_ID . '=' . $contentsId; | |
105 | + $param = M3_REQUEST_PARAM_PRODUCT_ID . '=' . $contentsId; | |
90 | 106 | break; |
91 | 107 | case M3_VIEW_TYPE_BBS: // BBS |
92 | - $url .= '?' . M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $contentsId; | |
108 | + $param = M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $contentsId; | |
93 | 109 | break; |
94 | 110 | case M3_VIEW_TYPE_BLOG: // ブログ |
95 | - $url .= '?' . M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $contentsId; | |
111 | + $param = M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $contentsId; | |
96 | 112 | break; |
97 | 113 | case M3_VIEW_TYPE_WIKI: // wiki |
98 | - $url .= '?' . $contentsId; | |
114 | + $param = $contentsId; | |
99 | 115 | break; |
100 | 116 | case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ |
101 | - $url .= '?' . M3_REQUEST_PARAM_ROOM_ID . '=' . $contentsId; | |
117 | + $param = M3_REQUEST_PARAM_ROOM_ID . '=' . $contentsId; | |
102 | 118 | break; |
103 | 119 | case M3_VIEW_TYPE_EVENT: // イベント情報 |
104 | - $url .= '?' . M3_REQUEST_PARAM_EVENT_ID . '=' . $contentsId; | |
120 | + $param = M3_REQUEST_PARAM_EVENT_ID . '=' . $contentsId; | |
105 | 121 | break; |
106 | 122 | case M3_VIEW_TYPE_PHOTO: // フォトギャラリー |
107 | - $url .= '?' . M3_REQUEST_PARAM_PHOTO_ID . '=' . $contentsId; | |
123 | + $param = M3_REQUEST_PARAM_PHOTO_ID . '=' . $contentsId; | |
108 | 124 | break; |
109 | 125 | } |
110 | - if (empty($url)) return ''; | |
111 | - | |
112 | - if (!empty($commentNo)) $url .= '#' . commentCommonDef::COMMENT_PERMA_HEAD . $commentNo; // コメントパーマリンク | |
113 | - return $url; | |
126 | + return $param; | |
114 | 127 | } |
115 | 128 | /** |
116 | 129 | * アップロード画像格納ディレクトリ取得 |
@@ -14,6 +14,7 @@ | ||
14 | 14 | * @link http://www.magic3.org |
15 | 15 | */ |
16 | 16 | require_once($gEnvManager->getWidgetContainerPath('comment') . '/commentBaseWidgetContainer.php'); |
17 | +require_once($gEnvManager->getLibPath() . '/qqFileUploader/fileuploader.php'); | |
17 | 18 | |
18 | 19 | class commentTopWidgetContainer extends commentBaseWidgetContainer |
19 | 20 | { |
@@ -23,6 +24,8 @@ | ||
23 | 24 | private $commentSerialNo; // コメントシリアル番号 |
24 | 25 | private $isReadImageCheck; // 画像読み込みチェックかどうか |
25 | 26 | private $isErrorInReadImage; // 画像読み込み中にエラーがあるかどうか |
27 | + private $readImageCount; // 読み込み画像総数 | |
28 | + private $addImageCount; // 読み込み画像追加数 | |
26 | 29 | private $currentPageUrl; // 現在のページURL |
27 | 30 | private $currentPageRootUrl; |
28 | 31 | private $widgetTitle; // ウィジェットタイトル |
@@ -39,6 +42,8 @@ | ||
39 | 42 | private $permitImage; // 画像あり |
40 | 43 | private $autolink; // 自動リンク |
41 | 44 | private $addLib = array(); // 追加スクリプト |
45 | + private $addScript = array(); // 追加スクリプト | |
46 | + private $addCss = array(); // 追加CSS | |
42 | 47 | private $avatarSize; // アバター画像サイズ |
43 | 48 | private $maxImageSize; // 画像最大サイズ |
44 | 49 | private $imageDir; // 画像格納ディレクトリ |
@@ -58,6 +63,10 @@ | ||
58 | 63 | const PERMALINK_ICON_FILE = '/images/system/permalink.png'; // 「パーマリンク」アイコン |
59 | 64 | const PERMA_BUTTON_ICON_SIZE = 16; // ボタン用アイコンサイズ |
60 | 65 | |
66 | + // ファイルアップロード用スクリプト | |
67 | + const FILE_UPLOAD_SCRIPT_FILE = '/fileuploader/fileuploader.js'; // スクリプトファイル | |
68 | + const FILE_UPLOAD_CSS_FILE = '/fileuploader.css'; // CSSファイル | |
69 | + | |
61 | 70 | /** |
62 | 71 | * コンストラクタ |
63 | 72 | */ |
@@ -96,7 +105,8 @@ | ||
96 | 105 | { |
97 | 106 | $contentsId = ''; // 共通コンテンツID |
98 | 107 | $this->cmd = $request->trimValueOf(M3_REQUEST_PARAM_OPERATION_COMMAND); |
99 | - if ($this->cmd == M3_REQUEST_CMD_DO_WIDGET){ // ウィジェット単体実行 | |
108 | + $act = $request->trimValueOf('act'); | |
109 | + if ($this->cmd == M3_REQUEST_CMD_DO_WIDGET && empty($act)){ // ウィジェット単体実行 | |
100 | 110 | // 画像IDからコメントシリアル番号取得 |
101 | 111 | // コメントに添付されている場合はコメントの表示条件をチェック |
102 | 112 | $imageId = $request->trimValueOf(commentCommonDef::REQUEST_PARAM_IMAGE_ID); // 画像ID |
@@ -215,7 +225,6 @@ | ||
215 | 225 | $this->gInstance->getImageManager()->parseImageFormat($avatarFormat, $imageType, $imageAttr, $this->avatarSize); // 画像情報取得 |
216 | 226 | |
217 | 227 | // 入力値取得 |
218 | - $act = $request->trimValueOf('act'); | |
219 | 228 | $pageNo = $request->trimIntValueOf('page', '1'); // ページ番号 |
220 | 229 | if ($this->useTitle){ |
221 | 230 | $title = $request->trimValueOf('title'); |
@@ -261,10 +270,73 @@ | ||
261 | 270 | $isInit = false; // 初期表示かどうか |
262 | 271 | if ($this->cmd == M3_REQUEST_CMD_DO_WIDGET){ // ウィジェット単体実行 |
263 | 272 | if (!$this->userLimited || ($this->userLimited && $this->gEnv->isCurrentUserLogined())){ // ユーザ制限なし、または、ユーザ制限ありでログイン済みの場合 |
264 | - $this->downloadImage($request); // 画像取得 | |
265 | - } else { | |
266 | - $this->exitWidget(); // ウィジェット終了処理 | |
273 | + if (empty($act)){ // 画像取得 | |
274 | + //if (!$this->userLimited || ($this->userLimited && $this->gEnv->isCurrentUserLogined())){ // ユーザ制限なし、または、ユーザ制限ありでログイン済みの場合 | |
275 | + $this->downloadImage($request); // 画像取得 | |
276 | + //} | |
277 | + } else if ($act == 'uploadimage'){ // 画像アップロード | |
278 | + // ##### 画像ありの場合は画像を取り込む ##### | |
279 | + if ($this->permitHtml && $this->permitImage){ | |
280 | + $uploader = new qqFileUploader(); | |
281 | + $resultObj = $uploader->handleUpload($this->gEnv->getWorkDirPath()); // 一時ディレクトリに保存 | |
282 | + | |
283 | + if ($resultObj['success']){ | |
284 | + $fileInfo = $resultObj['file']; | |
285 | + $tmpFile = $fileInfo['path']; | |
286 | + | |
287 | + // 画像ファイル名作成 | |
288 | + $imageId = $this->gInstance->getFileManager()->createRandFileId(); | |
289 | + $imagePath = $this->imageDir . DIRECTORY_SEPARATOR . $imageId; | |
290 | + | |
291 | + // 画像作成 | |
292 | + $ret = $this->gInstance->getImageManager()->createImage($tmpFile, $imagePath, $this->maxImageSize, commentCommonDef::OUTPUT_IMAGE_TYPE, $destSize); | |
293 | + | |
294 | + // 画像登録 | |
295 | + if ($ret){ | |
296 | + $ret = $this->gInstance->getFileManager()->addAttachFileInfo(commentCommonDef::$_viewContentType, $imageId, $imagePath, $fileInfo['filename']); | |
297 | + } | |
298 | + | |
299 | + $destTag = ''; | |
300 | + if ($ret){ | |
301 | + $param = commentCommonDef::REQUEST_PARAM_IMAGE_ID . '=' . $imageId; | |
302 | + $newUrl = $this->createCmdUrlToCurrentWidget($param); | |
303 | + $destTag = '<img src="' . $this->getUrl($newUrl) . '" width="' . $destSize['width'] . '" height="' . $destSize['height'] . '" />'; | |
304 | + } else { // エラーの場合 | |
305 | + $resultObj = array('error' => 'Could not create file information.'); | |
306 | + } | |
307 | + | |
308 | + // 結果オブジェクト更新 | |
309 | + $resultObj['file']['fileid'] = $imageId; | |
310 | + $resultObj['file']['html'] = $destTag; | |
311 | + unset($resultObj['file']['path']); | |
312 | + unset($resultObj['file']['filename']); | |
313 | + unset($resultObj['file']['size']); | |
314 | + | |
315 | + // 一時ファイル削除 | |
316 | + unlink($tmpFile); | |
317 | + } | |
318 | + | |
319 | + // ##### 添付ファイルアップロード結果を返す ##### | |
320 | + // ページ作成処理中断 | |
321 | + $this->gPage->abortPage(); | |
322 | + | |
323 | + // 添付ファイルの登録データを返す | |
324 | + if (function_exists('json_encode')){ | |
325 | + $destStr = json_encode($resultObj); | |
326 | + } else { | |
327 | + $destStr = $this->gInstance->getAjaxManager()->createJsonString($resultObj); | |
328 | + } | |
329 | + //$destStr = htmlspecialchars($destStr, ENT_NOQUOTES);// 「&」が「&」に変換されるので使用しない | |
330 | + //header('Content-type: application/json; charset=utf-8'); | |
331 | + header('Content-Type: text/html; charset=UTF-8'); // JSONタイプを指定するとIE8で動作しないのでHTMLタイプを指定 | |
332 | + echo $destStr; | |
333 | + | |
334 | + // システム強制終了 | |
335 | + $this->gPage->exitSystem(); | |
336 | + } | |
337 | + } | |
267 | 338 | } |
339 | + $this->exitWidget(); // ウィジェット終了処理 | |
268 | 340 | } else if ($act == 'checkcomment' && $sendStatus == 0){ // コメント確認のとき |
269 | 341 | if (!empty($postTicket) && $postTicket == $request->getSessionValue(M3_SESSION_POST_TICKET) && $isCommentValid){ // 正常なPOST値のとき |
270 | 342 | // 入力チェック |
@@ -280,8 +352,14 @@ | ||
280 | 352 | |
281 | 353 | // ##### 画像ありの場合は画像を取り込む ##### |
282 | 354 | if ($this->permitHtml && $this->permitImage){ |
355 | + // 仮登録画像を取得 | |
356 | + $this->imageFileInfoArray = $this->getImageFileInfo(); | |
357 | + | |
283 | 358 | // 画像URL変換 |
359 | + $this->readImageCount = 0; // 読み込み画像総数 | |
360 | + $this->addImageCount = 0; // 読み込み画像追加数 | |
284 | 361 | $commentHtml = $this->convertImageUrl($commentHtml); |
362 | + if ($this->readImageCount != count($this->imageFileInfoArray) + $this->addImageCount) $this->isErrorInReadImage = true; // 画像総数をチェック | |
285 | 363 | if ($this->isErrorInReadImage){ |
286 | 364 | $this->setUserErrorMsg('画像読み込みに失敗しました'); |
287 | 365 | $commentHtml = ''; |
@@ -321,7 +399,8 @@ | ||
321 | 399 | // ##### 画像ありの場合は画像を取り込む ##### |
322 | 400 | if ($this->permitHtml && $this->permitImage){ |
323 | 401 | // 仮登録画像を取得 |
324 | - $this->imageFileInfoArray = array(); | |
402 | + $this->imageFileInfoArray = $this->getImageFileInfo(); | |
403 | +/* $this->imageFileInfoArray = array(); | |
325 | 404 | $clientId = $this->gAccess->getClientId(); |
326 | 405 | if (!empty($clientId)){ |
327 | 406 | $ret = $this->gInstance->getFileManager()->getAttachFileInfoByClientId(commentCommonDef::$_viewContentType, $clientId, $imageFileRows); |
@@ -336,11 +415,14 @@ | ||
336 | 415 | $this->imageFileInfoArray[] = $newInfoObj; |
337 | 416 | } |
338 | 417 | } |
339 | - } | |
418 | + }*/ | |
340 | 419 | |
341 | 420 | // 画像URL変換 |
342 | 421 | $this->isReadImageCheck = true; // 画像読み込みチェック |
422 | + $this->readImageCount = 0; // 読み込み画像総数 | |
423 | + $this->addImageCount = 0; // 読み込み画像追加数 | |
343 | 424 | $commentHtml = $this->convertImageUrl($commentHtml); |
425 | + if ($this->readImageCount != count($this->imageFileInfoArray)) $this->isErrorInReadImage = true; // 画像総数をチェック | |
344 | 426 | if ($this->isErrorInReadImage){ |
345 | 427 | $this->setUserErrorMsg('画像読み込みに失敗しました'); |
346 | 428 | $commentHtml = ''; |
@@ -533,6 +615,23 @@ | ||
533 | 615 | |
534 | 616 | $this->tmpl->setAttribute('show_wysiwyg', 'visibility', 'visible'); // wysiwygエディター表示 |
535 | 617 | $this->addLib[] = ScriptLibInfo::LIB_CKEDITOR; // CKEditorライブラリを追加 |
618 | + | |
619 | + // 画像ありの場合は画像アップロード領域表示 | |
620 | + if ($this->permitImage){ | |
621 | + // アップロードライブラリ追加 | |
622 | + $this->addScript = array($this->getUrl($this->gEnv->getScriptsUrl() . self::FILE_UPLOAD_SCRIPT_FILE)); // スクリプトファイル | |
623 | + $this->addCss = array($this->getUrl($this->gEnv->getCurrentWidgetCssUrl() . self::FILE_UPLOAD_CSS_FILE)); // CSSファイル | |
624 | + | |
625 | + $this->tmpl->setAttribute('show_uploader', 'visibility', 'visible'); | |
626 | + $this->tmpl->setAttribute('create_uploader', 'visibility', 'visible'); // 画像アップローダー作成 | |
627 | + $this->tmpl->setAttribute('upload_image', 'visibility', 'visible'); // 画像アップロード領域 | |
628 | + | |
629 | + // アップロード実行用URL | |
630 | + $param = commentCommonDef::createContentParam($this->contentType, $contentsId); | |
631 | + $param .= '&' . M3_REQUEST_PARAM_OPERATION_ACT . '=' . 'uploadimage'; | |
632 | + $uploadUrl = $this->createCmdUrlToCurrentWidget($param); | |
633 | + $this->tmpl->addVar("create_uploader", "upload_url", $this->getUrl($uploadUrl)); | |
634 | + } | |
536 | 635 | } else { |
537 | 636 | $this->tmpl->setAttribute('show_comment', 'visibility', 'visible'); |
538 | 637 | $this->tmpl->addVar('show_comment', 'comment_html', $commentHtml); // HTMLコメント |
@@ -734,6 +833,34 @@ | ||
734 | 833 | return $this->addLib; |
735 | 834 | } |
736 | 835 | /** |
836 | + * JavascriptファイルをHTMLヘッダ部に設定 | |
837 | + * | |
838 | + * JavascriptファイルをHTMLのheadタグ内に追加出力する。 | |
839 | + * _assign()よりも後に実行される。 | |
840 | + * | |
841 | + * @param RequestManager $request HTTPリクエスト処理クラス | |
842 | + * @param object $param 任意使用パラメータ。 | |
843 | + * @return string Javascriptファイル。出力しない場合は空文字列を設定。 | |
844 | + */ | |
845 | + function _addScriptFileToHead($request, &$param) | |
846 | + { | |
847 | + return $this->addScript; | |
848 | + } | |
849 | + /** | |
850 | + * CSSファイルをHTMLヘッダ部に設定 | |
851 | + * | |
852 | + * CSSファイルをHTMLのheadタグ内に追加出力する。 | |
853 | + * _assign()よりも後に実行される。 | |
854 | + * | |
855 | + * @param RequestManager $request HTTPリクエスト処理クラス | |
856 | + * @param object $param 任意使用パラメータ。 | |
857 | + * @return string CSS文字列。出力しない場合は空文字列を設定。 | |
858 | + */ | |
859 | + function _addCssFileToHead($request, &$param) | |
860 | + { | |
861 | + return $this->addCss; | |
862 | + } | |
863 | + /** | |
737 | 864 | * 取得したコンテンツ項目をテンプレートに設定する |
738 | 865 | * |
739 | 866 | * @param int $index 行番号 |
@@ -883,20 +1010,49 @@ | ||
883 | 1010 | */ |
884 | 1011 | function _convert_image_url_callback($matchData) |
885 | 1012 | { |
886 | - static $index = 0; | |
887 | - | |
888 | 1013 | // エラーチェック |
889 | 1014 | if ($this->isErrorInReadImage) return ''; // 画像読み込みエラー発生 |
890 | 1015 | |
891 | 1016 | //$destTag = $matchData[0]; // マッチしたタグ全体 |
892 | 1017 | $destTag = ''; |
893 | - $imageUrl = $matchData[1]; | |
1018 | + //$imageUrl = $matchData[1]; | |
1019 | + $imageUrl = html_entity_decode($matchData[1]); // BBCodeのparse()でIMGタグのsrcの「&」が「&」に変換されてしまう(バグ?)ので戻す | |
1020 | + if (empty($imageUrl)){ | |
1021 | + $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
1022 | + return ''; | |
1023 | + } | |
1024 | + | |
894 | 1025 | if ($this->gEnv->isSystemUrlAccess($imageUrl)){ // システム内のファイルのとき |
1026 | + // URLを解析 | |
1027 | + $queryArray = array(); | |
1028 | + $parsedUrl = parse_url($imageUrl); | |
1029 | + if (!empty($parsedUrl['query'])) parse_str($parsedUrl['query'], $queryArray); // クエリーの解析 | |
1030 | + | |
1031 | + for ($i = 0; $i < count($this->imageFileInfoArray); $i++){ | |
1032 | + $fileInfo = $this->imageFileInfoArray[$i]; | |
1033 | + $imageId = $fileInfo->fileId; // 画像ID | |
1034 | + | |
1035 | + if ($queryArray[commentCommonDef::REQUEST_PARAM_IMAGE_ID] == $imageId){ | |
1036 | + // 画像サイズ取得 | |
1037 | + $imagePath = $this->imageDir . DIRECTORY_SEPARATOR . $imageId; | |
1038 | + $this->gInstance->getImageManager()->getImageInfo($imagePath, $width, $height); | |
1039 | + | |
1040 | + $param = commentCommonDef::REQUEST_PARAM_IMAGE_ID . '=' . $imageId; | |
1041 | + if ($this->isReadImageCheck){ // 保存前の画像チェックのとき | |
1042 | + $newUrl = $this->createCmdUrlToCurrentWidget($param, true/*マクロ形式で取得*/); | |
1043 | + } else { | |
1044 | + $newUrl = $this->createCmdUrlToCurrentWidget($param); | |
1045 | + } | |
1046 | + $destTag = '<img src="' . $newUrl . '" width="' . $width . '" height="' . $height . '" />'; | |
1047 | + break; | |
1048 | + } | |
1049 | + } | |
1050 | + if ($i == count($this->imageFileInfoArray)) $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
895 | 1051 | } else { |
896 | - if ($this->isReadImageCheck){ | |
897 | - if ($index < count($this->imageFileInfoArray)){ | |
898 | - $fileInfo = $this->imageFileInfoArray[$index]; | |
899 | - if (!empty($imageUrl) && $imageUrl == $fileInfo->originalUrl){ // 取得先URL比較 | |
1052 | + if ($this->isReadImageCheck){ // 保存前の画像チェックのとき | |
1053 | + for ($i = 0; $i < count($this->imageFileInfoArray); $i++){ | |
1054 | + $fileInfo = $this->imageFileInfoArray[$i]; | |
1055 | + if ($imageUrl == $fileInfo->originalUrl){ // 取得先URL比較 | |
900 | 1056 | $imageId = $fileInfo->fileId; // 画像ID |
901 | 1057 | $imagePath = $this->imageDir . DIRECTORY_SEPARATOR . $imageId; |
902 | 1058 |
@@ -906,62 +1062,83 @@ | ||
906 | 1062 | $param = commentCommonDef::REQUEST_PARAM_IMAGE_ID . '=' . $imageId; |
907 | 1063 | $newUrl = $this->createCmdUrlToCurrentWidget($param, true/*マクロ形式で取得*/); |
908 | 1064 | $destTag = '<img src="' . $newUrl . '" width="' . $width . '" height="' . $height . '" />'; |
909 | - } else { | |
910 | - $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
1065 | + break; | |
911 | 1066 | } |
912 | - } else { | |
913 | - $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
914 | 1067 | } |
1068 | + if ($i == count($this->imageFileInfoArray)) $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
915 | 1069 | } else { |
916 | - if (empty($imageUrl)){ | |
917 | - $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
918 | - } else { | |
919 | - // 画像ファイル名作成 | |
920 | - $imageId = $this->gInstance->getFileManager()->createRandFileId(); | |
921 | - $originalFilename = basename($imageUrl); // 元のファイル名 | |
922 | - $imagePath = $this->imageDir . DIRECTORY_SEPARATOR . $imageId; | |
923 | - | |
924 | - // 画像を取り込む | |
925 | - $tmpFile = tempnam($this->gEnv->getWorkDirPath(), M3_SYSTEM_WORK_UPLOAD_FILENAME_HEAD); | |
926 | - if ($tmpFile !== false){ | |
927 | - // 一時ファイルに読み込む | |
928 | - $ret = true; | |
929 | - if ($input = @fopen($imageUrl, 'r')){ | |
930 | - $ret = file_put_contents($tmpFile, $input); | |
931 | - if ($ret !== false) $ret = true; | |
932 | - @fclose($input); | |
933 | - } else { | |
934 | - $ret = false; | |
935 | - } | |
1070 | + // 画像ファイル名作成 | |
1071 | + $imageId = $this->gInstance->getFileManager()->createRandFileId(); | |
1072 | + $originalFilename = basename($imageUrl); // 元のファイル名 | |
1073 | + $imagePath = $this->imageDir . DIRECTORY_SEPARATOR . $imageId; | |
1074 | + | |
1075 | + // 画像を取り込む | |
1076 | + $tmpFile = tempnam($this->gEnv->getWorkDirPath(), M3_SYSTEM_WORK_UPLOAD_FILENAME_HEAD); | |
1077 | + if ($tmpFile !== false){ | |
1078 | + // 一時ファイルに読み込む | |
1079 | + $ret = true; | |
1080 | + if ($input = @fopen($imageUrl, 'r')){ | |
1081 | + $ret = file_put_contents($tmpFile, $input); | |
1082 | + if ($ret !== false) $ret = true; | |
1083 | + @fclose($input); | |
1084 | + } else { | |
1085 | + $ret = false; | |
1086 | + } | |
936 | 1087 | |
937 | - // 画像作成 | |
938 | - if ($ret){ | |
939 | - $ret = $this->gInstance->getImageManager()->createImage($tmpFile, $imagePath, $this->maxImageSize, commentCommonDef::OUTPUT_IMAGE_TYPE, $destSize); | |
940 | - } | |
1088 | + // 画像作成 | |
1089 | + if ($ret){ | |
1090 | + $ret = $this->gInstance->getImageManager()->createImage($tmpFile, $imagePath, $this->maxImageSize, commentCommonDef::OUTPUT_IMAGE_TYPE, $destSize); | |
1091 | + } | |
941 | 1092 | |
942 | - // 画像登録 | |
943 | - if ($ret){ | |
944 | - $ret = $this->gInstance->getFileManager()->addAttachFileInfo(commentCommonDef::$_viewContentType, $imageId, $imagePath, $originalFilename, $imageUrl); | |
945 | - } | |
1093 | + // 画像登録 | |
1094 | + if ($ret){ | |
1095 | + $ret = $this->gInstance->getFileManager()->addAttachFileInfo(commentCommonDef::$_viewContentType, $imageId, $imagePath, $originalFilename, $imageUrl); | |
1096 | + } | |
946 | 1097 | |
947 | - // 画像が作成できない場合は画像を表示しない | |
948 | - if ($ret){ | |
949 | - $param = commentCommonDef::REQUEST_PARAM_IMAGE_ID . '=' . $imageId; | |
950 | - $newUrl = $this->createCmdUrlToCurrentWidget($param); | |
951 | - $destTag = '<img src="' . $this->getUrl($newUrl) . '" width="' . $destSize['width'] . '" height="' . $destSize['height'] . '" />'; | |
952 | - } | |
953 | - if (!$ret) $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
1098 | + // 画像が作成できない場合は画像を表示しない | |
1099 | + if ($ret){ | |
1100 | + $param = commentCommonDef::REQUEST_PARAM_IMAGE_ID . '=' . $imageId; | |
1101 | + $newUrl = $this->createCmdUrlToCurrentWidget($param); | |
1102 | + $destTag = '<img src="' . $this->getUrl($newUrl) . '" width="' . $destSize['width'] . '" height="' . $destSize['height'] . '" />'; | |
1103 | + | |
1104 | + $this->addImageCount++; // 読み込み画像追加数 | |
1105 | + } | |
1106 | + if (!$ret) $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
954 | 1107 | |
955 | - // 一時ファイル削除 | |
956 | - unlink($tmpFile); | |
957 | - } else { | |
958 | - $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
959 | - } | |
1108 | + // 一時ファイル削除 | |
1109 | + unlink($tmpFile); | |
1110 | + } else { | |
1111 | + $this->isErrorInReadImage = true; // 画像読み込みエラー発生 | |
960 | 1112 | } |
961 | 1113 | } |
962 | 1114 | } |
963 | - $index++; | |
1115 | + if (!$this->isErrorInReadImage) $this->readImageCount++; // 読み込み画像総数更新 | |
964 | 1116 | return $destTag; |
965 | 1117 | } |
1118 | + /** | |
1119 | + * 仮登録画像情報を取得 | |
1120 | + * | |
1121 | + * @return array 仮登録画像情報 | |
1122 | + */ | |
1123 | + function getImageFileInfo() | |
1124 | + { | |
1125 | + $imageFileInfoArray = array(); | |
1126 | + $clientId = $this->gAccess->getClientId(); | |
1127 | + if (!empty($clientId)){ | |
1128 | + $ret = $this->gInstance->getFileManager()->getAttachFileInfoByClientId(commentCommonDef::$_viewContentType, $clientId, $imageFileRows); | |
1129 | + if ($ret){ | |
1130 | + for ($i = 0; $i < count($imageFileRows); $i++){ | |
1131 | + $fileRow = $imageFileRows[$i]; | |
1132 | + $newInfoObj = new stdClass; | |
1133 | + $newInfoObj->title = ''; | |
1134 | + $newInfoObj->filename = ''; | |
1135 | + $newInfoObj->fileId = $fileRow['af_file_id']; | |
1136 | + $newInfoObj->originalUrl = $fileRow['af_original_url']; // 取得先URL | |
1137 | + $imageFileInfoArray[] = $newInfoObj; | |
1138 | + } | |
1139 | + } | |
1140 | + } | |
1141 | + return $imageFileInfoArray; | |
1142 | + } | |
966 | 1143 | } |
967 | 1144 | ?> |
@@ -27,12 +27,26 @@ | ||
27 | 27 | document.comment_main.submit(); |
28 | 28 | return true; |
29 | 29 | } |
30 | -/* | |
31 | -function sendcancel(){ | |
32 | - document.comment_main.act.value = 'sendcancel'; | |
33 | - document.comment_main.submit(); | |
34 | - return true; | |
35 | -}*/ | |
30 | +<patTemplate:tmpl name="create_uploader" visibility="hidden"> | |
31 | +function createUploader(){ | |
32 | + var uploader = new qq.FileUploader({ | |
33 | + element: document.getElementById('comment-image-uploader'), | |
34 | + action: '{UPLOAD_URL}', | |
35 | + onComplete: function(id, fileName, responseJson){ | |
36 | + // 一覧に添付ファイルを追加 | |
37 | + //CKEDITOR.instances['comment'].insertText("[img]http://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Go-home.svg/100px-Go-home.svg.png[/img]"); | |
38 | + // CKEDITOR.instances['comment'].insertHTML("[img]http://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Go-home.svg/100px-Go-home.svg.png[/img]"); | |
39 | + //addAttachFile(responseJson.file.fileid, responseJson.file.filename); | |
40 | +var oEditor = CKEDITOR.instances['comment']; | |
41 | +//var html = '<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Go-home.svg/100px-Go-home.svg.png" />'; | |
42 | +var html = responseJson.file.html; | |
43 | +var newElement = CKEDITOR.dom.element.createFromHtml( html, oEditor.document ); | |
44 | +oEditor.insertElement( newElement ); | |
45 | + }, | |
46 | + debug: true | |
47 | + }); | |
48 | +} | |
49 | +</patTemplate:tmpl> | |
36 | 50 | $(function(){ |
37 | 51 | $('#comment_cancel').click(function(){ |
38 | 52 | document.comment_main.act.value = 'sendcancel'; |
@@ -45,9 +59,28 @@ | ||
45 | 59 | $('body').scrollTo('#comment_form_head'); |
46 | 60 | </patTemplate:tmpl> |
47 | 61 | <patTemplate:tmpl name="show_wysiwyg" visibility="hidden"> |
62 | + // 画像のドロップを禁止 | |
63 | + CKEDITOR.on('instanceReady', function (ev){ | |
64 | + var dragstart_outside = true; | |
65 | + ev.editor.document.on('dragstart', function (ev){ | |
66 | + dragstart_outside = false; | |
67 | + }); | |
68 | + ev.editor.document.on('drop', function (ev){ | |
69 | + if (dragstart_outside) { | |
70 | + ev.data.preventDefault(true); | |
71 | + } | |
72 | + dragstart_outside = true; | |
73 | + }); | |
74 | + }); | |
75 | + | |
48 | 76 | m3SetSafeWysiwygEditor('comment', 150); |
77 | + | |
78 | +<patTemplate:tmpl name="show_uploader" visibility="hidden"> | |
79 | + // 画像アップローダー作成 | |
80 | + createUploader(); | |
49 | 81 | </patTemplate:tmpl> |
50 | 82 | </patTemplate:tmpl> |
83 | +</patTemplate:tmpl> | |
51 | 84 | }); |
52 | 85 | //]]> |
53 | 86 | </script> |
@@ -109,14 +142,13 @@ | ||
109 | 142 | <patTemplate:tmpl name="show_comment" visibility="hidden"><div>{COMMENT_HTML}</div><input type="hidden" name="comment" value="{COMMENT}" /> |
110 | 143 | </patTemplate:tmpl> |
111 | 144 | </div> |
145 | +<patTemplate:tmpl name="upload_image" visibility="hidden"><p><div id="comment-image-uploader"></div> | |
146 | +<small>画像ファイルを「ファイルアップロード」にドラッグ&ドロップします。<br />エリアをクリックした場合は選択ダイアログが表示されます。</small></p></patTemplate:tmpl> | |
112 | 147 | <p class="form-submit"> |
113 | 148 | <input type="submit" class="button" value="{SEND_BUTTON_LABEL}" onclick="sendcomment({SEND_STATUS});" /> |
114 | 149 | <patTemplate:tmpl name="cancel_button" visibility="hidden"><input id="comment_cancel" type="submit" class="button" value="キャンセル" /></patTemplate:tmpl> |
115 | 150 | </p> |
116 | - | |
117 | 151 | </form> |
118 | 152 | </div> |
119 | 153 | </patTemplate:tmpl> |
120 | - | |
121 | - | |
122 | 154 | </patTemplate:tmpl> |
@@ -0,0 +1,64 @@ | ||
1 | +.qq-uploader { | |
2 | + position:relative; | |
3 | + /*width: 300px;*/ | |
4 | + width: 99%; | |
5 | +} | |
6 | + | |
7 | +.qq-upload-button { | |
8 | + display:block; /* or inline-block */ | |
9 | + width: 100%; | |
10 | + height: 100px; | |
11 | + border:2px dashed #c6cfe1; | |
12 | + -moz-border-radius:5px; | |
13 | + -webkit-border-radius:5px; | |
14 | + border-radius:5px; | |
15 | + line-height:35px; | |
16 | +/* text-align:center;*/ | |
17 | + font-size:120%; | |
18 | + font-weight:bold; | |
19 | + color:#333333; | |
20 | + background-color:#dfe4ee; | |
21 | + background-image: url(../images/upload_box.png); | |
22 | + background-repeat: no-repeat; | |
23 | +} | |
24 | +.qq-upload-button span{ | |
25 | + margin-left:35px; | |
26 | + padding-top:70px; | |
27 | +} | |
28 | +/*.qq-upload-button-hover {background:#cc0000;} | |
29 | +.qq-upload-button-focus {outline:1px dotted black;}*/ | |
30 | + | |
31 | +.qq-upload-drop-area { | |
32 | + position:absolute; | |
33 | + top:0; | |
34 | + left:0; | |
35 | + width:100%; | |
36 | + height:100px; | |
37 | + z-index:2; | |
38 | + border:2px dashed #c6cfe1; | |
39 | + -moz-border-radius:5px; | |
40 | + -webkit-border-radius:5px; | |
41 | + border-radius:5px; | |
42 | + font-size:120%; | |
43 | + font-weight:bold; | |
44 | + text-align:center; | |
45 | + color:#333333; | |
46 | + background:#FF9797; | |
47 | +} | |
48 | +.qq-upload-drop-area span { | |
49 | + display:block; position:absolute; top: 50%; width:100%; | |
50 | +} | |
51 | +.qq-upload-drop-area-active {background:#FF7171;} | |
52 | + | |
53 | +.qq-upload-list {margin:15px 35px; padding:0; list-style:disc;display:none;} | |
54 | +.qq-upload-list li { margin:0; padding:0; line-height:15px; font-size:12px;} | |
55 | +.qq-upload-file, .qq-upload-spinner, .qq-upload-size, .qq-upload-cancel, .qq-upload-failed-text { | |
56 | + margin-right: 7px; | |
57 | +} | |
58 | + | |
59 | +.qq-upload-file {} | |
60 | +.qq-upload-spinner {display:inline-block; background: url("../images/loading.gif"); width:15px; height:15px; vertical-align:text-bottom;} | |
61 | +.qq-upload-size,.qq-upload-cancel {font-size:11px;} | |
62 | + | |
63 | +.qq-upload-failed-text {display:none;} | |
64 | +.qq-upload-fail .qq-upload-failed-text {display:inline;} | |
\ No newline at end of file |