-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Drupal\sensitive_content_checker\Form; | ||
use Drupal\Core\Form\ConfigFormBase; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
|
||
/** | ||
* Configure sensitive content checker settings for this site. | ||
*/ | ||
class SensitiveContentConfigForm extends ConfigFormBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getEditableConfigNames() { | ||
return ['sensitive_content_checker.settings']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFormId() { | ||
return 'sensitive_content_checker_config_form'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(array $form, FormStateInterface $form_state) { | ||
$config = $this->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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Drupal\sensitive_content_checker\Plugin\Block; | ||
|
||
use Drupal\Core\Block\BlockBase; | ||
use Drupal\Core\DependencyInjection\ContainerInterface; | ||
use Drupal\sensitive_content_checker\SensitiveContentCheckerSettings; | ||
|
||
/** | ||
* Provides a block for sensitive content. | ||
* | ||
* @Block( | ||
* id = "sensitive_content_block", | ||
* admin_label = @Translation("Sensitive Content Block") | ||
* ) | ||
*/ | ||
class SensitiveContentBlock extends BlockBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function build() { | ||
// Get the blocked classes from configuration. | ||
$configuration = \Drupal::config('sensitive_content_checker.settings'); | ||
|
||
$blocked_classes = $configuration->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' => '<div id="sensitive-content-parent"></div>', | ||
'#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, | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
} |