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_get_fb_locale() |
---|
27 | { |
---|
28 | global $user; |
---|
29 | |
---|
30 | // Array compute by plugins/FacebookPlug/tools/check_language.php script |
---|
31 | $valid_fb_locales = array ( 0 => 'af_ZA', 1 => 'ar_AR', 2 => 'ay_BO', 3 => 'az_AZ', 4 => 'be_BY', 5 => 'bg_BG', 6 => 'bn_IN', 7 => 'bs_BA', 8 => 'ca_ES', 9 => 'ck_US', 10 => 'cs_CZ', 11 => 'cy_GB', 12 => 'da_DK', 13 => 'de_DE', 14 => 'el_GR', 15 => 'en_GB', 16 => 'en_PI', 17 => 'en_UD', 18 => 'en_US', 19 => 'eo_EO', 20 => 'es_CL', 21 => 'es_CO', 22 => 'es_ES', 23 => 'es_LA', 24 => 'es_MX', 25 => 'es_VE', 26 => 'et_EE', 27 => 'eu_ES', 28 => 'fa_IR', 29 => 'fb_FI', 30 => 'fb_LT', 31 => 'fi_FI', 32 => 'fo_FO', 33 => 'fr_CA', 34 => 'fr_FR', 35 => 'ga_IE', 36 => 'gl_ES', 37 => 'gn_PY', 38 => 'gu_IN', 39 => 'he_IL', 40 => 'hi_IN', 41 => 'hr_HR', 42 => 'hu_HU', 43 => 'hy_AM', 44 => 'id_ID', 45 => 'is_IS', 46 => 'it_IT', 47 => 'ja_JP', 48 => 'jv_ID', 49 => 'ka_GE', 50 => 'kk_KZ', 51 => 'km_KH', 52 => 'kn_IN', 53 => 'ko_KR', 54 => 'ku_TR', 55 => 'la_VA', 56 => 'li_NL', 57 => 'lt_LT', 58 => 'lv_LV', 59 => 'mg_MG', 60 => 'mk_MK', 61 => 'ml_IN', 62 => 'mn_MN', 63 => 'mr_IN', 64 => 'ms_MY', 65 => 'mt_MT', 66 => 'nb_NO', 67 => 'ne_NP', 68 => 'nl_BE', 69 => 'nl_NL', 70 => 'nn_NO', 71 => 'pa_IN', 72 => 'pl_PL', 73 => 'ps_AF', 74 => 'pt_BR', 75 => 'pt_PT', 76 => 'qu_PE', 77 => 'rm_CH', 78 => 'ro_RO', 79 => 'ru_RU', 80 => 'sa_IN', 81 => 'se_NO', 82 => 'sk_SK', 83 => 'sl_SI', 84 => 'so_SO', 85 => 'sq_AL', 86 => 'sr_RS', 87 => 'sv_SE', 88 => 'sw_KE', 89 => 'sy_SY', 90 => 'ta_IN', 91 => 'te_IN', 92 => 'tg_TJ', 93 => 'th_TH', 94 => 'tl_PH', 95 => 'tl_ST', 96 => 'tr_TR', 97 => 'tt_RU', 98 => 'uk_UA', 99 => 'ur_PK', 100 => 'uz_UZ', 101 => 'vi_VN', 102 => 'xh_ZA', 103 => 'yi_DE', 104 => 'zh_CN', 105 => 'zh_HK', 106 => 'zh_TW', 107 => 'zu_ZA', ); |
---|
32 | |
---|
33 | // User language |
---|
34 | $locale = $user['language']; |
---|
35 | if (! in_array($locale, $valid_fb_locales)) |
---|
36 | { |
---|
37 | $code_lang = substr($locale, 0, 2); |
---|
38 | // Compose a locale |
---|
39 | $locale = $code_lang.'_'.strtoupper($code_lang); |
---|
40 | if (! in_array($locale, $valid_fb_locales)) |
---|
41 | { |
---|
42 | // Search a locale |
---|
43 | foreach ($valid_fb_locales as $valid_fb_locale) |
---|
44 | { |
---|
45 | if ($code_lang == substr($valid_fb_locale, 0, 2)) |
---|
46 | { |
---|
47 | return $valid_fb_locale; |
---|
48 | } |
---|
49 | } |
---|
50 | // default locale |
---|
51 | $locale = 'en_US'; |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | return $locale; |
---|
56 | } |
---|
57 | |
---|
58 | function fbp_header($content, &$smarty) |
---|
59 | { |
---|
60 | // replace tag html |
---|
61 | $search = '<html '; |
---|
62 | $replacement = '<html xmlns:fb="http://www.facebook.com/2008/fbml" '; |
---|
63 | |
---|
64 | //~ $content = preg_replace('#'.$search.'#', $replacement, $content); |
---|
65 | return preg_replace('#'.$search.'#', $replacement, $content); |
---|
66 | //~ $fbp_content = file_get_contents(FBP_DIR.'/tpl/init.fb.tpl'); |
---|
67 | |
---|
68 | //~ $search = '<div id="the_page">'; |
---|
69 | //~ return preg_replace('#'.$search.'#', $fbp_content.$search, $content); |
---|
70 | } |
---|
71 | |
---|
72 | function fbp_init() |
---|
73 | { |
---|
74 | global $template, $conf, $user, $page; |
---|
75 | |
---|
76 | // Lingua |
---|
77 | load_language('common.lang', FBP_DIR.'/'); |
---|
78 | |
---|
79 | // Get init facebook |
---|
80 | $page['fbp']['do_facebook_init'] = trigger_event('fbp_do_facebook_init', $conf['fbp']['force_facebook_init']); |
---|
81 | if ($page['fbp']['do_facebook_init']) |
---|
82 | { |
---|
83 | // define ID |
---|
84 | $template->assign('FACEBOOK_APP_ID', (is_numeric($conf['fbp']['facebook_app_id']) ? $conf['fbp']['facebook_app_id'] : FACEBOOK_APP_ID)); |
---|
85 | // define language |
---|
86 | $template->assign('FACEBOOK_LOCALE', fbp_get_fb_locale()); |
---|
87 | $template->assign('FBP_PATH', FBP_PATH); |
---|
88 | $template->assign('FBP_SCRIPT_BASENAME', script_basename()); |
---|
89 | $template->assign('fbp', $conf['fbp']); |
---|
90 | //~ $template->smarty->register_modifier('boolean_to_string', 'boolean_to_string'); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | function fbp_loc_end_page_header() |
---|
95 | { |
---|
96 | global $template, $conf, $user, $page; |
---|
97 | |
---|
98 | if ($page['fbp']['do_facebook_init']) |
---|
99 | { |
---|
100 | // set prefilter |
---|
101 | $template->set_prefilter('header', 'fbp_header'); |
---|
102 | |
---|
103 | if (empty($page['fbp']['url'])) |
---|
104 | { |
---|
105 | $page['fbp']['url'] = get_absolute_root_url().script_basename(); |
---|
106 | if ($conf['php_extension_in_urls']) |
---|
107 | { |
---|
108 | $page['fbp']['url'] .= '.php'; |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | $template->assign('fbp_page', $page['fbp']); |
---|
113 | |
---|
114 | $template->set_filename('fbp_init.fb', FBP_DIR.'/tpl/init.fb.tpl'); |
---|
115 | $template->append('head_elements', $template->parse('fbp_init.fb', true)); |
---|
116 | |
---|
117 | if ( |
---|
118 | (script_basename() == 'index') |
---|
119 | and |
---|
120 | ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled']) |
---|
121 | ) |
---|
122 | { |
---|
123 | $template->func_combine_css(array('path' => FBP_PATH.'/css/fbp.css')); |
---|
124 | } |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | function fbp_do_facebook_init($do_it) |
---|
129 | { |
---|
130 | global $conf; |
---|
131 | |
---|
132 | return |
---|
133 | $do_it |
---|
134 | or |
---|
135 | ( |
---|
136 | ( |
---|
137 | (script_basename() == 'picture') |
---|
138 | and |
---|
139 | ($conf['fbp']['social_plugin_like_button']['enabled'] or $conf['fbp']['social_plugin_facepile']['enabled'] or $conf['fbp']['social_plugin_comments']['enabled'] or $conf['fbp']['share_picture'] or $conf['fbp']['upload_picture']) |
---|
140 | ) |
---|
141 | or |
---|
142 | ( |
---|
143 | (script_basename() == 'index') |
---|
144 | and |
---|
145 | ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'] or $conf['fbp']['share_album']) |
---|
146 | ) |
---|
147 | or |
---|
148 | ( |
---|
149 | (script_basename() == 'admin') |
---|
150 | and |
---|
151 | ( |
---|
152 | (isset($_GET['page']) and preg_match('/^plugin-FacebookPlug(?:-(.*))?$/', $_GET['page'])) |
---|
153 | or |
---|
154 | ( |
---|
155 | (isset($_GET['page']) and $_GET['page'] == 'plugin') |
---|
156 | and |
---|
157 | (isset($_GET['section']) and strtok($_GET['section'], '/') == 'FacebookPlug') |
---|
158 | ) |
---|
159 | ) |
---|
160 | ) |
---|
161 | ) |
---|
162 | ; |
---|
163 | } |
---|
164 | |
---|
165 | function fbp_is_facebook_ip() |
---|
166 | { |
---|
167 | foreach (array( |
---|
168 | FBP_IP_FB, |
---|
169 | //~ '127.0', |
---|
170 | ) as $ip_fb) |
---|
171 | { |
---|
172 | if (preg_match('/'.$ip_fb. '/', $_SERVER["REMOTE_ADDR"])) |
---|
173 | { |
---|
174 | return true; |
---|
175 | } |
---|
176 | } |
---|
177 | return false; |
---|
178 | } |
---|
179 | |
---|
180 | function ftp_loc_end_section_init() |
---|
181 | { |
---|
182 | global $conf, $page, $user; |
---|
183 | |
---|
184 | // No restristion for facebook user |
---|
185 | if ( |
---|
186 | $page['fbp']['do_facebook_init'] |
---|
187 | and |
---|
188 | is_a_guest() |
---|
189 | and |
---|
190 | $conf['fbp']['allow_fb_access_private_page'] |
---|
191 | and |
---|
192 | fbp_is_facebook_ip() |
---|
193 | ) |
---|
194 | { |
---|
195 | global $user, $header_notes; |
---|
196 | |
---|
197 | // Notes |
---|
198 | $header_notes[] = 'Facebook robot detected, guest can access private page'; |
---|
199 | // Allow guest access |
---|
200 | $conf['guest_access'] = true; |
---|
201 | // No forbidden categorie |
---|
202 | $user['forbidden_categories'] = ''; |
---|
203 | $user['level'] = max($conf['available_permission_levels']); |
---|
204 | switch (script_basename()) |
---|
205 | { |
---|
206 | case 'picture': |
---|
207 | if (isset($page['image_id'])) |
---|
208 | { |
---|
209 | $page['rank_of'][$page['image_id']] = 0; |
---|
210 | $page['items'] = array_flip($page['rank_of']); |
---|
211 | } |
---|
212 | break; |
---|
213 | case 'index': |
---|
214 | if (isset($page['category']['representative_picture_id'])) |
---|
215 | { |
---|
216 | fbp_loc_begin_index_category_thumbnails(array($page['category'])); |
---|
217 | } |
---|
218 | break; |
---|
219 | } |
---|
220 | //~ else if $page['category']['id'] |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | add_event_handler('init', 'fbp_init'); |
---|
225 | add_event_handler('loc_end_page_header', 'fbp_loc_end_page_header'); |
---|
226 | add_event_handler('fbp_do_facebook_init', 'fbp_do_facebook_init'); |
---|
227 | add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init'); |
---|
228 | |
---|
229 | ?> |
---|