]> git.mxchange.org Git - friendica.git/blob - mod/wall_upload.php
don't make -desc so obnoxious looking
[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                 if(! x($_FILES,'media')) {
9                         $nick = $a->argv[1];
10                         $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid`  WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
11                                 dbesc($nick)
12                         );
13
14                         if(! count($r))
15                                 return;
16                 }
17                 else {
18                         $user_info = api_get_user($a);
19                         $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid`  WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
20                                 dbesc($user_info['screen_name'])
21                         );
22                 }
23         }
24         else
25                 return;
26
27
28         $can_post  = false;
29         $visitor   = 0;
30
31         $page_owner_uid   = $r[0]['uid'];
32         $default_cid      = $r[0]['id'];
33         $page_owner_nick  = $r[0]['nickname'];
34         $community_page   = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
35
36         if((local_user()) && (local_user() == $page_owner_uid))
37                 $can_post = true;
38         else {
39                 if($community_page && remote_user()) {
40                         $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
41                                 intval(remote_user()),
42                                 intval($page_owner_uid)
43                         );
44                         if(count($r)) {
45                                 $can_post = true;
46                                 $visitor = remote_user();
47                                 $default_cid = $visitor;
48                         }
49                 }
50         }
51
52         if(! $can_post) {
53                 notice( t('Permission denied.') . EOL );
54                 killme();
55         }
56
57         if(! x($_FILES,'userfile') && ! x($_FILES,'media'))
58                 killme();
59
60         if(x($_FILES,'userfile')) {
61                 $src      = $_FILES['userfile']['tmp_name'];
62                 $filename = basename($_FILES['userfile']['name']);
63                 $filesize = intval($_FILES['userfile']['size']);
64         }
65         elseif(x($_FILES,'media')) {
66                 $src = $_FILES['media']['tmp_name'];
67                 $filename = basename($_FILES['media']['name']);
68                 $filesize = intval($_FILES['media']['size']);
69         }
70
71         $maximagesize = get_config('system','maximagesize');
72
73         if(($maximagesize) && ($filesize > $maximagesize)) {
74                 echo  sprintf( t('Image exceeds size limit of %d'), $maximagesize) . EOL;
75                 @unlink($src);
76                 killme();
77         }
78
79         $imagedata = @file_get_contents($src);
80         $ph = new Photo($imagedata);
81
82         if(! $ph->is_valid()) {
83                 echo ( t('Unable to process image.') . EOL);
84                 @unlink($src);
85                 killme();
86         }
87
88         @unlink($src);
89
90         $width = $ph->getWidth();
91         $height = $ph->getHeight();
92
93         $hash = photo_new_resource();
94         
95         $smallest = 0;
96
97         $defperm = '<' . $default_cid . '>';
98
99         $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm);
100
101         if(! $r) {
102                 echo ( t('Image upload failed.') . EOL);
103                 killme();
104         }
105
106         if($width > 640 || $height > 640) {
107                 $ph->scaleImage(640);
108                 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm);
109                 if($r) 
110                         $smallest = 1;
111         }
112
113         if($width > 320 || $height > 320) {
114                 $ph->scaleImage(320);
115                 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm);
116                 if($r)
117                         $smallest = 2;
118         }
119
120         $basename = basename($filename);
121
122
123 /* mod Waitman Gobble NO WARRANTY */
124
125 //if we get the signal then return the image url info in BBCODE, otherwise this outputs the info and bails (for the ajax image uploader on wall post)
126         if ($_REQUEST['hush']!='yeah') {
127
128                 /*existing code*/
129                 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
130                         echo  "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.jpg[/img][/url]\n\n";
131                 else
132                         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 />";
133                 /*existing code*/
134                 
135         } else {
136                 $m = '[url=' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.jpg[/img][/url]";
137                 return($m);
138         }
139 /* mod Waitman Gobble NO WARRANTY */
140
141         killme();
142         // NOTREACHED
143 }