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.

105 lines
2.4 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. <?php
  2. require_once('Photo.php');
  3. function wall_upload_post(&$a) {
  4. if($a->argc > 1) {
  5. $nick = $a->argv[1];
  6. $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
  7. dbesc($nick)
  8. );
  9. if(! count($r))
  10. return;
  11. }
  12. else
  13. return;
  14. $can_post = false;
  15. $visitor = 0;
  16. $page_owner_uid = $r[0]['uid'];
  17. $page_owner_nick = $r[0]['nickname'];
  18. $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
  19. if((local_user()) && (local_user() == $page_owner_uid))
  20. $can_post = true;
  21. else {
  22. if($community_page && remote_user()) {
  23. $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
  24. intval(remote_user()),
  25. intval($page_owner_uid)
  26. );
  27. if(count($r)) {
  28. $can_post = true;
  29. $visitor = remote_user();
  30. }
  31. }
  32. }
  33. if(! $can_post) {
  34. notice( t('Permission denied.') . EOL );
  35. killme();
  36. }
  37. if(! x($_FILES,'userfile'))
  38. killme();
  39. $src = $_FILES['userfile']['tmp_name'];
  40. $filename = basename($_FILES['userfile']['name']);
  41. $filesize = intval($_FILES['userfile']['size']);
  42. $maximagesize = get_config('system','maximagesize');
  43. if(($maximagesize) && ($filesize > $maximagesize)) {
  44. echo sprintf( t('Image exceeds size limit of %d'), $maximagesize) . EOL;
  45. @unlink($src);
  46. return;
  47. }
  48. $imagedata = @file_get_contents($src);
  49. $ph = new Photo($imagedata);
  50. if(! $ph->is_valid()) {
  51. echo ( t('Unable to process image.') . EOL);
  52. @unlink($src);
  53. killme();
  54. }
  55. @unlink($src);
  56. $width = $ph->getWidth();
  57. $height = $ph->getHeight();
  58. $hash = photo_new_resource();
  59. $smallest = 0;
  60. $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, '<0>');
  61. if(! $r) {
  62. echo ( t('Image upload failed.') . EOL);
  63. killme();
  64. }
  65. if($width > 640 || $height > 640) {
  66. $ph->scaleImage(640);
  67. $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, '<0>');
  68. if($r)
  69. $smallest = 1;
  70. }
  71. if($width > 320 || $height > 320) {
  72. $ph->scaleImage(320);
  73. $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, '<0>' );
  74. if($r)
  75. $smallest = 2;
  76. }
  77. $basename = basename($filename);
  78. echo '<br /><br /><a href="' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '" ><img src="' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" /></a><br /><br />";
  79. killme();
  80. // NOTREACHED
  81. }