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; }
function hocwp_generate_unsubscribe_link($email, $text = '') { if (!is_email($email)) { return ''; } $query = hocwp_get_post_by_meta('subscriber_email', $email, array('post_type' => 'hocwp_subscriber')); $key = ''; $post = null; if ($query->have_posts()) { $post = array_shift($query->posts); $key = hocwp_get_post_meta('subscriber_deactivate_key', $post->ID); } if (empty($key)) { $key = hocwp_generate_reset_key(); if (is_a($post, 'WP_Post')) { update_post_meta($post->ID, 'subscriber_deactivate_key', $key); } } $url = home_url('/'); $url = add_query_arg(array('key' => $key, 'action' => 'unsubscribe', 'email' => $email), $url); $a = new HOCWP_HTML('a'); $a->set_href($url); if (empty($text)) { $text = $url; } $a->set_text($text); $a->set_attribute('target', '_blank'); return $a->build(); }
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_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); }
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; }
function hocwp_setup_theme_delete_subscriber_user($user_id) { $query = hocwp_get_post_by_meta('subscriber_user', $user_id); if ($query->have_posts()) { foreach ($query->posts as $subscriber) { update_post_meta($subscriber->ID, 'subscriber_user', ''); } } }
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); } }