'widget_al2fb', 'description' => ''); parent::__construct('AL2FB_Widget', 'Add Link to Facebook', $widget_ops); //$this->WP_Widget('AL2FB_Widget', 'Add Link to Facebook', $widget_ops); } function widget($args, $instance) { global $wp_al2fb; $user_ID = isset($instance['al2fb_userid']) ? $instance['al2fb_userid'] : false; if (!$user_ID && !is_single() && !is_page()) return; // Get current post if (!empty($GLOBALS['post'])) $post = $GLOBALS['post']; if (empty($post->ID) && !empty($post['post_id'])) $post = get_post($post['post_id']); if (empty($post) || empty($post->ID)) return; // Excluded post types $ex_custom_types = explode(',', get_option(c_al2fb_option_exclude_type)); if (in_array($post->post_type, $ex_custom_types)) return; // Get user if (!$user_ID) $user_ID = $wp_al2fb->Get_user_ID($post); // Check if widget should be displayed if ((get_user_meta($user_ID, c_al2fb_meta_like_nohome, true) && is_home()) || (get_user_meta($user_ID, c_al2fb_meta_like_noposts, true) && is_single()) || (get_user_meta($user_ID, c_al2fb_meta_like_nopages, true) && is_page()) || (get_user_meta($user_ID, c_al2fb_meta_like_noarchives, true) && is_archive()) || (get_user_meta($user_ID, c_al2fb_meta_like_nocategories, true) && is_category()) || get_post_meta($post->ID, c_al2fb_meta_nolike, true)) return; // Get settings $comments = isset($instance['al2fb_comments']) ? $instance['al2fb_comments'] : false; $comments_count = isset($instance['al2fb_comments_count']) ? $instance['al2fb_comments_count'] : false; $messages = isset($instance['al2fb_messages']) ? $instance['al2fb_messages'] : false; $messages_count = isset($instance['al2fb_messages_count']) ? $instance['al2fb_messages_count'] : false; $messages_comments = isset($instance['al2fb_messages_comments']) ? $instance['al2fb_messages_comments'] : false; $like_button = isset($instance['al2fb_like_button']) ? $instance['al2fb_like_button'] : false; $like_box = isset($instance['al2fb_like_box']) ? $instance['al2fb_like_box'] : false; $send_button = isset($instance['al2fb_send_button']) ? $instance['al2fb_send_button'] : false; $subscribe_button = isset($instance['al2fb_subscribe_button']) ? $instance['al2fb_subscribe_button'] : false; $comments_plugin = isset($instance['al2fb_comments_plugin']) ? $instance['al2fb_comments_plugin'] : false; $face_pile = isset($instance['al2fb_face_pile']) ? $instance['al2fb_face_pile'] : false; $profile = isset($instance['al2fb_profile']) ? $instance['al2fb_profile'] : false; $registration = isset($instance['al2fb_registration']) ? $instance['al2fb_registration'] : false; $login = isset($instance['al2fb_login']) ? $instance['al2fb_login'] : false; $activity = isset($instance['al2fb_activity']) ? $instance['al2fb_activity'] : false; // Logged in? $registration = ($registration && !is_user_logged_in() && get_option('users_can_register')); $login = ($login && !is_user_logged_in()); // More settings $charset = get_bloginfo('charset'); $link_id = get_post_meta($post->ID, c_al2fb_meta_link_id, true); // Get link type $comments_nolink = get_user_meta($user_ID, c_al2fb_meta_fb_comments_nolink, true); if (empty($comments_nolink)) $comments_nolink = 'author'; else if ($comments_nolink == 'on') $comments_nolink = 'none'; // Get comments $fb_comments = false; if ($comments) $fb_comments = WPAL2Int::Get_comments_or_likes($post, false); // Get messages $fb_messages = false; if ($messages) try { $fb_messages = WPAL2Int::Get_fb_feed_cached($user_ID); } catch (Exception $e) { if ($wp_al2fb->debug) print_r($e); } if ($fb_comments || $fb_messages || $like_button || $like_box || $send_button || $subscribe_button || $comments_plugin || $face_pile || $profile || $registration || $login || $activity) { // Get values extract($args); $title = apply_filters('widget_title', $instance['title']); // Build content echo $before_widget; if (empty($title)) $title = 'Add Link to Facebook'; echo $before_title . $title . $after_title; // Comments if ($fb_comments) { echo '
'; self::Render_fb_comments($fb_comments, $comments_nolink, $link_id, $comments_count); echo '
'; } // Status messages if ($fb_messages) { echo '
'; self::Render_fb_messages($fb_messages, $comments_nolink, $link_id, $messages_count, $messages_comments); echo '
'; } // Facebook like button if ($like_button) echo WPAL2Int::Get_like_button($post, false); // Facebook like box if ($like_box) echo WPAL2Int::Get_like_button($post, true); // Facebook send button if ($send_button) echo WPAL2Int::Get_send_button($post); if ($subscribe_button) echo WPAL2Int::Get_subscribe_button($post); // Facebook comments plugins if ($comments_plugin) echo WPAL2Int::Get_comments_plugin($post); // Facebook Face pile if ($face_pile) echo WPAL2Int::Get_face_pile($post); // Facebook profile if ($profile) echo WPAL2Int::Get_profile_link($post); // Facebook registration if ($registration) echo WPAL2Int::Get_registration($post); // Facebook login if ($login) echo WPAL2Int::Get_login($post); // Facebook activity feed if ($activity) echo WPAL2Int::Get_activity_feed($post); echo $after_widget; } } // Helper render Facebook comments function Render_fb_comments($fb_comments, $comments_nolink, $link_id, $max_count) { $charset = get_bloginfo('charset'); // Get time zone offset $tz_off = get_option('gmt_offset'); if (empty($tz_off)) $tz_off = 0; $tz_off = apply_filters('al2fb_gmt_offset', $tz_off); $tz_off = $tz_off * 3600; $fb_comments->data = array_reverse($fb_comments->data); $count = 0; echo ''; } // Helper render Facebook status messages function Render_fb_messages($fb_messages, $comments_nolink, $link_id, $max_count, $messages_comments) { $charset = get_bloginfo('charset'); // Get time zone offset $tz_off = get_option('gmt_offset'); if (empty($tz_off)) $tz_off = 0; $tz_off = apply_filters('al2fb_gmt_offset', $tz_off); $tz_off = $tz_off * 3600; $count = 0; echo ''; } function update($new_instance, $old_instance) { // Get current user global $user_ID; get_currentuserinfo(); $instance = $old_instance; if (!$instance['al2fb_userid'] || $instance['al2fb_userid'] == $user_ID) { $instance['title'] = strip_tags($new_instance['title']); $instance['al2fb_comments'] = $new_instance['al2fb_comments']; $instance['al2fb_comments_count'] = $new_instance['al2fb_comments_count']; $instance['al2fb_messages'] = $new_instance['al2fb_messages']; $instance['al2fb_messages_count'] = $new_instance['al2fb_messages_count']; $instance['al2fb_messages_comments'] = $new_instance['al2fb_messages_comments']; $instance['al2fb_like_button'] = $new_instance['al2fb_like_button']; $instance['al2fb_like_box'] = $new_instance['al2fb_like_box']; $instance['al2fb_send_button'] = $new_instance['al2fb_send_button']; $instance['al2fb_subscribe_button'] = $new_instance['al2fb_subscribe_button']; $instance['al2fb_comments_plugin'] = $new_instance['al2fb_comments_plugin']; $instance['al2fb_face_pile'] = $new_instance['al2fb_face_pile']; $instance['al2fb_profile'] = $new_instance['al2fb_profile']; $instance['al2fb_registration'] = $new_instance['al2fb_registration']; $instance['al2fb_login'] = $new_instance['al2fb_login']; $instance['al2fb_activity'] = $new_instance['al2fb_activity']; $instance['al2fb_userid'] = $new_instance['al2fb_userid'] ? $user_ID : false; } return $instance; } function form($instance) { // Get current user global $user_ID; get_currentuserinfo(); if (empty($instance['title'])) $instance['title'] = null; if (empty($instance['al2fb_comments'])) $instance['al2fb_comments'] = false; if (empty($instance['al2fb_comments_count'])) $instance['al2fb_comments_count'] = null; if (empty($instance['al2fb_messages'])) $instance['al2fb_messages'] = false; if (empty($instance['al2fb_messages_count'])) $instance['al2fb_messages_count'] = null; if (empty($instance['al2fb_messages_comments'])) $instance['al2fb_messages_comments'] = false; if (empty($instance['al2fb_like_button'])) $instance['al2fb_like_button'] = false; if (empty($instance['al2fb_like_box'])) $instance['al2fb_like_box'] = false; if (empty($instance['al2fb_send_button'])) $instance['al2fb_send_button'] = false; if (empty($instance['al2fb_subscribe_button'])) $instance['al2fb_subscribe_button'] = false; if (empty($instance['al2fb_comments_plugin'])) $instance['al2fb_comments_plugin'] = false; if (empty($instance['al2fb_face_pile'])) $instance['al2fb_face_pile'] = false; if (empty($instance['al2fb_profile'])) $instance['al2fb_profile'] = false; if (empty($instance['al2fb_registration'])) $instance['al2fb_registration'] = false; if (empty($instance['al2fb_login'])) $instance['al2fb_login'] = false; if (empty($instance['al2fb_activity'])) $instance['al2fb_activity'] = false; if (empty($instance['al2fb_userid'])) $instance['al2fb_userid'] = false; $shared_user_ID = $instance['al2fb_userid']; if ($shared_user_ID && $shared_user_ID != $user_ID) { $userdata = get_userdata($shared_user_ID); echo '

'; echo __('Only this user can access the settings:', c_al2fb_text_domain); echo ' ' . $userdata->user_login . ' (id=' . $shared_user_ID . ')'; echo '

'; return; } $chk_comments = ($instance['al2fb_comments'] ? ' checked ' : ''); $chk_messages = ($instance['al2fb_messages'] ? ' checked ' : ''); $chk_messages_comments = ($instance['al2fb_messages_comments'] ? ' checked ' : ''); $chk_like = ($instance['al2fb_like_button'] ? ' checked ' : ''); $chk_box = ($instance['al2fb_like_box'] ? ' checked ' : ''); $chk_send = ($instance['al2fb_send_button'] ? ' checked ' : ''); $chk_subscribe = ($instance['al2fb_subscribe_button'] ? ' checked ' : ''); $chk_comments_plugin = ($instance['al2fb_comments_plugin'] ? ' checked ' : ''); $chk_face_pile = ($instance['al2fb_face_pile'] ? ' checked ' : ''); $chk_profile = ($instance['al2fb_profile'] ? ' checked ' : ''); $chk_registration = ($instance['al2fb_registration'] ? ' checked ' : ''); $chk_login = ($instance['al2fb_login'] ? ' checked ' : ''); $chk_activity = ($instance['al2fb_activity'] ? ' checked ' : ''); $chk_userid = ($instance['al2fb_userid'] ? ' checked ' : ''); ?>


