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.

143 lines
3.4 KiB

10 years ago
10 years ago
  1. <?php
  2. require_once('include/attach.php');
  3. require_once('include/datetime.php');
  4. function wall_attach_post(&$a) {
  5. if($a->argc > 1) {
  6. $nick = $a->argv[1];
  7. $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
  8. dbesc($nick)
  9. );
  10. if(! count($r))
  11. return;
  12. }
  13. else
  14. return;
  15. $can_post = false;
  16. $visitor = 0;
  17. $page_owner_uid = $r[0]['uid'];
  18. $page_owner_cid = $r[0]['id'];
  19. $page_owner_nick = $r[0]['nickname'];
  20. $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
  21. if((local_user()) && (local_user() == $page_owner_uid))
  22. $can_post = true;
  23. else {
  24. if($community_page && remote_user()) {
  25. $cid = 0;
  26. if(is_array($_SESSION['remote'])) {
  27. foreach($_SESSION['remote'] as $v) {
  28. if($v['uid'] == $page_owner_uid) {
  29. $cid = $v['cid'];
  30. break;
  31. }
  32. }
  33. }
  34. if($cid) {
  35. $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
  36. intval($cid),
  37. intval($page_owner_uid)
  38. );
  39. if(count($r)) {
  40. $can_post = true;
  41. $visitor = $cid;
  42. }
  43. }
  44. }
  45. }
  46. if(! $can_post) {
  47. notice( t('Permission denied.') . EOL );
  48. killme();
  49. }
  50. if(! x($_FILES,'userfile'))
  51. killme();
  52. $src = $_FILES['userfile']['tmp_name'];
  53. $filename = basename($_FILES['userfile']['name']);
  54. $filesize = intval($_FILES['userfile']['size']);
  55. $maxfilesize = get_config('system','maxfilesize');
  56. /* Found html code written in text field of form,
  57. * when trying to upload a file with filesize
  58. * greater than upload_max_filesize. Cause is unknown.
  59. * Then Filesize gets <= 0.
  60. */
  61. if($filesize <=0) {
  62. notice(t('Sorry, maybe your upload is bigger than the PHP configuration allows') . EOL .(t('Or - did you try to upload an empty file?')) . EOL);
  63. @unlink($src);
  64. killme();
  65. }
  66. if(($maxfilesize) && ($filesize > $maxfilesize)) {
  67. echo sprintf(t('File exceeds size limit of %s'), formatBytes($maxfilesize)) . EOL;
  68. @unlink($src);
  69. killme();
  70. }
  71. $r = q("select sum(octet_length(data)) as total from attach where uid = %d ",
  72. intval($page_owner_uid)
  73. );
  74. $limit = service_class_fetch($page_owner_uid,'attach_upload_limit');
  75. if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
  76. echo upgrade_message(true) . EOL ;
  77. @unlink($src);
  78. killme();
  79. }
  80. $filedata = @file_get_contents($src);
  81. $mimetype = z_mime_content_type($filename);
  82. $hash = get_guid(64);
  83. $created = datetime_convert();
  84. $r = q("INSERT INTO `attach` ( `uid`, `hash`, `filename`, `filetype`, `filesize`, `data`, `created`, `edited`, `allow_cid`, `allow_gid`,`deny_cid`, `deny_gid` )
  85. VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
  86. intval($page_owner_uid),
  87. dbesc($hash),
  88. dbesc($filename),
  89. dbesc($mimetype),
  90. intval($filesize),
  91. dbesc($filedata),
  92. dbesc($created),
  93. dbesc($created),
  94. dbesc('<' . $page_owner_cid . '>'),
  95. dbesc(''),
  96. dbesc(''),
  97. dbesc('')
  98. );
  99. @unlink($src);
  100. if(! $r) {
  101. echo ( t('File upload failed.') . EOL);
  102. killme();
  103. }
  104. $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `created` = '%s' AND `hash` = '%s' LIMIT 1",
  105. intval($page_owner_uid),
  106. dbesc($created),
  107. dbesc($hash)
  108. );
  109. if(! count($r)) {
  110. echo ( t('File upload failed.') . EOL);
  111. killme();
  112. }
  113. $lf = "\n";
  114. echo $lf . $lf . '[attachment]' . $r[0]['id'] . '[/attachment]' . $lf;
  115. killme();
  116. // NOTREACHED
  117. }