3 require_once('include/security.php');
4 require_once('include/Photo.php');
6 function photo_init(&$a) {
9 $prvcachecontrol = false;
13 $person = $a->argv[3];
14 $customres = intval($a->argv[2]);
18 $person = $a->argv[2];
30 // strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= filemtime($localFileName)) {
31 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
32 header('HTTP/1.1 304 Not Modified');
33 header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
34 header('Etag: '.$_SERVER['HTTP_IF_NONE_MATCH']);
35 header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
36 header("Cache-Control: max-age=31536000");
37 if(function_exists('header_remove')) {
38 header_remove('Last-Modified');
39 header_remove('Expires');
40 header_remove('Cache-Control');
46 $default = 'images/person-175.jpg';
63 $default = 'images/person-48.jpg';
68 $default = 'images/person-80.jpg';
72 $uid = str_replace(array('.jpg','.png'),array('',''), $person);
74 $r = q("SELECT * FROM `photo` WHERE `scale` = %d AND `uid` = %d AND `profile` = 1 LIMIT 1",
79 $data = $r[0]['data'];
80 $mimetype = $r[0]['type'];
83 $data = file_get_contents($default);
84 $mimetype = 'image/jpeg';
94 foreach( Photo::supportedTypes() as $m=>$e){
95 $photo = str_replace(".$e",'',$photo);
98 if(substr($photo,-2,1) == '-') {
99 $resolution = intval(substr($photo,-1,1));
100 $photo = substr($photo,0,-2);
103 $r = q("SELECT `uid` FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
109 $sql_extra = permissions_sql($r[0]['uid']);
111 // Now we'll see if we can access the photo
113 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d $sql_extra LIMIT 1",
119 $data = $r[0]['data'];
120 $mimetype = $r[0]['type'];
124 // Does the picture exist? It may be a remote person with no credentials,
125 // but who should otherwise be able to view it. Show a default image to let
126 // them know permissions was denied. It may be possible to view the image
127 // through an authenticated profile visit.
128 // There won't be many completely unauthorised people seeing this because
129 // they won't have the photo link, so there's a reasonable chance that the person
130 // might be able to obtain permission to view it.
132 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
137 $data = file_get_contents('images/nosign.jpg');
138 $mimetype = 'image/jpeg';
139 $prvcachecontrol = true;
146 if(isset($resolution)) {
147 switch($resolution) {
150 $data = file_get_contents('images/person-175.jpg');
151 $mimetype = 'image/jpeg';
154 $data = file_get_contents('images/person-80.jpg');
155 $mimetype = 'image/jpeg';
158 $data = file_get_contents('images/person-48.jpg');
159 $mimetype = 'image/jpeg';
169 if(isset($customres) && $customres > 0 && $customres < 500) {
170 $ph = new Photo($data, $mimetype);
171 if($ph->is_valid()) {
172 $ph->scaleImageSquare($customres);
173 $data = $ph->imageString();
174 $mimetype = $ph->getType();
178 if(function_exists('header_remove')) {
179 header_remove('Pragma');
180 header_remove('pragma');
183 header("Content-type: ".$mimetype);
185 if($prvcachecontrol) {
187 // it is a private photo that they have no permission to view.
188 // tell the browser not to cache it, in case they authenticate
189 // and subsequently have permission to see it
191 header("Cache-Control: no-store, no-cache, must-revalidate");
195 header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
196 header('Etag: "'.md5($data).'"');
197 header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
198 header("Cache-Control: max-age=31536000");