/** * @param $xml * @param array $namespaces * @return array */ public function build_skin_data(SimpleXMLElement $xml, $namespaces = null) { if (empty($namespaces)) { $namespaces = $this->namespaces; } #$node=dom_import_simplexml($xml);//dom_import_simplexml() #$n = $xml->getNameSpaces(false);_print($node->localName.','.$node->textContent); #$xml->getDocNamespaces(0); #if(empty($n)) return; HW_HOANGWEB::load_class('HW_File_Directory'); if (empty($namespaces)) { $namespaces = $this->valid_namespaces($xml); } $skin_tag = $xml->xpath('params:skin_encoded'); $data = array(); if (!empty($skin_tag) || count($xml->xpath('params:skin_instance'))) { $params = $xml->children($namespaces['params']); $hash_skin = array(); $skin_config = array(); $apply_plugin = ''; $skin_name = ''; $skin_data = array(); $screenshot = ''; $screenshot_ext = 'jpg'; /*if(isset($skin->apply_plugin)) { //apply skin $apply_plugin = (string) $skin->apply_plugin ; } else*/ if (isset($skin_data['apply_plugin'])) { $apply_plugin = $skin_data['apply_plugin']; } else { $apply_plugin = ''; //leave empty for hw-hoangweb plugin } //for skin link if (!empty($params->skin_file) && HW_XML::count_childs($params->skin_file)) { $atts = $params->skin_file->attributes(); //if(!isset($atts['name'])) $atts['name'] = 'url'; //skin_config //get skin data if (isset($atts['instance']) && isset($this->skins_data[(string) $atts['instance']])) { $skin_data = $this->skins_data[(string) $atts['instance']]; } $skin = $params->skin_file->children($namespaces['skin']); $hash_skin['type'] = ''; //get source if (isset($skin->source)) { $hash_skin['source'] = (string) $skin->source; } else { $hash_skin['source'] = 'plugin'; } $file_link = (string) $skin->file; $skin_file_name = isset($atts['name']) ? (string) $atts['name'] : 'url'; //get group if (isset($skin->group)) { $group = (string) $skin->group; } elseif (isset($skin_config['group'])) { $group = $skin_config['group']; } elseif (isset($skin_data['group'])) { $group = $skin_data['group']; } //$hash_skin = HW_SKIN::valid_holder_path($apply_plugin, $hash_skin); /*$file_url = HW_File_Directory::generate_url(HW_HOANGWEB_PLUGINS_URL,$apply_plugin, $skin_config['default_skin_path'], $group, $file_link ); //$hash_skin['screenshot_url'] = $hash_skin['file_url'] = $file_url; */ $hash_skin['file'] = $hash_skin['name'] = $file_link; //$data[isset($atts['name'])? (string) $atts['name']: 'url'] = $file_url ; } //parse hash_skin value if (isset($params->skin_encoded) && HW_XML::count_childs($params->skin_encoded)) { $atts = $params->skin_encoded->attributes(); //if(!isset($atts['name'])) $atts['name'] = 'hash_skin'; //default hash_skin field-> not allow to update if (isset($atts['instance']) && isset($this->skins_data[(string) $atts['instance']])) { $skin_data = $this->skins_data[(string) $atts['instance']]; } #$params->skin_encoded->xpath('skin:skins_path'); $skin = $params->skin_encoded->children($namespaces['skin']); if (isset($skin->apply_plugin)) { //apply skin $apply_plugin = (string) $skin->apply_plugin; } elseif (isset($skin_data['apply_plugin'])) { $apply_plugin = $skin_data['apply_plugin']; } else { $apply_plugin = ''; //leave empty for hw-hoangweb plugin } //get source if (isset($skin->source)) { $hash_skin['source'] = (string) $skin->source; } else { $hash_skin['source'] = 'plugin'; } //skin name /*if(isset($skin->skin_name)) { $skin_name = (string) $skin->skin_name; } else*/ if (isset($skin_data['skin_name'])) { $skin_name = $skin_data['skin_name']; } //$hash = array('skins_path', ''); $hash_skin['holder'] = $apply_plugin; if ($apply_plugin) { $hash_skin = HW_SKIN::valid_holder_path($apply_plugin, $hash_skin); } else { //refer to hw-hoangweb plugin if (!file_exists($hash_skin['holder'])) { $hash_skin['holder'] = ''; #HW_HOANGWEB_PATH. DIRECTORY_SEPARATOR; $hash_skin['holder_url'] = ''; //HW_HOANGWEB_URL ; } } if (isset($skin->screenshot)) { //screenshot $screenshot = (string) $skin->screenshot; } /*elseif(isset($skin_data['screenshot'])) { $screenshot = $skin_data['screenshot']; }*/ if (isset($skin->skin_type)) { //skin type $hash_skin['type'] = (string) $skin->skin_type; } elseif (isset($skin_data['skin_type'])) { $hash_skin['type'] = $skin_data['skin_type']; } //group if (isset($skin->group)) { $hash_skin['group'] = (string) $skin->group; } elseif (isset($skin_data['group'])) { $hash_skin['group'] = $skin_data['group']; } else { $hash_skin['group'] = ''; } if (isset($skin->default_folder)) { //skins path $hash_skin['default_folder'] = (string) $skin->default_folder; } elseif (isset($skin_data['default_skin_path'])) { $hash_skin['default_folder'] = $skin_data['default_skin_path']; } //skin_folder if ($hash_skin['type'] == 'file') { $hash_skin['skin_folder'] = $hash_skin['default_folder'] . '/' . $hash_skin['group']; } else { $hash_skin['skin_folder'] = $hash_skin['default_folder']; } if ($hash_skin['type'] === 'link') { //path $hash_skin['path'] = rtrim($hash_skin['group'], '\\/') . '/'; } else { if (isset($skin->skin)) { //skin folder $hash_skin['path'] = (string) $skin->skin; } elseif (isset($skin_data['default_skin'])) { $hash_skin['path'] = $skin_data['default_skin']; } } $hash_skin['path'] = rtrim($hash_skin['path'], '\\/') . '/'; //valid $full_holder = HW_SKIN::get_skin_realpath(array('path' => $hash_skin['holder']), $hash_skin['source'])->path; $skin_path = HW_File_Directory::generate_path($full_holder, $hash_skin['default_folder'], $hash_skin['group'], $hash_skin['path']); //screenshot mimetype /*if(isset($skin->screenshot_mimetype)) { //no, we auto find screenshot mimetype $screenshot_ext = (string) $skin->screenshot_mimetype; }*/ $screenshot_ext = file_exists($skin_path . '/screenshot.png') ? 'png' : 'jpg'; //skin name if ($hash_skin['type'] == 'file' && $skin_name) { $hash_skin['filename'] = $skin_name; } #else $hash_skin['file'] = $skin_name; //for skin link, do it above if (isset($skin->title) && !isset($hash_skin['name'])) { //title $hash_skin['name'] = (string) $skin->title; } else { if (isset($hash_skin['holder']) && isset($hash_skin['default_folder']) && !isset($hash_skin['name'])) { if (isset($skin_data['template_header'])) { $header = $skin_data['template_header']; } else { $header = array('name' => 'HW Template', 'description' => 'Description', 'author' => 'Author', 'uri' => 'Author URI'); } if ($hash_skin['type'] == 'file') { $skin_file = HW_File_Directory::generate_path($full_holder, $hash_skin['default_folder'], $hash_skin['group'], $hash_skin['path']) . '/' . $skin_name; } else { $skin_file = HW_File_Directory::generate_path($full_holder, $hash_skin['default_folder'], $hash_skin['path']) . '/' . $skin_name; } $temp_header = HW_SKIN::get_template_data($skin_file, 0, $header); $hash_skin['name'] = $temp_header['name']; } } $hash_skin['skin_url'] = HW_File_Directory::generate_url($hash_skin['holder_url'], $hash_skin['skin_folder'], $hash_skin['path']); if (isset($skin_file_name) && isset($file_link)) { $hash_skin['file_url'] = HW_File_Directory::generate_url($hash_skin['skin_url'], $file_link); $data[$skin_file_name] = $hash_skin['screenshot_url'] = $hash_skin['file_url']; } /*if($screenshot && !isset($hash_skin['screenshot_url'])) { //skin screenshot $hash_skin['screenshot_url'] = $screenshot; if(!HW_Validation::hw_valid_url($hash_skin['screenshot_url'])) { $hash_skin['screenshot_url'] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS_URL, $hash_skin['screenshot_url']); } } else*/ if (!isset($hash_skin['screenshot_url'])) { $hash_skin['screenshot_url'] = HW_File_Directory::generate_url($hash_skin['skin_url'], 'screenshot.' . ltrim($screenshot_ext, '.')); //default jpg mimetype } //valid hash skin value if (count($hash_skin) < 7) { return; } //$hash_skin = hwArray::sortArrayByArray($hash_skin, array('skins_path','skin_folder','skin_url','skin_type','title','screenshot','skin_name')); if (isset($hash_skin['type']) && $hash_skin['type'] == 'file') { $hash_skin_value = HW_SKIN::generate_skin_path($hash_skin); } else { $hash_skin_value = HW_SKIN::generate_skin_file($hash_skin); } #__print(($hash_skin));exit; $data[isset($atts['name']) ? (string) $atts['name'] : 'hash_skin'] = $hash_skin_value; } //parse skin config if (isset($params->skin_instance)) { $atts = $params->skin_instance->attributes(); //if(!isset($atts['name'])) $atts['name'] = 'skin_config'; //skin_config if (isset($atts['instance']) && isset($this->skins_data[(string) $atts['instance']])) { $skin_data = $this->skins_data[(string) $atts['instance']]; } $skin = $params->skin_instance->children($namespaces['skin']); //get default values if (isset($skin->apply_plugin) && !$apply_plugin) { //apply_plugin $apply_plugin = (string) $skin->apply_skin; } elseif (isset($skin_data['apply_plugin']) && !$apply_plugin) { $apply_plugin = $skin_data['apply_plugin']; } if (isset($skin->skin_name) && !$skin_name) { //skin_name $skin_name = (string) $skin->skin_name; } elseif (isset($skin_data['skin_name']) && !$skin_name) { $skin_name = $skin_data['skin_name']; } //grab /*if(isset($skin->apply_current_path)) { //apply_current_path $skin_config['apply_current_path'] = (string) $skin->apply_current_path; if(!file_exists($skin_config['apply_current_path'])) { $skin_config['apply_current_path'] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS, $skin_config['apply_current_path']); } } if(isset($skin->plugin_url)) { //plugin_url $skin_config['plugin_url'] = (string) $skin->plugin_url; if(!HW_Validation::hw_valid_url($skin_config['plugin_url'])) { $skin_config['plugin_url'] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS_URL , $skin_config['plugin_url']); } }*/ if (isset($skin->other_folder)) { //other_folder $skin_config['other_folder'] = (string) $skin->other_folder; } elseif (isset($skin_data['other_folder'])) { $skin_config['other_folder'] = $skin_data['other_folder']; } if ($skin_name) { //skin_name $skin_config['skin_name'] = $skin_name; } if (isset($skin->default_skin_path)) { //default_skin_path $skin_config['default_skin_path'] = (string) $skin->default_skin_path; } elseif (isset($skin_data['default_skin_path'])) { $skin_config['default_skin_path'] = $skin_data['default_skin_path']; } if (isset($skin->group)) { //group $skin_config['group'] = (string) $skin->group; } elseif (isset($skin_data['group'])) { $skin_config['group'] = $skin_data['group']; } if (isset($skin->enable_external_callback)) { //enable_external_callback $skin_config['enable_external_callback'] = (string) $skin->enable_external_callback; } elseif (isset($skin_data['enable_external_callback'])) { $skin_config['enable_external_callback'] = $skin_data['enable_external_callback']; } //allow skin names if (isset($skin->allows_skin_names)) { $skin_config['allows_skin_names'] = HW_XML::xml2array($skin->allows_skin_names->children(), 'param', 'params'); } elseif (isset($skin_data['allows_skin_names'])) { $skin_config['allows_skin_names'] = $skin_data['allows_skin_names']; } //properties if (isset($skin->properties)) { $skin_config['properties'] = HW_XML::xml2array($skin->properties->children(), 'param', 'params'); } elseif (isset($skin_data['properties'])) { $skin_config['properties'] = $skin_data['properties']; } //options if (isset($skin->options)) { $skin_config['options'] = HW_XML::xml2array($skin->properties->children(), 'param', 'params'); } elseif (isset($skin_data['options'])) { $skin_config['options'] = $skin_data['options']; } if ($apply_plugin && !isset($skin_config['apply_current_path'])) { //$skin_config["apply_current_path"] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS,$apply_plugin); $skin_config["apply_current_path"] = $apply_plugin; } if ($apply_plugin && !isset($skin_config['plugin_url'])) { //$skin_config['plugin_url'] = HW_File_Directory::generate_path(HW_HOANGWEB_PLUGINS_URL, $apply_plugin); $skin_config['plugin_url'] = $apply_plugin; } //other params $other_config_params = HW_XML::xml2array($params->skin_instance->children(), 'param', 'params'); //fix if (!isset($other_config_params['allows_skin_names'])) { $other_config_params['allows_skin_names'] = array(); } elseif (isset($skin_data['allows_skin_names'])) { $other_config_params['allows_skin_names'] = $skin_data['allows_skin_names']; } if (isset($skin_config['skin_name']) && !in_array($skin_config['skin_name'], $other_config_params['allows_skin_names'])) { $other_config_params['allows_skin_names'][] = $skin_config['skin_name']; } if (!empty($other_config_params)) { $skin_config = array_merge($skin_config, $other_config_params); } $data[isset($atts['name']) ? (string) $atts['name'] : 'skin_config'] = HW_SKIN::generate_skin_config($skin_config); } //other params $data = array_merge($data, HW_XML::xml2array($xml)); /*$atts = $xml->attributes(); //get attributes if(isset($atts['name'])) { $data = array((string)$atts['name'] => $data); }*/ return count($data) ? $data : null; } }
/** * generate skins options tag * @param string $current_skin: current skin * @param string $theme: try 2 theme 'simple|dropdown_ddslick', with ddslick lib you will see nice dropdown with image * @param string $skins: what type of skin data type need to fetch, default is skin files (.php) */ public function generate_skin_options_tag($current_skin = '', $skins = self::SKIN_FILES, $theme = self::DROPDOWN_DDSSLICK_THEME) { $skins = $this->get_skins_data($skins); #$this->widget_ref->skin->myskins();->wrong //get all skins first //if(!isset($this->skins_data)) $this->skins_data = $this->load_skins_data($skins); //load skin data $out = ''; //output $last_group = 0; //group skins $option_atts = array(); $count = 0; //count items $selected_index = 0; //get selected index //if($empty_option) $out .= '<option value="">------Chọn ------</option>'; //empty option, wrong because need to pass through method generate_skin_file foreach ($skins as $skin) { if ($skin['type'] == 'file') { $skin_path = HW_SKIN::generate_skin_path($skin); } else { $skin_path = HW_SKIN::generate_skin_file($skin); } //populate group if (!isset($skin['group'])) { $skin['group'] = self::DEFAULT_GROUP; } //default skin in default group //style option tag if ($theme == self::DROPDOWN_DDSSLICK_THEME) { $skin = $this->valid_skin_path($skin); if ($skin['type'] == 'file') { $option_atts['data-imagesrc'] = $skin['skin_url'] . '/' . $skin['screenshot']; } else { $option_atts['data-imagesrc'] = $skin['file_url']; } $option_atts['data-description'] = 'Folder: ' . $skin['group']; } if ($last_group !== $skin['group']) { if ($last_group) { $out .= '</optgroup>'; //close group $close_group = 1; } $out .= '<optgroup label="' . $skin['group'] . '">'; $close_group = 0; $last_group = $skin['group']; //remind new group } if (!$last_group) { $last_group = $skin['group']; } //save first group //active item if ($skin_path == $current_skin) { $selected_index = $count; } $out .= '<option ' . self::array2attrs($option_atts) . ' value="' . $skin_path . '" ' . selected($skin_path, $current_skin, false) . '>' . $skin['name'] . '</option>'; $count++; } if (!isset($close_group) || !$close_group) { $out .= '</optgroup>'; } //note you should close group after all return array('options' => $out, 'selectedIndex' => $selected_index, 'skins_data' => $this->skins_data, 'skins' => $skins); }