Esempio n. 1
0
 /**
  * Compile PDF/image preview for any kind of file
  *
  *
  * @return  mixed  array or false
  */
 protected function _compile()
 {
     // Combine file and folder data
     $items = $this->_sortIncoming();
     // Get stored remote connections
     $remotes = $this->_getRemoteConnections();
     // Params for repo call
     $params = array('subdir' => $this->subdir, 'remoteConnections' => $remotes);
     // Incoming
     $commit = Request::getInt('commit', 0);
     $download = Request::getInt('download', 0);
     // Check that we have compile enabled
     if (!$this->params->get('latex')) {
         $this->setError(Lang::txt('PLG_PROJECTS_FILES_COMPILE_NOTALLOWED'));
         return;
     }
     // Output HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'compiled'));
     // Get selected item
     if (!$items) {
         $view->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_FILES_TO_COMPILE'));
         $view->loadTemplate();
         return;
     } else {
         foreach ($items as $element) {
             foreach ($element as $type => $item) {
                 // Get our metadata
                 $file = $this->repo->getMetadata($item, 'file', $params);
                 break;
             }
         }
     }
     // We need a file
     if (empty($file)) {
         $view->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_FILES_TO_COMPILE'));
         $view->loadTemplate();
         return;
     }
     // Path for storing temp previews
     $imagePath = trim($this->model->config()->get('imagepath', '/site/projects'), DS);
     $outputDir = DS . $imagePath . DS . strtolower($this->model->get('alias')) . DS . 'compiled';
     // Make sure output dir exists
     if (!is_dir(PATH_APP . $outputDir)) {
         if (!Filesystem::makeDirectory(PATH_APP . $outputDir)) {
             $this->setError(Lang::txt('PLG_PROJECTS_FILES_UNABLE_TO_CREATE_UPLOAD_PATH'));
             return;
         }
     }
     // Get LaTeX helper
     $compiler = new \Components\Projects\Helpers\Compiler();
     // Tex compiler path
     $texPath = DS . trim($this->params->get('texpath'), DS);
     $view->file = $file;
     $view->oWidth = '780';
     $view->oHeight = '460';
     $view->url = Route::url($this->model->link('files'));
     $cExt = 'pdf';
     // Take out Google native extension if present
     $fileName = $file->get('name');
     if (in_array($file->get('ext'), \Components\Projects\Helpers\Google::getGoogleNativeExts())) {
         $fileName = preg_replace("/." . $file->get('ext') . "\\z/", "", $file->get('name'));
     }
     // Tex file?
     $tex = $compiler->isTexFile($fileName);
     // Build temp name
     $tempBase = $tex ? 'temp__' . \Components\Projects\Helpers\Html::takeOutExt($fileName) : $fileName;
     $tempBase = str_replace(' ', '_', $tempBase);
     // Get file contents
     if (!empty($this->_remoteService) && $file->get('converted')) {
         // Load remote resource
         $this->_connect->setUser($this->model->get('owned_by_user'));
         $resource = $this->_connect->loadRemoteResource($this->_remoteService, $this->model->get('owned_by_user'), $file->get('remoteId'));
         $cExt = $tex ? 'tex' : \Components\Projects\Helpers\Google::getGoogleImportExt($resource['mimeType']);
         $cExt = in_array($cExt, array('tex', 'jpeg')) ? $cExt : 'pdf';
         $url = \Components\Projects\Helpers\Google::getDownloadUrl($resource, $cExt);
         // Get data
         $view->data = $this->_connect->sendHttpRequest($this->_remoteService, $this->model->get('owned_by_user'), $url);
     } elseif ($file->exists()) {
         $view->data = $file->isImage() ? NULL : $file->contents();
     } else {
         $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_NO_DATA'));
     }
     // LaTeX file?
     if ($tex && !empty($view->data)) {
         // Clean up data from Windows characters - important!
         $view->data = preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $view->data);
         // Compile and get path to PDF
         $contentFile = $compiler->compileTex($file->get('fullPath'), $view->data, $texPath, PATH_APP . $outputDir, 1, $tempBase);
         // Read log (to show in case of error)
         $logFile = $tempBase . '.log';
         if (file_exists(PATH_APP . $outputDir . DS . $logFile)) {
             $view->log = Filesystem::read(PATH_APP . $outputDir . DS . $logFile);
         }
         if (!$contentFile) {
             $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_TEX_FAILED'));
         }
     } elseif ($file->get('converted') && !empty($view->data)) {
         $tempBase = \Components\Projects\Helpers\Google::getImportFilename($file->get('name'), $cExt);
         // Write content to temp file
         $this->_connect->fetchFile($view->data, $tempBase, PATH_APP . $outputDir);
         $contentFile = $tempBase;
     } elseif (!$this->getError()) {
         // Make sure we can handle preview of this type of file
         if ($file->get('ext') == 'pdf' || $file->isImage() || !$file->isBinary()) {
             Filesystem::copy($file->get('fullPath'), PATH_APP . $outputDir . DS . $tempBase);
             $contentFile = $tempBase;
         }
     }
     $url = $this->model->link('files');
     $url .= $this->repo->isLocal() ? '' : '&repo=' . $this->repo->get('name');
     $url .= $this->subdir ? '&subdir=' . urlencode($this->subdir) : '';
     // Parse output
     if (!empty($contentFile) && file_exists(PATH_APP . $outputDir . DS . $contentFile)) {
         // Get compiled content mimetype
         $cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile);
         // Is image?
         if (strpos($cType, 'image/') !== false) {
             // Fix up object width & height
             list($width, $height, $type, $attr) = getimagesize(PATH_APP . $outputDir . DS . $contentFile);
             $xRatio = $view->oWidth / $width;
             $yRatio = $view->oHeight / $height;
             if ($xRatio * $height < $view->oHeight) {
                 // Resize the image based on width
                 $view->oHeight = ceil($xRatio * $height);
             } else {
                 // Resize the image based on height
                 $view->oWidth = ceil($yRatio * $width);
             }
         }
         // Download compiled file?
         if ($download) {
             $pdfName = $tex ? str_replace('temp__', '', basename($contentFile)) : basename($contentFile);
             // Serve up file
             $server = new \Hubzero\Content\Server();
             $server->filename(PATH_APP . $outputDir . DS . $contentFile);
             $server->disposition('attachment');
             $server->acceptranges(false);
             $server->saveas($pdfName);
             $result = $server->serve_attachment(PATH_APP . $outputDir . DS . $contentFile, $pdfName, false);
             if (!$result) {
                 // Should only get here on error
                 App::abort(404, Lang::txt('PLG_PROJECTS_FILES_SERVER_ERROR'));
             } else {
                 exit;
             }
         }
         // Add compiled PDF to repository?
         if ($commit && $tex) {
             $pdfName = str_replace('temp__', '', basename($contentFile));
             $where = $this->subdir ? $this->subdir . DS . $pdfName : $pdfName;
             if (Filesystem::copy(PATH_APP . $outputDir . DS . $contentFile, $this->_path . DS . $where)) {
                 // Checkin into repo
                 $params = array('subdir' => $this->subdir);
                 $params['file'] = $this->repo->getMetadata($pdfName, 'file', $params);
                 $this->repo->call('checkin', $params);
                 if ($this->repo->isLocal()) {
                     $this->model->saveParam('google_sync_queue', 1);
                 }
                 \Notify::message(Lang::txt('PLG_PROJECTS_FILES_SUCCESS_COMPILED'), 'success', 'projects');
                 // Redirect to file list
                 App::redirect(Route::url($url));
                 return;
             }
         }
         // Generate preview image for browsers that cannot embed pdf
         if ($cType == 'application/pdf') {
             // GS path
             $gspath = trim($this->params->get('gspath'), DS);
             if ($gspath && file_exists(DS . $gspath . DS . 'gs')) {
                 $gspath = DS . $gspath . DS;
                 $pdfName = $tex ? str_replace('temp__', '', basename($contentFile)) : basename($contentFile);
                 $pdfPath = PATH_APP . $outputDir . DS . $contentFile;
                 $exportPath = PATH_APP . $outputDir . DS . $tempBase . '%d.jpg';
                 exec($gspath . "gs -dNOPAUSE -sDEVICE=jpeg -r300 -dFirstPage=1 -dLastPage=1 -sOutputFile={$exportPath} {$pdfPath} 2>&1", $out);
                 if (is_file(PATH_APP . $outputDir . DS . $tempBase . '1.jpg')) {
                     $hi = new \Hubzero\Image\Processor(PATH_APP . $outputDir . DS . $tempBase . '1.jpg');
                     if (count($hi->getErrors()) == 0) {
                         $hi->resize($view->oWidth, false, false, true);
                         $hi->save(PATH_APP . $outputDir . DS . $tempBase . '1.jpg');
                     } else {
                         return false;
                     }
                 }
                 if (is_file(PATH_APP . $outputDir . DS . $tempBase . '1.jpg')) {
                     $image = $tempBase . '1.jpg';
                 }
             }
         }
     } elseif (!$this->getError()) {
         $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_PREVIEW_FAILED'));
     }
     $view->file = $file;
     $view->outputDir = $outputDir;
     $view->embed = $contentFile;
     $view->cType = $cType;
     $view->subdir = $this->subdir;
     $view->option = $this->_option;
     $view->image = !empty($image) ? $image : NULL;
     $view->model = $this->model;
     $view->repo = $this->repo;
     if ($this->getError()) {
         $view->setError($this->getError());
     }
     return $view->loadTemplate();
 }
