From 37de796949437181dab3b588bed06ea1c0f38e25 Mon Sep 17 00:00:00 2001 From: abejith Date: Fri, 20 Dec 2024 12:06:44 -0500 Subject: [PATCH] added the initial files --- .github/workflows/gitlab_mirror.yml | 19 ++++ composer.json | 15 ++++ .../sensitive_content_checker.settings.yml | 4 + css/sensitive-content.css | 49 +++++++++++ js/sensitive-content.js | 46 ++++++++++ sensitive_content_checker.info.yml | 12 +++ sensitive_content_checker.libraries.yml | 12 +++ sensitive_content_checker.links.menu.yml | 5 ++ sensitive_content_checker.routing.yml | 7 ++ src/Form/SensitiveContentConfigForm.php | 87 +++++++++++++++++++ src/Plugin/Block/SensitiveContentBlock.php | 66 ++++++++++++++ 11 files changed, 322 insertions(+) create mode 100644 .github/workflows/gitlab_mirror.yml create mode 100644 composer.json create mode 100644 config/install/sensitive_content_checker.settings.yml create mode 100644 css/sensitive-content.css create mode 100644 js/sensitive-content.js create mode 100644 sensitive_content_checker.info.yml create mode 100644 sensitive_content_checker.libraries.yml create mode 100644 sensitive_content_checker.links.menu.yml create mode 100644 sensitive_content_checker.routing.yml create mode 100644 src/Form/SensitiveContentConfigForm.php create mode 100644 src/Plugin/Block/SensitiveContentBlock.php diff --git a/.github/workflows/gitlab_mirror.yml b/.github/workflows/gitlab_mirror.yml new file mode 100644 index 0000000..57c5f21 --- /dev/null +++ b/.github/workflows/gitlab_mirror.yml @@ -0,0 +1,19 @@ +name: Mirror and run GitLab CI + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Mirror + trigger CI + uses: SvanBoxel/gitlab-mirror-and-ci-action@master + with: + args: "https://git.drupalcode.org/project/sensitive_content" + env: + GITLAB_HOSTNAME: "git.drupal.org" + GITLAB_USERNAME: "project_169619_bot_5ef740282e5913b658eb7eb092e3ef4d" + GITLAB_PASSWORD: ${{ secrets.GITLAB_PASSWORD }} + GITLAB_PROJECT_ID: "169619" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a18a20d --- /dev/null +++ b/composer.json @@ -0,0 +1,15 @@ +{ + "name": "drupal/sensitive_content_checker", + "description": "Sensitive Content Checker", + "type": "drupal-module", + "require": { + "drupal/context": "^4.0" + }, + + "authors": [ + { + "name": "abejithp", + "email": "abejithp@hotmail.com" + } + ] +} \ No newline at end of file diff --git a/config/install/sensitive_content_checker.settings.yml b/config/install/sensitive_content_checker.settings.yml new file mode 100644 index 0000000..2b8b0ed --- /dev/null +++ b/config/install/sensitive_content_checker.settings.yml @@ -0,0 +1,4 @@ +blocked_classes: '#block-mirador-block, #block-views-block-media-display-blocks-pdfjs' +title: 'Warning' +description: 'The content you are trying to view is sensitive.' +button_text: 'View Content' diff --git a/css/sensitive-content.css b/css/sensitive-content.css new file mode 100644 index 0000000..f920b38 --- /dev/null +++ b/css/sensitive-content.css @@ -0,0 +1,49 @@ +.sensitive-overlay{ + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + backdrop-filter: blur(10px); + z-index: 9999; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + border-color: white; + border-width: 5px; +} + +.sensitive-overlay .sensitive-container{ + background-color: white; + width: 80%; + padding: 2rem; + border-radius: 0.5rem; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + text-align: center; + gap: 1.5rem; + +} + +.sensitive-overlay h1{ + font-size: 2rem; + margin: 0; +} + +.sensitive-overlay p{ + font-size: 1.25rem; + margin: 0; +} + +.sensitive-overlay button{ + color: white; + background-color: #0a0a0a; + padding: 0.75rem 1.25rem; + border: 1px solid transparent; + border-radius: 0.25rem; + cursor: pointer; +} \ No newline at end of file diff --git a/js/sensitive-content.js b/js/sensitive-content.js new file mode 100644 index 0000000..49aab56 --- /dev/null +++ b/js/sensitive-content.js @@ -0,0 +1,46 @@ +const blockedClasses = drupalSettings.sensitive_content_checker.blockedClasses; +const titleText = drupalSettings.sensitive_content_checker.title; +const descriptionText = drupalSettings.sensitive_content_checker.description; +const buttonText = drupalSettings.sensitive_content_checker.buttonText; + +// If there are no blocked classes, exit early +if (!blockedClasses) { + console.log('No classes to block.'); +} + +// Split the classes by comma (assuming they are entered as comma-separated values) +const classesToBlock = blockedClasses.split(',').map(className => className.trim()); + +// Loop through each class and find elements to block +classesToBlock.forEach(className => { + const elements = document.querySelectorAll(className); + + elements.forEach(el => { + + const overlay = document.createElement('div'); + const container = document.createElement('div'); + + overlay.classList.add('sensitive-overlay'); + container.classList.add('sensitive-container'); + + const title = document.createElement('h1'); + const description = document.createElement('p'); + const button = document.createElement('button'); + + title.innerHTML = titleText; + description.innerHTML = descriptionText; + button.innerHTML = buttonText; + + container.appendChild(title); + container.appendChild(description); + container.appendChild(button); + + overlay.appendChild(container); + + button.addEventListener('click', function () { + overlay.style.display = 'none'; + }); + + el.appendChild(overlay); + }); +}); diff --git a/sensitive_content_checker.info.yml b/sensitive_content_checker.info.yml new file mode 100644 index 0000000..ccbe443 --- /dev/null +++ b/sensitive_content_checker.info.yml @@ -0,0 +1,12 @@ +name: 'Sensitive Content Checker' +type: module +description: 'Checks for sensitive content and displays a block or renders the content.' +package: Custom +libraries: + - sensitive_content_checker/sensitive_content_styles + - sensitive_content_checker/sensitive_content_checker +core_version_requirement: ^9 || ^10 +dependencies: + - drupal:block +config: + 'form': 'Drupal\sensitive_content_checker\Form\SensitiveContentConfigForm' diff --git a/sensitive_content_checker.libraries.yml b/sensitive_content_checker.libraries.yml new file mode 100644 index 0000000..bbc4c66 --- /dev/null +++ b/sensitive_content_checker.libraries.yml @@ -0,0 +1,12 @@ +sensitive_content_styles: + css: + theme: + css/sensitive-content.css: {} + +sensitive_content_checker: + js: + js/sensitive-content.js: {} + dependencies: + - core/drupalSettings + - core/drupal + - drupal/context \ No newline at end of file diff --git a/sensitive_content_checker.links.menu.yml b/sensitive_content_checker.links.menu.yml new file mode 100644 index 0000000..c145e2a --- /dev/null +++ b/sensitive_content_checker.links.menu.yml @@ -0,0 +1,5 @@ +sensitive_content_checker.settings: + title: 'Sensitive Content' + description: 'Configure the settings for the Sensitive Content Checker.' + parent: system.admin_config_media + route_name: sensitive_content_checker.settings \ No newline at end of file diff --git a/sensitive_content_checker.routing.yml b/sensitive_content_checker.routing.yml new file mode 100644 index 0000000..a6b817e --- /dev/null +++ b/sensitive_content_checker.routing.yml @@ -0,0 +1,7 @@ +sensitive_content_checker.settings: + path: '/admin/config/content/sensitive-content-checker' + defaults: + _form: '\Drupal\sensitive_content_checker\Form\SensitiveContentConfigForm' + _title: 'Sensitive Content Settings' + requirements: + _permission: 'administer sensitive content checker' \ No newline at end of file diff --git a/src/Form/SensitiveContentConfigForm.php b/src/Form/SensitiveContentConfigForm.php new file mode 100644 index 0000000..d1911cc --- /dev/null +++ b/src/Form/SensitiveContentConfigForm.php @@ -0,0 +1,87 @@ +config('sensitive_content_checker.settings'); + + $form['blocked_classes'] = [ + '#type' => 'textarea', + '#title' => $this->t('Sensitive Words'), + '#description' => $this->t('Enter the words to be flagged as sensitive, separated by commas.'), + '#default_value' => $config->get('blocked_classes'), + ]; + + $form['title'] = [ + '#type' => 'textfield', + '#title' => $this->t('Title'), + '#description' => $this->t('Enter the title of the block.'), + '#default_value' => $config->get('title'), + ]; + + $form['description'] = [ + '#type' => 'textfield', + '#title' => $this->t('Description'), + '#description' => $this->t('Enter the description of the block.'), + '#default_value' => $config->get('description'), + ]; + + $form['button_text'] = [ + '#type' => 'textfield', + '#title' => $this->t('Button Text'), + '#description' => $this->t('Enter the text for the button.'), + '#default_value' => $config->get('button_text'), + ]; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->config('sensitive_content_checker.settings') + ->set('blocked_classes', $form_state->getValue('blocked_classes')) + ->save(); + + $this->config('sensitive_content_checker.settings') + ->set('title', $form_state->getValue('title')) + ->save(); + + $this->config('sensitive_content_checker.settings') + ->set('description', $form_state->getValue('description')) + ->save(); + + $this->config('sensitive_content_checker.settings') + ->set('button_text', $form_state->getValue('button_text')) + ->save(); + + parent::submitForm($form, $form_state); + } + +} \ No newline at end of file diff --git a/src/Plugin/Block/SensitiveContentBlock.php b/src/Plugin/Block/SensitiveContentBlock.php new file mode 100644 index 0000000..c959913 --- /dev/null +++ b/src/Plugin/Block/SensitiveContentBlock.php @@ -0,0 +1,66 @@ +get('blocked_classes'); + $title = $configuration->get('title'); + $description = $configuration->get('description'); + $button_text = $configuration->get('button_text'); + + if (empty($blocked_classes)) { + $blocked_classes = ''; // or provide a default value + } + + if (empty($title)) { + $title = 'Sensitive Content Block'; + } + + if (empty($description)) { + $description = 'This block will check for sensitive content.'; + } + + if (empty($button_text)) { + $button_text = 'Check Content'; + } + + // Return the block with necessary JS and CSS attached. + return [ + '#markup' => '
', + '#attached' => [ + 'library' => [ + 'sensitive_content_checker/sensitive_content_styles', + 'sensitive_content_checker/sensitive_content_checker', + ], + 'drupalSettings' => [ + 'sensitive_content_checker' => [ + 'blockedClasses' => $blocked_classes, + 'title'=> $title, + 'description'=> $description, + 'buttonText'=> $button_text, + ], + ], + ], + ]; + } +}