/** * Validate and save changes. * * @return Response */ public function patchIndex(BoardConfigRequest $request, Board $board) { $input = $request->all(); $optionGroups = $request->getBoardOptions(); foreach ($optionGroups as $optionGroup) { foreach ($optionGroup->options as $option) { $setting = BoardSetting::firstOrNew(['option_name' => $option->option_name, 'board_uri' => $board->board_uri]); $option->option_value = $input[$option->option_name]; $setting->option_value = $input[$option->option_name]; $setting->save(); } } $board->title = $input['boardBasicTitle']; $board->description = $input['boardBasicDesc']; $board->is_overboard = isset($input['boardBasicOverboard']) && !!$input['boardBasicOverboard']; $board->is_indexed = isset($input['boardBasicIndexed']) && !!$input['boardBasicIndexed']; $board->is_worksafe = isset($input['boardBasicWorksafe']) && !!$input['boardBasicWorksafe']; $board->save(); Event::fire(new BoardWasModified($board)); return $this->view(static::VIEW_CONFIG, ['board' => $board, 'groups' => $optionGroups]); }
/** * Imports configuration files. */ public function importInfinityBoardConfig() { $this->info("\tImporting board assets ..."); BoardSetting::truncate(); Board::orderBy('board_uri', 'asc')->chunk(1, function ($boards) { foreach ($boards as $board) { $this->line("\t\tImporting config from /{$board->board_uri}/"); # CONFIG $config = []; $configPath = "{$this->targetLocation}/{$board->board_uri}/config.php"; $settings = []; $permissions = []; if (is_readable($configPath)) { try { include $configPath; } catch (\Exception $e) { $this->warn("\t\tBAD CONFIG!"); } } foreach ($config as $configName => $configValue) { $optionName = null; $optionValue = null; switch ($configName) { # CONTENT RESTRICTIONS case "field_disable_name": $optionName = "postsAllowAuthor"; $optionValue = !!$configValue; break; case "force_image_op": $optionName = "threadAttachmentsMin"; $optionValue = $configValue ? 1 : 0; break; case "force_subject_op": $optionName = "threadRequireSubject"; $optionValue = !!$configValue; break; case "max_newlines": $optionName = "postNewLines"; $optionValue = max((int) $configValue, 0); break; case "min_body": $optionName = "postMinLength"; $optionValue = max((int) $configValue, 0); break; # POST META # POST META case "anonymous": $optionName = "postAnonymousName"; $optionValue = $configValue ?: null; break; case "country_flags": $optionName = "postsAuthorCountry"; $optionValue = !!$configValue; break; case "poster_ids": $optionName = "postsThreadId"; $optionValue = !!$configValue; break; # ORIGINALITY ENFORCEMENT # ORIGINALITY ENFORCEMENT case "robot_enable": $optionName = "originalityPosts"; $optionValue = $configValue ? "boardr9k" : ""; break; case "disable_images": $optionName = "postAttachmentsMax"; $optionValue = $configValue ? 0 : 5; break; case "image_reject_repost": case "image_reject_repost_in_thread": $optionName = "originalityImages"; if (isset($config['image_reject_repost']) && $config['image_reject_repost']) { $optionValue = "board"; } else { if (isset($config['image_reject_repost_in_thread']) && $config['image_reject_repost_in_thread']) { $optionValue = "thread"; } else { $optionValue = ""; } } break; # EPHEMERALITY # EPHEMERALITY case "max_pages": $optionName = "epheDeleteThreadPage"; $optionValue = max((int) $configValue, 1); break; case "reply_limit": $optionName = "epheLockThreadReply"; $optionValue = max((int) $configValue, 1); break; # PERMISSIONS # PERMISSIONS case "tor_posting": $permissions[] = ['permission_id' => "board.post.create.thread", 'value' => !!$configValue]; $permissions[] = ['permission_id' => "board.post.create.reply", 'value' => !!$configValue]; continue; case "tor_image_posting": $permissions[] = ['permission_id' => "board.image.upload.new", 'value' => !!$configValue]; $permissions[] = ['permission_id' => "board.image.upload.old", 'value' => true]; continue; # CSS # CSS case "stylesheets": if (is_array($configValue)) { $optionName = "boardCustomCSS"; $optionValue = "/* Styling imported from Infinity. ~ xoxo Josh */\n\n"; $cssPath = "{$this->targetLocation}/stylesheets/"; foreach ($configValue as $stylesheet) { if (is_readable("{$cssPath}{$stylesheet}")) { $optionValue .= file_get_contents("{$cssPath}{$stylesheet}"); } } } break; } if (!is_null($optionName)) { $settings[$optionName] = ['board_uri' => $board->board_uri, 'option_name' => $optionName, 'option_value' => $optionValue, 'is_locked' => false]; } } if (count($settings)) { $board->settings()->createMany($settings); } if (count($permissions)) { $role = Role::getUnaccountableRoleForBoard($board); $role->permissions()->detach(); $role->permissionAssignments()->createMany($permissions); } } }); }
/** * Validate and save changes. * * @return Response */ public function patchConfig(BoardConfigRequest $request, Board $board) { $input = $request->all(); $optionGroups = $request->getBoardOptions(); $settings = []; foreach ($optionGroups as &$optionGroup) { foreach ($optionGroup->options as &$option) { $setting = BoardSetting::firstOrNew(['option_name' => $option->option_name, 'board_uri' => $board->board_uri]); // Skip locked items unless we can edit them. $locking = isset($input['lock'][$option->option_name]) && !!$input['lock'][$option->option_name]; if ($setting->isLocked() && !$this->user->canEditSettingLock($board, $option)) { continue; } // Save the value. if (isset($input[$option->option_name])) { $setting->option_value = $input[$option->option_name]; } else { if ($option->format == "onoff") { $setting->option_value = false; } else { if (!$locking) { // Delete it if we have no value and aren't saving. $setting->delete(); continue; } else { $setting->option_value = null; } } } // Set our locked status. if ($locking) { $setting->is_locked = !!$input['lock'][$option->option_name]; } $setting->save(); $settings[] = $setting; } } $board->title = $input['boardBasicTitle']; $board->description = $input['boardBasicDesc']; $board->is_overboard = isset($input['boardBasicOverboard']) && !!$input['boardBasicOverboard']; $board->is_indexed = isset($input['boardBasicIndexed']) && !!$input['boardBasicIndexed']; $board->is_worksafe = isset($input['boardBasicWorksafe']) && !!$input['boardBasicWorksafe']; $board->save(); Event::fire(new BoardWasModified($board)); return $this->getConfig($board); }