id="get_field_id('al2fb_comments'); ?>" name="get_field_name('al2fb_comments'); ?>" />


id="get_field_id('al2fb_messages'); ?>" name="get_field_name('al2fb_messages'); ?>" />

id="get_field_id('al2fb_messages_comments'); ?>" name="get_field_name('al2fb_messages_comments'); ?>" />

id="get_field_id('al2fb_like_button'); ?>" name="get_field_name('al2fb_like_button'); ?>" />
id="get_field_id('al2fb_like_box'); ?>" name="get_field_name('al2fb_like_box'); ?>" />
id="get_field_id('al2fb_send_button'); ?>" name="get_field_name('al2fb_send_button'); ?>" />
id="get_field_id('al2fb_subscribe_button'); ?>" name="get_field_name('al2fb_subscribe_button'); ?>" />
id="get_field_id('al2fb_comments_plugin'); ?>" name="get_field_name('al2fb_comments_plugin'); ?>" />
id="get_field_id('al2fb_face_pile'); ?>" name="get_field_name('al2fb_face_pile'); ?>" />
id="get_field_id('al2fb_profile'); ?>" name="get_field_name('al2fb_profile'); ?>" />
id="get_field_id('al2fb_registration'); ?>" name="get_field_name('al2fb_registration'); ?>" />
id="get_field_id('al2fb_login'); ?>" name="get_field_name('al2fb_login'); ?>" />
id="get_field_id('al2fb_activity'); ?>" name="get_field_name('al2fb_activity'); ?>" />
id="get_field_id('al2fb_userid'); ?>" name="get_field_name('al2fb_userid'); ?>" />