-
Notifications
You must be signed in to change notification settings - Fork 5
/
pro-player.php
316 lines (255 loc) · 14.2 KB
/
pro-player.php
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php
/*
Plugin Name: PRO Player
Plugin URI: http://isagoksu.com/proplayer-wordpress-plugin/
Description: Display videos from various online sources in a Custom FLV Player. For details please visit <a href="http://isagoksu.com/proplayer-wordpress-plugin/" target="_new">project page</a> for more information.
Author: Isa Goksu
Version: 4.7.9.1
Author URI: http://isagoksu.com
Special thanks to:
- SWFObject [ http://code.google.com/p/swfobject ] authors, they made flash part really easier.
*/
require dirname(__FILE__) . "/content-handler.php";
require dirname(__FILE__) . "/attribute-resolver.php";
require dirname(__FILE__) . "/constants.php";
require dirname(__FILE__) . "/configuration-builder.php";
if (!class_exists("ProPlayer")) {
class ProPlayer {
var $NEW_LINE = "\r";
var $PLUGIN_URL;
var $contentHandler;
function ProPlayer() {
$this->PLUGIN_URL = WP_PLUGIN_URL."/proplayer";
$this->contentHandler = new ContentHandler();
}
function constructSnippet($attrs, $content = '') {
$configurationBuilder = new ConfigurationBuilder($attrs);
$configuration = $configurationBuilder->build();
$flashvars = $configuration->getFlashVars();
$params = $configuration->getParams();
$others = $configuration->getOthers();
$id = $others[Constants::$ID_KEY].uniqid('pp-single-');
$result = '<!-- ProPlayer by Isa Goksu -->';
$result .= '<div name="mediaspace" id="mediaspace"><div class="pro-player-container" width="'.$flashvars[Constants::$WIDTH_KEY].'px" height="'.$flashvars[Constants::$HEIGHT_KEY].'px"><div id="pro-player-'.$id.'"></div></div></div>'.$this->NEW_LINE;
$result .= '<script type="text/javascript" charset="utf-8">'.$this->NEW_LINE;
$result .= $this->getFlashVars($flashvars, $id, $content);
$result .= $this->getParams($params);
$result .= 'var attributes = {'.$this->NEW_LINE;
$result .= 'id: "obj-pro-player-'.$id.'",'.$this->NEW_LINE;
$result .= 'name: "obj-pro-player-'.$id.'"'.$this->NEW_LINE;
$result .= '};'.$this->NEW_LINE;
$result .= 'swfobject.embedSWF("'.$this->getPlayer().'", "pro-player-'.$id.'", "'.$flashvars[Constants::$WIDTH_KEY].'", "'.$flashvars[Constants::$HEIGHT_KEY].'", "9.0.0", false, flashvars, params, attributes);';
$result .= '</script>'.$this->NEW_LINE;
$result .= $others[Constants::$AD_SCRIPT_KEY];
return $result;
}
/* ---= getters =--- */
function getFlashVars($flashvars, $id, $content) {
$result = 'var flashvars = {'.$this->NEW_LINE;
for ($i = 0; $i < count($flashvars); $i++) {
$keys = array_keys($flashvars);
$values = array_values($flashvars);
if ($keys[$i] != Constants::$FILE_TYPE_KEY) {
$result .= $keys[$i].': "'.$values[$i].'",'.$this->NEW_LINE;
}
}
$result .= Constants::$JAVASCRIPT_ID_KEY.': "'.$id.'",'.$this->NEW_LINE;
$result .= Constants::$PREVIEW_KEY.': "'.$flashvars[Constants::$PREVIEW_KEY].'",'.$this->NEW_LINE;
$playlist = $this->contentHandler->addFileAttributes($id, $content, $flashvars[Constants::$FILE_TYPE_KEY], $flashvars[Constants::$PREVIEW_KEY]);
$result .= $playlist.$this->NEW_LINE;
$result .= '};'.$this->NEW_LINE;
return $result;
}
function getParams($params) {
$result = 'var params = {'.$this->NEW_LINE;
for ($i = 0; $i < count($params); $i++) {
$keys = array_keys($params);
$values = array_values($params);
$result .= $keys[$i].': "'.$values[$i].'",'.$this->NEW_LINE;
}
$result = substr($result, 0, strlen($result)-2).$this->NEW_LINE.'};'.$this->NEW_LINE;
return $result;
}
function getPlayer() {
return $this->PLUGIN_URL."/players/player.swf";
}
function getSkinPath() {
return $this->PLUGIN_URL."/players/skins";
}
/* ---= wordpress settings =--- */
function addHeaderCode() {
print "<script type='text/javascript' src='".$this->PLUGIN_URL."/js/swfobject.js'></script>";
}
function addOptions() {
add_option("PRO_PLAYER_WIDTH", Constants::$WIDTH_VALUE);
add_option("PRO_PLAYER_HEIGHT", Constants::$HEIGHT_VALUE);
add_option("PRO_PLAYER_TYPE", Constants::$FILE_TYPE_VALUE);
add_option("PRO_PLAYER_BACKCOLOR", Constants::$BACKGROUND_COLOR_VALUE);
add_option("PRO_PLAYER_FRONTCOLOR", Constants::$FOREGROUND_COLOR_VALUE);
add_option("PRO_PLAYER_LIGHTCOLOR", Constants::$LIGHT_COLOR_VALUE);
add_option("PRO_PLAYER_STRETCHING", Constants::$STRETCHING_VALUE);
add_option("PRO_PLAYER_AUTO_START", Constants::$AUTO_START_VALUE);
add_option("PRO_PLAYER_REPEAT", Constants::$REPEAT_VALUE);
add_option("PRO_PLAYER_SHOW_WATERMARK", "true");
add_option("PRO_PLAYER_SHOW_DEFAULT_PREVIEW_IMAGE", "true");
add_option("PRO_PLAYER_DEFAULT_PREVIEW_IMAGE", $this->PLUGIN_URL.'/players/'.Constants::$PREVIEW_VALUE);
add_option("PRO_PLAYER_SKIN_FILE", $this->getSkinPath().'/'.Constants::$SKIN_VALUE);
add_option("PRO_PLAYER_VISUALIZER_SUPPORT", "false");
add_option("PRO_PLAYER_RATING_SUPPORT", "false");
add_option("PRO_PLAYER_EMBEDDING_SUPPORT", "false");
add_option('PRO_PLAYER_SUBTITLE_SUPPORT', 'false');
add_option('PRO_PLAYER_SHORTCUT_SUPPORT', 'false');
add_option('PRO_PLAYER_FLOW_VIEW_SUPPORT', 'false');
add_option("PRO_PLAYER_AD_SUPPORT", "false");
add_option("PRO_PLAYER_AD_CHANNEL", "");
add_option("PRO_PLAYER_AD_SCRIPT", "");
add_option("PRO_PLAYER_CACHE_TIMEOUT", "90");
}
function removeOptions() {
delete_option("PRO_PLAYER_WIDTH");
delete_option("PRO_PLAYER_HEIGHT");
delete_option("PRO_PLAYER_TYPE");
delete_option("PRO_PLAYER_BACKCOLOR");
delete_option("PRO_PLAYER_FRONTCOLOR");
delete_option("PRO_PLAYER_LIGHTCOLOR");
delete_option("PRO_PLAYER_STRETCHING");
delete_option("PRO_PLAYER_SKIN_FILE");
delete_option("PRO_PLAYER_VISUALIZER_SUPPORT");
delete_option("PRO_PLAYER_RATING_SUPPORT");
delete_option("PRO_PLAYER_EMBEDDING_SUPPORT");
delete_option("PRO_PLAYER_SHOW_WATERMARK");
delete_option("PRO_PLAYER_SHOW_DEFAULT_PREVIEW_IMAGE");
delete_option("PRO_PLAYER_DEFAULT_PREVIEW_IMAGE");
delete_option("PRO_PLAYER_REPEAT");
delete_option("PRO_PLAYER_CACHE_TIMEOUT");
delete_option("PRO_PLAYER_AUTO_START");
delete_option('PRO_PLAYER_SUBTITLE_SUPPORT');
delete_option('PRO_PLAYER_SHORTCUT_SUPPORT');
delete_option('PRO_PLAYER_FLOW_VIEW_SUPPORT');
delete_option("PRO_PLAYER_AD_SUPPORT");
delete_option("PRO_PLAYER_AD_CHANNEL");
delete_option("PRO_PLAYER_AD_SCRIPT");
}
function addOptionsPage() {
add_options_page(
"ProPlayer Configuration",
"ProPlayer",
9,
"proplayer/options-page.php"
);
}
function updateOptions($post) {
if (is_array($post)) {
update_option("PRO_PLAYER_WIDTH", $post["proPlayerWidth"]);
update_option("PRO_PLAYER_CACHE_TIMEOUT", $post["proPlayerCacheTimeout"]);
update_option("PRO_PLAYER_HEIGHT", $post["proPlayerHeight"]);
update_option("PRO_PLAYER_TYPE", $post["proPlayerType"]);
update_option("PRO_PLAYER_BACKCOLOR", $post["proPlayerBackColor"]);
update_option("PRO_PLAYER_FRONTCOLOR", $post["proPlayerFrontColor"]);
update_option("PRO_PLAYER_LIGHTCOLOR", $post["proPlayerLightColor"]);
update_option("PRO_PLAYER_STRETCHING", $post["proPlayerStretching"]);
update_option("PRO_PLAYER_SKIN_FILE", $post["proPlayerSkinFile"]);
update_option("PRO_PLAYER_VISUALIZER_SUPPORT", isset($post["proPlayerVisualizerSupport"]) ? $post["proPlayerVisualizerSupport"] : "false");
update_option("PRO_PLAYER_RATING_SUPPORT", isset($post["proPlayerRatingSupport"]) ? $post["proPlayerRatingSupport"] : "false");
update_option("PRO_PLAYER_EMBEDDING_SUPPORT", isset($post["proPlayerEmbeddingSupport"]) ? $post["proPlayerEmbeddingSupport"] : "false");
update_option("PRO_PLAYER_SHOW_WATERMARK", isset($post["proPlayerShowWatermark"]) ? $post["proPlayerShowWatermark"] : "false");
update_option("PRO_PLAYER_SHOW_DEFAULT_PREVIEW_IMAGE", isset($post["proPlayerShowDefaultPreviewImage"]) ? $post["proPlayerShowDefaultPreviewImage"] : "false");
update_option("PRO_PLAYER_DEFAULT_PREVIEW_IMAGE", $post["proPlayerDefaultPreviewImage"]);
update_option("PRO_PLAYER_REPEAT", isset($post["proPlayerRepeat"]) ? $post["proPlayerRepeat"] : "false");
update_option("PRO_PLAYER_AUTO_START", isset($post["proPlayerAutoStart"]) ? $post["proPlayerAutoStart"] : "false");
update_option("PRO_PLAYER_AD_SUPPORT", isset($post["proPlayerAdSupport"]) ? $post["proPlayerAdSupport"] : "false");
update_option("PRO_PLAYER_AD_CHANNEL", $post["proPlayerAdChannel"]);
update_option("PRO_PLAYER_AD_SCRIPT", $post["proPlayerAdScript"]);
update_option("PRO_PLAYER_SUBTITLE_SUPPORT", isset($post["proPlayerSubtitleSupport"]) ? $post["proPlayerSubtitleSupport"] : "false");
update_option("PRO_PLAYER_SHORTCUT_SUPPORT", isset($post["proPlayerShortcutSupport"]) ? $post["proPlayerShortcutSupport"] : "false");
update_option("PRO_PLAYER_FLOW_VIEW_SUPPORT", isset($post["proPlayerFlowViewSupport"]) ? $post["proPlayerFlowViewSupport"] : "false");
}
}
function addTinyMCEButton() {
if ( get_user_option("rich_editing") == "true") {
add_filter("mce_external_plugins", array(&$this, "addTinyMCEPlugin"));
add_filter("mce_buttons", array(&$this, "registerTinyMCEButton"));
}
}
function quickTagButtonAction() {
?>
<script type="text/javascript">
function proPlayerQuickTagAction(querystr) {
var content = document.getElementById('content');
var prefix = content.value.substring(0, content.selectionStart);
var selection = content.value.substring(content.selectionStart, content.selectionEnd);
var suffix = content.value.substring(content.selectionEnd);
if (selection != "") {
content.value = prefix + "[pro-player]" + selection + "[/pro-player]" + suffix;
} else {
alert("Please, select the URL string and then click!")
}
return false;
}
var ed_toolbar = document.getElementById("ed_toolbar");
if (ed_toolbar) {
var theButton = document.createElement('input');
theButton.type = 'button';
theButton.value = 'ProPlayer';
theButton.onclick = proPlayerQuickTagAction;
theButton.className = 'ed_button';
theButton.title = 'ProPlayer!';
theButton.id = 'ed_ProPlayer';
ed_toolbar.appendChild(theButton);
}
</script>
<?php
}
function registerTinyMCEButton($buttons) {
array_push($buttons, "separator", "proPlayer");
return $buttons;
}
function addTinyMCEPlugin($plugin_array) {
$plugin_array["proPlayer"] = $this->PLUGIN_URL."/tinymce/editor_plugin.js";
return $plugin_array;
}
function installDatabase() {
global $wpdb;
$cacheTable = $wpdb->prefix."proplayer";
$playlistTable = $wpdb->prefix."proplayer_playlist";
$wpdb->query("DROP TABLE IF EXISTS ".$cacheTable);
$wpdb->query("DROP TABLE IF EXISTS ".$playlistTable);
$sql = "CREATE TABLE ".$cacheTable." (
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
VIDEO_SOURCE VARCHAR(255) NOT NULL,
VIDEO_ID VARCHAR(100) NOT NULL,
VIDEO_URL TEXT NOT NULL,
PREVIEW_IMAGE TEXT,
TITLE VARCHAR(255) NOT NULL,
CREATION_DATE DATETIME NOT NULL
);
CREATE TABLE ".$playlistTable." (
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
POST_ID VARCHAR(50) NOT NULL,
PLAYLIST TEXT NOT NULL
);
";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("PRO_PLAYER_DB_VERSION", "1.1");
}
}
}
function insert_proplayer($attrs = array(), $content = '') {
$proPlayer = new ProPlayer();
return $proPlayer->constructSnippet($attrs, $content);
}
$proPlayer = new ProPlayer();
// add plugin actions
add_action("wp_head", array(&$proPlayer, "addHeaderCode"), 1);
add_shortcode('pro-player', array(&$proPlayer, "constructSnippet"));
// register option hooks
register_activation_hook(__FILE__, array(&$proPlayer, "addOptions"));
register_activation_hook(__FILE__,array(&$proPlayer, "installDatabase"));
register_deactivation_hook(__FILE__, array(&$proPlayer, "removeOptions"));
// add options page
add_action("admin_menu", array(&$proPlayer, "addOptionsPage"));
// add tinymce buttons
add_action("init", array(&$proPlayer, "addTinyMCEButton"));
add_filter("admin_footer", array(&$proPlayer, "quickTagButtonAction"));
?>