This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
/
page-add-new.php
258 lines (210 loc) · 8.89 KB
/
page-add-new.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
<?php
global $wpdb;
$info = '';
$videoName = (isset($_POST['name'])) ? $_POST['name'] : 'VideoStir clip';
$embed = (isset($_POST['embed'])) ? stripslashes($_POST['embed']) : '';
function generateParamsForEmbedLine($hash,&$errorMessages)
{
$allData = array();
$params = array();
$position = array();
$position['bottom']='0';
$position['right']='350';
$allData['position'] = $position;
$allData['width'] = '448';
$allData['height'] = '252';
$allData['url'] = $hash;
if (!ctype_alnum($allData['url']) || strlen($allData['url']) !== 32) {
$errorMessages[] = 'Clip ID is not valid.';
}
$params['auto-play']='true';
$params['auto-play-limit']='10';
$params['playback-delay']='0';
$params['on-finish']='play-button';
$params['on-click-open-url']='';
$params['extrab']='2';
$allData['settings'] = $params;
return $allData;
}
if (isset($_POST['apply'])) {
$errorMessages = array();
$matches = array();
if (strlen($embed) < 16) {
$errorMessages[] = 'Code is empty.';
} else {
preg_match('/\<script\>\s*VS\.Player\.show\((.+)\);\s*\<\/script\>/s', $embed, $matches);
}
$embedHash=false;
$newEmbedHash = false;
if (!count($matches) ) // if it's not regular embed code
{
$pos=strstr($embed,'vsembed.js');
if ($pos)
{
$embedHash = substr($embed,strlen($embed)-41,32);
}
}
if (!count($matches) ) // if it's not regular embed code
{
$pos=strstr($embed,'videostir.start');
if ($pos)
{
$pos = strrpos($embed,'videoHash=');
$newEmbedHash = substr($embed,$pos+11,32);
}
}
//var_dump($matches);
//exit();
$playerParams = array();
if (count($matches)) {
$settings = $matches[1];
preg_match('/(".+"|{.+})\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*"(\w+)"\s*,\s*({.+})/s', $settings, $matches);
if (count($matches) != 6) {
$errorMessages[] = 'Unknown format for "VS.Player".';
}
$playerParams['position'] = $matches[1];
if ($playerParams['position'][0] != '"') {
$playerParams['position'] = json_decode($playerParams['position'], true);
if ($playerParams['position'] == null) {
$errorMessages[] = 'Error parsing position object.';
}
}
$playerParams['width'] = $matches[2];
$playerParams['height'] = $matches[3];
$playerParams['url'] = $matches[4];
if (!ctype_alnum($playerParams['url']) || strlen($playerParams['url']) !== 32) {
$errorMessages[] = 'Clip ID is not valid.';
}
$playerParams['settings'] = json_decode($matches[5], true);
if ($playerParams['settings'] == null) {
$errorMessages[] = 'Error parsing special parameters.';
}
}
else if ($embedHash)
{
// $params = array();
// $position = array();
// $position['bottom']='0';
// $position['right']='350';
// $playerParams['position'] = $position;
// $playerParams['width'] = '448';
// $playerParams['height'] = '252';
// $playerParams['url'] = $embedHash;
// if (!ctype_alnum($playerParams['url']) || strlen($playerParams['url']) !== 32) {
// $errorMessages[] = 'Clip ID is not valid.';
// }
// $params['auto-play']='true';
// $params['auto-play-limit']='10';
// $params['playback-delay']='0';
// $params['on-finish']='play-button';
// $params['on-click-open-url']='';
// $params['extrab']='2';
// $playerParams['settings'] = $params;
$playerParams = generateParamsForEmbedLine($embedHash,$errorMessages);
}
else if ($newEmbedHash)
{
$playerParams = generateParamsForEmbedLine($newEmbedHash,$errorMessages);
//var_dump($playerParams);
}
if (!count($errorMessages)) {
$sql = $wpdb->prepare('
INSERT INTO `'.VideoStir::getTableName().'`
(
`name`
, `pages`
, `active`
, `position`
, `width`
, `height`
, `url`
, `settings`
) VALUES (
%s
, %s
, %d
, %s
, %d
, %d
, %s
, %s
)',
$videoName
, ''
, 1
, ''
, $playerParams['width']
, $playerParams['height']
, $playerParams['url']
, ''
);
$wpdb->query($sql);
?>
<div style="margin-bottom: 15px;" class="updated">
<div class="spacer-05"> </div>
Has added a new video.<br/>
Redirect to edit.
<div class="spacer-05"> </div>
</div>
<script type="text/javascript">
<!--
window.location = "<?php echo get_bloginfo('url').'/wp-admin/admin.php?page=videostir_options_sub&action=edit&id='.$wpdb->insert_id; ?> "
//-->
</script>
<?php
} else {
$info['type'] = 'Error';
$info['text'] = 'Please paste the correct code.<br/>'.implode('<br/>', $errorMessages);
}
}
?>
<?php include 'css-script.php'; ?>
<div class="wrap">
<h2><img class="logo" src="<?php echo $this->logo; ?>" alt="VideoStir" /> Add new video</h2>
<?php if ($info != '') { ?>
<div style="margin-bottom: 15px; color: #c00;" class="messages <?php echo $info['type']; ?>">
<div class="spacer-05"> </div>
<?php echo $info['text']; ?>
<div class="spacer-05"> </div>
</div>
<?php } ?>
<div id="poststuff" class="metabox-holder">
<div style="width: 60%;float: left;">
<div id="formdiv" class="postbox " style=" box-shadow: 0 5px 15px rgba(0,0,0,0.15);border: 1px solid rgba(0,0,0,0.25);padding: 20px" >
<h2 style="margin: 10px 0 0px;">INSTRUCTIONS</h2>
<ol>
<li>In the textbox below, paste the Embed Line you got from <a href="http://videostir.com/?page=wp-instructions">videostir.com</a> after transforming your video into a floating clip (or use one from our <a target="_blank" href="http://videostir.com/clips-stock/try-a-free-clip?page=wp-market">clip market</a>).</li>
<li>Click “Next”.</li>
<li>You can now give your clip a name, adjust its customization parameters to suit your preferences, and choose in which pages/posts your clip will appear.</li>
<li>Click “Apply”.</li>
</ol>
</div>
<div id="formdiv" class="postbox " style=" box-shadow: 0 5px 15px rgba(0,0,0,0.15);border: 1px solid rgba(0,0,0,0.25);" >
<div class="inside">
<form method="post" action="" onsubmit="return videostirValidateNewVideo();">
<h2 style="margin: 10px 0 0px;">ADD A NEW CLIP TO YOUR WORDPRESS SITE</h2>
<br/>
<label>Name<br/><input id="name" name="name" value="<?php echo $videoName; ?>" /></label>
<div class="spacer-5"> </div>
<label>Paste embed code here:<br/><textarea style="width: 100%;" rows="4" id="embed" name="embed"><?php echo stripslashes($embed); ?></textarea></label>
<p style="text-align: right;">
<!-- <button type="button" class="nbutton" onclick="window.open('http://videostir.com/video/download/1')">HELP</button>-->
<button type="button" class="nbutton effect3" onclick="window.location='<?php echo get_bloginfo('url').'/wp-admin/admin.php?page=videostir_options' ?>'">CANCEL</button>
<button type="submit" class="nbutton" ><strong>NEXT</strong></button>
<input type="hidden" name="apply" />
</p>
</form>
</div>
</div>
<div id="formdiv" class="postbox" style=" box-shadow: 0 5px 15px rgba(0,0,0,0.15);border: 1px solid rgba(0,0,0,0.25);">
<h3 style="cursor: default;">Tutorial — How to use this plugin</h3>
<iframe title="YouTube video player" class="youtube-player" type="text/html" width="100%" height="550" src="http://www.youtube.com/embed/_jmNZoMLFlc?theme=light&color=white&showinfo=0&controls=1&wmode=transparent&rel=0" frameborder="0" allowFullScreen></iframe>
</div>
</div>
<div style="width: 3%; float: left;"> </div>
<div style="width: 37%;float: left;">
<?php include 'rigth-bar.php'; ?>
</div>
</div>
<br class="clear">
</div>