[8275] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | FacebookPlug - a Piwigo Plugin | |
---|
[8425] | 4 | // | Copyright (C) 2010-2011 Ruben ARNAUD - rub@piwigo.org | |
---|
[8275] | 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 | |
---|
[8435] | 26 | function fbp_get_fb_language() |
---|
| 27 | { |
---|
| 28 | global $user; |
---|
| 29 | |
---|
| 30 | // Array compute by plugins/FacebookPlug/tools/check_language.php script |
---|
| 31 | $valid_fb_languages = array ( 0 => 'ca_ES', 1 => 'cs_CZ', 2 => 'da_DK', 3 => 'de_DE', 4 => 'es_ES', 5 => 'fa_IR', 6 => 'fr_CA', 7 => 'fr_FR', 8 => 'he_IL', 9 => 'hr_HR', 10 => 'hu_HU', 11 => 'it_IT', 12 => 'ja_JP', 13 => 'ka_GE', 14 => 'lv_LV', 15 => 'mk_MK', 16 => 'nl_NL', 17 => 'pl_PL', 18 => 'pt_BR', 19 => 'pt_PT', 20 => 'ro_RO', 21 => 'ru_RU', 22 => 'sk_SK', 23 => 'sr_RS', 24 => 'sv_SE', 25 => 'tr_TR', 26 => 'vi_VN', 27 => 'zh_CN', ); |
---|
| 32 | |
---|
| 33 | // User language |
---|
| 34 | $language = $user['language']; |
---|
| 35 | if (! in_array($language, $valid_fb_languages)) |
---|
| 36 | { |
---|
| 37 | $code_lang = substr($language, 0, 2); |
---|
| 38 | // Compose a language |
---|
| 39 | $language = $code_lang.'_'.strtoupper($code_lang); |
---|
| 40 | if (! in_array($language, $valid_fb_languages)) |
---|
| 41 | { |
---|
| 42 | // Search a language |
---|
| 43 | foreach ($valid_fb_languages as $valid_fb_language) |
---|
| 44 | { |
---|
| 45 | if ($code_lang == substr($valid_fb_language, 0, 2)) |
---|
| 46 | { |
---|
| 47 | return $valid_fb_language; |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | // default language |
---|
| 51 | $language = 'en_US'; |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | return $language; |
---|
| 56 | } |
---|
| 57 | |
---|
[8275] | 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 | { |
---|
[8395] | 74 | global $template, $conf, $user, $page; |
---|
[8275] | 75 | |
---|
[8436] | 76 | // Lingua |
---|
| 77 | load_language('common.lang', FBP_DIR.'/'); |
---|
| 78 | |
---|
[8395] | 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 |
---|
[8435] | 86 | $template->assign('FACEBOOK_LANGUAGE', fbp_get_fb_language()); |
---|
[8436] | 87 | $template->assign('FBP_PATH', FBP_PATH); |
---|
[8440] | 88 | $template->assign('FBP_SCRIPT_BASENAME', script_basename()); |
---|
[8395] | 89 | $template->assign('fbp', $conf['fbp']); |
---|
[8400] | 90 | //~ $template->smarty->register_modifier('boolean_to_string', 'boolean_to_string'); |
---|
[8395] | 91 | } |
---|
| 92 | } |
---|
[8275] | 93 | |
---|
[8395] | 94 | function fbp_loc_end_page_header() |
---|
| 95 | { |
---|
| 96 | global $template, $conf, $user, $page; |
---|
| 97 | |
---|
| 98 | if ($page['fbp']['do_facebook_init']) |
---|
[8375] | 99 | { |
---|
| 100 | // set prefilter |
---|
| 101 | $template->set_prefilter('header', 'fbp_header'); |
---|
[8275] | 102 | |
---|
[8402] | 103 | if (empty($page['fbp']['url'])) |
---|
[8395] | 104 | { |
---|
[8402] | 105 | $page['fbp']['url'] = get_absolute_root_url().script_basename(); |
---|
[8395] | 106 | if ($conf['php_extension_in_urls']) |
---|
| 107 | { |
---|
[8402] | 108 | $page['fbp']['url'] .= '.php'; |
---|
[8395] | 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | $template->assign('fbp_page', $page['fbp']); |
---|
| 113 | |
---|
[8375] | 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 | |
---|
[8395] | 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->block_html_head('', '<link rel="stylesheet" type="text/css" href="'.FBP_PATH.'/css/fbp.css">', $smarty, $repeat); |
---|
| 124 | } |
---|
[8375] | 125 | } |
---|
[8275] | 126 | } |
---|
| 127 | |
---|
[8366] | 128 | function fbp_do_facebook_init($do_it) |
---|
| 129 | { |
---|
| 130 | global $conf; |
---|
[8275] | 131 | |
---|
[8366] | 132 | return |
---|
| 133 | $do_it |
---|
| 134 | or |
---|
| 135 | ( |
---|
| 136 | ( |
---|
| 137 | (script_basename() == 'picture') |
---|
| 138 | and |
---|
[8440] | 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']) |
---|
[8366] | 140 | ) |
---|
[8302] | 141 | or |
---|
[8366] | 142 | ( |
---|
| 143 | (script_basename() == 'index') |
---|
| 144 | and |
---|
[8436] | 145 | ($conf['fbp']['social_plugin_activity_feed']['enabled'] or $conf['fbp']['social_plugin_like_box']['enabled'] or $conf['fbp']['share_album']) |
---|
[8366] | 146 | ) |
---|
[8386] | 147 | or |
---|
| 148 | ( |
---|
| 149 | (script_basename() == 'admin') |
---|
| 150 | and |
---|
[8387] | 151 | (isset($_GET['page']) and $_GET['page'] == 'plugin') |
---|
[8386] | 152 | and |
---|
[8387] | 153 | (isset($_GET['section']) and strtok($_GET['section'], '/') == 'FacebookPlug') |
---|
[8386] | 154 | ) |
---|
[8302] | 155 | ) |
---|
[8366] | 156 | ; |
---|
| 157 | } |
---|
| 158 | |
---|
[8420] | 159 | function fbp_is_facebook_ip() |
---|
| 160 | { |
---|
| 161 | foreach (array( |
---|
| 162 | FBP_IP_FB, |
---|
| 163 | //~ '127.0', |
---|
| 164 | ) as $ip_fb) |
---|
| 165 | { |
---|
| 166 | if (preg_match('/'.$ip_fb. '/', $_SERVER["REMOTE_ADDR"])) |
---|
| 167 | { |
---|
| 168 | return true; |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | return false; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | function ftp_loc_end_section_init() |
---|
| 175 | { |
---|
| 176 | global $conf, $page, $user; |
---|
| 177 | |
---|
| 178 | // No restristion for facebook user |
---|
| 179 | if ( |
---|
| 180 | $page['fbp']['do_facebook_init'] |
---|
| 181 | and |
---|
| 182 | is_a_guest() |
---|
| 183 | and |
---|
| 184 | $conf['fbp']['allow_fb_access_private_page'] |
---|
| 185 | and |
---|
| 186 | fbp_is_facebook_ip() |
---|
| 187 | ) |
---|
| 188 | { |
---|
| 189 | global $user, $header_notes; |
---|
| 190 | |
---|
| 191 | // Notes |
---|
| 192 | $header_notes[] = 'Facebook robot detected, guest can access private page'; |
---|
| 193 | // Allow guest access |
---|
| 194 | $conf['guest_access'] = true; |
---|
| 195 | // No forbidden categorie |
---|
| 196 | $user['forbidden_categories'] = ''; |
---|
| 197 | $user['level'] = max($conf['available_permission_levels']); |
---|
| 198 | switch (script_basename()) |
---|
| 199 | { |
---|
| 200 | case 'picture': |
---|
| 201 | if (isset($page['image_id'])) |
---|
| 202 | { |
---|
| 203 | $page['rank_of'][$page['image_id']] = 0; |
---|
| 204 | $page['items'] = array_flip($page['rank_of']); |
---|
| 205 | } |
---|
| 206 | break; |
---|
| 207 | case 'index': |
---|
| 208 | if (isset($page['category']['representative_picture_id'])) |
---|
| 209 | { |
---|
| 210 | fbp_loc_begin_index_category_thumbnails(array($page['category'])); |
---|
| 211 | } |
---|
| 212 | break; |
---|
| 213 | } |
---|
| 214 | //~ else if $page['category']['id'] |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | |
---|
[8395] | 218 | add_event_handler('init', 'fbp_init'); |
---|
| 219 | add_event_handler('loc_end_page_header', 'fbp_loc_end_page_header'); |
---|
[8420] | 220 | add_event_handler('fbp_do_facebook_init', 'fbp_do_facebook_init'); |
---|
| 221 | add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init'); |
---|
[8275] | 222 | |
---|
| 223 | ?> |
---|