]> git.mxchange.org Git - friendica.git/blob - mod/wall_upload.php
25a7ac50ee836eae9791c8111a12f0f9b74601c7
[friendica.git] / mod / wall_upload.php
1 <?php
2
3 require_once('Photo.php');
4
5 function wall_upload_post(&$a) {
6
7         if($a->argc > 1) {
8                 $nick = $a->argv[1];
9                 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
10                         dbesc($nick)
11                 );
12                 if(! count($r))
13                         return;
14
15         }
16         else
17                 return;
18
19         $can_post  = false;
20         $visitor   = 0;
21
22         $page_owner_uid = $r[0]['uid'];
23         $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
24
25         if((local_user()) && (local_user() == $page_owner_uid))
26                 $can_post = true;
27         else {
28                 if($community_page && remote_user()) {
29                         $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
30                                 intval(remote_user()),
31                                 intval($page_owner_uid)
32                         );
33                         if(count($r)) {
34                                 $can_post = true;
35                                 $visitor = remote_user();
36                         }
37                 }
38         }
39
40         if(! $can_post) {
41                 notice( t('Permission denied.') . EOL );
42                 killme();
43         }
44
45         if(! x($_FILES,'userfile'))
46                 killme();
47
48         $src      = $_FILES['userfile']['tmp_name'];
49         $filename = basename($_FILES['userfile']['name']);
50         $filesize = intval($_FILES['userfile']['size']);
51
52         $maximagesize = get_config('system','maximagesize');
53
54         if(($maximagesize) && ($filesize > $maximagesize)) {
55                 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
56                 @unlink($src);
57                 return;
58         }
59
60         $imagedata = @file_get_contents($src);
61         $ph = new Photo($imagedata);
62
63         if(! $ph->is_valid()) {
64                 echo ( t('Unable to process image.') . EOL);
65                 @unlink($src);
66                 killme();
67         }
68
69         @unlink($src);
70
71         $width = $ph->getWidth();
72         $height = $ph->getHeight();
73
74         $hash = photo_new_resource();
75         
76         $smallest = 0;
77
78         $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0 );
79
80         if(! $r) {
81                 echo ( t('Image upload failed.') . EOL);
82                 killme();
83         }
84
85         if($width > 640 || $height > 640) {
86                 $ph->scaleImage(640);
87                 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1 );
88                 if($r) 
89                         $smallest = 1;
90         }
91
92         if($width > 320 || $height > 320) {
93                 $ph->scaleImage(320);
94                 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2 );
95                 if($r)
96                         $smallest = 2;
97         }
98
99         $basename = basename($filename);
100         echo  "<br /><br /><img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" /><br /><br />";
101
102         killme();
103         return; // NOTREACHED
104 }