X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fshare.php;h=f0a2170b5e90b683c9d2b2b080181e96f9f05d5d;hb=f826ce70ceb9f810a16b70d3d77b9ba2c8d9097d;hp=7eb588112b90ecf2fe00fabcfaf02364abf71f17;hpb=5d2fce417d3a6646fcfe64450a247b2163e12336;p=friendica.git diff --git a/mod/share.php b/mod/share.php index 7eb588112b..f0a2170b5e 100644 --- a/mod/share.php +++ b/mod/share.php @@ -1,57 +1,51 @@ . + * + */ use Friendica\App; -use Friendica\Database\DBM; +use Friendica\Content\Text\BBCode; +use Friendica\Core\System; +use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model\Item; +use Friendica\Model\Post; function share_init(App $a) { - $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); + $post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0); - if (!$post_id || !local_user()) { - killme(); + if (!$post_id || !DI::userSession()->getLocalUserId()) { + System::exit(); } - $fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar', - 'guid', 'created', 'plink', 'title']; - $item = Item::selectFirst(local_user(), $fields, ['id' => $post_id]); + $fields = ['private', 'body', 'uri']; + $item = Post::selectFirst($fields, ['id' => $post_id]); - if (!DBM::is_result($item) || $item['private']) { - killme(); + if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) { + System::exit(); } - if (strpos($item['body'], "[/share]") !== false) { - $pos = strpos($item['body'], "[share"); - $o = substr($item['body'], $pos); + $shared = DI::contentItem()->getSharedPost($item, ['uri']); + if (!empty($shared) && empty($shared['comment'])) { + $content = '[share]' . $shared['post']['uri'] . '[/share]'; } else { - $o = share_header($item['author-name'], $item['author-link'], $item['author-avatar'], $item['guid'], $item['created'], $item['plink']); - - if ($item['title']) { - $o .= '[b]'.$item['title'].'[/b]'."\n"; - } - - $o .= $item['body']; - $o .= "[/share]"; + $content = '[share]' . $item['uri'] . '[/share]'; } - - echo $o; - killme(); -} - -/// @TODO Rewrite to handle over whole record array -function share_header($author, $profile, $avatar, $guid, $posted, $link) { - $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author). - "' profile='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $profile). - "' avatar='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar); - - if ($guid) { - $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid); - } - - if ($posted) { - $header .= "' posted='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $posted); - } - - $header .= "' link='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']"; - - return $header; + System::httpExit($content); }