فهرست منبع

Ticket #4940 - Hashtags parsing: Double linking issue.

AntonLV 1 سال پیش
والد
کامیت
b8a4db73e2
1فایلهای تغییر یافته به همراه10 افزوده شده و 1 حذف شده
  1. 10 1
      inc/classes/BxDolMetatags.php

+ 10 - 1
inc/classes/BxDolMetatags.php

@@ -366,7 +366,10 @@ class BxDolMetatags extends BxDolFactory implements iBxDolFactoryObject
      */
      */
     public function keywordsAdd($iId, $s) 
     public function keywordsAdd($iId, $s) 
     {
     {
-        //--- Remove <a> tags WITH their content first.
+        /**
+         * First of all remove <a> HTML tags which don't have 'bx-mention-link' class WITH their content.
+         * It's needed because hashtags cannot be used inside links, otherwise we'll get link inside link.
+         */
         $s = preg_replace("/<a\b((?!bx-mention-link)[^>])*>(.*?)<\/a>/si", '', $s);
         $s = preg_replace("/<a\b((?!bx-mention-link)[^>])*>(.*?)<\/a>/si", '', $s);
 
 
         //--- Strip the other HTML tags.
         //--- Strip the other HTML tags.
@@ -484,6 +487,12 @@ class BxDolMetatags extends BxDolFactory implements iBxDolFactoryObject
         if (empty($a))
         if (empty($a))
             return $s;
             return $s;
 
 
+        /**
+         * Replace <a> tags, which have 'bx-mention-link' class, with their content. 
+         * It's needed to avoid link inside link after hashtags parsing.
+         */
+        $s = preg_replace('/<a\b[^>]*\bbx-mention-link\b[^>]*>(.*?)<\/a>/si', '$1', $s);
+
         foreach ($a as $sKeyword) {
         foreach ($a as $sKeyword) {
             $f = function ($a) use ($sKeyword, $iId) {
             $f = function ($a) use ($sKeyword, $iId) {
                 return $a[1] . '<a class="bx-tag" rel="tag" href="' . $this->keywordsGetHashTagUrl($sKeyword, $iId) . '">' . (bx_is_api() ? '#' . $sKeyword : '<s>#</s><b>' . $sKeyword . '</b>') . '</a>';
                 return $a[1] . '<a class="bx-tag" rel="tag" href="' . $this->keywordsGetHashTagUrl($sKeyword, $iId) . '">' . (bx_is_api() ? '#' . $sKeyword : '<s>#</s><b>' . $sKeyword . '</b>') . '</a>';