ActivityVerbPostModule.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /*
  3. * GNU Social - a federating social network
  4. * Copyright (C) 2014, Free Software Foundation, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('GNUSOCIAL')) { exit(1); }
  20. /**
  21. * @package Activity
  22. * @maintainer Mikael Nordfeldth <mmn@hethane.se>
  23. */
  24. class ActivityVerbPostModule extends ActivityVerbHandlerModule
  25. {
  26. const MODULE_VERSION = '2.0.0';
  27. // TODO: Implement a "fallback" feature which can handle anything _as_ an activityobject "note"
  28. public function tag()
  29. {
  30. return 'post';
  31. }
  32. public function types()
  33. {
  34. return array(ActivityObject::ARTICLE,
  35. ActivityObject::BLOGENTRY,
  36. ActivityObject::NOTE,
  37. ActivityObject::STATUS,
  38. ActivityObject::COMMENT,
  39. // null, // if we want to follow the original Ostatus_profile::processActivity code
  40. );
  41. }
  42. public function verbs()
  43. {
  44. return array(ActivityVerb::POST);
  45. }
  46. // FIXME: Set this to abstract public in classes/modules/ActivityHandlerModule.php when all plugins have migrated!
  47. protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
  48. {
  49. if (!$this->isMyActivity($act)) {
  50. doom("あなたのアクティビティではありません。", __FILE__, __LINE__);
  51. }
  52. $stored->object_type = ActivityUtils::resolveUri($act->objects[0]->type);
  53. if (common_valid_http_url($act->objects[0]->link)) {
  54. $stored->url = $act->objects[0]->link;
  55. }
  56. // We don't have to do just about anything for a new, remote notice since the fields
  57. // are handled in the main Notice::saveActivity function. Such as content, attachments,
  58. // parent/conversation etc.
  59. // By returning true here instead of something that evaluates
  60. // to false, we show that we have processed everything properly.
  61. return true;
  62. }
  63. public function activityObjectFromNotice(Notice $notice)
  64. {
  65. $object = new ActivityObject();
  66. $object->type = $notice->object_type ?: ActivityObject::NOTE;
  67. $object->id = $notice->getUri();
  68. $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
  69. $object->content = $notice->getRendered();
  70. $object->link = $notice->getUrl();
  71. $object->extra[] = array('statusnet:notice_id', null, $notice->getID());
  72. return $object;
  73. }
  74. public function deleteRelated(Notice $notice)
  75. {
  76. // No action needed as the table for data storage _is_ the notice table.
  77. return true;
  78. }
  79. /**
  80. * Command stuff
  81. */
  82. // FIXME: Move stuff from lib/command.php to here just as with Share etc.
  83. /**
  84. * Layout stuff
  85. */
  86. protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
  87. {
  88. $out->raw($stored->getRendered());
  89. }
  90. protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  91. {
  92. // return page title
  93. }
  94. protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  95. {
  96. // prepare Action?
  97. }
  98. protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  99. {
  100. // handle POST
  101. }
  102. protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  103. {
  104. return new NoticeForm($action, array());
  105. }
  106. public function onModuleVersion(array &$versions): bool
  107. {
  108. $versions[] = array('name' => 'Post verb',
  109. 'version' => self::MODULE_VERSION,
  110. 'author' => 'Mikael Nordfeldth',
  111. 'homepage' => GNUSOCIAL_ENGINE_URL,
  112. 'rawdescription' =>
  113. // TRANS: Module description.
  114. _m('Post handling with ActivityStreams.'));
  115. return true;
  116. }
  117. }