/**
  *
  * Saving lang files from $res
  *
  * @param string $res
  * @param string $lang
  * @param string $fname
  * @return bool
  * @throws \Exception
  */
 public function parseLangCSV($res, $lang = '', $fname = 'main', $commentSeparator = '#')
 {
     $path = \App::langPath() . DIRECTORY_SEPARATOR;
     $path_js = \App::publicPath() . DIRECTORY_SEPARATOR . 'js/lang/' . DIRECTORY_SEPARATOR;
     $file = \App::storagePath() . DIRECTORY_SEPARATOR . 'temp.csv';
     file_put_contents($file, $res);
     $csvFile = fopen($file, 'r');
     while (!feof($csvFile)) {
         $csv = fgetcsv($csvFile);
         $csvArr[] = $csv;
     }
     $csv = $csvArr;
     if (!empty($csv)) {
         /*foreach ($csv as $k => $v) {
               $csv[$k] = str_getcsv($v);
           }*/
         $langs = $csv[0];
         unset($csv[0], $langs[0]);
         //dd($langs);
         foreach ($langs as $k => $lang) {
             $data = array();
             $count = 0;
             foreach ($csv as $line) {
                 if (empty($line[0])) {
                     continue;
                 }
                 if (count($line) < 2) {
                     continue;
                 }
                 if ($line[0][0] == $commentSeparator) {
                     continue;
                 }
                 if (isset($line[$k])) {
                     $data[$line[0]] = $line[$k];
                     $count++;
                 }
             }
             $r = $this->writeLangFile($data, $path . $lang . DIRECTORY_SEPARATOR, $fname . '.php');
             $s = $this->writeLangJsFile($data, $path_js . $lang . DIRECTORY_SEPARATOR, $fname . '.js');
             if ($r && $s) {
                 echo 'writing ' . $lang . ': ' . $count . " entries\n";
             } else {
                 echo 'error writing ' . $lang . " (php: {$r} / js: {$s}) \n";
             }
         }
         return true;
     } else {
         throw new \Exception('Empty Data', 500);
     }
 }
示例#2
0
 /**
  * Tworzy miniaturke i zwraca do niej ścieżkę
  * @param string $file ścieżka do pliku
  * @param array $options szerokość, wysokość, tryb
  * @return string
  */
 public function thumbnail($file, array $options = array())
 {
     $public_path = \App::publicPath();
     if (is_file($public_path . $file)) {
         $fileinfo = pathinfo($file);
         $imagesize = getimagesize($public_path . $file);
         $width = isset($options[0]) ? $options[0] : null;
         $height = isset($options[1]) ? $options[1] : null;
         $mode = isset($options[2]) ? $options[2] : 'landscape';
         $offset = isset($options[3]) ? $options[3] : [0, 0];
         $thumb = $fileinfo['dirname'] . '/thumb_' . $fileinfo['filename'] . '_' . $width . 'x' . $height . '_' . $mode . '.' . $fileinfo['extension'];
         if (file_exists($public_path . $thumb) && !filemtime($public_path . $thumb) <= filemtime($public_path . $file)) {
             $file = $thumb;
         } elseif ($imagesize[0] != $width && ($resizer = Resizer::open($public_path . $file)->resize($width, $height, $mode, $offset))) {
             $resizer->save($public_path . $thumb);
             $file = $thumb;
         }
     }
     return $file;
 }