Index: extensions/FacebookPlug/Plugin/include/header.inc.php
===================================================================
--- extensions/FacebookPlug/Plugin/include/header.inc.php	(revision 8393)
+++ extensions/FacebookPlug/Plugin/include/header.inc.php	(revision 8395)
@@ -40,29 +40,54 @@
 function fbp_init()
 {
-  global $template, $conf, $user;
+  global $template, $conf, $user, $page;
 
-  // define ID
-  $template->assign('FACEBOOK_APP_ID', (is_numeric($conf['fbp']['facebook_app_id']) ? $conf['fbp']['facebook_app_id'] : FACEBOOK_APP_ID));
-  // define language
-  $template->assign('LANGUAGE', $user['language']);
-  $template->assign('fbp', $conf['fbp']);
-  $template->smarty->register_modifier('boolean_to_string', 'boolean_to_string');
+  // Get init facebook
+  $page['fbp']['do_facebook_init'] = trigger_event('fbp_do_facebook_init', $conf['fbp']['force_facebook_init']);
+  if ($page['fbp']['do_facebook_init'])
+  {
+    // define ID
+    $template->assign('FACEBOOK_APP_ID', (is_numeric($conf['fbp']['facebook_app_id']) ? $conf['fbp']['facebook_app_id'] : FACEBOOK_APP_ID));
+    // define language
+    $template->assign('LANGUAGE', $user['language']);
+    $template->assign('fbp', $conf['fbp']);
+    $template->smarty->register_modifier('boolean_to_string', 'boolean_to_string');
+  }
+}
 
-  if (trigger_event('fbp_do_facebook_init', $conf['fbp']['force_facebook_init']))
+function fbp_loc_end_page_header()
+{
+  global $template, $conf, $user, $page;
+
+  if ($page['fbp']['do_facebook_init'])
   {
     // set prefilter
     $template->set_prefilter('header', 'fbp_header');
 
+    if (empty($page['fbp']['og']['url']))
+    {
+      $page['fbp']['og']['url'] = get_absolute_root_url().script_basename();
+      if ($conf['php_extension_in_urls'])
+      {
+        $page['fbp']['og']['url'] .= '.php';
+      }
+    }
+    //~ if (empty($page['fbp']['url_image']))
+    //~ {
+    //~ // todo
+    //~ }
+
+    $template->assign('fbp_page', $page['fbp']);
+
     $template->set_filename('fbp_init.fb', FBP_DIR.'/tpl/init.fb.tpl');
     $template->append('head_elements', $template->parse('fbp_init.fb', true));
-  }
 
-  if (
-      (script_basename() == 'index')
-      and
-      ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
-      )
-  {
-    $template->block_html_head('', '<link rel="stylesheet" type="text/css" href="'.FBP_PATH.'/css/fbp.css">', $smarty, $repeat);
+    if (
+        (script_basename() == 'index')
+        and
+        ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
+        )
+    {
+      $template->block_html_head('', '<link rel="stylesheet" type="text/css" href="'.FBP_PATH.'/css/fbp.css">', $smarty, $repeat);
+    }
   }
 }
@@ -100,8 +125,6 @@
 add_event_handler('fbp_do_facebook_init', 'fbp_do_facebook_init');
 
-//~ if (trigger_event('fbp_do_facebook_init', $conf['fbp']['force_facebook_init']))
-//~ {
-  add_event_handler('init', 'fbp_init');
-//~ }
+add_event_handler('init', 'fbp_init');
+add_event_handler('loc_end_page_header', 'fbp_loc_end_page_header');
 
 ?>
Index: extensions/FacebookPlug/Plugin/include/index.inc.php
===================================================================
--- extensions/FacebookPlug/Plugin/include/index.inc.php	(revision 8393)
+++ extensions/FacebookPlug/Plugin/include/index.inc.php	(revision 8395)
@@ -42,5 +42,5 @@
 }
 
-function fpt_blockmanager_apply($menu_ref_arr)
+function fbp_blockmanager_apply($menu_ref_arr)
 {
   global $template;
@@ -58,10 +58,59 @@
 }
 
