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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
function save_sexhack_video_forms( $post_id)
{
// Verify that the nonce is set and valid.
if ((!isset( $_POST['sh_video_description_nonce']) || !wp_verify_nonce( $_POST['sh_video_description_nonce'], 'video_description_nonce' ))
&& (!isset( $_POST['sh_editvideo_nonce']) || !wp_verify_nonce( $_POST['sh_editvideo_nonce'], 'sh_editvideo')))
{
return;
}
$admin=false;
if(isset( $_POST['sh_video_description_nonce']) && wp_verify_nonce( $_POST['sh_video_description_nonce'], 'video_description_nonce' )) $admin=true;
// We need to be executed only when post_type is set...
if(!isset($_POST['post_type'])) return;
// ... ant it's set to sexhack_video
if($_POST['post_type']!='sexhack_video') return;
// ... what if we are saving the wrong post?
if(get_post_type($post_id) != 'sexhack_video') return;
// Make sure we don't get caught in any loop
if($admin) unset($_POST['sh_video_description_nonce']);
if(!$admin) unset($_POST['sh_editvideo_nonce']);
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else { // XXX Add more specific permission for our pages?
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
/* OK, it's safe for us to save the data now. */
// **** VIDEO OBJECT CREACTION **** //
// Make sure that it is set.
if ( ! isset( $_POST['video_description'] ) ) {
return;
}
// Get $video object
$setslug = false;
$newvideo = true;
$video = sh_get_video_from_post($post_id);
if(!$video) sexhack_log("Video object not initialized, new video?? (form passed \"$post_id\" \$post_id");
if(!$video) sexhack_log($video);
if(!$video) $setslug = true;
if(!$video) $newvideo = true;
if(!$video) $video = new SH_Video();
// **** VIDEO OBJECT BASIC SETTINGS **** //
// Set post_id
$video->post_id = $post_id;
// set post
$post = $video->get_post();
// XXX TODO Sanitize inputs!
//
// Title and slug
$video->title = $post->post_title;
if(!$video->slug || $setslug) $video->slug = uniqidReal()."-".$post->post_name;
// Model
if($admin) {
if(array_key_exists('video_model', $_POST) && is_numeric($_POST['video_model']) && intval($_POST['video_model']) > 0)
$video->user_id = intval($_POST['video_model']);
} else {
$video->user_id = get_current_user_id();
}
// Video description
$video->description = sanitize_text_field( $_POST['video_description'] );
// Save video status as "creating" to get video id
if($newvideo)
{
$video->status = "creating";
$video = sh_save_video($video, 'FORM');
}
// Video status
$validstatuses = array('creating','uploading','queue','processing','ready','published','error');
if(array_key_exists('video_status', $_POST) && in_array(sanitize_text_field($_POST['video_status']), $validstatuses))
$video->status = sanitize_text_field($_POST['video_status']);
else if(!$admin) $video->status = get_post_status($post_id);
// Video private
if(array_key_exists('video_private', $_POST) && in_array($_POST['video_private'], array('Y','N')))
$video->private = $_POST['video_private'];
// Video visible
if(array_key_exists('video_visible', $_POST) && in_array($_POST['video_visible'], array('Y','N')))
$video->visible = $_POST['video_visible'];
// Video price
if(array_key_exists('video_price', $_POST) && is_numeric($_POST['video_price']) && (floatval($_POST['video_price']) >= 0))
$video->price = floatval($_POST['video_price']);
else $video->price = 0;
// Video type
if(array_key_exists('video_type', $_POST) && in_array($_POST['video_type'], array('VR', 'FLAT')))
$video->video_type = $_POST['video_type'];
// VR Projection
if(array_key_exists('video_vr_projection', $_POST) && in_array($_POST['video_vr_projection'], array('VR180_LR','VR360_LR')))
$video->vr_projection = $_POST['video_vr_projection'];
// **** VIDEO ASSOCIATIVE ARRAYS **** //
// Video Guests
if(array_key_exists('vguests', $_POST) && is_array($_POST['vguests']))
{
foreach($_POST['vguests'] as $guest_id)
{
if(is_numeric($guest_id) && intval($guest_id) > 0)
{
if($admin || (!$admin && intval($guest_id) != get_current_user_id())) {
$guest = get_userdata(intval($guest_id));
if($guest) $video->add_guest($guest);
}
}
}
}
// Make sure the guestss array is initialized
$video->get_guests(false);
// Video Categories
if(array_key_exists('vcategory', $_POST) && is_array($_POST['vcategory']))
{
foreach($_POST['vcategory'] as $cat_id)
{
if(is_numeric($cat_id) && intval($cat_id) > 0)
{
$cat = sh_get_categories(intval($cat_id));
if($cat) $video->add_category($cat);
}
}
}
// Make sure the categories array is initialized
$video->get_categories(false);
// Video Tags
if(array_key_exists('video_tags', $_POST) && is_array($_POST['video_tags']))
{
foreach($_POST['video_tags'] as $tag_name)
{
$tag_name = str_replace("#", "", $tag_name);
$vtags = $video->get_tags(false);
if(sanitize_text_field(strtolower($tag_name)))
{
$tag_name = sanitize_text_field(strtolower($tag_name));
$tag = sh_get_tag_by_name($tag_name, true);
if($tag) $video->add_tag($tag);
}
}
}
// Make sure the tags array is initialized
$video->get_tags(false);
// **** HLS AND DOWNLOAD VIDEO PROCESSING **** //
// Differenciated content for access levels
$public_exist=false;
$members_exists=false;
$selectedv=false;
foreach(array('public','members','premium') as $vt)
{
if(!$admin && array_key_exists('video_'.$vt, $_POST) &&
sanitize_text_field($_POST['video_'.$vt]) && !$selectedv)
{
$selectedv = get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_'.$vt]);
}
// HLS playlist
if($admin &&array_key_exists('video_hls_'.$vt, $_POST) &&
check_url_or_path(sanitize_text_field($_POST['video_hls_'.$vt])) &&
(strncasecmp(strrev(sanitize_text_field($_POST['video_hls_'.$vt])), '8u3m', 4) === 0))
{
$video->__set('hls_'.$vt, sanitize_text_field($_POST['video_hls_'.$vt]));
}
else if(!$admin && array_key_exists('video_'.$vt, $_POST) &&
sanitize_text_field($_POST['video_'.$vt]))
{
//$video->__set('hls_'.$vt, get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_'.$vt]));
sh_add_video_job($video->id, 'process_hls_'.$vt, get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_'.$vt]));
if($vt=='public') $public_exists=true;
if($vt=='members')
{
$members_exists=true;
if(array_key_exists('video_createPublic_'.$vt, $_POST) &&
array_key_exists('video_createPublicStart_'.$vt, $_POST) &&
\DateTime::createFromFormat('H:i:s',$_POST['video_createPublicStart_'.$vt]) &&
array_key_exists('video_createPublicDuration_'.$vt, $_POST) &&
is_numeric($_POST['video_createPublicDuration_'.$vt]) && intval($_POST['video_createPublicDuration_'.$vt]) > 0 &&
in_array($_POST['video_createPublic_'.$vt], array('Y','N')) && !$public_exists)
{
$file=get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_'.$vt]);
$start=$_POST['video_createPublicStart_'.$vt];
$duration=$_POST['video_createPublicDuration_'.$vt];
sh_add_video_job($video->id, 'create_hls_public', json_encode(array('file' => $file, 'start' => $start, 'duration' => $duration )));
$public_exists=true;
}
}
if($vt=='premium')
{
if(array_key_exists('video_createPublic_'.$vt, $_POST) &&
array_key_exists('video_createPublicStart_'.$vt, $_POST) &&
\DateTime::createFromFormat('H:i:s',$_POST['video_createPublicStart_'.$vt]) &&
array_key_exists('video_createPublicDuration_'.$vt, $_POST) &&
is_numeric($_POST['video_createPublicDuration_'.$vt]) && intval($_POST['video_createPublicDuration_'.$vt]) > 0 &&
in_array($_POST['video_createPublic_'.$vt], array('Y','N')) && !$public_exists)
{
$file=get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_'.$vt]);
$start=$_POST['video_createPublicStart_'.$vt];
$duration=$_POST['video_createPublicDuration_'.$vt];
sh_add_video_job($video->id, 'create_hls_public', json_encode(array('file' => $file, 'start' => $start, 'duration' => $duration )));
$public_exists=true;
}
if(array_key_exists('video_createMembers_'.$vt, $_POST) &&
array_key_exists('video_createMembersStart_'.$vt, $_POST) &&
\DateTime::createFromFormat('H:i:s',$_POST['video_createMembersStart_'.$vt]) &&
array_key_exists('video_createMembersDuration_'.$vt, $_POST) &&
is_numeric($_POST['video_createMembersDuration_'.$vt]) && intval($_POST['video_createMembersDuration_'.$vt]) > 0 &&
in_array($_POST['video_createMembers_'.$vt], array('Y','N')) && !$members_exists)
{
$file=get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_'.$vt]);
$start=$_POST['video_createMembersStart_'.$vt];
$duration=$_POST['video_createMembersDuration_'.$vt];
sh_add_video_job($video->id, 'create_hls_members', json_encode(array('file' => $file, 'start' => $start, 'duration' => $duration )));
$members_exists=true;
}
}
$video->__set('hls_'.$vt, false);
}
else $video->__set('hls_'.$vt, false);
// Download
if($admin && array_key_exists('video_download_'.$vt, $_POST) &&
check_url_or_path(sanitize_text_field($_POST['video_download_'.$vt])))
{
$video->__set('download_'.$vt, sanitize_text_field($_POST['video_download_'.$vt]));
}
else if(!$admin && array_key_exists($vt.'_isdownload', $_POST) &&
in_array($_POST[$vt.'_isdownload'], array('Y','N')) && array_key_exists('video_'.$vt, $_POST) &&
sanitize_text_field($_POST['video_'.$vt]))
{
//$video->__set('download_'.$vt, get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_'.$vt]));
sh_add_video_job($video->id, 'process_download_'.$vt, get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_'.$vt]));
}
else $video->__set('download_'.$vt, false);
// Text only data
if($admin) {
foreach(array('size','format','codec','acodec','duration','resolution') as $key)
{
if(array_key_exists('video_'.$key.'_'.$vt, $_POST) &&
sanitize_text_field($_POST['video_'.$key.'_'.$vt]))
{
$video->__set($key.'_'.$vt, sanitize_text_field($_POST['video_'.$key.'_'.$vt]));
} else $video->__set($key.'_'.$vt, false);
}
}
}
// **** VIDEO EXTRACTIONS PROPERTIES (XXX those NEEDS to be AFTER video processing) **** //
// Video thumbnail
if($admin) {
if(array_key_exists('video_thumbnail', $_POST) && sanitize_text_field($_POST['video_thumbnail']))
$video->thumbnail = sanitize_text_field( $_POST['video_thumbnail'] );
else if(array_key_exists('_thumbnail_id', $_POST)
&& is_numeric($_POST['_thumbnail_id'])
&& intval($_POST['_thumbnail_id']) > 0)
{
$video->thumbnail = intval($_POST['_thumbnail_id']);
}
else
$video->thumbnail = false;
} else {
// Shoudn't we move it somewhere?
if(isset($_POST['video_thumb'])
&& !empty($_POST['video_thumb']))
{
//$video->thumbnail = get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_thumb']);
sh_add_video_job($video->id, 'process_thumb', get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_thumb']));
$video->thumbnail = false;
}
else
{
if($selectedv) sh_add_video_job($video->id, 'create_thumb', $selectedv);
$video->thumbnail = false;
}
}
// Animated gif path
if($admin && array_key_exists('video_gif', $_POST) && check_url_or_path(sanitize_text_field($_POST['video_gif'])))
$video->gif = sanitize_text_field($_POST['video_gif']);
elseif(!$admin && array_key_exists('video_gif', $_POST) &&
sanitize_text_field($_POST['video_gif']))
{
//$video->gif = sanitize_text_field(get_option('sexhack_video_tmp_path', '/tmp')."/".$_POST['video_gif']);
sh_add_video_job($video->id, 'process_gif', get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_gif']));
$video->gif = false;
}
elseif(!$admin &&
array_key_exists('video_createStart_gif', $_POST) &&
\DateTime::createFromFormat('H:i:s',$_POST['video_createStart_gif']) &&
array_key_exists('video_createDuration_gif', $_POST) &&
is_numeric($_POST['video_createDuration_gif']) && intval($_POST['video_createDuration_gif']) > 0 &&
array_key_exists('video_createFPS_gif', $_POST) &&
is_numeric($_POST['video_createFPS_gif']) && intval($_POST['video_createFPS_gif']) > 0 )
{
$duration=$_POST['video_createDuration_gif'];
$start=$_POST['video_createStart_gif'];
$fps=$_POST['video_createFPS_gif'];
sh_add_video_job($video->id, 'create_gif', json_encode(array('start' => $start, 'fps' => $fps, 'duration' => $duration, 'file' => $selectedv )));
$video->gif = false;
}
else
$video->gif = false;
// Small Animated gif path
if($admin && array_key_exists('video_gif_small', $_POST) && check_url_or_path(sanitize_text_field($_POST['video_gif_small'])))
$video->gif_small = sanitize_text_field($_POST['video_gif_small']);
elseif(!$admin && array_key_exists('video_gif_small', $_POST) &&
sanitize_text_field($_POST['video_gif_small']))
{
//$video->gif_small = sanitize_text_field(get_option('sexhack_video_tmp_path', '/tmp')."/".$_POST['video_gif_small']);
sh_add_video_job($video->id, 'process_gif_small', get_option('sexhack_video_tmp_path', '/tmp')."/".sanitize_text_field($_POST['video_gif_small']));
$video->gif_small = false;
}
elseif(!$admin &&
array_key_exists('video_createStart_gif_small', $_POST) &&
\DateTime::createFromFormat('H:i:s',$_POST['video_createStart_gif_small']) &&
array_key_exists('video_createDuration_gif_small', $_POST) &&
is_numeric($_POST['video_createDuration_gif_small']) && intval($_POST['video_createDuration_gif_small']) > 0 &&
array_key_exists('video_createFPS_gif_small', $_POST) &&
is_numeric($_POST['video_createFPS_gif_small']) && intval($_POST['video_createFPS_gif_small']) > 0 )
{
$duration=$_POST['video_createDuration_gif_small'];
$start=$_POST['video_createStart_gif_small'];
$fps=$_POST['video_createFPS_gif_small'];
sh_add_video_job($video->id, 'create_gif_small', json_encode(array('start' => $start, 'fps' => $fps, 'duration' => $duration, 'file' => $selectedv )));
$video->gif_small = false;
}
else
$video->gif_small = false;
// Preview video
if($admin && array_key_exists('video_preview', $_POST) && check_url_or_path(sanitize_text_field($_POST['video_preview'])))
$video->preview = sanitize_text_field($_POST['video_preview']);
elseif(!$admin && array_key_exists('video_preview', $_POST) &&
sanitize_text_field($_POST['video_preview']))
{
//$video->preview = sanitize_text_field(get_option('sexhack_video_tmp_path', '/tmp')."/".$_POST['video_preview']);
sh_add_video_job($video->id, 'process_preview', sanitize_text_field(get_option('sexhack_video_tmp_path', '/tmp')."/".$_POST['video_preview']));
}
else
$video->preview = false;
// Socialpost
if(!$admin)
{
//sh_add_video_job($video->id, 'socialpost_text'); // Not needed. shmproc will give you the text to do if it doesn't exists already
sh_add_video_job($video->id, 'socialpost_media', $selectedv);
}
// Save the video data in the database.
//sexhack_log("SAVING VIDEO FROM FORM");
//sexhack_log($video);
sh_save_video($video, 'FORM');
}
?>