Esempio n. 2
0
 /**
  * Unlock sync and view sync log for project
  *
  * @return  void
  */
 public function fixsyncTask()
 {
     $id = Request::getVar('id', 0);
     $service = 'google';
     // Initiate extended database class
     $obj = new Tables\Project($this->database);
     if (!$id or !$obj->loadProject($id)) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     // Unlock sync
     $obj->saveParam($id, $service . '_sync_lock', '');
     // Get log file
     $repodir = Helpers\Html::getProjectRepoPath($obj->alias, 'logs');
     $sfile = $repodir . DS . 'sync.' . Date::format('Y-m') . '.log';
     if (file_exists($sfile)) {
         // Serve up file
         $server = new \Hubzero\Content\Server();
         $server->filename($sfile);
         $server->disposition('attachment');
         $server->acceptranges(false);
         $server->saveas('sync.' . Date::format('Y-m') . '.txt');
         $result = $server->serve_attachment($sfile, 'sync.' . Date::format('Y-m') . '.txt', false);
         exit;
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&task=edit&id=' . $id, false), Lang::txt('Sync log unavailable'));
 }
Esempio n. 3
0
 /**
  * Download a file
  *
  * @param   object  $member
  * @return  void
  */
 protected function _download($member)
 {
     $database = App::get('db');
     // Ensure we have a database object
     if (!$database) {
         App::abort(500, Lang::txt('DATABASE_NOT_FOUND'));
         return;
     }
     // Incoming
     $uid = $member->get('id');
     // Load the resume
     $resume = new \Components\Jobs\Tables\Resume($database);
     $file = '';
     $path = $this->build_path($uid);
     if ($resume->loadResume($uid)) {
         $file = PATH_APP . $path . DS . $resume->filename;
     }
     if (!is_file($file)) {
         App::abort(404, Lang::txt('FILE_NOT_FOUND'));
         return;
     }
     // Use user name as file name
     $default_title = $member->get('givenName') ? $member->get('givenName') . ' ' . $member->get('surname') . ' ' . ucfirst(Lang::txt('Resume')) : $member->get('name') . ' ' . ucfirst(Lang::txt('Resume'));
     $default_title .= substr($resume->filename, strripos($resume->filename, '.'));
     // Initiate a new content server and serve up the file
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename($file);
     // record view
     $stats = new \Components\Jobs\Tables\JobStats($database);
     if (User::get('id') != $uid) {
         $stats->saveView($uid, 'seeker');
     }
     $xserver->disposition('attachment');
     $xserver->acceptranges(false);
     // @TODO fix byte range support
     $xserver->saveas(stripslashes($resume->title));
     $result = $xserver->serve_attachment($file, stripslashes($default_title), false);
     // @TODO fix byte range support
     if (!$result) {
         App::abort(500, Lang::txt('SERVER_ERROR'));
     }
     exit;
 }
Esempio n. 4
0
 /**
  * Batch resume download
  *
  * @return     void
  */
 public function batchTask()
 {
     // Login required
     if (User::isGuest()) {
         \Notify::warning(Lang::txt('COM_JOBS_PLEASE_LOGIN_ACCESS_EMPLOYER'));
         $this->login();
         return;
     }
     // Check authorization
     if (!$this->_admin && !$this->_emp) {
         App::redirect(Route::url('index.php?option=com_jobs&task=subscribe'));
     }
     // Incoming
     $pile = Request::getVar('pile', 'all');
     // Zip the requested resumes
     $archive = $this->_archiveResumes($pile);
     if ($archive) {
         // Initiate a new content server and serve up the file
         $xserver = new \Hubzero\Content\Server();
         $xserver->filename($archive['path']);
         $xserver->disposition('attachment');
         $xserver->acceptranges(false);
         $xserver->saveas(Lang::txt('JOBS_RESUME_BATCH=Resume Batch'));
         $result = $xserver->serve_attachment($archive['path'], $archive['name'], false);
         // Delete downloaded zip
         \Filesystem::delete($archive['path']);
         if (!$result) {
             throw new Exception(Lang::txt('COM_JOBS_ERROR_ARCHIVE_FAILED'), 500);
         } else {
             exit;
         }
     } else {
         App::redirect(Route::url('index.php?option=com_jobs&task=dashboard'), Lang::txt('COM_JOBS_ERROR_ARCHIVE_FAILED'), 'error');
     }
 }
Esempio n. 5
0
 /**
  * Download source code for a tool
  *
  * @return     void
  */
 public function sourcecodeTask()
 {
     // Get tool instance
     $tool = Request::getVar('tool', 0);
     // Ensure we have a tool
     if (!$tool) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
         return;
     }
     // Load the tool version
     $tv = new \Components\Tools\Tables\Version($this->database);
     $tv->loadFromInstance($tool);
     // Concat tarball name for this version
     $tarname = $tv->toolname . '-r' . $tv->revision . '.tar.gz';
     // Get contribtool params
     $tparams = Component::params('com_tools');
     $tarball_path = $tparams->get('sourcecodePath');
     if (empty($tarball_path)) {
         $tarball_path = "site/protected/source";
     }
     if ($tarball_path[0] != DS) {
         $tarball_path = rtrim(PATH_APP . DS . $tarball_path, DS);
     }
     $tarpath = $tarball_path . DS . $tv->toolname . DS;
     $opencode = $tv->codeaccess == '@OPEN' ? 1 : 0;
     // Is a tarball available?
     if (!file_exists($tarpath . $tarname)) {
         // File not found
         App::abort(404, Lang::txt('COM_RESOURCES_FILE_NOT_FOUND'));
         return;
     }
     if (!$opencode) {
         // This tool is not open source
         App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH'));
         return;
     }
     // Serve up the file
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename($tarpath . $tarname);
     $xserver->disposition('attachment');
     $xserver->acceptranges(false);
     // @TODO fix byte range support
     $xserver->saveas($tarname);
     if (!$xserver->serve_attachment($tarpath . $tarname, $tarname, false)) {
         // @TODO fix byte range support
         throw new Exception(Lang::txt('COM_RESOURCES_SERVER_ERROR'), 500);
     } else {
         exit;
     }
     return;
 }
