| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | //if accessed directly exit |
| 3 | 3 | if (!defined('ABSPATH')) exit; |
| 4 | 4 | |
| 5 | 5 | use FluentBoards\App\Services\Helper; |
| 6 | +use FluentBoards\App\Services\Libs\FileSystem; | |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * All registered action's handlers should be in app\Hooks\Handlers, |
| 9 | 10 | * addAction is similar to add_action and addCustomAction is just a |
| @@ -17,9 +18,41 @@ | ||
| 17 | 18 | * @var $app FluentBoards\Framework\Foundation\Application |
| 18 | 19 | */ |
| 19 | 20 | |
| 20 | 21 | (new \FluentBoards\App\Hooks\Handlers\AdminMenuHandler())->register(); |
| 22 | +$app->addAction('admin_init', 'UpdateHandler@maybeUpgradeIndexes', 10, 0); | |
| 21 | 23 | |
| 24 | +add_action('fluent_boards/check_upload_protection', function () { | |
| 25 | + FileSystem::checkUploadProtection(); | |
| 26 | +}); | |
| 27 | + | |
| 28 | +// Cover existing uploads after updates, even before another file is uploaded. | |
| 29 | +add_action('admin_init', function () { | |
| 30 | + if (!current_user_can('manage_options') || wp_doing_ajax()) { | |
| 31 | + return; | |
| 32 | + } | |
| 33 | + | |
| 34 | + $protectionReady = FileSystem::installUploadProtectionRules(false); | |
| 35 | + $blocked = FileSystem::checkUploadProtection(false); | |
| 36 | + if (!$protectionReady || $blocked !== true) { | |
| 37 | + add_action('admin_notices', function () use ($protectionReady, $blocked) { | |
| 38 | + if ($blocked === false) { | |
| 39 | + $message = __('Fluent Boards uploads are accessible by direct URL without a login. Ask your hosting provider to block direct web access to this directory and its subdirectories.', 'fluent-boards'); | |
| 40 | + } elseif (!$protectionReady) { | |
| 41 | + $message = __('Fluent Boards could not prepare upload-directory protection. Ask your hosting provider to check filesystem permissions and block direct access to uploads.', 'fluent-boards'); | |
| 42 | + } else { | |
| 43 | + $message = __('Fluent Boards could not verify upload-directory protection. Writing .htaccess rules does not confirm that your web server enforces them.', 'fluent-boards'); | |
| 44 | + } | |
| 45 | + $uploads = wp_upload_dir(); | |
| 46 | + $folder = apply_filters('fluent_boards/upload_folder_name', FLUENT_BOARDS_UPLOAD_DIR); | |
| 47 | + $url = trailingslashit($uploads['baseurl']) . trim($folder, '/'); | |
| 48 | + echo '<div class="notice notice-warning"><p>' . esc_html($message) . '</p><p>' | |
| 49 | + . esc_html__('Nginx requires a server rule denying this upload URL and every path beneath it. Apache must honor the generated .htaccess authorization rules. Verify that direct file requests return 403 or 404. This check retries every five minutes.', 'fluent-boards') | |
| 50 | + . '</p><p><code>' . esc_html($url) . '</code></p></div>'; | |
| 51 | + }); | |
| 52 | + } | |
| 53 | +}); | |
| 54 | + | |
| 22 | 55 | /* |
| 23 | 56 | * Add custom CSS for fbs_notice. |
| 24 | 57 | */ |
| 25 | 58 | add_action('admin_head', function () { |
| @@ -62,9 +95,11 @@ | ||
| 62 | 95 | $app->addCustomAction('task_created', 'ActivityHandler@logTaskCreationActivity', 10, 1); |
| 63 | 96 | $app->addCustomAction('task_content_updated', 'ActivityHandler@logTaskContentUpdatedActivity', 10, 3); |
| 64 | 97 | $app->addCustomAction('task_deleted', 'TaskHandler@taskDeleted', 10, 1); |
| 65 | 98 | $app->addCustomAction('task_archived', 'ActivityHandler@taskArchived', 10, 1); |
| 66 | -//$app->addCustomAction('task_custom_field_changed', 'ActivityHandler@logCustomFieldActivity', 10, 5); // commented for now, will implement later | |
| 99 | +$app->addCustomAction('task_custom_field_changed', 'ActivityHandler@logCustomFieldActivity', 10, 5); | |
| 100 | +$app->addCustomAction('board_custom_field_created', 'BoardHandler@customFieldCreated', 10, 1); | |
| 101 | +$app->addCustomAction('board_custom_field_updated', 'BoardHandler@customFieldUpdated', 10, 2); | |
| 67 | 102 | |
| 68 | 103 | $app->addCustomAction('board_created', 'BoardHandler@boardCreated', 10, 1); |
| 69 | 104 | $app->addCustomAction('board_created_from_automation', 'BoardHandler@boardCreatedFromAutomation', 10, 1); |
| 70 | 105 | $app->addCustomAction('before_board_deleted', 'BoardHandler@beforeBoardDeleted', 10, 2); |
| @@ -127,8 +162,9 @@ | ||
| 127 | 162 | $app->addCustomAction('task_attachment_deleted', 'ActivityHandler@taskAttachmentDeleted', 10, 1); |
| 128 | 163 | $app->addCustomAction('task_attachment_deleted', 'TaskHandler@taskAttachmentDeleted', 10, 2); |
| 129 | 164 | // Removed: direct call is made from Comment::deleting to TaskHandler@commentImageDeleted |
| 130 | 165 | $app->addAction('deleted_user', 'BoardHandler@deleteUserRelatedData', 10, 3); |
| 166 | +$app->addAction('fluent_boards/delete_remote_attachment_files', 'FileHandler@deleteRemoteAttachmentFiles', 10, 1); | |
| 131 | 167 | |
| 132 | 168 | $app->addCustomAction('task_created', 'TaskHandler@onTaskCreated', 10, 1); |
| 133 | 169 | $app->addCustomAction('comment_created', 'TaskHandler@onCommentCreated', 10, 1); |
| 134 | 170 | $app->addCustomAction('assign_another_user', 'TaskHandler@onAssignAnotherUser', 10, 2); |
| @@ -213,8 +249,10 @@ | ||
| 213 | 249 | ]; |
| 214 | 250 | |
| 215 | 251 | return $handlers; |
| 216 | 252 | }); |
| 253 | + | |
| 254 | +\FluentBoards\App\Services\MCPAccessService::registerHooks(); | |
| 217 | 255 | |
| 218 | 256 | add_action('init', function () { |
| 219 | 257 | if (!function_exists('wp_register_ability')) { |
| 220 | 258 | return; |