1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | FacebookPlug - a Piwigo Plugin | |
---|
4 | // | Copyright (C) 2010-2011 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 | |
---|
21 | if (!defined('PHPWG_ROOT_PATH')) |
---|
22 | { |
---|
23 | die('Hacking attempt!'); |
---|
24 | } |
---|
25 | |
---|
26 | function 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 | |
---|
40 | function fbp_init() |
---|
41 | { |
---|
42 | global $template, $conf, $user, $page; |
---|
43 | |
---|
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 | } |
---|
56 | |
---|
57 | function fbp_loc_end_page_header() |
---|
58 | { |
---|
59 | global $template, $conf, $user, $page; |
---|
60 | |
---|
61 | if ($page['fbp']['do_facebook_init']) |
---|
62 | { |
---|
63 | // set prefilter |
---|
64 | $template->set_prefilter('header', 'fbp_header'); |
---|
65 | |
---|
66 | if (empty($page['fbp']['url'])) |
---|
67 | { |
---|
68 | $page['fbp']['url'] = get_absolute_root_url().script_basename(); |
---|
69 | if ($conf['php_extension_in_urls']) |
---|
70 | { |
---|
71 | $page['fbp']['url'] .= '.php'; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | $template->assign('fbp_page', $page['fbp']); |
---|
76 | |
---|
77 | $template->set_filename('fbp_init.fb', FBP_DIR.'/tpl/init.fb.tpl'); |
---|
78 | $template->append('head_elements', $template->parse('fbp_init.fb', true)); |
---|
79 | |
---|
80 | if ( |
---|
81 | (script_basename() == 'index') |
---|
82 | and |
---|
83 | ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled']) |
---|
84 | ) |
---|
85 | { |
---|
86 | $template->block_html_head('', '<link rel="stylesheet" type="text/css" href="'.FBP_PATH.'/css/fbp.css">', $smarty, $repeat); |
---|
87 | } |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | function fbp_do_facebook_init($do_it) |
---|
92 | { |
---|
93 | global $conf; |
---|
94 | |
---|
95 | return |
---|
96 | $do_it |
---|
97 | or |
---|
98 | ( |
---|
99 | ( |
---|
100 | (script_basename() == 'picture') |
---|
101 | and |
---|
102 | ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_facepile']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled']) |
---|
103 | ) |
---|
104 | or |
---|
105 | ( |
---|
106 | (script_basename() == 'index') |
---|
107 | and |
---|
108 | ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled']) |
---|
109 | ) |
---|
110 | or |
---|
111 | ( |
---|
112 | (script_basename() == 'admin') |
---|
113 | and |
---|
114 | (isset($_GET['page']) and $_GET['page'] == 'plugin') |
---|
115 | and |
---|
116 | (isset($_GET['section']) and strtok($_GET['section'], '/') == 'FacebookPlug') |
---|
117 | ) |
---|
118 | ) |
---|
119 | ; |
---|
120 | } |
---|
121 | |
---|
122 | function fbp_is_facebook_ip() |
---|
123 | { |
---|
124 | foreach (array( |
---|
125 | FBP_IP_FB, |
---|
126 | //~ '127.0', |
---|
127 | ) as $ip_fb) |
---|
128 | { |
---|
129 | if (preg_match('/'.$ip_fb. '/', $_SERVER["REMOTE_ADDR"])) |
---|
130 | { |
---|
131 | return true; |
---|
132 | } |
---|
133 | } |
---|
134 | return false; |
---|
135 | } |
---|
136 | |
---|
137 | function ftp_loc_end_section_init() |
---|
138 | { |
---|
139 | global $conf, $page, $user; |
---|
140 | |
---|
141 | // No restristion for facebook user |
---|
142 | if ( |
---|
143 | $page['fbp']['do_facebook_init'] |
---|
144 | and |
---|
145 | is_a_guest() |
---|
146 | and |
---|
147 | $conf['fbp']['allow_fb_access_private_page'] |
---|
148 | and |
---|
149 | fbp_is_facebook_ip() |
---|
150 | ) |
---|
151 | { |
---|
152 | global $user, $header_notes; |
---|
153 | |
---|
154 | // Notes |
---|
155 | $header_notes[] = 'Facebook robot detected, guest can access private page'; |
---|
156 | // Allow guest access |
---|
157 | $conf['guest_access'] = true; |
---|
158 | // No forbidden categorie |
---|
159 | $user['forbidden_categories'] = ''; |
---|
160 | $user['level'] = max($conf['available_permission_levels']); |
---|
161 | switch (script_basename()) |
---|
162 | { |
---|
163 | case 'picture': |
---|
164 | if (isset($page['image_id'])) |
---|
165 | { |
---|
166 | $page['rank_of'][$page['image_id']] = 0; |
---|
167 | $page['items'] = array_flip($page['rank_of']); |
---|
168 | } |
---|
169 | break; |
---|
170 | case 'index': |
---|
171 | if (isset($page['category']['representative_picture_id'])) |
---|
172 | { |
---|
173 | fbp_loc_begin_index_category_thumbnails(array($page['category'])); |
---|
174 | } |
---|
175 | break; |
---|
176 | } |
---|
177 | //~ else if $page['category']['id'] |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | add_event_handler('init', 'fbp_init'); |
---|
182 | add_event_handler('loc_end_page_header', 'fbp_loc_end_page_header'); |
---|
183 | add_event_handler('fbp_do_facebook_init', 'fbp_do_facebook_init'); |
---|
184 | add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init'); |
---|
185 | |
---|
186 | ?> |
---|