]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Merge branch 'nightly' into 'master'
[quix0rs-gnu-social.git] / lib / util.php
index b67df923d915ceb025a4994cad0290551c89ec01..6ab5d7ae851eee9fe90dd66044396413559a05a8 100644 (file)
@@ -610,6 +610,10 @@ function common_purify($html, array $args=array())
         $cfg->set('URI.Base', $args['URI.Base']);   // if null this is like unsetting it I presume
         $cfg->set('URI.MakeAbsolute', !is_null($args['URI.Base']));   // if we have a URI base, convert relative URLs to absolute ones.
     }
+    if (common_config('cache', 'dir')) {
+        $cfg->set('Cache.SerializerPath', common_config('cache', 'dir'));
+    }
+    // if you don't want to use the default cache dir for htmlpurifier, set it specifically as $config['htmlpurifier']['Cache.SerializerPath'] = '/tmp'; or something.
     foreach (common_config('htmlpurifier') as $key=>$val) {
         $cfg->set($key, $val);
     }
@@ -768,7 +772,7 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
             }
         }
 
-        $matches = common_find_mentions_raw($text);
+        $matches = common_find_mentions_raw($text, '@');
 
         foreach ($matches as $match) {
             try {
@@ -847,9 +851,8 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
                                 'url' => $url);
         }
 
-        preg_match_all('/'.Nickname::BEFORE_MENTIONS.'!(' . Nickname::DISPLAY_FMT . ')/',
-                       $text, $hmatches, PREG_OFFSET_CAPTURE);
-        foreach ($hmatches[1] as $hmatch) {
+        $hmatches = common_find_mentions_raw($text, '!');
+        foreach ($hmatches as $hmatch) {
             $nickname = Nickname::normalize($hmatch[0]);
             $group = User_group::getForNickname($nickname, $sender);
 
@@ -879,9 +882,10 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
  * Should generally not be called directly; for use in common_find_mentions.
  *
  * @param string $text
+ * @param string $preMention Character(s) that signals a mention ('@', '!'...)
  * @return array of PCRE match arrays
  */
-function common_find_mentions_raw($text)
+function common_find_mentions_raw($text, $preMention='@')
 {
     $tmatches = array();
     preg_match_all('/^T (' . Nickname::DISPLAY_FMT . ') /',
@@ -891,7 +895,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('/'.Nickname::BEFORE_MENTIONS.'@(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/',
+    preg_match_all('/'.Nickname::BEFORE_MENTIONS.preg_quote($preMention, '/').'(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/',
                    $text,
                    $atmatches,
                    PREG_OFFSET_CAPTURE);
@@ -2060,7 +2064,7 @@ function common_bare_mime($mimetype)
     if ($semicolon = mb_strpos($mimetype, ';')) {
         $mimetype = mb_substr($mimetype, 0, $semicolon);
     }
-    return $mimetype;
+    return trim($mimetype);
 }
 
 function common_mime_type_match($type, $avail)