Socialnetwork::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace XoopsModules\Xoosocialnetwork;
4
5
/**
6
 * Xoosocialnetwork module
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xoosocialnetwork
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
21
 */
22
use Xoops\Core\Request;
23
24
/**
25
 * Class Socialnetwork
26
 */
27
class Socialnetwork extends \XoopsObject
28
{
29
    // constructor
30
31
    public function __construct()
32
    {
33
        $this->initVar('xoosocialnetwork_id', XOBJ_DTYPE_INT, 0, false, 11);
34
        $this->initVar('xoosocialnetwork_title', XOBJ_DTYPE_TXTBOX, '', true, 100);
35
        $this->initVar('xoosocialnetwork_url', XOBJ_DTYPE_TXTBOX, '', true, 100);
36
        $this->initVar('xoosocialnetwork_image', XOBJ_DTYPE_TXTBOX, 'blank.gif', true, 100);
37
        $this->initVar('xoosocialnetwork_query_url', XOBJ_DTYPE_TXTBOX, '', true, 20);
38
        $this->initVar('xoosocialnetwork_query_title', XOBJ_DTYPE_TXTBOX, '', true, 20);
39
        $this->initVar('xoosocialnetwork_display', XOBJ_DTYPE_INT, 1, true, 1);
40
        $this->initVar('xoosocialnetwork_order', XOBJ_DTYPE_INT, 1, true, 3);
41
42
        // Pour autoriser le html
43
        //        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
44
    }
45
46
    /**
47
     * @return bool
48
     */
49
    public function setView()
50
    {
51
        $this->setVar('xoosocialnetwork_display', 1);
52
53
        return true;
54
    }
55
56
    /**
57
     * @return bool
58
     */
59
    public function setHide()
60
    {
61
        $this->setVar('xoosocialnetwork_display', 0);
62
63
        return true;
64
    }
65
66
    /**
67
     * @param null $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
68
     * @param null $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
69
     * @param null $maxDepth
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $maxDepth is correct as it would always require null to be passed?
Loading history...
70
     * @return array
71
     */
72
    public function getValues($keys = null, $format = null, $maxDepth = null)
73
    {
74
        $xoops = \Xoops::getInstance();
75
        $helper = \XoopsModules\Xoosocialnetwork\Helper::getInstance();
76
        $sn_config = $helper->loadConfig();
0 ignored issues
show
Bug introduced by
The method loadConfig() does not exist on Xoops\Module\Helper\HelperAbstract. It seems like you code against a sub-type of Xoops\Module\Helper\HelperAbstract such as XoopsModules\Xoosocialnetwork\Helper. ( Ignorable by Annotation )

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

76
        /** @scrutinizer ignore-call */ 
77
        $sn_config = $helper->loadConfig();
Loading history...
77
78
        $ret = parent::getValues();
79
        if ('blank.gif' !== $ret['xoosocialnetwork_image']) {
80
            $ret['xoosocialnetwork_image_link'] = $xoops->url('modules/xoosocialnetwork/assets/icons/' . $sn_config['xoosocialnetwork_theme']) . '/' . $ret['xoosocialnetwork_image'];
81
        }
82
83
        return $ret;
84
    }
85
86
    public function cleanVarsForDB()
87
    {
88
        $system = \System::getInstance();
89
        foreach (parent::getValues() as $k => $v) {
90
            if ('dohtml' !== $k) {
91
                if (XOBJ_DTYPE_STIME == $this->vars[$k]['data_type'] || XOBJ_DTYPE_MTIME == $this->vars[$k]['data_type'] || XOBJ_DTYPE_LTIME == $this->vars[$k]['data_type']) {
92
                    $value0 = $system->cleanVars($_POST[$k], 'date', date('Y-m-d'), 'date') + $system->cleanVars($_POST[$k], 'time', date('u'), 'int');
0 ignored issues
show
Unused Code introduced by
The assignment to $value0 is dead and can be removed.
Loading history...
93
                    //TODO should we use here getString??
94
                    $value = Request::getString('date', date('Y-m-d'), $_POST[$k]) + Request::getInt('time', date('u'), $_POST[$k]);
0 ignored issues
show
Bug introduced by
date('u') of type string is incompatible with the type integer expected by parameter $default of Xmf\Request::getInt(). ( Ignorable by Annotation )

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

94
                    $value = Request::getString('date', date('Y-m-d'), $_POST[$k]) + Request::getInt('time', /** @scrutinizer ignore-type */ date('u'), $_POST[$k]);
Loading history...
95
96
                    $this->setVar($k, isset($_POST[$k]) ? $value : $v);
97
                } elseif (XOBJ_DTYPE_INT == $this->vars[$k]['data_type']) {
98
                    $value = Request::getInt($k, $v, 'POST'); //$system->cleanVars($_POST, $k, $v, 'int');
99
                    $this->setVar($k, $value);
100
                } elseif (XOBJ_DTYPE_ARRAY == $this->vars[$k]['data_type']) {
101
                    $value = Request::getArray($k, $v, 'POST'); //$system->cleanVars($_POST, $k, $v, 'array');
102
                    $this->setVar($k, $value);
103
                } else {
104
                    $value = Request::getString($k, $v, 'POST'); //$system->cleanVars($_POST, $k, $v, 'string');
105
                    $this->setVar($k, $value);
106
                }
107
            }
108
        }
109
    }
110
}
111