Ignore:
Timestamp:
Dec 30, 2010, 4:00:41 PM (13 years ago)
Author:
rub
Message:

Add Open Graph Meta (Like Plugin Facebook Integration)

Location:
extensions/FacebookPlug/Plugin
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/FacebookPlug/Plugin/include/header.inc.php

    r8387 r8395  
    4040function fbp_init()
    4141{
    42   global $template, $conf, $user;
     42  global $template, $conf, $user, $page;
    4343
    44   // define ID
    45   $template->assign('FACEBOOK_APP_ID', (is_numeric($conf['fbp']['facebook_app_id']) ? $conf['fbp']['facebook_app_id'] : FACEBOOK_APP_ID));
    46   // define language
    47   $template->assign('LANGUAGE', $user['language']);
    48   $template->assign('fbp', $conf['fbp']);
    49   $template->smarty->register_modifier('boolean_to_string', 'boolean_to_string');
     44  // Get init facebook
     45  $page['fbp']['do_facebook_init'] = trigger_event('fbp_do_facebook_init', $conf['fbp']['force_facebook_init']);
     46  if ($page['fbp']['do_facebook_init'])
     47  {
     48    // define ID
     49    $template->assign('FACEBOOK_APP_ID', (is_numeric($conf['fbp']['facebook_app_id']) ? $conf['fbp']['facebook_app_id'] : FACEBOOK_APP_ID));
     50    // define language
     51    $template->assign('LANGUAGE', $user['language']);
     52    $template->assign('fbp', $conf['fbp']);
     53    $template->smarty->register_modifier('boolean_to_string', 'boolean_to_string');
     54  }
     55}
    5056
    51   if (trigger_event('fbp_do_facebook_init', $conf['fbp']['force_facebook_init']))
     57function fbp_loc_end_page_header()
     58{
     59  global $template, $conf, $user, $page;
     60
     61  if ($page['fbp']['do_facebook_init'])
    5262  {
    5363    // set prefilter
    5464    $template->set_prefilter('header', 'fbp_header');
    5565
     66    if (empty($page['fbp']['og']['url']))
     67    {
     68      $page['fbp']['og']['url'] = get_absolute_root_url().script_basename();
     69      if ($conf['php_extension_in_urls'])
     70      {
     71        $page['fbp']['og']['url'] .= '.php';
     72      }
     73    }
     74    //~ if (empty($page['fbp']['url_image']))
     75    //~ {
     76    //~ // todo
     77    //~ }
     78
     79    $template->assign('fbp_page', $page['fbp']);
     80
    5681    $template->set_filename('fbp_init.fb', FBP_DIR.'/tpl/init.fb.tpl');
    5782    $template->append('head_elements', $template->parse('fbp_init.fb', true));
    58   }
    5983
    60   if (
    61       (script_basename() == 'index')
    62       and
    63       ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
    64       )
    65   {
    66     $template->block_html_head('', '<link rel="stylesheet" type="text/css" href="'.FBP_PATH.'/css/fbp.css">', $smarty, $repeat);
     84    if (
     85        (script_basename() == 'index')
     86        and
     87        ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
     88        )
     89    {
     90      $template->block_html_head('', '<link rel="stylesheet" type="text/css" href="'.FBP_PATH.'/css/fbp.css">', $smarty, $repeat);
     91    }
    6792  }
    6893}
     
    100125add_event_handler('fbp_do_facebook_init', 'fbp_do_facebook_init');
    101126
    102 //~ if (trigger_event('fbp_do_facebook_init', $conf['fbp']['force_facebook_init']))
    103 //~ {
    104   add_event_handler('init', 'fbp_init');
    105 //~ }
     127add_event_handler('init', 'fbp_init');
     128add_event_handler('loc_end_page_header', 'fbp_loc_end_page_header');
    106129
    107130?>
  • extensions/FacebookPlug/Plugin/include/index.inc.php

    r8386 r8395  
    4242}
    4343
    44 function fpt_blockmanager_apply($menu_ref_arr)
     44function fbp_blockmanager_apply($menu_ref_arr)
    4545{
    4646  global $template;
     
    5858}
    5959
     60function fbp_loc_begin_index()
     61{
     62  global $page;
     63
     64  set_make_full_url();
     65  $page['fbp']['og']['url'] = duplicate_index_url(array(''), array('start', 'flat', 'chronology_date', 'chronology_field', 'chronology_style', 'chronology_view'));
     66  unset_make_full_url();
     67}
     68
     69function fbp_loc_begin_index_category_thumbnails($categories)
     70{
     71  global $page;
     72
     73  if (count($categories) > 0)
     74  {
     75    include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     76    $category = reset($categories);
     77    $query = '
     78SELECT id, path, tn_ext
     79FROM '.IMAGES_TABLE.'
     80WHERE id = '.$category['representative_picture_id'].'
     81;';
     82    $result = pwg_query($query);
     83    if($row = pwg_db_fetch_assoc($result))
     84    {
     85      set_make_full_url();
     86      $page['fbp']['og']['url_image'] = get_element_url($row);
     87      unset_make_full_url();
     88    }
     89  }
     90}
     91
     92function fbp_loc_begin_index_thumbnails($pictures)
     93{
     94  global $page;
     95
     96  if (count($pictures) > 0)
     97  {
     98    include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
     99    $picture = reset($pictures);
     100    set_make_full_url();
     101    $page['fbp']['og']['url_image'] = get_element_url($picture);
     102    unset_make_full_url();
     103  }
     104}
    60105
    61106if ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
    62107{
    63108  add_event_handler('blockmanager_register_blocks', 'fbp_blockmanager_register_blocks', EVENT_HANDLER_PRIORITY_NEUTRAL);
    64   add_event_handler('blockmanager_apply', 'fpt_blockmanager_apply');
     109  add_event_handler('blockmanager_apply', 'fbp_blockmanager_apply');
    65110}
    66111
     112add_event_handler('loc_begin_index', 'fbp_loc_begin_index');
     113add_event_handler('loc_begin_index_category_thumbnails', 'fbp_loc_begin_index_category_thumbnails', EVENT_HANDLER_PRIORITY_NEUTRAL, 1);
     114add_event_handler('loc_begin_index_thumbnails', 'fbp_loc_begin_index_thumbnails', EVENT_HANDLER_PRIORITY_NEUTRAL, 1);
     115
    67116?>
  • extensions/FacebookPlug/Plugin/include/picture.inc.php

    r8366 r8395  
    2828  global $template, $user, $page, $conf, $picture;
    2929
    30   if ($page['slideshow'] and $conf['fbp']['social_plugin_facepile']['enabled'])
     30  if ($page['fbp']['do_facebook_init'])
    3131  {
    32     $tpl = 'social.plugin.facepile';
    33   }
    34   else if (! $page['slideshow'])
    35   {
    36     if ($conf['fbp']['social_plugin_like_button']['enabled'])
     32    // Header for each page
     33    //~ $tpls[] = 'picture.header';
     34
     35    // Specific
     36    if ($page['slideshow'] and $conf['fbp']['social_plugin_facepile']['enabled'])
    3737    {
    38       $tpl = 'social.plugin.like.button';
     38      $tpls[] = 'social.plugin.facepile';
    3939    }
    40     else if ($conf['fbp']['social_plugin_comments']['enabled'])
     40    else if (! $page['slideshow'])
    4141    {
    42       $tpl = 'social.plugin.comments';
     42      if ($conf['fbp']['social_plugin_like_button']['enabled'])
     43      {
     44        $tpls[] = 'social.plugin.like.button';
     45      }
     46      else if ($conf['fbp']['social_plugin_comments']['enabled'])
     47      {
     48        $tpls[] = 'social.plugin.comments';
     49      }
     50    }
     51
     52    // define picture FB link
     53    // Always use full url for FB social plugin
     54    set_make_full_url();
     55    if ($conf['fbp']['picture_url_type'] == 'image')
     56    {
     57      $fbp_url_picture = get_element_url($current_picture);
     58    }
     59    else
     60    {
     61      $fbp_url_picture = make_picture_url(array('image_id' => $page['image_id']));
     62    }
     63    $page['fbp']['og']['url'] = $fbp_url_picture;
     64    $page['fbp']['og']['url_image'] = get_element_url($current_picture);
     65    unset_make_full_url();
     66
     67    // Assign template
     68    $template->assign('fbp_url_picture', $fbp_url_picture);
     69    $template->assign('fbp_urlencode_picture', urlencode($fbp_url_picture));
     70
     71    // Parse TPL
     72    foreach($tpls as $tpl)
     73    {
     74      // XFBML implementation
     75      $template->set_filename($tpl, FBP_DIR.'/tpl/'.$tpl.'.tpl');
     76      $content .= $template->parse($tpl, true);
    4377    }
    4478  }
    45 
    46   if (empty($tpl))
    47   {
    48     // nothing to do
    49     return $content;
    50   }
    51 
    52   // define picture FB link
    53   // Always use full url for FB social plugin
    54   set_make_full_url();
    55   if ($conf['fbp']['picture_url_type'] == 'image')
    56   {
    57     $fbp_url_picture = get_element_url($current_picture);
    58   }
    59   else
    60   {
    61     $fbp_url_picture = make_picture_url(array('image_id' => $page['image_id']));
    62   }
    63   unset_make_full_url();
    64   $template->assign('fbp_url_picture', $fbp_url_picture);
    65   $template->assign('fbp_urlencode_picture', urlencode($fbp_url_picture));
    66 
    67   // XFBML implementation
    68   $template->set_filename($tpl, FBP_DIR.'/tpl/'.$tpl.'.tpl');
    69   $content .= $template->parse($tpl, true);
    7079
    7180  return $content;
     
    7483function ftp_loc_end_section_init()
    7584{
    76   global $conf;
     85  global $conf, $page;
    7786
    78   if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'])
     87  //~ if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'])
     88  if ($page['fbp']['do_facebook_init'])
    7989  {
    8090    if ($conf['fbp']['allow_fb_access_private_page'])
     
    97107}
    98108
    99 if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_facepile']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'])
    100 {
    101   //~ add_event_handler('loc_begin_picture', 'fbp_loc_begin_picture');
    102   add_event_handler('render_element_content', 'fbp_render_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL+1 /*in order to have picture content*/, 2);
    103   //~ add_event_handler('loc_end_picture', 'fbp_loc_end_picture');
    104   add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init');
    105 }
     109add_event_handler('render_element_content', 'fbp_render_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL+1 /*in order to have picture content*/, 2);
     110add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init');
    106111
    107112?>
  • extensions/FacebookPlug/Plugin/tpl/init.fb.tpl

    r8295 r8395  
    11<!-- By FacebookPlug a Piwigo Plugin -->
     2{if isset($fbp_page.og.title)}
     3<meta property="og:title" content="{$fbp_page.og.title|@replace:'"':' '}">
     4{else}
     5  {if (isset($REVERSE) and $REVERSE and $PAGE_TITLE == l10n('Home'))}
     6<meta property="og:title" content="{$GALLERY_TITLE|@replace:'"':' '} | {$PAGE_TITLE|@replace:'"':' '}">
     7  {else}
     8<meta property="og:title" content="{$PAGE_TITLE|@replace:'"':' '} | {$GALLERY_TITLE|@replace:'"':' '}">
     9  {/if}
     10{/if}
     11{if isset($fbp_page.og.description)}
     12<meta property="og:description" content="{$fbp_page.og.description|@replace:'"':' '}">
     13{else}
     14  {if isset($COMMENT_IMG)}
     15<meta property="og:description" content="{$COMMENT_IMG|@strip_tags:false|@replace:'"':' '}{if isset($INFO_FILE)} - {$INFO_FILE|@replace:'"':' '}{/if}">
     16  {else}
     17<meta property="og:description" content="{$PAGE_TITLE|@replace:'"':' '}{if isset($INFO_FILE)} - {$INFO_FILE|@replace:'"':' '}{/if}">
     18  {/if}
     19{/if}
     20<meta property="og:site_name" content="{if isset($fbp_page.og.site_name)}{$fbp_page.og.site_name|@replace:'"':' '}{else}{$GALLERY_TITLE|@replace:'"':' '}{/if}">
     21<meta property="fb:app_id" content="{if isset($fbp_page.og.app_id)}{$fbp_page.og.app_id}{else}{$FACEBOOK_APP_ID}{/if}">
     22<meta property="og:type" content="{if isset($fbp_page.og.type)}{$fbp_page.og.type}{else}website{/if}">
     23<meta property="og:image" content="{$fbp_page.og.url_image}">
     24<meta property="og:url" content="{if isset($fbp_page.og.url)}{$fbp_page.og.url}{else}{$smarty.server.REQUEST_URI}{/if}">
     25
    226{if $fbp.async_script}
    327<div id="fb-root"></div>
Note: See TracChangeset for help on using the changeset viewer.