siteinfo_helper.php ➔ siteInfoAdditionalManipulations()   C
last analyzed

Complexity

Conditions 12
Paths 68

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
nc 68
nop 1
dl 0
loc 43
rs 6.9666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use template_manager\classes\TemplateManager;
4
5
if (!defined('BASEPATH')) {
6
    exit('No direct script access allowed');
7
}
8
9
/**
10
 * ImageCMS
11
 * siteinfo helper
12
 */
13
if (!function_exists('siteinfo')) {
14
15
    /**
16
     * Get information about site
17
     *
18
     * @param string $name - name of siteinfo param
19
     *    - siteinfo_compatyname
20
     *    - siteinfo_address
21
     *    - siteinfo_mainphone
22
     *    - siteinfo_contacts
23
     *    - siteinfo_logo
24
     *    - siteinfo_favicon
25
     *    - "or some contact name"
26
     * @return bool|string
27
     */
28
    function siteinfo($name = NULL) {
29
30
        // for shorter notation...
31
        if (0 !== strpos($name, 'siteinfo_')) {
32
            $name = 'siteinfo_' . $name;
33
        }
34
        $ci = &get_instance();
35
        $ci->load->library('SiteInfo');
36
        $siteinfo = new SiteInfo();
37
        // next code is only for compatibility with older versions of library,
38
        // so in the future needed to be removed (with funciton processOldVersions() too)
39
40
        if (FALSE !== $data = siteInfoAdditionalManipulations($name)) {
0 ignored issues
show
Deprecated Code introduced by
The function siteInfoAdditionalManipulations() has been deprecated with message: since version 4.6

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
41
            return $data;
42
        } else {
43
            $value = $siteinfo->getSiteInfo($name);
44
45
            if (in_array($name, ['siteinfo_logo', 'siteinfo_favicon'])) {
46
                return $ci->siteinfo->imagesPath . $value;
47
            }
48
            return $value;
49
        }
50
    }
51
52
}
53
54
if (!function_exists('siteInfoAdditionalManipulations')) {
55
56
    /**
57
     * Функція існує суто для сумісності із старими версіями
58
     * @deprecated since version 4.6
59
     * @param string $name
60
     * @return string|boolean
61
     */
62
    function siteInfoAdditionalManipulations($name) {
63
        if (FALSE !== strpos($name, '_path')) {
64
            $name = str_replace('_path', '', $name);
65
        }
66
        if (FALSE !== strpos($name, '_url')) {
67
            $name = str_replace('_url', '', $name);
68
        }
69
70
        $siteinfo = new SiteInfo();
71
        $value = $siteinfo->getSiteInfo($name);
72
        switch ($name) {
73
            case 'siteinfo_favicon':
74
            case 'siteinfo_logo':
75
                // із врахуванням активного шаблону
76
                if (is_array($value)) {
77
                    $settings = CI::$APP->cms_base->get_settings();
78
                    if (array_key_exists($settings['site_template'], $value)) {
79
                        $fileName = $value[$settings['site_template']];
80
                        if (SHOP_INSTALLED) {
81
                            $colorScheme = CI::$APP->load->module('template_manager')->getComponent('TColorScheme')->getColorSheme();
82
83
                            return "/templates/{$settings['site_template']}/css/{$colorScheme}/{$fileName}";
84
                        } else {
85
                            return "/templates/{$settings['site_template']}/images/{$fileName}";
86
                        }
87
                    } elseif (count($value) > 0) {
88
                        reset($value);
89
                        $key = key($value);
90
                        if (SHOP_INSTALLED) {
91
                            $colorScheme = CI::$APP->load->module('template_manager')->getComponent('TColorScheme')->getColorSheme();
92
                            $template = TemplateManager::getInstance()->getCurentTemplate();
93
                            return '/templates/' . $template->name . "/css/{$colorScheme}/" . $value[$key];
94
                        } else {
95
                            return "/templates/{$settings['site_template']}/images/" . array_shift($value);
96
                        }
97
                    }
98
                    return '';
99
                } elseif (is_string($value)) {
100
                    return empty($value) ? '' : CI::$APP->siteinfo->imagesPath . $value;
101
                }
102
        }
103
        return false;
104
    }
105
106
}