3 require_once('include/security.php');
4 require_once('include/Photo.php');
6 function photo_init(&$a) {
9 // - checking with realpath
10 // - checking permissions
12 $cache = get_config('system','itemcache');
13 if (($cache != '') and is_dir($cache)) {
14 $cachefile = $cache."/".$a->argc."-".$a->argv[1]."-".$a->argv[2]."-".$a->argv[3];
15 if (file_exists($cachefile)) {
16 $data = file_get_contents($cachefile);
18 if(function_exists('header_remove')) {
19 header_remove('Pragma');
20 header_remove('pragma');
23 header("Content-type: image/jpeg");
24 header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
25 header("Cache-Control: max-age=" . (3600*24));
32 $prvcachecontrol = false;
36 $person = $a->argv[3];
37 $customres = intval($a->argv[2]);
41 $person = $a->argv[2];
53 $default = 'images/person-175.jpg';
70 $default = 'images/person-48.jpg';
75 $default = 'images/person-80.jpg';
79 $uid = str_replace(array('.jpg','.png'),array('',''), $person);
81 $r = q("SELECT * FROM `photo` WHERE `scale` = %d AND `uid` = %d AND `profile` = 1 LIMIT 1",
86 $data = $r[0]['data'];
87 $mimetype = $r[0]['type'];
90 $data = file_get_contents($default);
91 $mimetype = 'image/jpeg';
101 foreach( Photo::supportedTypes() as $m=>$e){
102 $photo = str_replace(".$e",'',$photo);
105 if(substr($photo,-2,1) == '-') {
106 $resolution = intval(substr($photo,-1,1));
107 $photo = substr($photo,0,-2);
110 $r = q("SELECT `uid` FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
116 $sql_extra = permissions_sql($r[0]['uid']);
118 // Now we'll see if we can access the photo
120 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d $sql_extra LIMIT 1",
126 $data = $r[0]['data'];
127 $mimetype = $r[0]['type'];
131 // Does the picture exist? It may be a remote person with no credentials,
132 // but who should otherwise be able to view it. Show a default image to let
133 // them know permissions was denied. It may be possible to view the image
134 // through an authenticated profile visit.
135 // There won't be many completely unauthorised people seeing this because
136 // they won't have the photo link, so there's a reasonable chance that the person
137 // might be able to obtain permission to view it.
139 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
144 $data = file_get_contents('images/nosign.jpg');
145 $mimetype = 'image/jpeg';
146 $prvcachecontrol = true;
153 if(isset($resolution)) {
154 switch($resolution) {
157 $data = file_get_contents('images/person-175.jpg');
158 $mimetype = 'image/jpeg';
161 $data = file_get_contents('images/person-80.jpg');
162 $mimetype = 'image/jpeg';
165 $data = file_get_contents('images/person-48.jpg');
166 $mimetype = 'image/jpeg';
176 if(isset($customres) && $customres > 0 && $customres < 500) {
177 $ph = new Photo($data, $mimetype);
178 if($ph->is_valid()) {
179 $ph->scaleImageSquare($customres);
180 $data = $ph->imageString();
181 $mimetype = $ph->getType();
185 // Writing in cachefile
186 if (isset($cachefile) && $cachefile != '')
187 file_put_contents($cachefile, $data);
189 if(function_exists('header_remove')) {
190 header_remove('Pragma');
191 header_remove('pragma');
194 header("Content-type: ".$mimetype);
196 if($prvcachecontrol) {
198 // it is a private photo that they have no permission to view.
199 // tell the browser not to cache it, in case they authenticate
200 // and subsequently have permission to see it
202 header("Cache-Control: no-store, no-cache, must-revalidate");
207 header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
208 header("Cache-Control: max-age=" . (3600*24));