first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitef3a658a88d521398d72929dc54fa111::getLoader();

View File

@@ -0,0 +1,36 @@
# WP content importer used in OCDI
List of files from the [original repo](https://github.com/humanmade/WordPress-Importer/):
- class-logger-cli.php,
- class-logger.php,
- class-wxr-importer.php
One click demo import plugin page: https://wordpress.org/plugins/one-click-demo-import/
One click demo import github page: https://github.com/awesomemotive/one-click-demo-import
## Changelog
*July 21st 2020*
- Fixed incorrect post meta import.
- Fixed Elementor import after `wp_slash` updates in this repo.
*July 14th 2020*
- Fixed incorrect post and post meta import (unicode and other special characters were not escaped properly).
*February 7th 2018*
- Clean up the WXRImporter code
- Created a "wrapper" class `Importer.php` with additional functionality (importing by smaller parts -> users, categories, tags, terms and posts)
- tagging version 2.0
*October 29th 2016*
- Cleaned up this forked repo, to only include the thing we need in the OCDI plugin.
- Changed the class names and use psr-4 autoloading in composer.json
*October 26th 2016*
- made a fork from the original repo
- merged a pull request for "term meta data" from the original repo: https://github.com/humanmade/WordPress-Importer/pull/18

View File

@@ -0,0 +1,25 @@
{
"name": "awesomemotive/wp-content-importer-v2",
"description": "Improved WP content importer used in OCDI plugin.",
"keywords": ["wp", "wordpress", "awesomemotive", "theme", "import", "content"],
"license": "GPL-2.0+",
"authors": [
{
"name": "Gregor Capuder",
"email": "capuderg@gmail.com"
},
{
"name": "Primoz Cigler",
"email": "primoz@proteusnet.com"
},
{
"name" : "Humanmade contributors",
"homepage" : "https://github.com/humanmade/WordPress-Importer/graphs/contributors"
}
],
"autoload": {
"psr-4": {
"AwesomeMotive\\WPContentImporter2\\": "src/"
}
}
}

View File

@@ -0,0 +1,629 @@
<?php
/**
* The main importer class, extending the slightly modified WP importer 2.0 class WXRImporter
*/
namespace AwesomeMotive\WPContentImporter2;
use XMLReader;
class Importer extends WXRImporter {
/**
* Time in milliseconds, marking the beginning of the import.
*
* @var float
*/
private $start_time;
/**
* Importer constructor.
* Look at the parent constructor for the options parameters.
*
* @param array $options The importer options.
* @param object $logger The logger object.
*/
public function __construct( $options = array(), $logger = null ) {
parent::__construct( $options );
$this->set_logger( $logger );
// Check, if a new AJAX request is required.
add_filter( 'wxr_importer.pre_process.post', array( $this, 'new_ajax_request_maybe' ) );
// WooCommerce product attributes registration.
if ( class_exists( 'WooCommerce' ) ) {
add_filter( 'wxr_importer.pre_process.term', array( $this, 'woocommerce_product_attributes_registration' ), 10, 1 );
}
}
/**
* Get the XML reader for the file.
*
* @param string $file Path to the XML file.
*
* @return XMLReader|boolean Reader instance on success, false otherwise.
*/
protected function get_reader( $file ) {
// Avoid loading external entities for security
$old_value = null;
if ( function_exists( 'libxml_disable_entity_loader' ) ) {
// $old_value = libxml_disable_entity_loader( true );
}
if ( ! class_exists( 'XMLReader' ) ) {
$this->logger->critical( __( 'The XMLReader class is missing! Please install the XMLReader PHP extension on your server', 'wordpress-importer' ) );
return false;
}
$reader = new XMLReader();
$status = $reader->open( $file );
if ( ! is_null( $old_value ) ) {
// libxml_disable_entity_loader( $old_value );
}
if ( ! $status ) {
$this->logger->error( __( 'Could not open the XML file for parsing!', 'wordpress-importer' ) );
return false;
}
return $reader;
}
/**
* Get the basic import content data.
* Which elements are present in this import file (check possible elements in the $data variable)?
*
* @param $file
*
* @return array|bool
*/
public function get_basic_import_content_data( $file ) {
$data = array(
'users' => false,
'categories' => false,
'tags' => false,
'terms' => false,
'posts' => false,
);
// Get the XML reader and open the file.
$reader = $this->get_reader( $file );
if ( empty( $reader ) ) {
return false;
}
// Start parsing!
while ( $reader->read() ) {
// Only deal with element opens.
if ( $reader->nodeType !== XMLReader::ELEMENT ) {
continue;
}
switch ( $reader->name ) {
case 'wp:author':
// Skip, if the users were already detected.
if ( $data['users'] ) {
$reader->next();
break;
}
$node = $reader->expand();
$parsed = $this->parse_author_node( $node );
// Skip, if there was an error in parsing the author node.
if ( is_wp_error( $parsed ) ) {
$reader->next();
break;
}
$data['users'] = true;
// Handled everything in this node, move on to the next.
$reader->next();
break;
case 'item':
// Skip, if the posts were already detected.
if ( $data['posts'] ) {
$reader->next();
break;
}
$node = $reader->expand();
$parsed = $this->parse_post_node( $node );
// Skip, if there was an error in parsing the item node.
if ( is_wp_error( $parsed ) ) {
$reader->next();
break;
}
$data['posts'] = true;
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'wp:category':
$data['categories'] = true;
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'wp:tag':
$data['tags'] = true;
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'wp:term':
$data['terms'] = true;
// Handled everything in this node, move on to the next
$reader->next();
break;
}
}
return $data;
}
/**
* Get the number of posts (posts, pages, CPT, attachments), that the import file has.
*
* @param $file
*
* @return int
*/
public function get_number_of_posts_to_import( $file ) {
$reader = $this->get_reader( $file );
$counter = 0;
if ( empty( $reader ) ) {
return $counter;
}
// Start parsing!
while ( $reader->read() ) {
// Only deal with element opens.
if ( $reader->nodeType !== XMLReader::ELEMENT ) {
continue;
}
if ( 'item' == $reader->name ) {
$node = $reader->expand();
$parsed = $this->parse_post_node( $node );
// Skip, if there was an error in parsing the item node.
if ( is_wp_error( $parsed ) ) {
$reader->next();
continue;
}
$counter++;
}
}
return $counter;
}
/**
* The main controller for the actual import stage.
*
* @param string $file Path to the WXR file for importing.
* @param array $options Import options (which parts to import).
*
* @return boolean
*/
public function import( $file, $options = array() ) {
add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
// Start the import timer.
$this->start_time = microtime( true );
// Set the existing import data, from previous AJAX call, if any.
$this->restore_import_data_transient();
// Set the import options defaults.
if ( empty( $options ) ) {
$options = array(
'users' => false,
'categories' => true,
'tags' => true,
'terms' => true,
'posts' => true,
);
}
$result = $this->import_start( $file );
if ( is_wp_error( $result ) ) {
$this->logger->error( __( 'Content import start error: ', 'wordpress-importer' ) . $result->get_error_message() );
return false;
}
// Get the actual XML reader.
$reader = $this->get_reader( $file );
if ( empty( $reader ) ) {
return false;
}
// Set the version to compatibility mode first
$this->version = '1.0';
// Reset other variables
$this->base_url = '';
// Start parsing!
while ( $reader->read() ) {
// Only deal with element opens.
if ( $reader->nodeType !== XMLReader::ELEMENT ) {
continue;
}
switch ( $reader->name ) {
case 'wp:wxr_version':
// Upgrade to the correct version
$this->version = $reader->readString();
if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
$this->logger->warning( sprintf(
__( 'This WXR file (version %s) is newer than the importer (version %s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
$this->version,
self::MAX_WXR_VERSION
) );
}
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'wp:base_site_url':
$this->base_url = $reader->readString();
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'item':
if ( empty( $options['posts'] ) ) {
$reader->next();
break;
}
$node = $reader->expand();
$parsed = $this->parse_post_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$this->process_post( $parsed['data'], $parsed['meta'], $parsed['comments'], $parsed['terms'] );
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'wp:author':
if ( empty( $options['users'] ) ) {
$reader->next();
break;
}
$node = $reader->expand();
$parsed = $this->parse_author_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$status = $this->process_author( $parsed['data'], $parsed['meta'] );
if ( is_wp_error( $status ) ) {
$this->log_error( $status );
}
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'wp:category':
if ( empty( $options['categories'] ) ) {
$reader->next();
break;
}
$node = $reader->expand();
$parsed = $this->parse_term_node( $node, 'category' );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'wp:tag':
if ( empty( $options['tags'] ) ) {
$reader->next();
break;
}
$node = $reader->expand();
$parsed = $this->parse_term_node( $node, 'tag' );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
// Handled everything in this node, move on to the next
$reader->next();
break;
case 'wp:term':
if ( empty( $options['terms'] ) ) {
$reader->next();
break;
}
$node = $reader->expand();
$parsed = $this->parse_term_node( $node );
if ( is_wp_error( $parsed ) ) {
$this->log_error( $parsed );
// Skip the rest of this post
$reader->next();
break;
}
$status = $this->process_term( $parsed['data'], $parsed['meta'] );
// Handled everything in this node, move on to the next
$reader->next();
break;
default:
// Skip this node, probably handled by something already
break;
}
}
// Now that we've done the main processing, do any required
// post-processing and remapping.
$this->post_process();
if ( $this->options['aggressive_url_search'] ) {
$this->replace_attachment_urls_in_content();
}
$this->remap_featured_images();
$this->import_end();
// Set the current importer state, so the data can be used on the next AJAX call.
$this->set_current_importer_data();
return true;
}
/**
* Import users only.
*
* @param string $file Path to the import file.
*/
public function import_users( $file ) {
return $this->import( $file, array( 'users' => true ) );
}
/**
* Import categories only.
*
* @param string $file Path to the import file.
*/
public function import_categories( $file ) {
return $this->import( $file, array( 'categories' => true ) );
}
/**
* Import tags only.
*
* @param string $file Path to the import file.
*/
public function import_tags( $file ) {
return $this->import( $file, array( 'tags' => true ) );
}
/**
* Import terms only.
*
* @param string $file Path to the import file.
*/
public function import_terms( $file ) {
return $this->import( $file, array( 'terms' => true ) );
}
/**
* Import posts only.
*
* @param string $file Path to the import file.
*/
public function import_posts( $file ) {
return $this->import( $file, array( 'posts' => true ) );
}
/**
* Check if we need to create a new AJAX request, so that server does not timeout.
* And fix the import warning for missing post author.
*
* @param array $data current post data.
* @return array
*/
public function new_ajax_request_maybe( $data ) {
$time = microtime( true ) - $this->start_time;
// We should make a new ajax call, if the time is right.
if ( $time > apply_filters( 'pt-importer/time_for_one_ajax_call', 20 ) ) {
$response = apply_filters( 'pt-importer/new_ajax_request_response_data', array(
'status' => 'newAJAX',
'log' => 'Time for new AJAX request!: ' . $time,
'num_of_imported_posts' => count( $this->mapping['post'] ),
) );
// Add message to log file.
$this->logger->info( __( 'New AJAX call!', 'wordpress-importer' ) );
// Set the current importer state, so it can be continued on the next AJAX call.
$this->set_current_importer_data();
// Send the request for a new AJAX call.
wp_send_json( $response );
}
// Set importing author to the current user.
// Fixes the [WARNING] Could not find the author for ... log warning messages.
$current_user_obj = wp_get_current_user();
$data['post_author'] = $current_user_obj->user_login;
return $data;
}
/**
* Save current importer data to the DB, for later use.
*/
public function set_current_importer_data() {
$data = apply_filters( 'pt-importer/set_current_importer_data', array(
'options' => $this->options,
'mapping' => $this->mapping,
'requires_remapping' => $this->requires_remapping,
'exists' => $this->exists,
'user_slug_override' => $this->user_slug_override,
'url_remap' => $this->url_remap,
'featured_images' => $this->featured_images,
) );
$this->save_current_import_data_transient( $data );
}
/**
* Set the importer data to the transient.
*
* @param array $data Data to be saved to the transient.
*/
public function save_current_import_data_transient( $data ) {
set_transient( 'pt_importer_data', $data, MINUTE_IN_SECONDS );
}
/**
* Restore the importer data from the transient.
*
* @return boolean
*/
public function restore_import_data_transient() {
if ( $data = get_transient( 'pt_importer_data' ) ) {
$this->options = empty( $data['options'] ) ? array() : $data['options'];
$this->mapping = empty( $data['mapping'] ) ? array() : $data['mapping'];
$this->requires_remapping = empty( $data['requires_remapping'] ) ? array() : $data['requires_remapping'];
$this->exists = empty( $data['exists'] ) ? array() : $data['exists'];
$this->user_slug_override = empty( $data['user_slug_override'] ) ? array() : $data['user_slug_override'];
$this->url_remap = empty( $data['url_remap'] ) ? array() : $data['url_remap'];
$this->featured_images = empty( $data['featured_images'] ) ? array() : $data['featured_images'];
do_action( 'pt-importer/restore_import_data_transient' );
return true;
}
return false;
}
/**
* Get the importer mapping data.
*
* @return array An empty array or an array of mapping data.
*/
public function get_mapping() {
return $this->mapping;
}
/**
* Hook into the pre-process term filter of the content import and register the
* custom WooCommerce product attributes, so that the terms can then be imported normally.
*
* This should probably be removed once the WP importer 2.0 support is added in WooCommerce.
*
* Fixes: [WARNING] Failed to import pa_size L warnings in content import.
* Code from: woocommerce/includes/admin/class-wc-admin-importers.php (ver 2.6.9).
*
* Github issue: https://github.com/awesomemotive/one-click-demo-import/issues/71
*
* @param array $date The term data to import.
* @return array The unchanged term data.
*/
public function woocommerce_product_attributes_registration( $data ) {
global $wpdb;
if ( strstr( $data['taxonomy'], 'pa_' ) ) {
if ( ! taxonomy_exists( $data['taxonomy'] ) ) {
$attribute_name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $data['taxonomy'] ) );
// 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(
$data['taxonomy'],
apply_filters( 'woocommerce_taxonomy_objects_' . $data['taxonomy'], array( 'product' ) ),
apply_filters( 'woocommerce_taxonomy_args_' . $data['taxonomy'], array(
'hierarchical' => true,
'show_ui' => false,
'query_var' => true,
'rewrite' => false,
) )
);
}
}
return $data;
}
}

