]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Mentioning matches (@this too) now.
authorMikael Nordfeldth <mmn@hethane.se>
Thu, 25 Feb 2016 23:08:51 +0000 (00:08 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Thu, 25 Feb 2016 23:08:51 +0000 (00:08 +0100)
lib/nickname.php
lib/util.php

index 2dd08efc3f7baeee1de2245453d3c915cde23f8b..5a5b515b4dfceec44f70c3f4b63c7e7b7285ef98 100644 (file)
@@ -76,6 +76,16 @@ class Nickname
      */
     const MAX_LEN = 64;
 
+    /**
+     * Regex with non-capturing group that matches whitespace and some
+     * characters which are allowed right before an @ or ! when mentioning
+     * other users. Like: 'This goes out to:@mmn (@chimo too) (!awwyiss).'
+     *
+     * FIXME: Make this so you can have multiple whitespace but not multiple
+     * parenthesis or something. '(((@n_n@)))' might as well be a smiley.
+     */
+    const BEFORE_MENTIONS = '(?:^|[\s\.\,\:\;\[\(]+)';
+
     /**
      * Nice simple check of whether the given string is a valid input nickname,
      * which can be normalized into an internally canonical form.
index c87b0f1bf69d9ca1cfdeef7958992f247b2a25d0..f029eb429d264ab4d77eb4947c249d21b98d5097 100644 (file)
@@ -800,7 +800,7 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
 
         // @#tag => mention of all subscriptions tagged 'tag'
 
-        preg_match_all('/(?:^|[\s\.\,\:\;]+)@#([\pL\pN_\-\.]{1,64})/',
+        preg_match_all('/'.Nickname::BEFORE_MENTIONS.'@#([\pL\pN_\-\.]{1,64})/',
                        $text, $hmatches, PREG_OFFSET_CAPTURE);
         foreach ($hmatches[1] as $hmatch) {
             $tag = common_canonical_tag($hmatch[0]);
@@ -822,7 +822,7 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
                                 'url' => $url);
         }
 
-        preg_match_all('/(?:^|[\s\.\,\:\;]+)!(' . Nickname::DISPLAY_FMT . ')/',
+        preg_match_all('/'.Nickname::BEFORE_MENTIONS.'!(' . Nickname::DISPLAY_FMT . ')/',
                        $text, $hmatches, PREG_OFFSET_CAPTURE);
         foreach ($hmatches[1] as $hmatch) {
             $nickname = Nickname::normalize($hmatch[0]);
@@ -866,7 +866,7 @@ function common_find_mentions_raw($text)
 
     $atmatches = array();
     // the regexp's "(?!\@)" makes sure it doesn't matches the single "@remote" in "@remote@server.com"
-    preg_match_all('/(?:^|\s+)@(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/',
+    preg_match_all('/'.Nickname::BEFORE_MENTIONS.'@(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/',
                    $text,
                    $atmatches,
                    PREG_OFFSET_CAPTURE);