Example #1
0
 /**
  * Returns a file.
  *
  * Called when this component receives an HTTP GET request to
  * /Csv/$a/$b/$c/$file/$filename.
  *
  * @param string $hash The hash of the file which should be returned.
  * @param string $filename A freely chosen filename of the returned file.
  */
 public function getCsvDocument($callName, $input, $params = array())
 {
     $path = array($params['folder'], $params['a'], $params['b'], $params['c'], $params['file']);
     $filePath = implode('/', array_slice($path, 0));
     if (strlen($this->config['DIR']['files'] . '/' . $filePath) > 1 && file_exists($this->config['DIR']['files'] . '/' . $filePath)) {
         // the file was found
         Model::header('Content-Type', 'text/csv');
         Model::header('Content-Disposition', "attachment; filename=\"" . $params['filename'] . "\"");
         Model::header('Content-Length', filesize($this->config['DIR']['files'] . '/' . $filePath));
         Model::header('Accept-Ranges', 'none');
         readfile($this->config['DIR']['files'] . '/' . $filePath);
         return Model::isOk();
     }
     return Model::isProblem();
 }
Example #2
0
 /**
  * Returns a file.
  *
  * Called when this component receives an HTTP GET request to
  * /zip/$a/$b/$c/$file/$filename.
  *
  * @param string $hash The hash of the file which should be returned.
  * @param string $filename A freely chosen filename of the returned file.
  */
 public function getZipDocument($callName, $input, $params = array())
 {
     $path = array(self::getBaseDir(), $a, $b, $c, $file);
     $filePath = implode('/', array_slice($path, 0));
     if (strlen($this->config['DIR']['files'] . '/' . $filePath) > 1 && file_exists($this->config['DIR']['files'] . '/' . $filePath)) {
         // the file was found
         Model::header('Content-Type', 'application/zip');
         Model::header('Content-Disposition', "attachment; filename=\"" . $params['filename'] . "\"");
         Model::header('Accept-Ranges', 'none');
         readfile($this->config['DIR']['files'] . '/' . $filePath);
         return Model::isOk();
     }
     return Model::isProblem();
 }
Example #3
0
 public function getHelp($callName, $input, $params = array())
 {
     if (!isset($this->config['MAIN']['externalUrl'])) {
         return Model::isProblem();
     }
     array_unshift($params['path'], $params['language']);
     $fileName = array_pop($params['path']);
     $path_parts = pathinfo($fileName);
     $cacheFolder = dirname(__FILE__) . '/cache/' . implode('/', $params['path']);
     self::generatepath($cacheFolder);
     $realExtension = isset($path_parts['extension']) ? '.' . strtolower($path_parts['extension']) : '';
     $params['path'][] = $path_parts['filename'] . $realExtension;
     $cacheExtension = $realExtension;
     if ($cacheExtension == '.md') {
         $cacheExtension = '.html';
     }
     $cachePath = dirname(__FILE__) . '/cache/' . implode('/', $params['path']) . $cacheExtension;
     if (false && file_exists($cachePath)) {
         Model::header('Content-Length', filesize($cachePath));
         return Model::isOk(file_get_contents($cachePath));
     }
     $order = implode('/', $params['path']);
     $order = '/help/' . $order;
     $positive = function ($input, $cachePath, $realExtension, $negativeMethod, $cacheFilename) {
         if (empty($input)) {
             // wenn die zurückgegebene Datei leer ist, wird nicht gecached und die negative Methode aufgerufen
             return call_user_func_array($negativeMethod, array());
         }
         if ($realExtension == '.md') {
             $parser = new \Michelf\MarkdownExtra();
             $input = $this->umlaute($input);
             $my_html = $parser->transform($input);
             $input = '<html><head></head><body><link rel="stylesheet" href="' . $this->config['MAIN']['externalUrl'] . '/UI/css/github-markdown.css" type="text/css"><span class="markdown-body">' . $my_html . '</span></body></html>';
         }
         Model::header('Content-Length', strlen($input));
         // die Hilfedatei wird lokal gespeichert
         @file_put_contents($cachePath, $input);
         return Model::isOk($input);
     };
     $negative = function () {
         $input = '#### !!!Kein Inhalt!!!';
         $parser = new \Michelf\MarkdownExtra();
         $input = $this->umlaute($input);
         $my_html = $parser->transform($input);
         $input = '<html><head></head><body><link rel="stylesheet" href="' . $this->config['MAIN']['externalUrl'] . '/UI/css/github-markdown.css" type="text/css"><span class="markdown-body">' . $my_html . '</span></body></html>';
         Model::header('Content-Length', strlen($input));
         return Model::isOk($input);
     };
     return $this->_component->callByURI('request', $order, array('language' => $params['language']), '', 200, $positive, array('cachePath' => $cachePath, 'realExtension' => $realExtension, 'negativeMethod' => $negative, 'cacheFilename' => $path_parts['filename'] . $cacheExtension), $negative, array());
 }