View File

@@ -0,0 +1,137 @@
<?php
namespace AwesomeMotive\WPContentImporter2;
/**
* Describes a logger instance
*
* Based on PSR-3: http://www.php-fig.org/psr/psr-3/
*
* The message MUST be a string or object implementing __toString().
*
* The message MAY contain placeholders in the form: {foo} where foo
* will be replaced by the context data in key "foo".
*
* The context array can contain arbitrary data, the only assumption that
* can be made by implementors is that if an Exception instance is given
* to produce a stack trace, it MUST be in a key named "exception".
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
* for the full interface specification.
*/
class WPImporterLogger {
/**
* System is unusable.
*
* @param string $message
* @param array $context
* @return null
*/
public function emergency( $message, array $context = array() ) {
return $this->log( 'emergency', $message, $context );
}
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param string $message
* @param array $context
* @return null
*/
public function alert( $message, array $context = array() ) {
return $this->log( 'alert', $message, $context );
}
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
* @param array $context
* @return null
*/
public function critical( $message, array $context = array() ) {
return $this->log( 'critical', $message, $context );
}
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string $message
* @param array $context
* @return null
*/
public function error( $message, array $context = array()) {
return $this->log( 'error', $message, $context );
}
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param string $message
* @param array $context
* @return null
*/
public function warning( $message, array $context = array() ) {
return $this->log( 'warning', $message, $context );
}
/**
* Normal but significant events.
*
* @param string $message
* @param array $context
* @return null
*/
public function notice( $message, array $context = array() ) {
return $this->log( 'notice', $message, $context );
}
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string $message
* @param array $context
* @return null
*/
public function info( $message, array $context = array() ) {
return $this->log( 'info', $message, $context );
}
/**
* Detailed debug information.
*
* @param string $message
* @param array $context
* @return null
*/
public function debug( $message, array $context = array() ) {
return $this->log( 'debug', $message, $context );
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log( $level, $message, array $context = array() ) {
$this->messages[] = array(
'timestamp' => time(),
'level' => $level,
'message' => $message,
'context' => $context,
);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace AwesomeMotive\WPContentImporter2;
class WPImporterLoggerCLI extends WPImporterLogger {
public $min_level = 'notice';
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log( $level, $message, array $context = array() ) {
if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) {
return;
}
printf(
'[%s] %s' . PHP_EOL,
strtoupper( $level ),
$message
);
}
public static function level_to_numeric( $level ) {
$levels = array(
'emergency' => 8,
'alert' => 7,
'critical' => 6,
'error' => 5,
'warning' => 4,
'notice' => 3,
'info' => 2,
'debug' => 1,
);
if ( ! isset( $levels[ $level ] ) ) {
return 0;
}
return $levels[ $level ];
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace AwesomeMotive\WPContentImporter2;
class WXRImportInfo {
public $home;
public $siteurl;
public $title;
public $users = array();
public $post_count = 0;
public $media_count = 0;
public $comment_count = 0;
public $term_count = 0;
public $generator = '';
public $version;
}

View File

@@ -0,0 +1,445 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

View File

@@ -0,0 +1,21 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,9 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,11 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'OCDI\\' => array($baseDir . '/inc'),
'AwesomeMotive\\WPContentImporter2\\' => array($vendorDir . '/awesomemotive/wp-content-importer-v2/src'),
);

View File

@@ -0,0 +1,55 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitef3a658a88d521398d72929dc54fa111
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitef3a658a88d521398d72929dc54fa111', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitef3a658a88d521398d72929dc54fa111', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitef3a658a88d521398d72929dc54fa111::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
return $loader;
}
}

View File

@@ -0,0 +1,39 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInitef3a658a88d521398d72929dc54fa111
{
public static $prefixLengthsPsr4 = array (
'O' =>
array (
'OCDI\\' => 5,
),
'A' =>
array (
'AwesomeMotive\\WPContentImporter2\\' => 33,
),
);
public static $prefixDirsPsr4 = array (
'OCDI\\' =>
array (
0 => __DIR__ . '/../..' . '/inc',
),
'AwesomeMotive\\WPContentImporter2\\' =>
array (
0 => __DIR__ . '/..' . '/awesomemotive/wp-content-importer-v2/src',
),
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitef3a658a88d521398d72929dc54fa111::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitef3a658a88d521398d72929dc54fa111::$prefixDirsPsr4;
}, null, ClassLoader::class);
}
}

