Пример #1
0
 /**
  * Read a file's contents.
  * @param $fileId integer
  * @param $revision integer
  * @param $output boolean output the file's contents instead of returning a string
  * @return boolean
  */
 function readFile($fileId, $revision = null, $output = false)
 {
     $monographFile =& MonographFileManager::_getFile($fileId, $revision);
     if (isset($monographFile)) {
         return parent::readFile($monographFile->getFilePath(), $output);
     } else {
         return false;
     }
 }
 /**
  * Read a file's contents.
  * @param $output boolean output the file's contents instead of returning a string
  * @return boolean
  */
 function readFile($fileId, $userId, $output = false)
 {
     $temporaryFile =& $this->getFile($fileId, $userId);
     if (isset($temporaryFile)) {
         $filePath = $this->filesDir . $temporaryFile->getFileName();
         return parent::readFile($filePath, $output);
     } else {
         return false;
     }
 }
Пример #3
0
 /**
  * Read a file's contents.
  * @param $output boolean output the file's contents instead of returning a string
  * @return boolean
  */
 function readFile($fileId, $output = false)
 {
     $minutesFile =& $this->getFile($fileId);
     if (isset($minutesFile)) {
         $filePath = $this->filesDir . $minutesFile->getType() . '/' . $minutesFile->getFileName();
         return parent::readFile($filePath, $output);
     } else {
         return false;
     }
 }
 function &createChildFromFile(&$doc, &$node, $name, $filename)
 {
     $contents =& FileManager::readFile($filename);
     if ($contents === false) {
         return null;
     }
 }
Пример #5
0
 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $mediaType string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $mediaType = null, $inline = false, $fileName = null)
 {
     $result = null;
     if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result, &$fileName))) {
         return $result;
     }
     if (is_readable($filePath)) {
         if ($mediaType === null) {
             // If the media type wasn't specified, try to detect.
             $mediaType = String::mime_content_type($filePath);
             if (empty($mediaType)) {
                 $mediaType = 'application/octet-stream';
             }
         }
         if ($fileName === null) {
             // If the filename wasn't specified, use the server-side.
             $fileName = basename($filePath);
         }
         Registry::clear();
         // Free some memory
         header("Content-Type: {$mediaType}");
         header('Content-Length: ' . filesize($filePath));
         header('Content-Disposition: ' . ($inline ? 'inline' : 'attachment') . "; filename=\"{$fileName}\"");
         header('Cache-Control: private');
         // Workarounds for IE weirdness
         header('Pragma: public');
         // Beware of converting to instance call
         // https://github.com/pkp/pkp-lib/commit/82f4a36db406ecac3eb88875541a74123e455713#commitcomment-1459396
         FileManager::readFile($filePath, true);
         return true;
     } else {
         return false;
     }
 }
Пример #6
0
 /**
  *  Creates a METS:file for the Supplementary File
  *  checks if METS:FContent or METS:FLocat should be used
  */
 function generateArticleSuppFileDom(&$doc, &$root, &$article, &$suppFile, &$journal)
 {
     import('classes.file.PublicFileManager');
     import('lib.pkp.classes.file.FileManager');
     $fileManager = new FileManager();
     $contentWrapper = Request::getUserVar('contentWrapper');
     $mfile =& XMLCustomWriter::createElement($doc, 'METS:file');
     $filePath = MetsExportDom::getPublicFilePath($suppFile, '/supp/', $journal);
     $chkmd5return = md5_file($filePath);
     XMLCustomWriter::setAttribute($mfile, 'ID', 'SF' . $suppFile->getFileId() . '-A' . $suppFile->getArticleId());
     XMLCustomWriter::setAttribute($mfile, 'SIZE', $suppFile->getFileSize());
     XMLCustomWriter::setAttribute($mfile, 'MIMETYPE', $suppFile->getFileType());
     XMLCustomWriter::setAttribute($mfile, 'OWNERID', $suppFile->getFileName());
     XMLCustomWriter::setAttribute($mfile, 'CHECKSUM', $chkmd5return);
     XMLCustomWriter::setAttribute($mfile, 'CHECKSUMTYPE', 'MD5');
     if ($contentWrapper == 'FContent') {
         $fileContent =& $fileManager->readFile($filePath);
         $fContent =& XMLCustomWriter::createElement($doc, 'METS:FContent');
         $fNameNode =& XMLCustomWriter::createChildWithText($doc, $fContent, 'METS:binData', base64_encode($fileContent));
         XMLCustomWriter::appendChild($mfile, $fContent);
     } else {
         $fLocat =& XMLCustomWriter::createElement($doc, 'METS:FLocat');
         XMLCustomWriter::setAttribute($fLocat, 'xlink:href', Request::url($journal->getPath(), 'article', 'downloadSuppFile', array($suppFile->getArticleId(), $suppFile->getId())));
         XMLCustomWriter::setAttribute($fLocat, 'LOCTYPE', 'URL');
         XMLCustomWriter::appendChild($mfile, $fLocat);
     }
     XMLCustomWriter::appendChild($root, $mfile);
 }
