[8213] | 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 | |
---|
| 21 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 22 | { |
---|
| 23 | die('Hacking attempt!'); |
---|
| 24 | } |
---|
| 25 | |
---|
[8241] | 26 | function fbp_header($content, &$smarty) |
---|
[8213] | 27 | { |
---|
[8241] | 28 | global $conf; |
---|
[8215] | 29 | |
---|
[8241] | 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 | |
---|
| 36 | // Piwigo init |
---|
| 37 | if ($conf['fbp']['async_script']) |
---|
| 38 | { |
---|
| 39 | // async method |
---|
| 40 | $fbp_content = ' |
---|
| 41 | <div id="fb-root"></div> |
---|
[8215] | 42 | <script> |
---|
| 43 | {literal} |
---|
| 44 | window.fbAsyncInit = function() { |
---|
| 45 | FB.init({ |
---|
[8241] | 46 | appId : \''.FACEBOOK_APP_ID.'\', |
---|
[8215] | 47 | status : true, // check login status |
---|
| 48 | cookie : true, // enable cookies to allow the server to access the session |
---|
| 49 | xfbml : true // parse XFBML |
---|
| 50 | }); |
---|
| 51 | }; |
---|
| 52 | (function() { |
---|
| 53 | var e = document.createElement(\'script\'); |
---|
| 54 | {/literal} |
---|
[8216] | 55 | e.src = document.location.protocol + \'//connect.facebook.net/{$LANGUAGE}/all.js\'; |
---|
[8215] | 56 | {literal} |
---|
| 57 | e.async = true; |
---|
| 58 | document.getElementById(\'fb-root\').appendChild(e); |
---|
| 59 | }()); |
---|
| 60 | {/literal} |
---|
| 61 | </script> |
---|
[8241] | 62 | '; |
---|
| 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
| 66 | // sync method |
---|
| 67 | $fbp_content = ' |
---|
[8215] | 68 | <div id="fb-root"></div> |
---|
| 69 | <script src="http://connect.facebook.net/en_US/all.js"></script> |
---|
| 70 | <script> |
---|
| 71 | FB.init({ldelim} |
---|
[8241] | 72 | appId : \''.FACEBOOK_APP_ID.'\', |
---|
[8215] | 73 | status : true, // check login status |
---|
| 74 | cookie : true, // enable cookies to allow the server to access the session |
---|
| 75 | xfbml : true // parse XFBML |
---|
| 76 | {rdelim}); |
---|
| 77 | </script> |
---|
[8216] | 78 | <script src="http://connect.facebook.net/{$LANGUAGE}/all.js#xfbml=1"></script> |
---|
[8213] | 79 | '; |
---|
[8241] | 80 | } |
---|
| 81 | |
---|
| 82 | $search = '<div id="the_page">'; |
---|
[8243] | 83 | return preg_replace('#'.$search.'#', $fbp_content.$search, $content); |
---|
[8241] | 84 | } |
---|
| 85 | |
---|
| 86 | function fbp_add_social($content, &$smarty) |
---|
| 87 | { |
---|
| 88 | global $conf; |
---|
| 89 | $fbp_content .= '<div id="fb-xfbml">'; |
---|
| 90 | |
---|
| 91 | // iframe implementation |
---|
| 92 | /* $fbp_content = ' |
---|
| 93 | <iframe src="http://www.facebook.com/plugins/like.php?href={$SRC_IMG}&layout=standard&show_faces=true&width={$WIDTH_IMG}&action=like&colorscheme=light&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:{$WIDTH_IMG}px; height:80px;" allowTransparency="true"></iframe> |
---|
| 94 | ';*/ |
---|
| 95 | |
---|
| 96 | // XFBML implementation |
---|
[8216] | 97 | /*$fbp_content .= ' |
---|
| 98 | <fb:like href="{$SRC_IMG}" show_faces="true" width="{$WIDTH_IMG}"></fb:like> |
---|
| 99 | ';*/ |
---|
[8215] | 100 | $fbp_content .= ' |
---|
[8241] | 101 | <fb:like href="{$FBP_URL_PICTURE}" layout="{$FBP_SOCIAL_PLUGIN_LIKE_BUTTON.layout}" show_faces="{if $FBP_SOCIAL_PLUGIN_LIKE_BUTTON.show_faces}true{else}false{/if}" width="{$WIDTH_IMG}" action="{$FBP_SOCIAL_PLUGIN_LIKE_BUTTON.action}" colorscheme="{$FBP_SOCIAL_PLUGIN_LIKE_BUTTON.colorscheme}"></fb:like> |
---|
[8215] | 102 | '; |
---|
[8216] | 103 | |
---|
[8241] | 104 | $fbp_content .= '</div>'; |
---|
| 105 | |
---|
[8213] | 106 | return $content.$fbp_content; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | function fbp_loc_begin_picture() |
---|
| 110 | { |
---|
[8241] | 111 | global $template, $user, $page, $conf, $picture; |
---|
[8215] | 112 | |
---|
[8213] | 113 | // set prefilter |
---|
[8215] | 114 | $template->set_prefilter('header', 'fbp_header'); |
---|
[8241] | 115 | //~ $template->set_prefilter('header', 'fbp_add_fb_init'); |
---|
| 116 | if ($conf['fbp']['social_plugin_like_button']['enabled']) |
---|
| 117 | { |
---|
| 118 | $template->set_prefilter('default_content', 'fbp_add_social'); |
---|
| 119 | } |
---|
[8213] | 120 | } |
---|
| 121 | |
---|
[8241] | 122 | //~ function fbp_loc_end_picture() |
---|
| 123 | function fbp_render_element_content($content, $current_picture) |
---|
[8213] | 124 | { |
---|
[8241] | 125 | global $template, $user, $page, $conf, $picture; |
---|
[8213] | 126 | |
---|
[8241] | 127 | if ($conf['fbp']['social_plugin_like_button']['enabled']) |
---|
| 128 | { |
---|
| 129 | //~ $template->set_prefilter('default_content', 'fbp_add_social'); |
---|
| 130 | // Always use full url for FB social plugin |
---|
| 131 | //~ set_make_full_url(); |
---|
| 132 | // define language |
---|
| 133 | $template->assign('LANGUAGE', $user['language']); |
---|
| 134 | // define picture FB link |
---|
| 135 | set_make_full_url(); |
---|
| 136 | if ($conf['fbp']['social_plugin_like_button']['url_type'] == 'image') |
---|
| 137 | { |
---|
| 138 | $fbp_url_picture = get_element_url($picture['current']); |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | { |
---|
| 142 | $fbp_url_picture = make_picture_url(array('image_id' => $page['image_id'])); |
---|
| 143 | } |
---|
| 144 | unset_make_full_url(); |
---|
| 145 | $template->assign('FBP_URL_PICTURE', $fbp_url_picture); |
---|
| 146 | $template->assign('FBP_SOCIAL_PLUGIN_LIKE_BUTTON', $conf['fbp']['social_plugin_like_button']); |
---|
| 147 | } |
---|
| 148 | return $content; |
---|
[8215] | 149 | } |
---|
| 150 | |
---|
[8218] | 151 | function ftp_loc_end_section_init() |
---|
| 152 | { |
---|
[8241] | 153 | global $conf; |
---|
[8218] | 154 | |
---|
[8241] | 155 | if ($conf['fbp']['social_plugin_like_button']['enabled']) |
---|
[8218] | 156 | { |
---|
[8241] | 157 | if ($conf['fbp']['allow_fb_access_private_page']) |
---|
| 158 | { |
---|
| 159 | global $user, $page; |
---|
| 160 | |
---|
| 161 | // No restristion for facebook user |
---|
| 162 | if (preg_match('/'.FBP_IP_FB. '/', $_SERVER["REMOTE_ADDR"])) |
---|
| 163 | { |
---|
| 164 | //Allow guest access |
---|
| 165 | $conf['guest_access'] = true; |
---|
| 166 | // No forbidden categorie |
---|
| 167 | $user['forbidden_categories'] = ''; |
---|
| 168 | $user['level'] = max($conf['available_permission_levels']); |
---|
| 169 | $page['rank_of'][$page['image_id']] = 0; |
---|
| 170 | $page['items'] = array_flip($page['rank_of']); |
---|
| 171 | } |
---|
| 172 | } |
---|
[8218] | 173 | } |
---|
| 174 | } |
---|
| 175 | |
---|
[8241] | 176 | if ($conf['fbp']['social_plugin_like_button']['enabled']) |
---|
| 177 | { |
---|
| 178 | add_event_handler('loc_begin_picture', 'fbp_loc_begin_picture'); |
---|
| 179 | add_event_handler('render_element_content', 'fbp_render_element_content', null, 2); |
---|
| 180 | //~ add_event_handler('loc_end_picture', 'fbp_loc_end_picture'); |
---|
| 181 | add_event_handler('loc_end_section_init', 'ftp_loc_end_section_init'); |
---|
| 182 | } |
---|
| 183 | |
---|
[8213] | 184 | ?> |
---|