/**
  * Display the reaction area at the end of post's content
  *
  * @param string $content
  * @return string Filtered content
  */
 public function display($content = '')
 {
     if (!Emoji_Reactions_Utils::can_react_to_post(get_the_ID())) {
         return $content;
     }
     $filtered_content = apply_filters('emoji_reactions_reaction_area', $content);
     $empty_flair = $this->before_display('') . $this->after_display('');
     if ($content . $empty_flair == $filtered_content) {
         return $content;
     } else {
         return $filtered_content;
     }
 }
 /**
  * Loads assets for the emoji picker
  */
 public function load_assets()
 {
     wp_enqueue_style('emoji-reactions-display-reactions-css', plugins_url('assets/css/display-reactions.css', dirname(__FILE__)));
     wp_enqueue_script('emoji-reactions-display-reactions-js', plugins_url('assets/js/display-reactions.js', dirname(__FILE__)), array('jquery'));
     // data for displaying the reactions area
     wp_localize_script('emoji-reactions-display-reactions-js', 'emojiData', array('pluginURL' => plugins_url('', dirname(__FILE__)), 'custom' => Emoji_Reactions_Utils::get_custom_emoji()));
 }
Пример #3
0
 /**
  * Loads assets for the emoji picker
  */
 public function load_assets()
 {
     wp_enqueue_style('emoji-reactions-emoji-picker-css', plugins_url('assets/css/emoji-picker.css', dirname(__FILE__)));
     wp_enqueue_script('emoji-reactions-emoji-picker-js', plugins_url('assets/js/emoji-picker.js', dirname(__FILE__)), array('jquery'));
     // data for displaying the reactions area
     wp_localize_script('emoji-reactions-emoji-picker-js', 'emojiPickerData', array('pluginURL' => plugins_url('', dirname(__FILE__)), 'custom' => Emoji_Reactions_Utils::get_custom_emoji()));
     // i18n strings
     wp_localize_script('emoji-reactions-emoji-picker-js', 'emojiPickerStrings', array('people' => esc_html__('People', 'emoji-reactions'), 'nature' => esc_html__('Nature', 'emoji-reactions'), 'foods' => esc_html__('Food & Drink', 'emoji-reactions'), 'celebration' => esc_html__('Celebration', 'emoji-reactions'), 'activity' => esc_html__('Activity', 'emoji-reactions'), 'places' => esc_html__('Travel & Places', 'emoji-reactions'), 'symbols' => esc_html__('Objects & Symbols', 'emoji-reactions'), 'custom' => esc_html__('Custom', 'emoji-reactions')));
 }
Пример #4
0
 /**
  * Returns true if the provided $emoji shorthand is a valid emoji or false if not
  * Checks against both custom emoji and standard emoji
  * @param  string  $emoji
  * @return boolean
  */
 public static function is_valid_emoji($emoji)
 {
     if ("custom_" === substr($emoji, 0, 7)) {
         $emoji = substr($emoji, 7);
     }
     $custom_emoji = Emoji_Reactions_Utils::get_custom_emoji();
     if (array_key_exists($emoji, $custom_emoji)) {
         return true;
     }
     $emoji_raw_json = file_get_contents(__DIR__ . '/../emoji.json');
     $emoji_json = json_decode($emoji_raw_json);
     $is_valid_emoji = false;
     foreach ($emoji_json as $single_emoji_object) {
         if ($emoji === $single_emoji_object->short_name) {
             $is_valid_emoji = true;
             break;
         }
     }
     return $is_valid_emoji;
 }
Пример #5
0
 /**
  * Sends our reaction to the server
  */
 public function do_reaction()
 {
     if (empty($_REQUEST['post_ID']) || empty($_REQUEST['emoji'])) {
         wp_send_json_error(esc_html__('The required post ID and emoji fields were not provided.', 'emoji-reactions'));
     }
     $post_ID = $_REQUEST['post_ID'];
     $emoji = $_REQUEST['emoji'];
     if (!Emoji_Reactions_Utils::can_react_to_post($post_ID)) {
         wp_send_json_error(esc_html__('Post is not available.', 'emoji-reactions'));
     }
     if (!Emoji_Reactions_Utils::is_valid_emoji($emoji)) {
         wp_send_json_error(esc_html__('Provided emoji not recognized.', 'emoji-reactions'));
     }
     $ip_address = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
     $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 254) : '';
     $data = array('comment_post_ID' => $post_ID, 'comment_content' => $emoji, 'comment_type' => 'emoji-reaction', 'comment_approved' => 1, 'comment_author_IP' => $ip_address, 'comment_agent' => $user_agent);
     if (is_user_logged_in()) {
         $current_user = wp_get_current_user();
         if ($current_user->user_login !== $current_user->display_name) {
             $user_name = $current_user->display_name;
         } else {
             $user_name = $current_user->user_login;
         }
         $data['user_id'] = get_current_user_id();
         $data['comment_author'] = $user_name;
         $data['comment_author_email'] = $current_user->user_email;
     } else {
         $data['comment_author'] = esc_html__('Guest', 'emoji-reactions');
     }
     $id = wp_insert_comment($data);
     if (!$id) {
         wp_send_json_error(esc_html__('Reaction failed to post.', 'emoji-reactions'));
     }
     wp_send_json(array('success' => true, 'reaction_ID' => $id));
     die;
 }