Passed
Push — master ( a42092...8afea9 )
by Goffy
03:23
created

b_wgfilemanager_directory_show()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 45
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 34
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 45
rs 8.7537
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;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/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 before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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] . "' >&nbsp;<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