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