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.

160 lines
3.9 KiB

  1. <?php
  2. require_once('include/message.php');
  3. function wallmessage_post(&$a) {
  4. $replyto = get_my_url();
  5. if(! $replyto) {
  6. notice( t('Permission denied.') . EOL);
  7. return;
  8. }
  9. $subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : '');
  10. $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : '');
  11. $recipient = (($a->argc > 1) ? notags($a->argv[1]) : '');
  12. if((! $recipient) || (! $body)) {
  13. return;
  14. }
  15. $r = q("select * from user where nickname = '%s' limit 1",
  16. dbesc($recipient)
  17. );
  18. if(! count($r)) {
  19. logger('wallmessage: no recipient');
  20. return;
  21. }
  22. $user = $r[0];
  23. if(! intval($user['unkmail'])) {
  24. notice( t('Permission denied.') . EOL);
  25. return;
  26. }
  27. $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
  28. intval($user['uid'])
  29. );
  30. if($r[0]['total'] > $user['cntunkmail']) {
  31. notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])));
  32. return;
  33. }
  34. // Work around doubled linefeeds in Tinymce 3.5b2
  35. $body = str_replace("\r\n","\n",$body);
  36. $body = str_replace("\n\n","\n",$body);
  37. $ret = send_wallmessage($user, $body, $subject, $replyto);
  38. switch($ret){
  39. case -1:
  40. notice( t('No recipient selected.') . EOL );
  41. break;
  42. case -2:
  43. notice( t('Unable to check your home location.') . EOL );
  44. break;
  45. case -3:
  46. notice( t('Message could not be sent.') . EOL );
  47. break;
  48. case -4:
  49. notice( t('Message collection failure.') . EOL );
  50. break;
  51. default:
  52. info( t('Message sent.') . EOL );
  53. }
  54. // goaway($a->get_baseurl() . '/profile/' . $user['nickname']);
  55. }
  56. function wallmessage_content(&$a) {
  57. if(! get_my_url()) {
  58. notice( t('Permission denied.') . EOL);
  59. return;
  60. }
  61. $recipient = (($a->argc > 1) ? $a->argv[1] : '');
  62. if(! $recipient) {
  63. notice( t('No recipient.') . EOL);
  64. return;
  65. }
  66. $r = q("select * from user where nickname = '%s' limit 1",
  67. dbesc($recipient)
  68. );
  69. if(! count($r)) {
  70. notice( t('No recipient.') . EOL);
  71. logger('wallmessage: no recipient');
  72. return;
  73. }
  74. $user = $r[0];
  75. if(! intval($user['unkmail'])) {
  76. notice( t('Permission denied.') . EOL);
  77. return;
  78. }
  79. $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
  80. intval($user['uid'])
  81. );
  82. if($r[0]['total'] > $user['cntunkmail']) {
  83. notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])));
  84. return;
  85. }
  86. $editselect = 'none';
  87. if( feature_enabled(local_user(), 'richtext') )
  88. $editselect = '/(profile-jot-text|prvmail-text)/';
  89. $tpl = get_markup_template('wallmsg-header.tpl');
  90. $a->page['htmlhead'] .= replace_macros($tpl, array(
  91. '$baseurl' => $a->get_baseurl(true),
  92. '$editselect' => $editselect,
  93. '$nickname' => $user['nickname'],
  94. '$linkurl' => t('Please enter a link URL:')
  95. ));
  96. $tpl = get_markup_template('wallmsg-end.tpl');
  97. $a->page['end'] .= replace_macros($tpl, array(
  98. '$baseurl' => $a->get_baseurl(true),
  99. '$editselect' => $editselect,
  100. '$nickname' => $user['nickname'],
  101. '$linkurl' => t('Please enter a link URL:')
  102. ));
  103. $tpl = get_markup_template('wallmessage.tpl');
  104. $o .= replace_macros($tpl,array(
  105. '$header' => t('Send Private Message'),
  106. '$subheader' => sprintf( t('If you wish for %s to respond, please check that the privacy settings on your site allow private mail from unknown senders.'), $user['username']),
  107. '$to' => t('To:'),
  108. '$subject' => t('Subject:'),
  109. '$recipname' => $user['username'],
  110. '$nickname' => $user['nickname'],
  111. '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
  112. '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
  113. '$readonly' => '',
  114. '$yourmessage' => t('Your message:'),
  115. '$select' => $select,
  116. '$parent' => '',
  117. '$upload' => t('Upload photo'),
  118. '$insert' => t('Insert web link'),
  119. '$wait' => t('Please wait')
  120. ));
  121. return $o;
  122. }