]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge branch 'master' into develop
[friendica.git] / include / text.php
index 6c09167494231dd20635681ef307ef6bb55c822c..53eae1ff33924f7118df4c5f8beb3714743628c0 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
+use Friendica\Model\Contact;
 use Friendica\Model\Event;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
@@ -151,7 +152,7 @@ function autoname($len) {
                                'nd','ng','nk','nt','rn','rp','rt'];
 
        $noend = ['bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
-                               'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh'];
+                               'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh','q'];
 
        $start = mt_rand(0,2);
        if ($start == 0) {
@@ -177,14 +178,13 @@ function autoname($len) {
        $word = substr($word,0,$len);
 
        foreach ($noend as $noe) {
-               if ((strlen($word) > 2) && (substr($word, -2) == $noe)) {
-                       $word = substr($word, 0, -1);
+               $noelen = strlen($noe);
+               if ((strlen($word) > $noelen) && (substr($word, -$noelen) == $noe)) {
+                       $word = autoname($len);
                        break;
                }
        }
-       if (substr($word, -1) == 'q') {
-               $word = substr($word, 0, -1);
-       }
+
        return $word;
 }
 
@@ -452,7 +452,7 @@ function perms2str($p) {
        if (is_array($p)) {
                $tmp = $p;
        } else {
-               $tmp = explode(',',$p);
+               $tmp = explode(',', $p);
        }
 
        if (is_array($tmp)) {
@@ -513,7 +513,7 @@ function load_view_file($s) {
                return $content;
        }
 
-       $theme = current_theme();
+       $theme = $a->getCurrentTheme();
 
        if (file_exists("$d/theme/$theme/$b")) {
                $stamp1 = microtime(true);
@@ -637,7 +637,7 @@ function logger($msg, $level = 0) {
 
        // turn off logger in install mode
        if (
-               $a->module == 'install'
+               $a->mode == App::MODE_INSTALL
                || !dba::$connected
        ) {
                return;
@@ -709,7 +709,7 @@ function dlogger($msg, $level = 0) {
 
        // turn off logger in install mode
        if (
-               $a->module == 'install'
+               $a->mode == App::MODE_INSTALL
                || !dba::$connected
        ) {
                return;
@@ -1249,7 +1249,7 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
 
        // Compile eventual content filter reasons
        $filter_reasons = [];
-       if (!$is_preview && !($item['self'] && local_user() == $item['uid'])) {
+       if (!$is_preview && public_contact() != $item['author-id']) {
                if (!empty($item['content-warning']) && (!local_user() || !PConfig::get(local_user(), 'system', 'disable_cw', false))) {
                        $filter_reasons[] = L10n::t('Content warning: %s', $item['content-warning']);
                }
@@ -1411,27 +1411,13 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
 function apply_content_filter($html, array $reasons)
 {
        if (count($reasons)) {
-               $rnd = random_string(8);
-
-               if (count($reasons) > 1) {
-                       $content_filter_html = '<ul class="content-filter-reasons">';
-                       foreach ($reasons as $reason) {
-                               $content_filter_html .= '<li>' . htmlspecialchars($reason) . '</li>' . PHP_EOL;
-                       }
-                       $content_filter_html .= '</ul>
-                               <p><button type="button" id="content-filter-wrap-' . $rnd . '" class="btn btn-default btn-small content-filter-button" onclick="openClose(\'content-filter-' . $rnd . '\');"><i class="glyphicon glyphicon-eye-open"></i> ' .
-                               L10n::t('Click to open/close') .
-                               '</button></p>';
-               } elseif (count($reasons) == 1) {
-                       $reason = array_pop($reasons);
-                       $content_filter_html .= '<p>' . htmlspecialchars($reason) . ' <button type="button" id="content-filter-wrap-' . $rnd . '" class="btn btn-default btn-xs content-filter-button" onclick="openClose(\'content-filter-' . $rnd . '\');"><i class="glyphicon glyphicon-eye-open"></i> ' .
-                               L10n::t('Click to open/close') .
-                               '</button></p>';
-               }
-
-               $content_filter_html .= '<div id="content-filter-' . $rnd . '" class="content-filter-content" style="display: none;">';
-
-               $html = $content_filter_html . $html . '</div>';
+               $tpl = get_markup_template('wall/content_filter.tpl');
+               $html = replace_macros($tpl, [
+                       '$reasons'   => $reasons,
+                       '$rnd'       => random_string(8),
+                       '$openclose' => L10n::t('Click to open/close'),
+                       '$html'      => $html
+               ]);
        }
 
        return $html;
@@ -1674,10 +1660,11 @@ function bb_translate_video($s) {
        $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
        if ($r) {
                foreach ($matches as $mtch) {
-                       if ((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
-                               $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
-                       elseif (stristr($mtch[1],'vimeo'))
-                               $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
+                       if ((stristr($mtch[1], 'youtube')) || (stristr($mtch[1], 'youtu.be'))) {
+                               $s = str_replace($mtch[0], '[youtube]' . $mtch[1] . '[/youtube]', $s);
+                       } elseif (stristr($mtch[1], 'vimeo')) {
+                               $s = str_replace($mtch[0], '[vimeo]' . $mtch[1] . '[/vimeo]', $s);
+                       }
                }
        }
        return $s;
@@ -1795,7 +1782,7 @@ function file_tag_file_query($table,$s,$type = 'file') {
 }
 
 // ex. given music,video return <music><video> or [music][video]
-function file_tag_list_to_file($list,$type = 'file') {
+function file_tag_list_to_file($list, $type = 'file') {
        $tag_list = '';
        if (strlen($list)) {
                $list_array = explode(",",$list);
@@ -1817,7 +1804,7 @@ function file_tag_list_to_file($list,$type = 'file') {
 }
 
 // ex. given <music><video>[friends], return music,video or friends
-function file_tag_file_to_list($file,$type = 'file') {
+function file_tag_file_to_list($file, $type = 'file') {
        $matches = false;
        $list = '';
        if ($type == 'file') {
@@ -1843,8 +1830,7 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
 
        if (!intval($uid)) {
                return false;
-       }
-       if ($file_old == $file_new) {
+       } elseif ($file_old == $file_new) {
                return true;
        }
 
@@ -1867,8 +1853,9 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
                $check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
 
                foreach ($check_new_tags as $tag) {
-                       if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
+                       if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) {
                                $new_tags[] = $tag;
+                       }
                }
 
                $filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
@@ -1878,8 +1865,9 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
                $check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
 
                foreach ($check_deleted_tags as $tag) {
-                       if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
+                       if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) {
                                $deleted_tags[] = $tag;
+                       }
                }
 
                foreach ($deleted_tags as $key => $tag) {
@@ -1979,6 +1967,10 @@ function undo_post_tagging($s) {
        $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism', $s, $matches, PREG_SET_ORDER);
        if ($cnt) {
                foreach ($matches as $mtch) {
+                       if (in_array($mtch[1], ['!', '@'])) {
+                               $contact = Contact::getDetailsByURL($mtch[2]);
+                               $mtch[3] = empty($contact['addr']) ? $mtch[2] : $contact['addr'];
+                       }
                        $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);
                }
        }
@@ -1989,17 +1981,22 @@ function protect_sprintf($s) {
        return str_replace('%', '%%', $s);
 }
 
-
+/// @TODO Rewrite this
 function is_a_date_arg($s) {
        $i = intval($s);
+
        if ($i > 1900) {
                $y = date('Y');
+
                if ($i <= $y + 1 && strpos($s, '-') == 4) {
-                       $m = intval(substr($s,5));
-                       if ($m > 0 && $m <= 12)
+                       $m = intval(substr($s, 5));
+
+                       if ($m > 0 && $m <= 12) {
                                return true;
+                       }
                }
        }
+
        return false;
 }
 
@@ -2017,6 +2014,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) {
                preg_match("|^" . $chr . "*|", $lines[$k], $m);
                $count = strlen($m[0]);
        }
+
        for ($k = 0; $k < count($lines); $k++) {
                $lines[$k] = preg_replace("|^" . $chr . "{" . $count . "}|", "", $lines[$k]);
        }