X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fconversation.php;h=0fc43fb090abca4173e1cad9d232097b0dabf354;hb=e74f186b3488dfe2eb607f21f7f3c53e8a392333;hp=94f5918744c309bb607180b9d6c65c23d5e22edf;hpb=428a22cc7628d5bf0f6c98f9912b5879d6c756dc;p=friendica.git diff --git a/include/conversation.php b/include/conversation.php index 94f5918744..0fc43fb090 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -2,9 +2,11 @@ /** * @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; @@ -13,10 +15,12 @@ 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) { @@ -34,7 +38,7 @@ function item_extract_images($body) { $img_st_close++; // make it point to AFTER the closing bracket $img_end += $img_start; - if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { + if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { // This is an embedded image $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); @@ -68,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'; @@ -86,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; @@ -184,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."".unxmlify($obj->link).""); + $obj = XML::parseString($xmlhead.$item['object']); + $links = XML::parseString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; $Blink = ""; $Bphoto = ""; @@ -208,7 +213,7 @@ function localize_item(&$item) { } if (stristr($item['verb'], ACTIVITY_POKE)) { $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); - if (! $verb) { + if (!$verb) { return; } if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) { @@ -220,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."".unxmlify($obj->link).""); + $obj = XML::parseString($xmlhead.$item['object']); + $links = XML::parseString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; $Blink = ""; @@ -295,7 +300,7 @@ 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'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag ); @@ -312,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), @@ -333,7 +338,7 @@ function localize_item(&$item) { $matches = null; if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) { foreach ($matches as $mtch) { - if (! strpos($mtch[1], 'zrl=')) { + if (!strpos($mtch[1], 'zrl=')) { $item['body'] = str_replace($mtch[0], '@[url=' . Profile::zrl($mtch[1]) . ']', $item['body']); } } @@ -343,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 @@ -368,7 +373,7 @@ function count_descendants($item) { if ($total > 0) { foreach ($item['children'] as $child) { - if (! visible_activity($child)) { + if (!visible_activity($child)) { $total --; } $total += count_descendants($child); @@ -392,7 +397,7 @@ function visible_activity($item) { } if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) { - if (! (($item['self']) && ($item['uid'] == local_user()))) { + if (!($item['self'] && ($item['uid'] == local_user()))) { return false; } } @@ -434,14 +439,13 @@ 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`, */ return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`, `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`, - `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, + `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`content-warning`, `item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`, `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`, `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, @@ -492,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); @@ -517,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) { /* @@ -577,9 +581,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { . " var profile_page = 1; "; } } 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 = '
' . "\r\n" @@ -613,37 +615,31 @@ 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) { + if (!visible_activity($item)) { + continue; + } + if ($arr_blocked) { $blocked = false; foreach ($arr_blocked as $b) { @@ -669,8 +665,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { continue; } - $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if ($item['author-link'] && (! $item['author-name'])) { + $profile_name = (strlen($item['author-name']) ? $item['author-name'] : $item['name']); + if ($item['author-link'] && !$item['author-name']) { $profile_name = $item['author-link']; } @@ -799,8 +795,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']) ? 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, @@ -862,7 +858,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { continue; } - if (! visible_activity($item)) { + if (!visible_activity($item)) { continue; } @@ -908,15 +904,23 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { * * @return array items with parents and comments */ -function community_add_items($parents) { - $max_comments = Config::get("system", "max_comments", 100); +function conversation_add_children($parents, $block_authors, $order) { + $max_comments = Config::get('system', 'max_comments', 100); + + if ($max_comments > 0) { + $limit = ' LIMIT '.intval($max_comments + 1); + } else { + $limit = ''; + } $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` = ? - ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1), + AND `item`.`parent-uri` = ? $block_sql + ORDER BY `item`.`commented` DESC" . $limit, local_user(), $parent['uri'] ); @@ -957,7 +961,7 @@ function community_add_items($parents) { } } - $items = conv_sort($items, "`commented`"); + $items = conv_sort($items, $order); return $items; } @@ -990,7 +994,7 @@ function best_link_url($item, &$sparkle, $url = '') { } } } - if (! $best_url) { + if (!$best_url) { if ($url != '') { $best_url = $url; } elseif (strlen($item['author-link'])) { @@ -1013,7 +1017,7 @@ function item_photo_menu($item) { $photos_link = ''; $posts_link = ''; - if ((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) { + if (local_user() && local_user() == $item['uid'] && $item['parent'] == $item['id'] && !$item['self']) { $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;'; } @@ -1126,9 +1130,9 @@ function builtin_activity_puller($item, &$conv_responses) { return; } - if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { + if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) { $url = $item['author-link']; - if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) { + if (local_user() && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && !$item['self'] && link_compare($item['author-link'], $item['url'])) { $url = 'redir/' . $item['contact-id']; $sparkle = ' class="sparkle" '; } else { @@ -1137,12 +1141,12 @@ function builtin_activity_puller($item, &$conv_responses) { $url = '' . htmlentities($item['author-name']) . ''; - if (! $item['thr-parent']) { + if (!$item['thr-parent']) { $item['thr-parent'] = $item['parent-uri']; } - if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l'])) - && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) { + if (!(isset($conv_responses[$mode][$item['thr-parent'] . '-l']) + && is_array($conv_responses[$mode][$item['thr-parent'] . '-l']))) { $conv_responses[$mode][$item['thr-parent'] . '-l'] = []; } @@ -1151,7 +1155,7 @@ function builtin_activity_puller($item, &$conv_responses) { continue; } - if (! isset($conv_responses[$mode][$item['thr-parent']])) { + if (!isset($conv_responses[$mode][$item['thr-parent']])) { $conv_responses[$mode][$item['thr-parent']] = 1; } else { $conv_responses[$mode][$item['thr-parent']] ++; @@ -1175,7 +1179,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 = ''; @@ -1217,7 +1221,7 @@ function format_like($cnt, array $arr, $type, $id) { } if ($total >= MAX_LIKERS) { $str = implode(', ', $arr); - $str .= L10n::t(', and %d other people', $total - MAX_LIKERS ); + $str .= L10n::t('and %d other people', $total - MAX_LIKERS ); } $likers = $str; @@ -1243,7 +1247,7 @@ function format_like($cnt, array $arr, $type, $id) { break; case 'attendmaybe': $phrase = L10n::t('%2$d people attend maybe', $spanatts, $cnt); - $explikers = L10n::t('%s anttend maybe.', $likers); + $explikers = L10n::t('%s attend maybe.', $likers); break; } @@ -1280,7 +1284,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'); @@ -1347,7 +1351,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'), @@ -1478,7 +1482,7 @@ function add_children_to_list(array $children, array &$item_list) */ function smart_flatten_conversation(array $parent) { - if (! isset($parent['children']) || count($parent['children']) == 0) { + if (!isset($parent['children']) || count($parent['children']) == 0) { return $parent; } @@ -1641,7 +1645,7 @@ function get_responses($conv_responses, $response_verbs, $ob, $item) { foreach ($response_verbs as $v) { $ret[$v] = []; $ret[$v]['count'] = defaults($conv_responses[$v], $item['uri'], ''); - $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', ''); + $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', []); $ret[$v]['self'] = defaults($conv_responses[$v], $item['uri'] . '-self', '0'); if (count($ret[$v]['list']) > MAX_LIKERS) { $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);