Ejemplo n.º 1
2
function wp_ulike_prize_user($user_id, $user_score, $level)
{
    $user_ids = [$user_id];
    // Проверяем пользователя по чёрному списку
    $mail_ids = apply_filters('wp_ulike_mailing_ids', $user_ids);
    if (!in_array($user_id, $mail_ids)) {
        // Пользователь в чёрном списке?
        return;
    }
    // Оставляем только белый список
    $mail_ids = array_diff($mail_ids, $user_ids);
    $site_url = get_bloginfo('url');
    $site_name = get_bloginfo('name');
    $site_desc = get_bloginfo('description');
    // Если уровень больше 3 используем настройки уровня 3
    $settings = $level < 4 ? "wp_ulike_mailing_level_{$level}" : "wp_ulike_mailing_level_3";
    $user_id = stripslashes($user_id);
    $user_score = stripslashes($user_score);
    $user_info = get_userdata($user_id);
    if ($user_info) {
        $user_profile = bbp_get_user_profile_url($user_id);
        // url профиля пользователя
        $subject = wp_ulike_get_setting($settings, 'top_user_mail_subject');
        $subject = str_replace(['%user_name%', '%user_id%', '%user_profile%', '%user_score%', '%user_level%', '%site_url%', '%site_name%'], [mb_convert_case(rtrim($user_info->first_name), MB_CASE_TITLE, 'UTF-8'), $user_id, $user_profile, $user_score, $level, $site_url, $site_name], $subject);
        $content = wp_ulike_get_setting($settings, 'top_user_mail_template');
        $content = str_replace(['%user_name%', '%user_id%', '%user_profile%', '%user_score%', '%user_level%', '%site_url%', '%site_name%'], [mb_convert_case(rtrim($user_info->first_name), MB_CASE_TITLE, 'UTF-8'), $user_id, $user_profile, $user_score, $level, $site_url, $site_name], $content);
        $buf = ob_start();
        if ($buf) {
            include plugin_dir_path(__FILE__) . 'mail-template.php';
            // Подключаем шаблон
            $mail_body = ob_get_clean();
            if ($mail_body) {
                $from = wp_ulike_get_setting('wp_ulike_general', 'mail_from');
                if (!$from) {
                    $from = '*****@*****.**';
                }
                $headers = ['Content-Type: text/html; charset=UTF-8', 'From: ' . $from];
                // Отправляем уведомление пользователю
                if (wp_mail($user_info->user_email, $subject, $mail_body, $headers)) {
                    wp_ulike_mark_mailing_done($user_id, $level);
                }
                // Отправляем копии по белому списку
                while (list($i, $id) = each($mail_ids)) {
                    $user_info = get_userdata($id);
                    if ($user_info) {
                        wp_mail($user_info->user_email, $subject, $mail_body, $headers);
                    }
                }
            }
        }
    }
}
Ejemplo n.º 2
0
function wp_ulike_enqueue_scripts()
{
    //enqueue JQuery script
    wp_enqueue_script('jquery');
    //Add ulike script file with special functions.
    wp_enqueue_script('wp_ulike', plugins_url('assets/js/wp-ulike-scripts.min.js', dirname(__FILE__)), array('jquery'), '1.2.2');
    //Add ulike plugin file, such as: tooltip, transaction, ...
    wp_enqueue_script('wp_ulike_plugins', plugins_url('assets/js/wp-ulike-plugins.js', dirname(__FILE__)), array('jquery'), '1.0.0', true);
    //localize script
    wp_localize_script('wp_ulike', 'ulike_obj', array('ajaxurl' => admin_url('admin-ajax.php'), 'button_text_u' => wp_ulike_get_setting('wp_ulike_general', 'button_text_u'), 'button_text' => wp_ulike_get_setting('wp_ulike_general', 'button_text'), 'button_type' => wp_ulike_get_setting('wp_ulike_general', 'button_type')));
    //wp_ajax hooks for the custom AJAX requests
    add_action('wp_ajax_wp_ulike_process', 'wp_ulike_process');
    add_action('wp_ajax_nopriv_wp_ulike_process', 'wp_ulike_process');
}
Ejemplo n.º 3
0
/**
 * Convert numbers of Likes with string (kilobyte) format
 *
 * @author       	Alimir
 * @param           Integer $num (get like number)	 
 * @since           1.5
 * @updated         2.0
 * @return          String
 */