Пример #7
0
 /**
  * Creates a METS:file for the Supplementary File
  * checks if METS:FContent or METS:FLocat should be used
  */
 function generateArticleSuppFileDom(&$doc, &$root, $article, &$suppFile)
 {
     import('classes.file.PublicFileManager');
     import('classes.file.FileManager');
     $contentWrapper = $this->getSetting($this->journalId, 'contentWrapper');
     $mfile =& XMLCustomWriter::createElement($doc, 'METS:file');
     $filePath = MetsExportDom::getPublicFilePath($suppFile, '/supp/');
     $chkmd5return = md5_file($filePath);
     XMLCustomWriter::setAttribute($mfile, 'ID', 'SF' . $suppFile->getFileId() . '-A' . $suppFile->getArticleId());
     XMLCustomWriter::setAttribute($mfile, 'SIZE', $suppFile->getFileSize());
     XMLCustomWriter::setAttribute($mfile, 'MIMETYPE', $suppFile->getFileType());
     XMLCustomWriter::setAttribute($mfile, 'OWNERID', $suppFile->getFileName());
     XMLCustomWriter::setAttribute($mfile, 'CHECKSUM', $chkmd5return);
     XMLCustomWriter::setAttribute($mfile, 'CHECKSUMTYPE', 'MD5');
     if ($contentWrapper == 'FContent') {
         $fileContent =& FileManager::readFile($filePath);
         $fContent =& XMLCustomWriter::createElement($doc, 'METS:FContent');
         $fNameNode =& XMLCustomWriter::createChildWithText($doc, $fContent, 'METS:binData', base64_encode($fileContent));
         XMLCustomWriter::appendChild($mfile, $fContent);
     } else {
         $fLocat =& XMLCustomWriter::createElement($doc, 'METS:FLocat');
         $fileUrl = MetsExportDom::getPublicSuppFileUrl($suppFile);
         XMLCustomWriter::setAttribute($fLocat, 'xlink:href', $fileUrl);
         XMLCustomWriter::setAttribute($fLocat, 'LOCTYPE', 'URL');
         XMLCustomWriter::appendChild($mfile, $fLocat);
     }
     XMLCustomWriter::appendChild($root, $mfile);
 }
Пример #8
0
 function &createChildFromFile(&$doc, &$node, $name, $filename)
 {
     $fileManager = new FileManager();
     $contents =& $fileManager->readFile($filename);
     if ($contents === false) {
         $nullVar = null;
         return $nullVar;
     }
 }
Пример #9
0
 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $mediaType string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $mediaType = null, $inline = false, $fileName = null)
 {
     $result = null;
     if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result, &$fileName))) {
         return $result;
     }
     $postDownloadHookList = array('FileManager::downloadFileFinished', 'UsageEventPlugin::getUsageEvent');
     if (is_readable($filePath)) {
         if ($mediaType === null) {
             // If the media type wasn't specified, try to detect.
             $mediaType = String::mime_content_type($filePath);
             if (empty($mediaType)) {
                 $mediaType = 'application/octet-stream';
             }
         }
         if ($fileName === null) {
             // If the filename wasn't specified, use the server-side.
             $fileName = basename($filePath);
         }
         $postDownloadHooks = null;
         $hooks = HookRegistry::getHooks();
         foreach ($postDownloadHookList as $hookName) {
             if (isset($hooks[$hookName])) {
                 $postDownloadHooks[$hookName] = $hooks[$hookName];
             }
         }
         unset($hooks);
         Registry::clear();
         // Stream the file to the end user.
         header("Content-Type: {$mediaType}");
         header('Content-Length: ' . filesize($filePath));
         header('Content-Disposition: ' . ($inline ? 'inline' : 'attachment') . "; filename=\"{$fileName}\"");
         header('Cache-Control: private');
         // Workarounds for IE weirdness
         header('Pragma: public');
         // Beware of converting to instance call
         // https://github.com/pkp/pkp-lib/commit/82f4a36db406ecac3eb88875541a74123e455713#commitcomment-1459396
         FileManager::readFile($filePath, true);
         if ($postDownloadHooks) {
             foreach ($postDownloadHooks as $hookName => $hooks) {
                 HookRegistry::setHooks($hookName, $hooks);
             }
         }
         $returner = true;
     } else {
         $returner = false;
     }
     HookRegistry::call('FileManager::downloadFileFinished', array(&$returner));
     return $returner;
 }
