当前位置: 首页>>代码示例>>PHP>>正文


PHP PMXI_Import_Record::preprocessXml方法代码示例

本文整理汇总了PHP中PMXI_Import_Record::preprocessXml方法的典型用法代码示例。如果您正苦于以下问题:PHP PMXI_Import_Record::preprocessXml方法的具体用法?PHP PMXI_Import_Record::preprocessXml怎么用?PHP PMXI_Import_Record::preprocessXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PMXI_Import_Record的用法示例。


在下文中一共展示了PMXI_Import_Record::preprocessXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validateXml

 /**
  * Validate XML to be valid for import
  * @param string $xml
  * @param WP_Error[optional] $errors
  * @return bool Validation status
  */
 public static function validateXml(&$xml, $errors = NULL)
 {
     if (FALSE === $xml or '' == $xml) {
         $errors and $errors->add('form-validation', __('XML file does not exist, not accessible or empty', 'pmxi_plugin'));
     } else {
         PMXI_Import_Record::preprocessXml($xml);
         if (function_exists('simplexml_load_string')) {
             libxml_use_internal_errors(true);
             libxml_clear_errors();
             $_x = @simplexml_load_string($xml);
             $xml_errors = libxml_get_errors();
             libxml_clear_errors();
             if ($xml_errors) {
                 $error_msg = '<strong>' . __('Invalid XML', 'pmxi_plugin') . '</strong><ul>';
                 foreach ($xml_errors as $error) {
                     $error_msg .= '<li>';
                     $error_msg .= __('Line', 'pmxi_plugin') . ' ' . $error->line . ', ';
                     $error_msg .= __('Column', 'pmxi_plugin') . ' ' . $error->column . ', ';
                     $error_msg .= __('Code', 'pmxi_plugin') . ' ' . $error->code . ': ';
                     $error_msg .= '<em>' . trim(esc_html($error->message)) . '</em>';
                     $error_msg .= '</li>';
                 }
                 $error_msg .= '</ul>';
                 $errors and $errors->add('form-validation', $error_msg);
             } else {
                 return true;
             }
         } else {
             $errors and $errors->add('form-validation', __('simplexml module is disabled on your server', 'pmxi_plugin'));
         }
     }
     return false;
 }
开发者ID:thabofletcher,项目名称:tc-site,代码行数:39,代码来源:record.php

示例2: validateXml

 /**
  * Validate XML to be valid for import
  * @param string $xml
  * @param WP_Error[optional] $errors
  * @return bool Validation status
  */
 public static function validateXml(&$xml, $errors = NULL)
 {
     if (FALSE === $xml or '' == $xml) {
         $errors and $errors->add('form-validation', __('WP All Import can\'t read your file.<br/><br/>Probably, you are trying to import an invalid XML feed. Try opening the XML feed in a web browser (Google Chrome is recommended for opening XML files) to see if there is an error message.<br/>Alternatively, run the feed through a validator: http://validator.w3.org/<br/>99% of the time, the reason for this error is because your XML feed isn\'t valid.<br/>If you are 100% sure you are importing a valid XML feed, please contact WP All Import support.', 'wp_all_import_plugin'));
     } else {
         PMXI_Import_Record::preprocessXml($xml);
         if (function_exists('simplexml_load_string')) {
             libxml_use_internal_errors(true);
             libxml_clear_errors();
             $_x = @simplexml_load_string($xml);
             $xml_errors = libxml_get_errors();
             libxml_clear_errors();
             if ($xml_errors) {
                 $error_msg = '<strong>' . __('Invalid XML', 'wp_all_import_plugin') . '</strong><ul>';
                 foreach ($xml_errors as $error) {
                     $error_msg .= '<li>';
                     $error_msg .= __('Line', 'wp_all_import_plugin') . ' ' . $error->line . ', ';
                     $error_msg .= __('Column', 'wp_all_import_plugin') . ' ' . $error->column . ', ';
                     $error_msg .= __('Code', 'wp_all_import_plugin') . ' ' . $error->code . ': ';
                     $error_msg .= '<em>' . trim(esc_html($error->message)) . '</em>';
                     $error_msg .= '</li>';
                 }
                 $error_msg .= '</ul>';
                 $errors and $errors->add('form-validation', $error_msg);
             } else {
                 return true;
             }
         } else {
             $errors and $errors->add('form-validation', __('Required PHP components are missing.', 'wp_all_import_plugin'));
             $errors and $errors->add('form-validation', __('WP All Import requires the SimpleXML PHP module to be installed. This is a standard feature of PHP, and is necessary for WP All Import to read the files you are trying to import.<br/>Please contact your web hosting provider and ask them to install and activate the SimpleXML PHP module.', 'wp_all_import_plugin'));
         }
     }
     return false;
 }
