ActivityVerbPostPlugin.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 ActivityVerbPostPlugin extends ActivityVerbHandlerPlugin
  25. {
  26. // TODO: Implement a "fallback" feature which can handle anything _as_ an activityobject "note"
  27. public function tag()
  28. {
  29. return 'post';
  30. }
  31. public function types()
  32. {
  33. return array(ActivityObject::ARTICLE,
  34. ActivityObject::BLOGENTRY,
  35. ActivityObject::NOTE,
  36. ActivityObject::STATUS,
  37. ActivityObject::COMMENT,
  38. // null, // if we want to follow the original Ostatus_profile::processActivity code
  39. );
  40. }
  41. public function verbs()
  42. {
  43. return array(ActivityVerb::POST);
  44. }
  45. // FIXME: Set this to abstract public in lib/activityhandlerplugin.php when all plugins have migrated!
  46. protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
  47. {
  48. assert($this->isMyActivity($act));
  49. $stored->object_type = ActivityUtils::resolveUri($act->objects[0]->type);
  50. if (common_valid_http_url($act->objects[0]->link)) {
  51. $stored->url = $act->objects[0]->link;
  52. }
  53. // We don't have to do just about anything for a new, remote notice since the fields
  54. // are handled in the main Notice::saveActivity function. Such as content, attachments,
  55. // parent/conversation etc.
  56. // By returning true here instead of something that evaluates
  57. // to false, we show that we have processed everything properly.
  58. return true;
  59. }
  60. public function activityObjectFromNotice(Notice $notice)
  61. {
  62. $object = new ActivityObject();
  63. $object->type = $notice->object_type ?: ActivityObject::NOTE;
  64. $object->id = $notice->getUri();
  65. $object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
  66. $object->content = $notice->getRendered();
  67. $object->link = $notice->getUrl();
  68. $object->extra[] = array('status_net', array('notice_id' => $notice->getID()));
  69. return $object;
  70. }
  71. public function deleteRelated(Notice $notice)
  72. {
  73. // No action needed as the table for data storage _is_ the notice table.
  74. return true;
  75. }
  76. /**
  77. * Command stuff
  78. */
  79. // FIXME: Move stuff from lib/command.php to here just as with Share etc.
  80. /**
  81. * Layout stuff
  82. */
  83. protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
  84. {
  85. $out->raw($stored->getRendered());
  86. }
  87. protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  88. {
  89. // return page title
  90. }
  91. protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  92. {
  93. // prepare Action?
  94. }
  95. protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  96. {
  97. // handle POST
  98. }
  99. protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  100. {
  101. return new NoticeForm($action, array());
  102. }
  103. public function onPluginVersion(array &$versions)
  104. {
  105. $versions[] = array('name' => 'Post verb',
  106. 'version' => GNUSOCIAL_VERSION,
  107. 'author' => 'Mikael Nordfeldth',
  108. 'homepage' => 'https://gnu.io/',
  109. 'rawdescription' =>
  110. // TRANS: Plugin description.
  111. _m('Post handling with ActivityStreams.'));
  112. return true;
  113. }
  114. }