Пример #10
0
 /**
  * Read a file's contents.
  * @param $output boolean output the file's contents instead of returning a string
  * @return boolean
  */
 function readFile($fileId, $revision = null, $output = false)
 {
     $paperFile =& $this->getFile($fileId, $revision);
     if (isset($paperFile)) {
         $fileType = $paperFile->getFileType();
         $filePath = $this->filesDir . $paperFile->getType() . '/' . $paperFile->getFileName();
         return parent::readFile($filePath, $output);
     } else {
         return false;
     }
 }
Пример #11
0
 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $mediaType string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $mediaType = null, $inline = false)
 {
     $result = null;
     if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result))) {
         return $result;
     }
     if (is_readable($filePath)) {
         if ($mediaType == null) {
             $mediaType = String::mime_content_type($filePath);
             if (empty($mediaType)) {
                 $mediaType = 'application/octet-stream';
             }
         }
         Registry::clear();
         // Free some memory
         header("Content-Type: {$mediaType}");
         header("Content-Length: " . filesize($filePath));
         header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . basename($filePath) . "\"");
         header("Cache-Control: private");
         // Workarounds for IE weirdness
         header("Pragma: public");
         import('lib.pkp.classes.file.FileManager');
         FileManager::readFile($filePath, true);
         return true;
     } else {
         return false;
     }
 }
Пример #12
0
 /**
  * Read a file's contents.
  * @param $output boolean output the file's contents instead of returning a string
  * @return boolean
  */
 function readFile($fileId, $revision = null, $output = false)
 {
     $articleFile =& $this->getFile($fileId, $revision);
     if (isset($articleFile)) {
         $filePath = $this->filesDir . $this->fileStageToPath($articleFile->getFileStage()) . '/' . $articleFile->getFileName();
         return parent::readFile($filePath, $output);
     } else {
         return false;
     }
 }
Пример #13
0
 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $type string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $type = null, $inline = false)
 {
     if (is_readable($filePath)) {
         if ($type == null) {
             $type = String::mime_content_type($filePath);
             if (empty($type)) {
                 $type = 'application/octet-stream';
             }
         }
         header("Content-Type: {$type}");
         header("Content-Length: " . filesize($filePath));
         header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . basename($filePath) . "\"");
         header("Cache-Control: private");
         // Workarounds for IE weirdness
         header("Pragma: public");
         import('file.FileManager');
         FileManager::readFile($filePath, true);
         return true;
     } else {
         return false;
     }
 }
Пример #14
0
 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $type string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $type = null, $inline = false, $filename = null)
 {
     if (is_null($filename)) {
         $filename = basename($filePath);
     }
     $u_agent = $_SERVER['HTTP_USER_AGENT'];
     if (preg_match('/MSIE/i', $u_agent) && !preg_match('/Opera/i', $u_agent) || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false) {
         $filename = iconv('utf8', 'big5', $filename);
     }
     //$filename = basename($filePath);
     $result = null;
     if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$type, &$inline, &$result))) {
         return $result;
     }
     if (is_readable($filePath)) {
         if ($type == null) {
             $type = String::mime_content_type($filePath);
             if (empty($type)) {
                 $type = 'application/octet-stream';
             }
         }
         Registry::clear();
         // Free some memory
         header("Content-Type: {$type}");
         header("Content-Length: " . filesize($filePath));
         header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . $filename . "\"");
         header("Cache-Control: private");
         // Workarounds for IE weirdness
         header("Pragma: public");
         import('file.FileManager');
         FileManager::readFile($filePath, true);
         return true;
     } else {
         return false;
     }
 }
