public function export_to_db($string, $translation = '')
 {
     $encrypted_string = md5($string);
     $query = hocwp_get_post_by_meta('encrypted_string', $encrypted_string);
     $post_id = $this->post_id;
     $post_title = $this->build_post_title($string);
     $postarr = array('post_content' => $translation, 'post_type' => 'hocwp_mo', 'post_title' => $post_title, 'post_status' => 'private', 'post_excerpt' => $string);
     if (!$query->have_posts()) {
         if (hocwp_id_number_valid($post_id)) {
             $postarr['ID'] = $post_id;
         } else {
             $mo = $this->get_object($string);
             if (is_a($mo, 'WP_Post')) {
                 $postarr['ID'] = $mo->ID;
             }
         }
     } else {
         if (hocwp_id_number_valid($this->post_id)) {
             $postarr['ID'] = $this->post_id;
         } else {
             $object = array_shift($query->posts);
             $postarr['ID'] = $object->ID;
         }
     }
     $post_id = hocwp_insert_post($postarr);
     if (hocwp_id_number_valid($post_id)) {
         update_post_meta($post_id, 'encrypted_string', $encrypted_string);
         update_post_meta($post_id, 'string', $string);
     }
     return $post_id;
 }
示例#2
0
function hocwp_get_option_post($option_name, $slug, $option_base = 'hocwp_theme_setting')
{
    $options = get_option($option_base);
    $post_id = hocwp_get_value_by_key($options, $option_name);
    if (hocwp_id_number_valid($post_id)) {
        $result = get_post($post_id);
    } else {
        $result = hocwp_get_post_by_slug($slug);
    }
    if (!is_a($result, 'WP_Post')) {
        $result = new WP_Error();
    }
    return apply_filters('hocwp_get_option_post', $result, $option_name, $slug, $option_base);
}
 public function widget($args, $instance)
 {
     $this->instance = $instance;
     $category = $this->get_category_from_instance($instance);
     $categories = array();
     foreach ($category as $pvalue) {
         $value = hocwp_get_value_by_key($pvalue, 'value');
         if (hocwp_id_number_valid($value)) {
             $categories[] = $value;
         }
     }
     $bm_args = array('category' => implode(',', $categories));
     $bookmarks = get_bookmarks($bm_args);
     hocwp_widget_before($args, $instance);
     $bookmarks = hocwp_sanitize_bookmark_link_image($bookmarks);
     $bm_args = array('before' => '', 'after' => '');
     echo _walk_bookmarks($bookmarks, $bm_args);
     hocwp_widget_after($args, $instance);
 }
示例#4
0
function hocwp_theme_meta_box_subscriber_information($post_type, $post)
{
    if (!hocwp_is_post($post)) {
        return;
    }
    $post_id = $post->ID;
    if ('hocwp_subscriber' == $post_type) {
        $meta = new HOCWP_Meta('post');
        $meta->set_id('hocwp_subscriber_information');
        $meta->set_title(__('Subscriber Information', 'hocwp-theme'));
        $meta->add_post_type('hocwp_subscriber');
        $field_args = array('id' => 'subscriber_email', 'label' => __('Email:', 'hocwp-theme'), 'readonly' => true);
        $meta->add_field($field_args);
        $field_args = array('id' => 'subscriber_name', 'label' => __('Name:', 'hocwp-theme'));
        $meta->add_field($field_args);
        $field_args = array('id' => 'subscriber_phone', 'label' => __('Phone:', 'hocwp-theme'));
        $meta->add_field($field_args);
        if (hocwp_id_number_valid($post_id)) {
            $field_args = array('id' => 'subscriber_user', 'label' => __('User ID:', 'hocwp-theme'), 'readonly' => true);
            $meta->add_field($field_args);
        }
        $meta->init();
    }
}
示例#5
0
function hocwp_find_post($data, $post_type = 'post')
{
    $result = null;
    if (!empty($data)) {
        if (hocwp_id_number_valid($data)) {
            $temp = get_post($data);
            if (hocwp_is_post($temp) && $temp->post_type == $post_type) {
                $result = $temp;
            }
        } else {
            $result = hocwp_get_post_by_slug($data, $post_type);
        }
    }
    return $result;
}
 public function save_term_data($term_id)
 {
     $taxonomy = isset($_REQUEST['taxonomy']) ? $_REQUEST['taxonomy'] : '';
     $fields = $this->get_fields();
     foreach ($fields as $field) {
         $type = isset($field['type']) ? $field['type'] : 'default';
         $name = isset($field['field_args']['name']) ? $field['field_args']['name'] : '';
         if (empty($name)) {
             continue;
         }
         $value = hocwp_sanitize_form_post($name, $type);
         hocwp_term_update_meta($term_id, $name, $value);
         if ('thumbnail' == $name) {
             if ('product_cat' == $taxonomy && hocwp_wc_installed()) {
                 $value = hocwp_sanitize_media_value($value);
                 $id = $value['id'];
                 if (hocwp_id_number_valid($id)) {
                     hocwp_term_update_meta($term_id, 'thumbnail_id', $id);
                 } else {
                     hocwp_term_update_meta($term_id, 'thumbnail_id', '');
                 }
             }
         }
     }
     return $term_id;
 }
