public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
 {
     $menu_title = $item->title;
     $menu_title_slug = hocwp_sanitize_file_name($menu_title);
     $indent = $depth ? str_repeat("\t", $depth) : '';
     $classes = empty($item->classes) ? array() : (array) $item->classes;
     $classes[] = 'menu-item-' . $item->ID;
     $classes[] = 'menu-' . $menu_title_slug;
     $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args, $depth));
     $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
     $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
     $id = $id ? ' id="' . esc_attr($id) . '"' : '';
     $output .= $indent . '<li' . $id . $class_names;
     $atts = apply_filters('hocwp_menu_item_attributes', '', $item, $depth, $args);
     $atts = hocwp_attribute_to_string($atts);
     hocwp_add_string_with_space_before($output, $atts);
     $output .= '>';
     $atts = array();
     $atts['title'] = !empty($item->attr_title) ? $item->attr_title : '';
     $atts['target'] = !empty($item->target) ? $item->target : '';
     $atts['rel'] = !empty($item->xfn) ? $item->xfn : '';
     $atts['href'] = !empty($item->url) ? $item->url : '';
     $atts = apply_filters('nav_menu_link_attributes', $atts, $item, $args, $depth);
     $attributes = '';
     foreach ($atts as $attr => $value) {
         if (!empty($value)) {
             $value = 'href' === $attr ? esc_url($value) : esc_attr($value);
             $attributes .= ' ' . $attr . '="' . $value . '"';
         }
     }
     $item_output = $args->before;
     $item_output .= '<a' . $attributes . '>';
     $item_output .= $args->link_before;
     $item_output = apply_filters('hocwp_menu_item_output_link_text_before', $item_output, $item, $args, $depth);
     $link_text = apply_filters('the_title', $item->title, $item->ID);
     $item_output .= apply_filters('hocwp_menu_item_output_link_text', $link_text, $item, $args, $depth);
     if (!empty($item->description)) {
         $item_output .= '<span class="description">' . $item->description . '</span>';
     }
     $item_output = apply_filters('hocwp_menu_item_output_link_text_after', $item_output, $item, $args, $depth);
     $item_output .= $args->link_after;
     $item_output .= '</a>';
     $item_output .= $args->after;
     $item_output = apply_filters('hocwp_menu_item_output_link_after', $item_output, $item, $args, $depth);
     $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
 }
Esempio n. 2
0
function hocwp_autoload($class_name)
{
    $base_path = HOCWP_PATH;
    $pieces = explode('_', $class_name);
    $pieces = array_filter($pieces);
    $first_piece = current($pieces);
    if ('HOCWP' !== $class_name && 'HOCWP' !== $first_piece) {
        return;
    }
    if (false !== strrpos($class_name, 'HOCWP_Widget')) {
        $base_path .= '/widgets';
    }
    $file = $base_path . '/class-' . hocwp_sanitize_file_name($class_name);
    $file .= '.php';
    if (file_exists($file)) {
        require $file;
    }
}
 public function term_field_edit_page($term)
 {
     if (hocwp_callback_exists($this->get_edit_callback())) {
         call_user_func($this->get_edit_callback(), $term);
     } else {
         $term_id = $term->term_id;
         foreach ($this->get_fields() as $field) {
             $field_args = isset($field['field_args']) ? $field['field_args'] : array();
             $callback = isset($field['field_callback']) ? $field['field_callback'] : 'hocwp_field_input';
             $label = hocwp_get_value_by_key($field_args, 'title', hocwp_get_value_by_key($field_args, 'label'));
             if ('hocwp_field_input_checkbox' != $callback && 'hocwp_field_input_radio' != $callback) {
                 unset($field_args['label']);
             }
             $id = isset($field_args['id']) ? $field_args['id'] : '';
             $name = isset($field_args['name']) ? $field_args['name'] : '';
             hocwp_transmit_id_and_name($id, $name);
             if (!isset($field_args['value'])) {
                 $value = hocwp_term_get_meta($term_id, $name);
                 if (empty($value) && 'hocwp_field_input_radio' == $callback) {
                     $value = hocwp_get_value_by_key($field, 'default');
                 }
                 $field_args['value'] = $value;
             }
             $class = 'term-' . $name . '-wrap';
             $class = hocwp_sanitize_file_name($class);
             hocwp_add_string_with_space_before($class, 'form-field hocwp');
             $data = array('id' => $id, 'class' => $class, 'label' => $label, 'field_args' => $field_args, 'callback' => $callback);
             hocwp_term_meta_edit_field($data);
         }
     }
 }