+function fbp_loc_begin_index()
+{
+  global $page;
+
+  set_make_full_url();
+  $page['fbp']['og']['url'] = duplicate_index_url(array(''), array('start', 'flat', 'chronology_date', 'chronology_field', 'chronology_style', 'chronology_view'));
+  unset_make_full_url();
+}
+
+function fbp_loc_begin_index_category_thumbnails($categories)
+{
+  global $page;
+
+  if (count($categories) > 0)
+  {
+    include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
+    $category = reset($categories);
+    $query = '
+SELECT id, path, tn_ext
+FROM '.IMAGES_TABLE.'
+WHERE id = '.$category['representative_picture_id'].'
+;';
+    $result = pwg_query($query);
+    if($row = pwg_db_fetch_assoc($result))
+    {
+      set_make_full_url();
+      $page['fbp']['og']['url_image'] = get_element_url($row);
+      unset_make_full_url();
+    }
+  }
+}
+
+function fbp_loc_begin_index_thumbnails($pictures)
+{
+  global $page;
+
+  if (count($pictures) > 0)
+  {
+    include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
+    $picture = reset($pictures);
+    set_make_full_url();
+    $page['fbp']['og']['url_image'] = get_element_url($picture);
+    unset_make_full_url();
+  }
+}
 
 if ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
 {
   add_event_handler('blockmanager_register_blocks', 'fbp_blockmanager_register_blocks', EVENT_HANDLER_PRIORITY_NEUTRAL);
-  add_event_handler('blockmanager_apply', 'fpt_blockmanager_apply');
+  add_event_handler('blockmanager_apply', 'fbp_blockmanager_apply');
 }
 
+add_event_handler('loc_begin_index', 'fbp_loc_begin_index');
+add_event_handler('loc_begin_index_category_thumbnails', 'fbp_loc_begin_index_category_thumbnails', EVENT_HANDLER_PRIORITY_NEUTRAL, 1);
+add_event_handler('loc_begin_index_thumbnails', 'fbp_loc_begin_index_thumbnails', EVENT_HANDLER_PRIORITY_NEUTRAL, 1);
+
 ?>
Index: extensions/FacebookPlug/Plugin/include/picture.inc.php
===================================================================
--- extensions/FacebookPlug/Plugin/include/picture.inc.php	(revision 8393)
+++ extensions/FacebookPlug/Plugin/include/picture.inc.php	(revision 8395)
@@ -28,44 +28,53 @@
   global $template, $user, $page, $conf, $picture;
 
-  if ($page['slideshow'] and $conf['fbp']['social_plugin_facepile']['enabled'])
+  if ($page['fbp']['do_facebook_init'])
   {
-    $tpl = 'social.plugin.facepile';
-  }
-  else if (! $page['slideshow'])
-  {
-    if ($conf['fbp']['social_plugin_like_button']['enabled'])
+    // Header for each page
+    //~ $tpls[] = 'picture.header';
+
+    // Specific
+    if ($page['slideshow'] and $conf['fbp']['social_plugin_facepile']['enabled'])
     {
-      $tpl = 'social.plugin.like.button';
+      $tpls[] = 'social.plugin.facepile';
     }
-    else if ($conf['fbp']['social_plugin_comments']['enabled'])
+    else if (! $page['slideshow'])
     {
-      $tpl = 'social.plugin.comments';
+      if ($conf['fbp']['social_plugin_like_button']['enabled'])
+      {
+        $tpls[] = 'social.plugin.like.button';
+      }
+      else if ($conf['fbp']['social_plugin_comments']['enabled'])
+      {
+        $tpls[] = 'social.plugin.comments';
+      }
+    }
+
+    // define picture FB link
+    // Always use full url for FB social plugin
+    set_make_full_url();
+    if ($conf['fbp']['picture_url_type'] == 'image')
+    {
+      $fbp_url_picture = get_element_url($current_picture);
+    }
+    else
+    {
+      $fbp_url_picture = make_picture_url(array('image_id' => $page['image_id']));
+    }
+    $page['fbp']['og']['url'] = $fbp_url_picture;
+    $page['fbp']['og']['url_image'] = get_element_url($current_picture);
+    unset_make_full_url();
+
+    // Assign template
+    $template->assign('fbp_url_picture', $fbp_url_picture);
+    $template->assign('fbp_urlencode_picture', urlencode($fbp_url_picture));
+
+    // Parse TPL
+    foreach($tpls as $tpl)
+    {
+      // XFBML implementation
+      $template->set_filename($tpl, FBP_DIR.'/tpl/'.$tpl.'.tpl');
+      $content .= $template->parse($tpl, true);
     }
   }
