<?php //global $Zotpress_update_version; $wpdb->update($wpdb->prefix . "zotpress", array('version' => $GLOBALS['Zotpress_update_db_by_version']), array('api_user_id' => $api_user_id), array('%s'), array('%s')); } else { if (isset($_GET['step']) && $_GET['step'] == "selective") { // Check selected top level collections if (isset($_GET['collections']) && preg_match("/[0-9a-zA-Z,]+/", $_GET['collections'])) { $api_user_id = zp_get_api_user_id(); // Clear last import zp_clear_last_import($wpdb, $api_user_id, "selective", $_GET['collections']); // Import top level collections' data $GLOBALS['zp_session'][$api_user_id]['collections']['query_params'] = array(); $GLOBALS['zp_session'][$api_user_id]['collections']['query_total_entries'] = 0; foreach (explode(",", $_GET['collections']) as $zp_single_collection) { zp_get_collections($wpdb, $api_user_id, 0, false, false, $zp_single_collection); } zp_save_collections($wpdb, $api_user_id, false, false); ?> var zpCollections = '<?php echo $_GET['collections']; ?> '; zpCollections = zpCollections.split(','); zp_get_items_ajax( <?php echo "'" . ZOTPRESS_PLUGIN_URL . "', '" . $api_user_id; ?> ', '0', zpCollections[0] ); <?php
// Access WordPress db global $wpdb; // Ignore user abort ignore_user_abort(true); set_time_limit(60); // 1 minute (vs. 60*10) // Include Request Functionality require "../request/rss.request.php"; // Include Import Functions require "import.functions.php"; $GLOBALS['zp_session'][$api_user_id]['collections']['last_set'] = 0; $GLOBALS['zp_session'][$api_user_id]['collections']['query_params'] = array(); $GLOBALS['zp_session'][$api_user_id]['collections']['query_total_entries'] = 0; $zp_current_set = 0; while ($zp_current_set <= $GLOBALS['zp_session'][$api_user_id]['collections']['last_set']) { $zp_continue = zp_get_collections($wpdb, $api_user_id, $zp_current_set, true); //zp_save_collections ($wpdb, $api_user_id, true, true); // saving now might be confusing to users because it doesn't import items or subcollections $zp_current_set += 50; } $output = "<!DOCTYPE HTML>\n<html>\n<head>"; $output .= '<script type="text/javascript" src="' . ZOTPRESS_PLUGIN_URL . 'js/jquery-1.5.2.min.js"></script>'; $output .= '<script> jQuery(document).ready(function() { jQuery("input").click( function() { jQuery(this).parent().toggleClass("selected"); }); jQuery(".zp-Collection").click( function()
function zotpress_import_ajax() { // Check nonce if (check_admin_referer('zp_importing_' . intval($_GET['api_user_id']) . '_' . date('Y-j-G'), 'zp_nonce')) { // Include Request functionality require dirname(__FILE__) . '/../request/rss.request.php'; // Include Import and Sync functions require dirname(__FILE__) . '/../import/import.functions.php'; // Set up XML document $xml = ""; /* STEPS */ if (isset($_GET['step'])) { // Set up error array $errors = array("api_user_id_blank" => array(0, "<strong>User ID</strong> was left blank."), "api_user_id_format" => array(0, "<strong>User ID</strong> was formatted incorrectly."), "step_blank" => array(0, "<strong>Step</strong> was not set."), "step_format" => array(0, "<strong>Step</strong> was not formatted correctly."), "start_blank" => array(0, "<strong>Start</strong> were not set."), "start_format" => array(0, "<strong>Start</strong> were not formatted correctly.")); // CHECK API USER ID if ($_GET['api_user_id'] != "") { if (preg_match("/^[0-9]+\$/", $_GET['api_user_id']) == 1) { $api_user_id = htmlentities($_GET['api_user_id']); } else { $errors['api_user_id_format'][0] = 1; } } else { $errors['api_user_id_blank'][0] = 1; } // CHECK STEP if ($_GET['step'] != "") { if (preg_match("/^[a-z]+\$/", $_GET['step']) == 1) { $step = htmlentities($_GET['step']); } else { $errors['step_format'][0] = 1; } } else { $errors['step_blank'][0] = 1; } // CHECK START if ($_GET['start'] != "") { if (preg_match("/^[a-zA-Z0-9,]+\$/", $_GET['start']) == 1) { if ($step == "selective") { $start = htmlentities($_GET['start']); } else { $start = intval(htmlentities($_GET['start'])); } } else { $errors['start_format'][0] = 1; } } else { $errors['start_blank'][0] = 1; } // CHECK ERRORS $errorCheck = false; foreach ($errors as $field => $error) { if ($error[0] == 1) { $errorCheck = true; break; } } // IMPORT if ($errorCheck == false) { // Setup $GLOBALS['zp_session'][$api_user_id]['items']['query_params'] = array(); $GLOBALS['zp_session'][$api_user_id]['items']['query_total_entries'] = 0; $GLOBALS['zp_session'][$api_user_id]['collections']['query_params'] = array(); $GLOBALS['zp_session'][$api_user_id]['collections']['query_total_entries'] = 0; $GLOBALS['zp_session'][$api_user_id]['tags']['query_params'] = array(); $GLOBALS['zp_session'][$api_user_id]['tags']['query_total_entries'] = 0; // ITEMS if (isset($_GET['step']) && $_GET['step'] == "items") { global $wpdb; $zp_selective = false; if (isset($_GET['selective']) && preg_match("/^[a-zA-Z0-9,]+\$/", $_GET['selective']) && $_GET['selective'] != "false") { $zp_selective = $_GET['selective']; } $zp_continue = zp_get_items($wpdb, $api_user_id, $start, $zp_selective); if ($zp_continue === true) { zp_save_items($wpdb, $api_user_id, true); $xml = "<result success=\"true\" next=\"" . ($start + 50) . "\" saved=\"true\" />\n"; } else { if ($zp_continue === false) { zp_save_items($wpdb, $api_user_id, false); $xml = "<result success=\"next\" next=\"collections\" />\n"; } else { $xml = "<result success=\"false\" />\n"; $xml = "<errors>" . $zp_continue . "</errors>\n"; } } } else { if (isset($_GET['step']) && $_GET['step'] == "collections") { global $wpdb; $zp_selective = false; if (isset($_GET['selective']) && preg_match("/^[a-zA-Z0-9,]+\$/", $_GET['selective']) && $_GET['selective'] != "false") { $zp_selective = $_GET['selective']; } $zp_continue = zp_get_collections($wpdb, $api_user_id, $start, false, $zp_selective); if ($zp_continue["continue"] === true) { zp_save_collections($wpdb, $api_user_id, true); $xml = "<result success=\"true\" next=\"" . ($start + 50) . "\" saved=\"true\" />\n"; if ($zp_selective) { $xml .= "<subcollections>" . $zp_continue["collections"] . "</subcollections>\n"; } } else { zp_save_collections($wpdb, $api_user_id, false); //zp_link_collections ($wpdb, $api_user_id); for wp custom types $xml = "<result success=\"next\" next=\"tags\" />\n"; if ($zp_selective) { $xml .= "<subcollections>" . $zp_continue["collections"] . "</subcollections>\n"; } } } else { if (isset($_GET['step']) && $_GET['step'] == "tags") { global $wpdb; $zp_selective = false; if (isset($_GET['selective']) && preg_match("/^[a-zA-Z0-9,]+\$/", $_GET['selective']) && $_GET['selective'] != "false") { $zp_selective = $_GET['selective']; } $zp_continue = zp_get_tags($wpdb, $api_user_id, $start, $zp_selective); if ($zp_continue === true) { zp_save_tags($wpdb, $api_user_id, true); $xml = "<result success=\"true\" next=\"" . ($start + 50) . "\" saved=\"true\" />\n"; } else { zp_save_tags($wpdb, $api_user_id, false); $xml = "<result success=\"next\" next=\"complete\" />\n"; } } } } } else { $xml .= "<result success=\"false\" />\n"; $xml .= "<import>\n"; $xml .= "<errors>\n"; foreach ($errors as $field => $error) { if ($error[0] == 1) { $xml .= $error[1] . "\n"; } } $xml .= "</errors>\n"; $xml .= "</import>\n"; } } /* DISPLAY XML */ header('Content-Type: application/xml; charset=ISO-8859-1'); echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; echo "<import>\n"; echo $xml; echo "</import>"; exit; } // nonce }