示例#7
0
function hocwp_crop_image($args = array())
{
    $attachment_id = hocwp_get_value_by_key($args, 'attachment_id');
    $url = hocwp_get_value_by_key($args, 'url');
    $base_url = '';
    if (!hocwp_id_number_valid($attachment_id) && !empty($url)) {
        $attachment_id = hocwp_get_media_id($url);
    }
    if (!hocwp_id_number_valid($attachment_id)) {
        if (empty($url)) {
            return new WP_Error('crop_image_size', __('Attachment ID is not valid.', 'hocwp-theme'));
        } else {
            $cropped = $url;
        }
    } else {
        $file_path = hocwp_get_media_file_path($attachment_id);
        $width = hocwp_get_value_by_key($args, 'width');
        $height = hocwp_get_value_by_key($args, 'height');
        $size = hocwp_get_image_sizes($attachment_id);
        $size = hocwp_sanitize_size($size);
        if (empty($width) && empty($height)) {
            $cropped = $file_path;
        } else {
            if (empty($width)) {
                $width = $size[0];
            }
            if (empty($height)) {
                $height = $size[1];
            }
            $x = apply_filters('hocwp_crop_image_x', 0, $args);
            $y = apply_filters('hocwp_crop_image_y', 0, $args);
            $x = hocwp_get_value_by_key($args, 'x', $x);
            $y = hocwp_get_value_by_key($args, 'y', $y);
            $dest_file = hocwp_get_value_by_key($args, 'dest_file', '');
            $path_info = pathinfo($file_path);
            if (empty($dest_file)) {
                $upload_dir = hocwp_get_upload_folder_details();
                $base_path = apply_filters('hocwp_custom_thumbnail_base_path', untrailingslashit($upload_dir['path']) . '/hocwp/thumbs/', $args);
                if (!file_exists($base_path)) {
                    wp_mkdir_p($base_path);
                }
                $base_url = apply_filters('hocwp_custom_thumbnail_base_url', untrailingslashit($upload_dir['url']) . '/hocwp/thumbs/', $args);
                $filename = $path_info['filename'];
                $dest_file = $base_path . str_replace($filename, $filename . '-' . $width . '-' . $height, basename($file_path));
            }
            $crop_args = array('source' => get_attached_file($attachment_id), 'dest' => $dest_file, 'width' => $width, 'height' => $height, 'x' => $x, 'y' => $y);
            $crop_args = wp_parse_args($args, $crop_args);
            if (file_exists($dest_file)) {
                $override = hocwp_get_value_by_key($args, 'override', false);
                if ($override) {
                    unlink($dest_file);
                    $cropped = hocwp_crop_image_helper($crop_args);
                } else {
                    $cropped = $dest_file;
                }
            } else {
                $cropped = hocwp_crop_image_helper($crop_args);
            }
        }
    }
    if (file_exists($cropped)) {
        $output = hocwp_get_value_by_key($args, 'output', 'url');
        if ('url' == $output) {
            $cropped = hocwp_media_path_to_url($attachment_id, $cropped, $base_url);
        }
    } else {
        $cropped = $url;
    }
    return apply_filters('hocwp_crop_image', $cropped, $args);
}
 function hocwp_widget_subscribe_ajax_callback()
 {
     $use_captcha = (bool) hocwp_get_method_value('use_captcha');
     $captcha_code = hocwp_get_method_value('captcha');
     $email = hocwp_get_method_value('email');
     $name = hocwp_get_method_value('name');
     $phone = hocwp_get_method_value('phone');
     $register = (bool) hocwp_get_method_value('register');
     $result = array('success' => false, 'message' => hocwp_build_message(hocwp_text_error_default(), 'danger'));
     $captcha_valid = true;
     if ($use_captcha) {
         $captcha = new HOCWP_Captcha();
         $captcha_valid = $captcha->check($captcha_code);
     }
     $re_verify = false;
     $query = hocwp_get_post_by_meta('subscriber_email', $email, array('post_type' => 'hocwp_subscriber'));
     if ($query->have_posts()) {
         $subscriber = array_shift($query->posts);
         $verified = hocwp_get_post_meta('subscriber_verified', $subscriber->ID);
         if (1 != $verified) {
             $re_verify = true;
         }
     }
     if ($captcha_valid) {
         if (is_email($email)) {
             $active_key = hocwp_generate_reset_key();
             $verify_link = hocwp_generate_verify_link($active_key);
             if ($re_verify) {
                 hocwp_send_mail_verify_email_subscription(hocwp_text_email_subject_verify_subscription(), $email, $verify_link);
                 $result['success'] = true;
                 $result['message'] = hocwp_build_message(hocwp_text_success_register_and_verify_email(), 'success');
             } else {
                 if ($query->have_posts() || $register && email_exists($email)) {
                     $result['message'] = hocwp_build_message(hocwp_text_error_email_exists(), 'danger');
                 } else {
                     $post_title = '';
                     if (!empty($name)) {
                         $post_title .= $name;
                     }
                     if (empty($post_title)) {
                         $post_title = $email;
                     } else {
                         $post_title .= ' - ' . $email;
                     }
                     $post_data = array('post_type' => 'hocwp_subscriber', 'post_title' => $post_title, 'post_status' => 'publish');
                     $post_id = hocwp_insert_post($post_data);
                     if (hocwp_id_number_valid($post_id)) {
                         update_post_meta($post_id, 'subscriber_name', $name);
                         update_post_meta($post_id, 'subscriber_email', $email);
                         update_post_meta($post_id, 'subscriber_phone', $phone);
                         update_post_meta($post_id, 'subscriber_verified', 0);
                         update_post_meta($post_id, 'subscriber_active_key', $active_key);
                         if ($register) {
                             $password = wp_generate_password();
                             $user_data = array('username' => $email, 'email' => $email, 'password' => $password);
                             $user_id = hocwp_add_user($user_data);
                             if (hocwp_id_number_valid($user_id)) {
                                 wp_send_new_user_notifications($user_id);
                                 update_post_meta($post_id, 'subscriber_user', $user_id);
                                 update_user_meta($user_id, 'subscriber_id', $post_id);
                             }
                         }
                         hocwp_send_mail_verify_email_subscription(hocwp_text_email_subject_verify_subscription(), $email, $verify_link);
                         $result['success'] = true;
                         $result['message'] = hocwp_build_message(hocwp_text_success_register_and_verify_email(), 'success');
                     }
                 }
             }
         } else {
             $result['message'] = hocwp_build_message(hocwp_text_error_email_not_valid(), 'danger');
         }
     } else {
         $result['message'] = hocwp_build_message(hocwp_text_error_captcha_not_valid(), 'danger');
     }
     wp_send_json($result);
 }
