示例#1
0
文件: Yml.php 项目: infrajs/yml
 public static function init()
 {
     $data = Catalog::init();
     Xlsx::runGroups($data, function (&$group, $i, &$parent) {
         $group['data'] = array_filter($group['data'], function (&$pos) {
             //Убираем позиции у которых не указана цена
             //if($pos['Синхронизация']!='Да')return false;
             if (!$pos['Цена']) {
                 return false;
             }
             $pos['Цена'] = preg_replace('/\\s/', '', $pos['Цена']);
             if (!$pos['Цена']) {
                 return false;
             }
             if (strtolower($pos['Маркет']) == 'да') {
                 $pos['Описание'] = strip_tags($pos['Описание']);
                 $pos['Описание'] = preg_replace('/ /', ' ', $pos['Описание']);
                 return true;
             }
         });
         $group['data'] = array_values($group['data']);
     });
     Xlsx::runGroups($data, function (&$group, $i, &$parent) {
         if ($group['childs']) {
             $group['childs'] = array_filter($group['childs'], function (&$g) {
                 if (!$g['data'] && !$g['childs']) {
                     return false;
                 }
                 return true;
             });
             $group['childs'] = array_values($group['childs']);
         }
     }, array(), true);
     Xlsx::runPoss($data, function (&$pos) {
         $conf = Catalog::$conf;
         Xlsx::addFiles($conf['dir'], $pos, array('Производитель', 'article'));
         foreach ($pos['images'] as $k => $v) {
             $src = $pos['images'][$k];
             $p = explode('/', $src);
             foreach ($p as $i => $n) {
                 $p[$i] = urlencode($n);
                 $p[$i] = preg_replace('/\\+/', '%20', $p[$i]);
             }
             $pos['images'][$k] = implode('/', $p);
         }
     });
     return static::parse($data);
 }
示例#2
0
 public static function getPos(&$pos)
 {
     $args = array($pos['producer'], $pos['article']);
     return Access::cache('Catalog::getPos', function () use($pos) {
         Xlsx::addFiles(Catalog::$conf['dir'], $pos);
         $files = explode(',', @$pos['Файлы']);
         foreach ($files as $f) {
             if (!$f) {
                 continue;
             }
             $f = trim($f);
             Xlsx::addFiles(Catalog::$conf['dir'], $pos, $f);
         }
         $files = array();
         foreach ($pos['files'] as $f) {
             if (is_string($f)) {
                 $f = Path::theme($f);
                 //убрали звездочку
                 $d = Load::srcInfo(Path::toutf($f));
             } else {
                 $d = $f;
                 $f = $d['src'];
             }
             $d['size'] = round(filesize(Path::tofs($f)) / 1000000, 2);
             if (!$d['size']) {
                 $d['size'] = '0.01';
             }
             $d['src'] = Path::pretty($d['src']);
             $files[] = $d;
         }
         $pos['files'] = $files;
         if ($pos['texts']) {
             foreach ($pos['texts'] as $k => $t) {
                 $pos['texts'][$k] = Load::loadTEXT('-doc/get.php?src=' . $t);
             }
         }
         return $pos;
     }, $args);
 }