本文整理汇总了PHP中WXR_Parser类的典型用法代码示例。如果您正苦于以下问题:PHP WXR_Parser类的具体用法?PHP WXR_Parser怎么用?PHP WXR_Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WXR_Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: woocommerce_import_start
/**
* Functions for handling WordPress import to make it compatable with WooCommerce
*
* WordPress import should work - however, it fails to import custom product attribute taxonomies.
* This code grabs the file before it is imported and ensures the taxonomies are created.
*
* @author WooThemes
* @category Admin
* @package WooCommerce
*/
function woocommerce_import_start()
{
global $wpdb;
$id = (int) $_POST['import_id'];
$file = get_attached_file($id);
$parser = new WXR_Parser();
$import_data = $parser->parse($file);
if (isset($import_data['posts'])) {
$posts = $import_data['posts'];
if ($posts && sizeof($posts) > 0) {
foreach ($posts as $post) {
if ($post['post_type'] == 'product') {
if ($post['terms'] && sizeof($post['terms']) > 0) {
foreach ($post['terms'] as $term) {
$domain = $term['domain'];
if (strstr($domain, 'pa_')) {
// Make sure it exists!
if (!taxonomy_exists($domain)) {
$nicename = strtolower(sanitize_title(str_replace('pa_', '', $domain)));
$exists_in_db = $wpdb->get_var("SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '" . $nicename . "';");
if (!$exists_in_db) {
// Create the taxonomy
$wpdb->insert($wpdb->prefix . "woocommerce_attribute_taxonomies", array('attribute_name' => $nicename, 'attribute_type' => 'select'), array('%s', '%s'));
}
// Register the taxonomy now so that the import works!
register_taxonomy($domain, array('product'), array('hierarchical' => true, 'labels' => array('name' => $nicename, 'singular_name' => $nicename, 'search_items' => __('Search', 'woothemes') . ' ' . $nicename, 'all_items' => __('All', 'woothemes') . ' ' . $nicename, 'parent_item' => __('Parent', 'woothemes') . ' ' . $nicename, 'parent_item_colon' => __('Parent', 'woothemes') . ' ' . $nicename . ':', 'edit_item' => __('Edit', 'woothemes') . ' ' . $nicename, 'update_item' => __('Update', 'woothemes') . ' ' . $nicename, 'add_new_item' => __('Add New', 'woothemes') . ' ' . $nicename, 'new_item_name' => __('New', 'woothemes') . ' ' . $nicename), 'show_ui' => false, 'query_var' => true, 'rewrite' => array('slug' => strtolower(sanitize_title($nicename)), 'with_front' => false, 'hierarchical' => true)));
}
}
}
}
}
}
}
}
}
示例2: importwxr
public function importwxr()
{
$this->requireUserPermission('extensions');
// \util::var_dump($this->config);
$filename = __DIR__ . "/" . $this->config['file'];
$file = realpath(__DIR__ . "/" . $this->config['file']);
$output = "";
$this->foundcategories = array();
// No logging. saves memory..
$this->app['db.config']->setSQLLogger(null);
if (!empty($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = "start";
}
require_once "src/parsers.php";
$parser = new \WXR_Parser();
switch ($action) {
case "start":
if (empty($file) || !is_readable($file)) {
$output .= "<p>File {$filename} doesn't exist. Correct this in <code>app/extensions/ImportWXR/config.yml</code>, and refresh this page.</p>";
} else {
$output .= sprintf("<p>File <code>%s</code> selected for import.</p>", $this->config['file']);
$output .= "<p><a class='btn btn-primary' href='?action=dryrun'><strong>Test a few records</strong></a></p>";
$output .= "<p>This mapping will be used:</p>";
$output .= \util::var_dump($this->config['mapping'], true);
}
break;
case "confirm":
$res = $parser->parse($file);
foreach ($res['posts'] as $post) {
$output .= $this->importPost($post, false);
}
$output .= "<p><strong>Done!</strong></p>";
if (!empty($this->foundcategories)) {
$output .= "<p>These categories were found, make sure you add them to your <code>taxonomy.yml</code></p>";
$output .= "<textarea style='width: 400px;'>" . json_encode($this->foundcategories) . "</textarea>";
}
break;
case "dryrun":
$counter = 1;
$res = $parser->parse($file);
foreach ($res['posts'] as $post) {
$output .= $this->importPost($post, true);
if ($counter++ >= 4) {
break;
}
}
$output .= sprintf("<p>Looking good? Then click below to import the Records: </p>");
$output .= "<p><a class='btn btn-primary' href='?action=confirm'><strong>Confirm!</strong></a></p>";
}
unset($res);
return $this->app['render']->render('base.twig', array('title' => "Import WXR (PivotX / Wordpress XML)", 'content' => $output));
}
示例3: woocommerce_import_start
/**
* When running the WP importer, ensure attributes exist.
*
* @access public
* @return void
*/
function woocommerce_import_start()
{
global $wpdb;
if (!isset($_POST['import_id'])) {
return;
}
if (!class_exists('WXR_Parser')) {
return;
}
$id = (int) $_POST['import_id'];
$file = get_attached_file($id);
$parser = new WXR_Parser();
$import_data = $parser->parse($file);
if (isset($import_data['posts'])) {
$posts = $import_data['posts'];
if ($posts && sizeof($posts) > 0) {
foreach ($posts as $post) {
if ($post['post_type'] == 'product') {
if ($post['terms'] && sizeof($post['terms']) > 0) {
foreach ($post['terms'] as $term) {
$domain = $term['domain'];
if (strstr($domain, 'pa_')) {
// Make sure it exists!
if (!taxonomy_exists($domain)) {
$nicename = strtolower(sanitize_title(str_replace('pa_', '', $domain)));
$exists_in_db = $wpdb->get_var("SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '" . $nicename . "';");
if (!$exists_in_db) {
// Create the taxonomy
$wpdb->insert($wpdb->prefix . "woocommerce_attribute_taxonomies", array('attribute_name' => $nicename, 'attribute_type' => 'select'), array('%s', '%s'));
}
// Register the taxonomy now so that the import works!
register_taxonomy($domain, array('product'), array('hierarchical' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => false));
}
}
}
}
}
}
}
}
}
示例4: post_importer_compatibility
/**
* When running the WP importer, ensure attributes exist.
*
* WordPress import should work - however, it fails to import custom product attribute taxonomies.
* This code grabs the file before it is imported and ensures the taxonomies are created.
*/
public function post_importer_compatibility()
{
global $wpdb;
if (empty($_POST['import_id']) || !class_exists('WXR_Parser')) {
return;
}
$id = absint($_POST['import_id']);
$file = get_attached_file($id);
$parser = new WXR_Parser();
$import_data = $parser->parse($file);
if (isset($import_data['posts'])) {
$posts = $import_data['posts'];
if ($posts && sizeof($posts) > 0) {
foreach ($posts as $post) {
if ('product' === $post['post_type']) {
if (!empty($post['terms'])) {
foreach ($post['terms'] as $term) {
if (strstr($term['domain'], 'pa_')) {
if (!taxonomy_exists($term['domain'])) {
$attribute_name = wc_sanitize_taxonomy_name(str_replace('pa_', '', $term['domain']));
// Create the taxonomy
if (!in_array($attribute_name, wc_get_attribute_taxonomies())) {
$attribute = array('attribute_label' => $attribute_name, 'attribute_name' => $attribute_name, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order', 'attribute_public' => 0);
$wpdb->insert($wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute);
delete_transient('wc_attribute_taxonomies');
}
// Register the taxonomy now so that the import works!
register_taxonomy($term['domain'], apply_filters('woocommerce_taxonomy_objects_' . $term['domain'], array('product')), apply_filters('woocommerce_taxonomy_args_' . $term['domain'], array('hierarchical' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => false)));
}
}
}
}
}
}
}
}
}
示例5: parse
/**
* Parse a WXR file
*
* @param string $file Path to WXR file for parsing
* @return array Information gathered from the WXR file
*/
function parse($file)
{
$parser = new WXR_Parser();
return $parser->parse($file);
}
示例6: jigoshop_import_start
/**
* Support for Import/Export
*
* WordPress import should work - however, it fails to import custom product attribute taxonomies.
* This code grabs the file before it is imported and ensures the taxonomies are created.
**/
function jigoshop_import_start() {
global $wpdb;
$id = (int) $_POST['import_id'];
$file = get_attached_file( $id );
$parser = new WXR_Parser();
$import_data = $parser->parse( $file );
if (isset($import_data['posts'])) :
$posts = $import_data['posts'];
if ($posts && sizeof($posts)>0) foreach ($posts as $post) :
if ($post['post_type']=='product') :
if ($post['terms'] && sizeof($post['terms'])>0) :
foreach ($post['terms'] as $term) :
$domain = $term['domain'];
if (strstr($domain, 'pa_')) :
// Make sure it exists!
if (!taxonomy_exists( $domain )) :
$nicename = ucfirst(str_replace('pa_', '', $domain));
// Create the taxonomy
$wpdb->insert( $wpdb->prefix . "jigoshop_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_type' => 'text' ), array( '%s', '%s' ) );
// Register the taxonomy now so that the import works!
register_taxonomy( $domain,
array('product'),
array(
'hierarchical' => true,
'labels' => array(
'name' => $nicename,
'singular_name' => $nicename,
'search_items' => __( 'Search ', 'jigoshop') . $nicename,
'all_items' => __( 'All ', 'jigoshop') . $nicename,
'parent_item' => __( 'Parent ', 'jigoshop') . $nicename,
'parent_item_colon' => __( 'Parent ', 'jigoshop') . $nicename . ':',
'edit_item' => __( 'Edit ', 'jigoshop') . $nicename,
'update_item' => __( 'Update ', 'jigoshop') . $nicename,
'add_new_item' => __( 'Add New ', 'jigoshop') . $nicename,
'new_item_name' => __( 'New ', 'jigoshop') . $nicename
),
'show_ui' => false,
'query_var' => true,
'rewrite' => array( 'slug' => strtolower(sanitize_title($nicename)), 'with_front' => false, 'hierarchical' => true ),
)
);
update_option('jigowatt_update_rewrite_rules', '1');
endif;
endif;
endforeach;
endif;
endif;
endforeach;
endif;
}
示例7: prepData
/**
* Parses XML File from Wordpress export. Handles name spacing and returns array
* containing accessible post ID's.
*
* @param string $path // path to XML file
*
* @return Array
*/
public function prepData($path)
{
$parser = new \WXR_Parser();
return @$parser->parse($path);
}
示例8: cherry_plugin_parse_xml
function cherry_plugin_parse_xml($file)
{
$file_content = file_get_contents($file);
$file_content = iconv('utf-8', 'utf-8//IGNORE', $file_content);
$file_content = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', '', $file_content);
if ($file_content != null) {
$dom = new DOMDocument('1.0');
$dom->loadXML($file_content);
$xml = simplexml_import_dom($dom);
$old_upload_url = $xml->xpath('/rss/channel/wp:base_site_url');
$old_upload_url = $old_upload_url[0];
$upload_dir = wp_upload_dir();
$upload_dir = $upload_dir['url'];
$cut_upload_dir = substr($upload_dir, strpos($upload_dir, 'wp-content/uploads'), strlen($upload_dir) - 1);
$cut_date_upload_dir = '<![CDATA[' . substr($upload_dir, strpos($upload_dir, 'wp-content/uploads') + 19, strlen($upload_dir) - 1);
$cut_date_upload_dir_2 = "\"" . substr($upload_dir, strpos($upload_dir, 'wp-content/uploads') + 19, strlen($upload_dir) - 1);
$pattern = '/wp-content\\/uploads\\/\\d{4}\\/\\d{2}/i';
$patternCDATA = '/<!\\[CDATA\\[\\d{4}\\/\\d{2}/i';
$pattern_meta_value = '/("|\')\\d{4}\\/\\d{2}/i';
$file_content = str_replace($old_upload_url, site_url(), $file_content);
$file_content = preg_replace($patternCDATA, $cut_date_upload_dir, $file_content);
$file_content = preg_replace($pattern_meta_value, $cut_date_upload_dir_2, $file_content);
$file_content = preg_replace($pattern, $cut_upload_dir, $file_content);
$parser = new WXR_Parser();
$parser_array = $parser->parse($file_content, $file);
$parser_array['site_settings'] = array('blogname' => implode($xml->xpath('/rss/channel/title')), 'blogdescription' => implode($xml->xpath('/rss/channel/description')));
return $parser_array;
} else {
exit('error');
}
}
示例9: parse
function parse($file)
{
$parser = new WXR_Parser();
// TFUSE 2012.02.10
$this->tfuse_import_options($file);
return $parser->parse($file);
}
示例10: import_fields
/**
* Import fields configuration from an exported WordPress View preset
* @param string $file path to file
* @return array Fields config array (unserialized)
*/
function import_fields($file)
{
if (empty($file) || !file_exists($file)) {
do_action('gravityview_log_error', '[import_fields] Importing Preset Fields. File not found. (File)', $file);
return false;
}
if (!class_exists('WXR_Parser')) {
include_once GRAVITYVIEW_DIR . 'includes/lib/xml-parsers/parsers.php';
}
$parser = new WXR_Parser();
$presets = $parser->parse($file);
if (is_wp_error($presets)) {
do_action('gravityview_log_error', '[import_fields] Importing Preset Fields failed. Threw WP_Error.', $presets);
return false;
}
if (empty($presets['posts'][0]['postmeta']) && !is_array($presets['posts'][0]['postmeta'])) {
do_action('gravityview_log_error', '[import_fields] Importing Preset Fields failed. Meta not found in file.', $file);
return false;
}
do_action('gravityview_log_debug', '[import_fields] postmeta', $presets['posts'][0]['postmeta']);
$fields = $widgets = array();
foreach ($presets['posts'][0]['postmeta'] as $meta) {
switch ($meta['key']) {
case '_gravityview_directory_fields':
$fields = maybe_unserialize($meta['value']);
break;
case '_gravityview_directory_widgets':
$widgets = maybe_unserialize($meta['value']);
break;
}
}
do_action('gravityview_log_debug', '[import_fields] Imported Preset (Fields)', $fields);
do_action('gravityview_log_debug', '[import_fields] Imported Preset (Widgets)', $widgets);
return array('fields' => $fields, 'widgets' => $widgets);
}
示例11: create_guest_authors_from_wxr
/**
* Subcommand to create guest authors from an author list in a WXR file
*
* @subcommand create-guest-authors-from-wxr
* @synopsis --file=<file>
*/
public function create_guest_authors_from_wxr($args, $assoc_args)
{
global $coauthors_plus;
$defaults = array('file' => '');
$this->args = wp_parse_args($assoc_args, $defaults);
if (empty($this->args['file']) || !is_readable($this->args['file'])) {
WP_CLI::error('Please specify a valid WXR file with the --file arg.');
}
if (!class_exists('WXR_Parser')) {
require_once WP_CONTENT_DIR . '/admin-plugins/wordpress-importer/parsers.php';
}
$parser = new WXR_Parser();
$import_data = $parser->parse($this->args['file']);
if (is_wp_error($import_data)) {
WP_CLI::error('Failed to read WXR file.');
}
// Get author nodes
$authors = $import_data['authors'];
foreach ($authors as $author) {
WP_CLI::line(sprintf('Processing author %s (%s)', $author['author_login'], $author['author_email']));
$guest_author_data = array('display_name' => $author['author_display_name'], 'user_login' => $author['author_login'], 'user_email' => $author['author_email'], 'first_name' => $author['author_first_name'], 'last_name' => $author['author_last_name'], 'ID' => $author['author_id']);
$guest_author_id = $this->create_guest_author($guest_author_data);
}
WP_CLI::line('All done!');
}
示例12: parse
/**
* Parse a WXR file
*
* @param string $file Path to WXR file for parsing
* @return array Information gathered from the WXR file
*/
function parse($file)
{
if (!class_exists('WXR_Parser')) {
require_once dirname(__FILE__) . '/parsers.php';
}
$parser = new WXR_Parser();
return $parser->parse($file);
}
示例13: demo_installer
//.........这里部分代码省略.........
?>
<div>
<h4 class="error" style="width:80%;text-align:center;margin:auto;"><?php
echo sprintf('File %s not found.', esc_url($this->content_demo));
?>
</h4>
</div>
<?php
} else {
?>
<div>
<h4 class="error" style="width:80%;text-align:center;margin:auto;">The file <?php
echo esc_url($this->content_demo);
?>
can't be read. Please change file permission to 777.</h4>
</div>
<?php
die;
}
}
} else {
?>
<div>
<h4 class="error" style="width:80%;text-align:center;margin:auto;"><?php
print_r($response->errors['http_request_failed'][0]);
?>
</h4>
</div>
<?php
die;
}
// include WXR file parsers
require_once dirname(__FILE__) . '/parsers.php';
$parser = new WXR_Parser();
$parsed_xml = $parser->parse($this->content_demo);
$post_array = array();
$page_array = array();
$portfolio_array = array();
$product_array = array();
foreach ($parsed_xml['posts'] as $key => $value) {
switch ($value['post_type']) {
case 'post':
$ids = array($value['post_id']);
foreach ($value['postmeta'] as $meta_key => $meta_value) {
if ($meta_value['key'] === '_uncode_blocks_list') {
$ids[] = $meta_value['value'];
}
}
$post_array[$value['post_title']] = array('ids' => $ids);
break;
case 'page':
$ids = array($value['post_id']);
foreach ($value['postmeta'] as $meta_key => $meta_value) {
if ($meta_value['key'] === '_uncode_blocks_list') {
$ids[] = $meta_value['value'];
}
}
$page_array[$value['post_title']] = array('ids' => $ids);
break;
case 'portfolio':
$ids = array($value['post_id']);
foreach ($value['postmeta'] as $meta_key => $meta_value) {
if ($meta_value['key'] === '_uncode_blocks_list') {
$ids[] = $meta_value['value'];
}
}
示例14: post_importer_compatibility
public function post_importer_compatibility($file)
{
global $wpdb;
if (!$this->wc_is_enabled() || !class_exists('WXR_Parser')) {
return;
}
$parser = new WXR_Parser();
$import_data = $parser->parse($file);
if (isset($import_data['posts'])) {
$posts = $import_data['posts'];
if ($posts && sizeof($posts) > 0) {
foreach ($posts as $post) {
if ($post['post_type'] == 'product') {
if ($post['terms'] && sizeof($post['terms']) > 0) {
foreach ($post['terms'] as $term) {
$domain = $term['domain'];
if (strstr($domain, 'pa_')) {
// Make sure it exists!
if (!taxonomy_exists($domain)) {
$nicename = strtolower(sanitize_title(str_replace('pa_', '', $domain)));
$exists_in_db = $wpdb->get_var($wpdb->prepare("SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $nicename));
// Create the taxonomy
if (!$exists_in_db) {
$wpdb->insert($wpdb->prefix . "woocommerce_attribute_taxonomies", array('attribute_name' => $nicename, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order'), array('%s', '%s', '%s'));
}
// Register the taxonomy now so that the import works!
register_taxonomy($domain, apply_filters('woocommerce_taxonomy_objects_' . $domain, array('product')), apply_filters('woocommerce_taxonomy_args_' . $domain, array('hierarchical' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => false)));
}
}
}
}
}
}
}
}
}
示例15: parse
/**
* Parse a WXR file
*
* @param string $file Path to WXR file for parsing
* @return array Information gathered from the WXR file
*/
function parse($file)
{
require dirname(__FILE__) . '/parsers.php';
$parser = new WXR_Parser();
return $parser->parse($file);
}