开发者ID:k-hasan-19,项目名称:wp-all-import,代码行数:40,代码来源:record.php

示例3: merge

 public function merge()
 {
     /* Merge nested XML/CSV files */
     if (!empty($this->nested_files)) {
         $tmp_files = array();
         foreach ($this->nested_files as $key => $nfile) {
             $nested_fileURL = array_shift(XmlImportParser::factory($this->xml, $this->xpath, $nfile, $tmp_file)->parse());
             $tmp_files[] = $tmp_file;
             if (!empty($nested_fileURL)) {
                 $errors = new WP_Error();
                 $uploader = new PMXI_Upload($nested_fileURL, $errors);
                 $upload_result = $uploader->url();
                 if ($upload_result instanceof WP_Error) {
                     $errors = $upload_result;
                 } else {
                     $source = $upload_result['source'];
                     $filePath = $upload_result['filePath'];
                     if (!empty($upload_result['root_element'])) {
                         $root_element = $upload_result['root_element'];
                     } else {
                         $root_element = '';
                     }
                     $feed_type = $upload_result['feed_type'];
                 }
                 unset($uploader);
                 $nested_xml = file_get_contents($filePath);
                 if (!empty($nested_xml)) {
                     PMXI_Import_Record::preprocessXml($nested_xml);
                     if (PMXI_Import_Record::validateXml($nested_xml) === true) {
                         $nestedDom = new DOMDocument('1.0', 'UTF-8');
                         $nestedold = libxml_use_internal_errors(true);
                         $nestedDom->loadXML($nested_xml);
                         libxml_use_internal_errors($nestedold);
                         $second = $nestedDom->documentElement;
                         if ($second->hasChildNodes()) {
                             foreach ($second->childNodes as $node) {
                                 $importNode = $this->dom->importNode($node, true);
                                 $this->dom->documentElement->appendChild($importNode);
                             }
                             $this->xml = $this->elements ? $this->dom->saveXML($this->elements->item(0)) : $this->dom->saveXML();
                         }
                         unset($nestedDom);
                     }
                 }
             }
         }
         foreach ($tmp_files as $tmp_file) {
             // remove all temporary files created
             @unlink($tmp_file);
         }
     }
 }
开发者ID:lizbur10,项目名称:js_finalproject,代码行数:52,代码来源:nested.php

示例4: pmxi_wp_ajax_nested_xpath

function pmxi_wp_ajax_nested_xpath()
{
    if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
        exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin'))));
    }
    if (!current_user_can(PMXI_Plugin::$capabilities)) {
        exit(json_encode(array('result' => array(), 'msg' => __('Security check', 'wp_all_import_plugin'))));
    }
    extract($_POST);
    $result = array();
    if (@file_exists($filePath)) {
        $file = new PMXI_Chunk($filePath, array('element' => $root_element, 'encoding' => 'UTF-8'));
        $tagno = 0;
        $loop = 0;
        $count = 0;
        $xml_tree = '';
        while ($xml = $file->read()) {
            if (!empty($xml)) {
                PMXI_Import_Record::preprocessXml($xml);
                $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml;
                if ('' != $customXpath) {
                    $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($customXpath) and $elements->length) {
                        $loop++;
                        $count += $elements->length;
                        if (!$tagno or $loop == $tagno) {
                            ob_start();
                            PMXI_Render::render_xml_element($elements->item(0), true);
                            $xml_tree = ob_get_clean();
                            $tagno = 1;
                        }
                    }
                } else {
                    exit(json_encode(array('success' => false, 'msg' => __('XPath is required', 'wp_all_import_plugin'))));
                    die;
                }
            }
        }
        unset($file);
    } else {
        exit(json_encode(array('success' => false, 'msg' => 'File path is required', 'wp_all_import_plugin')));
        die;
    }
    exit(json_encode(array('success' => true, 'xml_tree' => $xml_tree, 'count' => $count ? sprintf("<p class='green pmxi_counter'>" . __('Elements found', 'pmxi_pligun') . " <strong>%s</strong></p>", $count) : "<p class='red pmxi_counter'>" . __('Elements not found', 'pmxi_pligun') . "</p>")));
    die;
}
开发者ID:estrategasdigitales,项目名称:rufiatta,代码行数:50,代码来源:wp_ajax_nested_xpath.php

