コード例 #1
0
ファイル: likebtn_like_button.php プロジェクト: Omuze/barakat
function _likebtn_get_entity_title($entity_name, $entity_id, $max_length = LIKEBTN_TITLE_MAX_LENGTH)
{
    switch ($entity_name) {
        case LIKEBTN_ENTITY_COMMENT:
            $title = get_comment_text($entity_id);
            break;
        case LIKEBTN_ENTITY_BP_ACTIVITY_POST:
        case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE:
        case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT:
        case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC:
            $title = _likebtn_bp_get_activity_title($entity_id);
            break;
        case LIKEBTN_ENTITY_BP_MEMBER:
        case LIKEBTN_ENTITY_BBP_USER:
        case LIKEBTN_ENTITY_USER:
            if (function_exists('bp_core_get_user_displayname')) {
                $title = bp_core_get_user_displayname($entity_id);
            } else {
                $title = get_the_author_meta('user_nicename', $entity_id);
            }
            break;
        default:
            $title = get_the_title($entity_id);
            break;
    }
    if ($max_length) {
        $title = _likebtn_shorten_title($title, $max_length);
    }
    return $title;
}
コード例 #2
0
function _likebtn_get_markup($entity_name, $entity_id, $values = null, $use_entity_name = '', $use_entity_settings = true, $wrap = true)
{
    global $wp_version;
    global $likebtn_map_entities;
    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'] !== '') {
        $data = ' data-identifier="' . $values['identifier'] . '" ';
    } else {
        $identifier = $entity_name;
        if (!empty($likebtn_map_entities[$entity_name])) {
            $identifier = $likebtn_map_entities[$entity_name];
        }
        $data = ' data-identifier="' . $identifier . '_' . $entity_id . '" ';
    }
    // Site ID
    if (get_option('likebtn_site_id')) {
        $data .= ' data-site_id="' . get_option('likebtn_site_id') . '" ';
    }
    $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 {
            $data .= ' data-' . $option_name . '="' . $option_value_prepared . '" ';
        }
    }
    // Add item options
    $entity = null;
    $entity_url = '';
    $entity_title = '';
    $entity_image = '';
    if ($entity_name == LIKEBTN_ENTITY_COMMENT) {
        $entity = get_comment($entity_id);
        if ($entity) {
            $entity_url = get_comment_link($entity->comment_ID);
            $entity_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_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) {
                if (function_exists('bp_core_get_username')) {
                    $entity_title = bp_core_get_username($entity_id);
                }
                if (function_exists('bp_core_get_user_domain')) {
                    $entity_url = bp_core_get_user_domain($entity_id);
                }
            } else {
                $entity = get_post($entity_id);
                if ($entity) {
                    $entity_url = get_permalink($entity->ID);
                    $entity_title = $entity->post_title;
                    $entity_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($entity->ID), 'large');
                    if (!empty($entity_image_url[0])) {
                        $entity_image = $entity_image_url[0];
                    }
                }
            }
        }
    }
    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 . '" ';
    }
    // 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 . '" ';
    }
    $public_url = _likebtn_get_public_url();
    $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;
    // 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>';
        }
    }
    return $markup;
}