Esempio n. 6
0
 /**
  * Serve the file
  *
  * @param		$pId
  * @return     	void
  */
 public function displayTask()
 {
     // Get the transaction ID
     $tId = Request::getInt('task', '');
     // Get the SKU ID
     $sId = Request::getVar('p0');
     // Get the landing page flag
     $direct = Request::getVar('p1');
     // Check if the transaction is complete and belongs to the user and is active and the SKU requested is valid
     $transaction = Cart::getTransactionFacts($tId);
     $transactionExistingItems = $transaction->items;
     $transaction = $transaction->info;
     $transactionItems = unserialize($transaction->tiItems);
     $tStatus = $transaction->tStatus;
     $crtId = $transaction->crtId;
     // get cart user
     $cartUser = Cart::getCartUser($crtId);
     $currentUser = $this->juser->id;
     // Error if needed
     if ($tStatus !== 'completed') {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_TRANSACTION_NOT_COMPLETED'), 'error'));
         $this->messageTask($messages);
         return;
     } elseif ($cartUser != $currentUser) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_NOT_AUTHORIZED'), 'error'));
         $this->messageTask($messages);
         return;
     } elseif (!array_key_exists($sId, $transactionItems)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_NOT_AUTHORIZED'), 'error'));
         $this->messageTask($messages);
         return;
     }
     // Check if the product is valid and downloadable; find the file
     $warehouse = new Warehouse();
     $sku = $warehouse->getSkuInfo($sId);
     $productType = $warehouse->getProductTypeInfo($sku['info']->ptId);
     $downloadFile = $sku['meta']['downloadFile'];
     // Error if needed
     if ($productType['ptName'] != 'Software Download' || empty($downloadFile)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_DOWNLOADABLE'), 'error'));
         $this->messageTask($messages);
         return;
     }
     $db = \App::get('db');
     // Check if there is a limit on how many times the product can be downloaded
     // Get the number of downloads allowed
     if (isset($sku['meta']['downloadLimit']) && $sku['meta']['downloadLimit'] && is_numeric($sku['meta']['downloadLimit'])) {
         $sql = "SELECT COUNT(`dId`) FROM `#__cart_downloads` WHERE `uId` = {$currentUser} AND `sId` = {$sId} AND `dStatus` > 0";
         $db->setQuery($sql);
         $downloadsCount = $db->loadResult();
         if ($downloadsCount >= $sku['meta']['downloadLimit']) {
             $messages = array(array('Download limit exceeded', 'error'));
             $this->messageTask($messages);
             return;
         }
     }
     // Path and file name
     $storefrontConfig = Component::params('com_storefront');
     $dir = $storefrontConfig->get('downloadFolder', '/site/protected/storefront/software');
     $file = PATH_APP . $dir . DS . $downloadFile;
     if (!file_exists($file)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_FOUND'), 'error'));
         $this->messageTask($messages);
         return;
     }
     if (!$direct) {
         $this->landingTask($tId, $sId);
         return;
     }
     // Log the download
     $sql = "INSERT INTO `#__cart_downloads` SET\n\t\t\t\t`uId` = " . $currentUser . ",\n\t\t\t\t`sId` = " . $sId . ",\n\t\t\t\t`dIp` = INET_ATON(" . $db->quote(Request::ip()) . "),\n\t\t\t\t`dDownloaded` = NOW()";
     $db->setQuery($sql);
     $db->query();
     $dId = $db->insertid();
     // Save the meta data
     $userGroups = User::getAuthorisedGroups();
     $meta = array();
     $ignoreGroups = array('public', 'registered');
     foreach ($userGroups as $groupId) {
         $group = Accessgroup::one($groupId);
         if (!in_array(strtolower($group->get('title')), $ignoreGroups)) {
             $meta[$groupId] = $group->get('title');
         }
     }
     if ($mta = User::getState('metadata')) {
         $meta = array_merge($meta, $mta);
     }
     $sql = "INSERT INTO `#__cart_meta` SET\n\t\t\t\t`scope_id` = " . $dId . ",\n\t\t\t\t`scope` = 'download',\n\t\t\t\t`mtKey` = 'userInfo',\n\t\t\t\t`mtValue` = '" . serialize($meta) . "'";
     $db->setQuery($sql);
     $db->query();
     // Figure out if the EULA was accepted
     $itemTransactionInfoMeta = $transactionExistingItems[$sId]['transactionInfo']->tiMeta;
     $eulaAccepted = $itemTransactionInfoMeta && property_exists($itemTransactionInfoMeta, 'eulaAccepted') && $itemTransactionInfoMeta->eulaAccepted ? true : false;
     if ($eulaAccepted) {
         $sql = "INSERT INTO `#__cart_meta` SET\n\t\t\t\t\t`scope_id` = " . $dId . ",\n\t\t\t\t\t`scope` = 'download',\n\t\t\t\t\t`mtKey` = 'eulaAccepted',\n\t\t\t\t\t`mtValue` = '" . $eulaAccepted . "'";
         $db->setQuery($sql);
         $db->query();
     }
     // Serve up the file
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename($file);
     $xserver->serve_attachment($file);
     // Firefox and Chrome fail if served inline
     exit;
 }