示例5: update

 /**
  * Re-run import
  */
 public function update()
 {
     $id = $this->input->get('id');
     PMXI_Plugin::$session->clean_session($id);
     $action_type = false;
     $this->data['import'] = $item = new PMXI_Import_Record();
     if (!$id or $item->getById($id)->isEmpty()) {
         wp_redirect($this->baseUrl);
         die;
     }
     $this->data['isWizard'] = false;
     $default = PMXI_Plugin::get_default_import_options();
     $DefaultOptions = $item->options + $default;
     foreach (PMXI_Admin_Addons::get_active_addons() as $class) {
         if (class_exists($class)) {
             $DefaultOptions += call_user_func(array($class, "get_default_import_options"));
         }
     }
     $this->data['post'] =& $DefaultOptions;
     $this->data['source'] = array('path' => $item->path, 'root_element' => $item->root_element);
     $this->data['xpath'] = $item->xpath;
     $this->data['count'] = $item->count;
     $history = new PMXI_File_List();
     $history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $item->id), 'id DESC');
     if ($history->count()) {
         foreach ($history as $file) {
             if (@file_exists($file['path'])) {
                 $this->data['locfilePath'] = $file['path'];
                 break;
             }
         }
     }
     $chunks = 0;
     if ($this->input->post('is_confirmed') and check_admin_referer('confirm', '_wpnonce_confirm')) {
         $continue = $this->input->post('is_continue', 'no');
         // mark action type ad continue
         if ($continue == 'yes') {
             $action_type = 'continue';
         }
         $filePath = '';
         // upload new file in case when import is not continue
         if (empty(PMXI_Plugin::$session->chunk_number)) {
             if ($item->type == 'upload') {
                 // retrieve already uploaded file
                 $uploader = new PMXI_Upload(trim($item->path), $this->errors, rtrim(str_replace(basename($item->path), '', $item->path), '/'));
                 $upload_result = $uploader->upload();
                 if ($upload_result instanceof WP_Error) {
                     $this->errors = $upload_result;
                 } else {
                     $filePath = $upload_result['filePath'];
                 }
             }
             if (empty($item->options['encoding'])) {
                 $currentOptions = $item->options;
                 $currentOptions['encoding'] = 'UTF-8';
                 $item->set(array('options' => $currentOptions))->update();
             }
             @set_time_limit(0);
             $local_paths = !empty($local_paths) ? $local_paths : array($filePath);
             foreach ($local_paths as $key => $path) {
                 if (!empty($action_type) and $action_type == 'continue') {
                     $chunks = $item->count;
                 } else {
                     $file = new PMXI_Chunk($path, array('element' => $item->root_element, 'encoding' => $item->options['encoding']));
                     while ($xml = $file->read()) {
                         if (!empty($xml)) {
                             PMXI_Import_Record::preprocessXml($xml);
                             $xml = "<?xml version=\"1.0\" encoding=\"" . $item->options['encoding'] . "\"?>" . "\n" . $xml;
                             $dom = new DOMDocument('1.0', !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8');
                             $old = libxml_use_internal_errors(true);
                             $dom->loadXML($xml);
                             // 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($item->xpath) and !empty($elements) and !empty($elements->length)) {
                                 $chunks += $elements->length;
                             }
                             unset($dom, $xpath, $elements);
                         }
                     }
                     unset($file);
                 }
                 !$key and $filePath = $path;
             }
             if (empty($chunks)) {
                 $this->errors->add('form-validation', __('No matching elements found for Root element and XPath expression specified', 'wp_all_import_plugin'));
             }
         }
         if ($chunks) {
             // xml is valid
             if (!PMXI_Plugin::is_ajax() and empty(PMXI_Plugin::$session->chunk_number)) {
                 // compose data to look like result of wizard steps
                 $sesson_data = array('filePath' => $filePath, 'source' => array('name' => $item->name, 'type' => $item->type, 'path' => $item->path, 'root_element' => $item->root_element), 'feed_type' => $item->feed_type, 'update_previous' => $item->id, 'parent_import_id' => $item->parent_import_id, 'xpath' => $item->xpath, 'options' => $item->options, 'encoding' => !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8', 'is_csv' => !empty($item->options['delimiter']) ? $item->options['delimiter'] : PMXI_Plugin::$is_csv, 'csv_path' => PMXI_Plugin::$csv_path, 'chunk_number' => 1, 'log' => '', 'warnings' => 0, 'errors' => 0, 'start_time' => 0, 'pointer' => 1, 'count' => isset($chunks) ? $chunks : 0, 'local_paths' => !empty($local_paths) ? $local_paths : array(), 'action' => (!empty($action_type) and $action_type == 'continue') ? 'continue' : 'update', 'nonce' => wp_create_nonce('import'));
                 foreach ($sesson_data as $key => $value) {
                     PMXI_Plugin::$session->set($key, $value);
                 }
                 PMXI_Plugin::$session->save_data();
//.........这里部分代码省略.........
开发者ID:GolgoSoft,项目名称:KeenerWP,代码行数:101,代码来源:manage.php

示例6: pmxi_wp_ajax_upload_resource

function pmxi_wp_ajax_upload_resource()
{
    if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
        exit(json_encode(array('success' => false, 'errors' => '<div class="error inline"><p>' . __('Security check', 'wp_all_import_plugin') . '</p></div>')));
    }
    if (!current_user_can('manage_options')) {
        exit(json_encode(array('success' => false, 'errors' => '<div class="error inline"><p>' . __('Security check', 'wp_all_import_plugin') . '</p></div>')));
    }
    $input = new PMXI_Input();
    $post = $input->post(array('type' => '', 'file' => ''));
    $response = array('success' => true, 'errors' => false, 'upload_result' => '', 'filesize' => 0);
    if ($post['type'] == 'url') {
        $filesXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<data><node></node></data>";
        $files = XmlImportParser::factory($filesXML, '/data/node', $post['file'], $file)->parse();
        $tmp_files[] = $file;
        foreach ($tmp_files as $tmp_file) {
            // remove all temporary files created
            @unlink($tmp_file);
        }
        $file_to_import = $post['file'];
        if (!empty($files) and is_array($files)) {
            $file_to_import = array_shift($files);
        }
        $errors = new WP_Error();
        $uploader = new PMXI_Upload(trim($file_to_import), $errors);
        $upload_result = $uploader->url('', $post['file']);
        if ($upload_result instanceof WP_Error) {
            $errors = $upload_result;
            $msgs = $errors->get_error_messages();
            ob_start();
            ?>
			<?php 
            foreach ($msgs as $msg) {
                ?>
				<div class="error inline"><p><?php 
                echo $msg;
                ?>
</p></div>
			<?php 
            }
            ?>
			<?php 
            $response = array('success' => false, 'errors' => ob_get_clean());
        } else {
            // validate XML
            $file = new PMXI_Chunk($upload_result['filePath'], array('element' => $upload_result['root_element']));
            $is_valid = true;
            if (!empty($file->options['element'])) {
                $defaultXpath = "/" . $file->options['element'];
            } else {
                $is_valid = false;
            }
            if ($is_valid) {
                while ($xml = $file->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;
                        }
                    }
                    /*else {
                      	$is_valid = false;
                      	break;
                      }*/
                }
                if (empty($xml)) {
                    $is_valid = false;
                }
            }
            unset($file);
            if (!$is_valid) {
                ob_start();
                ?>
				
				<div class="error inline"><p><?php 
                _e('Please confirm you are importing a valid feed.<br/> Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.<br/><br/>WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.<br/><br/>It is also possible that there is a bug in WP All Import, and the problem is not with the feed.<br/><br/>If you need assistance, please contact support – <a href="mailto:support@wpallimport.com">support@wpallimport.com</a> – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'wp_all_import_plugin');
                ?>
</p></div>
				
				<?php 
                $response = array('success' => false, 'errors' => ob_get_clean());
            } else {
                $response['upload_result'] = $upload_result;
                $response['filesize'] = filesize($upload_result['filePath']);
            }
        }
    }
    exit(json_encode($response));
}
开发者ID:yarwalker,项目名称:ecobyt,代码行数:95,代码来源:wp_ajax_upload_resource.php

示例7: get_xml

 protected function get_xml($tagno = 0, $debug = false)
 {
     $xml = '';
     $update_previous = new PMXI_Import_Record();
     if (!empty(PMXI_Plugin::$session->update_previous)) {
         $update_previous->getById(PMXI_Plugin::$session->update_previous);
     }
     $local_paths = empty(PMXI_Plugin::$session->local_paths) ? array() : PMXI_Plugin::$session->local_paths;
     if (empty($local_paths) and !$update_previous->isEmpty()) {
         $history_file = new PMXI_File_Record();
         $history_file->getBy(array('import_id' => $update_previous->id), 'id DESC');
         $local_paths = !$history_file->isEmpty() ? array(wp_all_import_get_absolute_path($history_file->path)) : array();
     }
     if (!empty($local_paths)) {
         $loop = 0;
         foreach ($local_paths as $key => $path) {
             if (@file_exists($path)) {
                 $root_element = !$update_previous->isEmpty() ? $update_previous->root_element : PMXI_Plugin::$session->source['root_element'];
                 $file = new PMXI_Chunk($path, array('element' => $root_element, 'encoding' => PMXI_Plugin::$session->encoding));
                 while ($xml = $file->read()) {
                     if (!empty($xml)) {
                         PMXI_Import_Record::preprocessXml($xml);
                         $xml = "<?xml version=\"1.0\" encoding=\"" . PMXI_Plugin::$session->encoding . "\"?>" . "\n" . $xml;
                         if (PMXI_Plugin::$session->xpath) {
                             $dom = new DOMDocument('1.0', PMXI_Plugin::$session->encoding);
                             $old = libxml_use_internal_errors(true);
                             $dom->loadXML($xml);
                             libxml_use_internal_errors($old);
                             $xpath = new DOMXPath($dom);
                             if ($elements = $xpath->query(PMXI_Plugin::$session->xpath) and $elements->length) {
                                 $this->data['dom'] = $dom;
                                 $loop++;
                                 if (!$tagno or $loop == $tagno) {
                                     break;
                                 }
                             }
                         } else {
                             break;
                         }
                     }
                 }
                 unset($file);
             }
         }
     }
     return $xml;
 }
开发者ID:hikaram,项目名称:wee,代码行数:47,代码来源:import.php

示例8: upload


//.........这里部分代码省略.........
                    exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 101, "message" => __("Failed to open input stream.", "wp_all_import_plugin")), "id" => "id")));
                }
                fclose($in);
                fclose($out);
            } else {
                delete_transient(self::$upload_transient);
                exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 102, "message" => __("Failed to open output stream.", "wp_all_import_plugin")), "id" => "id")));
            }
        }
        $post_type = false;
        // Check if file has been uploaded
        if (!$chunks || $chunk == $chunks - 1) {
            // Strip the temp .part suffix off
            rename("{$filePath}.part", $filePath);
            chmod($filePath, 0755);
            delete_transient(self::$upload_transient);
            $errors = new WP_Error();
            $uploader = new PMXI_Upload($filePath, $errors, rtrim(str_replace(basename($filePath), '', $filePath), '/'));
            $upload_result = $uploader->upload();
            if ($upload_result instanceof WP_Error) {
                $errors = $upload_result;
                $msgs = $errors->get_error_messages();
                ob_start();
                ?>
				<?php 
                foreach ($msgs as $msg) {
                    ?>
					<div class="error inline"><p><?php 
                    echo $msg;
                    ?>
</p></div>
				<?php 
                }
                ?>
				<?php 
                $response = ob_get_clean();
                exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 102, "message" => $response), "id" => "id")));
            } else {
                // validate XML
                $file = new PMXI_Chunk($upload_result['filePath'], array('element' => $upload_result['root_element']));
                $is_valid = true;
                if (!empty($file->options['element'])) {
                    $defaultXpath = "/" . $file->options['element'];
                } else {
                    $is_valid = false;
                }
                if ($is_valid) {
                    while ($xml = $file->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;
                            }
                        }
                        /*else {
                          	$is_valid = false;
                          	break;
                          }*/
                    }
                    if (empty($xml)) {
                        $is_valid = false;
                    }
                }
                unset($file);
                if (!preg_match('%\\W(xml)$%i', trim($upload_result['source']['path']))) {
                    @unlink($upload_result['filePath']);
                }
                if (!$is_valid) {
                    ob_start();
                    ?>
					
					<div class="error inline"><p><?php 
                    _e('Please confirm you are importing a valid feed.<br/> Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.<br/><br/>WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.<br/><br/>It is also possible that there is a bug in WP All Import, and the problem is not with the feed.<br/><br/>If you need assistance, please contact support – <a href="mailto:support@wpallimport.com">support@wpallimport.com</a> – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'wp_all_import_plugin');
                    ?>
</p></div>
					
					<?php 
                    $response = ob_get_clean();
                    exit(json_encode(array("jsonrpc" => "2.0", "error" => array("code" => 102, "message" => $response), "id" => "id")));
                } else {
                    $wp_uploads = wp_upload_dir();
                    $uploads = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR;
                    if (!file_exists($uploads . basename($filePath))) {
                        @copy($filePath, $uploads . basename($filePath));
                    }
                }
                if (!empty($upload_result['post_type'])) {
                    $post_type = $upload_result['post_type'];
                }
            }
        }
        // Return JSON-RPC response
        exit(json_encode(array("jsonrpc" => "2.0", "error" => null, "result" => null, "id" => "id", "name" => $filePath, "post_type" => $post_type)));
    }
