PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.1.5
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.1.5
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / wp-all-export.php
wp-all-export Last commit date
actions 8 years ago classes 8 years ago config 8 years ago controllers 8 years ago dist 8 years ago filters 8 years ago helpers 8 years ago history 8 years ago i18n 8 years ago libraries 8 years ago models 8 years ago sessions 8 years ago shortcodes 8 years ago src 8 years ago static 8 years ago views 8 years ago banner-772x250.png 8 years ago readme.txt 8 years ago schema.php 8 years ago screenshot-1.png 8 years ago screenshot-2.png 8 years ago wp-all-export.php 8 years ago wpae_api.php 8 years ago
wp-all-export.php
811 lines
1 <?php
2 /*
3 Plugin Name: WP All Export
4 Plugin URI: http://www.wpallimport.com/export/
5 Description: Export any post type to a CSV or XML file. Edit the exported data, and then re-import it later using WP All Import.
6 Version: 1.1.5
7 Author: Soflyy
8 */
9
10 require_once(__DIR__.'/classes/CdataStrategyFactory.php');
11
12 if( ! defined( 'PMXE_SESSION_COOKIE' ) )
13 define( 'PMXE_SESSION_COOKIE', '_pmxe_session' );
14
15 /**
16 * Plugin root dir with forward slashes as directory separator regardless of actuall DIRECTORY_SEPARATOR value
17 * @var string
18 */
19 define('PMXE_ROOT_DIR', str_replace('\\', '/', dirname(__FILE__)));
20 /**
21 * Plugin root url for referencing static content
22 * @var string
23 */
24 define('PMXE_ROOT_URL', rtrim(plugin_dir_url(__FILE__), '/'));
25
26 if ( class_exists('PMXE_Plugin') and PMXE_EDITION == "paid"){
27
28 function pmxe_notice(){
29
30 ?>
31 <div class="error">
32 <p>
33 <?php printf(__('Please de-activate and remove the free version of the WP All Export before activating the paid version.', 'wp_all_export_plugin')); ?>
34 </p>
35 </div>
36 <?php
37
38 deactivate_plugins( str_replace('\\', '/', dirname(__FILE__)) . '/wp-all-export.php');
39
40 }
41
42 add_action('admin_notices', 'pmxe_notice');
43
44 }
45 else {
46
47 /**
48 * Plugin prefix for making names unique (be aware that this variable is used in conjuction with naming convention,
49 * i.e. in order to change it one must not only modify this constant but also rename all constants, classes and functions which
50 * names composed using this prefix)
51 * @var string
52 */
53 define('PMXE_PREFIX', 'pmxe_');
54
55 define('PMXE_VERSION', '1.1.5');
56
57 define('PMXE_EDITION', 'free');
58
59 /**
60 * Plugin root uploads folder name
61 * @var string
62 */
63 define('WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY', 'wpallexport');
64 /**
65 * Plugin uploads folder name
66 * @var string
67 */
68 define('WP_ALL_EXPORT_UPLOADS_DIRECTORY', WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'exports');
69
70 /**
71 * Plugin temp folder name
72 * @var string
73 */
74 define('WP_ALL_EXPORT_TEMP_DIRECTORY', WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'temp');
75
76 /**
77 * Plugin temp folder name
78 * @var string
79 */
80 define('WP_ALL_EXPORT_CRON_DIRECTORY', WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'exports');
81
82 /**
83 * Main plugin file, Introduces MVC pattern
84 *
85 * @singletone
86 * @author Pavel Kulbakin <p.kulbakin@gmail.com>
87 */
88 final class PMXE_Plugin {
89 /**
90 * Singletone instance
91 * @var PMXE_Plugin
92 */
93 protected static $instance;
94
95 /**
96 * Plugin options
97 * @var array
98 */
99 protected $options = array();
100
101 /**
102 * Plugin root dir
103 * @var string
104 */
105 const ROOT_DIR = PMXE_ROOT_DIR;
106 /**
107 * Plugin root URL
108 * @var string
109 */
110 const ROOT_URL = PMXE_ROOT_URL;
111 /**
112 * Prefix used for names of shortcodes, action handlers, filter functions etc.
113 * @var string
114 */
115 const PREFIX = PMXE_PREFIX;
116 /**
117 * Plugin file path
118 * @var string
119 */
120 const FILE = __FILE__;
121 /**
122 * Max allowed file size (bytes) to import in default mode
123 * @var int
124 */
125 const LARGE_SIZE = 0; // all files will importing in large import mode
126
127 /**
128 * WP All Import temp folder
129 * @var string
130 */
131 const TEMP_DIRECTORY = WP_ALL_EXPORT_TEMP_DIRECTORY;
132 /**
133 * WP All Import uploads folder
134 * @var string
135 */
136 const UPLOADS_DIRECTORY = WP_ALL_EXPORT_UPLOADS_DIRECTORY;
137 /**
138 * WP All Import uploads folder
139 * @var string
140 */
141 const CRON_DIRECTORY = WP_ALL_EXPORT_CRON_DIRECTORY;
142
143 public static $session = null;
144
145 public static $capabilities = 'manage_options';
146
147 /**
148 * Return singletone instance
149 * @return PMXE_Plugin
150 */
151 static public function getInstance() {
152 if (self::$instance == NULL) {
153 self::$instance = new self();
154 }
155 return self::$instance;
156 }
157
158 static public function getEddName(){
159 return 'WP All Export';
160 }
161
162 /**
163 * Common logic for requestin plugin info fields
164 */
165 public function __call($method, $args) {
166 if (preg_match('%^get(.+)%i', $method, $mtch)) {
167 $info = get_plugin_data(self::FILE);
168 if (isset($info[$mtch[1]])) {
169 return $info[$mtch[1]];
170 }
171 }
172 throw new Exception("Requested method " . get_class($this) . "::$method doesn't exist.");
173 }
174
175 /**
176 * Get path to plagin dir relative to wordpress root
177 * @param bool[optional] $noForwardSlash Whether path should be returned withot forwarding slash
178 * @return string
179 */
180 public function getRelativePath($noForwardSlash = false) {
181 $wp_root = str_replace('\\', '/', ABSPATH);
182 return ($noForwardSlash ? '' : '/') . str_replace($wp_root, '', self::ROOT_DIR);
183 }
184
185 /**
186 * Check whether plugin is activated as network one
187 * @return bool
188 */
189 public function isNetwork() {
190 if ( !is_multisite() )
191 return false;
192
193 $plugins = get_site_option('active_sitewide_plugins');
194 if (isset($plugins[plugin_basename(self::FILE)]))
195 return true;
196
197 return false;
198 }
199
200 /**
201 * Check whether permalinks is enabled
202 * @return bool
203 */
204 public function isPermalinks() {
205 global $wp_rewrite;
206
207 return $wp_rewrite->using_permalinks();
208 }
209
210 /**
211 * Return prefix for plugin database tables
212 * @return string
213 */
214 public function getTablePrefix() {
215 global $wpdb;
216
217 //return ($this->isNetwork() ? $wpdb->base_prefix : $wpdb->prefix) . self::PREFIX;
218 return $wpdb->prefix . self::PREFIX;
219 }
220
221 /**
222 * Return prefix for wordpress database tables
223 * @return string
224 */
225 public function getWPPrefix() {
226 global $wpdb;
227 return ($this->isNetwork()) ? $wpdb->base_prefix : $wpdb->prefix;
228 }
229
230 /**
231 * Class constructor containing dispatching logic
232 * @param string $rootDir Plugin root dir
233 * @param string $pluginFilePath Plugin main file
234 */
235 protected function __construct() {
236
237 require_once (self::ROOT_DIR . '/classes/installer.php');
238
239 $installer = new PMXE_Installer();
240 $installer->checkActivationConditions();
241
242 // uncaught exception doesn't prevent plugin from being activated, therefore replace it with fatal error so it does
243 //set_exception_handler(create_function('$e', 'trigger_error($e->getMessage(), E_USER_ERROR);'));
244
245 // register autoloading method
246 spl_autoload_register(array($this, 'autoload'));
247
248 // register helpers
249 if (is_dir(self::ROOT_DIR . '/helpers')) foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/helpers/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) {
250 require_once $filePath;
251 }
252
253 // init plugin options
254 $option_name = get_class($this) . '_Options';
255 $options_default = PMXE_Config::createFromFile(self::ROOT_DIR . '/config/options.php')->toArray();
256 $this->options = array_intersect_key(get_option($option_name, array()), $options_default) + $options_default;
257 $this->options = array_intersect_key($options_default, array_flip(array('info_api_url'))) + $this->options; // make sure hidden options apply upon plugin reactivation
258 if ('' == $this->options['cron_job_key']) $this->options['cron_job_key'] = wp_all_export_url_title(wp_all_export_rand_char(12));
259
260 update_option($option_name, $this->options);
261 $this->options = get_option(get_class($this) . '_Options');
262 register_activation_hook(self::FILE, array($this, 'activation'));
263
264 // register action handlers
265 if (is_dir(self::ROOT_DIR . '/actions')) if (is_dir(self::ROOT_DIR . '/actions')) foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/actions/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) {
266 require_once $filePath;
267 $function = $actionName = basename($filePath, '.php');
268 if (preg_match('%^(.+?)[_-](\d+)$%', $actionName, $m)) {
269 $actionName = $m[1];
270 $priority = intval($m[2]);
271 } else {
272 $priority = 10;
273 }
274 add_action($actionName, self::PREFIX . str_replace('-', '_', $function), $priority, 99); // since we don't know at this point how many parameters each plugin expects, we make sure they will be provided with all of them (it's unlikely any developer will specify more than 99 parameters in a function)
275 }
276
277 // register filter handlers
278 if (is_dir(self::ROOT_DIR . '/filters')) foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/filters/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) {
279 require_once $filePath;
280 $function = $actionName = basename($filePath, '.php');
281 if (preg_match('%^(.+?)[_-](\d+)$%', $actionName, $m)) {
282 $actionName = $m[1];
283 $priority = intval($m[2]);
284 } else {
285 $priority = 10;
286 }
287 add_filter($actionName, self::PREFIX . str_replace('-', '_', $function), $priority, 99); // since we don't know at this point how many parameters each plugin expects, we make sure they will be provided with all of them (it's unlikely any developer will specify more than 99 parameters in a function)
288 }
289
290 // register shortcodes handlers
291 if (is_dir(self::ROOT_DIR . '/shortcodes')) foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/shortcodes/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) {
292 $tag = strtolower(str_replace('/', '_', preg_replace('%^' . preg_quote(self::ROOT_DIR . '/shortcodes/', '%') . '|\.php$%', '', $filePath)));
293 add_shortcode($tag, array($this, 'shortcodeDispatcher'));
294 }
295
296 // register admin page pre-dispatcher
297 add_action('admin_init', array($this, 'adminInit'));
298 add_action('admin_init', array($this, 'fix_db_schema'));
299 add_action('init', array($this, 'init'));
300 }
301
302 public function init(){
303 $this->load_plugin_textdomain();
304 }
305
306 /**
307 * pre-dispatching logic for admin page controllers
308 */
309 public function adminInit() {
310
311 // create history folder
312 $uploads = wp_upload_dir();
313
314 $wpallimportDirs = array( WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY, self::TEMP_DIRECTORY, self::UPLOADS_DIRECTORY, self::CRON_DIRECTORY);
315
316 foreach ($wpallimportDirs as $destination) {
317
318 $dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . $destination;
319
320 if ( !is_dir($dir)) wp_mkdir_p($dir);
321
322 if ( ! @file_exists($dir . DIRECTORY_SEPARATOR . 'index.php') ) @touch( $dir . DIRECTORY_SEPARATOR . 'index.php' );
323
324 }
325
326 if ( ! is_dir($uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY) or ! is_writable($uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY)) {
327 die(sprintf(__('Uploads folder %s must be writable', 'wp_all_export_plugin'), $uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY));
328 }
329
330 if ( ! is_dir($uploads['basedir'] . DIRECTORY_SEPARATOR . self::UPLOADS_DIRECTORY) or ! is_writable($uploads['basedir'] . DIRECTORY_SEPARATOR . self::UPLOADS_DIRECTORY)) {
331 die(sprintf(__('Uploads folder %s must be writable', 'wp_all_export_plugin'), $uploads['basedir'] . DIRECTORY_SEPARATOR . self::UPLOADS_DIRECTORY));
332 }
333
334 self::$session = new PMXE_Handler();
335
336 $input = new PMXE_Input();
337 $page = strtolower($input->getpost('page', ''));
338
339 if (preg_match('%^' . preg_quote(str_replace('_', '-', self::PREFIX), '%') . '([\w-]+)$%', $page)) {
340 //$this->adminDispatcher($page, strtolower($input->getpost('action', 'index')));
341
342 $action = strtolower($input->getpost('action', 'index'));
343
344 // capitalize prefix and first letters of class name parts
345 $controllerName = preg_replace_callback('%(^' . preg_quote(self::PREFIX, '%') . '|_).%', array($this, "replace_callback"),str_replace('-', '_', $page));
346 $actionName = str_replace('-', '_', $action);
347 if (method_exists($controllerName, $actionName)) {
348
349 if ( ! get_current_user_id() or ! current_user_can(self::$capabilities)) {
350 // This nonce is not valid.
351 die( 'Security check' );
352
353 } else {
354
355 $this->_admin_current_screen = (object)array(
356 'id' => $controllerName,
357 'base' => $controllerName,
358 'action' => $actionName,
359 'is_ajax' => strpos($_SERVER["HTTP_ACCEPT"], 'json') !== false,
360 'is_network' => is_network_admin(),
361 'is_user' => is_user_admin(),
362 );
363 add_filter('current_screen', array($this, 'getAdminCurrentScreen'));
364 add_filter('admin_body_class', create_function('', 'return "' . 'wpallexport-plugin";'));
365
366 $controller = new $controllerName();
367 if ( ! $controller instanceof PMXE_Controller_Admin) {
368 throw new Exception("Administration page `$page` matches to a wrong controller type.");
369 }
370
371 if ($this->_admin_current_screen->is_ajax) { // ajax request
372 $controller->$action();
373 do_action('wpallexport_action_after');
374 die(); // stop processing since we want to output only what controller is randered, nothing in addition
375 } elseif ( ! $controller->isInline) {
376 @ob_start();
377 $controller->$action();
378 self::$buffer = @ob_get_clean();
379 } else {
380 self::$buffer_callback = array($controller, $action);
381 }
382 }
383
384 } else { // redirect to dashboard if requested page and/or action don't exist
385 wp_redirect(admin_url()); die();
386 }
387
388 }
389 }
390
391 /**
392 * Dispatch shorttag: create corresponding controller instance and call its index method
393 * @param array $args Shortcode tag attributes
394 * @param string $content Shortcode tag content
395 * @param string $tag Shortcode tag name which is being dispatched
396 * @return string
397 * @throws Exception
398 */
399 public function shortcodeDispatcher($args, $content, $tag) {
400
401 $controllerName = self::PREFIX . preg_replace_callback('%(^|_).%', array($this, "replace_callback"), $tag);// capitalize first letters of class name parts and add prefix
402 $controller = new $controllerName();
403 if ( ! $controller instanceof PMXE_Controller) {
404 throw new Exception("Shortcode `$tag` matches to a wrong controller type.");
405 }
406 ob_start();
407 $controller->index($args, $content);
408 return ob_get_clean();
409 }
410
411 static $buffer = NULL;
412 static $buffer_callback = NULL;
413
414 /**
415 * Dispatch admin page: call corresponding controller based on get parameter `page`
416 * The method is called twice: 1st time as handler `parse_header` action and then as admin menu item handler
417 * @param string $page
418 * @param string $action
419 * @throws Exception
420 * @internal param $string [optional] $page When $page set to empty string ealier buffered content is outputted, otherwise controller is called based on $page value
421 */
422 public function adminDispatcher($page = '', $action = 'index') {
423 if ('' === $page) {
424 if ( ! is_null(self::$buffer)) {
425 echo '<div class="wrap">';
426 echo self::$buffer;
427 do_action('wpallexport_action_after');
428 echo '</div>';
429 } elseif ( ! is_null(self::$buffer_callback)) {
430 echo '<div class="wrap">';
431 call_user_func(self::$buffer_callback);
432 do_action('wpallexport_action_after');
433 echo '</div>';
434 } else {
435 throw new Exception('There is no previousely buffered content to display.');
436 }
437 }
438 }
439
440 public function replace_callback($matches){
441 return strtoupper($matches[0]);
442 }
443
444 protected $_admin_current_screen = NULL;
445 public function getAdminCurrentScreen()
446 {
447 return $this->_admin_current_screen;
448 }
449
450 /**
451 * Autoloader
452 * It's assumed class name consists of prefix folloed by its name which in turn corresponds to location of source file
453 * if `_` symbols replaced by directory path separator. File name consists of prefix folloed by last part in class name (i.e.
454 * symbols after last `_` in class name)
455 * When class has prefix it's source is looked in `models`, `controllers`, `shortcodes` folders, otherwise it looked in `core` or `library` folder
456 *
457 * @param string $className
458 * @return bool
459 */
460 public function autoload($className) {
461
462 $is_prefix = false;
463 $filePath = str_replace('_', '/', preg_replace('%^' . preg_quote(self::PREFIX, '%') . '%', '', strtolower($className), 1, $is_prefix)) . '.php';
464 if ( ! $is_prefix) { // also check file with original letter case
465 $filePathAlt = $className . '.php';
466 }
467 foreach ($is_prefix ? array('models', 'controllers', 'shortcodes', 'classes') : array('libraries') as $subdir) {
468 $path = self::ROOT_DIR . '/' . $subdir . '/' . $filePath;
469 if (is_file($path)) {
470 require $path;
471 return TRUE;
472 }
473 if ( ! $is_prefix) {
474 $pathAlt = self::ROOT_DIR . '/' . $subdir . '/' . $filePathAlt;
475 if(strpos($className, '_') !== false) {
476 $pathAlt = str_replace('_',DIRECTORY_SEPARATOR, $pathAlt);
477 }
478 if (is_file($pathAlt)) {
479 require $pathAlt;
480 return TRUE;
481 }
482 }
483 }
484
485 if(strpos($className, '\\') !== false){
486 // project-specific namespace prefix
487 $prefix = 'Wpae\\';
488
489 // base directory for the namespace prefix
490 $base_dir = self::ROOT_DIR . '/src/';
491
492 // does the class use the namespace prefix?
493 $len = strlen($prefix);
494 if (strncmp($prefix, $className, $len) !== 0) {
495 // no, move to the next registered autoloader
496 return;
497 }
498
499 // get the relative class name
500 $relative_class = substr($className, $len);
501
502 // replace the namespace prefix with the base directory, replace namespace
503 // separators with directory separators in the relative class name, append
504 // with .php
505 $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
506
507 // if the file exists, require it
508 if (file_exists($file)) {
509 require $file;
510 }
511 }
512
513 return FALSE;
514 }
515
516 /**
517 * Get plugin option
518 * @param string [optional] $option Parameter to return, all array of options is returned if not set
519 * @return mixed
520 * @throws Exception
521 */
522 public function getOption($option = NULL) {
523 $options = apply_filters('wp_all_export_config_options', $this->options);
524 if (is_null($option)) {
525 return $options;
526 } else if (isset($options[$option])) {
527 return $options[$option];
528 } else {
529 throw new Exception("Specified option is not defined for the plugin");
530 }
531 }
532
533 /**
534 * Update plugin option value
535 * @param string $option Parameter name or array of name => value pairs
536 * @param null $value
537 * @return array
538 * @throws Exception
539 * @internal param $mixed [optional] $value New value for the option, if not set than 1st parameter is supposed to be array of name => value pairs
540 */
541 public function updateOption($option, $value = NULL) {
542 is_null($value) or $option = array($option => $value);
543 if (array_diff_key($option, $this->options)) {
544 throw new Exception("Specified option is not defined for the plugin");
545 }
546 $this->options = $option + $this->options;
547 update_option(get_class($this) . '_Options', $this->options);
548
549 return $this->options;
550 }
551
552 /**
553 * Plugin activation logic
554 */
555 public function activation() {
556 // uncaught exception doesn't prevent plugin from being activated, therefore replace it with fatal error so it does
557 set_exception_handler(create_function('$e', 'trigger_error($e->getMessage(), E_USER_ERROR);'));
558
559 // create plugin options
560 $option_name = get_class($this) . '_Options';
561 $options_default = PMXE_Config::createFromFile(self::ROOT_DIR . '/config/options.php')->toArray();
562 $wpai_options = get_option($option_name, false);
563 if ( ! $wpai_options ) update_option($option_name, $options_default);
564
565 // create/update required database tables
566 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
567 require self::ROOT_DIR . '/schema.php';
568 global $wpdb;
569
570 if (function_exists('is_multisite') && is_multisite()) {
571 // check if it is a network activation - if so, run the activation function for each blog id
572 if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
573 $old_blog = $wpdb->blogid;
574 // Get all blog ids
575 $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
576 foreach ($blogids as $blog_id) {
577 switch_to_blog($blog_id);
578 require self::ROOT_DIR . '/schema.php';
579 dbDelta($plugin_queries);
580 }
581 switch_to_blog($old_blog);
582 return;
583 }
584 }
585
586 dbDelta($plugin_queries);
587
588 }
589
590 /**
591 * Load Localisation files.
592 *
593 * Note: the first-loaded translation file overrides any following ones if the same translation is present
594 *
595 * @access public
596 * @return void
597 */
598 public function load_plugin_textdomain() {
599
600 $locale = apply_filters( 'plugin_locale', get_locale(), 'wp_all_export_plugin' );
601
602 load_plugin_textdomain( 'wp_all_export_plugin', false, dirname( plugin_basename( __FILE__ ) ) . "/i18n/languages" );
603 }
604
605 public function fix_db_schema(){
606
607 global $wpdb;
608 $installed_ver = get_option( "wp_all_export_db_version" );
609
610 if ( $installed_ver == PMXE_VERSION ) return true;
611
612 if ( ! empty($wpdb->charset))
613 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
614 if ( ! empty($wpdb->collate))
615 $charset_collate .= " COLLATE $wpdb->collate";
616
617 $table_prefix = $this->getTablePrefix();
618
619 $wpdb->query("CREATE TABLE IF NOT EXISTS {$table_prefix}templates (
620 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
621 name VARCHAR(200) NOT NULL DEFAULT '',
622 options LONGTEXT,
623 PRIMARY KEY (id)
624 ) $charset_collate;");
625
626 $wpdb->query("CREATE TABLE IF NOT EXISTS {$table_prefix}posts (
627 id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
628 post_id BIGINT(20) UNSIGNED NOT NULL,
629 export_id BIGINT(20) UNSIGNED NOT NULL,
630 iteration BIGINT(20) NOT NULL DEFAULT 0,
631 PRIMARY KEY (id)
632 ) $charset_collate;");
633
634 $googleCatsTableExists = $wpdb->query("SHOW TABLES LIKE '{$table_prefix}google_cats'");
635 if(!$googleCatsTableExists) {
636 require_once self::ROOT_DIR . '/schema.php';
637 $wpdb->query($googleCatsQueryCreate);
638 $wpdb->query($googleCatsQueryData);
639 }
640
641 $table = $this->getTablePrefix() . 'exports';
642 $tablefields = $wpdb->get_results("DESCRIBE {$table};");
643 $iteration = false;
644 $parent_id = false;
645 $export_post_type = false;
646
647 // Check if field exists
648 foreach ($tablefields as $tablefield) {
649 if ('iteration' == $tablefield->Field) $iteration = true;
650 if ('parent_id' == $tablefield->Field) $parent_id = true;
651 if ('export_post_type' == $tablefield->Field) $export_post_type = true;
652 }
653
654 if ( ! $iteration ){
655 $wpdb->query("ALTER TABLE {$table} ADD `iteration` BIGINT(20) NOT NULL DEFAULT 0;");
656 }
657 if ( ! $parent_id ){
658 $wpdb->query("ALTER TABLE {$table} ADD `parent_id` BIGINT(20) NOT NULL DEFAULT 0;");
659 }
660 if ( ! $export_post_type ){
661 $wpdb->query("ALTER TABLE {$table} ADD `export_post_type` VARCHAR(64) NOT NULL DEFAULT '';");
662 }
663
664 update_option( "wp_all_export_db_version", PMXE_VERSION );
665 }
666
667 /**
668 * Determine is current export was created before current version
669 */
670 public static function isExistingExport( $checkVersion = false ){
671
672 $input = new PMXE_Input();
673 $export_id = $input->get('id', 0);
674
675 if (empty($export_id)) $export_id = $input->get('export_id', 0);
676
677 // ID not found means this is new export
678 if (empty($export_id)) return false;
679
680 if ( ! $checkVersion ) $checkVersion = PMXE_VERSION;
681
682 $export = new PMXE_Export_Record();
683 $export->getById($export_id);
684 if ( ! $export->isEmpty() && (empty($export->options['created_at_version']) || version_compare($export->options['created_at_version'], $checkVersion) < 0 )){
685 return true;
686 }
687
688 return false;
689 }
690
691 /**
692 * Determine is current export is first time running
693 */
694 public static function isNewExport(){
695
696 $input = new PMXE_Input();
697 $export_id = $input->get('id', 0);
698
699 if (empty($export_id)) $export_id = $input->get('export_id', 0);
700
701 if (empty($export_id)) $export_id = XmlExportEngine::$exportID;
702
703 // ID not found means this is new export
704 if (empty($export_id)) return true;
705
706 $export = new PMXE_Export_Record();
707 $export->getById($export_id);
708 if ( ! $export->isEmpty() && ! $export->iteration ){
709 return true;
710 }
711
712 return false;
713 }
714
715 /**
716 * Method returns default import options, main utility of the method is to avoid warnings when new
717 * option is introduced but already registered imports don't have it
718 */
719 public static function get_default_import_options() {
720 return array(
721 'cpt' => array(),
722 'whereclause' => '',
723 'joinclause' => '',
724 'filter_rules_hierarhy' => '',
725 'product_matching_mode' => 'parent',
726 'order_item_per_row' => 1,
727 'order_item_fill_empty_columns' => 1,
728 'filepath' => '',
729 'current_filepath' => '',
730 'bundlepath' => '',
731 'export_type' => 'specific',
732 'wp_query' => '',
733 'wp_query_selector' => 'wp_query',
734 'is_user_export' => false,
735 'is_comment_export' => false,
736 'export_to' => 'csv',
737 'export_to_sheet' => 'csv',
738 'delimiter' => ',',
739 'encoding' => 'UTF-8',
740 'is_generate_templates' => 1,
741 'is_generate_import' => 1,
742 'import_id' => 0,
743 'template_name' => '',
744 'is_scheduled' => 0,
745 'scheduled_period' => '',
746 'scheduled_email' => '',
747 'cc_label' => array(),
748 'cc_type' => array(),
749 'cc_value' => array(),
750 'cc_name' => array(),
751 'cc_php' => array(),
752 'cc_code' => array(),
753 'cc_sql' => array(),
754 'cc_options' => array(),
755 'cc_settings' => array(),
756 'friendly_name' => '',
757 'fields' => array('default', 'other', 'cf', 'cats'),
758 'ids' => array(),
759 'rules' => array(),
760 'records_per_iteration' => 50,
761 'include_bom' => 0,
762 'include_functions' => 1,
763 'split_large_exports' => 0,
764 'split_large_exports_count' => 10000,
765 'split_files_list' => array(),
766 'main_xml_tag' => 'data',
767 'record_xml_tag' => 'post',
768 'save_template_as' => 0,
769 'name' => '',
770 'export_only_new_stuff' => 0,
771 'export_only_modified_stuff' => 0,
772 'creata_a_new_export_file' => 0,
773 'attachment_list' => array(),
774 'order_include_poducts' => 0,
775 'order_include_all_poducts' => 0,
776 'order_include_coupons' => 0,
777 'order_include_all_coupons' => 0,
778 'order_include_customers' => 0,
779 'order_include_all_customers' => 0,
780 'migration' => '',
781 'xml_template_type' => 'simple',
782 'custom_xml_template' => '',
783 'custom_xml_template_header' => '',
784 'custom_xml_template_loop' => '',
785 'custom_xml_template_footer' => '',
786 'custom_xml_template_options' => array(),
787 'custom_xml_cdata_logic' => 'auto',
788 'show_cdata_in_preview' => 0,
789 'taxonomy_to_export' => '',
790 'created_at_version' => '',
791 'export_variations' => XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION,
792 'export_variations_title' => XmlExportEngine::VARIATION_USE_PARENT_TITLE,
793 'show_cdata_in_preview' => 0,
794 'include_header_row' => 1,
795 'wpml_lang' => 'all'
796 );
797 }
798
799 public static function is_ajax(){
800 return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false ;
801 }
802
803 }
804
805 PMXE_Plugin::getInstance();
806
807 // Include the api front controller
808 include_once('wpae_api.php');
809
810 }
811