* You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ OCP\JSON::checkAppEnabled('conversations'); OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); $path = isset($_POST['path']) ? $_POST['path'] : false; if ($path) { $room = OC_Conversations::getRoom(); $userId = OC_User::getUser(); \OC_Util::setupFS($userId); \OC\Files\Filesystem::initMountPoints($userId); $view = new \OC\Files\View('/' . $userId . '/files'); $fileinfo = $view->getFileInfo($path); $owner = $view->getOwner($path); if (strpos($fileinfo['mimetype'], "image") !== false) { $type = 'internal_image'; } else { $type = 'internal_file'; } $download_url = OCP\Util::linkToRoute('download', array('file' => $path)); // File not found if (\OC\Files\Filesystem::is_file($path) == false) { $fileinfo['name'] = "File not found."; $download_url = "#"; } // array for attachment template $tmpl_arr = array("type" => $type, "mimetype" => $fileinfo['mimetype'], "path" => $path, "name" => $fileinfo['name'], "download_url" => $download_url); // result array for new comment attachment data $data = array("type" => $type, "fileid" => $fileinfo['fileid'], "path" => urlencode($fileinfo['path']), "owner" => $owner);
/** * get uid of the owners of the file and the path to the file * @param string $path Path of the file to check * @throws \Exception * @note $shareFilePath must be relative to data/UID/files. Files * relative to /Shared are also acceptable * @return array */ public function getUidAndFilename($path) { $pathinfo = pathinfo($path); $partfile = false; $parentFolder = false; if (array_key_exists('extension', $pathinfo) && $pathinfo['extension'] === 'part') { // if the real file exists we check this file $filePath = $this->userFilesDir . '/' . $pathinfo['dirname'] . '/' . $pathinfo['filename']; if ($this->view->file_exists($filePath)) { $pathToCheck = $pathinfo['dirname'] . '/' . $pathinfo['filename']; } else { // otherwise we look for the parent $pathToCheck = $pathinfo['dirname']; $parentFolder = true; } $partfile = true; } else { $pathToCheck = $path; } $view = new \OC\Files\View($this->userFilesDir); $fileOwnerUid = $view->getOwner($pathToCheck); // handle public access if ($this->isPublic) { return array($this->userId, $path); } else { // Check that UID is valid if (!\OCP\User::userExists($fileOwnerUid)) { throw new \Exception('Could not find owner (UID = "' . var_export($fileOwnerUid, 1) . '") of file "' . $path . '"'); } // NOTE: Bah, this dependency should be elsewhere \OC\Files\Filesystem::initMountPoints($fileOwnerUid); // If the file owner is the currently logged in user if ($fileOwnerUid === $this->userId) { // Assume the path supplied is correct $filename = $path; } else { $info = $view->getFileInfo($pathToCheck); $ownerView = new \OC\Files\View('/' . $fileOwnerUid . '/files'); // Fetch real file path from DB $filename = $ownerView->getPath($info['fileid']); if ($parentFolder) { $filename = $filename . '/' . $pathinfo['filename']; } if ($partfile) { $filename = $filename . '.' . $pathinfo['extension']; } } return array($fileOwnerUid, \OC\Files\Filesystem::normalizePath($filename)); } }
/** * @brief get uid of the owners of the file and the path to the file * @param string $path Path of the file to check * @throws \Exception * @note $shareFilePath must be relative to data/UID/files. Files * relative to /Shared are also acceptable * @return array */ public function getUidAndFilename($path) { $view = new \OC\Files\View($this->userFilesDir); $fileOwnerUid = $view->getOwner($path); // handle public access if ($this->isPublic) { $filename = $path; $fileOwnerUid = $GLOBALS['fileOwner']; return array($fileOwnerUid, $filename); } else { // Check that UID is valid if (!\OCP\User::userExists($fileOwnerUid)) { throw new \Exception('Could not find owner (UID = "' . var_export($fileOwnerUid, 1) . '") of file "' . $path . '"'); } // NOTE: Bah, this dependency should be elsewhere \OC\Files\Filesystem::initMountPoints($fileOwnerUid); // If the file owner is the currently logged in user if ($fileOwnerUid === $this->userId) { // Assume the path supplied is correct $filename = $path; } else { $info = $view->getFileInfo($path); $ownerView = new \OC\Files\View('/' . $fileOwnerUid . '/files'); // Fetch real file path from DB $filename = $ownerView->getPath($info['fileid']); // TODO: Check that this returns a path without including the user data dir } return array($fileOwnerUid, \OC_Filesystem::normalizePath($filename)); } }