/** * display widget */ function widget($args, $instance) { extract($args, EXTR_SKIP); global $wpdb, $user_ID, $table_prefix, $blog_id; $userid = $instance['snorl']; $result = wordbooker_get_cache($userid); echo $before_widget; $name = $result->name; if (strlen($instance['dname']) > 0) { $name = $instance['dname']; } $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); if (!empty($title)) { echo $before_title . $title . $after_title; } echo '<br /><div class="facebook_picture" align="center">'; echo '<a href="' . $result->url . '" target="facebook">'; echo '<img src="' . $result->pic . '" alt=" FB photo for ' . $name . '" /></a>'; echo '</div>'; if ($result->status) { $current_offset = 0; # $current_offset = get_option('gmt_offset'); echo '<p><br /><a href="' . $result->url . '">' . $name . '</a> : '; echo '<i>' . $result->status . '</i><br />'; if ($instance['df'] == 'fbt') { echo '(' . nicetime($result->updated + 3600 * $current_offset) . ').'; } else { echo '(' . date($instance['df'], $result->updated + 3600 * $current_offset) . ').'; } } echo "</p>" . $after_widget; }
/** * admin control form */ function form($instance) { global $user_ID, $wpdb, $table_prefix, $blog_id; $result = wordbooker_get_cache($user_ID, 'pages', 1); $fanpages = unserialize($result->pages); $xx = array('id' => 'FW:254577506873', 'name' => 'Wordbooker', 'url' => 'http://www.facebook.com/Wordbooker'); $fanpages[] = $xx; $default = array('title' => __('Fan Page', 'wordbooker'), 'snorl' => $user_ID, 'dname' => '', 'pid' => '254577506873', 'stream' => 'false', 'connections' => 6, 'width' => 188, 'height' => 260, 'header' => 'false', 'scheme' => 'light'); $instance = wp_parse_args((array) $instance, $default); $title_id = $this->get_field_id('title'); $title_name = $this->get_field_name('title'); $snorl_id = $this->get_field_id('snorl'); $snorl_name = $this->get_field_name('snorl'); $fanpages_id = $this->get_field_id('fanpages'); $fanpages_name = $this->get_field_name('fanpages'); $dname_id = $this->get_field_id('dname'); $dname_name = $this->get_field_name('dname'); $df_id = $this->get_field_id('pid'); $df_name = $this->get_field_name('pid'); $stream_id = $this->get_field_id('stream'); $stream_name = $this->get_field_name('stream'); $faces_id = $this->get_field_id('faces'); $faces_name = $this->get_field_name('faces'); $scheme_id = $this->get_field_id('scheme'); $scheme_name = $this->get_field_name('scheme'); $header_id = $this->get_field_id('header'); $header_name = $this->get_field_name('header'); $width_id = $this->get_field_id('width'); $width_name = $this->get_field_name('width'); $height_id = $this->get_field_id('height'); $height_name = $this->get_field_name('height'); $border_id = $this->get_field_id('border_colour'); $border_name = $this->get_field_name('border_colour'); $colorscheme = array('dark' => 'Dark', 'light' => 'Light'); $checked_flag = array('on' => 'checked', 'off' => '', 'true' => 'checked', 'false' => ''); if (!is_numeric($instance['width']) || $instance['width'] < 0) { $instance['width'] = 188; } if (!is_numeric($instance['height']) || $instance['height'] < 0) { $instance['height'] = 260; } echo '<input type="hidden" class="widefat" id="' . $snorl_id . '" name="' . $snorl_name . '" value="' . attribute_escape($instance['snorl']) . '" /></p>'; echo '<p><label for="' . $title_id . '">' . __('Title of Widget', 'wordbooker') . ': </label> <input type="text" class="widefat" id="' . $title_id . '" name="' . $title_name . '" value="' . attribute_escape($instance['title']) . '" /></p>'; $fanpagelist = ''; echo "\r\n" . '<p><label for="' . $df_id . '">' . __('Fan Page', 'wordbooker') . ': </label>'; echo '<select id=id="' . $df_id . '" name="' . $df_name . '" >'; foreach ($fanpages as $fan_page) { $fanpagelist[$fan_page['id']] = $fan_page['url']; if ($fan_page[id] == attribute_escape($instance['pid'])) { print '<option selected="yes" value="' . $fan_page[id] . '" >' . $fan_page[name] . '</option>'; } else { print '<option value="' . $fan_page[id] . '" >' . $fan_page[name] . '</option>'; } } echo '</select></p>'; echo "<input type='hidden' class='widefat' id='" . $fanpages_id . "' name='" . $fanpages_name . "' value='" . mysql_real_escape_string(serialize($fanpagelist)) . "' />"; echo '<p><label for="' . $stream_id . '">' . __("Include Stream ", 'wordbooker') . ' : </label>'; echo '<INPUT TYPE=CHECKBOX class="widefat"id="' . $stream_id . '" name="' . $stream_name . '" ' . $checked_flag[attribute_escape($instance['stream'])] . ' /></p>'; echo '<p><label for="' . $stream_id . '">' . __("Include Header ", 'wordbooker') . ' : </label>'; echo '<INPUT TYPE=CHECKBOX class="widefat"id="' . $header_id . '" name="' . $header_name . '" ' . $checked_flag[attribute_escape($instance['header'])] . ' /></p>'; echo '<p><label for="' . $scheme_id . '">' . __('Colour Scheme', 'wordbooker') . ': </label> <select id="' . $scheme_id . '" name="' . $scheme_name . '" >'; foreach ($colorscheme as $i => $value) { if ($i == $instance['scheme']) { print '<option selected="yes" value="' . $i . '" >' . $colorscheme[$i] . '</option>'; } else { print '<option value="' . $i . '" >' . $colorscheme[$i] . '</option>'; } } echo "</select><br />"; echo '<p><label for="' . $faces_id . '">' . __("Show Faces ", 'wordbooker') . ' : </label>'; echo '<INPUT TYPE=CHECKBOX class="widefat"id="' . $faces_id . '" name="' . $faces_name . '" ' . $checked_flag[attribute_escape($instance['faces'])] . ' /></p>'; echo '<p><label for="' . $width_id . '">' . __('Widget Width', 'wordbooker') . ': </label> <input type="text" size="7" id="' . $width_id . '" name="' . $width_name . '" value="' . attribute_escape($instance['width']) . '" /></p>'; echo '<p><label for="' . $height_id . '">' . __('Widget Height', 'wordbooker') . ': </label> <input type="text" size="7" id="' . $height_id . '" name="' . $height_name . '" value="' . attribute_escape($instance['height']) . '" /></p>'; echo '<p><label for="' . $height_id . '">' . __('Widget Border Colour', 'wordbooker') . ': </label>#<input type="text" size="6" maxlength=6 id="' . $border_id . '" name="' . $border_name . '" value="' . attribute_escape($instance['border_colour']) . '" /></p>'; }
function wordbooker_check_permissions($wbuser, $user) { global $user_ID; $perm_miss = wordbooker_get_cache($user_ID, 'auths_needed', 1); if ($perm_miss->auths_needed == 0) { return; } $perms_to_check = array(WORDBOOKER_FB_PUBLISH_STREAM, WORDBOOKER_FB_STATUS_UPDATE, WORDBOOKER_FB_READ_STREAM, WORDBOOKER_FB_CREATE_NOTE, WORDBOOKER_FB_PHOTO_UPLOAD, WORDBOOKER_FB_VIDEO_UPLOAD, WORDBOOKER_FB_MANAGE_PAGES, WORDBOOKER_FB_READ_FRIENDS); $perm_messages = array(__('Publish content to your Wall/Fan pages', 'wordbooker'), __('Update your status', 'wordbooker'), __('Read your News Feed and Wall', 'wordbooker'), __('Create notes', 'wordbooker'), __('Upload photos', 'wordbooker'), __('Upload videos', 'wordbooker'), __('Manage_pages', 'wordbooker'), __('Read friend lists', 'wordbooker')); $preamble = __("but requires authorization to ", 'wordbooker'); $postamble = __(" on Facebook. Click on the following link to grant permission", 'wordbooker'); $loginUrl2 = 'https://www.facebook.com/dialog/oauth?client_id=' . WORDBOOKER_FB_ID . '&redirect_uri=https://wordbooker.tty.org.uk/index2.html?br=' . urlencode(get_bloginfo('wpurl') . '&fbid=' . WORDBOOKER_FB_ID) . '&scope=' . implode(',', $perms_to_check) . '&response_type=token'; if (is_array($perms_to_check)) { foreach (array_keys($perms_to_check) as $key) { # Bit map check to put out the right text for the missing permissions. if (pow(2, $key) & $perm_miss->auths_needed) { $midamble .= $perm_messages[$key] . ", "; } } $midamble = rtrim($midamble, ","); $midamble = trim(preg_replace("/(.*?)((,|\\s)*)\$/m", "\$1", $midamble)); $midamble = substr_replace($midamble, " and ", strrpos($midamble, ","), strlen(",")); echo " " . $preamble . $midamble . $postamble . '</p><div style="text-align: center;"><a href="' . $loginUrl2 . '" > <img src="http://static.ak.facebook.com/images/devsite/facebook_login.gif" alt="Facebook Login Button" /></a><br /></div>'; } echo "and then save your settings<br />"; echo '<form action="' . WORDBOOKER_SETTINGS_URL . '" method="post"> <input type="hidden" name="action" value="" />'; echo '<p style="text-align: center;"><input type="submit" name="perm_save" class="button-primary" value="' . __('Save Configuration', 'wordbooker') . '" /></p></form>'; }