]> git.mxchange.org Git - friendica.git/blob - mod/share.php
f3a221eb8ef4c985f9b8ad9e86a523efb8a4fa61
[friendica.git] / mod / share.php
1 <?php
2
3 if(! function_exists('share_init')) {
4 function share_init(&$a) {
5
6         $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
7         if((! $post_id) || (! local_user()))
8                 killme();
9
10         $r = q("SELECT item.*, contact.network FROM `item`
11                 inner join contact on `item`.`contact-id` = `contact`.`id`
12                 WHERE `item`.`id` = %d AND `item`.`uid` = %d LIMIT 1",
13
14                 intval($post_id),
15                 intval(local_user())
16         );
17         if(! count($r) || ($r[0]['private'] == 1))
18                 killme();
19
20         if (!intval(get_config('system','old_share'))) {
21                 if (strpos($r[0]['body'], "[/share]") !== false) {
22                         $pos = strpos($r[0]['body'], "[share");
23                         $o = substr($r[0]['body'], $pos);
24                 } else {
25                         $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
26
27                         if($r[0]['title'])
28                                 $o .= '[b]'.$r[0]['title'].'[/b]'."\n";
29                         $o .= $r[0]['body'];
30                         $o.= "[/share]";
31                 }
32         } else {
33                 $o = '';
34
35                 $o .= "\xE2\x99\xb2" . ' [url=' . $r[0]['author-link'] . ']' . $r[0]['author-name'] . '[/url]' . "\n";
36                 if($r[0]['title'])
37                         $o .= '[b]' . $r[0]['title'] . '[/b]' . "\n";
38                 $o .= $r[0]['body'] . "\n" ;
39
40                 $o .= (($r[0]['plink']) ? '[url=' . $r[0]['plink'] . ']' . t('link') . '[/url]' . "\n" : '');
41         }
42         echo $o;
43         killme();
44 }
45 }
46
47 if(! function_exists('share_header')) {
48 function share_header($author, $profile, $avatar, $guid, $posted, $link) {
49         $header = "[share author='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$author).
50                 "' profile='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$profile).
51                 "' avatar='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$avatar);
52
53         if ($guid)
54                 $header .= "' guid='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$guid);
55
56         if ($posted)
57                 $header .= "' posted='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$posted);
58
59         $header .= "' link='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$link)."']";
60
61         return $header;
62 }
63 }