コード例 #1
0
ファイル: send-button.php プロジェクト: jeetututeja/Ingenia
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @since 1.0
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  * @return void
  */
 public function widget($args, $instance)
 {
     extract($args);
     if (!isset($instance['ref'])) {
         $instance['ref'] = 'widget';
     }
     if (!function_exists('facebook_get_send_button')) {
         require_once dirname(dirname(__FILE__)) . '/social-plugins.php';
     }
     $send_button_html = facebook_get_send_button($instance);
     if (!(is_string($send_button_html) && $send_button_html)) {
         return;
     }
     echo $before_widget;
     $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
     if ($title) {
         echo $before_title . esc_html($title) . $after_title;
     }
     echo $send_button_html;
     echo $after_widget;
 }
コード例 #2
0
/**
 * Add Send Button(s) to post content
 * Adds a send button above the post, below the post, or both above and below the post depending on stored preferences.
 *
 * @since 1.1
 * @param string $content existing content
 * @return string passed content with Send Button markup prepended, appended, or both.
 */
function facebook_the_content_send_button($content)
{
    global $post;
    // Send Button should not be the only content
    if (!$content) {
        return $content;
    }
    $options = get_option('facebook_send_button');
    if (!is_array($options)) {
        $options = array();
    }
    if (!is_singular(get_post_type($post))) {
        $options['href'] = apply_filters('facebook_rel_canonical', get_permalink($post->ID));
    }
    if ($options['position'] === 'top') {
        $options['ref'] = 'above-post';
        return facebook_get_send_button($options) . $content;
    } else {
        if ($options['position'] === 'bottom') {
            $options['ref'] = 'below-post';
            return $content . facebook_get_send_button($options);
        } else {
            if ($options['position'] === 'both') {
                $options['ref'] = 'above-post';
                $above = facebook_get_send_button($options);
                $options['ref'] = 'below-post';
                return $above . $content . facebook_get_send_button($options);
            }
        }
    }
    // don't break the filter
    return $content;
}
コード例 #3
0
 /**
  * Generate a HTML div element with data-* attributes to be converted into a Send Button by the Facebook JavaScript SDK
  *
  * @since 1.1.6
  *
  * @param array $attributes shortcode attributes. overrides site options for specific button attributes
  * @param string $content shortcode content. no effect
  * @return string send button HTML div or empty string if minimum requirements not met
  */
 public static function send_button($attributes, $content = null)
 {
     global $post;
     $site_options = get_option('facebook_send_button');
     if (!is_array($site_options)) {
         $site_options = array();
     }
     $options = shortcode_atts(array('href' => '', 'font' => isset($site_options['font']) ? $site_options['font'] : '', 'colorscheme' => isset($site_options['colorscheme']) ? $site_options['colorscheme'] : '', 'ref' => 'shortcode'), $attributes, 'facebook_send_button');
     // check for valid href value. unset if not valid, allowing for a possible permalink replacement
     if (is_string($options['href']) && $options['href']) {
         $options['href'] = esc_url_raw($options['href'], array('http', 'https'));
     }
     if (!(is_string($options['href']) && $options['href'])) {
         unset($options['href']);
         if (isset($post)) {
             $options['href'] = apply_filters('facebook_rel_canonical', get_permalink($post->ID));
         }
     }
     foreach (array('font', 'colorscheme', 'ref') as $key) {
         $options[$key] = trim($options[$key]);
         if (!$options[$key]) {
             unset($options[$key]);
         }
     }
     if (!function_exists('facebook_get_send_button')) {
         require_once dirname(__FILE__) . '/social-plugins.php';
     }
     return facebook_get_send_button($options);
 }