/** * @param $path * @param $demo */ private function add_demo($path, $demo) { if (isset(self::$data[$demo])) { return self::$data[$demo]; } $meta = $path . '/theme.xml'; //fetch meta data $xml = $this->importer->parser->simplexml_parser->read_simplexml_object($meta, false); if ($xml !== false) { $hw = $xml->xml->channel->children($xml->namespaces['hw']); //$title = /*(string)*/ $xml->xml->xpath('/theme/channel/hw:title'); $title = (string) $hw->title; //parse theme config $this->import($meta); //self::parse_theme_config()->import($meta); } if (empty($title)) { $title = $demo; } self::$data[$demo] = 'placeholder'; //this important to prevent infinitive loop $inst = new self($demo); $inst->demo_info = array('title' => print_r($title, true), 'path' => $path, 'import_file' => $path . '/data.xml', 'base_url' => rtrim(HW_URL::get_path_url($meta, true), '\\/') . '/'); self::$data[$demo] = $inst; //add to manager return $inst; }
/** * parse wxr data * @param $file * @return array|WP_Error */ function parse($file) { $wxr_version = $in_post = false; $fp = $this->fopen($file, 'r'); if ($fp) { $paths = array(); if (is_string($file)) { if (!$this->parser->data('import_path')) { $paths['import_path'] = rtrim(HW_URL::get_path_url($file, true), '\\/') . '/'; } if (!$this->parser->data('import_dir')) { $paths['import_dir'] = dirname($file); } $this->parser->update_variables($paths); } while (!$this->feof($fp)) { $importline = rtrim($this->fgets($fp)); if (!$wxr_version && preg_match('|<wp:wxr_version>(\\d+\\.\\d+)</wp:wxr_version>|', $importline, $version)) { $wxr_version = $version[1]; } if (false !== strpos($importline, '<wp:base_site_url>')) { preg_match('|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url); $this->base_url = $url[1]; continue; } if (false !== strpos($importline, '<wp:category>')) { preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category); $this->categories[] = $this->process_category($category[1]); continue; } if (false !== strpos($importline, '<wp:tag>')) { preg_match('|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag); $this->tags[] = $this->process_tag($tag[1]); continue; } if (false !== strpos($importline, '<wp:term>')) { preg_match('|<wp:term>(.*?)</wp:term>|is', $importline, $term); $this->terms[] = $this->process_term($term[1]); continue; } if (false !== strpos($importline, '<wp:author>')) { preg_match('|<wp:author>(.*?)</wp:author>|is', $importline, $author); $a = $this->process_author($author[1]); $this->authors[$a['author_login']] = $a; continue; } if (false !== strpos($importline, '<item>')) { $post = ''; $in_post = true; continue; } if (false !== strpos($importline, '</item>')) { $in_post = false; $this->posts[] = $this->process_post($post); continue; } if ($in_post) { $post .= $importline . "\n"; } } $this->fclose($fp); } if (!$wxr_version) { return new WP_Error('WXR_parse_error', __('This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer')); } return array('authors' => $this->authors, 'posts' => $this->posts, 'categories' => $this->categories, 'tags' => $this->tags, 'terms' => $this->terms, 'base_url' => $this->base_url, 'version' => $wxr_version); }