XoopsModules25x /
suico
| 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 | |||
| 7 | This program is distributed in the hope that it will be useful, |
||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @category Module |
||
| 14 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 15 | * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 16 | * @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
||
| 17 | */ |
||
| 18 | |||
| 19 | use Xmf\Request; |
||
|
0 ignored issues
–
show
|
|||
| 20 | use XoopsModules\Suico\{ |
||
| 21 | AudioHandler |
||
| 22 | }; |
||
| 23 | |||
| 24 | require __DIR__ . '/header.php'; |
||
| 25 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
| 26 | redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED); |
||
| 27 | } |
||
| 28 | /** |
||
| 29 | * Receiving info from get parameters |
||
| 30 | */ |
||
| 31 | $cod_audio = Request::getString('cod_audio', '', 'POST'); |
||
| 32 | if (!isset($_POST['confirm']) || 1 !== Request::getInt('confirm', 0, 'POST')) { |
||
| 33 | xoops_confirm( |
||
| 34 | [ |
||
| 35 | 'cod_audio' => $cod_audio, |
||
| 36 | 'confirm' => 1, |
||
| 37 | ], |
||
| 38 | 'delaudio.php', |
||
| 39 | _MD_SUICO_AUDIO_DELETE_CONFIRM_ASK, |
||
| 40 | _MD_SUICO_AUDIO_DELETE_CONFIRM |
||
| 41 | ); |
||
| 42 | } else { |
||
| 43 | /** |
||
| 44 | * Creating the factory and the criteria to delete the picture |
||
| 45 | * The user must be the owner |
||
| 46 | */ |
||
| 47 | $audioFactory = new AudioHandler( |
||
| 48 | $xoopsDB |
||
| 49 | ); |
||
| 50 | $criteria_aud = new Criteria('audio_id', $cod_audio); |
||
| 51 | $uid = (int)$xoopsUser->getVar('uid'); |
||
| 52 | $criteriaUid = new Criteria('uid_owner', $uid); |
||
| 53 | $criteria = new CriteriaCompo($criteria_aud); |
||
| 54 | $criteria->add($criteriaUid); |
||
| 55 | $objects_array = $audioFactory->getObjects($criteria); |
||
| 56 | $audio_name = $objects_array[0]->getVar('filename'); |
||
| 57 | /** |
||
| 58 | * Try to delete |
||
| 59 | */ |
||
| 60 | if ($audioFactory->deleteAll($criteria)) { |
||
| 61 | unlink(XOOPS_ROOT_PATH . '/uploads/suico/audio/' . $audio_name); |
||
| 62 | redirect_header('audios.php', 2, _MD_SUICO_AUDIO_DELETED); |
||
| 63 | } else { |
||
| 64 | redirect_header('audios.php', 2, _MD_SUICO_ERROR); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | require \dirname(__DIR__, 2) . '/footer.php'; |
||
| 68 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: