]> git.mxchange.org Git - friendica-addons.git/blobdiff - statusnet/statusnet.php
Support for simple shortening
[friendica-addons.git] / statusnet / statusnet.php
index 89f6f0e8875524a4fa00e8d19fd3a29e3b4dfbb6..6f4c3e20da6d2d7bf74b863fe9e55f2c81cdaff1 100644 (file)
@@ -52,8 +52,8 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
-use Friendica\Model\ItemContent;
 use Friendica\Model\Photo;
+use Friendica\Model\Post;
 use Friendica\Model\User;
 use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
@@ -402,7 +402,7 @@ function statusnet_hook_fork(App $a, array &$b)
 
        if (DI::pConfig()->get($post['uid'], 'statusnet', 'import')) {
                // Don't fork if it isn't a reply to a GNU Social post
-               if (($post['parent'] != $post['id']) && !Item::exists(['id' => $post['parent'], 'network' => Protocol::STATUSNET])) {
+               if (($post['parent'] != $post['id']) && !Post::exists(['id' => $post['parent'], 'network' => Protocol::STATUSNET])) {
                        Logger::log('No GNU Social parent found for item ' . $post['id']);
                        $b['execute'] = false;
                        return;
@@ -481,6 +481,8 @@ function statusnet_post_hook(App $a, &$b)
                        return;
        }
 
+       $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], $b['body']);
+
        $api = DI::pConfig()->get($b["uid"], 'statusnet', 'baseapi');
        $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api);
 
@@ -495,7 +497,7 @@ function statusnet_post_hook(App $a, &$b)
                }
 
                $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]];
-               $orig_post = Item::selectFirst(['author-link', 'uri'], $condition);
+               $orig_post = Post::selectFirst(['author-link', 'uri'], $condition);
                if (!DBA::isResult($orig_post)) {
                        Logger::log("statusnet_post_hook: no parent found " . $b["thr-parent"]);
                        return;
@@ -577,11 +579,11 @@ function statusnet_post_hook(App $a, &$b)
                DI::pConfig()->set($b['uid'], 'statusnet', 'max_char', $max_char);
 
                $tempfile = "";
-               $msgarr = ItemContent::getPlaintextPost($b, $max_char, true, 7);
+               $msgarr = Plaintext::getPost($b, $max_char, true, 7);
                $msg = $msgarr["text"];
 
                if (($msg == "") && isset($msgarr["title"]))
-                       $msg = Plaintext::shorten($msgarr["title"], $max_char - 50);
+                       $msg = Plaintext::shorten($msgarr["title"], $max_char - 50, $b['uid']);
 
                $image = "";
 
@@ -716,7 +718,7 @@ function statusnet_prepare_body(App $a, &$b)
                $item["plink"] = DI::baseUrl()->get() . "/display/" . $item["guid"];
 
                $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()];
-               $orig_post = Item::selectFirst(['author-link', 'uri'], $condition);
+               $orig_post = Post::selectFirst(['author-link', 'uri'], $condition);
                if (DBA::isResult($orig_post)) {
                        $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]);
 
@@ -728,7 +730,7 @@ function statusnet_prepare_body(App $a, &$b)
                        }
                }
 
-               $msgarr = ItemContent::getPlaintextPost($item, $max_char, true, 7);
+               $msgarr = Plaintext::getPost($item, $max_char, true, 7);
                $msg = $msgarr["text"];
 
                if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) {
@@ -876,7 +878,7 @@ function statusnet_fetchtimeline(App $a, $uid)
 
                                $_REQUEST["title"] = "";
 
-                               $_REQUEST["body"] = PageInfo::searchAndAppendToBody($post->text, true);
+                               $_REQUEST["body"] = $post->text;
                                if (is_string($post->place->name)) {
                                        $_REQUEST["location"] = $post->place->name;
                                }
@@ -1097,7 +1099,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
 
        $postarray['uri'] = $hostname . "::" . $content->id;
 
-       if (Item::exists(['extid' => $postarray['uri'], 'uid' => $uid])) {
+       if (Post::exists(['extid' => $postarray['uri'], 'uid' => $uid])) {
                return [];
        }
 
@@ -1106,9 +1108,9 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
        if (!empty($content->in_reply_to_status_id)) {
                $thr_parent = $hostname . "::" . $content->in_reply_to_status_id;
 
-               $item = Item::selectFirst(['uri'], ['uri' => $thr_parent, 'uid' => $uid]);
+               $item = Post::selectFirst(['uri'], ['uri' => $thr_parent, 'uid' => $uid]);
                if (!DBA::isResult($item)) {
-                       $item = Item::selectFirst(['uri'], ['extid' => $thr_parent, 'uid' => $uid]);
+                       $item = Post::selectFirst(['uri'], ['extid' => $thr_parent, 'uid' => $uid]);
                }
 
                if (DBA::isResult($item)) {