]> git.mxchange.org Git - friendica.git/blob - mod/share.php
Merge remote-tracking branch 'upstream/develop' into 1702-detect-server
[friendica.git] / mod / share.php
1 <?php
2 function share_init(App $a) {
3
4         $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
5         if((! $post_id) || (! local_user()))
6                 killme();
7
8         $r = q("SELECT item.*, contact.network FROM `item`
9                 inner join contact on `item`.`contact-id` = `contact`.`id`
10                 WHERE `item`.`id` = %d AND `item`.`uid` = %d LIMIT 1",
11
12                 intval($post_id),
13                 intval(local_user())
14         );
15         if(! dbm::is_result($r) || ($r[0]['private'] == 1))
16                 killme();
17
18         if (strpos($r[0]['body'], "[/share]") !== false) {
19                 $pos = strpos($r[0]['body'], "[share");
20                 $o = substr($r[0]['body'], $pos);
21         } else {
22                 $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
23
24                 if($r[0]['title'])
25                         $o .= '[b]'.$r[0]['title'].'[/b]'."\n";
26                 $o .= $r[0]['body'];
27                 $o.= "[/share]";
28         }
29
30         echo $o;
31         killme();
32 }
33
34 function share_header($author, $profile, $avatar, $guid, $posted, $link) {
35         $header = "[share author='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$author).
36                 "' profile='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$profile).
37                 "' avatar='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$avatar);
38
39         if ($guid)
40                 $header .= "' guid='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$guid);
41
42         if ($posted)
43                 $header .= "' posted='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$posted);
44
45         $header .= "' link='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$link)."']";
46
47         return $header;
48 }