/** * Post Comment * * @params $subject_id: Id of item on which user comment * $guid: User id * $comment: Comment * $type: Post or Entity * * @return bool; */ public function PostComment($subject_id, $guid, $comment, $type = 'post') { if ($subject_id < 1 || $guid < 1 || empty($comment)) { return false; } $this->subject_guid = $subject_id; $this->owner_guid = $guid; $this->type = "comments:{$type}"; $this->value = $comment; if ($this->addAnnotation()) { if (isset($this->comment_image)) { $image = base64_decode($this->comment_image); $file = ossn_string_decrypt(base64_decode($image)); $file_path = rtrim(ossn_validate_filepath($file), '/'); $_FILES['attachment'] = array('name' => $file_path, 'tmp_name' => $file_path, 'type' => 'image/jpeg', 'size' => filesize($file_path), 'error' => UPLOAD_ERR_OK); $file = new OssnFile(); $file->type = 'annotation'; $file->subtype = 'comment:photo'; $file->setFile('attachment'); $file->setPath('comment/photo/'); $file->owner_guid = $this->getAnnotationId(); if ($file->owner_guid !== 0) { $file->addFile(); unlink($file_path); unset($_FILES['attachment']); } } return true; } return false; }
/** * Comment page for viewing comment photos * * @access private; */ function ossn_comment_page($pages) { $page = $pages[0]; switch ($page) { case 'image': if (!empty($pages[1]) && !empty($pages[2])) { $file = ossn_get_userdata("annotation/{$pages[1]}/comment/photo/{$pages[2]}"); header('Content-Type: image/jpeg'); if (is_file($file)) { echo ossn_resize_image($file, 300, 300); } else { ossn_error_page(); } } else { ossn_error_page(); } break; case 'attachment': header('Content-Type: application/json'); if (isset($_FILES['file']['tmp_name']) && ossn_isLoggedin()) { $file = $_FILES['file']['tmp_name']; $unique = time() . '-' . substr(md5(time()), 0, 6) . '.jpg'; $newfile = ossn_get_userdata("tmp/photos/{$unique}"); $dir = ossn_get_userdata("tmp/photos/"); if (!is_dir($dir)) { mkdir($dir, 0755, true); } if (move_uploaded_file($file, $newfile)) { $file = base64_encode(ossn_string_encrypt($newfile)); echo json_encode(array('file' => base64_encode($file), 'type' => 1)); exit; } } echo json_encode(array('type' => 0)); break; case 'staticimage': $image = base64_decode(input('image')); if (!empty($image)) { $file = ossn_string_decrypt(base64_decode($image)); header('content-type: image/jpeg'); $file = rtrim(ossn_validate_filepath($file), '/'); if (is_file($file)) { echo file_get_contents($file); } else { ossn_error_page(); } } else { ossn_error_page(); } break; } }