XooSocialNetworkPreload::isActive()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
/**
3
 * Xoosocialnetwork module
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       XOOPS Project (https://xoops.org)
13
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @package         Xoosocialnetwork
15
 * @since           2.6.0
16
 * @author          Laurent JEN (Aka DuGris)
17
 */
18
use Xoops\Core\PreloadItem;
19
20
/**
21
 * Class XooSocialNetworkPreload
22
 */
23
class XooSocialNetworkPreload extends PreloadItem
24
{
25
    /**
26
     * @param $args
27
     */
28
    public static function eventCoreHeaderAddmeta($args)
0 ignored issues
show
Unused Code introduced by
The parameter $args 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

28
    public static function eventCoreHeaderAddmeta(/** @scrutinizer ignore-unused */ $args)

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...
29
    {
30
        $xoops = \Xoops::getInstance();
31
        $sn = [];
32
        $helper = \XoopsModules\Xoosocialnetwork\Helper::getInstance();
33
        if (null !== $xoops->module && is_object($xoops->module) && 'index.php' !== basename($xoops->getEnv('PHP_SELF'))) {
34
            if (self::isActive()) {
35
                $url = $xoops->getEnv('HTTPS') ? 'https://' : 'http://';
36
                $url .= $xoops->getEnv('SERVER_NAME');
37
                if ($xoops->getEnv('QUERY_STRING')) {
38
                    $url .= $xoops->getEnv('PHP_SELF') . '?' . urlencode($xoops->getEnv('QUERY_STRING'));
39
                } else {
40
                    $url .= $xoops->getEnv('PHP_SELF');
41
                }
42
43
                $socialnetworkHandler = $helper->getHandler('Socialnetwork');
44
                $config = $socialnetworkHandler->loadConfig();
0 ignored issues
show
Bug introduced by
The method loadConfig() does not exist on XoopsObjectHandler. ( Ignorable by Annotation )

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

44
                /** @scrutinizer ignore-call */ 
45
                $config = $socialnetworkHandler->loadConfig();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
                if (is_array($config)) {
46
                    foreach ($config as $k => $v) {
47
                        $sn[$k]['xoosocialnetwork_title']      = $v['xoosocialnetwork_title'];
48
                        $sn[$k]['xoosocialnetwork_image_link'] = $v['xoosocialnetwork_image_link'];
49
                        $sn[$k]['xoosocialnetwork_url']        = $v['xoosocialnetwork_url'] . '?';
50
                        $sn[$k]['xoosocialnetwork_url']        .= $v['xoosocialnetwork_query_url'] . '=';
51
                        $sn[$k]['xoosocialnetwork_url']        .= $url;
52
                        if ('' != $v['xoosocialnetwork_query_title']) {
53
                            $sn[$k]['xoosocialnetwork_url'] .= '&amp;';
54
                            $sn[$k]['xoosocialnetwork_url'] .= $v['xoosocialnetwork_query_title'] . '=';
55
                            $sn[$k]['xoosocialnetwork_url'] .= rawurlencode($xoops->tpl()->tpl_vars['xoops_pagetitle']);
56
                        }
57
                    }
58
                }
59
                if (is_array($sn) && count($sn) > 0) {
60
                    $xoops->tpl()->assign('xoosocialnetwork', $sn);
61
                }
62
            }
63
        }
64
    }
65
66
    /**
67
     * @param $args
68
     */
69
    public static function eventCoreIncludeCommonEnd($args)
0 ignored issues
show
Unused Code introduced by
The parameter $args 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

69
    public static function eventCoreIncludeCommonEnd(/** @scrutinizer ignore-unused */ $args)

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...
70
    {
71
        require_once __DIR__ . '/autoloader.php';
72
    }
73
74
    /**
75
     * @return bool
76
     */
77
    private static function isActive()
78
    {
79
        $xoops = \Xoops::getInstance();
80
        $moduleHandler = $xoops->getHandlerModule();
81
        $module = $moduleHandler->getByDirname('xoosocialnetwork');
82
83
        return ($module && $module->getVar('isactive')) ? true : false;
84
    }
85
}
86