开发者ID:hikaram,项目名称:wee,代码行数:101,代码来源:settings.php

示例9: filter

 function filter($in, $out, &$consumed, $closing)
 {
     while ($bucket = stream_bucket_make_writeable($in)) {
         PMXI_Import_Record::preprocessXml($bucket->data);
         $consumed += $bucket->datalen;
         stream_bucket_append($out, $bucket);
     }
     return PSFS_PASS_ON;
 }
开发者ID:yarwalker,项目名称:ecobyt,代码行数:9,代码来源:chunk.php

示例10: pmxi_wp_ajax_parse_nested_file

/**
*
*	Ajax action that will parse nested XML/CSV files
*
*/
function pmxi_wp_ajax_parse_nested_file()
{
    extract($_POST);
    $result = array();
    $wp_uploads = wp_upload_dir();
    if (!empty($_POST['nested_type'])) {
        $root_element = '';
        $feed_type = '';
        $errors = new WP_Error();
        switch ($_POST['nested_type']) {
            case 'upload':
                $uploader = new PMXI_Upload($_POST['nested_filepath'], $errors);
                $upload_result = $uploader->upload();
                if ($upload_result instanceof WP_Error) {
                    $errors = $upload_result;
                } else {
                    $source = $upload_result['source'];
                    $filePath = $upload_result['filePath'];
                    if (!empty($upload_result['root_element'])) {
                        $root_element = $upload_result['root_element'];
                    }
                }
                break;
            case 'url':
                $uploader = new PMXI_Upload($_POST['nested_url'], $errors);
                $upload_result = $uploader->url();
                if ($upload_result instanceof WP_Error) {
                    $errors = $upload_result;
                } else {
                    $source = $upload_result['source'];
                    $filePath = $upload_result['filePath'];
                    if (!empty($upload_result['root_element'])) {
                        $root_element = $upload_result['root_element'];
                    }
                    $feed_type = $upload_result['feed_type'];
                }
                break;
            case 'file':
                $uploader = new PMXI_Upload($_POST['nested_file'], $errors);
                $upload_result = $uploader->file();
                if ($upload_result instanceof WP_Error) {
                    $errors = $upload_result;
                } else {
                    $source = $upload_result['source'];
                    $filePath = $upload_result['filePath'];
                    if (!empty($upload_result['root_element'])) {
                        $root_element = $upload_result['root_element'];
                    }
                }
                break;
        }
    }
    if ($errors->get_error_codes()) {
        $msgs = $errors->get_error_messages();
        ob_start();
        ?>
		<?php 
        foreach ($msgs as $msg) {
            ?>
			<div class="error"><p><?php 
            echo $msg;
            ?>
</p></div>
		<?php 
        }
        ?>
		<?php 
        exit(json_encode(array('success' => false, 'errors' => ob_get_clean())));
        die;
    } else {
        $xml_tree = '';
        if (@file_exists($filePath)) {
            $file = new PMXI_Chunk($filePath, array('element' => $root_element));
            if (!empty($file->options['element'])) {
                $customXpath = "/" . $file->options['element'];
                $elements_cloud = $file->cloud;
            }
            $root_element = $file->options['element'];
            $file = new PMXI_Chunk($filePath, array('element' => $root_element, 'encoding' => 'UTF-8'));
            $tagno = 0;
            $loop = 0;
            $count = 0;
            while ($xml = $file->read()) {
                if (!empty($xml)) {
                    PMXI_Import_Record::preprocessXml($xml);
                    $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml;
                    if ('' != $customXpath) {
                        $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($customXpath) and $elements->length) {
                            $loop++;
                            $count += $elements->length;
//.........这里部分代码省略.........
开发者ID:rebeccayshen,项目名称:kitlist,代码行数:101,代码来源:wp_ajax_parse_nested_file.php

示例11: execute


//.........这里部分代码省略.........
                     die;
                 }
                 $this->set(array('processing' => 0))->update();
                 // unlock cron requests
             }
             // if empty file path, than it's mean feed in cron process. Take feed path from history.
             if (empty($filePath)) {
                 $history = new PMXI_File_List();
                 $history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $this->id), 'id DESC');
                 if ($history->count()) {
                     $history_file = new PMXI_File_Record();
                     $history_file->getBy('id', $history[0]['id']);
                     $filePath = wp_all_import_get_absolute_path($history_file->path);
                 }
             }
             // if feed path found
             if (!empty($filePath) and @file_exists($filePath)) {
                 if ($this->queue_chunk_number === 1 and $this->processing == 0) {
                     // import first cron request
                     $this->set(array('processing' => 1))->update();
                     // lock cron requests
                     if (empty($this->options['encoding'])) {
                         $currentOptions = $this->options;
                         $currentOptions['encoding'] = 'UTF-8';
                         $this->set(array('options' => $currentOptions))->update();
                     }
                     set_time_limit(0);
                     $file = new PMXI_Chunk($filePath, array('element' => $this->root_element, 'encoding' => $this->options['encoding']));
                     // chunks counting
                     $chunks = 0;
                     $history_xml = '';
                     while ($xml = $file->read()) {
                         if (!empty($xml)) {
                             PMXI_Import_Record::preprocessXml($xml);
                             $xml = "<?xml version=\"1.0\" encoding=\"" . $this->options['encoding'] . "\"?>" . "\n" . $xml;
                             $dom = new DOMDocument('1.0', !empty($this->options['encoding']) ? $this->options['encoding'] : 'UTF-8');
                             $old = libxml_use_internal_errors(true);
                             $dom->loadXML($xml);
                             libxml_use_internal_errors($old);
                             $xpath = new DOMXPath($dom);
                             if ($elements = @$xpath->query($this->xpath) and $elements->length) {
                                 $chunks += $elements->length;
                                 if ("" == $history_xml) {
                                     $history_xml = $xml;
                                 }
                             }
                             unset($dom, $xpath, $elements);
                         }
                     }
                     unset($file);
                     if (!$chunks) {
                         //$logger and call_user_func($logger, sprintf(__('#%s No matching elements found for Root element and XPath expression specified', 'wp_all_import_plugin'), $this->id));
                         $this->set(array('queue_chunk_number' => 0, 'processing' => 0, 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'triggered' => 0))->update();
                         return array('status' => 500, 'message' => sprintf(__('#%s No matching elements found for Root element and XPath expression specified', 'wp_all_import_plugin'), $this->id));
                         die;
                     }
                     // unlick previous files
                     $history = new PMXI_File_List();
                     $history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $this->id), 'id DESC');
                     if ($history->count()) {
                         foreach ($history as $file) {
                             $history_file_path = wp_all_import_get_absolute_path($file['path']);
                             if (@file_exists($history_file_path) and $history_file_path != $filePath) {
                                 if (in_array($this->type, array('upload'))) {
                                     wp_all_import_remove_source($history_file_path, false);
                                 } else {
开发者ID:seoduda,项目名称:Patua,代码行数:67,代码来源:record.php

示例12: removeColonsFromRSS

 public static function removeColonsFromRSS($feed)
 {
     $feed = str_replace("_colon_", ":", $feed);
     // pull out colons from start tags
     // (<\w+):(\w+>)
     $pattern = '/(<\\w+):([\\w+|\\.|-]+[ |>]{1})/i';
     $replacement = '$1_$2';
     $feed = preg_replace($pattern, $replacement, $feed);
     // pull out colons from end tags
     // (<\/\w+):(\w+>)
     $pattern = '/(<\\/\\w+):([\\w+|\\.|-]+>)/i';
     $replacement = '$1_$2';
     $feed = preg_replace($pattern, $replacement, $feed);
     // pull out colons from attributes
     $pattern = '/(\\s+\\w+):(\\w+[=]{1})/i';
     $replacement = '$1_$2';
     $feed = preg_replace($pattern, $replacement, $feed);
     // pull colons from single element
     // (<\w+):(\w+\/>)
     $pattern = '/(<\\w+):([\\w+|\\.|-]+\\/>)/i';
     $replacement = '$1_$2';
     $feed = preg_replace($pattern, $replacement, $feed);
     $is_preprocess_enabled = apply_filters('is_xml_preprocess_enabled', true);
     if ($is_preprocess_enabled) {
         // replace temporary word _ampersand_ back to & symbol
         $feed = str_replace("_ampersand_", "&", $feed);
     }
     // replace all standalone & symbols ( which is not in htmlentities e.q. &nbsp; and not wrapped in CDATA section ) to &amp;
     PMXI_Import_Record::preprocessXml($feed);
     return $feed;
 }
开发者ID:mynein,项目名称:myne,代码行数:31,代码来源:chunk.php

示例13: filter

 function filter($in, $out, &$consumed, $closing)
 {
     while ($bucket = stream_bucket_make_writeable($in)) {
         PMXI_Import_Record::preprocessXml($bucket->data);
         $is_remove_colons_from_rss = apply_filters('wp_all_import_remove_colons_from_rss', true);
         if ($is_remove_colons_from_rss) {
             $bucket->data = $this->replace_colons($bucket->data);
         }
         $consumed += $bucket->datalen;
         stream_bucket_append($out, $bucket);
     }
     return PSFS_PASS_ON;
 }
开发者ID:lizbur10,项目名称:js_finalproject,代码行数:13,代码来源:chunk.php

示例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");
     }
     $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;
 }
开发者ID:lizbur10,项目名称:js_finalproject,代码行数:89,代码来源:wp_all_import_get_url.php

示例15: update


//.........这里部分代码省略.........
                                     if (zip_entry_open($zip, $zip_entry, "r")) {
                                         $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                                         fwrite($fp, "{$buf}");
                                         zip_entry_close($zip_entry);
                                         fclose($fp);
                                     }
                                     break;
                                 }
                                 zip_close($zip);
                             } else {
                                 $this->errors->add('form-validation', __('Failed to open uploaded ZIP archive. Can\'t extract files.', 'pmxi_plugin'));
                             }
                         }
                         if (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($filePath))) {
                             // If CSV file found in archieve
                             if ($uploads['error']) {
                                 $this->errors->add('form-validation', __('Can not create upload folder. Permision denied', 'pmxi_plugin'));
                             }
                             include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
                             $csv = new PMXI_CsvParser($filePath, true, '', !empty($item->options['delimiter']) ? $item->options['delimiter'] : '', !empty($item->options['encoding']) ? $item->options['encoding'] : '');
                             // create chunks
                             $filePath = $csv->xml_path;
                         }
                     }
                 } elseif (preg_match('%\\W(csv|txt|dat|psv)$%i', trim($item->path))) {
                     // If CSV file uploaded
                     if ($uploads['error']) {
                         $this->errors->add('form-validation', __('Can not create upload folder. Permision denied', 'pmxi_plugin'));
                     }
                     include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
                     $csv = new PMXI_CsvParser($item->path, true, '', !empty($item->options['delimiter']) ? $item->options['delimiter'] : '', !empty($item->options['encoding']) ? $item->options['encoding'] : '');
                     $filePath = $csv->xml_path;
                 } elseif (preg_match('%\\W(gz)$%i', trim($item->path))) {
                     // If gz file uploaded
                     $fileInfo = pmxi_gzfile_get_contents($item->path);
                     if (!is_wp_error($fileInfo)) {
                         $filePath = $fileInfo['localPath'];
                         // detect CSV or XML
                         if ($fileInfo['type'] == 'csv') {
                             // it is CSV file
                             include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php';
                             $csv = new PMXI_CsvParser($filePath, true, '', !empty($item->options['delimiter']) ? $item->options['delimiter'] : '', !empty($item->options['encoding']) ? $item->options['encoding'] : '');
                             // create chunks
                             $filePath = $csv->xml_path;
                         }
                     } else {
                         $this->errors->add('form-validation', $fileInfo->get_error_message());
                     }
                 } else {
                     // If XML file uploaded
                     $filePath = $item->path;
                 }
             }
             @set_time_limit(0);
             $local_paths = !empty($local_paths) ? $local_paths : array($filePath);
             foreach ($local_paths as $key => $path) {
                 if (!empty($action_type) and $action_type == 'continue') {
                     $chunks = $item->count;
                 } else {
                     $file = new PMXI_Chunk($path, array('element' => $item->root_element, 'encoding' => $item->options['encoding']));
                     while ($xml = $file->read()) {
                         if (!empty($xml)) {
                             PMXI_Import_Record::preprocessXml($xml);
                             $xml = "<?xml version=\"1.0\" encoding=\"" . $item->options['encoding'] . "\"?>" . "\n" . $xml;
                             $dom = new DOMDocument('1.0', !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8');
                             $old = libxml_use_internal_errors(true);
                             $dom->loadXML($xml);
                             // 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($item->xpath) and !empty($elements) and !empty($elements->length)) {
                                 $chunks += $elements->length;
                             }
                             unset($dom, $xpath, $elements);
                         }
                     }
                     unset($file);
                 }
                 !$key and $filePath = $path;
             }
             if (empty($chunks)) {
                 $this->errors->add('form-validation', __('No matching elements found for Root element and XPath expression specified', 'pmxi_plugin'));
             }
         }
         if ($chunks) {
             // xml is valid
             if (!PMXI_Plugin::is_ajax() and empty(PMXI_Plugin::$session->data['pmxi_import']['chunk_number'])) {
                 // compose data to look like result of wizard steps
                 PMXI_Plugin::$session['pmxi_import'] = array('filePath' => $filePath, 'source' => array('name' => $item->name, 'type' => $item->type, 'path' => $item->path, 'root_element' => $item->root_element), 'feed_type' => $item->feed_type, 'update_previous' => $item->id, 'parent_import_id' => $item->parent_import_id, 'xpath' => $item->xpath, 'template' => $item->template, 'options' => $item->options, 'encoding' => !empty($item->options['encoding']) ? $item->options['encoding'] : 'UTF-8', 'is_csv' => !empty($item->options['delimiter']) ? $item->options['delimiter'] : PMXI_Plugin::$is_csv, 'csv_path' => PMXI_Plugin::$csv_path, 'scheduled' => $item->scheduled, 'chunk_number' => 1, 'log' => '', 'warnings' => 0, 'errors' => 0, 'start_time' => 0, 'pointer' => 1, 'count' => isset($chunks) ? $chunks : 0, 'local_paths' => !empty($local_paths) ? $local_paths : array(), 'action' => (!empty($action_type) and $action_type == 'continue') ? 'continue' : 'update');
                 pmxi_session_commit();
             }
             // deligate operation to other controller
             $controller = new PMXI_Admin_Import();
             $controller->data['update_previous'] = $item;
             $controller->process();
             return;
         }
     }
     $this->render();
 }
开发者ID:thabofletcher,项目名称:tc-site,代码行数:101,代码来源:manage.php


注:本文中的PMXI_Import_Record::preprocessXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。