]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #3800 from annando/better-callstack
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Wed, 18 Oct 2017 06:31:14 +0000 (08:31 +0200)
committerGitHub <noreply@github.com>
Wed, 18 Oct 2017 06:31:14 +0000 (08:31 +0200)
Improve the way the callstack is built

README.translate.md
doc/translations.md
include/dfrn.php
include/feed.php
mod/display.php
mod/notes.php
view/templates/display-head.tpl

index 696dec10b12ddb30aa6128d3ef7c89f9f664df90..83c24e05424022ef7103b9f765efb51ee511a601 100644 (file)
@@ -56,6 +56,9 @@ Assuming you want to convert the German localization which is placed in view/lan
        repository, push it to your fork of the friendica repository at github and
        issue a pull request for that commit.
 
+You should translate the PO files at Transifex.
+Otherwise your work might get lost, when the translation from Transifex is included to the Friendica repository after it was updated there.
+
 Utilities
 ---------
 
index c14b685be113578efdf712826d848c84e5c8058a..d6b48d9eac3579b3cd9aaf3169ae242a82e87964 100644 (file)
@@ -58,6 +58,9 @@ Assuming you want to convert the German localization which is placed in view/lan
        repository, push it to your fork of the friendica repository at github and
        issue a pull request for that commit.
 
+You should translate the PO files at Transifex.
+Otherwise your work might get lost, when the translation from Transifex is included to the Friendica repository after it was updated there.
+
 Utilities
 ---------
 
