postvideo.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 PostvideoAction extends Action {
  32. var $user = null;
  33. var $url = null;
  34. function prepare(array $args = array())
  35. {
  36. parent::prepare($args);
  37. $this->user = common_current_user();
  38. if(empty($this->user)){
  39. throw new ClientException(_('Must be logged in to post a video'),
  40. 403);
  41. }
  42. if($this->isPost()){
  43. $this->checkSessionToken();
  44. }
  45. $this->url = filter_var($this->trimmed('url'), FILTER_SANITIZE_URL);
  46. $this->url = filter_var($this->url, FILTER_VALIDATE_URL);
  47. return true;
  48. }
  49. function handle()
  50. {
  51. parent::handle();
  52. if ($this->isPost()) {
  53. $this->handlePost($args);
  54. } else {
  55. $this->showPage();
  56. }
  57. }
  58. function handlePost($args)
  59. {
  60. if (empty($this->url)) {
  61. throw new ClientException(_('Bad URL.'));
  62. }
  63. $profile = $this->user->getProfile();
  64. $options = array();
  65. ToSelector::fillOptions($this, $options);
  66. $vid = Video::saveNew($profile, $this->url, $options);
  67. common_redirect($vid->uri, 303);
  68. }
  69. function showContent()
  70. {
  71. $form = new VideoForm();
  72. $form->show();
  73. }
  74. }