コード例 #1
0
ファイル: search.php プロジェクト: infrajs/catalog
 //Массив позиций
 Catalog::search($md, $ans);
 $conf = Catalog::$conf;
 //BREADCRUMBS TITLE
 if (!$md['group'] && $md['producer'] && sizeof($md['producer']) == 1) {
     //ПРОИЗВОДИТЕЛЬ
     if ($md['producer']) {
         foreach ($md['producer'] as $producer => $v) {
             break;
         }
     } else {
         $producer = false;
     }
     //is!, descr!, text!, name!, breadcrumbs!
     $ans['is'] = 'producer';
     $name = Catalog::getProducer($producer);
     $ans['name'] = $name;
     $ans['title'] = $name;
     $conf = Config::get('catalog');
     $ans['breadcrumbs'][] = array('title' => $conf['title'], 'add' => 'producer:');
     $menu = Load::loadJSON('-catalog/menu.json');
     $ans['breadcrumbs'][] = array('href' => 'producers', 'title' => $menu['producers']['title']);
     $ans['breadcrumbs'][] = array('add' => 'producer::producer.' . $name . '=1', 'title' => $name);
     $ans['breadcrumbs'][sizeof($ans['breadcrumbs']) - 1]['active'] = true;
 } else {
     if (!$md['group'] && $md['search']) {
         $ans['is'] = 'search';
         $ans['name'] = $md['search'];
         $ans['title'] = Path::encode($md['search']);
         $ans['breadcrumbs'][] = array('title' => $conf['title'], 'add' => 'search:');
         $menu = Load::loadJSON('-catalog/menu.json');
コード例 #2
0
ファイル: Catalog.php プロジェクト: infrajs/catalog
 public static function markData(&$md)
 {
     if (isset($md['sort'])) {
         $md['sort'] = (string) $md['sort'];
         // price, name, def, group
         if (!in_array($md['sort'], array('name', 'art', 'group', 'change', 'cost'))) {
             unset($md['sort']);
         }
     }
     if (isset($md['search'])) {
         $md['search'] = (string) $md['search'];
         $md['search'] = trim($md['search']);
         $ar = preg_split('/[\\s,]+/', $md['search']);
         $res = array();
         foreach ($ar as $k => $v) {
             if ($v == '') {
                 continue;
             }
             $res[] = $v;
         }
         if ($res) {
             $md['search'] = implode(' ', $res);
         } else {
             unset($md['search']);
         }
     }
     if (isset($md['producer'])) {
         if (!is_array($md['producer'])) {
             $md['producer'] = array();
         }
         $md['producer'] = array_filter($md['producer']);
         $producers = array_keys($md['producer']);
         $producers = array_filter($producers, function (&$value) {
             if (in_array($value, array('yes', 'no'))) {
                 return true;
             }
             if (Catalog::getProducer($value)) {
                 return true;
             }
             return false;
         });
         $md['producer'] = array_fill_keys($producers, 1);
         if (!$md['producer']) {
             unset($md['producer']);
         }
     }
     if (isset($md['reverse'])) {
         $md['reverse'] = (bool) $md['reverse'];
         if (!$md['reverse']) {
             unset($md['reverse']);
         }
     }
     if (isset($md['count'])) {
         $md['count'] = (int) $md['count'];
         if ($md['count'] < 1) {
             unset($md['count']);
         }
         if ($md['count'] > 1000) {
             unset($md['count']);
         }
     }
     $key = 'group';
     if (isset($md[$key])) {
         if (!is_array($md[$key])) {
             $val = $md[$key];
             $md[$key] = array();
             $md[$key][$val] = 1;
         }
         $md[$key] = array_filter($md[$key]);
         $values = array_keys($md[$key]);
         $values = array_filter($values, function (&$value) {
             if (in_array($value, array('yes', 'no'))) {
                 return true;
             }
             if (!$value) {
                 return false;
             }
             if (!Catalog::getGroup($value)) {
                 return false;
             }
             return true;
         });
         $md[$key] = array_fill_keys($values, 1);
         if (!$md[$key]) {
             unset($md[$key]);
         }
     }
     $name = 'cost';
     if (isset($md[$name])) {
         if (!is_array($md[$name])) {
             $md[$name] = array();
         }
         $md[$name] = array_filter($md[$name]);
         //Удаляет false значения
         $values = array_keys($md[$name]);
         $values = array_filter($values, function (&$val) {
             if (in_array($value, array('yes', 'no'))) {
                 return true;
             }
             if (!$val) {
                 return false;
             }
             return true;
         });
         $md[$name] = array_fill_keys($values, 1);
         if (!$md[$name]) {
             unset($md[$name]);
         }
     }
     if (isset($md['more'])) {
         if (!is_array($md['more'])) {
             unset($md['more']);
         } else {
             foreach ($md['more'] as $k => $v) {
                 if (!is_array($v)) {
                     unset($md['more'][$k]);
                 } else {
                     foreach ($v as $kk => $vv) {
                         if (!$vv) {
                             unset($md['more'][$k][$kk]);
                         }
                     }
                     if (!$md['more'][$k]) {
                         unset($md['more'][$k]);
                     }
                 }
             }
             if (!$md['more']) {
                 unset($md['more']);
             }
         }
     }
     Extend::markData($md);
 }