예제 #1
0
파일: Htmlizer.php 프로젝트: ankhzet/Ankh
 public function apply(Transformable $transformable)
 {
     $file = \File::get(public_path('assets/img/borders.png'));
     $img = base64_encode($file);
     $data = str_ireplace(["\r", "\n"], '', $transformable->getContents());
     $data = preg_replace("~<(/?(br|p|dd))[^>]*?>~i", '<\\1>', $data);
     $data = preg_replace("~</(p|dd)>~i", '', $data);
     $data = preg_replace("~<(br|p|dd)>~i", static::LINEBREAK, $data);
     $data = preg_replace('/[ ]{2,}/', ' ', $data);
     $data = preg_replace("/" . static::LINEBREAK . "[ ]+/s", static::LINEBREAK . "    ", $data);
     $data = str_replace(static::LINEBREAK, '<p>', $data);
     $page = $transformable->page;
     $author = $page->author;
     $charset = $transformable->charset ?: 'utf-8';
     $title = $author->fio . " - " . $page->title;
     $link = \HTML::link(path_join("http://samlib.ru", $author->absoluteLink()), $author->fio) . " - " . \HTML::link(path_join("http://samlib.ru", $page->absoluteLink()), $page->title);
     $annotation = $page->annotation;
     $contents = $data;
     $downloaded = \Lang::get('pages.pages.downloaded', ['url' => \Request::fullUrl()]);
     if ($charset != 'utf-8') {
         $e = app('charset-encoder');
         $c = $e->remap($charset, true);
         $title = $e->transform($title, 'utf-8', $c);
         $link = $e->transform($link, 'utf-8', $c);
         $annotation = $e->transform($annotation, 'utf-8', $c);
         $downloaded = $e->transform($downloaded, 'utf-8', $c);
     }
     $view = view('pages.html-download', compact('img', 'charset', 'title', 'link', 'annotation', 'contents', 'downloaded'));
     $transformable->setContents((string) $view);
     $transformable->setType(static::EXTENSION);
     return $transformable;
 }
예제 #2
0
 public function apply(Transformable $transformable, $toEncoding = null)
 {
     $data = (string) $transformable;
     $data = $this->transform($data, $this->detectEncoding($data), $toEncoding);
     if (!!$data) {
         $transformable->charset = $this->remap($this->detectEncoding($data));
     }
     return $transformable->setContents($data);
 }
예제 #3
0
 public function apply(Transformable $transformable)
 {
     $data = str_ireplace(["\r", "\n"], '', $transformable->getContents());
     $data = preg_replace("~<(/?(br|p|dd))[^>]*?>~i", '<\\1>', $data);
     $data = preg_replace("~</(p|dd)>~i", '', $data);
     $data = preg_replace("~<(br|p|dd)>~i", static::LINEBREAK, $data);
     $data = str_ireplace(['&nbsp;', '&nbsp'], ' ', $data);
     $data = strip_tags($data);
     $trans = get_html_translation_table(HTML_ENTITIES);
     $trans = array_flip($trans);
     $data = strtr($data, $trans);
     $data = strip_tags($data);
     $data = preg_replace('/ {3,}/', '  ', $data);
     $data = preg_replace('/' . static::LINEBREAK . '[ ]+/', static::LINEBREAK . "\t", $data);
     $transformable->setContents(rtrim($data, static::LINEBREAK) . static::LINEBREAK);
     $transformable->setType(static::EXTENSION);
     return $transformable;
 }
예제 #4
0
파일: Ziper.php 프로젝트: ankhzet/Ankh
 public function apply(Transformable $transformable)
 {
     return $transformable->setContents((new Zip())->singleFile($transformable));
 }