Esempio n. 4
0
function hocwp_media_sanitize_upload_file_name($file)
{
    $file_name = isset($file['name']) ? $file['name'] : '';
    $file['name'] = hocwp_sanitize_file_name($file_name);
    return $file;
}
Esempio n. 5
0
function hocwp_execute_upload($args = array())
{
    $files = isset($args['files']) ? $args['files'] : array();
    unset($args['files']);
    $upload_path = isset($args['upload_path']) ? $args['upload_path'] : '';
    unset($args['upload_path']);
    $upload_url = isset($args['upload_url']) ? $args['upload_url'] : '';
    unset($args['upload_url']);
    if (empty($upload_path)) {
        $upload_dir = hocwp_get_upload_folder_details();
        $target_dir = untrailingslashit($upload_dir['path']) . '/hocwp';
        $upload_url = untrailingslashit($upload_dir['url']) . '/hocwp';
        if (!file_exists($target_dir)) {
            wp_mkdir_p($target_dir);
        }
        $upload_path = $target_dir;
    }
    $file_names = isset($files['name']) ? $files['name'] : array();
    $file_count = count($file_names);
    $list_files = array();
    for ($i = 0; $i < $file_count; $i++) {
        $name = isset($files['name'][$i]) ? $files['name'][$i] : '';
        $type = isset($files['type'][$i]) ? $files['type'][$i] : '';
        $tmp_name = isset($files['tmp_name'][$i]) ? $files['tmp_name'][$i] : '';
        $error = isset($files['error'][$i]) ? $files['error'][$i] : '';
        $size = isset($files['size'][$i]) ? $files['size'][$i] : '';
        $file_item = array('name' => $name, 'type' => $type, 'tmp_name' => $tmp_name, 'error' => $error, 'size' => $size);
        $list_files[] = $file_item;
    }
    $list_results = array();
    foreach ($list_files as $key => $file) {
        $file['path'] = $upload_path;
        $file = wp_parse_args($args, $file);
        $result = hocwp_upload($file);
        if ($result['success']) {
            $file_name = $file['name'];
            $file_path = untrailingslashit($upload_path) . '/' . hocwp_sanitize_file_name($file_name);
            $file_url = untrailingslashit($upload_url) . '/' . hocwp_sanitize_file_name(basename($result['name']));
            $attachment = array('guid' => $file_url);
            hocwp_insert_attachment($attachment, $file_path);
            $result['url'] = $file_url;
        }
        $list_results[] = $result;
    }
    return $list_results;
}
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;
}
Esempio n. 7
0
function hocwp_field_fieldset($args = array())
{
    $args = hocwp_field_sanitize_args($args);
    $label = isset($args['label']) ? $args['label'] : '';
    $callback = hocwp_sanitize_callback($args);
    $container_class = isset($args['container_class']) ? $args['container_class'] : '';
    $func_args = hocwp_sanitize_callback_args($args);
    if (!is_array($callback)) {
        hocwp_add_string_with_space_before($container_class, hocwp_sanitize_file_name($callback));
    } else {
        $cb_class = isset($callback[1]) ? $callback[1] : '';
        if (!empty($cb_class)) {
            hocwp_add_string_with_space_before($container_class, hocwp_sanitize_file_name($cb_class));
        }
    }
    hocwp_add_string_with_space_before($container_class, 'hocwp-fieldset');
    unset($args['label']);
    hocwp_field_before($args);
    ?>
	<fieldset class="<?php 
    echo $container_class;
    ?>
">
		<legend><?php 
    echo $label;
    ?>
</legend>
		<?php 
    call_user_func($callback, $func_args);
    ?>
	</fieldset>
	<?php 
    hocwp_field_after($args);
}