示例#9
0
function hocwp_field_input_file($args = array())
{
    $args['type'] = 'file';
    $image = (bool) hocwp_get_value_by_key($args, 'image');
    $max = hocwp_get_value_by_key($args, 'max');
    $attributes = hocwp_get_value_by_key($args, 'attributes');
    $attributes = hocwp_sanitize_array($attributes);
    $multiple = hocwp_get_value_by_key($args, 'multiple');
    $class = hocwp_get_value_by_key($args, 'class');
    $name = hocwp_get_value_by_key($args, 'name');
    if (empty($name)) {
        $name = 'file_names';
    }
    hocwp_add_string_with_space_before($class, 'hocwp-field-upload');
    if ($image) {
        $attributes['accept'] = 'image/*';
    }
    if (hocwp_id_number_valid($max)) {
        $attributes['data-max'] = $max;
        if (1 < $max) {
            $multiple = true;
        }
    }
    if ($multiple) {
        $attributes['multiple'] = 'multiple';
        if (false === strpos($name, '[]')) {
            $name .= '[]';
        }
        hocwp_add_string_with_space_before($class, 'multiple-file');
    } else {
        hocwp_add_string_with_space_before($class, 'single-file');
    }
    $args['attributes'] = $attributes;
    $args['class'] = $class;
    $after = hocwp_get_value_by_key($args, 'after');
    $after = '<div class="image-preview"></div>' . $after;
    $args['after'] = $after;
    $args['name'] = $name;
    hocwp_field_input($args);
}
示例#10
0
function hocwp_classifieds_admin_notice()
{
    $post_id = hocwp_get_method_value('post', 'request');
    if (hocwp_id_number_valid($post_id)) {
        $transient_name = hocwp_build_transient_name('hocwp_save_classifieds_post_%s_error', $post_id);
        $errors = get_transient($transient_name);
        if (false !== $errors) {
            foreach ($errors as $error) {
                hocwp_admin_notice(array('text' => $error, 'error' => true));
            }
            delete_transient($transient_name);
        }
    }
}
示例#11
0
function hocwp_register_string_language($args = array())
{
    if (!did_action('init')) {
        _doing_it_wrong(__FUNCTION__, __('Please call this function in <strong>hocwp_register_string_translation</strong> hook.', 'hocwp-theme'), HOCWP_VERSION);
        return;
    }
    if (!is_array($args)) {
        $args = array('string' => $args);
    }
    $name = hocwp_get_value_by_key($args, 'name');
    $string = hocwp_get_value_by_key($args, 'string');
    $context = hocwp_get_value_by_key($args, 'context', 'HocWP');
    $multiline = hocwp_get_value_by_key($args, 'multiline');
    $key = md5($string);
    $active_strings = hocwp_get_active_registered_string_language();
    $active_strings[$key]['name'] = $name;
    $active_strings[$key]['string'] = $string;
    $active_strings[$key]['context'] = $context;
    $active_strings[$key]['multiline'] = $multiline;
    global $hocwp_active_registered_string_translations;
    $hocwp_active_registered_string_translations = $active_strings;
    $transient_name = hocwp_build_transient_name('hocwp_string_translation_registered_%s', $args);
    if (false === get_transient($transient_name)) {
        $strings = hocwp_get_registered_string_language();
        $strings[$key]['name'] = $name;
        $strings[$key]['string'] = $string;
        $strings[$key]['context'] = $context;
        $strings[$key]['multiline'] = $multiline;
        update_option('hocwp_string_translations', $strings);
        $mo = new HOCWP_MO();
        $translation = '';
        $object = $mo->get_object($string);
        if (is_a($object, 'WP_Post')) {
            $translation = $object->post_content;
        }
        $post_id = $mo->export_to_db($string, $translation);
        if (hocwp_id_number_valid($post_id)) {
            set_transient($transient_name, $post_id, WEEK_IN_SECONDS);
        }
    }
}
示例#12
0
function hocwp_setup_theme_add_default_sidebars()
{
    $added = (bool) get_option('hocwp_default_sidebars_added');
    if ($added) {
        $query = hocwp_query(array('post_type' => 'hocwp_sidebar', 'posts_per_page' => -1));
        if (!$query->have_posts()) {
            $added = false;
        }
    }
    if (!$added) {
        $sidebars = hocwp_theme_get_default_sidebars();
        foreach ($sidebars as $name => $data) {
            $sidebar = hocwp_get_post_by_meta('sidebar_id', $name);
            if (!$sidebar->have_posts()) {
                $post_data = array('post_title' => $data['name'], 'post_type' => 'hocwp_sidebar', 'post_status' => 'publish');
                $post_id = hocwp_insert_post($post_data);
                if (hocwp_id_number_valid($post_id)) {
                    update_post_meta($post_id, 'sidebar_default', 1);
                    update_post_meta($post_id, 'sidebar_id', $name);
                    update_post_meta($post_id, 'sidebar_name', $data['name']);
                    update_post_meta($post_id, 'sidebar_description', $data['description']);
                    update_post_meta($post_id, 'sidebar_tag', $data['tag']);
                    update_post_meta($post_id, 'active', 1);
                }
            }
        }
        update_option('hocwp_default_sidebars_added', 1);
    }
}
示例#13
0
function hocwp_get_image_sizes($id)
{
    $path = $id;
    if (hocwp_id_number_valid($id)) {
        $path = get_attached_file($id);
    }
    if (!file_exists($path)) {
        return null;
    }
    return getimagesize($path);
}
示例#14
0
function hocwp_update_user_saved_posts($user_id = null, $post_id = null)
{
    $user_id = hocwp_return_user($user_id, 'id');
    if (hocwp_id_number_valid($user_id)) {
        $post_id = hocwp_return_post($post_id, 'id');
        if (hocwp_id_number_valid($post_id)) {
            $saved = hocwp_get_user_saved_posts($user_id);
            $saved = hocwp_sanitize_array($saved);
            if (in_array($post_id, $saved)) {
                unset($saved[array_search($post_id, $saved)]);
            } else {
                array_push($saved, $post_id);
            }
            $saved = hocwp_remove_empty_array_item($saved, true);
            return update_user_meta($user_id, 'saved_posts', $saved);
        }
    }
    return false;
}
示例#15
0
function hocwp_wc_on_product_updated($meta_id, $object_id, $meta_key, $meta_value)
{
    if (hocwp_id_number_valid($meta_id)) {
        $post = get_post($object_id);
        if ('product' == $post->post_type) {
            if ('_featured' == $meta_key) {
                if ('yes' == $meta_value) {
                    update_post_meta($object_id, 'featured', 1);
                } else {
                    update_post_meta($object_id, 'featured', 0);
                }
            } elseif ('featured' == $meta_key) {
                if (1 == $meta_value) {
                    update_post_meta($object_id, '_featured', 'yes');
                } else {
                    update_post_meta($object_id, '_featured', 'no');
                }
            }
        }
    }
}
示例#16
0
function hocwp_post_rating_ajax_callback()
{
    $result = array('success' => false);
    $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : 0;
    if (hocwp_id_number_valid($post_id)) {
        $score = isset($_POST['score']) ? $_POST['score'] : 0;
        if (is_numeric($score) && $score > 0) {
            $number = isset($_POST['number']) ? $_POST['number'] : 5;
            $number_max = isset($_POST['number_max']) ? $_POST['number_max'] : 5;
            $high_number = $number;
            if ($number > $number_max) {
                $high_number = $number_max;
            }
            $ratings_score = floatval(get_post_meta($post_id, 'ratings_score', true));
            $ratings_score += $score;
            $ratings_users = absint(get_post_meta($post_id, 'ratings_users', true));
            $ratings_users++;
            $high_ratings_users = absint(get_post_meta($post_id, 'high_ratings_users', true));
            if ($score == $high_number) {
                $high_ratings_users++;
                update_post_meta($post_id, 'high_ratings_users', $high_ratings_users);
            }
            $ratings_average = $score;
            update_post_meta($post_id, 'ratings_users', $ratings_users);
            update_post_meta($post_id, 'ratings_score', $ratings_score);
            if ($ratings_users > 0) {
                $ratings_average = $ratings_score / $ratings_users;
            }
            update_post_meta($post_id, 'ratings_average', $ratings_average);
            $result['success'] = true;
            $result['score'] = $ratings_average;
            $session_key = 'hocwp_post_' . $post_id . '_rated';
            $_SESSION[$session_key] = 1;
            do_action('hocwp_post_rated', $score, $post_id);
        }
    }
    return $result;
}
示例#17
0
function hocwp_the_comment_link($args = array())
{
    $post_id = hocwp_get_value_by_key($args, 'post_id', get_the_ID());
    if (hocwp_id_number_valid($post_id) && comments_open($post_id)) {
        $comment_count = hocwp_get_post_comment_count($post_id);
        $format = hocwp_get_value_by_key($args, 'format');
        if (empty($format)) {
            $format = '%COUNT% ' . _n('Comment', 'Comments', $comment_count, 'hocwp-theme');
        }
        $comment_text = str_replace('%COUNT%', $comment_count, $format);
        ?>
		<span class="entry-comments-link">
            <a href="<?php 
        the_permalink();
        ?>
#comments"><?php 
        echo $comment_text;
        ?>
</a>
        </span>
		<?php 
    }
}
function hocwp_setup_theme_edit_link_admin_footer()
{
    global $pagenow;
    if ('link.php' == $pagenow || 'link-add.php' == $pagenow) {
        $link_category = array();
        $link_id = hocwp_get_method_value('link_id', 'get');
        if (hocwp_id_number_valid($link_id)) {
            $bookmark = get_bookmark($link_id);
            if (hocwp_object_valid($bookmark)) {
                $link_category = $bookmark->link_category;
            }
        }
        hocwp_field_input_hidden(array('name' => 'hocwp_link_category', 'value' => json_encode($link_category)));
    }
}
示例#19
0
function hocwp_update_post_temperature_ajax_callback()
{
    $result = array();
    $post_id = hocwp_get_method_value('post_id');
    if (hocwp_id_number_valid($post_id)) {
        $type = hocwp_get_method_value('type');
        hocwp_update_post_temperature($type, $post_id);
    }
    wp_send_json($result);
}
示例#20
0
function hocwp_meta_box_google_maps($args = array())
{
    global $pagenow;
    if ('post-new.php' == $pagenow || 'post.php' == $pagenow) {
        $post_id = hocwp_get_value_by_key($_REQUEST, 'post');
        $id = hocwp_get_value_by_key($args, 'id', 'google_maps_box');
        $title = hocwp_get_value_by_key($args, 'title', __('Maps', 'hocwp-theme'));
        $post_types = hocwp_get_value_by_key($args, 'post_types', array('post'));
        $meta = new HOCWP_Meta('post');
        $meta->set_title($title);
        $meta->set_id($id);
        $meta->set_post_types($post_types);
        $map_args = array('id' => 'maps_content', 'label' => '', 'field_callback' => 'hocwp_field_google_maps', 'names' => array('google_maps'));
        if (hocwp_id_number_valid($post_id)) {
            $google_maps = hocwp_get_post_meta('google_maps', $post_id);
            $google_maps = hocwp_json_string_to_array($google_maps);
            $map_args['lat'] = hocwp_get_value_by_key($google_maps, 'lat');
            $map_args['long'] = hocwp_get_value_by_key($google_maps, 'lng');
        }
        $meta->add_field($map_args);
        //$meta->add_field(array('id' => 'google_maps', 'label' => '', 'field_callback' => 'hocwp_field_input_hidden'));
        $meta->init();
    }
}
    public function widget($args, $instance)
    {
        $this->instance = $instance;
        $number = hocwp_get_value_by_key($instance, 'number', hocwp_get_value_by_key($this->args, 'number'));
        $time = hocwp_get_value_by_key($instance, 'time', hocwp_get_value_by_key($this->args, 'time'));
        $exclude_users = hocwp_get_value_by_key($instance, 'exclude_users');
        $exclude_users = hocwp_json_string_to_array($exclude_users);
        $show_count = hocwp_get_value_by_key($instance, 'show_count', hocwp_get_value_by_key($this->args, 'show_count'));
        $link_author_name = hocwp_get_value_by_key($instance, 'link_author_name', hocwp_get_value_by_key($this->args, 'link_author_name'));
        $none_text = hocwp_get_value_by_key($instance, 'none_text', hocwp_get_value_by_key($this->args, 'none_text'));
        hocwp_widget_before($args, $instance);
        $condition = '';
        if (hocwp_array_has_value($exclude_users)) {
            $not_in = array();
            foreach ($exclude_users as $data) {
                $uid = hocwp_get_value_by_key($data, 'value');
                if (hocwp_id_number_valid($uid)) {
                    $not_in[] = $uid;
                }
            }
            if (hocwp_array_has_value($not_in)) {
                $condition = 'AND user_id NOT IN (' . implode(', ', $not_in) . ')';
            }
        }
        $commenters = hocwp_get_top_commenters($number, $time, $condition);
        ob_start();
        if (!hocwp_array_has_value($commenters)) {
            echo wpautop($none_text);
        } else {
            ?>
			<ol class="list-commenters">
				<?php 
            foreach ($commenters as $commenter) {
                $url = $commenter->comment_author_url;
                $author = $commenter->comment_author;
                $count = absint($commenter->comments_count);
                $email = $commenter->comment_author_email;
                $user_id = 0;
                if (!empty($commenter->user_id)) {
                    $user_id = $commenter->user_id;
                }
                if ((bool) $show_count) {
                    $author .= " ({$count})";
                }
                if (empty($url) || 'http://' == $url || !(bool) $link_author_name) {
                    $url = $author;
                } else {
                    $url = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>";
                }
                ?>
					<li class="commenter"><?php 
                echo $url;
                ?>
</li>
					<?php 
            }
            ?>
			</ol>
			<?php 
        }
        $widget_html = ob_get_clean();
        $widget_html = apply_filters('hocwp_widget_top_commenter_html', $widget_html, $args, $instance, $this);
        echo $widget_html;
        hocwp_widget_after($args, $instance);
    }