Esempio n. 7
0
 /**
  * Serve the file
  *
  * @param		$pId
  * @return     	void
  */
 public function displayTask()
 {
     // Get the transaction ID
     $tId = Request::getInt('task', '');
     // Get the SKU ID
     $sId = Request::getVar('p0');
     // Get the landing page flag
     $direct = Request::getVar('p1');
     // Check if the transaction is complete and belongs to the user and is active
     $transaction = Cart::getTransactionFacts($tId);
     $transaction = $transaction->info;
     $tStatus = $transaction->tStatus;
     $crtId = $transaction->crtId;
     // get cart user
     $cartUser = Cart::getCartUser($crtId);
     $currentUser = $this->juser->id;
     // Error if needed
     if ($tStatus !== 'completed') {
         $messages = array(array('COM_CART_DOWNLOAD_TRANSACTION_NOT_COMPLETED', 'error'));
         $this->messageTask($messages);
         return;
     } elseif ($cartUser != $currentUser) {
         $messages = array(array('COM_CART_DOWNLOAD_NOT_AUTHORIZED', 'error'));
         $this->messageTask($messages);
         return;
     }
     // Check if the product is valid and downloadable; find the file
     $warehouse = new Warehouse();
     $sku = $warehouse->getSkuInfo($sId);
     $productType = $sku['info']->ptId;
     $downloadFile = $sku['meta']['downloadFile'];
     // Error if needed
     if ($productType != 30 || empty($downloadFile)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_DOWNLOABLE'), 'error'));
         $this->messageTask($messages);
         return;
     }
     $db = \App::get('db');
     // Check if there is a limit on how many times the product can be downloaded
     // Get the number of downloads allowed
     $allowedDownloads = $sku;
     if (isset($sku['meta']['downloadLimit']) && $sku['meta']['downloadLimit'] && is_numeric($sku['meta']['downloadLimit'])) {
         $sql = "SELECT COUNT(`dId`) FROM `#__cart_downloads` WHERE `uId` = {$currentUser} AND `sId` = {$sId}";
         $db->setQuery($sql);
         $downloadsCount = $db->loadResult();
         if ($downloadsCount >= $sku['meta']['downloadLimit']) {
             $messages = array(array('Download limit exceeded', 'error'));
             $this->messageTask($messages);
             return;
         }
     }
     // Path and file name
     $storefrontConfig = Component::params('com_storefront');
     $dir = $storefrontConfig->get('downloadFolder');
     $file = PATH_ROOT . $dir . DS . $downloadFile;
     if (!file_exists($file)) {
         $messages = array(array(Lang::txt('COM_CART_DOWNLOAD_FILE_NOT_FOUND'), 'error'));
         $this->messageTask($messages);
         return;
     }
     if (!$direct) {
         $this->landingTask($tId, $sId);
         return;
     }
     // Log the download
     $sql = "INSERT INTO `#__cart_downloads` SET\n\t\t\t\t`uId` = " . $currentUser . ",\n\t\t\t\t`sId` = " . $sId . ",\n\t\t\t\t`dIp` = INET_ATON(" . $db->quote(Request::getClientIp()) . "),\n\t\t\t\t`dDownloaded` = NOW()";
     $db->setQuery($sql);
     $db->query();
     // Serve up the file
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename($file);
     $xserver->serve_attachment($file);
     // Firefox and Chrome fail if served inline
     exit;
 }