Video.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 videos.
  32. */
  33. class Video extends Managed_DataObject
  34. {
  35. const OBJECT_TYPE = 'http://activitystrea.ms/schema/1.0/video';
  36. public $__table = 'video'; // table name
  37. public $id; // char (36) // UUID
  38. public $uri; // varchar (191) This is the corresponding notice's uri. not 255 because utf8mb4 takes more space
  39. public $url; // varchar (191) not 255 because utf8mb4 takes more space
  40. public $profile_id; // int
  41. public static function getByNotice($notice)
  42. {
  43. return self::getKV('uri', $notice->uri);
  44. }
  45. public function getNotice()
  46. {
  47. return Notice::getKV('uri', $this->uri);
  48. }
  49. public static function schemaDef()
  50. {
  51. return array(
  52. 'description' => 'A video clip',
  53. 'fields' => array(
  54. 'id' => array('type' => 'char',
  55. 'length' => 36,
  56. 'not null' => true,
  57. 'description' => 'UUID'),
  58. 'uri' => array('type' => 'varchar',
  59. 'length' => 191,
  60. 'not null' => true),
  61. 'url' => array('type' => 'varchar',
  62. 'length' => 191,
  63. 'not null' => true),
  64. 'profile_id' => array('type' => 'int', 'not null' => true),
  65. ),
  66. 'primary key' => array('id'),
  67. 'foreign keys' => array('video_profile_id__key' => array('profile' => array('profile_id' => 'id'))),
  68. );
  69. }
  70. static function saveNew(Profile $profile, $url, $options=array())
  71. {
  72. $vid = new Video();
  73. $vid->id = UUID::gen();
  74. $vid->profile_id = $profile->id;
  75. $vid->url = $url;
  76. $options['object_type'] = Video::OBJECT_TYPE;
  77. if (!array_key_exists('uri', $options)) {
  78. $options['uri'] = common_local_url('showvideo', array('id' => $vid->id));
  79. }
  80. if (!array_key_exists('rendered', $options)) {
  81. $options['rendered'] = sprintf("<video src=\"%s\">Sorry, your browser doesn't support the video tag.</video>", $url);
  82. }
  83. $vid->uri = $options['uri'];
  84. $vid->insert();
  85. return Notice::saveNew($profile->id,
  86. '',
  87. 'web',
  88. $options);
  89. }
  90. }