advisor.php
1 year ago
chatbot.php
11 months ago
discussions.php
11 months ago
files.php
1 year ago
gdpr.php
1 year ago
search.php
1 year ago
security.php
1 year ago
tasks.php
1 year ago
wand.php
1 year ago
gdpr.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Modules_GDPR { |
| 4 | public $core = null; |
| 5 | |
| 6 | public function __construct( $core ) { |
| 7 | $this->core = $core; |
| 8 | add_filter( 'mwai_chatbot_blocks', [ $this, 'chatbot_blocks' ], 10, 2 ); |
| 9 | } |
| 10 | |
| 11 | public function chatbot_blocks( $blocks, $args ) { |
| 12 | $gdpr_text = $this->core->get_option( 'chatbot_gdpr_text' ) ?: 'By using this chatbot, you agree to the recording and processing of your data by our website and the external services it might use (LLMs, vector databases, etc.).'; |
| 13 | $gdpr_button = $this->core->get_option( 'chatbot_gdpr_button' ) ?: '👍 I understand'; |
| 14 | $gdpr_text = esc_html( $gdpr_text ); |
| 15 | $gdpr_button = esc_html( $gdpr_button ); |
| 16 | if ( $args['step'] !== 'init' ) { |
| 17 | return $blocks; |
| 18 | } |
| 19 | $botId = $args['botId']; |
| 20 | $uniqueId = uniqid( 'mwai_gdpr_' ); |
| 21 | $blocks[] = [ |
| 22 | 'id' => $uniqueId, |
| 23 | 'type' => 'content', |
| 24 | 'data' => [ |
| 25 | 'id' => $uniqueId, |
| 26 | 'html' => '<div> |
| 27 | <p>' . $gdpr_text . '</p> |
| 28 | <form id="mwai-gdpr-form-' . $botId . '"> |
| 29 | <button type="submit">' . $gdpr_button . '</button> |
| 30 | </form> |
| 31 | </div>', |
| 32 | 'script' => ' |
| 33 | (function() { |
| 34 | let chatbot_' . $uniqueId . ' = MwaiAPI.getChatbot("' . $botId . '"); |
| 35 | if (document.cookie.indexOf("mwai_gdpr_accepted=1") !== -1) { |
| 36 | chatbot_' . $uniqueId . '.removeBlockById("' . $uniqueId . '"); |
| 37 | return; |
| 38 | } |
| 39 | chatbot_' . $uniqueId . '.lock(); |
| 40 | document.getElementById("mwai-gdpr-form-' . $botId . '").addEventListener("submit", function(event) { |
| 41 | event.preventDefault(); |
| 42 | chatbot_' . $uniqueId . '.unlock(); |
| 43 | chatbot_' . $uniqueId . '.setBlocks([]); |
| 44 | let date = new Date(); |
| 45 | date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000)); |
| 46 | document.cookie = "mwai_gdpr_accepted=1; expires=" + date.toUTCString() + "; path=/"; |
| 47 | }); |
| 48 | })(); |
| 49 | ' |
| 50 | ] |
| 51 | ]; |
| 52 | return $blocks; |
| 53 | } |
| 54 | } |
| 55 |