GNUsocialPhotoPlugin.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 GNUsocialPhotoPlugin extends MicroAppPlugin
  32. {
  33. var $oldSaveNew = true;
  34. function onCheckSchema()
  35. {
  36. $schema = Schema::get();
  37. $schema->ensureTable('photo', Photo::schemaDef());
  38. return true;
  39. }
  40. function onRouterInitialized($m)
  41. {
  42. $m->connect('main/photo/new', ['action' => 'newphoto']);
  43. $m->connect('main/photo/:id', ['action' => 'showphoto']);
  44. return true;
  45. }
  46. function entryForm($out)
  47. {
  48. return new NewPhotoForm($out);
  49. }
  50. function appTitle()
  51. {
  52. return _('Photo');
  53. }
  54. function tag()
  55. {
  56. return 'Photo';
  57. }
  58. function types()
  59. {
  60. return array(Photo::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. $photoObj = $activity->objects[0];
  68. if ($photoObj->type != Photo::OBJECT_TYPE) {
  69. throw new Exception('Wrong type for object.');
  70. }
  71. $photo_uri = $photoObj->largerImage;
  72. $thumb_uri = $photo_uri;
  73. if(!empty($photoObj->thumbnail)){
  74. $thumb_uri = $photoObj->thumbnail;
  75. }
  76. $description = $photoObj->description;
  77. $title = $photoObj->title;
  78. $options['object_type'] = Photo::OBJECT_TYPE;
  79. Photo::saveNew($actor, $photo_uri, $thumb_uri, $title, $description, $options);
  80. }
  81. function activityObjectFromNotice(Notice $notice)
  82. {
  83. $photo = Photo::getByNotice($notice);
  84. $object = new ActivityObject();
  85. $object->id = $notice->uri;
  86. $object->type = Photo::OBJECT_TYPE;
  87. $object->title = $photo->title;
  88. $object->summary = $notice->content;
  89. $object->link = $notice->getUrl();
  90. $object->largerImage = $photo->photo_uri;
  91. $object->thumbnail = $photo->thumb_uri;
  92. $object->description = $photo->description;
  93. return $object;
  94. }
  95. function showNoticeContent(Notice $notice, HTMLOutputter $out)
  96. {
  97. $photo = Photo::getByNotice($notice);
  98. if ($photo) {
  99. if($photo->title){
  100. // TODO: ugly. feel like we should have a more abstract way
  101. // of choosing the h-level.
  102. $out->element('h3', array(), $title);
  103. }
  104. $out->element('img', array('src' => $photo->photo_uri,
  105. 'width' => '100%'));
  106. // TODO: add description
  107. }
  108. }
  109. function deleteRelated(Notice $notice)
  110. {
  111. $photo = Photo::getByNotice($notice);
  112. if ($photo) {
  113. $photo->delete();
  114. }
  115. }
  116. }