b_sitemap_lexikon()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
nc 4
nop 0
dl 0
loc 29
rs 9.6333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * sitemap-plugin
5
 * version 1.5
6
 */
7
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
8
9
/**
10
 * @return array
11
 */
12
function b_sitemap_lexikon()
13
{
14
    $db   = \XoopsDatabaseFactory::getDatabaseConnection();
15
    $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
16
17
    // Permission
18
    global $xoopsUser;
19
    /** @var \XoopsGroupPermHandler $grouppermHandler */
20
    $grouppermHandler = xoops_getHandler('groupperm');
21
    $groups           = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
22
    /** @var \XoopsModuleHandler $moduleHandler */
23
    $moduleHandler = xoops_getHandler('module');
24
    $module        = $moduleHandler->getByDirname('lexikon');
25
    $module_id     = $module->getVar('mid');
26
    $allowed_cats  = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id);
27
    $catids        = implode(',', $allowed_cats);
28
    $catperms      = " WHERE categoryID IN ($catids) ";
29
    $result        = $db->query('SELECT categoryID, name FROM ' . $db->prefix('lxcategories') . ' ' . $catperms . ' ORDER BY weight');
30
31
    $ret = [];
32
    while (list($id, $name) = $db->fetchRow($result)) {
33
        $ret['parent'][] = [
34
            'id'    => $id,
35
            'title' => htmlspecialchars($name, ENT_QUOTES | ENT_HTML5),
36
            'url'   => "category.php?categoryID=$id",
37
        ];
38
    }
39
40
    return $ret;
41
}
42