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