private function onDownloadCompressed() { $data = $this->request->data; if (!array_key_exists("items", $data)) { throw $this->invalidRequestException(); } if (!is_array($data['items']) || count($data['items']) < 1) { throw $this->invalidRequestException(); } $items = array(); $name = FALSE; foreach ($data['items'] as $i) { $items[] = $this->item($i); } if (count($items) == 0) { throw $this->invalidRequestException(); } if (count($items) == 1) { $name = $items[0]->name(); } $this->env->filesystem()->assertRights($items, FilesystemController::PERMISSION_LEVEL_READ, "download compressed"); $a = $this->archiveManager()->compress($items); $id = uniqid(); $this->env->session()->param("archive_" . $id, $a); if ($name) { $this->env->session()->param("archive_" . $id . "_name", $name); } if (is_array($items)) { $this->env->events()->onEvent(MultiFileEvent::download($items)); } else { $this->env->events()->onEvent(FileEvent::download($items)); } $this->response()->success(array("id" => $id)); }
public function onAction($ac, $item) { if (FileEvent::DOWNLOAD != $ac or $item == NULL or !$item->isFile()) { return; } $user = $this->env->session()->user(); if (!$user) { return; } $excludeUsers = $this->getSetting("exclude_users"); if ($excludeUsers != NULL) { if (in_array($user["id"], $excludeUsers)) { Logging::logDebug("User excluded, ignoring: " . $user["id"]); return; } } $excludeGroups = $this->getSetting("exclude_groups"); if ($excludeGroups != NULL) { $groups = $this->env->session()->userGroups(); if ($groups != NULL) { foreach ($groups as $g) { if (in_array($g["id"], $excludeGroups)) { Logging::logDebug("User group excluded, ignoring: " . $g["id"]); return; } } } } $type = $item->extension(); if (!$type or strlen($type) == 0) { return; } $types = $this->getSetting("types"); if ($types == NULL or !array_key_exists($type, $types)) { return; } $watermark = $this->getWatermarkText($item, $user); if (!$watermark) { return; } $marker = $this->getMarker($type, $types[$type]); if (!$marker) { return; } $original = $item->internalPath(); $file = $this->getTempFile($item, $type); Logging::logDebug("Watermarking [" . $original . "] -> temp [" . $file . "], mark [" . $watermark . "]"); $marked = $marker->mark($original, $file, $watermark); if (!$marked) { return; } $handle = @fopen($file, "rb"); if (!$handle) { throw new ServiceException("REQUEST_FAILED", "Could not open file for reading: " . $file); } //TODO range support $mobile = ($this->env->request()->hasParam("m") and strcmp($this->env->request()->param("m"), "1") == 0); $this->env->events()->onEvent(FileEvent::download($item)); $this->env->response()->download($item->name(), $type, $mobile, $handle); unlink($file); return TRUE; }
private function onDownloadCompressed() { $data = $this->request->data; if (!array_key_exists("items", $data)) { throw $this->invalidRequestException(); } if (!is_array($data['items']) || count($data['items']) < 1) { throw $this->invalidRequestException(); } $items = array(); foreach ($data['items'] as $i) { $items[] = $this->item($i); } if (count($items) == 0) { throw $this->invalidRequestException(); } $this->env->filesystem()->assertRights($items, Authentication::RIGHTS_READ, "download compressed"); $a = $this->archiveManager()->compress($items); $id = uniqid(); $this->env->session()->param("archive_" . $id, $a); if (is_array($items)) { $this->env->events()->onEvent(MultiFileEvent::download($items)); } else { $this->env->events()->onEvent(FileEvent::download($items)); } $this->response()->success(array("id" => $id)); }
public function download($file, $mobile, $range = NULL) { if (!$range) { Logging::logDebug('download [' . $file->id() . ']'); } $this->assertRights($file, self::PERMISSION_LEVEL_READ, "download"); if ($this->triggerActionInterceptor(FileEvent::DOWNLOAD, $file, array("mobile" => $mobile, "range" => $range))) { return; } if (!$file->filesystem()->isDirectDownload()) { $this->env->response()->redirect($file->filesystem()->getDownloadUrl($file)); return; } $name = $file->name(); $size = $file->size(); $range = $this->getDownloadRangeInfo($range); if ($range) { Logging::logDebug("Download range " . $range[0] . "-" . $range[1]); } else { $this->env->events()->onEvent(FileEvent::download($file)); } $this->env->response()->download($name, $file->extension(), $mobile, $file->read($range), $size, $range); }
public function download($file, $mobile, $range = NULL) { if (!$range) { Logging::logDebug('download [' . $file->id() . ']'); } $this->assertRights($file, self::PERMISSION_LEVEL_READ, "download"); if (!$file->filesystem()->isDirectDownload()) { $this->env->response()->redirect($file->filesystem()->getDownloadUrl($file)); return; } $name = $file->name(); $size = $file->size(); if ($range != NULL) { list($unit, $range) = explode('=', $range, 2); if ($unit == 'bytes') { $pos = strpos(",", $range); if ($pos != false) { if ($pos === 0) { $range = NULL; } else { if ($pos >= 0) { $range = substr($range, 0, $pos); } } } } else { $range = NULL; } } if ($range != NULL) { list($start, $end) = explode('-', $range, 2); $end = empty($end) ? $size - 1 : min(abs(intval($end)), $size - 1); $start = empty($start) || $end < abs(intval($start)) ? 0 : max(abs(intval($start)), 0); $range = array($start, $end, $size); Logging::logDebug("Download range " . $start . "-" . $end); } if (!$range) { $this->env->events()->onEvent(FileEvent::download($file)); } $this->env->response()->download($name, $file->extension(), $mobile, $file->read($range), $size, $range); }