|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of EC-CUBE |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* http://www.lockon.co.jp/ |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
12
|
|
|
* of the License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program; if not, write to the Free Software |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
namespace Eccube\Controller\Admin\Content; |
|
26
|
|
|
|
|
27
|
|
|
use Eccube\Application; |
|
28
|
|
|
use Eccube\Controller\AbstractController; |
|
29
|
|
|
use Eccube\Entity\Master\DeviceType; |
|
30
|
|
|
use Symfony\Component\Finder\Finder; |
|
31
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
32
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
33
|
|
|
|
|
34
|
|
|
class BlockController extends AbstractController |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
1 |
|
public function index(Application $app) |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
$DeviceType = $app['eccube.repository.master.device_type'] |
|
39
|
|
|
->find(DeviceType::DEVICE_TYPE_PC); |
|
40
|
|
|
|
|
41
|
|
|
// 登録されているブロック一覧の取得 |
|
42
|
|
|
$Blocks = $app['eccube.repository.block']->getList($DeviceType); |
|
43
|
|
|
|
|
44
|
1 |
|
return $app->render('Content/block.twig', array( |
|
45
|
|
|
'Blocks' => $Blocks, |
|
46
|
|
|
)); |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
2 |
|
public function edit(Application $app, $id = null) |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$DeviceType = $app['eccube.repository.master.device_type'] |
|
52
|
|
|
->find(DeviceType::DEVICE_TYPE_PC); |
|
53
|
|
|
|
|
54
|
|
|
$Block = $app['eccube.repository.block'] |
|
55
|
|
|
->findOrCreate($id, $DeviceType); |
|
56
|
|
|
|
|
57
|
2 |
|
if (!$Block) { |
|
58
|
|
|
throw new NotFoundHttpException(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$form = $app['form.factory'] |
|
62
|
|
|
->createBuilder('block', $Block) |
|
63
|
|
|
->getForm(); |
|
64
|
|
|
|
|
65
|
2 |
|
$html = ''; |
|
66
|
2 |
|
$previous_filename = null; |
|
67
|
|
|
$deletable = $Block->getDeletableFlg(); |
|
68
|
|
|
|
|
69
|
2 |
|
if ($id) { |
|
70
|
|
|
// テンプレートファイルの取得 |
|
71
|
|
|
$previous_filename = $Block->getFileName(); |
|
72
|
|
|
$file = $app['eccube.repository.block'] |
|
73
|
|
|
->getReadTemplateFile($previous_filename, $deletable); |
|
74
|
2 |
|
$html = $file['tpl_data']; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$form->get('block_html')->setData($html); |
|
78
|
|
|
|
|
79
|
|
|
if ($app['request']->getMethod() === 'POST') { |
|
80
|
|
|
$form->handleRequest($app['request']); |
|
81
|
|
|
if ($form->isValid()) { |
|
82
|
|
|
$Block = $form->getData(); |
|
83
|
|
|
|
|
84
|
|
|
// DB登録 |
|
85
|
|
|
$app['orm.em']->persist($Block); |
|
86
|
|
|
$app['orm.em']->flush(); |
|
87
|
|
|
|
|
88
|
|
|
// ファイル生成・更新 |
|
89
|
|
|
$tplDir = $app['config']['block_realdir']; |
|
90
|
|
|
|
|
91
|
|
|
$filePath = $tplDir . '/' . $Block->getFileName() . '.twig'; |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$fs = new Filesystem(); |
|
94
|
|
|
$fs->dumpFile($filePath, $form->get('block_html')->getData()); |
|
95
|
|
|
// 更新でファイル名を変更した場合、以前のファイルを削除 |
|
96
|
|
|
if ($Block->getFileName() != $previous_filename && !is_null($previous_filename)) { |
|
97
|
1 |
|
$oldFilePath = $tplDir . $previous_filename; |
|
|
|
|
|
|
98
|
|
|
if ($fs->exists($oldFilePath)) { |
|
99
|
|
|
$fs->remove($oldFilePath); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
\Eccube\Util\Cache::clear($app,false); |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
$app->addSuccess('admin.register.complete', 'admin'); |
|
106
|
|
|
|
|
107
|
|
|
return $app->redirect($app->url('admin_content_block_edit', array('id' => $Block->getId()))); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
1 |
|
return $app->render('Content/block_edit.twig', array( |
|
113
|
1 |
|
'form' => $form->createView(), |
|
114
|
|
|
'block_id' => $id, |
|
115
|
|
|
'deletable' => $deletable, |
|
116
|
|
|
)); |
|
117
|
2 |
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
public function delete(Application $app, $id) |
|
|
|
|
|
|
120
|
|
|
{ |
|
121
|
|
|
$this->isTokenValid($app); |
|
122
|
|
|
|
|
123
|
|
|
$DeviceType = $app['eccube.repository.master.device_type'] |
|
124
|
|
|
->find(DeviceType::DEVICE_TYPE_PC); |
|
125
|
|
|
|
|
126
|
|
|
$Block = $app['eccube.repository.block']->findOneBy(array( |
|
|
|
|
|
|
127
|
|
|
'id' => $id, |
|
128
|
|
|
'DeviceType' => $DeviceType |
|
129
|
|
|
)); |
|
130
|
|
|
|
|
131
|
1 |
|
if (!$Block) { |
|
132
|
|
|
$app->deleteMessage(); |
|
133
|
|
|
return $app->redirect($app->url('admin_content_block')); |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
// ユーザーが作ったブロックのみ削除する |
|
137
|
|
|
// テンプレートが変更されていた場合、DBからはブロック削除されるがtwigファイルは残る |
|
138
|
|
|
if ($Block->getDeletableFlg() > 0) { |
|
139
|
|
|
$tplDir = $app['config']['block_realdir']; |
|
140
|
|
|
$file = $tplDir . '/' . $Block->getFileName() . '.twig'; |
|
|
|
|
|
|
141
|
|
|
$fs = new Filesystem(); |
|
142
|
|
|
if ($fs->exists($file)) { |
|
143
|
|
|
$fs->remove($file); |
|
144
|
|
|
} |
|
145
|
|
|
$app['orm.em']->remove($Block); |
|
146
|
|
|
$app['orm.em']->flush(); |
|
147
|
|
|
|
|
148
|
|
|
$app->addSuccess('admin.delete.complete', 'admin'); |
|
149
|
|
|
\Eccube\Util\Cache::clear($app,false); |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
return $app->redirect($app->url('admin_content_block')); |
|
154
|
1 |
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|