]> git.mxchange.org Git - friendica.git/blob - mod/share.php
Merge pull request #2148 from annando/issue-1871
[friendica.git] / mod / share.php
1 <?php
2 function share_init(&$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(! count($r) || ($r[0]['private'] == 1))
16                 killme();
17
18         if (!intval(get_config('system','old_share'))) {
19                 if (strpos($r[0]['body'], "[/share]") !== false) {
20                         $pos = strpos($r[0]['body'], "[share");
21                         $o = substr($r[0]['body'], $pos);
22                 } else {
23                         $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
24
25                         if($r[0]['title'])
26                                 $o .= '[b]'.$r[0]['title'].'[/b]'."\n";
27                         $o .= $r[0]['body'];
28                         $o.= "[/share]";
29                 }
30         } else {
31                 $o = '';
32
33                 $o .= "\xE2\x99\xb2" . ' [url=' . $r[0]['author-link'] . ']' . $r[0]['author-name'] . '[/url]' . "\n";
34                 if($r[0]['title'])
35                         $o .= '[b]' . $r[0]['title'] . '[/b]' . "\n";
36                 $o .= $r[0]['body'] . "\n" ;
37
38                 $o .= (($r[0]['plink']) ? '[url=' . $r[0]['plink'] . ']' . t('link') . '[/url]' . "\n" : '');
39         }
40         echo $o;
41         killme();
42 }
43
44 function share_header($author, $profile, $avatar, $guid, $posted, $link) {
45         $header = "[share author='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$author).
46                 "' profile='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$profile).
47                 "' avatar='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$avatar);
48
49         if ($guid)
50                 $header .= "' guid='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$guid);
51
52         if ($posted)
53                 $header .= "' posted='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$posted);
54
55         $header .= "' link='".str_replace(array("'", "[", "]"), array("&#x27;", "&#x5B;", "&#x5D;"),$link)."']";
56
57         return $header;
58 }