-
-  if (empty($tpl))
-  {
-    // nothing to do
-    return $content;
-  }
-
-  // define picture FB link
-  // Always use full url for FB social plugin
-  set_make_full_url();
-  if ($conf['fbp']['picture_url_type'] == 'image')
-  {
-    $fbp_url_picture = get_element_url($current_picture);
-  }
-  else
-  {
-    $fbp_url_picture = make_picture_url(array('image_id' => $page['image_id']));
-  }
-  unset_make_full_url();
-  $template->assign('fbp_url_picture', $fbp_url_picture);
-  $template->assign('fbp_urlencode_picture', urlencode($fbp_url_picture));
-
-  // XFBML implementation
-  $template->set_filename($tpl, FBP_DIR.'/tpl/'.$tpl.'.tpl');
-  $content .= $template->parse($tpl, true);
 
   return $content;
@@ -74,7 +83,8 @@
 function ftp_loc_end_section_init()
 {
-  global $conf;
+  global $conf, $page;
 
-  if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'])
+  //~ if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'])
+  if ($page['fbp']['do_facebook_init'])
   {
     if ($conf['fbp']['allow_fb_access_private_page'])
@@ -97,11 +107,6 @@
 }
 
-if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_facepile']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'])
-{
-  //~ add_event_handler('loc_begin_picture', 'fbp_loc_begin_picture');
-  add_event_handler('render_element_content', 'fbp_render_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL+1 /*in order to have picture content*/, 2);
-  //~ add_event_handler('loc_end_picture', 'fbp_loc_end_picture');
-  add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init');
-}
+add_event_handler('render_element_content', 'fbp_render_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL+1 /*in order to have picture content*/, 2);
+add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init');
 
 ?>
Index: extensions/FacebookPlug/Plugin/tpl/header.tpl
===================================================================
--- extensions/FacebookPlug/Plugin/tpl/header.tpl	(revision 8395)
+++ extensions/FacebookPlug/Plugin/tpl/header.tpl	(revision 8395)
@@ -0,0 +1,4 @@
+{html_head}
+<meta property="og:image" content="{$fbp_url_image}">
+<meta property="og:url" content="{$fbp_url_picture}">
+{/html_head}
Index: extensions/FacebookPlug/Plugin/tpl/init.fb.tpl
===================================================================
--- extensions/FacebookPlug/Plugin/tpl/init.fb.tpl	(revision 8393)
+++ extensions/FacebookPlug/Plugin/tpl/init.fb.tpl	(revision 8395)
@@ -1,3 +1,27 @@
 <!-- By FacebookPlug a Piwigo Plugin -->
+{if isset($fbp_page.og.title)}
+<meta property="og:title" content="{$fbp_page.og.title|@replace:'"':' '}">
+{else}
+  {if (isset($REVERSE) and $REVERSE and $PAGE_TITLE == l10n('Home'))}
+<meta property="og:title" content="{$GALLERY_TITLE|@replace:'"':' '} | {$PAGE_TITLE|@replace:'"':' '}">
+  {else}
+<meta property="og:title" content="{$PAGE_TITLE|@replace:'"':' '} | {$GALLERY_TITLE|@replace:'"':' '}">
+  {/if}
+{/if}
+{if isset($fbp_page.og.description)}
+<meta property="og:description" content="{$fbp_page.og.description|@replace:'"':' '}">
+{else}
+  {if isset($COMMENT_IMG)}
+<meta property="og:description" content="{$COMMENT_IMG|@strip_tags:false|@replace:'"':' '}{if isset($INFO_FILE)} - {$INFO_FILE|@replace:'"':' '}{/if}">
+  {else}
+<meta property="og:description" content="{$PAGE_TITLE|@replace:'"':' '}{if isset($INFO_FILE)} - {$INFO_FILE|@replace:'"':' '}{/if}">
+  {/if}
+{/if}
+<meta property="og:site_name" content="{if isset($fbp_page.og.site_name)}{$fbp_page.og.site_name|@replace:'"':' '}{else}{$GALLERY_TITLE|@replace:'"':' '}{/if}">
+<meta property="fb:app_id" content="{if isset($fbp_page.og.app_id)}{$fbp_page.og.app_id}{else}{$FACEBOOK_APP_ID}{/if}">
+<meta property="og:type" content="{if isset($fbp_page.og.type)}{$fbp_page.og.type}{else}website{/if}">
+<meta property="og:image" content="{$fbp_page.og.url_image}">
+<meta property="og:url" content="{if isset($fbp_page.og.url)}{$fbp_page.og.url}{else}{$smarty.server.REQUEST_URI}{/if}">
+
 {if $fbp.async_script}
 <div id="fb-root"></div>