Пример #15
0
 function save()
 {
     global $settings, $rules;
     $hasLeaguePref = mysql_fetch_object(mysql_query("SELECT f_lid from league_prefs where f_lid={$this->lid}"));
     if ($hasLeaguePref) {
         $query = "UPDATE league_prefs SET prime_tid={$this->p_tour}, league_name='" . mysql_real_escape_string($this->league_name) . "', forum_url='" . mysql_real_escape_string($this->forum_url) . "' , welcome='" . mysql_real_escape_string($this->welcome) . "' , rules='" . mysql_real_escape_string($this->rules) . "'  WHERE f_lid={$this->lid}";
     } else {
         $query = "INSERT INTO league_prefs (f_lid, prime_tid, second_tid, league_name, forum_url, welcome, rules) VALUE ({$this->lid}, {$this->p_tour}, {$this->s_tour}, '" . mysql_real_escape_string($this->league_name) . "', '" . mysql_real_escape_string($this->forum_url) . "', '" . mysql_real_escape_string($this->welcome) . "', '" . mysql_real_escape_string($this->rules) . "')";
     }
     FileManager::writeFile(FileManager::getCssDirectoryName() . "/league_override_{$this->lid}.css", $this->theme_css);
     $settingsFileContents = FileManager::readFile(FileManager::getSettingsDirectoryName() . "/settings_{$this->lid}.php");
     $settingsFileContents = preg_replace("/settings\\['stylesheet'\\]\\s*=\\s['A-Za-z0-9_]+/", "settings['stylesheet'] = {$this->core_theme_id}", $settingsFileContents);
     $settingsFileContents = preg_replace("/settings\\['lang'\\]\\s*=\\s['A-Za-z0-9_\\-]+/", "settings['lang'] = '{$this->language}'", $settingsFileContents);
     $settingsFileContents = preg_replace("/rules\\['initial_treasury'\\]\\s*=\\s['A-Za-z0-9_]+/", "rules['initial_treasury'] = {$this->tv}", $settingsFileContents);
     $settingsFileContents = preg_replace("/settings\\['core_rules_file'\\]\\s*=\\s[\\.\\/'A-Za-z0-9_]+/", "settings['core_rules_file'] = '{$this->core_rules_file}'", $settingsFileContents);
     FileManager::writeFile(FileManager::getSettingsDirectoryName() . "/settings_{$this->lid}.php", $settingsFileContents);
     $settings['stylesheet'] = $this->core_theme_id;
     $settings['lang'] = $this->language;
     $rules['initial_treasury'] = $this->tv;
     $settings['core_rules_file'] = $this->core_rules_file;
     return mysql_query($query);
 }
Пример #16
0
 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $type string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $type = null, $inline = false, $label = null, $repo = false)
 {
     if ($repo == false) {
         if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$type, &$inline, &$result))) {
             return $result;
         }
         if (is_readable($filePath)) {
             if ($type == null) {
                 $type = String::mime_content_type($filePath);
                 if (empty($type)) {
                     $type = 'application/octet-stream';
                 }
             }
             Registry::clear();
             // Free some memory
             header("Content-Type: {$type}");
             header("Content-Length: " . filesize($filePath));
             header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . basename($filePath) . "\"");
             header("Cache-Control: private");
             header("Pragma: public");
             import('lib.pkp.classes.file.FileManager');
             FileManager::readFile($filePath, true);
             return true;
         } else {
             return false;
         }
     } else {
         //return file from repository
         $ch = curl_init($filePath);
         curl_setopt($ch, CURLOPT_HEADER, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $c = curl_exec($ch);
         $info = curl_getinfo($ch);
         curl_close($ch);
         if ($label == null) {
             $filename = str_replace("/content", "", $filePath);
             $filename = substr($filename, strrpos($filename, "/") + 1);
         }
         header("Etag: " . md5($filename));
         header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         header("Content-Type:" . $info['content_type']);
         header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . $label . "\"");
         header("Cache-Control: private");
         header("Pragma: public");
         ob_clean();
         flush();
         readfile($filePath);
     }
 }