Photo.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * @package GNUsocial
  18. * @author Ian Denhardt <ian@zenhack.net>
  19. * @copyright 2011 Free Software Foundation, Inc http://www.fsf.org
  20. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  21. */
  22. if (!defined('STATUSNET')) {
  23. exit(1);
  24. }
  25. /**
  26. * Data class for photos
  27. *
  28. * @copyright 2011 Free Software Foundation, Inc http://www.fsf.org
  29. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  30. */
  31. class Photo extends Managed_DataObject
  32. {
  33. const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/photo';
  34. public $__table = 'photo'; // table name
  35. public $id; // char (36) // UUID
  36. public $uri; // varchar (191) // This is the corresponding notice's uri. not 255 because utf8mb4 takes more space
  37. public $photo_uri; // varchar (191) not 255 because utf8mb4 takes more space
  38. public $thumb_uri; // varchar (191) not 255 because utf8mb4 takes more space
  39. public $title; // varchar (191) not 255 because utf8mb4 takes more space
  40. public $description; // text
  41. public $profile_id; // int
  42. public static function getByNotice($notice)
  43. {
  44. return self::getKV('uri', $notice->uri);
  45. }
  46. public function getNotice()
  47. {
  48. return Notice::getKV('uri', $this->uri);
  49. }
  50. public static function schemaDef()
  51. {
  52. return array(
  53. 'description' => 'A photograph',
  54. 'fields' => array(
  55. 'id' => array('type' => 'char',
  56. 'length' => 36,
  57. 'not null' => true,
  58. 'description' => 'UUID'),
  59. 'uri' => array('type' => 'varchar',
  60. 'length' => 191,
  61. 'not null' => true),
  62. 'photo_uri' => array('type' => 'varchar',
  63. 'length' => 191,
  64. 'not null' => true),
  65. 'photo_uri' => array('type' => 'varchar',
  66. 'length' => 191,
  67. 'not null' => true),
  68. 'profile_id' => array('type' => 'int', 'not null' => true),
  69. ),
  70. 'primary key' => array('id'),
  71. 'foreign keys' => array(
  72. 'photo_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
  73. ),
  74. );
  75. }
  76. public 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(
  89. "<img src=\"%s\" alt=\"%s\"></img>",
  90. $photo_uri,
  91. $title
  92. );
  93. }
  94. $photo->uri = $options['uri'];
  95. $photo->insert();
  96. return Notice::saveNew(
  97. $profile->id,
  98. '',
  99. 'web',
  100. $options
  101. );
  102. }
  103. }