1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
This program is distributed in the hope that it will be useful, |
7
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
8
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @category Module |
13
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
14
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
15
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use Xmf\Request; |
|
|
|
|
19
|
|
|
use XoopsModules\Suico\{ |
20
|
|
|
VideoHandler |
21
|
|
|
}; |
22
|
|
|
|
23
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'suico_index.tpl'; |
24
|
|
|
require __DIR__ . '/header.php'; |
25
|
|
|
//require_once __DIR__ . '/class/Video.php'; |
26
|
|
|
/** |
27
|
|
|
* Factory of pictures created |
28
|
|
|
*/ |
29
|
|
|
$videoFactory = new VideoHandler($xoopsDB); |
30
|
|
|
$url = Request::getUrl('videourl', '', 'POST'); |
31
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
32
|
|
|
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED); |
33
|
|
|
} |
34
|
|
|
/** |
35
|
|
|
* Try to upload picture resize it insert in database and then redirect to index |
36
|
|
|
*/ |
37
|
|
|
$newvideo = $videoFactory->create( |
38
|
|
|
true |
39
|
|
|
); |
40
|
|
|
$newvideo->setVar('uid_owner', (int)$xoopsUser->getVar('uid')); |
41
|
|
|
$newvideo->setVar('video_title', Request::getString('title', '', 'POST')); |
42
|
|
|
$newvideo->setVar('video_desc', Request::getString('caption', '', 'POST')); |
43
|
|
|
|
44
|
|
|
if (11 === mb_strlen($url)) { |
45
|
|
|
$code = $url; |
46
|
|
|
} else { |
47
|
|
|
//Get youtube video id |
48
|
|
|
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); |
49
|
|
|
$code = $match[1]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$newvideo->setVar('youtube_code', $code); |
53
|
|
|
$newvideo->setVar('featured_video', Request::getInt('featured_video', 0, 'POST')); |
54
|
|
|
$newvideo->setVar('date_created', \time()); |
55
|
|
|
$newvideo->setVar('date_updated', \time()); |
56
|
|
|
$videoFactory->insert($newvideo); |
57
|
|
|
$insertId = $xoopsDB->getInsertId(); |
58
|
|
|
if ($videoFactory->insert($newvideo)) { |
59
|
|
|
$extra_tags['X_OWNER_NAME'] = $xoopsUser->getVar('uname'); |
60
|
|
|
$extra_tags['X_OWNER_UID'] = (int)$xoopsUser->getVar('uid'); |
61
|
|
|
/** @var \XoopsNotificationHandler $notificationHandler */ |
62
|
|
|
$notificationHandler = xoops_getHandler('notification'); |
63
|
|
|
$notificationHandler->triggerEvent('video', (int)$xoopsUser->getVar('uid'), 'new_video', $extra_tags); |
64
|
|
|
redirect_header( |
65
|
|
|
XOOPS_URL . '/modules/suico/videos.php?uid=' . (int)$xoopsUser->getVar('uid') . '#' . $insertId, |
66
|
|
|
2, |
67
|
|
|
_MD_SUICO_VIDEOSAVED |
68
|
|
|
); |
69
|
|
|
} else { |
70
|
|
|
redirect_header( |
71
|
|
|
XOOPS_URL . '/modules/suico/videos.php?uid=' . (int)$xoopsUser->getVar('uid'), |
72
|
|
|
2, |
73
|
|
|
_MD_SUICO_ERROR |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
require \dirname(__DIR__, 2) . '/footer.php'; |
77
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: