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));
33 $person = $a->argv[3];
34 $customres = intval($a->argv[2]);
38 $person = $a->argv[2];
50 $default = 'images/person-175.jpg';
67 $default = 'images/person-48.jpg';
72 $default = 'images/person-80.jpg';
76 $uid = str_replace('.jpg', '', $person);
78 $r = q("SELECT * FROM `photo` WHERE `scale` = %d AND `uid` = %d AND `profile` = 1 LIMIT 1",
83 $data = $r[0]['data'];
86 $data = file_get_contents($default);
96 $photo = str_replace('.jpg','',$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'];
123 // Does the picture exist? It may be a remote person with no credentials,
124 // but who should otherwise be able to view it. Show a default image to let
125 // them know permissions was denied. It may be possible to view the image
126 // through an authenticated profile visit.
127 // There won't be many completely unauthorised people seeing this because
128 // they won't have the photo link, so there's a reasonable chance that the person
129 // might be able to obtain permission to view it.
131 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
136 $data = file_get_contents('images/nosign.jpg');
143 if(isset($resolution)) {
144 switch($resolution) {
147 $data = file_get_contents('images/person-175.jpg');
150 $data = file_get_contents('images/person-80.jpg');
153 $data = file_get_contents('images/person-48.jpg');
163 if(isset($customres) && $customres > 0 && $customres < 500) {
164 require_once('include/Photo.php');
165 $ph = new Photo($data);
166 if($ph->is_valid()) {
167 $ph->scaleImageSquare($customres);
168 $data = $ph->imageString();
172 // Writing in cachefile
173 if (isset($cachefile) && $cachefile != '')
174 file_put_contents($cachefile, $data);
176 if(function_exists('header_remove')) {
177 header_remove('Pragma');
178 header_remove('pragma');
181 header("Content-type: image/jpeg");
182 header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT");
183 header("Cache-Control: max-age=" . (3600*24));