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_mainTemplistWidgetContainer.php 5499 2012-12-31 10:37:44Z 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'); // 定義クラス
20 require_once($gEnvManager->getCommonPath() . '/archive.php');
22 require_once($gEnvManager->getJoomlaRootPath() . '/JParameter.php');
23 require_once($gEnvManager->getJoomlaRootPath() . '/JRender.php');
25 class admin_mainTemplistWidgetContainer extends admin_mainBaseWidgetContainer
27 private $db; // DB接続オブジェクト
28 private $sysDb; // システムDBオブジェクト
29 private $newTemplate = array(); // 新規追加テンプレート
30 private $defalutTemplate; // デフォルトのテンプレート
31 private $templateTypeArray; // テンプレートタイプ
32 private $templateType; // 現在のテンプレートタイプ
33 private $showDetail; // 詳細表示するかどうか
34 private $isExistsTemplateList; // テンプレートが存在するかどうか
35 const TEMPLATE_THUMBNAIL_FILENAME = 'template_thumbnail.png'; // テンプレートサムネール
36 const previewImageSizeHeight = 27;
37 const previewImageSizeWidth = 42;
38 const imageSizeHeight = 135;
39 const imageSizeWidth = 210;
40 const JOOMLA_CONFIG_FILENAME = 'templateDetails.xml'; // Joomla!のテンプレート設定ファイル名
41 const NOT_FOUND_TEMPLATE_ICON_FILE = '/images/system/notfound32.png'; // テンプレートが見つからないアイコン
46 function __construct()
49 parent::__construct();
52 $this->db = new admin_mainDb();
53 $this->sysDb = $this->gInstance->getSytemDbObject();
56 $this->templateTypeArray = array( array( 'name' => $this->_('For PC'), 'value' => '0'), // PC用
57 array( 'name' => $this->_('For Mobile'), 'value' => '1'), // 携帯用
58 array( 'name' => $this->_('For Smartphone'), 'value' => '2')); // スマートフォン用
63 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
64 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
66 * @param RequestManager $request HTTPリクエスト処理クラス
67 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
68 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
70 function _setTemplate($request, &$param)
72 return 'templist.tmpl.html';
77 * ヘルプの設定を行う場合はヘルプIDを返す。
78 * ヘルプデータの読み込むディレクトリは「自ウィジェットディレクトリ/include/help」に固定。
80 * @param RequestManager $request HTTPリクエスト処理クラス
81 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
82 * @return string ヘルプID。ヘルプデータはファイル名「help_[ヘルプID].php」で作成。ヘルプを使用しない場合は空文字列「''」を返す。
84 function _setHelp($request, &$param)
91 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
93 * @param RequestManager $request HTTPリクエスト処理クラス
94 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
97 function _assign($request, &$param)
99 $act = $request->trimValueOf('act');
100 $selectedItemNo = $request->trimValueOf('no'); // 処理対象の項目番号
101 $userId = $this->gEnv->getCurrentUserId();
102 $templateId = $request->trimValueOf('template'); // テンプレートID
103 $this->templateType = $request->trimValueOf('item_type');// 現在のテンプレートタイプ
104 if ($this->templateType == '') $this->templateType = '0'; // デフォルトはPC用テンプレート
105 $this->showDetail = ($request->trimValueOf('item_show_detail') == 'on') ? 1 : 0; // 詳細表示するかどうか
107 if ($act == 'readnew'){ // テンプレート再読み込みのとき
108 $addTemplateCount = 0;
110 if ($this->db->getAllTemplateIdList($rows)){
112 switch ($this->templateType){
113 case '0': // PC用テンプレート
115 $searchPath = $this->gEnv->getTemplatesPath();
117 case '1': // 携帯用テンプレート
118 $searchPath = $this->gEnv->getTemplatesPath() . '/' . M3_DIR_NAME_MOBILE;
120 case '2': // スマートフォン用テンプレート
121 $searchPath = $this->gEnv->getTemplatesPath() . '/' . M3_DIR_NAME_SMARTPHONE;
125 if (is_dir($searchPath)){
126 $dir = dir($searchPath);
127 while (($file = $dir->read()) !== false){
128 $filePath = $searchPath . '/' . $file;
130 if (strncmp($file, '.', 1) != 0 && $file != '..' && is_dir($filePath) &&
131 strncmp($file, '_', 1) != 0 && // 「_」で始まる名前のディレクトリは読み込まない
132 strlen($file) > 1 && // 携帯、スマートフォン用ディレクトリ「m」「s」は読み込まない
133 !($this->templateType == 0 && $file == 'system')){ // PC用Joomla!デフォルトテンプレート「system」は読み込まない
136 switch ($this->templateType){
137 case '0': // PC用テンプレート
141 case '1': // 携帯用テンプレート
142 $templateId = M3_DIR_NAME_MOBILE . '/' . $file;
144 case '2': // スマートフォン用テンプレート
145 $templateId = M3_DIR_NAME_SMARTPHONE . '/' . $file;
150 for ($i = 0; $i < count($rows); $i++){
151 if ($templateId == $rows[$i]['tm_id']) break;
153 if ($i == count($rows)){
155 $ret = $this->addNewTemplate(intval($this->templateType), $templateId);
157 $this->newTemplate[] = $templateId;
158 $addTemplateCount++; // テンプレート追加
168 if ($addTemplateCount > 0){
169 //$msg = '新規テンプレートを追加しました(追加数=' . $addTemplateCount . ')';
170 $msg = sprintf($this->_('New templates added. (templates count=%d)'), $addTemplateCount); // 新規テンプレートを追加しました(追加数=%d)
172 //$msg = '新規テンプレートはありません';
173 $msg = $this->_('No new templates added.'); // 新規テンプレートはありません
175 $this->setMsg(self::MSG_GUIDANCE, $msg);
176 } else if ($act == 'updateline'){ // 行更新のとき
178 if (empty($templateId)) $this->setMsg(self::MSG_APP_ERR, $this->_('Template not selected.')); // テンプレートが選択されていません
180 if (!$this->isExistsMsg()){ // エラーなしのとき
182 $updateName = $request->trimValueOf('item' . $selectedItemNo . '_name'); // 名前
183 $updateIsDefault = ($request->trimValueOf('item' . $selectedItemNo . '_isdefault') == 'on') ? 1 : 0; // デフォルトかどうか
184 $ret = $this->db->updateTemplate($templateId, $updateName);
185 if ($ret){ // データ更新成功のとき
186 //$this->setMsg(self::MSG_GUIDANCE, 'データを更新しました(テンプレートID:' . $templateId . ')');
187 $this->setMsg(self::MSG_GUIDANCE, sprintf($this->_('Line updated. (template ID: %s)'), $templateId)); // データを更新しました(テンプレートID:%s)
189 //$this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました(テンプレートID:' . $templateId . ')');
190 $this->setMsg(self::MSG_APP_ERR, sprintf($this->_('Failed in updating line. (template ID: %s)'), $templateId)); // データ更新に失敗しました(テンプレートID:%s)
193 } else if ($act == 'deleteline'){ // テンプレート削除のとき
195 if (empty($templateId)) $this->setMsg(self::MSG_APP_ERR, $this->_('Template not selected.')); // テンプレートが選択されていません
197 if (!$this->isExistsMsg()){ // エラーなしのとき
199 $templatePath = $this->gEnv->getTemplatesPath() . '/' . $templateId;
202 if ((is_dir($templatePath) && rmDirectory($templatePath)) || !is_dir($templatePath)){// 削除成功か、ディレクトリが存在しないとき
203 $ret = $this->db->deleteTemplate($templateId);
204 if ($ret){ // データ更新成功のとき
205 //$this->setMsg(self::MSG_GUIDANCE, 'テンプレートを削除しました(テンプレートID:' . $templateId . ')');
206 $this->setMsg(self::MSG_GUIDANCE, sprintf($this->_('Template deleted. (template ID: %s)'), $templateId)); // テンプレートを削除しました(テンプレートID:%s)
208 //$this->setMsg(self::MSG_APP_ERR, 'テンプレート削除に失敗しました(テンプレートID:' . $templateId . ')');
209 $this->setMsg(self::MSG_APP_ERR, sprintf($this->_('Failed in deleting template. (template ID: %s)'), $templateId)); // テンプレート削除に失敗しました(テンプレートID:%s)
212 //$this->setMsg(self::MSG_APP_ERR, 'テンプレートのディレクトリが削除できませんでした(テンプレートID:' . $templateId . ')');
213 $this->setMsg(self::MSG_APP_ERR, sprintf($this->_('Failed in deleting template directory. (directory: %s)'), $templatePath)); // テンプレートのディレクトリが削除できませんでした(ディレクトリ:%s)
216 } else if ($act == 'upload'){ // ファイルアップロードの場合
217 // アップロードされたファイルか?セキュリティチェックする
218 if (is_uploaded_file($_FILES['upfile']['tmp_name'])){
219 $uploadFilename = $_FILES['upfile']['name']; // アップロードされたファイルのファイル名取得
222 $pathParts = pathinfo($uploadFilename);
223 $ext = $pathParts['extension']; // 拡張子
224 $templateName = basename($uploadFilename, '.' . $ext); // 拡張子をはずす
225 $ext = strtolower($ext);
229 //$msg = 'zip圧縮のファイルのみアップロード可能です';
230 $msg = $this->_('Only zip format file is allowed to upload.'); // zip圧縮のファイルのみアップロード可能です
231 $this->setAppErrorMsg($msg);
234 // テンポラリディレクトリの書き込み権限をチェック
235 if (!is_writable($this->gEnv->getWorkDirPath())){
236 //$msg = '一時ディレクトリに書き込み権限がありません。ディレクトリ:' . $this->gEnv->getWorkDirPath();
237 $msg = sprintf($this->_('You are not allowed to write temporary directory. (directory: %s)'), $this->gEnv->getWorkDirPath()); // 一時ディレクトリに書き込み権限がありません。(ディレクトリ:%s)
238 $this->setAppErrorMsg($msg);
241 if ($this->getMsgCount() == 0){ // エラーが発生していないとき
242 // ファイルを保存するサーバディレクトリを指定
243 $tmpFile = tempnam($this->gEnv->getWorkDirPath(), M3_SYSTEM_WORK_UPLOAD_FILENAME_HEAD);
245 // アップされたテンポラリファイルを保存ディレクトリにコピー
246 $ret = move_uploaded_file($_FILES['upfile']['tmp_name'], $tmpFile);
249 $extDir = $this->gEnv->getTempDir();
252 $archiver = new Archive();
253 $ret = $archiver->extract($tmpFile, $extDir, $ext);
256 $fileList = getFileList($extDir);
257 if (count($fileList) == 1 && is_dir($extDir . '/' . $fileList[0])){ // 単一ディレクトリのとき
258 $srcTemplateDir = $extDir . '/' . $fileList[0];
261 $srcTemplateDir = $extDir;
264 $templateId = $this->getTemplateId($srcTemplateDir);
266 // テンプレートIDが取得できないときは、送信されたファイルのファイル名を使用
267 if (empty($templateId)) $templateId = $templateName;
270 switch ($this->templateType){
271 case '0': // PC用テンプレート
274 case '1': // 携帯用テンプレート
275 $templateId = M3_DIR_NAME_MOBILE . '/' . $templateId;
277 case '2': // スマートフォン用テンプレート
278 $templateId = M3_DIR_NAME_SMARTPHONE . '/' . $templateId;
282 // 同IDのテンプレートがないかチェック
283 if ($this->db->getAllTemplateIdList($rows)){
284 for ($i = 0; $i < count($rows); $i++){
285 if ($templateId == $rows[$i]['tm_id']) break;
287 if ($i < count($rows)){
288 //$msg = '同じIDのテンプレートがすでに存在します(テンプレートID:' . $templateId . ')';
289 $msg = sprintf($this->_('The template already exists. (template ID: %s)'), $templateId); // テンプレートがすでに存在します(テンプレートID:%s)
290 $this->setAppErrorMsg($msg);
294 if ($this->getMsgCount() == 0){ // エラーが発生していないとき
296 $destTemplateDir = $this->gEnv->getTemplatesPath() . '/' . $templateId; // テンプレートの移動先
297 if (file_exists($destTemplateDir)){
298 //$msg = '同じIDのテンプレートディレクトリがすでに存在します(テンプレートID:' . $templateId . ')';
299 $msg = sprintf($this->_('The template directory already exists. (directory: %s)'), $destTemplateDir);// テンプレートディレクトリがすでに存在します(ディレクトリ:%s)
300 $this->setAppErrorMsg($msg);
303 $ret = @rename($srcTemplateDir, $destTemplateDir);
304 if (!$ret) $ret = mvDirectory($srcTemplateDir, $destTemplateDir); // 2009/7/17 異なるデバイス間でrenameできなかった問題に対応
307 $ret = $this->addNewTemplate(intval($this->templateType), $templateId);
309 //$msg = 'ファイルのアップロードが完了しました(テンプレートID:' . $templateId . ')';
310 $msg = sprintf($this->_('File uploaded. (template ID: %s)'), $templateId); // ファイルのアップロードが完了しました(テンプレートID: %s)
311 $this->setGuidanceMsg($msg);
312 $this->newTemplate[] = $templateId;
314 //$msg = 'ディレクトリの移動に失敗しました(ディレクトリ:' . $destTemplateDir . ')';
315 $msg = sprintf($this->_('Failed in moving directory. (directory: %s)'), $destTemplateDir);// ディレクトリの移動に失敗しました(ディレクトリ:%s)
316 $this->setAppErrorMsg($msg);
322 if (file_exists($extDir)) rmDirectory($extDir);
324 //$msg = 'ファイルのアップロードに失敗しました';
325 $msg = $this->_('Failed in uploading file.'); // ファイルのアップロードに失敗しました
326 $this->setAppErrorMsg($msg);
332 //$msg = 'アップロードファイルが見つかりません(要因:アップロード可能なファイルのMaxサイズを超えている可能性があります - ' . $this->gSystem->getMaxFileSizeForUpload() . 'バイト)';
333 $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バイト)
334 $this->setAppErrorMsg($msg);
336 } else if ($act == 'download'){ // ファイルダウンロードのとき
337 switch ($this->templateType){
338 case '0': // PC用テンプレート
340 $templatesDir = $this->gEnv->getTemplatesPath(); // テンプレートディレクトリ
341 $templateDir = $templatesDir . '/' . $templateId; // ダウンロードするテンプレートのディレクトリ
342 $downloadFilename = $templateId . '.zip'; // ダウンロード時のファイル名
344 case '1': // 携帯用テンプレート
345 $templatesDir = $this->gEnv->getTemplatesPath() . '/' . M3_DIR_NAME_MOBILE; // テンプレートディレクトリ
346 $templateDir = $this->gEnv->getTemplatesPath() . '/' . $templateId; // ダウンロードするテンプレートのディレクトリ
347 list($dir, $filename) = explode('/', $templateId); // 先頭の「m/」を削除
348 $downloadFilename = $filename . '.zip'; // ダウンロード時のファイル名
350 case '2': // スマートフォン用テンプレート
351 $templatesDir = $this->gEnv->getTemplatesPath() . '/' . M3_DIR_NAME_SMARTPHONE; // テンプレートディレクトリ
352 $templateDir = $this->gEnv->getTemplatesPath() . '/' . $templateId; // ダウンロードするテンプレートのディレクトリ
353 list($dir, $filename) = explode('/', $templateId); // 先頭の「s/」を削除
354 $downloadFilename = $filename . '.zip'; // ダウンロード時のファイル名
357 $tmpFile = tempnam($this->gEnv->getWorkDirPath(), M3_SYSTEM_WORK_DOWNLOAD_FILENAME_HEAD); // zip処理用一時ファイル
360 $zipFile = new PclZip($tmpFile);
361 $ret = $zipFile->create($templateDir, PCLZIP_OPT_REMOVE_PATH, $templatesDir);
364 $this->gPage->abortPage();
367 $ret = $this->gPage->downloadFile($tmpFile, $downloadFilename, true/*実行後ファイル削除*/);
370 $this->gPage->exitSystem();
372 //$msg = 'ファイルのダウンロードに失敗しました(要因: ' . $zipFile->errorName(true) . ')';
373 $msg = sprintf($this->_('Failed in downloading file. (detail: %s)'), $zipFile->errorName(true)); // ファイルのダウンロードに失敗しました(要因: %s)
374 $this->setAppErrorMsg($msg);
379 } else if ($act == 'changedefault'){ // デフォルトテンプレートの変更のとき
381 if (empty($templateId)) $this->setMsg(self::MSG_APP_ERR, $this->_('Template not selected.')); // テンプレートが選択されていません
383 if (!$this->isExistsMsg()){ // エラーなしのとき
384 switch ($this->templateType){
385 case '0': // PC用テンプレート
388 $this->gSystem->changeDefaultTemplate($templateId);
391 $request->setSessionValue(M3_SESSION_CURRENT_TEMPLATE, $templateId);
393 case '1': // 携帯用テンプレート
395 $this->gSystem->changeDefaultMobileTemplate($templateId);
397 case '2': // スマートフォン用テンプレート
399 $this->gSystem->changeDefaultSmartphoneTemplate($templateId);
403 $this->gCache->clearAllCache();
405 } else if ($act == 'changedetail'){ // 詳細表示の変更のとき
407 $this->gDisp->setAdminConfig(admin_mainDef::CFG_SHOW_TEMPLATE_DETAIL, strval($this->showDetail));
408 } else if ($act == 'changetype'){ // テンプレートタイプの変更のとき
412 $this->showDetail = intval($this->gDisp->getAdminConfig(admin_mainDef::CFG_SHOW_TEMPLATE_DETAIL));
415 switch ($this->templateType){
416 case '0': // PC用テンプレート
418 $this->defalutTemplate = $this->gSystem->defaultTemplateId();// デフォルトのテンプレート
419 $installDir = $this->gEnv->getTemplatesPath();// テンプレート格納ディレクトリ
421 case '1': // 携帯用テンプレート
422 $this->defalutTemplate = $this->gSystem->defaultMobileTemplateId();// デフォルトのテンプレート
423 $installDir = $this->gEnv->getTemplatesPath() . '/' . M3_DIR_NAME_MOBILE;// テンプレート格納ディレクトリ
425 case '2': // スマートフォン用テンプレート
426 $this->defalutTemplate = $this->gSystem->defaultSmartphoneTemplateId();// デフォルトのテンプレート
427 $installDir = $this->gEnv->getTemplatesPath() . '/' . M3_DIR_NAME_SMARTPHONE;// テンプレート格納ディレクトリ
431 if (!empty($this->showDetail)){ // 詳細表示のとき
432 $this->tmpl->setAttribute('show_dir', 'visibility', 'visible');// ディレクトリ表示
436 $this->createTemplateTypeMenu();
439 $this->db->getAllTemplateList(intval($this->templateType), array($this, 'tempListLoop'));
440 if (!$this->isExistsTemplateList) $this->tmpl->setAttribute('templist', 'visibility', 'hidden');// テンプレートがないときは、一覧を表示しない
444 if (!empty($this->showDetail)) $checkedStr = 'checked';
445 $this->tmpl->addVar("_widget", "show_detail", $checkedStr); // 詳細表示
446 $this->tmpl->addVar("show_dir", "install_dir", $installDir);// インストールディレクトリ
447 $this->tmpl->addVar("_widget", "admin_url", $this->getUrl($this->gEnv->getDefaultAdminUrl()));// 管理用URL
450 $localeText = array();
451 $localeText['msg_update_line'] = $this->_('Update line?'); // 行を更新しますか?
452 $localeText['msg_delete_line'] = $this->_('Delete tmplate?'); // テンプレートを削除しますか?
453 $localeText['msg_no_upload_file'] = $this->_('File not selected.'); // アップロードするファイルが選択されていません
454 $localeText['msg_upload_file'] = $this->_('Upload file.'); // ファイルをアップロードします
455 $localeText['label_template_list'] = $this->_('Template List'); // テンプレート一覧
456 $localeText['label_template_type'] = $this->_('Template Type:'); // テンプレートタイプ:
457 $localeText['label_install_dir'] = $this->_('Install Directory:'); // インストールディレクトリ:
458 $localeText['label_read_new'] = $this->_('Reload directory'); // ディレクトリ再読み込み
459 $localeText['label_show_detail'] = $this->_('Show detail'); // 詳細表示
460 $localeText['label_template_name'] = $this->_('Name'); // 名前
461 $localeText['label_template_format'] = $this->_('Format'); // 形式
462 $localeText['label_template_creator'] = $this->_('Artisteer Version'); // Artisteerバージョン
463 $localeText['label_template_default'] = $this->_('Default'); // デフォルト
464 $localeText['label_template_date'] = $this->_('Update Date'); // 更新日時
465 $localeText['label_template_operation'] = $this->_('Operation'); // 操作
466 $localeText['label_template_upload'] = $this->_('Template Upload (zip compressed file)'); // テンプレートアップロード(zip圧縮ファイル)
467 $localeText['label_upload'] = $this->_('Upload'); // アップロード
468 $this->setLocaleText($localeText);
471 * テンプレートリスト、取得したデータをテンプレートに設定する
473 * @param int $index 行番号(0~)
474 * @param array $fetchedRow フェッチ取得した行
475 * @param object $param 未使用
476 * @return bool true=処理続行の場合、false=処理終了の場合
478 function tempListLoop($index, $fetchedRow, $param)
480 // テンプレートが存在するかどうかチェック
481 $isExistsTemplate = false;
482 $templateId = $fetchedRow['tm_id'];// テンプレートID
483 $templateDir = $this->gEnv->getTemplatesPath() . '/' . $templateId; // テンプレートのディレクトリ
484 if (file_exists($templateDir)) $isExistsTemplate = true;
487 if ($this->showDetail){
488 $this->tmpl->addVar('templist', 'templatetype', 'detail'); // 詳細表示
493 if ($fetchedRow['tm_id'] == $this->defalutTemplate){
494 $defaultCheck = 'checked ';
496 if (!$isExistsTemplate) $defaultCheck .= 'disabled'; // テンプレートが存在しないときは使用不可
499 $name = $this->convertToDispString($fetchedRow['tm_name']); // テンプレート名
500 $templateIndexFile = $templateDir . '/index.php'; // テンプレートindex.phpファイル
501 $imgUrl = $this->gEnv->getTemplatesUrl() . '/' . $templateId . '/' . self::TEMPLATE_THUMBNAIL_FILENAME;
503 // 新規に追加されたテンプレートかチェック
504 $idText = $this->convertToDispString($templateId);
505 for ($i = 0; $i < count($this->newTemplate); $i++){
506 if ($this->newTemplate[$i] == $templateId){
507 $idText = '<b><font color="green">' . $this->convertToDispString($templateId) . '</font></b>';
512 if ($isExistsTemplate){ // テンプレートが存在するとき
513 $imageTag = '<img src="' . $this->getUrl($imgUrl) . '" width="' . self::previewImageSizeWidth . '" height="' . self::previewImageSizeHeight . '" border="0" />';
515 $iconTitle = $this->_('Template not found.'); // テンプレートが見つかりません
516 $iconUrl = $this->gEnv->getRootUrl() . self::NOT_FOUND_TEMPLATE_ICON_FILE;
517 $imageTag = '<img src="' . $this->getUrl($iconUrl) . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
521 switch ($fetchedRow['tm_type']){
522 case 0: // Joomla!v1.0型
523 $formatType = 'J10'; // テンプレート形式
525 case 1: // Joomla!v1.5型
526 $formatType = 'J15'; // テンプレート形式
528 case 2: // Joomla!v2.5型
529 $formatType = 'J25'; // テンプレート形式
532 $formatType = $this->_('Not Detected'); // 未定
535 $formatType .= ' /<br />';
537 // テンプレートを作成したArtisteerのバージョンを取得
538 if (file_exists($templateIndexFile)){
539 $content = file_get_contents($templateIndexFile);
540 $version = $this->getArtVersion($content);
541 if (empty($version)){
542 $formatType .= $this->_('Not Detected'); // 未検出
544 $formatType .= $version;
549 $downloadButton = '';
550 if (!$isExistsTemplate) $downloadButton = 'disabled';
553 'no' => $index + 1, // 行番号
554 'serial' => $this->convertToDispString($fetchedRow['tm_serial']), // シリアル番号
556 'id' => $this->convertToDispString($templateId), // ID
557 'name' => $name, // 名前
558 'format_type' => $formatType, // テンプレート形式
559 'update_dt' => $this->convertToDispDateTime($fetchedRow['tm_create_dt']), // 更新日時
560 'is_default' => $defaultCheck, // デフォルトテンプレートかどうか
561 'image_tag' => $imageTag, // 画像
562 'download_button' => $downloadButton, // ダウンロードボタン
563 'label_preview' => $this->_('Preview'), // プレビュー
564 'label_update' => $this->_('Update'), // 更新
565 'label_delete' => $this->_('Delete'), // 削除
566 'label_download' => $this->_('Download') // ダウンロード
568 $this->tmpl->addVars('templist', $row);
569 $this->tmpl->parseTemplate('templist', 'a');
571 $this->isExistsTemplateList = true; // テンプレートが存在する
577 * @param int $type テンプレート種別(0=PC用、1=携帯用, 2=スマートフォン用)
578 * @param string $id テンプレートID(ディレクトリ名)
579 * @param bool true=成功、false=失敗
581 function addNewTemplate($type, $id)
584 $templType = 0; // テンプレートのタイプデフォルト値(Joomla!1.0)
585 $cleanType = 0; // HTMLの出力のクリーニングタイプ
589 case '0': // PC用テンプレート
590 case '2': // スマートフォン用テンプレート
591 $configFile = $this->gEnv->getTemplatesPath() . '/' . $id . '/' . self::JOOMLA_CONFIG_FILENAME;
592 if (file_exists($configFile)){
593 if (!function_exists('simplexml_load_file')){
594 $msg = $this->_('SimpleXML module not installed.'); // SimpleXML拡張モジュールがインストールされていません
595 $this->setAppErrorMsg($msg);
598 $xml = simplexml_load_file($configFile);
600 if ($xml->attributes()->type == 'template'){
601 $version = $xml->attributes()->version;
602 if (version_compare($version, '1.6') >= 0){
603 $templType = 2; // Joomla!v2.5テンプレート
604 } else if (version_compare($version, '1.5') >= 0){
605 $templType = 1; // Joomla!v1.5テンプレート
608 $cleanType = $this->checkTemplate($id);
617 $ret = $this->db->addNewTemplate($id, $id, $templType, intval($type), $cleanType);
623 * @param string $dir テンプレートのディレクトリ
624 * @return string テンプレート(取得できないときは空を返す)
626 function getTemplateId($dir)
629 $id = basename($dir);
632 $configFile = $dir . '/' . self::JOOMLA_CONFIG_FILENAME;
633 if (file_exists($configFile)){
634 if (!function_exists('simplexml_load_file')){
635 $msg = $this->_('SimpleXML module not installed.'); // SimpleXML拡張モジュールがインストールされていません
636 $this->setAppErrorMsg($msg);
639 $xml = simplexml_load_file($configFile);
641 $name = trim($xml->name);
642 if (!empty($name)) $id = $name;
652 function createTemplateTypeMenu()
654 for ($i = 0; $i < count($this->templateTypeArray); $i++){
655 $value = $this->templateTypeArray[$i]['value'];
656 $name = $this->templateTypeArray[$i]['name'];
659 if ($value == $this->templateType) $selected = 'selected';
662 'value' => $value, // ページID
663 'name' => $name, // ページ名
664 'selected' => $selected // 選択中かどうか
666 $this->tmpl->addVars('item_type_list', $row);
667 $this->tmpl->parseTemplate('item_type_list', 'a');
673 * @param string $templateId テンプレートID
674 * @return int クリーン処理タイプ
676 function checkTemplate($id)
680 // Joomla!テンプレート共通の設定
684 define('JPATH_BASE', dirname(__FILE__));
685 define('DS', DIRECTORY_SEPARATOR);
690 $render = new JRender();
691 $render->setTemplate($id);
692 $contents = $render->getComponentContents('test', 'dummy contents', 'test');
695 $pos = strpos($contents, 'PostHeaderIcons');
696 if ($pos !== false) $cleanType = 1;
703 * テンプレートのindex.phpファイルからArtisteerバージョンを取得
705 * @param string $src 検索するデータ
706 * @return string 検出の場合はバージョン文字列、未検出の場合は空文字列。
708 function getArtVersion($src)
711 // <!-- Created by Artisteer v4.1.0.59688 -->
712 $pattern = '/<!-- Created by Artisteer[^<]*?v([.\d]+)[^<]*?-->/i';
713 $ret = preg_match($pattern, $src, $matches);
714 if ($ret) $version = $matches[1];