/objects/sites.php

https://github.com/DanielnetoDotCom/YouPHPTube · PHP · 77 lines · 62 code · 15 blank · 0 comment · 4 complexity · e1e869a39e92123faacee6280e2b0859 MD5 · raw file

  1. <?php
  2. global $global, $config;
  3. if(!isset($global['systemRootPath'])){
  4. require_once '../videos/configuration.php';
  5. }
  6. class Sites extends ObjectYPT {
  7. protected $name, $url, $status, $secret;
  8. public static function getSearchFieldsNames() {
  9. return array('name', 'url');
  10. }
  11. public static function getTableName() {
  12. return 'sites';
  13. }
  14. function getName() {
  15. return $this->name;
  16. }
  17. function getUrl() {
  18. return $this->url;
  19. }
  20. function getStatus() {
  21. return $this->status;
  22. }
  23. function setName($name) {
  24. $this->name = $name;
  25. }
  26. function setUrl($url) {
  27. $this->url = $url;
  28. }
  29. function setStatus($status) {
  30. $this->status = $status;
  31. }
  32. function getSecret() {
  33. return $this->secret;
  34. }
  35. function setSecret($secret) {
  36. $this->secret = $secret;
  37. }
  38. function save() {
  39. if(empty($this->getSecret())){
  40. $this->setSecret(md5(uniqid()));
  41. }
  42. $siteURL = $this->getUrl();
  43. if (substr($siteURL, -1) !== '/') {
  44. $siteURL .= "/";
  45. }
  46. $this->setUrl($siteURL);
  47. return parent::save();
  48. }
  49. static function getFromFileName($fileName){
  50. $obj = new stdClass();
  51. $obj->url = "";
  52. $obj->secret = "";
  53. $obj->filename = $fileName;
  54. $video = Video::getVideoFromFileNameLight($fileName);
  55. if(!empty($video['sites_id'])){
  56. $site = new Sites($video['sites_id']);
  57. $obj->url = $site->getUrl();
  58. $obj->secret = $site->getSecret();
  59. }
  60. return $obj;
  61. }
  62. }