Example #1
0
function hocwp_show_ads($args = array())
{
    $ads = $args;
    $position = '';
    if (!is_object($args)) {
        if (!is_array($args)) {
            $args = array('position' => $args);
        }
        $position = hocwp_get_value_by_key($args, 'position');
        if (!empty($position)) {
            $random = (bool) hocwp_get_value_by_key($args, 'random');
            $current_datetime = date(hocwp_get_date_format());
            $current_datetime = strtotime($current_datetime);
            $query_args = array('post_type' => 'hocwp_ads', 'posts_per_page' => 1, 'meta_query' => array('relation' => 'AND', array('relation' => 'OR', array('key' => 'expire', 'compare' => 'NOT EXISTS'), array('key' => 'expire', 'value' => '', 'compare' => '='), array('key' => 'expire', 'value' => 0, 'type' => 'numeric'), array('key' => 'expire', 'value' => $current_datetime, 'type' => 'numeric', 'compare' => '>=')), array('key' => 'active', 'value' => 1, 'type' => 'numeric')));
            if ($random) {
                $query_args['orderby'] = 'rand';
            }
            $ads = hocwp_get_post_by_meta('position', $position, $query_args);
            if ($ads->have_posts()) {
                $posts = $ads->posts;
                $ads = array_shift($posts);
            }
        }
    }
    if (hocwp_is_post($ads) && 'hocwp_ads' == $ads->post_type) {
        $code = hocwp_get_post_meta('code', $ads->ID);
        if (empty($code)) {
            $image = hocwp_get_post_meta('image', $ads->ID);
            $image = hocwp_sanitize_media_value($image);
            $image = $image['url'];
            if (!empty($image)) {
                $img = new HOCWP_HTML('img');
                $img->set_image_src($image);
                $url = hocwp_get_post_meta('url', $ads->ID);
                if (!empty($url)) {
                    $a = new HOCWP_HTML('a');
                    $a->set_href($url);
                    $a->set_text($img);
                    $code = $a->build();
                } else {
                    $code = $img->build();
                }
            }
        }
        if (!empty($code)) {
            $class = hocwp_get_value_by_key($args, 'class');
            hocwp_add_string_with_space_before($class, 'hocwp-ads text-center ads');
            if (!empty($position)) {
                hocwp_add_string_with_space_before($class, 'position-' . $position);
                $position = hocwp_sanitize_html_class($position);
                $class = hocwp_add_more_class($class, $position);
            }
            hocwp_add_string_with_space_before($class, $ads->post_name);
            $div = new HOCWP_HTML('div');
            $div->set_class($class);
            $div->set_text($code);
            $html = $div->build();
            $html = apply_filters('hocwp_ads_html', $html, $ads_or_args = $args);
            echo $html;
        }
    }
}
function hocwp_theme_post_column_content_subscriber($column, $post_id)
{
    global $post_type;
    $post = get_post($post_id);
    if ('hocwp_subscriber' == $post_type) {
        if ('subscriber_date' == $column) {
            echo date(hocwp_get_date_format(), strtotime($post->post_date));
        } else {
            if ('active' != $column) {
                echo hocwp_get_post_meta($column, $post_id);
            }
        }
    }
}
Example #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;
}
Example #4
0
function hocwp_field_datetime_picker($args = array())
{
    hocwp_sanitize_field_args($args);
    $class = hocwp_get_value_by_key($args, 'class');
    hocwp_add_string_with_space_before($class, 'hocwp-datetime-picker');
    $min_date = hocwp_get_value_by_key($args, 'min_date');
    $max_date = hocwp_get_value_by_key($args, 'max_date');
    $date_format = hocwp_get_value_by_key($args, 'date_format', hocwp_get_date_format());
    $value = hocwp_get_value_by_key($args, 'value');
    $args['class'] = $class;
    $atts = hocwp_get_value_by_key($args, 'attributes');
    $atts['autocomplete'] = 'off';
    $atts['data-min-date'] = $min_date;
    $atts['data-max-date'] = $max_date;
    $atts['data-date-format'] = hocwp_convert_datetime_format_to_jquery($date_format);
    $args['attributes'] = $atts;
    $args['type'] = 'text';
    if (is_numeric($value) && $value > 0) {
        $value = date($date_format, $value);
    }
    if (is_numeric($value) && 0 == $value) {
        $value = '';
    }
    $args['value'] = $value;
    hocwp_field_input($args);
}