7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2013 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_photo_mainImagebrowseWidgetContainer.php 5630 2013-02-10 11:08:39Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_photo_mainBaseWidgetContainer.php');
18 class admin_photo_mainImagebrowseWidgetContainer extends admin_photo_mainBaseWidgetContainer
20 private $serialArray = array(); // 表示されているファイルのインデックス番号
21 private $photoBasePath; // アクセス可能な画像格納ディレクトリ
22 private $sortOrderByDateAsc; // 日付でソート
23 private $masterMimeType; // マスター画像のMIMEタイプ
24 private $permitMimeType; // アップロードを許可する画像タイプ
25 private $userId; // 現在のユーザ
26 private $langId; // 現在の言語
27 private $fileListAdded; // 一覧にデータが追加されたかどうか
28 const DEFAULT_LIST_COUNT = 30; // 最大リスト表示数
29 const FILE_ICON_FILE = '/images/system/tree/file.png'; // ファイルアイコン
30 const FOLDER_ICON_FILE = '/images/system/tree/folder.png'; // ディレクトリアイコン
31 const PARENT_ICON_FILE = '/images/system/tree/parent.png'; // 親ディレクトリアイコン
32 const CALENDAR_ICON_FILE = '/images/system/calendar.png'; // カレンダーアイコン
33 const ACTIVE_ICON_FILE = '/images/system/active.png'; // 公開中アイコン
34 const INACTIVE_ICON_FILE = '/images/system/inactive.png'; // 非公開アイコン
35 const ICON_SIZE = 16; // アイコンのサイズ
36 const LIST_ICON_SIZE = 64; // リスト用アイコンのサイズ
37 const CSS_FILE = '/swfupload2.5/css/default.css'; // CSSファイルのパス
38 // const PHOTO_DIR = '/etc/photo'; // マスター画像格納ディレクトリ
39 const PHOTO_HOME_DIR = '/etc/photo/home'; // マスター画像格納ディレクトリ(ユーザ別)
40 const DEFAULT_THUMBNAIL_SIZE = 128; // サムネール画像サイズ
41 const DEFAULT_IMAGE_EXT = 'jpg'; // 画像ファイルのデフォルト拡張子
42 const DEFAULT_IMAGE_TYPE = IMAGETYPE_JPEG;
43 const THUMBNAIL_DIR = '/widgets/photo/image'; // 画像格納ディレクトリ
44 const IMAGE_QUALITY = 100; // 生成画像の品質(0~100)
49 function __construct()
52 parent::__construct();
55 $this->masterMimeType = image_type_to_mime_type(IMAGETYPE_JPEG); // マスター画像のMIMEタイプ
56 $this->permitMimeType = array( image_type_to_mime_type(IMAGETYPE_GIF),
57 image_type_to_mime_type(IMAGETYPE_JPEG),
58 image_type_to_mime_type(IMAGETYPE_PNG),
59 image_type_to_mime_type(IMAGETYPE_BMP)); // アップロードを許可する画像タイプ
61 $this->langId = $this->gEnv->getCurrentLanguage();
62 $this->userId = $this->gEnv->getCurrentUserId();
67 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
68 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
70 * @param RequestManager $request HTTPリクエスト処理クラス
71 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
72 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
74 function _setTemplate($request, &$param)
76 $task = $request->trimValueOf('task');
80 $filename = 'imagebrowse.tmpl.html';
82 case 'imagebrowse_detail':
83 $filename = 'imagebrowse_detail.tmpl.html';
85 case 'imagebrowse_direct':
94 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
96 * @param RequestManager $request HTTPリクエスト処理クラス
97 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
100 function _assign($request, &$param)
102 $act = $request->trimValueOf('act');
103 $task = $request->trimValueOf('task');
108 $this->createList($request);
110 case 'imagebrowse_detail':
111 $this->createDetail($request);
113 case 'imagebrowse_direct':
114 if ($act == 'getimage'){ // 画像取得
115 $width = $request->trimValueOf('width');
116 $height = $request->trimValueOf('height');
117 $photoId = $request->trimValueOf(M3_REQUEST_PARAM_PHOTO_ID); // 画像ID
118 photo_mainCommonDef::getImage($photoId, self::$_mainDb, $width, $height);
126 * @param RequestManager $request HTTPリクエスト処理クラス
129 function createList($request)
131 $account = $this->gEnv->getCurrentUserAccount();
134 if (empty($account)){
135 $this->SetMsg(self::MSG_APP_ERR, $this->_('Error parameters.'));// パラメータにエラーがあります。
140 if (self::$_isLimitedUser){ // 使用限定ユーザの場合
141 $this->photoBasePath = $this->gEnv->getIncludePath() . self::PHOTO_HOME_DIR . DIRECTORY_SEPARATOR . $account; // 画像格納ディレクトリ
144 if (!is_dir($this->photoBasePath)) @mkdir($this->photoBasePath, M3_SYSTEM_DIR_PERMISSION);
146 $this->photoBasePath = $this->gEnv->getIncludePath() . photo_mainCommonDef::PHOTO_DIR; // 画像格納ディレクトリ
150 $path = trim($request->valueOf('path')); // 現在のパス
152 $path = $this->photoBasePath;
154 if (!strStartsWith($path, '/')) $path = '/' . $path;
155 $path = $this->photoBasePath . $path;
158 if (isDescendantPath($this->photoBasePath, $path)){
160 $this->setUserErrorMsg($this->_('Can not access the page.')); // アクセスできません
164 $this->setUserErrorMsg($this->_('Can not access the page.')); // アクセスできません
169 $viewCount = self::DEFAULT_LIST_COUNT; // 表示項目数
170 $pageNo = $request->trimValueOf(M3_REQUEST_PARAM_PAGE_NO); // ページ番号
171 if (empty($pageNo)) $pageNo = 1;
173 $act = $request->trimValueOf('act');
174 if ($act == 'uploadfile'){ // ファイルアップロードのとき
176 $this->gPage->abortPage();
179 if (isset($_FILES["Filedata"]) && is_uploaded_file($_FILES['Filedata']['tmp_name'])){ // アップロードファイルがある場合
181 $code = $account . '-' . self::$_mainDb->getNewPhotoNo($this->userId); // 画像コード
182 $ret = self::$_mainDb->isExistsPhotoCode($code); // 画像コードの重複確認
183 if ($ret){ // 画像コードが重複するとき
184 $errMessage = '画像コードが重複しています。';
185 $errDetail = '画像コード=' . $code;
187 // ファイル名は画像ファイルのハッシュを取得
188 //$filename = md5($code . time());
189 $filename = md5_file($_FILES['Filedata']['tmp_name']);
190 $originalFilename = $_FILES['Filedata']['name']; // 元のファイル名
191 $filePath = $path . DIRECTORY_SEPARATOR . $filename;
194 $ret = self::$_mainDb->isExistsPhoto($filename);
196 $errMessage = '画像ファイルが重複しています。';
197 $errDetail = '画像ID=' . $filename . ', 元のファイル名=' . $originalFilename;
201 if (!$ret){ // 画像の重複がない場合
202 if (file_exists($filePath)) $this->writeError(__METHOD__, 'アップロード画像がすでに存在しています。新しい画像で置き換えます。', 1100, '元のファイル名=' . $originalFilename);
205 $ret = move_uploaded_file($_FILES['Filedata']['tmp_name'], $filePath);
207 $isErr = false; // エラーが発生したかどうか
210 $imageSize = @getimagesize($filePath);
212 $imageWidth = $imageSize[0];
213 $imageHeight = $imageSize[1];
214 $imageType = $imageSize[2];
215 $imageMimeType = $imageSize['mime']; // ファイルタイプを取得
218 if (!in_array($imageMimeType, $this->permitMimeType)){
220 $this->writeUserError(__METHOD__, 'アップロード画像のタイプが不正です。アカウント: ' . $account, 2200, '元のファイル名=' . $originalFilename);
224 $this->writeUserError(__METHOD__, 'アップロード画像が不正です。アカウント: ' . $account, 2200, '元のファイル名=' . $originalFilename);
229 $ret = $this->createImages($filename, $filePath, $originalFilename, $thumbFilename);
230 if (!$ret) $isErr = true;
233 //$relativePath = strtr(str_replace($this->gEnv->getIncludePath() . photo_mainCommonDef::PHOTO_DIR, '', $path), '\\', '/'); // 画像格納ディレクトリ
234 $relativePath = strtr(substr($path, strlen($this->gEnv->getIncludePath() . photo_mainCommonDef::PHOTO_DIR)), '\\', '/'); // 画像格納ディレクトリ
235 $imageSize = $imageWidth . 'x' . $imageHeight; // 画像の縦横サイズ
236 $filesize = filesize($filePath);; // ファイルサイズ(バイト数)
237 $name = removeExtension($originalFilename); // 画像名
238 $name = strtr($name, '_', ' ');
240 $location = ''; // 場所
241 $date = $this->gEnv->getInitValueOfDate(); // 撮影日
242 $summary = ''; // 画像概要
243 $description = ''; // その他情報
244 $license = ''; // ライセンス
245 $keyword = ''; // 検索情報
246 $visible = true; // 表示
247 $ret = self::$_mainDb->updatePhotoInfo(self::$_isLimitedUser, 0/*新規追加*/, $this->langId, $filename, $relativePath, $code, $imageMimeType,
248 $imageSize, $originalFilename, $filesize, $name, $camera, $location, $date, $summary, $description, $license, $this->userId,
249 $keyword, $visible, 0/*ソート順*/, array()/*画像カテゴリー*/, $thumbFilename, $newSerial);
252 $this->writeError(__METHOD__, 'アップロード画像のデータ登録に失敗しました。', 1100, '元のファイル名=' . $originalFilename);
259 header("HTTP/1.1 595 File Upload Error"); // エラーコードはブラウザ画面に表示される
265 header("HTTP/1.1 596 File Upload Error"); // エラーコードはブラウザ画面に表示される
268 header("HTTP/1.1 597 File Upload Error"); // エラーコードはブラウザ画面に表示される
269 $this->writeError(__METHOD__, $errMessage, 1100, $errDetail);
271 } else { // アップロードファイルがないとき
272 header("HTTP/1.1 598 File Upload Error"); // エラーコードはブラウザ画面に表示される
273 if (isset($_FILES["Filedata"])) echo $_FILES["Filedata"]["error"];
277 $this->gPage->exitSystem();
278 } else if ($act == 'delete'){ // ファイル削除のとき
279 $listedItem = explode(',', $request->trimValueOf('seriallist'));
280 $delItems = array(); // シリアル番号
281 $delPhotos = array(); // 写真ID
282 $delFiles = array(); // ファイル名
283 $delSystemFiles = array(); // 削除するシステム用画像ファイル
284 for ($i = 0; $i < count($listedItem); $i++){
286 $itemName = 'item' . $i . '_selected';
287 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
289 if ($itemValue){ // チェック項目
291 $filename = $request->trimValueOf('item' . $i . '_name');
292 $filePath = $path . DIRECTORY_SEPARATOR . $filename;
293 if (is_writable($filePath) && strStartsWith($filePath, $this->photoBasePath . DIRECTORY_SEPARATOR)){
294 $serial = $listedItem[$i];
297 $ret = self::$_mainDb->getPhotoInfoBySerial($serial, $row);
299 if (!self::$_isLimitedUser || (self::$_isLimitedUser && $this->userId == $row['ht_owner_id'])){
300 $delItems[] = $serial;
301 $delPhotos[] = $filename; // 写真ID
302 $delSystemFiles[] = $row['ht_thumb_filename'];
306 $delFiles[] = $filePath; // 削除するファイルのパス
308 //$this->setMsg(self::MSG_USER_ERR, '削除できないファイルが含まれています。ファイル名=' . $this->convertToDispString($filename));
309 $this->setMsg(self::MSG_USER_ERR, sprintf($this->_('Include files not allowed to delete. (filename: %s)'), $this->convertToDispString($filename))); // 削除できないファイルが含まれています。(ファイル名: %s)
314 if ($this->getMsgCount() == 0 && count($delFiles) > 0){
315 $ret = self::$_mainDb->delPhotoInfo($delItems);
318 for ($i = 0; $i < count($delFiles); $i++){
319 $file = $delFiles[$i];
321 // ファイル、ディレクトリがある場合は削除しない
322 $files = getFileList($file);
323 if (count($files) == 0){
324 if (!rmDirectory($file)) $ret = false;
329 if (!@unlink($file)) $ret = false;
333 $ret = $this->deleteImages($delPhotos, $delSystemFiles);
334 /*for ($i = 0; $i < count($delPhotos); $i++){
336 $thumbnailPath = photo_mainCommonDef::getThumbnailPath($delPhotos[$i]);
337 if (!@unlink($thumbnailPath)) $ret = false;
338 $publicImagePath = photo_mainCommonDef::getPublicImagePath($delPhotos[$i]);
339 if (!@unlink($publicImagePath)) $ret = false;
342 if ($ret){ // ファイル削除成功のとき
343 //$this->setGuidanceMsg('ファイルを削除しました');
344 $this->setGuidanceMsg($this->_('Files deleted.')); // ファイルを削除しました
346 //$this->setAppErrorMsg('ファイル削除に失敗しました');
347 $this->setAppErrorMsg($this->_('Failed in deleting files.')); // ファイル削除に失敗しました
350 } else if ($act == 'createdir'){ // ディレクトリ作成のとき
351 $dirName = $request->trimValueOf('directory_name');
352 $this->checkSingleByte($dirName, $this->_('Directory Name')); // ディレクトリ名
354 if ($this->getMsgCount() == 0){
355 $dirPath = $path . DIRECTORY_SEPARATOR . $dirName;
356 $ret = @mkdir($dirPath, M3_SYSTEM_DIR_PERMISSION);
357 if ($ret){ // ファイル削除成功のとき
358 $this->setGuidanceMsg($this->_('Directory created.')); // ディレクトリを作成しました
361 $this->setAppErrorMsg($this->_('Failed in creating directory.')); // ディレクトリ作成に失敗しました
367 $photoParentPath = dirname($this->photoBasePath);
369 //$relativePath = str_replace($photoParentPath, '', $path);
370 $relativePath = substr($path, strlen($photoParentPath));
371 $relativePath = trim($relativePath, DIRECTORY_SEPARATOR);
372 if (!empty($relativePath)){
373 //$absPath = $this->gEnv->getSystemRootPath();
374 $absPath = $photoParentPath;
375 $pathArray = explode(DIRECTORY_SEPARATOR, $relativePath);
376 for ($i = 0; $i < count($pathArray); $i++){
377 if ($i == count($pathArray) -1){
378 $pathLink .= ' ' . DIRECTORY_SEPARATOR . ' ' . $this->convertToDispString($pathArray[$i]);
380 $absPath .= DIRECTORY_SEPARATOR . $pathArray[$i];
381 $relativeFilePath = substr($absPath, strlen($this->photoBasePath));
382 $pathLink .= ' ' . DIRECTORY_SEPARATOR . ' ';
383 //$pathLink .= '<a href="#" onclick="selDir(\'' . $this->adaptWindowsPath($this->convertToDispString($absPath)) . '\');return false;">' . $this->convertToDispString($pathArray[$i]) . '</a>';
384 //$pathLink .= '<a href="#" onclick="selDir(\'' . $this->adaptWindowsPath($this->convertToDispString($relativeFilePath)) . '\');return false;">' . $this->convertToDispString($pathArray[$i]) . '</a>';
385 $pageUrl = $this->_baseUrl . '&task=imagebrowse&path=' . $relativeFilePath;
386 $pathLink .= '<a href="' . $this->convertUrlToHtmlEntity($this->getUrl($pageUrl)) . '">' . $this->convertToDispString($pathArray[$i]) . '</a>';
391 /* $this->canDeleteFile = false;
392 if ($relativePath == M3_DIR_NAME_RESOURCE || strStartsWith($relativePath, M3_DIR_NAME_RESOURCE . DIRECTORY_SEPARATOR)){
393 $this->canDeleteFile = true;
396 $this->tmpl->addVar("_widget", "del_disabled", 'disabled ');
400 $fileList = $this->getFileList($path);
401 $totalCount = count($fileList);
404 $pageCount = (int)(($totalCount -1) / $viewCount) + 1; // 総ページ数
405 if ($pageNo < 1) $pageNo = 1;
406 if ($pageNo > $pageCount) $pageNo = $pageCount;
407 $this->firstNo = ($pageNo -1) * $viewCount + 1; // 先頭番号
408 $startNo = ($pageNo -1) * $viewCount +1; // 先頭の行番号
409 $endNo = $pageNo * $viewCount > $totalCount ? $totalCount : $pageNo * $viewCount;// 最後の行番号
413 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
414 for ($i = 1; $i <= $pageCount; $i++){
416 $link = ' ' . $i;
418 //$link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
419 $relativePath = substr($path, strlen($this->photoBasePath));
420 $pageUrl = $this->_baseUrl . '&task=imagebrowse&path=' . $relativePath;
421 if ($i > 1) $pageUrl .= '&page=' . $i;
422 $link = ' <a href="' . $this->convertUrlToHtmlEntity($this->getUrl($pageUrl)) . '">' . $i . '</a>';
427 $this->tmpl->addVar("_widget", "page_link", $pageLink);
428 $this->tmpl->addVar("_widget", "total_count", sprintf($this->_('%d Total'), $totalCount));// 全 x件
429 $this->tmpl->addVar("_widget", "page", $pageNo); // ページ番号
430 $this->tmpl->addVar("search_range", "start_no", $startNo);
431 $this->tmpl->addVar("search_range", "end_no", $endNo);
432 if ($totalCount > 0) $this->tmpl->setAttribute('search_range', 'visibility', 'visible');// 検出範囲を表示
435 $this->createFileList($path, $fileList, $startNo, $endNo);
436 if (!$this->fileListAdded) $this->tmpl->setAttribute('file_list', 'visibility', 'hidden'); // 一覧にデータが追加されたかどうか
438 $this->tmpl->addVar('_widget', 'path', substr($path, strlen($this->photoBasePath)));// 現在のディレクトリ
439 $this->tmpl->addVar('_widget', 'path_link', $pathLink);// 現在のディレクトリ
440 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
441 $this->tmpl->addVar('_widget', 'directory_name', $this->convertToDispString($dirName));// ディレクトリ作成用
444 $uploadUrl = $this->gEnv->getDefaultAdminUrl() . '?' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_CONFIG_WIDGET; // ウィジェット設定画面
445 $uploadUrl .= '&' . M3_REQUEST_PARAM_WIDGET_ID . '=' . $this->gEnv->getCurrentWidgetId(); // ウィジェットID
446 $uploadUrl .= '&' . M3_REQUEST_PARAM_OPERATION_TASK . '=' . 'imagebrowse';
447 $uploadUrl .= '&' . M3_REQUEST_PARAM_OPERATION_ACT . '=' . 'uploadfile';
448 $uploadUrl .= '&' . M3_REQUEST_PARAM_ADMIN_KEY . '=' . $this->gEnv->getAdminKey(); // 管理者キー
449 //$uploadUrl .= '&path=' . $this->adaptWindowsPath($path);
450 $uploadUrl .= '&path=' . $this->adaptWindowsPath(substr($path, strlen($this->photoBasePath))); // アップロードディレクトリ
451 $this->tmpl->addVar("_widget", "upload_url", $this->getUrl($uploadUrl));
454 $localeText = array();
455 $localeText['msg_file_upload'] = $this->_('Files uploaded. Refresh file list?'); // アップロード終了しました。ファイル一覧を更新しますか?
456 $localeText['msg_select_item_to_edit'] = $this->_('Select item to edit.'); // 編集する項目を選択してください
457 $localeText['msg_select_item_to_del'] = $this->_('Select item to delete.'); // 削除する項目を選択してください
458 $localeText['msg_delete_item'] = $this->_('Delete selected item?'); // 選択項目を削除しますか?
459 $localeText['msg_directory_not_allowed'] = $this->_('Directory not allowed to edit.'); // ディレクトリは編集できません
460 $localeText['msg_create_directory'] = $this->_('Create directory?'); // ディレクトリを作成しますか?
461 $localeText['label_path'] = $this->_('Path:'); // パス
462 $localeText['label_edit'] = $this->_('Edit'); // 編集
463 $localeText['label_delete'] = $this->_('Delete'); // 削除
464 $localeText['label_check'] = $this->_('Select'); // 選択
465 $localeText['label_filename'] = $this->_('Filename'); // ファイル名
466 $localeText['label_status'] = $this->_('Status'); // 状態
467 $localeText['label_image_code'] = $this->_('Image Code'); // 画像コード
468 $localeText['label_size'] = $this->_('Size'); // サイズ
469 $localeText['label_view_count'] = $this->_('View Count'); // 閲覧数
470 $localeText['label_rate'] = $this->_('Rating'); // 評価
471 $localeText['label_date'] = $this->_('Update Date'); // 更新日時
472 $localeText['label_upload'] = $this->_('Image Upload'); // 画像アップロード
473 $localeText['label_filesize'] = $this->_('Max Filesize'); // 1ファイル最大サイズ
474 $localeText['label_select_file'] = $this->_('Select Files'); // ファイルを選択
475 $localeText['label_create_directory'] = $this->_('Create Directory'); // ディレクトリ作成
476 $localeText['label_directory_name'] = $this->_('Directory Name');// ディレクトリ名
477 $localeText['label_create'] = $this->_('Create');// 作成
478 $localeText['label_cancel'] = $this->_('Cancel');// キャンセル
479 $localeText['label_range'] = $this->_('Range:'); // 範囲:
480 $this->setLocaleText($localeText);
485 * @param RequestManager $request HTTPリクエスト処理クラス
488 function createDetail($request)
491 $openby = $request->trimValueOf(M3_REQUEST_PARAM_OPEN_BY);
493 $categoryCount = self::$_configArray[photo_mainCommonDef::CF_IMAGE_CATEGORY_COUNT]; // カテゴリ数
494 if (empty($categoryCount)) $categoryCount = photo_mainCommonDef::DEFAULT_CATEGORY_COUNT;
496 $act = $request->trimValueOf('act');
497 $this->serialNo = intval($request->trimValueOf('serial')); // 選択項目のシリアル番号
498 $name = $request->trimValueOf('item_name');
499 $sortOrder = $request->trimValueOf('item_sort_order'); // 表示順
500 $location = $request->trimValueOf('item_location'); // 撮影場所
501 $camera = $request->trimValueOf('item_camera'); // カメラ
502 $summary = $request->trimValueOf('item_summary'); // 画像概要
503 if (self::$_configArray[photo_mainCommonDef::CF_HTML_PHOTO_DESCRIPTION]){ // HTMLタイプの説明のとき
504 $description = $request->valueOf('item_description'); // 画像説明
506 $description = $request->trimValueOf('item_description'); // 画像説明
508 $keyword = $request->trimValueOf('item_keyword'); // 検索キーワード
509 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0; // チェックボックス
510 $photoDate = $request->trimValueOf('item_date'); // 撮影日
511 if (!empty($photoDate)) $photoDate = $this->convertToProperDate($photoDate);
514 $categoryArray = array();
515 for ($i = 0; $i < $categoryCount; $i++){
516 $itemName = 'item_category' . $i;
517 $itemValue = $request->trimValueOf($itemName);
518 if (!empty($itemValue)){ // 0以外の値を取得
519 $categoryArray[] = $itemValue;
523 $reloadData = false; // データの再読み込み
524 if ($act == 'update'){ // 行更新のとき
526 $this->checkInput($name, $this->_('Name')); // 名前
527 $this->checkNumeric($sortOrder, '表示順');
530 if ($this->getMsgCount() == 0){
531 $ret = self::$_mainDb->updatePhotoInfo(self::$_isLimitedUser, $this->serialNo/*更新*/, $this->langId, ''/*ファイル名*/, ''/*格納ディレクトリ*/, ''/*画像コード*/, ''/*画像MIMEタイプ*/,
532 ''/*画像縦横サイズ*/, ''/*元のファイル名*/, ''/*ファイルサイズ*/, $name, $camera, $location, $photoDate, $summary, $description, ''/*ライセンス*/, 0/*所有者*/, $keyword, $visible, $sortOrder, $categoryArray/*画像カテゴリー*/, ''/*サムネールファイル名*/, $newSerial);
533 if ($ret){ // データ追加成功のとき
534 $this->setMsg(self::MSG_GUIDANCE, $this->_('Item updated.')); // データを更新しました
535 $this->serialNo = $newSerial;
536 $reloadData = true; // データの再読み込み
538 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in updating item.')); // データ更新に失敗しました
541 } else if ($act == 'delete'){ // 削除のとき
542 $ret = self::$_mainDb->getPhotoInfoBySerial($this->serialNo, $row);
544 $delItems = array($this->serialNo); // シリアル番号
545 $delPhotos = array($row['ht_public_id']); // 公開画像ID
546 $imagePath = $this->gEnv->getIncludePath() . photo_mainCommonDef::PHOTO_DIR . $row['ht_dir'] . DIRECTORY_SEPARATOR . $row['ht_public_id'];
547 $delFiles = array($imagePath); // ファイル名
548 $delSystemFiles = array($row['ht_thumb_filename']); // 削除するシステム用画像ファイル
551 $ret = self::$_mainDb->delPhotoInfo($delItems);
554 for ($i = 0; $i < count($delFiles); $i++){
555 $file = $delFiles[$i];
557 // ファイル、ディレクトリがある場合は削除しない
558 $files = getFileList($file);
559 if (count($files) == 0){
560 if (!rmDirectory($file)) $ret = false;
565 if (!@unlink($file)) $ret = false;
569 $ret = $this->deleteImages($delPhotos, $delSystemFiles);
570 /*for ($i = 0; $i < count($delPhotos); $i++){
571 $thumbnailPath = photo_mainCommonDef::getThumbnailPath($delPhotos[$i]);
572 if (!@unlink($thumbnailPath)) $ret = false;
573 $publicImagePath = photo_mainCommonDef::getPublicImagePath($delPhotos[$i]);
574 if (!@unlink($publicImagePath)) $ret = false;
577 if ($ret){ // ファイル削除成功のとき
578 //$this->setGuidanceMsg('ファイルを削除しました');
579 $this->setGuidanceMsg($this->_('Files deleted.')); // ファイルを削除しました
581 //$this->setAppErrorMsg('ファイル削除に失敗しました');
582 $this->setAppErrorMsg($this->_('Failed in deleting files.')); // ファイル削除に失敗しました
585 $this->setAppErrorMsg($this->_('Failed in deleting files.')); // ファイル削除に失敗しました
587 } else if ($act == 'recreate_image'){ // 画像再作成のとき
588 $ret = self::$_mainDb->getPhotoInfoBySerial($this->serialNo, $row);
590 $photoId = $row['ht_public_id'];
591 $originalName = $row['ht_original_filename'];
592 $imagePath = $this->gEnv->getIncludePath() . photo_mainCommonDef::PHOTO_DIR . $row['ht_dir'] . DIRECTORY_SEPARATOR . $row['ht_public_id'];
593 $ret = $this->createImages($photoId, $imagePath, $originalName, $thumbFilename);
594 if ($ret){ // ファイル削除成功のとき
595 $this->setGuidanceMsg($this->_('Images recreated.')); // 画像再作成しました
598 $reloadData = true; // データの再読み込み
601 $reloadData = true; // データの再読み込み
603 $isPhtoInfo = false; // 画像情報があるかどうか
604 if ($reloadData){ // データの再読み込み
605 $ret = self::$_mainDb->getPhotoInfoBySerial($this->serialNo, $row, $categoryRows);
607 $name = $row['ht_name'];
608 $photoId = $row['ht_public_id'];
609 $photoCode = $row['ht_code'];
610 $originalName = $row['ht_original_filename'];
611 $size = $row['ht_image_size'];
612 $author = $row['lu_name'];
613 $sortOrder = $row['ht_sort_order']; // ソート順
614 $location = $row['ht_location']; // 撮影場所
615 $camera = $row['ht_camera']; // カメラ
616 $summary = $row['ht_summary']; // 画像概要
617 $description = $row['ht_description']; // 画像説明
618 $keyword = $row['ht_keyword']; // 検索キーワード
619 $visible = $row['ht_visible']; // 公開
620 $photoDate = $this->convertToDispDate($row['ht_date']); // 撮影日
621 $photoTime = $this->convertToDispTime($row['ht_time'], 1/*時分*/); // 撮影時間
624 list($width, $height) = explode('x', $row['ht_image_size']);
625 $originalWidth = $width;
626 $originalHeight = $height;
629 $mimeType = $row['ht_mime_type'];
631 if ($mimeType == image_type_to_mime_type(IMAGETYPE_GIF)){
633 } else if ($mimeType == image_type_to_mime_type(IMAGETYPE_JPEG)){
635 } else if ($mimeType == image_type_to_mime_type(IMAGETYPE_PNG)){
637 } else if ($mimeType == image_type_to_mime_type(IMAGETYPE_BMP)){
642 photo_mainCommonDef::adjustImageSize($width, $height, photo_mainCommonDef::DEFAULT_PUBLIC_IMAGE_SIZE);
643 $originalImageUrl = $this->_baseUrl . '&task=imagebrowse_direct&act=getimage&' . M3_REQUEST_PARAM_PHOTO_ID . '=' . $photoId; // 元の写真
644 $imageUrl = $originalImageUrl . '&width=' . $width . '&height=' . $height;// 画像
645 $imageTag = '<img src="' . $this->getUrl($imageUrl) . '" width="' . $width . '" height="' . $height . '" border="0" alt="' . $photoId . '" title="' . $photoId . '" />';
648 $categoryArray = $this->getCategory($categoryRows, $categoryCount);
650 $isPhtoInfo = true; // 画像情報があるかどうか
652 $this->setAppErrorMsg($this->_('Can not find photo information.')); // 画像情報が見つかりません
656 if (!self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_DATE]){
657 $this->tmpl->setAttribute('show_photo_date', 'visibility', 'hidden'); // 画像情報(撮影日)を使用
658 $this->tmpl->setAttribute('show_calender', 'visibility', 'hidden'); // カレンダーを作成しない
660 if (!self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_LOCATION]) $this->tmpl->setAttribute('show_photo_location', 'visibility', 'hidden'); // 画像情報(撮影場所)を使用
661 if (!self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_CAMERA]) $this->tmpl->setAttribute('show_photo_camera', 'visibility', 'hidden'); // 画像情報(カメラ)を使用
662 if (self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_DESCRIPTION]){
663 if (self::$_configArray[photo_mainCommonDef::CF_HTML_PHOTO_DESCRIPTION]) $this->tmpl->setAttribute('show_html_description', 'visibility', 'visible'); // HTMLエディターを表示
665 $this->tmpl->setAttribute('show_photo_description', 'visibility', 'hidden'); // 画像情報(説明)を使用
667 if (!self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_KEYWORD]) $this->tmpl->setAttribute('show_photo_keyword', 'visibility', 'hidden'); // 画像情報(検索キーワード)を使用
668 if (!self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_CATEGORY]) $this->tmpl->setAttribute('show_photo_category', 'visibility', 'hidden'); // 画像情報(カテゴリー)を使用
671 if (self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_CATEGORY]){ // 画像情報(カテゴリー)を使用のとき
672 $ret = self::$_mainDb->getAllCategory($this->langId, $allCategoryRows);
673 if ($ret) $this->createCategoryMenu($allCategoryRows, $categoryArray, $categoryCount);
677 $thumbnailUrlHtml = '';
678 $thumbailSizeArray = trimExplode(',', self::$_configArray[photo_mainCommonDef::CF_THUMBNAIL_SIZE]);
679 if (empty($thumbailSizeArray)) $thumbailSizeArray = array(photo_mainCommonDef::DEFAULT_THUMBNAIL_SIZE);
680 for ($i = 0; $i < count($thumbailSizeArray); $i++){
681 $thumbnailSize = $thumbailSizeArray[$i];
682 $thumbnailPath = photo_mainCommonDef::getThumbnailPath($photoId, $thumbnailSize);
683 if (file_exists($thumbnailPath)){ // サムネールが存在するとき
684 $thumbnailUrlHtml .= '<b><font color="green">';
686 $thumbnailUrlHtml .= '<b><font color="red">';
688 $thumbnailUrlHtml .= $this->convertToDispString($this->getUrl(photo_mainCommonDef::getThumbnailUrl($photoId, $thumbnailSize)));
689 $thumbnailUrlHtml .= '</font></b><br />';
693 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
694 $this->tmpl->addVar("_widget", "photo_id", $this->convertToDispString($photoId));
695 $this->tmpl->addVar("_widget", "code", $this->convertToDispString($photoCode));
696 $this->tmpl->addVar("_widget", "name", $this->convertToDispString($name));
697 $this->tmpl->addVar("_widget", "sort_order", $this->convertToDispString($sortOrder));
698 $this->tmpl->addVar("_widget", "original_name", $this->convertToDispString($originalName));
699 $this->tmpl->addVar("_widget", "image_tag", $imageTag);
700 $this->tmpl->addVar("_widget", "image_url", $this->getUrl($originalImageUrl));
701 $this->tmpl->addVar("_widget", "format", $this->convertToDispString($format));
702 $this->tmpl->addVar("_widget", "size", $this->convertToDispString($size));
703 $this->tmpl->addVar("_widget", "author", $this->convertToDispString($author));
704 $this->tmpl->addVar("_widget", "summary", $this->convertToDispString($summary)); // 画像概要
705 if (self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_LOCATION]){ // 画像情報(撮影場所)を使用のとき
706 $this->tmpl->addVar("show_photo_location", "location", $this->convertToDispString($location)); // 撮影場所
708 if (self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_CAMERA]){ // 画像情報(カメラ)を使用のとき
709 $this->tmpl->addVar("show_photo_camera", "camera", $this->convertToDispString($camera)); // カメラ
711 if (self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_DESCRIPTION]){ // 画像情報(説明)を使用のとき
712 $this->tmpl->addVar("show_photo_description", "description", $this->convertToDispString($description));
714 if (self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_KEYWORD]){ // 画像情報(検索キーワード)を使用のとき
715 $this->tmpl->addVar("show_photo_keyword", "keyword", $this->convertToDispString($keyword)); // 検索キーワード
717 if (self::$_configArray[photo_mainCommonDef::CF_USE_PHOTO_DATE]){ // 画像情報(撮影日)を使用のとき
718 $this->tmpl->addVar("show_photo_date", "date", $photoDate); // 撮影日
719 $this->tmpl->addVar('show_photo_date', 'calendar_img', $this->getUrl($this->gEnv->getRootUrl() . self::CALENDAR_ICON_FILE)); // カレンダーアイコン
721 $this->tmpl->addVar('_widget', 'public_image_url', $this->convertToDispString($this->getUrl(photo_mainCommonDef::getPublicImageUrl($photoId)))); // 公開画像URL
722 $this->tmpl->addVar('_widget', 'thumbnail_url', $thumbnailUrlHtml); // サムネール画像URL
724 if ($visible) $checkedStr = 'checked';
725 $this->tmpl->addVar("_widget", "visible", $checkedStr); // 公開
727 if (!empty($this->serialNo) && $isPhtoInfo){ // 新規以外で画像情報がある場合
728 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 更新、削除ボタン表示
731 if ($openby == 'simple' || $openby == 'tabs') $this->tmpl->setAttribute('cancel_button', 'visibility', 'hidden'); // 詳細画面のみの表示またはタブ表示のときは戻るボタンを隠す
736 * @param string $path パス
737 * @param array $fileList ファイル一覧
738 * @param int $startNo 開始番号
739 * @param int $endNo 終了番号
742 function createFileList($path, $fileList, $startNo, $endNo)
745 if ($path != $this->photoBasePath){
747 $relativeFilePath = substr(dirname($path), strlen($this->photoBasePath));
748 //$fileLink = '<a href="#" onclick="selDir(\'' . $this->adaptWindowsPath($this->convertToDispString(dirname($path))) . '\');return false;">' . $this->convertToDispString($file) . '</a>';
749 //$fileLink = '<a href="#" onclick="selDir(\'' . $this->adaptWindowsPath($this->convertToDispString($relativeFilePath)) . '\');return false;">' . $this->convertToDispString($file) . '</a>';
750 $pageUrl = $this->_baseUrl . '&task=imagebrowse&path=' . $relativeFilePath;
751 $fileLink = '<a href="' . $this->convertUrlToHtmlEntity($this->getUrl($pageUrl)) . '">' . $this->convertToDispString($file) . '</a>';
755 $iconUrl = $this->gEnv->getRootUrl() . self::PARENT_ICON_FILE;
756 $iconTag = '<a href="' . $this->convertUrlToHtmlEntity($this->getUrl($pageUrl)) . '">';
757 $iconTag .= '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
760 $checkDisabled = 'disabled ';
762 'icon' => $iconTag, // アイコン
763 'name' => $this->convertToDispString($file), // ファイル名
764 'filename' => $fileLink, // ファイル名
765 'size' => $size, // ファイルサイズ
766 'check_disabled' => $checkDisabled, // チェックボックス使用制御
767 'selected' => $selected // 選択中かどうか
769 $this->tmpl->addVars('file_list', $row);
770 $this->tmpl->parseTemplate('file_list', 'a');
772 $this->fileListAdded = true; // 一覧にデータが追加されたかどうか
775 $index = 0; // インデックス番号
776 //for ($i = 0; $i < count($fileList); $i++){
777 for ($i = $startNo -1; $i < $endNo; $i++){
778 $filePath = $fileList[$i];
779 $relativeFilePath = substr($filePath, strlen($this->photoBasePath));
781 //$pathParts = pathinfo($filePath);
782 ////$file = basename($filePath);
783 //$file = $pathParts['basename'];
784 $file = end(explode('/', $filePath)); // pathinfo,basenameは日本語処理できないので日本語対応
787 $filenameOption = ''; // ファイル名オプション
789 $checkDisabled = ''; // チェックボックス使用制御
790 $statusImg = ''; // 状態
792 if (is_dir($filePath)){ // ディレクトリのとき
794 $iconUrl = $this->gEnv->getRootUrl() . self::FOLDER_ICON_FILE;
795 $iconTitle = $this->convertToDispString($file);
796 $pageUrl = $this->_baseUrl . '&task=imagebrowse&path=' . $relativeFilePath;
797 $iconTag = '<a href="' . $this->convertUrlToHtmlEntity($this->getUrl($pageUrl)) . '">';
798 $iconTag .= '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
801 $fileLink = '<a href="' . $this->convertUrlToHtmlEntity($this->getUrl($pageUrl)) . '">' . $this->convertToDispString($file) . '</a>';
803 // ファイルまたはディレクトリがないときは削除可能
804 $files = getFileList($filePath);
805 if (count($files) > 0){
806 $checkDisabled = 'disabled '; // チェックボックス使用制御
810 $totalViewCount = ''; // 総参照数
811 } else { // 画像ファイルのとき
813 $ret = self::$_mainDb->getPhotoInfo($file, $this->langId, $row, $categoryRows);
815 $serial = $row['ht_serial'];
816 $code = $row['ht_code']; // 画像コード
817 $rating = $row['ht_rate_average']; // 評価
820 $categoryCount = count($categoryRows);
821 for ($j = 0; $j < $categoryCount; $j++){
822 $categoryStr .= $categoryRows[$j]['hc_name'];
823 if ($j < $categoryCount -1) $categoryStr .= ', ';
825 $filenameOption = '<br />元のファイル名: ' . $this->convertToDispString($row['ht_original_filename']); // ファイル名オプション
826 $filenameOption .= '<br />タイトル名: ' . $this->convertToDispString($row['ht_name']); // タイトル名
827 $filenameOption .= '<br />カテゴリー: ' . $this->convertToDispString($categoryStr); // 所属カテゴリー
829 // 使用限定ユーザの場合は、所有者でなければ削除できない
830 if (self::$_isLimitedUser && $this->userId != $row['ht_owner_id']){
831 $checkDisabled = 'disabled '; // チェックボックス使用制御
835 if (self::$_isLimitedUser){ // 使用限定ユーザの場合は削除不可
836 $checkDisabled = 'disabled '; // チェックボックス使用制御
841 //if (!$this->canDeleteFile || !is_writable($filePath)) $checkDisabled = 'disabled '; // チェックボックス使用制御
843 $thumbnailPath = photo_mainCommonDef::getThumbnailPath($file);
846 $iconTitle = $this->convertToDispString($file);
847 if (file_exists($thumbnailPath)){ // サムネールが存在する場合
848 $iconUrl = photo_mainCommonDef::getThumbnailUrl($file);
849 $iconTag = '<a href="#" onclick="editItemBySerial(' . $serial . ');return false;">';
850 $iconTag .= '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::LIST_ICON_SIZE . '" height="' . self::LIST_ICON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
853 $iconUrl = $this->gEnv->getRootUrl() . self::FILE_ICON_FILE;
854 $iconTag = '<a href="#" onclick="editItemBySerial(' . $serial . ');return false;">';
855 $iconTag .= '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
859 //$fileLink = $this->convertToDispString($file);
860 $fileLink = '<a href="#" onclick="editItemBySerial(' . $serial . ');return false;">' . $this->convertToDispString($file) . '</a>';
861 $size = filesize($filePath);
864 //$totalViewCount = $this->gInstance->getAnalyzeManager()->getTotalContentViewCount(photo_mainCommonDef::REF_TYPE_CONTENT, $row['ht_id']);
865 $totalViewCount = $row['ht_view_count'];
868 $isActive = false; // 公開状態
869 if ($row['ht_visible']) $isActive = true;// 表示可能
871 if ($isActive){ // コンテンツが公開状態のとき
872 $iconUrl = $this->gEnv->getRootUrl() . self::ACTIVE_ICON_FILE; // 公開中アイコン
873 $iconTitle = $this->_('Published');
875 $iconUrl = $this->gEnv->getRootUrl() . self::INACTIVE_ICON_FILE; // 非公開アイコン
876 $iconTitle = $this->_('Unpublished');
878 $statusImg = '<img src="' . $this->getUrl($iconUrl) . '" width="' . self::ICON_SIZE . '" height="' . self::ICON_SIZE . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
882 $updateDate = date('Y/m/d H:i:s', filemtime($filePath));
886 'index' => $index, // インデックス番号(チェックボックス識別)
887 'icon' => $iconTag, // アイコン
888 'name' => $this->convertToDispString($file), // ファイル名
889 'filename' => $fileLink, // ファイル名
890 'filename_option' => $filenameOption, // ファイル名オプション
891 'code' => $this->convertToDispString($code), // 画像コード
892 'size' => $size, // ファイルサイズ
893 'date' => $updateDate, // 更新日時
894 'view_count' => $totalViewCount, // 総参照数
895 'rate' => $this->convertToDispString($rating), // 評価
896 'status' => $statusImg, // 公開状況
897 'check_disabled' => $checkDisabled, // チェックボックス使用制御
899 $this->tmpl->addVars('file_list', $row);
900 $this->tmpl->parseTemplate('file_list', 'a');
903 $this->serialArray[] = $serial;
905 $this->fileListAdded = true; // 一覧にデータが追加されたかどうか
911 * @param string $path ディレクトリパス
912 * @return array ファイルパスのリスト
914 function getFileList($path)
919 if (!is_dir($path)) return $fileList;
922 while (($file = $dir->read()) !== false){
923 $filePath = $path . DIRECTORY_SEPARATOR . $file;
924 // カレントディレクトリかどうかチェック
925 if ($file != '.' && $file != '..') $fileList[] = $filePath;
930 $this->sortOrderByDateAsc = false; // 日付で降順にソート
931 usort($fileList, array($this, 'sortOrderByDate'));
936 * ファイルパスを日付で昇順にソートする。ディレクトリは先頭。
938 * @param string $path1 比較するパス1
939 * @param string $path2 比較するパス2
940 * @return int 同じとき0、$path1が$path2より大きいとき1,$path1が$path2より小さいとき-1を返す
942 function sortOrderByDate($path1, $path2)
945 if (is_dir($path1)){ // ディレクトリのとき
946 if (!is_dir($path2)) return -1; // ファイルのとき
948 if (is_dir($path2)) return 1; // ディレクトリのとき
950 $fileTime1 = filemtime($path1);
951 $fileTime2 = filemtime($path2);
953 if ($fileTime1 == $fileTime2) return 0;
954 if ($this->sortOrderByDateAsc){ // 日付で昇順にソート
955 return ($fileTime1 < $fileTime2) ? -1 : 1;
957 return ($fileTime1 > $fileTime2) ? -1 : 1;
961 * CSSファイルをHTMLヘッダ部に設定
963 * CSSファイルをHTMLのheadタグ内に追加出力する。
964 * _assign()よりも後に実行される。
966 * @param RequestManager $request HTTPリクエスト処理クラス
967 * @param object $param 任意使用パラメータ。
968 * @return string CSS文字列。出力しない場合は空文字列を設定。
970 function _addCssFileToHead($request, &$param)
972 return $this->getUrl($this->gEnv->getScriptsUrl() . self::CSS_FILE);
975 * windowパスを使用する場合は、Javascriptに認識させる
977 * @param string $src パス文字列
978 * @return string 作成文字列
980 function adaptWindowsPath($src)
983 if (DIRECTORY_SEPARATOR == '\\'){ // windowsパスのとき
984 return addslashes($src);
992 * @param string $path ファイルパス
993 * @param int $type 画像タイプ
994 * @param string $destPath 出力ファイル保存のパス
995 * @param int $destType 出力画像タイプ
996 * @param int $size サムネールの縦横サイズ
997 * @return bool true=成功、false=失敗
999 function createThumbImage($path, $type, $destPath, $destType, $size)
1004 $image = @imagecreatefromgif($path);
1006 case IMAGETYPE_JPEG:
1007 $image = @imagecreatefromjpeg($path);
1010 $image = @imagecreatefrompng($path);
1017 $width = imagesx($image);
1018 $height = imagesy($image);
1020 if ($width > $height){
1021 $n_height = $height * ($size / $width);
1024 $n_width = $width * ($size / $height);
1030 if ($n_width < $size) $x = round(($size - $n_width) / 2);
1031 if ($n_height < $size) $y = round(($size - $n_height) / 2);
1034 $bgColor = self::$_configArray[photo_mainCommonDef::CF_THUMBNAIL_BG_COLOR]; // サムネール背景色
1035 $bgColorR = intval(substr($bgColor, 1, 2), 16);
1036 $bgColorG = intval(substr($bgColor, 3, 2), 16);
1037 $bgColorB = intval(substr($bgColor, 5, 2), 16);
1040 $thumb = imagecreatetruecolor($size, $size);
1041 //$bgcolor = imagecolorallocate($thumb, 255, 255, 255); // 背景色設定
1042 $bgcolor = imagecolorallocate($thumb, $bgColorR, $bgColorG, $bgColorB); // 背景色設定
1043 imagefill($thumb, 0, 0, $bgcolor);
1046 // imagecopyresampledの方がimagecopyresizedよりも画質が良いのでこちらを使用
1047 if (function_exists("imagecopyresampled")){
1048 if (!imagecopyresampled($thumb, $image, $x, $y, 0, 0, $n_width, $n_height, $width, $height)){
1049 if (!imagecopyresized($thumb, $image, $x, $y, 0, 0, $n_width, $n_height, $width, $height)) return false;
1052 if (!imagecopyresized($thumb, $image, $x, $y, 0, 0, $n_width, $n_height, $width, $height)) return false;
1058 $ret = @imagegif($thumb, $destPath, self::IMAGE_QUALITY);
1060 case IMAGETYPE_JPEG:
1061 $ret = @imagejpeg($thumb, $destPath, self::IMAGE_QUALITY);
1064 $ret = @imagepng($thumb, $destPath, self::IMAGE_QUALITY);
1068 $ret = imagedestroy($image);
1069 $ret = imagedestroy($thumb);
1075 * @param string $path 元画像ファイルパス
1076 * @param int $type 元画像の画像タイプ
1077 * @param string $wPath ウォータマーク画像ファイルパス
1078 * @param int $wType ウォータマーク画像の画像タイプ
1079 * @param string $destPath 出力画像のパス
1080 * @param int $destType 出力画像の画像タイプ
1081 * @param int $size 出力画像の縦または横の最大サイズ
1082 * @return bool true=成功、false=失敗
1084 function createPublicImage($path, $type, $wPath, $wType, $destPath, $destType, $size)
1089 $image = @imagecreatefromgif($path);
1091 case IMAGETYPE_JPEG:
1092 $image = @imagecreatefromjpeg($path);
1095 $image = @imagecreatefrompng($path);
1102 $width = imagesx($image);
1103 $height = imagesy($image);
1107 $destHeight = $size;
1108 $imageRatio = $width / $height;
1109 if ($destWidth / $destHeight > $imageRatio){
1110 $destWidth = $destHeight * $imageRatio;
1112 $destHeight = $destWidth / $imageRatio;
1115 // imagecopyresampledの方がimagecopyresizedよりも画質が良いのでこちらを使用
1116 $destImage = imagecreatetruecolor($destWidth, $destHeight);
1117 imagecopyresampled($destImage, $image, 0, 0, 0, 0, $destWidth, $destHeight, $width, $height);
1119 if (!empty(self::$_configArray[photo_mainCommonDef::CF_IMAGE_PROTECT_COPYRIGHT])){ // 著作権保護ありの場合
1123 $wImage = @imagecreatefromgif($wPath);
1125 case IMAGETYPE_JPEG:
1126 $wImage = @imagecreatefromjpeg($wPath);
1129 $wImage = @imagecreatefrompng($wPath);
1136 $wWidth = imagesx($wImage);
1137 $wHeight = imagesy($wImage);
1139 $startwidth = ($destWidth - $wWidth) / 2;
1140 $startheight = ($destHeight - $wHeight) / 2;
1141 imagecopymerge($destImage, $wImage, $startwidth, $startheight, 0, 0, $wWidth, $wHeight, 10);
1147 $ret = @imagegif($destImage, $destPath, self::IMAGE_QUALITY);
1149 case IMAGETYPE_JPEG:
1150 $ret = @imagejpeg($destImage, $destPath, self::IMAGE_QUALITY);
1153 $ret = @imagepng($destImage, $destPath, self::IMAGE_QUALITY);
1157 $ret = imagedestroy($destImage);
1158 $ret = imagedestroy($image);
1159 if (isset($wImage)) $ret = imagedestroy($wImage);
1165 * @param array $srcRows 全取得行
1166 * @param int $categoryCount 取得行数
1167 * @return array 取得した行
1169 function getCategory($srcRows, $categoryCount)
1171 $destArray = array();
1173 for ($i = 0; $i < count($srcRows); $i++){
1174 if (!empty($srcRows[$i]['hw_category_id'])){
1175 $destArray[] = $srcRows[$i]['hw_category_id'];
1177 if ($itemCount >= $categoryCount) break;
1185 * @param array $categoryRows カテゴリー情報
1186 * @param array $categoryArray 選択中のカテゴリー
1187 * @param int $size メニューの表示数
1190 function createCategoryMenu($categoryRows, $categoryArray, $size)
1192 for ($j = 0; $j < $size; $j++){
1194 $this->tmpl->clearTemplate('category_list');
1195 for ($i = 0; $i < count($categoryRows); $i++){
1196 $categoryId = $categoryRows[$i]['hc_id'];
1198 if ($j < count($categoryArray) && $categoryArray[$j] == $categoryId){
1199 $selected = 'selected';
1202 'value' => $categoryId, // カテゴリーID
1203 'name' => $categoryRows[$i]['hc_name'], // カテゴリー名
1204 'selected' => $selected // 選択中かどうか
1206 $this->tmpl->addVars('category_list', $menurow);
1207 $this->tmpl->parseTemplate('category_list', 'a');
1210 'index' => $j // 項目番号
1212 $this->tmpl->addVars('category', $itemRow);
1213 $this->tmpl->parseTemplate('category', 'a');
1219 * @param string $photoId 公開画像ID
1220 * @param string $imagePath 画像パス
1221 * @param string $originalFilename オリジナル画像名
1222 * @param string $thumbFilename サムネールファイル名(画像情報格納用)
1223 * @return bool true=成功、失敗
1225 function createImages($photoId, $imagePath, $originalFilename, &$thumbFilename)
1228 $imageSize = @getimagesize($imagePath);
1230 $imageType = $imageSize[2];
1234 // ##### システム用サムネール作成 #####
1235 /* $ret = $this->gInstance->getImageManager()->createDefaultThumb(M3_VIEW_TYPE_PHOTO, $photoId, $imagePath);
1237 $this->writeError(__METHOD__, 'システム用画像ファイル作成に失敗しました。', 1100,
1238 '元のファイル名=' . $originalFilename);// 運用ログに記録
1240 $ret = $this->gInstance->getImageManager()->createSystemDefaultThumb(M3_VIEW_TYPE_PHOTO, 0/*PC用*/, $photoId, $imagePath, $destFilename);
1242 $thumbFilename = implode(';', $destFilename);
1244 $this->writeError(__METHOD__, 'システム用画像ファイル作成に失敗しました。', 1100, '元のファイル名=' . $originalFilename);// 運用ログに記録
1247 // ##### サムネール画像作成 #####
1249 $thumbailSizeArray = trimExplode(',', self::$_configArray[photo_mainCommonDef::CF_THUMBNAIL_SIZE]);
1250 if (empty($thumbailSizeArray)) $thumbailSizeArray = array(photo_mainCommonDef::DEFAULT_THUMBNAIL_SIZE);
1251 for ($i = 0; $i < count($thumbailSizeArray); $i++){
1252 $thumbnailSize = $thumbailSizeArray[$i];
1253 $thumbnailPath = photo_mainCommonDef::getThumbnailPath($photoId, $thumbnailSize);
1254 //$ret = $this->createThumbImage($imagePath, $imageType, $thumbnailPath, self::DEFAULT_IMAGE_TYPE, $thumbnailSize);
1255 if (self::$_configArray[photo_mainCommonDef::CF_THUMBNAIL_CROP]){ // 切り取りサムネールの場合
1256 $ret = $this->gInstance->getImageManager()->createThumb($imagePath, $thumbnailPath, $thumbnailSize, self::DEFAULT_IMAGE_TYPE, true);
1258 $ret = $this->gInstance->getImageManager()->createThumb($imagePath, $thumbnailPath, $thumbnailSize, self::DEFAULT_IMAGE_TYPE, false, self::$_configArray[photo_mainCommonDef::CF_THUMBNAIL_BG_COLOR]);
1261 $this->writeError(__METHOD__, '画像ファイル作成に失敗しました。', 1100,
1262 '元のファイル名=' . $originalFilename . ', 画像ファイル=' . $thumbnailPath);// 運用ログに記録
1266 // ##### ウォータマーク画像作成 #####
1268 $watermarkPath = $this->gEnv->getCurrentWidgetRootPath() . '/images/default_mark.png';
1269 $watermarkSize = @getimagesize($watermarkPath);
1270 if ($watermarkSize) $watermarkType = $watermarkSize[2]; // ファイルタイプを取得
1271 $imageMaxSize = intval(self::$_configArray[photo_mainCommonDef::CF_DEFAULT_IMAGE_SIZE]);
1272 if ($imageMaxSize <= 0) $imageMaxSize = photo_mainCommonDef::DEFAULT_IMAGE_SIZE;
1273 //$ret = $this->createPublicImage($imagePath, $imageType, $watermarkPath, $watermarkType,
1274 // photo_mainCommonDef::getPublicImagePath($photoId), self::DEFAULT_IMAGE_TYPE, photo_mainCommonDef::DEFAULT_PUBLIC_IMAGE_SIZE);
1275 $ret = $this->createPublicImage($imagePath, $imageType, $watermarkPath, $watermarkType,
1276 photo_mainCommonDef::getPublicImagePath($photoId), self::DEFAULT_IMAGE_TYPE, $imageMaxSize);
1278 $this->writeError(__METHOD__, '画像ファイル作成に失敗しました。', 1100,
1279 '元のファイル名=' . $originalFilename . ', 画像ファイル=' . $watermarkPath);// 運用ログに記録
1287 * @param array $photoIdArray 公開画像ID
1288 * @param array $systemFiles システム用画像ファイル
1289 * @return bool true=成功、失敗
1291 function deleteImages($photoIdArray, $systemFiles)
1294 for ($i = 0; $i < count($photoIdArray); $i++){
1296 //$thumbnailPath = photo_mainCommonDef::getThumbnailPath($photoIdArray[$i]);
1297 //if (!@unlink($thumbnailPath)) $ret = false;
1298 $thumbailSizeArray = trimExplode(',', self::$_configArray[photo_mainCommonDef::CF_THUMBNAIL_SIZE]);
1299 if (empty($thumbailSizeArray)) $thumbailSizeArray = array(photo_mainCommonDef::DEFAULT_THUMBNAIL_SIZE);
1300 for ($j = 0; $j < count($thumbailSizeArray); $j++){
1301 $thumbnailSize = $thumbailSizeArray[$j];
1302 $thumbnailPath = photo_mainCommonDef::getThumbnailPath($photoIdArray[$i], $thumbnailSize);
1303 if (!@unlink($thumbnailPath)) $ret = false;
1306 $publicImagePath = photo_mainCommonDef::getPublicImagePath($photoIdArray[$i]);
1307 if (!@unlink($publicImagePath)) $ret = false;
1310 $oldFiles = explode(';', $systemFiles[$i]);
1311 $this->gInstance->getImageManager()->delSystemDefaultThumb(M3_VIEW_TYPE_PHOTO, 0/*PC用*/, $oldFiles);