Ejemplo n.º 1
0
 /**
  * doAjax
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     if (!$this->app->get('unidev.image.storage')) {
         throw new \LogicException('No image storage set in config.');
     }
     $file = $this->input->files->get($this->fieldName);
     $folder = $this->input->getPath('folder');
     $folder = ltrim($folder . '/', '/');
     if ($file->getError()) {
         throw new \RuntimeException('Upload fail: ' . UploadedFileHelper::getUploadMessage($file->getError()), 500);
     }
     $id = $this->getImageName($file->getClientFilename());
     $temp = $this->getImageTemp($id, File::getExtension($file->getClientFilename()));
     if (!is_dir(dirname($temp))) {
         Folder::create(dirname($temp));
     }
     $file->moveTo($temp);
     $temp = $this->resize($temp);
     if (!is_file($temp)) {
         throw new \RuntimeException('Temp file not exists');
     }
     $url = ImageUploader::upload($temp, $this->getImagePath($folder . $id, File::getExtension($temp)));
     File::delete($temp);
     $this->addMessage('Upload success.');
     return array('url' => $url);
 }
Ejemplo n.º 2
0
 /**
  * loadFile
  *
  * @param string $file
  * @param string $type
  *
  * @return  string
  */
 public static function loadFile($file, $type = null)
 {
     if (!is_file($file)) {
         throw new \RuntimeException('File not found.');
     }
     $image = file_get_contents($file);
     $type = $type ?: File::getExtension($file);
     $type = $type == 'jpg' ? 'jpeg' : $type;
     return static::encode($image, $type);
 }
Ejemplo n.º 3
0
 /**
  * loadRouting
  *
  * @return  mixed
  */
 public function loadRouting()
 {
     $files = Folder::files(__DIR__ . '/Resources/routing');
     $routes = array();
     foreach ($files as $file) {
         $ext = File::getExtension($file);
         if ($ext != 'yml') {
             continue;
         }
         $routes = array_merge($routes, Yaml::parse(file_get_contents($file)));
     }
     return $routes;
 }
Ejemplo n.º 4
0
 /**
  * doExecute
  *
  * @return  int
  */
 protected function doExecute()
 {
     $path = $this->getArgument(0);
     $package = $this->getOption('p');
     $folder = $this->console->get('asset.folder', 'asset');
     if ($package = PackageHelper::getPackage($package)) {
         $path = $package->getDir() . '/Resources/asset/' . $path;
     } else {
         $path = WINDWALKER_PUBLIC . '/' . trim($folder, '/') . '/' . $path;
     }
     if (is_file($path)) {
         $files = array(new \SplFileInfo($path));
     } elseif (is_dir($path)) {
         $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::FOLLOW_SYMLINKS));
     } else {
         throw new \InvalidArgumentException('No path');
     }
     /** @var \SplFileInfo $file */
     foreach ($files as $file) {
         $ext = File::getExtension($file->getPathname());
         if (StringHelper::endsWith($file->getBasename(), '.min.' . $ext)) {
             continue;
         }
         if ($ext == 'css') {
             $this->out('[<comment>Compressing</comment>] ' . $file);
             $data = \Minify_CSS_Compressor::process(file_get_contents($file));
             $data = str_replace("\n", ' ', $data);
         } elseif ($ext == 'js') {
             $this->out('[<comment>Compressing</comment>] ' . $file);
             $data = \JSMinPlus::minify(file_get_contents($file));
             $data = str_replace("\n", ';', $data);
         } else {
             continue;
         }
         $newName = $file->getPath() . '/' . File::stripExtension($file->getBasename()) . '.min.' . $ext;
         file_put_contents($newName, $data);
         $this->out('[<info>Compressed</info>] ' . $newName);
     }
 }
Ejemplo n.º 5
0
 /**
  * loadAllFromPath
  *
  * @param   string $path
  * @param   string $format
  * @param   string $package
  */
 public static function loadAllFromPath($path, $format, $package = null)
 {
     $config = Ioc::getConfig();
     $locale = $config['language.locale'] ?: 'en-GB';
     $default = $config['language.default'] ?: 'en-GB';
     $locale = LanguageNormalize::toLanguageTag($locale);
     $default = LanguageNormalize::toLanguageTag($default);
     $localePath = $path . '/' . $locale;
     $files = array();
     if (is_dir($localePath)) {
         $files = array_merge($files, (array) Folder::files($localePath, false, Folder::PATH_BASENAME));
     }
     $defaultPath = $path . '/' . $default;
     if (is_dir($defaultPath)) {
         $files = array_merge($files, (array) Folder::files($defaultPath, false, Folder::PATH_BASENAME));
     }
     foreach ($files as $file) {
         $ext = File::getExtension($file);
         if (strcasecmp($ext, $format) !== 0) {
             continue;
         }
         Translator::loadFile(File::stripExtension($file), strtolower($format), $package);
     }
 }
Ejemplo n.º 6
0
 /**
  * Method to test getExtension().
  *
  * @return void
  *
  * @covers Windwalker\Filesystem\File::getExtension
  */
 public function testGetExtension()
 {
     $ext = File::getExtension('Wu-la.la');
     $this->assertEquals('la', $ext);
 }
Ejemplo n.º 7
0
 /**
  * getRemoteUrl
  *
  * @param   string  $path
  *
  * @return  string
  */
 public function getRemoteUrl($path)
 {
     if (!File::getExtension($path)) {
         $img = $this->imgur->image($path);
         return $img->link;
     }
     return static::getHost() . '/' . $path;
 }
Ejemplo n.º 8
0
 /**
  * onAfterWriteFiles
  *
  * @return  void
  */
 public function onAfterWriteFiles()
 {
     include_once __DIR__ . '/../../vendor/autoload.php';
     $base = realpath(__DIR__ . '/../../..');
     $items = Folder::files($base, true);
     $sitemap = new Sitemap();
     $root = Ioc::getConfig()->get('site.root');
     $sitemap->addItem($root, 1.0);
     foreach ($items as $item) {
         if (File::getExtension($item) != 'html') {
             continue;
         }
         $loc = str_replace('\\', '/', substr($item, strlen($base) + 1));
         $sitemap->addItem($root . '/' . $loc, 0.8, ChangeFreq::WEEKLY, new \DateTime());
     }
     $xml = $sitemap->toString();
     file_put_contents($base . '/sitemap.xml', $xml);
 }
Ejemplo n.º 9
0
 /**
  * loadRouting
  *
  * @return  mixed
  */
 public function loadRouting()
 {
     $routes = parent::loadRouting();
     foreach (Folder::files(__DIR__ . '/Resources/routing') as $file) {
         if (File::getExtension($file) == 'yml') {
             $routes = array_merge($routes, (array) Yaml::parse(file_get_contents($file)));
         }
     }
     // Merge other routes here...
     $routes = array_merge($routes, WarderHelper::getAdminRouting());
     $routes = array_merge($routes, LunaHelper::getAdminRouting());
     return $routes;
 }