]> git.mxchange.org Git - friendica.git/blob - mod/share.php
added spaces + some curly braces + some usage of dbm::is_result()
[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         if (!$post_id || !local_user()) {
9                 killme();
10         }
11
12         $r = q("SELECT item.*, contact.network FROM `item`
13                 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
14                 WHERE `item`.`id` = %d LIMIT 1",
15                 intval($post_id)
16         );
17         if (!DBM::is_result($r) || ($r[0]['private'] == 1)) {
18                 killme();
19         }
20         if (strpos($r[0]['body'], "[/share]") !== false) {
21                 $pos = strpos($r[0]['body'], "[share");
22                 $o = substr($r[0]['body'], $pos);
23         } else {
24                 $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
25
26                 if ($r[0]['title']) {
27                         $o .= '[b]'.$r[0]['title'].'[/b]'."\n";
28                 }
29                 $o .= $r[0]['body'];
30                 $o .= "[/share]";
31         }
32
33         echo $o;
34         killme();
35 }
36
37 function share_header($author, $profile, $avatar, $guid, $posted, $link) {
38         $header = "[share author='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $author).
39                 "' profile='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $profile).
40                 "' avatar='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $avatar);
41
42         if ($guid) {
43                 $header .= "' guid='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $guid);
44         }
45         if ($posted) {
46                 $header .= "' posted='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $posted);
47         }
48         $header .= "' link='" . str_replace(["'", "[", "]"], ["&#x27;", "&#x5B;", "&#x5D;"], $link)."']";
49
50         return $header;
51 }