3 require_once('include/security.php');
5 function photo_init(&$a) {
8 // - checking with realpath
9 // - checking permissions
11 $cache = get_config('system','itemcache');
12 if (($cache != '') and is_dir($cache)) {
13 $cachefile = $cache."/".$a->argc."-".$a->argv[1]."-".$a->argv[2]."-".$a->argv[3];
14 if (file_exists($cachefile)) {
15 $data = file_get_contents($cachefile);
17 if(function_exists('header_remove')) {
18 header_remove('Pragma');
19 header_remove('pragma');
22 header("Content-type: image/jpeg");
23 header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
24 header("Cache-Control: max-age=" . (3600*24));
31 $prvcachecontrol = false;
35 $person = $a->argv[3];
36 $customres = intval($a->argv[2]);
40 $person = $a->argv[2];
52 $default = 'images/person-175.jpg';
69 $default = 'images/person-48.jpg';
74 $default = 'images/person-80.jpg';
78 $uid = str_replace('.jpg', '', $person);
80 $r = q("SELECT * FROM `photo` WHERE `scale` = %d AND `uid` = %d AND `profile` = 1 LIMIT 1",
85 $data = $r[0]['data'];
88 $data = file_get_contents($default);
98 $photo = str_replace('.jpg','',$photo);
100 if(substr($photo,-2,1) == '-') {
101 $resolution = intval(substr($photo,-1,1));
102 $photo = substr($photo,0,-2);
105 $r = q("SELECT `uid` FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
111 $sql_extra = permissions_sql($r[0]['uid']);
113 // Now we'll see if we can access the photo
115 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d $sql_extra LIMIT 1",
121 $data = $r[0]['data'];
125 // Does the picture exist? It may be a remote person with no credentials,
126 // but who should otherwise be able to view it. Show a default image to let
127 // them know permissions was denied. It may be possible to view the image
128 // through an authenticated profile visit.
129 // There won't be many completely unauthorised people seeing this because
130 // they won't have the photo link, so there's a reasonable chance that the person
131 // might be able to obtain permission to view it.
133 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
138 $data = file_get_contents('images/nosign.jpg');
139 $prvcachecontrol = true;
146 if(isset($resolution)) {
147 switch($resolution) {
150 $data = file_get_contents('images/person-175.jpg');
153 $data = file_get_contents('images/person-80.jpg');
156 $data = file_get_contents('images/person-48.jpg');
166 if(isset($customres) && $customres > 0 && $customres < 500) {
167 require_once('include/Photo.php');
168 $ph = new Photo($data);
169 if($ph->is_valid()) {
170 $ph->scaleImageSquare($customres);
171 $data = $ph->imageString();
175 // Writing in cachefile
176 if (isset($cachefile) && $cachefile != '')
177 file_put_contents($cachefile, $data);
179 if(function_exists('header_remove')) {
180 header_remove('Pragma');
181 header_remove('pragma');
184 header("Content-type: image/jpeg");
186 if($prvcachecontrol) {
188 // it is a private photo that they have no permission to view.
189 // tell the browser not to cache it, in case they authenticate
190 // and subsequently have permission to see it
192 header("Cache-Control: no-store, no-cache, must-revalidate");
197 header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
198 header("Cache-Control: max-age=" . (3600*24));