Пример #1
0
 /**
  * load module skins
  */
 protected function load_module_skins()
 {
     $skins_file = $this->get_module()->get_module_wxr_files('skins');
     if ($skins_file) {
         $skins = HW_WXR_Parser_SimpleXML::read_simplexml_object($skins_file);
         if (!is_wp_error($skins) && !empty($skins) && isset($skins->xml)) {
             foreach ($skins->xml->xpath('/rss/skins/hw:skin') as $item) {
                 $name = (string) $item->attributes()->name;
                 $skin = HW_WXR_Parser_SimpleXML::parse_skin_data($item);
                 //parse hw skin data
                 if (!isset($skin['apply_plugin'])) {
                     $skin['apply_plugin'] = $this->get_module()->option('module_name');
                 }
                 //fix apply_module to current
                 $this->skins->add_skin($name, $skin);
             }
         }
     }
 }
 /**
  * get non-action wxr data
  * @param string $item
  */
 public static function get_theme_data($item = '')
 {
     $wxr_files = array();
     if (file_exists(get_stylesheet_directory() . '/config/skins.xml')) {
         $wxr_files['skins'] = HW_WXR_Parser_SimpleXML::read_simplexml_object(get_stylesheet_directory() . '/config/skins.xml');
     }
     if (file_exists(get_stylesheet_directory() . '/config/widgets.xml')) {
         $wxr_files['widgets'] = HW_WXR_Parser_SimpleXML::read_simplexml_object(get_stylesheet_directory() . '/config/widgets.xml');
     }
     return $item ? isset($wxr_files[$item]) ? $wxr_files[$item] : null : $wxr_files;
 }
Пример #3
0
 /**
  * main class construct
  * @param $file
  */
 function __construct($file = '')
 {
     if ($file && is_string($file)) {
         $this->xml = HW_SimpleXMLElement::parser_xml($file);
     } elseif (is_object($file) && $file instanceof HW_SimpleXMLElement) {
         $this->xml = $file;
     }
     //get doc namespaces
     if (!empty($this->xml)) {
         $this->namespaces = $this->xml->getDocNamespaces();
     }
     if (!isset($this->namespaces['wp'])) {
         $this->namespaces['wp'] = 'http://wordpress.org/export/1.1/';
     }
     if (!isset($this->namespaces['excerpt'])) {
         $this->namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
     }
     //get config data
     $parser = new HW_WXR_Parser_SimpleXML();
     $this->config_data = $parser->parse($this->xml);
 }
 /**
  * fetch wp plugins package
  * @return mixed
  */
 public static function fetch_plugins_package()
 {
     include_once HW_HOANGWEB_PLUGINS . '/hw-importer/includes/parsers.php';
     $xml = HW_WXR_Parser_SimpleXML::read_simplexml_object(HW_HOANGWEB_PLUGINS . '/plugins-package.xml');
     return $xml;
 }
