'', 'fb:appid' => '', 'fb:page_id' => '', ); define('OGPT_DEFAULT_TYPE', 'website'); define('OGPT_SETTINGS_KEY_FB_APPID', 'wpogp-fb:appid'); define('OGPT_SETTINGS_KEY_FB_ADMINS', 'wpogp-fb:admins'); define('OGPT_SETTINGS_KEY_FB_PAGEID', 'wpogp-fb:page_id'); $wpogp_keys = array( OGPT_SETTINGS_KEY_FB_APPID => 'A Facebook Platform application ID that administers this site.', OGPT_SETTINGS_KEY_FB_ADMINS => 'A comma-separated list of Facebook user IDs that administers this site. You can find your user id by visiting http://apps.facebook.com/what-is-my-user-id/', OGPT_SETTINGS_KEY_FB_PAGEID => 'Gain access to insights for your website by adding a fb:page_id tag to your root webpage, linking it to a Page.' ); add_theme_support( 'post-thumbnails' ); function get_the_post_thumbnail_src($img) { return (preg_match('~\bsrc="([^"]++)"~', $img, $matches)) ? $matches[1] : ''; } function wpogp_plugin_menu() { add_submenu_page('options-general.php', 'WP-OGP', 'WP-OGP', 'manage_options', 'WP-OGP', 'wpogp_plugin_options'); } function wpogp_plugin_options() { global $wpogp_keys; echo '
'; echo '
'; echo ''; echo ''; echo wp_nonce_field('update-options'); echo '

To include the Facebook "like" code on your page, you must first include values for the below items. Your Facebook User ID is a number. You may specify multiple user IDs if you like.

'; echo ''; foreach ($wpogp_keys as $key => $desc) { echo ''; echo ''; echo ''; echo ''; } echo '
'; echo array_pop(explode('-',$key)); echo '
'; echo $desc; echo '
'; echo '

'; echo ''; echo '

'; echo '
'; echo '
'; } function load_wpogp_settings() { global $ogpt_settings; $ogpt_settings['fb:appid'] = get_option(OGPT_SETTINGS_KEY_FB_APPID); $ogpt_settings['fb:admins'] = get_option(OGPT_SETTINGS_KEY_FB_ADMINS); $ogpt_settings['fb:page_id'] = get_option(OGPT_SETTINGS_KEY_FB_PAGEID); } function wpogp_plugin_path() { return get_option('siteurl') .'/wp-content/plugins/' . basename(dirname(__FILE__)); } function wpogp_image_url_default() { // default image associated is in the plugin directory named "default.png" return wpogp_plugin_path() . '/default.jpg'; } function wpogp_image_url() { global $post; $image = get_the_post_thumbnail_src(get_the_post_thumbnail($post->ID)); if ( empty($image) ) { return wpogp_image_url_default();} else { return $image; } } function wpogp_set_data() { global $wp_query; load_wpogp_settings(); $data = array(); if (is_home()) : $data['og:title'] = get_bloginfo('name'); $data['og:type'] = OGPT_DEFAULT_TYPE; $data['og:image'] = wpogp_image_url_default(); $data['image_src'] = wpogp_image_url_default(); $data['og:url'] = get_bloginfo('url'); $data['og:site_name'] = get_bloginfo('name'); elseif (is_single() || is_page()): $data['og:title'] = get_the_title(); $data['og:type'] = 'article'; $data['og:image'] = wpogp_image_url(); $data['image_src'] = wpogp_image_url(); $data['og:url'] = get_permalink(); $data['og:site_name'] = get_bloginfo('name'); else: $data['og:title'] = get_bloginfo('name'); $data['og:type'] = 'article'; $data['og:image'] = wpogp_image_url(); $data['image_src'] = wpogp_image_url(); $data['og:url'] = get_bloginfo('url'); $data['og:site_name'] = get_bloginfo('name'); endif; global $ogpt_settings; foreach($ogpt_settings as $key => $value) { if ($value!='') { $data[$key] = $value; } } return $data; } function wpogp_add_head() { $data = wpogp_set_data(); echo get_wpogp_headers($data); } function get_wpogp_headers($data) { if (!count($data)) { return; } $out = array(); $out[] = "\n"; foreach ($data as $property => $content) { if ($content != '') { $out[] = get_wpogp_tag($property, $content); } else { $out[] = ""; } } return implode("\n", $out); } function get_wpogp_tag($property, $content) { return ""; } function wpogp_add_head_desc() { $default_blog_desc = ''; // default description (setting overrides blog tagline) $post_desc_length = 75; // description length in # words for post/Page $post_use_excerpt = 1; // 0 (zero) to force content as description for post/Page $custom_desc_key = 'description'; // custom field key; if used, overrides excerpt/content global $cat, $cache_categories, $wp_query, $wp_version; if(is_single() || is_page()) { $post = $wp_query->post; $post_custom = get_post_custom($post->ID); $custom_desc_value = $post_custom["$custom_desc_key"][0]; if($custom_desc_value) { $text = $custom_desc_value; } elseif($post_use_excerpt && !empty($post->post_excerpt)) { $text = $post->post_excerpt; } else { $text = $post->post_content; } $text = str_replace(array("\r\n", "\r", "\n", " "), " ", $text); $text = str_replace(array("\""), "", $text); $text = trim(strip_tags($text)); $text = explode(' ', $text); if(count($text) > $post_desc_length) { $l = $post_desc_length; $ellipsis = '...'; } else { $l = count($text); $ellipsis = ''; } $description = ''; for ($i=0; $i<$l; $i++) $description .= $text[$i] . ' '; $description .= $ellipsis; } elseif(is_category()) { $category = $wp_query->get_queried_object(); $description = trim(strip_tags($category->category_description)); } else { $description = (empty($default_blog_desc)) ? trim(strip_tags(get_bloginfo('description'))) : $default_blog_desc; } if($description) { echo "\n\n"; echo "\n"; } } add_action('wp_head', 'wpogp_add_head'); add_action('wp_head', 'wpogp_add_head_desc'); add_action('admin_menu', 'wpogp_plugin_menu'); ?>