|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use CMSFactory\assetManager; |
|
4
|
|
|
|
|
5
|
|
|
if (!defined('BASEPATH')) { |
|
6
|
|
|
exit('No direct script access allowed'); |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Image CMS |
|
11
|
|
|
*/ |
|
12
|
|
|
class Gallery_Widgets extends MY_Controller |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Gallery_Widgets constructor. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct() { |
|
19
|
|
|
parent::__construct(); |
|
20
|
|
|
$lang = new MY_Lang(); |
|
21
|
|
|
$lang->load('gallery'); |
|
22
|
|
|
$this->load->helper('gallery'); |
|
23
|
|
|
$this->load->model('gallery_m'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param array $widget |
|
28
|
|
|
* @return string |
|
29
|
|
|
*/ |
|
30
|
|
|
public function latest_fotos(array $widget = []) { |
|
31
|
|
|
|
|
32
|
|
|
if ($widget['settings']['order'] == 'latest') { |
|
33
|
|
|
$images = gallery_latest_images($widget['settings']['limit']); |
|
34
|
|
|
} else { |
|
35
|
|
|
$images = gallery_latest_images($widget['settings']['limit'], 'random'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (!empty($images)) { |
|
39
|
|
|
$countImages = count($images); |
|
40
|
|
|
for ($i = 0; $i < $countImages; $i++) { |
|
41
|
|
|
$images[$i]['url'] = site_url($images[$i]['url']); |
|
42
|
|
|
$images[$i]['file_path'] = media_url($images[$i]['file_path']); |
|
43
|
|
|
$images[$i]['thumb_path'] = media_url('uploads/gallery/' . $images[$i]['album_id'] . '/_thumbs/' . $images[$i]['file_name'] . $images[$i]['file_ext']); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->template->add_array( |
|
48
|
|
|
['images' => $images] |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
return $this->template->fetch('widgets/' . $widget['name'], $data); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $action |
|
56
|
|
|
* @param array $widget_data |
|
57
|
|
|
*/ |
|
58
|
|
|
public function latest_fotos_configure($action = 'show_settings', array $widget_data = []) { |
|
59
|
|
|
if ($this->dx_auth->is_admin() == FALSE) { |
|
60
|
|
|
exit; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
switch ($action) { |
|
64
|
|
|
case 'show_settings': |
|
65
|
|
|
assetManager::create() |
|
66
|
|
|
->setData('widget', $widget_data) |
|
67
|
|
|
->renderAdmin('../../templates/latest_fotos_form'); |
|
68
|
|
|
break; |
|
69
|
|
|
|
|
70
|
|
|
case 'update_settings': |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
$this->load->library('Form_validation'); |
|
73
|
|
|
$this->form_validation->set_rules('limit', lang('Image limit', 'gallery'), 'trim|required|integer'); |
|
74
|
|
|
|
|
75
|
|
View Code Duplication |
if ($this->form_validation->run($this) == FALSE) { |
|
76
|
|
|
showMessage(validation_errors(), false, 'r'); |
|
77
|
|
|
exit; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$data = [ |
|
81
|
|
|
'limit' => $this->input->post('limit'), |
|
82
|
|
|
'order' => $this->input->post('order'), |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
$this->load->module('admin/widgets_manager')->update_config($widget_data['id'], $data); |
|
86
|
|
|
|
|
87
|
|
|
showMessage(lang('Settings have been saved', 'gallery')); |
|
88
|
|
|
if ($this->input->post('action') == 'tomain') { |
|
89
|
|
|
pjax('/admin/widgets_manager/index'); |
|
90
|
|
|
} |
|
91
|
|
|
break; |
|
92
|
|
|
|
|
93
|
|
|
case 'install_defaults': |
|
94
|
|
|
$data = [ |
|
95
|
|
|
'limit' => 5, |
|
96
|
|
|
'order' => 'latest', |
|
97
|
|
|
]; |
|
98
|
|
|
|
|
99
|
|
|
$this->load->module('admin/widgets_manager')->update_config($widget_data['id'], $data); |
|
100
|
|
|
break; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param array $widget |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
|
|
public function album_images(array $widget = []) { |
|
110
|
|
|
|
|
111
|
|
|
$images = $this->gallery_m->get_album_images($widget['settings']['album_id'], $widget['settings']['limit']); |
|
112
|
|
|
|
|
113
|
|
|
if (!empty($images)) { |
|
114
|
|
|
$countImages = count($images); |
|
115
|
|
|
for ($i = 0; $i < $countImages; $i++) { |
|
116
|
|
|
$images[$i]['url'] = site_url('gallery/album/' . $images[$i]['album_id'] . '/image/' . $images[$i]['id']); |
|
117
|
|
|
$images[$i]['file_path'] = media_url('uploads/gallery/' . $images[$i]['album_id'] . '/' . $images[$i]['file_name'] . $images[$i]['file_ext']); |
|
118
|
|
|
$images[$i]['thumb_path'] = media_url('uploads/gallery/' . $images[$i]['album_id'] . '/_thumbs/' . $images[$i]['file_name'] . $images[$i]['file_ext']); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return assetManager::create() |
|
123
|
|
|
->setData('images', $images) |
|
124
|
|
|
->fetchTemplate('../widgets/' . $widget['name']); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param string $action |
|
130
|
|
|
* @param array $widget_data |
|
131
|
|
|
*/ |
|
132
|
|
|
public function album_images_configure($action = 'show_settings', array $widget_data = []) { |
|
133
|
|
|
if ($this->dx_auth->is_admin() == FALSE) { |
|
134
|
|
|
exit; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
switch ($action) { |
|
138
|
|
|
case 'show_settings': |
|
139
|
|
|
assetManager::create() |
|
140
|
|
|
->setData('widget', $widget_data) |
|
141
|
|
|
->setData('albums', $this->gallery_m->get_albums()) |
|
142
|
|
|
->renderAdmin('../../templates/album_images_form'); |
|
143
|
|
|
break; |
|
144
|
|
|
|
|
145
|
|
|
case 'update_settings': |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
$this->load->library('Form_validation'); |
|
148
|
|
|
$this->form_validation->set_rules('limit', lang('Image limit', 'gallery'), 'trim|required|integer'); |
|
149
|
|
|
$this->form_validation->set_rules('album_id', lang('Choose Album', 'gallery'), 'trim|required|integer'); |
|
150
|
|
|
|
|
151
|
|
View Code Duplication |
if ($this->form_validation->run($this) == FALSE) { |
|
152
|
|
|
showMessage(validation_errors(), false, 'r'); |
|
153
|
|
|
exit; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
$data = [ |
|
157
|
|
|
'limit' => $this->input->post('limit'), |
|
158
|
|
|
'album_id' => $this->input->post('album_id'), |
|
159
|
|
|
]; |
|
160
|
|
|
|
|
161
|
|
|
$this->load->module('admin/widgets_manager')->update_config($widget_data['id'], $data); |
|
162
|
|
|
|
|
163
|
|
|
showMessage(lang('Settings have been saved', 'gallery')); |
|
164
|
|
|
if ($this->input->post('action') == 'tomain') { |
|
165
|
|
|
pjax('/admin/widgets_manager/index'); |
|
166
|
|
|
} |
|
167
|
|
|
break; |
|
168
|
|
|
|
|
169
|
|
|
case 'install_defaults': |
|
170
|
|
|
$this->load->module('admin/widgets_manager')->update_config($widget_data['id'], ['limit' => 15]); |
|
171
|
|
|
break; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.