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 | define('FACEBOOKPLUG_ROOT_PATH','./'); |
---|
22 | |
---|
23 | require_once 'include/common.php'; |
---|
24 | |
---|
25 | // Check argument |
---|
26 | !empty($_GET['u']) or die('Missing argument!'); |
---|
27 | |
---|
28 | fbp_mkdir($conf['local_upload_dir']); |
---|
29 | |
---|
30 | $image_url = $_GET['u']; |
---|
31 | if (! in_array(strtoupper(pathinfo($image_url, PATHINFO_EXTENSION)), $conf['available_upload_ext'])) |
---|
32 | { |
---|
33 | die($image_url.' is not a uploaded file: incorrect type'); |
---|
34 | } |
---|
35 | |
---|
36 | $page_url = @$_GET['pu']; |
---|
37 | $page_title = @$_GET['pt']; |
---|
38 | $gallery_title = @$_GET['gt']; |
---|
39 | |
---|
40 | //~ $local_filename = $conf['local_upload_dir'].'/'.basename($image_url); |
---|
41 | $local_filename = $conf['local_upload_dir'].'/'.md5($image_url.$page_url.$page_title.$gallery_title.$_SERVER['REMOTE_ADDR'].print_r(getdate(), true)).'.'.pathinfo($image_url, PATHINFO_EXTENSION); |
---|
42 | |
---|
43 | // Prevent error for local use, IP are not admitted |
---|
44 | //~ $page_url = str_replace('http://127.0.0.1', 'http://localhost', $page_url); |
---|
45 | |
---|
46 | @unlink($local_filename); |
---|
47 | |
---|
48 | @set_time_limit(0); |
---|
49 | |
---|
50 | if ($handle = @fopen($local_filename, 'wb') and fbp_fetchRemote($image_url, $handle)) |
---|
51 | { |
---|
52 | fclose($handle); |
---|
53 | } |
---|
54 | |
---|
55 | if (is_file($local_filename)) |
---|
56 | { |
---|
57 | try |
---|
58 | { |
---|
59 | $facebook->setFileUploadSupport(true); |
---|
60 | $result = $facebook->api( |
---|
61 | '/me/photos', 'post', |
---|
62 | array( |
---|
63 | 'source' => '@'.$local_filename, |
---|
64 | 'message' => $page_title.' |
---|
65 | '.$gallery_title.' |
---|
66 | '. $page_url, |
---|
67 | )); |
---|
68 | // Send Result |
---|
69 | if (isset($result['id'])) |
---|
70 | { |
---|
71 | echo $result['id']; |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | die($image_url.' not uploaded on Facebook'); |
---|
76 | } |
---|
77 | } |
---|
78 | catch (FacebookApiException $e) |
---|
79 | { |
---|
80 | die($image_url.' not uploaded on Facebook'); |
---|
81 | } |
---|
82 | unlink($local_filename); |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | die($image_url.' not uploaded locally'); |
---|
87 | } |
---|
88 | |
---|
89 | // Mettre des stats |
---|
90 | |
---|
91 | ?> |
---|