function log_write($data, FileDownload $file, IDownloader $downloader)
{
    $cache = Environment::getCache("FileDownloader/log");
    $log = array();
    $tid = (string) $file->getTransferId();
    if (!isset($cache["registry"])) {
        $cache["registry"] = array();
    }
    $reg = $cache["registry"];
    $reg[$tid] = true;
    $cache["registry"] = $reg;
    if (isset($cache[$tid])) {
        $log = $cache[$tid];
    }
    Debugger::fireLog("Data: " . $data . "; " . $downloader->end);
    $data = $data . ": " . Helpers::bytes($file->transferredBytes) . " <->; ";
    if ($downloader instanceof AdvancedDownloader and $downloader->isInitialized()) {
        $data .= "position: " . Helpers::bytes($downloader->position) . "; ";
        //$data .= "length: ".Helpers::bytes($downloader->length)."; ";
        $data .= "http-range: " . Helpers::bytes($downloader->start) . "-" . Helpers::bytes($downloader->end) . "; ";
        $data .= "progress (con: " . round($file->transferredBytes / $downloader->end * 100) . "% X ";
        $data .= "file: " . round($downloader->position / $file->sourceFileSize * 100) . "%)";
    }
    $log[] = $data;
    $cache[$tid] = $log;
}
Exemple #2
0
 /**
  * Create DATA URL from file
  * @param Media $data
  * @param bool $prettyPrint
  * @return string
  *
  * @throws InvalidArgumentException
  */
 public function stringify($data, $prettyPrint = TRUE)
 {
     if (!$data instanceof Media) {
         throw new InvalidArgumentException('DataUrlMapper expects object of type Media, ' . gettype($data) . ' given');
     }
     return Helpers::dataStream((string) $data, $data->getContentType());
 }
Exemple #3
0
 public function getPanel()
 {
     $buff = '<h1>WebLoader</h1>' . '<div class="nette-inner">' . '<table>' . '<thead><tr><th>Source</th><th>Generated file</th><th>Memory usage</th></tr></thead>';
     $i = 0;
     foreach (self::$files as $source => $generated) {
         $buff .= '<tr><th' . ($i % 2 ? 'class="nette-alt"' : '') . '>' . self::link($source) . '</th><td>' . self::link($generated['name']) . '</td><td>' . \Nette\Templating\Helpers::bytes($generated['memory']) . '</td></tr>';
     }
     return $buff . '</table></div>';
 }
Exemple #4
0
 /**
  * @param mixed $value
  * @return string
  */
 protected function formatValue($value)
 {
     if ($value === NULL) {
         return $this->applyReplacement($value);
     } elseif (is_scalar($value)) {
         $value = \Nette\Templating\Helpers::escapeHtml($value);
         $replaced = $this->applyReplacement($value);
         if ($value !== $replaced && is_scalar($replaced)) {
             return $replaced;
         }
     }
     return $value instanceof \DateTime ? $value->format($this->dateFormat) : date($this->dateFormat, is_numeric($value) ? $value : strtotime($value));
     //@todo add notice when result is "01.01.1970"
 }
 public function suggest($column, array $conditions, $limit)
 {
     $fluent = clone $this->getSelection();
     is_string($column) && $fluent->removeClause('SELECT')->select("DISTINCT {$column}");
     foreach ($conditions as $condition) {
         $this->makeWhere($condition, $fluent);
     }
     $items = array();
     $data = $fluent->fetchAll(0, $limit);
     foreach ($data as $row) {
         if (is_string($column)) {
             $value = (string) $row[$column];
         } elseif (is_callable($column)) {
             $value = (string) $column($row);
         } else {
             $type = gettype($column);
             throw new \InvalidArgumentException("Column of suggestion must be string or callback, {$type} given.");
         }
         $items[$value] = \Nette\Templating\Helpers::escapeHtml($value);
     }
     return array_values($items);
 }
Exemple #6
0
 /**
  * Applies filters on template content.
  * @return string
  */
 public function compile()
 {
     if (!$this->filters) {
         $this->onPrepareFilters($this);
     }
     $code = $this->getSource();
     foreach ($this->filters as $filter) {
         $code = self::extractPhp($code, $blocks);
         $code = call_user_func($filter, $code);
         $code = strtr($code, $blocks);
         // put PHP code back
     }
     if ($latte = $this->getLatte()) {
         return $latte->setLoader(new Latte\Loaders\StringLoader())->compile($code);
     }
     return Helpers::optimizePhp($code);
 }
Exemple #7
0
 /**
  * Applies filters on template content.
  * @return string
  */
 public function compile()
 {
     if (!$this->filters) {
         $this->onPrepareFilters($this);
     }
     $code = $this->getSource();
     foreach ($this->filters as $filter) {
         $code = self::extractPhp($code, $blocks);
         $code = $filter($code);
         $code = strtr($code, $blocks);
         // put PHP code back
     }
     return Helpers::optimizePhp($code);
 }
Exemple #8
0
 /**
  * @param mixed $column
  * @param array $conditions
  * @param int $limit
  * @return array
  */
 public function suggest($column, array $conditions, $limit)
 {
     $data = $this->data;
     foreach ($conditions as $condition) {
         $data = $this->makeWhere($condition, $data);
     }
     array_slice($data, 1, $limit);
     $items = array();
     foreach ($data as $row) {
         if (is_string($column)) {
             $value = (string) $row[$column];
         } elseif (is_callable($column)) {
             $value = (string) $column($row);
         } else {
             $type = gettype($column);
             throw new \InvalidArgumentException("Column of suggestion must be string or callback, {$type} given.");
         }
         $items[$value] = \Nette\Templating\Helpers::escapeHtml($value);
     }
     return array_values($items);
 }
