about_block_page_edit()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 31
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 31
rs 9.52
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 * About
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright      The XOOPS Co.Ltd. http://www.xoops.com.cn
13
 * @copyright      XOOPS Project (https://xoops.org)
14
 * @license        GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package        about
16
 * @since          1.0.0
17
 * @author         Mengjue Shao <[email protected]>
18
 * @author         Susheng Yang <[email protected]>
19
 */
20
21
use XoopsModules\About\Constants;
22
use XoopsModules\About\Helper;
23
24
/** @var Helper $helper */
25
26
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
27
/**
28
 * @return mixed
29
 */
30
function about_block_menu_show()
31
{
32
    $moduleDirName = basename(dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
33
34
    $helper        = Helper::getInstance();
35
    $pageHandler   = $helper->getHandler('Page');
36
    $menu_criteria = new \CriteriaCompo();
37
    $menu_criteria->add(new \Criteria('page_status', Constants::PUBLISHED), 'AND');
38
    $menu_criteria->add(new \Criteria('page_menu_status', Constants::IN_MENU));
39
    $menu_criteria->setSort('page_order');
40
    $menu_criteria->order = 'ASC';
41
    $fields               = [
42
        'page_id',
43
        'page_menu_title',
44
        'page_blank',
45
        'page_menu_status',
46
        'page_status',
47
    ];
48
    $page_menu            = $pageHandler->getAll($menu_criteria, $fields, false);
49
    foreach ($page_menu as $k => $v) {
50
        $page_menu[$k]['links'] = $helper->url("index.php?page_id={$v['page_id']}");
51
    }
52
53
    return $page_menu;
54
}
55
56
/**
57
 * @param $options
58
 * @return array|bool
59
 */
60
function about_block_page_show($options)
61
{
62
    if (empty($options[0])) {
63
        return false;
64
    }
65
    $moduleDirName = basename(dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
66
    $helper = Helper::getInstance();
67
68
    $myts        = \MyTextSanitizer::getInstance();
69
    $block       = [];
70
    $pageHandler = $helper->getHandler('Page');
71
    $page        = $pageHandler->get($options[0]);
72
    if (!is_object($page)) {
73
        return false;
74
    }
75
    $page_text = strip_tags($page->getVar('page_text', 'n'));
0 ignored issues
show
Bug introduced by
It seems like $page->getVar('page_text', 'n') can also be of type null; however, parameter $string of strip_tags() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

75
    $page_text = strip_tags(/** @scrutinizer ignore-type */ $page->getVar('page_text', 'n'));
Loading history...
76
    if ($options[1] > 0) {
77
        $url        = $helper->url("index.php?page_id={$options[0]}");
78
        $trimmarker = <<<EOF
79
<a href="{$url}" class="more">{$options[2]}</a>
80
EOF;
81
        $page_text  = xoops_substr($page_text, 0, $options[1]) . $trimmarker;
82
    }
83
84
    $block['page_text']  = $myts->nl2br($page_text);
85
    $block['page_image'] = 1 == $options[3] ? $helper->url($page->getVar('page_image', 's')) : '';
0 ignored issues
show
Bug introduced by
It seems like $page->getVar('page_image', 's') can also be of type array and array; however, parameter $url of Xmf\Module\Helper\GenericHelper::url() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

85
    $block['page_image'] = 1 == $options[3] ? $helper->url(/** @scrutinizer ignore-type */ $page->getVar('page_image', 's')) : '';
Loading history...
86
87
    return $block;
88
}
89
90
/**
91
 * @param $options
92
 * @return string
93
 */
94
function about_block_page_edit($options)
95
{
96
    $moduleDirName = basename(dirname(__DIR__));
97
    $helper       = Helper::getInstance();
98
    $options_page = [];
99
100
    $helper->loadLanguage('blocks');
101
    $pageHandler = $helper->getHandler('Page');
102
    $criteria    = new \CriteriaCompo();
103
    $criteria->add(new \Criteria('page_status', Constants::PUBLISHED), 'AND');
104
    $criteria->add(new \Criteria('page_type', Constants::PAGE_TYPE_PAGE));
105
    $criteria->setSort('page_order');
106
    $criteria->order = 'ASC';
107
    $fields          = ['page_id', 'page_title', 'page_image'];
108
    $pages           = $pageHandler->getAll($criteria, $fields, false);
109
    $page_title      = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $page_title is dead and can be removed.
Loading history...
110
    foreach ($pages as $k => $v) {
111
        $page_title       = '<a href="' . $helper->url("index.php?page_id={$k}") . '" target="_blank">' . $v['page_title'] . '</a>';
112
        $options_page[$k] = empty($v['page_image']) ? $page_title : $page_title . '<img src="' . $helper->url('assets/images/picture.png') . '">';
113
    }
114
    //    require_once dirname(__DIR__) . '/include/xoopsformloader.php';
115
    xoops_load('blockform', $moduleDirName);
116
    $form        = new XoopsModules\About\BlockForm();
117
    $page_select = new \XoopsFormRadio(_MB_ABOUT_BLOCKPAGE, 'options[0]', $options[0], '<br>');
118
    $page_select->addOptionArray($options_page);
119
    $form->addElement($page_select);
120
    $form->addElement(new \XoopsFormText(_MB_ABOUT_TEXT_LENGTH, 'options[1]', 5, 5, $options[1]));
121
    $form->addElement(new \XoopsFormText(_MB_ABOUT_VIEW_MORELINKTEXT, 'options[2]', 30, 50, $options[2]));
122
    $form->addElement(new \XoopsFormRadioYN(_MB_ABOUT_DOTITLEIMAGE, 'options[3]', $options[3]));
123
124
    return $form->render();
125
}
126