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