source: extensions/FacebookPlug/Plugin/include/picture.inc.php @ 8254

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

Use tpl instead of XFBML on php

  • Property svn:eol-style set to LF
File size: 6.4 KB
Line 
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  global $conf;
29
30  // replace tag html
31  $search = '<html ';
32  $replacement = '<html xmlns:fb="http://www.facebook.com/2008/fbml" ';
33
34  //~ $content = preg_replace('#'.$search.'#', $replacement, $content);
35  return preg_replace('#'.$search.'#', $replacement, $content);
36  //~ $fbp_content = file_get_contents(FBP_DIR.'/tpl/init.fb.tpl');
37
38  $search = '<div id="the_page">';
39  return preg_replace('#'.$search.'#', $fbp_content.$search, $content);
40}
41
42function fbp_loc_begin_picture()
43{
44  global $template, $user, $page, $conf, $picture;
45
46  // set prefilter
47  $template->set_prefilter('header', 'fbp_header');
48
49  $template->assign('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  $template->set_filename('init.fb', FBP_DIR.'/tpl/init.fb.tpl');
56  $template->append('head_elements', $template->parse('init.fb', true));
57}
58
59function fbp_render_element_content($content, $current_picture)
60{
61  global $template, $user, $page, $conf, $picture;
62
63  if ($page['slideshow'])
64  {
65    // nothing to do on slideshow other media aren't usable
66    return $content;
67  }
68
69  if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
70  {
71    // define picture FB link
72    // Always use full url for FB social plugin
73    set_make_full_url();
74    if ($conf['fbp']['social_plugin_like_button']['url_type'] == 'image')
75    {
76      $fbp_url_picture = get_element_url($current_picture);
77    }
78    else
79    {
80      $fbp_url_picture = make_picture_url(array('image_id' => $page['image_id']));
81    }
82    unset_make_full_url();
83    $template->assign('fbp_url_picture', $fbp_url_picture);
84    //~ $template->assign('FBP_SOCIAL_PLUGIN_LIKE_BUTTON', $conf['fbp']['social_plugin_like_button']);
85    //~ $template->assign('FBP_SOCIAL_PLUGIN_LIKE_BOX', $conf['fbp']['social_plugin_like_box']);
86
87     // iframe implementation
88    /*  $$content = '
89    <iframe src="http://www.facebook.com/plugins/like.php?href={$SRC_IMG}&amp;layout=standard&amp;show_faces=true&amp;width={$WIDTH_IMG}&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:{$WIDTH_IMG}px; height:80px;" allowTransparency="true"></iframe>
90    ';*/
91    // XFBML implementation
92    //~ $content .= '
93//~ <div id="fb-xfbml">';
94    if ($conf['fbp']['social_plugin_like_button']['enabled'])
95    {
96      //~ $content .= '
97//~ <div id="fb-xfbml">
98//~ <fb:like href="'.$fbp_url_picture.'" layout="'.$conf['fbp']['social_plugin_like_button']['layout'].'" show_faces="'.boolean_to_string($conf['fbp']['social_plugin_like_button']['show_faces']).'" width="'.@$current_picture['scaled_width'].'" action="'.$conf['fbp']['social_plugin_like_button']['action'].'" colorscheme="'.$conf['fbp']['social_plugin_like_button']['colorscheme'].'"></fb:like>
99//~ </div>';
100      $template->set_filename('social.plugin.like.button', FBP_DIR.'/tpl/social.plugin.like.button.tpl');
101      $content .= $template->parse('social.plugin.like.button', true);
102    }
103    if ($conf['fbp']['social_plugin_like_box']['enabled'])
104    {
105      //~ $content .= '
106//~ <div id="fb-xfbml">
107//~ <fb:like-box href="'.$fbp_url_picture.'" width="'.@$current_picture['scaled_width'].'" show_faces="'.boolean_to_string($conf['fbp']['social_plugin_like_box']['show_faces']).'" stream="'.boolean_to_string($conf['fbp']['social_plugin_like_box']['stream']).'" header="'.boolean_to_string($conf['fbp']['social_plugin_like_box']['header']).'"></fb:like-box>
108//~ </div>';
109      $template->set_filename('social.plugin.like.box', FBP_DIR.'/tpl/social.plugin.like.box.tpl');
110      $content .= $template->parse('social.plugin.like.box', true);
111    }
112
113    //~ $content .= '
114//~ </div>';
115}
116
117  return $content;
118}
119
120function ftp_loc_end_section_init()
121{
122  global $conf;
123
124  if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
125  {
126    if ($conf['fbp']['allow_fb_access_private_page'])
127    {
128      global $user, $page;
129
130      // No restristion for facebook user
131      if (preg_match('/'.FBP_IP_FB. '/', $_SERVER["REMOTE_ADDR"]))
132      {
133        //Allow guest access
134        $conf['guest_access'] = true;
135        // No forbidden categorie
136        $user['forbidden_categories'] = '';
137        $user['level'] = max($conf['available_permission_levels']);
138        $page['rank_of'][$page['image_id']] = 0;
139        $page['items'] = array_flip($page['rank_of']);
140      }
141    }
142  }
143}
144
145if ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'])
146{
147  add_event_handler('loc_begin_picture', 'fbp_loc_begin_picture');
148  add_event_handler('render_element_content', 'fbp_render_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL+1 /*in order to have picture content*/, 2);
149  //~ add_event_handler('loc_end_picture', 'fbp_loc_end_picture');
150  add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init');
151}
152
153?>
Note: See TracBrowser for help on using the repository browser.