/** * enqueue required styles in library or specific resource * @example ->enqueue_styles('colorbox.css',..) * @example ->enqueue_styles() #enqueue required styles from the lib */ public function enqueue_styles() { $args = hwArray::multi2single(func_get_args()); $_handle = $this->get_handle(); //stylesheets if ($_handle && !empty($_handle['styles']) && is_array($_handle['styles'])) { foreach ($_handle['styles'] as $name => $_file) { //valid, make sure enqueue required script or match given file name if (count($args) > 0 && !in_array($name, $args) || count($args) == 0 && is_array($_file) && isset($_file['required']) && $_file['required'] == false) { continue; } $handle_name = $this->get_name() . '-' . $name; //valid file name if (is_array($_file) && isset($_file['file'])) { $file = $_file['file']; //resource file } elseif (is_string($_file)) { $file = $_file; } else { continue; } //valid resource url if (class_exists('HW_URL') && !HW_URL::valid_url($file)) { $file = $this->get_resource_url($file); } wp_enqueue_style($handle_name, $file, isset($handle['depends']) ? $this->valid_depends_enqueue($handle['depends']) : array()); } } }
/** * setup site metadata * @param $command */ public function setup_site_meta($command, $args) { #$this->command_log('setup site meta');return; //get current template context $theme_config = $this->get_option('theme_config'); //parse config file for current theme #site meta if ($theme_config->item('site')) { $site = $theme_config->item('site'); HW_NHP_Main_Settings::update_data(array('last_tab' => '1')); //fix current tab //update site info (name & description, phone...) HW__Site::update_site_info($site); //update logo if (!empty($site['logo'])) { //get relative path from current theme directory if (!HW_URL::valid_url($site['logo'])) { $site['logo'] = get_stylesheet_directory_uri() . '/' . $site['logo']; } HW__Site::set_logo($site['logo']); } //set banner if exists if (!empty($site['banner'])) { //get relative path from current theme directory if (!HW_URL::valid_url($site['banner'])) { $site['banner'] = get_stylesheet_directory_uri() . '/' . $site['banner']; } HW__Site::set_banner($site['banner']); } //update user info $user = _hw_global('admin')->load_api('HW_WP_User'); $user->update_user(array('user_email' => $site['email'], 'user_url' => 'http://hoangweb.com', 'description' => $site['footer_text'])); } if ($theme_config->item('configuration')) { } $this->command_log('setup site meta'); }
/** * return url to file in demo folder * @param $file * @return string */ public function get_file_url($file) { if (!HW_URL::valid_url($file)) { $file = HW_File_Directory::generate_url($this->info('base_url'), $file); } return $file; }
/** * update banner * @param $url * @param $set_related */ public static function set_banner($url, $set_related = true) { if (HW_URL::valid_url($url)) { set_theme_mod('header_image', esc_url_raw(set_url_scheme($url))); if ($set_related) { HW_NHP_Main_Settings::update_data(array('site_banner' => $url)); } return true; } //trailingslashit( get_stylesheet_directory_uri() ).'images/banner.jpg' //define('HEADER_IMAGE', $url); }
/** * enqueue assets for js+css file * @hook wp_enqueue_scripts */ public static function _enqueue_scripts() { global $wp_styles; $current = self::get_current_template(false); $config = $current['object']->get_config_data(); #$current['object'] $active_assets = array(); $assets = $config->item('assets') ? $config->item('assets') : array(); //->item('assets'); /* * From WP * Adds JavaScript to pages with the comment form to support * sites with threaded comments (when in use). */ if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } //common assets if (!empty($assets['__all__'])) { $active_assets = array_merge($active_assets, $assets['__all__']); } if (!empty($assets[$current['name']])) { //get assets for current context $active_assets = array_merge($active_assets, $assets[$current['name']]); } foreach ($active_assets as $file) { //valid file path if (!is_dir($file['name']) && !file_exists($file['name'])) { $url = get_stylesheet_directory_uri() . '/' . $file['name']; } else { $url = $file['name']; } if (!HW_URL::valid_url($url)) { continue; } $handle = isset($file['handle']) ? $file['handle'] : md5($file['name']); //for js if ($file['type'] == 'js') { if (HW_URL::valid_url($url)) { wp_enqueue_script($handle, $url, $file['depends']); } continue; } elseif ($file['type'] == 'css') { wp_enqueue_style(md5($file['name']), $url, $file['depends']); continue; } } if (is_object($current) && method_exists($current, 'enqueue_scripts')) { call_user_func(array($current, 'enqueue_scripts')); //addition stuff } //default js if (!is_admin()) { HW_Libraries::enqueue_jquery_libs('pageload/nprogress'); } //show progressbar while page loading }
/** * do import for posts * @param $post * @return array */ public function process_post($post) { $post_id = $this->get_tag($post, 'wp:post_id'); $post_title = $this->get_tag($post, 'title'); $post_date = $this->get_tag($post, 'wp:post_date'); $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt'); $comment_status = $this->get_tag($post, 'wp:comment_status'); $ping_status = $this->get_tag($post, 'wp:ping_status'); $status = $this->get_tag($post, 'wp:status'); $post_name = $this->get_tag($post, 'wp:post_name'); $post_parent = $this->get_tag($post, 'wp:post_parent'); $menu_order = $this->get_tag($post, 'wp:menu_order'); $post_type = $this->get_tag($post, 'wp:post_type'); $post_password = $this->get_tag($post, 'wp:post_password'); $is_sticky = $this->get_tag($post, 'wp:is_sticky'); $guid = $this->get_tag($post, 'guid'); $post_author = $this->get_tag($post, 'dc:creator'); $post_excerpt = $this->get_tag($post, 'excerpt:encoded'); $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_excerpt); $post_excerpt = str_replace('<br>', '<br />', $post_excerpt); $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt); $post_content = $this->get_tag($post, 'content:encoded'); $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array(&$this, '_normalize_tag'), $post_content); $post_content = str_replace('<br>', '<br />', $post_content); $post_content = str_replace('<hr>', '<hr />', $post_content); $post_content = $this->parser->pre_shortcode_tags($post_content); $postdata = compact('post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password', 'is_sticky'); $attachment_url = $this->get_tag($post, 'wp:attachment_url'); if ($attachment_url) { $postdata['attachment_url'] = $attachment_url; } //hw attachment preg_match_all('|<hw:attachment>(.+?)</hw:attachment>|is', $post, $attachments); $attachments = $attachments[1]; if ($attachments) { foreach ($attachments as $p) { $hw_attachment_url = $this->get_tag($p, 'hw:url'); if ($hw_attachment_url) { if (!HW_URL::valid_url($hw_attachment_url)) { $postdata['attachment_url'] = $this->parser->data('import_path') . $hw_attachment_url; } else { $postdata['attachment_url'] = $hw_attachment_url; } //found new attachment in post if ($post_type !== 'attachment') { $_postdata = hwArray::cloneArray($postdata); $_postdata['post_content'] = HW_String::limit($_postdata['post_content'], 50); $_postdata['post_excerpt'] = HW_String::limit($_postdata['post_excerpt'], 50); $_postdata['post_type'] = 'attachment'; $_postdata['_id'] = $this->get_tag($p, 'hw:_id'); $_postdata['thumbnail'] = $this->get_tag($p, 'hw:thumbnail'); if ($_postdata['thumbnail']) { $_postdata['hw_thumbnail_id'] = $this->get_tag($p, 'hw:_id'); } $this->posts[] = $_postdata; } /*else { $postdata['thumbnail'] = $this->get_tag($p, 'hw:thumbnail'); if($postdata['thumbnail']) $postdata['hw_thumbnail_id'] = $this->get_tag($p, 'hw:_id'); }*/ } } } preg_match_all('|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER); foreach ($terms as $t) { $post_terms[] = array('slug' => $t[2], 'domain' => $t[1], 'name' => str_replace(array('<![CDATA[', ']]>'), '', $t[3])); } if (!empty($post_terms)) { $postdata['terms'] = $post_terms; } preg_match_all('|<wp:comment>(.+?)</wp:comment>|is', $post, $comments); $comments = $comments[1]; if ($comments) { foreach ($comments as $comment) { preg_match_all('|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta); $commentmeta = $commentmeta[1]; $c_meta = array(); foreach ($commentmeta as $m) { $c_meta[] = array('key' => $this->get_tag($m, 'wp:meta_key'), 'value' => $this->get_tag($m, 'wp:meta_value')); } $post_comments[] = array('comment_id' => $this->get_tag($comment, 'wp:comment_id'), 'comment_author' => $this->get_tag($comment, 'wp:comment_author'), 'comment_author_email' => $this->get_tag($comment, 'wp:comment_author_email'), 'comment_author_IP' => $this->get_tag($comment, 'wp:comment_author_IP'), 'comment_author_url' => $this->get_tag($comment, 'wp:comment_author_url'), 'comment_date' => $this->get_tag($comment, 'wp:comment_date'), 'comment_date_gmt' => $this->get_tag($comment, 'wp:comment_date_gmt'), 'comment_content' => $this->get_tag($comment, 'wp:comment_content'), 'comment_approved' => $this->get_tag($comment, 'wp:comment_approved'), 'comment_type' => $this->get_tag($comment, 'wp:comment_type'), 'comment_parent' => $this->get_tag($comment, 'wp:comment_parent'), 'comment_user_id' => $this->get_tag($comment, 'wp:comment_user_id'), 'commentmeta' => $c_meta); } } if (!empty($post_comments)) { $postdata['comments'] = $post_comments; } preg_match_all('|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta); $postmeta = $postmeta[1]; if ($postmeta) { foreach ($postmeta as $p) { $post_postmeta[] = array('key' => $this->get_tag($p, 'wp:meta_key'), 'value' => $this->get_tag($p, 'wp:meta_value', true)); } } if (!empty($post_postmeta)) { $postdata['postmeta'] = $post_postmeta; } return $postdata; }
/** * install serve image subdomain * @ajax hw_install_static_url_subdomain */ public function _ajax_install_static_url_subdomain() { if (!wp_verify_nonce($_REQUEST['nonce'], "hw_install_static_url_subdomain_nonce")) { exit("hacked !"); } global $wpdb; //update option 'upload_url_path' if (!isset($_POST['subdomain'])) { return; } //get subdomain $schema = 'http://'; if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { // SSL connection $schema = 'https://'; } $subdomain = rtrim($schema . $_POST['subdomain'] . '.' . $_SERVER['SERVER_NAME'], '/'); $main_domain = rtrim(site_url(), '/'); //main domain /** * scan some table to update absolute url */ //$query[] = 'update wp_options set option_value=REPLACE(option_value,"'.$main_domain.'","'.$subdomain.'")'; //$query[] = 'update wp_posts set guid=REPLACE(guid,"'.$main_domain.'","'.$subdomain.'")'; $query[] = 'update wp_posts set post_content=REPLACE(post_content,"' . $main_domain . '","' . $subdomain . '")'; //$query[] = 'update wp_postmeta set meta_value=REPLACE(meta_value,"'.$main_domain.'","'.$subdomain.'")'; if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { if (HW_URL::valid_url($subdomain)) { update_option('upload_url_path', $subdomain); } foreach ($query as $sql) { $wpdb->query($sql); } echo 'Chú ý: Sửa file .htaccess'; } else { header("Location: " . $_SERVER["HTTP_REFERER"]); } die; }
/** * valid skin url & path * @param $skin */ public static function valid_skin_path($skin) { if (isset($skin['apply_plugin'])) { $apply_plugin = $skin['apply_plugin']; } //self::current()->_apply_plugin; //from plugin if ($skin['source'] == 'plugin') { if (isset($skin['file_path']) && !file_exists($skin['file_path'])) { if (empty($apply_plugin)) { $apply_plugin = self::get_apply_plugin_from_path($skin['file_path']); } $skin['file_path'] = rtrim(HW_File_Directory::generate_path(HW_HOANGWEB_PATH, $skin['file_path']), '\\/'); } if (isset($skin['file_url']) && !HW_URL::valid_url($skin['file_url'])) { if (empty($apply_plugin)) { $apply_plugin = self::get_apply_plugin_from_path($skin['file_url']); } $skin['file_url'] = HW_File_Directory::generate_url(HW_HOANGWEB_URL, $skin['file_url']); } if (isset($skin['skin_url']) && !HW_URL::valid_url($skin['skin_url'])) { if (empty($apply_plugin)) { $apply_plugin = self::get_apply_plugin_from_path($skin['skin_url']); } $skin['skin_url'] = HW_File_Directory::generate_url(HW_HOANGWEB_URL, $skin['skin_url']); } } elseif ($skin['source'] == 'theme') { $theme_source_path = get_stylesheet_directory(); $theme_source_url = get_stylesheet_directory_uri(); /*if(!empty($apply_plugin)) { //no need i added in get_skins method $theme_source_path .= '/modules/'. $apply_plugin; $theme_source_url .= '/modules/'. $apply_plugin; }*/ if (isset($skin['file_path']) && !file_exists($skin['file_path'])) { $skin['file_path'] = rtrim(HW_File_Directory::generate_path($theme_source_path, $skin['file_path']), '\\/'); } if (isset($skin['file_url']) && !HW_URL::valid_url($skin['file_url'])) { $skin['file_url'] = HW_File_Directory::generate_url($theme_source_url, $skin['file_url']); } if (isset($skin['skin_url']) && !HW_URL::valid_url($skin['skin_url'])) { $skin['skin_url'] = HW_File_Directory::generate_url($theme_source_url, $skin['skin_url']); } } elseif ($skin['source'] == 'wp_content') { if (isset($skin['file_path']) && !file_exists($skin['file_path'])) { $skin['file_path'] = rtrim(HW_File_Directory::generate_path(WP_CONTENT_DIR, $skin['file_path']), '\\/'); } if (isset($skin['file_url']) && !HW_URL::valid_url($skin['file_url'])) { $skin['file_url'] = HW_File_Directory::generate_url(WP_CONTENT_URL, $skin['file_url']); } if (isset($skin['skin_url']) && !HW_URL::valid_url($skin['skin_url'])) { $skin['skin_url'] = HW_File_Directory::generate_url(WP_CONTENT_URL, $skin['skin_url']); } } return $skin; }