]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge pull request #2989 from tobiasd/20161203-de
[friendica.git] / include / text.php
index 1b3050f5fe8b275241b3cd270ffa58a9616a0745..b57016456a8c366485035527f635a81906059d6b 100644 (file)
@@ -12,7 +12,7 @@ if(! function_exists('replace_macros')) {
  * This is our template processor
  *
  * @param string|FriendicaSmarty $s the string requiring macro substitution,
- *                                                                     or an instance of FriendicaSmarty
+ *                             or an instance of FriendicaSmarty
  * @param array $r key value pairs (search => replace)
  * @return string substituted string
  */
@@ -707,9 +707,6 @@ function logger($msg, $level = 0) {
        if (
                $a->module == 'install'
                || ! ($db && $db->connected)
-               || ! $debugging
-               || ! $logfile
-               || $level > $loglevel
        ) {
                return;
        }
@@ -718,6 +715,14 @@ function logger($msg, $level = 0) {
        $logfile   = get_config('system','logfile');
        $loglevel = intval(get_config('system','loglevel'));
 
+       if (
+               ! $debugging
+               || ! $logfile
+               || $level > $loglevel
+       ) {
+               return;
+       }
+
        if (count($LOGGER_LEVELS) == 0) {
                foreach (get_defined_constants() as $k => $v) {
                        if (substr($k, 0, 7) == "LOGGER_") {
@@ -764,71 +769,75 @@ function activity_match($haystack,$needle) {
 }}
 
 
-if(! function_exists('get_tags')) {
 /**
- * Pull out all #hashtags and @person tags from $s;
+ * @brief Pull out all #hashtags and @person tags from $string.
+ * 
  * We also get @person@domain.com - which would make
  * the regex quite complicated as tags can also
  * end a sentence. So we'll run through our results
  * and strip the period from any tags which end with one.
  * Returns array of tags found, or empty array.
  *
- * @param string $s
- * @return array
+ * @param string $string Post content
+ * @return array List of tag and person names
  */
-function get_tags($s) {
+function get_tags($string) {
        $ret = array();
 
        // Convert hashtag links to hashtags
-       $s = preg_replace("/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism", "#$2", $s);
+       $string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2', $string);
 
        // ignore anything in a code block
-       $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s);
+       $string = preg_replace('/\[code\](.*?)\[\/code\]/sm', '', $string);
 
        // Force line feeds at bbtags
-       $s = str_replace(array("[", "]"), array("\n[", "]\n"), $s);
+       $string = str_replace(array('[', ']'), array("\n[", "]\n"), $string);
 
        // ignore anything in a bbtag
-       $s = preg_replace('/\[(.*?)\]/sm','',$s);
+       $string = preg_replace('/\[(.*?)\]/sm', '', $string);
 
        // Match full names against @tags including the space between first and last
        // We will look these up afterward to see if they are full names or not recognisable.
 
-       if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/',$s,$match)) {
-               foreach($match[1] as $mtch) {
-                       if(strstr($mtch,"]")) {
+       if (preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/', $string, $matches)) {
+               foreach ($matches[1] as $match) {
+                       if (strstr($match, ']')) {
                                // we might be inside a bbcode color tag - leave it alone
                                continue;
                        }
-                       if(substr($mtch,-1,1) === '.')
-                               $ret[] = substr($mtch,0,-1);
-                       else
-                               $ret[] = $mtch;
+                       if (substr($match, -1, 1) === '.') {
+                               $ret[] = substr($match, 0, -1);
+                       } else {
+                               $ret[] = $match;
+                       }
                }
        }
 
        // Otherwise pull out single word tags. These can be @nickname, @first_last
        // and #hash tags.
 
-       if(preg_match_all('/([!#@][^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/',$s,$match)) {
-               foreach($match[1] as $mtch) {
-                       if(strstr($mtch,"]")) {
+       if (preg_match_all('/([!#@][^\^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/', $string, $matches)) {
+               foreach($matches[1] as $match) {
+                       if (strstr($match, ']')) {
                                // we might be inside a bbcode color tag - leave it alone
                                continue;
                        }
-                       if(substr($mtch,-1,1) === '.')
-                               $mtch = substr($mtch,0,-1);
+                       if (substr($match, -1, 1) === '.') {
+                               $match = substr($match,0,-1);
+                       }
                        // ignore strictly numeric tags like #1
-                       if((strpos($mtch,'#') === 0) && ctype_digit(substr($mtch,1)))
+                       if ((strpos($match, '#') === 0) && ctype_digit(substr($match, 1))) {
                                continue;
+                       }
                        // try not to catch url fragments
-                       if(strpos($s,$mtch) && preg_match('/[a-zA-z0-9\/]/',substr($s,strpos($s,$mtch)-1,1)))
+                       if (strpos($string, $match) && preg_match('/[a-zA-z0-9\/]/', substr($string, strpos($string, $match) - 1, 1))) {
                                continue;
-                       $ret[] = $mtch;
+                       }
+                       $ret[] = $match;
                }
        }
        return $ret;
-}}
+}
 
 
 //
@@ -865,8 +874,8 @@ function contact_block() {
        if((! is_array($a->profile)) || ($a->profile['hide-friends']))
                return $o;
        $r = q("SELECT COUNT(*) AS `total` FROM `contact`
-                       WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0
-                               AND `hidden` = 0 AND `archive` = 0
+                       WHERE `uid` = %d AND NOT `self` AND NOT `blocked`
+                               AND NOT `hidden` AND NOT `archive`
                                AND `network` IN ('%s', '%s', '%s')",
                        intval($a->profile['uid']),
                        dbesc(NETWORK_DFRN),
@@ -883,7 +892,7 @@ function contact_block() {
        } else {
                // Splitting the query in two parts makes it much faster
                $r = q("SELECT `id` FROM `contact`
-                               WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending`
+                               WHERE `uid` = %d AND NOT `self` AND NOT `blocked`
                                        AND NOT `hidden` AND NOT `archive`
                                AND `network` IN ('%s', '%s', '%s') ORDER BY RAND() LIMIT %d",
                                intval($a->profile['uid']),