function wp_ulike_format_number($num)
{
    $plus = $num != 0 ? '+' : '';
    if ($num >= 1000 && wp_ulike_get_setting('wp_ulike_general', 'format_number') == '1') {
        $value = round($num / 1000, 2) . 'K' . $plus;
    } else {
        $value = $num . $plus;
    }
    $value = apply_filters('wp_ulike_format_number', $value, $num, $plus);
    return $value;
}
Ejemplo n.º 4
0
 /**
  * Get Liked User
  *
  * @author       	Alimir
  * @param           Integer $id
  * @param           String $table
  * @param           String $column_id
  * @param           String $setting_key
  * @since           2.0
  * @updated         2.3
  * @return			String
  */
 public function get_liked_users($id, $table, $column_id, $setting_key)
 {
     $users_list = '';
     $limit_num = wp_ulike_get_setting($setting_key, 'number_of_users');
     if ($limit_num == 0) {
         $limit_num = 10;
     }
     $get_users = $this->wpdb->get_results("SELECT user_id FROM " . $this->wpdb->prefix . "{$table} WHERE {$column_id} = '{$id}' AND status = 'like' AND user_id BETWEEN 1 AND 999999 GROUP BY user_id LIMIT {$limit_num}");
     if (wp_ulike_get_setting($setting_key, 'users_liked_box') == '1' && !$get_users == '') {
         $get_template = wp_ulike_get_setting($setting_key, 'users_liked_box_template');
         if ($get_template == '') {
             $get_template = '<br />';
         }
         $inner_template = $this->get_template_between($get_template, "%START_WHILE%", "%END_WHILE%");
         foreach ($get_users as $get_user) {
             $user_info = get_userdata($get_user->user_id);
             $out_template = $inner_template;
             if ($user_info) {
                 if (strpos($out_template, '%USER_AVATAR%') !== false) {
                     $avatar_size = wp_ulike_get_setting($setting_key, 'users_liked_box_avatar_size');
                     $USER_AVATAR = get_avatar($user_info->user_email, $avatar_size, '', 'avatar');
                     $out_template = str_replace("%USER_AVATAR%", $USER_AVATAR, $out_template);
                 }
                 if (strpos($out_template, '%USER_NAME%') !== false) {
                     $USER_NAME = $user_info->display_name;
                     $out_template = str_replace("%USER_NAME%", $USER_NAME, $out_template);
                 }
                 if (strpos($out_template, '%UM_PROFILE_URL%') !== false && function_exists('um_fetch_user')) {
                     global $ultimatemember;
                     um_fetch_user($user_info->ID);
                     $UM_PROFILE_URL = um_user_profile_url();
                     $out_template = str_replace("%UM_PROFILE_URL%", $UM_PROFILE_URL, $out_template);
                 }
                 if (strpos($out_template, '%BP_PROFILE_URL%') !== false && function_exists('bp_core_get_user_domain')) {
                     $BP_PROFILE_URL = bp_core_get_user_domain($user_info->ID);
                     $out_template = str_replace("%BP_PROFILE_URL%", $BP_PROFILE_URL, $out_template);
                 }
                 $users_list .= $out_template;
             }
         }
         if ($users_list != '') {
             $users_list = $this->put_template_between($get_template, $users_list, "%START_WHILE%", "%END_WHILE%");
         }
     }
     return $users_list;
 }
Ejemplo n.º 5
0
 public function get_top_users($limit = 10)
 {
     $theshold = wp_ulike_get_setting('wp_ulike_mailing_level_1', 'top_users_threshold');
     // Assume level 1 as lowest
     if ($theshold) {
         return $this->get_users_with_score_more_than($theshold, $limit);
     }
     return false;
 }
