. */ require('components.php'); // COMPLETE AUTHENTICATION, usually handled by api.php $user = OBFUser::get_instance(); $auth_id = null; $auth_key = null; // try to get an ID/key pair for user authorization. if(!empty($_POST['i']) && !empty($_POST['k'])) { $auth_id = $_POST['i']; $auth_key = $_POST['k']; } // if not in post, try fetching from cookie. elseif(!empty($_COOKIE['ob_auth_id']) && !empty($_COOKIE['ob_auth_key'])) { $auth_id = $_COOKIE['ob_auth_id']; $auth_key = $_COOKIE['ob_auth_key']; } // authorize our user (from post data, cookie data, whatever.) $user->auth($auth_id,$auth_key); class MediaThumbnail extends OBFController { public function not_found() { http_response_code(404); die(); } public function output($id) { global $user; $this->db->where('id',$id); $media = $this->db->get_one('media'); if(!$media) $this->not_found(); // check permissions $is_media_owner = $media['owner_id']==$user->param('id'); if($media['status']=='private' && !$is_media_owner) $user->require_permission('manage_media'); $l0 = $media['file_location'][0]; $l1 = $media['file_location'][1]; $file = OB_CACHE.'/thumbnails/'.$l0.'/'.$l1.'/'.$media['id'].'.jpg'; if(!file_exists($file)) $this->not_found(); header('Content-Type: image/jpeg'); readfile($file); } } $thumbnail = new MediaThumbnail(); $thumbnail->output($_GET['id']);