示例#22
0
function hocwp_return_term($taxonomy, $term_id = null, $output = OBJECT)
{
    if ('id' == strtolower($output) && hocwp_id_number_valid($term_id)) {
        return $term_id;
    }
    if (is_a($term_id, 'WP_Term')) {
        $term = $term_id;
    } elseif (hocwp_id_number_valid($term_id)) {
        $term = get_term_by('id', $term_id, $taxonomy);
    } else {
        $term = hocwp_term_get_current();
    }
    if (!is_a($term, 'WP_Term')) {
        return new WP_Error();
    }
    if (OBJECT == strtoupper($output)) {
        return $term;
    }
    return $term->term_id;
}
示例#23
0
function hocwp_query_post_in_same_category($args = array())
{
    $post_id = absint(isset($args['post_id']) ? $args['post_id'] : get_the_ID());
    $query = new WP_Query();
    if (!hocwp_id_number_valid($post_id)) {
        return $query;
    }
    $cache = (bool) hocwp_get_value_by_key($args, 'cache', true);
    $transient_name = 'hocwp_query_post_' . $post_id . '_in_same_category_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $args);
    $query = get_transient($transient_name);
    if (!$cache || false === $query) {
        $taxonomies = get_post_taxonomies($post_id);
        foreach ($taxonomies as $key => $tax_name) {
            $taxonomy = get_taxonomy($tax_name);
            if (!$taxonomy->hierarchical) {
                unset($taxonomies[$key]);
            }
        }
        if (hocwp_array_has_value($taxonomies)) {
            $defaults = array();
            foreach ($taxonomies as $taxonomy) {
                $term_ids = wp_get_post_terms($post_id, $taxonomy, array('fields' => 'ids'));
                if (hocwp_array_has_value($term_ids)) {
                    $tax_item = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_ids);
                    $defaults = hocwp_query_sanitize_tax_query($tax_item, $defaults);
                }
            }
            $args = wp_parse_args($args, $defaults);
            $args['tax_query']['relation'] = 'OR';
            $query = hocwp_query($args);
            if ($cache && $query->have_posts()) {
                set_transient($transient_name, $query, DAY_IN_SECONDS);
            }
        }
    }
    return $query;
}
示例#24
0
function hocwp_execute_lostpassword()
{
    $http_post = 'POST' == $_SERVER['REQUEST_METHOD'];
    $user = null;
    $user_login = '';
    $user_id = '';
    $user_email = '';
    $error = false;
    $message = __('There was an error occurred, please try again.', 'hocwp-theme');
    $redirect = hocwp_get_value_by_key($_REQUEST, 'redirect_to');
    $redirect_to = apply_filters('lostpassword_redirect', $redirect);
    if (is_user_logged_in()) {
        if (empty($redirect_to)) {
            $redirect_to = home_url('/');
        }
        wp_redirect($redirect_to);
        exit;
    }
    $transient = '';
    $captcha = hocwp_get_method_value('captcha');
    if ($http_post) {
        $action = hocwp_get_method_value('action');
        if ('lostpassword' === $action || 'retrievepassword' === $action) {
            $user_login = hocwp_get_method_value('user_login');
            $transient_name = hocwp_build_transient_name('hocwp_lostpassword_user_%s', $user_login);
            if ((isset($_POST['submit']) || isset($_POST['wp-submit'])) && false === ($transient = get_transient($transient_name))) {
                if (empty($user_login)) {
                    $error = true;
                    $message = __('Please enter your account name or email address.', 'hocwp-theme');
                } else {
                    if (isset($_POST['captcha'])) {
                        $capt = new HOCWP_Captcha();
                        if (!$capt->check($captcha)) {
                            $error = true;
                            $message = __('The security code is incorrect.', 'hocwp-theme');
                        }
                    }
                    if (!$error) {
                        $user = hocwp_return_user($user_login);
                        if (!is_a($user, 'WP_User')) {
                            $error = true;
                            $message = __('Username or email is not exists.', 'hocwp-theme');
                        } else {
                            $user_login = $user->user_login;
                            $user_id = $user->ID;
                            $user_email = $user->user_email;
                        }
                    }
                }
                if (!$error && is_a($user, 'WP_User')) {
                    $key = get_password_reset_key($user);
                    if (is_wp_error($key)) {
                        $error = true;
                        $message = __('There was an error occurred, please try again or contact the administrator.', 'hocwp-theme');
                    } else {
                        $message = wpautop(__('Someone has requested a password reset for the following account:', 'hocwp-theme'));
                        $message .= wpautop(network_home_url('/'));
                        $message .= wpautop(sprintf(__('Username: %s', 'hocwp-theme'), $user_login));
                        $message .= wpautop(__('If this was a mistake, just ignore this email and nothing will happen.', 'hocwp-theme'));
                        $message .= wpautop(__('To reset your password, visit the following address:', 'hocwp-theme'));
                        $message .= wpautop(network_site_url("wp-login.php?action=rp&key={$key}&login=" . rawurlencode($user_login), 'login'));
                        if (is_multisite()) {
                            $blogname = $GLOBALS['current_site']->site_name;
                        } else {
                            $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
                        }
                        $title = sprintf(__('[%s] Password Reset'), $blogname);
                        $title = apply_filters('retrieve_password_title', $title, $user_login, $user);
                        $message = apply_filters('retrieve_password_message', $message, $key, $user_login, $user);
                        if (!is_email($user_email)) {
                            $user_email = $user->user_email;
                        }
                        if ($message && !hocwp_send_html_mail($user_email, wp_specialchars_decode($title), $message)) {
                            $error = true;
                            $message = __('The email could not be sent. Possible reason: your host may have disabled the mail() function.', 'hocwp-theme');
                        } else {
                            $error = false;
                            $message = __('Password recovery information has been sent, please check your mailbox.', 'hocwp-theme');
                            set_transient($transient_name, $user_id, 15 * MINUTE_IN_SECONDS);
                        }
                    }
                }
            } else {
                if (hocwp_id_number_valid($transient)) {
                    $error = false;
                    $message = __('Password recovery information has been sent, please check your mailbox.', 'hocwp-theme');
                }
            }
        }
    }
    $result = array('user_id' => $user_id, 'user_email' => $user_email, 'user_login' => $user_login, 'captcha' => $captcha, 'error' => $error, 'message' => $message, 'redirect_to' => $redirect_to, 'transient' => $transient);
    return $result;
}
示例#25
0
function hocwp_get_post_class($post_id = null, $class = '')
{
    if (!hocwp_id_number_valid($post_id)) {
        $post_id = get_the_ID();
    }
    return join(' ', get_post_class($class, $post_id));
}
 public function widget($args, $instance)
 {
     $this->instance = $instance;
     $before_widget = hocwp_get_value_by_key($args, 'before_widget');
     $taxonomy = $this->get_taxonomy_from_instance($instance);
     $taxonomies = array();
     $widget_class = '';
     foreach ($taxonomy as $tax) {
         $tax = hocwp_get_value_by_key($tax, 'value');
         if (!empty($tax)) {
             $taxonomies[] = $tax;
             hocwp_add_string_with_space_before($widget_class, hocwp_sanitize_html_class($tax));
         }
     }
     $before_widget = hocwp_add_class_to_string('', $before_widget, $widget_class);
     $args['before_widget'] = $before_widget;
     $in_current_post = (bool) hocwp_get_value_by_key($instance, 'in_current_post', hocwp_get_value_by_key($this->args, 'in_current_post'));
     if ($in_current_post && (!is_singular() || is_page())) {
         return;
     }
     if ($in_current_post) {
         $post_id = get_the_ID();
         $current_post = get_post($post_id);
         $obj_taxs = get_object_taxonomies($current_post->post_type);
         $has_tax = false;
         foreach ($taxonomies as $tax) {
             foreach ($obj_taxs as $tax_name) {
                 if ($tax == $tax_name) {
                     $has_tax = true;
                     break;
                 }
             }
         }
         if (!$has_tax) {
             return;
         }
         $before_widget = hocwp_add_class_to_string('', $before_widget, 'in-current-post');
         $args['before_widget'] = $before_widget;
     }
     $number = hocwp_get_value_by_key($instance, 'number', hocwp_get_value_by_key($this->args, 'number'));
     if (0 > $number) {
         $number = 0;
     }
     $thumbnail_size = hocwp_get_value_by_key($instance, 'thumbnail_size', hocwp_get_value_by_key($this->args, 'thumbnail_size'));
     $thumbnail_size = hocwp_sanitize_size($thumbnail_size);
     $full_width_item = hocwp_get_value_by_key($instance, 'full_width_item', hocwp_get_value_by_key($this->args, 'full_width_item'));
     $show_count = hocwp_get_value_by_key($instance, 'show_count', hocwp_get_value_by_key($this->args, 'show_count'));
     $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail'));
     $only_thumbnail = hocwp_get_value_by_key($instance, 'only_thumbnail', hocwp_get_value_by_key($this->args, 'only_thumbnail'));
     $order = hocwp_get_value_by_key($instance, 'order', hocwp_get_value_by_key($this->args, 'order'));
     $orderby = hocwp_get_value_by_key($instance, 'orderby', hocwp_get_value_by_key($this->args, 'orderby'));
     $count_format = hocwp_get_value_by_key($instance, 'count_format', hocwp_get_value_by_key($this->args, 'count_format'));
     $different_name = (bool) hocwp_get_value_by_key($instance, 'different_name', hocwp_get_value_by_key($this->args, 'different_name'));
     $hide_empty = hocwp_get_value_by_key($instance, 'hide_empty', hocwp_get_value_by_key($this->args, 'hide_empty'));
     $only_parent = hocwp_get_value_by_key($instance, 'only_parent', hocwp_get_value_by_key($this->args, 'only_parent'));
     $child_of_current = hocwp_get_value_by_key($instance, 'child_of_current', hocwp_get_value_by_key($this->args, 'child_of_current'));
     $child_of_parent = hocwp_get_value_by_key($instance, 'child_of_parent', hocwp_get_value_by_key($this->args, 'child_of_parent'));
     $parent_as_title = hocwp_get_value_by_key($instance, 'parent_as_title', hocwp_get_value_by_key($this->args, 'parent_as_title'));
     if ($hide_thumbnail) {
         $only_thumbnail = false;
     }
     $defaults = array('order' => $order, 'orderby' => $orderby, 'number' => absint($number));
     if (0 == $hide_empty || !(bool) $hide_empty) {
         $defaults['hide_empty'] = 0;
     } else {
         $defaults['hide_empty'] = 1;
     }
     if ($only_parent) {
         $defaults['parent'] = 0;
     }
     if ($in_current_post && is_singular()) {
         $terms = wp_get_post_terms(get_the_ID(), $taxonomies);
     } elseif (($child_of_current || $child_of_parent) && is_tax()) {
         $current_term = hocwp_term_get_current();
         $tax_args = array('child_of' => $current_term->term_id);
         $tax_args = wp_parse_args($tax_args, $defaults);
         unset($tax_args['parent']);
         $terms = hocwp_get_terms($current_term->taxonomy, $tax_args);
         if ($child_of_parent) {
             if (!hocwp_array_has_value($terms) && hocwp_id_number_valid($current_term->parent)) {
                 $parent = hocwp_term_get_top_most_parent($current_term);
                 $tax_args['child_of'] = $parent->term_id;
                 $terms = hocwp_get_terms($parent->taxonomy, $tax_args);
             }
         }
     } else {
         $terms = hocwp_get_terms($taxonomies, $defaults);
     }
     if (($in_current_post || $child_of_current) && !hocwp_array_has_value($terms)) {
         return;
     }
     if ($parent_as_title && is_tax()) {
         $current_term = hocwp_term_get_current();
         if (hocwp_id_number_valid($current_term->parent)) {
             $parent = hocwp_term_get_top_most_parent($current_term);
             $instance['title'] = $parent->name;
         } elseif ($child_of_current) {
             $instance['title'] = $current_term->name;
         }
     }
     hocwp_widget_before($args, $instance);
     ob_start();
     if (hocwp_array_has_value($terms)) {
         $count_terms = count($terms);
         $html = '<ul class="list-unstyled list-terms">';
         $count = 0;
         foreach ($terms as $term) {
             $item_class = 'term-item';
             hocwp_add_string_with_space_before($item_class, hocwp_sanitize_html_class('tax-' . $term->taxonomy));
             if (!(bool) $hide_thumbnail) {
                 hocwp_add_string_with_space_before($item_class, 'show-thumbnail');
             }
             if ((bool) $only_thumbnail) {
                 hocwp_add_string_with_space_before($item_class, 'only-thumbnail');
             }
             $full_width = hocwp_widget_item_full_width_result($full_width_item, $count_terms, $count);
             if ($full_width) {
                 hocwp_add_string_with_space_before($item_class, 'full-width');
             }
             if ((bool) $show_count) {
                 hocwp_add_string_with_space_before($item_class, 'show-count');
             } else {
                 hocwp_add_string_with_space_before($item_class, 'no-count');
             }
             $html .= '<li class="' . $item_class . '">';
             if (!(bool) $hide_thumbnail) {
                 $html .= hocwp_term_get_thumbnail_html(array('term' => $term, 'width' => $thumbnail_size[0], $thumbnail_size[1], 'bfi_thumb' => false));
             }
             if (!(bool) $only_thumbnail) {
                 $term_name = $term->name;
                 if ($different_name) {
                     $term_name = hocwp_term_get_name($term);
                 }
                 $html .= '<a class="term-name" href="' . get_term_link($term) . '">' . $term_name . '</a>';
                 if ((bool) $show_count && !empty($count_format)) {
                     $html .= ' <span class="count">' . str_replace('%TERM_COUNT%', $term->count, $count_format) . '</span>';
                 }
             }
             $html .= '</li>';
             $count++;
         }
         $html .= '</ul>';
         echo $html;
     } else {
         _e('Sorry, nothing found.', 'hocwp-theme');
     }
     $widget_html = ob_get_clean();
     $widget_html = apply_filters('hocwp_widget_term_html', $widget_html, $args, $instance, $this);
     echo $widget_html;
     hocwp_widget_after($args, $instance);
 }