source: extensions/FacebookPlug/Plugin/picture.inc.php @ 8218

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

Try to authorize Facebook to read private picture page.

  • Property svn:eol-style set to LF
File size: 4.7 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_AddSocial($content, &$smarty)
27{
28  // iframe implementation
29/*  $fbp_content = '
30<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>
31';*/
32
33  // XFBML implementation
34  // async method
35/*  $fbp_content = '
36<div id="fb-root"></div> 
37<script>
38{literal}
39  window.fbAsyncInit = function() {
40    FB.init({
41      appId  : \'111499825588662\',
42      status : true, // check login status
43      cookie : true, // enable cookies to allow the server to access the session
44      xfbml  : true  // parse XFBML
45    });
46  };
47  (function() {
48    var e = document.createElement(\'script\');
49  {/literal}
50    e.src = document.location.protocol + \'//connect.facebook.net/{$LANGUAGE}/all.js\';
51{literal}
52    e.async = true;
53    document.getElementById(\'fb-root\').appendChild(e);
54  }());
55{/literal}
56</script>
57';*/
58  // sync method
59  $fbp_content = '
60<div id="fb-root"></div>
61<script src="http://connect.facebook.net/en_US/all.js"></script>
62<script>
63  FB.init({ldelim}
64    appId  : \'111499825588662\',
65    status : true, // check login status
66    cookie : true, // enable cookies to allow the server to access the session
67    xfbml  : true  // parse XFBML
68 {rdelim});
69</script>
70<script src="http://connect.facebook.net/{$LANGUAGE}/all.js#xfbml=1"></script>
71';
72  /*$fbp_content .= '
73<fb:like href="{$SRC_IMG}" show_faces="true" width="{$WIDTH_IMG}"></fb:like>
74';*/
75  $fbp_content .= '
76<fb:like href="{$FBP_URL_PICTURE}" show_faces="true" width="{$WIDTH_IMG}"></fb:like>
77';
78
79  return $content.$fbp_content;
80}
81
82function fbp_loc_begin_picture()
83{
84  global $template, $user, $page;
85
86  // set prefilter
87  $template->set_prefilter('header', 'fbp_header');
88  $template->set_prefilter('default_content', 'fbp_AddSocial');
89  // Always use full url for FB social plugin
90  //~ set_make_full_url();
91  // define language
92  $template->assign('LANGUAGE', $user['language']);
93  // define picture FB link
94  set_make_full_url();
95  $template->assign('FBP_URL_PICTURE', make_picture_url(array('image_id' => $page['image_id'])));
96  unset_make_full_url();
97}
98
99function fbp_loc_end_picture()
100{
101  // Restore url
102  //~ unset_make_full_url();
103}
104
105function fbp_header($content, &$smarty)
106{
107  $search = '#<html #';
108
109  $replacement = '<html xmlns:fb="http://www.facebook.com/2008/fbml" ';
110
111  return preg_replace($search, $replacement, $content);
112}
113
114add_event_handler('loc_begin_picture', 'fbp_loc_begin_picture');
115add_event_handler('loc_end_picture', 'fbp_loc_end_picture');
116
117
118function ftp_loc_end_section_init()
119{
120  global $conf, $user, $page;
121
122  $fbp_ip_check = '66.220.';
123  //~ $fbp_ip_check = '127.0.';
124  // No restristion for facebook user
125  if (preg_match('/'. $fbp_ip_check . '/', $_SERVER["REMOTE_ADDR"]))
126  {
127    //Allow guest access
128    $conf['guest_access'] = true;
129    // No forbidden categorie
130    $user['forbidden_categories'] = '';
131    $user['level'] = max($conf['available_permission_levels']);
132    $page['rank_of'][$page['image_id']] = 0;
133    $page['items'] = array_flip($page['rank_of']);
134  }
135}
136add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init');
137
138?>
Note: See TracBrowser for help on using the repository browser.