GNUsocialVideoPlugin.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * GNU Social
  4. * Copyright (C) 2011, Free Software Foundation, Inc.
  5. *
  6. * PHP version 5
  7. *
  8. * LICENCE:
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Widget
  23. * @package GNU Social
  24. * @author Ian Denhardt <ian@zenhack.net>
  25. * @copyright 2011 Free Software Foundation, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  27. */
  28. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. class GNUsocialVideoPlugin extends MicroAppPlugin
  32. {
  33. var $oldSaveNew = true;
  34. function onCheckSchema()
  35. {
  36. $schema = Schema::get();
  37. $schema->ensureTable('video', Video::schemaDef());
  38. return true;
  39. }
  40. function onRouterInitialized($m)
  41. {
  42. $m->connect('main/postvideo', ['action' => 'postvideo']);
  43. $m->connect('showvideo/:id', ['action' => 'showvideo']);
  44. return true;
  45. }
  46. function entryForm($out)
  47. {
  48. return new VideoForm($out);
  49. }
  50. function appTitle()
  51. {
  52. return _('Video');
  53. }
  54. function tag()
  55. {
  56. return 'GNUsocialVideo';
  57. }
  58. function types()
  59. {
  60. return array(Video::OBJECT_TYPE);
  61. }
  62. function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array())
  63. {
  64. if(count($activity->objects) != 1) {
  65. throw new Exception('Too many activity objects.');
  66. }
  67. $videoObj = $activity->objects[0];
  68. if ($videoObj->type != Video::OBJECT_TYPE) {
  69. throw new Exception('Wrong type for object.');
  70. }
  71. // For now we read straight from the xml tree, no other way to get this information.
  72. // When there's a better API for this, we should change to it.
  73. $uri = ActivityUtils::getLink($activity->entry, 'enclosure');
  74. $options['object_type'] = Video::OBJECT_TYPE;
  75. Video::saveNew($actor, $uri, $options);
  76. }
  77. function activityObjectFromNotice(Notice $notice)
  78. {
  79. $object = new ActivityObject();
  80. $object->id = $notice->uri;
  81. $object->type = Video::OBJECT_TYPE;
  82. $object->title = $notice->content;
  83. $object->summary = $notice->content;
  84. $object->link = $notice->getUrl();
  85. $vid = Video::getByNotice($notice);
  86. if ($vid) {
  87. $object->extra[] = array('link', array('rel' => 'enclosure', 'href' => $vid->url), array());
  88. }
  89. return $object;
  90. }
  91. function showNotice(Notice $notice, HTMLOutputter $out)
  92. {
  93. $vid = Video::getByNotice($notice);
  94. if ($vid) {
  95. $out->element('video', array('src' => $vid->url,
  96. 'width' => '100%',
  97. 'controls' => 'controls'));
  98. }
  99. }
  100. function deleteRelated(Notice $notice)
  101. {
  102. $vid = Video::getByNotice($notice);
  103. if ($vid) {
  104. $vid->delete();
  105. }
  106. }
  107. }