]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Merge pull request #4491 from tobiasd/20180224-settinghelp
[friendica.git] / include / conversation.php
index bcc0b855f5abfd0acec9e70cca724eaa3f4ef1b1..b262ee4c828b498734a7e9b7e2e96c903674318b 100644 (file)
@@ -2,20 +2,25 @@
 /**
  * @file include/conversation.php
  */
+
 use Friendica\App;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Feature;
+use Friendica\Content\Text\BBCode;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
-use Friendica\Object\Thread;
 use Friendica\Object\Post;
+use Friendica\Object\Thread;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Temporal;
+use Friendica\Util\XML;
 
-require_once "include/bbcode.php";
 require_once "include/acl_selectors.php";
 
 function item_extract_images($body) {
@@ -67,7 +72,7 @@ function item_redir_and_replace_images($body, $images, $cid) {
        $newbody = '';
 
        $cnt = 1;
-       $pos = get_bb_tag_pos($origbody, 'url', 1);
+       $pos = BBCode::getTagPosition($origbody, 'url', 0);
        while ($pos !== false && $cnt < 1000) {
 
                $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
@@ -85,7 +90,8 @@ function item_redir_and_replace_images($body, $images, $cid) {
                $newbody .= $subject;
 
                $cnt++;
-               $pos = get_bb_tag_pos($origbody, 'url', 1);
+               // Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
+               $pos = BBCode::getTagPosition($origbody, 'url', 0);
        }
        $newbody .= $origbody;
 
@@ -183,8 +189,8 @@ function localize_item(&$item) {
 
                $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
 
-               $obj = parse_xml_string($xmlhead.$item['object']);
-               $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
+               $obj = XML::parseString($xmlhead.$item['object']);
+               $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
 
                $Bname = $obj->title;
                $Blink = ""; $Bphoto = "";
@@ -202,7 +208,7 @@ function localize_item(&$item) {
                        $Bphoto = '[url=' . Profile::zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
                }
 
-               $item['body'] = sprintf( L10n::t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
+               $item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
 
        }
        if (stristr($item['verb'], ACTIVITY_POKE)) {
@@ -219,8 +225,8 @@ function localize_item(&$item) {
 
                $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
 
-               $obj = parse_xml_string($xmlhead.$item['object']);
-               $links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
+               $obj = XML::parseString($xmlhead.$item['object']);
+               $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
 
                $Bname = $obj->title;
                $Blink = "";
@@ -294,10 +300,10 @@ function localize_item(&$item) {
                }
                $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
 
-               $parsedobj = parse_xml_string($xmlhead.$item['object']);
+               $parsedobj = XML::parseString($xmlhead.$item['object']);
 
                $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
-               $item['body'] = sprintf( L10n::t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
+               $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
 
        }
        if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
@@ -311,7 +317,7 @@ function localize_item(&$item) {
 
                $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
 
-               $obj = parse_xml_string($xmlhead.$item['object']);
+               $obj = XML::parseString($xmlhead.$item['object']);
                if (strlen($obj->id)) {
                        $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                                        dbesc($obj->id),
@@ -325,7 +331,7 @@ function localize_item(&$item) {
                                $A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
                                $B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
                                $P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]';
-                               $item['body'] = sprintf( L10n::t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
+                               $item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
                        }
                }
        }
@@ -342,7 +348,7 @@ function localize_item(&$item) {
        $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
        if (preg_match($photo_pattern, $item['body'])) {
                $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5'  . '[/img][/url]';
-               $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
+               $item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
        }
 
        // add sparkle links to appropriate permalinks
@@ -433,7 +439,6 @@ These Fields are not added below (yet). They are here to for bug search.
 `item`.`forum_mode`,
 `item`.`mention`,
 `item`.`global`,
-`item`.`gcontact-id`,
 `item`.`shadow`,
 */
 
@@ -491,8 +496,7 @@ function item_condition() {
  * that are based on unique features of the calling module.
  *
  */
-function conversation(App $a, $items, $mode, $update, $preview = false) {
-       require_once 'include/bbcode.php';
+function conversation(App $a, $items, $mode, $update, $preview = false, $order = 'commented') {
        require_once 'mod/proxy.php';
 
        $ssl_state = ((local_user()) ? true : false);
@@ -516,6 +520,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
        $previewing = (($preview) ? ' preview ' : '');
 
        if ($mode === 'network') {
+               $items = conversation_add_children($items, false, $order);
                $profile_owner = local_user();
                if (!$update) {
                        /*
@@ -576,9 +581,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                                . " var profile_page = 1; </script>";
                }
        } elseif ($mode === 'community') {
-               if (!$community_readonly) {
-                       $items = community_add_items($items);
-               }
+               $items = conversation_add_children($items, true, $order);
                $profile_owner = 0;
                if (!$update) {
                        $live_update_div = '<div id="live-community"></div>' . "\r\n"
@@ -612,33 +615,23 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
        $page_template = get_markup_template("conversation.tpl");
 
        if ($items && count($items)) {
-               $community_readonly = ($mode === 'community');
-
-               // Currently behind a config value. This allows the commenting and sharing of every public item.
-               if (Config::get('system', 'comment_public')) {
-                       if ($mode === 'community') {
-                               $community_readonly = false;
-                               $writable = true;
-                       } else {
-                               $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
-                       }
+               if ($mode === 'community') {
+                       $writable = true;
                } else {
-                       $writable = false;
+                       $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
                }
 
                if (!local_user()) {
                        $writable = false;
                }
 
-               if (in_array($mode, ['network-new', 'search', 'contact-posts']) || $community_readonly) {
+               if (in_array($mode, ['network-new', 'search', 'contact-posts'])) {
 
                        /*
                         * "New Item View" on network page or search page results
                         * - just loop through the items and format them minimally for display
                         */
 
-                       /// @TODO old lost code?
-                       // $tpl = get_markup_template('search_item.tpl');
                        $tpl = 'search_item.tpl';
 
                        foreach ($items as $item) {
@@ -779,7 +772,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                                        'guid' => (($preview) ? 'Q0' : $item['guid']),
                                        'network' => $item['item_network'],
                                        'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
-                                       'linktitle' => sprintf( L10n::t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
+                                       'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
                                        'profile_url' => $profile_link,
                                        'item_photo_menu' => item_photo_menu($item),
                                        'name' => $profile_name_e,
@@ -798,8 +791,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                                        'categories' => $categories,
                                        'folders' => $folders,
                                        'text' => strip_tags($body_e),
-                                       'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
-                                       'ago' => (($item['app']) ? sprintf( L10n::t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
+                                       'localtime' => DateTimeFormat::local($item['created'], 'r'),
+                                       'ago' => (($item['app']) ? L10n::t('%s from %s', Temporal::getRelativeDate($item['created']),$item['app']) : Temporal::getRelativeDate($item['created'])),
                                        'location' => $location_e,
                                        'indent' => '',
                                        'owner_name' => $owner_name_e,
@@ -907,14 +900,16 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
  *
  * @return array items with parents and comments
  */
-function community_add_items($parents) {
+function conversation_add_children($parents, $block_authors, $order) {
        $max_comments = Config::get("system", "max_comments", 100);
 
        $items = [];
 
+       $block_sql = $block_authors ? "AND NOT `author`.`hidden` AND NOT `author`.`blocked`" : "";
+
        foreach ($parents AS $parent) {
                $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
-                       AND `item`.`parent-uri` = ?
+                       AND `item`.`parent-uri` = ? $block_sql
                        ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
                        local_user(),
                        $parent['uri']
@@ -956,7 +951,7 @@ function community_add_items($parents) {
                }
        }
 
-       $items = conv_sort($items, "`commented`");
+       $items = conv_sort($items, $order);
 
        return $items;
 }
@@ -1174,7 +1169,7 @@ function builtin_activity_puller($item, &$conv_responses) {
  * @param array $arr = array of pre-linked names of likers/dislikers
  * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
  * @param int $id  = item id
- * @return formatted text
+ * @return string formatted text
  */
 function format_like($cnt, array $arr, $type, $id) {
        $o = '';
@@ -1187,19 +1182,19 @@ function format_like($cnt, array $arr, $type, $id) {
                // list which show all likers
                switch ($type) {
                        case 'like' :
-                               $phrase = sprintf( L10n::t('%s likes this.'), $likers);
+                               $phrase = L10n::t('%s likes this.', $likers);
                                break;
                        case 'dislike' :
-                               $phrase = sprintf( L10n::t('%s doesn\'t like this.'), $likers);
+                               $phrase = L10n::t('%s doesn\'t like this.', $likers);
                                break;
                        case 'attendyes' :
-                               $phrase = sprintf( L10n::t('%s attends.'), $likers);
+                               $phrase = L10n::t('%s attends.', $likers);
                                break;
                        case 'attendno' :
-                               $phrase = sprintf( L10n::t('%s doesn\'t attend.'), $likers);
+                               $phrase = L10n::t('%s doesn\'t attend.', $likers);
                                break;
                        case 'attendmaybe' :
-                               $phrase = sprintf( L10n::t('%s attends maybe.'), $likers);
+                               $phrase = L10n::t('%s attends maybe.', $likers);
                                break;
                }
        }
@@ -1216,7 +1211,7 @@ function format_like($cnt, array $arr, $type, $id) {
                }
                if ($total >= MAX_LIKERS) {
                        $str = implode(', ', $arr);
-                       $str .= sprintf( L10n::t(', and %d other people'), $total - MAX_LIKERS );
+                       $str .= L10n::t('and %d other people', $total - MAX_LIKERS );
                }
 
                $likers = $str;
@@ -1225,24 +1220,24 @@ function format_like($cnt, array $arr, $type, $id) {
 
                switch ($type) {
                        case 'like':
-                               $phrase = sprintf( L10n::t('<span  %1$s>%2$d people</span> like this'), $spanatts, $cnt);
-                               $explikers = sprintf( L10n::t('%s like this.'), $likers);
+                               $phrase = L10n::t('<span  %1$s>%2$d people</span> like this', $spanatts, $cnt);
+                               $explikers = L10n::t('%s like this.', $likers);
                                break;
                        case 'dislike':
-                               $phrase = sprintf( L10n::t('<span  %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
-                               $explikers = sprintf( L10n::t('%s don\'t like this.'), $likers);
+                               $phrase = L10n::t('<span  %1$s>%2$d people</span> don\'t like this', $spanatts, $cnt);
+                               $explikers = L10n::t('%s don\'t like this.', $likers);
                                break;
                        case 'attendyes':
-                               $phrase = sprintf( L10n::t('<span  %1$s>%2$d people</span> attend'), $spanatts, $cnt);
-                               $explikers = sprintf( L10n::t('%s attend.'), $likers);
+                               $phrase = L10n::t('<span  %1$s>%2$d people</span> attend', $spanatts, $cnt);
+                               $explikers = L10n::t('%s attend.', $likers);
                                break;
                        case 'attendno':
-                               $phrase = sprintf( L10n::t('<span  %1$s>%2$d people</span> don\'t attend'), $spanatts, $cnt);
-                               $explikers = sprintf( L10n::t('%s don\'t attend.'), $likers);
+                               $phrase = L10n::t('<span  %1$s>%2$d people</span> don\'t attend', $spanatts, $cnt);
+                               $explikers = L10n::t('%s don\'t attend.', $likers);
                                break;
                        case 'attendmaybe':
-                               $phrase = sprintf( L10n::t('<span  %1$s>%2$d people</span> attend maybe'), $spanatts, $cnt);
-                               $explikers = sprintf( L10n::t('%s anttend maybe.'), $likers);
+                               $phrase = L10n::t('<span  %1$s>%2$d people</span> attend maybe', $spanatts, $cnt);
+                               $explikers = L10n::t('%s anttend maybe.', $likers);
                                break;
                }
 
@@ -1279,7 +1274,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
                '$term'      => L10n::t('Tag term:'),
                '$fileas'    => L10n::t('Save to Folder:'),
                '$whereareu' => L10n::t('Where are you right now?'),
-               '$delitems'  => L10n::t('Delete item(s)?')
+               '$delitems'  => L10n::t("Delete item\x28s\x29?")
        ]);
 
        $tpl = get_markup_template('jot-end.tpl');
@@ -1346,7 +1341,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
                '$title'        => defaults($x, 'title', ''),
                '$placeholdertitle' => L10n::t('Set title'),
                '$category'     => defaults($x, 'category', ''),
-               '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? L10n::t('Categories (comma-separated list)') : '',
+               '$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? L10n::t("Categories \x28comma-separated list\x29") : '',
                '$wait'         => L10n::t('Please wait'),
                '$permset'      => L10n::t('Permission settings'),
                '$shortpermset' => L10n::t('permissions'),
@@ -1668,19 +1663,19 @@ function get_response_button_text($v, $count)
 {
        switch ($v) {
                case 'like':
-                       $return = tt('Like', 'Likes', $count);
+                       $return = L10n::tt('Like', 'Likes', $count);
                        break;
                case 'dislike':
-                       $return = tt('Dislike', 'Dislikes', $count);
+                       $return = L10n::tt('Dislike', 'Dislikes', $count);
                        break;
                case 'attendyes':
-                       $return = tt('Attending', 'Attending', $count);
+                       $return = L10n::tt('Attending', 'Attending', $count);
                        break;
                case 'attendno':
-                       $return = tt('Not Attending', 'Not Attending', $count);
+                       $return = L10n::tt('Not Attending', 'Not Attending', $count);
                        break;
                case 'attendmaybe':
-                       $return = tt('Undecided', 'Undecided', $count);
+                       $return = L10n::tt('Undecided', 'Undecided', $count);
                        break;
        }