]> git.mxchange.org Git - friendica.git/blob - mod/share.php
Class file relocations
[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
8         $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
9         if((! $post_id) || (! local_user()))
10                 killme();
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 AND `item`.`uid` = %d LIMIT 1",
15
16                 intval($post_id),
17                 intval(local_user())
18         );
19         if(! DBM::is_result($r) || ($r[0]['private'] == 1))
20                 killme();
21
22         if (strpos($r[0]['body'], "[/share]") !== false) {
23                 $pos = strpos($r[0]['body'], "[share");
24                 $o = substr($r[0]['body'], $pos);
25         } else {
26                 $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
27
28                 if($r[0]['title'])
29                         $o .= '[b]'.$r[0]['title'].'[/b]'."\n";
30                 $o .= $r[0]['body'];
31                 $o.= "[/share]";
32         }
33
34         echo $o;
35         killme();
36 }
37
38 function share_header($author, $profile, $avatar, $guid, $posted, $link) {
39         $header = "[share author='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$author).
40                 "' profile='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$profile).
41                 "' avatar='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$avatar);
42
43         if ($guid)
44                 $header .= "' guid='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$guid);
45
46         if ($posted)
47                 $header .= "' posted='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$posted);
48
49         $header .= "' link='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$link)."']";
50
51         return $header;
52 }