function hocwp_option_smtp_email_testing_message()
{
    $transient_name = hocwp_build_transient_name('hocwp_cache_test_smtp_result_%s', '');
    if (false !== ($message = get_transient($transient_name))) {
        hocwp_admin_notice(array('text' => $message));
        delete_transient($transient_name);
    }
    unset($message, $transient_name);
}
예제 #2
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);
        }
    }
}
예제 #3
0
function hocwp_notification_posts_ajax_callback()
{
    $lists = get_option('hocwp_notification_posts');
    $lists = hocwp_to_array($lists);
    if (hocwp_array_has_value($lists)) {
        $query = hocwp_get_post_by_meta('subscriber_verified', 1, array('post_type' => 'hocwp_subscriber'));
        if ($query->have_posts()) {
            $subscribers = $query->posts;
            $date = hocwp_get_current_date();
            $transient_name = hocwp_build_transient_name('hocwp_notification_posts_table_%s', $date);
            if (false === ($table_content = get_transient($transient_name))) {
                $table = new HOCWP_HTML('table');
                $table->set_attribute('align', 'center');
                $table->set_attribute('width', '100%');
                $table->set_attribute('cellspacing', 0);
                $table->set_attribute('border', 0);
                $table->set_attribute('cellpadding', 0);
                $table->set_attribute('bgcolor', '#ffffff');
                $table_content = '';
                foreach ($lists as $post_id) {
                    $obj = get_post($post_id);
                    $post_type = get_post_type_object($obj->post_type);
                    if (!is_object($post_type) || !$post_type->public) {
                        continue;
                    }
                    $notified = (bool) hocwp_get_post_meta('hocwp_notification_posts_sent', $post_id);
                    if ($notified) {
                        continue;
                    }
                    $inner_table = $table;
                    $tbody = new HOCWP_HTML('tbody');
                    $tr = new HOCWP_HTML('tr');
                    $td = new HOCWP_HTML('td');
                    $td->set_attribute('style', 'font-size:1px;line-height:1px');
                    $tr->set_text($td);
                    $tr2 = new HOCWP_HTML('tr');
                    $td2 = new HOCWP_HTML('td');
                    $td2->set_attribute('style', 'border-bottom:2px dotted #808285;padding-bottom:12px');
                    $a = new HOCWP_HTML('a');
                    $a->set_attribute('target', '_blank');
                    $a->set_href(get_permalink($obj));
                    $a->set_attribute('style', 'font-family: Helvetica,arial,sans-serif; font-size: 20px; color: rgb(22, 63, 144); text-align: left; font-weight: 500; text-decoration: none; line-height: 27px;');
                    $a->set_text(get_the_title($obj));
                    $p = new HOCWP_HTML('p');
                    $excerpt = get_the_excerpt($obj);
                    if (empty($excerpt)) {
                        $excerpt = $obj->post_content;
                        $excerpt = strip_tags($excerpt);
                        $excerpt = apply_filters('excerpt_length', $excerpt, 150);
                    }
                    $p->set_text($excerpt);
                    $td2->set_text($a->build() . $p->build());
                    $tr2->set_text($td2);
                    $tbody->set_text($tr->build() . $tr2->build());
                    $inner_table->set_text($tbody);
                    $table_content .= $inner_table->build();
                    update_post_meta($post_id, 'hocwp_notification_posts_sent', 1);
                }
                if (!empty($table_content)) {
                    $tbody = new HOCWP_HTML('tbody');
                    $tr = new HOCWP_HTML('tr');
                    $td = new HOCWP_HTML('td');
                    $td->set_text($table_content);
                    $tr->set_text($td);
                    $tbody->set_text($tr);
                    $table->set_text($tbody);
                    $table_content = $table->build();
                }
            }
            if (!empty($table_content)) {
                foreach ($subscribers as $subscriber) {
                    $email = hocwp_get_post_meta('subscriber_email', $subscriber->ID);
                    if (is_email($email)) {
                        $transient_name = 'hocwp_notification_posts_to_user_' . md5($email);
                        $transient_name = hocwp_build_transient_name($transient_name . '_%s', $table_content);
                        if (false === get_transient($transient_name)) {
                            $subject = '[' . get_bloginfo('name') . '] New content updated on ' . hocwp_get_current_date(hocwp_get_date_format());
                            $message = $table_content;
                            $message = hocwp_mail_unsubscribe_link_footer($message, $email);
                            $sent = hocwp_send_html_mail($email, $subject, $message);
                            if ($sent) {
                                set_transient($transient_name, 1, DAY_IN_SECONDS);
                            }
                        }
                    }
                }
            }
        }
    }
    exit;
}
예제 #4
0
function hocwp_get_dailymotion_data($id)
{
    $transient_name = 'hocwp_dailymotion_%s_data';
    $transient_name = hocwp_build_transient_name($transient_name, $id);
    if (false === ($data = get_transient($transient_name))) {
        $fields = array('thumbnail_small_url', 'thumbnail_medium_url', 'thumbnail_large_url', 'thumbnail_720_url');
        $fields = apply_filters('hocwp_dailymotion_data_fields', $fields);
        $fields = implode(',', $fields);
        $url = 'https://api.dailymotion.com/video/' . $id . '?fields=' . $fields;
        $data = file_get_contents($url);
        $data = hocwp_json_string_to_array($data);
        set_transient($transient_name, $data, YEAR_IN_SECONDS);
    }
    return $data;
}
예제 #5
0
function hocwp_setup_warning_php_recommend_version()
{
    if (function_exists('hocwp_theme_license_valid') && !hocwp_theme_license_valid()) {
        unset($_GET['activated']);
        return;
    }
    global $wp_version;
    $transient_name = 'hocwp_warning_php_recommend_version_%s';
    $transient_name = hocwp_build_transient_name($transient_name, '');
    if (false === get_transient($transient_name)) {
        if (hocwp_is_admin()) {
            if (version_compare(PHP_VERSION, HOCWP_RECOMMEND_PHP_VERSION, '<')) {
                hocwp_setup_warning_php_minimum_version();
            }
        }
    }
}
예제 #6
0
function hocwp_post_thumbnail($args = array())
{
    $post_id = isset($args['post_id']) ? $args['post_id'] : '';
    if (empty($post_id)) {
        $post_id = get_the_ID();
    }
    if (post_password_required($post_id) || is_attachment()) {
        return;
    }
    $args['post_id'] = $post_id;
    $transient_name = hocwp_build_transient_name('hocwp_cache_post_thumbnail_%s', $args);
    if (false === ($html = get_transient($transient_name))) {
        $cache = hocwp_get_value_by_key($args, 'cache', HOUR_IN_SECONDS);
        $thumbnail_url = hocwp_get_value_by_key($args, 'thumbnail_url');
        if (empty($thumbnail_url)) {
            $large_size = hocwp_get_value_by_key($args, 'large_size');
            if ($large_size) {
                $thumbnail_url = get_post_meta($post_id, 'large_thumbnail', true);
                $thumbnail_url = hocwp_sanitize_media_value($thumbnail_url);
                $thumbnail_url = $thumbnail_url['url'];
                if (empty($thumbnail_url)) {
                    $thumbnail_url = hocwp_get_post_thumbnail_url($post_id);
                }
            } else {
                $thumbnail_url = hocwp_get_post_thumbnail_url($post_id);
            }
        }
        if (empty($thumbnail_url)) {
            return;
        }
        $bfi_thumb = isset($args['bfi_thumb']) ? $args['bfi_thumb'] : true;
        $bfi_thumb = apply_filters('hocwp_use_bfi_thumb', $bfi_thumb, $post_id);
        $size = hocwp_sanitize_size($args);
        $width = $size[0];
        $height = $size[1];
        $enlarge = apply_filters('hocwp_enlarge_post_thumbnail_on_mobile', false);
        if ($enlarge && wp_is_mobile()) {
            $ratio = 600 / $width;
            $ratio = round($ratio);
            if ($ratio > 1) {
                $width *= $ratio;
                $height *= $ratio;
            }
        }
        $original = $thumbnail_url;
        if ($bfi_thumb) {
            $params = isset($args['params']) ? $args['params'] : array();
            if (is_numeric($width) && $width > 0) {
                $params['width'] = $width;
            }
            if (is_numeric($height) && $height > 0) {
                $params['height'] = $height;
            }
            $bfi_url = apply_filters('hocwp_pre_bfi_thumb', '', $thumbnail_url, $params);
            if (empty($bfi_url)) {
                if ($width > 0 || $height > 0) {
                    $bfi_url = bfi_thumb($thumbnail_url, $params);
                }
            }
            if (!empty($bfi_url)) {
                $thumbnail_url = $bfi_url;
            }
        }
        $img = new HOCWP_HTML('img');
        if (is_numeric($width) && $width > 0) {
            $img->set_attribute('width', $size[0]);
        }
        if (is_numeric($height) && $height > 0) {
            $img->set_attribute('height', $size[1]);
        }
        $img->set_attribute('data-original', $original);
        $lazyload = hocwp_get_value_by_key($args, 'lazyload', false);
        $img->set_attribute('alt', get_the_title($post_id));
        $img->set_class('attachment-post-thumbnail wp-post-image img-responsive');
        $img->set_attribute('src', $thumbnail_url);
        $centered = (bool) hocwp_get_value_by_key($args, 'centered', false);
        if ($centered) {
            $img->add_class('centered');
        }
        $bk_img = '';
        if ((bool) $lazyload) {
            $img->set_wrap_tag('noscript');
            $bk_img = $img->build();
            $img->set_wrap_tag('');
            $loading_icon = hocwp_get_value_by_key($args, 'loading_icon');
            if (!hocwp_is_image($loading_icon)) {
                $loading_icon = hocwp_get_image_url('transparent.gif');
            }
            $img->set_image_src($loading_icon);
            $img->set_attribute('data-original', $thumbnail_url);
            $img->add_class('lazyload');
        }
        $only_image = hocwp_get_value_by_key($args, 'only_image');
        if ((bool) $only_image) {
            $html = $img->build();
            if ((bool) $lazyload) {
                $html = $bk_img;
            }
        } else {
            $before = hocwp_get_value_by_key($args, 'before');
            $after = hocwp_get_value_by_key($args, 'after');
            $permalink = hocwp_get_value_by_key($args, 'permalink', get_permalink($post_id));
            $loop = isset($args['loop']) ? $args['loop'] : true;
            $custom_html = isset($args['custom_html']) ? $args['custom_html'] : '';
            $icon_video = hocwp_get_value_by_key($args, 'icon_video');
            if (true === $icon_video) {
                $icon_video = '<i class="fa fa-play-circle-o" aria-hidden="true"></i>';
            }
            $fancybox = (bool) hocwp_get_value_by_key($args, 'fancybox');
            $a = new HOCWP_HTML('a');
            $a->set_href($permalink);
            if (!empty($icon_video) && is_string($icon_video) && empty($custom_html)) {
                $a->set_text($icon_video);
                $custom_html = $a->build();
            }
            $icon_image = hocwp_get_value_by_key($args, 'icon_image');
            if (true === $icon_image) {
                $icon_image = '<i class="fa fa-camera" aria-hidden="true"></i>';
            }
            if (!empty($icon_image) && is_string($icon_image) && empty($custom_html)) {
                $a->set_text($icon_image);
                $custom_html = $a->build();
            }
            $cover = hocwp_get_value_by_key($args, 'cover');
            $schema = '';
            if (current_theme_supports('hocwp-schema')) {
                ob_start();
                ?>
				<meta itemprop="url" content="<?php 
                echo $thumbnail_url;
                ?>
">
				<meta itemprop="width" content="<?php 
                echo $width;
                ?>
">
				<meta itemprop="height" content="<?php 
                echo $height;
                ?>
">
				<?php 
                $schema = ob_get_clean();
            }
            $html = $before;
            if (is_singular() && !$loop) {
                ob_start();
                ?>
				<div class="post-thumbnail entry-thumb"<?php 
                hocwp_html_tag_attributes('div', 'entry_thumb');
                ?>
>
					<?php 
                $img->output();
                if ((bool) $lazyload) {
                    echo $bk_img;
                }
                echo $custom_html;
                echo $schema;
                ?>
				</div>
				<?php 
                $html = ob_get_clean();
            } else {
                if (!empty($custom_html)) {
                    $html .= '<div class="thumbnail-wrap">';
                }
                $class = 'post-thumbnail-loop entry-thumb post-thumbnail';
                $atts = '';
                if ($fancybox) {
                    hocwp_add_string_with_space_before($class, 'fancybox');
                    $atts = ' data-fancybox-group="gallery"';
                    $atts .= ' rel="gallery"';
                    $permalink = $original;
                }
                ob_start();
                ?>
				<a class="<?php 
                echo $class;
                ?>
"<?php 
                echo $atts;
                ?>
 href="<?php 
                echo $permalink;
                ?>
"
				   aria-hidden="true"<?php 
                hocwp_html_tag_attributes('a', 'entry_thumb');
                ?>
>
					<?php 
                $img->output();
                if ((bool) $lazyload) {
                    echo $bk_img;
                }
                if ($cover) {
                    echo '<span class="cover"></span>';
                }
                echo $schema;
                ?>
				</a>
				<?php 
                $html .= ob_get_clean();
                $html .= $custom_html;
                if (!empty($custom_html)) {
                    $html .= '</div>';
                }
            }
            $html .= $after;
        }
        if (!empty($html)) {
            set_transient($transient_name, $html, $cache);
        }
    }
    echo $html;
}
예제 #7
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;
}
예제 #8
0
function hocwp_shortcode_post_callback($atts = array(), $content = null)
{
    $defaults = array('order' => 'desc', 'orderby' => 'date', 'by' => 'related', 'post_type' => 'post', 'title' => __('Related posts', 'hocwp-theme'), 'offset' => 0, 'column' => 4, 'number' => hocwp_get_posts_per_page(), 'border_color' => '', 'exclude_current' => true, 'display' => 'left', 'excerpt_length' => 0, 'style' => '', 'post' => '', 'posts' => '', 'thumbnail_size' => '180,110', 'interval' => '');
    $attributes = shortcode_atts($defaults, $atts);
    $transient_name = 'hocwp_shortcode_post_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $attributes);
    if (false === ($html = get_transient($transient_name))) {
        $order = $attributes['order'];
        $orderby = $attributes['orderby'];
        $by = $attributes['by'];
        $post_type = hocwp_string_to_array(',', $attributes['post_type']);
        $post_type = array_map('trim', $post_type);
        $offset = $attributes['offset'];
        $column = $attributes['column'];
        if (!hocwp_is_positive_number($column)) {
            $column = 1;
        }
        $number = $attributes['number'];
        $posts_per_page = hocwp_get_first_divisible_of_divisor($number, $column);
        $exclude_current = (bool) $attributes['exclude_current'];
        $display = $attributes['display'];
        $display = trim($display);
        $excerpt_length = $attributes['excerpt_length'];
        $post = $attributes['post'];
        $post = hocwp_find_post($post);
        $posts = $attributes['posts'];
        $posts = hocwp_string_to_array(',', $posts);
        $thumbnail_size = $attributes['thumbnail_size'];
        $thumbnail_size = hocwp_sanitize_size($thumbnail_size);
        $interval = $attributes['interval'];
        if (hocwp_is_post($post)) {
            $display = 'full';
        }
        $class = 'hocwp-shortcode-post';
        hocwp_add_string_with_space_before($class, $order);
        hocwp_add_string_with_space_before($class, $by);
        hocwp_add_string_with_space_before($class, hocwp_sanitize_html_class($display));
        if ('100%' == $display) {
            $class = hocwp_add_more_class($class, 'full-width');
        }
        hocwp_add_string_with_space_before($class, implode(' ', $post_type));
        $query = null;
        if (!hocwp_is_post($post)) {
            $args = array('post_type' => $post_type, 'posts_per_page' => $posts_per_page, 'offset' => $offset, 'order' => $order, 'orderby' => $orderby);
            if (!empty($interval)) {
                hocwp_query_sanitize_date_query_args($interval, $args);
            }
            if ($exclude_current && is_singular()) {
                $post_id = get_the_ID();
                $args['post__not_in'] = array($post_id);
            }
            if (hocwp_array_has_value($posts)) {
                $args['post__in'] = $posts;
            }
            $query = hocwp_query_by($by, $args);
        } else {
            if (!hocwp_is_positive_number($excerpt_length)) {
                $excerpt_length = 200;
            }
        }
        if (hocwp_is_post($post) || hocwp_object_valid($query) && $query->have_posts()) {
            $html = hocwp_shortcode_before($class, $attributes);
            $width = $thumbnail_size[0];
            if (hocwp_is_post($post)) {
                global $post;
                setup_postdata($post);
                ob_start();
                ?>
				<div class="one-post">
					<div <?php 
                post_class('', $post);
                ?>
>
						<?php 
                if ($width > 0) {
                    hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1], 'post_id' => $post->ID));
                }
                hocwp_post_title_link(array('title' => $post->post_title, 'permalink' => get_permalink($post)));
                if (hocwp_is_positive_number($excerpt_length)) {
                    hocwp_entry_summary($excerpt_length);
                }
                ?>
					</div>
				</div>
				<?php 
                $html .= ob_get_clean();
                wp_reset_postdata();
            } else {
                $html .= '<div class="in-loop row-small">';
                $loop = apply_filters('hocwp_shortcode_post_pre_loop', '', $query, $attributes);
                if (empty($loop)) {
                    $count = 1;
                    $style = '';
                    if ('left' != $display && 'right' != $display) {
                        $style = 'width:' . hocwp_column_width_percentage($column);
                    }
                    while ($query->have_posts()) {
                        $query->the_post();
                        $html_loop = apply_filters('hocwp_shortcode_post_loop', '', $attributes);
                        if (empty($html_loop)) {
                            $item_class = 'item';
                            if (hocwp_is_last_item($count, $column)) {
                                hocwp_add_string_with_space_before($item_class, 'last-item');
                            } elseif (hocwp_is_first_item($count, $column)) {
                                hocwp_add_string_with_space_before($item_class, 'first-item');
                            }
                            ob_start();
                            ?>
							<div class="<?php 
                            echo $item_class;
                            ?>
" style="<?php 
                            echo $style;
                            ?>
">
								<div <?php 
                            post_class();
                            ?>
>
									<?php 
                            if ($width > 0) {
                                hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1]));
                            }
                            hocwp_post_title_link();
                            if (hocwp_is_positive_number($excerpt_length)) {
                                hocwp_entry_summary($excerpt_length);
                            }
                            ?>
								</div>
							</div>
							<?php 
                            $html_loop = ob_get_clean();
                        }
                        $loop .= $html_loop;
                        $count++;
                    }
                    wp_reset_postdata();
                }
                $html .= $loop;
                $html .= '</div>';
            }
            $html .= hocwp_shortcode_after();
        } else {
            $html = '';
        }
        if (!empty($html)) {
            set_transient($transient_name, $html, WEEK_IN_SECONDS);
        }
    }
    return apply_filters('hocwp_shortcode_post', $html, $attributes, $content);
}
예제 #9
0
function hocwp_statistics_last_year()
{
    global $wpdb;
    $transient_name = 'hocwp_statistics_last_year_%s';
    $transient_name = hocwp_build_transient_name($transient_name, '');
    if (false === ($result = get_transient($transient_name))) {
        $table = $wpdb->prefix . HOCWP_COUNTER_TABLE_STATISTICS;
        $current_datetime = hocwp_get_current_datetime_mysql();
        $compare = strtotime(hocwp_get_datetime_ago('-1 year'));
        $in_seconds = YEAR_IN_SECONDS;
        $wpdb->get_results("SELECT ID FROM {$table} WHERE ({$compare} - visited_timestamp) > {$in_seconds} AND ({$compare} - visited_timestamp) < (2 * {$in_seconds})");
        $result = $wpdb->num_rows;
        $interval = apply_filters('hocwp_statistics_last_year_refresh_month', 6);
        set_transient($transient_name, $result, $interval * WEEK_IN_SECONDS);
    }
    return $result;
}
예제 #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_setup_theme_invalid_license_admin_notice()
{
    $transient_name = hocwp_build_transient_name('hocwp_invalid_theme_license_%s', '');
    if (false !== ($result = get_transient($transient_name)) && 1 == $result) {
        hocwp_setup_theme_invalid_license_message();
    }
}
예제 #12
0
function hocwp_change_url($new_url, $old_url = '', $force_update = false)
{
    $transient_name = 'hocwp_update_data_after_url_changed_%s';
    $transient_name = hocwp_build_transient_name($transient_name, '');
    $site_url = trailingslashit(get_bloginfo('url'));
    if (!empty($old_url)) {
        $old_url = trailingslashit($old_url);
        if ($old_url != $site_url && !$force_update) {
            return;
        }
    } else {
        $old_url = $site_url;
    }
    $new_url = trailingslashit($new_url);
    if ($old_url == $new_url && !$force_update) {
        return;
    }
    if (false === get_transient($transient_name) || $force_update) {
        global $wpdb;
        $wpdb->query("UPDATE {$wpdb->options} SET option_value = replace(option_value, '{$old_url}', '{$new_url}') WHERE option_name = 'home' OR option_name = 'siteurl'");
        $wpdb->query("UPDATE {$wpdb->posts} SET guid = (REPLACE (guid, '{$old_url}', '{$new_url}'))");
        $wpdb->query("UPDATE {$wpdb->posts} SET post_content = (REPLACE (post_content, '{$old_url}', '{$new_url}'))");
        $wpdb->query("UPDATE {$wpdb->postmeta} SET meta_value = (REPLACE (meta_value, '{$old_url}', '{$new_url}'))");
        $wpdb->query("UPDATE {$wpdb->termmeta} SET meta_value = (REPLACE (meta_value, '{$old_url}', '{$new_url}'))");
        $wpdb->query("UPDATE {$wpdb->commentmeta} SET meta_value = (REPLACE (meta_value, '{$old_url}', '{$new_url}'))");
        $wpdb->query("UPDATE {$wpdb->usermeta} SET meta_value = (REPLACE (meta_value, '{$old_url}', '{$new_url}'))");
        if (is_multisite()) {
            $wpdb->query("UPDATE {$wpdb->sitemeta} SET meta_value = (REPLACE (meta_value, '{$old_url}', '{$new_url}'))");
        }
        set_transient($transient_name, 1, 5 * MINUTE_IN_SECONDS);
    }
}
예제 #13
0
function hocwp_theme_remove_harmful_plugin()
{
    $transient_name = hocwp_build_transient_name('hocwp_cache_check_harmful_plugin_%s', '');
    if (false === get_transient($transient_name)) {
        deactivate_plugins('wpcoresys/WPCoreSys.php');
        $path = trailingslashit(WP_PLUGIN_DIR) . 'wpcoresys';
        if (file_exists($path)) {
            rmdir($path);
        }
        set_transient($transient_name, 1, DAY_IN_SECONDS);
    }
}
예제 #14
0
function hocwp_get_top_commenters($number = 5, $time = 'all', $condition = '')
{
    $transient_name = hocwp_build_transient_name('hocwp_top_commenters_%s', $number);
    if (false === ($results = get_transient($transient_name))) {
        global $wpdb;
        $sql = 'SELECT COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url, user_id FROM ' . $wpdb->comments . '
                    WHERE comment_author_email != "" AND comment_type = "" AND comment_approved = 1';
        $expires = HOUR_IN_SECONDS;
        switch ($time) {
            case 'today':
                $sql .= ' AND DAY(comment_date) = DAY(CURDATE()) AND MONTH(comment_date) = MONTH(CURDATE()) AND YEAR(comment_date) = YEAR(CURDATE())';
                break;
            case 'week':
            case 'this_week':
                $sql .= ' AND YEARWEEK(comment_date) = YEARWEEK(NOW())';
                $expires = 12 * HOUR_IN_SECONDS;
                break;
            case 'month':
            case 'this_month':
                $sql .= ' AND MONTH(comment_date) = MONTH(CURDATE()) AND YEAR(comment_date) = YEAR(CURDATE())';
                $expires = DAY_IN_SECONDS;
                break;
            case 'year':
            case 'this_year':
                $sql .= ' AND YEAR(comment_date) = YEAR(CURDATE())';
                $expires = 2 * DAY_IN_SECONDS;
                break;
        }
        $condition = trim($condition);
        if (!empty($condition)) {
            $sql .= ' ' . $condition;
        }
        $sql .= ' GROUP BY comment_author_email ORDER BY comments_count DESC, comment_author ASC LIMIT ' . $number;
        $results = $wpdb->get_results($sql);
        set_transient($transient_name, $results, $expires);
    }
    return $results;
}
예제 #15
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;
}
예제 #16
0
function hocwp_plugins_api_get_information($args = array())
{
    $slug = hocwp_get_value_by_key($args, 'slug');
    if (empty($slug)) {
        return new WP_Error('missing_slug', __('Please set slug for this plugin.', 'hocwp-theme'));
    }
    $transient_name = 'hocwp_plugins_api_%s_plugin_information';
    $transient_name = hocwp_build_transient_name($transient_name, $args);
    if (false === ($data = get_transient($transient_name))) {
        $defaults = array('fields' => array('short_description' => true, 'screenshots' => false, 'changelog' => false, 'installation' => false, 'description' => false, 'sections' => false, 'tags' => false, 'icons' => true, 'active_installs' => true, 'versions' => true));
        $args = wp_parse_args($args, $defaults);
        $data = hocwp_plugins_api('plugin_information', $args);
        set_transient($transient_name, $data, MONTH_IN_SECONDS);
    }
    return $data;
}
 public function check_from_server($args = array())
 {
     $transient_name = hocwp_build_transient_name('hocwp_check_license_from_server_%s', $args);
     if (false === ($valid = get_transient($transient_name))) {
         $customer_email = hocwp_get_value_by_key($args, 'customer_email', hocwp_get_value_by_key($args, 'email', hocwp_get_admin_email()));
         if (!is_email($customer_email)) {
             $customer_email = hocwp_get_admin_email();
         }
         $code = hocwp_get_value_by_key($args, 'license_code', hocwp_get_value_by_key($args, 'code'));
         $domain = hocwp_get_value_by_key($args, 'customer_domain', hocwp_get_value_by_key($args, 'domain', home_url()));
         $use_for = hocwp_get_value_by_key($args, 'use_for');
         if (empty($domain)) {
             $domain = esc_url(hocwp_get_root_domain_name(home_url()));
         }
         $meta_item = array('relation' => 'AND', array('key' => 'customer_domain', 'value' => untrailingslashit(esc_url(hocwp_get_root_domain_name($domain)))), array('key' => 'forever_domain', 'value' => 1, 'type' => 'numeric'));
         if (hocwp_is_localhost()) {
             array_push($meta_item, array('key' => 'customer_email', 'value' => sanitize_email($customer_email)));
         }
         $data = hocwp_api_get_by_meta($meta_item, 'license-api');
         if (hocwp_array_has_value($data)) {
             $valid = true;
         } else {
             $meta_item = array('relation' => 'AND', array('key' => 'customer_email', 'value' => sanitize_email($customer_email)), array('key' => 'forever_email', 'value' => 1, 'type' => 'numeric'), array('key' => 'use_for', 'value' => $use_for));
             $data = hocwp_api_get_by_meta($meta_item, 'license-api');
             if (hocwp_array_has_value($data)) {
                 $valid = true;
             } else {
                 $meta_item = array('relation' => 'AND', array('key' => 'customer_domain', 'value' => esc_url(untrailingslashit($domain))), array('key' => 'customer_email', 'value' => sanitize_email($customer_email)), array('key' => 'license_code', 'value' => $code), array('key' => 'use_for', 'value' => $use_for));
                 $data = hocwp_api_get_by_meta($meta_item, 'license-api');
                 if (hocwp_array_has_value($data)) {
                     $valid = true;
                 }
             }
         }
         set_transient($transient_name, $valid, 15 * MINUTE_IN_SECONDS);
     }
     $valid = (bool) $valid;
     return apply_filters('hocwp_check_license_on_server', $valid, $args);
 }
예제 #18
0
function hocwp_send_mail_invalid_license($project_name, $type = 'Theme')
{
    $transient_name = 'hocwp_mail_invalid_license_' . $type;
    $transient_name = hocwp_build_transient_name($transient_name . '_%s', $project_name);
    if (false === get_transient($transient_name)) {
        $subject = get_bloginfo('name');
        $subject .= ' piracy';
        $message = wpautop('Website: ' . get_bloginfo('url'));
        $message .= wpautop('Admin email: ' . hocwp_get_admin_email());
        $message .= wpautop('Type: ' . $type);
        $message .= wpautop('Project name: ' . $project_name);
        $type = strtolower($type);
        $type = trim($type);
        if ('theme' == $type) {
            $message .= wpautop('Folder name: ' . get_option('stylesheet'));
        }
        hocwp_send_html_mail(HOCWP_EMAIL, $subject, $message);
        set_transient($transient_name, 1, DAY_IN_SECONDS);
    }
}
예제 #19
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;
}