/** * Award user and author */ public function award($entity_name, $entity_id, $instance, $ref_user, $ref_author) { $user_id = get_current_user_id(); if (!$user_id) { return; } // Check if user is excluded (required) if ($this->core->exclude_user($user_id)) { return; } $author_id = _likebtn_get_author_id($entity_name, $entity_id); // Award for liking content if ($this->prefs[$instance]['creds'] != 0) { $data = array('entity_name' => $entity_name); // Limit and make sure this is unique event if (!$this->over_hook_limit($instance, $ref_user, $user_id) && !$this->core->has_entry($ref_user, $entity_id, $user_id, $data)) { // Execute $this->core->add_creds($ref_user, $user_id, $this->prefs[$instance]['creds'], $this->prefs[$instance]['log'], $entity_id, $data, $this->mycred_type); } } // Award post author for being liked // Do nothing is user liked own content if ($user_id == $author_id) { return; } if ($this->prefs['get_' . $instance]['creds'] != 0 && $author_id) { $data = array('entity_name' => $entity_name, 'user_id' => $user_id); // Limit and make sure this is unique event if (!$this->over_hook_limit('get_' . $instance, $ref_author, $user_id) && !$this->core->has_entry($ref_author, $entity_id, $user_id, $data)) { // Execute $this->core->add_creds($ref_user, $author_id, $this->prefs['get_' . $instance]['creds'], $this->prefs['get_' . $instance]['log'], $entity_id, $data, $this->mycred_type); } } }
/** * Award user and author */ public function award($entity_name, $entity_id, $instance, $ref_user, $ref_author) { $user_id = get_current_user_id(); if (!$user_id) { return; } // Check if user is excluded (required) if ($this->core->exclude_user($user_id)) { return; } $instance = $instance . '_' . $entity_name; $creds = $this->prefs[$instance]['creds']; $get_creds = $this->prefs['get_' . $instance]['creds']; $author_id = _likebtn_get_author_id($entity_name, $entity_id); $share = (double) $this->prefs[$instance]['share']; $get_share = (double) $this->prefs['get_' . $instance]['share']; if ($share != 0 || $get_share != 0) { $user_creds = (double) mycred_get_users_cred($user_id); } if ($share != 0) { $extra_creds = abs($user_creds / 100.0 * $share); if ($creds > 0) { $creds = $creds + $extra_creds; } else { $creds = $creds - $extra_creds; } } if ($get_share != 0) { $extra_creds = abs($user_creds / 100.0 * $get_share); if ($get_creds > 0) { $get_creds = $get_creds + $extra_creds; } else { $get_creds = $get_creds - $extra_creds; } } // Award for liking content if ($creds != 0) { $data = array('entity_name' => $entity_name); // Limit and make sure this is unique event if (!$this->over_hook_limit($instance, $ref_user, $user_id) && !$this->core->has_entry($ref_user, $entity_id, $user_id, $data)) { // Execute $this->core->add_creds($ref_user, $user_id, $creds, $this->prefs[$instance]['log'], $entity_id, $data, $this->mycred_type); } } // Award post author for being liked // Do nothing is user liked own content if ($user_id == $author_id) { return; } if ($get_creds != 0 && $author_id) { $data = array('entity_name' => $entity_name, 'user_id' => $user_id); // Limit and make sure this is unique event if (!$this->over_hook_limit('get_' . $instance, $ref_author, $user_id) && !$this->core->has_entry($ref_author, $entity_id, $user_id, $data)) { // Execute $this->core->add_creds($ref_user, $author_id, $get_creds, $this->prefs['get_' . $instance]['log'], $entity_id, $data, $this->mycred_type); } } }
function _likebtn_bp_notifications_add_notification($entity_name, $entity_id, $voter_id, $action) { if (!in_array($action, array('like', 'dislike'))) { $action = 'like'; } // No notifications from Anonymous if (!$voter_id) { return false; } $author_id = _likebtn_get_author_id($entity_name, $entity_id); if (!$author_id || $author_id == $voter_id) { return false; } bp_notifications_add_notification(array('user_id' => $author_id, 'item_id' => $entity_id, 'secondary_item_id' => $voter_id, 'component_name' => LIKEBTN_BP_COMPONENT_NAME, 'component_action' => 'likebtn_' . $entity_name . '_' . $action, 'date_notified' => bp_core_current_time(), 'is_new' => 1)); // bp_notifications_add_meta($notification_id, 'entity_name', $entity_name, true) }
function widget($args, $instance = array()) { global $wpdb; global $likebtn_nonpost_entities; global $likebtn_bbp_post_types; $has_posts = false; $post_types_count = 0; if (is_array($args)) { extract($args); } $instance = LikeBtnLikeButtonMostLikedWidget::prepareInstance($instance); if (is_array($instance)) { extract($instance); } if (empty($instance['entity_name'])) { $instance['entity_name'] = array(LIKEBTN_ENTITY_POST); } if (empty($instance['exclude_categories'])) { $instance['exclude_categories'] = array(); } // Author $author_in = ''; if (!empty($instance['author'])) { $author_in = "'" . implode("','", explode(",", preg_replace("/[^0-9,]/", '', $instance['author']))) . "'"; } // Add bbPress $nonpost_entities = $likebtn_nonpost_entities; $nonpost_entities[] = LIKEBTN_ENTITY_BBP_POST; foreach ($instance['entity_name'] as $entity_index => $entity_name) { $instance['entity_name'][$entity_index] = str_replace("'", '', trim($entity_name)); if (!in_array($entity_name, $nonpost_entities)) { $has_posts = true; } } $query_limit = ''; if (isset($instance['number']) && (int) $instance['number'] > 0) { $query_limit = "LIMIT " . (int) $instance['number']; } // getting the most liked content $query = ''; // Posts if ($has_posts) { $query_post_types = "'" . implode("','", $instance['entity_name']) . "'"; $query_exclude_categories = ''; if (count($instance['exclude_categories'])) { $query_exclude_categories = "'" . implode("','", $instance['exclude_categories']) . "'"; } $query_attachment = ''; if (in_array(LIKEBTN_ENTITY_ATTACHMENT, $instance['entity_name'])) { $query_attachment = " OR (p.post_type = 'attachment') "; } $query .= "\n SELECT\n DISTINCT p.ID as 'post_id',\n p.post_title,\n p.post_date,\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, SIGNED INTEGER) as 'likes_minus_dislikes',\n p.post_type,\n p.post_mime_type,\n '' as url\n FROM {$wpdb->prefix}postmeta pm_likes\n LEFT JOIN {$wpdb->prefix}posts p\n ON (p.ID = pm_likes.post_id)\n LEFT JOIN {$wpdb->prefix}postmeta pm_dislikes\n ON (pm_dislikes.post_id = pm_likes.post_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}postmeta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.post_id = pm_likes.post_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "') \n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "'\n AND ((p.post_status = 'publish'\n AND p.post_type in ({$query_post_types})) {$query_attachment}) "; if ($query_exclude_categories) { // ".($query_exclude_categories ? " // LEFT JOIN {$wpdb->term_relationships} t_rel ON (t_rel.object_id = p.ID) // LEFT JOIN {$wpdb->term_taxonomy} t_tax ON (t_tax.term_taxonomy_id = t_rel.term_taxonomy_id)" : '')." $query .= " AND NOT EXISTS (\n SELECT t_tax.term_id\n FROM {$wpdb->term_relationships} t_rel\n LEFT JOIN {$wpdb->term_taxonomy} t_tax ON (t_tax.term_taxonomy_id = t_rel.term_taxonomy_id)\n WHERE t_rel.object_id = p.ID AND t_tax.term_id IN ({$query_exclude_categories})\n ) "; } if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND p.post_date >= '" . $this->timeRangeToDateTime($instance['time_range']) . "' "; } if ($author_in) { $query .= " AND p.post_author IN (" . $author_in . ") "; } $post_types_count++; } // Comments if (in_array(LIKEBTN_ENTITY_COMMENT, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT\n p.comment_ID as 'post_id',\n p.comment_content as post_title,\n p.comment_date as 'post_date',\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, SIGNED INTEGER) as 'likes_minus_dislikes',\n '" . LIKEBTN_ENTITY_COMMENT . "' as post_type,\n '' as post_mime_type,\n '' as url\n FROM {$wpdb->prefix}commentmeta pm_likes\n LEFT JOIN {$wpdb->prefix}comments p\n ON (p.comment_ID = pm_likes.comment_id)\n LEFT JOIN {$wpdb->prefix}commentmeta pm_dislikes\n ON (pm_dislikes.comment_id = pm_likes.comment_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}commentmeta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.comment_id = pm_likes.comment_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "' \n AND p.comment_approved = 1 "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND comment_date >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } if ($author_in) { $query .= " AND p.comment_author IN (" . $author_in . ") "; } $post_types_count++; } // Custom items if (in_array(LIKEBTN_ENTITY_CUSTOM_ITEM, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query_post_types = "'" . implode("','", $instance['entity_name']) . "'"; $query .= "\n SELECT\n p.ID as 'post_id',\n p.identifier as 'post_title',\n '' as 'post_date',\n p.likes,\n p.dislikes,\n p.likes_minus_dislikes,\n '" . LIKEBTN_ENTITY_CUSTOM_ITEM . "' as 'post_type',\n '' as 'post_mime_type',\n url\n FROM {$wpdb->prefix}" . LIKEBTN_TABLE_ITEM . " p\n WHERE\n 1 = 1 "; $post_types_count++; } // BuddyPress Member if (_likebtn_is_bp_active() && in_array(LIKEBTN_ENTITY_BP_MEMBER, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT\n p.ID as 'post_id',\n p.display_name as post_title,\n p.user_registered as 'post_date',\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, SIGNED INTEGER) as 'likes_minus_dislikes',\n '" . LIKEBTN_ENTITY_BP_MEMBER . "' as post_type,\n '' as post_mime_type,\n '' as url\n FROM {$wpdb->prefix}bp_xprofile_meta pm_likes\n LEFT JOIN {$wpdb->prefix}users p\n ON (p.ID = pm_likes.object_id AND pm_likes.object_type = '" . LIKEBTN_BP_XPROFILE_OBJECT_TYPE . "')\n LEFT JOIN {$wpdb->prefix}bp_xprofile_meta pm_dislikes\n ON (pm_dislikes.object_id = pm_likes.object_id AND pm_dislikes.object_type = '" . LIKEBTN_BP_XPROFILE_OBJECT_TYPE . "' AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}bp_xprofile_meta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.object_id = pm_likes.object_id AND pm_likes_minus_dislikes.object_type = '" . LIKEBTN_BP_XPROFILE_OBJECT_TYPE . "' AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "' \n AND p.user_status = 0 "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND p.user_registered >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } $post_types_count++; } // BuddyPress Activities if (_likebtn_is_bp_active() && (in_array(LIKEBTN_ENTITY_BP_ACTIVITY_POST, $instance['entity_name']) || in_array(LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE, $instance['entity_name']) || in_array(LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT, $instance['entity_name']) || in_array(LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC, $instance['entity_name']))) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT \n p.id as 'post_id',\n CONCAT( IF(p.action != '', p.action, IF(p.content !='', p.content, IF(p.primary_link != '', p.primary_link, p.type))), IF(p.content != '' && p.type != 'bbp_topic_create' && p.type != 'new_blog_post', CONCAT(': ', p.content), '') ) as 'post_title',\n p.date_recorded as 'post_date',\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, SIGNED INTEGER) as 'likes_minus_dislikes',\n IF (p.type = 'bbp_topic_create',\n '" . LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC . "',\n IF (p.type = 'new_blog_post',\n '" . LIKEBTN_ENTITY_BP_ACTIVITY_POST . "',\n '" . LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE . "'\n )\n ) as post_type,\n '' as post_mime_type,\n '' as url\n FROM {$wpdb->prefix}bp_activity_meta pm_likes\n LEFT JOIN {$wpdb->prefix}bp_activity p\n ON (p.id = pm_likes.activity_id)\n LEFT JOIN {$wpdb->prefix}bp_activity_meta pm_dislikes\n ON (pm_dislikes.activity_id = pm_likes.activity_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}bp_activity_meta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.activity_id = pm_likes.activity_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "' \n AND p.hide_sitewide = 0\n AND p.is_spam = 0 "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND p.user_registered >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } if ($author_in) { $query .= " AND p.user_id IN (" . $author_in . ") "; } $post_types_count++; } // bbPress Post if (_likebtn_is_bbp_active() && in_array(LIKEBTN_ENTITY_BBP_POST, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT\n p.ID as 'post_id',\n IF (p.post_title != '', p.post_title, p.post_content) as post_title,\n p.post_date,\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, SIGNED INTEGER) as 'likes_minus_dislikes',\n p.post_type,\n p.post_mime_type,\n '' as url\n FROM {$wpdb->prefix}postmeta pm_likes\n LEFT JOIN {$wpdb->prefix}posts p\n ON (p.ID = pm_likes.post_id)\n LEFT JOIN {$wpdb->prefix}postmeta pm_dislikes\n ON (pm_dislikes.post_id = pm_likes.post_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}postmeta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.post_id = pm_likes.post_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "'\n AND p.post_type in ('" . implode("', '", $likebtn_bbp_post_types) . "') \n AND p.post_status = 'publish' "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND post_date >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } if ($author_in) { $query .= " AND p.post_author IN (" . $author_in . ") "; } $post_types_count++; } // bbPress User if (_likebtn_is_bbp_active() && in_array(LIKEBTN_ENTITY_BBP_USER, $instance['entity_name'])) { if ($post_types_count > 0) { $query .= " UNION "; } $query .= "\n SELECT\n p.ID as 'post_id',\n p.display_name as post_title,\n p.user_registered as 'post_date',\n CONVERT(pm_likes.meta_value, UNSIGNED INTEGER) as 'likes',\n CONVERT(pm_dislikes.meta_value, UNSIGNED INTEGER) as 'dislikes',\n CONVERT(pm_likes_minus_dislikes.meta_value, SIGNED INTEGER) as 'likes_minus_dislikes',\n '" . LIKEBTN_ENTITY_BBP_USER . "' as post_type,\n '' as post_mime_type,\n '' as url\n FROM {$wpdb->prefix}usermeta pm_likes\n LEFT JOIN {$wpdb->prefix}users p\n ON (p.ID = pm_likes.user_id)\n LEFT JOIN {$wpdb->prefix}usermeta pm_dislikes\n ON (pm_dislikes.user_id = pm_likes.user_id AND pm_dislikes.meta_key = '" . LIKEBTN_META_KEY_DISLIKES . "')\n LEFT JOIN {$wpdb->prefix}usermeta pm_likes_minus_dislikes\n ON (pm_likes_minus_dislikes.user_id = pm_likes.user_id AND pm_likes_minus_dislikes.meta_key = '" . LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES . "')\n WHERE\n pm_likes.meta_key = '" . LIKEBTN_META_KEY_LIKES . "' \n AND p.user_status = 0 "; if (!empty($instance['time_range']) && $instance['time_range'] != 'all') { $query .= " AND p.user_registered >= '" . $this->timeRangeToDateTime($instance['time_range']) . "'"; } $post_types_count++; } if ($post_types_count > 1) { $query = "SELECT * FROM (" . $query . ") main_query"; } $query .= "\n ORDER BY "; switch ($instance['order']) { default: case 'likes': $query .= "likes"; break; case 'dislikes': $query .= "dislikes"; break; case 'likes_minus_dislikes': $query .= "likes_minus_dislikes"; break; } $query .= " DESC"; $query .= " {$query_limit}"; // echo "<pre>"; // print_r($query); // exit(); $posts = $wpdb->get_results($query); $post_loop = array(); if (count($posts) > 0) { foreach ($posts as $i => $db_post) { $post = array('id' => $db_post->post_id, 'type' => $db_post->post_type, 'post_mime_type' => $db_post->post_mime_type, 'title' => '', 'link' => '', 'likes' => '', 'dislikes' => '', 'date' => '', 'excerpt' => '', 'author_id' => '', 'author_name' => ''); if (empty($instance['title_length'])) { $instance['title_length'] = LIKEBTN_WIDGET_TITLE_LENGTH; } // Title $post['title'] = _likebtn_prepare_title($db_post->post_type, $db_post->post_title, $instance['title_length']); // Link $post['link'] = _likebtn_get_entity_url($db_post->post_type, $db_post->post_id, $db_post->url); $post['likes'] = $db_post->likes; $post['dislikes'] = $db_post->dislikes; if ($show_date) { $post['date'] = strtotime($db_post->post_date); } if ($show_author) { $author_id = _likebtn_get_author_id($db_post->post_type, $db_post->post_id); if ($author_id) { $post['author_id'] = $author_id; $post['author_name'] = _likebtn_get_entity_title(LIKEBTN_ENTITY_USER, $author_id); } } if ($show_excerpt) { $post['excerpt'] = _likebtn_get_entity_excerpt($db_post->post_type, $db_post->post_id); } // For bbPress replies if (!$post['title']) { $post['title'] = _likebtn_shorten_title($post['excerpt'], $instance['title_length']); } $post_loop[$i] = $post; } } // Get and include the template we're going to use ob_start(); include $this->getTemplateHierarchy(self::TEMPLATE); $result = ob_get_contents(); ob_get_clean(); return $result; }
function _likebtn_get_markup($entity_name, $entity_id, $values = null, $use_entity_name = '', $use_entity_settings = true, $wrap = true, $include_script = false, $like_box = false) { global $wp_version; global $likebtn_settings_deprecated; $prepared_settings = array(); if (!$use_entity_name) { $use_entity_name = $entity_name; } // Cut excerpt flag from entity_name if ($entity_id !== 'demo') { $entity_name = _likebtn_cut_list_flag($entity_name); } if ($values && isset($values['identifier']) && $values['identifier'] !== '') { $identifier = $values['identifier']; } else { $identifier = _likebtn_entity_to_identifier($entity_name, $entity_id); } $data = ' data-identifier="' . $identifier . '" '; // Site ID if (get_option('likebtn_site_id')) { $data .= ' data-site_id="' . get_option('likebtn_site_id') . '" '; } // Authorization check if (get_option('likebtn_user_logged_in_' . $use_entity_name) == LIKEBTN_USER_LOGGED_IN_MODAL && !is_user_logged_in()) { $values['voting_enabled'] = '0'; $data .= ' data-clk_modal="' . htmlspecialchars(_likebtn_get_user_logged_in_alert($use_entity_name)) . '" '; } if (get_option('likebtn_voting_author_' . $use_entity_name) == '1' && get_current_user_id()) { $author_id = _likebtn_get_author_id($use_entity_name, $entity_id); if ($author_id == get_current_user_id()) { $values['voting_enabled'] = '0'; } } $likebtn_settings = _likebtn_get_all_settings(); foreach ($likebtn_settings as $option_name => $option_info) { if ($values && isset($values[$option_name])) { // if values passed $option_value = $values[$option_name]; } elseif (!$use_entity_settings && !in_array($option_name, $likebtn_settings_deprecated)) { // Do not use entity value - use default. Usually in shortcodes. $option_value = $option_info['default']; } else { $option_value = get_option('likebtn_settings_' . $option_name . '_' . $use_entity_name); } $option_value_prepared = _likebtn_prepare_option($option_name, $option_value); $prepared_settings[$option_name] = $option_value_prepared; // do not add option if it has default value if (isset($likebtn_settings[$option_name]['default']) && $option_value == $likebtn_settings[$option_name]['default'] || $option_value === '' && (isset($likebtn_settings[$option_name]['default']) && $likebtn_settings[$option_name]['default'] == '0')) { // option has default value } else { // Some options need extra procession if ($option_name == 'event_handler') { $option_name = 'custom_eh'; } $data .= ' data-' . $option_name . '="' . $option_value_prepared . '" '; } } // Add item options $entity = null; $entity_url = ''; $entity_title = ''; $entity_image = ''; $entity_date = ''; if ($entity_name == LIKEBTN_ENTITY_COMMENT) { $entity = get_comment($entity_id); if ($entity) { $entity_url = get_comment_link($entity->comment_ID); $entity_title = _likebtn_shorten_title($entity->comment_content); } } else { if (in_array($entity_name, array(LIKEBTN_ENTITY_BP_ACTIVITY_POST, LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE, LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT, LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC))) { $entity_title = _likebtn_shorten_title(_likebtn_bp_get_activity_title($entity_id)); if (function_exists('bp_activity_get_permalink')) { $entity_url = bp_activity_get_permalink($entity_id); } } else { if ($entity_name == LIKEBTN_ENTITY_BP_MEMBER || $entity_name == LIKEBTN_ENTITY_USER || $entity_name == LIKEBTN_ENTITY_BBP_USER) { if (function_exists('bp_core_get_user_displayname')) { $entity_title = bp_core_get_user_displayname($entity_id); } else { $entity_title = get_the_author_meta('user_nicename', $entity_id); } if (function_exists('bp_core_get_user_domain')) { $entity_url = bp_core_get_user_domain($entity_id); } else { $entity_url = get_author_posts_url($entity_id); } $entity_image = _likebtn_get_avatar_url($entity_id); $user_info = get_userdata($entity_id); if (!empty($user_info) && !empty($user_info->user_registered)) { $entity_date = mysql2date("c", $user_info->user_registered); } } else { $entity = get_post($entity_id); if ($entity) { $entity_url = get_permalink($entity->ID); $entity_title = $entity->post_title; $entity_image = _likebtn_get_entity_image($entity_name, $entity_id); $entity_date = mysql2date("c", $entity->post_date); } } } } if ($entity_url && !$prepared_settings['item_url']) { $data .= ' data-item_url="' . $entity_url . '" '; } if ($entity_title && !$prepared_settings['item_title']) { $entity_title = strip_shortcodes($entity_title); $entity_title = preg_replace('/\\s+/', ' ', $entity_title); $entity_title = htmlspecialchars($entity_title); $data .= ' data-item_title="' . $entity_title . '" '; } if ($entity_image && !$prepared_settings['item_image']) { $data .= ' data-item_image="' . $entity_image . '" '; } if ($entity_date && !$prepared_settings['item_date']) { $data .= ' data-item_date="' . $entity_date . '" '; } // Set engine and plugin info $data .= ' data-engine="WordPress" '; $data .= ' data-engine_v="' . $wp_version . '" '; $plugin_v = LIKEBTN_VERSION; if ($plugin_v) { $data .= ' data-plugin_v="' . $plugin_v . '" '; } if (get_option('likebtn_acc_data_correct') == '1') { // Proxy $prx = admin_url('admin-ajax.php') . '?action=likebtn_prx'; $data .= ' data-prx="' . $prx . '" '; } // Event handler $data .= ' data-event_handler="likebtn_eh" '; $data .= ' data-engine_v="' . $wp_version . '" '; $public_url = _likebtn_get_public_url(); if ($include_script) { $markup = <<<MARKUP <!-- LikeBtn.com BEGIN --><span class="likebtn-wrapper" {$data}></span><script>(function(d, e, s) {a = d.createElement(e);m = d.getElementsByTagName(e)[0];a.async = 1;a.src = s;m.parentNode.insertBefore(a, m)})(document, 'script', '//w.likebtn.com/js/w/widget.js'); if (typeof(LikeBtn) != "undefined") { LikeBtn.init(); }</script><!-- LikeBtn.com END --> MARKUP; } else { $markup = <<<MARKUP <!-- LikeBtn.com BEGIN --><span class="likebtn-wrapper" {$data}></span><!-- LikeBtn.com END --> MARKUP; } // HTML before $html_before = ''; if (isset($values['html_before'])) { $html_before = $values['html_before']; } elseif (get_option('likebtn_html_before_' . $use_entity_name)) { $html_before = get_option('likebtn_html_before_' . $use_entity_name); } if (trim($html_before)) { $markup = $html_before . $markup; } // HTML after $html_after = ''; if (isset($values['html_after'])) { $html_after = $values['html_after']; } elseif (get_option('likebtn_html_after_' . $use_entity_name)) { $html_after = get_option('likebtn_html_after_' . $use_entity_name); } if (trim($html_after)) { $markup = $markup . $html_after; } if ($wrap) { if (get_option('likebtn_wrap_' . $use_entity_name) != '1') { $wrap = false; } } if ($wrap) { $alignment = get_option('likebtn_alignment_' . $use_entity_name); $newline = get_option('likebtn_newline_' . $use_entity_name); $style = ''; if ($newline == '1') { $style .= 'clear:both;'; } if ($alignment == LIKEBTN_ALIGNMENT_RIGHT) { $style .= 'text-align:right;'; $markup = '<div class="likebtn_container" style="' . $style . '">' . $markup . '</div>'; } elseif ($alignment == LIKEBTN_ALIGNMENT_CENTER) { $style .= 'text-align:center;'; $markup = '<div class="likebtn_container" style="' . $style . '">' . $markup . '</div>'; } else { $markup = '<div class="likebtn_container" style="' . $style . '">' . $markup . '</div>'; } } // Like box if ($like_box && !is_admin()) { $like_box = get_option('likebtn_like_box_' . $entity_name); if ($like_box) { $like_box_html = _likebtn_like_box($identifier, get_option('likebtn_like_box_size_' . $entity_name), get_option('likebtn_like_box_text_' . $entity_name), get_option('likebtn_like_box_type_' . $entity_name)); if ($like_box == LIKEBTN_LIKE_BOX_BEFORE) { $markup = $like_box_html . $markup; } else { $markup = $markup . $like_box_html; } } } return $markup; }