|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if (!defined('BASEPATH')) { |
|
4
|
|
|
exit('No direct script access allowed'); |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* ImageCMS |
|
9
|
|
|
* Widgets helper |
|
10
|
|
|
* @property CI_DB_active_record $db |
|
11
|
|
|
*/ |
|
12
|
|
|
if (!function_exists('widget')) { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Run widget |
|
16
|
|
|
* |
|
17
|
|
|
* @param bool|string $name - widget name |
|
18
|
|
|
* @param bool|int $cache - cache ttl in minutes |
|
19
|
|
|
* @return array |
|
20
|
|
|
*/ |
|
21
|
|
|
function widget($name = FALSE, $cache = FALSE) { |
|
22
|
|
|
$ci = &get_instance(); |
|
23
|
|
|
$widget = []; |
|
24
|
|
|
|
|
25
|
|
|
$query = $ci->db->limit(1)->get_where('widgets', ['name' => $name]); |
|
26
|
|
|
|
|
27
|
|
View Code Duplication |
if ($query->num_rows() == 1) { |
|
28
|
|
|
$widget = $query->row_array(); |
|
29
|
|
|
} else { |
|
30
|
|
|
log_message('error', 'Can\'t run widget <b>' . $name . '</b>'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (($data = $ci->cache->fetch('widget' . $name, 'widgets')) != FALSE AND $cache != FALSE) { |
|
34
|
|
|
return $data; |
|
35
|
|
|
} else { |
|
36
|
|
|
$widget['settings'] = unserialize($widget['settings']); |
|
37
|
|
|
|
|
38
|
|
|
switch ($widget['type']) { |
|
39
|
|
|
case 'module': |
|
40
|
|
|
$subpath = isset($widget['settings']['subpath']) ? $widget['settings']['subpath'] . '/' : ''; |
|
41
|
|
|
$method = $widget['method']; |
|
42
|
|
|
$result = $ci->load->module($widget['data'] . '/' . $subpath . $widget['data'] . '_widgets')->$method($widget); |
|
43
|
|
|
break; |
|
44
|
|
|
|
|
45
|
|
|
case 'html': |
|
46
|
|
|
$locale = MY_Controller::getCurrentLocale(); |
|
47
|
|
|
$id = $widget['id']; |
|
48
|
|
|
$sql = "select * from widget_i18n where locale = '$locale' and id = '$id'"; |
|
49
|
|
|
$w_i18 = $ci->db->query($sql)->row_array(); |
|
50
|
|
|
$result = $w_i18['data']; |
|
51
|
|
|
break; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if ($cache != FALSE AND is_integer($cache)) { |
|
|
|
|
|
|
55
|
|
|
$ci->cache->store('widget' . $name, $result, $cache * 60, 'widgets'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $result; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (!function_exists('widget_ajax')) { |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $name |
|
68
|
|
|
* @param string $container |
|
69
|
|
|
*/ |
|
70
|
|
|
function widget_ajax($name, $container) { |
|
71
|
|
|
|
|
72
|
|
|
echo " |
|
73
|
|
|
<script type=text/javascript> |
|
74
|
|
|
$(window).load(function(){ |
|
75
|
|
|
$.ajax({ |
|
76
|
|
|
async : 'false', |
|
77
|
|
|
type : 'post', |
|
78
|
|
|
url : locale+'/shop/ajax/widget/$name', |
|
79
|
|
|
success : function(data){ |
|
80
|
|
|
$('$container').html(data); |
|
81
|
|
|
$(document).trigger({type: 'widget_ajax', el: $('$container')}) |
|
82
|
|
|
} |
|
83
|
|
|
}) |
|
84
|
|
|
}) |
|
85
|
|
|
|
|
86
|
|
|
</script> |
|
87
|
|
|
"; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (!function_exists('getWidgetName')) { |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $name |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
function getWidgetName($name) { |
|
|
|
|
|
|
100
|
|
|
$ci = &get_instance(); |
|
101
|
|
|
|
|
102
|
|
|
$query = $ci->db->limit(1)->get_where('widgets', ['name' => $name]); |
|
103
|
|
|
|
|
104
|
|
View Code Duplication |
if ($query->num_rows() == 1) { |
|
105
|
|
|
$widget = $query->row_array(); |
|
106
|
|
|
} else { |
|
107
|
|
|
log_message('error', 'Can\'t run widget <b>' . $name . '</b>'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$widget = unserialize($widget['settings']); |
|
111
|
|
|
|
|
112
|
|
|
return $widget['title']; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
if (!function_exists('getWidgeTitle')) { |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param string $name |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
function getWidgetTitle($name) { |
|
|
|
|
|
|
124
|
|
|
$ci = &get_instance(); |
|
125
|
|
|
|
|
126
|
|
|
$locale = MY_Controller::getCurrentLocale(); |
|
127
|
|
|
$query = $ci->db |
|
128
|
|
|
->join('widget_i18n', 'widget_i18n.id=widgets.id AND locale="' . $locale . '"', 'left') |
|
129
|
|
|
->get_where('widgets', ['name' => $name]); |
|
130
|
|
|
|
|
131
|
|
|
if ($query->num_rows() == 1) { |
|
132
|
|
|
$widget = $query->row_array(); |
|
133
|
|
|
$title = $widget['title']; |
|
134
|
|
|
|
|
135
|
|
|
$settings = @unserialize($widget[settings]); |
|
136
|
|
|
if ($settings) { |
|
137
|
|
|
$title = $title ? : $settings['title']; |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $title; |
|
141
|
|
|
} else { |
|
142
|
|
|
log_message('error', 'Can\'t run widget <b>' . $name . '</b>'); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return ''; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if (!function_exists('getProductViewsCount')) { |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return int |
|
154
|
|
|
*/ |
|
155
|
|
|
function getProductViewsCount() { |
|
|
|
|
|
|
156
|
|
|
$ci = &get_instance(); |
|
157
|
|
|
|
|
158
|
|
|
$views = $ci->session->userdata('page'); |
|
159
|
|
|
|
|
160
|
|
|
if ($views) { |
|
161
|
|
|
$count = count($views); |
|
162
|
|
|
} else { |
|
163
|
|
|
$count = 0; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
return $count; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
} |
|
170
|
|
|
/* End of widget_helper.php */ |