]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Merge pull request #4491 from tobiasd/20180224-settinghelp
[friendica.git] / include / conversation.php
index d312c2d9e24886c05f6a78d2f1850af505d00597..b262ee4c828b498734a7e9b7e2e96c903674318b 100644 (file)
@@ -6,6 +6,7 @@
 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;
@@ -15,11 +16,11 @@ use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
 use Friendica\Object\Post;
-use Friendica\Util\XML;
 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) {
@@ -71,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';
@@ -89,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;
 
@@ -346,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
@@ -437,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`,
 */
 
@@ -495,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);
@@ -520,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) {
                        /*
@@ -580,7 +581,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                                . " var profile_page = 1; </script>";
                }
        } elseif ($mode === 'community') {
-               $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"
@@ -791,7 +792,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                                        'folders' => $folders,
                                        'text' => strip_tags($body_e),
                                        'localtime' => DateTimeFormat::local($item['created'], 'r'),
-                                       'ago' => (($item['app']) ? L10n::t('%s from %s', relative_date($item['created']),$item['app']) : relative_date($item['created'])),
+                                       '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,
@@ -899,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']
@@ -948,7 +951,7 @@ function community_add_items($parents) {
                }
        }
 
-       $items = conv_sort($items, "`commented`");
+       $items = conv_sort($items, $order);
 
        return $items;
 }
@@ -1166,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 = '';