예제 #1
0
파일: UploadForm.php 프로젝트: kd-brinex/kd
 public function getText()
 {
     $file = FileHelper::localize($this->textFile);
     //        FileHelper::getMimeType()
     $f = file('uploads/' . $file->name);
     return $f;
 }
예제 #2
0
파일: View.php 프로젝트: rocketyang/mincms
 public function renderFile($viewFile, $params = array(), $context = null)
 {
     $viewFile = \Yii::getAlias($viewFile);
     if ($this->theme !== null) {
         $viewFile = $this->theme->applyTo($viewFile);
     }
     if (is_file($viewFile)) {
         $viewFile = \yii\helpers\FileHelper::localize($viewFile);
     } else {
         throw new \yii\base\InvalidParamException("The view file does not exist: {$viewFile}");
     }
     $oldContext = $this->context;
     if ($context !== null) {
         $this->context = $context;
     }
     $output = '';
     if ($this->beforeRender($viewFile)) {
         $ext = pathinfo($viewFile, PATHINFO_EXTENSION);
         if (isset($this->renderers[$ext])) {
             if (is_array($this->renderers[$ext])) {
                 $this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
             }
             /** @var ViewRenderer $renderer */
             $renderer = $this->renderers[$ext];
             $output = $renderer->render($this, $viewFile, $params);
         } else {
             $output = $this->renderPhpFile($viewFile, $params);
         }
         $this->afterRender($viewFile, $output);
     }
     $this->context = $oldContext;
     return $output;
 }
예제 #3
0
 /**
  * Renders a view file.
  *
  * If [[theme]] is enabled (not null), it will try to render the themed version of the view file as long
  * as it is available.
  *
  * The method will call [[FileHelper::localize()]] to localize the view file.
  *
  * If [[renderers|renderer]] is enabled (not null), the method will use it to render the view file.
  * Otherwise, it will simply include the view file as a normal PHP file, capture its output and
  * return it as a string.
  *
  * @param string $viewFile
  *            the view file. This can be either an absolute file path or an alias of it.
  * @param array $params
  *            the parameters (name-value pairs) that will be extracted and made available in the view file.
  * @param object $context
  *            the context that the view should use for rendering the view. If null,
  *            existing [[context]] will be used.
  * @return string the rendering result
  * @throws InvalidParamException if the view file does not exist
  */
 public function renderFile($viewFile, $params = [], $context = null)
 {
     $viewFile = $this->findViewFileByDefault($viewFile);
     if (is_file($viewFile)) {
         $viewFile = FileHelper::localize($viewFile);
     } else {
         throw new InvalidParamException("The view file does not exist: {$viewFile}");
     }
     $oldContext = $this->context;
     if ($context !== null) {
         $this->context = $context;
     }
     $output = '';
     $this->_viewFiles[] = $viewFile;
     if ($this->beforeRender($viewFile, $params)) {
         Yii::trace("Rendering view file: {$viewFile}", __METHOD__);
         $ext = pathinfo($viewFile, PATHINFO_EXTENSION);
         if (isset($this->renderers[$ext])) {
             if (is_array($this->renderers[$ext]) || is_string($this->renderers[$ext])) {
                 $this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
             }
             /* @var $renderer ViewRenderer */
             $renderer = $this->renderers[$ext];
             $output = $renderer->render($this, $viewFile, $params);
         } else {
             $output = $this->renderPhpFile($viewFile, $params);
         }
         $this->afterRender($viewFile, $params, $output);
     }
     array_pop($this->_viewFiles);
     $this->context = $oldContext;
     return $output;
 }
예제 #4
0
파일: View.php 프로젝트: netis-pl/yii2-crud
 /**
  * Changes:
  *
  * * if view file does not exist, find view file using $this as context.
  *
  * @inheritdoc
  */
 protected function findViewFile($view, $context = null)
 {
     $path = parent::findViewFile($view, $context);
     if ($this->theme !== null) {
         $path = $this->theme->applyTo($path);
     }
     if (!is_file($path)) {
         //find default view file
         return $this->findDefaultViewFile($view, $context);
     }
     return FileHelper::localize($path);
 }
