]> git.mxchange.org Git - friendica.git/blob - mod/share.php
Ops, one more left ...
[friendica.git] / mod / share.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Database\DBA;
5 use Friendica\Model\Item;
6
7 function share_init(App $a) {
8         $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
9
10         if (!$post_id || !local_user()) {
11                 killme();
12         }
13
14         $fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar',
15                 'guid', 'created', 'plink', 'title'];
16         $item = Item::selectFirst($fields, ['id' => $post_id]);
17
18         if (!DBA::isResult($item) || $item['private'] == 1) {
19                 killme();
20         }
21
22         if (strpos($item['body'], "[/share]") !== false) {
23                 $pos = strpos($item['body'], "[share");
24                 $o = substr($item['body'], $pos);
25         } else {
26                 $o = share_header($item['author-name'], $item['author-link'], $item['author-avatar'], $item['guid'], $item['created'], $item['plink']);
27
28                 if ($item['title']) {
29                         $o .= '[b]'.$item['title'].'[/b]'."\n";
30                 }
31
32                 $o .= $item['body'];
33                 $o .= "[/share]";
34         }
35
36         echo $o;
37         killme();
38 }
39
40 /// @TODO Rewrite to handle over whole record array
41 function share_header($author, $profile, $avatar, $guid, $posted, $link) {
42         $header = "[share author='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $author).
43                 "' profile='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $profile).
44                 "' avatar='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $avatar);
45
46         if ($guid) {
47                 $header .= "' guid='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $guid);
48         }
49
50         if ($posted) {
51                 $header .= "' posted='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $posted);
52         }
53
54         $header .= "' link='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $link)."']";
55
56         return $header;
57 }