This repository was archived by the owner on Apr 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontent-handler.php
More file actions
125 lines (103 loc) · 4.84 KB
/
content-handler.php
File metadata and controls
125 lines (103 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
require dirname(__FILE__) . "/playlist-controller.php";
require dirname(__FILE__) . "/video-factory.php";
require dirname(__FILE__) . "/playlist-entry.php";
if (!class_exists("ContentHandler")) {
class ContentHandler {
var $VIDEO_URL_PATTERN = "/\](.*)\[/i";
var $SUPPORTED_SOURCES = array("youtube.com", "vimeo.com", "veoh.com", "dailymotion.com", "google.com", "googlevideo.com", "myspace.com", "youku.com");
var $PLUGIN_URL;
// playlist controller
var $playlistController;
// default constructor
function ContentHandler() {
global $wpdb;
$this->playlistController = new PlaylistController();
$this->PLUGIN_URL = WP_PLUGIN_URL."/proplayer";
}
// check if the url is one of the supported one
function isSupportedUrl($url = '') {
if (!empty($url)) {
foreach ($this->SUPPORTED_SOURCES as $source) {
if (strstr($url, $source)) {
return true;
}
}
}
return false;
}
// future releases will be able to pass their own title, image and type; right now they will be all same
function addFileAttributes($id = '', $videoURL = '', $type = 'video', $defaultImage = '') {
$fileAttributes = "";
$urlList = split(",\s*", $videoURL);
$image = $defaultImage;
foreach ($urlList as $url) {
if (strstr($url, "youtube.com") && strstr($url, "list?p")) {
// process YouTube playlist
$this->processYouTubePlaylist($id, $url, $type);
} else {
if ($this->isSupportedUrl($url)) {
$videoFactory = new VideoFactory();
$videoSource = $videoFactory->createVideoSource($url);
// get the online video source link
try {
if (strstr($url, "youtube.com")) {
// leave the url as same and just set the type
$type = "youtube";
}
$url = $videoSource->getComputedVideoUrl();
if (strstr(get_option('PRO_PLAYER_DEFAULT_PREVIEW_IMAGE'), $defaultImage)) {
$image = $videoSource->getPreviewImageUrl();
}
$title = $videoSource->getTitle();
} catch (Exception $e) {
$url = '';
}
}
if (!empty($url)) {
$entry = new PlaylistEntry($url, $image, $type, $title);
$this->playlistController->addToPlaylist($id, $entry);
}
}
}
$this->playlistController->savePlaylist($id);
$fileAttributes = "file: '".$this->PLUGIN_URL."/playlist-controller.php?pp_playlist_id=".$id."&sid=".strtotime("now")."'";
return $fileAttributes;
}
function processYouTubePlaylist($id = '', $url = '', $type = 'video') {
$url = str_replace('</em>', '_', str_replace('<em>', '_', $url));
$session = curl_init($url);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
curl_setopt($session, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$response = curl_exec($session);
$error = curl_error($session);
if (empty($error)) {
preg_match_all("#href.*watch.{1}v=(.*)&feature#i", $response, $matches);
$matches = array_unique($matches[1]);
if (count($matches) > 0) {
$videoUrl = "http://www.youtube.com/watch?v=";
}
foreach ($matches as $match) {
// get the online video source link
$videoFactory = new VideoFactory();
$videoSource = $videoFactory->createVideoSource($videoUrl.$match);
try {
$image = $videoSource->getPreviewImageUrl();
$title = $videoSource->getTitle();
$currentUrl = $videoSource->getComputedVideoUrl();
} catch (Exception $e) {
$currentUrl = '';
}
if (!empty($currentUrl)) {
$entry = new PlaylistEntry($currentUrl, $image, "youtube", $title);
$this->playlistController->addToPlaylist($id, $entry);
}
}
}
}
}
}
?>