]> git.mxchange.org Git - friendica.git/blob - mod/share.php
Merge pull request #5037 from Quix0r/rewrites/curly-braces-is-result-usage-001
[friendica.git] / mod / share.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Database\DBM;
5
6 function share_init(App $a) {
7         $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
8
9         if (!$post_id || !local_user()) {
10                 killme();
11         }
12
13         $r = q("SELECT item.*, contact.network FROM `item`
14                 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
15                 WHERE `item`.`id` = %d LIMIT 1",
16                 intval($post_id)
17         );
18
19         if (!DBM::is_result($r) || ($r[0]['private'] == 1)) {
20                 killme();
21         }
22
23         if (strpos($r[0]['body'], "[/share]") !== false) {
24                 $pos = strpos($r[0]['body'], "[share");
25                 $o = substr($r[0]['body'], $pos);
26         } else {
27                 $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
28
29                 if ($r[0]['title']) {
30                         $o .= '[b]'.$r[0]['title'].'[/b]'."\n";
31                 }
32
33                 $o .= $r[0]['body'];
34                 $o .= "[/share]";
35         }
36
37         echo $o;
38         killme();
39 }
40
41 /// @TODO Rewrite to handle over whole record array
42 function share_header($author, $profile, $avatar, $guid, $posted, $link) {
43         $header = "[share author='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $author).
44                 "' profile='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $profile).
45                 "' avatar='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $avatar);
46
47         if ($guid) {
48                 $header .= "' guid='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $guid);
49         }
50
51         if ($posted) {
52                 $header .= "' posted='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $posted);
53         }
54
55         $header .= "' link='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $link)."']";
56
57         return $header;
58 }