index eb0f9fbb4ee0d0fd7513095f053d31f83e8f246b..55c51cb0118a69fd482b2f61c13a9046656647c0 100644 (file)
@@ -289,10 +289,17 @@ class dfrn {
         * @brief Generate an atom entry for a given item id
         *
         * @param int $item_id The item id
+        * @param boolean $conversation Show the conversation. If false show the single post.
         *
         * @return string DFRN feed entry
         */
-       public static function itemFeed($item_id) {
+       public static function itemFeed($item_id, $conversation = false) {
+               if ($conversation) {
+                       $condition = '`item`.`parent`';
+               } else {
+                       $condition = '`item`.`id`';
+               }
+
                $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
                        `contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
                        `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
@@ -302,8 +309,9 @@ class dfrn {
                        STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                                AND (NOT `contact`.`blocked` OR `contact`.`pending`)
                        LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
-                       WHERE `item`.`id` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
+                       WHERE %s = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
                        AND NOT `item`.`private`",
+                       $condition,
                        intval($item_id)
                );
 
@@ -311,6 +319,7 @@ class dfrn {
                        killme();
                }
 
+               $items = $r;
                $item = $r[0];
 
                $r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
@@ -327,12 +336,31 @@ class dfrn {
 
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
+               $type = 'html';
 
-               $alternatelink = $owner['url'];
+               if ($conversation) {
+                       $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
+                       $doc->appendChild($root);
 
-               $type = 'html';
+                       $root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
+                       $root->setAttribute("xmlns:at", NAMESPACE_TOMB);
+                       $root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
+                       $root->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
+                       $root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
+                       $root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
+                       $root->setAttribute("xmlns:poco", NAMESPACE_POCO);
+                       $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
+                       $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
+
+                       //$root = self::add_header($doc, $owner, "dfrn:owner", "", false);
 
-               $root = self::entry($doc, $type, $item, $owner, true, 0, true);
+                       foreach ($items as $item) {
+                               $entry = self::entry($doc, $type, $item, $owner, true, 0);
+                               $root->appendChild($entry);
+                       }
+               } else {
+                       $root = self::entry($doc, $type, $item, $owner, true, 0, true);
+               }
 
                $atom = trim($doc->saveXML());
                return $atom;
index 1aab26e1dfe7d503bf3ddcdea17af54b5073edf1..fb97c14ba126aa1875d1202df05a5caa8aad64e7 100644 (file)
@@ -319,6 +319,30 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
                        $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'"[/attach]';
                }
 
+               $body = trim($xpath->evaluate('atom:content/text()', $entry)->item(0)->nodeValue);
+
+               if ($body == "") {
+                       $body = trim($xpath->evaluate('content:encoded/text()', $entry)->item(0)->nodeValue);
+               }
+               if ($body == "") {
+                       $body = trim($xpath->evaluate('description/text()', $entry)->item(0)->nodeValue);
+               }
+               if ($body == "") {
+                       $body = trim($xpath->evaluate('atom:summary/text()', $entry)->item(0)->nodeValue);
+               }
+
+               // remove the content of the title if it is identically to the body
+               // This helps with auto generated titles e.g. from tumblr
+               if (title_is_body($item["title"], $body)) {
+                       $item["title"] = "";
+               }
+               $item["body"] = html2bbcode($body, $basepath);
+
+               if (($item["body"] == '') && ($item["title"] != '')) {
+                       $item["body"] = $item["title"];
+                       $item["title"] = '';
+               }
+
                if ($contact["fetch_further_information"]) {
                        $preview = "";
 
@@ -329,36 +353,33 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
                                }
                        }
 
-                       $item["body"] = $item["title"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
-                       $item["tag"] = add_page_keywords($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
-                       $item["title"] = "";
-                       $item["object-type"] = ACTIVITY_OBJ_BOOKMARK;
-                       unset($item["attach"]);
-               } else {
-                       $body = trim($xpath->evaluate('atom:content/text()', $entry)->item(0)->nodeValue);
+                       // Remove a possible link to the item itself
+                       $item["body"] = str_replace($item["plink"], '', $item["body"]);
+                       $item["body"] = preg_replace('/\[url\=\](\w+.*?)\[\/url\]/i', '', $item["body"]);
 
-                       if ($body == "") {
-                               $body = trim($xpath->evaluate('content:encoded/text()', $entry)->item(0)->nodeValue);
-                       }
-                       if ($body == "") {
-                               $body = trim($xpath->evaluate('description/text()', $entry)->item(0)->nodeValue);
-                       }
-                       if ($body == "") {
-                               $body = trim($xpath->evaluate('atom:summary/text()', $entry)->item(0)->nodeValue);
+                       // Replace the content when the title is longer than the body
+                       $replace = (strlen($item["title"]) > strlen($item["body"]));
+
+                       // Replace it, when there is an image in the body
+                       if (strstr($item["body"], '[/img]')) {
+                               $replace = true;
                        }
 
-                       // remove the content of the title if it is identically to the body
-                       // This helps with auto generated titles e.g. from tumblr
-                       if (title_is_body($item["title"], $body)) {
-                               $item["title"] = "";
+                       // Replace it, when there is a link in the body
+                       if (strstr($item["body"], '[/url]')) {
+                               $replace = true;
                        }
-                       $item["body"] = html2bbcode($body, $basepath);
 
-                       if (($item["body"] == '') && ($item["title"] != '')) {
+                       if ($replace) {
                                $item["body"] = $item["title"];
-                               $item["title"] = '';
                        }
-
+                       // We always strip the title since it will be added in the page information
+                       $item["title"] = "";
+                       $item["body"] = $item["body"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
+                       $item["tag"] = add_page_keywords($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
+                       $item["object-type"] = ACTIVITY_OBJ_BOOKMARK;
+                       unset($item["attach"]);
+               } else {
                        if (!strstr($item["body"], '[url') && ($item['plink'] != '')) {
                                $item["body"] .= "[hr][url]".$item['plink']."[/url]";
                        }
index 1ecff36182197a0e4b9392638c48e86912cbb924..bdb32e9de9a8c462c4c658a09b343d004340fe7d 100644 (file)
@@ -17,7 +17,14 @@ function display_init(App $a) {
        if ($a->argc == 3) {
                if (substr($a->argv[2], -5) == '.atom') {
                        $item_id = substr($a->argv[2], 0, -5);
-                       displayShowFeed($item_id);
+                       displayShowFeed($item_id, false);
+               }
+       }
+
+       if ($a->argc == 4) {
+               if ($a->argv[3] == 'conversation.atom') {
+                       $item_id = $a->argv[2];
+                       displayShowFeed($item_id, true);
                }
        }
 
@@ -66,7 +73,7 @@ function display_init(App $a) {
 
                        if (strstr($_SERVER['HTTP_ACCEPT'], 'application/atom+xml')) {
                                logger('Directly serving XML for id '.$r["id"], LOGGER_DEBUG);
-                               displayShowFeed($r["id"]);
+                               displayShowFeed($r["id"], false);
                        }
 
                        if ($r["id"] != $r["parent"]) {
@@ -219,17 +226,18 @@ function display_content(App $a, $update = 0) {
                        $nick = "";
 
                        if (local_user()) {
-                               $r = dba::fetch_first("SELECT `id` FROM `item`
+                               $r = dba::fetch_first("SELECT `id`, `parent` FROM `item`
                                        WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
                                                AND `guid` = ? AND `uid` = ?", $a->argv[1], local_user());
                                if (dbm::is_result($r)) {
                                        $item_id = $r["id"];
+                                       $item_parent = $r["parent"];
                                        $nick = $a->user["nickname"];
                                }
                        }
 
                        if ($nick == "") {
-                               $r = dba::fetch_first("SELECT `user`.`nickname`, `item`.`id` FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
+                               $r = dba::fetch_first("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent` FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
                                        WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
                                                AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
                                                AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
@@ -237,11 +245,12 @@ function display_content(App $a, $update = 0) {
                                                AND `item`.`guid` = ?", $a->argv[1]);
                                if (dbm::is_result($r)) {
                                        $item_id = $r["id"];
+                                       $item_parent = $r["parent"];
                                        $nick = $r["nickname"];
                                }
                        }
                        if ($nick == "") {
-                               $r = dba::fetch_first("SELECT `item`.`id` FROM `item`
+                               $r = dba::fetch_first("SELECT `item`.`id`, `item`.`parent` FROM `item`
                                        WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
                                                AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
                                                AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
@@ -249,15 +258,17 @@ function display_content(App $a, $update = 0) {
                                                AND `item`.`guid` = ?", $a->argv[1]);
                                if (dbm::is_result($r)) {
                                        $item_id = $r["id"];
+                                       $item_parent = $r["parent"];
                                }
                        }
                }
        }
 
        if ($item_id && !is_numeric($item_id)) {
-               $r = dba::select('item', array('id'), array('uri' => $item_id, 'uid' => $a->profile['uid']), array('limit' => 1));
+               $r = dba::select('item', array('id', 'parent'), array('uri' => $item_id, 'uid' => $a->profile['uid']), array('limit' => 1));
                if (dbm::is_result($r)) {
                        $item_id = $r["id"];
+                       $item_parent = $r["parent"];
                } else {
                        $item_id = false;
                }
@@ -273,12 +284,15 @@ function display_content(App $a, $update = 0) {
        $is_public = dba::exists('item', array('id' => $item_id, 'private' => false));
        if ($is_public) {
                $alternate = System::baseUrl().'/display/'.$nick.'/'.$item_id.'.atom';
+               $conversation = System::baseUrl().'/display/'.$nick.'/'.$item_parent.'/conversation.atom';
        } else {
                $alternate = '';
+               $conversation = '';
        }
 
        $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'),
-                               array('$alternate' => $alternate));
+                               array('$alternate' => $alternate,
+                                       '$conversation' => $conversation));
 
        $groups = array();
 
@@ -476,8 +490,8 @@ function display_content(App $a, $update = 0) {
        return $o;
 }
 
-function displayShowFeed($item_id) {
-       $xml = dfrn::itemFeed($item_id);
+function displayShowFeed($item_id, $conversation) {
+       $xml = dfrn::itemFeed($item_id, $conversation);
        if ($xml == '') {
                http_status_exit(500);
        }
index 835627586cada10d58b75113a1783e4a852f4386..d1810604ca514bd8ddbcf292e061701017dbf2e5 100644 (file)
@@ -73,7 +73,7 @@ function notes_content(App $a, $update = false) {
 
        // default permissions - anonymous user
 
-       $sql_extra = " AND `allow_cid` = '<" . $a->contact['id'] . ">' ";
+       $sql_extra = " AND `item`.`allow_cid` = '<" . $a->contact['id'] . ">' ";
 
        $r = q("SELECT COUNT(*) AS `total`
                FROM `item` %s
index dda816214624576873eadf3d00389cc0f9ffd579..b0f0a828e717e49fce08d9ff6f049de7dec66b28 100644 (file)
@@ -1,4 +1,9 @@
-{{if $alternate}}<link href='{{$alternate}}' rel='alternate' type='application/atom+xml'>{{/if}}
+{{if $alternate}}
+<link href='{{$alternate}}' rel='alternate' type='application/atom+xml'>
+{{/if}}
+{{if $conversation}}
+<link href='{{$conversation}}' rel='conversation' type='application/atom+xml'>
+{{/if}}
 <script>
 $(document).ready(function() {
        $(".comment-edit-wrapper textarea").editor_autocomplete(baseurl+"/acl");