This repository was archived by the owner on Jul 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtab.simple_cloner.php
More file actions
executable file
·290 lines (254 loc) · 7.99 KB
/
tab.simple_cloner.php
File metadata and controls
executable file
·290 lines (254 loc) · 7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once PATH_THIRD . 'simple_cloner/config.php';
/**
* Simple Cloner Tab class
*
* @package simple_cloner
* @author Stuart Thornton <sthornton@knightknox.com>
* @link http://www.github.com/ThorntonStuart
* @copyright Copyright (c) 2016, Stuart Thornton
*/
class Simple_cloner_tab {
var $class_name = SIMPLE_CLONER_NAME_FORMATTED;
/**
* Constructor
*
* @access public
* @return void
*/
public function __construct()
{
// Load module lang file and set tab title.
ee()->lang->loadfile('simple_cloner');
$tab_title = 'Simple Cloner';
if($tab_title) {
ee()->lang->language['simple_cloner'] = $tab_title;
}
}
/**
* Tab display
*
* @access public
* @param int
* @param int
* @return array
*/
public function display($channel_id, $entry_id = '') {
// Initialize settings array and assign each setting as an index with required vals.
$settings = array();
$settings['cloned_entry_status'] = array(
'field_id' => 'cloned_entry_status',
'field_label' => lang('tab_cloned_entry_status'),
'field_required' => 'n',
'field_data' => '',
'field_list_items' => '',
'field_fmt' => '',
'options' => array(),
'field_instructions' => lang('tab_cloned_entry_status_instructions'),
'field_show_fmt' => 'n',
'field_text_direction' => 'ltr',
'field_type' => 'text',
'field_maxl' => '1024'
);
$settings['title_suffix'] = array(
'field_id' => 'title_suffix',
'field_label' => lang('tab_title_suffix'),
'field_required' => 'n',
'field_data' => '',
'field_list_items' => '',
'field_fmt' => '',
'options' => array(),
'field_instructions' => lang('tab_title_suffix_instructions'),
'field_show_fmt' => 'n',
'field_fmt_options' => array(),
'field_pre_populate' => 'n',
'field_text_direction' => 'ltr',
'field_type' => 'text',
'field_maxl' => '1024'
);
$settings['url_title_suffix'] = array(
'field_id' => 'url_title_suffix',
'field_label' => lang('tab_url_title_suffix'),
'field_required' => 'n',
'field_data' => '',
'field_list_items' => '',
'field_fmt' => '',
'options' => array(),
'field_instructions' => lang('tab_url_title_suffix_instructions'),
'field_show_fmt' => 'n',
'field_fmt_options' => array(),
'field_pre_populate' => 'n',
'field_text_direction' => 'ltr',
'field_type' => 'text',
'field_maxl' => '1024'
);
$settings['update_entry_time'] = array(
'field_id' => 'update_entry_time',
'field_label' => lang('tab_update_entry_time'),
'field_required' => 'n',
'field_data' => '',
'field_list_items' => '',
'field_fmt' => '',
'options' => array(),
'field_instructions' => lang('tab_update_entry_time_instructions'),
'field_show_fmt' => 'n',
'field_fmt_options' => array(),
'field_pre_populate' => 'n',
'field_text_direction' => 'ltr',
'field_type' => 'toggle',
'field_maxl' => '1024'
);
$settings['clone_entry'] = array(
'field_id' => 'clone_entry',
'field_label' => lang('tab_clone_entry'),
'field_required' => 'n',
'field_data' => '',
'field_list_items' => '',
'field_fmt' => '',
'options' => array(),
'field_instructions' => lang('tab_clone_entry_instructions'),
'field_show_fmt' => 'n',
'field_fmt_options' => array(),
'field_pre_populate' => 'n',
'field_text_direction' => 'ltr',
'field_type' => 'toggle',
'field_maxl' => '1024'
);
// Check if toggle is a fieldtype in user's EE version. If not, change fieldtype.
$hasToggle = ee()->db->select('*')
->from('fieldtypes')
->where(array('name' => 'toggle'))
->get();
$status_group_query = ee()->db->select('status_group')
->from('channels')
->where('channel_id', $channel_id)
->get();
$status_group = $status_group_query->result_array();
$statuses_query = ee()->db->select('status')
->from('statuses')
->where('group_id', $status_group[0]['status_group'])
->get();
$statuses = $statuses_query->result_array();
$settings['cloned_entry_status']['field_type'] = 'select';
$settings['cloned_entry_status']['field_list_items'] = array();
array_push($settings['cloned_entry_status']['field_list_items'], "Channel Default");
foreach($statuses as $key => $value) {
array_push($settings['cloned_entry_status']['field_list_items'], ucwords($statuses[$key]['status']));
}
if($hasToggle->num_rows() == 0) {
$settings['update_entry_time']['field_type'] = 'select';
$settings['update_entry_time']['field_list_items'] = array('Yes', 'No');
$settings['clone_entry']['field_type'] = 'select';
$settings['clone_entry']['field_list_items'] = array('Yes', 'No');
}
// Query module settings and set update_entry_time to default in tab value exists.
$settings_query = ee()->db->select('settings')
->where('enabled', 'y')
->where('class', $this->class_name.'_ext')
->get('extensions', 1);
$settings_query = unserialize($settings_query->row()->settings);
if($settings_query['update_entry_time'] == 'y') {
if($hasToggle->num_rows() == 0) {
$settings['update_entry_time']['field_data'] = '0';
$settings['clone_entry']['field_data'] = '1';
} else {
$settings['update_entry_time']['field_data'] = '1';
$settings['clone_entry']['field_data'] = '0';
}
}
return $settings;
}
/**
* Validate method (not used)
*
* @access public
* @param EllisLabExpressionEngineModuleChannelModelChannelEntry
* @param array
* @return bool
*/
public function validate($channel_entry, $params) {
return TRUE;
}
/**
* Save tab
*
* @access public
* @param EllisLabExpressionEngineModuleChannelModelChannelEntry
* @param array
* @return void
*/
public function save($channel_entry, $params) {
// Check if fieldtypes have been switched to selects. If they have, convert values to toggle values for DB. Needs refactoring.
$hasToggle = ee()->db->select('*')
->from('fieldtypes')
->where(array('name' => 'toggle'))
->get();
if($hasToggle->num_rows() == 0) {
switch($params['update_entry_time']) {
case '0':
$params['update_entry_time'] = '1';
break;
case '1':
$params['update_entry_time'] = '0';
break;
default:
$params['update_entry_time'] = '0';
}
switch($params['clone_entry']) {
case '0':
$params['clone_entry'] = '1';
break;
case '1':
$params['clone_entry'] = '0';
break;
default:
$params['clone_entry'] = '0';
}
}
// Assign content variables to be entered into Simple Cloner Content table.
$site_id = $channel_entry->site_id;
$entry_id = $channel_entry->entry_id;
$content = array(
'site_id' => $site_id,
'entry_id' => $entry_id,
'cloned_entry_status' => $params['cloned_entry_status'],
'title_suffix' => $params['title_suffix'],
'url_title_suffix' => $params['url_title_suffix'],
'update_entry_time' => $params['update_entry_time'],
'clone_entry' => $params['clone_entry']
);
// Fetch table and set where statement for specific entry and site.
$table_name = 'simple_cloner_content';
$where = array(
'entry_id' => $entry_id,
'site_id' => $site_id
);
$default_where = $where;
$default_conent = $content;
$default_table_name = $table_name;
$query = ee()->db->get_where($table_name, $where);
// If clone entry flag has been selected, update the table, if not insert row.
if($params['clone_entry'] == '1') {
if($query->num_rows()) {
ee()->db->where($where);
ee()->db->update($table_name, $content);
} else {
ee()->db->insert($table_name, $content);
}
}
}
/**
* Delete row from table if entry deleted.
*
* @access public
* @param array
* @return void
*/
public function delete($entry_ids)
{
foreach ($entry_ids as $i => $entry_id) {
ee()->db->where('entry_id', $entry_id);
ee()->db->delete('simple_cloner_content');
}
}
}