1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* Admin functions.
|
4
|
|
|
*
|
5
|
|
|
* @since 1.0.0
|
6
|
|
|
* @package GeoDirectory
|
7
|
|
|
*/
|
8
|
|
|
|
9
|
|
|
/**
|
10
|
|
|
* Updates option value when GeoDirectory get deactivated.
|
11
|
|
|
*
|
12
|
|
|
* @since 1.0.0
|
13
|
|
|
* @package GeoDirectory
|
14
|
|
|
*/
|
15
|
|
|
function geodir_deactivation() {
|
16
|
|
|
// Update installed variable
|
17
|
|
|
update_option("geodir_installed", 0);
|
18
|
|
|
|
19
|
|
|
// Remove rewrite rules and then recreate rewrite rules.
|
20
|
|
|
flush_rewrite_rules();
|
21
|
|
|
}
|
22
|
|
|
|
23
|
|
|
if (!function_exists('geodir_admin_styles')) {
|
24
|
|
|
/**
|
25
|
|
|
* Enqueue Admin Styles.
|
26
|
|
|
*
|
27
|
|
|
* @since 1.0.0
|
28
|
|
|
* @package GeoDirectory
|
29
|
|
|
*/
|
30
|
|
|
function geodir_admin_styles() {
|
31
|
|
|
wp_register_style('geodirectory-admin-css', geodir_plugin_url() . '/geodirectory-assets/css/admin.css', array(), GEODIRECTORY_VERSION);
|
32
|
|
|
wp_enqueue_style('geodirectory-admin-css');
|
33
|
|
|
|
34
|
|
|
wp_register_style('geodirectory-frontend-style', geodir_plugin_url() . '/geodirectory-assets/css/style.css', array(), GEODIRECTORY_VERSION);
|
35
|
|
|
wp_enqueue_style('geodirectory-frontend-style');
|
36
|
|
|
|
37
|
|
|
wp_register_style('geodir-chosen-style', geodir_plugin_url() . '/geodirectory-assets/css/chosen.css', array(), GEODIRECTORY_VERSION);
|
38
|
|
|
wp_enqueue_style('geodir-chosen-style');
|
39
|
|
|
|
40
|
|
|
wp_register_style('geodirectory-jquery-ui-timepicker-css', geodir_plugin_url() . '/geodirectory-assets/css/jquery.ui.timepicker.css', array(), GEODIRECTORY_VERSION);
|
41
|
|
|
wp_enqueue_style('geodirectory-jquery-ui-timepicker-css');
|
42
|
|
|
|
43
|
|
|
wp_register_style('geodirectory-jquery-ui-css', geodir_plugin_url() . '/geodirectory-assets/css/jquery-ui.css', array(), GEODIRECTORY_VERSION);
|
44
|
|
|
wp_enqueue_style('geodirectory-jquery-ui-css');
|
45
|
|
|
|
46
|
|
|
wp_register_style('geodirectory-custom-fields-css', geodir_plugin_url() . '/geodirectory-assets/css/custom_field.css', array(), GEODIRECTORY_VERSION);
|
47
|
|
|
wp_enqueue_style('geodirectory-custom-fields-css');
|
48
|
|
|
|
49
|
|
|
wp_register_style('geodirectory-pluplodar-css', geodir_plugin_url() . '/geodirectory-assets/css/pluploader.css', array(), GEODIRECTORY_VERSION);
|
50
|
|
|
wp_enqueue_style('geodirectory-pluplodar-css');
|
51
|
|
|
|
52
|
|
|
wp_register_style('geodir-rating-style', geodir_plugin_url() . '/geodirectory-assets/css/jRating.jquery.css', array(), GEODIRECTORY_VERSION);
|
53
|
|
|
wp_enqueue_style('geodir-rating-style');
|
54
|
|
|
|
55
|
|
|
wp_register_style('geodir-rtl-style', geodir_plugin_url() . '/geodirectory-assets/css/rtl.css', array(), GEODIRECTORY_VERSION);
|
56
|
|
|
wp_enqueue_style('geodir-rtl-style');
|
57
|
|
|
}
|
58
|
|
|
}
|
59
|
|
|
|
60
|
|
|
if (!function_exists('geodir_admin_styles_req')) {
|
61
|
|
|
/**
|
62
|
|
|
* Loads stylesheets from CDN.
|
63
|
|
|
*
|
64
|
|
|
* @since 1.0.0
|
65
|
|
|
* @package GeoDirectory
|
66
|
|
|
*/
|
67
|
|
|
function geodir_admin_styles_req()
|
68
|
|
|
{
|
69
|
|
|
|
70
|
|
|
wp_register_style('font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css', array(), GEODIRECTORY_VERSION);
|
71
|
|
|
wp_enqueue_style('font-awesome');
|
72
|
|
|
|
73
|
|
|
wp_register_script('geodirectory-admin', geodir_plugin_url() . '/geodirectory-assets/js/admin-req.min.js', array('jquery'), GEODIRECTORY_VERSION);
|
74
|
|
|
wp_enqueue_script('geodirectory-admin');
|
75
|
|
|
|
76
|
|
|
}
|
77
|
|
|
}
|
78
|
|
|
|
79
|
|
|
if (!function_exists('geodir_admin_scripts')) {
|
80
|
|
|
/**
|
81
|
|
|
* Enqueue Admin Scripts.
|
82
|
|
|
*
|
83
|
|
|
* @since 1.0.0
|
84
|
|
|
* @package GeoDirectory
|
85
|
|
|
*/
|
86
|
|
|
function geodir_admin_scripts()
|
87
|
|
|
{
|
88
|
|
|
$geodir_map_name = geodir_map_name();
|
89
|
|
|
|
90
|
|
|
wp_enqueue_script('jquery');
|
91
|
|
|
|
92
|
|
|
wp_enqueue_script('geodirectory-jquery-ui-timepicker-js', geodir_plugin_url() . '/geodirectory-assets/js/jquery.ui.timepicker.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), '', true);
|
93
|
|
|
|
94
|
|
|
wp_register_script('chosen', geodir_plugin_url() . '/geodirectory-assets/js/chosen.jquery.js', array('jquery'), GEODIRECTORY_VERSION);
|
95
|
|
|
wp_enqueue_script('chosen');
|
96
|
|
|
|
97
|
|
|
wp_register_script('geodirectory-choose-ajax', geodir_plugin_url() . '/geodirectory-assets/js/ajax-chosen.js', array(), GEODIRECTORY_VERSION);
|
98
|
|
|
wp_enqueue_script('geodirectory-choose-ajax');
|
99
|
|
|
|
100
|
|
|
if (isset($_REQUEST['listing_type'])) {
|
101
|
|
|
wp_register_script('geodirectory-custom-fields-script', geodir_plugin_url() . '/geodirectory-assets/js/custom_fields.js', array(), GEODIRECTORY_VERSION);
|
102
|
|
|
}
|
103
|
|
|
|
104
|
|
|
wp_enqueue_script('geodirectory-custom-fields-script');
|
105
|
|
|
$plugin_path = geodir_plugin_url() . '/geodirectory-functions/cat-meta-functions';
|
106
|
|
|
|
107
|
|
|
wp_enqueue_script('tax-meta-clss', $plugin_path . '/js/tax-meta-clss.js', array('jquery'), null, true);
|
108
|
|
|
|
109
|
|
View Code Duplication |
if (in_array($geodir_map_name, array('auto', 'google'))) {
|
110
|
|
|
$map_lang = "&language=" . geodir_get_map_default_language();
|
111
|
|
|
$map_key = "&key=" . geodir_get_map_api_key();
|
112
|
|
|
/** This filter is documented in geodirectory_template_tags.php */
|
113
|
|
|
$map_extra = apply_filters('geodir_googlemap_script_extra', '');
|
114
|
|
|
wp_enqueue_script('geodirectory-googlemap-script', 'https://maps.google.com/maps/api/js?' . $map_lang . $map_key . $map_extra, '', NULL);
|
115
|
|
|
}
|
116
|
|
|
|
117
|
|
|
if ($geodir_map_name == 'osm') {
|
118
|
|
|
// Leaflet OpenStreetMap
|
119
|
|
|
wp_register_style('geodirectory-leaflet-style', geodir_plugin_url() . '/geodirectory-assets/leaflet/leaflet.css', array(), GEODIRECTORY_VERSION);
|
120
|
|
|
wp_enqueue_style('geodirectory-leaflet-style');
|
121
|
|
|
|
122
|
|
|
wp_register_script('geodirectory-leaflet-script', geodir_plugin_url() . '/geodirectory-assets/leaflet/leaflet.min.js', array(), GEODIRECTORY_VERSION);
|
123
|
|
|
wp_enqueue_script('geodirectory-leaflet-script');
|
124
|
|
|
|
125
|
|
|
wp_register_script('geodirectory-leaflet-geo-script', geodir_plugin_url() . '/geodirectory-assets/leaflet/osm.geocode.js', array('geodirectory-leaflet-script'), GEODIRECTORY_VERSION);
|
126
|
|
|
wp_enqueue_script('geodirectory-leaflet-geo-script');
|
127
|
|
|
}
|
128
|
|
|
wp_enqueue_script( 'jquery-ui-autocomplete' );
|
129
|
|
|
|
130
|
|
|
wp_register_script('geodirectory-goMap-script', geodir_plugin_url() . '/geodirectory-assets/js/goMap.min.js', array(), GEODIRECTORY_VERSION,true);
|
131
|
|
|
wp_enqueue_script('geodirectory-goMap-script');
|
132
|
|
|
|
133
|
|
|
wp_register_script('geodirectory-goMap-script', geodir_plugin_url() . '/geodirectory-assets/js/goMap.js', array(), GEODIRECTORY_VERSION);
|
134
|
|
|
wp_enqueue_script('geodirectory-goMap-script');
|
135
|
|
|
|
136
|
|
|
// font awesome rating script
|
137
|
|
View Code Duplication |
if (get_option('geodir_reviewrating_enable_font_awesome')) {
|
138
|
|
|
wp_register_script('geodir-barrating-js', geodir_plugin_url() . '/geodirectory-assets/js/jquery.barrating.min.js', array(), GEODIRECTORY_VERSION);
|
139
|
|
|
wp_enqueue_script('geodir-barrating-js');
|
140
|
|
|
} else { // default rating script
|
141
|
|
|
wp_register_script('geodir-jRating-js', geodir_plugin_url() . '/geodirectory-assets/js/jRating.jquery.js', array(), GEODIRECTORY_VERSION);
|
142
|
|
|
wp_enqueue_script('geodir-jRating-js');
|
143
|
|
|
}
|
144
|
|
|
|
145
|
|
|
wp_register_script('geodir-on-document-load', geodir_plugin_url() . '/geodirectory-assets/js/on_document_load.js', array(), GEODIRECTORY_VERSION);
|
146
|
|
|
wp_enqueue_script('geodir-on-document-load');
|
147
|
|
|
|
148
|
|
|
|
149
|
|
|
// SCRIPT FOR UPLOAD
|
150
|
|
|
wp_enqueue_script('plupload-all');
|
151
|
|
|
wp_enqueue_script('jquery-ui-sortable');
|
152
|
|
|
|
153
|
|
|
wp_register_script('geodirectory-plupload-script', geodir_plugin_url() . '/geodirectory-assets/js/geodirectory-plupload.js', array(), GEODIRECTORY_VERSION);
|
154
|
|
|
wp_enqueue_script('geodirectory-plupload-script');
|
155
|
|
|
|
156
|
|
|
// SCRIPT FOR UPLOAD END
|
157
|
|
|
|
158
|
|
|
|
159
|
|
|
// place js config array for plupload
|
160
|
|
|
$plupload_init = array(
|
161
|
|
|
'runtimes' => 'html5,silverlight,flash,html4',
|
162
|
|
|
'browse_button' => 'plupload-browse-button', // will be adjusted per uploader
|
163
|
|
|
'container' => 'plupload-upload-ui', // will be adjusted per uploader
|
164
|
|
|
'drop_element' => 'dropbox', // will be adjusted per uploader
|
165
|
|
|
'file_data_name' => 'async-upload', // will be adjusted per uploader
|
166
|
|
|
'multiple_queues' => true,
|
167
|
|
|
'max_file_size' => geodir_max_upload_size(),
|
168
|
|
|
'url' => admin_url('admin-ajax.php'),
|
169
|
|
|
'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
|
170
|
|
|
'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
|
171
|
|
|
'filters' => array(array('title' => __('Allowed Files', 'geodirectory'), 'extensions' => '*')),
|
172
|
|
|
'multipart' => true,
|
173
|
|
|
'urlstream_upload' => true,
|
174
|
|
|
'multi_selection' => false, // will be added per uploader
|
175
|
|
|
// additional post data to send to our ajax hook
|
176
|
|
|
'multipart_params' => array(
|
177
|
|
|
'_ajax_nonce' => "", // will be added per uploader
|
178
|
|
|
'action' => 'plupload_action', // the ajax action name
|
179
|
|
|
'imgid' => 0 // will be added per uploader
|
180
|
|
|
)
|
181
|
|
|
);
|
182
|
|
|
$base_plupload_config = json_encode($plupload_init);
|
183
|
|
|
|
184
|
|
|
|
185
|
|
|
$thumb_img_arr = array();
|
186
|
|
|
|
187
|
|
|
if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '')
|
188
|
|
|
$thumb_img_arr = geodir_get_images($_REQUEST['pid']);
|
189
|
|
|
|
190
|
|
|
$totImg = '';
|
191
|
|
|
$image_limit = '';
|
192
|
|
|
if (!empty($thumb_img_arr)) {
|
193
|
|
|
$totImg = count($thumb_img_arr);
|
194
|
|
|
}
|
195
|
|
|
|
196
|
|
|
$gd_plupload_init = array('base_plupload_config' => $base_plupload_config,
|
197
|
|
|
'totalImg' => $totImg,
|
198
|
|
|
'image_limit' => $image_limit,
|
199
|
|
|
'upload_img_size' => geodir_max_upload_size());
|
200
|
|
|
|
201
|
|
|
wp_localize_script('geodirectory-plupload-script', 'gd_plupload', $gd_plupload_init);
|
202
|
|
|
|
203
|
|
|
$ajax_cons_data = array('url' => __(admin_url('admin-ajax.php')));
|
204
|
|
|
wp_localize_script('geodirectory-custom-fields-script', 'geodir_admin_ajax', $ajax_cons_data);
|
205
|
|
|
|
206
|
|
|
|
207
|
|
|
wp_register_script('geodirectory-admin-script', geodir_plugin_url() . '/geodirectory-assets/js/admin.js', array(), GEODIRECTORY_VERSION);
|
208
|
|
|
wp_enqueue_script('geodirectory-admin-script');
|
209
|
|
|
|
210
|
|
|
wp_enqueue_style('farbtastic');
|
211
|
|
|
wp_enqueue_script('farbtastic');
|
212
|
|
|
|
213
|
|
|
$screen = get_current_screen();
|
214
|
|
|
if ($screen->base == 'post' && in_array($screen->post_type, geodir_get_posttypes())) {
|
215
|
|
|
wp_enqueue_script('geodirectory-listing-validation-script', geodir_plugin_url() . '/geodirectory-assets/js/listing_validation_admin.js');
|
216
|
|
|
}
|
217
|
|
|
|
218
|
|
|
$ajax_cons_data = array('url' => esc_url(__(get_option('siteurl') . '?geodir_ajax=true')));
|
219
|
|
|
wp_localize_script('geodirectory-admin-script', 'geodir_ajax', $ajax_cons_data);
|
220
|
|
|
|
221
|
|
|
}
|
222
|
|
|
}
|
223
|
|
|
|
224
|
|
|
if (!function_exists('geodir_admin_menu')) {
|
225
|
|
|
/**
|
226
|
|
|
* Admin Menus
|
227
|
|
|
*
|
228
|
|
|
* Sets up the admin menus in wordpress.
|
229
|
|
|
*
|
230
|
|
|
* @since 1.0.0
|
231
|
|
|
* @package GeoDirectory
|
232
|
|
|
* @global array $menu Menu array.
|
233
|
|
|
* @global object $geodirectory GeoDirectory plugin object.
|
234
|
|
|
*/
|
235
|
|
|
function geodir_admin_menu()
|
236
|
|
|
{
|
237
|
|
|
global $menu, $geodirectory;
|
238
|
|
|
|
239
|
|
|
if (current_user_can('manage_options')) $menu[] = array('', 'read', 'separator-geodirectory', '', 'wp-menu-separator geodirectory');
|
240
|
|
|
|
241
|
|
|
add_menu_page(__('Geodirectory', 'geodirectory'), __('Geodirectory', 'geodirectory'), 'manage_options', 'geodirectory', 'geodir_admin_panel', geodir_plugin_url() . '/geodirectory-assets/images/favicon.ico', '55.1984');
|
242
|
|
|
|
243
|
|
|
|
244
|
|
|
}
|
245
|
|
|
}
|
246
|
|
|
|
247
|
|
|
if (!function_exists('geodir_admin_menu_order')) {
|
248
|
|
|
/**
|
249
|
|
|
* Order admin menus.
|
250
|
|
|
*
|
251
|
|
|
* @since 1.0.0
|
252
|
|
|
* @package GeoDirectory
|
253
|
|
|
* @param array $menu_order Menu order array.
|
254
|
|
|
* @return array Modified menu order array.
|
255
|
|
|
*/
|
256
|
|
|
function geodir_admin_menu_order($menu_order)
|
257
|
|
|
{
|
258
|
|
|
|
259
|
|
|
// Initialize our custom order array
|
260
|
|
|
$geodir_menu_order = array();
|
261
|
|
|
|
262
|
|
|
// Get the index of our custom separator
|
263
|
|
|
$geodir_separator = array_search('separator-geodirectory', $menu_order);
|
264
|
|
|
|
265
|
|
|
// Get index of posttype menu
|
266
|
|
|
$post_types = geodir_get_posttypes();
|
267
|
|
|
|
268
|
|
|
// Loop through menu order and do some rearranging
|
269
|
|
|
foreach ($menu_order as $index => $item) :
|
270
|
|
|
|
271
|
|
|
if ((('geodirectory') == $item)) :
|
272
|
|
|
$geodir_menu_order[] = 'separator-geodirectory';
|
273
|
|
|
if (!empty($post_types)) {
|
274
|
|
|
foreach ($post_types as $post_type) {
|
|
|
|
|
275
|
|
|
$geodir_menu_order[] = 'edit.php?post_type=' . $post_type;
|
276
|
|
|
}
|
277
|
|
|
}
|
278
|
|
|
$geodir_menu_order[] = $item;
|
279
|
|
|
|
280
|
|
|
unset($menu_order[$geodir_separator]);
|
281
|
|
|
//unset( $menu_order[$geodir_places] );
|
|
|
|
|
282
|
|
|
elseif (!in_array($item, array('separator-geodirectory'))) :
|
283
|
|
|
$geodir_menu_order[] = $item;
|
284
|
|
|
endif;
|
285
|
|
|
|
286
|
|
|
endforeach;
|
287
|
|
|
|
288
|
|
|
// Return order
|
289
|
|
|
return $geodir_menu_order;
|
290
|
|
|
}
|
291
|
|
|
}
|
292
|
|
|
|
293
|
|
|
if (!function_exists('geodir_admin_custom_menu_order')) {
|
294
|
|
|
/**
|
295
|
|
|
* Enables custom menu order.
|
296
|
|
|
*
|
297
|
|
|
* @since 1.0.0
|
298
|
|
|
* @package GeoDirectory
|
299
|
|
|
* @return bool
|
300
|
|
|
*/
|
301
|
|
|
function geodir_admin_custom_menu_order()
|
302
|
|
|
{
|
303
|
|
|
if (!current_user_can('manage_options')) return false;
|
304
|
|
|
return true;
|
305
|
|
|
}
|
306
|
|
|
}
|
307
|
|
|
|
308
|
|
|
/**
|
309
|
|
|
* Function to show success or error message on admin option form submission.
|
310
|
|
|
*
|
311
|
|
|
* @since 1.0.0
|
312
|
|
|
* @package GeoDirectory
|
313
|
|
|
*/
|
314
|
|
|
function geodir_before_admin_panel()
|
315
|
|
|
{
|
316
|
|
|
if (isset($_REQUEST['installed']) && $_REQUEST['installed'] != '') {
|
317
|
|
|
echo '<div id="message" class="updated fade">
|
318
|
|
|
<p style="float:right;">' . __('Like Geodirectory?', 'geodirectory') . ' <a href="http://wordpress.org/extend/plugins/Geodirectory/" target="_blank">' . __('Support us by leaving a rating!', 'geodirectory') . '</a></p>
|
319
|
|
|
<p><strong>' . __('Geodirectory has been installed and setup. Enjoy :)', 'geodirectory') . '</strong></p>
|
320
|
|
|
</div>';
|
321
|
|
|
|
322
|
|
|
}
|
323
|
|
|
|
324
|
|
|
if (isset($_REQUEST['msg']) && $_REQUEST['msg'] != '') {
|
325
|
|
|
switch ($_REQUEST['msg']) {
|
326
|
|
|
case 'success':
|
327
|
|
|
echo '<div id="message" class="updated fade"><p><strong>' . __('Your settings have been saved.', 'geodirectory') . '</strong></p></div>';
|
328
|
|
|
flush_rewrite_rules(false);
|
329
|
|
|
|
330
|
|
|
break;
|
331
|
|
|
case 'fail':
|
332
|
|
|
$gderr = isset($_REQUEST['gderr']) ? $_REQUEST['gderr'] : '';
|
333
|
|
|
|
334
|
|
|
if ($gderr == 21)
|
335
|
1 |
|
echo '<div id="message" class="error fade"><p><strong>' . __('Error: You can not add same permalinks for both Listing and Location, please try again.', 'geodirectory') . '</strong></p></div>';
|
336
|
|
|
else
|
337
|
|
|
echo '<div id="message" class="error fade"><p><strong>' . __('Error: Your settings have not been saved, please try again.', 'geodirectory') . '</strong></p></div>';
|
338
|
|
|
break;
|
339
|
|
|
}
|
340
|
|
|
}
|
341
|
|
|
|
342
|
|
|
$geodir_load_map = get_option('geodir_load_map');
|
343
|
1 |
|
$need_map_key = false;
|
344
|
|
|
if($geodir_load_map=='' || $geodir_load_map=='google' || $geodir_load_map=='auto' ){
|
345
|
|
|
$need_map_key = true;
|
346
|
|
|
}
|
347
|
|
|
|
348
|
|
View Code Duplication |
if (!geodir_get_map_api_key() && $need_map_key) {
|
349
|
|
|
echo '<div class="error"><p><strong>' . sprintf(__('Google Maps API KEY not set, %sclick here%s to set one OR use Open Street Maps instead.', 'geodirectory'), '<a href=\'' . admin_url('admin.php?page=geodirectory&tab=design_settings&active_tab=geodir_map_settings') . '\'>', '</a>') . '</strong></p></div>';
|
350
|
|
|
}
|
351
|
|
|
|
352
|
|
View Code Duplication |
if (!geodir_is_default_location_set()) {
|
353
|
|
|
echo '<div class="updated fade"><p><strong>' . sprintf(__('Please %sclick here%s to set a default location, this will make the plugin work properly.', 'geodirectory'), '<a href=\'' . admin_url('admin.php?page=geodirectory&tab=default_location_settings') . '\'>', '</a>') . '</strong></p></div>';
|
354
|
|
|
|
355
|
|
|
}
|
356
|
|
|
|
357
|
|
|
if (!function_exists('curl_init')) {
|
358
|
|
|
echo '<div class="error"><p><strong>' . __('CURL is not installed on this server, this can cause problems, please ask your server admin to install it.', 'geodirectory') . '</strong></p></div>';
|
359
|
|
|
|
360
|
|
|
}
|
361
|
1 |
|
|
362
|
1 |
|
|
363
|
1 |
|
|
364
|
1 |
|
|
365
|
1 |
|
}
|
366
|
|
|
|
367
|
1 |
|
/**
|
368
|
1 |
|
* Handles data posted from GeoDirectory settings form.
|
369
|
1 |
|
*
|
370
|
|
|
* @since 1.0.0
|
371
|
1 |
|
* @package GeoDirectory
|
372
|
|
|
* @global array $geodir_settings Geodirectory settings array.
|
373
|
|
|
* @param string $current_tab The current settings tab name.
|
374
|
|
|
*/
|
375
|
|
|
function geodir_handle_option_form_submit($current_tab)
|
376
|
1 |
|
{
|
377
|
|
|
global $geodir_settings;
|
378
|
|
|
if (file_exists(dirname(__FILE__) . '/option-pages/' . $current_tab . '_array.php')) {
|
379
|
|
|
/**
|
380
|
|
|
* Contains settings array for current tab.
|
381
|
|
|
*
|
382
|
|
|
* @since 1.0.0
|
383
|
|
|
* @package GeoDirectory
|
384
|
1 |
|
*/
|
385
|
|
|
include_once('option-pages/' . $current_tab . '_array.php');
|
386
|
|
|
}
|
387
|
|
|
if (isset($_POST) && $_POST && isset($_REQUEST['page']) && $_REQUEST['page'] == 'geodirectory') :
|
388
|
|
|
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'geodir-settings')) die(__('Action failed. Please refresh the page and retry.', 'geodirectory'));
|
389
|
|
|
if (!wp_verify_nonce($_REQUEST['_wpnonce-' . $current_tab], 'geodir-settings-' . $current_tab)) die(__('Action failed. Please refresh the page and retry.', 'geodirectory'));
|
390
|
|
|
|
391
|
|
|
/**
|
392
|
|
|
* Fires before updating geodirectory admin settings.
|
393
|
|
|
*
|
394
|
|
|
* @since 1.4.2
|
395
|
|
|
*
|
396
|
|
|
* @param string $current_tab Current tab in geodirectory settings.
|
397
|
|
|
* @param array $geodir_settings Array of geodirectory settings.
|
398
|
|
|
*/
|
399
|
|
|
do_action('geodir_before_update_options', $current_tab, $geodir_settings);
|
400
|
|
|
|
401
|
|
|
if (!empty($geodir_settings[$current_tab]))
|
402
|
|
|
geodir_update_options($geodir_settings[$current_tab]);
|
403
|
|
|
|
404
|
|
|
/**
|
405
|
|
|
* Called after GeoDirectory options settings are updated.
|
406
|
|
|
*
|
407
|
|
|
* @since 1.0.0
|
408
|
|
|
* @param array $geodir_settings The array of GeoDirectory settings.
|
409
|
|
|
* @see 'geodir_before_update_options'
|
410
|
|
|
*/
|
411
|
|
|
do_action('geodir_update_options', $geodir_settings);
|
412
|
|
|
|
413
|
|
|
/**
|
414
|
|
|
* Called after GeoDirectory options settings are updated.
|
415
|
|
|
*
|
416
|
|
|
* Provides tab specific settings.
|
417
|
|
|
*
|
418
|
|
|
* @since 1.0.0
|
419
|
|
|
* @param string $current_tab The current settings tab name.
|
420
|
|
|
* @param array $geodir_settings[$current_tab] The array of settings for the current settings tab.
|
421
|
|
|
*/
|
422
|
|
|
do_action('geodir_update_options_' . $current_tab, $geodir_settings[$current_tab]);
|
423
|
|
|
|
424
|
|
|
flush_rewrite_rules(false);
|
425
|
|
|
|
426
|
|
|
$current_tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : '';
|
427
|
|
|
|
428
|
|
|
$redirect_url = admin_url('admin.php?page=geodirectory&tab=' . $current_tab . '&active_tab=' . $_REQUEST['active_tab'] . '&msg=success');
|
429
|
|
|
|
430
|
|
|
wp_redirect($redirect_url);
|
431
|
|
|
exit();
|
432
|
|
|
endif;
|
433
|
|
|
|
434
|
|
|
|
435
|
|
|
}
|
436
|
|
|
|
437
|
|
|
|
438
|
|
|
if (!function_exists('geodir_autoinstall_admin_header') && (get_option('geodir_installed') || defined( 'GD_TESTING_MODE' ))) {
|
439
|
|
|
/**
|
440
|
|
|
* GeoDirectory dummy data installation.
|
441
|
|
|
*
|
442
|
|
|
* @since 1.0.0
|
443
|
|
|
* @package GeoDirectory
|
444
|
|
|
* @global object $wpdb WordPress Database object.
|
445
|
|
|
* @global string $plugin_prefix Geodirectory plugin table prefix.
|
446
|
|
|
* @param string $post_type The post type.
|
447
|
|
|
*/
|
448
|
|
|
function geodir_autoinstall_admin_header($post_type = 'gd_place')
|
449
|
|
|
{
|
450
|
|
|
|
451
|
|
|
global $wpdb, $plugin_prefix;
|
452
|
|
|
|
453
|
|
|
if (!geodir_is_default_location_set()) {
|
454
|
|
|
echo '<div class="updated fade"><p><strong>' . sprintf(__('Please %sclick here%s to set a default location, this will help to set location of all dummy data.', 'geodirectory'), '<a href=\'' . admin_url('admin.php?page=geodirectory&tab=default_location_settings') . '\'>', '</a>') . '</strong></p></div>';
|
455
|
|
|
} else {
|
456
|
|
|
|
457
|
|
|
$geodir_url = admin_url() . 'admin.php?page=geodirectory&tab=general_settings&active_tab=';
|
458
|
|
|
|
459
|
|
|
$post_counts = $wpdb->get_var("SELECT count(post_id) FROM " . $plugin_prefix . $post_type . "_detail WHERE post_dummy='1'");
|
460
|
|
|
|
461
|
|
|
if ($post_counts > 0) {
|
462
|
|
|
$nonce = wp_create_nonce('geodir_dummy_posts_delete_noncename');
|
463
|
|
|
|
464
|
|
|
$dummy_msg = '<div id="" class="geodir_auto_install updated highlight fade"><p><b>' . SAMPLE_DATA_SHOW_MSG . '</b><br /><a id="geodir_dummy_delete" class="button_delete" onclick="geodir_autoinstall(this,\'geodir_dummy_delete\',\'' . $nonce . '\',\'' . $post_type . '\')" href="javascript:void(0);" redirect_to="' . $geodir_url . '" >' . DELETE_BTN_SAMPLE_MSG . '</a></p></div>';
|
465
|
|
|
$dummy_msg .= '<div id="" style="display:none;" class="geodir_show_progress updated highlight fade"><p><b>' . GEODIR_SAMPLE_DATA_DELETE_MSG . '</b><br><img src="' . geodir_plugin_url() . '/geodirectory-assets/images/loadingAnimation.gif" /></p></div>';
|
466
|
|
|
} else {
|
467
|
|
|
$options_list = '';
|
468
|
|
|
for ($option = 1; $option <= 30; $option++) {
|
469
|
|
|
$selected = '';
|
470
|
1 |
|
if ($option == 10)
|
471
|
|
|
$selected = 'selected="selected"';
|
472
|
1 |
|
|
473
|
|
|
$options_list .= '<option ' . $selected . ' value="' . $option . '">' . $option . '</option>';
|
474
|
|
|
}
|
475
|
|
|
|
476
|
1 |
|
$nonce = wp_create_nonce('geodir_dummy_posts_insert_noncename');
|
477
|
|
|
|
478
|
1 |
|
$dummy_msg = '<div id="" class="geodir_auto_install updated highlight fade"><p><b>' . AUTO_INSATALL_MSG . '</b><br /><select class="selected_sample_data">' . $options_list . '</select><a id="geodir_dummy_insert" class="button_insert" href="javascript:void(0);" onclick="geodir_autoinstall(this,\'geodir_dummy_insert\',\'' . $nonce . '\',\'' . $post_type . '\')" redirect_to="' . $geodir_url . '" >' . INSERT_BTN_SAMPLE_MSG . '</a></p></div>';
|
479
|
|
|
$dummy_msg .= '<div id="" style="display:none;" class="geodir_show_progress updated highlight fade"><p><b>' . GEODIR_SAMPLE_DATA_IMPORT_MSG . '</b><br><img src="' . geodir_plugin_url() . '/geodirectory-assets/images/loadingAnimation.gif" /><br><span class="dummy_post_inserted"></span></div>';
|
480
|
1 |
|
|
481
|
1 |
|
}
|
482
|
|
|
echo $dummy_msg;
|
483
|
1 |
|
|
484
|
1 |
|
$default_location = geodir_get_default_location();
|
485
|
1 |
|
$city = isset($default_location->city) ? $default_location->city : '';
|
486
|
|
|
$region = isset($default_location->region) ? $default_location->region : '';
|
487
|
|
|
$country = isset($default_location->country) ? $default_location->country : '';
|
488
|
|
|
$city_latitude = isset($default_location->city_latitude) ? $default_location->city_latitude : '';
|
489
|
|
|
$city_longitude = isset($default_location->city_longitude) ? $default_location->city_longitude : '';
|
490
|
|
|
?>
|
491
|
|
|
<script type="text/javascript">
|
492
|
|
|
var geocoder = window.gdMaps == 'google' ? new google.maps.Geocoder() : null;
|
493
|
|
|
var CITY_ADDRESS = '<?php echo addslashes( $city . ',' . $region . ',' . $country );?>';
|
494
|
|
|
var bound_lat_lng;
|
495
|
|
|
var latlng = ['<?php echo $city_latitude; ?>', <?php echo $city_longitude; ?>];
|
496
|
|
|
var lat = <?php echo $city_latitude; ?>;
|
497
|
|
|
var lng = <?php echo $city_longitude; ?>;
|
498
|
|
|
|
499
|
|
|
if (window.gdMaps == 'google') {
|
500
|
|
|
latlng = new google.maps.LatLng(lat, lng);
|
501
|
1 |
|
|
502
|
|
|
geocoder.geocode({'address': CITY_ADDRESS},
|
503
|
|
|
function (results, status) {
|
504
|
|
|
if (status == google.maps.GeocoderStatus.OK) {
|
505
|
1 |
|
// Bounds for North America
|
506
|
1 |
|
if (results[0].geometry.bounds == null) {
|
507
|
1 |
|
bound_lat_lng1 = String(results[0].geometry.viewport.getSouthWest());
|
508
|
1 |
|
bound_lat_lng1 = bound_lat_lng1.replace(/[()]/g, "");
|
509
|
1 |
|
bound_lat_lng2 = String(results[0].geometry.viewport.getNorthEast());
|
510
|
1 |
|
bound_lat_lng2 = bound_lat_lng2.replace(/[()]/g, "");
|
511
|
|
|
bound_lat_lng2 = bound_lat_lng1 + "," + bound_lat_lng2;
|
512
|
|
|
bound_lat_lng = bound_lat_lng2.split(',');
|
513
|
|
|
} else {
|
514
|
|
|
bound_lat_lng = String(results[0].geometry.bounds);
|
515
|
|
|
bound_lat_lng = bound_lat_lng.replace(/[()]/g, "");
|
516
|
|
|
bound_lat_lng = bound_lat_lng.split(',');
|
517
|
|
|
}
|
518
|
|
|
|
519
|
|
|
bound_lat_lng = bound_lat_lng.map( function(x) {
|
520
|
|
|
return x.replace(" ", '');
|
521
|
|
|
}); // remove spaces from lat/lon
|
522
|
|
|
} else {
|
523
|
|
|
alert("<?php _e('Geocode was not successful for the following reason:','geodirectory');?> " + status);
|
524
|
|
|
}
|
525
|
|
|
});
|
526
|
|
|
} else if (window.gdMaps == 'osm') {
|
527
|
|
|
latlng = L.latLng(lat, lng);
|
528
|
|
|
|
529
|
|
|
geocodePositionOSM(false, CITY_ADDRESS, false, false, function(geodata) {
|
530
|
|
|
if (typeof geodata == 'object' && geodata.boundingbox) {
|
531
|
|
|
bound_lat_lng = [geodata.boundingbox[0], geodata.boundingbox[2], geodata.boundingbox[1], geodata.boundingbox[3]];
|
532
|
|
|
} else {
|
533
|
|
|
geocodePositionOSM(latlng, false, false, false, function(geodata) {
|
534
|
|
|
if (typeof geodata == 'object' && geodata.boundingbox) {
|
535
|
|
|
bound_lat_lng = [geodata.boundingbox[0], geodata.boundingbox[2], geodata.boundingbox[1], geodata.boundingbox[3]];
|
536
|
|
|
}
|
537
|
|
|
});
|
538
|
|
|
}
|
539
|
|
|
});
|
540
|
|
|
}
|
541
|
|
|
|
542
|
|
|
var dummy_post_index = 1;
|
543
|
|
|
function geodir_autoinstall(obj, id, nonce, posttype) {
|
544
|
|
|
var active_tab = jQuery(obj).closest('form').find('dl dd.gd-tab-active').attr('id');
|
545
|
|
|
var total_dummy_post_count = jQuery('#sub_' + active_tab).find('.selected_sample_data').val();
|
546
|
|
|
|
547
|
|
|
if (id == 'geodir_dummy_delete') {
|
548
|
|
|
if (confirm('<?php _e('Are you sure you want to delete dummy data?' , 'geodirectory'); ?>')) {
|
549
|
|
|
jQuery('#sub_' + active_tab).find('.geodir_auto_install').hide();
|
550
|
|
|
jQuery('#sub_' + active_tab).find('.geodir_show_progress').show();
|
551
|
|
|
jQuery.post('<?php echo geodir_get_ajax_url(); ?>&geodir_autofill=' + id + '&posttype=' + posttype + '&_wpnonce=' + nonce,
|
552
|
|
|
function (data) {
|
553
|
|
|
window.location.href = jQuery('#' + id).attr('redirect_to') + active_tab;
|
554
|
|
|
});
|
555
|
|
|
return true;
|
556
|
|
|
} else {
|
557
|
|
|
return false;
|
558
|
|
|
}
|
559
|
|
|
} else {
|
560
|
|
|
if (!(typeof bound_lat_lng == 'object' && bound_lat_lng.length == 4)) {
|
561
|
|
|
bound_lat_lng = ['<?php echo $city_latitude; ?>', <?php echo $city_longitude; ?>, '<?php echo $city_latitude; ?>', <?php echo $city_longitude; ?>];
|
562
|
|
|
}
|
563
|
|
|
jQuery('#sub_' + active_tab).find('.geodir_auto_install').hide();
|
564
|
|
|
jQuery('#sub_' + active_tab).find('.geodir_show_progress').show();
|
565
|
|
|
|
566
|
|
|
var post_url = '<?php echo geodir_get_ajax_url(); ?>&geodir_autofill=' + id + '&posttype=' + posttype + '&insert_dummy_post_index=' + dummy_post_index + '&city_bound_lat1=' + bound_lat_lng[0] + '&city_bound_lng1=' + bound_lat_lng[1] + '&city_bound_lat2=' + bound_lat_lng[2] + '&city_bound_lng2=' + bound_lat_lng[3] + '&_wpnonce=' + nonce;
|
567
|
|
|
|
568
|
|
|
jQuery.post( post_url, function (data) {
|
569
|
|
|
jQuery(obj).closest('form').find('.dummy_post_inserted').html('<?php _e('Dummy post(s) inserted:','geodirectory');?> ' + dummy_post_index + ' <?php _e('of' ,'geodirectory'); ?> ' + total_dummy_post_count + '');
|
570
|
|
|
|
571
|
|
|
dummy_post_index++;
|
572
|
|
|
|
573
|
|
|
if (dummy_post_index <= total_dummy_post_count)
|
574
|
|
|
geodir_autoinstall(obj, id, nonce, posttype);
|
575
|
|
|
else {
|
576
|
|
|
window.location.href = jQuery('#' + id).attr('redirect_to') + active_tab;
|
577
|
|
|
}
|
578
|
|
|
});
|
579
|
|
|
}
|
580
|
|
|
}
|
581
|
|
|
</script>
|
582
|
|
|
<?php
|
583
|
|
|
}
|
584
|
|
|
}
|
585
|
|
|
}
|
586
|
|
|
|
587
|
|
|
/**
|
588
|
|
|
* Inserts GeoDirectory dummy posts.
|
589
|
|
|
*
|
590
|
|
|
* @since 1.0.0
|
591
|
|
|
* @package GeoDirectory
|
592
|
|
|
* @global object $wpdb WordPress Database object.
|
593
|
|
|
* @global object $current_user Current user object.
|
594
|
|
|
*/
|
595
|
|
|
function geodir_insert_dummy_posts()
|
596
|
|
|
{
|
597
|
|
|
geodir_default_taxonomies();
|
598
|
|
|
|
599
|
|
|
ini_set('max_execution_time', 999999); //300 seconds = 5 minutes
|
600
|
|
|
|
601
|
|
|
global $wpdb, $current_user;
|
602
|
|
|
|
603
|
1 |
|
/**
|
604
|
|
|
* Contains dummy post content.
|
605
|
|
|
*
|
606
|
|
|
* @since 1.0.0
|
607
|
|
|
* @package GeoDirectory
|
608
|
|
|
*/
|
609
|
|
|
include_once('place_dummy_post.php');
|
610
|
|
|
delete_transient( 'cached_dummy_images' );
|
611
|
|
|
|
612
|
|
|
}
|
613
|
|
|
|
614
|
|
|
/**
|
615
|
|
|
* Deletes GeoDirectory dummy data.
|
616
|
|
|
*
|
617
|
|
|
* @since 1.0.0
|
618
|
|
|
* @package GeoDirectory
|
619
|
|
|
* @global object $wpdb WordPress Database object.
|
620
|
|
|
* @global string $plugin_prefix Geodirectory plugin table prefix.
|
621
|
|
|
*/
|
622
|
|
|
function geodir_delete_dummy_posts()
|
623
|
|
|
{
|
624
|
|
|
global $wpdb, $plugin_prefix;
|
625
|
|
|
|
626
|
|
|
|
627
|
|
|
$post_ids = $wpdb->get_results("SELECT post_id FROM " . $plugin_prefix . "gd_place_detail WHERE post_dummy='1'");
|
628
|
|
|
|
629
|
|
|
|
630
|
|
|
foreach ($post_ids as $post_ids_obj) {
|
631
|
|
|
wp_delete_post($post_ids_obj->post_id);
|
632
|
|
|
}
|
633
|
|
|
|
634
|
|
|
//double check posts are deleted
|
635
|
|
|
$wpdb->get_results("DELETE FROM " . $plugin_prefix . "gd_place_detail WHERE post_dummy='1'");
|
636
|
|
|
}
|
637
|
|
|
|
638
|
|
|
/**
|
639
|
|
|
* Default taxonomies
|
640
|
|
|
*
|
641
|
|
|
* Adds the default terms for taxonomies - placecategory. Modify at your own risk.
|
642
|
|
|
*
|
643
|
2 |
|
* @since 1.0.0
|
644
|
|
|
* @package GeoDirectory
|
645
|
|
|
* @global object $wpdb WordPress Database object.
|
646
|
2 |
|
* @global string $dummy_image_path The dummy image path.
|
647
|
|
|
*/
|
648
|
|
|
function geodir_default_taxonomies() {
|
649
|
2 |
|
global $wpdb, $dummy_image_path;
|
650
|
2 |
|
|
651
|
2 |
|
$category_array = array('Attractions', 'Hotels', 'Restaurants', 'Food Nightlife', 'Festival', 'Videos', 'Feature');
|
652
|
|
|
|
653
|
|
|
$last_catid = '';
|
|
|
|
|
654
|
2 |
|
|
655
|
2 |
|
$uploads = wp_upload_dir(); // Array of key => value pairs
|
656
|
|
|
|
657
|
|
|
for ($i = 0; $i < count($category_array); $i++) {
|
|
|
|
|
658
|
|
|
$parent_catid = 0;
|
659
|
|
|
if (is_array($category_array[$i])) {
|
660
|
|
|
$cat_name_arr = $category_array[$i];
|
661
|
|
|
for ($j = 0; $j < count($cat_name_arr); $j++) {
|
|
|
|
|
662
|
|
|
$catname = $cat_name_arr[$j];
|
663
|
|
|
|
664
|
|
|
if (!term_exists($catname, 'gd_placecategory')) {
|
665
|
|
|
$last_catid = wp_insert_term($catname, 'gd_placecategory', $args = array('parent' => $parent_catid));
|
666
|
|
|
|
667
|
|
|
if ($j == 0) {
|
668
|
1 |
|
$parent_catid = $last_catid;
|
669
|
|
|
}
|
670
|
1 |
|
|
671
|
|
|
|
672
|
1 |
|
if (geodir_dummy_folder_exists())
|
673
|
|
|
$dummy_image_url = geodir_plugin_url() . "/geodirectory-admin/dummy/cat_icon";
|
674
|
1 |
|
else
|
675
|
|
|
$dummy_image_url = 'http://www.wpgeodirectory.com/dummy/cat_icon';
|
676
|
1 |
|
|
677
|
1 |
|
$dummy_image_url = apply_filters('place_dummy_cat_image_url', $dummy_image_url);
|
678
|
1 |
|
|
679
|
|
|
$catname = str_replace(' ', '_', $catname);
|
680
|
|
|
$uploaded = (array)fetch_remote_file("$dummy_image_url/" . $catname . ".png");
|
681
|
|
|
|
682
|
|
|
if (empty($uploaded['error'])) {
|
683
|
|
|
$new_path = $uploaded['file'];
|
684
|
|
|
$new_url = $uploaded['url'];
|
685
|
|
|
}
|
686
|
|
|
|
687
|
|
|
$wp_filetype = wp_check_filetype(basename($new_path), null);
|
|
|
|
|
688
|
|
|
|
689
|
|
|
$attachment = array(
|
690
|
|
|
'guid' => $uploads['baseurl'] . '/' . basename($new_path),
|
691
|
|
|
'post_mime_type' => $wp_filetype['type'],
|
692
|
|
|
'post_title' => preg_replace('/\.[^.]+$/', '', basename($new_path)),
|
693
|
|
|
'post_content' => '',
|
694
|
|
|
'post_status' => 'inherit'
|
695
|
|
|
);
|
696
|
|
|
$attach_id = wp_insert_attachment($attachment, $new_path);
|
697
|
|
|
|
698
|
|
|
// you must first include the image.php file
|
699
|
|
|
// for the function wp_generate_attachment_metadata() to work
|
700
|
|
|
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
701
|
|
|
$attach_data = wp_generate_attachment_metadata($attach_id, $new_path);
|
702
|
|
|
wp_update_attachment_metadata($attach_id, $attach_data);
|
703
|
|
|
|
704
|
|
View Code Duplication |
if (!get_tax_meta($last_catid['term_id'], 'ct_cat_icon', false, 'gd_place')) {
|
705
|
|
|
update_tax_meta($last_catid['term_id'], 'ct_cat_icon', array('id' => 'icon', 'src' => $new_url), 'gd_place');
|
|
|
|
|
706
|
|
|
}
|
707
|
|
|
}
|
708
|
|
|
}
|
709
|
|
|
|
710
|
|
|
} else {
|
711
|
|
|
$catname = $category_array[$i];
|
712
|
|
|
|
713
|
|
|
if (!term_exists($catname, 'gd_placecategory')) {
|
714
|
|
|
$last_catid = wp_insert_term($catname, 'gd_placecategory');
|
715
|
|
|
|
716
|
|
|
if (geodir_dummy_folder_exists())
|
717
|
|
|
$dummy_image_url = geodir_plugin_url() . "/geodirectory-admin/dummy/cat_icon";
|
718
|
|
|
else
|
719
|
|
|
$dummy_image_url = 'http://www.wpgeodirectory.com/dummy/cat_icon';
|
720
|
|
|
|
721
|
|
|
$dummy_image_url = apply_filters('place_dummy_cat_image_url', $dummy_image_url);
|
722
|
|
|
|
723
|
|
|
$catname = str_replace(' ', '_', $catname);
|
724
|
|
|
$uploaded = (array)fetch_remote_file("$dummy_image_url/" . $catname . ".png");
|
725
|
|
|
|
726
|
|
|
if (empty($uploaded['error'])) {
|
727
|
|
|
$new_path = $uploaded['file'];
|
728
|
|
|
$new_url = $uploaded['url'];
|
729
|
|
|
}
|
730
|
1 |
|
|
731
|
|
|
$wp_filetype = wp_check_filetype(basename($new_path), null);
|
732
|
1 |
|
|
733
|
|
|
$attachment = array(
|
734
|
|
|
'guid' => $uploads['baseurl'] . '/' . basename($new_path),
|
735
|
|
|
'post_mime_type' => $wp_filetype['type'],
|
736
|
|
|
'post_title' => preg_replace('/\.[^.]+$/', '', basename($new_path)),
|
737
|
|
|
'post_content' => '',
|
738
|
|
|
'post_status' => 'inherit'
|
739
|
|
|
);
|
740
|
|
|
|
741
|
|
|
$attach_id = wp_insert_attachment($attachment, $new_path);
|
742
|
|
|
|
743
|
|
|
|
744
|
|
|
// you must first include the image.php file
|
745
|
|
|
// for the function wp_generate_attachment_metadata() to work
|
746
|
|
|
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
747
|
|
|
$attach_data = wp_generate_attachment_metadata($attach_id, $new_path);
|
748
|
|
|
wp_update_attachment_metadata($attach_id, $attach_data);
|
749
|
|
|
|
750
|
|
View Code Duplication |
if (!get_tax_meta($last_catid['term_id'], 'ct_cat_icon', false, 'gd_place')) {
|
751
|
|
|
update_tax_meta($last_catid['term_id'], 'ct_cat_icon', array('id' => $attach_id, 'src' => $new_url), 'gd_place');
|
752
|
|
|
}
|
753
|
|
|
}
|
754
|
|
|
}
|
755
|
|
|
|
756
|
|
|
}
|
757
|
|
|
}
|
758
|
|
|
|
759
|
|
|
/**
|
760
|
|
|
* Update options
|
761
|
|
|
*
|
762
|
|
|
* Updates the options on the geodirectory settings pages. Returns true if saved.
|
763
|
|
|
*
|
764
|
|
|
* @since 1.0.0
|
765
|
|
|
* @package GeoDirectory
|
766
|
|
|
* @param array $options The option array.
|
767
|
|
|
* @param bool $dummy Is this dummy settings? Default: false.
|
768
|
|
|
* @return bool Returns true if saved.
|
769
|
|
|
*/
|
770
|
|
|
function geodir_update_options($options, $dummy = false) {
|
771
|
|
|
if ((!isset($_POST) || !$_POST) && !$dummy) return false;
|
772
|
|
|
|
773
|
|
|
foreach ($options as $value) {
|
774
|
|
|
if ($dummy && isset($value['std']))
|
775
|
1 |
|
$_POST[$value['id']] = $value['std'];
|
776
|
1 |
|
|
777
|
|
|
|
778
|
|
|
if (isset($value['type']) && $value['type'] == 'checkbox') :
|
779
|
|
|
|
780
|
|
View Code Duplication |
if (isset($value['id']) && isset($_POST[$value['id']])) {
|
781
|
|
|
update_option($value['id'], $_POST[$value['id']]);
|
782
|
|
|
} else {
|
783
|
|
|
update_option($value['id'], 0);
|
784
|
|
|
}
|
785
|
|
|
|
786
|
|
|
elseif (isset($value['type']) && $value['type'] == 'image_width') :
|
787
|
|
|
|
788
|
|
|
if (isset($value['id']) && isset($_POST[$value['id'] . '_width'])) {
|
789
|
|
|
update_option($value['id'] . '_width', $_POST[$value['id'] . '_width']);
|
790
|
1 |
|
update_option($value['id'] . '_height', $_POST[$value['id'] . '_height']);
|
791
|
|
View Code Duplication |
if (isset($_POST[$value['id'] . '_crop'])) :
|
792
|
1 |
|
update_option($value['id'] . '_crop', 1);
|
793
|
1 |
|
else :
|
794
|
1 |
|
update_option($value['id'] . '_crop', 0);
|
795
|
|
|
endif;
|
796
|
|
View Code Duplication |
} else {
|
797
|
1 |
|
update_option($value['id'] . '_width', $value['std']);
|
798
|
|
|
update_option($value['id'] . '_height', $value['std']);
|
799
|
1 |
|
update_option($value['id'] . '_crop', 1);
|
800
|
1 |
|
}
|
801
|
1 |
|
|
802
|
|
|
elseif (isset($value['type']) && $value['type'] == 'map') :
|
803
|
|
|
$post_types = array();
|
804
|
|
|
$categories = array();
|
805
|
1 |
|
|
806
|
|
|
if (!empty($_POST['home_map_post_types'])) :
|
807
|
|
|
foreach ($_POST['home_map_post_types'] as $post_type) :
|
808
|
|
|
$post_types[] = $post_type;
|
809
|
|
|
endforeach;
|
810
|
|
|
endif;
|
811
|
|
|
|
812
|
|
|
update_option('geodir_exclude_post_type_on_map', $post_types);
|
813
|
|
|
|
814
|
|
|
if (!empty($_POST['post_category'])) :
|
815
|
|
|
foreach ($_POST['post_category'] as $texonomy => $cat_arr) :
|
816
|
|
|
$categories[$texonomy] = array();
|
817
|
|
|
foreach ($cat_arr as $category) :
|
818
|
|
|
$categories[$texonomy][] = $category;
|
819
|
|
|
endforeach;
|
820
|
|
|
$categories[$texonomy] = !empty($categories[$texonomy]) ? array_unique($categories[$texonomy]) : array();
|
821
|
1 |
|
endforeach;
|
822
|
1 |
|
endif;
|
823
|
1 |
|
update_option('geodir_exclude_cat_on_map', $categories);
|
824
|
|
|
update_option('geodir_exclude_cat_on_map_upgrade', 1);
|
825
|
1 |
|
elseif (isset($value['type']) && $value['type'] == 'map_default_settings') :
|
826
|
|
|
|
827
|
|
|
|
828
|
|
|
if (!empty($_POST['geodir_default_map_language'])):
|
829
|
|
|
update_option('geodir_default_map_language', $_POST['geodir_default_map_language']);
|
830
|
|
|
endif;
|
831
|
1 |
|
|
832
|
|
|
|
833
|
1 |
|
if (!empty($_POST['geodir_default_map_search_pt'])):
|
834
|
|
|
update_option('geodir_default_map_search_pt', $_POST['geodir_default_map_search_pt']);
|
835
|
|
|
endif;
|
836
|
|
|
|
837
|
|
|
|
838
|
|
|
elseif (isset($value['type']) && $value['type'] == 'file') :
|
839
|
|
|
|
840
|
|
|
|
841
|
|
|
if (isset($_POST[$value['id'] . '_remove']) && $_POST[$value['id'] . '_remove']) {// if remove is set then remove the file
|
842
|
1 |
|
|
843
|
1 |
View Code Duplication |
if (get_option($value['id'])) {
|
844
|
1 |
|
$image_name_arr = explode('/', get_option($value['id']));
|
845
|
|
|
$noimg_name = end($image_name_arr);
|
846
|
|
|
$img_path = $uploads['path'] . '/' . $noimg_name;
|
|
|
|
|
847
|
1 |
|
if (file_exists($img_path))
|
848
|
|
|
unlink($img_path);
|
849
|
|
|
}
|
850
|
|
|
|
851
|
|
|
update_option($value['id'], '');
|
852
|
1 |
|
}
|
853
|
|
|
|
854
|
|
|
$uploadedfile = isset($_FILES[$value['id']]) ? $_FILES[$value['id']] : '';
|
855
|
|
|
$filename = isset($_FILES[$value['id']]['name']) ? $_FILES[$value['id']]['name'] : '';
|
856
|
|
|
|
857
|
1 |
|
if (!empty($filename)):
|
858
|
|
|
$ext = pathinfo($filename, PATHINFO_EXTENSION);
|
|
|
|
|
859
|
|
|
$uplaods = array();
|
860
|
1 |
|
|
861
|
|
|
foreach ($uploadedfile as $key => $uplaod):
|
862
|
|
|
if ($key == 'name'):
|
863
|
|
|
$uplaods[$key] = $filename;
|
864
|
|
|
else :
|
865
|
|
|
$uplaods[$key] = $uplaod;
|
866
|
|
|
endif;
|
867
|
|
|
endforeach;
|
868
|
|
|
|
869
|
|
|
$uploads = wp_upload_dir();
|
870
|
|
|
|
871
|
|
View Code Duplication |
if (get_option($value['id'])) {
|
872
|
|
|
$image_name_arr = explode('/', get_option($value['id']));
|
873
|
1 |
|
$noimg_name = end($image_name_arr);
|
874
|
1 |
|
$img_path = $uploads['path'] . '/' . $noimg_name;
|
875
|
|
|
if (file_exists($img_path))
|
876
|
1 |
|
unlink($img_path);
|
877
|
|
|
}
|
878
|
|
|
|
879
|
|
|
$upload_overrides = array('test_form' => false);
|
880
|
|
|
$movefile = wp_handle_upload($uplaods, $upload_overrides);
|
881
|
|
|
|
882
|
|
|
update_option($value['id'], $movefile['url']);
|
883
|
|
|
|
884
|
|
|
endif;
|
885
|
|
|
|
886
|
|
|
if (!get_option($value['id']) && isset($value['value'])):
|
887
|
|
|
update_option($value['id'], $value['value']);
|
888
|
|
|
endif;
|
889
|
|
|
|
890
|
|
|
|
891
|
|
|
else :
|
892
|
|
|
// same menu setting per theme.
|
893
|
|
|
if (isset($value['id']) && $value['id'] == 'geodir_theme_location_nav' && isset($_POST[$value['id']])) {
|
894
|
|
|
$theme = wp_get_theme();
|
895
|
|
|
update_option('geodir_theme_location_nav_' . $theme->name, $_POST[$value['id']]);
|
896
|
|
|
}
|
897
|
|
|
|
898
|
|
View Code Duplication |
if (isset($value['id']) && isset($_POST[$value['id']])) {
|
899
|
|
|
update_option($value['id'], $_POST[$value['id']]);
|
900
|
|
|
} else {
|
901
|
|
|
delete_option($value['id']);
|
902
|
|
|
}
|
903
|
|
|
|
904
|
|
|
endif;
|
905
|
1 |
|
}
|
906
|
|
|
if ($dummy)
|
907
|
|
|
$_POST = array();
|
908
|
|
|
return true;
|
909
|
|
|
|
910
|
1 |
|
}
|
911
|
|
|
|
912
|
1 |
|
/**
|
913
|
1 |
|
* create custom fields for place.
|
914
|
1 |
|
*
|
915
|
1 |
|
* @since 1.0.0
|
916
|
|
|
* @package GeoDirectory
|
917
|
1 |
|
* @param array $tabs {
|
918
|
1 |
|
* Attributes of the tabs array.
|
919
|
1 |
|
*
|
920
|
1 |
|
* @type array $general_settings {
|
921
|
|
|
* Attributes of general settings.
|
922
|
|
|
*
|
923
|
|
|
* @type string $label Default "General".
|
924
|
1 |
|
*
|
925
|
|
|
* }
|
926
|
1 |
|
* @type array $design_settings {
|
927
|
1 |
|
* Attributes of design settings.
|
928
|
|
|
*
|
929
|
|
|
* @type string $label Default "Design".
|
930
|
|
|
*
|
931
|
|
|
* }
|
932
|
|
|
* @type array $permalink_settings {
|
933
|
|
|
* Attributes of permalink settings.
|
934
|
|
|
*
|
935
|
|
|
* @type string $label Default "Permalinks".
|
936
|
|
|
*
|
937
|
|
|
* }
|
938
|
|
|
* @type array $notifications_settings {
|
939
|
|
|
* Attributes of notifications settings.
|
940
|
|
|
*
|
941
|
|
|
* @type string $label Default "Notifications".
|
942
|
|
|
*
|
943
|
|
|
* }
|
944
|
|
|
* @type array $default_location_settings {
|
945
|
|
|
* Attributes of default location settings.
|
946
|
|
|
*
|
947
|
|
|
* @type string $label Default "Set Default Location".
|
948
|
|
|
*
|
949
|
|
|
* }
|
950
|
|
|
*
|
951
|
|
|
* }
|
952
|
|
|
* @return array Modified tabs array.
|
953
|
|
|
*/
|
954
|
|
|
function places_custom_fields_tab($tabs)
|
955
|
|
|
{
|
956
|
|
|
|
957
|
|
|
$geodir_post_types = get_option('geodir_post_types');
|
958
|
|
|
|
959
|
|
|
if (!empty($geodir_post_types)) {
|
960
|
|
|
|
961
|
|
|
foreach ($geodir_post_types as $geodir_post_type => $geodir_posttype_info):
|
962
|
|
|
|
963
|
|
|
$listing_slug = $geodir_posttype_info['labels']['singular_name'];
|
964
|
|
|
|
965
|
|
|
$tabs[$geodir_post_type . '_fields_settings'] = array(
|
966
|
|
|
'label' => __(ucfirst($listing_slug) . ' Settings', 'geodirectory'),
|
967
|
|
|
'subtabs' => array(
|
968
|
|
|
array('subtab' => 'custom_fields',
|
969
|
|
|
'label' => __('Custom Fields', 'geodirectory'),
|
970
|
|
|
'request' => array('listing_type' => $geodir_post_type)),
|
971
|
|
|
array('subtab' => 'sorting_options',
|
972
|
|
|
'label' => __('Sorting Options', 'geodirectory'),
|
973
|
|
|
'request' => array('listing_type' => $geodir_post_type)),
|
974
|
|
|
),
|
975
|
|
|
'tab_index' => 9,
|
976
|
|
|
'request' => array('listing_type' => $geodir_post_type)
|
977
|
|
|
);
|
978
|
|
|
|
979
|
|
|
endforeach;
|
980
|
|
|
|
981
|
|
|
}
|
982
|
|
|
|
983
|
|
|
return $tabs;
|
984
|
|
|
}
|
985
|
|
|
|
986
|
|
|
|
987
|
|
|
/**
|
988
|
|
|
* Adds GD Tools settings menu to GeoDirectory settings.
|
989
|
|
|
*
|
990
|
|
|
* Can be found here. WP Admin -> Geodirectory -> GD Tools.
|
991
|
|
|
*
|
992
|
|
|
* @since 1.0.0
|
993
|
|
|
* @package GeoDirectory
|
994
|
|
|
* @param array $tabs Tab menu array {@see places_custom_fields_tab()}.
|
995
|
|
|
* @return array Modified tab menu array.
|
996
|
|
|
*/
|
997
|
|
|
function geodir_tools_setting_tab($tabs)
|
998
|
|
|
{
|
999
|
|
|
wp_enqueue_script( 'jquery-ui-progressbar' );
|
1000
|
|
|
$tabs['tools_settings'] = array('label' => __('GD Tools', 'geodirectory'));
|
1001
|
|
|
return $tabs;
|
1002
|
|
|
}
|
1003
|
|
|
|
1004
|
|
|
/**
|
1005
|
|
|
* Adds Theme Compatibility menu item to GeoDirectory settings page.
|
1006
|
|
|
*
|
1007
|
|
|
* Can be found here. WP Admin -> Geodirectory -> Theme Compatibility.
|
1008
|
|
|
*
|
1009
|
|
|
* @since 1.0.0
|
1010
|
|
|
* @package GeoDirectory
|
1011
|
|
|
* @param array $tabs Tab menu array {@see places_custom_fields_tab()}.
|
1012
|
|
|
* @return array Modified tab menu array.
|
1013
|
|
|
*/
|
1014
|
|
|
function geodir_compatibility_setting_tab($tabs)
|
1015
|
|
|
{
|
1016
|
|
|
$tabs['compatibility_settings'] = array('label' => __('Theme Compatibility', 'geodirectory'));
|
1017
|
|
|
return $tabs;
|
1018
|
|
|
}
|
1019
|
|
|
|
1020
|
|
|
|
1021
|
|
|
/**
|
1022
|
|
|
* Adds Extend Geodirectory menu item to GeoDirectory settings page.
|
1023
|
|
|
*
|
1024
|
|
|
* Can be found here. WP Admin -> Geodirectory -> Extend Geodirectory.
|
1025
|
|
|
*
|
1026
|
|
|
* @since 1.0.0
|
1027
|
|
|
* @package GeoDirectory
|
1028
|
|
|
* @param array $tabs Tab menu array {@see places_custom_fields_tab()}.
|
1029
|
|
|
* @return array Modified tab menu array.
|
1030
|
|
|
*/
|
1031
|
|
|
function geodir_extend_geodirectory_setting_tab($tabs)
|
1032
|
|
|
{
|
1033
|
|
|
$tabs['extend_geodirectory_settings'] = array('label' => __('Extend Geodirectory', 'geodirectory'). ' <i class="fa fa-plug"></i>', 'url' => 'http://wpgeodirectory.com', 'target' => '_blank');
|
1034
|
|
|
return $tabs;
|
1035
|
|
|
}
|
1036
|
|
|
|
1037
|
|
|
|
1038
|
|
|
if (!function_exists('geodir_edit_post_columns')) {
|
1039
|
|
|
/**
|
1040
|
|
|
* Modify admin post listing page columns.
|
1041
|
|
|
*
|
1042
|
|
|
* @since 1.0.0
|
1043
|
|
|
* @package GeoDirectory
|
1044
|
|
|
* @param array $columns The column array.
|
1045
|
|
|
* @return array Altered column array.
|
1046
|
|
|
*/
|
1047
|
|
|
function geodir_edit_post_columns($columns)
|
1048
|
|
|
{
|
1049
|
|
|
|
1050
|
|
|
$new_columns = array('location' => __('Location (ID)', 'geodirectory'),
|
1051
|
|
|
'categorys' => __('Categories', 'geodirectory'));
|
1052
|
|
|
|
1053
|
|
|
if (($offset = array_search('author', array_keys($columns))) === false) // if the key doesn't exist
|
1054
|
|
|
{
|
1055
|
|
|
$offset = 0; // should we prepend $array with $data?
|
|
|
|
|
1056
|
|
|
$offset = count($columns); // or should we append $array with $data? lets pick this one...
|
1057
|
|
|
}
|
1058
|
|
|
|
1059
|
|
|
$columns = array_merge(array_slice($columns, 0, $offset), $new_columns, array_slice($columns, $offset));
|
1060
|
|
|
|
1061
|
|
|
$columns = array_merge($columns, array('expire' => __('Expires', 'geodirectory')));
|
1062
|
|
|
|
1063
|
|
|
return $columns;
|
1064
|
|
|
}
|
1065
|
|
|
}
|
1066
|
|
|
|
1067
|
|
|
|
1068
|
|
|
if (!function_exists('geodir_manage_post_columns')) {
|
1069
|
|
|
/**
|
1070
|
|
|
* Adds content to our custom post listing page columns.
|
1071
|
|
|
*
|
1072
|
|
|
* @since 1.0.0
|
1073
|
|
|
* @package GeoDirectory
|
1074
|
|
|
* @global object $wpdb WordPress Database object.
|
1075
|
|
|
* @global object $post WordPress Post object.
|
1076
|
|
|
* @param string $column The column name.
|
1077
|
|
|
* @param int $post_id The post ID.
|
1078
|
|
|
*/
|
1079
|
|
|
function geodir_manage_post_columns($column, $post_id)
|
1080
|
|
|
{
|
1081
|
|
|
global $post, $wpdb;
|
1082
|
|
|
|
1083
|
|
|
switch ($column):
|
1084
|
|
|
/* If displaying the 'city' column. */
|
1085
|
|
|
case 'location' :
|
1086
|
|
|
$location_id = geodir_get_post_meta($post->ID, 'post_location_id', true);
|
1087
|
|
|
$location = geodir_get_location($location_id);
|
1088
|
|
|
/* If no city is found, output a default message. */
|
1089
|
|
|
if (empty($location)) {
|
1090
|
|
|
_e('Unknown', 'geodirectory');
|
1091
|
|
|
} else {
|
1092
|
|
|
/* If there is a city id, append 'city name' to the text string. */
|
1093
|
|
|
$add_location_id = $location_id > 0 ? ' (' . $location_id . ')' : '';
|
1094
|
|
|
echo(__($location->country, 'geodirectory') . '-' . $location->region . '-' . $location->city . $add_location_id);
|
1095
|
|
|
}
|
1096
|
|
|
break;
|
1097
|
|
|
|
1098
|
|
|
/* If displaying the 'expire' column. */
|
1099
|
|
|
case 'expire' :
|
1100
|
|
|
$expire_date = geodir_get_post_meta($post->ID, 'expire_date', true);
|
1101
|
|
|
$d1 = $expire_date; // get expire_date
|
1102
|
|
|
$d2 = date('Y-m-d'); // get current date
|
1103
|
|
|
$state = __('days left', 'geodirectory');
|
1104
|
|
|
$date_diff_text = '';
|
1105
|
|
|
$expire_class = 'expire_left';
|
1106
|
|
|
if ($expire_date != 'Never') {
|
1107
|
|
|
if (strtotime($d1) < strtotime($d2)) {
|
1108
|
|
|
$state = __('days overdue', 'geodirectory');
|
1109
|
|
|
$expire_class = 'expire_over';
|
1110
|
|
|
}
|
1111
|
|
|
$date_diff = round(abs(strtotime($d1) - strtotime($d2)) / 86400); // get the difference in days
|
1112
|
|
|
$date_diff_text = '<br /><span class="' . $expire_class . '">(' . $date_diff . ' ' . $state . ')</span>';
|
1113
|
|
|
}
|
1114
|
|
|
/* If no expire_date is found, output a default message. */
|
1115
|
|
|
if (empty($expire_date))
|
1116
|
|
|
echo __('Unknown', 'geodirectory');
|
1117
|
|
|
/* If there is a expire_date, append 'days left' to the text string. */
|
1118
|
|
|
else
|
1119
|
|
|
echo $expire_date . $date_diff_text;
|
1120
|
|
|
break;
|
1121
|
|
|
|
1122
|
|
|
/* If displaying the 'categorys' column. */
|
1123
|
|
|
case 'categorys' :
|
1124
|
|
|
|
1125
|
|
|
/* Get the categorys for the post. */
|
1126
|
|
|
|
1127
|
|
|
|
1128
|
|
|
$terms = wp_get_object_terms($post_id, get_object_taxonomies($post));
|
1129
|
|
|
|
1130
|
|
|
/* If terms were found. */
|
1131
|
|
|
if (!empty($terms)) {
|
1132
|
|
|
$out = array();
|
1133
|
|
|
/* Loop through each term, linking to the 'edit posts' page for the specific term. */
|
1134
|
|
|
foreach ($terms as $term) {
|
1135
|
|
|
if (!strstr($term->taxonomy, 'tag')) {
|
1136
|
|
|
$out[] = sprintf('<a href="%s">%s</a>',
|
1137
|
|
|
esc_url(add_query_arg(array('post_type' => $post->post_type, $term->taxonomy => $term->slug), 'edit.php')),
|
1138
|
|
|
esc_html(sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, 'display'))
|
1139
|
|
|
);
|
1140
|
|
|
}
|
1141
|
|
|
}
|
1142
|
|
|
/* Join the terms, separating them with a comma. */
|
1143
|
|
|
echo(join(', ', $out));
|
1144
|
|
|
} /* If no terms were found, output a default message. */
|
1145
|
|
|
else {
|
1146
|
|
|
_e('No Categories', 'geodirectory');
|
1147
|
|
|
}
|
1148
|
|
|
break;
|
1149
|
|
|
|
1150
|
|
|
endswitch;
|
1151
|
|
|
}
|
1152
|
|
|
}
|
1153
|
|
|
|
1154
|
|
|
|
1155
|
|
|
if (!function_exists('geodir_post_sortable_columns')) {
|
1156
|
|
|
/**
|
1157
|
|
|
* Makes admin post listing page columns sortable.
|
1158
|
|
|
*
|
1159
|
|
|
* @since 1.0.0
|
1160
|
|
|
* @package GeoDirectory
|
1161
|
|
|
* @param array $columns The column array.
|
1162
|
|
|
* @return array Altered column array.
|
1163
|
|
|
*/
|
1164
|
|
|
function geodir_post_sortable_columns($columns)
|
1165
|
|
|
{
|
1166
|
|
|
|
1167
|
|
|
$columns['expire'] = 'expire';
|
1168
|
|
|
|
1169
|
|
|
return $columns;
|
1170
|
|
|
}
|
1171
|
|
|
}
|
1172
|
|
|
|
1173
|
|
|
/**
|
1174
|
|
|
* Saves listing data from request variable to database.
|
1175
|
|
|
*
|
1176
|
|
|
* @since 1.0.0
|
1177
|
|
|
* @package GeoDirectory
|
1178
|
|
|
* @global object $wpdb WordPress Database object.
|
1179
|
|
|
* @global object $current_user Current user object.
|
1180
|
|
|
* @global object $post WordPress Post object.
|
1181
|
|
|
* @param int $post_id The post ID.
|
1182
|
|
|
*/
|
1183
|
|
|
function geodir_post_information_save($post_id, $post) {
|
1184
|
|
|
global $wpdb, $current_user;
|
1185
|
|
|
|
1186
|
|
|
if (isset($post->post_type) && ($post->post_type=='nav_menu_item' || $post->post_type=='page' || $post->post_type=='post')) {
|
1187
|
|
|
return;
|
1188
|
|
|
}
|
1189
|
|
|
|
1190
|
|
|
$geodir_posttypes = geodir_get_posttypes();
|
1191
|
|
|
|
1192
|
|
|
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
|
1193
|
|
|
return;
|
1194
|
|
|
|
1195
|
|
|
if (!wp_is_post_revision($post_id) && isset($post->post_type) && in_array($post->post_type, $geodir_posttypes)) {
|
1196
|
|
|
if (isset($_REQUEST['_status']))
|
1197
|
|
|
geodir_change_post_status($post_id, $_REQUEST['_status']);
|
1198
|
|
|
|
1199
|
|
|
if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'trash' || $_REQUEST['action'] == 'untrash'))
|
1200
|
|
|
return;
|
1201
|
|
|
|
1202
|
|
View Code Duplication |
if (!isset($_POST['geodir_post_info_noncename']) || !wp_verify_nonce($_POST['geodir_post_info_noncename'], plugin_basename(__FILE__)))
|
1203
|
2 |
|
return;
|
1204
|
|
|
|
1205
|
2 |
View Code Duplication |
if (!isset($_POST['geodir_post_attachments_noncename']) || !wp_verify_nonce($_POST['geodir_post_attachments_noncename'], plugin_basename(__FILE__)))
|
1206
|
2 |
|
return;
|
1207
|
|
|
|
1208
|
|
|
geodir_save_listing($_REQUEST);
|
1209
|
|
|
}
|
1210
|
|
|
}
|
1211
|
|
|
|
1212
|
|
|
/**
|
1213
|
|
|
* Admin fields
|
1214
|
|
|
*
|
1215
|
|
|
* Loops though the geodirectory options array and outputs each field.
|
1216
|
|
|
*
|
1217
|
|
|
* @since 1.0.0
|
1218
|
|
|
* @package GeoDirectory
|
1219
|
|
|
* @global object $geodirectory GeoDirectory plugin object.
|
1220
|
|
|
* @global object $sitepress Sitepress WPML object.
|
1221
|
|
|
* @param array $options The options array.
|
1222
|
|
|
*/
|
1223
|
|
|
function geodir_admin_fields($options)
|
1224
|
|
|
{
|
1225
|
|
|
global $geodirectory;
|
1226
|
|
|
|
1227
|
|
|
$first_title = true;
|
1228
|
|
|
$tab_id = '';
|
1229
|
|
|
$i = 0;
|
1230
|
|
|
foreach ($options as $value) :
|
1231
|
|
|
if (!isset($value['name'])) $value['name'] = '';
|
1232
|
|
|
if (!isset($value['class'])) $value['class'] = '';
|
1233
|
|
|
if (!isset($value['css'])) $value['css'] = '';
|
1234
|
|
|
if (!isset($value['std'])) $value['std'] = '';
|
1235
|
|
|
$desc = '';
|
1236
|
|
|
switch ($value['type']) :
|
1237
|
|
|
case 'dummy_installer':
|
1238
|
|
|
$post_type = isset($value['post_type']) ? $value['post_type'] : 'gd_place';
|
1239
|
|
|
geodir_autoinstall_admin_header($post_type);
|
1240
|
|
|
break;
|
1241
|
|
|
case 'title':
|
1242
|
|
|
|
1243
|
|
|
if ($i == 0) {
|
1244
|
1 |
|
echo '<dl id="geodir_oiption_tabs" class="gd-tab-head"></dl>';
|
1245
|
|
|
echo '<div class="inner_content_tab_main">';
|
1246
|
1 |
|
}
|
1247
|
1 |
|
|
1248
|
1 |
|
$i++;
|
1249
|
1 |
|
|
1250
|
1 |
|
if (isset($value['id']) && $value['id'])
|
1251
|
1 |
|
$tab_id = $value['id'];
|
1252
|
1 |
|
|
1253
|
1 |
View Code Duplication |
if (isset($value['desc']) && $value['desc'])
|
1254
|
1 |
|
$desc = '<span style=" text-transform:none;">:- ' . $value['desc'] . '</span>';
|
|
|
|
|
1255
|
1 |
|
|
1256
|
1 |
|
if (isset($value['name']) && $value['name']) {
|
1257
|
1 |
|
if ($first_title === true) {
|
1258
|
1 |
|
$first_title = false;
|
1259
|
1 |
|
} else {
|
1260
|
1 |
|
echo '</div>';
|
1261
|
|
|
}
|
1262
|
1 |
|
echo '<dd id="' . trim($tab_id) . '" class="geodir_option_tabs" ><a href="javascript:void(0);">' . $value['name'] . '</a></dd>';
|
1263
|
1 |
|
|
1264
|
1 |
|
echo '<div id="sub_' . trim($tab_id) . '" class="gd-content-heading" style=" margin-bottom:10px;" >';
|
1265
|
1 |
|
}
|
1266
|
|
|
|
1267
|
1 |
|
/**
|
1268
|
|
|
* Called after a GeoDirectory settings title is output in the GD settings page.
|
1269
|
1 |
|
*
|
1270
|
1 |
|
* The action is called dynamically geodir_settings_$value['id'].
|
1271
|
|
|
*
|
1272
|
1 |
|
* @since 1.0.0
|
1273
|
1 |
|
*/
|
1274
|
|
|
do_action('geodir_settings_' . sanitize_title($value['id']));
|
1275
|
1 |
|
break;
|
1276
|
1 |
|
|
1277
|
1 |
|
case 'no_tabs':
|
1278
|
1 |
|
|
1279
|
1 |
|
echo '<div class="inner_content_tab_main">';
|
1280
|
|
|
echo '<div id="sub_' . trim($tab_id) . '" class="gd-content-heading" style=" margin-bottom:10px;" >';
|
1281
|
1 |
|
|
1282
|
|
|
break;
|
1283
|
1 |
|
|
1284
|
1 |
|
case 'sectionstart':
|
1285
|
|
View Code Duplication |
if (isset($value['desc']) && $value['desc'])
|
1286
|
|
|
$desc = '<span style=" text-transform:none;"> - ' . $value['desc'] . '</span>';
|
1287
|
|
View Code Duplication |
if (isset($value['name']) && $value['name'])
|
1288
|
|
|
echo '<h3>' . $value['name'] . $desc . '</h3>';
|
1289
|
|
|
/**
|
1290
|
|
|
* Called after a GeoDirectory settings sectionstart is output in the GD settings page.
|
1291
|
|
|
*
|
1292
|
|
|
* The action is called dynamically geodir_settings_$value['id']_start.
|
1293
|
1 |
|
*
|
1294
|
1 |
|
* @since 1.0.0
|
1295
|
|
|
*/
|
1296
|
1 |
View Code Duplication |
if (isset($value['id']) && $value['id']) do_action('geodir_settings_' . sanitize_title($value['id']) . '_start');
|
1297
|
|
|
echo '<table class="form-table">' . "\n\n";
|
1298
|
1 |
|
|
1299
|
1 |
|
break;
|
1300
|
|
|
case 'sectionend':
|
1301
|
1 |
|
/**
|
1302
|
|
|
* Called before a GeoDirectory settings sectionend is output in the GD settings page.
|
1303
|
1 |
|
*
|
1304
|
1 |
|
* The action is called dynamically geodir_settings_$value['id']_end.
|
1305
|
1 |
|
*
|
1306
|
1 |
|
* @since 1.0.0
|
1307
|
1 |
|
*/
|
1308
|
|
View Code Duplication |
if (isset($value['id']) && $value['id']) do_action('geodir_settings_' . sanitize_title($value['id']) . '_end');
|
1309
|
|
|
echo '</table>';
|
1310
|
|
|
/**
|
1311
|
|
|
* Called after a GeoDirectory settings sectionend is output in the GD settings page.
|
1312
|
|
|
*
|
1313
|
|
|
* The action is called dynamically geodir_settings_$value['id']_end.
|
1314
|
|
|
*
|
1315
|
1 |
|
* @since 1.0.0
|
1316
|
1 |
|
*/
|
1317
|
|
View Code Duplication |
if (isset($value['id']) && $value['id']) do_action('geodir_settings_' . sanitize_title($value['id']) . '_after');
|
1318
|
1 |
|
break;
|
1319
|
1 |
View Code Duplication |
case 'text':
|
1320
|
|
|
?>
|
1321
|
|
|
<tr valign="top">
|
1322
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
|
1323
|
|
|
<td class="forminp"><input name="<?php echo esc_attr($value['id']); ?>"
|
1324
|
|
|
id="<?php echo esc_attr($value['id']); ?>"
|
1325
|
|
|
type="<?php echo esc_attr($value['type']); ?>"
|
1326
|
|
|
<?php if(isset($value['placeholder'])){?>placeholder="<?php echo esc_attr($value['placeholder']); ?>"<?php }?>
|
1327
|
1 |
|
style=" <?php echo esc_attr($value['css']); ?>"
|
1328
|
1 |
|
value="<?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
|
1329
|
|
|
echo esc_attr(stripslashes(get_option($value['id'])));
|
1330
|
|
|
} else {
|
1331
|
|
|
echo esc_attr($value['std']);
|
1332
|
|
|
} ?>"/> <span class="description"><?php echo $value['desc']; ?></span></td>
|
1333
|
|
|
</tr><?php
|
1334
|
|
|
break;
|
1335
|
|
|
|
1336
|
1 |
View Code Duplication |
case 'password':
|
1337
|
1 |
|
?>
|
1338
|
1 |
|
<tr valign="top">
|
1339
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
|
1340
|
|
|
<td class="forminp"><input name="<?php echo esc_attr($value['id']); ?>"
|
1341
|
|
|
id="<?php echo esc_attr($value['id']); ?>"
|
1342
|
|
|
type="<?php echo esc_attr($value['type']); ?>"
|
1343
|
|
|
<?php if(isset($value['placeholder'])){?>placeholder="<?php echo esc_attr($value['placeholder']); ?>"<?php }?>
|
1344
|
|
|
style="<?php echo esc_attr($value['css']); ?>"
|
1345
|
|
|
value="<?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
|
1346
|
|
|
echo esc_attr(stripslashes(get_option($value['id'])));
|
1347
|
|
|
} else {
|
1348
|
1 |
|
echo esc_attr($value['std']);
|
1349
|
1 |
|
} ?>"/> <span class="description"><?php echo $value['desc']; ?></span></td>
|
1350
|
|
|
</tr><?php
|
1351
|
|
|
break;
|
1352
|
|
|
|
1353
|
1 |
|
case 'html_content':
|
1354
|
|
|
?>
|
1355
|
1 |
|
<tr valign="top">
|
1356
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
|
1357
|
|
|
<td class="forminp"><span class="description"><?php echo $value['desc']; ?></span></td>
|
1358
|
|
|
</tr><?php
|
1359
|
|
|
break;
|
1360
|
|
|
|
1361
|
|
|
case 'color' :
|
1362
|
|
|
?>
|
1363
|
|
|
<tr valign="top">
|
1364
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
|
1365
|
1 |
|
<td class="forminp"><input name="<?php echo esc_attr($value['id']); ?>"
|
1366
|
1 |
|
id="<?php echo esc_attr($value['id']); ?>" type="text"
|
1367
|
|
|
style="<?php echo esc_attr($value['css']); ?>"
|
1368
|
|
|
value="<?php if (get_option($value['id']) !== false && get_option($value['id']) !== null) {
|
1369
|
|
|
echo esc_attr(stripslashes(get_option($value['id'])));
|
1370
|
1 |
|
} else {
|
1371
|
|
|
echo esc_attr($value['std']);
|
1372
|
1 |
|
} ?>" class="colorpick"/> <span
|
1373
|
|
|
class="description"><?php echo $value['desc']; ?></span>
|
1374
|
|
|
|
1375
|
|
|
<div id="colorPickerDiv_<?php echo esc_attr($value['id']); ?>" class="colorpickdiv"
|
1376
|
|
|
style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>
|
1377
|
|
|
</td>
|
1378
|
1 |
|
</tr><?php
|
1379
|
|
|
break;
|
1380
|
1 |
|
case 'image_width' :
|
1381
|
|
|
?>
|
1382
|
|
|
<tr valign="top">
|
1383
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1384
|
|
|
<td class="forminp">
|
1385
|
|
|
|
1386
|
|
|
<?php _e('Width', 'geodirectory'); ?> <input
|
1387
|
|
|
name="<?php echo esc_attr($value['id']); ?>_width"
|
1388
|
1 |
|
id="<?php echo esc_attr($value['id']); ?>_width" type="text" size="3"
|
1389
|
1 |
|
value="<?php if ($size = get_option($value['id'] . '_width')) echo stripslashes($size); else echo $value['std']; ?>"/>
|
1390
|
|
|
|
1391
|
|
|
<?php _e('Height', 'geodirectory'); ?> <input
|
1392
|
|
|
name="<?php echo esc_attr($value['id']); ?>_height"
|
1393
|
|
|
id="<?php echo esc_attr($value['id']); ?>_height" type="text" size="3"
|
1394
|
|
|
value="<?php if ($size = get_option($value['id'] . '_height')) echo stripslashes($size); else echo $value['std']; ?>"/>
|
1395
|
|
|
|
1396
|
|
|
<label><?php _e('Hard Crop', 'geodirectory'); ?> <input
|
1397
|
|
|
name="<?php echo esc_attr($value['id']); ?>_crop"
|
1398
|
1 |
|
id="<?php echo esc_attr($value['id']); ?>_crop"
|
1399
|
1 |
|
type="checkbox" <?php if (get_option($value['id'] . '_crop') != '') checked(get_option($value['id'] . '_crop'), 1); else checked(1); ?> /></label>
|
1400
|
|
|
|
1401
|
|
|
<span class="description"><?php echo $value['desc'] ?></span></td>
|
1402
|
|
|
</tr><?php
|
1403
|
|
|
break;
|
1404
|
|
|
case 'select':
|
1405
|
|
|
$option_value = get_option($value['id']);
|
1406
|
|
|
$option_value = !empty($option_value) ? stripslashes_deep($option_value) : $option_value;
|
1407
|
|
|
?>
|
1408
|
|
|
<tr valign="top">
|
1409
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1410
|
|
|
<td class="forminp"><select name="<?php echo esc_attr($value['id']); ?>"
|
1411
|
|
|
id="<?php echo esc_attr($value['id']); ?>"
|
1412
|
|
|
style="<?php echo esc_attr($value['css']); ?>"
|
1413
|
|
|
class="<?php if (isset($value['class'])) echo $value['class']; ?>"
|
1414
|
|
|
option-ajaxchosen="false">
|
1415
|
|
|
<?php
|
1416
|
|
|
foreach ($value['options'] as $key => $val) {
|
1417
|
|
|
$geodir_select_value = '';
|
1418
|
|
|
if ($option_value != '') {
|
1419
|
|
|
if ($option_value != '' && $option_value == $key)
|
1420
|
|
|
$geodir_select_value = ' selected="selected" ';
|
1421
|
|
|
} else {
|
1422
|
|
|
if ($value['std'] == $key)
|
1423
|
1 |
|
$geodir_select_value = ' selected="selected" ';
|
1424
|
1 |
|
}
|
1425
|
1 |
|
?>
|
1426
|
|
|
<option
|
1427
|
|
|
value="<?php echo esc_attr($key); ?>" <?php echo $geodir_select_value; ?> ><?php echo ucfirst($val) ?></option>
|
1428
|
|
|
<?php
|
1429
|
|
|
}
|
1430
|
|
|
?>
|
1431
|
|
|
</select> <span class="description"><?php echo $value['desc'] ?></span>
|
1432
|
|
|
</td>
|
1433
|
|
|
</tr><?php
|
1434
|
|
|
break;
|
1435
|
1 |
|
|
1436
|
1 |
|
case 'multiselect':
|
1437
|
1 |
|
$option_values = get_option($value['id']);
|
1438
|
1 |
|
if ($option_values === '' && !empty($value['std']) && is_array($value['std'])) {
|
1439
|
1 |
|
$option_values = $value['std'];
|
1440
|
1 |
|
}
|
1441
|
1 |
|
$option_values = !empty($option_values) ? stripslashes_deep($option_values) : $option_values;
|
1442
|
1 |
|
?>
|
1443
|
|
|
<tr valign="top">
|
1444
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
|
1445
|
|
|
<td class="forminp"><select multiple="multiple" name="<?php echo esc_attr($value['id']); ?>[]"
|
1446
|
|
|
id="<?php echo esc_attr($value['id']); ?>"
|
1447
|
|
|
style="<?php echo esc_attr($value['css']); ?>"
|
1448
|
1 |
|
class="<?php if (isset($value['class'])) echo $value['class']; ?>"
|
1449
|
|
|
data-placeholder="<?php if (isset($value['placeholder_text'])) echo $value['placeholder_text'];?>"
|
1450
|
|
|
option-ajaxchosen="false">
|
1451
|
|
|
<?php
|
1452
|
|
|
foreach ($value['options'] as $key => $val) {
|
1453
|
1 |
|
if (strpos($key, 'optgroup_start-') === 0) {
|
1454
|
|
|
?><optgroup label="<?php echo ucfirst($val); ?>"><?php
|
1455
|
1 |
|
} else if (strpos($key, 'optgroup_end-') === 0) {
|
1456
|
1 |
|
?></optgroup><?php
|
1457
|
1 |
|
} else {
|
1458
|
|
|
?>
|
1459
|
|
|
<option
|
1460
|
1 |
|
value="<?php echo esc_attr($key); ?>" <?php selected(true, (is_array($option_values) && in_array($key, $option_values)));?>><?php echo ucfirst($val) ?></option>
|
1461
|
|
|
<?php
|
1462
|
|
|
}
|
1463
|
|
|
}
|
1464
|
|
|
?>
|
1465
|
|
|
</select> <span class="description"><?php echo $value['desc'] ?></span>
|
1466
|
|
|
</td>
|
1467
|
|
|
</tr><?php
|
1468
|
|
|
break;
|
1469
|
|
|
case 'file':
|
1470
|
|
|
?>
|
1471
|
1 |
|
<tr valign="top">
|
1472
|
1 |
|
<th scope="row" class="titledesc"><?php echo $value['name']; ?></th>
|
1473
|
|
|
<td class="forminp">
|
1474
|
1 |
|
<input type="file" name="<?php echo esc_attr($value['id']); ?>"
|
1475
|
|
|
id="<?php echo esc_attr($value['id']); ?>" style="<?php echo esc_attr($value['css']); ?>"
|
1476
|
|
|
class="<?php if (isset($value['class'])) echo $value['class']; ?>"/>
|
1477
|
|
|
<?php if (get_option($value['id'])) { ?>
|
1478
|
|
|
<input type="hidden" name="<?php echo esc_attr($value['id']); ?>_remove"
|
1479
|
|
|
id="<?php echo esc_attr($value['id']); ?>_remove" value="0">
|
1480
|
|
|
<span class="description"> <a
|
1481
|
|
|
href="<?php echo get_option($value['id']); ?>"
|
1482
|
1 |
|
target="_blank"><?php echo get_option($value['id']); ?></a> <i
|
1483
|
|
|
title="<?php _e('remove file (set to empty)', 'geodirectory'); ?>"
|
1484
|
|
|
onclick="jQuery('#<?php echo esc_attr($value['id']); ?>_remove').val('1'); jQuery( this ).parent().text('<?php _e('save to remove file', 'geodirectory'); ?>');"
|
1485
|
|
|
class="fa fa-times gd-remove-file"></i></span>
|
1486
|
|
|
|
1487
|
1 |
|
<?php } ?>
|
1488
|
1 |
|
</td>
|
1489
|
|
|
</tr><?php
|
1490
|
|
|
break;
|
1491
|
|
|
case 'map_default_settings' :
|
1492
|
|
|
?>
|
1493
|
|
|
|
1494
|
|
|
<tr valign="top">
|
1495
|
|
|
<th class="titledesc" width="40%"><?php _e('Default map language', 'geodirectory');?></th>
|
1496
|
|
|
<td width="60%">
|
1497
|
|
|
<select name="geodir_default_map_language" style="width:60%">
|
1498
|
|
|
<?php
|
1499
|
|
|
$arr_map_langages = array(
|
1500
|
|
|
'ar' => __('ARABIC', 'geodirectory'),
|
1501
|
|
|
'eu' => __('BASQUE', 'geodirectory'),
|
1502
|
|
|
'bg' => __('BULGARIAN', 'geodirectory'),
|
1503
|
|
|
'bn' => __('BENGALI', 'geodirectory'),
|
1504
|
|
|
'ca' => __('CATALAN', 'geodirectory'),
|
1505
|
|
|
'cs' => __('CZECH', 'geodirectory'),
|
1506
|
|
|
'da' => __('DANISH', 'geodirectory'),
|
1507
|
|
|
'de' => __('GERMAN', 'geodirectory'),
|
1508
|
|
|
'el' => __('GREEK', 'geodirectory'),
|
1509
|
1 |
|
'en' => __('ENGLISH', 'geodirectory'),
|
1510
|
1 |
|
'en-AU' => __('ENGLISH (AUSTRALIAN)', 'geodirectory'),
|
1511
|
|
|
'en-GB' => __('ENGLISH (GREAT BRITAIN)', 'geodirectory'),
|
1512
|
|
|
'es' => __('SPANISH', 'geodirectory'),
|
1513
|
|
|
'eu' => __('BASQUE', 'geodirectory'),
|
1514
|
|
|
'fa' => __('FARSI', 'geodirectory'),
|
1515
|
|
|
'fi' => __('FINNISH', 'geodirectory'),
|
1516
|
|
|
'fil' => __('FILIPINO', 'geodirectory'),
|
1517
|
|
|
'fr' => __('FRENCH', 'geodirectory'),
|
1518
|
|
|
'gl' => __('GALICIAN', 'geodirectory'),
|
1519
|
1 |
|
'gu' => __('GUJARATI', 'geodirectory'),
|
1520
|
1 |
|
'hi' => __('HINDI', 'geodirectory'),
|
1521
|
1 |
|
'hr' => __('CROATIAN', 'geodirectory'),
|
1522
|
1 |
|
'hu' => __('HUNGARIAN', 'geodirectory'),
|
1523
|
1 |
|
'id' => __('INDONESIAN', 'geodirectory'),
|
1524
|
1 |
|
'it' => __('ITALIAN', 'geodirectory'),
|
1525
|
1 |
|
'iw' => __('HEBREW', 'geodirectory'),
|
1526
|
1 |
|
'ja' => __('JAPANESE', 'geodirectory'),
|
1527
|
1 |
|
'kn' => __('KANNADA', 'geodirectory'),
|
1528
|
1 |
|
'ko' => __('KOREAN', 'geodirectory'),
|
1529
|
1 |
|
'lt' => __('LITHUANIAN', 'geodirectory'),
|
1530
|
1 |
|
'lv' => __('LATVIAN', 'geodirectory'),
|
1531
|
1 |
|
'ml' => __('MALAYALAM', 'geodirectory'),
|
1532
|
1 |
|
'mr' => __('MARATHI', 'geodirectory'),
|
1533
|
1 |
|
'nl' => __('DUTCH', 'geodirectory'),
|
1534
|
1 |
|
'no' => __('NORWEGIAN', 'geodirectory'),
|
1535
|
1 |
|
'pl' => __('POLISH', 'geodirectory'),
|
1536
|
1 |
|
'pt' => __('PORTUGUESE', 'geodirectory'),
|
1537
|
1 |
|
'pt-BR' => __('PORTUGUESE (BRAZIL)', 'geodirectory'),
|
1538
|
1 |
|
'pt-PT' => __('PORTUGUESE (PORTUGAL)', 'geodirectory'),
|
1539
|
1 |
|
'ro' => __('ROMANIAN', 'geodirectory'),
|
1540
|
1 |
|
'ru' => __('RUSSIAN', 'geodirectory'),
|
1541
|
1 |
|
'ru' => __('RUSSIAN', 'geodirectory'),
|
1542
|
1 |
|
'sk' => __('SLOVAK', 'geodirectory'),
|
1543
|
1 |
|
'sl' => __('SLOVENIAN', 'geodirectory'),
|
1544
|
1 |
|
'sr' => __('SERBIAN', 'geodirectory'),
|
1545
|
1 |
|
'sv' => __(' SWEDISH', 'geodirectory'),
|
1546
|
1 |
|
'tl' => __('TAGALOG', 'geodirectory'),
|
1547
|
1 |
|
'ta' => __('TAMIL', 'geodirectory'),
|
1548
|
1 |
|
'te' => __('TELUGU', 'geodirectory'),
|
1549
|
1 |
|
'th' => __('THAI', 'geodirectory'),
|
1550
|
1 |
|
'tr' => __('TURKISH', 'geodirectory'),
|
1551
|
1 |
|
'uk' => __('UKRAINIAN', 'geodirectory'),
|
1552
|
1 |
|
'vi' => __('VIETNAMESE', 'geodirectory'),
|
1553
|
1 |
|
'zh-CN' => __('CHINESE (SIMPLIFIED)', 'geodirectory'),
|
1554
|
1 |
|
'zh-TW' => __('CHINESE (TRADITIONAL)', 'geodirectory'),
|
1555
|
1 |
|
);
|
1556
|
1 |
|
$geodir_default_map_language = get_option('geodir_default_map_language');
|
1557
|
1 |
|
if (empty($geodir_default_map_language))
|
1558
|
1 |
|
$geodir_default_map_language = 'en';
|
1559
|
1 |
|
foreach ($arr_map_langages as $language_key => $language_txt) {
|
1560
|
1 |
|
if (!empty($geodir_default_map_language) && $language_key == $geodir_default_map_language)
|
1561
|
1 |
|
$geodir_default_language_selected = "selected='selected'";
|
1562
|
1 |
|
else
|
1563
|
1 |
|
$geodir_default_language_selected = '';
|
1564
|
1 |
|
|
1565
|
1 |
|
?>
|
1566
|
1 |
|
<option
|
1567
|
1 |
|
value="<?php echo $language_key?>" <?php echo $geodir_default_language_selected; ?>><?php echo $language_txt; ?></option>
|
1568
|
1 |
|
|
1569
|
1 |
|
<?php }
|
1570
|
1 |
|
?>
|
1571
|
1 |
|
</select>
|
1572
|
1 |
|
</td>
|
1573
|
1 |
|
</tr>
|
1574
|
1 |
|
|
1575
|
1 |
|
<tr valign="top">
|
1576
|
1 |
|
<th class="titledesc"
|
1577
|
1 |
|
width="40%"><?php _e('Default post type search on map', 'geodirectory');?></th>
|
1578
|
1 |
|
<td width="60%">
|
1579
|
1 |
|
<select name="geodir_default_map_search_pt" style="width:60%">
|
1580
|
1 |
|
<?php
|
1581
|
|
|
$post_types = geodir_get_posttypes('array');
|
1582
|
1 |
|
$geodir_default_map_search_pt = get_option('geodir_default_map_search_pt');
|
1583
|
|
|
if (empty($geodir_default_map_search_pt))
|
1584
|
|
|
$geodir_default_map_search_pt = 'gd_place';
|
1585
|
|
|
if (is_array($post_types)) {
|
1586
|
|
|
foreach ($post_types as $key => $post_types_obj) {
|
1587
|
|
|
if (!empty($geodir_default_map_search_pt) && $key == $geodir_default_map_search_pt)
|
1588
|
|
|
$geodir_search_pt_selected = "selected='selected'";
|
1589
|
|
|
else
|
1590
|
|
|
$geodir_search_pt_selected = '';
|
1591
|
|
|
|
1592
|
|
|
?>
|
1593
|
|
|
<option
|
1594
|
|
|
value="<?php echo $key?>" <?php echo $geodir_search_pt_selected; ?>><?php echo $post_types_obj['labels']['singular_name']; ?></option>
|
1595
|
|
|
|
1596
|
|
|
<?php }
|
1597
|
|
|
|
1598
|
|
|
}
|
1599
|
|
|
|
1600
|
1 |
|
?>
|
1601
|
1 |
|
</select>
|
1602
|
1 |
|
</td>
|
1603
|
1 |
|
</tr>
|
1604
|
1 |
|
|
1605
|
1 |
|
<?php
|
1606
|
1 |
|
break;
|
1607
|
1 |
|
|
1608
|
|
|
case 'map':
|
1609
|
|
|
?>
|
1610
|
|
|
<tr valign="top">
|
1611
|
|
|
<td class="forminp">
|
1612
|
|
|
<?php
|
1613
|
|
|
global $post_cat, $cat_display;
|
1614
|
|
|
$post_types = geodir_get_posttypes('object');
|
1615
|
|
|
$cat_display = 'checkbox';
|
1616
|
|
|
$gd_post_types = get_option('geodir_exclude_post_type_on_map');
|
1617
|
1 |
|
$gd_cats = get_option('geodir_exclude_cat_on_map');
|
1618
|
|
|
$gd_cats_upgrade = (int)get_option('geodir_exclude_cat_on_map_upgrade');
|
1619
|
|
|
$count = 1;
|
1620
|
|
|
?>
|
1621
|
|
|
<table width="70%" class="widefat">
|
1622
|
|
|
<thead>
|
1623
|
|
|
<tr>
|
1624
|
|
|
<th><b><?php echo DESIGN_POST_TYPE_SNO; ?></b></th>
|
1625
|
1 |
|
<th><b><?php echo DESIGN_POST_TYPE; ?></b></th>
|
1626
|
|
|
<th><b><?php echo DESIGN_POST_TYPE_CAT; ?></b></th>
|
1627
|
1 |
|
</tr>
|
1628
|
|
|
<?php
|
1629
|
|
|
$gd_categs = $gd_cats;
|
1630
|
|
|
foreach ($post_types as $key => $post_types_obj) :
|
|
|
|
|
1631
|
|
|
$checked = is_array($gd_post_types) && in_array($key, $gd_post_types) ? 'checked="checked"' : '';
|
1632
|
1 |
|
$gd_taxonomy = geodir_get_taxonomies($key);
|
1633
|
1 |
View Code Duplication |
if ($gd_cats_upgrade) {
|
1634
|
1 |
|
$gd_cat_taxonomy = isset($gd_taxonomy[0]) ? $gd_taxonomy[0] : '';
|
1635
|
1 |
|
$gd_cats = isset($gd_categs[$gd_cat_taxonomy]) ? $gd_categs[$gd_cat_taxonomy] : array();
|
1636
|
1 |
|
$gd_cats = !empty($gd_cats) && is_array($gd_cats) ? array_unique($gd_cats) : array();
|
1637
|
1 |
|
}
|
1638
|
1 |
|
$post_cat = implode(',', $gd_cats);
|
1639
|
|
|
$gd_taxonomy_list = geodir_custom_taxonomy_walker($gd_taxonomy);
|
|
|
|
|
1640
|
|
|
?>
|
1641
|
|
|
<tr>
|
1642
|
|
|
<td valign="top" width="5%"><?php echo $count; ?></td>
|
1643
|
|
|
<td valign="top" width="25%" id="td_post_types"><input type="checkbox"
|
1644
|
|
|
name="home_map_post_types[]"
|
1645
|
|
|
id="<?php echo esc_attr($value['id']); ?>"
|
1646
|
|
|
value="<?php echo $key; ?>"
|
1647
|
|
|
class="map_post_type" <?php echo $checked;?> />
|
1648
|
1 |
|
<?php echo $post_types_obj->labels->singular_name; ?></td>
|
1649
|
1 |
|
<td width="40%">
|
1650
|
1 |
|
<div class="home_map_category" style="overflow:auto;width:200px;height:100px;"
|
1651
|
1 |
|
id="<?php echo $key; ?>"><?php echo $gd_taxonomy_list; ?></div>
|
1652
|
1 |
|
</td>
|
1653
|
1 |
|
</tr>
|
1654
|
1 |
|
<?php $count++; endforeach; ?>
|
1655
|
1 |
|
</thead>
|
1656
|
1 |
|
</table>
|
1657
|
1 |
|
<p><?php _e('Note: Tick respective post type or categories which you want to hide from home page map widget.', 'geodirectory')?></p>
|
1658
|
1 |
|
</td>
|
1659
|
|
|
</tr>
|
1660
|
|
|
<?php
|
1661
|
|
|
break;
|
1662
|
|
|
|
1663
|
|
|
case 'checkbox' :
|
1664
|
|
|
|
1665
|
|
|
if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup'] == 'start')) :
|
1666
|
|
|
?>
|
1667
|
|
|
<tr valign="top">
|
1668
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1669
|
|
|
<td class="forminp">
|
1670
|
|
|
<?php
|
1671
|
|
|
endif;
|
1672
|
|
|
|
1673
|
|
|
?>
|
1674
|
|
|
<fieldset>
|
1675
|
|
|
<legend class="screen-reader-text"><span><?php echo $value['name'] ?></span></legend>
|
1676
|
|
|
<label for="<?php echo $value['id'] ?>">
|
1677
|
|
|
<input name="<?php echo esc_attr($value['id']); ?>" id="<?php echo esc_attr($value['id']); ?>"
|
1678
|
|
|
type="checkbox" value="1" <?php checked(get_option($value['id']), true); ?> />
|
1679
|
|
|
<?php echo $value['desc'] ?></label><br>
|
1680
|
1 |
|
</fieldset>
|
1681
|
|
|
<?php
|
1682
|
1 |
|
|
1683
|
|
|
if (!isset($value['checkboxgroup']) || (isset($value['checkboxgroup']) && $value['checkboxgroup'] == 'end')) :
|
1684
|
1 |
|
?>
|
1685
|
|
|
</td>
|
1686
|
|
|
</tr>
|
1687
|
|
|
<?php
|
1688
|
|
|
endif;
|
1689
|
|
|
|
1690
|
1 |
|
break;
|
1691
|
|
|
|
1692
|
|
|
case 'radio' :
|
1693
|
|
|
|
1694
|
|
View Code Duplication |
if (!isset($value['radiogroup']) || (isset($value['radiogroup']) && $value['radiogroup'] == 'start')) :
|
1695
|
|
|
?>
|
1696
|
|
|
<tr valign="top">
|
1697
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1698
|
|
|
<td class="forminp">
|
1699
|
|
|
<?php
|
1700
|
|
|
endif;
|
1701
|
|
|
|
1702
|
1 |
|
?>
|
1703
|
|
|
<fieldset>
|
1704
|
|
|
<legend class="screen-reader-text"><span><?php echo $value['name'] ?></span></legend>
|
1705
|
|
|
<label for="<?php echo $value['id'];?>">
|
1706
|
|
|
<input name="<?php echo esc_attr($value['id']); ?>"
|
1707
|
1 |
|
id="<?php echo esc_attr($value['id'] . $value['value']); ?>" type="radio"
|
1708
|
|
|
value="<?php echo $value['value'] ?>" <?php if (get_option($value['id']) == $value['value']) {
|
1709
|
1 |
|
echo 'checked="checked"';
|
1710
|
|
|
}elseif(get_option($value['id'])=='' && $value['std']==$value['value']){echo 'checked="checked"';} ?> />
|
1711
|
1 |
|
<?php echo $value['desc']; ?></label><br>
|
1712
|
|
|
</fieldset>
|
1713
|
1 |
|
<?php
|
1714
|
|
|
|
1715
|
|
View Code Duplication |
if (!isset($value['radiogroup']) || (isset($value['radiogroup']) && $value['radiogroup'] == 'end')) :
|
1716
|
|
|
?>
|
1717
|
|
|
</td>
|
1718
|
|
|
</tr>
|
1719
|
1 |
|
<?php
|
1720
|
|
|
endif;
|
1721
|
|
|
|
1722
|
|
|
break;
|
1723
|
|
|
|
1724
|
|
|
case 'textarea':
|
1725
|
|
|
?>
|
1726
|
|
|
<tr valign="top">
|
1727
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1728
|
1 |
|
<td class="forminp">
|
1729
|
|
|
<textarea
|
1730
|
|
|
<?php if (isset($value['args'])) echo $value['args'] . ' '; ?>name="<?php echo esc_attr($value['id']); ?>"
|
1731
|
|
|
id="<?php echo esc_attr($value['id']); ?>"
|
1732
|
|
|
<?php if(isset($value['placeholder'])){?>placeholder="<?php echo esc_attr($value['placeholder']); ?>"<?php }?>
|
1733
|
|
|
style="<?php echo esc_attr($value['css']); ?>"><?php if (get_option($value['id'])) echo esc_textarea(stripslashes(get_option($value['id']))); else echo esc_textarea($value['std']); ?></textarea><span
|
1734
|
1 |
|
class="description"><?php echo $value['desc'] ?></span>
|
1735
|
|
|
|
1736
|
|
|
</td>
|
1737
|
|
|
</tr><?php
|
1738
|
|
|
break;
|
1739
|
1 |
|
|
1740
|
|
|
case 'editor':
|
1741
|
1 |
|
?>
|
1742
|
|
|
<tr valign="top">
|
1743
|
1 |
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1744
|
|
|
<td class="forminp"><?php
|
1745
|
|
|
if (get_option($value['id']))
|
1746
|
|
|
$content = stripslashes(get_option($value['id']));
|
1747
|
|
|
else
|
1748
|
|
|
$content = $value['std'];
|
1749
|
|
|
|
1750
|
|
|
$editor_settings = array('media_buttons' => false, 'textarea_rows' => 10);
|
1751
|
|
|
|
1752
|
|
|
wp_editor($content, esc_attr($value['id']), $editor_settings);
|
1753
|
|
|
|
1754
|
|
|
?> <span class="description"><?php echo $value['desc'] ?></span>
|
1755
|
|
|
|
1756
|
|
|
</td>
|
1757
|
1 |
|
</tr><?php
|
1758
|
|
|
break;
|
1759
|
1 |
|
|
1760
|
|
|
case 'single_select_page' :
|
1761
|
|
|
// WPML
|
1762
|
|
|
$switch_lang = false;
|
1763
|
|
|
$disabled = '';
|
1764
|
|
|
if (geodir_is_wpml() && isset($_REQUEST['tab']) && $_REQUEST['tab'] == 'permalink_settings') {
|
1765
|
|
|
global $sitepress;
|
1766
|
|
|
|
1767
|
|
|
$default_lang = $sitepress->get_default_language();
|
1768
|
|
|
$current_lang = $sitepress->get_current_language();
|
1769
|
|
|
|
1770
|
|
|
if ($current_lang != 'all' && $current_lang != $default_lang) {
|
1771
|
|
|
$disabled = "disabled='disabled'";
|
1772
|
|
|
$switch_lang = $current_lang;
|
1773
|
|
|
$sitepress->switch_lang('all', true);
|
1774
|
|
|
}
|
1775
|
|
|
}
|
1776
|
|
|
//
|
1777
|
|
|
$page_setting = (int)get_option($value['id']);
|
1778
|
|
|
|
1779
|
1 |
|
$args = array('name' => $value['id'],
|
1780
|
|
|
'id' => $value['id'],
|
1781
|
1 |
|
'sort_column' => 'menu_order',
|
1782
|
1 |
|
'sort_order' => 'ASC',
|
1783
|
1 |
|
'show_option_none' => ' ',
|
1784
|
|
|
'class' => $value['class'],
|
1785
|
|
|
'echo' => false,
|
1786
|
|
|
'selected' => $page_setting);
|
1787
|
|
|
|
1788
|
|
|
if (isset($value['args'])) $args = wp_parse_args($value['args'], $args);
|
1789
|
|
|
|
1790
|
|
|
?>
|
1791
|
|
|
<tr valign="top" class="single_select_page">
|
1792
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1793
|
|
|
<td class="forminp">
|
1794
|
|
|
<?php echo str_replace(' id=', " data-placeholder='" . __('Select a page...', 'geodirectory') . "' style='" . $value['css'] . "' class='" . $value['class'] . "' " . $disabled . " id=", wp_dropdown_pages($args)); ?>
|
1795
|
|
|
<span class="description"><?php echo $value['desc'] ?></span>
|
1796
|
1 |
|
</td>
|
1797
|
|
|
</tr><?php
|
1798
|
1 |
|
if ($switch_lang) {
|
1799
|
1 |
|
$sitepress->switch_lang($switch_lang, true);
|
|
|
|
|
1800
|
1 |
|
}
|
1801
|
1 |
|
break;
|
1802
|
1 |
|
case 'single_select_country' :
|
1803
|
1 |
|
$country_setting = (string)get_option($value['id']);
|
1804
|
1 |
|
if (strstr($country_setting, ':')) :
|
1805
|
1 |
|
$country = current(explode(':', $country_setting));
|
1806
|
|
|
$state = end(explode(':', $country_setting));
|
|
|
|
|
1807
|
1 |
|
else :
|
1808
|
|
|
$country = $country_setting;
|
1809
|
|
|
$state = '*';
|
1810
|
|
|
endif;
|
1811
|
|
|
?>
|
1812
|
|
|
<tr valign="top">
|
1813
|
|
|
<th scope="rpw" class="titledesc"><?php echo $value['name'] ?></th>
|
1814
|
|
|
<td class="forminp"><select name="<?php echo esc_attr($value['id']); ?>"
|
1815
|
|
|
style="<?php echo esc_attr($value['css']); ?>"
|
1816
|
|
|
data-placeholder="<?php _e('Choose a country…', 'geodirectory'); ?>"
|
1817
|
1 |
|
title="Country" class="chosen_select">
|
1818
|
|
|
<?php echo $geodirectory->countries->country_dropdown_options($country, $state); ?>
|
1819
|
|
|
</select> <span class="description"><?php echo $value['desc'] ?></span>
|
1820
|
1 |
|
</td>
|
1821
|
1 |
|
</tr><?php
|
1822
|
|
|
break;
|
1823
|
|
|
case 'multi_select_countries' :
|
1824
|
|
|
$countries = $geodirectory->countries->countries;
|
1825
|
|
|
asort($countries);
|
1826
|
|
|
$selections = (array)get_option($value['id']);
|
1827
|
|
|
?>
|
1828
|
|
|
<tr valign="top">
|
1829
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1830
|
|
|
<td class="forminp">
|
1831
|
|
|
<select multiple="multiple" name="<?php echo esc_attr($value['id']); ?>[]" style="width:450px;"
|
1832
|
|
|
data-placeholder="<?php _e('Choose countries…', 'geodirectory'); ?>"
|
1833
|
|
|
title="Country" class="chosen_select">
|
1834
|
|
|
<?php
|
1835
|
|
|
if ($countries) foreach ($countries as $key => $val) :
|
|
|
|
|
1836
|
|
|
echo '<option value="' . $key . '" ' . selected(in_array($key, $selections), true, false) . '>' . $val . '</option>';
|
1837
|
|
|
endforeach;
|
1838
|
|
|
?>
|
1839
|
|
|
</select>
|
1840
|
|
|
</td>
|
1841
|
|
|
</tr>
|
1842
|
1 |
|
|
1843
|
|
|
<?php
|
1844
|
|
|
|
1845
|
|
|
break;
|
1846
|
|
|
|
1847
|
|
|
case 'google_analytics' :
|
1848
|
|
|
$selections = (array)get_option($value['id']);
|
|
|
|
|
1849
|
|
|
if(get_option('geodir_ga_client_id') && get_option('geodir_ga_client_secret') ) {
|
1850
|
|
|
?>
|
1851
|
|
|
<tr valign="top">
|
1852
|
|
|
<th scope="row" class="titledesc"><?php echo $value['name'] ?></th>
|
1853
|
|
|
<td class="forminp">
|
1854
|
|
|
|
1855
|
|
|
|
1856
|
|
|
<?php
|
1857
|
|
|
|
1858
|
|
|
$oAuthURL = "https://accounts.google.com/o/oauth2/auth?";
|
1859
|
|
|
$scope = "scope=https://www.googleapis.com/auth/analytics.readonly";
|
1860
|
|
|
$state = "&state=123";//any string
|
1861
|
|
|
$redirect_uri = "&redirect_uri=" . admin_url('admin-ajax.php') . "?action=geodir_ga_callback";
|
1862
|
|
|
$response_type = "&response_type=code";
|
1863
|
|
|
$client_id = "&client_id=".get_option('geodir_ga_client_id');
|
1864
|
|
|
$access_type = "&access_type=offline";
|
1865
|
|
|
$approval_prompt = "&approval_prompt=force";
|
1866
|
1 |
|
|
1867
|
1 |
|
$auth_url = $oAuthURL . $scope . $state . $redirect_uri . $response_type . $client_id . $access_type . $approval_prompt;
|
1868
|
1 |
|
|
1869
|
|
|
|
1870
|
|
|
?>
|
1871
|
|
|
<script>
|
1872
|
|
|
function gd_ga_popup() {
|
1873
|
|
|
var win = window.open("<?php echo $auth_url;?>", "Google Analytics", "");
|
1874
|
|
|
var pollTimer = window.setInterval(function () {
|
1875
|
|
|
if (win.closed !== false) { // !== is required for compatibility with Opera
|
1876
|
|
|
window.clearInterval(pollTimer);
|
1877
|
|
|
|
1878
|
|
|
jQuery(".general_settings .submit .button-primary").trigger('click');
|
1879
|
|
|
}
|
1880
|
|
|
}, 200);
|
1881
|
|
|
}
|
1882
|
|
|
</script>
|
1883
|
|
|
|
1884
|
|
|
<?php
|
1885
|
|
|
if (get_option('gd_ga_refresh_token')) {
|
1886
|
|
|
?>
|
1887
|
|
|
<span class="button-primary"
|
1888
|
|
|
onclick="gd_ga_popup();"><?php _e('Re-authorize', 'geodirectory'); ?></span>
|
1889
|
|
|
<span
|
1890
|
|
|
style="color: green; font-weight: bold;"><?php _e('Authorized', 'geodirectory'); ?></span>
|
1891
|
|
|
<?php
|
1892
|
|
|
} else {
|
1893
|
|
|
?>
|
1894
|
|
|
<span class="button-primary"
|
1895
|
|
|
onclick="gd_ga_popup();"><?php _e('Authorize', 'geodirectory');?></span>
|
1896
|
|
|
<?php
|
1897
|
|
|
}
|
1898
|
|
|
?>
|
1899
|
|
|
</td>
|
1900
|
|
|
</tr>
|
1901
|
|
|
|
1902
|
|
|
<?php
|
1903
|
|
|
}
|
1904
|
|
|
|
1905
|
|
|
break;
|
1906
|
|
|
|
1907
|
|
|
case 'field_seperator' :
|
1908
|
|
|
|
1909
|
|
|
?>
|
1910
|
|
|
<tr valign="top">
|
1911
|
|
|
<td colspan="2" class="forminp geodir_line_seperator"></td>
|
1912
|
|
|
</tr>
|
1913
|
|
|
<?php
|
1914
|
|
|
|
1915
|
|
|
break;
|
1916
|
|
|
|
1917
|
|
|
endswitch;
|
1918
|
|
|
|
1919
|
|
|
endforeach;
|
1920
|
|
|
|
1921
|
|
|
if ($first_title === false) {
|
1922
|
|
|
echo "</div>";
|
1923
|
|
|
}
|
1924
|
1 |
|
|
1925
|
|
|
?>
|
1926
|
|
|
|
1927
|
|
|
<script type="text/javascript">
|
1928
|
|
|
|
1929
|
|
|
|
1930
|
|
|
jQuery(document).ready(function () {
|
1931
|
|
|
|
1932
|
|
|
jQuery('.geodir_option_tabs').each(function (ele) {
|
1933
|
|
|
jQuery('#geodir_oiption_tabs').append(jQuery(this));
|
1934
|
|
|
});
|
1935
|
|
|
|
1936
|
1 |
|
|
1937
|
|
|
jQuery('.geodir_option_tabs').removeClass('gd-tab-active');
|
1938
|
1 |
|
jQuery('.geodir_option_tabs:first').addClass('gd-tab-active');
|
1939
|
|
|
|
1940
|
1 |
|
jQuery('.gd-content-heading').hide();
|
1941
|
1 |
|
jQuery('.gd-content-heading:first').show();
|
1942
|
1 |
|
jQuery('.geodir_option_tabs').bind('click', function () {
|
1943
|
|
|
var tab_id = jQuery(this).attr('id');
|
1944
|
|
|
|
1945
|
|
|
if (tab_id == 'dummy_data_settings') {
|
1946
|
|
|
jQuery('p .button-primary').hide();
|
1947
|
|
|
} else if (tab_id == 'csv_upload_settings') {
|
1948
|
|
|
jQuery('p .button-primary').hide();
|
1949
|
|
|
} else {
|
1950
|
|
|
jQuery('.button-primary').show();
|
1951
|
|
|
}
|
1952
|
|
|
|
1953
|
|
|
if (jQuery('#sub_' + tab_id + ' div').hasClass('geodir_auto_install'))
|
1954
|
|
|
jQuery('p .button-primary').hide();
|
1955
|
|
|
|
1956
|
|
|
jQuery('.geodir_option_tabs').removeClass('gd-tab-active');
|
1957
|
|
|
jQuery(this).addClass('gd-tab-active');
|
1958
|
|
|
jQuery('.gd-content-heading').hide();
|
1959
|
|
|
jQuery('#sub_' + tab_id).show();
|
1960
|
|
|
jQuery('.active_tab').val(tab_id);
|
1961
|
|
|
jQuery("select.chosen_select").trigger("chosen:updated"); //refresh chosen
|
1962
|
|
|
});
|
1963
|
|
|
|
1964
|
|
|
<?php if (isset($_REQUEST['active_tab']) && $_REQUEST['active_tab'] != '') { ?>
|
1965
|
|
|
jQuery('.geodir_option_tabs').removeClass('gd-tab-active');
|
1966
|
|
|
jQuery('#<?php echo sanitize_text_field($_REQUEST['active_tab']);?>').addClass('gd-tab-active');
|
1967
|
|
|
jQuery('.gd-content-heading').hide();
|
1968
|
|
|
jQuery('#sub_<?php echo sanitize_text_field($_REQUEST['active_tab']);?>').show();
|
1969
|
|
|
<?php } ?>
|
1970
|
|
|
});
|
1971
|
|
|
</script>
|
1972
|
|
|
<?php
|
1973
|
|
|
}
|
1974
|
|
|
|
1975
|
|
|
/**
|
1976
|
|
|
* Prints post information meta box content.
|
1977
|
|
|
*
|
1978
|
|
|
* @since 1.0.0
|
1979
|
|
|
* @package GeoDirectory
|
1980
|
|
|
* @global object $post The post object.
|
1981
|
|
|
* @global int $post_id The post ID.
|
1982
|
|
|
*/
|
1983
|
|
|
function geodir_post_info_setting()
|
1984
|
|
|
{
|
1985
|
|
|
global $post, $post_id;
|
1986
|
|
|
|
1987
|
|
|
$post_type = get_post_type();
|
1988
|
|
|
|
1989
|
|
|
$package_info = array();
|
1990
|
|
|
|
1991
|
|
|
$package_info = geodir_post_package_info($package_info, $post, $post_type);
|
1992
|
1 |
|
wp_nonce_field(plugin_basename(__FILE__), 'geodir_post_info_noncename');
|
1993
|
|
|
echo '<div id="geodir_wrapper">';
|
1994
|
|
|
/**
|
1995
|
|
|
* Called before the GD custom fields are output in the wp-admin area.
|
1996
|
|
|
*
|
1997
|
|
|
* @since 1.0.0
|
1998
|
|
|
* @see 'geodir_after_default_field_in_meta_box'
|
1999
|
|
|
*/
|
2000
|
|
|
do_action('geodir_before_default_field_in_meta_box');
|
2001
|
|
|
//geodir_get_custom_fields_html($package_info->pid,'default',$post_type);
|
|
|
|
|
2002
|
|
|
// to display all fields in one information box
|
2003
|
|
|
geodir_get_custom_fields_html($package_info->pid, 'all', $post_type);
|
2004
|
|
|
/**
|
2005
|
|
|
* Called after the GD custom fields are output in the wp-admin area.
|
2006
|
|
|
*
|
2007
|
|
|
* @since 1.0.0
|
2008
|
|
|
* @see 'geodir_before_default_field_in_meta_box'
|
2009
|
|
|
*/
|
2010
|
|
|
do_action('geodir_after_default_field_in_meta_box');
|
2011
|
|
|
echo '</div>';
|
2012
|
|
|
}
|
2013
|
|
|
|
2014
|
|
|
/**
|
2015
|
|
|
* Prints additional information meta box content.
|
2016
|
|
|
*
|
2017
|
|
|
* @since 1.0.0
|
2018
|
|
|
* @package GeoDirectory
|
2019
|
|
|
* @global object $post The post object.
|
2020
|
|
|
* @global int $post_id The post ID.
|
2021
|
|
|
*/
|
2022
|
|
|
function geodir_post_addinfo_setting()
|
2023
|
|
|
{
|
2024
|
|
|
global $post, $post_id;
|
2025
|
|
|
|
2026
|
|
|
$post_type = get_post_type();
|
2027
|
|
|
|
2028
|
|
|
$package_info = array();
|
2029
|
|
|
|
2030
|
|
|
$package_info = geodir_post_package_info($package_info, $post, $post_type);
|
2031
|
|
|
|
2032
|
|
|
wp_nonce_field(plugin_basename(__FILE__), 'geodir_post_addinfo_noncename');
|
2033
|
|
|
echo '<div id="geodir_wrapper">';
|
2034
|
|
|
geodir_get_custom_fields_html($package_info->pid, 'custom', $post_type);
|
2035
|
|
|
echo '</div>';
|
2036
|
|
|
|
2037
|
|
|
}
|
2038
|
|
|
|
2039
|
|
|
/**
|
2040
|
|
|
* Prints Attachments meta box content.
|
2041
|
|
|
*
|
2042
|
|
|
* @since 1.0.0
|
2043
|
|
|
* @package GeoDirectory
|
2044
|
|
|
* @global object $post The post object.
|
2045
|
|
|
* @global int $post_id The post ID.
|
2046
|
|
|
*/
|
2047
|
|
|
function geodir_post_attachments()
|
2048
|
|
|
{
|
2049
|
|
|
global $post, $post_id;
|
2050
|
|
|
|
2051
|
|
|
wp_nonce_field(plugin_basename(__FILE__), 'geodir_post_attachments_noncename');
|
2052
|
|
|
|
2053
|
|
|
if (geodir_get_featured_image($post_id, 'thumbnail')) {
|
2054
|
|
|
echo '<h4>' . __('Featured Image', 'geodirectory') . '</h4>';
|
2055
|
|
|
geodir_show_featured_image($post_id, 'thumbnail');
|
2056
|
|
|
}
|
2057
|
|
|
|
2058
|
|
|
$image_limit = 0;
|
2059
|
|
|
|
2060
|
|
|
?>
|
2061
|
|
|
|
2062
|
|
|
|
2063
|
|
|
<h5 class="form_title">
|
2064
|
|
View Code Duplication |
<?php if ($image_limit != 0 && $image_limit == 1) {
|
2065
|
|
|
echo '<br /><small>(' . __('You can upload', 'geodirectory') . ' ' . $image_limit . ' ' . __('image with this package', 'geodirectory') . ')</small>';
|
2066
|
|
|
} ?>
|
2067
|
|
View Code Duplication |
<?php if ($image_limit != 0 && $image_limit > 1) {
|
2068
|
|
|
echo '<br /><small>(' . __('You can upload', 'geodirectory') . ' ' . $image_limit . ' ' . __('images with this package', 'geodirectory') . ')</small>';
|
2069
|
|
|
} ?>
|
2070
|
|
|
<?php if ($image_limit == 0) {
|
2071
|
|
|
echo '<br /><small>(' . __('You can upload unlimited images with this package', 'geodirectory') . ')</small>';
|
2072
|
|
|
} ?>
|
2073
|
|
|
</h5>
|
2074
|
|
|
|
2075
|
|
|
|
2076
|
|
|
<?php
|
2077
|
|
|
|
2078
|
|
|
$curImages = geodir_get_images($post_id);
|
2079
|
|
|
$place_img_array = array();
|
2080
|
|
|
|
2081
|
|
|
if (!empty($curImages)):
|
2082
|
|
|
foreach ($curImages as $p_img):
|
|
|
|
|
2083
|
|
|
$place_img_array[] = $p_img->src;
|
2084
|
|
|
endforeach;
|
2085
|
|
|
endif;
|
2086
|
|
|
|
2087
|
|
|
if (!empty($place_img_array))
|
2088
|
|
|
$curImages = implode(',', $place_img_array);
|
2089
|
|
|
|
2090
|
|
|
|
2091
|
|
|
// adjust values here
|
2092
|
|
|
$id = "post_images"; // this will be the name of form field. Image url(s) will be submitted in $_POST using this key. So if $id == �img1� then $_POST[�img1�] will have all the image urls
|
2093
|
|
|
|
2094
|
|
|
$svalue = $curImages; // this will be initial value of the above form field. Image urls.
|
2095
|
|
|
|
2096
|
|
|
$multiple = true; // allow multiple files upload
|
2097
|
|
|
|
2098
|
|
|
$width = geodir_media_image_large_width(); // If you want to automatically resize all uploaded images then provide width here (in pixels)
|
2099
|
|
|
|
2100
|
|
|
$height = geodir_media_image_large_height(); // If you want to automatically resize all uploaded images then provide height here (in pixels)
|
2101
|
|
|
|
2102
|
|
|
?>
|
2103
|
|
|
|
2104
|
|
|
<div class="gtd-form_row clearfix" id="<?php echo $id; ?>dropbox" style="border:1px solid #999999;padding:5px;text-align:center;">
|
2105
|
|
|
<input type="hidden" name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="<?php echo $svalue; ?>"/>
|
2106
|
|
|
|
2107
|
|
|
<div
|
2108
|
|
|
class="plupload-upload-uic hide-if-no-js <?php if ($multiple): ?>plupload-upload-uic-multiple<?php endif; ?>"
|
2109
|
|
|
id="<?php echo $id; ?>plupload-upload-ui">
|
2110
|
|
|
<h4><?php _e('Drop files to upload', 'geodirectory');?></h4>
|
2111
|
|
|
<input id="<?php echo $id; ?>plupload-browse-button" type="button"
|
2112
|
|
|
value="<?php _e('Select Files', 'geodirectory'); ?>" class="button"/>
|
2113
|
|
|
<span class="ajaxnonceplu" id="ajaxnonceplu<?php echo wp_create_nonce($id . 'pluploadan'); ?>"></span>
|
2114
|
|
|
<?php if ($width && $height): ?>
|
2115
|
|
|
<span class="plupload-resize"></span>
|
2116
|
|
|
<span class="plupload-width" id="plupload-width<?php echo $width; ?>"></span>
|
2117
|
|
|
<span class="plupload-height" id="plupload-height<?php echo $height; ?>"></span>
|
2118
|
|
|
<?php endif; ?>
|
2119
|
|
|
<div class="filelist"></div>
|
2120
|
|
|
</div>
|
2121
|
|
|
<div class="plupload-thumbs <?php if ($multiple): ?>plupload-thumbs-multiple<?php endif; ?> clearfix"
|
2122
|
|
|
id="<?php echo $id; ?>plupload-thumbs" style="border-top:1px solid #ccc; padding-top:10px;">
|
2123
|
|
|
</div>
|
2124
|
|
|
<span
|
2125
|
|
|
id="upload-msg"><?php _e('Please drag & drop the images to rearrange the order', 'geodirectory');?></span>
|
2126
|
|
|
<span id="<?php echo $id; ?>upload-error" style="display:none"></span>
|
2127
|
|
|
</div>
|
2128
|
|
|
|
2129
|
|
|
<?php
|
2130
|
|
|
|
2131
|
|
|
}
|
2132
|
|
|
|
2133
|
|
|
/**
|
2134
|
|
|
* Updates custom table when post get updated.
|
2135
|
|
|
*
|
2136
|
|
|
* @since 1.0.0
|
2137
|
|
|
* @package GeoDirectory
|
2138
|
|
|
* @param int $post_ID The post ID.
|
2139
|
|
|
* @param object $post_after Post object after the update.
|
2140
|
|
|
* @param object $post_before Post object before the update.
|
2141
|
|
|
*/
|
2142
|
|
|
function geodir_action_post_updated($post_ID, $post_after, $post_before)
|
2143
|
|
|
{
|
2144
|
|
|
$post_type = get_post_type($post_ID);
|
2145
|
|
|
|
2146
|
|
|
if (isset($_POST['action']) && $_POST['action'] == 'inline-save') {
|
2147
|
|
|
if ($post_type != '' && in_array($post_type, geodir_get_posttypes()) && !wp_is_post_revision($post_ID) && !empty($post_after->post_title) && $post_after->post_title != $post_before->post_title) {
|
2148
|
|
|
geodir_save_post_meta($post_ID, 'post_title', $post_after->post_title);
|
2149
|
|
|
}
|
2150
|
|
|
}
|
2151
|
|
|
}
|
2152
|
|
|
|
2153
|
|
|
/**
|
2154
|
|
|
* Add Listing published bcc option.
|
2155
|
|
|
*
|
2156
|
|
|
* WP Admin -> Geodirectory -> Notifications -> Site Bcc Options
|
2157
|
|
|
*
|
2158
|
|
|
* @since 1.0.0
|
2159
|
|
|
* @package GeoDirectory
|
2160
|
|
|
* @param array $settings The settings array.
|
2161
|
|
|
* @return array
|
2162
|
|
|
*/
|
2163
|
1 |
|
function geodir_notification_add_bcc_option($settings)
|
2164
|
|
|
{
|
2165
|
1 |
|
if (!empty($settings)) {
|
2166
|
|
|
$new_settings = array();
|
2167
|
|
|
foreach ($settings as $setting) {
|
2168
|
|
|
if (isset($setting['id']) && $setting['id'] == 'site_bcc_options' && isset($setting['type']) && $setting['type'] == 'sectionend') {
|
2169
|
|
|
$geodir_bcc_listing_published_yes = array(
|
2170
|
1 |
|
'name' => __('Listing published', 'geodirectory'),
|
2171
|
|
|
'desc' => __('Yes', 'geodirectory'),
|
2172
|
|
|
'id' => 'geodir_bcc_listing_published',
|
2173
|
|
|
'std' => 'yes',
|
2174
|
|
|
'type' => 'radio',
|
2175
|
|
|
'value' => '1',
|
2176
|
|
|
'radiogroup' => 'start'
|
2177
|
|
|
);
|
2178
|
|
|
|
2179
|
|
|
$geodir_bcc_listing_published_no = array(
|
2180
|
|
|
'name' => __('Listing published', 'geodirectory'),
|
2181
|
|
|
'desc' => __('No', 'geodirectory'),
|
2182
|
|
|
'id' => 'geodir_bcc_listing_published',
|
2183
|
|
|
'std' => 'yes',
|
2184
|
|
|
'type' => 'radio',
|
2185
|
|
|
'value' => '0',
|
2186
|
|
|
'radiogroup' => 'end'
|
2187
|
|
|
);
|
2188
|
|
|
|
2189
|
|
|
$new_settings[] = $geodir_bcc_listing_published_yes;
|
2190
|
|
|
$new_settings[] = $geodir_bcc_listing_published_no;
|
2191
|
|
|
}
|
2192
|
|
|
$new_settings[] = $setting;
|
2193
|
|
|
}
|
2194
|
|
|
$settings = $new_settings;
|
2195
|
|
|
}
|
2196
|
|
|
|
2197
|
|
|
return $settings;
|
2198
|
|
|
}
|
2199
|
|
|
|
2200
|
|
|
|
2201
|
|
|
add_action('wp_ajax_get_gd_theme_compat_callback', 'get_gd_theme_compat_callback');
|
2202
|
|
|
|
2203
|
|
|
/**
|
2204
|
|
|
* Exports theme compatibility data for given theme.
|
2205
|
|
|
*
|
2206
|
|
|
* @since 1.0.0
|
2207
|
|
|
* @package GeoDirectory
|
2208
|
|
|
* @global object $wpdb WordPress Database object.
|
2209
|
|
|
*/
|
2210
|
|
|
function get_gd_theme_compat_callback()
|
2211
|
|
|
{
|
2212
|
|
|
global $wpdb;
|
2213
|
|
|
$themes = get_option('gd_theme_compats');
|
2214
|
|
|
|
2215
|
|
|
if (isset($_POST['theme']) && isset($themes[$_POST['theme']]) && !empty($themes[$_POST['theme']])) {
|
2216
|
|
|
if (isset($_POST['export'])) {
|
2217
|
|
|
echo json_encode(array($_POST['theme'] => $themes[$_POST['theme']]));
|
2218
|
|
|
} else {
|
2219
|
|
|
echo json_encode($themes[$_POST['theme']]);
|
2220
|
|
|
}
|
2221
|
|
|
|
2222
|
|
|
}
|
2223
|
|
|
|
2224
|
|
|
die();
|
2225
|
|
|
}
|
2226
|
|
|
|
2227
|
|
|
add_action('wp_ajax_get_gd_theme_compat_import_callback', 'get_gd_theme_compat_import_callback');
|
2228
|
|
|
|
2229
|
|
|
/**
|
2230
|
|
|
* Imports theme compatibility data for given theme.
|
2231
|
|
|
*
|
2232
|
|
|
* @since 1.0.0
|
2233
|
|
|
* @package GeoDirectory
|
2234
|
|
|
* @global object $wpdb WordPress Database object.
|
2235
|
|
|
*/
|
2236
|
|
|
function get_gd_theme_compat_import_callback()
|
2237
|
|
|
{
|
2238
|
|
|
global $wpdb;
|
2239
|
|
|
$themes = get_option('gd_theme_compats');
|
2240
|
|
|
if (isset($_POST['theme']) && !empty($_POST['theme'])) {
|
2241
|
|
|
$json = json_decode(stripslashes($_POST['theme']), true);
|
2242
|
|
|
if (!empty($json) && is_array($json)) {
|
2243
|
|
|
$key = sanitize_text_field(key($json));
|
2244
|
|
|
$themes[$key] = $json[$key];
|
2245
|
|
|
update_option('gd_theme_compats', $themes);
|
2246
|
|
|
echo $key;
|
2247
|
|
|
die();
|
2248
|
|
|
}
|
2249
|
|
|
}
|
2250
|
|
|
echo '0';
|
2251
|
|
|
die();
|
2252
|
|
|
}
|
2253
|
|
|
|
2254
|
|
|
|
2255
|
|
|
/**
|
2256
|
|
|
* Sets theme compatibility options.
|
2257
|
|
|
*
|
2258
|
|
|
* @since 1.0.0
|
2259
|
|
|
* @package GeoDirectory
|
2260
|
|
|
* @global object $wpdb WordPress Database object.
|
2261
|
|
|
*/
|
2262
|
|
|
function gd_set_theme_compat()
|
2263
|
|
|
{
|
2264
|
|
|
global $wpdb;
|
2265
|
|
|
$theme = wp_get_theme();
|
2266
|
|
|
|
2267
|
|
View Code Duplication |
if ($theme->parent()) {
|
2268
|
|
|
$theme_name = str_replace(" ", "_", $theme->parent()->get('Name'));
|
2269
|
|
|
} else {
|
2270
|
|
|
$theme_name = str_replace(" ", "_", $theme->get('Name'));
|
2271
|
|
|
}
|
2272
|
|
|
|
2273
|
|
|
$theme_compats = get_option('gd_theme_compats');
|
2274
|
|
|
$current_compat = get_option('gd_theme_compat');
|
2275
|
|
|
$current_compat = str_replace("_custom", "", $current_compat);
|
2276
|
|
|
|
2277
|
|
|
if ($current_compat == $theme_name && strpos("_custom", get_option('gd_theme_compat')) !== false) {
|
2278
|
|
|
return;
|
2279
|
|
|
}// if already running correct compat then bail
|
2280
|
|
|
|
2281
|
|
|
if (isset($theme_compats[$theme_name])) {// if there is a compat avail then set it
|
2282
|
|
|
update_option('gd_theme_compat', $theme_name);
|
2283
|
1 |
|
update_option('theme_compatibility_setting', $theme_compats[$theme_name]);
|
2284
|
1 |
|
|
2285
|
|
|
// if there are default options to set then set them
|
2286
|
1 |
|
if (isset($theme_compats[$theme_name]['geodir_theme_compat_default_options']) && !empty($theme_compats[$theme_name]['geodir_theme_compat_default_options'])) {
|
2287
|
|
|
|
2288
|
|
|
foreach ($theme_compats[$theme_name]['geodir_theme_compat_default_options'] as $key => $val) {
|
2289
|
1 |
|
update_option($key, $val);
|
2290
|
|
|
}
|
2291
|
|
|
}
|
2292
|
1 |
|
|
2293
|
1 |
|
} else {
|
2294
|
1 |
|
update_option('gd_theme_compat', '');
|
2295
|
|
|
update_option('theme_compatibility_setting', '');
|
2296
|
1 |
|
}
|
2297
|
|
|
|
2298
|
|
|
|
2299
|
|
|
}
|
2300
|
1 |
|
|
2301
|
|
|
|
2302
|
|
|
add_action('wp_loaded', 'gd_check_avada_compat');
|
2303
|
|
|
/**
|
2304
|
|
|
* Function to check if Avada needs header.php replaced
|
2305
|
|
|
*
|
2306
|
|
|
* @since 1.0.0
|
2307
|
|
|
* @package GeoDirectory
|
2308
|
|
|
*/
|
2309
|
|
|
function gd_check_avada_compat()
|
2310
|
|
|
{
|
2311
|
|
|
if (function_exists('avada_load_textdomain') && !get_option('avada_nag')) {
|
2312
|
|
|
add_action('admin_notices', 'gd_avada_compat_warning');
|
2313
|
1 |
|
}
|
2314
|
1 |
|
}
|
2315
|
|
|
|
2316
|
|
|
|
2317
|
|
|
/**
|
2318
|
1 |
|
* Displays Avada compatibility warning.
|
2319
|
|
|
*
|
2320
|
|
|
* @since 1.0.0
|
2321
|
|
|
* @package GeoDirectory
|
2322
|
|
|
*/
|
2323
|
|
|
function gd_avada_compat_warning()
|
2324
|
|
|
{
|
2325
|
|
|
|
2326
|
|
|
/*
|
2327
|
|
|
$msg_type = error
|
2328
|
|
|
$msg_type = updated fade
|
2329
|
|
|
$msg_type = update-nag
|
2330
|
|
|
*/
|
2331
|
|
|
|
2332
|
|
|
$plugin = 'avada-nag';
|
2333
|
|
|
$timestamp = 'avada-nag1234';
|
2334
|
|
|
$message = __('Welcome to GeoDirectory, please have a look <a href="https://docs.wpgeodirectory.com/category/getting-started/" target="_blank">here</a> to get started. :)', 'geodirectory');
|
2335
|
|
|
echo '<div id="' . $timestamp . '" class="error">';
|
2336
|
|
|
echo '<span class="gd-remove-noti" onclick="gdRemoveANotification(\'' . $plugin . '\',\'' . $timestamp . '\');" ><i class="fa fa-times"></i></span>';
|
2337
|
|
|
echo "<img class='gd-icon-noti' src='" . plugin_dir_url('') . "geodirectory/geodirectory-assets/images/favicon.ico' > ";
|
2338
|
|
|
echo "<p>$message</p>";
|
2339
|
|
|
echo "</div>";
|
2340
|
|
|
|
2341
|
|
|
?>
|
2342
|
|
|
<script>
|
2343
|
|
|
function gdRemoveANotification($plugin, $timestamp) {
|
2344
|
|
|
|
2345
|
|
|
jQuery('#' + $timestamp).css("background-color", "red");
|
2346
|
|
|
jQuery('#' + $timestamp).fadeOut("slow");
|
2347
|
|
|
// This does the ajax request
|
2348
|
|
|
jQuery.ajax({
|
2349
|
|
|
url: ajaxurl,
|
2350
|
|
|
type: 'POST',
|
2351
|
|
|
data: {
|
2352
|
|
|
'action': 'geodir_avada_remove_notification',
|
2353
|
|
|
'plugin': $plugin,
|
2354
|
|
|
'timestamp': $timestamp
|
2355
|
|
|
},
|
2356
|
|
|
success: function (data) {
|
2357
|
|
|
// This outputs the result of the ajax request
|
2358
|
|
|
//alert(data);
|
2359
|
|
|
},
|
2360
|
|
|
error: function (errorThrown) {
|
2361
|
|
|
console.log(errorThrown);
|
2362
|
|
|
}
|
2363
|
|
|
});
|
2364
|
|
|
|
2365
|
|
|
}
|
2366
|
|
|
</script>
|
2367
|
|
|
<style>
|
2368
|
|
|
.gd-icon-noti {
|
2369
|
|
|
float: left;
|
2370
|
|
|
margin-top: 10px;
|
2371
|
|
|
margin-right: 5px;
|
2372
|
|
|
}
|
2373
|
|
|
|
2374
|
|
|
.update-nag .gd-icon-noti {
|
2375
|
|
|
margin-top: 2px;
|
2376
|
|
|
}
|
2377
|
|
|
|
2378
|
|
|
.gd-remove-noti {
|
2379
|
|
|
float: right;
|
2380
|
|
|
margin-top: -20px;
|
2381
|
|
|
margin-right: -20px;
|
2382
|
|
|
color: #FF0000;
|
2383
|
|
|
cursor: pointer;
|
2384
|
|
|
}
|
2385
|
|
|
|
2386
|
|
|
.updated .gd-remove-noti, .error .gd-remove-noti {
|
2387
|
|
|
float: right;
|
2388
|
|
|
margin-top: -10px;
|
2389
|
|
|
margin-right: -17px;
|
2390
|
|
|
color: #FF0000;
|
2391
|
|
|
cursor: pointer;
|
2392
|
|
|
}
|
2393
|
|
|
|
2394
|
|
|
|
2395
|
|
|
</style>
|
2396
|
|
|
<?php
|
2397
|
|
|
|
2398
|
|
|
}
|
2399
|
|
|
|
2400
|
|
|
|
2401
|
|
|
/**
|
2402
|
|
|
* Removes Avada compatibility warning.
|
2403
|
|
|
*
|
2404
|
|
|
* @since 1.0.0
|
2405
|
|
|
* @package GeoDirectory
|
2406
|
|
|
*/
|
2407
|
|
|
function geodir_avada_remove_notification()
|
2408
|
|
|
{
|
2409
|
|
|
update_option('avada_nag', TRUE);
|
2410
|
|
|
|
2411
|
|
|
// Always die in functions echoing ajax content
|
2412
|
|
|
die();
|
2413
|
|
|
}
|
2414
|
|
|
|
2415
|
|
|
|
2416
|
|
|
add_action('wp_ajax_geodir_avada_remove_notification', 'geodir_avada_remove_notification');
|
2417
|
|
|
|
2418
|
|
|
/**
|
2419
|
|
|
* Get the current post type in the WordPress admin
|
2420
|
|
|
*
|
2421
|
|
|
* @since 1.4.2
|
2422
|
|
|
* @package GeoDirectory
|
2423
|
|
|
*
|
2424
|
|
|
* @global null|WP_Post $post Post object.
|
2425
|
|
|
* @global string $typenow Post type.
|
2426
|
|
|
* @global object|WP_Screen $current_screen Current screen object
|
2427
|
|
|
*
|
2428
|
|
|
* @return string Post type ex: gd_place
|
2429
|
|
|
*/
|
2430
|
|
|
function geodir_admin_current_post_type() {
|
2431
|
|
|
global $post, $typenow, $current_screen;
|
2432
|
|
|
|
2433
|
|
|
$post_type = NULL;
|
2434
|
|
|
if (isset($_REQUEST['post']) && get_post_type($_REQUEST['post']))
|
2435
|
|
|
$post_type = get_post_type($_REQUEST['post']);
|
2436
|
|
|
elseif ($post && isset($post->post_type))
|
2437
|
|
|
$post_type = $post->post_type;
|
2438
|
|
|
elseif ($typenow)
|
2439
|
|
|
$post_type = $typenow;
|
2440
|
|
|
elseif ($current_screen && isset($current_screen->post_type))
|
2441
|
|
|
$post_type = $current_screen->post_type;
|
2442
|
|
|
elseif (isset($_REQUEST['post_type']))
|
2443
|
|
|
$post_type = sanitize_key($_REQUEST['post_type']);
|
2444
|
|
|
|
2445
|
|
|
|
2446
|
|
|
return $post_type;
|
2447
|
|
|
}
|
2448
|
|
|
|
2449
|
|
|
/**
|
2450
|
|
|
* Fires before updating geodirectory admin settings.
|
2451
|
|
|
*
|
2452
|
|
|
* @since 1.4.2
|
2453
|
|
|
* @package GeoDirectory
|
2454
|
|
|
*
|
2455
|
|
|
* @global object $sitepress Sitepress WPML object.
|
2456
|
|
|
*
|
2457
|
|
|
* @param string $current_tab Current tab in geodirectory settings.
|
2458
|
|
|
* @param array $geodir_settings Array of geodirectory settings.
|
2459
|
|
|
*/
|
2460
|
|
|
function geodir_before_update_options($current_tab, $geodir_settings) {
|
|
|
|
|
2461
|
|
|
$active_tab = isset($_REQUEST['active_tab']) ? trim($_REQUEST['active_tab']) : '';
|
2462
|
|
|
|
2463
|
|
|
// Permalink settings
|
2464
|
|
|
if ($current_tab == 'permalink_settings') {
|
2465
|
|
|
$listing_prefix = isset($_POST['geodir_listing_prefix']) ? trim($_POST['geodir_listing_prefix']) : '';
|
2466
|
|
|
$location_prefix = isset($_POST['geodir_location_prefix']) ? trim($_POST['geodir_location_prefix']) : '';
|
2467
|
|
|
|
2468
|
|
|
// Don't allow same slug url for listing and location
|
2469
|
|
|
if (geodir_strtolower($listing_prefix) == geodir_strtolower($location_prefix)) {
|
2470
|
|
|
$redirect_url = admin_url('admin.php?page=geodirectory&tab=' . $current_tab . '&active_tab=' . $active_tab . '&msg=fail&gderr=21');
|
2471
|
|
|
wp_redirect($redirect_url);
|
2472
|
|
|
exit;
|
2473
|
|
|
}
|
2474
|
|
|
|
2475
|
|
|
// Don't allow to update page settings on different language.
|
2476
|
|
|
if (geodir_is_wpml()) {
|
2477
|
|
|
global $sitepress;
|
2478
|
|
|
$current_language = $sitepress->get_current_language();
|
2479
|
|
|
$default_language = $sitepress->get_default_language();
|
2480
|
|
|
|
2481
|
|
|
if ($current_language != 'all' && $current_language != $default_language) {
|
2482
|
|
|
$redirect_url = admin_url('admin.php?page=geodirectory&tab=' . $current_tab . '&active_tab=' . $active_tab);
|
2483
|
|
|
wp_redirect($redirect_url);
|
2484
|
|
|
exit;
|
2485
|
|
|
}
|
2486
|
|
|
}
|
2487
|
|
|
}
|
2488
|
|
|
}
|
2489
|
|
|
|
2490
|
|
|
|
2491
|
|
|
/**
|
2492
|
|
|
* Removes the preview buttons from the wp-admin area for GD post types.
|
2493
|
|
|
*
|
2494
|
|
|
* This was removed as the preview page was causing bugs.
|
2495
|
|
|
*
|
2496
|
|
|
* @global string $post_type The current post type.
|
2497
|
|
|
* @since 1.4.3
|
2498
|
|
|
* @package GeoDirectory
|
2499
|
|
|
*/
|
2500
|
|
|
function geodir_hide_admin_preview_button() {
|
2501
|
|
|
global $post_type;
|
2502
|
|
|
$post_types = geodir_get_posttypes();
|
2503
|
|
|
if(in_array($post_type, $post_types))
|
2504
|
|
|
echo '<style type="text/css">#post-preview, #view-post-btn{display: none;}</style>';
|
2505
|
|
|
}
|
2506
|
|
|
add_action( 'admin_head-post-new.php', 'geodir_hide_admin_preview_button' );
|
2507
|
|
|
add_action( 'admin_head-post.php', 'geodir_hide_admin_preview_button' );
|
2508
|
|
|
|
2509
|
|
|
/**
|
2510
|
|
|
* Add the tab in left sidebar menu fro import & export page.
|
2511
|
|
|
*
|
2512
|
|
|
* @since 1.4.6
|
2513
|
|
|
* @package GeoDirectory
|
2514
|
|
|
*
|
2515
|
|
|
* @return array Array of tab data.
|
2516
|
|
|
*/
|
2517
|
|
|
function geodir_import_export_tab( $tabs ) {
|
2518
|
|
|
$tabs['import_export'] = array( 'label' => __( 'Import & Export', 'geodirectory' ) );
|
2519
|
|
|
return $tabs;
|
2520
|
|
|
}
|
2521
|
|
|
|
2522
|
|
|
/**
|
2523
|
|
|
* Display the page to manage import/export categories/listings.
|
2524
|
|
|
*
|
2525
|
|
|
* @since 1.4.6
|
2526
|
|
|
* @since 1.5.6 Option added to export max number listings per csv file.
|
2527
|
|
|
* @package GeoDirectory
|
2528
|
|
|
*
|
2529
|
|
|
* @return string Html content.
|
2530
|
|
|
*/
|
2531
|
|
|
function geodir_import_export_page() {
|
2532
|
|
|
$nonce = wp_create_nonce( 'geodir_import_export_nonce' );
|
2533
|
|
|
$gd_cats_sample_csv = geodir_plugin_url() . '/geodirectory-assets/gd_sample_categories.csv';
|
2534
|
|
|
/**
|
2535
|
|
|
* Filter sample category data csv file url.
|
2536
|
|
|
*
|
2537
|
1 |
|
* @since 1.0.0
|
2538
|
1 |
|
* @package GeoDirectory
|
2539
|
|
|
*
|
2540
|
|
|
* @param string $gd_cats_sample_csv Sample category data csv file url.
|
2541
|
|
|
*/
|
2542
|
|
|
$gd_cats_sample_csv = apply_filters( 'geodir_export_cats_sample_csv', $gd_cats_sample_csv );
|
2543
|
|
|
|
2544
|
|
|
$gd_posts_sample_csv = geodir_plugin_url() . '/geodirectory-assets/place_listing.csv';
|
2545
|
|
|
/**
|
2546
|
|
|
* Filter sample post data csv file url.
|
2547
|
|
|
*
|
2548
|
|
|
* @since 1.0.0
|
2549
|
|
|
* @package GeoDirectory
|
2550
|
|
|
*
|
2551
|
1 |
|
* @param string $gd_posts_sample_csv Sample post data csv file url.
|
2552
|
1 |
|
*/
|
2553
|
|
|
$gd_posts_sample_csv = apply_filters( 'geodir_export_posts_sample_csv', $gd_posts_sample_csv );
|
2554
|
|
|
|
2555
|
|
|
$gd_posttypes = geodir_get_posttypes( 'array' );
|
2556
|
|
|
|
2557
|
|
|
$gd_posttypes_option = '';
|
2558
|
|
|
foreach ( $gd_posttypes as $gd_posttype => $row ) {
|
|
|
|
|
2559
|
|
|
$gd_posttypes_option .= '<option value="' . $gd_posttype . '" data-cats="' . (int)geodir_get_terms_count( $gd_posttype ) . '" data-posts="' . (int)geodir_get_posts_count( $gd_posttype ) . '">' . __( $row['labels']['name'], 'geodirectory' ) . '</option>';
|
2560
|
|
|
}
|
2561
|
1 |
|
wp_enqueue_script( 'jquery-ui-progressbar' );
|
2562
|
|
|
|
2563
|
1 |
|
$gd_chunksize_options = array();
|
2564
|
|
|
$gd_chunksize_options[100] = 100;
|
2565
|
|
|
$gd_chunksize_options[200] = 200;
|
2566
|
|
|
$gd_chunksize_options[500] = 500;
|
2567
|
|
|
$gd_chunksize_options[1000] = 1000;
|
2568
|
|
|
$gd_chunksize_options[2000] = 2000;
|
2569
|
|
|
$gd_chunksize_options[5000] = 5000;
|
2570
|
|
|
$gd_chunksize_options[10000] = 10000;
|
2571
|
|
|
$gd_chunksize_options[20000] = 20000;
|
2572
|
1 |
|
$gd_chunksize_options[50000] = 50000;
|
2573
|
|
|
$gd_chunksize_options[100000] = 100000;
|
2574
|
1 |
|
|
2575
|
|
|
/**
|
2576
|
1 |
|
* Filter max entries per export csv file.
|
2577
|
1 |
|
*
|
2578
|
1 |
|
* @since 1.5.6
|
2579
|
1 |
|
* @package GeoDirectory
|
2580
|
1 |
|
*
|
2581
|
|
|
* @param string $gd_chunksize_options Entries options.
|
2582
|
1 |
|
*/
|
2583
|
1 |
|
$gd_chunksize_options = apply_filters( 'geodir_export_csv_chunksize_options', $gd_chunksize_options );
|
2584
|
1 |
|
|
2585
|
1 |
|
$gd_chunksize_option = '';
|
2586
|
1 |
|
foreach ($gd_chunksize_options as $value => $title) {
|
2587
|
1 |
|
$gd_chunksize_option .= '<option value="' . $value . '" ' . selected($value, 5000, false) . '>' . $title . '</option>';
|
2588
|
1 |
|
}
|
2589
|
1 |
|
|
2590
|
1 |
|
$uploads = wp_upload_dir();
|
2591
|
1 |
|
?>
|
2592
|
1 |
|
</form>
|
2593
|
|
|
<div class="inner_content_tab_main gd-import-export">
|
2594
|
|
|
<h3><?php _e( 'GD Import & Export CSV', 'geodirectory' ) ;?></h3>
|
2595
|
|
|
<span class="description"><?php _e( 'Import & export csv for GD listings & categories.', 'geodirectory' ) ;?></span>
|
2596
|
|
|
<div class="gd-content-heading">
|
2597
|
|
|
|
2598
|
|
|
<?php
|
2599
|
|
|
ini_set('max_execution_time', 999999);
|
2600
|
|
|
$ini_max_execution_time_check = @ini_get( 'max_execution_time' );
|
2601
|
|
|
ini_restore('max_execution_time');
|
2602
|
1 |
|
|
2603
|
|
|
if($ini_max_execution_time_check != 999999){ // only show these setting to the user if we can't change the ini setting
|
2604
|
1 |
|
?>
|
2605
|
1 |
|
<div id="gd_ie_reqs" class="metabox-holder">
|
2606
|
1 |
|
<div class="meta-box-sortables ui-sortable">
|
2607
|
1 |
|
<div class="postbox">
|
2608
|
|
|
<h3 class="hndle"><span style='vertical-align:top;'><?php echo __( 'PHP Requirements for GD Import & Export CSV', 'geodirectory' );?></span></h3>
|
2609
|
1 |
|
<div class="inside">
|
2610
|
|
|
<span class="description"><?php echo __( 'Note: In case GD import & export csv not working for larger data then please check and configure following php settings.', 'geodirectory' );?></span>
|
2611
|
|
|
<table class="form-table">
|
2612
|
|
|
<thead>
|
2613
|
|
|
<tr>
|
2614
|
|
|
<th><?php _e( 'PHP Settings', 'geodirectory' );?></th><th><?php _e( 'Current Value', 'geodirectory' );?></th><th><?php _e( 'Recommended Value', 'geodirectory' );?></th>
|
2615
|
|
|
</tr>
|
2616
|
|
|
</thead>
|
2617
|
|
|
<tbody>
|
2618
|
1 |
|
<tr>
|
2619
|
1 |
|
<td>max_input_time</td><td><?php echo @ini_get( 'max_input_time' );?></td><td>3000</td>
|
2620
|
1 |
|
</tr>
|
2621
|
|
|
<tr>
|
2622
|
1 |
|
<td>max_execution_time</td><td><?php echo @ini_get( 'max_execution_time' );?></td><td>3000</td>
|
2623
|
|
|
</tr>
|
2624
|
|
|
<tr>
|
2625
|
|
|
<td>memory_limit</td><td><?php echo @ini_get( 'memory_limit' );?></td><td>256M</td>
|
2626
|
|
|
</tr>
|
2627
|
|
|
</tbody>
|
2628
|
|
|
</table>
|
2629
|
|
|
</div>
|
2630
|
|
|
</div>
|
2631
|
|
|
</div>
|
2632
|
|
|
</div>
|
2633
|
|
|
<?php }?>
|
2634
|
|
|
<div id="gd_ie_imposts" class="metabox-holder">
|
2635
|
|
|
<div class="meta-box-sortables ui-sortable">
|
2636
|
|
|
<div id="gd_ie_im_posts" class="postbox gd-hndle-pbox">
|
2637
|
|
|
<button class="handlediv button-link" type="button"><span class="screen-reader-text"><?php _e( 'Toggle panel - GD Listings: Import CSV', 'geodirectory' );?></span><span aria-hidden="true" class="toggle-indicator"></span></button>
|
2638
|
|
|
<h3 class="hndle gd-hndle-click"><span style='vertical-align:top;'><?php echo __( 'GD Listings: Import CSV', 'geodirectory' );?></span></h3>
|
2639
|
|
|
<div class="inside">
|
2640
|
|
|
<table class="form-table">
|
2641
|
|
|
<tbody>
|
2642
|
|
|
<tr>
|
2643
|
|
|
<td class="gd-imex-box">
|
2644
|
|
|
<div class="gd-im-choices">
|
2645
|
|
|
<p><input type="radio" value="update" name="gd_im_choicepost" id="gd_im_pchoice_u" /><label for="gd_im_pchoice_u"><?php _e( 'Update listing if post with post_id already exists.', 'geodirectory' );?></label></p>
|
2646
|
|
|
<p><input type="radio" checked="checked" value="skip" name="gd_im_choicepost" id="gd_im_pchoice_s" /><label for="gd_im_pchoice_s"><?php _e( 'Ignore listing if post with post_id already exists.', 'geodirectory' );?></label></p>
|
2647
|
|
|
</div>
|
2648
|
|
|
<div class="plupload-upload-uic hide-if-no-js" id="gd_im_postplupload-upload-ui">
|
2649
|
|
|
<input type="text" readonly="readonly" name="gd_im_post_file" class="gd-imex-file gd_im_post_file" id="gd_im_post" onclick="jQuery('#gd_im_postplupload-browse-button').trigger('click');" />
|
2650
|
|
|
<input id="gd_im_postplupload-browse-button" type="button" value="<?php echo SELECT_UPLOAD_CSV; ?>" class="gd-imex-pupload button-primary" /><input type="button" value="<?php echo esc_attr( __( 'Download Sample CSV', 'geodirectory' ) );?>" class="button-secondary" name="gd_ie_imposts_sample" id="gd_ie_imposts_sample">
|
2651
|
|
|
<input type="hidden" id="gd_ie_imposts_csv" value="<?php echo $gd_posts_sample_csv;?>" />
|
2652
|
|
|
<?php
|
2653
|
|
|
/**
|
2654
|
|
|
* Called just after the sample CSV download link.
|
2655
|
|
|
*
|
2656
|
|
|
* @since 1.0.0
|
2657
|
|
|
*/
|
2658
|
|
|
do_action('geodir_sample_csv_download_link');
|
2659
|
|
|
?>
|
2660
|
|
|
<span class="ajaxnonceplu" id="ajaxnonceplu<?php echo wp_create_nonce( 'gd_im_postpluploadan' ); ?>"></span>
|
2661
|
|
|
<div class="filelist"></div>
|
2662
|
|
|
</div>
|
2663
|
|
|
<span id="gd_im_catupload-error" style="display:none"></span>
|
2664
|
|
|
<span class="description"></span>
|
2665
|
|
|
<div id="gd_importer" style="display:none">
|
2666
|
|
|
<input type="hidden" id="gd_total" value="0"/>
|
2667
|
|
|
<input type="hidden" id="gd_prepared" value="continue"/>
|
2668
|
|
|
<input type="hidden" id="gd_processed" value="0"/>
|
2669
|
|
|
<input type="hidden" id="gd_created" value="0"/>
|
2670
|
|
|
<input type="hidden" id="gd_updated" value="0"/>
|
2671
|
|
|
<input type="hidden" id="gd_skipped" value="0"/>
|
2672
|
|
|
<input type="hidden" id="gd_invalid" value="0"/>
|
2673
|
|
|
<input type="hidden" id="gd_invalid_addr" value="0"/>
|
2674
|
|
|
<input type="hidden" id="gd_images" value="0"/>
|
2675
|
|
|
<input type="hidden" id="gd_terminateaction" value="continue"/>
|
2676
|
|
|
</div>
|
2677
|
1 |
|
<div class="gd-import-progress" id="gd-import-progress" style="display:none">
|
2678
|
|
|
<div class="gd-import-file"><b><?php _e("Import Data Status :", 'geodirectory');?> </b><font
|
2679
|
|
|
id="gd-import-done">0</font> / <font id="gd-import-total">0</font> ( <font
|
2680
|
|
|
id="gd-import-perc">0%</font> )
|
2681
|
|
|
<div class="gd-fileprogress"></div>
|
2682
|
|
|
</div>
|
2683
|
|
|
</div>
|
2684
|
|
|
<div class="gd-import-msg" id="gd-import-msg" style="display:none">
|
2685
|
|
|
<div id="message" class="message fade"></div>
|
2686
|
|
|
</div>
|
2687
|
|
|
<div class="gd-imex-btns" style="display:none;">
|
2688
|
|
|
<input type="hidden" class="geodir_import_file" name="geodir_import_file" value="save"/>
|
2689
|
|
|
<input onclick="gd_imex_PrepareImport(this, 'post')" type="button" value="<?php echo CSV_IMPORT_DATA; ?>" id="gd_import_data" class="button-primary" />
|
2690
|
|
|
<input onclick="gd_imex_ContinueImport(this, 'post')" type="button" value="<?php _e( "Continue Import Data", 'geodirectory' );?>" id="gd_continue_data" class="button-primary" style="display:none"/>
|
2691
|
|
|
<input type="button" value="<?php _e("Terminate Import Data", 'geodirectory');?>" id="gd_stop_import" class="button-primary" name="gd_stop_import" style="display:none" onclick="gd_imex_TerminateImport(this, 'post')"/>
|
2692
|
|
|
<div id="gd_process_data" style="display:none">
|
2693
|
|
|
<span class="spinner is-active" style="display:inline-block;margin:0 5px 0 5px;float:left"></span><?php _e("Wait, processing import data...", 'geodirectory');?>
|
2694
|
|
|
</div>
|
2695
|
|
|
</div>
|
2696
|
|
|
</td>
|
2697
|
|
|
</tr>
|
2698
|
|
|
</tbody>
|
2699
|
|
|
</table>
|
2700
|
|
|
</div>
|
2701
|
|
|
</div>
|
2702
|
|
|
</div>
|
2703
|
|
|
</div>
|
2704
|
|
|
<div id="gd_ie_excategs" class="metabox-holder">
|
2705
|
|
|
<div class="meta-box-sortables ui-sortable">
|
2706
|
|
|
<div id="gd_ie_ex_posts" class="postbox gd-hndle-pbox">
|
2707
|
|
|
<button class="handlediv button-link" type="button"><span class="screen-reader-text"><?php _e( 'Toggle panel - Listings: Export CSV', 'geodirectory' );?></span><span aria-hidden="true" class="toggle-indicator"></span></button>
|
2708
|
|
|
<h3 class="hndle gd-hndle-click"><span style='vertical-align:top;'><?php echo __( 'GD Listings: Export CSV', 'geodirectory' );?></span></h3>
|
2709
|
|
|
<div class="inside">
|
2710
|
|
|
<table class="form-table">
|
2711
|
|
|
<tbody>
|
2712
|
|
|
<tr>
|
2713
|
|
|
<td class="fld"><label for="gd_post_type">
|
2714
|
|
|
<?php _e( 'Post Type:', 'geodirectory' );?>
|
2715
|
|
|
</label></td>
|
2716
|
|
|
<td><select name="gd_post_type" id="gd_post_type" style="min-width:140px">
|
2717
|
|
|
<?php echo $gd_posttypes_option;?>
|
2718
|
|
|
</select></td>
|
2719
|
|
|
</tr>
|
2720
|
|
|
<tr>
|
2721
|
|
|
<td class="fld" style="vertical-align:top"><label for="gd_chunk_size"><?php _e( 'Max entries per csv file:', 'geodirectory' );?></label></td>
|
2722
|
|
|
<td><select name="gd_chunk_size" id="gd_chunk_size" style="min-width:140px"><?php echo $gd_chunksize_option;?></select><span class="description"><?php _e( 'Please select the maximum number of entries per csv file (defaults to 5000, you might want to lower this to prevent memory issues on some installs)', 'geodirectory' );?></span></td>
|
2723
|
|
|
</tr>
|
2724
|
|
|
<tr class="gd-imex-dates">
|
2725
|
|
|
<td class="fld"><label><?php _e( 'Published Date:', 'geodirectory' );?></label></td>
|
2726
|
|
|
<td><label><span class="label-responsive"><?php _e( 'Start date:', 'geodirectory' );?></span><input type="text" id="gd_imex_start_date" name="gd_imex[start_date]" data-type="date" /></label><label><span class="label-responsive"><?php _e( 'End date:', 'geodirectory' );?></span><input type="text" id="gd_imex_end_date" name="gd_imex[end_date]" data-type="date" /></label></td>
|
2727
|
|
|
</tr>
|
2728
|
|
|
<tr>
|
2729
|
|
|
<td class="fld" style="vertical-align:top"><label>
|
2730
|
|
|
<?php _e( 'Progress:', 'geodirectory' );?>
|
2731
|
|
|
</label></td>
|
2732
|
|
|
<td><div id='gd_progressbar_box'>
|
2733
|
|
|
<div id="gd_progressbar" class="gd_progressbar">
|
2734
|
|
|
<div class="gd-progress-label"></div>
|
2735
|
|
|
</div>
|
2736
|
|
|
</div>
|
2737
|
|
|
<p style="display:inline-block">
|
2738
|
|
|
<?php _e( 'Elapsed Time:', 'geodirectory' );?>
|
2739
|
|
|
</p>
|
2740
|
|
|
|
2741
|
|
|
<p id="gd_timer" class="gd_timer">00:00:00</p></td>
|
2742
|
|
|
</tr>
|
2743
|
|
|
<tr class="gd-ie-actions">
|
2744
|
|
|
<td style="vertical-align:top"><input type="submit" value="<?php echo esc_attr( __( 'Export CSV', 'geodirectory' ) );?>" class="button-primary" name="gd_ie_exposts_submit" id="gd_ie_exposts_submit">
|
2745
|
|
|
</td>
|
2746
|
|
|
<td id="gd_ie_ex_files" class="gd-ie-files"></td>
|
2747
|
|
|
</tr>
|
2748
|
|
|
</tbody>
|
2749
|
|
|
</table>
|
2750
|
|
|
</div>
|
2751
|
|
|
</div>
|
2752
|
|
|
</div>
|
2753
|
|
|
</div>
|
2754
|
|
|
<div id="gd_ie_imcategs" class="metabox-holder">
|
2755
|
|
|
<div class="meta-box-sortables ui-sortable">
|
2756
|
|
|
<div id="gd_ie_imcats" class="postbox gd-hndle-pbox">
|
2757
|
|
|
<button class="handlediv button-link" type="button"><span class="screen-reader-text"><?php _e( 'Toggle panel - GD Categories: Import CSV', 'geodirectory' );?></span><span aria-hidden="true" class="toggle-indicator"></span></button>
|
2758
|
|
|
<h3 class="hndle gd-hndle-click"><span style='vertical-align:top;'><?php echo __( 'GD Categories: Import CSV', 'geodirectory' );?></span></h3>
|
2759
|
|
|
<div class="inside">
|
2760
|
|
|
<table class="form-table">
|
2761
|
|
|
<tbody>
|
2762
|
|
|
<tr>
|
2763
|
|
|
<td class="gd-imex-box">
|
2764
|
|
|
<div class="gd-im-choices">
|
2765
|
|
|
<p><input type="radio" value="update" name="gd_im_choicecat" id="gd_im_cchoice_u" /><label for="gd_im_cchoice_u"><?php _e( 'Update item if item with cat_id/cat_slug already exists.', 'geodirectory' );?></label></p>
|
2766
|
|
|
<p><input type="radio" checked="checked" value="skip" name="gd_im_choicecat" id="gd_im_cchoice_s" /><label for="gd_im_cchoice_s"><?php _e( 'Ignore item if item with cat_id/cat_slug already exists.', 'geodirectory' );?></label></p>
|
2767
|
|
|
</div>
|
2768
|
|
|
<div class="plupload-upload-uic hide-if-no-js" id="gd_im_catplupload-upload-ui">
|
2769
|
|
|
<input type="text" readonly="readonly" name="gd_im_cat_file" class="gd-imex-file gd_im_cat_file" id="gd_im_cat" onclick="jQuery('#gd_im_catplupload-browse-button').trigger('click');" />
|
2770
|
|
|
<input id="gd_im_catplupload-browse-button" type="button" value="<?php echo SELECT_UPLOAD_CSV; ?>" class="gd-imex-cupload button-primary" /><input type="button" value="<?php echo esc_attr( __( 'Download Sample CSV', 'geodirectory' ) );?>" class="button-secondary" name="gd_ie_imcats_sample" id="gd_ie_imcats_sample">
|
2771
|
|
|
<input type="hidden" id="gd_ie_imcats_csv" value="<?php echo $gd_cats_sample_csv;?>" />
|
2772
|
|
|
<?php
|
2773
|
|
|
/**
|
2774
|
|
|
* Called just after the sample CSV download link.
|
2775
|
|
|
*
|
2776
|
|
|
* @since 1.0.0
|
2777
|
|
|
* @package GeoDirectory
|
2778
|
|
|
*/
|
2779
|
|
|
do_action('geodir_sample_cats_csv_download_link');
|
2780
|
|
|
?>
|
2781
|
|
|
<span class="ajaxnonceplu" id="ajaxnonceplu<?php echo wp_create_nonce( 'gd_im_catpluploadan' ); ?>"></span>
|
2782
|
|
|
<div class="filelist"></div>
|
2783
|
|
|
</div>
|
2784
|
|
|
<span id="gd_im_catupload-error" style="display:none"></span>
|
2785
|
|
|
<span class="description"></span>
|
2786
|
|
|
<div id="gd_importer" style="display:none">
|
2787
|
|
|
<input type="hidden" id="gd_total" value="0"/>
|
2788
|
|
|
<input type="hidden" id="gd_prepared" value="continue"/>
|
2789
|
|
|
<input type="hidden" id="gd_processed" value="0"/>
|
2790
|
|
|
<input type="hidden" id="gd_created" value="0"/>
|
2791
|
|
|
<input type="hidden" id="gd_updated" value="0"/>
|
2792
|
|
|
<input type="hidden" id="gd_skipped" value="0"/>
|
2793
|
|
|
<input type="hidden" id="gd_invalid" value="0"/>
|
2794
|
|
|
<input type="hidden" id="gd_images" value="0"/>
|
2795
|
|
|
<input type="hidden" id="gd_terminateaction" value="continue"/>
|
2796
|
|
|
</div>
|
2797
|
|
|
<div class="gd-import-progress" id="gd-import-progress" style="display:none">
|
2798
|
1 |
|
<div class="gd-import-file"><b><?php _e("Import Data Status :", 'geodirectory');?> </b><font
|
2799
|
|
|
id="gd-import-done">0</font> / <font id="gd-import-total">0</font> ( <font
|
2800
|
|
|
id="gd-import-perc">0%</font> )
|
2801
|
|
|
<div class="gd-fileprogress"></div>
|
2802
|
|
|
</div>
|
2803
|
|
|
</div>
|
2804
|
|
|
<div class="gd-import-msg" id="gd-import-msg" style="display:none">
|
2805
|
|
|
<div id="message" class="message fade"></div>
|
2806
|
|
|
</div>
|
2807
|
|
|
<div class="gd-imex-btns" style="display:none;">
|
2808
|
|
|
<input type="hidden" class="geodir_import_file" name="geodir_import_file" value="save"/>
|
2809
|
|
|
<input onclick="gd_imex_PrepareImport(this, 'cat')" type="button" value="<?php echo CSV_IMPORT_DATA; ?>" id="gd_import_data" class="button-primary" />
|
2810
|
|
|
<input onclick="gd_imex_ContinueImport(this, 'cat')" type="button" value="<?php _e( "Continue Import Data", 'geodirectory' );?>" id="gd_continue_data" class="button-primary" style="display:none"/>
|
2811
|
|
|
<input type="button" value="<?php _e("Terminate Import Data", 'geodirectory');?>" id="gd_stop_import" class="button-primary" name="gd_stop_import" style="display:none" onclick="gd_imex_TerminateImport(this, 'cat')"/>
|
2812
|
|
|
<div id="gd_process_data" style="display:none">
|
2813
|
|
|
<span class="spinner is-active" style="display:inline-block;margin:0 5px 0 5px;float:left"></span><?php _e("Wait, processing import data...", 'geodirectory');?>
|
2814
|
|
|
</div>
|
2815
|
|
|
</div>
|
2816
|
|
|
</td>
|
2817
|
|
|
</tr>
|
2818
|
|
|
</tbody>
|
2819
|
|
|
</table>
|
2820
|
|
|
</div>
|
2821
|
|
|
</div>
|
2822
|
|
|
</div>
|
2823
|
|
|
</div>
|
2824
|
|
|
<div id="gd_ie_excategs" class="metabox-holder">
|
2825
|
|
|
<div class="meta-box-sortables ui-sortable">
|
2826
|
|
|
<div id="gd_ie_ex_cats" class="postbox gd-hndle-pbox">
|
2827
|
|
|
<button class="handlediv button-link" type="button"><span class="screen-reader-text"><?php _e( 'Toggle panel - GD Categories: Export CSV', 'geodirectory' );?></span><span aria-hidden="true" class="toggle-indicator"></span></button>
|
2828
|
|
|
<h3 class="hndle gd-hndle-click"><span style='vertical-align:top;'><?php echo __( 'GD Categories: Export CSV', 'geodirectory' );?></span></h3>
|
2829
|
|
|
<div class="inside">
|
2830
|
|
|
<table class="form-table">
|
2831
|
|
|
<tbody>
|
2832
|
|
|
<tr>
|
2833
|
|
|
<td class="fld"><label for="gd_post_type"><?php _e( 'Post Type:', 'geodirectory' );?></label></td>
|
2834
|
|
|
<td><select name="gd_post_type" id="gd_post_type" style="min-width:140px"><?php echo $gd_posttypes_option;?></select></td>
|
2835
|
|
|
</tr>
|
2836
|
|
|
<tr>
|
2837
|
|
|
<td class="fld" style="vertical-align:top"><label for="gd_chunk_size"><?php _e( 'Max entries per csv file:', 'geodirectory' );?></label></td>
|
2838
|
|
|
<td><select name="gd_chunk_size" id="gd_chunk_size" style="min-width:140px"><?php echo $gd_chunksize_option;?></select><span class="description"><?php _e( 'Please select the maximum number of entries per csv file (defaults to 5000, you might want to lower this to prevent memory issues on some installs)', 'geodirectory' );?></span></td>
|
2839
|
|
|
</tr>
|
2840
|
|
|
<tr>
|
2841
|
|
|
<td class="fld" style="vertical-align:top"><label><?php _e( 'Progress:', 'geodirectory' );?></label></td>
|
2842
|
|
|
<td><div id='gd_progressbar_box'><div id="gd_progressbar" class="gd_progressbar"><div class="gd-progress-label"></div></div></div><p style="display:inline-block"><?php _e( 'Elapsed Time:', 'geodirectory' );?></p> <p id="gd_timer" class="gd_timer">00:00:00</p></td>
|
2843
|
|
|
</tr>
|
2844
|
|
|
<tr class="gd-ie-actions">
|
2845
|
|
|
<td style="vertical-align:top">
|
2846
|
|
|
<input type="submit" value="<?php echo esc_attr( __( 'Export CSV', 'geodirectory' ) );?>" class="button-primary" name="gd_ie_excats_submit" id="gd_ie_excats_submit">
|
2847
|
|
|
</td>
|
2848
|
|
|
<td id="gd_ie_ex_files" class="gd-ie-files"></td>
|
2849
|
|
|
</tr>
|
2850
|
|
|
</tbody>
|
2851
|
|
|
</table>
|
2852
|
|
|
</div>
|
2853
|
|
|
</div>
|
2854
|
|
|
</div>
|
2855
|
|
|
</div>
|
2856
|
|
|
<?php
|
2857
|
|
|
/**
|
2858
|
|
|
* Allows you to add more setting to the GD > Import & Export page.
|
2859
|
|
|
*
|
2860
|
|
|
* Called after the last setting on the GD > Import & Export page.
|
2861
|
|
|
* @since 1.4.6
|
2862
|
|
|
* @package GeoDirectory
|
2863
|
|
|
*
|
2864
|
|
|
* @param array $gd_posttypes GD post types.
|
2865
|
|
|
* @param array $gd_chunksize_options File chunk size options.
|
2866
|
|
|
* @param string $nonce Wordpress security token for GD import & export.
|
2867
|
|
|
*/
|
2868
|
|
|
do_action( 'geodir_import_export', $gd_posttypes, $gd_chunksize_options, $nonce );
|
2869
|
|
|
?>
|
2870
|
|
|
</div>
|
2871
|
|
|
</div>
|
2872
|
|
|
<script type="text/javascript">
|
2873
|
|
|
var timoutC, timoutP, timoutL, timoutH;
|
2874
|
|
|
|
2875
|
|
|
function gd_imex_PrepareImport(el, type) {
|
2876
|
|
|
var cont = jQuery(el).closest('.gd-imex-box');
|
2877
|
|
|
var gd_prepared = jQuery('#gd_prepared', cont).val();
|
2878
|
|
|
var uploadedFile = jQuery('#gd_im_' + type, cont).val();
|
2879
|
|
|
jQuery('gd-import-msg', cont).hide();
|
2880
|
|
|
if(gd_prepared == uploadedFile) {
|
2881
|
|
|
gd_imex_ContinueImport(el, type);
|
2882
|
|
|
jQuery('#gd_import_data', cont).attr('disabled', 'disabled');
|
2883
|
|
|
} else {
|
2884
|
|
|
jQuery.ajax({
|
2885
|
|
|
url: ajaxurl,
|
2886
|
|
|
type: "POST",
|
2887
|
1 |
|
data: 'action=geodir_import_export&task=prepare_import&_pt=' + type + '&_file=' + uploadedFile + '&_nonce=<?php echo $nonce;?>',
|
2888
|
|
|
dataType: 'json',
|
2889
|
|
|
cache: false,
|
2890
|
|
|
success: function(data) {
|
2891
|
|
|
if(typeof data == 'object') {
|
2892
|
|
|
if(data.error) {
|
2893
|
|
|
jQuery('#gd-import-msg', cont).find('#message').removeClass('updated').addClass('error').html('<p>' + data.error + '</p>');
|
2894
|
|
|
jQuery('#gd-import-msg', cont).show();
|
2895
|
|
|
} else if(!data.error && typeof data.rows != 'undefined') {
|
2896
|
|
|
jQuery('#gd_total', cont).val(data.rows);
|
2897
|
|
|
jQuery('#gd_prepared', cont).val(uploadedFile);
|
2898
|
|
|
jQuery('#gd_processed', cont).val('0');
|
2899
|
|
|
jQuery('#gd_created', cont).val('0');
|
2900
|
|
|
jQuery('#gd_updated', cont).val('0');
|
2901
|
|
|
jQuery('#gd_skipped', cont).val('0');
|
2902
|
|
|
jQuery('#gd_invalid', cont).val('0');
|
2903
|
|
|
jQuery('#gd_images', cont).val('0');
|
2904
|
|
|
if(type == 'post') {
|
2905
|
|
|
jQuery('#gd_invalid_addr', cont).val('0');
|
2906
|
|
|
}
|
2907
|
|
|
gd_imex_StartImport(el, type);
|
2908
|
|
|
}
|
2909
|
|
|
}
|
2910
|
|
|
},
|
2911
|
|
|
error: function(errorThrown) {
|
2912
|
|
|
console.log(errorThrown);
|
2913
|
|
|
}
|
2914
|
|
|
});
|
2915
|
|
|
}
|
2916
|
|
|
}
|
2917
|
|
|
|
2918
|
|
|
function gd_imex_StartImport(el, type) {
|
2919
|
|
|
var cont = jQuery(el).closest('.gd-imex-box');
|
2920
|
|
|
|
2921
|
|
|
var limit = 1;
|
2922
|
|
|
var total = parseInt(jQuery('#gd_total', cont).val());
|
2923
|
|
|
var total_processed = parseInt(jQuery('#gd_processed', cont).val());
|
2924
|
|
|
var uploadedFile = jQuery('#gd_im_' + type, cont).val();
|
2925
|
|
|
var choice = jQuery('input[name="gd_im_choice'+ type +'"]:checked', cont).val();
|
2926
|
|
|
|
2927
|
|
|
if (!uploadedFile) {
|
2928
|
|
|
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
|
2929
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
2930
|
|
|
jQuery('#gd_process_data', cont).hide();
|
2931
|
|
|
jQuery('#gd-import-progress', cont).hide();
|
2932
|
|
|
jQuery('.gd-fileprogress', cont).width(0);
|
2933
|
|
|
jQuery('#gd-import-done', cont).text('0');
|
2934
|
|
|
jQuery('#gd-import-total', cont).text('0');
|
2935
|
|
|
jQuery('#gd-import-perc', cont).text('0%');
|
2936
|
|
|
|
2937
|
|
|
jQuery(cont).find('.filelist .file').remove();
|
2938
|
|
|
|
2939
|
|
|
jQuery('#gd-import-msg', cont).find('#message').removeClass('updated').addClass('error').html("<p><?php echo esc_attr( PLZ_SELECT_CSV_FILE );?></p>");
|
2940
|
|
|
jQuery('#gd-import-msg', cont).show();
|
2941
|
|
|
|
2942
|
|
|
return false;
|
2943
|
|
|
}
|
2944
|
|
|
|
2945
|
|
|
jQuery('#gd-import-total', cont).text(total);
|
2946
|
|
|
jQuery('#gd_stop_import', cont).show();
|
2947
|
|
|
jQuery('#gd_process_data', cont).css({
|
2948
|
|
|
'display': 'inline-block'
|
2949
|
|
|
});
|
2950
|
|
|
jQuery('#gd-import-progress', cont).show();
|
2951
|
|
|
if ((parseInt(total) / 100) > 0) {
|
2952
|
|
|
limit = parseInt(parseInt(total) / 100);
|
2953
|
|
|
}
|
2954
|
|
|
if (limit == 1) {
|
2955
|
|
|
if (parseInt(total) > 50) {
|
2956
|
|
|
limit = 5;
|
2957
|
|
|
} else if (parseInt(total) > 10 && parseInt(total) < 51) {
|
2958
|
|
|
limit = 2;
|
2959
|
|
|
}
|
2960
|
|
|
}
|
2961
|
|
|
if (limit > 10) {
|
2962
|
|
|
limit = 10;
|
2963
|
|
|
}
|
2964
|
|
|
if (limit < 1) {
|
2965
|
|
|
limit = 1;
|
2966
|
|
|
}
|
2967
|
|
|
|
2968
|
|
|
if ( parseInt(limit) > parseInt(total) )
|
2969
|
|
|
limit = parseInt(total);
|
2970
|
|
|
if (total_processed >= total) {
|
2971
|
|
|
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
|
2972
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
2973
|
|
|
jQuery('#gd_process_data', cont).hide();
|
2974
|
|
|
|
2975
|
|
|
gd_imex_showStatusMsg(el, type);
|
2976
|
|
|
|
2977
|
|
|
jQuery('#gd_im_' + type, cont).val('');
|
2978
|
|
|
jQuery('#gd_prepared', cont).val('');
|
2979
|
|
|
|
2980
|
|
|
return false;
|
2981
|
|
|
}
|
2982
|
|
|
jQuery('#gd-import-msg', cont).hide();
|
2983
|
|
|
|
2984
|
|
|
var gd_processed = parseInt(jQuery('#gd_processed', cont).val());
|
2985
|
|
|
var gd_created = parseInt(jQuery('#gd_created', cont).val());
|
2986
|
|
|
var gd_updated = parseInt(jQuery('#gd_updated', cont).val());
|
2987
|
|
|
var gd_skipped = parseInt(jQuery('#gd_skipped', cont).val());
|
2988
|
|
|
var gd_invalid = parseInt(jQuery('#gd_invalid', cont).val());
|
2989
|
|
|
var gd_images = parseInt(jQuery('#gd_images', cont).val());
|
2990
|
|
|
if (type=='post') {
|
2991
|
|
|
var gd_invalid_addr = parseInt(jQuery('#gd_invalid_addr', cont).val());
|
2992
|
|
|
}
|
2993
|
|
|
|
2994
|
|
|
var gddata = '&limit=' + limit + '&processed=' + gd_processed;
|
2995
|
|
|
jQuery.ajax({
|
2996
|
|
|
url: ajaxurl,
|
2997
|
|
|
type: "POST",
|
2998
|
|
|
data: 'action=geodir_import_export&task=import_' + type + '&_pt=' + type + '&_file=' + uploadedFile + gddata + '&_ch=' + choice + '&_nonce=<?php echo $nonce;?>',
|
2999
|
|
|
dataType : 'json',
|
3000
|
|
|
cache: false,
|
3001
|
|
|
success: function (data) {
|
3002
|
|
|
if (typeof data == 'object') {
|
3003
|
|
|
if (data.error) {
|
3004
|
|
|
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
|
3005
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
3006
|
|
|
jQuery('#gd_process_data', cont).hide();
|
3007
|
|
|
jQuery('#gd-import-msg', cont).find('#message').removeClass('updated').addClass('error').html('<p>' + data.error + '</p>');
|
3008
|
|
|
jQuery('#gd-import-msg', cont).show();
|
3009
|
|
|
} else {
|
3010
|
|
|
gd_processed = gd_processed + parseInt(data.processed);
|
3011
|
|
|
gd_processed = Math.min(gd_processed, total);
|
3012
|
|
|
gd_created = gd_created + parseInt(data.created);
|
3013
|
|
|
gd_updated = gd_updated + parseInt(data.updated);
|
3014
|
|
|
gd_skipped = gd_skipped + parseInt(data.skipped);
|
3015
|
|
|
gd_invalid = gd_invalid + parseInt(data.invalid);
|
3016
|
|
|
gd_images = gd_images + parseInt(data.images);
|
3017
|
|
|
if (type=='post' && typeof data.invalid_addr != 'undefined') {
|
3018
|
|
|
gd_invalid_addr = gd_invalid_addr + parseInt(data.invalid_addr);
|
3019
|
|
|
}
|
3020
|
|
|
|
3021
|
|
|
jQuery('#gd_processed', cont).val(gd_processed);
|
3022
|
|
|
jQuery('#gd_created', cont).val(gd_created);
|
3023
|
|
|
jQuery('#gd_updated', cont).val(gd_updated);
|
3024
|
|
|
jQuery('#gd_skipped', cont).val(gd_skipped);
|
3025
|
|
|
jQuery('#gd_invalid', cont).val(gd_invalid);
|
3026
|
|
|
jQuery('#gd_images', cont).val(gd_images);
|
3027
|
|
|
if (type=='post') {
|
3028
|
|
|
jQuery('#gd_invalid_addr', cont).val(gd_invalid_addr);
|
3029
|
|
|
}
|
3030
|
|
|
|
3031
|
|
|
if (parseInt(gd_processed) == parseInt(total)) {
|
3032
|
|
|
jQuery('#gd-import-done', cont).text(total);
|
3033
|
|
|
jQuery('#gd-import-perc', cont).text('100%');
|
3034
|
|
|
jQuery('.gd-fileprogress', cont).css({
|
3035
|
|
|
'width': '100%'
|
3036
|
|
|
});
|
3037
|
|
|
jQuery('#gd_im_' + type, cont).val('');
|
3038
|
|
|
jQuery('#gd_prepared', cont).val('');
|
3039
|
|
|
|
3040
|
|
|
gd_imex_showStatusMsg(el, type);
|
3041
|
|
|
gd_imex_FinishImport(el, type);
|
3042
|
|
|
|
3043
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
3044
|
|
|
}
|
3045
|
|
|
if (parseInt(gd_processed) < parseInt(total)) {
|
3046
|
|
|
var terminate_action = jQuery('#gd_terminateaction', cont).val();
|
3047
|
|
|
if (terminate_action == 'continue') {
|
3048
|
|
|
var nTmpCnt = parseInt(total_processed) + parseInt(limit);
|
3049
|
|
|
nTmpCnt = nTmpCnt > total ? total : nTmpCnt;
|
3050
|
|
|
|
3051
|
|
|
jQuery('#gd_processed', cont).val(nTmpCnt);
|
3052
|
|
|
|
3053
|
|
|
jQuery('#gd-import-done', cont).text(nTmpCnt);
|
3054
|
|
|
if (parseInt(total) > 0) {
|
3055
|
|
|
var percentage = ((parseInt(nTmpCnt) / parseInt(total)) * 100);
|
3056
|
|
|
percentage = percentage > 100 ? 100 : percentage;
|
3057
|
|
|
jQuery('#gd-import-perc', cont).text(parseInt(percentage) + '%');
|
3058
|
|
|
jQuery('.gd-fileprogress', cont).css({
|
3059
|
|
|
'width': percentage + '%'
|
3060
|
|
|
});
|
3061
|
|
|
}
|
3062
|
|
|
|
3063
|
|
|
if (type=='cat') {
|
3064
|
|
|
clearTimeout(timoutC);
|
3065
|
|
|
timoutC = setTimeout(function () {
|
3066
|
|
|
gd_imex_StartImport(el, type);
|
3067
|
|
|
}, 0);
|
3068
|
|
|
}
|
3069
|
|
|
if (type=='post') {
|
3070
|
|
|
clearTimeout(timoutP);
|
3071
|
|
|
timoutP = setTimeout(function () {
|
3072
|
|
|
gd_imex_StartImport(el, type);
|
3073
|
|
|
}, 0);
|
3074
|
|
|
}
|
3075
|
|
|
if (type=='loc') {
|
3076
|
|
|
clearTimeout(timoutL);
|
3077
|
|
|
timoutL = setTimeout(function () {
|
3078
|
|
|
gd_imex_StartImport(el, type);
|
3079
|
|
|
}, 0);
|
3080
|
|
|
}
|
3081
|
|
|
if (type=='hood') {
|
3082
|
|
|
clearTimeout(timoutH);
|
3083
|
|
|
timoutH = setTimeout(function () {
|
3084
|
|
|
gd_imex_StartImport(el, type);
|
3085
|
|
|
}, 0);
|
3086
|
|
|
}
|
3087
|
|
|
} else {
|
3088
|
|
|
jQuery('#gd_import_data', cont).hide();
|
3089
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
3090
|
|
|
jQuery('#gd_process_data', cont).hide();
|
3091
|
|
|
jQuery('#gd_continue_data', cont).show();
|
3092
|
|
|
return false;
|
3093
|
|
|
}
|
3094
|
|
|
} else {
|
3095
|
|
|
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
|
3096
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
3097
|
|
|
jQuery('#gd_process_data', cont).hide();
|
3098
|
|
|
return false;
|
3099
|
|
|
}
|
3100
|
|
|
}
|
3101
|
|
|
} else {
|
3102
|
|
|
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
|
3103
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
3104
|
|
|
jQuery('#gd_process_data', cont).hide();
|
3105
|
|
|
}
|
3106
|
|
|
},
|
3107
|
|
|
error: function (errorThrown) {
|
3108
|
|
|
jQuery('#gd_import_data', cont).removeAttr('disabled').show();
|
3109
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
3110
|
|
|
jQuery('#gd_process_data', cont).hide();
|
3111
|
|
|
console.log(errorThrown);
|
3112
|
|
|
}
|
3113
|
|
|
});
|
3114
|
|
|
}
|
3115
|
|
|
|
3116
|
|
|
function gd_imex_TerminateImport(el, type) {
|
3117
|
|
|
var cont = jQuery(el).closest('.gd-imex-box');
|
3118
|
|
|
jQuery('#gd_terminateaction', cont).val('terminate');
|
3119
|
|
|
jQuery('#gd_import_data', cont).hide();
|
3120
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
3121
|
|
|
jQuery('#gd_process_data', cont).hide();
|
3122
|
|
|
jQuery('#gd_continue_data', cont).show();
|
3123
|
|
|
}
|
3124
|
|
|
|
3125
|
|
|
function gd_imex_ContinueImport(el, type) {
|
3126
|
|
|
var cont = jQuery(el).closest('.gd-imex-box');
|
3127
|
|
|
var processed = jQuery('#gd_processed', cont).val();
|
3128
|
|
|
var total = jQuery('#gd_total', cont).val();
|
3129
|
|
|
if (parseInt(processed) > parseInt(total)) {
|
3130
|
|
|
jQuery('#gd_stop_import', cont).hide();
|
3131
|
|
|
} else {
|
3132
|
|
|
jQuery('#gd_stop_import', cont).show();
|
3133
|
|
|
}
|
3134
|
|
|
jQuery('#gd_import_data', cont).show();
|
3135
|
|
|
jQuery('#gd_import_data', cont).attr('disabled', 'disabled');
|
3136
|
|
|
jQuery('#gd_process_data', cont).css({
|
3137
|
|
|
'display': 'inline-block'
|
3138
|
|
|
});
|
3139
|
|
|
jQuery('#gd_continue_data', cont).hide();
|
3140
|
|
|
jQuery('#gd_terminateaction', cont).val('continue');
|
3141
|
|
|
|
3142
|
|
|
if (type=='cat') {
|
3143
|
|
|
clearTimeout(timoutC);
|
3144
|
|
|
timoutC = setTimeout(function () {
|
3145
|
|
|
gd_imex_StartImport(el, type);
|
3146
|
|
|
}, 0);
|
3147
|
|
|
}
|
3148
|
|
|
|
3149
|
|
|
if (type=='post') {
|
3150
|
|
|
clearTimeout(timoutP);
|
3151
|
|
|
timoutP = setTimeout(function () {
|
3152
|
|
|
gd_imex_StartImport(el, type);
|
3153
|
|
|
}, 0);
|
3154
|
|
|
}
|
3155
|
|
|
|
3156
|
|
|
if (type=='loc') {
|
3157
|
|
|
clearTimeout(timoutL);
|
3158
|
|
|
timoutL = setTimeout(function () {
|
3159
|
|
|
gd_imex_StartImport(el, type);
|
3160
|
|
|
}, 0);
|
3161
|
|
|
}
|
3162
|
|
|
|
3163
|
|
|
if (type=='hood') {
|
3164
|
|
|
clearTimeout(timoutH);
|
3165
|
|
|
timoutH = setTimeout(function () {
|
3166
|
|
|
gd_imex_StartImport(el, type);
|
3167
|
|
|
}, 0);
|
3168
|
|
|
}
|
3169
|
|
|
}
|
3170
|
|
|
|
3171
|
|
|
function gd_imex_showStatusMsg(el, type) {
|
3172
|
|
|
var cont = jQuery(el).closest('.gd-imex-box');
|
3173
|
|
|
|
3174
|
|
|
var total = parseInt(jQuery('#gd_total', cont).val());
|
3175
|
|
|
var processed = parseInt(jQuery('#gd_processed', cont).val());
|
3176
|
|
|
var created = parseInt(jQuery('#gd_created', cont).val());
|
3177
|
|
|
var updated = parseInt(jQuery('#gd_updated', cont).val());
|
3178
|
|
|
var skipped = parseInt(jQuery('#gd_skipped', cont).val());
|
3179
|
|
|
var invalid = parseInt(jQuery('#gd_invalid', cont).val());
|
3180
|
|
|
var images = parseInt(jQuery('#gd_images', cont).val());
|
3181
|
|
|
if (type=='post') {
|
3182
|
|
|
var invalid_addr = parseInt(jQuery('#gd_invalid_addr', cont).val());
|
3183
|
|
|
}
|
3184
|
|
|
|
3185
|
|
|
var gdMsg = '<p></p>';
|
3186
|
|
|
if ( processed > 0 ) {
|
3187
|
|
|
var msgParse = '<p><?php echo addslashes( sprintf( __( 'Total %s item(s) found.', 'geodirectory' ), '%s' ) );?></p>';
|
3188
|
|
|
msgParse = msgParse.replace("%s", processed);
|
3189
|
|
|
gdMsg += msgParse;
|
3190
|
|
|
}
|
3191
|
|
|
|
3192
|
|
|
if ( updated > 0 ) {
|
3193
|
|
|
var msgParse = '<p><?php echo addslashes( sprintf( __( '%s / %s item(s) updated.', 'geodirectory' ), '%s', '%d' ) );?></p>';
|
3194
|
|
|
msgParse = msgParse.replace("%s", updated);
|
3195
|
|
|
msgParse = msgParse.replace("%d", processed);
|
3196
|
|
|
gdMsg += msgParse;
|
3197
|
|
|
}
|
3198
|
|
|
|
3199
|
|
|
if ( created > 0 ) {
|
3200
|
|
|
var msgParse = '<p><?php echo addslashes( sprintf( __( '%s / %s item(s) added.', 'geodirectory' ), '%s', '%d' ) );?></p>';
|
3201
|
|
|
msgParse = msgParse.replace("%s", created);
|
3202
|
|
|
msgParse = msgParse.replace("%d", processed);
|
3203
|
|
|
gdMsg += msgParse;
|
3204
|
|
|
}
|
3205
|
|
|
|
3206
|
|
|
if ( skipped > 0 ) {
|
3207
|
|
|
var msgParse = '<p><?php echo addslashes( sprintf( __( '%s / %s item(s) ignored due to already exists.', 'geodirectory' ), '%s', '%d' ) );?></p>';
|
3208
|
|
|
msgParse = msgParse.replace("%s", skipped);
|
3209
|
|
|
msgParse = msgParse.replace("%d", processed);
|
3210
|
|
|
gdMsg += msgParse;
|
3211
|
|
|
}
|
3212
|
|
|
|
3213
|
|
|
if ((type=='post' && invalid_addr > 0) || (type=='loc' && invalid > 0)) {
|
3214
|
|
|
if (type=='loc') {
|
3215
|
|
|
invalid_addr = invalid;
|
3216
|
|
|
}
|
3217
|
|
|
var msgParse = '<p><?php echo addslashes( sprintf( __( '%s / %s item(s) could not be added due to blank/invalid address(city, region, country, latitude, longitude).', 'geodirectory' ), '%s', '%d' ) );?></p>';
|
3218
|
|
|
msgParse = msgParse.replace("%s", invalid_addr);
|
3219
|
|
|
msgParse = msgParse.replace("%d", total);
|
3220
|
|
|
gdMsg += msgParse;
|
3221
|
|
|
}
|
3222
|
|
|
|
3223
|
|
|
if (invalid > 0 && type!='loc') {
|
3224
|
|
|
var msgParse = '<p><?php echo addslashes( sprintf( __( '%s / %s item(s) could not be added due to blank title/invalid post type/invalid characters used in data.', 'geodirectory' ), '%s', '%d' ) );?></p>';
|
3225
|
|
|
|
3226
|
|
|
if (type=='hood') {
|
3227
|
|
|
msgParse = '<p><?php echo addslashes( sprintf( __( '%s / %s item(s) could not be added due to invalid neighbourhood data(name, latitude, longitude) or invalid location data(either location_id or city/region/country is empty)', 'geodirectory' ), '%s', '%d' ) );?></p>';
|
3228
|
|
|
}
|
3229
|
|
|
msgParse = msgParse.replace("%s", invalid);
|
3230
|
|
|
msgParse = msgParse.replace("%d", total);
|
3231
|
|
|
gdMsg += msgParse;
|
3232
|
|
|
}
|
3233
|
|
|
|
3234
|
|
|
if (images > 0) {
|
3235
|
|
|
gdMsg += '<p><?php echo addslashes( sprintf( CSV_TRANSFER_IMG_FOLDER, $uploads['subdir'] ) );?></p>';
|
3236
|
|
|
}
|
3237
|
|
|
gdMsg += '<p></p>';
|
3238
|
|
|
jQuery('#gd-import-msg', cont).find('#message').removeClass('error').addClass('updated').html(gdMsg);
|
3239
|
|
|
jQuery('#gd-import-msg', cont).show();
|
3240
|
|
|
return;
|
3241
|
|
|
}
|
3242
|
|
|
|
3243
|
|
|
|
3244
|
|
|
|
3245
|
|
|
jQuery(function(){
|
3246
|
|
|
jQuery('.postbox.gd-hndle-pbox').addClass('closed');
|
3247
|
|
|
jQuery('.gd-import-export .postbox .gd-hndle-click, .gd-import-export .postbox .button-link').click(function(e){
|
3248
|
|
|
var $this = this;
|
3249
|
|
|
var $postbox = jQuery($this).closest('.postbox');
|
3250
|
|
|
|
3251
|
|
|
$postbox.toggleClass('closed');
|
3252
|
|
|
});
|
3253
|
|
|
|
3254
|
|
|
var intIp;
|
3255
|
|
|
var intIc;
|
3256
|
|
|
|
3257
|
|
|
jQuery(".gd-imex-pupload").click(function () {
|
3258
|
|
|
var $this = this;
|
3259
|
|
|
var $cont = jQuery($this).closest('.gd-imex-box');
|
3260
|
|
|
clearInterval(intIp);
|
3261
|
|
|
intIp = setInterval(function () {
|
3262
|
|
|
if (jQuery($cont).find('.gd-imex-file').val()) {
|
3263
|
|
|
jQuery($cont).find('.gd-imex-btns').show();
|
3264
|
|
|
}
|
3265
|
|
|
}, 1000);
|
3266
|
|
|
});
|
3267
|
|
|
|
3268
|
|
|
jQuery(".gd-imex-cupload").click(function () {
|
3269
|
|
|
var $this = this;
|
3270
|
|
|
var $cont = jQuery($this).closest('.gd-imex-box');
|
3271
|
|
|
clearInterval(intIc);
|
3272
|
|
|
intIc = setInterval(function () {
|
3273
|
|
|
if (jQuery($cont).find('.gd-imex-file').val()) {
|
3274
|
|
|
jQuery($cont).find('.gd-imex-btns').show();
|
3275
|
|
|
}
|
3276
|
|
|
}, 1000);
|
3277
|
|
|
});
|
3278
|
|
|
|
3279
|
|
|
jQuery('#gd_ie_imposts_sample').click(function(){
|
3280
|
|
|
if (jQuery('#gd_ie_imposts_csv').val() != '') {
|
3281
|
|
|
window.location.href = jQuery('#gd_ie_imposts_csv').val();
|
3282
|
|
|
return false;
|
3283
|
|
|
}
|
3284
|
|
|
});
|
3285
|
|
|
|
3286
|
|
|
jQuery('#gd_ie_imcats_sample').click(function(){
|
3287
|
|
|
if (jQuery('#gd_ie_imcats_csv').val() != '') {
|
3288
|
|
|
window.location.href = jQuery('#gd_ie_imcats_csv').val();
|
3289
|
|
|
return false;
|
3290
|
|
|
}
|
3291
|
|
|
});
|
3292
|
|
|
|
3293
|
|
|
jQuery('.gd-import-export .geodir_event_csv_download a').addClass('button-secondary');
|
3294
|
|
|
|
3295
|
|
|
jQuery( '.gd_progressbar' ).each(function(){
|
3296
|
|
|
jQuery(this).progressbar({value:0});
|
3297
|
|
|
});
|
3298
|
|
|
|
3299
|
|
|
var timer_posts;
|
3300
|
|
|
var pseconds;
|
3301
|
|
|
jQuery('#gd_ie_exposts_submit').click(function(){
|
3302
|
|
|
pseconds = 1;
|
3303
|
|
|
|
3304
|
|
|
var el = jQuery(this).closest('.postbox');
|
3305
|
|
|
var post_type = jQuery(el).find('#gd_post_type').val();
|
3306
|
|
|
if ( !post_type ) {
|
3307
|
|
|
jQuery(el).find('#gd_post_type').focus();
|
3308
|
|
|
return false;
|
3309
|
|
|
}
|
3310
|
|
|
window.clearInterval(timer_posts);
|
3311
|
|
|
|
3312
|
|
|
jQuery(this).prop('disabled', true);
|
3313
|
|
|
|
3314
|
|
|
timer_posts = window.setInterval( function() {
|
3315
|
|
|
jQuery(el).find(".gd_timer").gdposts_timer();
|
3316
|
|
|
}, 1000);
|
3317
|
|
|
|
3318
|
|
|
var chunk_size = parseInt(jQuery('#gd_chunk_size', el).val());
|
3319
|
|
|
var total_posts = parseInt(jQuery('option:selected', jQuery(el).find('#gd_post_type')).attr('data-posts'));
|
3320
|
|
|
chunk_size = chunk_size < 50 || chunk_size > 100000 ? 5000 : chunk_size;
|
3321
|
|
|
if (chunk_size > total_posts) {
|
3322
|
|
|
chunk_size = total_posts;
|
3323
|
|
|
}
|
3324
|
|
|
var pages = Math.ceil( total_posts / chunk_size );
|
3325
|
|
|
|
3326
|
|
|
var filters = '';
|
3327
|
|
|
var v;
|
3328
|
|
|
jQuery('[name^="gd_imex["]', el).each(function() {
|
3329
|
|
|
v = jQuery(this).val();
|
3330
|
|
|
v = typeof v == 'string' && v !== '' ? v.trim() : '';
|
3331
|
|
|
if (v !== '') {
|
3332
|
|
|
filters += '&' + jQuery(this).prop('name') + '=' + v;
|
3333
|
|
|
}
|
3334
|
|
|
});
|
3335
|
|
|
|
3336
|
|
|
gd_process_export_posts(el, post_type, total_posts, chunk_size, pages, 1, filters, true);
|
3337
|
|
|
});
|
3338
|
|
|
|
3339
|
|
|
jQuery.fn.gdposts_timer = function() {
|
3340
|
|
|
pseconds++;
|
3341
|
|
|
jQuery(this).text( pseconds.toString().toHMS() );
|
3342
|
|
|
}
|
3343
|
|
|
|
3344
|
|
|
var timer_cats;
|
3345
|
|
|
var cseconds;
|
3346
|
|
|
jQuery('#gd_ie_excats_submit').click(function(){
|
3347
|
|
|
cseconds = 1;
|
3348
|
|
|
|
3349
|
|
|
var el = jQuery(this).closest('.postbox');
|
3350
|
|
|
var post_type = jQuery(el).find('#gd_post_type').val();
|
3351
|
|
|
if ( !post_type ) {
|
3352
|
|
|
jQuery(el).find('#gd_post_type').focus();
|
3353
|
|
|
return false;
|
3354
|
|
|
}
|
3355
|
|
|
window.clearInterval(timer_cats);
|
3356
|
|
|
|
3357
|
|
|
jQuery(this).prop('disabled', true);
|
3358
|
|
|
|
3359
|
|
|
timer_cats = window.setInterval( function() {
|
3360
|
|
|
jQuery(el).find(".gd_timer").gdcats_timer();
|
3361
|
|
|
}, 1000);
|
3362
|
|
|
|
3363
|
|
|
var chunk_size = parseInt(jQuery('#gd_chunk_size', el).val());
|
3364
|
|
|
var total_cats = parseInt(jQuery('option:selected', jQuery(el).find('#gd_post_type')).attr('data-cats'));
|
3365
|
|
|
chunk_size = chunk_size < 50 || chunk_size > 100000 ? 5000 : chunk_size;
|
3366
|
|
|
if (chunk_size > total_cats) {
|
3367
|
|
|
chunk_size = total_cats;
|
3368
|
|
|
}
|
3369
|
|
|
var pages = Math.ceil( total_cats / chunk_size );
|
3370
|
|
|
|
3371
|
|
|
gd_process_export_cats(el, post_type, total_cats, chunk_size, pages, 1);
|
3372
|
|
|
});
|
3373
|
|
|
|
3374
|
|
|
jQuery.fn.gdcats_timer = function() {
|
3375
|
|
|
cseconds++;
|
3376
|
|
|
jQuery(this).text( cseconds.toString().toHMS() );
|
3377
|
|
|
}
|
3378
|
|
|
|
3379
|
|
|
String.prototype.toHMS = function () {
|
3380
|
|
|
var sec_num = parseInt(this, 10); // don't forget the second param
|
3381
|
|
|
var hours = Math.floor(sec_num / 3600);
|
3382
|
|
|
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
|
3383
|
|
|
var seconds = sec_num - (hours * 3600) - (minutes * 60);
|
3384
|
|
|
|
3385
|
|
|
if (hours < 10) {hours = "0"+hours;}
|
3386
|
|
|
if (minutes < 10) {minutes = "0"+minutes;}
|
3387
|
|
|
if (seconds < 10) {seconds = "0"+seconds;}
|
3388
|
|
|
var time = hours+':'+minutes+':'+seconds;
|
3389
|
|
|
return time;
|
3390
|
|
|
}
|
3391
|
|
|
|
3392
|
|
|
function gd_process_export_posts(el, post_type, total_posts, chunk_size, pages, page, filters, doFilter) {
|
3393
|
|
|
var attach = (typeof filters !== 'undefined' && filters) ? filters : '';
|
3394
|
|
|
var getTotal = false;
|
3395
|
|
|
if (page < 2) {
|
3396
|
|
|
if (typeof filters !== 'undefined' && filters && doFilter) {
|
3397
|
|
|
getTotal = true;
|
3398
|
|
|
attach += '&_c=1';
|
3399
|
|
|
gd_progressbar(el, 0, '<i class="fa fa-refresh fa-spin"></i><?php echo esc_attr( __( 'Preparing...', 'geodirectory' ) );?>');
|
3400
|
|
|
} else {
|
3401
|
|
|
gd_progressbar(el, 0, '0% (0 / ' + total_posts + ') <i class="fa fa-refresh fa-spin"></i><?php echo esc_attr( __( 'Exporting...', 'geodirectory' ) );?>');
|
3402
|
|
|
}
|
3403
|
|
|
jQuery(el).find('#gd_timer').text('00:00:01');
|
3404
|
|
|
jQuery('#gd_ie_ex_files', el).html('');
|
3405
|
|
|
}
|
3406
|
|
|
|
3407
|
|
|
jQuery.ajax({
|
3408
|
|
|
url: ajaxurl,
|
3409
|
|
|
type: "POST",
|
3410
|
|
|
data: 'action=geodir_import_export&task=export_posts&_pt=' + post_type + '&_n=' + chunk_size + '&_nonce=<?php echo $nonce;?>&_p=' + page + attach,
|
3411
|
|
|
dataType : 'json',
|
3412
|
|
|
cache: false,
|
3413
|
|
|
beforeSend: function (jqXHR, settings) {},
|
3414
|
|
|
success: function( data ) {
|
3415
|
|
|
jQuery(el).find('input[type="submit"]').prop('disabled', false);
|
3416
|
|
|
|
3417
|
|
|
if (typeof data == 'object') {
|
3418
|
|
|
if (typeof data.error != 'undefined' && data.error) {
|
3419
|
|
|
gd_progressbar(el, 0, '<i class="fa fa-warning"></i>' + data.error);
|
3420
|
|
|
window.clearInterval(timer_posts);
|
3421
|
|
|
} else {
|
3422
|
|
|
if (getTotal) {
|
3423
|
|
|
if (typeof data.total != 'undefined' ) {
|
3424
|
|
|
total_posts = parseInt(data.total);
|
3425
|
|
|
if (chunk_size > total_posts) {
|
3426
|
|
|
chunk_size = total_posts;
|
3427
|
|
|
}
|
3428
|
|
|
pages = Math.ceil( total_posts / chunk_size );
|
3429
|
|
|
|
3430
|
|
|
return gd_process_export_posts(el, post_type, total_posts, chunk_size, pages, 1, filters);
|
3431
|
|
|
}
|
3432
|
|
|
} else {
|
3433
|
|
|
if (pages < page || pages == page) {
|
3434
|
|
|
window.clearInterval(timer_posts);
|
3435
|
|
|
gd_progressbar(el, 100, '100% (' + total_posts + ' / ' + total_posts + ') <i class="fa fa-check"></i><?php echo esc_attr( __( 'Complete!', 'geodirectory' ) );?>');
|
3436
|
|
|
} else {
|
3437
|
|
|
var percentage = Math.round(((page * chunk_size) / total_posts) * 100);
|
3438
|
|
|
percentage = percentage > 100 ? 100 : percentage;
|
3439
|
|
|
gd_progressbar(el, percentage, '' + percentage + '% (' + ( page * chunk_size ) + ' / ' + total_posts + ') <i class="fa fa-refresh fa-spin"></i><?php echo esc_attr( __( 'Exporting...', 'geodirectory' ) );?>');
|
3440
|
|
|
}
|
3441
|
|
|
if (typeof data.files != 'undefined' && jQuery(data.files).length ) {
|
3442
|
|
|
var obj_files = data.files;
|
3443
|
|
|
var files = '';
|
3444
|
|
|
for (var i in data.files) {
|
3445
|
|
|
files += '<p>'+ obj_files[i].i +' <a class="gd-ie-file" href="' + obj_files[i].u + '" target="_blank">' + obj_files[i].u + '</a> (' + obj_files[i].s + ')</p>';
|
3446
|
|
|
}
|
3447
|
|
|
jQuery('#gd_ie_ex_files', el).append(files);
|
3448
|
|
|
if (pages > page) {
|
3449
|
|
|
return gd_process_export_posts(el, post_type, total_posts, chunk_size, pages, (page + 1));
|
3450
|
|
|
}
|
3451
|
|
|
return true;
|
3452
|
|
|
}
|
3453
|
|
|
}
|
3454
|
|
|
}
|
3455
|
|
|
}
|
3456
|
|
|
},
|
3457
|
|
|
error: function( data ) {
|
3458
|
|
|
jQuery(el).find('input[type="submit"]').prop('disabled', false);
|
3459
|
|
|
window.clearInterval(timer_posts);
|
3460
|
|
|
return;
|
3461
|
|
|
},
|
3462
|
|
|
complete: function( jqXHR, textStatus ) {
|
3463
|
|
|
return;
|
3464
|
|
|
}
|
3465
|
|
|
});
|
3466
|
|
|
}
|
3467
|
|
|
|
3468
|
|
|
function gd_process_export_cats(el, post_type, total_cats, chunk_size, pages, page) {
|
3469
|
|
|
if (page < 2) {
|
3470
|
|
|
gd_progressbar(el, 0, '0% (0 / ' + total_cats + ') <i class="fa fa-refresh fa-spin"></i><?php echo esc_attr( __( 'Exporting...', 'geodirectory' ) );?>');
|
3471
|
|
|
jQuery(el).find('#gd_timer').text('00:00:01');
|
3472
|
|
|
jQuery('#gd_ie_ex_files', el).html('');
|
3473
|
|
|
}
|
3474
|
|
|
|
3475
|
|
|
jQuery.ajax({
|
3476
|
|
|
url: ajaxurl,
|
3477
|
|
|
type: "POST",
|
3478
|
|
|
data: 'action=geodir_import_export&task=export_cats&_pt=' + post_type + '&_n=' + chunk_size + '&_nonce=<?php echo $nonce;?>&_p=' + page,
|
3479
|
|
|
dataType : 'json',
|
3480
|
|
|
cache: false,
|
3481
|
|
|
beforeSend: function (jqXHR, settings) {},
|
3482
|
|
|
success: function( data ) {
|
3483
|
|
|
jQuery(el).find('input[type="submit"]').prop('disabled', false);
|
3484
|
|
|
|
3485
|
|
|
if (typeof data == 'object') {
|
3486
|
|
|
if (typeof data.error != 'undefined' && data.error) {
|
3487
|
|
|
gd_progressbar(el, 0, '<i class="fa fa-warning"></i>' + data.error);
|
3488
|
|
|
window.clearInterval(timer_cats);
|
3489
|
|
|
} else {
|
3490
|
|
|
if (pages < page || pages == page) {
|
3491
|
|
|
window.clearInterval(timer_cats);
|
3492
|
|
|
gd_progressbar(el, 100, '100% (' + total_cats + ' / ' + total_cats + ') <i class="fa fa-check"></i><?php echo esc_attr( __( 'Complete!', 'geodirectory' ) );?>');
|
3493
|
|
|
} else {
|
3494
|
|
|
var percentage = Math.round(((page * chunk_size) / total_cats) * 100);
|
3495
|
|
|
percentage = percentage > 100 ? 100 : percentage;
|
3496
|
|
|
gd_progressbar(el, percentage, '' + percentage + '% (' + ( page * chunk_size ) + ' / ' + total_cats + ') <i class="fa fa-refresh fa-spin"></i><?php esc_attr_e( 'Exporting...', 'geodirectory' );?>');
|
3497
|
|
|
}
|
3498
|
|
|
if (typeof data.files != 'undefined' && jQuery(data.files).length ) {
|
3499
|
|
|
var obj_files = data.files;
|
3500
|
|
|
var files = '';
|
3501
|
|
|
for (var i in data.files) {
|
3502
|
|
|
files += '<p>'+ obj_files[i].i +' <a class="gd-ie-file" href="' + obj_files[i].u + '" target="_blank">' + obj_files[i].u + '</a> (' + obj_files[i].s + ')</p>';
|
3503
|
|
|
}
|
3504
|
|
|
jQuery('#gd_ie_ex_files', el).append(files);
|
3505
|
|
|
if (pages > page) {
|
3506
|
|
|
return gd_process_export_cats(el, post_type, total_cats, chunk_size, pages, (page + 1));
|
3507
|
|
|
}
|
3508
|
|
|
return true;
|
3509
|
|
|
}
|
3510
|
|
|
}
|
3511
|
|
|
}
|
3512
|
|
|
},
|
3513
|
|
|
error: function( data ) {
|
3514
|
|
|
jQuery(el).find('input[type="submit"]').prop('disabled', false);
|
3515
|
|
|
window.clearInterval(timer_cats);
|
3516
|
|
|
return;
|
3517
|
|
|
},
|
3518
|
|
|
complete: function( jqXHR, textStatus ) {
|
3519
|
|
|
return;
|
3520
|
|
|
}
|
3521
|
|
|
});
|
3522
|
|
|
}
|
3523
|
|
|
});
|
3524
|
|
|
|
3525
|
|
|
function gd_imex_FinishImport(el, type) {
|
3526
|
|
|
if (type=='post') {
|
3527
|
|
|
jQuery.ajax({
|
3528
|
|
|
url: ajaxurl,
|
3529
|
|
|
type: "POST",
|
3530
|
|
|
data: 'action=geodir_import_export&task=import_finish&_pt=' + type + '&_nonce=<?php echo $nonce; ?>',
|
3531
|
|
|
dataType : 'json',
|
3532
|
|
|
cache: false,
|
3533
|
|
|
success: function (data) {
|
3534
|
|
|
//import done
|
3535
|
|
|
}
|
3536
|
|
|
});
|
3537
|
|
|
}
|
3538
|
|
|
}
|
3539
|
|
|
</script>
|
3540
|
|
|
<?php
|
3541
|
|
|
}
|
3542
|
|
|
|
3543
|
|
|
/**
|
3544
|
|
|
* Initiate the WordPress file system and provide fallback if needed.
|
3545
|
|
|
*
|
3546
|
|
|
* @since 1.4.8
|
3547
|
|
|
* @package GeoDirectory
|
3548
|
|
|
* @return bool|string Returns the file system class on success. False on failure.
|
3549
|
|
|
*/
|
3550
|
|
|
function geodir_init_filesystem()
|
3551
|
|
|
{
|
3552
|
|
|
|
3553
|
|
|
if(!function_exists('get_filesystem_method')){
|
3554
|
|
|
require_once(ABSPATH."/wp-admin/includes/file.php");
|
3555
|
|
|
}
|
3556
|
|
|
$access_type = get_filesystem_method();
|
3557
|
|
|
if ($access_type === 'direct') {
|
3558
|
|
|
/* you can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
|
3559
|
|
|
$creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array());
|
3560
|
1 |
|
|
3561
|
|
|
/* initialize the API */
|
3562
|
|
|
if (!WP_Filesystem($creds)) {
|
3563
|
|
|
/* any problems and we exit */
|
3564
|
|
|
//return '@@@3';
|
3565
|
|
|
return false;
|
3566
|
|
|
}
|
3567
|
|
|
|
3568
|
|
|
global $wp_filesystem;
|
3569
|
|
|
return $wp_filesystem;
|
3570
|
|
|
/* do our file manipulations below */
|
3571
|
|
|
} elseif (defined('FTP_USER')) {
|
3572
|
|
|
$creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array());
|
3573
|
|
|
|
3574
|
|
|
/* initialize the API */
|
3575
|
|
|
if (!WP_Filesystem($creds)) {
|
3576
|
|
|
/* any problems and we exit */
|
3577
|
|
|
//return '@@@33';
|
3578
|
|
|
return false;
|
3579
|
|
|
}
|
3580
|
|
|
|
3581
|
|
|
global $wp_filesystem;
|
3582
|
|
|
//return '@@@1';
|
3583
|
|
|
return $wp_filesystem;
|
3584
|
|
|
|
3585
|
|
|
} else {
|
3586
|
|
|
//return '@@@2';
|
3587
|
|
|
/* don't have direct write access. Prompt user with our notice */
|
3588
|
|
|
add_action('admin_notice', 'geodir_filesystem_notice');
|
3589
|
|
|
return false;
|
3590
|
|
|
}
|
3591
|
|
|
|
3592
|
|
|
}
|
3593
|
|
|
|
3594
|
|
|
|
3595
|
|
|
add_action('admin_init', 'geodir_filesystem_notice');
|
3596
|
|
|
|
3597
|
|
|
/**
|
3598
|
|
|
* Output error message for file system access.
|
3599
|
|
|
*
|
3600
|
|
|
* Displays an admin message if the WordPress file system can't be automatically accessed. Called via admin_init hook.
|
3601
|
|
|
*
|
3602
|
|
|
* @since 1.4.8
|
3603
|
|
|
* @since 1.4.9 Added check to not run function when doing ajax calls.
|
3604
|
|
|
* @package GeoDirectory
|
3605
|
|
|
*/
|
3606
|
|
|
function geodir_filesystem_notice()
|
3607
|
|
|
{ if ( defined( 'DOING_AJAX' ) ){return;}
|
3608
|
|
|
$access_type = get_filesystem_method();
|
3609
|
|
|
if ($access_type === 'direct') {
|
3610
|
|
|
} elseif (!defined('FTP_USER')) {
|
3611
|
|
|
?>
|
3612
|
|
|
<div class="error">
|
3613
|
|
|
<p><?php _e('GeoDirectory does not have access to your filesystem, thing like import/export will not work. Please define your details in wp-config.php as explained here', 'geodirectory'); ?>
|
3614
|
|
|
<a target="_blank" href="http://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants">http://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants</a>
|
3615
|
|
|
</p>
|
3616
|
|
|
</div>
|
3617
|
|
|
<?php }
|
3618
|
|
|
}
|
3619
|
|
|
|
3620
|
|
|
|
3621
|
|
|
|
3622
|
|
|
/**
|
3623
|
|
|
* Handle import/export for categories & listings.
|
3624
|
|
|
*
|
3625
|
|
|
* @since 1.4.6
|
3626
|
1 |
|
* @since 1.5.4 Modified to add default category via csv import.
|
3627
|
|
|
* @since 1.5.7 Modified to fix 504 Gateway Time-out for very large data.
|
3628
|
|
|
* @package GeoDirectory
|
3629
|
|
|
*
|
3630
|
|
|
* @global object $wpdb WordPress Database object.
|
3631
|
|
|
* @global string $plugin_prefix Geodirectory plugin table prefix.
|
3632
|
|
|
* @global object $current_user Current user object.
|
3633
|
|
|
* @global null|object $wp_filesystem WP_Filesystem object.
|
3634
|
|
|
* @return string Json data.
|
3635
|
|
|
*/
|
3636
|
|
|
function geodir_ajax_import_export() {
|
3637
|
|
|
global $wpdb, $plugin_prefix, $current_user, $wp_filesystem;
|
3638
|
|
|
|
3639
|
|
|
error_reporting(0);
|
3640
|
|
|
|
3641
|
|
|
// try to set higher limits for import
|
3642
|
|
|
$max_input_time = ini_get('max_input_time');
|
3643
|
|
|
$max_execution_time = ini_get('max_execution_time');
|
3644
|
|
|
$memory_limit= ini_get('memory_limit');
|
3645
|
|
|
|
3646
|
|
|
if(!$max_input_time || $max_input_time<3000){
|
3647
|
|
|
ini_set('max_input_time', 3000);
|
3648
|
|
|
}
|
3649
|
|
|
|
3650
|
|
|
if(!$max_execution_time || $max_execution_time<3000){
|
3651
|
|
|
ini_set('max_execution_time', 3000);
|
3652
|
|
|
}
|
3653
|
|
|
|
3654
|
|
|
if($memory_limit && str_replace('M','',$memory_limit)){
|
3655
|
|
|
if(str_replace('M','',$memory_limit)<256){
|
3656
|
|
|
ini_set('memory_limit', '256M');
|
3657
|
|
|
}
|
3658
|
|
|
}
|
3659
|
|
|
|
3660
|
|
|
$json = array();
|
3661
|
|
|
|
3662
|
|
|
if ( !current_user_can( 'manage_options' ) ) {
|
3663
|
|
|
wp_send_json( $json );
|
3664
|
|
|
}
|
3665
|
|
|
|
3666
|
|
|
$task = isset( $_REQUEST['task'] ) ? $_REQUEST['task'] : NULL;
|
3667
|
|
|
$nonce = isset( $_REQUEST['_nonce'] ) ? $_REQUEST['_nonce'] : NULL;
|
3668
|
|
|
$stat = isset( $_REQUEST['_st'] ) ? $_REQUEST['_st'] : false;
|
|
|
|
|
3669
|
|
|
|
3670
|
|
|
if ( !wp_verify_nonce( $nonce, 'geodir_import_export_nonce' ) ) {
|
3671
|
|
|
wp_send_json( $json );
|
3672
|
|
|
}
|
3673
|
|
|
|
3674
|
|
|
$post_type = isset( $_REQUEST['_pt'] ) ? $_REQUEST['_pt'] : NULL;
|
3675
|
|
|
$chunk_per_page = isset( $_REQUEST['_n'] ) ? absint($_REQUEST['_n']) : NULL;
|
3676
|
|
|
$chunk_per_page = $chunk_per_page < 50 || $chunk_per_page > 100000 ? 5000 : $chunk_per_page;
|
3677
|
|
|
$chunk_page_no = isset( $_REQUEST['_p'] ) ? absint($_REQUEST['_p']) : 1;
|
3678
|
|
|
|
3679
|
|
|
$wp_filesystem = geodir_init_filesystem();
|
3680
|
|
|
if (!$wp_filesystem) {
|
3681
|
|
|
$json['error'] = __( 'Filesystem ERROR: Could not access filesystem.', 'geodirectory' );
|
3682
|
|
|
wp_send_json( $json );
|
3683
|
|
|
}
|
3684
|
|
|
|
3685
|
|
|
if (!empty($wp_filesystem) && isset($wp_filesystem->errors) && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
|
3686
|
|
|
$json['error'] = __( 'Filesystem ERROR: ' . $wp_filesystem->errors->get_error_message(), 'geodirectory' );
|
3687
|
|
|
wp_send_json( $json );
|
3688
|
|
|
}
|
3689
|
|
|
|
3690
|
|
|
$csv_file_dir = geodir_path_import_export( false );
|
3691
|
|
|
if ( !$wp_filesystem->is_dir( $csv_file_dir ) ) {
|
|
|
|
|
3692
|
|
|
if ( !$wp_filesystem->mkdir( $csv_file_dir, FS_CHMOD_DIR ) ) {
|
|
|
|
|
3693
|
|
|
$json['error'] = __( 'ERROR: Could not create cache directory. This is usually due to inconsistent file permissions.', 'geodirectory' );
|
3694
|
|
|
wp_send_json( $json );
|
3695
|
|
|
}
|
3696
|
|
|
}
|
3697
|
|
|
|
3698
|
|
|
$location_manager = function_exists('geodir_location_plugin_activated') ? true : false; // Check location manager installed & active.
|
3699
|
|
|
$neighbourhood_active = $location_manager && get_option('location_neighbourhoods') ? true : false;
|
3700
|
|
|
|
3701
|
|
|
switch ( $task ) {
|
3702
|
|
|
case 'export_posts': {
|
3703
|
|
|
// WPML
|
3704
|
|
|
$is_wpml = geodir_is_wpml();
|
3705
|
|
|
if ($is_wpml) {
|
3706
|
|
|
global $sitepress;
|
3707
|
|
|
$active_lang = ICL_LANGUAGE_CODE;
|
3708
|
|
|
|
3709
|
|
|
$sitepress->switch_lang('all', true);
|
3710
|
|
|
}
|
3711
|
|
|
// WPML
|
3712
|
|
|
if ( $post_type == 'gd_event' ) {
|
3713
|
|
|
add_filter( 'geodir_imex_export_posts_query', 'geodir_imex_get_events_query', 10, 2 );
|
3714
|
|
|
}
|
3715
|
|
|
$filters = !empty( $_REQUEST['gd_imex'] ) && is_array( $_REQUEST['gd_imex'] ) ? $_REQUEST['gd_imex'] : NULL;
|
3716
|
|
|
|
3717
|
|
|
$file_name = $post_type . '_' . date( 'dmyHi' );
|
3718
|
|
|
if ( $filters && isset( $filters['start_date'] ) && isset( $filters['end_date'] ) ) {
|
3719
|
|
|
$file_name = $post_type . '_' . date_i18n( 'dmy', strtotime( $filters['start_date'] ) ) . '_' . date_i18n( 'dmy', strtotime( $filters['end_date'] ) );
|
3720
|
|
|
}
|
3721
|
|
|
$posts_count = geodir_get_posts_count( $post_type );
|
3722
|
|
|
$file_url_base = geodir_path_import_export() . '/';
|
3723
|
|
|
$file_url = $file_url_base . $file_name . '.csv';
|
|
|
|
|
3724
|
|
|
$file_path = $csv_file_dir . '/' . $file_name . '.csv';
|
|
|
|
|
3725
|
|
|
$file_path_temp = $csv_file_dir . '/' . $post_type . '_' . $nonce . '.csv';
|
3726
|
|
|
|
3727
|
|
|
$chunk_file_paths = array();
|
3728
|
|
|
|
3729
|
|
|
if ( isset( $_REQUEST['_c'] ) ) {
|
3730
|
|
|
$json['total'] = $posts_count;
|
3731
|
|
|
// WPML
|
3732
|
|
|
if ($is_wpml) {
|
3733
|
|
|
$sitepress->switch_lang($active_lang, true);
|
|
|
|
|
3734
|
|
|
}
|
3735
|
|
|
// WPML
|
3736
|
|
|
wp_send_json( $json );
|
3737
|
|
|
gd_die();
|
3738
|
|
|
} else if ( isset( $_REQUEST['_st'] ) ) {
|
3739
|
|
|
$line_count = (int)geodir_import_export_line_count( $file_path_temp );
|
3740
|
|
|
$percentage = count( $posts_count ) > 0 && $line_count > 0 ? ceil( $line_count / $posts_count ) * 100 : 0;
|
3741
|
|
|
$percentage = min( $percentage, 100 );
|
3742
|
|
|
|
3743
|
|
|
$json['percentage'] = $percentage;
|
3744
|
|
|
// WPML
|
3745
|
|
|
if ($is_wpml) {
|
3746
|
|
|
$sitepress->switch_lang($active_lang, true);
|
3747
|
|
|
}
|
3748
|
|
|
// WPML
|
3749
|
|
|
wp_send_json( $json );
|
3750
|
|
|
gd_die();
|
3751
|
|
|
} else {
|
3752
|
|
|
if ( !$posts_count > 0 ) {
|
3753
|
|
|
$json['error'] = __( 'No records to export.', 'geodirectory' );
|
3754
|
|
|
} else {
|
3755
|
|
|
$total_posts = $posts_count;
|
3756
|
|
|
if ($chunk_per_page > $total_posts) {
|
3757
|
|
|
$chunk_per_page = $total_posts;
|
3758
|
|
|
}
|
3759
|
|
|
$chunk_total_pages = ceil( $total_posts / $chunk_per_page );
|
3760
|
|
|
|
3761
|
|
|
$j = $chunk_page_no;
|
3762
|
|
|
$chunk_save_posts = geodir_imex_get_posts( $post_type, $chunk_per_page, $j );
|
3763
|
|
|
|
3764
|
|
|
$per_page = 500;
|
3765
|
|
|
if ($per_page > $chunk_per_page) {
|
3766
|
|
|
$per_page = $chunk_per_page;
|
3767
|
|
|
}
|
3768
|
|
|
$total_pages = ceil( $chunk_per_page / $per_page );
|
3769
|
|
|
|
3770
|
|
|
for ( $i = 0; $i <= $total_pages; $i++ ) {
|
3771
|
|
|
$save_posts = array_slice( $chunk_save_posts , ( $i * $per_page ), $per_page );
|
3772
|
|
|
|
3773
|
|
|
$clear = $i == 0 ? true : false;
|
3774
|
|
|
geodir_save_csv_data( $file_path_temp, $save_posts, $clear );
|
3775
|
|
|
}
|
3776
|
|
|
|
3777
|
|
|
if ( $wp_filesystem->exists( $file_path_temp ) ) {
|
|
|
|
|
3778
|
|
|
$chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
|
3779
|
|
|
$chunk_file_name = $file_name . $chunk_page_no . '.csv';
|
3780
|
|
|
$file_path = $csv_file_dir . '/' . $chunk_file_name;
|
3781
|
|
|
$wp_filesystem->move( $file_path_temp, $file_path, true );
|
|
|
|
|
3782
|
|
|
|
3783
|
|
|
$file_url = $file_url_base . $chunk_file_name;
|
3784
|
|
|
$chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
|
3785
|
|
|
}
|
3786
|
|
|
|
3787
|
|
|
if ( !empty($chunk_file_paths) ) {
|
3788
|
|
|
$json['total'] = $posts_count;
|
3789
|
|
|
$json['files'] = $chunk_file_paths;
|
3790
|
|
|
} else {
|
3791
|
|
|
if ($j > 1) {
|
3792
|
|
|
$json['total'] = $posts_count;
|
3793
|
|
|
$json['files'] = array();
|
3794
|
|
|
} else {
|
3795
|
|
|
$json['error'] = __( 'ERROR: Could not create csv file. This is usually due to inconsistent file permissions.', 'geodirectory' );
|
3796
|
|
|
}
|
3797
|
|
|
}
|
3798
|
|
|
}
|
3799
|
|
|
// WPML
|
3800
|
|
|
if ($is_wpml) {
|
3801
|
|
|
$sitepress->switch_lang($active_lang, true);
|
3802
|
|
|
}
|
3803
|
|
|
// WPML
|
3804
|
|
|
wp_send_json( $json );
|
3805
|
|
|
}
|
3806
|
|
|
}
|
3807
|
|
|
break;
|
3808
|
|
|
case 'export_cats': {
|
3809
|
|
|
// WPML
|
3810
|
|
|
$is_wpml = geodir_is_wpml();
|
3811
|
|
|
if ($is_wpml) {
|
3812
|
|
|
global $sitepress;
|
3813
|
|
|
$active_lang = ICL_LANGUAGE_CODE;
|
3814
|
|
|
|
3815
|
|
|
$sitepress->switch_lang('all', true);
|
3816
|
|
|
}
|
3817
|
|
|
// WPML
|
3818
|
|
|
$file_name = $post_type . 'category_' . date( 'dmyHi' );
|
3819
|
|
|
|
3820
|
|
|
$terms_count = geodir_get_terms_count( $post_type );
|
3821
|
|
|
$file_url_base = geodir_path_import_export() . '/';
|
3822
|
|
|
$file_url = $file_url_base . $file_name . '.csv';
|
|
|
|
|
3823
|
|
|
$file_path = $csv_file_dir . '/' . $file_name . '.csv';
|
|
|
|
|
3824
|
|
|
$file_path_temp = $csv_file_dir . '/' . $post_type . 'category_' . $nonce . '.csv';
|
3825
|
|
|
|
3826
|
|
|
$chunk_file_paths = array();
|
3827
|
|
|
|
3828
|
|
|
if ( isset( $_REQUEST['_st'] ) ) {
|
3829
|
|
|
$line_count = (int)geodir_import_export_line_count( $file_path_temp );
|
3830
|
|
|
$percentage = count( $terms_count ) > 0 && $line_count > 0 ? ceil( $line_count / $terms_count ) * 100 : 0;
|
3831
|
|
|
$percentage = min( $percentage, 100 );
|
3832
|
|
|
|
3833
|
|
|
$json['percentage'] = $percentage;
|
3834
|
|
|
// WPML
|
3835
|
|
|
if ($is_wpml) {
|
3836
|
|
|
$sitepress->switch_lang($active_lang, true);
|
3837
|
|
|
}
|
3838
|
|
|
// WPML
|
3839
|
|
|
wp_send_json( $json );
|
3840
|
|
|
} else {
|
3841
|
|
|
if ( !$terms_count > 0 ) {
|
3842
|
|
|
$json['error'] = __( 'No records to export.', 'geodirectory' );
|
3843
|
|
|
} else {
|
3844
|
|
|
$total_terms = $terms_count;
|
3845
|
|
|
if ($chunk_per_page > $terms_count) {
|
3846
|
|
|
$chunk_per_page = $terms_count;
|
3847
|
|
|
}
|
3848
|
|
|
$chunk_total_pages = ceil( $total_terms / $chunk_per_page );
|
3849
|
|
|
|
3850
|
|
|
$j = $chunk_page_no;
|
3851
|
|
|
$chunk_save_terms = geodir_imex_get_terms( $post_type, $chunk_per_page, $j );
|
3852
|
|
|
|
3853
|
|
|
$per_page = 500;
|
3854
|
|
|
if ($per_page > $chunk_per_page) {
|
3855
|
|
|
$per_page = $chunk_per_page;
|
3856
|
|
|
}
|
3857
|
|
|
$total_pages = ceil( $chunk_per_page / $per_page );
|
3858
|
|
|
|
3859
|
|
|
for ( $i = 0; $i <= $total_pages; $i++ ) {
|
3860
|
|
|
$save_terms = array_slice( $chunk_save_terms , ( $i * $per_page ), $per_page );
|
3861
|
|
|
|
3862
|
|
|
$clear = $i == 0 ? true : false;
|
3863
|
|
|
geodir_save_csv_data( $file_path_temp, $save_terms, $clear );
|
3864
|
|
|
}
|
3865
|
|
|
|
3866
|
|
|
if ( $wp_filesystem->exists( $file_path_temp ) ) {
|
|
|
|
|
3867
|
|
|
$chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
|
3868
|
|
|
$chunk_file_name = $file_name . $chunk_page_no . '.csv';
|
3869
|
|
|
$file_path = $csv_file_dir . '/' . $chunk_file_name;
|
3870
|
|
|
$wp_filesystem->move( $file_path_temp, $file_path, true );
|
|
|
|
|
3871
|
|
|
|
3872
|
|
|
$file_url = $file_url_base . $chunk_file_name;
|
3873
|
|
|
$chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
|
3874
|
|
|
}
|
3875
|
|
|
|
3876
|
|
|
if ( !empty($chunk_file_paths) ) {
|
3877
|
|
|
$json['total'] = $terms_count;
|
3878
|
|
|
$json['files'] = $chunk_file_paths;
|
3879
|
|
|
} else {
|
3880
|
|
|
$json['error'] = __( 'ERROR: Could not create csv file. This is usually due to inconsistent file permissions.', 'geodirectory' );
|
3881
|
|
|
}
|
3882
|
|
|
}
|
3883
|
|
|
// WPML
|
3884
|
|
|
if ($is_wpml) {
|
3885
|
|
|
$sitepress->switch_lang($active_lang, true);
|
3886
|
|
|
}
|
3887
|
|
|
// WPML
|
3888
|
|
|
wp_send_json( $json );
|
3889
|
|
|
}
|
3890
|
|
|
}
|
3891
|
|
|
break;
|
3892
|
|
View Code Duplication |
case 'export_locations': {
|
3893
|
|
|
$file_url_base = geodir_path_import_export() . '/';
|
3894
|
|
|
$file_name = 'gd_locations_' . date( 'dmyHi' );
|
3895
|
|
|
$file_url = $file_url_base . $file_name . '.csv';
|
|
|
|
|
3896
|
|
|
$file_path = $csv_file_dir . '/' . $file_name . '.csv';
|
|
|
|
|
3897
|
|
|
$file_path_temp = $csv_file_dir . '/gd_locations_' . $nonce . '.csv';
|
3898
|
|
|
|
3899
|
|
|
$items_count = (int)geodir_location_imex_count_locations();
|
3900
|
|
|
|
3901
|
|
|
if ( isset( $_REQUEST['_st'] ) ) {
|
3902
|
|
|
$line_count = (int)geodir_import_export_line_count( $file_path_temp );
|
3903
|
|
|
$percentage = count( $items_count ) > 0 && $line_count > 0 ? ceil( $line_count / $items_count ) * 100 : 0;
|
3904
|
|
|
$percentage = min( $percentage, 100 );
|
3905
|
|
|
|
3906
|
|
|
$json['percentage'] = $percentage;
|
3907
|
|
|
wp_send_json( $json );
|
3908
|
|
|
} else {
|
3909
|
|
|
$chunk_file_paths = array();
|
3910
|
|
|
|
3911
|
|
|
if ( !$items_count > 0 ) {
|
3912
|
|
|
$json['error'] = __( 'No records to export.', 'geodirectory' );
|
3913
|
|
|
} else {
|
3914
|
|
|
$chunk_per_page = min( $chunk_per_page, $items_count );
|
3915
|
|
|
$chunk_total_pages = ceil( $items_count / $chunk_per_page );
|
3916
|
|
|
|
3917
|
|
|
$j = $chunk_page_no;
|
3918
|
|
|
$chunk_save_items = geodir_location_imex_locations_data( $chunk_per_page, $j );
|
3919
|
|
|
|
3920
|
|
|
$per_page = 500;
|
3921
|
|
|
$per_page = min( $per_page, $chunk_per_page );
|
3922
|
|
|
$total_pages = ceil( $chunk_per_page / $per_page );
|
3923
|
|
|
|
3924
|
|
|
for ( $i = 0; $i <= $total_pages; $i++ ) {
|
3925
|
|
|
$save_items = array_slice( $chunk_save_items , ( $i * $per_page ), $per_page );
|
3926
|
|
|
|
3927
|
|
|
$clear = $i == 0 ? true : false;
|
3928
|
|
|
geodir_save_csv_data( $file_path_temp, $save_items, $clear );
|
3929
|
|
|
}
|
3930
|
|
|
|
3931
|
|
|
if ( $wp_filesystem->exists( $file_path_temp ) ) {
|
|
|
|
|
3932
|
|
|
$chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
|
3933
|
|
|
$chunk_file_name = $file_name . $chunk_page_no . '.csv';
|
3934
|
|
|
$file_path = $csv_file_dir . '/' . $chunk_file_name;
|
3935
|
|
|
$wp_filesystem->move( $file_path_temp, $file_path, true );
|
|
|
|
|
3936
|
|
|
|
3937
|
|
|
$file_url = $file_url_base . $chunk_file_name;
|
3938
|
|
|
$chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
|
3939
|
|
|
}
|
3940
|
|
|
|
3941
|
|
|
if ( !empty($chunk_file_paths) ) {
|
3942
|
|
|
$json['total'] = $items_count;
|
3943
|
|
|
$json['files'] = $chunk_file_paths;
|
3944
|
|
|
} else {
|
3945
|
|
|
$json['error'] = __( 'Fail, something wrong to create csv file.', 'geodirectory' );
|
3946
|
|
|
}
|
3947
|
|
|
}
|
3948
|
|
|
wp_send_json( $json );
|
3949
|
|
|
}
|
3950
|
|
|
}
|
3951
|
|
|
break;
|
3952
|
|
View Code Duplication |
case 'export_hoods': {
|
3953
|
|
|
$file_url_base = geodir_path_import_export() . '/';
|
3954
|
|
|
$file_name = 'gd_neighbourhoods_' . date( 'dmyHi' );
|
3955
|
|
|
$file_url = $file_url_base . $file_name . '.csv';
|
|
|
|
|
3956
|
|
|
$file_path = $csv_file_dir . '/' . $file_name . '.csv';
|
|
|
|
|
3957
|
|
|
$file_path_temp = $csv_file_dir . '/gd_neighbourhoods_' . $nonce . '.csv';
|
3958
|
|
|
|
3959
|
|
|
$items_count = (int)geodir_location_imex_count_neighbourhoods();
|
3960
|
|
|
|
3961
|
|
|
if ( isset( $_REQUEST['_st'] ) ) {
|
3962
|
|
|
$line_count = (int)geodir_import_export_line_count( $file_path_temp );
|
3963
|
|
|
$percentage = count( $items_count ) > 0 && $line_count > 0 ? ceil( $line_count / $items_count ) * 100 : 0;
|
3964
|
|
|
$percentage = min( $percentage, 100 );
|
3965
|
|
|
|
3966
|
|
|
$json['percentage'] = $percentage;
|
3967
|
|
|
wp_send_json( $json );
|
3968
|
|
|
} else {
|
3969
|
|
|
$chunk_file_paths = array();
|
3970
|
|
|
|
3971
|
|
|
if ( !$items_count > 0 ) {
|
3972
|
|
|
$json['error'] = __( 'No records to export.', 'geodirectory' );
|
3973
|
|
|
} else {
|
3974
|
|
|
$chunk_per_page = min( $chunk_per_page, $items_count );
|
3975
|
|
|
$chunk_total_pages = ceil( $items_count / $chunk_per_page );
|
3976
|
|
|
|
3977
|
|
|
$j = $chunk_page_no;
|
3978
|
|
|
$chunk_save_items = geodir_location_imex_neighbourhoods_data( $chunk_per_page, $j );
|
3979
|
|
|
|
3980
|
|
|
$per_page = 500;
|
3981
|
|
|
$per_page = min( $per_page, $chunk_per_page );
|
3982
|
|
|
$total_pages = ceil( $chunk_per_page / $per_page );
|
3983
|
|
|
|
3984
|
|
|
for ( $i = 0; $i <= $total_pages; $i++ ) {
|
3985
|
|
|
$save_items = array_slice( $chunk_save_items , ( $i * $per_page ), $per_page );
|
3986
|
|
|
|
3987
|
|
|
$clear = $i == 0 ? true : false;
|
3988
|
|
|
geodir_save_csv_data( $file_path_temp, $save_items, $clear );
|
3989
|
|
|
}
|
3990
|
|
|
|
3991
|
|
|
if ( $wp_filesystem->exists( $file_path_temp ) ) {
|
|
|
|
|
3992
|
|
|
$chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
|
3993
|
|
|
$chunk_file_name = $file_name . $chunk_page_no . '.csv';
|
3994
|
|
|
$file_path = $csv_file_dir . '/' . $chunk_file_name;
|
3995
|
|
|
$wp_filesystem->move( $file_path_temp, $file_path, true );
|
|
|
|
|
3996
|
|
|
|
3997
|
|
|
$file_url = $file_url_base . $chunk_file_name;
|
3998
|
|
|
$chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
|
3999
|
|
|
}
|
4000
|
|
|
|
4001
|
|
|
if ( !empty($chunk_file_paths) ) {
|
4002
|
|
|
$json['total'] = $items_count;
|
4003
|
|
|
$json['files'] = $chunk_file_paths;
|
4004
|
|
|
} else {
|
4005
|
|
|
$json['error'] = __( 'Fail, something wrong to create csv file.', 'geodirectory' );
|
4006
|
|
|
}
|
4007
|
|
|
}
|
4008
|
|
|
wp_send_json( $json );
|
4009
|
|
|
}
|
4010
|
|
|
}
|
4011
|
|
|
break;
|
4012
|
|
|
case 'prepare_import':
|
4013
|
|
|
case 'import_cat':
|
4014
|
|
|
case 'import_post':
|
4015
|
|
|
case 'import_loc':
|
4016
|
|
|
case 'import_hood': {
|
4017
|
|
|
// WPML
|
4018
|
|
|
$is_wpml = geodir_is_wpml();
|
4019
|
|
|
if ($is_wpml) {
|
4020
|
|
|
global $sitepress;
|
4021
|
|
|
$active_lang = ICL_LANGUAGE_CODE;
|
4022
|
|
|
}
|
4023
|
|
|
// WPML
|
4024
|
|
|
|
4025
|
|
|
ini_set( 'auto_detect_line_endings', true );
|
4026
|
|
|
|
4027
|
|
|
$uploads = wp_upload_dir();
|
4028
|
|
|
$uploads_dir = $uploads['path'];
|
4029
|
|
|
$uploads_subdir = $uploads['subdir'];
|
4030
|
|
|
|
4031
|
|
|
$csv_file = isset( $_POST['_file'] ) ? $_POST['_file'] : NULL;
|
4032
|
|
|
$import_choice = isset( $_REQUEST['_ch'] ) ? $_REQUEST['_ch'] : 'skip';
|
4033
|
|
|
|
4034
|
|
|
$csv_file_arr = explode( '/', $csv_file );
|
4035
|
|
|
$csv_filename = end( $csv_file_arr );
|
4036
|
|
|
$target_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $csv_filename;
|
4037
|
|
|
|
4038
|
|
|
$json['file'] = $csv_file;
|
4039
|
|
|
$json['error'] = __( 'The uploaded file is not a valid csv file. Please try again.', 'geodirectory' );
|
4040
|
|
|
$file = array();
|
4041
|
|
|
|
4042
|
|
|
if ( $csv_file && $wp_filesystem->is_file( $target_path ) && $wp_filesystem->exists( $target_path ) ) {
|
|
|
|
|
4043
|
|
|
$wp_filetype = wp_check_filetype_and_ext( $target_path, $csv_filename );
|
4044
|
|
|
|
4045
|
|
|
if (!empty($wp_filetype) && isset($wp_filetype['ext']) && geodir_strtolower($wp_filetype['ext']) == 'csv') {
|
4046
|
|
|
$json['error'] = NULL;
|
4047
|
|
|
$json['rows'] = 0;
|
4048
|
|
|
|
4049
|
|
|
$lc_all = setlocale(LC_ALL, 0); // Fix issue of fgetcsv ignores special characters when they are at the beginning of line
|
4050
|
|
|
setlocale(LC_ALL, 'en_US.UTF-8');
|
4051
|
|
|
if ( ( $handle = fopen($target_path, "r" ) ) !== FALSE ) {
|
4052
|
|
|
while ( ( $data = fgetcsv( $handle, 100000, "," ) ) !== FALSE ) {
|
4053
|
|
|
if ( !empty( $data ) ) {
|
4054
|
|
|
$file[] = $data;
|
4055
|
|
|
}
|
4056
|
|
|
}
|
4057
|
|
|
fclose($handle);
|
4058
|
|
|
}
|
4059
|
|
|
setlocale(LC_ALL, $lc_all);
|
4060
|
|
|
|
4061
|
|
|
$json['rows'] = (!empty($file) && count($file) > 1) ? count($file) - 1 : 0;
|
4062
|
|
|
|
4063
|
|
|
if (!$json['rows'] > 0) {
|
4064
|
|
|
$json['error'] = __('No data found in csv file.', 'geodirectory');
|
4065
|
|
|
}
|
4066
|
|
|
} else {
|
4067
|
|
|
wp_send_json( $json );
|
4068
|
|
|
}
|
4069
|
|
|
} else {
|
4070
|
|
|
wp_send_json( $json );
|
4071
|
|
|
}
|
4072
|
|
|
|
4073
|
|
|
if ( $task == 'prepare_import' || !empty( $json['error'] ) ) {
|
4074
|
|
|
wp_send_json( $json );
|
4075
|
|
|
}
|
4076
|
|
|
|
4077
|
|
|
$total = $json['rows'];
|
4078
|
|
|
$limit = isset($_POST['limit']) ? (int)$_POST['limit'] : 1;
|
4079
|
|
|
$processed = isset($_POST['processed']) ? (int)$_POST['processed'] : 0;
|
4080
|
|
|
|
4081
|
|
|
$count = $limit;
|
4082
|
|
|
|
4083
|
|
|
if ($count < $total) {
|
4084
|
|
|
$count = $processed + $count;
|
4085
|
|
|
if ($count > $total) {
|
4086
|
|
|
$count = $total;
|
|
|
|
|
4087
|
|
|
}
|
4088
|
|
|
} else {
|
4089
|
|
|
$count = $total;
|
|
|
|
|
4090
|
|
|
}
|
4091
|
|
|
|
4092
|
|
|
$created = 0;
|
4093
|
|
|
$updated = 0;
|
4094
|
|
|
$skipped = 0;
|
4095
|
|
|
$invalid = 0;
|
4096
|
|
|
$invalid_addr = 0;
|
4097
|
|
|
$images = 0;
|
4098
|
|
|
|
4099
|
|
|
$gd_post_info = array();
|
|
|
|
|
4100
|
|
|
$countpost = 0;
|
|
|
|
|
4101
|
|
|
|
4102
|
|
|
$post_types = geodir_get_posttypes();
|
4103
|
|
|
|
4104
|
|
|
if ( $task == 'import_cat' ) {
|
4105
|
|
|
if (!empty($file)) {
|
4106
|
|
|
$columns = isset($file[0]) ? $file[0] : NULL;
|
4107
|
|
|
|
4108
|
|
View Code Duplication |
if (empty($columns) || (!empty($columns) && $columns[0] == '')) {
|
4109
|
|
|
$json['error'] = CSV_INVAILD_FILE;
|
4110
|
|
|
wp_send_json( $json );
|
4111
|
|
|
exit;
|
4112
|
|
|
}
|
4113
|
|
|
|
4114
|
|
|
$gd_error_log = __('GD IMPORT CATEGORIES [ROW %d]:', 'geodirectory');
|
4115
|
|
|
|
4116
|
|
|
for ($i = 1; $i <= $limit; $i++) {
|
4117
|
|
|
$index = $processed + $i;
|
4118
|
|
|
|
4119
|
|
|
if (isset($file[$index])) {
|
4120
|
|
|
$row = $file[$index];
|
4121
|
|
|
$row = array_map( 'trim', $row );
|
4122
|
|
|
//$row = array_map( 'utf8_encode', $row );
|
|
|
|
|
4123
|
|
|
|
4124
|
|
|
$cat_id = '';
|
4125
|
|
|
$cat_name = '';
|
4126
|
|
|
$cat_slug = '';
|
4127
|
|
|
$cat_posttype = '';
|
4128
|
|
|
$cat_parent = '';
|
4129
|
|
|
$cat_description = '';
|
4130
|
|
|
$cat_schema = '';
|
4131
|
|
|
$cat_top_description = '';
|
4132
|
|
|
$cat_image = '';
|
4133
|
|
|
$cat_icon = '';
|
4134
|
|
|
$cat_language = '';
|
4135
|
|
|
$cat_id_original = '';
|
4136
|
|
|
|
4137
|
|
|
$c = 0;
|
4138
|
|
|
foreach ($columns as $column ) {
|
4139
|
|
|
if ( $column == 'cat_id' ) {
|
4140
|
|
|
$cat_id = (int)$row[$c];
|
4141
|
|
|
} else if ( $column == 'cat_name' ) {
|
4142
|
|
|
$cat_name = $row[$c];
|
4143
|
|
|
} else if ( $column == 'cat_slug' ) {
|
4144
|
|
|
$cat_slug = $row[$c];
|
4145
|
|
|
} else if ( $column == 'cat_posttype' ) {
|
4146
|
|
|
$cat_posttype = $row[$c];
|
4147
|
|
|
} else if ( $column == 'cat_parent' ) {
|
4148
|
|
|
$cat_parent = trim($row[$c]);
|
4149
|
|
|
} else if ( $column == 'cat_schema' && $row[$c] != '' ) {
|
4150
|
|
|
$cat_schema = $row[$c];
|
4151
|
|
|
} else if ( $column == 'cat_description' ) {
|
4152
|
|
|
$cat_description = $row[$c];
|
4153
|
|
|
} else if ( $column == 'cat_top_description' ) {
|
4154
|
|
|
$cat_top_description = $row[$c];
|
4155
|
|
|
} else if ( $column == 'cat_image' ) {
|
4156
|
|
|
$cat_image = $row[$c];
|
4157
|
|
|
} else if ( $column == 'cat_icon' ) {
|
4158
|
|
|
$cat_icon = $row[$c];
|
4159
|
|
|
}
|
4160
|
|
|
// WPML
|
4161
|
|
View Code Duplication |
if ( $is_wpml ) {
|
4162
|
|
|
if ( $column == 'cat_language' ) {
|
4163
|
|
|
$cat_language = geodir_strtolower( trim( $row[$c] ) );
|
4164
|
|
|
} else if ( $column == 'cat_id_original' ) {
|
4165
|
|
|
$cat_id_original = (int)$row[$c];
|
4166
|
|
|
}
|
4167
|
|
|
}
|
4168
|
|
|
// WPML
|
4169
|
|
|
$c++;
|
4170
|
|
|
}
|
4171
|
|
|
|
4172
|
|
|
if ( $cat_name == '' || !in_array( $cat_posttype, $post_types ) ) {
|
4173
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be added due to blank title/invalid post type', 'geodirectory' ) );
|
4174
|
|
|
|
4175
|
|
|
$invalid++;
|
4176
|
|
|
continue;
|
4177
|
|
|
}
|
4178
|
|
|
|
4179
|
|
|
// WPML
|
4180
|
|
|
if ($is_wpml && $cat_language != '') {
|
4181
|
|
|
$sitepress->switch_lang($cat_language, true);
|
4182
|
|
|
}
|
4183
|
|
|
// WPML
|
4184
|
|
|
|
4185
|
|
|
$term_data = array();
|
4186
|
|
|
$term_data['name'] = $cat_name;
|
4187
|
|
|
$term_data['slug'] = $cat_slug;
|
4188
|
|
|
$term_data['description'] = $cat_description;
|
4189
|
|
|
$term_data['cat_schema'] = $cat_schema;
|
4190
|
|
|
$term_data['top_description'] = $cat_top_description;
|
4191
|
|
|
$term_data['image'] = $cat_image != '' ? basename( $cat_image ) : '';
|
4192
|
|
|
$term_data['icon'] = $cat_icon != '' ? basename( $cat_icon ) : '';
|
4193
|
|
|
|
4194
|
|
|
//$term_data = array_map( 'utf8_encode', $term_data );
|
|
|
|
|
4195
|
|
|
|
4196
|
|
|
$taxonomy = $cat_posttype . 'category';
|
4197
|
|
|
|
4198
|
|
|
$term_data['taxonomy'] = $taxonomy;
|
4199
|
|
|
|
4200
|
|
|
$term_parent_id = 0;
|
4201
|
|
|
if ($cat_parent != "" || (int)$cat_parent > 0) {
|
4202
|
|
|
$term_parent = '';
|
|
|
|
|
4203
|
|
|
|
4204
|
|
|
if ( $term_parent = get_term_by( 'name', $cat_parent, $taxonomy ) ) {
|
4205
|
|
|
//
|
4206
|
|
|
} else if ( $term_parent = get_term_by( 'slug', $cat_parent, $taxonomy ) ) {
|
4207
|
|
|
//
|
4208
|
|
|
} else if ( $term_parent = get_term_by( 'id', $cat_parent, $taxonomy ) ) {
|
4209
|
|
|
//
|
4210
|
|
|
} else {
|
4211
|
|
|
$term_parent_data = array();
|
4212
|
|
|
$term_parent_data['name'] = $cat_parent;
|
4213
|
|
|
//$term_parent_data = array_map( 'utf8_encode', $term_parent_data );
|
|
|
|
|
4214
|
|
|
$term_parent_data['taxonomy'] = $taxonomy;
|
4215
|
|
|
|
4216
|
|
|
$term_parent_id = (int)geodir_imex_insert_term( $taxonomy, $term_parent_data );
|
4217
|
|
|
}
|
4218
|
|
|
|
4219
|
|
|
if ( !empty( $term_parent ) && !is_wp_error( $term_parent ) ) {
|
4220
|
|
|
$term_parent_id = (int)$term_parent->term_id;
|
4221
|
|
|
}
|
4222
|
|
|
}
|
4223
|
|
|
$term_data['parent'] = (int)$term_parent_id;
|
4224
|
|
|
|
4225
|
|
|
$term_id = NULL;
|
4226
|
|
|
if ( $import_choice == 'update' ) {
|
4227
|
|
|
if ( $cat_id > 0 && $term = (array)term_exists( $cat_id, $taxonomy ) ) {
|
4228
|
|
|
$term_data['term_id'] = $term['term_id'];
|
4229
|
|
|
|
4230
|
|
View Code Duplication |
if ( $term_id = geodir_imex_update_term( $taxonomy, $term_data ) ) {
|
4231
|
|
|
$updated++;
|
4232
|
|
|
} else {
|
4233
|
|
|
$invalid++;
|
4234
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be updated due to invalid data (check & remove if any invalid characters used in data)', 'geodirectory' ) );
|
4235
|
|
|
}
|
4236
|
|
|
} else if ( $term_data['slug'] != '' && $term = (array)term_exists( $term_data['slug'], $taxonomy ) ) {
|
4237
|
|
|
$term_data['term_id'] = $term['term_id'];
|
4238
|
|
|
|
4239
|
|
View Code Duplication |
if ( $term_id = geodir_imex_update_term( $taxonomy, $term_data ) ) {
|
4240
|
|
|
$updated++;
|
4241
|
|
|
} else {
|
4242
|
|
|
$invalid++;
|
4243
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be updated due to invalid data (check & remove if any invalid characters used in data)', 'geodirectory' ) );
|
4244
|
|
|
}
|
4245
|
|
View Code Duplication |
} else {
|
4246
|
|
|
if ( $term_id = geodir_imex_insert_term( $taxonomy, $term_data ) ) {
|
4247
|
|
|
$created++;
|
4248
|
|
|
} else {
|
4249
|
|
|
$invalid++;
|
4250
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be added due to invalid data (check & remove if any invalid characters used in data)', 'geodirectory' ) );
|
4251
|
|
|
}
|
4252
|
|
|
}
|
4253
|
|
|
} else if ( $import_choice == 'skip' ) {
|
4254
|
|
|
if ( $cat_id > 0 && $term = (array)term_exists( $cat_id, $taxonomy ) ) {
|
4255
|
|
|
$skipped++;
|
4256
|
|
|
} else if ( $term_data['slug'] != '' && $term = (array)term_exists( $term_data['slug'], $taxonomy ) ) {
|
4257
|
|
|
$skipped++;
|
4258
|
|
View Code Duplication |
} else {
|
4259
|
|
|
if ( $term_id = geodir_imex_insert_term( $taxonomy, $term_data ) ) {
|
4260
|
|
|
$created++;
|
4261
|
|
|
} else {
|
4262
|
|
|
$invalid++;
|
4263
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be updated due to invalid data (check & remove if any invalid characters used in data)', 'geodirectory' ) );
|
4264
|
|
|
}
|
4265
|
|
|
}
|
4266
|
|
|
} else {
|
4267
|
|
|
$invalid++;
|
4268
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be added due to invalid data (check & remove if any invalid characters used in data)', 'geodirectory' ) );
|
4269
|
|
|
}
|
4270
|
|
|
|
4271
|
|
|
if ( $term_id ) {
|
4272
|
|
|
// WPML
|
4273
|
|
View Code Duplication |
if ($is_wpml && $cat_id_original > 0 && $cat_language != '') {
|
4274
|
|
|
$wpml_element_type = 'tax_' . $taxonomy;
|
4275
|
|
|
$source_language = geodir_get_language_for_element( $cat_id_original, $wpml_element_type );
|
4276
|
|
|
$source_language = $source_language != '' ? $source_language : $sitepress->get_default_language();
|
4277
|
|
|
|
4278
|
|
|
$trid = $sitepress->get_element_trid( $cat_id_original, $wpml_element_type );
|
4279
|
|
|
|
4280
|
|
|
$sitepress->set_element_language_details( $term_id, $wpml_element_type, $trid, $cat_language, $source_language );
|
4281
|
|
|
}
|
4282
|
|
|
// WPML
|
4283
|
|
|
|
4284
|
|
|
if ( isset( $term_data['top_description'] ) ) {
|
4285
|
|
|
update_tax_meta( $term_id, 'ct_cat_top_desc', $term_data['top_description'], $cat_posttype );
|
4286
|
|
|
}
|
4287
|
|
|
|
4288
|
|
|
if ( isset( $term_data['cat_schema'] ) ) {
|
4289
|
|
|
update_tax_meta( $term_id, 'ct_cat_schema', $term_data['cat_schema'], $cat_posttype );
|
4290
|
|
|
}
|
4291
|
|
|
|
4292
|
|
|
$attachment = false;
|
4293
|
|
View Code Duplication |
if ( isset( $term_data['image'] ) && $term_data['image'] != '' ) {
|
4294
|
|
|
$cat_image = geodir_get_default_catimage( $term_id, $cat_posttype );
|
4295
|
|
|
$cat_image = !empty( $cat_image ) && isset( $cat_image['src'] ) ? $cat_image['src'] : '';
|
4296
|
|
|
|
4297
|
|
|
if ( basename($cat_image) != $term_data['image'] ) {
|
4298
|
|
|
$attachment = true;
|
4299
|
|
|
update_tax_meta( $term_id, 'ct_cat_default_img', array( 'id' => 'image', 'src' => $uploads['url'] . '/' . $term_data['image'] ), $cat_posttype );
|
4300
|
|
|
}
|
4301
|
|
|
}
|
4302
|
|
|
|
4303
|
|
View Code Duplication |
if ( isset( $term_data['icon'] ) && $term_data['icon'] != '' ) {
|
4304
|
|
|
$cat_icon = get_tax_meta( $term_id, 'ct_cat_icon', false, $cat_posttype );
|
4305
|
|
|
$cat_icon = !empty( $cat_icon ) && isset( $cat_icon['src'] ) ? $cat_icon['src'] : '';
|
4306
|
|
|
|
4307
|
|
|
if ( basename($cat_icon) != $term_data['icon'] ) {
|
4308
|
|
|
$attachment = true;
|
4309
|
|
|
update_tax_meta( $term_id, 'ct_cat_icon', array( 'id' => 'icon', 'src' => $uploads['url'] . '/' . $term_data['icon'] ), $cat_posttype );
|
4310
|
|
|
}
|
4311
|
|
|
}
|
4312
|
|
|
|
4313
|
|
|
if ( $attachment ) {
|
4314
|
|
|
$images++;
|
4315
|
|
|
}
|
4316
|
|
|
}
|
4317
|
|
|
|
4318
|
|
|
// WPML
|
4319
|
|
|
if ($is_wpml && $cat_language != '') {
|
4320
|
|
|
$sitepress->switch_lang($active_lang, true);
|
4321
|
|
|
}
|
4322
|
|
|
// WPML
|
4323
|
|
|
}
|
4324
|
|
|
}
|
4325
|
|
|
}
|
4326
|
|
|
|
4327
|
|
|
$json = array();
|
4328
|
|
|
$json['processed'] = $limit;
|
4329
|
|
|
$json['created'] = $created;
|
4330
|
|
|
$json['updated'] = $updated;
|
4331
|
|
|
$json['skipped'] = $skipped;
|
4332
|
|
|
$json['invalid'] = $invalid;
|
4333
|
|
|
$json['images'] = $images;
|
4334
|
|
|
|
4335
|
|
|
wp_send_json( $json );
|
4336
|
|
|
exit;
|
4337
|
|
|
} else if ( $task == 'import_post' ) {
|
4338
|
|
|
//run some stuff to make the import quicker
|
4339
|
|
|
wp_defer_term_counting( true );
|
4340
|
|
|
wp_defer_comment_counting( true );
|
4341
|
|
|
$wpdb->query( 'SET autocommit = 0;' );
|
4342
|
|
|
|
4343
|
|
|
//remove_all_actions('publish_post');
|
4344
|
|
|
//remove_all_actions('transition_post_status');
|
4345
|
|
|
//remove_all_actions('publish_future_post');
|
4346
|
|
|
|
4347
|
|
|
if (!empty($file)) {
|
4348
|
|
|
$is_claim_active = is_plugin_active( 'geodir_claim_listing/geodir_claim_listing.php' ) && get_option('geodir_claim_enable') === 'yes' ? true : false;
|
4349
|
|
|
$wp_post_statuses = get_post_statuses(); // All of the WordPress supported post statuses.
|
4350
|
|
|
$default_status = 'publish';
|
4351
|
|
|
$current_date = date_i18n( 'Y-m-d', time() );
|
4352
|
|
|
|
4353
|
|
|
$columns = isset($file[0]) ? $file[0] : NULL;
|
4354
|
|
|
|
4355
|
|
View Code Duplication |
if (empty($columns) || (!empty($columns) && $columns[0] == '')) {
|
4356
|
|
|
$json['error'] = CSV_INVAILD_FILE;
|
4357
|
|
|
wp_send_json( $json );
|
4358
|
|
|
exit;
|
4359
|
|
|
}
|
4360
|
|
|
|
4361
|
|
|
$gd_error_log = __('GD IMPORT LISTINGS [ROW %d]:', 'geodirectory');
|
4362
|
|
|
$wp_chars_error = __( '(check & remove if any invalid characters used in data)', 'geodirectory' );
|
4363
|
|
|
$processed_actual = 0;
|
4364
|
|
|
for ($i = 1; $i <= $limit; $i++) {
|
4365
|
|
|
$index = $processed + $i;
|
4366
|
|
|
$gd_post = array();
|
4367
|
|
|
|
4368
|
|
|
if (isset($file[$index])) {
|
4369
|
|
|
$processed_actual++;
|
4370
|
|
|
$row = $file[$index];
|
4371
|
|
|
$row = array_map( 'trim', $row );
|
4372
|
|
|
//$row = array_map( 'utf8_encode', $row );
|
|
|
|
|
4373
|
|
|
$row = array_map( 'addslashes_gpc', $row );
|
4374
|
|
|
|
4375
|
|
|
$post_id = '';
|
4376
|
|
|
$post_title = '';
|
4377
|
|
|
$post_author = '';
|
4378
|
|
|
$post_content = '';
|
4379
|
|
|
$post_category_arr = array();
|
4380
|
|
|
$default_category = '';
|
4381
|
|
|
$post_tags = array();
|
4382
|
|
|
$post_type = '';
|
4383
|
|
|
$post_status = '';
|
4384
|
|
|
$geodir_video = '';
|
|
|
|
|
4385
|
|
|
$post_address = '';
|
4386
|
|
|
$post_city = '';
|
4387
|
|
|
$post_region = '';
|
4388
|
|
|
$post_country = '';
|
4389
|
|
|
$post_zip = '';
|
|
|
|
|
4390
|
|
|
$post_latitude = '';
|
4391
|
|
|
$post_longitude = '';
|
4392
|
|
|
$post_neighbourhood = '';
|
4393
|
|
|
$neighbourhood_latitude = '';
|
4394
|
|
|
$neighbourhood_longitude = '';
|
4395
|
|
|
$geodir_timing = '';
|
|
|
|
|
4396
|
|
|
$geodir_contact = '';
|
|
|
|
|
4397
|
|
|
$geodir_email = '';
|
|
|
|
|
4398
|
|
|
$geodir_website = '';
|
|
|
|
|
4399
|
|
|
$geodir_twitter = '';
|
|
|
|
|
4400
|
|
|
$geodir_facebook = '';
|
|
|
|
|
4401
|
|
|
$geodir_twitter = '';
|
|
|
|
|
4402
|
|
|
$post_images = array();
|
4403
|
|
|
|
4404
|
|
|
$expire_date = 'Never';
|
4405
|
|
|
|
4406
|
|
|
$language = '';
|
4407
|
|
|
$original_post_id = '';
|
4408
|
|
|
|
4409
|
|
|
$c = 0;
|
4410
|
|
|
foreach ($columns as $column ) {
|
4411
|
|
|
$gd_post[$column] = $row[$c];
|
4412
|
|
|
|
4413
|
|
|
if ( $column == 'post_id' ) {
|
4414
|
|
|
$post_id = $row[$c];
|
4415
|
|
|
} else if ( $column == 'post_title' ) {
|
4416
|
|
|
$post_title = sanitize_text_field($row[$c]);
|
4417
|
|
|
} else if ( $column == 'post_author' ) {
|
4418
|
|
|
$post_author = $row[$c];
|
4419
|
|
|
} else if ( $column == 'post_content' ) {
|
4420
|
|
|
$post_content = $row[$c];
|
4421
|
|
|
} else if ( $column == 'post_category' && $row[$c] != '' ) {
|
4422
|
|
|
$post_category_arr = explode( ',', $row[$c] );
|
4423
|
|
|
} else if ( $column == 'default_category' ) {
|
4424
|
|
|
$default_category = wp_kses_normalize_entities($row[$c]);
|
4425
|
|
|
} else if ( $column == 'post_tags' && $row[$c] != '' ) {
|
4426
|
|
|
$post_tags = explode( ',', sanitize_text_field($row[$c]) );
|
4427
|
|
|
} else if ( $column == 'post_type' ) {
|
4428
|
|
|
$post_type = $row[$c];
|
4429
|
|
|
} else if ( $column == 'post_status' ) {
|
4430
|
|
|
$post_status = sanitize_key( $row[$c] );
|
4431
|
|
|
} else if ( $column == 'is_featured' ) {
|
4432
|
|
|
$is_featured = (int)$row[$c];
|
4433
|
|
|
} else if ( $column == 'geodir_video' ) {
|
4434
|
|
|
$geodir_video = $row[$c];
|
|
|
|
|
4435
|
|
|
} else if ( $column == 'post_address' ) {
|
4436
|
|
|
$post_address = sanitize_text_field($row[$c]);
|
4437
|
|
|
} else if ( $column == 'post_city' ) {
|
4438
|
|
|
$post_city = sanitize_text_field($row[$c]);
|
4439
|
|
|
} else if ( $column == 'post_region' ) {
|
4440
|
|
|
$post_region = sanitize_text_field($row[$c]);
|
4441
|
|
|
} else if ( $column == 'post_country' ) {
|
4442
|
|
|
$post_country = sanitize_text_field($row[$c]);
|
4443
|
|
|
} else if ( $column == 'post_zip' ) {
|
4444
|
|
|
$post_zip = sanitize_text_field($row[$c]);
|
|
|
|
|
4445
|
|
|
} else if ( $column == 'post_latitude' ) {
|
4446
|
|
|
$post_latitude = sanitize_text_field($row[$c]);
|
4447
|
|
|
} else if ( $column == 'post_longitude' ) {
|
4448
|
|
|
$post_longitude = sanitize_text_field($row[$c]);
|
4449
|
|
|
} else if ( $column == 'post_neighbourhood' ) {
|
4450
|
|
|
$post_neighbourhood = sanitize_text_field($row[$c]);
|
4451
|
|
|
unset($gd_post[$column]);
|
4452
|
|
|
} else if ( $column == 'neighbourhood_latitude' ) {
|
4453
|
|
|
$neighbourhood_latitude = sanitize_text_field($row[$c]);
|
4454
|
|
|
} else if ( $column == 'neighbourhood_longitude' ) {
|
4455
|
|
|
$neighbourhood_longitude = sanitize_text_field($row[$c]);
|
4456
|
|
|
} else if ( $column == 'geodir_timing' ) {
|
4457
|
|
|
$geodir_timing = sanitize_text_field($row[$c]);
|
|
|
|
|
4458
|
|
|
} else if ( $column == 'geodir_contact' ) {
|
4459
|
|
|
$geodir_contact = sanitize_text_field($row[$c]);
|
|
|
|
|
4460
|
|
|
} else if ( $column == 'geodir_email' ) {
|
4461
|
|
|
$geodir_email = sanitize_email($row[$c]);
|
|
|
|
|
4462
|
|
|
} else if ( $column == 'geodir_website' ) {
|
4463
|
|
|
$geodir_website = sanitize_text_field($row[$c]);
|
|
|
|
|
4464
|
|
|
} else if ( $column == 'geodir_twitter' ) {
|
4465
|
|
|
$geodir_twitter = sanitize_text_field($row[$c]);
|
|
|
|
|
4466
|
|
|
} else if ( $column == 'geodir_facebook' ) {
|
4467
|
|
|
$geodir_facebook = sanitize_text_field($row[$c]);
|
|
|
|
|
4468
|
|
|
} else if ( $column == 'IMAGE' && !empty( $row[$c] ) && $row[$c] != '' ) {
|
4469
|
|
|
$post_images[] = $row[$c];
|
4470
|
|
|
} else if ( $column == 'alive_days' && (int)$row[$c] > 0 ) {
|
4471
|
|
|
$expire_date = date_i18n( 'Y-m-d', strtotime( $current_date . '+' . (int)$row[$c] . ' days' ) );
|
4472
|
|
|
} else if ( $column == 'expire_date' && $row[$c] != '' && geodir_strtolower($row[$c]) != 'never' ) {
|
4473
|
|
|
$row[$c] = str_replace('/', '-', $row[$c]);
|
4474
|
|
|
$expire_date = date_i18n( 'Y-m-d', strtotime( $row[$c] ) );
|
4475
|
|
|
}
|
4476
|
|
|
// WPML
|
4477
|
|
|
if ($is_wpml) {
|
4478
|
|
View Code Duplication |
if ($column == 'language') {
|
4479
|
|
|
$language = geodir_strtolower(trim($row[$c]));
|
4480
|
|
|
} else if ($column == 'original_post_id') {
|
4481
|
|
|
$original_post_id = (int)$row[$c];
|
4482
|
|
|
}
|
4483
|
|
|
}
|
4484
|
|
|
// WPML
|
4485
|
|
|
$c++;
|
4486
|
|
|
}
|
4487
|
|
|
// listing claimed or not
|
4488
|
|
|
if ($is_claim_active && isset($gd_post['claimed'])) {
|
4489
|
|
|
$gd_post['claimed'] = (int)$gd_post['claimed'] == 1 ? 1 : 0;
|
4490
|
|
|
}
|
4491
|
|
|
|
4492
|
|
|
// WPML
|
4493
|
|
|
if ($is_wpml && $language != '') {
|
4494
|
|
|
$sitepress->switch_lang($language, true);
|
4495
|
|
|
}
|
4496
|
|
|
// WPML
|
4497
|
|
|
|
4498
|
|
|
$gd_post['IMAGE'] = $post_images;
|
4499
|
|
|
|
4500
|
|
|
$post_status = !empty( $post_status ) ? sanitize_key( $post_status ) : $default_status;
|
4501
|
|
|
$post_status = !empty( $wp_post_statuses ) && !isset( $wp_post_statuses[$post_status] ) ? $default_status : $post_status;
|
4502
|
|
|
|
4503
|
|
|
$valid = true;
|
4504
|
|
|
|
4505
|
|
|
if ( $post_title == '' || !in_array( $post_type, $post_types ) ) {
|
4506
|
|
|
$invalid++;
|
4507
|
|
|
$valid = false;
|
4508
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be added due to blank title/invalid post type', 'geodirectory' ) );
|
4509
|
|
|
}
|
4510
|
|
|
|
4511
|
|
|
$location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true;
|
4512
|
|
|
if ( $location_allowed ) {
|
4513
|
|
|
$location_result = geodir_get_default_location();
|
4514
|
|
|
if ( $post_address == '' || $post_city == '' || $post_region == '' || $post_country == '' || $post_latitude == '' || $post_longitude == '' ) {
|
4515
|
|
|
$invalid_addr++;
|
4516
|
|
|
$valid = false;
|
4517
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be added due to blank/invalid address(city, region, country, latitude, longitude).', 'geodirectory' ) );
|
4518
|
|
|
} else if ( !empty( $location_result ) && $location_result->location_id == 0 ) {
|
4519
|
|
|
if ( ( geodir_strtolower( $post_city ) != geodir_strtolower( $location_result->city ) ) || ( geodir_strtolower( $post_region ) != geodir_strtolower( $location_result->region ) ) || (geodir_strtolower( $post_country ) != geodir_strtolower( $location_result->country ) ) ) {
|
4520
|
|
|
$invalid_addr++;
|
4521
|
|
|
$valid = false;
|
4522
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . __( 'Could not be added due to blank/invalid address(city, region, country, latitude, longitude).', 'geodirectory' ) );
|
4523
|
|
|
} else {
|
4524
|
|
|
if (!$location_manager) {
|
4525
|
|
|
$gd_post['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']'; // Set the default location when location manager not activated.
|
4526
|
|
|
}
|
4527
|
|
|
}
|
4528
|
|
|
}
|
4529
|
|
|
}
|
4530
|
|
|
|
4531
|
|
|
if ( !$valid ) {
|
4532
|
|
|
continue;
|
4533
|
|
|
}
|
4534
|
|
|
|
4535
|
|
|
$cat_taxonomy = $post_type . 'category';
|
4536
|
|
|
$tags_taxonomy = $post_type . '_tags';
|
4537
|
|
|
|
4538
|
|
|
if ($default_category != '' && !in_array($default_category, $post_category_arr)) {
|
4539
|
|
|
$post_category_arr = array_merge(array($default_category), $post_category_arr);
|
4540
|
|
|
}
|
4541
|
|
|
|
4542
|
|
|
$post_category = array();
|
4543
|
|
|
$default_category_id = NULL;
|
4544
|
|
|
if ( !empty( $post_category_arr ) ) {
|
4545
|
|
|
foreach ( $post_category_arr as $value ) {
|
4546
|
|
|
$category_name = wp_kses_normalize_entities( trim( $value ) );
|
4547
|
|
|
|
4548
|
|
|
if ( $category_name != '' ) {
|
4549
|
|
|
$term_category = array();
|
4550
|
|
|
|
4551
|
|
|
if ( $term = get_term_by( 'name', $category_name, $cat_taxonomy ) ) {
|
4552
|
|
|
$term_category = $term;
|
4553
|
|
|
} else if ( $term = get_term_by( 'slug', $category_name, $cat_taxonomy ) ) {
|
4554
|
|
|
$term_category = $term;
|
4555
|
|
|
} else {
|
4556
|
|
|
$term_data = array();
|
4557
|
|
|
$term_data['name'] = $category_name;
|
4558
|
|
|
$term_data['taxonomy'] = $cat_taxonomy;
|
4559
|
|
|
|
4560
|
|
|
$term_id = geodir_imex_insert_term( $cat_taxonomy, $term_data );
|
4561
|
|
|
if ( $term_id ) {
|
4562
|
|
|
$term_category = get_term( $term_id, $cat_taxonomy );
|
4563
|
|
|
}
|
4564
|
|
|
}
|
4565
|
|
|
|
4566
|
|
|
if ( !empty( $term_category ) && !is_wp_error( $term_category ) ) {
|
4567
|
|
|
$post_category[] = intval($term_category->term_id);
|
4568
|
|
|
|
4569
|
|
|
if ($category_name == $default_category) {
|
4570
|
|
|
$default_category_id = intval($term_category->term_id);
|
4571
|
|
|
}
|
4572
|
|
|
}
|
4573
|
|
|
}
|
4574
|
|
|
}
|
4575
|
|
|
}
|
4576
|
|
|
|
4577
|
|
|
$save_post = array();
|
4578
|
|
|
$save_post['post_title'] = $post_title;
|
4579
|
|
|
$save_post['post_content'] = $post_content;
|
4580
|
|
|
$save_post['post_type'] = $post_type;
|
4581
|
|
|
$save_post['post_author'] = $post_author;
|
4582
|
|
|
$save_post['post_status'] = $post_status;
|
4583
|
|
|
$save_post['post_category'] = $post_category;
|
4584
|
|
|
$save_post['post_tags'] = $post_tags;
|
4585
|
|
|
|
4586
|
|
|
$saved_post_id = NULL;
|
4587
|
|
|
if ( $import_choice == 'update' ) {
|
4588
|
|
|
$gd_wp_error = __( 'Unable to add listing, please check the listing data.', 'geodirectory' );
|
4589
|
|
|
|
4590
|
|
|
if ( $post_id > 0 && get_post( $post_id ) ) {
|
4591
|
|
|
$save_post['ID'] = $post_id;
|
4592
|
|
|
|
4593
|
|
View Code Duplication |
if ( $saved_post_id = wp_update_post( $save_post, true ) ) {
|
4594
|
|
|
if ( is_wp_error( $saved_post_id ) ) {
|
4595
|
|
|
$gd_wp_error = $saved_post_id->get_error_message() . ' ' . $wp_chars_error;
|
4596
|
|
|
$saved_post_id = 0;
|
4597
|
|
|
} else {
|
4598
|
|
|
$saved_post_id = $post_id;
|
4599
|
|
|
$updated++;
|
4600
|
|
|
}
|
4601
|
|
|
}
|
4602
|
|
View Code Duplication |
} else {
|
4603
|
|
|
if ( $saved_post_id = wp_insert_post( $save_post, true ) ) {
|
4604
|
|
|
if ( is_wp_error( $saved_post_id ) ) {
|
4605
|
|
|
$gd_wp_error = $saved_post_id->get_error_message() . ' ' . $wp_chars_error;
|
4606
|
|
|
$saved_post_id = 0;
|
4607
|
|
|
} else {
|
4608
|
|
|
$created++;
|
4609
|
|
|
}
|
4610
|
|
|
}
|
4611
|
|
|
}
|
4612
|
|
|
|
4613
|
|
|
if ( !$saved_post_id > 0 ) {
|
4614
|
|
|
$invalid++;
|
4615
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_wp_error );
|
4616
|
|
|
}
|
4617
|
|
|
} else if ( $import_choice == 'skip' ) {
|
4618
|
|
|
if ( $post_id > 0 && get_post( $post_id ) ) {
|
4619
|
|
|
$skipped++;
|
4620
|
|
|
} else {
|
4621
|
|
|
if ( $saved_post_id = wp_insert_post( $save_post, true ) ) {
|
4622
|
|
|
if ( is_wp_error( $saved_post_id ) ) {
|
4623
|
|
|
$invalid++;
|
4624
|
|
|
|
4625
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $saved_post_id->get_error_message() . ' ' . $wp_chars_error );
|
4626
|
|
|
$saved_post_id = 0;
|
4627
|
|
|
} else {
|
4628
|
|
|
$created++;
|
4629
|
|
|
}
|
4630
|
|
|
} else {
|
4631
|
|
|
$invalid++;
|
4632
|
|
|
|
4633
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $wp_chars_error );
|
4634
|
|
|
}
|
4635
|
|
|
}
|
4636
|
|
|
} else {
|
4637
|
|
|
$invalid++;
|
4638
|
|
|
|
4639
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $wp_chars_error );
|
4640
|
|
|
}
|
4641
|
|
|
|
4642
|
|
|
if ( (int)$saved_post_id > 0 ) {
|
4643
|
|
|
// WPML
|
4644
|
|
View Code Duplication |
if ($is_wpml && $original_post_id > 0 && $language != '') {
|
4645
|
|
|
$wpml_post_type = 'post_' . $post_type;
|
4646
|
|
|
$source_language = geodir_get_language_for_element( $original_post_id, $wpml_post_type );
|
4647
|
|
|
$source_language = $source_language != '' ? $source_language : $sitepress->get_default_language();
|
4648
|
|
|
|
4649
|
|
|
$trid = $sitepress->get_element_trid( $original_post_id, $wpml_post_type );
|
4650
|
|
|
|
4651
|
|
|
$sitepress->set_element_language_details( $saved_post_id, $wpml_post_type, $trid, $language, $source_language );
|
4652
|
|
|
}
|
4653
|
|
|
// WPML
|
4654
|
|
|
$gd_post_info = geodir_get_post_info( $saved_post_id );
|
4655
|
|
|
|
4656
|
|
|
$gd_post['post_id'] = $saved_post_id;
|
4657
|
|
|
$gd_post['ID'] = $saved_post_id;
|
4658
|
|
|
$gd_post['post_tags'] = $post_tags;
|
4659
|
|
|
$gd_post['post_title'] = $post_title;
|
4660
|
|
|
$gd_post['post_status'] = $post_status;
|
4661
|
|
|
$gd_post['submit_time'] = time();
|
4662
|
|
|
$gd_post['submit_ip'] = $_SERVER['REMOTE_ADDR'];
|
4663
|
|
|
|
4664
|
|
|
// post location
|
4665
|
|
|
$post_location_id = 0;
|
4666
|
|
|
if ( $location_allowed && !empty( $location_result ) && $location_result->location_id > 0 ) {
|
4667
|
|
|
$gd_post['post_neighbourhood'] = '';
|
4668
|
|
|
|
4669
|
|
|
$post_location_info = array(
|
4670
|
|
|
'city' => $post_city,
|
4671
|
|
|
'region' => $post_region,
|
4672
|
|
|
'country' => $post_country,
|
4673
|
|
|
'geo_lat' => $post_latitude,
|
4674
|
|
|
'geo_lng' => $post_longitude
|
4675
|
|
|
);
|
4676
|
|
|
if ( $location_id = (int)geodir_add_new_location( $post_location_info ) ) {
|
4677
|
|
|
$post_location_id = $location_id;
|
4678
|
|
|
}
|
4679
|
|
|
|
4680
|
|
|
if ($post_location_id > 0 && $neighbourhood_active && !empty($post_neighbourhood)) {
|
4681
|
|
|
$neighbourhood_info = geodir_location_neighbourhood_by_name_loc_id($post_neighbourhood, $post_location_id);
|
4682
|
|
|
|
4683
|
|
|
$hood_data = array();
|
4684
|
|
|
$hood_data['hood_location_id'] = $post_location_id;
|
4685
|
|
|
$hood_data['hood_name'] = $post_neighbourhood;
|
4686
|
|
|
|
4687
|
|
|
if (!empty($neighbourhood_info)) {
|
4688
|
|
|
$hood_data['hood_id'] = $neighbourhood_info->hood_id;
|
4689
|
|
|
$hood_data['hood_slug'] = $neighbourhood_info->hood_slug;
|
4690
|
|
|
|
4691
|
|
|
if (empty($neighbourhood_latitude) || empty($neighbourhood_longitude)) {
|
4692
|
|
|
$neighbourhood_latitude = $neighbourhood_info->hood_latitude;
|
4693
|
|
|
$neighbourhood_longitude = $neighbourhood_info->hood_longitude;
|
4694
|
|
|
}
|
4695
|
|
|
}
|
4696
|
|
|
|
4697
|
|
|
if (empty($neighbourhood_latitude) || empty($neighbourhood_longitude)) {
|
4698
|
|
|
$neighbourhood_latitude = $neighbourhood_info->hood_latitude;
|
|
|
|
|
4699
|
|
|
$neighbourhood_longitude = $neighbourhood_info->hood_longitude;
|
|
|
|
|
4700
|
|
|
}
|
4701
|
|
|
|
4702
|
|
|
$hood_data['hood_latitude'] = $post_latitude;
|
4703
|
|
|
$hood_data['hood_longitude'] = $post_longitude;
|
4704
|
|
|
|
4705
|
|
|
$neighbourhood_info = geodir_location_insert_update_neighbourhood($hood_data);
|
4706
|
|
|
if (!empty($neighbourhood_info) && isset($neighbourhood_info->hood_slug)) {
|
4707
|
|
|
$gd_post['post_neighbourhood'] = $neighbourhood_info->hood_slug;
|
4708
|
|
|
}
|
4709
|
|
|
}
|
4710
|
|
|
}
|
4711
|
|
|
$gd_post['post_location_id'] = $post_location_id;
|
4712
|
|
|
|
4713
|
|
|
// post package info
|
4714
|
|
|
$package_id = isset( $gd_post['package_id'] ) && !empty( $gd_post['package_id'] ) ? (int)$gd_post['package_id'] : 0;
|
4715
|
|
|
if (!$package_id && !empty($gd_post_info) && isset($gd_post_info->package_id) && $gd_post_info->package_id) {
|
4716
|
|
|
$package_id = $gd_post_info->package_id;
|
4717
|
|
|
}
|
4718
|
|
|
|
4719
|
|
|
$package_info = array();
|
4720
|
|
|
if ($package_id && function_exists('geodir_get_package_info_by_id')) {
|
4721
|
|
|
$package_info = (array)geodir_get_package_info_by_id($package_id);
|
4722
|
|
|
|
4723
|
|
|
if (!(!empty($package_info) && isset($package_info['post_type']) && $package_info['post_type'] == $post_type)) {
|
4724
|
|
|
$package_info = array();
|
4725
|
|
|
}
|
4726
|
|
|
}
|
4727
|
|
|
|
4728
|
|
|
if (empty($package_info)) {
|
4729
|
|
|
$package_info = (array)geodir_post_package_info( array(), '', $post_type );
|
4730
|
|
|
}
|
4731
|
|
|
|
4732
|
|
|
if (!empty($package_info)) {
|
4733
|
|
|
$package_id = $package_info['pid'];
|
4734
|
|
|
|
4735
|
|
|
if (isset($gd_post['alive_days']) || isset($gd_post['expire_date'])) {
|
4736
|
|
|
$gd_post['expire_date'] = $expire_date;
|
4737
|
|
|
} else {
|
4738
|
|
|
if ( isset( $package_info['days'] ) && (int)$package_info['days'] > 0 ) {
|
4739
|
|
|
$gd_post['alive_days'] = (int)$package_info['days'];
|
4740
|
|
|
$gd_post['expire_date'] = date_i18n( 'Y-m-d', strtotime( $current_date . '+' . (int)$package_info['days'] . ' days' ) );
|
4741
|
|
|
} else {
|
4742
|
|
|
$gd_post['expire_date'] = 'Never';
|
4743
|
|
|
}
|
4744
|
|
|
}
|
4745
|
|
|
|
4746
|
|
|
$gd_post['package_id'] = $package_id;
|
4747
|
|
|
}
|
4748
|
|
|
|
4749
|
|
|
$table = $plugin_prefix . $post_type . '_detail';
|
|
|
|
|
4750
|
|
|
|
4751
|
|
|
if ($post_type == 'gd_event') {
|
4752
|
|
|
$gd_post = geodir_imex_process_event_data($gd_post);
|
4753
|
|
|
}
|
4754
|
|
|
|
4755
|
|
|
if (isset($gd_post['post_id'])) {
|
4756
|
|
|
unset($gd_post['post_id']);
|
4757
|
|
|
}
|
4758
|
|
|
|
4759
|
|
|
// Export franchise fields
|
4760
|
|
|
$is_franchise_active = is_plugin_active( 'geodir_franchise/geodir_franchise.php' ) && geodir_franchise_enabled( $post_type ) ? true : false;
|
4761
|
|
|
if ($is_franchise_active) {
|
4762
|
|
|
if ( isset( $gd_post['gd_is_franchise'] ) && (int)$gd_post['gd_is_franchise'] == 1 ) {
|
4763
|
|
|
$gd_franchise_lock = array();
|
4764
|
|
|
|
4765
|
|
|
if ( isset( $gd_post['gd_franchise_lock'] ) ) {
|
4766
|
|
|
$gd_franchise_lock = str_replace(" ", "", $gd_post['gd_franchise_lock'] );
|
4767
|
|
|
$gd_franchise_lock = trim( $gd_franchise_lock );
|
4768
|
|
|
$gd_franchise_lock = explode( ",", $gd_franchise_lock );
|
4769
|
|
|
}
|
4770
|
|
|
|
4771
|
|
|
update_post_meta( $saved_post_id, 'gd_is_franchise', 1 );
|
4772
|
|
|
update_post_meta( $saved_post_id, 'gd_franchise_lock', $gd_franchise_lock );
|
4773
|
|
|
} else {
|
4774
|
|
|
if ( isset( $gd_post['franchise'] ) && (int)$gd_post['franchise'] > 0 && geodir_franchise_check( (int)$gd_post['franchise'] ) ) {
|
4775
|
|
|
geodir_save_post_meta( $saved_post_id, 'franchise', (int)$gd_post['franchise'] );
|
4776
|
|
|
}
|
4777
|
|
|
}
|
4778
|
|
|
}
|
4779
|
|
|
|
4780
|
|
|
if (!empty($save_post['post_category']) && is_array($save_post['post_category'])) {
|
4781
|
|
|
$save_post['post_category'] = array_unique( array_map( 'intval', $save_post['post_category'] ) );
|
4782
|
|
|
if ($default_category_id) {
|
|
|
|
|
4783
|
|
|
$save_post['post_default_category'] = $default_category_id;
|
4784
|
|
|
$gd_post['default_category'] = $default_category_id;
|
4785
|
|
|
}
|
4786
|
|
|
$gd_post[$cat_taxonomy] = $save_post['post_category'];
|
4787
|
|
|
}
|
4788
|
|
|
|
4789
|
|
|
// Save post info
|
4790
|
|
|
geodir_save_post_info( $saved_post_id, $gd_post );
|
4791
|
|
|
// post taxonomies
|
4792
|
|
|
if ( !empty( $save_post['post_category'] ) ) {
|
4793
|
|
|
wp_set_object_terms( $saved_post_id, $save_post['post_category'], $cat_taxonomy );
|
4794
|
|
|
|
4795
|
|
|
$post_default_category = isset( $save_post['post_default_category'] ) ? $save_post['post_default_category'] : '';
|
4796
|
|
|
if ($default_category_id) {
|
|
|
|
|
4797
|
|
|
$post_default_category = $default_category_id;
|
4798
|
|
|
}
|
4799
|
|
|
$post_cat_ids = geodir_get_post_meta($saved_post_id, $cat_taxonomy);
|
4800
|
|
|
$save_post['post_category'] = !empty($post_cat_ids) ? explode(",", trim($post_cat_ids, ",")) : $save_post['post_category'];
|
4801
|
|
|
$post_category_str = !empty($save_post['post_category']) ? implode(",y:#", $save_post['post_category']) . ',y:' : '';
|
4802
|
|
|
|
4803
|
|
|
if ($post_category_str != '' && $post_default_category) {
|
4804
|
|
|
$post_category_str = str_replace($post_default_category . ',y:', $post_default_category . ',y,d:', $post_category_str);
|
4805
|
|
|
}
|
4806
|
|
|
|
4807
|
|
|
$post_category_str = $post_category_str != '' ? array($cat_taxonomy => $post_category_str) : '';
|
4808
|
|
|
|
4809
|
|
|
geodir_set_postcat_structure( $saved_post_id, $cat_taxonomy, $post_default_category, $post_category_str );
|
4810
|
|
|
}
|
4811
|
|
|
|
4812
|
|
|
if ( !empty( $save_post['post_tags'] ) ) {
|
4813
|
|
|
wp_set_object_terms( $saved_post_id, $save_post['post_tags'], $tags_taxonomy );
|
4814
|
|
|
}
|
4815
|
|
|
|
4816
|
|
|
// Post images
|
4817
|
|
|
if ( !empty( $post_images ) ) {
|
4818
|
|
|
$post_images = array_unique($post_images);
|
4819
|
|
|
|
4820
|
|
|
$old_post_images_arr = array();
|
4821
|
|
|
$saved_post_images_arr = array();
|
4822
|
|
|
|
4823
|
|
|
$order = 1;
|
4824
|
|
|
|
4825
|
|
|
$old_post_images = geodir_get_images( $saved_post_id );
|
4826
|
|
|
if (!empty($old_post_images)) {
|
4827
|
|
|
foreach( $old_post_images as $old_post_image ) {
|
|
|
|
|
4828
|
|
|
if (!empty($old_post_image) && isset($old_post_image->file) && $old_post_image->file != '') {
|
4829
|
|
|
$old_post_images_arr[] = $old_post_image->file;
|
4830
|
|
|
}
|
4831
|
|
|
}
|
4832
|
|
|
}
|
4833
|
|
|
|
4834
|
|
|
foreach ( $post_images as $post_image ) {
|
4835
|
|
|
$image_name = basename( $post_image );
|
4836
|
|
|
$saved_post_images_arr[] = $image_name;
|
4837
|
|
|
|
4838
|
|
|
if (!empty($old_post_images_arr) && in_array( $image_name, $old_post_images_arr) ) {
|
4839
|
|
|
continue; // Skip if image already exists.
|
4840
|
|
|
}
|
4841
|
|
|
|
4842
|
|
|
$image_name_parts = explode( '.', $image_name );
|
4843
|
|
|
array_pop( $image_name_parts );
|
4844
|
|
|
$proper_image_name = implode( '.', $image_name_parts );
|
4845
|
|
|
|
4846
|
|
|
$arr_file_type = wp_check_filetype( $image_name );
|
4847
|
|
|
|
4848
|
|
|
if ( !empty( $arr_file_type ) ) {
|
4849
|
|
|
$uploaded_file_type = $arr_file_type['type'];
|
4850
|
|
|
|
4851
|
|
|
$attachment = array();
|
4852
|
|
|
$attachment['post_id'] = $saved_post_id;
|
4853
|
|
|
$attachment['title'] = $proper_image_name;
|
4854
|
|
|
$attachment['content'] = '';
|
4855
|
|
|
$attachment['file'] = $uploads_subdir . '/' . $image_name;
|
4856
|
|
|
$attachment['mime_type'] = $uploaded_file_type;
|
4857
|
|
|
$attachment['menu_order'] = $order;
|
4858
|
|
|
$attachment['is_featured'] = 0;
|
4859
|
|
|
|
4860
|
|
|
$attachment_set = '';
|
4861
|
|
|
foreach ( $attachment as $key => $val ) {
|
4862
|
|
|
if ( $val != '' ) {
|
4863
|
|
|
$attachment_set .= $key . " = '" . $val . "', ";
|
4864
|
|
|
}
|
4865
|
|
|
}
|
4866
|
|
|
$attachment_set = trim( $attachment_set, ", " );
|
4867
|
|
|
|
4868
|
|
|
// Add new attachment
|
4869
|
|
|
$wpdb->query( "INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set );
|
4870
|
|
|
|
4871
|
|
|
$order++;
|
4872
|
|
|
}
|
4873
|
|
|
}
|
4874
|
|
|
|
4875
|
|
|
$saved_post_images_sql = !empty($saved_post_images_arr) ? " AND ( file NOT LIKE '%/" . implode("' AND file NOT LIKE '%/", $saved_post_images_arr) . "' )" : '';
|
4876
|
|
|
// Remove previous attachment
|
4877
|
|
|
$wpdb->query( "DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id = " . (int)$saved_post_id . " " . $saved_post_images_sql );
|
4878
|
|
|
|
4879
|
|
|
if ( !empty( $saved_post_images_arr ) ) {
|
4880
|
|
|
geodir_set_wp_featured_image($saved_post_id);
|
4881
|
|
|
/*
|
|
|
|
|
4882
|
|
|
$menu_order = 1;
|
4883
|
|
|
|
4884
|
|
|
foreach ( $saved_post_images_arr as $img_name ) {
|
4885
|
|
|
$wpdb->query( $wpdb->prepare( "UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET menu_order = %d WHERE post_id =%d AND file LIKE %s", array( $menu_order, $saved_post_id, '%/' . $img_name ) ) );
|
4886
|
|
|
|
4887
|
|
|
if( $menu_order == 1 ) {
|
4888
|
|
|
if ( $featured_image = $wpdb->get_var( $wpdb->prepare( "SELECT file FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id =%d AND file LIKE %s", array( $saved_post_id, '%/' . $img_name ) ) ) ) {
|
4889
|
|
|
$wpdb->query( $wpdb->prepare( "UPDATE " . $table . " SET featured_image = %s WHERE post_id =%d", array( $featured_image, $saved_post_id ) ) );
|
4890
|
|
|
}
|
4891
|
|
|
}
|
4892
|
|
|
$menu_order++;
|
4893
|
|
|
}*/
|
4894
|
|
|
}
|
4895
|
|
|
|
4896
|
|
|
if ( $order > 1 ) {
|
4897
|
|
|
$images++;
|
4898
|
|
|
}
|
4899
|
|
|
}
|
4900
|
|
|
|
4901
|
|
|
/** This action is documented in geodirectory-functions/post-functions.php */
|
4902
|
|
|
do_action( 'geodir_after_save_listing', $saved_post_id, $gd_post );
|
4903
|
|
|
|
4904
|
|
|
if (isset($is_featured)) {
|
4905
|
|
|
geodir_save_post_meta($saved_post_id, 'is_featured', $is_featured);
|
4906
|
|
|
}
|
4907
|
|
|
if (isset($gd_post['expire_date'])) {
|
4908
|
|
|
geodir_save_post_meta($saved_post_id, 'expire_date', $gd_post['expire_date']);
|
4909
|
|
|
}
|
4910
|
|
|
}
|
4911
|
|
|
|
4912
|
|
|
// WPML
|
4913
|
|
|
if ($is_wpml && $language != '') {
|
4914
|
|
|
$sitepress->switch_lang($active_lang, true);
|
4915
|
|
|
}
|
4916
|
|
|
// WPML
|
4917
|
|
|
}
|
4918
|
|
|
}
|
4919
|
|
|
}
|
4920
|
|
|
|
4921
|
|
|
//undo some stuff to make the import quicker
|
4922
|
|
|
wp_defer_term_counting( false );
|
4923
|
|
|
wp_defer_comment_counting( false );
|
4924
|
|
|
$wpdb->query( 'COMMIT;' );
|
4925
|
|
|
$wpdb->query( 'SET autocommit = 1;' );
|
4926
|
|
|
|
4927
|
|
|
$json = array();
|
4928
|
|
|
$json['processed'] = $processed_actual;
|
|
|
|
|
4929
|
|
|
$json['created'] = $created;
|
4930
|
|
|
$json['updated'] = $updated;
|
4931
|
|
|
$json['skipped'] = $skipped;
|
4932
|
|
|
$json['invalid'] = $invalid;
|
4933
|
|
|
$json['invalid_addr'] = $invalid_addr;
|
4934
|
|
|
$json['images'] = $images;
|
4935
|
|
|
|
4936
|
|
|
wp_send_json( $json );
|
4937
|
|
|
exit;
|
4938
|
|
|
} else if ( $task == 'import_loc' ) {
|
4939
|
|
|
global $gd_post_types;
|
4940
|
|
|
$gd_post_types = $post_types;
|
4941
|
|
|
|
4942
|
|
|
if (!empty($file)) {
|
4943
|
|
|
$columns = isset($file[0]) ? $file[0] : NULL;
|
4944
|
|
|
|
4945
|
|
View Code Duplication |
if (empty($columns) || (!empty($columns) && $columns[0] == '')) {
|
4946
|
|
|
$json['error'] = __('File you are uploading is not valid. Columns does not matching.', 'geodirectory');
|
4947
|
|
|
wp_send_json( $json );
|
4948
|
|
|
}
|
4949
|
|
|
|
4950
|
|
|
$gd_error_log = __('GD IMPORT LOCATIONS [ROW %d]:', 'geodirectory');
|
4951
|
|
|
$gd_error_location = __( 'Could not be saved due to blank/invalid address(city, region, country, latitude, longitude)', 'geodirectory' );
|
4952
|
|
|
for ($i = 1; $i <= $limit; $i++) {
|
4953
|
|
|
$index = $processed + $i;
|
4954
|
|
|
|
4955
|
|
|
if (isset($file[$index])) {
|
4956
|
|
|
$row = $file[$index];
|
4957
|
|
|
$row = array_map( 'trim', $row );
|
4958
|
|
|
$data = array();
|
4959
|
|
|
|
4960
|
|
|
foreach ($columns as $c => $column ) {
|
4961
|
|
|
if (in_array($column, array('location_id', 'latitude', 'longitude', 'city', 'city_slug', 'region', 'country', 'city_meta', 'city_desc', 'region_meta', 'region_desc', 'country_meta', 'country_desc'))) {
|
4962
|
|
|
$data[$column] = $row[$c];
|
4963
|
|
|
}
|
4964
|
|
|
}
|
4965
|
|
|
|
4966
|
|
|
if ( empty($data['city']) || empty($data['region']) || empty($data['country']) || empty($data['latitude']) || empty($data['longitude']) ) {
|
4967
|
|
|
$invalid++;
|
4968
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_location );
|
4969
|
|
|
continue;
|
4970
|
|
|
}
|
4971
|
|
|
|
4972
|
|
|
$data['location_id'] = isset($data['location_id']) ? absint($data['location_id']) : 0;
|
4973
|
|
|
|
4974
|
|
|
if ( $import_choice == 'update' ) {
|
4975
|
|
|
if ( (int)$data['location_id'] > 0 && $location = geodir_get_location_by_id( '', (int)$data['location_id'] ) ) {
|
4976
|
|
|
if ( $location_id = geodir_location_update_city( $data, true, $location ) ) {
|
|
|
|
|
4977
|
|
|
$updated++;
|
4978
|
|
|
} else {
|
4979
|
|
|
$invalid++;
|
4980
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_location );
|
4981
|
|
|
}
|
4982
|
|
|
} else if ( !empty( $data['city_slug'] ) && $location = geodir_get_location_by_slug( 'city', array( 'city_slug' => $data['city_slug'] ) ) ) {
|
4983
|
|
|
$data['location_id'] = (int)$location->location_id;
|
4984
|
|
|
|
4985
|
|
|
if ( $location = geodir_get_location_by_slug( 'city', array( 'city_slug' => $data['city_slug'], 'country' => $data['country'], 'region' => $data['region'] ) ) ) {
|
4986
|
|
|
$data['location_id'] = (int)$location->location_id;
|
4987
|
|
|
} else if ( $location = geodir_get_location_by_slug( 'city', array( 'city_slug' => $data['city_slug'], 'region' => $data['region'] ) ) ) {
|
4988
|
|
|
$data['location_id'] = (int)$location->location_id;
|
4989
|
|
|
} else if ( $location = geodir_get_location_by_slug( 'city', array( 'city_slug' => $data['city_slug'], 'country' => $data['country'] ) ) ) {
|
4990
|
|
|
$data['location_id'] = (int)$location->location_id;
|
4991
|
|
|
}
|
4992
|
|
|
|
4993
|
|
|
if ( $location_id = geodir_location_update_city( $data, true, $location ) ) {
|
|
|
|
|
4994
|
|
|
$updated++;
|
4995
|
|
|
} else {
|
4996
|
|
|
$invalid++;
|
4997
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_location );
|
4998
|
|
|
}
|
4999
|
|
|
} else {
|
5000
|
|
|
if ( $location_id = geodir_location_insert_city( $data, true ) ) {
|
|
|
|
|
5001
|
|
|
$created++;
|
5002
|
|
|
} else {
|
5003
|
|
|
$invalid++;
|
5004
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_location );
|
5005
|
|
|
}
|
5006
|
|
|
}
|
5007
|
|
View Code Duplication |
} elseif ( $import_choice == 'skip' ) {
|
5008
|
|
|
if ( (int)$data['location_id'] > 0 && $location = geodir_get_location_by_id( '', (int)$data['location_id'] ) ) {
|
5009
|
|
|
$skipped++;
|
5010
|
|
|
} else if ( !empty( $data['city_slug'] ) && $location = geodir_get_location_by_slug( 'city', array( 'city_slug' => $data['city_slug'] ) ) ) {
|
5011
|
|
|
$skipped++;
|
5012
|
|
|
} else {
|
5013
|
|
|
if ( $location_id = geodir_location_insert_city( $data, true ) ) {
|
|
|
|
|
5014
|
|
|
$created++;
|
5015
|
|
|
} else {
|
5016
|
|
|
$invalid++;
|
5017
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_location );
|
5018
|
|
|
}
|
5019
|
|
|
}
|
5020
|
|
|
} else {
|
5021
|
|
|
$invalid++;
|
5022
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_location );
|
5023
|
|
|
}
|
5024
|
|
|
}
|
5025
|
|
|
}
|
5026
|
|
|
}
|
5027
|
|
|
|
5028
|
|
|
$json = array();
|
5029
|
|
|
$json['processed'] = $limit;
|
5030
|
|
|
$json['created'] = $created;
|
5031
|
|
|
$json['updated'] = $updated;
|
5032
|
|
|
$json['skipped'] = $skipped;
|
5033
|
|
|
$json['invalid'] = $invalid;
|
5034
|
|
|
$json['images'] = $images;
|
5035
|
|
|
|
5036
|
|
|
wp_send_json( $json );
|
5037
|
|
|
} else if ( $task == 'import_hood' ) {
|
5038
|
|
|
if (!empty($file)) {
|
5039
|
|
|
$columns = isset($file[0]) ? $file[0] : NULL;
|
5040
|
|
|
|
5041
|
|
View Code Duplication |
if (empty($columns) || (!empty($columns) && $columns[0] == '')) {
|
5042
|
|
|
$json['error'] = __('File you are uploading is not valid. Columns does not matching.', 'geodirectory');
|
5043
|
|
|
wp_send_json( $json );
|
5044
|
|
|
}
|
5045
|
|
|
|
5046
|
|
|
$gd_error_log = __('GD IMPORT NEIGHBOURHOODS [ROW %d]:', 'geodirectory');
|
5047
|
|
|
$gd_error_hood = __( 'Could not be saved due to invalid neighbourhood data(name, latitude, longitude) or invalid location data(either location_id or city/region/country is empty)', 'geodirectory' );
|
5048
|
|
|
for ($i = 1; $i <= $limit; $i++) {
|
5049
|
|
|
$index = $processed + $i;
|
5050
|
|
|
|
5051
|
|
|
if (isset($file[$index])) {
|
5052
|
|
|
$row = $file[$index];
|
5053
|
|
|
$row = array_map( 'trim', $row );
|
5054
|
|
|
$data = array();
|
5055
|
|
|
|
5056
|
|
|
foreach ($columns as $c => $column) {
|
5057
|
|
|
if (in_array($column, array('neighbourhood_id', 'neighbourhood_name', 'neighbourhood_slug', 'latitude', 'longitude', 'location_id', 'city', 'region', 'country'))) {
|
5058
|
|
|
$data[$column] = sanitize_text_field($row[$c]);
|
5059
|
|
|
}
|
5060
|
|
|
}
|
5061
|
|
|
|
5062
|
|
|
if (empty($data['neighbourhood_name']) || empty($data['latitude']) || empty($data['longitude'])) {
|
5063
|
|
|
$invalid++;
|
5064
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_hood );
|
5065
|
|
|
continue;
|
5066
|
|
|
}
|
5067
|
|
|
|
5068
|
|
|
$location_info = array();
|
5069
|
|
|
if (!empty($data['location_id']) && (int)$data['location_id'] > 0) {
|
5070
|
|
|
$location_info = geodir_get_location_by_id('', (int)$data['location_id']);
|
5071
|
|
|
} else if (!empty($data['city']) && !empty($data['region']) && !empty($data['country'])) {
|
5072
|
|
|
$location_info = geodir_get_location_by_slug('city', array('fields' => 'location_id', 'city' => $data['city'], 'country' => $data['country'], 'region' => $data['region']));
|
5073
|
|
|
}
|
5074
|
|
|
|
5075
|
|
|
if (empty($location_info)) {
|
5076
|
|
|
$invalid++;
|
5077
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_hood );
|
5078
|
|
|
continue;
|
5079
|
|
|
}
|
5080
|
|
|
|
5081
|
|
|
$location_id = $location_info->location_id;
|
5082
|
|
|
|
5083
|
|
|
$data['neighbourhood_id'] = isset($data['neighbourhood_id']) ? absint($data['neighbourhood_id']) : 0;
|
5084
|
|
|
|
5085
|
|
|
$hood_data = array();
|
5086
|
|
|
$hood_data['hood_name'] = $data['neighbourhood_name'];
|
5087
|
|
|
$hood_data['hood_slug'] = $data['neighbourhood_slug'];
|
5088
|
|
|
$hood_data['hood_latitude'] = $data['latitude'];
|
5089
|
|
|
$hood_data['hood_longitude'] = $data['longitude'];
|
5090
|
|
|
$hood_data['hood_location_id'] = $location_id;
|
5091
|
|
|
|
5092
|
|
|
if ( $import_choice == 'update' ) {
|
5093
|
|
|
if ((int)$data['neighbourhood_id'] > 0 && ($neighbourhood = geodir_location_get_neighbourhood_by_id((int)$data['neighbourhood_id']))) {
|
5094
|
|
|
$hood_data['hood_id'] = (int)$data['neighbourhood_id'];
|
5095
|
|
|
|
5096
|
|
|
if ($neighbourhood = geodir_location_insert_update_neighbourhood($hood_data)) {
|
5097
|
|
|
$updated++;
|
5098
|
|
|
} else {
|
5099
|
|
|
$invalid++;
|
5100
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_hood );
|
5101
|
|
|
}
|
5102
|
|
|
} else if (!empty($data['neighbourhood_slug']) && ($neighbourhood = geodir_location_get_neighbourhood_by_id($data['neighbourhood_slug'], true))) {
|
5103
|
|
|
$hood_data['hood_id'] = (int)$neighbourhood->hood_id;
|
5104
|
|
|
|
5105
|
|
|
if ($neighbourhood = geodir_location_insert_update_neighbourhood($hood_data)) {
|
5106
|
|
|
$updated++;
|
5107
|
|
|
} else {
|
5108
|
|
|
$invalid++;
|
5109
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_hood );
|
5110
|
|
|
}
|
5111
|
|
|
} else {
|
5112
|
|
|
if ($neighbourhood = geodir_location_insert_update_neighbourhood($hood_data)) {
|
5113
|
|
|
$created++;
|
5114
|
|
|
} else {
|
5115
|
|
|
$invalid++;
|
5116
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_hood );
|
5117
|
|
|
}
|
5118
|
|
|
}
|
5119
|
|
View Code Duplication |
} elseif ( $import_choice == 'skip' ) {
|
5120
|
|
|
if ((int)$data['neighbourhood_id'] > 0 && ($neighbourhood = geodir_location_get_neighbourhood_by_id((int)$data['neighbourhood_id']))) {
|
5121
|
|
|
$skipped++;
|
5122
|
|
|
} else if (!empty($data['neighbourhood_slug']) && ($neighbourhood = geodir_location_get_neighbourhood_by_id($data['neighbourhood_slug'], true))) {
|
5123
|
|
|
$skipped++;
|
5124
|
|
|
} else {
|
5125
|
|
|
|
5126
|
|
|
if ($neighbourhood = geodir_location_insert_update_neighbourhood($hood_data)) {
|
5127
|
|
|
$created++;
|
5128
|
|
|
} else {
|
5129
|
|
|
$invalid++;
|
5130
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_hood );
|
5131
|
|
|
}
|
5132
|
|
|
}
|
5133
|
|
|
} else {
|
5134
|
|
|
$invalid++;
|
5135
|
|
|
geodir_error_log( wp_sprintf( $gd_error_log, ($index + 1) ) . ' ' . $gd_error_hood );
|
5136
|
|
|
}
|
5137
|
|
|
}
|
5138
|
|
|
}
|
5139
|
|
|
}
|
5140
|
|
|
|
5141
|
|
|
$json = array();
|
5142
|
|
|
$json['processed'] = $limit;
|
5143
|
|
|
$json['created'] = $created;
|
5144
|
|
|
$json['updated'] = $updated;
|
5145
|
|
|
$json['skipped'] = $skipped;
|
5146
|
|
|
$json['invalid'] = $invalid;
|
5147
|
|
|
$json['images'] = $images;
|
5148
|
|
|
|
5149
|
|
|
wp_send_json( $json );
|
5150
|
|
|
}
|
5151
|
|
|
}
|
5152
|
|
|
break;
|
5153
|
|
|
case 'import_finish':{
|
5154
|
|
|
/**
|
5155
|
|
|
* Run an action when an import finishes.
|
5156
|
|
|
*
|
5157
|
|
|
* This action can be used to fire functions after an import ends.
|
5158
|
|
|
*
|
5159
|
|
|
* @since 1.5.3
|
5160
|
|
|
* @package GeoDirectory
|
5161
|
|
|
*/
|
5162
|
|
|
do_action('geodir_import_finished');
|
5163
|
|
|
}
|
5164
|
|
|
break;
|
5165
|
|
|
|
5166
|
|
|
}
|
5167
|
|
|
echo '0';
|
5168
|
|
|
gd_die();
|
5169
|
|
|
}
|
5170
|
|
|
|
5171
|
|
|
/**
|
5172
|
|
|
* Create new the post term.
|
5173
|
|
|
*
|
5174
|
|
|
* @since 1.4.6
|
5175
|
|
|
* @package GeoDirectory
|
5176
|
|
|
*
|
5177
|
|
|
* @param string $taxonomy Post taxonomy.
|
5178
|
|
|
* @param array $term_data {
|
5179
|
|
|
* Attributes of term data.
|
5180
|
|
|
*
|
5181
|
|
|
* @type string $name Term name.
|
5182
|
|
|
* @type string $slug Term slug.
|
5183
|
|
|
* @type string $description Term description.
|
5184
|
|
|
* @type string $top_description Term top description.
|
5185
|
|
|
* @type string $image Default Term image.
|
5186
|
|
|
* @type string $icon Default Term icon.
|
5187
|
|
|
* @type string $taxonomy Term taxonomy.
|
5188
|
|
|
* @type int $parent Term parent ID.
|
5189
|
|
|
*
|
5190
|
|
|
* }
|
5191
|
|
|
* @return int|bool Term id when success, false when fail.
|
5192
|
|
|
*/
|
5193
|
|
|
function geodir_imex_insert_term( $taxonomy, $term_data ) {
|
5194
|
|
|
if ( empty( $taxonomy ) || empty( $term_data ) ) {
|
5195
|
|
|
return false;
|
5196
|
|
|
}
|
5197
|
|
|
|
5198
|
|
|
$term = isset( $term_data['name'] ) && !empty( $term_data['name'] ) ? $term_data['name'] : '';
|
5199
|
|
|
$args = array();
|
5200
|
|
|
$args['description'] = isset( $term_data['description'] ) ? $term_data['description'] : '';
|
5201
|
|
|
$args['slug'] = isset( $term_data['slug'] ) ? $term_data['slug'] : '';
|
5202
|
|
|
$args['parent'] = isset( $term_data['parent'] ) ? (int)$term_data['parent'] : '';
|
5203
|
|
|
|
5204
|
|
|
if ( ( !empty( $args['slug'] ) && term_exists( $args['slug'], $taxonomy ) ) || empty( $args['slug'] ) ) {
|
5205
|
|
|
$term_args = array_merge( $term_data, $args );
|
5206
|
|
|
$defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
|
5207
|
|
|
$term_args = wp_parse_args( $term_args, $defaults );
|
5208
|
|
|
$term_args = sanitize_term( $term_args, $taxonomy, 'db' );
|
5209
|
|
|
$args['slug'] = wp_unique_term_slug( $args['slug'], (object)$term_args );
|
5210
|
|
|
}
|
5211
|
|
|
|
5212
|
|
|
if( !empty( $term ) ) {
|
5213
|
|
|
$result = wp_insert_term( $term, $taxonomy, $args );
|
5214
|
|
|
if( !is_wp_error( $result ) ) {
|
5215
|
|
|
return isset( $result['term_id'] ) ? $result['term_id'] : 0;
|
5216
|
|
|
}
|
5217
|
|
|
}
|
5218
|
|
|
|
5219
|
|
|
return false;
|
5220
|
|
|
}
|
5221
|
|
|
|
5222
|
|
|
/**
|
5223
|
|
|
* Update the post term.
|
5224
|
|
|
*
|
5225
|
|
|
* @since 1.4.6
|
5226
|
|
|
* @package GeoDirectory
|
5227
|
|
|
*
|
5228
|
|
|
* @param string $taxonomy Post taxonomy.
|
5229
|
|
|
* @param array $term_data {
|
5230
|
|
|
* Attributes of term data.
|
5231
|
|
|
*
|
5232
|
|
|
* @type string $term_id Term ID.
|
5233
|
|
|
* @type string $name Term name.
|
5234
|
|
|
* @type string $slug Term slug.
|
5235
|
|
|
* @type string $description Term description.
|
5236
|
|
|
* @type string $top_description Term top description.
|
5237
|
|
|
* @type string $image Default Term image.
|
5238
|
|
|
* @type string $icon Default Term icon.
|
5239
|
|
|
* @type string $taxonomy Term taxonomy.
|
5240
|
|
|
* @type int $parent Term parent ID.
|
5241
|
|
|
*
|
5242
|
|
|
* }
|
5243
|
|
|
* @return int|bool Term id when success, false when fail.
|
5244
|
|
|
*/
|
5245
|
|
|
function geodir_imex_update_term( $taxonomy, $term_data ) {
|
5246
|
|
|
if ( empty( $taxonomy ) || empty( $term_data ) ) {
|
5247
|
|
|
return false;
|
5248
|
|
|
}
|
5249
|
|
|
|
5250
|
|
|
$term_id = isset( $term_data['term_id'] ) && !empty( $term_data['term_id'] ) ? $term_data['term_id'] : 0;
|
5251
|
|
|
|
5252
|
|
|
$args = array();
|
5253
|
|
|
$args['description'] = isset( $term_data['description'] ) ? $term_data['description'] : '';
|
5254
|
|
|
$args['slug'] = isset( $term_data['slug'] ) ? $term_data['slug'] : '';
|
5255
|
|
|
$args['parent'] = isset( $term_data['parent'] ) ? (int)$term_data['parent'] : '';
|
5256
|
|
|
|
5257
|
|
|
if ( $term_id > 0 && $term_info = (array)get_term( $term_id, $taxonomy ) ) {
|
5258
|
|
|
$term_data['term_id'] = $term_info['term_id'];
|
5259
|
|
|
|
5260
|
|
|
$result = wp_update_term( $term_data['term_id'], $taxonomy, $term_data );
|
5261
|
|
|
|
5262
|
|
|
if( !is_wp_error( $result ) ) {
|
5263
|
|
|
return isset( $result['term_id'] ) ? $result['term_id'] : 0;
|
5264
|
|
|
}
|
5265
|
|
|
} else if ( $term_data['slug'] != '' && $term_info = (array)term_exists( $term_data['slug'], $taxonomy ) ) {
|
5266
|
|
|
$term_data['term_id'] = $term_info['term_id'];
|
5267
|
|
|
|
5268
|
|
|
$result = wp_update_term( $term_data['term_id'], $taxonomy, $term_data );
|
5269
|
|
|
|
5270
|
|
|
if( !is_wp_error( $result ) ) {
|
5271
|
|
|
return isset( $result['term_id'] ) ? $result['term_id'] : 0;
|
5272
|
|
|
}
|
5273
|
|
|
} else {
|
5274
|
|
|
return geodir_imex_insert_term( $taxonomy, $term_data );
|
5275
|
|
|
}
|
5276
|
|
|
|
5277
|
|
|
return false;
|
5278
|
|
|
}
|
5279
|
|
|
|
5280
|
|
|
/**
|
5281
|
|
|
* Get the posts counts for the current post type.
|
5282
|
|
|
*
|
5283
|
|
|
* @since 1.4.6
|
5284
|
|
|
* @since 1.6.4 Updated to filter posts.
|
5285
|
|
|
* @package GeoDirectory
|
5286
|
|
|
*
|
5287
|
|
|
* @global object $wpdb WordPress Database object.
|
5288
|
|
|
* @global string $plugin_prefix Geodirectory plugin table prefix.
|
5289
|
|
|
*
|
5290
|
|
|
* @param string $post_type Post type.
|
5291
|
|
|
* @return int Posts count.
|
5292
|
|
|
*/
|
5293
|
|
|
function geodir_get_posts_count( $post_type ) {
|
5294
|
|
|
global $wpdb, $plugin_prefix;
|
5295
|
|
|
|
5296
|
|
|
if ( !post_type_exists( $post_type ) ) {
|
5297
|
|
|
return 0;
|
5298
|
|
|
}
|
5299
|
|
|
|
5300
|
|
|
$table = $plugin_prefix . $post_type . '_detail';
|
5301
|
|
|
|
5302
|
|
|
// Skip listing with statuses trash, auto-draft etc...
|
5303
|
|
|
$skip_statuses = geodir_imex_export_skip_statuses();
|
5304
|
|
|
$where_statuses = '';
|
5305
|
|
View Code Duplication |
if ( !empty( $skip_statuses ) && is_array( $skip_statuses ) ) {
|
5306
|
|
|
$where_statuses = "AND `" . $wpdb->posts . "`.`post_status` NOT IN('" . implode( "','", $skip_statuses ) . "')";
|
5307
|
|
|
}
|
5308
|
|
|
|
5309
|
|
|
/**
|
5310
|
|
|
* Filter the SQL where clause part to filter posts count in import/export.
|
5311
|
|
|
*
|
5312
|
|
|
* @since 1.6.4
|
5313
|
1 |
|
* @package GeoDirectory
|
5314
|
|
|
*
|
5315
|
1 |
|
* @param string $where SQL where clause part.
|
5316
|
|
|
*/
|
5317
|
|
|
$where_statuses = apply_filters( 'geodir_get_posts_count', $where_statuses, $post_type );
|
5318
|
|
|
|
5319
|
1 |
|
$query = $wpdb->prepare( "SELECT COUNT({$wpdb->posts}.ID) FROM {$wpdb->posts} INNER JOIN {$table} ON {$table}.post_id = {$wpdb->posts}.ID WHERE {$wpdb->posts}.post_type = %s " . $where_statuses, $post_type );
|
5320
|
|
|
|
5321
|
|
|
$posts_count = (int)$wpdb->get_var( $query );
|
5322
|
1 |
|
|
5323
|
1 |
|
/**
|
5324
|
1 |
|
* Modify returned post counts for the current post type.
|
5325
|
1 |
|
*
|
5326
|
1 |
|
* @since 1.4.6
|
5327
|
|
|
* @package GeoDirectory
|
5328
|
|
|
*
|
5329
|
|
|
* @param int $posts_count Post counts.
|
5330
|
|
|
* @param string $post_type Post type.
|
5331
|
|
|
*/
|
5332
|
|
|
$posts_count = apply_filters( 'geodir_imex_count_posts', $posts_count, $post_type );
|
5333
|
|
|
|
5334
|
|
|
return $posts_count;
|
5335
|
|
|
}
|
5336
|
1 |
|
|
5337
|
|
|
/**
|
5338
|
1 |
|
* Retrieves the posts for the current post type.
|
5339
|
|
|
*
|
5340
|
1 |
|
* @since 1.4.6
|
5341
|
|
|
* @since 1.5.1 Updated to import & export recurring events.
|
5342
|
|
|
* @since 1.5.3 Fixed to get wpml original post id.
|
5343
|
|
|
* @since 1.5.7 $per_page & $page_no parameters added.
|
5344
|
|
|
* @package GeoDirectory
|
5345
|
|
|
*
|
5346
|
|
|
* @global object $wp_filesystem WordPress FileSystem object.
|
5347
|
|
|
*
|
5348
|
|
|
* @param string $post_type Post type.
|
5349
|
|
|
* @param int $per_page Per page limit. Default 0.
|
5350
|
|
|
* @param int $page_no Page number. Default 0.
|
5351
|
1 |
|
* @return array Array of posts data.
|
5352
|
|
|
*/
|
5353
|
1 |
|
function geodir_imex_get_posts( $post_type, $per_page = 0, $page_no = 0 ) {
|
5354
|
|
|
global $wp_filesystem;
|
5355
|
|
|
|
5356
|
|
|
$posts = geodir_get_export_posts( $post_type, $per_page, $page_no );
|
5357
|
|
|
|
5358
|
|
|
$csv_rows = array();
|
5359
|
|
|
|
5360
|
|
|
if ( !empty( $posts ) ) {
|
5361
|
|
|
$is_payment_plugin = is_plugin_active( 'geodir_payment_manager/geodir_payment_manager.php' );
|
5362
|
|
|
$location_manager = function_exists('geodir_location_plugin_activated') ? true : false; // Check location manager installed & active.
|
5363
|
|
|
$location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $post_type ) ? false : true;
|
5364
|
|
|
$neighbourhood_active = $location_manager && $location_allowed && get_option('location_neighbourhoods') ? true : false;
|
5365
|
|
|
$is_claim_active = is_plugin_active( 'geodir_claim_listing/geodir_claim_listing.php' ) && get_option('geodir_claim_enable') === 'yes' ? true : false;
|
5366
|
|
|
|
5367
|
|
|
$csv_row = array();
|
5368
|
|
|
$csv_row[] = 'post_id';
|
5369
|
|
|
$csv_row[] = 'post_title';
|
5370
|
|
|
$csv_row[] = 'post_author';
|
5371
|
|
|
$csv_row[] = 'post_content';
|
5372
|
|
|
$csv_row[] = 'post_category';
|
5373
|
|
|
$csv_row[] = 'default_category';
|
5374
|
|
|
$csv_row[] = 'post_tags';
|
5375
|
|
|
$csv_row[] = 'post_type';
|
5376
|
|
|
if ( $post_type == 'gd_event' ) {
|
5377
|
|
|
$csv_row[] = 'event_date';
|
5378
|
|
|
$csv_row[] = 'event_enddate';
|
5379
|
|
|
$csv_row[] = 'starttime';
|
5380
|
|
|
$csv_row[] = 'endtime';
|
5381
|
|
|
|
5382
|
|
|
$csv_row[] = 'is_recurring_event';
|
5383
|
|
|
$csv_row[] = 'event_duration_days';
|
5384
|
|
|
$csv_row[] = 'recurring_dates';
|
5385
|
|
|
$csv_row[] = 'is_whole_day_event';
|
5386
|
|
|
$csv_row[] = 'event_starttimes';
|
5387
|
|
|
$csv_row[] = 'event_endtimes';
|
5388
|
|
|
$csv_row[] = 'recurring_type';
|
5389
|
|
|
$csv_row[] = 'recurring_interval';
|
5390
|
|
|
$csv_row[] = 'recurring_week_days';
|
5391
|
|
|
$csv_row[] = 'recurring_week_nos';
|
5392
|
|
|
$csv_row[] = 'max_recurring_count';
|
5393
|
|
|
$csv_row[] = 'recurring_end_date';
|
5394
|
|
|
}
|
5395
|
|
|
$csv_row[] = 'post_status';
|
5396
|
|
|
$csv_row[] = 'is_featured';
|
5397
|
|
|
// Export claim listing field
|
5398
|
|
|
if ($is_claim_active) {
|
5399
|
|
|
$csv_row[] = 'claimed';
|
5400
|
|
|
}
|
5401
|
|
|
if ($is_payment_plugin) {
|
5402
|
|
|
$csv_row[] = 'package_id';
|
5403
|
|
|
$csv_row[] = 'expire_date';
|
5404
|
|
|
}
|
5405
|
|
|
$csv_row[] = 'post_date';
|
5406
|
|
|
$csv_row[] = 'post_address';
|
5407
|
|
|
$csv_row[] = 'post_city';
|
5408
|
|
|
$csv_row[] = 'post_region';
|
5409
|
|
|
$csv_row[] = 'post_country';
|
5410
|
|
|
$csv_row[] = 'post_zip';
|
5411
|
|
|
$csv_row[] = 'post_latitude';
|
5412
|
|
|
$csv_row[] = 'post_longitude';
|
5413
|
|
|
if ($neighbourhood_active) {
|
5414
|
|
|
$csv_row[] = 'post_neighbourhood';
|
5415
|
|
|
$csv_row[] = 'neighbourhood_latitude';
|
5416
|
|
|
$csv_row[] = 'neighbourhood_longitude';
|
5417
|
|
|
}
|
5418
|
|
|
$csv_row[] = 'geodir_timing';
|
5419
|
|
|
$csv_row[] = 'geodir_contact';
|
5420
|
|
|
$csv_row[] = 'geodir_email';
|
5421
|
|
|
$csv_row[] = 'geodir_website';
|
5422
|
|
|
$csv_row[] = 'geodir_twitter';
|
5423
|
|
|
$csv_row[] = 'geodir_facebook';
|
5424
|
|
|
$csv_row[] = 'geodir_video';
|
5425
|
|
|
$csv_row[] = 'geodir_special_offers';
|
5426
|
|
|
// WPML
|
5427
|
|
|
$is_wpml = geodir_is_wpml();
|
5428
|
|
|
if ($is_wpml) {
|
5429
|
|
|
$csv_row[] = 'language';
|
5430
|
|
|
$csv_row[] = 'original_post_id';
|
5431
|
|
|
}
|
5432
|
|
|
// WPML
|
5433
|
|
|
|
5434
|
|
|
$custom_fields = geodir_imex_get_custom_fields( $post_type );
|
5435
|
|
|
if ( !empty( $custom_fields ) ) {
|
5436
|
|
|
foreach ( $custom_fields as $custom_field ) {
|
5437
|
|
|
$csv_row[] = $custom_field->htmlvar_name;
|
5438
|
|
|
}
|
5439
|
|
|
}
|
5440
|
|
|
|
5441
|
|
|
// Export franchise fields
|
5442
|
|
|
$is_franchise_active = is_plugin_active( 'geodir_franchise/geodir_franchise.php' ) && geodir_franchise_enabled( $post_type ) ? true : false;
|
5443
|
|
|
if ($is_franchise_active) {
|
5444
|
|
|
$csv_row[] = 'gd_is_franchise';
|
5445
|
|
|
$csv_row[] = 'gd_franchise_lock';
|
5446
|
|
|
$csv_row[] = 'franchise';
|
5447
|
|
|
}
|
5448
|
|
|
|
5449
|
|
|
/**
|
5450
|
|
|
* Filter columns field names of gd export listings csv.
|
5451
|
|
|
*
|
5452
|
|
|
* @since 1.6.5
|
5453
|
|
|
* @package GeoDirectory
|
5454
|
|
|
*
|
5455
|
|
|
* @param array $csv_row Column names being exported in csv.
|
5456
|
|
|
* @param string $post_type The post type.
|
5457
|
|
|
*/
|
5458
|
|
|
$csv_row = apply_filters('geodir_export_listing_csv_column_names', $csv_row, $post_type);
|
5459
|
|
|
|
5460
|
|
|
$csv_rows[] = $csv_row;
|
5461
|
|
|
|
5462
|
|
|
$images_count = 5;
|
5463
|
|
|
$xx=0;
|
5464
|
|
|
foreach ( $posts as $post ) {$xx++;
|
5465
|
|
|
$post_id = $post['ID'];
|
5466
|
|
|
|
5467
|
|
|
$gd_post_info = geodir_get_post_info( $post_id );
|
5468
|
|
|
$post_info = (array)$gd_post_info;
|
5469
|
|
|
|
5470
|
|
|
$taxonomy_category = $post_type . 'category';
|
5471
|
|
|
$taxonomy_tags = $post_type . '_tags';
|
5472
|
|
|
|
5473
|
|
|
$post_category = '';
|
5474
|
|
|
$default_category_id = $gd_post_info->default_category;
|
5475
|
|
|
$default_category = '';
|
5476
|
|
|
$post_tags = '';
|
5477
|
|
|
$terms = wp_get_post_terms( $post_id, array( $taxonomy_category, $taxonomy_tags ) );
|
5478
|
|
|
|
5479
|
|
|
if ( !empty( $terms ) && !is_wp_error( $terms ) ) {
|
5480
|
|
|
$post_category = array();
|
5481
|
|
|
$post_tags = array();
|
5482
|
|
|
|
5483
|
|
|
foreach ( $terms as $term ) {
|
5484
|
|
|
if ( $term->taxonomy == $taxonomy_category ) {
|
5485
|
|
|
$post_category[] = $term->name;
|
5486
|
|
|
|
5487
|
|
|
if ($default_category_id == $term->term_id) {
|
5488
|
|
|
$default_category = $term->name; // Default category.
|
5489
|
|
|
}
|
5490
|
|
|
}
|
5491
|
|
|
|
5492
|
|
|
if ( $term->taxonomy == $taxonomy_tags ) {
|
5493
|
|
|
$post_tags[] = $term->name;
|
5494
|
|
|
}
|
5495
|
|
|
}
|
5496
|
|
|
|
5497
|
|
|
if (empty($default_category) && !empty($post_category)) {
|
5498
|
|
|
$default_category = $post_category[0]; // Set first one as default category.
|
5499
|
|
|
}
|
5500
|
|
|
$post_category = !empty( $post_category ) ? implode( ',', $post_category ) : '';
|
5501
|
|
|
$post_tags = !empty( $post_tags ) ? implode( ',', $post_tags ) : '';
|
5502
|
|
|
}
|
5503
|
|
|
|
5504
|
|
|
// Franchise data
|
5505
|
|
|
if ($is_franchise_active && isset($post_info['franchise']) && (int)$post_info['franchise'] > 0 && geodir_franchise_check((int)$post_info['franchise'])) {
|
5506
|
|
|
$franchise_id = $post_info['franchise'];
|
5507
|
|
|
$gd_franchise_info = geodir_get_post_info($franchise_id);
|
5508
|
|
|
|
5509
|
|
|
if (geodir_franchise_pkg_is_active($gd_franchise_info)) {
|
5510
|
|
|
$franchise_info = (array)$gd_franchise_info;
|
5511
|
|
|
$locked_fields = geodir_franchise_get_locked_fields($franchise_id, true);
|
5512
|
|
|
|
5513
|
|
|
if (!empty($locked_fields)) {
|
5514
|
|
|
foreach( $locked_fields as $locked_field) {
|
5515
|
|
|
if (isset($post_info[$locked_field]) && isset($franchise_info[$locked_field])) {
|
5516
|
|
|
$post_info[$locked_field] = $franchise_info[$locked_field];
|
5517
|
|
|
}
|
5518
|
|
|
|
5519
|
|
|
if (in_array($taxonomy_category, $locked_fields) || in_array('post_tags', $locked_fields)) {
|
5520
|
|
|
$franchise_terms = wp_get_post_terms( $franchise_id, array( $taxonomy_category, $taxonomy_tags ) );
|
5521
|
|
|
|
5522
|
|
|
if ( !empty( $franchise_terms ) && !is_wp_error( $franchise_terms ) ) {
|
5523
|
|
|
$franchise_post_category = array();
|
5524
|
|
|
$franchise_post_tags = array();
|
5525
|
|
|
|
5526
|
|
|
foreach ( $franchise_terms as $franchise_term ) {
|
5527
|
|
|
if ( $franchise_term->taxonomy == $taxonomy_category ) {
|
5528
|
|
|
$franchise_post_category[] = $franchise_term->name;
|
5529
|
|
|
}
|
5530
|
|
|
|
5531
|
|
|
if ( $franchise_term->taxonomy == $taxonomy_tags ) {
|
5532
|
|
|
$franchise_post_tags[] = $franchise_term->name;
|
5533
|
|
|
}
|
5534
|
|
|
}
|
5535
|
|
|
|
5536
|
|
|
if (in_array($taxonomy_category, $locked_fields)) {
|
5537
|
|
|
$post_category = !empty( $franchise_post_category ) ? implode( ',', $franchise_post_category ) : '';
|
5538
|
|
|
}
|
5539
|
|
|
if (in_array('post_tags', $locked_fields)) {
|
5540
|
|
|
$post_tags = !empty( $franchise_post_tags ) ? implode( ',', $franchise_post_tags ) : '';
|
5541
|
|
|
}
|
5542
|
|
|
}
|
5543
|
|
|
}
|
5544
|
|
|
}
|
5545
|
|
|
}
|
5546
|
|
|
}
|
5547
|
|
|
}
|
5548
|
|
|
|
5549
|
|
|
$post_images = geodir_get_images( $post_id );
|
5550
|
|
|
$current_images = array();
|
5551
|
|
|
if ( !empty( $post_images ) ) {
|
5552
|
|
|
foreach ( $post_images as $post_image ) {
|
|
|
|
|
5553
|
|
|
$post_image = (array)$post_image;
|
5554
|
|
|
$image = !empty( $post_image ) && isset( $post_image['path'] ) && $wp_filesystem->is_file( $post_image['path'] ) && $wp_filesystem->exists( $post_image['path'] ) ? $post_image['src'] : '';
|
5555
|
|
|
if ( $image ) {
|
5556
|
|
|
$current_images[] = $image;
|
5557
|
|
|
}
|
5558
|
|
|
}
|
5559
|
|
|
|
5560
|
|
|
$images_count = max( $images_count, count( $current_images ) );
|
5561
|
|
|
}
|
5562
|
|
|
|
5563
|
|
|
$csv_row = array();
|
5564
|
|
|
$csv_row[] = $post_id; // post_id
|
5565
|
|
|
$csv_row[] = $post_info['post_title']; // post_title
|
5566
|
|
|
$csv_row[] = $post_info['post_author']; // post_author
|
5567
|
|
|
$csv_row[] = $post_info['post_content']; // post_content
|
5568
|
|
|
$csv_row[] = $post_category; // post_category
|
5569
|
|
|
$csv_row[] = $default_category; // default_category
|
5570
|
|
|
$csv_row[] = $post_tags; // post_tags
|
5571
|
|
|
$csv_row[] = $post_type; // post_type
|
5572
|
|
|
if ( $post_type == 'gd_event' ) {
|
5573
|
|
|
$event_data = geodir_imex_get_event_data($post, $gd_post_info);
|
|
|
|
|
5574
|
|
|
$csv_row[] = $event_data['event_date']; // event_date
|
5575
|
|
|
$csv_row[] = $event_data['event_enddate']; // enddate
|
5576
|
|
|
$csv_row[] = $event_data['starttime']; // starttime
|
5577
|
|
|
$csv_row[] = $event_data['endtime']; // endtime
|
5578
|
|
|
|
5579
|
|
|
$csv_row[] = $event_data['is_recurring_event']; // is_recurring
|
5580
|
|
|
$csv_row[] = $event_data['event_duration_days']; // duration_x
|
5581
|
|
|
$csv_row[] = $event_data['recurring_dates']; // recurring_dates
|
5582
|
|
|
$csv_row[] = $event_data['is_whole_day_event']; // all_day
|
5583
|
|
|
$csv_row[] = $event_data['event_starttimes']; // starttimes
|
5584
|
|
|
$csv_row[] = $event_data['event_endtimes']; // endtimes
|
5585
|
|
|
$csv_row[] = $event_data['recurring_type']; // repeat_type
|
5586
|
|
|
$csv_row[] = $event_data['recurring_interval']; // repeat_x
|
5587
|
|
|
$csv_row[] = $event_data['recurring_week_days']; // repeat_days
|
5588
|
|
|
$csv_row[] = $event_data['recurring_week_nos']; // repeat_weeks
|
5589
|
|
|
$csv_row[] = $event_data['max_recurring_count']; // max_repeat
|
5590
|
|
|
$csv_row[] = $event_data['recurring_end_date']; // repeat_end
|
5591
|
|
|
}
|
5592
|
|
|
$csv_row[] = $post_info['post_status']; // post_status
|
5593
|
|
|
$csv_row[] = (int)$post_info['is_featured'] == 1 ? 1 : ''; // is_featured
|
5594
|
|
|
if ($is_claim_active) {
|
5595
|
|
|
$csv_row[] = !empty($post_info['claimed']) && (int)$post_info['claimed'] == 1 ? 1 : ''; // claimed
|
5596
|
|
|
}
|
5597
|
|
|
if ($is_payment_plugin) {
|
5598
|
|
|
$csv_row[] = (int)$post_info['package_id']; // package_id
|
5599
|
|
|
$csv_row[] = $post_info['expire_date'] != '' && geodir_strtolower($post_info['expire_date']) != 'never' ? date_i18n('Y-m-d', strtotime($post_info['expire_date'])) : 'Never'; // expire_date
|
5600
|
|
|
}
|
5601
|
|
|
$csv_row[] = $post_info['post_date']; // post_date
|
5602
|
|
|
$csv_row[] = $post_info['post_address']; // post_address
|
5603
|
|
|
$csv_row[] = $post_info['post_city']; // post_city
|
5604
|
|
|
$csv_row[] = $post_info['post_region']; // post_region
|
5605
|
|
|
$csv_row[] = $post_info['post_country']; // post_country
|
5606
|
|
|
$csv_row[] = $post_info['post_zip']; // post_zip
|
5607
|
|
|
$csv_row[] = $post_info['post_latitude']; // post_latitude
|
5608
|
|
|
$csv_row[] = $post_info['post_longitude']; // post_longitude
|
5609
|
|
|
if ($neighbourhood_active) {
|
5610
|
|
|
$post_neighbourhood = '';
|
5611
|
|
|
$neighbourhood_latitude = '';
|
5612
|
|
|
$neighbourhood_longitude = '';
|
5613
|
|
|
if (!empty($post_info['post_neighbourhood']) && ($hood_info = geodir_location_get_neighbourhood_by_id($post_info['post_neighbourhood'], true, $post_info['post_location_id']))) {
|
5614
|
|
|
if (!empty($hood_info)) {
|
5615
|
|
|
$post_neighbourhood = $hood_info->hood_name;
|
5616
|
|
|
$neighbourhood_latitude = $hood_info->hood_latitude;
|
5617
|
|
|
$neighbourhood_longitude = $hood_info->hood_longitude;
|
5618
|
|
|
}
|
5619
|
|
|
}
|
5620
|
|
|
$csv_row[] = $post_neighbourhood; // post_neighbourhood
|
5621
|
|
|
$csv_row[] = $neighbourhood_latitude; // neighbourhood_latitude
|
5622
|
|
|
$csv_row[] = $neighbourhood_longitude; // neighbourhood_longitude
|
5623
|
|
|
}
|
5624
|
|
|
$csv_row[] = $post_info['geodir_timing']; // geodir_timing
|
5625
|
|
|
$csv_row[] = $post_info['geodir_contact']; // geodir_contact
|
5626
|
|
|
$csv_row[] = $post_info['geodir_email']; // geodir_email
|
5627
|
|
|
$csv_row[] = $post_info['geodir_website']; // geodir_website
|
5628
|
|
|
$csv_row[] = $post_info['geodir_twitter']; // geodir_twitter
|
5629
|
|
|
$csv_row[] = $post_info['geodir_facebook']; // geodir_facebook
|
5630
|
|
|
$csv_row[] = $post_info['geodir_video']; // geodir_video
|
5631
|
|
|
$csv_row[] = $post_info['geodir_special_offers']; // geodir_special_offers
|
5632
|
|
|
// WPML
|
5633
|
|
|
if ($is_wpml) {
|
5634
|
|
|
$csv_row[] = geodir_get_language_for_element( $post_id, 'post_' . $post_type );
|
5635
|
|
|
$csv_row[] = geodir_imex_original_post_id( $post_id, 'post_' . $post_type );
|
5636
|
|
|
}
|
5637
|
|
|
// WPML
|
5638
|
|
|
|
5639
|
|
|
if ( !empty( $custom_fields ) ) {
|
5640
|
|
|
foreach ( $custom_fields as $custom_field ) {
|
5641
|
|
|
$csv_row[] = isset( $post_info[$custom_field->htmlvar_name] ) ? $post_info[$custom_field->htmlvar_name] : '';
|
5642
|
|
|
}
|
5643
|
|
|
}
|
5644
|
|
|
|
5645
|
|
|
// Franchise data
|
5646
|
|
|
if ($is_franchise_active) {
|
5647
|
|
|
$gd_is_franchise = '';
|
5648
|
|
|
$locaked_fields = '';
|
5649
|
|
|
$franchise = '';
|
5650
|
|
|
|
5651
|
|
|
if (geodir_franchise_pkg_is_active($gd_post_info)) {
|
5652
|
|
|
$gd_is_franchise = (int)get_post_meta( $post_id, 'gd_is_franchise', true );
|
5653
|
|
|
$locaked_fields = $gd_is_franchise ? get_post_meta( $post_id, 'gd_franchise_lock', true ) : '';
|
5654
|
|
|
$locaked_fields = (is_array($locaked_fields) && !empty($locaked_fields) ? implode(",", $locaked_fields) : '');
|
5655
|
|
|
$franchise = !$gd_is_franchise && isset($post_info['franchise']) && (int)$post_info['franchise'] > 0 ? (int)$post_info['franchise'] : 0; // franchise id
|
5656
|
|
|
}
|
5657
|
|
|
|
5658
|
|
|
$csv_row[] = (int)$gd_is_franchise; // gd_is_franchise
|
5659
|
|
|
$csv_row[] = $locaked_fields; // gd_franchise_lock fields
|
5660
|
|
|
$csv_row[] = (int)$franchise; // franchise id
|
5661
|
|
|
}
|
5662
|
|
|
|
5663
|
|
|
/**
|
5664
|
|
|
* Filter columns values of gd export listings csv file
|
5665
|
|
|
*
|
5666
|
|
|
* @since 1.6.5
|
5667
|
|
|
* @package GeoDirectory
|
5668
|
|
|
*
|
5669
|
|
|
* @param array $csv_row Field values being exported in csv.
|
5670
|
|
|
* @param array $post_info The post info.
|
5671
|
|
|
*/
|
5672
|
|
|
$csv_row = apply_filters('geodir_export_listing_csv_column_values', $csv_row, $post_info);
|
5673
|
|
|
|
5674
|
|
|
for ( $c = 0; $c < $images_count; $c++ ) {
|
5675
|
|
|
$csv_row[] = isset( $current_images[$c] ) ? $current_images[$c] : ''; // IMAGE
|
5676
|
|
|
}
|
5677
|
|
|
|
5678
|
|
|
$csv_rows[] = $csv_row;
|
5679
|
|
|
|
5680
|
|
|
}
|
5681
|
|
|
|
5682
|
|
|
for ( $c = 0; $c < $images_count; $c++ ) {
|
5683
|
|
|
$csv_rows[0][] = 'IMAGE';
|
5684
|
|
|
}
|
5685
|
|
|
}
|
5686
|
|
|
return $csv_rows;
|
5687
|
|
|
}
|
5688
|
|
|
|
5689
|
|
|
/**
|
5690
|
|
|
* Retrieves the posts for the current post type.
|
5691
|
|
|
*
|
5692
|
|
|
* @since 1.4.6
|
5693
|
|
|
* @since 1.5.7 $per_page & $page_no parameters added.
|
5694
|
|
|
* @package GeoDirectory
|
5695
|
|
|
*
|
5696
|
|
|
* @global object $wpdb WordPress Database object.
|
5697
|
|
|
* @global string $plugin_prefix Geodirectory plugin table prefix.
|
5698
|
|
|
*
|
5699
|
|
|
* @param string $post_type Post type.
|
5700
|
|
|
* @param int $per_page Per page limit. Default 0.
|
5701
|
|
|
* @param int $page_no Page number. Default 0.
|
5702
|
|
|
* @return array Array of posts data.
|
5703
|
|
|
*/
|
5704
|
|
|
function geodir_get_export_posts( $post_type, $per_page = 0, $page_no = 0 ) {
|
5705
|
|
|
global $wpdb, $plugin_prefix;
|
5706
|
|
|
|
5707
|
|
|
if ( ! post_type_exists( $post_type ) )
|
5708
|
|
|
return new stdClass;
|
5709
|
|
|
|
5710
|
|
|
$table = $plugin_prefix . $post_type . '_detail';
|
5711
|
|
|
|
5712
|
|
|
$limit = '';
|
5713
|
|
|
if ( $per_page > 0 && $page_no > 0 ) {
|
5714
|
|
|
$offset = ( $page_no - 1 ) * $per_page;
|
5715
|
|
|
|
5716
|
|
|
if ( $offset > 0 ) {
|
5717
|
|
|
$limit = " LIMIT " . $offset . "," . $per_page;
|
5718
|
|
|
} else {
|
5719
|
|
|
$limit = " LIMIT " . $per_page;
|
5720
|
|
|
}
|
5721
|
|
|
}
|
5722
|
|
|
|
5723
|
|
|
// Skip listing with statuses trash, auto-draft etc...
|
5724
|
|
|
$skip_statuses = geodir_imex_export_skip_statuses();
|
5725
|
|
|
$where_statuses = '';
|
5726
|
|
View Code Duplication |
if ( !empty( $skip_statuses ) && is_array( $skip_statuses ) ) {
|
5727
|
|
|
$where_statuses = "AND `" . $wpdb->posts . "`.`post_status` NOT IN('" . implode( "','", $skip_statuses ) . "')";
|
5728
|
|
|
}
|
5729
|
|
|
|
5730
|
|
|
/**
|
5731
|
|
|
* Filter the SQL where clause part to filter posts in import/export.
|
5732
|
|
|
*
|
5733
|
|
|
* @since 1.6.4
|
5734
|
|
|
* @package GeoDirectory
|
5735
|
|
|
*
|
5736
|
|
|
* @param string $where SQL where clause part.
|
5737
|
|
|
*/
|
5738
|
|
|
$where_statuses = apply_filters( 'geodir_get_export_posts', $where_statuses, $post_type );
|
5739
|
|
|
|
5740
|
|
|
$query = $wpdb->prepare( "SELECT {$wpdb->posts}.ID FROM {$wpdb->posts} INNER JOIN {$table} ON {$table}.post_id = {$wpdb->posts}.ID WHERE {$wpdb->posts}.post_type = %s " . $where_statuses . " ORDER BY {$wpdb->posts}.ID ASC" . $limit, $post_type );
|
5741
|
|
|
/**
|
5742
|
|
|
* Modify returned posts SQL query for the current post type.
|
5743
|
|
|
*
|
5744
|
|
|
* @since 1.4.6
|
5745
|
|
|
* @package GeoDirectory
|
5746
|
|
|
*
|
5747
|
|
|
* @param int $query The SQL query.
|
5748
|
|
|
* @param string $post_type Post type.
|
5749
|
|
|
*/
|
5750
|
|
|
$query = apply_filters( 'geodir_imex_export_posts_query', $query, $post_type );
|
5751
|
|
|
$results = (array)$wpdb->get_results( $wpdb->prepare( $query, $post_type ), ARRAY_A );
|
5752
|
|
|
|
5753
|
|
|
/**
|
5754
|
|
|
* Modify returned post results for the current post type.
|
5755
|
|
|
*
|
5756
|
|
|
* @since 1.4.6
|
5757
|
|
|
* @package GeoDirectory
|
5758
|
|
|
*
|
5759
|
|
|
* @param object $results An object containing all post ids.
|
5760
|
|
|
* @param string $post_type Post type.
|
5761
|
|
|
*/
|
5762
|
|
|
return apply_filters( 'geodir_export_posts', $results, $post_type );
|
5763
|
|
|
}
|
5764
|
|
|
|
5765
|
|
|
/**
|
5766
|
|
|
* Get the posts SQL query for the current post type.
|
5767
|
|
|
*
|
5768
|
|
|
* @since 1.4.6
|
5769
|
|
|
* @since 1.5.1 Query updated to get distinct posts.
|
5770
|
|
|
* @since 1.6.4 Updated to filter events.
|
5771
|
|
|
* @package GeoDirectory
|
5772
|
|
|
*
|
5773
|
|
|
* @global object $wpdb WordPress Database object.
|
5774
|
|
|
* @global string $plugin_prefix Geodirectory plugin table prefix.
|
5775
|
|
|
*
|
5776
|
|
|
* @param string $query The SQL query.
|
5777
|
|
|
* @param string $post_type Post type.
|
5778
|
|
|
* @return string The SQL query.
|
5779
|
|
|
*/
|
5780
|
|
|
function geodir_imex_get_events_query( $query, $post_type ) {
|
5781
|
|
|
if ( $post_type == 'gd_event' ) {
|
5782
|
|
|
global $wpdb, $plugin_prefix;
|
5783
|
|
|
|
5784
|
|
|
$table = $plugin_prefix . $post_type . '_detail';
|
5785
|
|
|
$schedule_table = EVENT_SCHEDULE;
|
5786
|
|
|
|
5787
|
|
|
// Skip listing with statuses trash, auto-draft etc...
|
5788
|
|
|
$skip_statuses = geodir_imex_export_skip_statuses();
|
5789
|
|
|
$where_statuses = '';
|
5790
|
|
View Code Duplication |
if ( !empty( $skip_statuses ) && is_array( $skip_statuses ) ) {
|
5791
|
|
|
$where_statuses = "AND `" . $wpdb->posts . "`.`post_status` NOT IN('" . implode( "','", $skip_statuses ) . "')";
|
5792
|
|
|
}
|
5793
|
|
|
|
5794
|
|
|
/** This action is documented in geodirectory-functions/geodirectory-admin/admin_functions.php */
|
5795
|
|
|
$where_statuses = apply_filters( 'geodir_get_export_posts', $where_statuses, $post_type );
|
5796
|
|
|
|
5797
|
|
|
$query = $wpdb->prepare( "SELECT {$wpdb->posts}.ID, {$schedule_table}.event_date, {$schedule_table}.event_enddate AS enddate, {$schedule_table}.event_starttime AS starttime, {$schedule_table}.event_endtime AS endtime FROM {$wpdb->posts} INNER JOIN {$table} ON ({$table}.post_id = {$wpdb->posts}.ID) INNER JOIN {$schedule_table} ON ({$schedule_table}.event_id = {$wpdb->posts}.ID) WHERE {$wpdb->posts}.post_type = %s " . $where_statuses . " GROUP BY {$table}.post_id ORDER BY {$wpdb->posts}.ID ASC, {$schedule_table}.schedule_id ASC", $post_type );
|
5798
|
|
|
}
|
5799
|
|
|
|
5800
|
|
|
return $query;
|
5801
|
|
|
}
|
5802
|
|
|
|
5803
|
|
|
/**
|
5804
|
|
|
* Retrieve terms count for given post type.
|
5805
|
|
|
*
|
5806
|
|
|
* @since 1.4.6
|
5807
|
|
|
* @package GeoDirectory
|
5808
|
|
|
*
|
5809
|
|
|
* @param string $post_type Post type.
|
5810
|
|
|
* @return int Total terms count.
|
5811
|
|
|
*/
|
5812
|
|
|
/**
|
5813
|
|
|
* Retrieve terms count for given post type.
|
5814
|
|
|
*
|
5815
|
|
|
* @since 1.4.6
|
5816
|
|
|
* @package GeoDirectory
|
5817
|
|
|
*
|
5818
|
|
|
* @param string $post_type Post type.
|
5819
|
|
|
* @return int Total terms count.
|
5820
|
|
|
*/
|
5821
|
|
|
function geodir_get_terms_count( $post_type ) {
|
5822
|
|
|
$args = array( 'hide_empty' => 0 );
|
5823
|
|
|
|
5824
|
|
|
remove_all_filters( 'get_terms' );
|
5825
|
|
|
|
5826
|
|
|
$taxonomy = $post_type . 'category';
|
5827
|
|
|
|
5828
|
|
|
// WPML
|
5829
|
|
|
$is_wpml = geodir_is_wpml();
|
5830
|
|
|
$active_lang = 'all';
|
5831
|
|
|
if ( $is_wpml ) {
|
5832
|
|
|
global $sitepress;
|
5833
|
|
|
$active_lang = $sitepress->get_current_language();
|
5834
|
|
|
|
5835
|
|
|
if ( $active_lang != 'all' ) {
|
5836
|
|
|
$sitepress->switch_lang( 'all', true );
|
5837
|
|
|
}
|
5838
|
|
|
}
|
5839
|
|
|
// WPML
|
5840
|
|
|
|
5841
|
1 |
|
$count_terms = wp_count_terms( $taxonomy, $args );
|
5842
|
|
|
|
5843
|
1 |
|
// WPML
|
5844
|
|
|
if ( $is_wpml && $active_lang !== 'all' ) {
|
5845
|
1 |
|
global $sitepress;
|
5846
|
|
|
$sitepress->switch_lang( $active_lang, true );
|
5847
|
|
|
}
|
5848
|
1 |
|
// WPML
|
5849
|
1 |
|
$count_terms = !is_wp_error( $count_terms ) ? $count_terms : 0;
|
5850
|
1 |
|
|
5851
|
|
|
return $count_terms;
|
5852
|
|
|
}
|
5853
|
|
|
|
5854
|
|
|
/**
|
5855
|
|
|
* Retrieve terms for given post type.
|
5856
|
|
|
*
|
5857
|
|
|
* @since 1.4.6
|
5858
|
|
|
* @since 1.5.7 $per_page & $page_no parameters added.
|
5859
|
|
|
* @package GeoDirectory
|
5860
|
1 |
|
*
|
5861
|
|
|
* @param string $post_type The post type.
|
5862
|
|
|
* @param int $per_page Per page limit. Default 0.
|
5863
|
1 |
|
* @param int $page_no Page number. Default 0.
|
5864
|
|
|
* @return array Array of terms data.
|
5865
|
|
|
*/
|
5866
|
|
|
function geodir_imex_get_terms( $post_type, $per_page = 0, $page_no = 0 ) {
|
5867
|
|
|
$args = array( 'hide_empty' => 0, 'orderby' => 'id' );
|
5868
|
1 |
|
|
5869
|
|
|
remove_all_filters( 'get_terms' );
|
5870
|
1 |
|
|
5871
|
|
|
$taxonomy = $post_type . 'category';
|
5872
|
|
|
|
5873
|
|
|
if ( $per_page > 0 && $page_no > 0 ) {
|
5874
|
|
|
$args['offset'] = ( $page_no - 1 ) * $per_page;
|
5875
|
|
|
$args['number'] = $per_page;
|
5876
|
|
|
}
|
5877
|
|
|
|
5878
|
|
|
$terms = get_terms( $taxonomy, $args );
|
5879
|
|
|
|
5880
|
|
|
$csv_rows = array();
|
5881
|
|
|
|
5882
|
|
|
if ( !empty( $terms ) ) {
|
5883
|
|
|
$csv_row = array();
|
5884
|
|
|
$csv_row[] = 'cat_id';
|
5885
|
|
|
$csv_row[] = 'cat_name';
|
5886
|
|
|
$csv_row[] = 'cat_slug';
|
5887
|
|
|
$csv_row[] = 'cat_posttype';
|
5888
|
|
|
$csv_row[] = 'cat_parent';
|
5889
|
|
|
$csv_row[] = 'cat_schema';
|
5890
|
|
|
// WPML
|
5891
|
|
|
$is_wpml = geodir_is_wpml();
|
5892
|
|
|
if ($is_wpml) {
|
5893
|
|
|
$csv_row[] = 'cat_language';
|
5894
|
|
|
$csv_row[] = 'cat_id_original';
|
5895
|
|
|
}
|
5896
|
|
|
// WPML
|
5897
|
|
|
$csv_row[] = 'cat_description';
|
5898
|
|
|
$csv_row[] = 'cat_top_description';
|
5899
|
|
|
$csv_row[] = 'cat_image';
|
5900
|
|
|
$csv_row[] = 'cat_icon';
|
5901
|
|
|
|
5902
|
|
|
$csv_rows[] = $csv_row;
|
5903
|
|
|
|
5904
|
|
|
foreach ( $terms as $term ) {
|
5905
|
|
|
$cat_icon = get_tax_meta( $term->term_id, 'ct_cat_icon', false, $post_type );
|
5906
|
|
|
$cat_icon = !empty( $cat_icon ) && isset( $cat_icon['src'] ) ? $cat_icon['src'] : '';
|
5907
|
|
|
|
5908
|
|
|
$cat_image = geodir_get_default_catimage( $term->term_id, $post_type );
|
5909
|
|
|
$cat_image = !empty( $cat_image ) && isset( $cat_image['src'] ) ? $cat_image['src'] : '';
|
5910
|
|
|
|
5911
|
|
|
$cat_parent = '';
|
5912
|
|
|
if (isset($term->parent) && (int)$term->parent > 0 && term_exists((int)$term->parent, $taxonomy)) {
|
5913
|
|
|
$parent_term = (array)get_term_by( 'id', (int)$term->parent, $taxonomy );
|
5914
|
|
|
$cat_parent = !empty($parent_term) && isset($parent_term['name']) ? $parent_term['name'] : '';
|
5915
|
|
|
}
|
5916
|
|
|
|
5917
|
|
|
$csv_row = array();
|
5918
|
|
|
$csv_row[] = $term->term_id;
|
5919
|
|
|
$csv_row[] = $term->name;
|
5920
|
|
|
$csv_row[] = $term->slug;
|
5921
|
|
|
$csv_row[] = $post_type;
|
5922
|
|
|
$csv_row[] = $cat_parent;
|
5923
|
|
|
$csv_row[] = get_tax_meta( $term->term_id, 'ct_cat_schema', false, $post_type );
|
5924
|
|
|
// WPML
|
5925
|
|
|
if ($is_wpml) {
|
5926
|
|
|
$csv_row[] = geodir_get_language_for_element( $term->term_id, 'tax_' . $taxonomy );
|
5927
|
|
|
$csv_row[] = geodir_imex_original_post_id( $term->term_id, 'tax_' . $taxonomy );
|
5928
|
|
|
}
|
5929
|
|
|
// WPML
|
5930
|
|
|
$csv_row[] = $term->description;
|
5931
|
|
|
$csv_row[] = get_tax_meta( $term->term_id, 'ct_cat_top_desc', false, $post_type );
|
5932
|
|
|
$csv_row[] = $cat_image;
|
5933
|
|
|
$csv_row[] = $cat_icon;
|
5934
|
|
|
|
5935
|
|
|
$csv_rows[] = $csv_row;
|
5936
|
|
|
}
|
5937
|
|
|
}
|
5938
|
|
|
return $csv_rows;
|
5939
|
|
|
}
|
5940
|
|
|
|
5941
|
|
|
/**
|
5942
|
|
|
* Get the path of cache directory.
|
5943
|
|
|
*
|
5944
|
|
|
* @since 1.4.6
|
5945
|
|
|
* @package GeoDirectory
|
5946
|
|
|
*
|
5947
|
|
|
* @param bool $relative True for relative path & False for absolute path.
|
5948
|
|
|
* @return string Path to the cache directory.
|
5949
|
|
|
*/
|
5950
|
|
|
function geodir_path_import_export( $relative = true ) {
|
5951
|
|
|
$upload_dir = wp_upload_dir();
|
5952
|
|
|
|
5953
|
|
|
return $relative ? $upload_dir['baseurl'] . '/cache' : $upload_dir['basedir'] . '/cache';
|
5954
|
|
|
}
|
5955
|
|
|
|
5956
|
|
|
/**
|
5957
|
|
|
* Save the data in CSV file to export.
|
5958
|
|
|
*
|
5959
|
|
|
* @since 1.4.6
|
5960
|
|
|
* @package GeoDirectory
|
5961
|
|
|
*
|
5962
|
|
|
* @global null|object $wp_filesystem WP_Filesystem object.
|
5963
|
|
|
*
|
5964
|
|
|
* @param string $file_path Full path to file.
|
5965
|
|
|
* @param array $csv_data Array of csv data.
|
5966
|
|
|
* @param bool $clear If true then it overwrite data otherwise add rows at the end of file.
|
5967
|
|
|
* @return bool true if success otherwise false.
|
5968
|
|
|
*/
|
5969
|
|
|
function geodir_save_csv_data( $file_path, $csv_data = array(), $clear = true ) {
|
5970
|
|
|
if ( empty( $csv_data ) ) {
|
5971
|
|
|
return false;
|
5972
|
|
|
}
|
5973
|
|
|
|
5974
|
|
|
global $wp_filesystem;
|
5975
|
|
|
|
5976
|
|
|
$mode = $clear ? 'w+' : 'a+';
|
5977
|
|
|
|
5978
|
|
|
if ( function_exists( 'fputcsv' ) ) {
|
5979
|
|
|
$file = fopen( $file_path, $mode );
|
5980
|
|
|
foreach( $csv_data as $csv_row ) {
|
5981
|
|
|
//$csv_row = array_map( 'utf8_decode', $csv_row );
|
|
|
|
|
5982
|
|
|
$write_successful = fputcsv( $file, $csv_row, ",", $enclosure = '"' );
|
|
|
|
|
5983
|
|
|
}
|
5984
|
|
|
fclose( $file );
|
5985
|
|
|
} else {
|
5986
|
|
|
foreach( $csv_data as $csv_row ) {
|
5987
|
|
|
//$csv_row = array_map( 'utf8_decode', $csv_row );
|
|
|
|
|
5988
|
|
|
$wp_filesystem->put_contents( $file_path, $csv_row );
|
5989
|
|
|
}
|
5990
|
|
|
}
|
5991
|
|
|
|
5992
|
|
|
return true;
|
5993
|
|
|
}
|
5994
|
|
|
|
5995
|
|
|
/**
|
5996
|
|
|
* Count the number of line from file.
|
5997
|
|
|
*
|
5998
|
|
|
* @since 1.4.6
|
5999
|
|
|
* @package GeoDirectory
|
6000
|
|
|
*
|
6001
|
|
|
* @global null|object $wp_filesystem WP_Filesystem object.
|
6002
|
|
|
*
|
6003
|
|
|
* @param string $file Full path to file.
|
6004
|
|
|
* @return int No of file rows.
|
6005
|
|
|
*/
|
6006
|
|
|
function geodir_import_export_line_count( $file ) {
|
6007
|
|
|
global $wp_filesystem;
|
6008
|
|
|
|
6009
|
|
|
if ( $wp_filesystem->is_file( $file ) && $wp_filesystem->exists( $file ) ) {
|
6010
|
|
|
$contents = $wp_filesystem->get_contents_array( $file );
|
6011
|
|
|
|
6012
|
|
|
if ( !empty( $contents ) && is_array( $contents ) ) {
|
6013
|
|
|
return count( $contents ) - 1;
|
6014
|
|
|
}
|
6015
|
|
|
}
|
6016
|
|
|
|
6017
|
|
|
return NULL;
|
6018
|
|
|
}
|
6019
|
|
|
|
6020
|
|
|
/**
|
6021
|
|
|
* Returns queried data from custom fields table.
|
6022
|
|
|
*
|
6023
|
|
|
* @since 1.0.0
|
6024
|
|
|
* @since 1.5.4 Modified to fix empty columns in export csv file.
|
6025
|
|
|
* @package GeoDirectory
|
6026
|
|
|
* @global object $wpdb WordPress Database object.
|
6027
|
|
|
* @param string $post_type The post type.
|
6028
|
|
|
* @return object Queried object.
|
6029
|
|
|
*/
|
6030
|
|
|
function geodir_imex_get_custom_fields( $post_type ) {
|
6031
|
|
|
global $wpdb;
|
6032
|
|
|
|
6033
|
|
|
$sql = $wpdb->prepare("SELECT htmlvar_name FROM " . GEODIR_CUSTOM_FIELDS_TABLE . " WHERE post_type=%s AND is_active='1' AND is_admin!='1' AND field_type != 'fieldset' AND htmlvar_name != '' ORDER BY id ASC", array( $post_type ) );
|
6034
|
|
|
$rows = $wpdb->get_results( $sql );
|
6035
|
|
|
|
6036
|
|
|
return $rows;
|
6037
|
|
|
}
|
6038
|
|
|
|
6039
|
|
|
/**
|
6040
|
|
|
* Check wpml active or not.
|
6041
|
|
|
*
|
6042
|
|
|
* @since 1.5.0
|
6043
|
|
|
*
|
6044
|
|
|
* @return True if WPML is active else False.
|
6045
|
|
|
*/
|
6046
|
|
|
function geodir_is_wpml() {
|
6047
|
|
|
if (function_exists('icl_object_id')) {
|
6048
|
|
|
return true;
|
6049
|
|
|
}
|
6050
|
|
|
|
6051
|
|
|
return false;
|
6052
|
|
|
}
|
6053
|
|
|
|
6054
|
|
|
/**
|
6055
|
|
|
* Get WPML language code for current term.
|
6056
|
|
|
*
|
6057
|
|
|
* @since 1.5.0
|
6058
|
|
|
*
|
6059
|
|
|
* @global object $sitepress Sitepress WPML object.
|
6060
|
|
|
*
|
6061
|
|
|
* @param int $element_id Post ID or Term id.
|
6062
|
|
|
* @param string $element_type Element type. Ex: post_gd_place or tax_gd_placecategory.
|
6063
|
|
|
* @return Language code.
|
6064
|
|
|
*/
|
6065
|
|
|
function geodir_get_language_for_element($element_id, $element_type) {
|
6066
|
1 |
|
global $sitepress;
|
6067
|
|
|
|
6068
|
|
|
return $sitepress->get_language_for_element($element_id, $element_type);
|
6069
|
|
|
}
|
6070
|
1 |
|
|
6071
|
|
|
/**
|
6072
|
|
|
* Duplicate post details for WPML translation post.
|
6073
|
|
|
*
|
6074
|
|
|
* @since 1.5.0
|
6075
|
|
|
*
|
6076
|
|
|
* @param int $master_post_id Original Post ID.
|
6077
|
|
|
* @param string $lang Language code for translating post.
|
6078
|
|
|
* @param array $postarr Array of post data.
|
6079
|
|
|
* @param int $tr_post_id Translation Post ID.
|
6080
|
|
|
*/
|
6081
|
|
|
function geodir_icl_make_duplicate($master_post_id, $lang, $postarr, $tr_post_id) {
|
|
|
|
|
6082
|
|
|
$post_type = get_post_type($master_post_id);
|
6083
|
|
|
|
6084
|
|
|
if (in_array($post_type, geodir_get_posttypes())) {
|
6085
|
|
|
// Duplicate post details
|
6086
|
|
|
geodir_icl_duplicate_post_details($master_post_id, $tr_post_id, $lang);
|
6087
|
|
|
|
6088
|
|
|
// Duplicate taxonomies
|
6089
|
|
|
geodir_icl_duplicate_taxonomies($master_post_id, $tr_post_id, $lang);
|
6090
|
|
|
|
6091
|
|
|
// Duplicate post images
|
6092
|
|
|
geodir_icl_duplicate_post_images($master_post_id, $tr_post_id, $lang);
|
6093
|
|
|
}
|
6094
|
|
|
}
|
6095
|
|
|
|
6096
|
|
|
/**
|
6097
|
|
|
* Duplicate post general details for WPML translation post.
|
6098
|
|
|
*
|
6099
|
|
|
* @since 1.5.0
|
6100
|
|
|
*
|
6101
|
|
|
* @global object $wpdb WordPress Database object.
|
6102
|
|
|
* @global string $plugin_prefix Geodirectory plugin table prefix.
|
6103
|
|
|
*
|
6104
|
|
|
* @param int $master_post_id Original Post ID.
|
6105
|
|
|
* @param int $tr_post_id Translation Post ID.
|
6106
|
|
|
* @param string $lang Language code for translating post.
|
6107
|
|
|
* @return bool True for success, False for fail.
|
6108
|
|
|
*/
|
6109
|
|
|
function geodir_icl_duplicate_post_details($master_post_id, $tr_post_id, $lang) {
|
|
|
|
|
6110
|
|
|
global $wpdb, $plugin_prefix;
|
6111
|
|
|
|
6112
|
|
|
$post_type = get_post_type($master_post_id);
|
6113
|
|
|
$post_table = $plugin_prefix . $post_type . '_detail';
|
6114
|
|
|
|
6115
|
|
|
$query = $wpdb->prepare("SELECT * FROM " . $post_table . " WHERE post_id = %d", array($master_post_id));
|
6116
|
|
|
$data = (array)$wpdb->get_row($query);
|
6117
|
|
|
|
6118
|
|
|
if ( !empty( $data ) ) {
|
6119
|
|
|
$data['post_id'] = $tr_post_id;
|
6120
|
|
|
unset($data['default_category'], $data['marker_json'], $data['featured_image'], $data[$post_type . 'category'], $data['overall_rating'], $data['rating_count'], $data['ratings']);
|
6121
|
|
|
|
6122
|
|
|
$wpdb->update($post_table, $data, array('post_id' => $tr_post_id));
|
6123
|
|
|
return true;
|
6124
|
|
|
}
|
6125
|
|
|
|
6126
|
|
|
return false;
|
6127
|
|
|
}
|
6128
|
|
|
|
6129
|
|
|
/**
|
6130
|
|
|
* Duplicate post taxonomies for WPML translation post.
|
6131
|
|
|
*
|
6132
|
|
|
* @since 1.5.0
|
6133
|
|
|
*
|
6134
|
|
|
* @global object $sitepress Sitepress WPML object.
|
6135
|
|
|
* @global object $wpdb WordPress Database object.
|
6136
|
|
|
*
|
6137
|
|
|
* @param int $master_post_id Original Post ID.
|
6138
|
|
|
* @param int $tr_post_id Translation Post ID.
|
6139
|
|
|
* @param string $lang Language code for translating post.
|
6140
|
|
|
* @return bool True for success, False for fail.
|
6141
|
|
|
*/
|
6142
|
|
|
function geodir_icl_duplicate_taxonomies($master_post_id, $tr_post_id, $lang) {
|
6143
|
|
|
global $sitepress, $wpdb;
|
6144
|
|
|
$post_type = get_post_type($master_post_id);
|
6145
|
|
|
|
6146
|
|
|
remove_filter('get_term', array($sitepress,'get_term_adjust_id')); // AVOID filtering to current language
|
6147
|
|
|
|
6148
|
|
|
$taxonomies = get_object_taxonomies($post_type);
|
6149
|
|
|
foreach ($taxonomies as $taxonomy) {
|
6150
|
|
|
$terms = get_the_terms($master_post_id, $taxonomy);
|
6151
|
|
|
$terms_array = array();
|
6152
|
|
|
|
6153
|
|
|
if ($terms) {
|
6154
|
|
|
foreach ($terms as $term) {
|
6155
|
|
|
$tr_id = apply_filters( 'translate_object_id',$term->term_id, $taxonomy, false, $lang);
|
6156
|
|
|
|
6157
|
|
|
if (!is_null($tr_id)){
|
6158
|
|
|
// not using get_term - unfiltered get_term
|
6159
|
|
|
$translated_term = $wpdb->get_row($wpdb->prepare("
|
6160
|
|
|
SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id = t.term_id WHERE t.term_id = %d AND x.taxonomy = %s", $tr_id, $taxonomy));
|
6161
|
|
|
|
6162
|
|
|
$terms_array[] = $translated_term->term_id;
|
6163
|
|
|
}
|
6164
|
|
|
}
|
6165
|
|
|
|
6166
|
|
|
if (!is_taxonomy_hierarchical($taxonomy)){
|
6167
|
|
|
$terms_array = array_unique( array_map( 'intval', $terms_array ) );
|
6168
|
|
|
}
|
6169
|
|
|
|
6170
|
|
|
wp_set_post_terms($tr_post_id, $terms_array, $taxonomy);
|
6171
|
|
|
|
6172
|
|
|
if ($taxonomy == $post_type . 'category') {
|
6173
|
|
|
geodir_set_postcat_structure($tr_post_id, $post_type . 'category');
|
6174
|
|
|
}
|
6175
|
|
|
}
|
6176
|
|
|
}
|
6177
|
|
|
}
|
6178
|
|
|
|
6179
|
|
|
/**
|
6180
|
|
|
* Duplicate post images for WPML translation post.
|
6181
|
|
|
*
|
6182
|
|
|
* @since 1.5.0
|
6183
|
|
|
*
|
6184
|
|
|
* @global object $wpdb WordPress Database object.
|
6185
|
|
|
*
|
6186
|
|
|
* @param int $master_post_id Original Post ID.
|
6187
|
|
|
* @param int $tr_post_id Translation Post ID.
|
6188
|
|
|
* @param string $lang Language code for translating post.
|
6189
|
|
|
* @return bool True for success, False for fail.
|
6190
|
|
|
*/
|
6191
|
|
|
function geodir_icl_duplicate_post_images($master_post_id, $tr_post_id, $lang) {
|
|
|
|
|
6192
|
|
|
global $wpdb;
|
6193
|
|
|
|
6194
|
|
|
$query = $wpdb->prepare("DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d", array('%image%', $tr_post_id));
|
6195
|
|
|
$wpdb->query($query);
|
6196
|
|
|
|
6197
|
|
|
$query = $wpdb->prepare("SELECT * FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE mime_type like %s AND post_id = %d ORDER BY menu_order ASC", array('%image%', $master_post_id));
|
6198
|
|
|
$post_images = $wpdb->get_results($query);
|
6199
|
|
|
|
6200
|
|
|
if ( !empty( $post_images ) ) {
|
6201
|
|
|
foreach ( $post_images as $post_image) {
|
6202
|
|
|
$image_data = (array)$post_image;
|
6203
|
|
|
unset($image_data['ID']);
|
6204
|
|
|
$image_data['post_id'] = $tr_post_id;
|
6205
|
|
|
|
6206
|
|
|
$wpdb->insert(GEODIR_ATTACHMENT_TABLE, $image_data);
|
6207
|
|
|
|
6208
|
|
|
geodir_set_wp_featured_image($tr_post_id);
|
6209
|
|
|
}
|
6210
|
|
|
|
6211
|
|
|
return true;
|
6212
|
|
|
}
|
6213
|
|
|
|
6214
|
|
|
return false;
|
6215
|
|
|
}
|
6216
|
|
|
|
6217
|
|
|
/**
|
6218
|
|
|
* Retrieves the event data to export.
|
6219
|
|
|
*
|
6220
|
|
|
* @since 1.5.1
|
6221
|
|
|
* @package GeoDirectory
|
6222
|
|
|
*
|
6223
|
|
|
* @param array $post Post array.
|
6224
|
|
|
* @param object $gd_post_info Geodirectory Post object.
|
6225
|
|
|
* @return array Event data array.
|
6226
|
|
|
*/
|
6227
|
|
|
function geodir_imex_get_event_data($post, $gd_post_info) {
|
6228
|
|
|
$event_date = isset( $post['event_date'] ) && $post['event_date'] != '' && $post['event_date'] != '0000-00-00 00:00:00' ? date_i18n( 'd/m/Y', strtotime( $post['event_date'] ) ) : '';
|
6229
|
|
|
$event_enddate = $event_date;
|
6230
|
|
|
$starttime = isset( $post['starttime'] ) && $post['starttime'] != '' && $post['starttime'] != '00:00:00' ? date_i18n( 'H:i', strtotime( $post['starttime'] ) ) : '';
|
6231
|
|
|
$endtime = isset( $post['endtime'] ) && $post['endtime'] != '' && $post['endtime'] != '00:00:00' ? date_i18n( 'H:i', strtotime( $post['endtime'] ) ) : '';
|
6232
|
|
|
|
6233
|
|
|
$is_recurring_event = '';
|
6234
|
|
|
$event_duration_days = '';
|
6235
|
|
|
$is_whole_day_event = '';
|
6236
|
|
|
$recurring_dates = '';
|
6237
|
|
|
$event_starttimes = '';
|
6238
|
|
|
$event_endtimes = '';
|
6239
|
|
|
$recurring_type = '';
|
6240
|
|
|
$recurring_interval = '';
|
6241
|
|
|
$recurring_week_days = '';
|
6242
|
|
|
$recurring_week_nos = '';
|
6243
|
|
|
$max_recurring_count = '';
|
6244
|
|
|
$recurring_end_date = '';
|
6245
|
|
|
|
6246
|
|
|
$recurring_data = isset($gd_post_info->recurring_dates) ? maybe_unserialize($gd_post_info->recurring_dates) : array();
|
6247
|
|
|
if (!empty($recurring_data)) {
|
6248
|
|
|
$event_date = isset( $recurring_data['event_start'] ) && $recurring_data['event_start'] != '' && $recurring_data['event_start'] != '0000-00-00 00:00:00' ? date_i18n( 'd/m/Y', strtotime( $recurring_data['event_start'] ) ) : $event_date;
|
6249
|
|
|
$event_enddate = isset( $recurring_data['event_end'] ) && $recurring_data['event_end'] != '' && $recurring_data['event_end'] != '0000-00-00 00:00:00' ? date_i18n( 'd/m/Y', strtotime( $recurring_data['event_end'] ) ) : $event_date;
|
6250
|
|
|
$starttime = isset( $recurring_data['starttime'] ) && $recurring_data['starttime'] != '' && $recurring_data['starttime'] != '00:00:00' ? date_i18n( 'H:i', strtotime( $recurring_data['starttime'] ) ) : $starttime;
|
6251
|
|
|
$endtime = isset( $recurring_data['endtime'] ) && $recurring_data['endtime'] != '' && $recurring_data['endtime'] != '00:00:00' ? date_i18n( 'H:i', strtotime( $recurring_data['endtime'] ) ) : $endtime;
|
6252
|
|
|
$is_whole_day_event = !empty($recurring_data['all_day']) ? 1 : '';
|
6253
|
|
|
$different_times = !empty($recurring_data['different_times']) ? true : false;
|
6254
|
|
|
|
6255
|
|
|
$recurring_pkg = geodir_event_recurring_pkg( $gd_post_info );
|
6256
|
|
|
$is_recurring = isset( $gd_post_info->is_recurring ) && (int)$gd_post_info->is_recurring == 0 ? false : true;
|
6257
|
|
|
|
6258
|
|
|
if ($recurring_pkg && $is_recurring) {
|
6259
|
|
|
$recurring_dates = $event_date;
|
6260
|
|
|
$event_enddate = '';
|
6261
|
|
|
$is_recurring_event = 1;
|
6262
|
|
|
|
6263
|
|
|
$recurring_type = !empty($recurring_data['repeat_type']) && in_array($recurring_data['repeat_type'], array('day', 'week', 'month', 'year', 'custom')) ? $recurring_data['repeat_type'] : 'custom';
|
6264
|
|
|
|
6265
|
|
|
if (!empty($recurring_data['event_recurring_dates'])) {
|
6266
|
|
|
$event_recurring_dates = explode( ',', $recurring_data['event_recurring_dates'] );
|
6267
|
|
|
|
6268
|
|
|
if (!empty($event_recurring_dates)) {
|
6269
|
|
|
$recurring_dates = array();
|
6270
|
|
|
|
6271
|
|
|
foreach ($event_recurring_dates as $date) {
|
6272
|
|
|
$recurring_dates[] = date_i18n( 'd/m/Y', strtotime( $date ) );
|
6273
|
|
|
}
|
6274
|
|
|
|
6275
|
|
|
$recurring_dates = implode(",", $recurring_dates);
|
6276
|
|
|
}
|
6277
|
|
|
}
|
6278
|
|
|
|
6279
|
|
|
if ($recurring_type == 'custom') {
|
6280
|
|
|
if (!$is_whole_day_event) {
|
6281
|
|
|
$event_starttimes = $starttime;
|
6282
|
|
|
$event_endtimes = $endtime;
|
6283
|
|
|
|
6284
|
|
View Code Duplication |
if (!empty($recurring_data['starttimes'])) {
|
6285
|
|
|
$times = array();
|
6286
|
|
|
|
6287
|
|
|
foreach ($recurring_data['starttimes'] as $time) {
|
6288
|
|
|
$times[] = $time != '00:00:00' ? date_i18n( 'H:i', strtotime( $time ) ) : '00:00';
|
6289
|
|
|
}
|
6290
|
|
|
|
6291
|
|
|
$event_starttimes = implode(",", $times);
|
6292
|
|
|
}
|
6293
|
|
|
|
6294
|
|
View Code Duplication |
if (!empty($recurring_data['endtimes'])) {
|
6295
|
|
|
$times = array();
|
6296
|
|
|
|
6297
|
|
|
foreach ($recurring_data['endtimes'] as $time) {
|
6298
|
|
|
$times[] = $time != '00:00:00' ? date_i18n( 'H:i', strtotime( $time ) ) : '00:00';
|
6299
|
|
|
}
|
6300
|
|
|
|
6301
|
|
|
$event_endtimes = implode(",", $times);
|
6302
|
|
|
}
|
6303
|
|
|
|
6304
|
|
|
if (!$different_times) {
|
6305
|
|
|
$event_starttimes = '';
|
6306
|
|
|
$event_endtimes = '';
|
6307
|
|
|
}
|
6308
|
|
|
}
|
6309
|
|
|
} else {
|
6310
|
|
|
$event_duration_days = isset($recurring_data['duration_x']) ? (int)$recurring_data['duration_x'] : 1;
|
6311
|
|
|
$recurring_interval = !empty($recurring_data['repeat_x']) && (int)$recurring_data['repeat_x'] > 0 ? $recurring_data['repeat_x'] : 1;
|
6312
|
|
|
|
6313
|
|
|
if (($recurring_type == 'week' || $recurring_type == 'month') && !empty($recurring_data['repeat_days'])) {
|
6314
|
|
|
$week_days = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
|
6315
|
|
|
|
6316
|
|
|
$days = array();
|
6317
|
|
|
foreach ($recurring_data['repeat_days'] as $day) {
|
6318
|
|
|
if (isset($week_days[$day])) {
|
6319
|
|
|
$days[] = $week_days[$day];
|
6320
|
|
|
}
|
6321
|
|
|
}
|
6322
|
|
|
|
6323
|
|
|
$recurring_week_days = implode(",", array_unique($days));
|
6324
|
|
|
}
|
6325
|
|
|
|
6326
|
|
|
$recurring_week_nos = $recurring_type == 'month' && !empty($recurring_data['repeat_weeks']) ? implode(",", $recurring_data['repeat_weeks']) : $recurring_week_nos;
|
6327
|
|
|
if (!empty($recurring_data['repeat_end_type']) && (int)$recurring_data['repeat_end_type'] == 1) {
|
6328
|
|
|
$recurring_end_date = isset($recurring_data['repeat_end']) && $recurring_data['repeat_end'] != '' && $recurring_data['repeat_end'] != '0000-00-00 00:00:00' ? date_i18n( 'd/m/Y', strtotime( $recurring_data['repeat_end'] ) ) : '';
|
6329
|
|
|
$max_recurring_count = empty($recurring_end_date) ? 1 : '';
|
6330
|
|
|
} else {
|
6331
|
|
|
$max_recurring_count = (!empty($recurring_data['max_repeat']) && (int)$recurring_data['max_repeat'] > 0 ? (int)$recurring_data['max_repeat'] : 1);
|
6332
|
|
|
}
|
6333
|
|
|
}
|
6334
|
|
|
}
|
6335
|
|
|
}
|
6336
|
|
|
if ($is_whole_day_event) {
|
6337
|
|
|
$starttime = '';
|
6338
|
|
|
$endtime = '';
|
6339
|
|
|
$event_starttimes = '';
|
6340
|
|
|
$event_endtimes = '';
|
6341
|
|
|
}
|
6342
|
|
|
|
6343
|
|
|
$data = array();
|
6344
|
|
|
$data['event_date'] = $event_date;
|
6345
|
|
|
$data['event_enddate'] = $event_enddate;
|
6346
|
|
|
$data['starttime'] = $starttime;
|
6347
|
|
|
$data['endtime'] = $endtime;
|
6348
|
|
|
$data['is_recurring_event'] = $is_recurring_event;
|
6349
|
|
|
$data['recurring_dates'] = $recurring_dates;
|
6350
|
|
|
$data['event_duration_days'] = $event_duration_days;
|
6351
|
|
|
$data['is_whole_day_event'] = $is_whole_day_event;
|
6352
|
|
|
$data['event_starttimes'] = $event_starttimes;
|
6353
|
|
|
$data['event_endtimes'] = $event_endtimes;
|
6354
|
|
|
$data['recurring_type'] = $recurring_type;
|
6355
|
|
|
$data['recurring_interval'] = $recurring_interval;
|
6356
|
|
|
$data['recurring_week_days'] = $recurring_week_days;
|
6357
|
|
|
$data['recurring_week_nos'] = $recurring_week_nos;
|
6358
|
|
|
$data['max_recurring_count'] = $max_recurring_count;
|
6359
|
|
|
$data['recurring_end_date'] = $recurring_end_date;
|
6360
|
|
|
|
6361
|
|
|
return $data;
|
6362
|
|
|
}
|
6363
|
|
|
|
6364
|
|
|
/**
|
6365
|
|
|
* Convert date format to store in database.
|
6366
|
|
|
*
|
6367
|
|
|
* PHP date() function doesn't work well with d/m/Y format
|
6368
|
|
|
* so this function validate and convert date to store in db.
|
6369
|
|
|
*
|
6370
|
|
|
* @since 1.5.1
|
6371
|
|
|
* @package GeoDirectory
|
6372
|
|
|
*
|
6373
|
|
|
* @param string $date Date in Y-m-d or d/m/Y format.
|
6374
|
|
|
* @return string Date in Y-m-d format.
|
6375
|
|
|
*/
|
6376
|
|
|
function geodir_imex_get_date_ymd($date) {
|
6377
|
|
|
if (strpos($date, '/') !== false) {
|
6378
|
|
|
$date = str_replace('/', '-', $date); // PHP doesn't work well with dd/mm/yyyy format.
|
6379
|
|
|
}
|
6380
|
|
|
|
6381
|
|
|
$date = date_i18n('Y-m-d', strtotime($date));
|
6382
|
|
|
return $date;
|
6383
|
|
|
}
|
6384
|
|
|
|
6385
|
|
|
/**
|
6386
|
|
|
* Validate the event data.
|
6387
|
|
|
*
|
6388
|
|
|
* @since 1.5.1
|
6389
|
|
|
* @package GeoDirectory
|
6390
|
|
|
*
|
6391
|
|
|
* @param array $gd_post Post array.
|
6392
|
|
|
* @return array Event data array.
|
6393
|
|
|
*/
|
6394
|
|
|
function geodir_imex_process_event_data($gd_post) {
|
6395
|
|
|
$recurring_pkg = geodir_event_recurring_pkg( (object)$gd_post );
|
6396
|
|
|
|
6397
|
|
|
$is_recurring = isset( $gd_post['is_recurring_event'] ) && (int)$gd_post['is_recurring_event'] == 0 ? false : true;
|
6398
|
|
|
$event_date = isset($gd_post['event_date']) && $gd_post['event_date'] != '' ? geodir_imex_get_date_ymd($gd_post['event_date']) : '';
|
6399
|
|
|
$event_enddate = isset($gd_post['event_enddate']) && $gd_post['event_enddate'] != '' ? geodir_imex_get_date_ymd($gd_post['event_enddate']) : $event_date;
|
6400
|
|
|
$all_day = isset($gd_post['is_whole_day_event']) && !empty($gd_post['is_whole_day_event']) ? true : false;
|
6401
|
|
|
$starttime = isset($gd_post['starttime']) && !$all_day ? $gd_post['starttime'] : '';
|
6402
|
|
|
$endtime = isset($gd_post['endtime']) && !$all_day ? $gd_post['endtime'] : '';
|
6403
|
|
|
|
6404
|
|
|
$repeat_type = '';
|
6405
|
|
|
$different_times = '';
|
6406
|
|
|
$starttimes = '';
|
6407
|
|
|
$endtimes = '';
|
6408
|
|
|
$repeat_days = '';
|
6409
|
|
|
$repeat_weeks = '';
|
6410
|
|
|
$event_recurring_dates = '';
|
6411
|
|
|
$repeat_x = '';
|
6412
|
|
|
$duration_x = '';
|
6413
|
|
|
$repeat_end_type = '';
|
6414
|
|
|
$max_repeat = '';
|
6415
|
|
|
$repeat_end = '';
|
6416
|
|
|
|
6417
|
|
|
if ($recurring_pkg && $is_recurring) {
|
6418
|
|
|
$repeat_type = $gd_post['recurring_type'];
|
6419
|
|
|
|
6420
|
|
|
if ($repeat_type == 'custom') {
|
6421
|
|
|
$starttimes = !$all_day && !empty($gd_post['event_starttimes']) ? explode(",", $gd_post['event_starttimes']) : array();
|
6422
|
|
|
$endtimes = !$all_day && !empty($gd_post['event_endtimes']) ? explode(",", $gd_post['event_endtimes']) : array();
|
6423
|
|
|
|
6424
|
|
|
if (!empty($starttimes) || !empty($endtimes)) {
|
6425
|
|
|
$different_times = true;
|
6426
|
|
|
}
|
6427
|
|
|
|
6428
|
|
|
$recurring_dates = isset($gd_post['recurring_dates']) && $gd_post['recurring_dates'] != '' ? explode(",", $gd_post['recurring_dates']) : array();
|
6429
|
|
|
if (!empty($recurring_dates)) {
|
6430
|
|
|
$event_recurring_dates = array();
|
6431
|
|
|
|
6432
|
|
|
foreach ($recurring_dates as $recurring_date) {
|
6433
|
|
|
$recurring_date = trim($recurring_date);
|
6434
|
|
|
|
6435
|
|
|
if ($recurring_date != '') {
|
6436
|
|
|
$event_recurring_dates[] = geodir_imex_get_date_ymd($recurring_date);
|
6437
|
|
|
}
|
6438
|
|
|
}
|
6439
|
|
|
|
6440
|
|
|
$event_recurring_dates = array_unique($event_recurring_dates);
|
6441
|
|
|
$event_recurring_dates = implode(",", $event_recurring_dates);
|
6442
|
|
|
}
|
6443
|
|
|
} else {
|
6444
|
|
|
$duration_x = !empty( $gd_post['event_duration_days'] ) ? (int)$gd_post['event_duration_days'] : 1;
|
6445
|
|
|
$repeat_x = !empty( $gd_post['recurring_interval'] ) ? (int)$gd_post['recurring_interval'] : 1;
|
6446
|
|
|
$max_repeat = !empty( $gd_post['max_recurring_count'] ) ? (int)$gd_post['max_recurring_count'] : 1;
|
6447
|
|
|
$repeat_end = !empty( $gd_post['recurring_end_date'] ) ? geodir_imex_get_date_ymd($gd_post['recurring_end_date']) : '';
|
6448
|
|
|
|
6449
|
|
|
$repeat_end_type = $repeat_end != '' ? 1 : 0;
|
6450
|
|
|
$max_repeat = $repeat_end != '' ? '' : $max_repeat;
|
6451
|
|
|
|
6452
|
|
|
$week_days = array_flip(array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'));
|
6453
|
|
|
|
6454
|
|
|
$a_repeat_days = isset($gd_post['recurring_week_days']) && trim($gd_post['recurring_week_days'])!='' ? explode(',', trim($gd_post['recurring_week_days'])) : array();
|
6455
|
|
|
$repeat_days = array();
|
6456
|
|
|
if (!empty($a_repeat_days)) {
|
6457
|
|
|
foreach ($a_repeat_days as $repeat_day) {
|
6458
|
|
|
$repeat_day = geodir_strtolower(trim($repeat_day));
|
6459
|
|
|
|
6460
|
|
|
if ($repeat_day != '' && isset($week_days[$repeat_day])) {
|
6461
|
|
|
$repeat_days[] = $week_days[$repeat_day];
|
6462
|
|
|
}
|
6463
|
|
|
}
|
6464
|
|
|
|
6465
|
|
|
$repeat_days = array_unique($repeat_days);
|
6466
|
|
|
}
|
6467
|
|
|
|
6468
|
|
|
$a_repeat_weeks = isset($gd_post['recurring_week_nos']) && trim($gd_post['recurring_week_nos']) != '' ? explode(",", trim($gd_post['recurring_week_nos'])) : array();
|
6469
|
|
|
$repeat_weeks = array();
|
6470
|
|
|
if (!empty($a_repeat_weeks)) {
|
6471
|
|
|
foreach ($a_repeat_weeks as $repeat_week) {
|
6472
|
|
|
$repeat_weeks[] = (int)$repeat_week;
|
6473
|
|
|
}
|
6474
|
|
|
|
6475
|
|
|
$repeat_weeks = array_unique($repeat_weeks);
|
6476
|
|
|
}
|
6477
|
|
|
}
|
6478
|
|
|
}
|
6479
|
|
|
|
6480
|
|
|
if (isset($gd_post['recurring_dates'])) {
|
6481
|
|
|
unset($gd_post['recurring_dates']);
|
6482
|
|
|
}
|
6483
|
|
|
|
6484
|
|
|
$gd_post['is_recurring'] = $is_recurring;
|
6485
|
|
|
$gd_post['event_date'] = $event_date;
|
6486
|
|
|
$gd_post['event_start'] = $event_date;
|
6487
|
|
|
$gd_post['event_end'] = $event_enddate;
|
6488
|
|
|
$gd_post['all_day'] = $all_day;
|
6489
|
|
|
$gd_post['starttime'] = $starttime;
|
6490
|
|
|
$gd_post['endtime'] = $endtime;
|
6491
|
|
|
|
6492
|
|
|
$gd_post['repeat_type'] = $repeat_type;
|
6493
|
|
|
$gd_post['different_times'] = $different_times;
|
6494
|
|
|
$gd_post['starttimes'] = $starttimes;
|
6495
|
|
|
$gd_post['endtimes'] = $endtimes;
|
6496
|
|
|
$gd_post['repeat_days'] = $repeat_days;
|
6497
|
|
|
$gd_post['repeat_weeks'] = $repeat_weeks;
|
6498
|
|
|
$gd_post['event_recurring_dates'] = $event_recurring_dates;
|
6499
|
|
|
$gd_post['repeat_x'] = $repeat_x;
|
6500
|
|
|
$gd_post['duration_x'] = $duration_x;
|
6501
|
|
|
$gd_post['repeat_end_type'] = $repeat_end_type;
|
6502
|
|
|
$gd_post['max_repeat'] = $max_repeat;
|
6503
|
|
|
$gd_post['repeat_end'] = $repeat_end;
|
6504
|
|
|
|
6505
|
|
|
return $gd_post;
|
6506
|
|
|
}
|
6507
|
|
|
|
6508
|
|
|
/**
|
6509
|
|
|
* Create a page.
|
6510
|
|
|
*
|
6511
|
|
|
* @since 1.0.0
|
6512
|
|
|
* @package GeoDirectory
|
6513
|
|
|
* @global object $wpdb WordPress Database object.
|
6514
|
|
|
* @global object $current_user Current user object.
|
6515
|
|
|
* @param string $slug The page slug.
|
6516
|
|
|
* @param string $option The option meta key.
|
6517
|
|
|
* @param string $page_title The page title.
|
6518
|
|
|
* @param string $page_content The page description.
|
6519
|
|
|
* @param int $post_parent Parent page ID.
|
6520
|
|
|
* @param string $status Post status.
|
6521
|
|
|
*/
|
6522
|
|
|
function geodir_create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0, $status = 'publish') {
|
6523
|
|
|
global $wpdb, $current_user;
|
6524
|
|
|
|
6525
|
|
|
$option_value = get_option($option);
|
6526
|
|
|
|
6527
|
|
|
if ($option_value > 0) :
|
6528
|
|
|
if (get_post($option_value)) :
|
6529
|
|
|
// Page exists
|
6530
|
|
|
return;
|
6531
|
|
|
endif;
|
6532
|
|
|
endif;
|
6533
|
|
|
|
6534
|
|
|
$page_found = $wpdb->get_var(
|
6535
|
|
|
$wpdb->prepare(
|
6536
|
|
|
"SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;",
|
6537
|
|
|
array($slug)
|
6538
|
|
|
)
|
6539
|
|
|
);
|
6540
|
|
|
|
6541
|
|
|
if ($page_found) :
|
6542
|
1 |
|
// Page exists
|
6543
|
|
|
if (!$option_value) update_option($option, $page_found);
|
6544
|
1 |
|
return;
|
6545
|
|
|
endif;
|
6546
|
1 |
|
|
6547
|
|
|
$page_data = array(
|
6548
|
|
|
'post_status' => $status,
|
6549
|
|
|
'post_type' => 'page',
|
6550
|
|
|
'post_author' => $current_user->ID,
|
6551
|
|
|
'post_name' => $slug,
|
6552
|
|
|
'post_title' => $page_title,
|
6553
|
1 |
|
'post_content' => $page_content,
|
6554
|
1 |
|
'post_parent' => $post_parent,
|
6555
|
1 |
|
'comment_status' => 'closed'
|
6556
|
1 |
|
);
|
6557
|
1 |
|
$page_id = wp_insert_post($page_data);
|
6558
|
1 |
|
|
6559
|
|
|
add_option($option, $page_id);
|
6560
|
1 |
|
|
6561
|
|
|
}
|
6562
|
1 |
|
|
6563
|
1 |
|
/**
|
6564
|
|
|
* Get WPML original translation element id.
|
6565
|
|
|
*
|
6566
|
|
|
* @since 1.5.3
|
6567
|
|
|
*
|
6568
|
|
|
* @global object $sitepress Sitepress WPML object.
|
6569
|
|
|
*
|
6570
|
|
|
* @param int $element_id Post ID or Term id.
|
6571
|
|
|
* @param string $element_type Element type. Ex: post_gd_place or tax_gd_placecategory.
|
6572
|
|
|
* @return Original element id.
|
6573
|
|
|
*/
|
6574
|
|
|
function geodir_imex_original_post_id($element_id, $element_type) {
|
6575
|
|
|
global $sitepress;
|
6576
|
|
|
|
6577
|
|
|
$original_element_id = $sitepress->get_original_element_id($element_id, $element_type);
|
6578
|
|
|
$element_id = $element_id != $original_element_id ? $original_element_id : '';
|
6579
|
|
|
|
6580
|
|
|
return $element_id;
|
6581
|
|
|
}
|
6582
|
|
|
|
6583
|
|
|
/*
|
6584
|
|
|
* Show admin notice if core is out of date for the current addons.
|
6585
|
|
|
*
|
6586
|
|
|
* @since 1.5.4
|
6587
|
|
|
* @package GeoDirectory
|
6588
|
|
|
*/
|
6589
|
|
|
function geodir_admin_upgrade_notice() {
|
6590
|
|
|
$class = "error";
|
6591
|
|
|
$message = __("Please update core GeoDirectory or some addons may not function correctly.","geodirectory");
|
6592
|
|
|
echo"<div class=\"$class\"> <p>$message</p></div>";
|
6593
|
|
|
}
|
6594
|
|
|
|
6595
|
|
|
/**
|
6596
|
|
|
* Displays an update message for plugin list screens.
|
6597
|
|
|
* Shows only the version updates from the current until the newest version
|
6598
|
|
|
*
|
6599
|
|
|
* @param (array) $plugin_data
|
6600
|
|
|
* @param (object) $r
|
6601
|
|
|
* @return (string) $output
|
6602
|
|
|
*/
|
6603
|
|
|
function geodire_admin_upgrade_notice( $plugin_data, $r )
|
|
|
|
|
6604
|
|
|
{
|
6605
|
|
|
// readme contents
|
6606
|
|
|
$args = array(
|
6607
|
|
|
'timeout' => 15,
|
6608
|
|
|
'redirection' => 5
|
6609
|
|
|
);
|
6610
|
|
|
$url = "http://plugins.svn.wordpress.org/geodirectory/trunk/readme.txt";
|
6611
|
|
|
$data = wp_remote_get( $url, $args );
|
6612
|
|
|
|
6613
|
|
|
if (!is_wp_error($data) && $data['response']['code'] == 200) {
|
6614
|
|
|
|
6615
|
|
|
geodir_in_plugin_update_message($data['body']);
|
6616
|
|
|
}
|
6617
|
|
|
}
|
6618
|
|
|
|
6619
|
|
|
|
6620
|
|
|
/*
|
6621
|
|
|
* @param string $content http response body
|
6622
|
|
|
*/
|
6623
|
|
|
function geodir_in_plugin_update_message($content) {
|
6624
|
|
|
// Output Upgrade Notice
|
6625
|
|
|
$matches = null;
|
6626
|
|
|
$regexp = '~==\s*Upgrade Notice\s*==\s*=\s*(.*)\s*=(.*)(=\s*' . preg_quote( GEODIRECTORY_VERSION ) . '\s*=|$)~Uis';
|
6627
|
|
|
$upgrade_notice = '';
|
6628
|
|
|
if ( preg_match( $regexp, $content, $matches ) ) {
|
6629
|
|
|
if(empty($matches)){return;}
|
6630
|
|
|
|
6631
|
|
|
$version = trim( $matches[1] );
|
6632
|
|
|
if($version && $version>GEODIRECTORY_VERSION){
|
6633
|
|
|
|
6634
|
|
|
|
6635
|
|
|
$notices = (array) preg_split('~[\r\n]+~', trim( $matches[2] ) );
|
6636
|
|
|
if ( version_compare( GEODIRECTORY_VERSION, $version, '<' ) ) {
|
6637
|
|
|
$upgrade_notice .= '<div class="geodir_plugin_upgrade_notice">';
|
6638
|
|
|
foreach ( $notices as $index => $line ) {
|
6639
|
|
|
$upgrade_notice .= wp_kses_post( preg_replace( '~\[([^\]]*)\]\(([^\)]*)\)~', '<a href="${2}">${1}</a>', $line ) );
|
6640
|
|
|
}
|
6641
|
|
|
$upgrade_notice .= '</div> ';
|
6642
|
|
|
}
|
6643
|
|
|
}
|
6644
|
|
|
}
|
6645
|
|
|
echo $upgrade_notice;
|
6646
|
|
|
}
|
6647
|
|
|
|
6648
|
|
|
/**
|
6649
|
|
|
* Display notice on geodirectory permalink settings page to don't pages settings on a different language when wpml is active.
|
6650
|
|
|
*
|
6651
|
|
|
* @package GeoDirectory
|
6652
|
|
|
* @since 1.5.7
|
6653
|
|
|
*
|
6654
|
|
|
* @global object $sitepress Sitepress WPML object.
|
6655
|
|
|
*/
|
6656
|
|
|
function geodir_wpml_permalink_setting_notice() {
|
6657
|
|
|
if (geodir_is_wpml()) {
|
6658
|
|
|
global $sitepress;
|
6659
|
|
|
$current_language = $sitepress->get_current_language();
|
6660
|
|
|
$default_language = $sitepress->get_default_language();
|
6661
|
|
|
if ($current_language != 'all' && $current_language != $default_language) {
|
6662
|
|
|
?>
|
6663
|
|
|
<div class="updated error notice-success" id="message"><p style="color:red"><strong><?php _e('Saving GeoDirectory pages settings on a different language breaks pages settings. Try to save after switching to default language.', 'geodirectory');?></strong></p></div>
|
6664
|
|
|
<?php
|
6665
|
|
|
}
|
6666
|
|
|
}
|
6667
|
|
|
}
|
6668
|
|
|
|
6669
|
|
|
/**
|
6670
|
|
|
* Get the statuses to skip during GD export listings.
|
6671
|
|
|
*
|
6672
|
|
|
* @package GeoDirectory
|
6673
|
|
|
* @since 1.6.0
|
6674
|
|
|
*
|
6675
|
|
|
* @param array Listing statuses to be skipped.
|
6676
|
|
|
*/
|
6677
|
|
|
function geodir_imex_export_skip_statuses() {
|
6678
|
|
|
$statuses = array( 'trash', 'auto-draft' );
|
6679
|
|
|
|
6680
|
|
|
/**
|
6681
|
|
|
* Filter the statuses to skip during GD export listings.
|
6682
|
|
|
*
|
6683
|
|
|
* @since 1.6.0
|
6684
|
|
|
* @package GeoDirectory
|
6685
|
|
|
*
|
6686
|
|
|
* @param array $statuses Listing statuses to be skipped.
|
6687
|
|
|
*/
|
6688
|
|
|
$statuses = apply_filters( 'geodir_imex_export_skip_statuses', $statuses );
|
6689
|
|
|
|
6690
|
|
|
return $statuses;
|
6691
|
|
|
}
|
6692
|
|
|
|
6693
|
|
|
/**
|
6694
|
|
|
* Dequeue jQuery chosen javascript.
|
6695
|
|
|
*
|
6696
|
|
|
* Fix conflicts between jQuery chosen javascripts.
|
6697
|
1 |
|
*
|
6698
|
|
|
* @package GeoDirectory
|
6699
|
|
|
* @since 1.6.3
|
6700
|
|
|
*/
|
6701
|
|
|
function geodir_admin_dequeue_scripts() {
|
6702
|
|
|
// EDD
|
6703
|
|
|
if (wp_script_is('jquery-chosen', 'enqueued')) {
|
6704
|
|
|
wp_dequeue_script('jquery-chosen');
|
6705
|
|
|
}
|
6706
|
|
|
|
6707
|
1 |
|
// Ultimate Addons for Visual Composer
|
6708
|
|
|
if (wp_script_is('ultimate-vc-backend-script', 'enqueued')) {
|
6709
|
1 |
|
wp_dequeue_script('ultimate-vc-backend-script');
|
6710
|
|
|
}
|
6711
|
|
|
}
|
6712
|
|
|
|
6713
|
|
|
/**
|
6714
|
|
|
* Get the SQL where clause part to filter posts in import/export.
|
6715
|
|
|
*
|
6716
|
|
|
* @package GeoDirectory
|
6717
|
|
|
* @since 1.6.4
|
6718
|
|
|
*
|
6719
|
|
|
* @global object $wpdb WordPress Database object.
|
6720
|
|
|
*
|
6721
|
|
|
* @param string $where The SQL where clause part. Default empty.
|
6722
|
|
|
* @param string $post_type The post type.
|
6723
|
|
|
* @return string SQL where clause part.
|
6724
|
|
|
*/
|
6725
|
|
|
function geodir_imex_get_filter_where($where = '', $post_type = '') {
|
|
|
|
|
6726
|
|
|
global $wpdb;
|
6727
|
|
|
|
6728
|
|
|
$filters = !empty( $_REQUEST['gd_imex'] ) && is_array( $_REQUEST['gd_imex'] ) ? $_REQUEST['gd_imex'] : NULL;
|
6729
|
|
|
|
6730
|
|
|
if ( !empty( $filters ) ) {
|
6731
|
|
|
foreach ( $filters as $field => $value ) {
|
6732
|
|
|
switch ($field) {
|
6733
|
|
|
case 'start_date':
|
6734
|
|
|
$where .= " AND `" . $wpdb->posts . "`.`post_date` >= '" . sanitize_text_field( $value ) . " 00:00:00'";
|
6735
|
|
|
break;
|
6736
|
|
|
case 'end_date':
|
6737
|
|
|
$where .= " AND `" . $wpdb->posts . "`.`post_date` <= '" . sanitize_text_field( $value ) . " 23:59:59'";
|
6738
|
|
|
break;
|
6739
|
|
|
}
|
6740
|
|
|
}
|
6741
|
|
|
}
|
6742
|
|
|
|
6743
|
|
|
return $where;
|
6744
|
|
|
}
|
6745
|
1 |
|
add_filter('geodir_get_posts_count', 'geodir_imex_get_filter_where', 10, 2);
|
6746
|
|
|
add_filter('geodir_get_export_posts', 'geodir_imex_get_filter_where', 10, 2);
|
6747
|
1 |
|
|
6748
|
|
|
/*
|
6749
|
1 |
|
* Look at doing menu items this way, must be customiser ready
|
6750
|
|
|
* @todo research below
|
6751
|
|
|
*/
|
6752
|
|
|
// GeoDirectory Menu Items
|
|
|
|
|
6753
|
|
|
/*
|
6754
|
|
|
|
6755
|
|
|
function geodir_register_menu_metabox() {
|
6756
|
|
|
$custom_param = array( 0 => 'This param will be passed to my_render_menu_metabox' );
|
6757
|
|
|
|
6758
|
|
|
add_meta_box( 'geodir-menu-metabox', 'GeoDirectory Items', 'geodir_render_menu_metabox', 'nav-menus', 'side', 'default', $custom_param );
|
6759
|
|
|
}
|
6760
|
|
|
add_action( 'admin_head-nav-menus.php', 'geodir_register_menu_metabox' );
|
6761
|
|
|
if(is_admin()){
|
6762
|
1 |
|
|
6763
|
|
|
//add_action( 'customize_register', 'geodir_register_menu_metabox' );
|
6764
|
|
|
}
|
6765
|
|
|
*/
|
6766
|
|
|
/**
|
6767
|
|
|
* Displays a menu metabox
|
6768
|
|
|
*
|
6769
|
|
|
* @param string $object Not used.
|
6770
|
|
|
* @param array $args Parameters and arguments. If you passed custom params to add_meta_box(),
|
6771
|
|
|
* they will be in $args['args']
|
6772
|
|
|
*/
|
6773
|
|
|
/*
|
|
|
|
|
6774
|
|
|
function geodir_render_menu_metabox( $object, $args ) {
|
6775
|
|
|
global $nav_menu_selected_id;
|
6776
|
|
|
|
6777
|
|
|
// Create an array of objects that imitate Post objects
|
6778
|
|
|
$my_items = array(
|
6779
|
|
|
(object) array(
|
6780
|
|
|
'ID' => 0,
|
6781
|
|
|
'db_id' => 0,
|
6782
|
|
|
'menu_item_parent' => 0,
|
6783
|
|
|
'object_id' => 1,
|
6784
|
|
|
'post_parent' => 0,
|
6785
|
|
|
'type' => 'custom',
|
6786
|
|
|
'object' => 'my-object-slug',
|
6787
|
|
|
'type_label' => 'My Cool Plugin',
|
6788
|
|
|
'title' => 'Custom Link 1',
|
6789
|
|
|
'url' => home_url( '/jobs/' ),
|
6790
|
|
|
'target' => '',
|
6791
|
|
|
'attr_title' => '',
|
6792
|
|
|
'description' => '123',
|
6793
|
|
|
'classes' => array(),
|
6794
|
|
|
'xfn' => '',
|
6795
|
|
|
),
|
6796
|
|
|
(object) array(
|
6797
|
|
|
'ID' => 2,
|
6798
|
|
|
'db_id' => 0,
|
6799
|
|
|
'menu_item_parent' => 0,
|
6800
|
|
|
'object_id' => 1,
|
6801
|
|
|
'post_parent' => 0,
|
6802
|
|
|
'type' => 'custom',
|
6803
|
|
|
'object' => 'my-object-slug',
|
6804
|
|
|
'type_label' => 'My Cool Plugin',
|
6805
|
|
|
'title' => 'Custom Link 2',
|
6806
|
|
|
'url' => home_url( '/custom-link-2/' ),
|
6807
|
|
|
'target' => '',
|
6808
|
|
|
'attr_title' => '',
|
6809
|
|
|
'description' => '123',
|
6810
|
|
|
'classes' => array(),
|
6811
|
|
|
'xfn' => '',
|
6812
|
|
|
),
|
6813
|
|
|
(object) array(
|
6814
|
|
|
'ID' => 3,
|
6815
|
|
|
'db_id' => 0,
|
6816
|
|
|
'menu_item_parent' => 0,
|
6817
|
|
|
'object_id' => 1,
|
6818
|
|
|
'post_parent' => 0,
|
6819
|
|
|
'type' => 'custom',
|
6820
|
|
|
'object' => 'my-object-slug',
|
6821
|
|
|
'type_label' => 'My Cool Plugin',
|
6822
|
|
|
'title' => 'Custom Link 3',
|
6823
|
|
|
'url' => home_url( '/custom-link-3/' ),
|
6824
|
|
|
'target' => '',
|
6825
|
|
|
'attr_title' => '',
|
6826
|
|
|
'description' => '123',
|
6827
|
|
|
'classes' => array(),
|
6828
|
|
|
'xfn' => '',
|
6829
|
|
|
),
|
6830
|
|
|
);
|
6831
|
|
|
$db_fields = false;
|
6832
|
|
|
// If your links will be hierarchical, adjust the $db_fields array bellow
|
6833
|
|
|
if ( false ) {
|
6834
|
|
|
$db_fields = array( 'parent' => 'parent', 'id' => 'post_parent' );
|
6835
|
|
|
}
|
6836
|
|
|
$walker = new Walker_Nav_Menu_Checklist( $db_fields );
|
6837
|
|
|
|
6838
|
|
|
$removed_args = array(
|
6839
|
|
|
'action',
|
6840
|
|
|
'customlink-tab',
|
6841
|
|
|
'edit-menu-item',
|
6842
|
|
|
'menu-item',
|
6843
|
|
|
'page-tab',
|
6844
|
|
|
'_wpnonce',
|
6845
|
|
|
); ?>
|
6846
|
|
|
<div id="my-plugin-div">
|
6847
|
|
|
<div id="tabs-panel-my-plugin-all" class="tabs-panel tabs-panel-active">
|
6848
|
|
|
<ul id="my-plugin-checklist-pop" class="categorychecklist form-no-clear" >
|
6849
|
|
|
<?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $my_items ), 0, (object) array( 'walker' => $walker ) ); ?>
|
6850
|
|
|
</ul>
|
6851
|
|
|
|
6852
|
|
|
<p class="button-controls">
|
6853
|
|
|
<span class="list-controls">
|
6854
|
|
|
<a href="<?php
|
6855
|
|
|
echo esc_url(add_query_arg(
|
6856
|
|
|
array(
|
6857
|
|
|
'my-plugin-all' => 'all',
|
6858
|
|
|
'selectall' => 1,
|
6859
|
|
|
),
|
6860
|
|
|
remove_query_arg( $removed_args )
|
6861
|
|
|
));
|
6862
|
|
|
?>#my-menu-test-metabox" class="select-all"><?php _e( 'Select All' ); ?></a>
|
6863
|
|
|
</span>
|
6864
|
|
|
|
6865
|
|
|
<span class="add-to-menu">
|
6866
|
|
|
<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-my-plugin-menu-item" id="submit-my-plugin-div" />
|
6867
|
|
|
<span class="spinner"></span>
|
6868
|
|
|
</span>
|
6869
|
|
|
</p>
|
6870
|
|
|
</div>
|
6871
|
|
|
<?php
|
6872
|
|
|
}
|
6873
|
|
|
*/ |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.