Просмотр исходного кода

Ask user confirmation before redirecting user to the external site

Alex Trofimov 3 лет назад
Родитель
Сommit
e992cb4df3

+ 1 - 0
inc/classes/BxDolTemplate.php

@@ -676,6 +676,7 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         $this->_oTemplateFunctions = BxTemplFunctions::getInstance($this);
 
         $this->addJsOption('sys_fixed_header');
+        $this->addJsOption('sys_confirmation_before_redirect');
     }
     
     protected function initImages()

+ 34 - 0
inc/js/functions.js

@@ -968,6 +968,9 @@ function bx_time(sLang, isAutoupdate, sRootSel) {
             if ('undefined' !== typeof(Prism) && eElement.size())
                 Prism.highlightAllUnder(eElement[0]);
 
+            // process links
+            bx_redirect_for_external_links(eElement);
+
             // flickity update
             setTimeout(function () {
                 const oFlickity = eElement.find('.flickity-enabled');
@@ -1417,4 +1420,35 @@ function bx_click_area(link, event)
     }
 }
 
+function bx_redirect_for_external_links (e)
+{
+    if ('undefined' === typeof(aDolOptions.sys_confirmation_before_redirect) || 'on' !== aDolOptions.sys_confirmation_before_redirect)
+        return;
+
+    var aExclude = ['javascript:', 'about:', sUrlRoot];
+    var sPattern = 'a';
+    $(aExclude).each(function () {
+        sPattern += ':not([href^="' + this + '"])';
+    });
+    sPattern += ":is([href^='http://'],[href^='https://'])";
+
+    if ('undefined' === typeof(e))
+        e = $('document');
+
+    e.find(sPattern).each(function() {
+        $(this).on('click', function() {
+        	var $this = $(this);
+            bx_redirect_for_external_links_open($this.attr('href'));
+	        return false;
+        });
+    });
+}
+
+function bx_redirect_for_external_links_open (sHref)
+{
+    bx_confirm(_t('_sys_redirect_confirmation', sHref).replace(/\"/g, ''), function () {
+        window.open(sHref, '_blank').focus();
+    });
+}
+
 /** @} */

+ 3 - 1
install/sql/system.sql

@@ -498,6 +498,7 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_recaptcha_key_public', '_adm_stg_cpt_option_sys_recaptcha_key_public', '', 'digit', '', '', '', 20),
 (@iCategoryId, 'sys_recaptcha_key_private', '_adm_stg_cpt_option_sys_recaptcha_key_private', '', 'digit', '', '', '', 21),
 (@iCategoryId, 'sys_add_nofollow', '_adm_stg_cpt_option_sys_add_nofollow', 'on', 'checkbox', '', '', '', 30),
+(@iCategoryId, 'sys_confirmation_before_redirect', '_adm_stg_cpt_option_sys_confirmation_before_redirect', 'on', 'checkbox', '', '', '', 31),
 (@iCategoryId, 'sys_security_block_content_after_n_reports', '_adm_stg_cpt_option_sys_security_block_content_after_n_reports', '0', 'digit', '', '', '', 35),
 
 (@iCategoryId, 'sys_cf_enable', '_adm_stg_cpt_option_sys_cf_enable', '', 'checkbox', '', '', '', 40),
@@ -5996,7 +5997,8 @@ INSERT INTO `sys_preloader`(`module`, `type`, `content`, `active`, `order`) VALU
 ('system', 'js_translation', '_Are_you_sure', 1, 1),
 ('system', 'js_translation', '_error occured', 1, 2),
 ('system', 'js_translation', '_sys_loading', 1, 3),
-('system', 'js_translation', '_copyright', 1, 4);
+('system', 'js_translation', '_copyright', 1, 4),
+('system', 'js_translation', '_sys_redirect_confirmation', 1, 5);
             
 -- --------------------------------------------------------
 

+ 2 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1585,6 +1585,7 @@
     <string name="_adm_stg_cpt_option_sys_cf_enable"><![CDATA[Enable content filters]]></string>
     <string name="_adm_stg_cpt_option_sys_cf_enable_comments"><![CDATA[Enable content filters for comments]]></string>
     <string name="_adm_stg_cpt_option_sys_cf_prohibited"><![CDATA[Prohibited content]]></string>
+    <string name="_adm_stg_cpt_option_sys_confirmation_before_redirect"><![CDATA[Ask user confirmation before redirecting user to the external site]]></string>
     <string name="_adm_stg_cpt_option_sys_email_attachable_email_templates"><![CDATA[Attachable email templates list]]></string>
     <string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Enable DB cache]]></string>
     <string name="_adm_stg_cpt_option_sys_db_cache_engine"><![CDATA[DB cache engine (other than File option may require custom server setup)]]></string>
@@ -3820,4 +3821,5 @@ If it is not enabled then please consider implement this optimization, since it
     <string name="_sys_queue_push"><![CDATA[PUSH]]></string>
     <string name="_sys_queue_transcoding"><![CDATA[Video transcoding]]></string>
     <string name="_sys_queue_storage"><![CDATA[Files storage]]></string>    
+    <string name="_sys_redirect_confirmation"><![CDATA[<div class="bx-def-font-h2">You're going to a link outside this site</div><div class="bx-def-font-small">Link: {0}</div><div class="bx-def-margin-sec-top">Are you sure you want to follow this link?</div>]]></string>
 </resources>

+ 4 - 2
modules/boonex/russian/data/langs/system/ru.xml

@@ -1563,6 +1563,7 @@
     <string name="_adm_stg_cpt_option_sys_cf_enable"><![CDATA[Включить контентные фильтры]]></string>
     <string name="_adm_stg_cpt_option_sys_cf_enable_comments"><![CDATA[Включить контентные фильтры для комментариев]]></string>
     <string name="_adm_stg_cpt_option_sys_cf_prohibited"><![CDATA[Запрещенный контент]]></string>
+    <string name="_adm_stg_cpt_option_sys_confirmation_before_redirect"><![CDATA[Требовать подтверждение перед переходом по ссылке на внешний сайт]]></string>
     <string name="_adm_stg_cpt_option_sys_email_attachable_email_templates"><![CDATA[Список присоединяемых email темплейтов]]></string>
     <string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Задействовать кэш БД]]></string>
     <string name="_adm_stg_cpt_option_sys_db_cache_engine"><![CDATA[Кэш-движок для БД (значение, отличное от File, может потребовать дополнительной настройки сервера)]]></string>
@@ -3730,10 +3731,11 @@
   <string name="_sys_txt_quill_tooltip_align"><![CDATA[Выравнивание текста]]></string>
   <string name="_sys_txt_quill_tooltip_header"><![CDATA[Стиль текста]]></string>
   <string name="_sys_txt_quill_tooltip_embed"><![CDATA[Вставить ембед]]></string>
-  <string name="_sys_txt_quill_tooltip_embed_popup_header"><![CDATA[Вставить адрес дла ембеда]]></string>
-  <string name="_sys_txt_quill_tooltip_link_popup_header"><![CDATA[Вставить адрес]]></string>
+  <string name="_sys_txt_quill_tooltip_embed_popup_header"><![CDATA[Введите адрес ембеда]]></string>
+  <string name="_sys_txt_quill_tooltip_link_popup_header"><![CDATA[Введите адрес]]></string>
   <string name="_sys_queue_emails"><![CDATA[Emails]]></string>
   <string name="_sys_queue_push"><![CDATA[PUSH]]></string>
   <string name="_sys_queue_transcoding"><![CDATA[Транскодирование видео]]></string>
   <string name="_sys_queue_storage"><![CDATA[Хранилище файлов]]></string>
+  <string name="_sys_redirect_confirmation"><![CDATA[<div class="bx-def-font-h2">Вы переходите по ссылке за пределы этого сайта</div><div class="bx-def-font-small">Ссылка: {0}</div><div class="bx-def-margin-sec-top">Вы действительно хотите перейти по этой ссылке?</div>]]></string>
 </resources>

+ 4 - 0
template/embed_embedly_integration.html

@@ -25,6 +25,10 @@ $(document).ready(function () {
         $card_parent.css('height', $card.height());
     });
 
+    embedly('on', 'card.rendered', function(iframe){
+        bx_redirect_for_external_links($(iframe).contents());
+    });
+
     function bx_embedly_process_links(e) {
         $(e).find('.bx-embed-link').each(function () { 
             $(this).html('');

+ 8 - 2
template/embed_iframely_integration.html

@@ -1,11 +1,17 @@
-<script async charset="utf-8" src="//cdn.iframe.ly/embed.js?api_key=__key__&iframe=card-small"></script>
+<script async charset="utf-8" src="//cdn.iframe.ly/embed.js?api_key=__key__&card=small"></script>
 <script>
 $(document).ready(function () {
     if (typeof glOnProcessHtml === 'undefined')
         glOnProcessHtml = [];
     if (glOnProcessHtml instanceof Array) {
         glOnProcessHtml.push(function (e) {
-            window.iframely && iframely.load();
+            if (window.iframely) {
+                iframely.openHref = function (sHref) {
+                    bx_redirect_for_external_links_open (sHref);
+                    return false;
+                }
+                iframely.load();
+            }
         });
     }
 });