Passed
Push — master ( ce3679...0e4f1a )
by Goffy
03:09
created

b_wgfilemanager_dirlist_show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
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_dirlist_show($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

36
function b_wgfilemanager_dirlist_show(/** @scrutinizer ignore-unused */ $options)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
{
38
    $block       = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
39
    $helper      = Helper::getInstance();
40
    $directoryHandler = $helper->getHandler('Directory');
41
42
    $dirId = Request::getInt('dir_id', 1);
43
44
    //get directory list
45
    $block = $directoryHandler->getDirList(0, $dirId);
46
    $GLOBALS['xoopsTpl']->assign('dir_list', $block);
47
    $GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL);
48
    return $block;
49
50
}
51
52
/**
53
 * Function show block
54
 * @param  $options
55
 * @return array
56
 */
57
function b_wgfilemanager_directory_show($options)
58
{
59
    $block       = [];
60
    $typeBlock   = $options[0];
61
    $limit       = $options[1];
62
    //$lenghtTitle = $options[2];
63
    $helper      = Helper::getInstance();
64
    $directoryHandler = $helper->getHandler('Directory');
65
    $crDirectory = new \CriteriaCompo();
66
    \array_shift($options);
67
    \array_shift($options);
68
    \array_shift($options);
69
70
    switch ($typeBlock) {
71
        case 'last':
72
        default:
73
            // For the block: directory last
74
            $crDirectory->setSort('date_created');
75
            $crDirectory->setOrder('DESC');
76
            break;
77
        case 'new':
78
            // For the block: directory new
79
            // new since last week: 7 * 24 * 60 * 60 = 604800
80
            $crDirectory->add(new \Criteria('date_created', \time() - 604800, '>='));
81
            $crDirectory->add(new \Criteria('date_created', \time(), '<='));
82
            $crDirectory->setSort('date_created');
83
            $crDirectory->setOrder('ASC');
84
            break;
85
    }
86
87
    $crDirectory->setLimit($limit);
88
    $directoryAll = $directoryHandler->getAll($crDirectory);
89
    unset($crDirectory);
90
    if (\count($directoryAll) > 0) {
91
        foreach (\array_keys($directoryAll) as $i) {
92
            /**
93
             * If you want to use the parameter for limits you have to adapt the line where it should be applied
94
             * e.g. change
95
             *     $block[$i]['title'] = $directoryAll[$i]->getVar('art_title');
96
             * into
97
             *     $myTitle = $directoryAll[$i]->getVar('art_title');
98
             *     if ($limit > 0) {
99
             *         $myTitle = \substr($myTitle, 0, (int)$limit);
100
             *     }
101
             *     $block[$i]['title'] =  $myTitle;
102
             */
103
            $block[$i]['id'] = $directoryAll[$i]->getVar('id');
104
            $block[$i]['name'] = \htmlspecialchars($directoryAll[$i]->getVar('name'), ENT_QUOTES | ENT_HTML5);
105
        }
106
    }
107
    $GLOBALS['xoopsTpl']->assign('wgfilemanager_url', \WGFILEMANAGER_URL);
108
    return $block;
109
110
}
111
112
/**
113
 * Function edit block
114
 * @param  $options
115
 * @return string
116
 */
117
function b_wgfilemanager_directory_edit($options)
118
{
119
    $GLOBALS['xoopsTpl']->assign('wgfilemanager_upload_url', \WGFILEMANAGER_UPLOAD_URL);
120
    $form = \_MB_WGFILEMANAGER_DISPLAY . ' : ';
121
    $form .= "<input type='hidden' name='options[0]' value='".$options[0]."' >";
122
    $form .= "<input type='text' name='options[1]' size='5' maxlength='255' value='" . $options[1] . "' >&nbsp;<br>";
123
    $form .= \_MB_WGFILEMANAGER_TITLE_LENGTH . " : <input type='text' name='options[2]' size='5' maxlength='255' value='" . $options[2] . "' ><br><br>";
124
    \array_shift($options);
125
    \array_shift($options);
126
    \array_shift($options);
127
128
    $crDirectory = new \CriteriaCompo();
129
    $crDirectory->add(new \Criteria('id', 0, '!='));
130
    $crDirectory->setSort('id');
131
    $crDirectory->setOrder('ASC');
132
133
    /**
134
     * If you want to filter your results by e.g. a category used in yourdirectory
135
     * then you can activate the following code, but you have to change it according your category
136
     */
137
    /*
138
    $helper = Helper::getInstance();
139
    $directoryHandler = $helper->getHandler('Directory');
140
    $directoryAll = $directoryHandler->getAll($crDirectory);
141
    unset($crDirectory);
142
    $form .= \_MB_WGFILEMANAGER_DIRECTORY_TO_DISPLAY . "<br><select name='options[]' multiple='multiple' size='5'>";
143
    $form .= "<option value='0' " . (!\in_array(0, $options) && !\in_array('0', $options) ? '' : "selected='selected'") . '>' . \_MB_WGFILEMANAGER_ALL_DIRECTORY . '</option>';
144
    foreach (\array_keys($directoryAll) as $i) {
145
        $dir_id = $directoryAll[$i]->getVar('id');
146
        $form .= "<option value='" . $dir_id . "' " . (!\in_array($dir_id, $options) ? '' : "selected='selected'") . '>' . $directoryAll[$i]->getVar('name') . '</option>';
147
    }
148
    $form .= '</select>';
149
150
    */
151
    return $form;
152
153
}
154