Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.9 KiB

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