View File

@@ -0,0 +1,55 @@
[
{
"name": "awesomemotive/wp-content-importer-v2",
"version": "v3.0.3",
"version_normalized": "3.0.3.0",
"source": {
"type": "git",
"url": "https://github.com/awesomemotive/WordPress-Importer.git",
"reference": "318c7657f4a4a84cf9e5a0d7f8d6ee2b2d0d0e9e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/awesomemotive/WordPress-Importer/zipball/318c7657f4a4a84cf9e5a0d7f8d6ee2b2d0d0e9e",
"reference": "318c7657f4a4a84cf9e5a0d7f8d6ee2b2d0d0e9e",
"shasum": ""
},
"time": "2020-07-21T15:06:58+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"AwesomeMotive\\WPContentImporter2\\": "src/"
}
},
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "Gregor Capuder",
"email": "capuderg@gmail.com"
},
{
"name": "Primoz Cigler",
"email": "primoz@proteusnet.com"
},
{
"name": "Humanmade contributors",
"homepage": "https://github.com/humanmade/WordPress-Importer/graphs/contributors"
}
],
"description": "Improved WP content importer used in OCDI plugin.",
"keywords": [
"awesomemotive",
"content",
"import",
"theme",
"wordpress",
"wp"
],
"support": {
"source": "https://github.com/awesomemotive/WordPress-Importer/tree/v3.0.3"
}
}
]