1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* wgFileManager module for xoops |
17
|
|
|
* |
18
|
|
|
* @copyright 2021 XOOPS Project (https://xoops.org) |
19
|
|
|
* @license GPL 2.0 or later |
20
|
|
|
* @package wgfilemanager |
21
|
|
|
* @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
//use XoopsModules\Wgfilemanager; |
25
|
|
|
use XoopsModules\Wgfilemanager\Helper; |
26
|
|
|
//use XoopsModules\Wgfilemanager\Constants; |
27
|
|
|
use Xmf\Request; |
|
|
|
|
28
|
|
|
|
29
|
|
|
require_once \XOOPS_ROOT_PATH . '/modules/wgfilemanager/include/common.php'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Function show block |
33
|
|
|
* @param $options |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
function b_wgfilemanager_directory_show($options) |
37
|
|
|
{ |
38
|
|
|
$block = []; |
39
|
|
|
$typeBlock = $options[0]; |
40
|
|
|
$limit = $options[1]; |
41
|
|
|
$lengthName = $options[2]; |
42
|
|
|
$helper = Helper::getInstance(); |
43
|
|
|
$directoryHandler = $helper->getHandler('Directory'); |
44
|
|
|
$crDirectory = new \CriteriaCompo(); |
45
|
|
|
\array_shift($options); |
46
|
|
|
\array_shift($options); |
47
|
|
|
\array_shift($options); |
48
|
|
|
|
49
|
|
|
switch ($typeBlock) { |
50
|
|
|
case 'last': |
51
|
|
|
default: |
52
|
|
|
// For the block: directory last |
53
|
|
|
$crDirectory->setSort('date_created'); |
54
|
|
|
$crDirectory->setOrder('DESC'); |
55
|
|
|
break; |
56
|
|
|
case 'new': |
57
|
|
|
// For the block: directory new |
58
|
|
|
// new since last week: 7 * 24 * 60 * 60 = 604800 |
59
|
|
|
$crDirectory->add(new \Criteria('date_created', \time() - 604800, '>=')); |
60
|
|
|
$crDirectory->add(new \Criteria('date_created', \time(), '<=')); |
61
|
|
|
$crDirectory->setSort('date_created'); |
62
|
|
|
$crDirectory->setOrder('ASC'); |
63
|
|
|
break; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$crDirectory->setLimit($limit); |
67
|
|
|
$directoryAll = $directoryHandler->getAll($crDirectory); |
68
|
|
|
unset($crDirectory); |
69
|
|
|
if (\count($directoryAll) > 0) { |
70
|
|
|
foreach (\array_keys($directoryAll) as $i) { |
71
|
|
|
$block[$i]['id'] = $directoryAll[$i]->getVar('id'); |
72
|
|
|
$nameShort = \htmlspecialchars($directoryAll[$i]->getVar('name'), ENT_QUOTES | ENT_HTML5); |
73
|
|
|
if ($lengthName > 0) { |
74
|
|
|
$nameShort = \substr($nameShort, 0, (int)$lengthName); |
75
|
|
|
} |
76
|
|
|
$block[$i]['name'] = $nameShort; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
$GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL); |
80
|
|
|
return $block; |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Function edit block |
86
|
|
|
* @param $options |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
function b_wgfilemanager_directory_edit($options) |
90
|
|
|
{ |
91
|
|
|
$GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL); |
92
|
|
|
$form = "<input type='hidden' name='options[0]' value='".$options[0]."' >"; |
93
|
|
|
$form .= \_MB_WGFILEMANAGER_DISPLAY . " : <input type='text' name='options[1]' size='5' maxlength='255' value='" . $options[1] . "' > <br>"; |
94
|
|
|
$form .= \_MB_WGFILEMANAGER_NAME_LENGTH . " : <input type='text' name='options[2]' size='5' maxlength='255' value='" . $options[2] . "' ><br><br>"; |
95
|
|
|
|
96
|
|
|
return $form; |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
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: