コード例 #1
0
ファイル: slider.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_register_slider_position($id, $name, $description = '')
{
    global $hocwp_slider_positions;
    if (!is_array($hocwp_slider_positions)) {
        $hocwp_slider_positions = array();
    }
    $id = hocwp_sanitize_id($id);
    if (array_key_exists($id, $hocwp_slider_positions)) {
        return;
    }
    $new_slider_item = array('id' => $id, 'name' => $name, 'description' => $description);
    $hocwp_slider_positions[$id] = $new_slider_item;
}
コード例 #2
0
function hocwp_plugin_upgrader_process_complete($upgrader, $options)
{
    $plugins = hocwp_get_value_by_key($options, 'plugins');
    if (!hocwp_array_has_value($plugins)) {
        return;
    }
    foreach ($plugins as $plugin) {
        $slug = hocwp_get_plugin_slug_from_file_path($plugin);
        $transient_name = 'hocwp_plugins_api_' . $slug . '_plugin_information';
        $transient_name = hocwp_sanitize_id($transient_name);
        delete_transient($transient_name);
    }
}
コード例 #3
0
ファイル: utils.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_get_sidebar_info($post)
{
    $post_id = $post->ID;
    $active = (bool) hocwp_get_post_meta('active', $post_id);
    $sidebar_id = hocwp_get_post_meta('sidebar_id', $post_id);
    $default = (bool) hocwp_get_post_meta('sidebar_default', $post_id);
    if (empty($sidebar_id)) {
        $sidebar_id = $post->post_name;
    }
    $sidebar_name = hocwp_get_value_by_key('sidebar_name', $post_id);
    if (empty($sidebar_name)) {
        $sidebar_name = $post->post_title;
    }
    if (hocwp_qtranslate_x_installed()) {
        $sidebar_name = apply_filters('translate_text', $sidebar_name, $lang = null, $flags = 0);
    }
    $sidebar_description = hocwp_get_post_meta('sidebar_description', $post_id);
    $sidebar_tag = hocwp_get_post_meta('sidebar_tag', $post_id);
    if (empty($sidebar_tag)) {
        $sidebar_tag = 'div';
    }
    $args = array('id' => hocwp_sanitize_id($sidebar_id), 'name' => strip_tags($sidebar_name), 'description' => strip_tags($sidebar_description), 'tag' => strtolower($sidebar_tag), 'active' => $active, 'default' => $default);
    return $args;
}
コード例 #4
0
ファイル: meta.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_term_meta_edit_field($args = array())
{
    $class = hocwp_get_value_by_key($args, 'class');
    $name = hocwp_get_value_by_key($args, 'name');
    $id = hocwp_get_value_by_key($args, 'id');
    $label = hocwp_get_value_by_key($args, 'label');
    $callback = hocwp_get_value_by_key($args, 'callback');
    if (!hocwp_callback_exists($callback)) {
        $callback = hocwp_get_value_by_key($args, 'field_callback');
    }
    $field_args = hocwp_get_value_by_key($args, 'field_args');
    $field_args = wp_parse_args($field_args, $args);
    hocwp_transmit_id_and_name($id, $name);
    $tmp = hocwp_sanitize_html_class($name);
    hocwp_add_string_with_space_before($class, 'form-field term-' . $name . '-wrap hocwp');
    ?>
	<tr class="<?php 
    echo $class;
    ?>
">
		<th scope="row">
			<label for="<?php 
    echo esc_attr(hocwp_sanitize_id($id));
    ?>
"><?php 
    echo $label;
    ?>
</label>
		</th>
		<td>
			<?php 
    if (hocwp_callback_exists($callback)) {
        unset($field_args['label']);
        call_user_func($callback, $field_args);
    } else {
        _e('Please set a valid callback for this field', 'hocwp-theme');
    }
    ?>
		</td>
	</tr>
	<?php 
}
コード例 #5
0
 public function get_field_id($field_id)
 {
     $id = $this->get_field_name($field_id);
     $id = hocwp_sanitize_id($id);
     return $id;
 }
コード例 #6
0
ファイル: meta.php プロジェクト: skylarkcob/hocwp-projects
function hocwp_theme_meta_product_tab_field_box_helper($posts)
{
    foreach ($posts as $tab) {
        $id = hocwp_sanitize_id($tab->post_name);
        $args = array('post_type' => 'product', 'title' => $tab->post_title, 'field_id' => $id, 'id' => 'meta_box_' . $id);
        hocwp_meta_box_editor($args);
    }
}
コード例 #7
0
function hocwp_setup_theme_custom_css()
{
    $option = get_option('hocwp_theme_custom_css');
    $theme = wp_get_theme();
    $template = hocwp_sanitize_id($theme->get_template());
    $css = hocwp_get_value_by_key($option, $template);
    if (!empty($css)) {
        $css = hocwp_minify_css($css);
        $style = new HOCWP_HTML('style');
        $style->set_attribute('type', 'text/css');
        $style->set_text($css);
        $style->output();
    }
}
コード例 #8
0
    public function widget($args, $instance)
    {
        $this->instance = $instance;
        global $post;
        $title = hocwp_widget_title($args, $instance, false);
        $post_type = $this->get_post_type_from_instance($instance);
        $post_types = array();
        foreach ($post_type as $fvdata) {
            $ptvalue = isset($fvdata['value']) ? $fvdata['value'] : '';
            if (!empty($ptvalue)) {
                $post_types[] = $ptvalue;
            }
        }
        $number = isset($instance['number']) ? $instance['number'] : $this->args['number'];
        $by = isset($instance['by']) ? $instance['by'] : $this->args['by'];
        $category = isset($instance['category']) ? $instance['category'] : json_encode($this->args['category']);
        $category = hocwp_json_string_to_array($category);
        $excerpt_length = isset($instance['excerpt_length']) ? $instance['excerpt_length'] : $this->args['excerpt_length'];
        $content_class = 'widget-content';
        $slider = hocwp_get_value_by_key($instance, 'slider', hocwp_get_value_by_key($this->args, 'slider'));
        $title_length = hocwp_get_value_by_key($instance, 'title_length', hocwp_get_value_by_key($this->args, 'title_length'));
        $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail'));
        $widget_title_link_category = hocwp_get_value_by_key($instance, 'widget_title_link_category', hocwp_get_value_by_key($this->args, 'widget_title_link_category'));
        $category_as_widget_title = hocwp_get_value_by_key($instance, 'category_as_widget_title', hocwp_get_value_by_key($this->args, 'category_as_widget_title'));
        if ((bool) $slider) {
            hocwp_add_string_with_space_before($content_class, 'post-slider');
        }
        if ('category' == $by && (bool) $widget_title_link_category) {
            $cvalue = current($category);
            $term_id = isset($cvalue['value']) ? $cvalue['value'] : '';
            $term_id = absint($term_id);
            if ($term_id > 0) {
                $taxonomy = isset($cvalue['taxonomy']) ? $cvalue['taxonomy'] : '';
                $link = new HOCWP_HTML('a');
                $link->set_class('term-link');
                $link->set_href(get_term_link($term_id, $taxonomy));
                if ((bool) $category_as_widget_title) {
                    $term = get_term($term_id, $taxonomy);
                    $title = $term->name;
                } else {
                    $title = hocwp_get_value_by_key($instance, 'title');
                }
                $link->set_text($title);
                $title = hocwp_get_value_by_key($args, 'before_title') . $link->build() . hocwp_get_value_by_key($args, 'after_title');
            }
        }
        $query_args = array('posts_per_page' => $number, 'post_type' => $post_types);
        $w_query = new WP_Query();
        $get_by = false;
        switch ($by) {
            case 'recent':
                $get_by = true;
                break;
            case 'modified':
            case 'recent_modified':
                $get_by = true;
                $query_args['orderby'] = 'modified';
                $query_args['order'] = 'DESC';
                break;
            case 'rand':
            case 'random':
                $get_by = true;
                $query_args['orderby'] = 'rand';
                break;
            case 'most_comment':
            case 'comment_count':
            case 'comment':
                $get_by = true;
                $query_args['orderby'] = 'comment_count';
                break;
            case 'category':
                foreach ($category as $cvalue) {
                    $term_id = isset($cvalue['value']) ? $cvalue['value'] : '';
                    $term_id = absint($term_id);
                    if ($term_id > 0) {
                        $taxonomy = isset($cvalue['taxonomy']) ? $cvalue['taxonomy'] : '';
                        if (!empty($taxonomy)) {
                            $tax_item = array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $term_id);
                            $query_args = hocwp_query_sanitize_tax_query($tax_item, $query_args);
                            $get_by = true;
                        }
                    }
                }
                break;
            case 'related':
                $get_by = true;
                break;
            case 'like':
                $get_by = true;
                $query_args['meta_key'] = 'likes';
                $query_args['orderby'] = 'meta_value_num';
                break;
            case 'view':
                $get_by = true;
                $query_args['meta_key'] = 'views';
                $query_args['orderby'] = 'meta_value_num';
                break;
            case 'featured':
                $get_by = true;
                hocwp_query_sanitize_featured_args($query_args);
                break;
            case 'favorite':
                break;
            case 'rate':
                break;
        }
        $get_by = apply_filters('hocwp_widget_post_get_by_check_status', $get_by, $args, $instance, $this);
        if ($get_by) {
            $query_args = apply_filters('hocwp_widget_post_query_args', $query_args, $args, $instance, $this);
            if ('related' == $by) {
                $w_query = hocwp_query_related_post($query_args);
            } else {
                $w_query = hocwp_query($query_args);
            }
        }
        $widget_html = hocwp_get_value_by_key($args, 'before_widget') . $title;
        $widget_html .= '<div class="' . $content_class . '">';
        $widget_post_pre_html = apply_filters('hocwp_widget_post_pre_html', '', $args, $instance, $this);
        if (!empty($widget_post_pre_html)) {
            $widget_html .= $widget_post_pre_html;
        } else {
            if ($w_query->have_posts()) {
                $widget_html .= apply_filters('hocwp_widget_post_before_loop', '', $args, $instance, $this);
                if ((bool) $slider) {
                    $four_posts = array_slice($w_query->posts, 0, 4);
                    $next_posts = array_slice($w_query->posts, 4, absint($w_query->post_count - 4));
                    $widget_content = apply_filters('hocwp_widget_post_pre_slider_html', '', $args, $instance, $this);
                    if (empty($widget_content)) {
                        $carousel_id = $this->id;
                        $carousel_id = hocwp_sanitize_id($carousel_id);
                        $count = 0;
                        ob_start();
                        ?>
						<div id="<?php 
                        echo $carousel_id;
                        ?>
" class="carousel slide" data-ride="carousel">
							<div class="carousel-inner" role="listbox">
								<?php 
                        foreach ($four_posts as $post) {
                            setup_postdata($post);
                            $class = 'item';
                            if (0 == $count) {
                                hocwp_add_string_with_space_before($class, 'active');
                            }
                            ?>
									<div class="<?php 
                            echo $class;
                            ?>
">
										<?php 
                            hocwp_article_before();
                            do_action('hocwp_widget_post_slider_before_post', $args, $instance, $this);
                            if (!(bool) $hide_thumbnail) {
                                if ('coupon' == $post->post_type) {
                                    $store = hocwp_get_coupon_store($post->ID);
                                    echo '<div class="text-center store-logo">';
                                    hocwp_term_the_thumbnail(array('term' => $store, 'width' => 180, 'height' => 110));
                                    echo '</div>';
                                } else {
                                    hocwp_post_thumbnail(array('width' => 300, 'height' => 200));
                                }
                            }
                            do_action('hocwp_widget_post_slider_before_post_title', $args, $instance, $this);
                            hocwp_post_title_link(array('title' => hocwp_substr(get_the_title(), $title_length)));
                            do_action('hocwp_widget_post_slider_after_post_title', $args, $instance, $this);
                            hocwp_entry_summary($excerpt_length);
                            do_action('hocwp_widget_post_slider_after_post', $args, $instance, $this);
                            hocwp_article_after();
                            ?>
									</div>
									<?php 
                            $count++;
                        }
                        wp_reset_postdata();
                        ?>
							</div>
							<ol class="carousel-indicators list-inline list-unstyled">
								<?php 
                        $count = count($four_posts);
                        for ($i = 0; $i < $count; $i++) {
                            $indicator_class = 'indicator-item';
                            if (0 == $i) {
                                hocwp_add_string_with_space_before($indicator_class, 'active');
                            }
                            ?>
									<li data-target="#<?php 
                            echo $carousel_id;
                            ?>
" data-slide-to="<?php 
                            echo $i;
                            ?>
"
									    class="<?php 
                            echo $indicator_class;
                            ?>
">
										<span><?php 
                            echo $i + 1;
                            ?>
</span>
									</li>
									<?php 
                        }
                        ?>
							</ol>
							<a class="left carousel-control" href="#<?php 
                        echo $carousel_id;
                        ?>
" role="button"
							   data-slide="prev">
								<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
								<span class="sr-only"><?php 
                        _e('Previous', 'hocwp-theme');
                        ?>
</span>
							</a>
							<a class="right carousel-control" href="#<?php 
                        echo $carousel_id;
                        ?>
" role="button"
							   data-slide="next">
								<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
								<span class="sr-only"><?php 
                        _e('Next', 'hocwp-theme');
                        ?>
</span>
							</a>
						</div>
						<?php 
                        $widget_content = ob_get_clean();
                        if (hocwp_array_has_value($next_posts)) {
                            $w_query->posts = $next_posts;
                            $w_query->post_count = count($next_posts);
                            ?>
							<div class="more-posts">
								<?php 
                            $widget_content .= $this->list_post_html($args, $instance, $w_query);
                            ?>
							</div>
							<?php 
                        }
                    }
                    $widget_content = apply_filters('hocwp_widget_post_slider_html', $widget_content, $args, $instance, $this);
                    $widget_html .= $widget_content;
                } else {
                    $widget_html .= $this->list_post_html($args, $instance, $w_query);
                }
                $widget_html .= apply_filters('hocwp_widget_post_after_loop', '', $args, $instance, $this);
            } else {
                $widget_html .= '<p class="nothing-found">' . __('Nothing found!', 'hocwp-theme') . '</p>';
            }
        }
        $widget_html = apply_filters('hocwp_widget_post_html', $widget_html, $args, $instance, $this);
        $widget_html .= '</div>';
        $widget_html .= hocwp_get_value_by_key($args, 'after_widget');
        echo $widget_html;
    }
コード例 #9
0
function hocwp_setup_theme_woocommerce_product_tabs($tabs)
{
    $args = array('posts_per_page' => -1, 'post_type' => 'hocwp_product_tab');
    $query = hocwp_query($args);
    if ($query->have_posts()) {
        foreach ($query->posts as $tab) {
            $id = hocwp_sanitize_id($tab->post_name);
            $tabs[$id] = array('title' => $tab->post_title, 'priority' => 20, 'callback' => 'hocwp_setup_theme_woocommerce_product_tabs_callback');
        }
    }
    return $tabs;
}
コード例 #10
0
function hocwp_admin_notice($args = array())
{
    $class = isset($args['class']) ? $args['class'] : '';
    hocwp_add_string_with_space_before($class, 'updated notice');
    $error = isset($args['error']) ? (bool) $args['error'] : false;
    $type = isset($args['type']) ? $args['type'] : 'default';
    $bs_callout = 'bs-callout-' . $type;
    hocwp_add_string_with_space_before($class, $bs_callout);
    if ($error) {
        hocwp_add_string_with_space_before($class, 'settings-error error');
    }
    $dismissible = isset($args['dismissible']) ? (bool) $args['dismissible'] : true;
    if ($dismissible) {
        hocwp_add_string_with_space_before($class, 'is-dismissible');
    }
    $id = isset($args['id']) ? $args['id'] : '';
    $id = hocwp_sanitize_id($id);
    $text = isset($args['text']) ? $args['text'] : '';
    if (empty($text)) {
        return;
    }
    $title = isset($args['title']) ? $args['title'] : '';
    if ($error && empty($title)) {
        $title = __('Error', 'hocwp-theme');
    }
    if (!empty($title)) {
        $text = '<strong>' . $title . ':</strong> ' . $text;
    }
    ?>
	<div class="<?php 
    echo esc_attr($class);
    ?>
" id="<?php 
    echo esc_attr($id);
    ?>
">
		<p><?php 
    echo $text;
    ?>
</p>
	</div>
	<?php 
}
コード例 #11
0
function hocwp_theme_the_menu($args = array())
{
    if (!is_array($args)) {
        $args = array('theme_location' => $args);
    }
    $items_wrap = '<ul id="%1$s" class="%2$s">%3$s</ul>';
    $theme_location = isset($args['theme_location']) ? $args['theme_location'] : 'primary';
    $menu_id = isset($args['menu_id']) ? $args['menu_id'] : $theme_location . '_menu';
    $menu_id = hocwp_sanitize_id($menu_id);
    $menu_class = isset($args['menu_class']) ? $args['menu_class'] : '';
    hocwp_add_string_with_space_before($menu_class, 'hocwp-menu');
    hocwp_add_string_with_space_before($menu_class, $theme_location);
    $nav_class = hocwp_get_value_by_key($args, 'nav_class');
    hocwp_add_string_with_space_before($nav_class, 'navigation');
    if ('primary' == $theme_location) {
        hocwp_add_string_with_space_before($nav_class, 'main-navigation');
    }
    hocwp_add_string_with_space_before($nav_class, hocwp_sanitize_html_class($theme_location . '-navigation'));
    $superfish = isset($args['superfish']) ? $args['superfish'] : true;
    if ($superfish) {
        hocwp_add_string_with_space_before($menu_class, 'hocwp-superfish-menu');
        $items_wrap = '<ul id="%1$s" class="sf-menu %2$s">%3$s</ul>';
    }
    $button_text = isset($args['button_text']) ? $args['button_text'] : __('Menu', 'hocwp-theme');
    hocwp_add_string_with_space_before($nav_class, 'clearfix');
    ?>
	<nav id="<?php 
    echo hocwp_sanitize_id($theme_location . '_navigation');
    ?>
"
	     class="<?php 
    echo $nav_class;
    ?>
"
	     data-button-text="<?php 
    echo $button_text;
    ?>
"<?php 
    hocwp_html_tag_attributes('nav', 'site_navigation');
    ?>
>
		<?php 
    $menu_args = array('theme_location' => $theme_location, 'menu_class' => $menu_class, 'menu_id' => $menu_id, 'items_wrap' => $items_wrap);
    $menu_args = wp_parse_args($args, $menu_args);
    wp_nav_menu($menu_args);
    ?>
	</nav><!-- #site-navigation -->
	<?php 
}
コード例 #12
0
function hocwp_parse_sjc_exchange_rate($url = '')
{
    $result = null;
    if (empty($url)) {
        $url = 'http://www.sjc.com.vn/xml/tygiavang.xml';
    }
    $transient_name = hocwp_build_transient_name('hocwp_exchange_rate_sjc_%s', '');
    if (false === ($result = get_transient($transient_name))) {
        $xml = hocwp_parse_xml($url);
        if (is_object($xml)) {
            $updated = (array) $xml->ratelist['updated'];
            $unit = (array) $xml->ratelist['unit'];
            $data = array('updated' => array_shift($updated), 'unit' => array_shift($unit));
            $cities = $xml->ratelist->city;
            $lists = array();
            foreach ($cities as $city) {
                $name = (array) $city['name'];
                $name = array_shift($name);
                $items = $city->item;
                $tmp = array('name' => $name);
                $childs = array();
                foreach ($items as $item) {
                    $buy = (array) $item['buy'];
                    $sell = (array) $item['sell'];
                    $type = (array) $item['type'];
                    $childs[] = array('buy' => array_shift($buy), 'sell' => array_shift($sell), 'type' => array_shift($type));
                }
                $tmp['item'] = $childs;
                $lists[hocwp_sanitize_id(hocwp_sanitize_file_name($name))] = $tmp;
            }
            $data['city'] = $lists;
            $result = $data;
            $expiration = apply_filters('hocwp_sjc_exchange_rate_expiration', HOUR_IN_SECONDS);
            set_transient($transient_name, $result, $expiration);
        }
    }
    return $result;
}
コード例 #13
0
function hocwp_field_select($args = array())
{
    $args = hocwp_field_sanitize_args($args);
    $id = isset($args['id']) ? $args['id'] : '';
    $name = isset($args['name']) ? $args['name'] : '';
    $list_options = isset($args['list_options']) ? $args['list_options'] : array();
    $options = isset($args['options']) ? $args['options'] : array();
    if (!hocwp_array_has_value($options)) {
        $options = hocwp_get_value_by_key($args, array('field_args', 'options'));
    }
    $load_item = isset($args['load_item']) ? $args['load_item'] : true;
    $value = isset($args['value']) ? $args['value'] : '';
    $field_class = isset($args['field_class']) ? $args['field_class'] : 'widefat';
    if (!is_array($options) || count($options) < 1) {
        $options = $list_options;
    }
    $all_option = isset($args['all_option']) ? $args['all_option'] : '';
    $autocomplete = isset($args['autocomplete']) ? $args['autocomplete'] : false;
    if (!$autocomplete) {
        $autocomplete = 'off';
    }
    $select_option = isset($args['default_option']) ? $args['default_option'] : '';
    if ($load_item && empty($all_option)) {
        foreach ($options as $key => $text) {
            $select_option .= hocwp_field_get_option(array('value' => $key, 'text' => $text, 'selected' => $value));
        }
    } else {
        $select_option .= $all_option;
    }
    if (!$load_item) {
        $custom_options = isset($args['custom_options']) ? $args['custom_options'] : '';
        $select_option .= $custom_options;
    }
    hocwp_field_before($args);
    $html = new HOCWP_HTML('select');
    $attributes = isset($args['attributes']) ? hocwp_sanitize_array($args['attributes']) : array();
    $atts = array('id' => hocwp_sanitize_id($id), 'name' => $name, 'class' => $field_class, 'autocomplete' => $autocomplete, 'text' => $select_option);
    $html->set_attribute_array($atts);
    foreach ($attributes as $key => $value) {
        $html->set_attribute($key, $value);
    }
    $html->output();
    hocwp_field_after($args);
}
コード例 #14
0
 public function set_id($id)
 {
     $id = hocwp_sanitize_id($id);
     $this->set_attribute('id', $id);
 }
コード例 #15
0
<?php

if (!function_exists('add_filter')) {
    exit;
}
global $hocwp_tos_tabs;
$parent_slug = 'hocwp_theme_option';
$theme = wp_get_theme();
$template = hocwp_sanitize_id($theme->get_template());
$option = new HOCWP_Option(__('Custom CSS', 'hocwp-theme'), 'hocwp_theme_custom_css');
$option->set_parent_slug($parent_slug);
$option->add_field(array('id' => $template, 'title' => __('Theme Custom CSS', 'hocwp-theme'), 'class' => 'widefat', 'row' => 30, 'field_callback' => 'hocwp_field_textarea'));
$option->add_option_tab($hocwp_tos_tabs);
$option->set_page_header_callback('hocwp_theme_option_form_before');
$option->set_page_footer_callback('hocwp_theme_option_form_after');
$option->set_page_sidebar_callback('hocwp_theme_option_sidebar_tab');
$option->init();
hocwp_option_add_object_to_list($option);