function import_sliders() { // Revolution Sliders if (axiom_exists_revslider() && file_exists(WP_PLUGIN_DIR . '/revslider/revslider.php')) { require_once WP_PLUGIN_DIR . '/revslider/revslider.php'; $dir = axiom_get_folder_dir($this->options['folder_with_revsliders']); if (is_dir($dir)) { $hdir = @opendir($dir); if ($hdir) { echo '<script>' . 'document.getElementById("import_progress_status").innerHTML = "' . __('Import Revolution sliders ...', 'axiom') . '";' . '</script>'; echo '<br><b>' . __('Import Revolution sliders ...', 'axiom') . '</b><br>'; flush(); $slider = new RevSlider(); $counter = 0; while (($file = readdir($hdir)) !== false) { $counter++; if ($counter <= $this->last_slider) { continue; } $pi = pathinfo($dir . '/' . $file); if (substr($file, 0, 1) == '.' || is_dir($dir . '/' . $file) || $pi['extension'] != 'zip') { continue; } if ($this->options['debug']) { printf(__('Slider "%s":', 'axiom'), $file); } if (!is_array($_FILES)) { $_FILES = array(); } $_FILES["import_file"] = array("tmp_name" => $dir . '/' . $file); $response = $slider->importSliderFromPost(); if ($response["success"] == false) { if ($this->options['debug']) { echo ' ' . __('import error:', 'axiom') . '<br>' . dumpVar($response); } } else { if ($this->options['debug']) { echo ' ' . __('imported', 'axiom') . '<br>'; } } flush(); break; } @closedir($hdir); // Write last slider into log axiom_fpc($this->import_log, $file ? '0|100|' . intval($counter) : ''); $this->last_slider = $file ? $counter : 0; } } } else { if ($this->options['debug']) { printf(__('Can not locate Revo plugin: %s', 'axiom'), WP_PLUGIN_DIR . '/revslider/revslider.php<br>'); flush(); } } }
function axiom_options_save() { global $AXIOM_GLOBALS; if (!wp_verify_nonce($_POST['nonce'], 'ajax_nonce')) { die; } $mode = $_POST['mode']; $override = $_POST['override'] == '' ? 'general' : $_POST['override']; $options = $AXIOM_GLOBALS['options']; if ($mode == 'save') { parse_str($_POST['data'], $post_data); } else { if ($mode == 'export') { parse_str($_POST['data'], $post_data); if (!empty($AXIOM_GLOBALS['post_meta_box']['fields'])) { $options = axiom_array_merge($AXIOM_GLOBALS['options'], $AXIOM_GLOBALS['post_meta_box']['fields']); } } else { $post_data = array(); } } $custom_options = array(); axiom_options_merge_new_values($options, $custom_options, $post_data, $mode, $override); if ($mode == 'export') { $name = trim(chop($_POST['name'])); $name2 = isset($_POST['name2']) ? trim(chop($_POST['name2'])) : ''; $key = $name == '' ? $name2 : $name; $export = get_option('axiom_options_' . $override, array()); $export[$key] = $custom_options; if ($name != '' && $name2 != '') { unset($export[$name2]); } update_option('axiom_options_' . $override, $export); $file = axiom_get_file_dir('core/core.options/core.options.txt'); $url = axiom_get_file_url('core/core.options/core.options.txt'); $export = serialize($custom_options); axiom_fpc($file, $export); $response = array('error' => '', 'data' => $export, 'link' => $url); echo json_encode($response); } else { update_option('axiom_options', apply_filters('axiom_filter_save_options', $custom_options, $override)); } die; }
/** * Create new posts based on import information * * Posts marked as having a parent which doesn't exist will become top level items. * Doesn't create a new post if: the post type doesn't exist, the given post ID * is already noted as imported or a post with the same title and date already exists. * Note that new/updated terms, comments and meta are imported for the last of the above. */ function process_posts() { $this->posts = apply_filters('wp_import_posts', $this->posts); usort($this->posts, array($this, 'compare_terms')); $posts_all = count($this->posts); $posts_counter = 0; $result = 0; foreach ($this->posts as $post) { $posts_counter++; if (!empty($post['post_id']) && $post['post_id'] <= $this->start_from_id) { continue; } $post = apply_filters('wp_import_post_data_raw', $post); if (!post_type_exists($post['post_type'])) { printf(__('Failed to import post “%s”: Invalid post type %s', 'axiom'), esc_html($post['post_title']), esc_html($post['post_type'])); echo '<br />'; do_action('wp_import_post_exists', $post); } else { if (!empty($post['post_id']) && isset($this->processed_posts[$post['post_id']])) { // Do nothing } else { if ($post['status'] == 'auto-draft') { // Do nothing } else { if ('nav_menu_item' == $post['post_type']) { $this->process_menu_item($post); } else { do { $post_type_object = get_post_type_object($post['post_type']); $post_exists = post_exists($post['post_title'], '', $post['post_date']); $original_post_ID = $post['post_id']; if ($post_exists && get_post_type($post_exists) == $post['post_type']) { printf(__('%s “%s” already exists.', 'axiom'), $post_type_object->labels->singular_name, esc_html($post['post_title'])); echo '<br />'; $comment_post_ID = $post_id = $post_exists; } else { $post_parent = (int) $post['post_parent']; if (!$this->overwrite && $post_parent) { // if we already know the parent, map it to the new local ID if (isset($this->processed_posts[$post_parent])) { $post_parent = $this->processed_posts[$post_parent]; // otherwise record the parent for later } else { $this->post_orphans[intval($post['post_id'])] = $post_parent; $post_parent = 0; } } // map the post author $author = sanitize_user($post['post_author'], true); if (isset($this->author_mapping[$author])) { $author = $this->author_mapping[$author]; } else { $author = (int) get_current_user_id(); } $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $this->replace_uploads($post['post_content']), 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']); $postdata = apply_filters('wp_import_post_data_processed', $postdata, $post); if ('attachment' == $postdata['post_type']) { $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid']; // try to use _wp_attached file for upload folder placement to ensure the same location as the export site // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload() $postdata['upload_date'] = $post['post_date']; if (isset($post['postmeta'])) { foreach ($post['postmeta'] as $meta) { if ($meta['key'] == '_wp_attached_file') { if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) { $postdata['upload_date'] = $matches[0]; } break; } } } $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url); } else { $comment_post_ID = $post_id = wp_insert_post($postdata, true); do_action('wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post); } if (is_wp_error($post_id)) { printf(__('Failed to import post %s: “%s”', 'axiom'), $post_type_object->labels->singular_name, esc_html($post['post_title'])); if ($this->debug) { echo ': ' . $post_id->get_error_message(); } echo '<br />'; break; } if ($this->overwrite) { if ($post_id != $original_post_ID) { global $wpdb; $wpdb->query($wpdb->prepare("UPDATE " . esc_sql($wpdb->term_relationships) . " SET object_id=%d WHERE object_id=%d", $original_post_ID, $post_id)); $wpdb->query($wpdb->prepare("UPDATE " . esc_sql($wpdb->postmeta) . " SET post_id=%d WHERE post_id=%d", $original_post_ID, $post_id)); $wpdb->query($wpdb->prepare("UPDATE " . esc_sql($wpdb->posts) . " SET ID=%d, post_parent=%d WHERE ID=%d LIMIT 1", $original_post_ID, $post_parent, $post_id)); if ($post_id < $original_post_ID) { $wpdb->query($wpdb->prepare("ALTER TABLE " . esc_sql($wpdb->posts) . " AUTO_INCREMENT=%d", $original_post_ID + 1)); } $comment_post_ID = $post_id = $original_post_ID; } } if ($post['is_sticky'] == 1) { stick_post($post_id); } if ($this->debug) { printf(__('%s "%s" (ID=%s) imported.', 'axiom') . '<br>', $post_type_object->labels->singular_name, esc_html($post['post_title']), $post_id); flush(); } } // map pre-import ID to local ID $this->processed_posts[intval($post['post_id'])] = (int) $post_id; if (!isset($post['terms'])) { $post['terms'] = array(); } $post['terms'] = apply_filters('wp_import_post_terms', $post['terms'], $post_id, $post); // add categories, tags and other terms if (!empty($post['terms'])) { $terms_to_set = array(); foreach ($post['terms'] as $term) { // back compat with WXR 1.0 map 'tag' to 'post_tag' $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain']; $term_exists = term_exists($term['slug'], $taxonomy); $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists; if (!$term_id) { $t = wp_insert_term($term['name'], $taxonomy, array('slug' => $term['slug'])); if (!is_wp_error($t)) { $term_id = $t['term_id']; do_action('wp_import_insert_term', $t, $term, $post_id, $post); //if ( $this->debug ) { printf( __( 'Post term %s: "%s" imported.', 'axiom' ).'<br>', esc_html($taxonomy), esc_html($term['name']) ); flush(); } } else { printf(__('Failed to import post term %s: "%s"', 'axiom'), esc_html($taxonomy), esc_html($term['name'])); if ($this->debug) { echo ': ' . $t->get_error_message(); } echo '<br />'; flush(); do_action('wp_import_insert_term_failed', $t, $term, $post_id, $post); break; } } $terms_to_set[$taxonomy][] = intval($term_id); } foreach ($terms_to_set as $tax => $ids) { $tt_ids = wp_set_post_terms($post_id, $ids, $tax); do_action('wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post); } unset($post['terms'], $terms_to_set); } if (!isset($post['comments'])) { $post['comments'] = array(); } $post['comments'] = apply_filters('wp_import_post_comments', $post['comments'], $post_id, $post); // add/update comments if (!empty($post['comments'])) { $num_comments = 0; $inserted_comments = array(); foreach ($post['comments'] as $comment) { $comment_id = $comment['comment_id']; $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID; $newcomments[$comment_id]['comment_author'] = $comment['comment_author']; $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email']; $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP']; $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url']; $newcomments[$comment_id]['comment_date'] = $comment['comment_date']; $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt']; $newcomments[$comment_id]['comment_content'] = $comment['comment_content']; $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; $newcomments[$comment_id]['comment_type'] = $comment['comment_type']; $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array(); if (isset($this->processed_authors[$comment['comment_user_id']])) { $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']]; } } ksort($newcomments); foreach ($newcomments as $key => $comment) { // if this is a new post we can skip the comment_exists() check if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) { if (isset($inserted_comments[$comment['comment_parent']])) { $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; } $comment = wp_filter_comment($comment); $inserted_comments[$key] = wp_insert_comment($comment); do_action('wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post); foreach ($comment['commentmeta'] as $meta) { $value = maybe_unserialize($meta['value']); add_comment_meta($inserted_comments[$key], $meta['key'], $value); } $num_comments++; } } unset($newcomments, $inserted_comments, $post['comments']); } if (!isset($post['postmeta'])) { $post['postmeta'] = array(); } $post['postmeta'] = apply_filters('wp_import_post_meta', $post['postmeta'], $post_id, $post); // add/update post meta if (!empty($post['postmeta'])) { foreach ($post['postmeta'] as $meta) { $key = apply_filters('import_post_meta_key', $meta['key'], $post_id, $post); $value = false; if ('_edit_last' == $key) { if (isset($this->processed_authors[intval($meta['value'])])) { $value = $this->processed_authors[intval($meta['value'])]; } else { $key = false; } } if ($key) { // export gets meta straight from the DB so could have a serialized string $replace = true; if (!$value) { $value = $meta['value']; if (is_serialized($value)) { $value = @unserialize($value); if (!$value) { $value = str_replace("\n", "\r\n", $meta['value']); $value = @unserialize($value); } if (!$value) { $value = str_replace(array("\n", "\r"), array('\\n', '\\r'), $meta['value']); $value = @unserialize($value); } if (!$value) { if ($meta['value'] != 'a:0:{}' && $this->debug) { printf(__('Post (ID=%s) - error unserialize postmeta: %s=', 'axiom'), $post['post_id'], $key); ds($meta['value']); flush(); } $value = $meta['value']; $replace = false; } } } if ($replace) { $value = $this->replace_uploads($value); } add_post_meta($post_id, $key, $value); do_action('import_post_meta', $post_id, $key, $value); // if the post has a featured image, take note of this in case of remap if ('_thumbnail_id' == $key) { $this->featured_images[$post_id] = (int) $value; } } } } } while (false); } } } } // Get max_execution_time $admin_tm = max(30, min(1800, (int) axiom_get_theme_option('admin_dummy_timeout'))); $tm = max(30, (int) ini_get('max_execution_time')); if ($tm < $admin_tm) { @set_time_limit($admin_tm); $tm = max(30, ini_get('max_execution_time')); $this->max_time = $tm - min(10, round($tm * 0.33)); } // Save into log last $result = $posts_counter < $posts_all ? round($posts_counter / $posts_all * 100) : 100; axiom_fpc($this->import_log, trim($original_post_ID) . '|' . trim($result)); printf(__('Post (ID=%s) imported. Current import progress: %s. Time limit: %s sec. Elapsed time: %s sec.', 'axiom'), $post['post_id'], $result . '%', $this->max_time, time() - $this->start_time); echo "<br /><br />"; // Break import after timeout or if leave one post and execution time > half of max_time if (time() - $this->start_time >= $this->max_time || $posts_counter + 1 >= $posts_all && time() - $this->start_time < $this->max_time / 2) { break; } } unset($this->posts); return $result; }
function actions_handler() { if (!empty($this->po_src)) { if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], __FILE__)) { $this->error = __('Incorrect WP-nonce data! Operation canceled!', 'axiom'); } else { do { // Get data from new .po_file $rez = $this->load_po(); if (!empty($rez['error'])) { $this->error = $rez['error']; break; } $po_text = $rez['data']; // Parse data if (($po_data = $this->parse_po($po_text)) === false) { $this->error = __('Error parsing new .po-file!', 'axiom'); break; } if ($this->po_src2 != '') { // Get data from old .po_file $rez = $this->load_po('2'); if (!empty($rez['error'])) { $this->error = $rez['error']; break; } $po_text2 = $rez['data']; if (($po_data2 = $this->parse_po($po_text2)) === false) { $this->error = __('Error parsing merging .po-file!', 'axiom'); break; } } if ($this->po_src2 != '' || !empty($_POST['po_translated_down'])) { // Compare data $header = array(); $translated = array(); $non_translated = array(); foreach ($po_data as $k => $v) { // First element - internal data - just copy it if ($k == 0) { $header[] = $v; continue; } // If string already exists in old po-file if ($this->po_src2 != '' && ($idx2 = $this->find_po($v, $po_data2)) !== false) { $v['msgstr'] = $po_data2[$idx2]['msgstr']; } // If string not translated if (empty($_POST['po_translated_down']) || count($v['msgstr']) == 1 && $v['msgstr'][0] == 'msgstr ""') { $non_translated[] = $v; } else { $translated[] = $v; } } $po_data = array_merge($header, $non_translated, $translated); $this->po_text = $this->generate_po($po_data); } else { if ($this->po_src != '') { $this->po_text = $this->generate_po($po_data); } else { $this->po_text = stripslashes($_POST['po_text']); } } } while (false); } // Save result if (empty($this->error)) { // Update temp files (always) $po_temp = get_template_directory() . '/core/tools/po_composer/data/temp.po'; if (is_writeable($po_temp)) { axiom_fpc($po_temp, $this->po_text); $this->po_link = get_template_directory_uri() . '/core/tools/po_composer/data/temp.po'; } $this->mo_text = $this->generate_mo($po_data); $mo_temp = get_template_directory() . '/core/tools/po_composer/data/temp.mo'; if (is_writeable($mo_temp)) { axiom_fpc($mo_temp, $this->mo_text); $this->mo_link = get_template_directory_uri() . '/core/tools/po_composer/data/temp.mo'; } // Update lang files on server $this->error_update = ''; if (empty($this->po_src2) && !empty($_POST['po_text']) && substr($this->po_src, 0, 7) == 'parent_' || substr($this->po_src, 0, 6) == 'child_') { $dir = substr($this->po_src, 0, 7) == 'parent_' ? $this->tpl_dir : $this->css_dir; $name = substr($this->po_src, strpos($this->po_src, '_') + 1); $po_file = trim($dir) . '/' . trim($name) . '.po'; if (is_writeable($po_file)) { axiom_fpc($po_file, $this->po_text); $this->success = sprintf(__('Language file "<b>%s.po</b>" was updated!', 'axiom'), $name); $mo_file = trim($dir) . '/' . trim($name) . '.mo'; if (is_writeable($mo_file)) { axiom_fpc($mo_file, $this->mo_text); $this->success .= '<br>' . sprintf(__('Language file "<b>%s.mo</b>" was generated!', 'axiom'), $name); } } else { $tjis->error_update = sprintf(__('Error writing in language file "<b>%s.po</b>"!<br>Please, copy text from textarea below and paste it in the .po-file manually<br>or use links to upload .po and .mo files below the text area!', 'axiom'), $name); } } } else { $this->po_text = stripslashes($_POST['po_text']); $this->po_text2 = stripslashes($_POST['po_text2']); } } }
function axiom_debug_trace_message($msg) { global $AXIOM_GLOBALS; axiom_fpc(get_stylesheet_directory() . '/' . $AXIOM_GLOBALS['debug_file_name'], date('d.m.Y H:i:s') . " {$msg}\n", FILE_APPEND); }