KXStudio Website https://kx.studio/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

video.php 7.0KB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. class Video extends Feathers implements Feather {
  3. public function __init() {
  4. $this->setField(array("attr" => "video",
  5. "type" => "text_block",
  6. "rows" => 4,
  7. "label" => __("Video", "video"),
  8. "preview" => true,
  9. "bookmarklet" => $this->isVideo() ?
  10. "url" :
  11. ""));
  12. $this->setField(array("attr" => "caption",
  13. "type" => "text_block",
  14. "rows" => 4,
  15. "label" => __("Caption", "video"),
  16. "optional" => true,
  17. "preview" => true,
  18. "bookmarklet" => "selection"));
  19. if ($this->isVideo())
  20. $this->bookmarkletSelected();
  21. $this->setFilter("caption", array("markup_text", "markup_post_text"));
  22. $this->respondTo("preview_video", "embed_tag");
  23. }
  24. public function submit() {
  25. if (empty($_POST['video']))
  26. error(__("Error"), __("Video can't be blank."));
  27. return Post::add(array("embed" => $this->embed_tag($_POST['video']),
  28. "video" => $_POST['video'],
  29. "caption" => $_POST['caption']),
  30. $_POST['slug'],
  31. Post::check_url($_POST['slug']));
  32. }
  33. public function update($post) {
  34. if (empty($_POST['video']))
  35. error(__("Error"), __("Video can't be blank."));
  36. $post->update(array("embed" => $this->embed_tag($_POST['video']),
  37. "video" => $_POST['video'],
  38. "caption" => $_POST['caption']));
  39. }
  40. public function title($post) {
  41. return $post->title_from_excerpt();
  42. }
  43. public function excerpt($post) {
  44. return $post->caption;
  45. }
  46. public function feed_content($post) {
  47. return $post->embed."<br /><br />".$post->caption;
  48. }
  49. public function embed_tag($video, $field = null) { # We use this for previewing too
  50. if (isset($field) and $field != "embed")
  51. return $video; # If they're previewing and the field argument isn't the embed, return the original.
  52. if (preg_match("/http:\/\/(www\.|[a-z]{2}\.)?youtube\.com\/watch\?v=([^&]+)/", $video, $matches)) {
  53. return '<object type="application/x-shockwave-flash" class="object-youtube" data="http://'.$matches[1].'youtube.com/v/'.$matches[2].'" width="468" height="391"><param name="movie" value="http://'.$matches[1].'youtube.com/v/'.$matches[2].'" /><param name="FlashVars" value="playerMode=embedded" /></object>';
  54. } else if (preg_match("/^http:\/\/(www\.)?vimeo.com\/([0-9]+)/", $video, $matches)) {
  55. $site = get_remote("http://vimeo.com/".$matches[2]);
  56. preg_match('/<div id="vimeo_player_[0-9]+" class="player" style="width:([0-9]+)px;height:([0-9]+)px;">/',
  57. $site,
  58. $scale);
  59. return '<object type="application/x-shockwave-flash" class="object-vimeo" width="'.$scale[1].'" height="'.$scale[2].'" data="http://www.vimeo.com/moogaloop.swf?clip_id='.$matches[2].'&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id='.$matches[2].'&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1" /></object>';
  60. } else if (preg_match("/http:\/\/(www\.)?metacafe.com\/watch\/([0-9]+)\/([^\/&\?]+)/", $video, $matches)) {
  61. return '<object type="application/x-shockwave-flash" class="object-metacafe" data="http://www.metacafe.com/fplayer/'.$matches[2].'/'.$matches[3].'.swf" width="400" height="345"></object>';
  62. } else if (preg_match("/http:\/\/(www\.)?revver.com\/video\/([0-9]+)/", $video, $matches)) {
  63. return '<script src="http://flash.revver.com/player/1.0/player.js?mediaId:'.$matches[2].';width:468;height:391;" type="text/javascript"></script>';
  64. } else if (preg_match("/http:\/\/(www\.)viddler\.com\/.+/", $video)) {
  65. $viddler_page = get_remote($video);
  66. if (preg_match("/<link\s+rel=\"video_src\"\s+href=\"http:\/\/(www\.)?viddler.com\/player\/([0-9a-fA-F]+)/", $viddler_page, $matches) and
  67. preg_match("/<meta\s+name=\"video_height\"\s+content=\"([0-9]+)\"/", $viddler_page, $height) and
  68. preg_match("/<meta\s+name=\"video_width\"\s+content=\"([0-9]+)\"/", $viddler_page, $width)) {
  69. return '<object type="application/x-shockwave-flash" data="http://www.viddler.com/player/'.$matches[2].'/" width="'.$width[1].'" height="'.$height[1].'" id="viddler_'.$matches[2].'" class="object-youtube"><param name="movie" value="http://www.viddler.com/player/'.$matches[2].'/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /></object>';
  70. }
  71. return $video;
  72. }
  73. return $video;
  74. }
  75. public function embed_tag_for($post, $max_width = 500) {
  76. $post->embed = preg_replace("/&([[:alnum:]_]+)=/", "&amp;\\1=", $post->embed);
  77. if (preg_match("/width(=\"|='|:\s*)([0-9]+)/", $post->embed, $width)) {
  78. $sep_w = $width[1];
  79. $original_width = $width[2];
  80. } else
  81. return $post->embed;
  82. if (preg_match("/height(=\"|='|:\s*)([0-9]+)/", $post->embed, $height)) {
  83. $sep_h = $height[1];
  84. $original_height = $height[2];
  85. $new_height = (int) (($max_width / $original_width) * $original_height);
  86. }
  87. $post->embed = str_replace(array($width[0], $height[0]), array("width".$sep_w.$max_width, "height".$sep_h.$new_height), $post->embed);
  88. return $post->embed;
  89. }
  90. public function isVideo() {
  91. if (!isset($_GET['url']))
  92. return false;
  93. if (preg_match("/http:\/\/(www\.|[a-z]{2}\.)?youtube\.com\/watch\?v=([^&]+)/", $_GET['url']) or
  94. preg_match("/http:\/\/(www\.)?vimeo.com\/([0-9]+)/", $_GET['url']) or
  95. preg_match('/http:\/\/(www\.)?metacafe.com\/watch\/([0-9]+)\/([^\/&\?]+)/', $_GET['url']) or
  96. preg_match("/http:\/\/(www\.)?revver.com\/video\/([0-9]+)/", $_GET['url']) or
  97. preg_match("/http:\/\/(www\.)viddler\.com\/.+/", $_GET['url']))
  98. return true;
  99. return false;
  100. }
  101. }