Ejemplo n.º 6
0
 public function admin_init()
 {
     foreach ($this->settings as $setting => $section) {
         register_setting($this->page, $setting, array($this, 'sanitize_setting'));
         add_settings_section($setting, $section['title'], array($this, 'do_section'), $this->page);
         if (!empty($section['fields'])) {
             $this->empty = false;
             $values = wp_ulike_get_setting($setting);
             foreach ($section['fields'] as $name => $field) {
                 $id = $setting . '_' . $name;
                 $field = array_merge(array('id' => $id, 'name' => $setting . '[' . $name . ']', 'value' => isset($values[$name]) ? $values[$name] : null, 'label_for' => $field['label'] === false ? 'hidden' : $id), $field);
                 add_settings_field($name, $field['label'], array(__CLASS__, 'do_field'), $this->page, $setting, $field);
                 if ($field['type'] === 'action' && is_callable($field['action'])) {
                     add_action("wp_ajax_{$setting}_{$name}", $field['action']);
                 }
             }
         }
     }
     if (isset($_POST["{$this->page}_reset"])) {
         $this->reset();
     }
 }
Ejemplo n.º 7
0
/**
 * wp_ulike_bbpress function for topics like/unlike display
 *
 * @author       	Alimir	 	
 * @since           2.2
 * @updated         2.3
 * @updated         2.4
 * @return			String
 */
function wp_ulike_bbpress($arg)
{
    //global variables
    global $post, $wp_ulike_class, $wp_user_IP;
    //Thanks to @Yehonal for this commit
    $replyID = bbp_get_reply_id();
    $post_ID = !$replyID ? $post->ID : $replyID;
    $get_post_meta = get_post_meta($post_ID, '_topicliked', true);
    $get_like = $get_post_meta != '' ? $get_post_meta : 0;
    $return_userID = $wp_ulike_class->get_reutrn_id();
    $theme_class = wp_ulike_get_setting('wp_ulike_bbpress', 'theme');
    if (wp_ulike_get_setting('wp_ulike_bbpress', 'only_registered_users') != '1' or wp_ulike_get_setting('wp_ulike_bbpress', 'only_registered_users') == '1' && is_user_logged_in()) {
        $data = array("id" => $post_ID, "user_id" => $return_userID, "user_ip" => $wp_user_IP, "get_like" => $get_like, "method" => 'likeThisTopic', "setting" => 'wp_ulike_bbpress', "type" => 'post', "table" => 'ulike_forums', "column" => 'topic_id', "key" => '_topicliked', "cookie" => 'topic-liked-');
        //call wp_get_ulike function from class-ulike calss
        $counter = $wp_ulike_class->wp_get_ulike($data);
        $counter = str_replace('<span class="count-box">0</span>', '<span class="count-box" style="display: none">0</span>', $counter);
        $wp_ulike = '<div id="wp-ulike-' . $post_ID . '" class="wpulike ' . $theme_class . '">';
        $wp_ulike .= '<div class="counter">' . $counter . '</div>';
        $wp_ulike .= '</div>';
        $wp_ulike .= $wp_ulike_class->get_liked_users($post_ID, 'ulike_forums', 'topic_id', 'wp_ulike_bbpress');
        if ($arg == 'put') {
            return $wp_ulike;
        } else {
            echo $wp_ulike;
        }
    } else {
        if (wp_ulike_get_setting('wp_ulike_bbpress', 'only_registered_users') == '1' && !is_user_logged_in()) {
            $login_type = wp_ulike_get_setting('wp_ulike_general', 'login_type');
            if ($login_type == "button") {
                $template = $wp_ulike_class->get_template($post_ID, 'likeThisTopic', $get_like, 1, 0);
                if (wp_ulike_get_setting('wp_ulike_general', 'button_type') == 'image') {
                    return '<div id="wp-ulike-' . $post_ID . '" class="wpulike ' . $theme_class . '"><div class="counter">' . $template['login_img'] . '</div></div>';
                } else {
                    return '<div id="wp-ulike-' . $post_ID . '" class="wpulike ' . $theme_class . '"><div class="counter">' . $template['login_text'] . '</div></div>';
                }
            } else {
                return '<p class="alert alert-info fade in" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>' . __('You need to login in order to like this post: ', WP_ULIKE_SLUG) . '<a href="' . wp_login_url(get_permalink()) . '"> ' . __('click here', WP_ULIKE_SLUG) . ' </a></p>';
            }
        }
    }
    //end only_registered_users condition
}