Пример #5
0
 /**
  * parse theme config using wrx format
  * @param $file
  */
 public function parse($file)
 {
     $site = $menus = $assets = $libs = $modules = $plugins = $positions = $configuration = array();
     $xml = HW_WXR_Parser_SimpleXML::read_simplexml_object($file);
     $namespaces = $xml->namespaces;
     $xml = $xml->xml;
     $xml_parser = new HW_WXR_Parser();
     //::get_instance();
     $simplexml_parser = $xml_parser->simplexml_parser;
     //site meta
     if (isset($xml->site)) {
         $hw = $xml->site->children($namespaces['hw']);
         if (isset($hw->name)) {
             $site['name'] = (string) $hw->name;
         }
         if (isset($hw->description)) {
             $site['description'] = (string) $hw->description;
         }
         if (isset($hw->logo)) {
             $site['logo'] = (string) $hw->logo;
         }
         if (isset($hw->banner)) {
             $site['banner'] = (string) $hw->banner;
         }
         if (isset($hw->phone)) {
             $site['phone'] = (string) $hw->phone;
         }
         if (isset($hw->email)) {
             $site['admin_email'] = (string) $hw->email;
         }
         if (isset($hw->address)) {
             $site['address'] = (string) $hw->address;
         }
         if (isset($hw->testimonials)) {
             $site['testimonials'] = (string) $hw->testimonials;
         }
         if (!empty($hw->footer_text)) {
             $site['footer'] = (string) $hw->footer_text;
         }
     }
     //configuration
     if (isset($xml->configuration)) {
         $hw = $xml->configuration->children($namespaces['hw']);
         $configuration['sample_data'] = (string) $hw->sample_data;
         $media = $hw->media->children('hw');
         $configuration['media'] = array();
         foreach ($media as $image) {
             foreach ($image as $size) {
                 $atts = $size->attributes();
                 $configuration['media'][$size->getName()] = array('width' => (string) $atts->width, 'height' => (string) $atts->height, 'crop' => (string) $atts->crop);
             }
         }
         /*if(!empty($media->thumbnail)) $configuration['media']['thumbnail'] = (string) $media->thumbnail;
           if(!empty($media->medium)) $configuration['media']['medium'] = (string) $media->medium;
           if(!empty($media->large)) $configuration['media']['large'] = (string) $media->large;*/
         $configuration['locale'] = (string) $hw->locale;
     }
     //fetch menus
     foreach ($xml->xpath('/theme/menus/hw:menu') as $menu) {
         $atts = $menu->attribute();
         $menus[(string) $atts['slug']] = (string) $menu;
     }
     //fetch sidebars
     $sidebars = array();
     #$simplexml_parser->grab_sidebars($xml->xpath('/theme')[0], $namespaces);
     foreach ($xml->xpath('/theme/sidebars/hw:sidebar') as $sidebar_widgets) {
         $atts = $sidebar_widgets->attributes();
         $skin = (string) $atts['skin'];
         //sidebar skin
         $sidebar_name = (string) $atts['name'];
         if (!isset($sidebars[(string) $atts['name']])) {
             $sidebars[$sidebar_name] = array('skin' => $skin, 'widgets' => array(), 'params' => array());
         }
         //get widgets in sidebar
         $hw = $sidebar_widgets->children($namespaces['hw']);
         foreach ($hw->widget as $widget) {
             $name = (string) $widget->attributes()->name;
             $sidebars[$sidebar_name]['widgets'][] = $name;
         }
         //sidebar params
         $sidebars[$sidebar_name]['params'] = array('name' => $sidebar_name);
         if (!empty($hw->params)) {
             $sidebars[$sidebar_name]['params'] = array_merge($sidebars[$sidebar_name]['params'], $simplexml_parser->recursive_option_data($hw->params[0]->children())->option);
         }
     }
     //fetch assets
     foreach ($xml->xpath('/theme/assets') as $items) {
         $atts = $items->attributes();
         $page = isset($atts['page']) ? (string) $atts['page'] : '__all__';
         //group by page
         if (!isset($assets[$page])) {
             $assets[$page] = array();
         }
         foreach ($items as $item) {
             $atts = $item->attributes();
             $file = array();
             $file['type'] = !empty($atts['type']) ? (string) $atts['type'] : '';
             //dependencies
             if (!empty($atts['depends'])) {
                 $file['depends'] = explode(',', (string) $atts['depends']);
             } else {
                 $file['depends'] = false;
             }
             //handle
             if (!empty($atts['handle'])) {
                 $file['handle'] = (string) $atts['handle'];
             }
             if (!empty($atts['ver'])) {
                 $file['ver'] = (string) $atts['ver'];
             }
             //version
             $file['name'] = (string) $item;
             $assets[$page][] = $file;
         }
     }
     //fetch libs
     foreach ($xml->xpath('/theme/libs/lib') as $item) {
         $atts = $item->attributes();
         $lib = isset($atts['name']) ? (string) $atts['name'] : (string) $item;
         $libs[] = $lib;
     }
     //fetch modules
     $modules_list = $xml->xpath('/theme/modules');
     if ($modules_list) {
         $only_list = (string) $modules_list[0]->attributes()->only_list;
     } else {
         $only_list = 0;
     }
     if (!$only_list) {
         $installed_modules = HW_TGM_Module_Activation::get_register_modules(array('active' => 1, 'core' => 1), 'or');
         #HW_Logger::log_file($installed_modules);   //get installed modules, refer to core modules
         foreach ($installed_modules as $slug => $module) {
             $modules[$slug] = array('name' => $slug, 'status' => 1, 'core' => !empty($module['force_activation']), 'active' => 1);
         }
     }
     foreach ($xml->xpath('/theme/modules/module') as $item) {
         $atts = $item->attributes();
         $module['name'] = isset($atts['name']) ? (string) $atts['name'] : (string) $item;
         $module['status'] = isset($atts['status']) ? (string) $atts['status'] : 1;
         //active module as default
         $modules[$module['name']] = $module;
     }
     //fetch wp plugins
     foreach ($xml->xpath('/theme/plugins/plugin') as $item) {
         $atts = $item->attributes();
         $plugin['name'] = isset($atts['name']) ? (string) $atts['name'] : (string) $item;
         $plugin['status'] = isset($atts['status']) ? (string) $atts['status'] : 1;
         //active plugin as default
         $plugins[$plugin['name']] = $plugin;
     }
     //positions
     foreach ($xml->xpath('/theme/positions/position') as $item) {
         $atts = $item->attributes();
         //valid hook name
         $name = isset($atts['name']) ? (string) $atts['name'] : (string) $item;
         $name = strtolower(HW_Validation::valid_objname($name));
         //display text
         $text = (string) $item;
         if (empty($text) && $name) {
             $text = $name;
         }
         $positions[] = array('name' => $name, 'text' => $text);
     }
     unset($xml);
     return array('assets' => $assets, 'libs' => $libs, 'modules' => $modules, 'plugins' => $plugins, 'positions' => $positions, 'sidebars' => $sidebars, 'menus' => $menus, 'site' => $site, 'configuration' => $configuration);
 }
Пример #6
0
 /**
  * start configure data for the module
  * @param $file
  */
 public function setup_demo($file)
 {
     if ($this->get_config()) {
         $xml = HW_WXR_Parser_SimpleXML::read_simplexml_object($file);
         if (!$this->get_module_exporter()) {
             return;
         }
         //update data on exporter
         $this->get_module_exporter()->xml_data = $xml->xml;
         $this->get_module_exporter()->namespaces = $xml->namespaces;
         $this->get_config()->setup_user_data($xml->xml, $xml->namespaces);
     }
 }