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-2012 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_mainWidgetlistWidgetContainer.php 5175 2012-09-07 05:10:38Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/admin_mainDb.php');
18 require_once($gEnvManager->getLibPath() . '/pcl/pclzip.lib.php' );
19 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_mainDef.php'); // 定義クラス
21 class admin_mainWidgetlistWidgetContainer extends admin_mainBaseWidgetContainer
23 private $db; // DB接続オブジェクト
24 private $newWidget = array(); // 新規追加ウィジェット
25 private $widgetTypeArray; // ウィジェットタイプ
26 private $widgetType; // 現在のウィジェットタイプ
27 private $showDetail; // 詳細表示するかどうか
28 private $defaultImageSize = 32; // ウィジェット画像サイズ
29 private $isExistsWidgetList; // ウィジェットが存在するかどうか
30 const SCRIPT_FILE_EXT = 'js'; // JavaScriptファイル拡張子
31 const CSS_FILE_EXT = 'css'; // cssファイル拡張子
32 const PHP_FILE_EXT = 'php'; // phpファイル拡張子
33 const NOT_FOUND_WIDGET_ICON_FILE = '/images/system/notfound32.png'; // ウィジェットが見つからないアイコン
38 function __construct()
41 parent::__construct();
44 $this->db = new admin_mainDb();
47 $this->widgetTypeArray = array( array( 'name' => $this->_('For PC'), 'value' => '0'), // PC用
48 array( 'name' => $this->_('For Mobile'), 'value' => '1'), // 携帯用
49 array( 'name' => $this->_('For Smartphone'), 'value' => '2')); // スマートフォン用
54 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
55 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
57 * @param RequestManager $request HTTPリクエスト処理クラス
58 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
59 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
61 function _setTemplate($request, &$param)
63 return 'widgetlist.tmpl.html';
68 * ヘルプの設定を行う場合はヘルプIDを返す。
69 * ヘルプデータの読み込むディレクトリは「自ウィジェットディレクトリ/include/help」に固定。
71 * @param RequestManager $request HTTPリクエスト処理クラス
72 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
73 * @return string ヘルプID。ヘルプデータはファイル名「help_[ヘルプID].php」で作成。ヘルプを使用しない場合は空文字列「''」を返す。
75 function _setHelp($request, &$param)
82 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
84 * @param RequestManager $request HTTPリクエスト処理クラス
85 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
88 function _assign($request, &$param)
90 $act = $request->trimValueOf('act');
91 $selectedItemNo = $request->trimValueOf('no'); // 処理対象の項目番号
92 $serial = $request->trimValueOf('serial'); // シリアルNo
93 $widgetId = $request->trimValueOf('widget'); // 処理対象のウィジェット
94 $this->widgetType = $request->trimValueOf('item_type');// 現在のウィジェットタイプ
95 if ($this->widgetType == '') $this->widgetType = '0'; // デフォルトはPC用ウィジェット
96 $this->showDetail = ($request->trimValueOf('item_show_detail') == 'on') ? 1 : 0; // 詳細表示するかどうか
98 if ($act == 'readnew'){ // ウィジェット再読み込みのとき
101 if ($this->db->getAllWidgetIdList($rows)){
103 switch ($this->widgetType){
104 case '0': // PC用テンプレート
106 $searchPath = $this->gEnv->getWidgetsPath();
108 case '1': // 携帯用テンプレート
109 $searchPath = $this->gEnv->getWidgetsPath() . '/' . M3_DIR_NAME_MOBILE;
111 case '2': // スマートフォン用テンプレート
112 $searchPath = $this->gEnv->getWidgetsPath() . '/' . M3_DIR_NAME_SMARTPHONE;
116 if (is_dir($searchPath)){
117 $dir = dir($searchPath);
118 while (($file = $dir->read()) !== false){
119 $filePath = $searchPath . '/' . $file;
121 if (strncmp($file, '.', 1) != 0 && $file != '..' && is_dir($filePath)
122 && strncmp($file, '_', 1) != 0 // 「_」で始まる名前のディレクトリは読み込まない
123 && strlen($file) > 1){ // 1文字のディレクトリは読み込まない
125 switch ($this->widgetType){
126 case '0': // PC用テンプレート
130 case '1': // 携帯用テンプレート
131 $widgetId = M3_DIR_NAME_MOBILE . '/' . $file;
133 case '2': // スマートフォン用テンプレート
134 $widgetId = M3_DIR_NAME_SMARTPHONE . '/' . $file;
139 for ($i = 0; $i < count($rows); $i++){
140 if ($widgetId == $rows[$i]['wd_id']) break;
142 if ($i == count($rows)){
143 // ディレクトリ内のスクリプト、CSSの状況を取得
144 $ret = $this->getDirStatus($filePath, $hasScripts, $hasCss, $hasAdmin);
148 $this->db->addNewWidget($widgetId, $file, intval($this->widgetType), $hasScripts, $hasCss, $hasAdmin);
150 $this->db->addNewWidget($widgetId, $file, intval($this->widgetType));
152 $this->newWidget[] = $widgetId; // 新規ウィジェットID保存
153 $addWidgetCount++; // ウィジェット追加
162 if ($addWidgetCount > 0){
163 //$msg = '新規ウィジェットを追加しました(追加数=' . $addWidgetCount . ')';
164 $msg = sprintf($this->_('New widgets added. (widgets count=%d)'), $addWidgetCount); // 新規ウィジェットを追加しました(追加数=%d)
166 //$msg = '新規ウィジェットはありません';
167 $msg = $this->_('No new widgets added.'); // 新規ウィジェットはありません
169 $this->setMsg(self::MSG_GUIDANCE, $msg);
170 } else if ($act == 'updateline'){ // 行更新のとき
172 $updateName = $request->trimValueOf('item' . $selectedItemNo . '_name'); // 名前
173 $updateAvailable = ($request->trimValueOf('item' . $selectedItemNo . '_available') == 'on') ? 1 : 0; // 利用可能かどうか
174 $updateActive = ($request->trimValueOf('item' . $selectedItemNo . '_active') == 'on') ? 1 : 0; // ウィジェット実行可能かどうか
176 $ret = $this->db->updateWidget($serial, $updateName, $updateAvailable, $updateActive);
177 if ($ret){ // データ更新成功のとき
178 //$this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
179 $this->setMsg(self::MSG_GUIDANCE, $this->_('Line updated.')); // データを更新しました
181 //$this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
182 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in updating line.')); // データ更新に失敗しました
184 } else if ($act == 'deleteline'){ // ウィジェット削除のとき
185 // ウィジェットが参照状況をチェック、参照されている場合は削除できない
186 if ($this->db->getWidget($serial, $row)){
188 $widgetId = $row['wd_id'];
189 $widgetPath = $this->gEnv->getWidgetsPath() . '/' . $widgetId;
191 // ウィジェットディレクトリの削除権限のチェック
192 if (is_writable($widgetPath) || !is_dir($widgetPath)){ // 削除可能か、すでにディレクトリがないとき
193 // インストール初期化フラグを一旦リセット
194 $this->db->updateIsWidgetInitialized($widgetId, false/*未初期化*/);
197 $saveWidgetId = $this->gEnv->getCurrentWidgetId();// ウィジェットID保存
198 $this->gEnv->setCurrentWidgetId($widgetId);// ウィジェットID一時設定
199 $this->gLaunch->goInstallWidget(1); // アンインストール
200 $this->gEnv->setCurrentWidgetId($saveWidgetId);// ウィジェットID戻す
203 $this->addMsg($this->gInstance->getMessageManager()->getErrorMessage(),
204 $this->gInstance->getMessageManager()->getWarningMessage(), $this->gInstance->getMessageManager()->getGuidanceMessage());
207 if ((is_dir($widgetPath) && rmDirectory($widgetPath)) || !is_dir($widgetPath)){// 削除成功か、ディレクトリが存在しないとき
208 $ret = $this->db->deleteWidget($serial);
209 //$this->setMsg(self::MSG_GUIDANCE, 'ウィジェットを削除しました(ウィジェットID:' . $widgetId . ')');
210 $this->setMsg(self::MSG_GUIDANCE, sprintf($this->_('Widget deleted. (widget ID: %s)'), $widgetId)); // ウィジェットを削除しました(ウィジェットID:%s)
212 //$this->setMsg(self::MSG_APP_ERR, 'ウィジェットのディレクトリが削除できませんでした(ディレクトリ:' . $widgetPath . ')');
213 $this->setMsg(self::MSG_APP_ERR, sprintf($this->_('Failed in deleting widget directory. (directory: %s)'), $widgetPath)); // ウィジェットのディレクトリが削除できませんでした(ディレクトリ:%s)
216 //$this->setMsg(self::MSG_APP_ERR, 'ウィジェットのディレクトリの削除権限がありません(ディレクトリ:' . $widgetPath . ')');
217 $this->setMsg(self::MSG_APP_ERR, sprintf($this->_('You are not allowed to delete widget directory. (directory: %s)'), $widgetPath)); // ウィジェットのディレクトリの削除権限がありません(ディレクトリ:%s)
220 //$this->setMsg(self::MSG_APP_ERR, '削除対象のウィジェットが見つかりません');
221 $this->setMsg(self::MSG_APP_ERR, $this->_('Widget not found.')); // 削除対象のウィジェットが見つかりません
223 } else if ($act == 'upload'){ // ファイルアップロードの場合
224 $replaceWidget = ($request->trimValueOf('item_replace') == 'on') ? 1 : 0; // ウィジェットを置き換えるかどうか
226 // アップロードされたファイルか?セキュリティチェックする
227 if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
228 $uploadFilename = $_FILES['upfile']['name']; // アップロードされたファイルのファイル名取得
231 $pathParts = pathinfo($uploadFilename);
232 $ext = $pathParts['extension']; // 拡張子
233 $widgetName = basename($uploadFilename, '.' . $ext); // 拡張子をはずす
234 $widgetId = $widgetName;
237 switch ($this->widgetType){
238 case '0': // PC用テンプレート
241 case '1': // 携帯用テンプレート
242 $widgetId = M3_DIR_NAME_MOBILE . '/' . $widgetId;
244 case '2': // スマートフォン用テンプレート
245 $widgetId = M3_DIR_NAME_SMARTPHONE . '/' . $widgetId;
251 //$msg = 'zip圧縮のファイルのみアップロード可能です';
252 $msg = $this->_('Only zip format file is allowed to upload.'); // zip圧縮のファイルのみアップロード可能です
253 $this->setAppErrorMsg($msg);
256 // テンポラリディレクトリの書き込み権限をチェック
257 if (!is_writable($this->gEnv->getWorkDirPath())){
258 //$msg = '一時ディレクトリに書き込み権限がありません。ディレクトリ:' . $this->gEnv->getWorkDirPath();
259 $msg = sprintf($this->_('You are not allowed to write temporary directory. (directory: %s)'), $this->gEnv->getWorkDirPath()); // 一時ディレクトリに書き込み権限がありません。(ディレクトリ:%s)
260 $this->setAppErrorMsg($msg);
263 if ($this->getMsgCount() == 0){ // エラーが発生していないとき
264 if (!$replaceWidget){ // ウィジェット置き換えないとき
265 // 同じIDのウィジェットがないかチェック
266 if ($this->db->isExistsWidgetId($widgetId)){
267 //$msg = 'ウィジェットがすでに存在します(ウィジェットID:' . $widgetId . ')';
268 $msg = sprintf($this->_('The widget already exists. (widget ID: %s)'), $widgetId); // ウィジェットがすでに存在します(ウィジェットID:%s)
269 $this->setAppErrorMsg($msg);
273 if ($this->getMsgCount() == 0){ // エラーが発生していないとき
274 // ファイルを保存するサーバディレクトリを指定
275 $tmpFile = tempnam($this->gEnv->getWorkDirPath(), M3_SYSTEM_WORK_UPLOAD_FILENAME_HEAD);
277 // アップされたテンポラリファイルを保存ディレクトリにコピー
278 $ret = move_uploaded_file($_FILES['upfile']['tmp_name'], $tmpFile);
281 switch ($this->widgetType){
282 case '0': // PC用テンプレート
284 $extDir = $this->gEnv->getWidgetsPath();
286 case '1': // 携帯用テンプレート
287 $extDir = $this->gEnv->getWidgetsPath() . '/' . M3_DIR_NAME_MOBILE;
289 case '2': // スマートフォン用テンプレート
290 $extDir = $this->gEnv->getWidgetsPath() . '/' . M3_DIR_NAME_SMARTPHONE;
295 $zipFile = new PclZip($tmpFile);
296 if (($zipList = $zipFile->listContent()) == 0){
297 //$msg = 'zipファイルの内容のリスト取得に失敗しました(要因: ' . $zipFile->errorName(true) . ')';
298 $msg = sprintf($this->_('Failed in getting file list from zip file. (detail: %s)'), $zipFile->errorName(true)); // zipファイルの内容のリスト取得に失敗しました(要因: %s)
299 $this->setAppErrorMsg($msg);
301 // zipファイル名とディレクトリ名が同じであるかチェック
302 $dirName = $widgetName . '/';
303 if (strncmp($zipList[0]['filename'], $dirName, strlen($dirName)) == 0){
304 $widgetPath = $this->gEnv->getWidgetsPath() . '/' . $widgetId;// ウィジェットのディレクトリ
305 if ($replaceWidget){ // ウィジェット置き換える場合
307 if ((is_dir($widgetPath) && rmDirectory($widgetPath)) || !is_dir($widgetPath)){// 削除成功か、ディレクトリが存在しないとき
309 //$this->setMsg(self::MSG_APP_ERR, 'ウィジェットのディレクトリが削除できませんでした');
310 $this->setMsg(self::MSG_APP_ERR, $this->_('Failed in deleting widget directory.')); // ウィジェットのディレクトリが削除できませんでした
314 if ($this->getMsgCount() == 0){ // エラーが発生していないとき
315 $ret = $zipFile->extract(PCLZIP_OPT_PATH, $extDir);
317 // ウィジェット新規登録のときだけウィジェット登録処理を実行
318 // ウィジェット情報が登録されているかチェック
319 $registWidget = false; // ウィジェットを登録するかどうか
320 if (!$replaceWidget || ($replaceWidget && !$this->db->isExistsWidgetId($widgetId))) $registWidget = true;
322 // ウィジェットの新規登録。ウィジェット情報がない場合は作成しておく
325 // ウィジェットが初期化されている場合はデータをそのまま残す→スクリプトを実行しない
326 $initialized = $this->db->isWidgetInitialized($widgetId);
328 // ディレクトリ内のスクリプト、CSSの状況を取得
329 $ret = $this->getDirStatus($widgetPath, $hasScripts, $hasCss, $hasAdmin);
333 $ret = $this->db->addNewWidget($widgetId, $widgetName, intval($this->widgetType), $hasScripts, $hasCss, $hasAdmin);
335 $ret = $this->db->addNewWidget($widgetId, $widgetName, intval($this->widgetType));
338 if ($initialized) $this->db->updateIsWidgetInitialized($widgetId, true/*初期化済み*/);
341 $installType = 0; // インストール
343 // インストール初期化フラグを一旦リセット
344 $this->db->updateIsWidgetInitialized($widgetId, false/*未初期化*/);
347 $installType = 2; // アップデート
351 $saveWidgetId = $this->gEnv->getCurrentWidgetId();// ウィジェットID保存
352 $this->gEnv->setCurrentWidgetId($widgetId);// ウィジェットID一時設定
353 //$this->gLaunch->goInstallWidget(0); // インストール
354 $this->gLaunch->goInstallWidget($installType); // インストール
355 $this->gEnv->setCurrentWidgetId($saveWidgetId);// ウィジェットID戻す
357 // インストールが完了したときは初期化済みに設定
358 $this->db->updateIsWidgetInitialized($widgetId, true/*初期化済み*/);
361 $this->addMsg($this->gInstance->getMessageManager()->getErrorMessage(),
362 $this->gInstance->getMessageManager()->getWarningMessage(), $this->gInstance->getMessageManager()->getGuidanceMessage());
365 if ($this->getMsgCount(self::MSG_APP_ERR) == 0 && $this->getMsgCount(self::MSG_USER_ERR) == 0){ // エラーが発生していないとき
367 $ret = $this->_db->getWidgetInfo($widgetId, $row);
368 if ($ret) $version = $row['wd_version']; // ウィジェットのバージョン
370 switch ($installType){
372 //$msg = 'ウィジェットのインストールが完了しました。';
373 $msg = $this->_('Widget installed successfully.'); // ウィジェットのインストールが完了しました。
376 //$msg = 'ウィジェットの更新が完了しました。';
377 $msg = $this->_('Widget updated successfully.'); // ウィジェットの更新が完了しました。
380 //$msg .= 'バージョンは' . $version . 'です。';
381 $msg .= ' ' . sprintf($this->_('Current version is %s.'), $version); // バージョンは$sです。
382 $this->setGuidanceMsg($msg);
384 //$msg = 'ファイルのアップロードが完了しました(ウィジェットID:' . $widgetId . ')';
385 $msg = sprintf($this->_('File uploaded. (widget ID: %s)'), $widgetId); // ファイルのアップロードが完了しました(ウィジェットID: %s)
386 $this->setGuidanceMsg($msg);
388 //$msg = 'ファイルのアップロードに失敗しました';
389 $msg = $this->_('Failed in uploading file.'); // ファイルのアップロードに失敗しました
390 $this->setAppErrorMsg($msg);
393 $this->newWidget[] = $widgetId; // 新規ウィジェットID保存
395 //$msg = 'ファイルのアップロードに失敗しました(要因: ' . $zipFile->errorName(true) . ')';
396 $msg = sprintf($this->_('Failed in uploading file. (detail: %s)'), $zipFile->errorName(true)); // ファイルのアップロードに失敗しました(要因: %s)
397 $this->setAppErrorMsg($msg);
401 //$msg = 'zipファイルのファイル名とディレクトリ名が異なっているか、全角文字が含まれています';
402 $msg = $this->_('The zip filename is different from directory name.'); // zipファイルのファイル名とディレクトリ名が異なっているか、全角文字が含まれています
403 $this->setAppErrorMsg($msg);
407 //$msg = 'ファイルのアップロードに失敗しました';
408 $msg = $this->_('Failed in uploading file.'); // ファイルのアップロードに失敗しました
409 $this->setAppErrorMsg($msg);
415 //$msg = 'アップロードファイルが見つかりません(要因:アップロード可能なファイルのMaxサイズを超えている可能性があります - ' . $this->gSystem->getMaxFileSizeForUpload() . 'バイト)';
416 $msg = sprintf($this->_('Uploded file not found. (detail: The file may be over maximum size to be allowed to upload. Size %s bytes.'), $this->gSystem->getMaxFileSizeForUpload()); // アップロードファイルが見つかりません(要因:アップロード可能なファイルのMaxサイズを超えている可能性があります。%sバイト)
417 $this->setAppErrorMsg($msg);
419 } else if ($act == 'download'){ // ファイルダウンロードのとき
420 switch ($this->widgetType){
421 case '0': // PC用テンプレート
423 $widgetsDir = $this->gEnv->getWidgetsPath(); // ウィジェットディレクトリ
424 $widgetDir = $widgetsDir . '/' . $widgetId; // ダウンロードするウィジェットのディレクトリ
425 $downloadFilename = $widgetId . '.zip'; // ダウンロード時のファイル名
427 case '1': // 携帯用テンプレート
428 $widgetsDir = $this->gEnv->getWidgetsPath() . '/' . M3_DIR_NAME_MOBILE; // ウィジェットディレクトリ
429 $widgetDir = $this->gEnv->getWidgetsPath() . '/' . $widgetId; // ダウンロードするウィジェットのディレクトリ
430 list($dir, $filename) = explode('/', $widgetId); // 先頭の「m/」を削除
431 $downloadFilename = $filename . '.zip'; // ダウンロード時のファイル名
433 case '2': // スマートフォン用テンプレート
434 $widgetsDir = $this->gEnv->getWidgetsPath() . '/' . M3_DIR_NAME_SMARTPHONE; // ウィジェットディレクトリ
435 $widgetDir = $this->gEnv->getWidgetsPath() . '/' . $widgetId; // ダウンロードするウィジェットのディレクトリ
436 list($dir, $filename) = explode('/', $widgetId); // 先頭の「s/」を削除
437 $downloadFilename = $filename . '.zip'; // ダウンロード時のファイル名
440 $tmpFile = tempnam($this->gEnv->getWorkDirPath(), M3_SYSTEM_WORK_DOWNLOAD_FILENAME_HEAD); // zip処理用一時ファイル
443 $zipFile = new PclZip($tmpFile);
444 $ret = $zipFile->create($widgetDir, PCLZIP_OPT_REMOVE_PATH, $widgetsDir);
447 $this->gPage->abortPage();
450 $ret = $this->gPage->downloadFile($tmpFile, $downloadFilename, true/*実行後ファイル削除*/);
453 $this->gPage->exitSystem();
455 //$msg = 'ファイルのダウンロードに失敗しました(要因: ' . $zipFile->errorName(true) . ')';
456 $msg = sprintf($this->_('Failed in downloading file. (detail: %s)'), $zipFile->errorName(true)); // ファイルのダウンロードに失敗しました(要因: %s)
457 $this->setAppErrorMsg($msg);
462 } else if ($act == 'changedetail'){ // 詳細表示の変更のとき
464 $this->gDisp->setAdminConfig(admin_mainDef::CFG_SHOW_WIDGET_DETAIL, strval($this->showDetail));
467 $this->showDetail = intval($this->gDisp->getAdminConfig(admin_mainDef::CFG_SHOW_WIDGET_DETAIL));
470 switch ($this->widgetType){
471 case '0': // PC用テンプレート
473 $installDir = $this->gEnv->getWidgetsPath();// ウィジェット格納ディレクトリ
475 case '1': // 携帯用テンプレート
476 $installDir = $this->gEnv->getWidgetsPath() . '/' . M3_DIR_NAME_MOBILE;// ウィジェット格納ディレクトリ
478 case '2': // スマートフォン用テンプレート
479 $installDir = $this->gEnv->getWidgetsPath() . '/' . M3_DIR_NAME_SMARTPHONE;// ウィジェット格納ディレクトリ
484 if (!empty($this->showDetail)){ // 詳細表示のとき
485 $this->tmpl->setAttribute('show_dir', 'visibility', 'visible');// ディレクトリ表示
486 $this->tmpl->setAttribute('show_list_detail', 'visibility', 'visible');// 一覧を詳細表示
489 $this->createWidgetTypeMenu();
492 $this->db->getAllWidgetList(intval($this->widgetType), array($this, 'widgetListLoop'));
493 if (!$this->isExistsWidgetList) $this->tmpl->setAttribute('widgetlist', 'visibility', 'hidden');// ウィジェットがないときは、一覧を表示しない
497 if (!empty($this->showDetail)) $checkedStr = 'checked';
498 $this->tmpl->addVar("_widget", "show_detail", $checkedStr); // 詳細表示
499 $this->tmpl->addVar("show_dir", "install_dir", $installDir);// インストールディレクトリを設定
502 $localeText = array();
503 $localeText['msg_update_line'] = $this->_('Update line?'); // 行を更新しますか?
504 $localeText['msg_delete_line'] = $this->_('Delete widget?'); // このウィジェットを削除しますか?
505 $localeText['msg_no_upload_file'] = $this->_('File not selected.'); // アップロードするファイルが選択されていません
506 $localeText['msg_upload_file'] = $this->_('Upload file.'); // ファイルをアップロードします
507 $localeText['label_widget_list'] = $this->_('Widget List'); // ウィジェット一覧
508 $localeText['label_widget_type'] = $this->_('Widget Type:'); // ウィジェットタイプ:
509 $localeText['label_install_dir'] = $this->_('Install Directory:'); // インストールディレクトリ:
510 $localeText['label_read_new'] = $this->_('Reload directory'); // ディレクトリ再読み込み
511 $localeText['label_show_detail'] = $this->_('Show detail'); // 詳細表示
512 $localeText['label_widget_name'] = $this->_('Name'); // 名前
513 $localeText['label_widget_version'] = $this->_('Version'); // バージョン
514 $localeText['label_widget_available'] = $this->_('Available'); // 配置可
515 $localeText['label_widget_active'] = $this->_('Active'); // 実行可
516 $localeText['label_widget_date'] = $this->_('Release Date'); // リリース日
517 $localeText['label_widget_operation'] = $this->_('Operation'); // 操作
518 $localeText['label_widget_upload'] = $this->_('Widget Upload (zip compressed file)'); // ウィジェットアップロード(zip圧縮ファイル)
519 $localeText['msg_replace_widget'] = $this->_('Replace widget if exists.'); // ウィジェットが存在する場合は置き換え
520 $localeText['label_upload'] = $this->_('Upload'); // アップロード
521 $this->setLocaleText($localeText);
524 * ウィジェットのディレクトリの状態を取得
526 * @param string $path ウィジェットディレクトリパス
527 * @param bool $hasScripts スクリプトファイルが存在するかどうか
528 * @param bool $hasCss CSSファイルが存在するかどうか
529 * @param bool $hasAdmin 管理画面があるかどうか
530 * @return bool true=取得成功、false=取得失敗
532 function getDirStatus($path, &$hasScripts, &$hasCss, &$hasAdmin)
541 $searchPath = $path . '/' . M3_DIR_NAME_SCRIPTS;
542 if (is_dir($searchPath)){
543 $dir = dir($searchPath);
544 while (($file = $dir->read()) !== false){
545 $filePath = $searchPath . '/' . $file;
546 $pathParts = pathinfo($file);
547 $ext = $pathParts['extension']; // 拡張子
550 if (strncmp($file, '.', 1) != 0 && $file != '..' && is_file($filePath)
551 && strncmp($file, '_', 1) != 0 && // 「_」で始まる名前のファイルは読み込まない
552 $ext == self::SCRIPT_FILE_EXT){ // 拡張子をチェック
560 $searchPath = $path . '/' . M3_DIR_NAME_CSS;
561 if (is_dir($searchPath)){
562 $dir = dir($searchPath);
563 while (($file = $dir->read()) !== false){
564 $filePath = $searchPath . '/' . $file;
565 $pathParts = pathinfo($file);
566 $ext = $pathParts['extension']; // 拡張子
569 if (strncmp($file, '.', 1) != 0 && $file != '..' && is_file($filePath)
570 && strncmp($file, '_', 1) != 0 && // 「_」で始まる名前のファイルは読み込まない
571 $ext == self::CSS_FILE_EXT){ // 拡張子をチェック
579 $searchPath = $path . '/' . M3_DIR_NAME_ADMIN;
580 if (is_dir($searchPath)){
581 $dir = dir($searchPath);
582 while (($file = $dir->read()) !== false){
583 $filePath = $searchPath . '/' . $file;
584 $pathParts = pathinfo($file);
585 $ext = $pathParts['extension']; // 拡張子
588 if (strncmp($file, '.', 1) != 0 && $file != '..' && is_file($filePath)
589 && strncmp($file, '_', 1) != 0 && // 「_」で始まる名前のファイルは読み込まない
590 $ext == self::PHP_FILE_EXT){ // 拡張子をチェック
604 function createWidgetTypeMenu()
606 for ($i = 0; $i < count($this->widgetTypeArray); $i++){
607 $value = $this->widgetTypeArray[$i]['value'];
608 $name = $this->widgetTypeArray[$i]['name'];
611 if ($value == $this->widgetType) $selected = 'selected';
614 'value' => $value, // ページID
615 'name' => $name, // ページ名
616 'selected' => $selected // 選択中かどうか
618 $this->tmpl->addVars('item_type_list', $row);
619 $this->tmpl->parseTemplate('item_type_list', 'a');
623 * ウィジェットリスト、取得したデータをテンプレートに設定する
625 * @param int $index 行番号(0~)
626 * @param array $fetchedRow フェッチ取得した行
627 * @param object $param 未使用
628 * @return bool true=処理続行の場合、false=処理終了の場合
630 function widgetListLoop($index, $fetchedRow, $param)
632 // ウィジェットが存在するかどうかチェック
633 $isExistsWidget = false;
634 $widgetId = $fetchedRow['wd_id'];// ウィジェットID
635 $widgetDir = $this->gEnv->getWidgetsPath() . '/' . $widgetId; // ウィジェットのディレクトリ
636 if (file_exists($widgetDir)) $isExistsWidget = true;
639 if ($this->showDetail){
640 $this->tmpl->addVar('widgetlist', 'widgettype', 'detail'); // 詳細表示
643 $available = ''; // 利用可能かどうか
644 if ($fetchedRow['wd_available']){
645 $available = 'checked';
647 $active = ''; // ウィジェット実行可能かどうか
648 if ($fetchedRow['wd_active']){
652 // 編集不可項目のときは、ボタンを使用不可にする
654 $availableDisabled = '';
655 $activeDisabled = '';
656 if (!$fetchedRow['wd_editable']){
657 $buttonEnabled = 'disabled';
658 $availableDisabled = 'disabled';
659 $activeDisabled = 'disabled';
662 // 管理画面がないときは、詳細ボタンを使用不可にする
663 $detailButtonEnabled = '';
664 if (!$fetchedRow['wd_has_admin']) $detailButtonEnabled = 'disabled';
666 // 新規に追加されたウィジェットかチェック
667 $idText = $this->convertToDispString($widgetId);
668 for ($i = 0; $i < count($this->newWidget); $i++){
669 if ($this->newWidget[$i] == $widgetId){
670 $idText = '<b><font color="green">' . $this->convertToDispString($widgetId) . '</font></b>';
675 if ($isExistsWidget){ // ウィジェットが存在するとき
677 $iconUrl = $this->gDesign->getWidgetIconUrl($widgetId, $this->defaultImageSize);
679 //$iconTitle = self::NOT_FOUND_WIDGET_MESSAGE; // ウィジェットが見つかりません
680 $iconTitle = $this->_('Widget not found.'); // ウィジェットが見つかりません
681 $iconUrl = $this->gEnv->getRootUrl() . self::NOT_FOUND_WIDGET_ICON_FILE;
683 $imageTag = '<img class="widget_obj" src="' . $this->getUrl($iconUrl) . '" ';
684 $imageTag .= 'width="' . $this->defaultImageSize . '"';
685 $imageTag .= ' height="' . $this->defaultImageSize . '"';
686 $imageTag .= ' border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
690 $title = $fetchedRow['wd_name'];
692 $helpText = $this->gInstance->getHelpManager()->createHelpText($title, $fetchedRow['wd_description']);
694 $idText = '<span ' . $helpText . '>' . $idText . '</span>';
697 $downloadButton = '';
698 if (!$isExistsWidget) $downloadButton = 'disabled';
699 if (!empty($fetchedRow['wd_license_type'])) $downloadButton = 'disabled';// ライセンスのチェック
702 'no' => $index + 1, // 行番号
703 'serial' => $this->convertToDispString($fetchedRow['wd_serial']), // シリアル番号
704 'id' => $this->convertToDispString($widgetId), // ID
705 'id_text' => $idText,
706 'name' => $this->convertToDispString($fetchedRow['wd_name']), // 名前
707 'version' => $this->convertToDispString($fetchedRow['wd_version']), // バージョン
708 'release_dt' => $this->convertToDispDate($fetchedRow['wd_release_dt']), // リリース日時
709 'available' => $available, // 利用可能かどうか
710 'active' => $active, // ウィジェット実行可能かどうか
711 'available_disabled' => $availableDisabled, // 利用可能かどうか、使用制御
712 'active_disabled' => $activeDisabled, // ウィジェット実行可能かどうか、使用制御
713 'update_button' => $buttonEnabled, // 更新ボタンの使用制御
714 'delete_button' => $buttonEnabled, // 削除ボタンの使用制御
715 'detail_button' => $detailButtonEnabled, // 詳細ボタンの使用制御
716 'download_button' => $downloadButton, // ダウンロードボタン
717 'image_tag' => $imageTag, // 画像
718 'label_widget_config' => $this->_('Configure'), // 設定
719 'label_update' => $this->_('Update'), // 更新
720 'label_delete' => $this->_('Delete'), // 削除
721 'label_download' => $this->_('Download') // ダウンロード
723 $this->tmpl->addVars('widgetlist', $row);
724 $this->tmpl->parseTemplate('widgetlist', 'a');
726 $this->isExistsWidgetList = true; // ウィジェットが存在する