本文整理汇总了PHP中wp_all_import_secure_file函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_all_import_secure_file函数的具体用法?PHP wp_all_import_secure_file怎么用?PHP wp_all_import_secure_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_all_import_secure_file函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_all_import_get_gz
function wp_all_import_get_gz($filename, $use_include_path = 0, $targetDir = false)
{
$type = 'csv';
$uploads = wp_upload_dir();
$targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
$tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
$localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
$fp = @fopen($localPath, 'w');
$file = @gzopen($filename, 'rb', $use_include_path);
if ($file) {
$first_chunk = true;
while (!gzeof($file)) {
$chunk = gzread($file, 1024);
if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
$type = 'xml';
$first_chunk = false;
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
@fwrite($fp, $chunk);
}
gzclose($file);
} else {
$tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
$localGZpath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
$request = get_file_curl($filename, $localGZpath, false, true);
if (!is_wp_error($request)) {
$file = @gzopen($localGZpath, 'rb', $use_include_path);
if ($file) {
$first_chunk = true;
while (!gzeof($file)) {
$chunk = gzread($file, 1024);
if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
$type = 'xml';
$first_chunk = false;
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
@fwrite($fp, $chunk);
}
gzclose($file);
}
@unlink($localGZpath);
} else {
return $request;
}
}
@fclose($fp);
if (preg_match('%\\W(gz)$%i', basename($localPath))) {
if (@rename($localPath, str_replace('.gz', '.' . $type, $localPath))) {
$localPath = str_replace('.gz', '.' . $type, $localPath);
}
} else {
if (@rename($localPath, $localPath . '.' . $type)) {
$localPath = $localPath . '.' . $type;
}
}
return array('type' => $type, 'localPath' => $localPath);
}
示例2: __construct
function __construct($file, $errors, $targetDir = false)
{
$this->file = $file;
$this->errors = $errors;
$uploads = wp_upload_dir();
if ($uploads['error']) {
$this->uploadsPath = false;
} else {
$this->uploadsPath = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
}
}
示例3: delete
public function delete($db = true)
{
if ($this->id) {
// delete history file first
$uploads = wp_upload_dir();
$history_file_path = wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::LOGS_DIRECTORY, $this->id) . DIRECTORY_SEPARATOR . $this->id . '.html';
if (@file_exists($history_file_path)) {
wp_all_import_remove_source($history_file_path);
}
}
return $db ? parent::delete() : true;
}
示例4: __construct
public function __construct()
{
parent::__construct();
self::$upload_transient = 'pmxi_uploads_path';
$uploads = wp_upload_dir();
$is_secure_import = PMXI_Plugin::getInstance()->getOption('secure');
if (!$is_secure_import) {
self::$path = wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY);
} else {
self::$path = get_transient(self::$upload_transient);
if (empty(self::$path)) {
self::$path = wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY);
set_transient(self::$upload_transient, self::$path);
}
}
}
示例5: log
public function log()
{
$nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : '';
if (!wp_verify_nonce($nonce, '_wpnonce-download_log')) {
die(__('Security check', 'wp_all_import_plugin'));
} else {
$id = $this->input->get('history_id');
$import_id = $this->input->get('id');
$wp_uploads = wp_upload_dir();
$log_file = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::LOGS_DIRECTORY, $id) . DIRECTORY_SEPARATOR . $id . '.html';
if (file_exists($log_file)) {
PMXI_download::xml($log_file);
} else {
wp_redirect(add_query_arg(array('id' => $import_id, 'pmxi_nt' => urlencode(__('Log file does not exists.', 'wp_all_import_plugin'))), $this->baseUrl));
die;
}
}
}
示例6: __construct
function __construct($file, $errors, $targetDir = false)
{
$this->file = $file;
$this->errors = $errors;
$uploads = wp_upload_dir();
$input = new PMXI_Input();
$import_id = $input->get('id');
if (empty($import_id)) {
$import_id = $input->get('import_id');
}
if (empty($import_id)) {
$import_id = false;
}
if ($uploads['error']) {
$this->uploadsPath = false;
} else {
$this->uploadsPath = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY, $import_id, true) : $targetDir;
}
}
示例7: __construct
/**
* data load initialize
*
* @param mixed $filename please look at the load() method
*
* @access public
* @see load()
* @return void
*/
public function __construct($options = array('filename' => null, 'xpath' => '', 'delimiter' => '', 'encoding' => '', 'xml_path' => '', 'targetDir' => false))
{
PMXI_Plugin::$csv_path = $options['filename'];
$this->xpath = !empty($options['xpath']) ? $options['xpath'] : (!empty($_POST['xpath']) ? $_POST['xpath'] : '/node');
if (!empty($options['delimiter'])) {
$this->delimiter = $options['delimiter'];
} else {
$input = new PMXI_Input();
$id = $input->get('id', 0);
if (!$id) {
$id = $input->get('import_id', 0);
}
if ($id) {
$import = new PMXI_Import_Record();
$import->getbyId($id);
if (!$import->isEmpty()) {
$this->delimiter = $import->options['delimiter'];
}
}
}
if (!empty($options['encoding'])) {
$this->csv_encoding = $options['encoding'];
$this->auto_encoding = false;
}
if (!empty($options['xml_path'])) {
$this->xml_path = $options['xml_path'];
}
@ini_set("display_errors", 0);
@ini_set('auto_detect_line_endings', true);
$file_params = self::analyse_file($options['filename'], 1);
$this->set_settings(array('delimiter' => $file_params['delimiter']['value'], 'eol' => $file_params['line_ending']['value']));
unset($file_params);
$wp_uploads = wp_upload_dir();
$this->targetDir = empty($options['targetDir']) ? wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $options['targetDir'];
$this->load($options['filename']);
}
示例8: pmxi_wp_loaded
function pmxi_wp_loaded()
{
@ini_set("max_input_time", PMXI_Plugin::getInstance()->getOption('max_input_time'));
@ini_set("max_execution_time", PMXI_Plugin::getInstance()->getOption('max_execution_time'));
$table = PMXI_Plugin::getInstance()->getTablePrefix() . 'imports';
global $wpdb;
$imports = $wpdb->get_results("SELECT `id`, `name`, `path` FROM {$table} WHERE `path` IS NULL", ARRAY_A);
if (!empty($imports)) {
$importRecord = new PMXI_Import_Record();
$importRecord->clear();
foreach ($imports as $imp) {
$importRecord->getById($imp['id']);
if (!$importRecord->isEmpty()) {
$importRecord->delete(true);
}
$importRecord->clear();
}
}
/* Check if cron is manualy, then execute import */
$cron_job_key = PMXI_Plugin::getInstance()->getOption('cron_job_key');
if (!empty($cron_job_key) and !empty($_GET['import_id']) and !empty($_GET['import_key']) and $_GET['import_key'] == $cron_job_key and !empty($_GET['action']) and in_array($_GET['action'], array('processing', 'trigger', 'pipe'))) {
$logger = create_function('$m', 'echo "<p>$m</p>\\n";');
$import = new PMXI_Import_Record();
$ids = explode(',', $_GET['import_id']);
if (!empty($ids) and is_array($ids)) {
foreach ($ids as $id) {
if (empty($id)) {
continue;
}
$import->getById($id);
if (!$import->isEmpty()) {
if (!in_array($import->type, array('url', 'ftp', 'file'))) {
$logger and call_user_func($logger, sprintf(__('Scheduling update is not working with "upload" import type. Import #%s.', 'wp_all_import_plugin'), $id));
}
switch ($_GET['action']) {
case 'trigger':
if ((int) $import->executing) {
$logger and call_user_func($logger, sprintf(__('Import #%s is currently in manually process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif (!$import->processing and !$import->triggered) {
$import->set(array('triggered' => 1, 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'queue_chunk_number' => 0, 'last_activity' => date('Y-m-d H:i:s')))->update();
$history_log = new PMXI_History_Record();
$history_log->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => 'trigger', 'summary' => __("triggered by cron", "wp_all_import_plugin")))->save();
$logger and call_user_func($logger, sprintf(__('#%s Cron job triggered.', 'wp_all_import_plugin'), $id));
} elseif ($import->processing and !$import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s currently in process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif (!$import->processing and $import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s already triggered. Request skipped.', 'wp_all_import_plugin'), $id));
}
break;
case 'processing':
if ($import->processing == 1 and time() - strtotime($import->registered_on) > (PMXI_Plugin::getInstance()->getOption('cron_processing_time_limit') ? PMXI_Plugin::getInstance()->getOption('cron_processing_time_limit') : 120)) {
// it means processor crashed, so it will reset processing to false, and terminate. Then next run it will work normally.
$import->set(array('processing' => 0))->update();
}
// start execution imports that is in the cron process
if (!(int) $import->triggered) {
$logger and call_user_func($logger, sprintf(__('Import #%s is not triggered. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif ((int) $import->executing) {
$logger and call_user_func($logger, sprintf(__('Import #%s is currently in manually process. Request skipped.', 'wp_all_import_plugin'), $id));
} elseif ((int) $import->triggered and !(int) $import->processing) {
$log_storage = (int) PMXI_Plugin::getInstance()->getOption('log_storage');
// unlink previous logs
$by = array();
$by[] = array(array('import_id' => $id, 'type NOT LIKE' => 'trigger'), 'AND');
$historyLogs = new PMXI_History_List();
$historyLogs->setColumns('id', 'import_id', 'type', 'date')->getBy($by, 'id ASC');
if ($historyLogs->count() and $historyLogs->count() >= $log_storage) {
$logsToRemove = $historyLogs->count() - $log_storage;
foreach ($historyLogs as $i => $file) {
$historyRecord = new PMXI_History_Record();
$historyRecord->getBy('id', $file['id']);
if (!$historyRecord->isEmpty()) {
$historyRecord->delete();
}
// unlink history file only
if ($i == $logsToRemove) {
break;
}
}
}
$history_log = new PMXI_History_Record();
$history_log->set(array('import_id' => $import->id, 'date' => date('Y-m-d H:i:s'), 'type' => 'processing', 'summary' => __("cron processing", "wp_all_import_plugin")))->save();
if ($log_storage) {
$wp_uploads = wp_upload_dir();
$log_file = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::LOGS_DIRECTORY, $history_log->id) . DIRECTORY_SEPARATOR . $history_log->id . '.html';
if (@file_exists($log_file)) {
wp_all_import_remove_source($log_file, false);
}
}
ob_start();
$import->set(array('canceled' => 0, 'failed' => 0))->execute($logger, true, $history_log->id);
$log_data = ob_get_clean();
if ($log_storage) {
$log = @fopen($log_file, 'a+');
@fwrite($log, $log_data);
@fclose($log);
}
if (!(int) $import->queue_chunk_number) {
$logger and call_user_func($logger, sprintf(__('Import #%s complete', 'wp_all_import_plugin'), $import->id));
} else {
//.........这里部分代码省略.........
示例9: process
//.........这里部分代码省略.........
Split file up into 1000 record chunks.
This option will decrease the amount of slowdown experienced at the end of large imports.
The slowdown is partially caused by the need for WP All Import to read deeper and deeper into the file on each successive iteration.
Splitting the file into pieces means that, for example, instead of having to read 19000 records into a 20000 record file when importing the last 1000 records,
WP All Import will just split it into 20 chunks, and then read the last chunk from the beginning.
*/
if ("ajax" == $import->options['import_processing'] and $import->count > PMXI_Plugin::getInstance()->getOption('large_feed_limit') and $import->options['chuncking']) {
$chunk_files = array();
if (!empty(PMXI_Plugin::$session->local_paths)) {
$records_count = 0;
$chunk_records_count = 0;
$feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
foreach (PMXI_Plugin::$session->local_paths as $key => $path) {
$file = new PMXI_Chunk($path, array('element' => $import->root_element, 'encoding' => $import->options['encoding']));
// loop through the file until all lines are read
while ($xml = $file->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$chunk = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . $xml;
$dom = new DOMDocument('1.0', $import->options['encoding']);
$old = libxml_use_internal_errors(true);
$dom->loadXML($chunk);
// FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load
libxml_use_internal_errors($old);
$xpath = new DOMXPath($dom);
if ($elements = @$xpath->query($import->xpath) and $elements->length) {
$records_count += $elements->length;
$chunk_records_count += $elements->length;
$feed .= $xml;
}
}
if ($chunk_records_count == PMXI_Plugin::getInstance()->getOption('large_feed_limit') or $records_count == $import->count) {
$feed .= "</pmxi_records>";
$chunk_file_path = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY) . DIRECTORY_SEPARATOR . "pmxi_chunk_" . count($chunk_files) . "_" . basename($path);
file_put_contents($chunk_file_path, $feed);
$chunk_files[] = $chunk_file_path;
$chunk_records_count = 0;
$feed = "<?xml version=\"1.0\" encoding=\"" . $import->options['encoding'] . "\"?>" . "\n" . "<pmxi_records>";
}
}
}
PMXI_Plugin::$session->set('local_paths', $chunk_files);
}
}
PMXI_Plugin::$session->save_data();
if ($log_storage) {
$log_file = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::LOGS_DIRECTORY, $history_log->id) . DIRECTORY_SEPARATOR . $history_log->id . '.html';
if (PMXI_Plugin::$session->action != 'continue') {
if (file_exists($log_file)) {
wp_all_import_remove_source($log_file, false);
}
//@file_put_contents($log_file, sprintf(__('<p>Source path `%s`</p>', 'wp_all_import_plugin'), $import->path));
}
}
$this->data['ajax_processing'] = "ajax" == $import->options['import_processing'] ? true : false;
$this->render();
wp_ob_end_flush_all();
flush();
@set_time_limit(0);
$import_id = $input->get('id', 0);
if ("ajax" == $import->options['import_processing'] and !$import_id) {
PMXI_Plugin::$session->convertData($import->id);
//die();
}
} elseif (empty($import->id)) {
$import = new PMXI_Import_Record();
示例10: wp_upload_dir
break;
default:
# code...
break;
}
?>
</td>
<?php
break;
case 'download':
?>
<td style="vertical-align: middle;">
<?php
if (!in_array($item['type'], array('trigger'))) {
$wp_uploads = wp_upload_dir();
$log_file = wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::LOGS_DIRECTORY, $item['id']) . DIRECTORY_SEPARATOR . $item['id'] . '.html';
if (file_exists($log_file)) {
?>
<a href="<?php
echo add_query_arg(array('id' => $import->id, 'action' => 'log', 'history_id' => $item['id'], '_wpnonce' => wp_create_nonce('_wpnonce-download_log')), $this->baseUrl);
?>
"><?php
_e('Download Log', 'wp_all_import_plugin');
?>
</a>
<?php
} else {
_e('Log Unavailable', 'wp_all_import_plugin');
}
} else {
示例11: __construct
public function __construct($path, $targetDir = false)
{
$this->_filename = $path;
$wp_uploads = wp_upload_dir();
$this->targetDir = !$targetDir ? wp_all_import_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
}
示例12: wp_all_import_get_url
function wp_all_import_get_url($filePath, $targetDir = false, $contentType = false, $contentEncoding = false, $detect = false)
{
$type = $contentType;
$uploads = wp_upload_dir();
$targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
$tmpname = wp_unique_filename($targetDir, ($type and strlen(basename($filePath)) < 30) ? basename($filePath) : time());
$localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname)) . (!$type ? '.tmp' : '');
if ($contentEncoding == 'gzip') {
$file = @fopen($filePath);
} else {
$file = @fopen($filePath, "rb");
}
$is_valid = false;
if (is_resource($file)) {
$fp = @fopen($localPath, 'w');
$first_chunk = true;
while (!@feof($file)) {
$chunk = @fread($file, 1024);
if (!$type and $first_chunk and (strpos($chunk, "<?") !== false or strpos($chunk, "<rss") !== false) or strpos($chunk, "xmlns") !== false) {
$type = 'xml';
} elseif (!$type and $first_chunk) {
$type = 'csv';
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
$first_chunk = false;
@fwrite($fp, $chunk);
}
@fclose($file);
@fclose($fp);
$chunk = new PMXI_Chunk($localPath);
$is_valid = true;
if (!empty($chunk->options['element'])) {
$defaultXpath = "/" . $chunk->options['element'];
} else {
$is_valid = false;
}
if ($is_valid) {
while ($xml = $chunk->read()) {
if (!empty($xml)) {
PMXI_Import_Record::preprocessXml($xml);
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml;
$dom = new DOMDocument('1.0', 'UTF-8');
$old = libxml_use_internal_errors(true);
$dom->loadXML($xml);
libxml_use_internal_errors($old);
$xpath = new DOMXPath($dom);
if ($elements = $xpath->query($defaultXpath) and $elements->length) {
break;
}
}
}
if (empty($xml)) {
$is_valid = false;
}
}
unset($chunk);
}
if (!$is_valid) {
$request = get_file_curl($filePath, $localPath);
if (!is_wp_error($request)) {
if (!$type) {
if ($contentEncoding == 'gzip') {
$file = @fopen($localPath);
} else {
$file = @fopen($localPath, "rb");
}
while (!@feof($file)) {
$chunk = @fread($file, 1024);
if (strpos($chunk, "<?") !== false or strpos($chunk, "<rss") !== false or strpos($chunk, "xmlns") !== false) {
$type = 'xml';
} else {
$type = 'csv';
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
break;
}
@fclose($file);
}
} else {
return $request;
}
}
if (!preg_match('%\\W(' . $type . ')$%i', basename($localPath))) {
if (@rename($localPath, $localPath . '.' . $type)) {
$localPath = $localPath . '.' . $type;
}
}
return $detect ? array('type' => $type, 'localPath' => $localPath) : $localPath;
}
示例13: wp_all_import_get_gz
function wp_all_import_get_gz($filename, $use_include_path = 0, $targetDir = false, $headers = false)
{
$type = 'csv';
$uploads = wp_upload_dir();
$targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
$tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
$localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
$fp = @fopen($localPath, 'w');
$file = @gzopen($filename, 'rb', $use_include_path);
if ($file) {
$first_chunk = true;
while (!gzeof($file)) {
$chunk = gzread($file, 1024);
if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
$type = 'xml';
$first_chunk = false;
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
@fwrite($fp, $chunk);
}
gzclose($file);
} else {
$tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
$localGZpath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
$request = get_file_curl($filename, $localGZpath, false, true);
if (!is_wp_error($request)) {
$file = @gzopen($localGZpath, 'rb', $use_include_path);
if ($file) {
$first_chunk = true;
while (!gzeof($file)) {
$chunk = gzread($file, 1024);
if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
$type = 'xml';
$first_chunk = false;
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
@fwrite($fp, $chunk);
}
gzclose($file);
}
@unlink($localGZpath);
} else {
return $request;
}
}
@fclose($fp);
if (strpos($headers['Content-Disposition'], 'tar.gz') !== false && class_exists('PharData')) {
rename($localPath, $localPath . '.tar');
$phar = new PharData($localPath . '.tar');
$phar->extractTo($targetDir);
@unlink($localPath . '.tar');
$scanned_files = @scandir($targetDir);
if (!empty($scanned_files) and is_array($scanned_files)) {
$files = array_diff($scanned_files, array('.', '..'));
if (!empty($files)) {
foreach ($files as $file) {
if (preg_match('%\\W(csv|xml|json|sql|txt|xls|xlsx)$%i', basename($file))) {
$localPath = $targetDir . DIRECTORY_SEPARATOR . $file;
break;
}
}
}
}
}
if (preg_match('%\\W(gz)$%i', basename($localPath))) {
if (@rename($localPath, str_replace('.gz', '.' . $type, $localPath))) {
$localPath = str_replace('.gz', '.' . $type, $localPath);
}
} else {
if (@rename($localPath, $localPath . '.' . $type)) {
$localPath = $localPath . '.' . $type;
}
}
return array('type' => $type, 'localPath' => $localPath);
}
示例14: wp_all_import_get_url
function wp_all_import_get_url($filePath, $targetDir = false, $contentType = false, $contentEncoding = false, $detect = false)
{
$type = $contentType;
$uploads = wp_upload_dir();
$targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
$tmpname = wp_unique_filename($targetDir, ($type and strlen(basename($filePath)) < 30) ? basename($filePath) : time());
$localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname)) . (!$type ? '.tmp' : '');
if ($contentEncoding == 'gzip') {
$file = @fopen($filePath);
} else {
$file = @fopen($filePath, "rb");
}
if (is_resource($file)) {
$fp = @fopen($localPath, 'w');
$first_chunk = true;
while (!@feof($file)) {
$chunk = @fread($file, 1024);
if (!$type and $first_chunk and (strpos($chunk, "<?") !== false or strpos($chunk, "<rss") !== false) or strpos($chunk, "xmlns") !== false) {
$type = 'xml';
} elseif (!$type and $first_chunk) {
$type = 'csv';
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
$first_chunk = false;
@fwrite($fp, $chunk);
}
@fclose($file);
@fclose($fp);
}
if (!file_exists($localPath)) {
$request = get_file_curl($filePath, $localPath);
if (!is_wp_error($request)) {
if (!$type) {
if ($contentEncoding == 'gzip') {
$file = @fopen($localPath);
} else {
$file = @fopen($localPath, "rb");
}
while (!@feof($file)) {
$chunk = @fread($file, 1024);
if (strpos($chunk, "<?") !== false or strpos($chunk, "<rss") !== false or strpos($chunk, "xmlns") !== false) {
$type = 'xml';
} else {
$type = 'csv';
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
break;
}
@fclose($file);
}
} else {
return $request;
}
}
if (!preg_match('%\\W(' . $type . ')$%i', basename($localPath))) {
if (@rename($localPath, $localPath . '.' . $type)) {
$localPath = $localPath . '.' . $type;
}
}
return $detect ? array('type' => $type, 'localPath' => $localPath) : $localPath;
}