EC-CUBE /
ec-cube
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 Eccube\Event\EccubeEvents; |
||
| 31 | use Eccube\Event\EventArgs; |
||
| 32 | use Eccube\Util\Str; |
||
| 33 | use Symfony\Component\Filesystem\Filesystem; |
||
| 34 | use Symfony\Component\Finder\Finder; |
||
| 35 | use Symfony\Component\HttpFoundation\Request; |
||
| 36 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
| 37 | |||
| 38 | class BlockController extends AbstractController |
||
| 39 | { |
||
| 40 | 2 | View Code Duplication | public function index(Application $app, Request $request) |
| 41 | { |
||
| 42 | 2 | $DeviceType = $app['eccube.repository.master.device_type'] |
|
| 43 | 2 | ->find(DeviceType::DEVICE_TYPE_PC); |
|
| 44 | |||
| 45 | // 登録されているブロック一覧の取得 |
||
| 46 | 2 | $Blocks = $app['eccube.repository.block']->getList($DeviceType); |
|
| 47 | |||
| 48 | 2 | $event = new EventArgs( |
|
| 49 | array( |
||
| 50 | 2 | 'DeviceType' => $DeviceType, |
|
| 51 | 2 | 'Blocks' => $Blocks, |
|
| 52 | ), |
||
| 53 | $request |
||
| 54 | ); |
||
| 55 | 2 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_INDEX_COMPLETE, $event); |
|
| 56 | |||
| 57 | 2 | return $app->render('Content/block.twig', array( |
|
| 58 | 2 | 'Blocks' => $Blocks, |
|
| 59 | )); |
||
| 60 | } |
||
| 61 | |||
| 62 | 4 | public function edit(Application $app, Request $request, $id = null) |
|
| 63 | { |
||
| 64 | 4 | $DeviceType = $app['eccube.repository.master.device_type'] |
|
| 65 | 4 | ->find(DeviceType::DEVICE_TYPE_PC); |
|
| 66 | |||
| 67 | 4 | $Block = $app['eccube.repository.block'] |
|
| 68 | 4 | ->findOrCreate($id, $DeviceType); |
|
| 69 | |||
| 70 | 4 | if (!$Block) { |
|
| 71 | throw new NotFoundHttpException(); |
||
| 72 | } |
||
| 73 | |||
| 74 | 4 | $builder = $app['form.factory'] |
|
| 75 | 4 | ->createBuilder('block', $Block); |
|
| 76 | |||
| 77 | 4 | $html = ''; |
|
| 78 | 4 | $previous_filename = null; |
|
| 79 | 4 | $deletable = $Block->getDeletableFlg(); |
|
| 80 | |||
| 81 | 4 | if ($id) { |
|
| 82 | // テンプレートファイルの取得 |
||
| 83 | 4 | $previous_filename = $Block->getFileName(); |
|
| 84 | 4 | $file = $app['eccube.repository.block'] |
|
| 85 | 4 | ->getReadTemplateFile($previous_filename, $deletable); |
|
| 86 | 4 | $html = $file['tpl_data']; |
|
| 87 | } |
||
| 88 | |||
| 89 | 4 | $event = new EventArgs( |
|
| 90 | array( |
||
| 91 | 4 | 'builder' => $builder, |
|
| 92 | 4 | 'DeviceType' => $DeviceType, |
|
| 93 | 4 | 'Block' => $Block, |
|
| 94 | 4 | 'html' => $html, |
|
| 95 | ), |
||
| 96 | $request |
||
| 97 | ); |
||
| 98 | 4 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_EDIT_INITIALIZE, $event); |
|
| 99 | 4 | $html = $event->getArgument('html'); |
|
| 100 | |||
| 101 | 4 | $form = $builder->getForm(); |
|
| 102 | |||
| 103 | 4 | $form->get('block_html')->setData($html); |
|
| 104 | |||
| 105 | 4 | if ($app['request']->getMethod() === 'POST') { |
|
| 106 | 2 | $form->handleRequest($app['request']); |
|
| 107 | 2 | if ($form->isValid()) { |
|
| 108 | 2 | $Block = $form->getData(); |
|
| 109 | |||
| 110 | // DB登録 |
||
| 111 | 2 | $app['orm.em']->persist($Block); |
|
| 112 | 2 | $app['orm.em']->flush(); |
|
| 113 | |||
| 114 | // ファイル生成・更新 |
||
| 115 | 2 | $tplDir = $app['config']['block_realdir']; |
|
| 116 | |||
| 117 | 2 | $filePath = $tplDir . '/' . $Block->getFileName() . '.twig'; |
|
| 118 | |||
| 119 | 2 | $fs = new Filesystem(); |
|
| 120 | 2 | $blockData = $form->get('block_html')->getData(); |
|
| 121 | 2 | $blockData = Str::convertLineFeed($blockData); |
|
| 122 | 2 | $fs->dumpFile($filePath, $blockData); |
|
| 123 | // 更新でファイル名を変更した場合、以前のファイルを削除 |
||
| 124 | 2 | View Code Duplication | if ($Block->getFileName() != $previous_filename && !is_null($previous_filename)) { |
| 125 | 2 | $oldFilePath = $tplDir . '/' . $previous_filename . '.twig'; |
|
| 126 | 2 | if ($fs->exists($oldFilePath)) { |
|
| 127 | $fs->remove($oldFilePath); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | 2 | \Eccube\Util\Cache::clear($app, false); |
|
|
0 ignored issues
–
show
|
|||
| 132 | |||
| 133 | 2 | $event = new EventArgs( |
|
| 134 | array( |
||
| 135 | 2 | 'form' => $form, |
|
| 136 | 2 | 'Block' => $Block, |
|
| 137 | ), |
||
| 138 | $request |
||
| 139 | ); |
||
| 140 | 2 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_EDIT_COMPLETE, $event); |
|
| 141 | |||
| 142 | 2 | $app->addSuccess('admin.register.complete', 'admin'); |
|
| 143 | |||
| 144 | 2 | return $app->redirect($app->url('admin_content_block_edit', array('id' => $Block->getId()))); |
|
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | |||
| 149 | 2 | return $app->render('Content/block_edit.twig', array( |
|
| 150 | 2 | 'form' => $form->createView(), |
|
| 151 | 2 | 'block_id' => $id, |
|
| 152 | 2 | 'deletable' => $deletable, |
|
| 153 | )); |
||
| 154 | } |
||
| 155 | |||
| 156 | 2 | public function delete(Application $app, Request $request, $id) |
|
| 157 | { |
||
| 158 | 2 | $this->isTokenValid($app); |
|
| 159 | |||
| 160 | 2 | $DeviceType = $app['eccube.repository.master.device_type'] |
|
| 161 | 2 | ->find(DeviceType::DEVICE_TYPE_PC); |
|
| 162 | |||
| 163 | 2 | $Block = $app['eccube.repository.block']->findOneBy(array( |
|
| 164 | 2 | 'id' => $id, |
|
| 165 | 2 | 'DeviceType' => $DeviceType |
|
| 166 | )); |
||
| 167 | |||
| 168 | 2 | if (!$Block) { |
|
| 169 | $app->deleteMessage(); |
||
| 170 | return $app->redirect($app->url('admin_content_block')); |
||
| 171 | } |
||
| 172 | |||
| 173 | // ユーザーが作ったブロックのみ削除する |
||
| 174 | // テンプレートが変更されていた場合、DBからはブロック削除されるがtwigファイルは残る |
||
| 175 | 2 | View Code Duplication | if ($Block->getDeletableFlg() > 0) { |
| 176 | 1 | $tplDir = $app['config']['block_realdir']; |
|
| 177 | 1 | $file = $tplDir . '/' . $Block->getFileName() . '.twig'; |
|
| 178 | 1 | $fs = new Filesystem(); |
|
| 179 | 1 | if ($fs->exists($file)) { |
|
| 180 | $fs->remove($file); |
||
| 181 | } |
||
| 182 | 1 | $app['orm.em']->remove($Block); |
|
| 183 | 1 | $app['orm.em']->flush(); |
|
| 184 | |||
| 185 | 1 | $event = new EventArgs( |
|
| 186 | array( |
||
| 187 | 1 | 'Block' => $Block, |
|
| 188 | ), |
||
| 189 | $request |
||
| 190 | ); |
||
| 191 | 1 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_DELETE_COMPLETE, $event); |
|
| 192 | |||
| 193 | 1 | $app->addSuccess('admin.delete.complete', 'admin'); |
|
| 194 | 1 | \Eccube\Util\Cache::clear($app, false); |
|
|
0 ignored issues
–
show
$app is of type object<Eccube\Application>, but the function expects a object<Eccube\Util\Application>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 195 | } |
||
| 196 | |||
| 197 | |||
| 198 | 2 | return $app->redirect($app->url('admin_content_block')); |
|
| 199 | } |
||
| 200 | } |
||
| 201 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: