XoopsModules25x /
news
| 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 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 14 | * @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
||
| 15 | * @author XOOPS Development Team |
||
| 16 | */ |
||
| 17 | |||
| 18 | use Xmf\Request; |
||
|
0 ignored issues
–
show
|
|||
| 19 | use XoopsModules\News\{ |
||
| 20 | Files, |
||
| 21 | NewsStory |
||
| 22 | }; |
||
| 23 | |||
| 24 | require_once \dirname(__DIR__, 2) . '/mainfile.php'; |
||
| 25 | // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php'; |
||
| 26 | // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
||
| 27 | |||
| 28 | $fileid = Request::getInt('fileid', 0, 'GET'); |
||
| 29 | if (empty($fileid)) { |
||
| 30 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _ERRORS); |
||
| 31 | } |
||
| 32 | $myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object |
||
| 33 | $sfiles = new Files($fileid); |
||
| 34 | |||
| 35 | // Do we have the right to see the file ? |
||
| 36 | $article = new NewsStory($sfiles->getStoryid()); |
||
| 37 | // and the news, can we see it ? |
||
| 38 | if (0 == $article->published() || $article->published() > time()) { |
||
| 39 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY); |
||
| 40 | } |
||
| 41 | // Expired |
||
| 42 | if (0 != $article->expired() && $article->expired() < time()) { |
||
| 43 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 47 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 48 | if (is_object($xoopsUser)) { |
||
| 49 | $groups = $xoopsUser->getGroups(); |
||
| 50 | } else { |
||
| 51 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
| 52 | } |
||
| 53 | if (!$grouppermHandler->checkRight('news_view', $article->topicid(), $groups, $xoopsModule->getVar('mid'))) { |
||
| 54 | redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); |
||
| 55 | } |
||
| 56 | |||
| 57 | $sfiles->updateCounter(); |
||
| 58 | $url = XOOPS_UPLOAD_URL . '/' . $sfiles->getDownloadname(); |
||
| 59 | if (!preg_match('/^ed2k*:\/\//i', $url)) { |
||
| 60 | header("Location: $url"); |
||
| 61 | } |
||
| 62 | echo '<html><head><meta http-equiv="Refresh" content="0; URL=' . htmlspecialchars($url, ENT_QUOTES | ENT_HTML5) . '"></meta></head><body></body></html>'; |
||
| 63 | exit(); |
||
| 64 |
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: