apactorinbox.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * GNU social - a federating social network
  4. *
  5. * ActivityPubPlugin implementation for GNU Social
  6. *
  7. * LICENCE: This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @category Plugin
  21. * @package GNUsocial
  22. * @author Diogo Cordeiro <diogo@fc.up.pt>
  23. * @author Daniel Supernault <danielsupernault@gmail.com>
  24. * @copyright 2018 Free Software Foundation http://fsf.org
  25. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  26. * @link https://www.gnu.org/software/social/
  27. */
  28. if (!defined ('GNUSOCIAL')) {
  29. exit (1);
  30. }
  31. /**
  32. * Actor's Inbox
  33. *
  34. * @category Plugin
  35. * @package GNUsocial
  36. * @author Diogo Cordeiro <diogo@fc.up.pt>
  37. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  38. * @link http://www.gnu.org/software/social/
  39. */
  40. class apActorInboxAction extends ManagedAction
  41. {
  42. protected $needLogin = false;
  43. protected $canPost = true;
  44. /**
  45. * Handle the Actor Inbox request
  46. *
  47. * @return void
  48. */
  49. protected function handle ()
  50. {
  51. $nickname = $this->trimmed ('nickname');
  52. try {
  53. $user = User::getByNickname ($nickname);
  54. $profile = $user->getProfile ();
  55. $url = $profile->profileurl;
  56. } catch (Exception $e) {
  57. ActivityPubReturn::error ("Invalid username.");
  58. }
  59. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  60. ActivityPubReturn::error ("C2S not implemented just yet.");
  61. }
  62. $data = json_decode (file_get_contents ('php://input'));
  63. // Validate data
  64. if (!(isset($data->type))) {
  65. ActivityPubReturn::error ("Type was not specified.");
  66. }
  67. if (!isset($data->actor)) {
  68. ActivityPubReturn::error ("Actor was not specified.");
  69. }
  70. if (!isset($data->object)) {
  71. ActivityPubReturn::error ("Object was not specified.");
  72. }
  73. // Get valid Actor object
  74. try {
  75. require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "explorer.php";
  76. $actor_profile = new Activitypub_explorer;
  77. $actor_profile = $actor_profile->lookup ($data->actor);
  78. $actor_profile = $actor_profile[0];
  79. } catch (Exception $e) {
  80. ActivityPubReturn::error ("Invalid Actor.", 404);
  81. }
  82. $to_profiles = array ($user);
  83. // Process request
  84. switch ($data->type) {
  85. case "Create":
  86. require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Create.php";
  87. break;
  88. case "Delete":
  89. require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Delete.php";
  90. break;
  91. case "Follow":
  92. require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Follow.php";
  93. break;
  94. case "Like":
  95. require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Like.php";
  96. break;
  97. case "Undo":
  98. require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Undo.php";
  99. break;
  100. case "Announce":
  101. require_once __DIR__ . DIRECTORY_SEPARATOR . "inbox" . DIRECTORY_SEPARATOR . "Announce.php";
  102. break;
  103. default:
  104. ActivityPubReturn::error ("Invalid type value.");
  105. }
  106. }
  107. }