siteinfo_helper.php ➔ siteinfo()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 6
nop 1
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
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
}