diff --git a/app/src/App.php b/app/src/App.php index 5ef64d27..11e99e52 100644 --- a/app/src/App.php +++ b/app/src/App.php @@ -241,11 +241,7 @@ public static function getDeviceType(Request $request): int // Cookieからデバイスタイプを取得 $device_type = $request->rawCookie('device'); - $devices = [ - App::DEVICE_PC, - App::DEVICE_SP, - ]; - if (!empty($device_type) && in_array($device_type, $devices)) { + if (!empty($device_type) && static::isExistsDeviceId($device_type)) { return (int)$device_type; } @@ -261,6 +257,16 @@ public static function getDeviceType(Request $request): int return App::DEVICE_PC; } + /** + * デバイスタイプが既知のものか?(許可されているか?) + * @param string $id + * @return bool + */ + public static function isExistsDeviceId(string $id): bool + { + return in_array($id, self::ALLOW_DEVICES); + } + /** * デバイスタイプを取得する * @param Request $request @@ -269,8 +275,7 @@ public static function getDeviceType(Request $request): int public static function getDeviceTypeStr(Request $request): string { $device_id = static::getDeviceType($request); - $device_table = App::DEVICE_FC2_KEY; - return $device_table[$device_id]; + return App::DEVICE_FC2_KEY[$device_id] ?? App::DEVICE_FC2_KEY[App::DEVICE_PC]; } /** diff --git a/app/src/Web/Controller/Admin/BlogPluginsController.php b/app/src/Web/Controller/Admin/BlogPluginsController.php index c51d221d..03143ab6 100644 --- a/app/src/Web/Controller/Admin/BlogPluginsController.php +++ b/app/src/Web/Controller/Admin/BlogPluginsController.php @@ -9,6 +9,7 @@ use Fc2blog\Model\BlogTemplatesModel; use Fc2blog\Model\Model; use Fc2blog\Model\PluginsModel; +use Fc2blog\Util\Log; use Fc2blog\Web\Request; class BlogPluginsController extends AdminController @@ -45,6 +46,7 @@ public function index(Request $request): string } } $this->set('blog_plugin_json', $blog_plugin_json); + $this->set('state', $request->get('state')); return "admin/blog_plugins/index.twig"; } @@ -73,6 +75,8 @@ public function share_search(Request $request): string return $this->plugin_search($request, false); } + const ALLOWED_PLUGIN_CATEGORY_TYPE_RANGE = "1-3"; + /** * プラグイン検索 (内部呼び出し) * @param Request $request @@ -117,6 +121,11 @@ private function plugin_search(Request $request, bool $is_official = true): stri $this->set('req_device_name', __(BlogTemplatesModel::getDeviceName((int)$request->get('device_type')))); $this->set('device_key', App::getDeviceFc2Key($request->get('device_type'))); $this->set('is_official', $is_official); + if (!preg_match('/\A[' . self::ALLOWED_PLUGIN_CATEGORY_TYPE_RANGE . ']\z/u', $request->get('category'))) { + Log::notice("Request invalid plugin category type " . $request->get('category')); + return $this->error400(); + } + $this->set('plugin_category_type_id', $request->get('category')); return 'admin/blog_plugins/plugin_search.twig'; } @@ -191,13 +200,15 @@ public function edit(Request $request): string $this->set('device_type_sp', (string)App::DEVICE_SP); // 編集対象のデータ取得、なければリダイレクト - if (!$blog_plugin = $blog_plugins_model->findByIdAndBlogId($id, $blog_id)) { + $blog_plugin = $blog_plugins_model->findByIdAndBlogId($id, $blog_id); + if ($blog_plugin === false) { $this->redirect($request, array('action' => 'index')); } // 初期表示時に編集データの設定 if (!$request->get('blog_plugin') || !$request->isValidSig()) { $request->set('blog_plugin', $blog_plugin); + $this->set('blog_plugin', $blog_plugin); return "admin/blog_plugins/edit.twig"; } diff --git a/app/src/Web/Controller/Admin/BlogTemplatesController.php b/app/src/Web/Controller/Admin/BlogTemplatesController.php index 40cc58ba..24feae7e 100644 --- a/app/src/Web/Controller/Admin/BlogTemplatesController.php +++ b/app/src/Web/Controller/Admin/BlogTemplatesController.php @@ -10,6 +10,7 @@ use Fc2blog\Model\Fc2TemplatesModel; use Fc2blog\Model\Model; use Fc2blog\Service\BlogService; +use Fc2blog\Util\Log; use Fc2blog\Web\Request; class BlogTemplatesController extends AdminController @@ -45,6 +46,11 @@ public function index(Request $request): string } $this->set('device_blog_templates', $device_blog_templates); $this->set('devices', BlogTemplatesModel::DEVICE_NAME); + if (!App::isExistsDeviceId($request->get("device_type", (string)App::DEVICE_PC))) { + Log::notice("invalid device_type params :" . $request->get("device_type")); + return $this->error400(); + } + $this->set('req_device_type', $request->get("device_type")); return "admin/blog_templates/index.twig"; } @@ -77,6 +83,11 @@ public function fc2_index(Request $request): string $this->set('templates', $templates); $this->set('paging', $paging); $this->set('devices', BlogTemplatesModel::DEVICE_NAME); + if (!App::isExistsDeviceId((string)$request->get("device_type", (string)App::DEVICE_PC))) { + Log::notice("invalid device_type params :" . $request->get("device_type")); + return $this->error400(); + } + $this->set('req_device_type', $request->get("device_type")); return "admin/blog_templates/fc2_index.twig"; } @@ -101,6 +112,12 @@ public function fc2_view(Request $request): string $device_type = $request->get('device_type', (string)App::DEVICE_PC); $request->set('device_type', $device_type); + if (!App::isExistsDeviceId($request->get("device_type", (string)App::DEVICE_PC))) { + Log::notice("invalid device_type params :" . $request->get("device_type")); + return $this->error400(); + } + $this->set('req_device_type', $request->get("device_type")); + // テンプレート取得 $device_key = App::getDeviceFc2Key($device_type); $template = Model::load('Fc2Templates')->findByIdAndDevice($request->get('fc2_id'), $device_key); @@ -177,13 +194,15 @@ public function edit(Request $request): string $id = $request->get('id'); $blog_id = $this->getBlogIdFromSession(); + $blog_template = $blog_templates_model->findByIdAndBlogId($id, $blog_id); // 初期表示時に編集データの取得&設定 if (!$request->get('blog_template') || !$request->isValidPost()) { - if (!$blog_template = $blog_templates_model->findByIdAndBlogId($id, $blog_id)) { + if (!$blog_template) { $this->redirect($request, ['action' => 'index']); } $request->set('blog_template', $blog_template); + $this->set('blog_template', $blog_template); return "admin/blog_templates/edit.twig"; } diff --git a/app/src/Web/Controller/Admin/CategoriesController.php b/app/src/Web/Controller/Admin/CategoriesController.php index f387c7d2..34948c92 100644 --- a/app/src/Web/Controller/Admin/CategoriesController.php +++ b/app/src/Web/Controller/Admin/CategoriesController.php @@ -40,6 +40,7 @@ public function create(Request $request): string // 初期表示時 if (!$request->get('category') || !$request->isValidSig()) { + $this->set('show_category_list', true); return "admin/categories/create.twig"; } @@ -79,12 +80,16 @@ public function edit(Request $request): string $options = $categories_model->getParentList($blog_id, $id); $this->set('category_parents', [0 => ''] + $options); $this->set('categories_model_order_list', $categories_model::getOrderList()); + $category = $categories_model->findByIdAndBlogId($id, $blog_id); + $this->set('category', $category); + + // 編集対象がみつからないので、新規作成にリダイレクト + if ($category === false) { + $this->redirect($request, ['action' => 'create']); + } // 初期表示時に編集データの取得&設定 if (!$request->get('category') || !$request->isValidSig()) { - if (!$category = $categories_model->findByIdAndBlogId($id, $blog_id)) { - $this->redirect($request, ['action' => 'create']); - } $request->set('category', $category); return "admin/categories/edit.twig"; } diff --git a/app/src/Web/Controller/Admin/TagsController.php b/app/src/Web/Controller/Admin/TagsController.php index 6396b8bb..e8549931 100644 --- a/app/src/Web/Controller/Admin/TagsController.php +++ b/app/src/Web/Controller/Admin/TagsController.php @@ -83,10 +83,10 @@ public function edit(Request $request): string { $tags_model = new TagsModel(); - $id = $request->get('id'); + $tag_id = $request->get('id'); $blog_id = $this->getBlogIdFromSession(); - if (!$tag = $tags_model->findByIdAndBlogId($id, $blog_id)) { + if (!$tag = $tags_model->findByIdAndBlogId($tag_id, $blog_id)) { $this->redirect($request, ['action' => 'index']); } $this->set('tag', $tag); @@ -104,11 +104,11 @@ public function edit(Request $request): string // 更新処理 if (!$request->isPost()) return $this->error400(); $tag_request = $request->get('tag'); - $tag_request['id'] = $id; + $tag_request['id'] = $tag_id; $tag_request['blog_id'] = $blog_id; $errors['tag'] = $tags_model->validate($tag_request, $data, ['name']); if (empty($errors['tag'])) { - if ($tags_model->updateByIdAndBlogId($data, $id, $blog_id)) { + if ($tags_model->updateByIdAndBlogId($data, $tag_id, $blog_id)) { $this->setInfoMessage(__('I have updated the tag')); // 元の画面へ戻る diff --git a/app/twig_templates/admin/blog_plugins/edit.twig b/app/twig_templates/admin/blog_plugins/edit.twig index c2226d0f..f15108ac 100644 --- a/app/twig_templates/admin/blog_plugins/edit.twig +++ b/app/twig_templates/admin/blog_plugins/edit.twig @@ -6,7 +6,7 @@