| @@ -1,25 +1,27 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly; | |
| 2 | +if (!defined('ABSPATH')) exit; // Exit if accessed directly; | |
| 3 | 3 | |
| 4 | -class Wdk_backendajax extends Winter_MVC_Controller { | |
| 4 | +class Wdk_backendajax extends Winter_MVC_Controller | |
| 5 | +{ | |
| 5 | 6 | |
| 6 | - public function __construct(){ | |
| 7 | - ini_set('display_errors',1); | |
| 8 | - ini_set('display_startup_errors',1); | |
| 9 | - error_reporting(-1); | |
| 10 | - parent::__construct(); | |
| 7 | + public function __construct() | |
| 8 | + { | |
| 9 | + if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 10 | + ini_set('display_errors', 1); | |
| 11 | + ini_set('display_startup_errors', 1); | |
| 12 | + error_reporting(-1); | |
| 13 | + } | |
| 14 | + parent::__construct(); | |
| 11 | 15 | |
| 12 | 16 | $this->data['is_ajax'] = true; |
| 13 | - | |
| 14 | - } | |
| 15 | - | |
| 16 | - public function index(&$output=NULL, $atts=array()) | |
| 17 | - { | |
| 17 | + } | |
| 18 | 18 | |
| 19 | - } | |
| 19 | + public function index(&$output = NULL, $atts = array()) | |
| 20 | + { | |
| 21 | + } | |
| 20 | 22 | |
| 21 | - | |
| 23 | + | |
| 22 | 24 | public function plugin_news() |
| 23 | 25 | { |
| 24 | 26 | $data = array(); |
| 25 | 27 | $data['message'] = __('No message returned!', 'wpdirectorykit'); |
| @@ -26,114 +28,134 @@ | ||
| 26 | 28 | $data['success'] = false; |
| 27 | 29 | $data['response'] = NULL; |
| 28 | 30 | $data['rss'] = array(); |
| 29 | 31 | |
| 32 | + /* protect */ | |
| 33 | + if(!current_user_can( 'read' ) && !wmvc_user_in_role('administrator')) { | |
| 34 | + $this->output($data); | |
| 35 | + } | |
| 36 | + | |
| 30 | 37 | //https://wpdirectorykit.com/wp/last_news.php?f=news.json |
| 31 | 38 | |
| 32 | - $request = wp_remote_get( 'https://wpdirectorykit.com/wp/last_news.php?f=news.json' ); | |
| 39 | + $request = wp_remote_get('https://wpdirectorykit.com/wp/last_news.php?f=news.json'); | |
| 33 | 40 | |
| 34 | 41 | // request failed |
| 35 | - if ( is_wp_error( $request ) ) { | |
| 42 | + if (is_wp_error($request)) { | |
| 36 | 43 | $data['response'] = $request; |
| 37 | 44 | } |
| 38 | - $code = (int) wp_remote_retrieve_response_code( $request ); | |
| 45 | + $code = (int) wp_remote_retrieve_response_code($request); | |
| 39 | 46 | |
| 40 | 47 | // make sure the fetch was successful |
| 41 | - if (empty($data['response']) && $code == 200 ) { | |
| 42 | - $response = wp_remote_retrieve_body( $request ); | |
| 48 | + if (empty($data['response']) && $code == 200) { | |
| 49 | + $response = wp_remote_retrieve_body($request); | |
| 43 | 50 | |
| 44 | 51 | // Decode the json |
| 45 | - $output = json_decode( $response ); | |
| 52 | + $output = json_decode($response); | |
| 46 | 53 | $count = 0; |
| 47 | 54 | foreach ($output as $key => $value) { |
| 48 | 55 | $data['rss'][] = array( |
| 49 | - 'date'=>wdk_get_date(wmvc_show_data('date', $value, date('Y-m-d H:i:s'), TRUE, TRUE), false), | |
| 50 | - 'title'=>wmvc_show_data('title', $value, '', TRUE, TRUE), | |
| 51 | - 'link'=>wmvc_show_data('link', $value, '', TRUE, TRUE), | |
| 56 | + 'date' => wdk_get_date(wmvc_show_data('date', $value, gmdate('Y-m-d H:i:s'), TRUE, TRUE), false), | |
| 57 | + 'title' => wmvc_show_data('title', $value, '', TRUE, TRUE), | |
| 58 | + 'link' => wmvc_show_data('link', $value, '', TRUE, TRUE), | |
| 52 | 59 | ); |
| 53 | 60 | $count++; |
| 54 | 61 | |
| 55 | - if($count > 10) break; | |
| 62 | + if ($count > 10) break; | |
| 56 | 63 | } |
| 57 | 64 | } else { |
| 58 | - $data['response'] = get_status_header_desc( $code ); | |
| 65 | + $data['response'] = get_status_header_desc($code); | |
| 59 | 66 | } |
| 60 | 67 | |
| 61 | - $this->output($data); | |
| 68 | + $this->output($data); | |
| 62 | 69 | } |
| 63 | - | |
| 64 | - public function plugin_upgrader($output="", $atts=array(), $instance=NULL) | |
| 70 | + | |
| 71 | + public function plugin_upgrader($output = "", $atts = array(), $instance = NULL) | |
| 65 | 72 | { |
| 66 | 73 | $data = array(); |
| 67 | 74 | $data['message'] = __('No message returned!', 'wpdirectorykit'); |
| 68 | 75 | $data['success'] = false; |
| 69 | 76 | |
| 77 | + /* protect */ | |
| 78 | + if(!current_user_can( 'install_plugins' ) && !wmvc_user_in_role('administrator')) { | |
| 79 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 80 | + $this->output($data); | |
| 81 | + } | |
| 82 | + | |
| 83 | + // Check _wpnonce | |
| 84 | + check_admin_referer( 'wdk-plugin_upgrader', '_wpnonce' ); | |
| 85 | + | |
| 70 | 86 | ob_start(); |
| 71 | - | |
| 87 | + | |
| 72 | 88 | $parameters = array(); |
| 73 | - | |
| 74 | - foreach ($_POST as $key => $value) { | |
| 75 | - $parameters[$key] = sanitize_text_field($value); | |
| 76 | - } | |
| 77 | 89 | |
| 78 | - $source = 'https://downloads.wordpress.org/plugin/'.$parameters['slug'].'.zip'; | |
| 90 | + foreach ($_POST as $key => $value) { | |
| 91 | + $parameters[$key] = sanitize_text_field($value); | |
| 92 | + } | |
| 79 | 93 | |
| 80 | - if(!empty($parameters['source'])) | |
| 94 | + $source = 'https://downloads.wordpress.org/plugin/' . $parameters['slug'] . '.zip'; | |
| 95 | + | |
| 96 | + if (!empty($parameters['source'])) | |
| 81 | 97 | $source = $parameters['source']; |
| 82 | 98 | |
| 83 | - if ( ! class_exists( 'Plugin_Upgrader', false ) ) { | |
| 99 | + if (!class_exists('Plugin_Upgrader', false)) { | |
| 84 | 100 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 85 | 101 | } |
| 86 | 102 | |
| 87 | - $upgrader = new Plugin_Upgrader(new PluginInstallerSkinSilentWdk( $skin_args )); | |
| 103 | + $upgrader = new Plugin_Upgrader(new PluginInstallerSkinSilentWdk($skin_args)); | |
| 88 | 104 | |
| 89 | - if(!file_exists(WP_PLUGIN_DIR .'/'.$parameters['slug'].'/'.$parameters['slug'].'.php')) | |
| 90 | - { | |
| 105 | + if (!file_exists(WP_PLUGIN_DIR . '/' . $parameters['slug'] . '/' . $parameters['slug'] . '.php')) { | |
| 91 | 106 | //exit(WP_PLUGIN_DIR .'/'.$parameters['slug'].'/'.$parameters['slug'].'.php'); |
| 92 | 107 | |
| 93 | - $upgrader->install( $source ); | |
| 108 | + $upgrader->install($source); | |
| 94 | 109 | } |
| 95 | 110 | |
| 96 | 111 | ob_clean(); |
| 97 | 112 | |
| 98 | - $activate = activate_plugin( $parameters['slug'].'/'.$parameters['slug'].'.php' ); | |
| 113 | + $activate = activate_plugin($parameters['slug'] . '/' . $parameters['slug'] . '.php'); | |
| 99 | 114 | |
| 100 | - if ( is_wp_error( $activate ) ) | |
| 101 | - { | |
| 102 | - $data['message'] = wp_kses_post( $activate->get_error_message() ); | |
| 115 | + if (is_wp_error($activate)) { | |
| 116 | + $data['message'] = wp_kses_post($activate->get_error_message()); | |
| 103 | 117 | $data['success'] = false; |
| 104 | - } | |
| 105 | - else | |
| 106 | - { | |
| 118 | + } else { | |
| 107 | 119 | $data['success'] = true; |
| 108 | 120 | } |
| 109 | 121 | |
| 110 | 122 | $data['slug'] = $parameters['slug']; |
| 111 | - | |
| 123 | + | |
| 112 | 124 | $data['parameters'] = $parameters; |
| 113 | 125 | |
| 114 | 126 | //$data['sql'] = $this->db->last_query(); |
| 115 | - $this->output($data); | |
| 127 | + $this->output($data); | |
| 116 | 128 | } |
| 117 | 129 | |
| 118 | - public function install_content($output="", $atts=array(), $instance=NULL) | |
| 130 | + public function install_content($output = "", $atts = array(), $instance = NULL) | |
| 119 | 131 | { |
| 120 | 132 | $data = array(); |
| 121 | 133 | $data['message'] = __('No message returned!', 'wpdirectorykit'); |
| 122 | 134 | $data['success'] = false; |
| 123 | 135 | |
| 136 | + | |
| 137 | + /* protect */ | |
| 138 | + if(!current_user_can( 'install_plugins' ) && !wmvc_user_in_role('administrator')) { | |
| 139 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 140 | + $this->output($data); | |
| 141 | + } | |
| 142 | + | |
| 143 | + // Check _wpnonce | |
| 144 | + check_admin_referer( 'wdk-install_content', '_wpnonce' ); | |
| 145 | + | |
| 124 | 146 | ob_start(); |
| 125 | - | |
| 147 | + | |
| 126 | 148 | $parameters = array(); |
| 127 | - | |
| 128 | - foreach ($_POST as $key => $value) { | |
| 129 | - $parameters[$key] = sanitize_text_field($value); | |
| 130 | - } | |
| 131 | 149 | |
| 132 | - if ( ! class_exists( '\WP_Importer' ) ) { | |
| 133 | - require ABSPATH . '/wp-admin/includes/class-wp-importer.php'; | |
| 134 | - } | |
| 150 | + foreach ($_POST as $key => $value) { | |
| 151 | + $parameters[$key] = sanitize_text_field($value); | |
| 152 | + } | |
| 135 | 153 | |
| 154 | + if (!class_exists('\WP_Importer')) { | |
| 155 | + require ABSPATH . '/wp-admin/includes/class-wp-importer.php'; | |
| 156 | + } | |
| 157 | + | |
| 136 | 158 | require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-logger.php'; |
| 137 | 159 | require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-logger-html.php'; |
| 138 | 160 | require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-logger-serversentevents.php'; |
| 139 | 161 | require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-wxr-importer.php'; |
| @@ -144,27 +166,24 @@ | ||
| 144 | 166 | ); |
| 145 | 167 | |
| 146 | 168 | $logger = new WP_Importer_Logger(); |
| 147 | 169 | |
| 148 | - $importer = new WXR_Importer( $importer_options ); | |
| 170 | + $importer = new WXR_Importer($importer_options); | |
| 149 | 171 | |
| 150 | 172 | $importer->set_logger($logger); |
| 151 | 173 | |
| 152 | 174 | $current_theme = wp_get_theme(); |
| 153 | 175 | |
| 154 | - $tmp_file = download_url( $current_theme->get( 'AuthorURI' ).'/demo_themes/'.$current_theme->get( 'TextDomain' ).'.xml' ); | |
| 176 | + $tmp_file = download_url($current_theme->get('AuthorURI') . '/demo_themes/' . $current_theme->get('TextDomain') . '.xml'); | |
| 155 | 177 | |
| 156 | 178 | $results_importer = $importer->import($tmp_file); |
| 157 | 179 | |
| 158 | 180 | ob_clean(); |
| 159 | 181 | |
| 160 | - if ( is_wp_error( $results_importer ) ) | |
| 161 | - { | |
| 162 | - $data['message'] = wp_kses_post( $results_importer->get_error_message() ); | |
| 182 | + if (is_wp_error($results_importer)) { | |
| 183 | + $data['message'] = wp_kses_post($results_importer->get_error_message()); | |
| 163 | 184 | $data['success'] = false; |
| 164 | - } | |
| 165 | - else | |
| 166 | - { | |
| 185 | + } else { | |
| 167 | 186 | $data['success'] = true; |
| 168 | 187 | } |
| 169 | 188 | |
| 170 | 189 | $data['parameters'] = $parameters; |
| @@ -169,37 +188,46 @@ | ||
| 169 | 188 | |
| 170 | 189 | $data['parameters'] = $parameters; |
| 171 | 190 | |
| 172 | 191 | //$data['sql'] = $this->db->last_query(); |
| 173 | - $this->output($data); | |
| 192 | + $this->output($data); | |
| 174 | 193 | } |
| 175 | 194 | |
| 176 | - public function install_listings($output="", $atts=array(), $instance=NULL) | |
| 195 | + public function install_listings($output = "", $atts = array(), $instance = NULL) | |
| 177 | 196 | { |
| 178 | - $this->load->load_helper('listing'); | |
| 179 | - $this->load->model('listing_m'); | |
| 180 | - $this->load->model('listingfield_m'); | |
| 197 | + $this->load->load_helper('listing'); | |
| 198 | + $this->load->model('listing_m'); | |
| 199 | + $this->load->model('listingfield_m'); | |
| 181 | 200 | |
| 182 | 201 | $data = array(); |
| 183 | 202 | $data['message'] = __('No message returned!', 'wpdirectorykit'); |
| 184 | 203 | $data['success'] = false; |
| 204 | + | |
| 205 | + /* protect */ | |
| 206 | + if(!current_user_can( 'install_plugins' ) && !wmvc_user_in_role('administrator')) { | |
| 207 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 208 | + $this->output($data); | |
| 209 | + } | |
| 185 | 210 | |
| 211 | + // Check _wpnonce | |
| 212 | + check_admin_referer( 'wdk-install_listings', '_wpnonce' ); | |
| 213 | + | |
| 186 | 214 | ob_start(); |
| 187 | - | |
| 215 | + | |
| 188 | 216 | $parameters = array(); |
| 189 | - | |
| 190 | - foreach ($_POST as $key => $value) { | |
| 191 | - $parameters[$key] = sanitize_text_field($value); | |
| 192 | - } | |
| 193 | 217 | |
| 218 | + foreach ($_POST as $key => $value) { | |
| 219 | + $parameters[$key] = sanitize_text_field($value); | |
| 220 | + } | |
| 221 | + | |
| 194 | 222 | $data['parameters'] = $parameters; |
| 195 | 223 | |
| 196 | 224 | //$data['sql'] = $this->db->last_query(); |
| 197 | - $this->output($data); | |
| 225 | + $this->output($data); | |
| 198 | 226 | } |
| 199 | 227 | |
| 200 | - | |
| 201 | - public function generated_listings_images_path () | |
| 228 | + | |
| 229 | + public function generated_listings_images_path() | |
| 202 | 230 | { |
| 203 | 231 | $data = array(); |
| 204 | 232 | $data['message'] = ''; |
| 205 | 233 | $data['popup_text_success'] = ''; |
| @@ -204,28 +232,36 @@ | ||
| 204 | 232 | $data['message'] = ''; |
| 205 | 233 | $data['popup_text_success'] = ''; |
| 206 | 234 | $data['popup_text_error'] = ''; |
| 207 | 235 | $data['parameters'] = $_POST; |
| 208 | - $data['success'] = false; | |
| 236 | + $data['success'] = false; | |
| 209 | 237 | |
| 238 | + /* protect */ | |
| 239 | + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) { | |
| 240 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 241 | + $this->output($data); | |
| 242 | + } | |
| 243 | + | |
| 244 | + // Check _wpnonce | |
| 245 | + check_admin_referer( 'wdk-generated_listings_images_path', '_wpnonce' ); | |
| 246 | + | |
| 210 | 247 | $this->load->load_helper('listing'); |
| 211 | - $this->load->model('listing_m'); | |
| 248 | + $this->load->model('listing_m'); | |
| 212 | 249 | $listings = $this->listing_m->get(); |
| 213 | 250 | |
| 214 | - foreach($listings as $listing) { | |
| 251 | + foreach ($listings as $listing) { | |
| 215 | 252 | $image_ids = explode(',', $listing->listing_images); |
| 216 | - $listing_data = array('listing_images_path' => '','listing_images_path_medium' => ''); | |
| 217 | - if(is_array($image_ids)) { | |
| 253 | + $listing_data = array('listing_images_path' => '', 'listing_images_path_medium' => ''); | |
| 254 | + if (is_array($image_ids)) { | |
| 218 | 255 | foreach ($image_ids as $image_id) { |
| 219 | - if(is_numeric($image_id)) | |
| 220 | - { | |
| 221 | - $image_path = wp_get_original_image_path( $image_id); | |
| 222 | - if(!$image_path) continue; | |
| 256 | + if (is_numeric($image_id)) { | |
| 257 | + $image_path = wp_get_original_image_path($image_id); | |
| 258 | + if (!$image_path) continue; | |
| 223 | 259 | |
| 224 | 260 | /* path of image */ |
| 225 | - $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path); | |
| 261 | + $next_path = str_replace(WP_CONTENT_DIR . '/uploads/', '', $image_path); | |
| 226 | 262 | |
| 227 | - if(!empty($listing_data['listing_images_path'])) | |
| 263 | + if (!empty($listing_data['listing_images_path'])) | |
| 228 | 264 | $listing_data['listing_images_path'] .= ','; |
| 229 | 265 | |
| 230 | 266 | $listing_data['listing_images_path'] .= $next_path; |
| 231 | 267 | } |
| @@ -230,19 +266,19 @@ | ||
| 230 | 266 | $listing_data['listing_images_path'] .= $next_path; |
| 231 | 267 | } |
| 232 | 268 | |
| 233 | 269 | $image_url = wp_get_attachment_image_url($image_id, 'large'); |
| 234 | - if($image_url) { | |
| 235 | - $parsed = parse_url($image_url); | |
| 236 | - $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8); | |
| 237 | - | |
| 238 | - if(!empty($listing_data['listing_images_path_medium'])) | |
| 270 | + if ($image_url) { | |
| 271 | + $parsed = wp_parse_url($image_url); | |
| 272 | + $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/') + 8); | |
| 273 | + | |
| 274 | + if (!empty($listing_data['listing_images_path_medium'])) | |
| 239 | 275 | $listing_data['listing_images_path_medium'] .= ','; |
| 240 | - | |
| 276 | + | |
| 241 | 277 | $listing_data['listing_images_path_medium'] .= $next_path; |
| 242 | 278 | } |
| 243 | 279 | } |
| 244 | - } | |
| 280 | + } | |
| 245 | 281 | |
| 246 | 282 | $this->listing_m->insert($listing_data, $listing->post_id); |
| 247 | 283 | } |
| 248 | 284 | |
| @@ -247,9 +283,9 @@ | ||
| 247 | 283 | } |
| 248 | 284 | |
| 249 | 285 | $this->load->model('location_m'); |
| 250 | 286 | $locations = $this->location_m->get(); |
| 251 | - if($locations)foreach($locations as $location) { | |
| 287 | + if ($locations) foreach ($locations as $location) { | |
| 252 | 288 | $save_data = array( |
| 253 | 289 | "parent_id" => $location->parent_id, |
| 254 | 290 | ); |
| 255 | 291 | $save_data['icon_path'] = wdk_generate_path_image($location->icon_id); |
| @@ -259,9 +295,9 @@ | ||
| 259 | 295 | } |
| 260 | 296 | |
| 261 | 297 | $this->load->model('category_m'); |
| 262 | 298 | $categories = $this->category_m->get(); |
| 263 | - if($categories)foreach($categories as $category) { | |
| 299 | + if ($categories) foreach ($categories as $category) { | |
| 264 | 300 | $save_data = array( |
| 265 | 301 | "parent_id" => $category->parent_id, |
| 266 | 302 | ); |
| 267 | 303 | $save_data['icon_path'] = wdk_generate_path_image($category->icon_id); |
| @@ -272,12 +308,12 @@ | ||
| 272 | 308 | } |
| 273 | 309 | |
| 274 | 310 | $data['success'] = true; |
| 275 | 311 | $data['popup_text_success'] = __('images path of listings,locations,categories generated', 'wpdirectorykit'); |
| 276 | - $this->output($data); | |
| 312 | + $this->output($data); | |
| 277 | 313 | } |
| 278 | - | |
| 279 | - public function optimization_listingfields_table () | |
| 314 | + | |
| 315 | + public function optimization_listingfields_table() | |
| 280 | 316 | { |
| 281 | 317 | $data = array(); |
| 282 | 318 | $data['message'] = ''; |
| 283 | 319 | $data['popup_text_success'] = ''; |
| @@ -282,13 +318,22 @@ | ||
| 282 | 318 | $data['message'] = ''; |
| 283 | 319 | $data['popup_text_success'] = ''; |
| 284 | 320 | $data['popup_text_error'] = ''; |
| 285 | 321 | $data['parameters'] = $_POST; |
| 286 | - $data['success'] = false; | |
| 322 | + $data['success'] = false; | |
| 287 | 323 | |
| 324 | + /* protect */ | |
| 325 | + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) { | |
| 326 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 327 | + $this->output($data); | |
| 328 | + } | |
| 329 | + | |
| 330 | + // Check _wpnonce | |
| 331 | + check_admin_referer( 'wdk-optimization_listingfields_table', '_wpnonce' ); | |
| 332 | + | |
| 288 | 333 | $this->load->load_helper('listing'); |
| 289 | - $this->load->model('listingfield_m'); | |
| 290 | - $this->load->model('field_m'); | |
| 334 | + $this->load->model('listingfield_m'); | |
| 335 | + $this->load->model('field_m'); | |
| 291 | 336 | $listingfields = $this->listingfield_m->get_available_fields(); |
| 292 | 337 | |
| 293 | 338 | global $wpdb; |
| 294 | 339 | |
| @@ -293,33 +338,34 @@ | ||
| 293 | 338 | global $wpdb; |
| 294 | 339 | |
| 295 | 340 | /* remove if missing */ |
| 296 | 341 | foreach ($listingfields as $listingfield => $field_data) { |
| 297 | - if(strpos($listingfield, 'field_') !== FALSE) { | |
| 342 | + if (strpos($listingfield, 'field_') !== FALSE) { | |
| 298 | 343 | list($prefix, $field_id, $field_type) = explode('_', $listingfield); |
| 299 | 344 | |
| 300 | - if(!wdk_field_option($field_id, 'field_type', false)) { | |
| 301 | - $wpdb->query( "ALTER TABLE {$this->listingfield_m->_table_name} DROP COLUMN $listingfield;" ); | |
| 345 | + if (!wdk_field_option($field_id, 'field_type', false)) { | |
| 346 | + $wpdb->query("ALTER TABLE {$this->listingfield_m->_table_name} DROP COLUMN $listingfield;"); | |
| 302 | 347 | } |
| 303 | 348 | } |
| 304 | 349 | } |
| 305 | 350 | |
| 306 | 351 | /* add if missing listingfield and change from varchar to TEXT */ |
| 307 | - $this->db->where(array('field_type !='=> 'SECTION')); | |
| 352 | + $this->db->where(array('field_type !=' => 'SECTION')); | |
| 308 | 353 | $fields = $this->field_m->get(); |
| 309 | 354 | |
| 310 | 355 | $listingfields = $this->listingfield_m->get_available_fields(); |
| 311 | 356 | foreach ($fields as $field) { |
| 312 | - $column_name ='field_'.$field->idfield.'_'.$field->field_type; | |
| 313 | - if(!isset($listingfields[$column_name])) { | |
| 314 | - $this->listingfield_m->create_table_column(array('field_type'=>$field->field_type), $field->idfield); | |
| 357 | + $column_name = 'field_' . $field->idfield . '_' . $field->field_type; | |
| 358 | + if (!isset($listingfields[$column_name])) { | |
| 359 | + $this->listingfield_m->create_table_column(array('field_type' => $field->field_type), $field->idfield); | |
| 315 | 360 | } else { |
| 316 | 361 | |
| 317 | 362 | /* change from varchar to TEXT */ |
| 318 | - if(stripos($listingfields[$column_name]->Type , 'VARCHAR') !== FALSE | |
| 319 | - && ($field->field_type == 'INPUTBOX' || $field->field_type == 'DROPDOWN' || $field->field_type == 'DROPDOWNMULTIPLE')) | |
| 320 | - { | |
| 321 | - $wpdb->query( "ALTER TABLE `{$this->listingfield_m->_table_name}` CHANGE `$column_name` `$column_name` TEXT NULL DEFAULT NULL;" ); | |
| 363 | + if ( | |
| 364 | + stripos($listingfields[$column_name]->Type, 'VARCHAR') !== FALSE | |
| 365 | + && ($field->field_type == 'INPUTBOX' || $field->field_type == 'DROPDOWN' || $field->field_type == 'DROPDOWNMULTIPLE') | |
| 366 | + ) { | |
| 367 | + $wpdb->query("ALTER TABLE `{$this->listingfield_m->_table_name}` CHANGE `$column_name` `$column_name` TEXT NULL DEFAULT NULL;"); | |
| 322 | 368 | } |
| 323 | 369 | } |
| 324 | 370 | } |
| 325 | 371 | |
| @@ -324,9 +370,9 @@ | ||
| 324 | 370 | } |
| 325 | 371 | |
| 326 | 372 | $data['success'] = true; |
| 327 | 373 | $data['popup_text_success'] = __('Table listingfields optimized', 'wpdirectorykit'); |
| 328 | - $this->output($data); | |
| 374 | + $this->output($data); | |
| 329 | 375 | } |
| 330 | 376 | |
| 331 | 377 | public function update_depend() |
| 332 | 378 | { |
| @@ -334,18 +380,27 @@ | ||
| 334 | 380 | $data['message'] = __('No message returned!', 'wpdirectorykit'); |
| 335 | 381 | $data['success'] = false; |
| 336 | 382 | $data['parameters'] = $_POST; |
| 337 | 383 | |
| 384 | + /* protect */ | |
| 385 | + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) { | |
| 386 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 387 | + $this->output($data); | |
| 388 | + } | |
| 389 | + | |
| 390 | + // Check _wpnonce | |
| 391 | + check_admin_referer( 'wdk-update_depend', '_wpnonce' ); | |
| 392 | + | |
| 338 | 393 | $this->load->load_helper('listing'); |
| 339 | - $this->load->model('dependfields_m'); | |
| 394 | + $this->load->model('dependfields_m'); | |
| 340 | 395 | |
| 341 | - if(wmvc_show_data('field_id', $data['parameters'], false) && wmvc_show_data('main_field', $data['parameters'], false)) { | |
| 396 | + if (wmvc_show_data('field_id', $data['parameters'], false) && wmvc_show_data('main_field', $data['parameters'], false)) { | |
| 342 | 397 | |
| 343 | 398 | $hidden_fields = array(); |
| 344 | 399 | foreach ($data['parameters'] as $key => $value) { |
| 345 | - if(strpos($key, 'field_hide_') !== FALSE) { | |
| 346 | - $field_id = str_replace('field_hide_','',$key); | |
| 347 | - if(is_intval($field_id)) { | |
| 400 | + if (strpos($key, 'field_hide_') !== FALSE) { | |
| 401 | + $field_id = str_replace('field_hide_', '', $key); | |
| 402 | + if (is_intval($field_id)) { | |
| 348 | 403 | $hidden_fields[] = $field_id; |
| 349 | 404 | } |
| 350 | 405 | } |
| 351 | 406 | } |
| @@ -350,23 +405,592 @@ | ||
| 350 | 405 | } |
| 351 | 406 | } |
| 352 | 407 | |
| 353 | 408 | $data_insert = array( |
| 354 | - 'main_field'=>wmvc_show_data('main_field', $data['parameters'], false), | |
| 355 | - 'field_id'=> wmvc_show_data('field_id', $data['parameters'], false), | |
| 356 | - 'hidden_fields_list'=>join(',',$hidden_fields), | |
| 409 | + 'main_field' => wmvc_show_data('main_field', $data['parameters'], false), | |
| 410 | + 'field_id' => wmvc_show_data('field_id', $data['parameters'], false), | |
| 411 | + 'hidden_fields_list' => join(',', $hidden_fields), | |
| 357 | 412 | ); |
| 358 | 413 | |
| 359 | - $this->dependfields_m->delete_where(array('field_id' => $data_insert['field_id'],'main_field' => $data_insert['main_field'])); | |
| 414 | + $this->dependfields_m->delete_where(array('field_id' => $data_insert['field_id'], 'main_field' => $data_insert['main_field'])); | |
| 360 | 415 | $this->dependfields_m->insert($data_insert); |
| 361 | 416 | } |
| 362 | 417 | |
| 363 | - $this->output($data); | |
| 418 | + $this->output($data); | |
| 419 | + } | |
| 364 | 420 | |
| 421 | + public function depend_copy_on_subcategories() | |
| 422 | + { | |
| 423 | + $data = array(); | |
| 424 | + $data['message'] = __('No message returned!', 'wpdirectorykit'); | |
| 425 | + $data['success'] = false; | |
| 426 | + $data['parameters'] = $_POST; | |
| 427 | + | |
| 428 | + /* protect */ | |
| 429 | + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) { | |
| 430 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 431 | + $this->output($data); | |
| 432 | + } | |
| 433 | + | |
| 434 | + // Check _wpnonce | |
| 435 | + check_admin_referer( 'wdk_depend_copy_on_subcategories', '_wpnonce' ); | |
| 436 | + | |
| 437 | + $this->load->load_helper('listing'); | |
| 438 | + $this->load->model('dependfields_m'); | |
| 439 | + | |
| 440 | + if (wmvc_show_data('category_id', $data['parameters'], false)) { | |
| 441 | + | |
| 442 | + $sub_categories_ids = wdk_category_get_all_childs(intval($data['parameters']['category_id'])); | |
| 443 | + | |
| 444 | + $depends_list = wdk_depend_get_hidden_fields(intval($data['parameters']['category_id'])); | |
| 445 | + | |
| 446 | + | |
| 447 | + $data['sub_categories_ids'] = $sub_categories_ids; | |
| 448 | + $data['depends_list'] = $depends_list; | |
| 449 | + | |
| 450 | + if($sub_categories_ids){ | |
| 451 | + $this->dependfields_m->delete_where(array('field_id IN ('.join(',',$sub_categories_ids).')'=>NULL)); | |
| 452 | + foreach ($sub_categories_ids as $key => $id) { | |
| 453 | + # code... | |
| 454 | + $data_insert = array( | |
| 455 | + 'main_field' => 'categories', | |
| 456 | + 'field_id' => $id, | |
| 457 | + 'hidden_fields_list' => $depends_list, | |
| 458 | + ); | |
| 459 | + $this->dependfields_m->insert($data_insert); | |
| 460 | + } | |
| 461 | + } | |
| 462 | + } | |
| 463 | + | |
| 464 | + $this->output($data); | |
| 365 | 465 | } |
| 366 | - | |
| 367 | - private function output($data, $print = TRUE) { | |
| 368 | - if($print) { | |
| 466 | + | |
| 467 | + public function generated_strings() | |
| 468 | + { | |
| 469 | + $data = array(); | |
| 470 | + $data['message'] = ''; | |
| 471 | + $data['popup_text_success'] = ''; | |
| 472 | + $data['popup_text_error'] = ''; | |
| 473 | + $data['parameters'] = $_POST; | |
| 474 | + $data['success'] = false; | |
| 475 | + | |
| 476 | + /* protect */ | |
| 477 | + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) { | |
| 478 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 479 | + $this->output($data); | |
| 480 | + } | |
| 481 | + | |
| 482 | + // Check _wpnonce | |
| 483 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 484 | + | |
| 485 | + global $wp_filesystem; | |
| 486 | + // Initialize the WP filesystem, no more using 'file-put-contents' function | |
| 487 | + if (empty($wp_filesystem)) { | |
| 488 | + require_once(ABSPATH . '/wp-admin/includes/file.php'); | |
| 489 | + WP_Filesystem(); | |
| 490 | + } | |
| 491 | + // @codingStandardsIgnoreEnd | |
| 492 | + | |
| 493 | + $this->load->load_helper('listing'); | |
| 494 | + $this->load->model('location_m'); | |
| 495 | + $this->load->model('category_m'); | |
| 496 | + | |
| 497 | + | |
| 498 | + /* locations strings */ | |
| 499 | + $this->db->select('location_title'); | |
| 500 | + $this->db->from($this->location_m->_table_name); | |
| 501 | + $query = $this->db->get(); | |
| 502 | + $count_file = 1; | |
| 503 | + $limit_size = '80000'; | |
| 504 | + $file_strings_content = '<?php '; | |
| 505 | + if ($this->db->num_rows() > 0) { | |
| 506 | + foreach ($this->db->results() as $location) { | |
| 507 | + $file_strings_content .= '__(\'' . addslashes($location->location_title) . '\',\'wpdirectorykit\');' . "\n"; | |
| 508 | + | |
| 509 | + if (strlen($file_strings_content) > $limit_size) { | |
| 510 | + $file_strings_content .= "\n" . '?>'; | |
| 511 | + $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/locations_' . $count_file . '.php', $file_strings_content); | |
| 512 | + | |
| 513 | + /* create new file */ | |
| 514 | + $file_strings_content = '<?php '; | |
| 515 | + $count_file++; | |
| 516 | + } | |
| 517 | + } | |
| 518 | + $file_strings_content .= "\n" . '?>'; | |
| 519 | + | |
| 520 | + if (!empty($file_strings_content)) | |
| 521 | + $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/locations_' . $count_file . '.php', $file_strings_content); | |
| 522 | + } | |
| 523 | + | |
| 524 | + | |
| 525 | + /* categories strings */ | |
| 526 | + $this->db->select('category_title'); | |
| 527 | + $this->db->from($this->category_m->_table_name); | |
| 528 | + $query = $this->db->get(); | |
| 529 | + $count_file = 1; | |
| 530 | + $limit_size = '80000'; | |
| 531 | + $file_strings_content = '<?php '; | |
| 532 | + if ($this->db->num_rows() > 0) { | |
| 533 | + foreach ($this->db->results() as $category) { | |
| 534 | + $file_strings_content .= '__(\'' . addslashes($category->category_title) . '\',\'wpdirectorykit\');' . "\n"; | |
| 535 | + | |
| 536 | + if (strlen($file_strings_content) > $limit_size) { | |
| 537 | + $file_strings_content .= "\n" . '?>'; | |
| 538 | + $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/categories_' . $count_file . '.php', $file_strings_content); | |
| 539 | + | |
| 540 | + /* create new file */ | |
| 541 | + $file_strings_content = '<?php '; | |
| 542 | + $count_file++; | |
| 543 | + } | |
| 544 | + } | |
| 545 | + $file_strings_content .= "\n" . '?>'; | |
| 546 | + | |
| 547 | + if (!empty($file_strings_content)) | |
| 548 | + $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/categories_' . $count_file . '.php', $file_strings_content); | |
| 549 | + } | |
| 550 | + | |
| 551 | + /* fields */ | |
| 552 | + | |
| 553 | + $this->load->model('field_m'); | |
| 554 | + $this->db->select('field_label,prefix,suffix,values_list,hint,placeholder'); | |
| 555 | + $this->db->from($this->field_m->_table_name); | |
| 556 | + $query = $this->db->get(); | |
| 557 | + $count_file = 1; | |
| 558 | + $limit_size = '70000'; | |
| 559 | + $file_strings_content = '<?php '; | |
| 560 | + if ($this->db->num_rows() > 0) { | |
| 561 | + foreach ($this->db->results() as $field) { | |
| 562 | + | |
| 563 | + if (!empty($field->field_label)) | |
| 564 | + $file_strings_content .= '__(\'' . addslashes($field->field_label) . '\',\'wpdirectorykit\');' . "\n"; | |
| 565 | + | |
| 566 | + if (!empty($field->prefix)) | |
| 567 | + $file_strings_content .= '__(\'' . addslashes($field->prefix) . '\',\'wpdirectorykit\');' . "\n"; | |
| 568 | + | |
| 569 | + if (!empty($field->suffix)) | |
| 570 | + $file_strings_content .= '__(\'' . addslashes($field->suffix) . '\',\'wpdirectorykit\');' . "\n"; | |
| 571 | + | |
| 572 | + if (!empty($field->values_list)) | |
| 573 | + $file_strings_content .= '__(\'' . addslashes($field->values_list) . '\',\'wpdirectorykit\');' . "\n"; | |
| 574 | + | |
| 575 | + if (!empty($field->placeholder)) | |
| 576 | + $file_strings_content .= '__(\'' . addslashes($field->placeholder) . '\',\'wpdirectorykit\');' . "\n"; | |
| 577 | + | |
| 578 | + if (strlen($file_strings_content) > $limit_size) { | |
| 579 | + $file_strings_content .= "\n" . '?>'; | |
| 580 | + $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/fields_' . $count_file . '.php', $file_strings_content); | |
| 581 | + | |
| 582 | + /* create new file */ | |
| 583 | + $file_strings_content = '<?php '; | |
| 584 | + $count_file++; | |
| 585 | + } | |
| 586 | + } | |
| 587 | + $file_strings_content .= "\n" . '?>'; | |
| 588 | + | |
| 589 | + if (!empty($file_strings_content)) | |
| 590 | + $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/fields_' . $count_file . '.php', $file_strings_content); | |
| 591 | + } | |
| 592 | + | |
| 593 | + | |
| 594 | + $data['success'] = true; | |
| 595 | + $data['popup_text_success'] = __('Strings generated', 'wpdirectorykit'); | |
| 596 | + $this->output($data); | |
| 597 | + } | |
| 598 | + | |
| 599 | + public function optimization_db_fields() | |
| 600 | + { | |
| 601 | + $data = array(); | |
| 602 | + $data['message'] = ''; | |
| 603 | + $data['popup_text_success'] = ''; | |
| 604 | + $data['popup_text_error'] = ''; | |
| 605 | + $data['parameters'] = $_POST; | |
| 606 | + $data['success'] = false; | |
| 607 | + | |
| 608 | + /* protect */ | |
| 609 | + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) { | |
| 610 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 611 | + $this->output($data); | |
| 612 | + } | |
| 613 | + | |
| 614 | + // Check _wpnonce | |
| 615 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 616 | + | |
| 617 | + $this->load->load_helper('listing'); | |
| 618 | + $this->load->model('field_m'); | |
| 619 | + $this->load->model('listingfield_m'); | |
| 620 | + | |
| 621 | + global $wpdb; | |
| 622 | + | |
| 623 | + $existing_listing_fields = $this->listingfield_m->get_available_fields(); | |
| 624 | + unset($existing_listing_fields['idlistings_fields'],$existing_listing_fields['post_id'],$existing_listing_fields['lang_code']); | |
| 625 | + | |
| 626 | + $fields = $this->field_m->get(); | |
| 627 | + foreach ($fields as $key => $field) { | |
| 628 | + // add exits fields | |
| 629 | + $field_col = 'field_'.$field->idfield.'_'.$field->field_type; | |
| 630 | + if(isset($existing_listing_fields[$field_col])) { | |
| 631 | + unset($existing_listing_fields[$field_col]); | |
| 632 | + } | |
| 633 | + } | |
| 634 | + $table_listing_fields = $wpdb->prefix . 'wdk_listings_fields'; | |
| 635 | + if(!empty($existing_listing_fields)) foreach ($existing_listing_fields as $field_listing_col => $field_listing) { | |
| 636 | + if(substr($field_listing_col, 0, 6) == 'field_') { | |
| 637 | + $wpdb->query( $wpdb->prepare( "ALTER TABLE `{$table_listing_fields}` DROP `$field_listing_col`;" ) ); | |
| 638 | + } | |
| 639 | + } | |
| 640 | + | |
| 641 | + | |
| 642 | + /* fields */ | |
| 643 | + $data['success'] = true; | |
| 644 | + $data['popup_text_success'] = __('Fields optimization', 'wpdirectorykit'); | |
| 645 | + $this->output($data); | |
| 646 | + } | |
| 647 | + | |
| 648 | + public function loading_sublistings() | |
| 649 | + { | |
| 650 | + $data = array(); | |
| 651 | + $data['message'] = ''; | |
| 652 | + $data['popup_text_success'] = ''; | |
| 653 | + $data['popup_text_error'] = ''; | |
| 654 | + $data['parameters'] = $_POST; | |
| 655 | + $data['success'] = false; | |
| 656 | + $data['results'] = array(); | |
| 657 | + | |
| 658 | + /* protect */ | |
| 659 | + if(!current_user_can('edit_own_listings') && !wmvc_user_in_role('administrator')) { | |
| 660 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 661 | + $this->output($data); | |
| 662 | + } | |
| 663 | + | |
| 664 | + // Check _wpnonce | |
| 665 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 666 | + | |
| 667 | + $listing_id = intval(wmvc_show_data('listing_id', $data['parameters'])); | |
| 668 | + | |
| 669 | + if (empty($listing_id)) { | |
| 670 | + $data['popup_text_error'] = __('Missing Listing', 'wpdirectorykit'); | |
| 671 | + } | |
| 672 | + | |
| 673 | + if (empty($data['popup_text_error'])) { | |
| 674 | + | |
| 675 | + $this->load->load_helper('listing'); | |
| 676 | + $this->load->model('listing_m'); | |
| 677 | + | |
| 678 | + | |
| 679 | + $this->db->where($this->db->prefix . 'wdk_listings.post_id IN(' . wdk_field_value('listing_related_ids', $listing_id) . ')', null, false); | |
| 680 | + $this->db->order_by('FIELD(' . $this->db->prefix . 'wdk_listings.post_id, ' . wdk_field_value('listing_related_ids', $listing_id) . ')'); | |
| 681 | + | |
| 682 | + $results = $this->listing_m->get(); | |
| 683 | + | |
| 684 | + foreach ($results as $sublisting) { | |
| 685 | + $_listing = array(); | |
| 686 | + $_listing['post_id'] = wdk_field_value('post_id', $sublisting); | |
| 687 | + $_listing['post_title'] = wdk_field_value('post_title', $sublisting); | |
| 688 | + $_listing['post_content_short'] = wmvc_character_limiter(wdk_field_value('post_content', $sublisting), 30); | |
| 689 | + $_listing['date'] = wdk_get_date(wdk_field_value('date', $sublisting), false); | |
| 690 | + $_listing['location'] = wdk_field_value('location_title', $sublisting); | |
| 691 | + $_listing['category'] = wdk_field_value('category_title', $sublisting); | |
| 692 | + $_listing['counter_views'] = wdk_field_value('counter_views', $sublisting); | |
| 693 | + $_listing['counter_results_views'] = wdk_field_value('counter_results_views', $sublisting); | |
| 694 | + $_listing['image_src'] = wdk_image_src($sublisting); | |
| 695 | + $_listing['listing_remove_url'] = esc_url(get_admin_url() . "admin.php?page=wdk&function=delete&id=" . wdk_field_value('post_id', $sublisting)); | |
| 696 | + $_listing['listing_view_url'] = get_permalink($sublisting); | |
| 697 | + $_listing['listing_edit_url'] = esc_url(get_admin_url() . "admin.php?page=wdk_listing&id=" . wdk_field_value('post_id', $sublisting)); | |
| 698 | + $_listing['listing_dash_remove_url'] = ''; | |
| 699 | + $_listing['listing_dash_edit_url'] = ''; | |
| 700 | + if(function_exists(' wdk_dash_url')) { | |
| 701 | + $_listing['listing_dash_remove_url'] = wdk_dash_url("dash_page=listings&table_action=table&action=delete&ids=" . wdk_field_value('post_id', $sublisting)); | |
| 702 | + $_listing['listing_dash_edit_url'] = wdk_dash_url("dash_page=listings&function=edit&id=" . wdk_field_value('post_id', $sublisting)); | |
| 703 | + } | |
| 704 | + | |
| 705 | + $data['results'][] = $_listing; | |
| 706 | + | |
| 707 | + } | |
| 708 | + } | |
| 709 | + | |
| 710 | + $data['success'] = true; | |
| 711 | + $this->output($data); | |
| 712 | + } | |
| 713 | + | |
| 714 | + public function remove_listing() | |
| 715 | + { | |
| 716 | + $data = array(); | |
| 717 | + $data['message'] = ''; | |
| 718 | + $data['popup_text_success'] = ''; | |
| 719 | + $data['popup_text_error'] = ''; | |
| 720 | + $data['parameters'] = $_POST; | |
| 721 | + $data['success'] = false; | |
| 722 | + $data['results'] = array(); | |
| 723 | + | |
| 724 | + /* protect */ | |
| 725 | + if(!current_user_can('edit_own_listings') && !wmvc_user_in_role('administrator')) { | |
| 726 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 727 | + $this->output($data); | |
| 728 | + } | |
| 729 | + | |
| 730 | + // Check _wpnonce | |
| 731 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 732 | + | |
| 733 | + $listing_id = intval(wmvc_show_data('listing_id', $data['parameters'])); | |
| 734 | + | |
| 735 | + if (empty($listing_id)) { | |
| 736 | + $data['popup_text_error'] = __('Missing Listing', 'wpdirectorykit'); | |
| 737 | + } | |
| 738 | + | |
| 739 | + if (empty($data['popup_text_error'])) { | |
| 740 | + | |
| 741 | + $this->load->load_helper('listing'); | |
| 742 | + $this->load->model('listing_m'); | |
| 743 | + | |
| 744 | + $listing = $this->listing_m->get($listing_id, TRUE); | |
| 745 | + $parent_listing = $this->listing_m->get($listing->listing_parent_post_id, TRUE); | |
| 746 | + | |
| 747 | + $this->listing_m->delete($listing_id); | |
| 748 | + | |
| 749 | + if(isset($parent_listing->listing_related_ids) && !empty($parent_listing->listing_related_ids)) { | |
| 750 | + $related_ids = trim(str_replace(','.$listing_id.'','', ','.$parent_listing->listing_related_ids.','),','); | |
| 751 | + $this->listing_m->insert(array('listing_related_ids' => $related_ids), $listing->listing_parent_post_id); | |
| 752 | + } | |
| 753 | + | |
| 754 | + $data['success'] = true; | |
| 755 | + } | |
| 756 | + | |
| 757 | + | |
| 758 | + $this->output($data); | |
| 759 | + } | |
| 760 | + | |
| 761 | + public function reinstall_page() | |
| 762 | + { | |
| 763 | + $data = array(); | |
| 764 | + $data['message'] = ''; | |
| 765 | + $data['popup_text_success'] = ''; | |
| 766 | + $data['popup_text_error'] = ''; | |
| 767 | + $data['parameters'] = $_POST; | |
| 768 | + $data['success'] = false; | |
| 769 | + $data['page_id'] = false; | |
| 770 | + $data['page_title'] = false; | |
| 771 | + $data['results'] = array(); | |
| 772 | + /* protect */ | |
| 773 | + if(!wmvc_user_in_role('administrator')) { | |
| 774 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 775 | + $this->output($data); | |
| 776 | + } | |
| 777 | + | |
| 778 | + // Check _wpnonce | |
| 779 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 780 | + | |
| 781 | + $page = sanitize_text_field(wmvc_show_data('arg', $data['parameters'])); | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + // Import elementor templates | |
| 786 | + switch($page) { | |
| 787 | + case 'wdk_listing_page': | |
| 788 | + $new_page = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas'); | |
| 789 | + $this->elementor_assign($new_page->ID, 'page-listing-preview.json'); | |
| 790 | + update_option('wdk_listing_page', $new_page->ID); | |
| 791 | + $data['page_title'] = esc_html__('Listing Preview', 'wpdirectorykit'); | |
| 792 | + break; | |
| 793 | + case 'wdk_results_page': | |
| 794 | + $new_page = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas'); | |
| 795 | + $this->elementor_assign($new_page->ID, 'page-results-listings.json'); | |
| 796 | + update_option('wdk_results_page', $new_page->ID); | |
| 797 | + $data['page_title'] = esc_html__('Results Listings', 'wpdirectorykit'); | |
| 798 | + break; | |
| 799 | + } | |
| 800 | + | |
| 801 | + if (empty($new_page)) { | |
| 802 | + $data['popup_text_error'] = __('Page not Created', 'wpdirectorykit'); | |
| 803 | + } else { | |
| 804 | + $data['page_id'] = $new_page->ID; | |
| 805 | + } | |
| 806 | + | |
| 807 | + if (empty($data['popup_text_error'])) { | |
| 808 | + $data['success'] = true; | |
| 809 | + } | |
| 810 | + | |
| 811 | + $this->output($data); | |
| 812 | + } | |
| 813 | + | |
| 814 | + public function wdk_save_ai_search_fields() | |
| 815 | + { | |
| 816 | + $data = array(); | |
| 817 | + $data['message'] = ''; | |
| 818 | + $data['popup_text_success'] = ''; | |
| 819 | + $data['popup_text_error'] = ''; | |
| 820 | + $data['parameters'] = $_POST; | |
| 821 | + $data['success'] = false; | |
| 822 | + $data['page_id'] = false; | |
| 823 | + $data['page_title'] = false; | |
| 824 | + $data['results'] = array(); | |
| 825 | + | |
| 826 | + /* protect */ | |
| 827 | + if(!wmvc_user_in_role('administrator')) { | |
| 828 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 829 | + $this->output($data); | |
| 830 | + } | |
| 831 | + | |
| 832 | + // Check _wpnonce | |
| 833 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 834 | + | |
| 835 | + $fields = isset($_POST['fields']) | |
| 836 | + ? array_filter( | |
| 837 | + array_map('intval', (array) wp_unslash($_POST['fields'])), | |
| 838 | + function($val) { return is_int($val) && $val > 0; } | |
| 839 | + ) | |
| 840 | + : []; | |
| 841 | + | |
| 842 | + | |
| 843 | + update_option( | |
| 844 | + 'wdk_ai_search_fields', | |
| 845 | + $fields | |
| 846 | + ); | |
| 847 | + | |
| 848 | + $data['popup_text_success'] = __('AI Search fields updated successfully.', 'wpdirectorykit'); | |
| 849 | + | |
| 850 | + if (empty($data['popup_text_error'])) { | |
| 851 | + $data['success'] = true; | |
| 852 | + } | |
| 853 | + | |
| 854 | + $this->output($data); | |
| 855 | + } | |
| 856 | + | |
| 857 | + public function upload_image() | |
| 858 | + { | |
| 859 | + $data = array(); | |
| 860 | + $data['message'] = ''; | |
| 861 | + $data['popup_text_success'] = ''; | |
| 862 | + $data['popup_text_error'] = ''; | |
| 863 | + $data['parameters'] = $_POST; | |
| 864 | + $data['success'] = false; | |
| 865 | + $data['page_id'] = false; | |
| 866 | + $data['page_title'] = false; | |
| 867 | + $data['results'] = array(); | |
| 868 | + /* protect */ | |
| 869 | + if(!wmvc_user_in_role('administrator')) { | |
| 870 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 871 | + $this->output($data); | |
| 872 | + } | |
| 873 | + | |
| 874 | + // Check _wpnonce | |
| 875 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 876 | + | |
| 877 | + if(!empty($data['parameters']['image'])) | |
| 878 | + foreach (explode(',', sanitize_text_field($_POST['image'])) as $key => $image_or_src) { | |
| 879 | + if(empty($image_or_src)) continue; | |
| 880 | + $image_id = wmvc_add_wp_image($image_or_src); | |
| 881 | + $image_url = wp_get_attachment_image_url($image_id, 'large'); | |
| 882 | + | |
| 883 | + $data['results'][] = [ | |
| 884 | + 'image_id'=> $image_id, | |
| 885 | + 'image_url'=> $image_url, | |
| 886 | + ]; | |
| 887 | + } | |
| 888 | + | |
| 889 | + | |
| 890 | + if (empty($data['popup_text_error'])) { | |
| 891 | + $data['success'] = true; | |
| 892 | + } | |
| 893 | + | |
| 894 | + $this->output($data); | |
| 895 | + } | |
| 896 | + | |
| 897 | + | |
| 898 | + /* Create Page */ | |
| 899 | + private function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0, $rebuild = FALSE) | |
| 900 | + { | |
| 901 | + | |
| 902 | + $post_id = NULL; | |
| 903 | + | |
| 904 | + // Delete posts and rebuild | |
| 905 | + if($rebuild) { | |
| 906 | + | |
| 907 | + $post = wdk_page_by_title($post_title, 'OBJECT', 'page' ); | |
| 908 | + if(!empty($post)) | |
| 909 | + { | |
| 910 | + wp_delete_post($post->ID, true); | |
| 911 | + $post=NULL; | |
| 912 | + } | |
| 913 | + if(!empty($post)) | |
| 914 | + $post_id = $post->ID; | |
| 915 | + } | |
| 916 | + | |
| 917 | + | |
| 918 | + if(empty($post_id)) | |
| 919 | + { | |
| 920 | + $error_obj = NULL; | |
| 921 | + $post_insert = array( | |
| 922 | + 'post_title' => wp_strip_all_tags( $post_title ), | |
| 923 | + 'post_content' => $post_content, | |
| 924 | + 'post_status' => 'publish', | |
| 925 | + 'post_type' => 'page', | |
| 926 | + 'post_author' => get_current_user_id(), | |
| 927 | + 'post_category' => array(1,2), | |
| 928 | + 'page_template' => $post_template, | |
| 929 | + 'post_parent' => $post_parent | |
| 930 | + ); | |
| 931 | + $post_id = wp_insert_post( $post_insert, $error_obj ); | |
| 932 | + } | |
| 933 | + | |
| 934 | + $post_insert = get_post( $post_id ); | |
| 935 | + | |
| 936 | + return $post_insert; | |
| 937 | + } | |
| 938 | + | |
| 939 | + /* Elementor Import Template */ | |
| 940 | + private function elementor_assign($page_id, $json_template_name = '') | |
| 941 | + { | |
| 942 | + | |
| 943 | + $file = false; | |
| 944 | + | |
| 945 | + if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name)) | |
| 946 | + { | |
| 947 | + $file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name; | |
| 948 | + } | |
| 949 | + elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name)) | |
| 950 | + { | |
| 951 | + $file = get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name; | |
| 952 | + } | |
| 953 | + elseif(file_exists( WPDIRECTORYKIT_PATH. '/demo-data/'.$json_template_name)) | |
| 954 | + { | |
| 955 | + $file = WPDIRECTORYKIT_PATH.'demo-data/'.$json_template_name; | |
| 956 | + } | |
| 957 | + | |
| 958 | + if(!$file || !class_exists('Elementor\Plugin')) | |
| 959 | + { | |
| 960 | + return false; | |
| 961 | + } | |
| 962 | + | |
| 963 | + $page_template = get_page_template_slug( $page_id ); | |
| 964 | + | |
| 965 | + add_post_meta( $page_id, '_elementor_edit_mode', 'builder' ); | |
| 966 | + | |
| 967 | + global $wp_filesystem; | |
| 968 | + // Initialize the WP filesystem, no more using 'file-put-contents' function | |
| 969 | + if (empty($wp_filesystem)) { | |
| 970 | + WP_Filesystem(); | |
| 971 | + } | |
| 972 | + | |
| 973 | + $string = $wp_filesystem->get_contents($file); | |
| 974 | + | |
| 975 | + $json_template = json_decode($string, true); | |
| 976 | + $elements = $json_template['content']; | |
| 977 | + | |
| 978 | + $data = array( | |
| 979 | + 'elements' => $elements, | |
| 980 | + 'settings' => array('post_status'=>'autosave', 'template'=>$page_template), | |
| 981 | + ); | |
| 982 | + // @codingStandardsIgnoreStart | |
| 983 | + $document = Elementor\Plugin::$instance->documents->get( $page_id, false ); | |
| 984 | + // @codingStandardsIgnoreEnd | |
| 985 | + return $document->save( $data ); | |
| 986 | + } | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + private function output($data, $print = TRUE) | |
| 991 | + { | |
| 992 | + if ($print) { | |
| 369 | 993 | header('Pragma: no-cache'); |
| 370 | 994 | header('Cache-Control: no-store, no-cache'); |
| 371 | 995 | header('Content-Type: application/json; charset=utf8'); |
| 372 | 996 | //header('Content-Length: '.$length); // special characters causing troubles |
| @@ -375,48 +999,58 @@ | ||
| 375 | 999 | } else { |
| 376 | 1000 | return $data; |
| 377 | 1001 | } |
| 378 | 1002 | } |
| 379 | - | |
| 380 | 1003 | } |
| 381 | 1004 | |
| 382 | -if ( ! class_exists( '\Plugin_Upgrader', false ) ) { | |
| 383 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 1005 | +if (!class_exists('\Plugin_Upgrader', false)) { | |
| 1006 | + require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 384 | 1007 | } |
| 385 | 1008 | |
| 386 | 1009 | /** |
| 387 | 1010 | * WordPress class extended for on-the-fly plugin installations. |
| 388 | 1011 | */ |
| 389 | -class PluginInstallerSkinSilentWdk extends \WP_Upgrader_Skin { | |
| 1012 | +class PluginInstallerSkinSilentWdk extends \WP_Upgrader_Skin | |
| 1013 | +{ | |
| 390 | 1014 | |
| 391 | - /** | |
| 392 | - * Empty out the header of its HTML content. | |
| 393 | - */ | |
| 394 | - public function header() {} | |
| 1015 | + /** | |
| 1016 | + * Empty out the header of its HTML content. | |
| 1017 | + */ | |
| 1018 | + public function header() | |
| 1019 | + { | |
| 1020 | + } | |
| 395 | 1021 | |
| 396 | - /** | |
| 397 | - * Empty out the footer of its HTML content. | |
| 398 | - */ | |
| 399 | - public function footer() {} | |
| 1022 | + /** | |
| 1023 | + * Empty out the footer of its HTML content. | |
| 1024 | + */ | |
| 1025 | + public function footer() | |
| 1026 | + { | |
| 1027 | + } | |
| 400 | 1028 | |
| 401 | - /** | |
| 402 | - * Empty out the footer of its HTML content. | |
| 403 | - * | |
| 404 | - * @param string $string | |
| 405 | - * @param mixed ...$args Optional text replacements. | |
| 406 | - */ | |
| 407 | - public function feedback( $string, ...$args ) {} | |
| 1029 | + /** | |
| 1030 | + * Empty out the footer of its HTML content. | |
| 1031 | + * | |
| 1032 | + * @param string $string | |
| 1033 | + * @param mixed ...$args Optional text replacements. | |
| 1034 | + */ | |
| 1035 | + public function feedback($string, ...$args) | |
| 1036 | + { | |
| 1037 | + } | |
| 408 | 1038 | |
| 409 | - /** | |
| 410 | - * Empty out JavaScript output that calls function to decrement the update counts. | |
| 411 | - * | |
| 412 | - * @param string $type Type of update count to decrement. | |
| 413 | - */ | |
| 414 | - public function decrement_update_count( $type ) {} | |
| 1039 | + /** | |
| 1040 | + * Empty out JavaScript output that calls function to decrement the update counts. | |
| 1041 | + * | |
| 1042 | + * @param string $type Type of update count to decrement. | |
| 1043 | + */ | |
| 1044 | + public function decrement_update_count($type) | |
| 1045 | + { | |
| 1046 | + } | |
| 415 | 1047 | |
| 416 | - /** | |
| 417 | - * Empty out the error HTML content. | |
| 418 | - * | |
| 419 | - * @param string|WP_Error $errors A string or WP_Error object of the install error/s. | |
| 420 | - */ | |
| 421 | - public function error( $errors ) {} | |
| 1048 | + /** | |
| 1049 | + * Empty out the error HTML content. | |
| 1050 | + * | |
| 1051 | + * @param string|WP_Error $errors A string or WP_Error object of the install error/s. | |
| 1052 | + */ | |
| 1053 | + public function error($errors) | |
| 1054 | + { | |
| 1055 | + } | |
| 422 | 1056 | } |