Exemple #9
0
 /**
  * @param mixed $value
  * @return mixed
  */
 protected function formatValue($value)
 {
     $value = is_string($value) ? \Nette\Templating\Helpers::escapeHtml($value) : $value;
     return $this->applyReplacement($value);
 }
Exemple #10
0
 /**
  * @param mixed $column
  * @param array $conditions
  * @param int $limit
  * @return array
  * @throws Exception
  */
 public function suggest($column, array $conditions, $limit)
 {
     $qb = clone $this->qb;
     $qb->setMaxResults($limit);
     if (is_string($column)) {
         $mapping = isset($this->filterMapping[$column]) ? $this->filterMapping[$column] : current($qb->getRootAliases()) . '.' . $column;
         $qb->select($mapping)->distinct()->orderBy($mapping);
     }
     foreach ($conditions as $condition) {
         $this->makeWhere($condition, $qb);
     }
     $items = array();
     $data = $qb->getQuery()->getScalarResult();
     foreach ($data as $row) {
         if (is_string($column)) {
             $value = (string) current($row);
         } elseif (is_callable($column)) {
             $value = (string) $column($row);
         } else {
             $type = gettype($column);
             throw new Exception("Column of suggestion must be string or callback, {$type} given.");
         }
         $items[$value] = \Nette\Templating\Helpers::escapeHtml($value);
     }
     is_callable($column) && sort($items);
     return array_values($items);
 }
Exemple #11
0
 /**
  * @param mixed $column
  * @param array $conditions
  * @param int $limit
  * @return array
  * @throws \InvalidArgumentException
  */
 public function suggest($column, array $conditions, $limit)
 {
     $selection = clone $this->selection;
     is_string($column) && $selection->select("DISTINCT {$column}")->order($column);
     $selection->limit($limit);
     foreach ($conditions as $condition) {
         $this->makeWhere($condition, $selection);
     }
     $items = array();
     foreach ($selection as $row) {
         if (is_string($column)) {
             $value = (string) $row[$column];
         } elseif (is_callable($column)) {
             $value = (string) $column($row);
         } else {
             $type = gettype($column);
             throw new \InvalidArgumentException("Column of suggestion must be string or callback, {$type} given.");
         }
         $items[$value] = \Nette\Templating\Helpers::escapeHtml($value);
     }
     is_callable($column) && sort($items);
     return array_values($items);
 }
 /**
  * Renders HTML code for custom tab.
  * @return string
  */
 public function getTab()
 {
     $icon = Html::el('img')->src(Helpers::dataStream(file_get_contents(__DIR__ . '/icon.png')))->height('16px');
     return '<span class="REST API resource routes">' . $icon . 'API resources</span>';
 }
 /**
  * Html code for DebuggerBar Tab
  * @return string
  */
 public function getTab()
 {
     return self::render(__DIR__ . '/templates/tab.phtml', array('src' => function ($file) {
         return \Nette\Templating\Helpers::dataStream(file_get_contents($file));
     }, 'esc' => \Nette\Utils\Callback::closure('Nette\\Templating\\Helpers::escapeHtml')));
 }
Exemple #14
0
 /**
  * @param mixed $value
  * @return mixed
  */
 protected function formatValue($value)
 {
     if (is_null($value) || is_scalar($value) || is_object($value) && method_exists($value, '__toString')) {
         $value = \Nette\Templating\Helpers::escapeHtml($value);
         $value = $this->applyReplacement($value);
     }
     return $value;
 }
Exemple #15
0
 public function formSubmited($form)
 {
     $formValues = $form->getValues();
     //        dump($formValues);
     //        die();
     $fileId = $formValues['fileId'];
     $_file = $this->presenter->mediaManagerService->getFile($fileId);
     $file = $this->presenter->mediaManagerService->loadFile($fileId);
     $paths = $file->getPaths();
     $section = $this->presenter->mediaManagerService->getFileSection($fileId);
     $el = NULL;
     $restoreUrl = $this->presenter->mediaManagerService->getFileRestoreUrl($_file['folder_id'], $fileId, $section, FALSE, $formValues);
     switch ($formValues['insertionMethod']) {
         case 0:
             // icon linking to file (default)
             $a = Html::el('a');
             $linkAttribs = array('href' => $paths['urls'][0], 'data-restoreUrl' => $restoreUrl);
             $a->addAttributes($linkAttribs);
             $imageAttributes = array('src' => $this->presenter->mediaManagerService->getIconBasePath() . '/default.png');
             $img = Html::el('img');
             $img->addAttributes($imageAttributes);
             $a->add($img);
             $el = $a;
             break;
         case 1:
             // text linking to file
             $text = $formValues['subform_1']['text'];
             $size = '';
             // create link
             $attribs = array('href' => $paths['urls'][0]);
             $el = Html::el('a');
             $el->addAttributes($attribs);
             if ($formValues['subform_1']['appendSize']) {
                 $size = '(' . Helpers::bytes($_file['size']) . ')';
             }
             $imageAttribs = array('data-restoreUrl' => $restoreUrl);
             $image = $el->create('span');
             $image->addAttributes($imageAttribs);
             $image->setText($text);
             break;
     }
     $tinyArgs = array('html' => $el->__toString());
     $this->media->sendTinyMceCommand($tinyArgs);
 }
Exemple #16
0
 private function isRegisteredGlobally($name)
 {
     return $this->isRegisteredLocally($name) || Nette\Templating\Helpers::loader($name) !== NULL;
 }