ActivityVerbPostModule.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. assert($this->isMyActivity($act));
  50. $stored->object_type = ActivityUtils::resolveUri($act->objects[0]->type);
  51. if (common_valid_http_url($act->objects[0]->link)) {
  52. $stored->url = $act->objects[0]->link;
  53. }
  54. // We don't have to do just about anything for a new, remote notice since the fields
  55. // are handled in the main Notice::saveActivity function. Such as content, attachments,
  56. // parent/conversation etc.
  57. // By returning true here instead of something that evaluates
  58. // to false, we show that we have processed everything properly.
  59. return true;
  60. }
  61. public function activityObjectFromNotice(Notice $notice)
  62. {
  63. $object = new ActivityObject();
  64. $object->type = $notice->object_type ?: ActivityObject::NOTE;
  65. $object->id = $notice->getUri();
  66. $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
  67. $object->content = $notice->getRendered();
  68. $object->link = $notice->getUrl();
  69. $object->extra[] = array('statusnet:notice_id', null, $notice->getID());
  70. return $object;
  71. }
  72. public function deleteRelated(Notice $notice)
  73. {
  74. // No action needed as the table for data storage _is_ the notice table.
  75. return true;
  76. }
  77. /**
  78. * Command stuff
  79. */
  80. // FIXME: Move stuff from lib/command.php to here just as with Share etc.
  81. /**
  82. * Layout stuff
  83. */
  84. protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
  85. {
  86. $out->raw($stored->getRendered());
  87. }
  88. protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  89. {
  90. // return page title
  91. }
  92. protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  93. {
  94. // prepare Action?
  95. }
  96. protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  97. {
  98. // handle POST
  99. }
  100. protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  101. {
  102. return new NoticeForm($action, array());
  103. }
  104. public function onModuleVersion(array &$versions): bool
  105. {
  106. $versions[] = array('name' => 'Post verb',
  107. 'version' => self::MODULE_VERSION,
  108. 'author' => 'Mikael Nordfeldth',
  109. 'homepage' => GNUSOCIAL_ENGINE_URL,
  110. 'rawdescription' =>
  111. // TRANS: Module description.
  112. _m('Post handling with ActivityStreams.'));
  113. return true;
  114. }
  115. }