ast
1 month ago
XmlImportConfig.php
1 month ago
XmlImportCsvParse.php
1 month ago
XmlImportException.php
1 month ago
XmlImportParser.php
1 month ago
XmlImportReaderInterface.php
1 month ago
XmlImportSQLParse.php
1 month ago
XmlImportStringReader.php
1 month ago
XmlImportTemplate.php
1 month ago
XmlImportTemplateCodeGenerator.php
1 month ago
XmlImportTemplateParser.php
1 month ago
XmlImportTemplateScanner.php
3 days ago
XmlImportToken.php
1 month ago
XmlImportXLSParse.php
1 month ago
wpaipclzip.lib.php
1 month ago
XmlImportTemplate.php
84 lines
| 1 | <?php |
| 2 | // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals |
| 3 | /** |
| 4 | * @author Olexandr Zanichkovsky <olexandr.zanichkovsky@zophiatech.com> |
| 5 | * @author Pavel Kulbakin <p.kulbakin@gmail.com> |
| 6 | * @package General |
| 7 | */ |
| 8 | |
| 9 | require_once dirname(__FILE__) . '/XmlImportConfig.php'; |
| 10 | |
| 11 | /** |
| 12 | * Represents a template |
| 13 | */ |
| 14 | class XmlImportTemplate { |
| 15 | /** |
| 16 | * Root element of the record that is being parsed |
| 17 | * |
| 18 | * @var SimpleXMLElement |
| 19 | */ |
| 20 | protected $xml; |
| 21 | |
| 22 | /** |
| 23 | * file name of the cached template |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | protected $cachedTemplate; |
| 28 | |
| 29 | protected $trimValues = TRUE; |
| 30 | |
| 31 | /** |
| 32 | * Creates new instance |
| 33 | * |
| 34 | * @param SimpleXmlElement $xml |
| 35 | * @param string $cachedTemplate |
| 36 | */ |
| 37 | public function __construct($xml, $cachedTemplate) |
| 38 | { |
| 39 | $this->xml = $xml; |
| 40 | $this->cachedTemplate = $cachedTemplate; |
| 41 | $this->trimValues = apply_filters('wp_all_import_is_trim_parsed_data', $this->trimValues); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Parses a template using {@see $this->xml} |
| 46 | * |
| 47 | * @return string |
| 48 | */ |
| 49 | public function parse() |
| 50 | { |
| 51 | |
| 52 | ob_start(); |
| 53 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting |
| 54 | $err_lvl = error_reporting(E_ALL); |
| 55 | include $this->cachedTemplate; |
| 56 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting |
| 57 | error_reporting($err_lvl); |
| 58 | |
| 59 | return ob_get_clean(); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get the value by XPath expression |
| 64 | * |
| 65 | * @param SimpleXmlElement $xpath XPath result |
| 66 | * @return mixed |
| 67 | */ |
| 68 | protected function getValue($xpath = array()) |
| 69 | { |
| 70 | |
| 71 | if (is_array($xpath) && count($xpath) > 0) { |
| 72 | $result = array(); |
| 73 | foreach ($xpath as $xp) { // concatenate multiple elements into 1 string |
| 74 | ob_start(); |
| 75 | echo $xp; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Captured into output buffer for internal concatenation, not sent to response. |
| 76 | $result[] = $this->trimValues ? trim(ob_get_clean()) : ob_get_clean(); |
| 77 | } |
| 78 | return implode(XmlImportConfig::getInstance()->getMultiGlue(), $result); |
| 79 | } else { |
| 80 | // return null if nothing found |
| 81 | return null; |
| 82 | } |
| 83 | } |
| 84 | } |