source: extensions/FacebookPlug/Plugin/include/header.inc.php @ 8395

Last change on this file since 8395 was 8395, checked in by rub, 13 years ago

Add Open Graph Meta (Like Plugin Facebook Integration)

  • Property svn:eol-style set to LF
File size: 4.5 KB
RevLine 
[8275]1<?php
2// +-----------------------------------------------------------------------+
3// | FacebookPlug - a Piwigo Plugin                                        |
4// | Copyright (C) 2010 Ruben ARNAUD - rub@piwigo.org                      |
5// +-----------------------------------------------------------------------+
6// | This program is free software; you can redistribute it and/or modify  |
7// | it under the terms of the GNU General Public License as published by  |
8// | the Free Software Foundation                                          |
9// |                                                                       |
10// | This program is distributed in the hope that it will be useful, but   |
11// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13// | General Public License for more details.                              |
14// |                                                                       |
15// | You should have received a copy of the GNU General Public License     |
16// | along with this program; if not, write to the Free Software           |
17// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18// | USA.                                                                  |
19// +-----------------------------------------------------------------------+
20
21if (!defined('PHPWG_ROOT_PATH'))
22{
23  die('Hacking attempt!');
24}
25
26function fbp_header($content, &$smarty)
27{
28  // replace tag html
29  $search = '<html ';
30  $replacement = '<html xmlns:fb="http://www.facebook.com/2008/fbml" ';
31
32  //~ $content = preg_replace('#'.$search.'#', $replacement, $content);
33  return preg_replace('#'.$search.'#', $replacement, $content);
34  //~ $fbp_content = file_get_contents(FBP_DIR.'/tpl/init.fb.tpl');
35
36  //~ $search = '<div id="the_page">';
37  //~ return preg_replace('#'.$search.'#', $fbp_content.$search, $content);
38}
39
40function fbp_init()
41{
[8395]42  global $template, $conf, $user, $page;
[8275]43
[8395]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}
[8275]56
[8395]57function fbp_loc_end_page_header()
58{
59  global $template, $conf, $user, $page;
60
61  if ($page['fbp']['do_facebook_init'])
[8375]62  {
63    // set prefilter
64    $template->set_prefilter('header', 'fbp_header');
[8275]65
[8395]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
[8375]81    $template->set_filename('fbp_init.fb', FBP_DIR.'/tpl/init.fb.tpl');
82    $template->append('head_elements', $template->parse('fbp_init.fb', true));
83
[8395]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    }
[8375]92  }
[8275]93}
94
[8366]95function fbp_do_facebook_init($do_it)
96{
97  global $conf;
[8275]98
[8366]99  return 
100    $do_it
101  or
102    (
103      (
104        (script_basename() == 'picture')
105        and
106        ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_facepile']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'])
107      )
[8302]108      or
[8366]109      (
110        (script_basename() == 'index')
111        and
[8386]112        ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
[8366]113      )
[8386]114      or
115      (
116        (script_basename() == 'admin')
117        and
[8387]118        (isset($_GET['page']) and $_GET['page'] == 'plugin')
[8386]119        and
[8387]120        (isset($_GET['section']) and strtok($_GET['section'], '/') == 'FacebookPlug')
[8386]121      )
[8302]122    )
[8366]123  ;
124}
125add_event_handler('fbp_do_facebook_init', 'fbp_do_facebook_init');
126
[8395]127add_event_handler('init', 'fbp_init');
128add_event_handler('loc_end_page_header', 'fbp_loc_end_page_header');
[8275]129
130?>
Note: See TracBrowser for help on using the repository browser.