Photo.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * @package GNU Social
  23. * @author Ian Denhardt <ian@zenhack.net>
  24. * @copyright 2011 Free Software Foundation, Inc.
  25. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  26. */
  27. if(!defined('STATUSNET')){
  28. exit(1);
  29. }
  30. /**
  31. * Data class for photos.
  32. */
  33. class Photo extends Managed_DataObject
  34. {
  35. const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/photo';
  36. public $__table = 'photo'; // table name
  37. public $id; // char (36) // UUID
  38. public $uri; // varchar (255) // This is the corresponding notice's uri.
  39. public $photo_uri; // varchar (255)
  40. public $thumb_uri; // varchar (255)
  41. public $title; // varchar (255)
  42. public $description; // text
  43. public $profile_id; // int
  44. public static function getByNotice($notice)
  45. {
  46. return self::getKV('uri', $notice->uri);
  47. }
  48. public function getNotice()
  49. {
  50. return Notice::getKV('uri', $this->uri);
  51. }
  52. public static function schemaDef()
  53. {
  54. return array(
  55. 'description' => 'A photograph',
  56. 'fields' => array(
  57. 'id' => array('type' => 'char',
  58. 'length' => 36,
  59. 'not null' => true,
  60. 'description' => 'UUID'),
  61. 'uri' => array('type' => 'varchar',
  62. 'length' => 255,
  63. 'not null' => true),
  64. 'photo_uri' => array('type' => 'varchar',
  65. 'length' => 255,
  66. 'not null' => true),
  67. 'photo_uri' => array('type' => 'varchar',
  68. 'length' => 255,
  69. 'not null' => true),
  70. 'profile_id' => array('type' => 'int', 'not null' => true),
  71. ),
  72. 'primary key' => array('id'),
  73. 'foreign keys' => array('photo_profile_id__key' => array('profile' => array('profile_id' => 'id'))),
  74. );
  75. }
  76. static function saveNew(Profile $profile, $photo_uri, $thumb_uri, $title, $description, $options=array())
  77. {
  78. $photo = new Photo();
  79. $photo->id = UUID::gen();
  80. $photo->profile_id = $profile->id;
  81. $photo->photo_uri = $photo_uri;
  82. $photo->thumb_uri = $thumb_uri;
  83. $options['object_type'] = Photo::OBJECT_TYPE;
  84. if (!array_key_exists('uri', $options)) {
  85. $options['uri'] = common_local_url('showphoto', array('id' => $photo->id));
  86. }
  87. if (!array_key_exists('rendered', $options)) {
  88. $options['rendered'] = sprintf("<img src=\"%s\" alt=\"%s\"></img>", $photo_uri,
  89. $title);
  90. }
  91. $photo->uri = $options['uri'];
  92. $photo->insert();
  93. return Notice::saveNew($profile->id,
  94. '',
  95. 'web',
  96. $options);
  97. }
  98. }