]> git.mxchange.org Git - friendica.git/blob - mod/wall_upload.php
template for photo display
[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                 notice( sprintf(t('Image exceeds size limit of %d'), $maximagesize) . EOL);
57                 @unlink($src);
58                 return;
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         $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, '<0>');
80
81         if(! $r) {
82                 echo ( t('Image upload failed.') . EOL);
83                 killme();
84         }
85
86         if($width > 640 || $height > 640) {
87                 $ph->scaleImage(640);
88                 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, '<0>');
89                 if($r) 
90                         $smallest = 1;
91         }
92
93         if($width > 320 || $height > 320) {
94                 $ph->scaleImage(320);
95                 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, '<0>' );
96                 if($r)
97                         $smallest = 2;
98         }
99
100         $basename = basename($filename);
101         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 />";
102
103         killme();
104         // NOTREACHED
105 }