예제 #5
0
파일: View.php 프로젝트: kalibao/magesko
 /**
  * Renders a view file.
  *
  * If [[theme]] is enabled (not null), it will try to render the themed version of the view file as long
  * as it is available.
  *
  * The method will call [[FileHelper::localize()]] to localize the view file.
  *
  * If [[renderers|renderer]] is enabled (not null), the method will use it to render the view file.
  * Otherwise, it will simply include the view file as a normal PHP file, capture its output and
  * return it as a string.
  *
  * @param string $viewFile the view file. This can be either an absolute file path or an alias of it.
  * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
  * @param object $context the context that the view should use for rendering the view. If null,
  * existing [[context]] will be used.
  * @return string the rendering result
  * @throws InvalidParamException if the view file does not exist
  */
 public function renderFile($viewFile, $params = [], $context = null)
 {
     $viewFile = Yii::getAlias($viewFile);
     if ($this->theme !== null) {
         $viewFile = $this->theme->applyTo($viewFile);
     }
     if (is_file($viewFile)) {
         $viewFile = FileHelper::localize($viewFile);
     } else {
         if (strpos($viewFile, $context->getViewPath()) === 0) {
             $viewFile = Yii::getAlias('@kalibao/views') . substr($viewFile, strlen($context->getViewPath()), strlen($viewFile));
         }
         if (!is_file($viewFile)) {
             throw new InvalidParamException("The view file does not exist: {$viewFile}");
         }
     }
     $oldContext = $this->context;
     if ($context !== null) {
         $this->context = $context;
     }
     $output = '';
     $this->viewFiles[] = $viewFile;
     if ($this->beforeRender($viewFile, $params)) {
         Yii::trace("Rendering view file: {$viewFile}", __METHOD__);
         $ext = pathinfo($viewFile, PATHINFO_EXTENSION);
         if (isset($this->renderers[$ext])) {
             if (is_array($this->renderers[$ext]) || is_string($this->renderers[$ext])) {
                 $this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
             }
             /* @var $renderer ViewRenderer */
             $renderer = $this->renderers[$ext];
             $output = $renderer->render($this, $viewFile, $params);
         } else {
             $output = $this->renderPhpFile($viewFile, $params);
         }
         $this->afterRender($viewFile, $params, $output);
     }
     array_pop($this->viewFiles);
     $this->context = $oldContext;
     return $output;
 }
 protected function generateIndexYii1($source, $target, $version, $language, $type = 'guide')
 {
     $this->stdout('populating elasticsearch index...');
     try {
         // first delete all records for this version
         $version = $this->version;
         $chapters = [];
         $sections = [];
         $file = "{$source}/toc.txt";
         $file = FileHelper::localize($file, $language, 'en');
         $lines = file($file);
         $chapter = '';
         foreach ($lines as $line) {
             // trim unicode BOM from line
             $line = trim(ltrim($line, ""));
             if ($line === '') {
                 continue;
             }
             if ($line[0] === '*') {
                 $chapter = trim($line, '* ');
             } else {
                 if ($line[0] === '-' && preg_match('/\\[(.*?)\\]\\((.*?)\\)/', $line, $matches)) {
                     $chapters[$chapter][$matches[1]] = $matches[2];
                     $sections[$matches[2]] = [$chapter, $matches[1]];
                     // elasticsearch
                     $file = $target . '/' . $matches[2] . '.html';
                     if (!file_exists($file)) {
                         echo "file not found: {$file}\n";
                         continue;
                     }
                     $html = file_get_contents($file);
                     SearchGuideSection::createRecord(basename($file, '.html'), $matches[1], $html, $this->version, $this->language, $type);
                 }
             }
         }
         $file = $type == 'blog' ? "{$source}/start.overview.txt" : "{$source}/index.txt";
         $file = FileHelper::localize($file, $language, 'en');
         $lines = file($file);
         if (($title = trim($lines[0])) === '') {
             $title = $type == 'blog' ? 'Building a Blog System Using Yii' : 'The Definitive Guide for Yii';
         }
         $title = str_replace('Yii', "Yii {$version}", $title);
         FileHelper::createDirectory($target);
         file_put_contents("{$target}/index.data", serialize([$title, $chapters, $sections]));
         $this->stdout("done.\n", Console::FG_GREEN);
     } catch (\Exception $e) {
         if (YII_DEBUG) {
             $this->stdout("!!! FAILED !!! Search will not be available.\n", Console::FG_RED, Console::BOLD);
             $this->stdout((string) $e . "\n\n");
         } else {
             throw $e;
         }
     }
 }
예제 #7
0
 public function testLocalizedDirectory()
 {
     $this->createFileStructure(['views' => ['faq.php' => 'English FAQ', 'de-DE' => ['faq.php' => 'German FAQ']]]);
     $viewFile = $this->testFilePath . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'faq.php';
     $sourceLanguage = 'en-US';
     // Source language and target language are same. The view path should be unchanged.
     $currentLanguage = $sourceLanguage;
     $this->assertSame($viewFile, FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage));
     // Source language and target language are different. The view path should be changed.
     $currentLanguage = 'de-DE';
     $this->assertSame($this->testFilePath . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $currentLanguage . DIRECTORY_SEPARATOR . 'faq.php', FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage));
 }
예제 #8
0
 public function getToc()
 {
     if ($this->_toc === null) {
         $file = $this->basePath . DIRECTORY_SEPARATOR . $this->tocFile . '.txt';
         $file = FileHelper::localize($file, $this->language, 'en');
         $lines = file($file);
         $chapter = '';
         foreach ($lines as $line) {
             // trim unicode BOM from line
             $line = trim(ltrim($line, ""));
             if ($line === '') {
                 continue;
             }
             if ($line[0] === '*') {
                 $chapter = trim($line, '* ');
             } elseif ($line[0] === '-' && preg_match('/\\[(.*?)\\]\\((.*?)\\)/', $line, $matches)) {
                 $this->_toc[$chapter][$matches[1]] = $matches[2];
                 $this->_sections[$matches[2]] = array($chapter, $matches[1]);
             }
         }
     }
     return $this->_toc;
 }