コード例 #1
0
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;
}
コード例 #2
0
ファイル: DataUrlMapper.php プロジェクト: lucien144/Restful
 /**
  * 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());
 }
コード例 #3
0
ファイル: Panel.php プロジェクト: lohini/webloader
 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>';
 }
コード例 #4
0
ファイル: Date.php プロジェクト: pepakriz/grido
 /**
  * @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"
 }
コード例 #5
0
ファイル: GridTableModel.php プロジェクト: hajek-raven/agenda
 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);
 }
コード例 #6
0
ファイル: Template.php プロジェクト: nette/deprecated
 /**
  * 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);
 }
コード例 #7
0
ファイル: Template.php プロジェクト: radeksimko/nette
 /**
  * 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);
 }
コード例 #8
0
ファイル: ArraySource.php プロジェクト: cujan/vcelyweb
 /**
  * @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);
 }
コード例 #9
0
ファイル: Column.php プロジェクト: s4muel/grido
 /**
  * @param mixed $value
  * @return mixed
  */
 protected function formatValue($value)
 {
     $value = is_string($value) ? \Nette\Templating\Helpers::escapeHtml($value) : $value;
     return $this->applyReplacement($value);
 }
コード例 #10
0
ファイル: Doctrine.php プロジェクト: s4muel/grido
 /**
  * @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);
 }
コード例 #11
0
ファイル: NetteDatabase.php プロジェクト: novotnej/grido
 /**
  * @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);
 }
コード例 #12
0
 /**
  * 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>';
 }
コード例 #13
0
 /**
  * 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')));
 }
コード例 #14
0
ファイル: Column.php プロジェクト: cujan/atlashornin
 /**
  * @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;
 }
コード例 #15
0
ファイル: MediaFileSettingForm.php プロジェクト: jurasm2/bubo
 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);
 }
コード例 #16
0
ファイル: Registry.php プロジェクト: dotblue/nette-templating
 private function isRegisteredGlobally($name)
 {
     return $this->isRegisteredLocally($name) || Nette\Templating\Helpers::loader($name) !== NULL;
 }