Beispiel #1
0
 /**
  * Поиск слоя по значению свойства
  **/
 public static function &find($name, $value)
 {
     $right = Sequence::right($name);
     return Run::exec(Controller::$layers, function &(&$layer) use($right, $value) {
         if (Sequence::get($layer, $right) == $value) {
             return $layer;
         }
         $r = null;
         return $r;
     });
 }
Beispiel #2
0
 private function __construct($mark)
 {
     $this->warrantytime = 60 * 60 * 24 * 60;
     //60 дней
     $mark = preg_replace("/:(.+)::\\./U", ":\$1::\$1.", $mark);
     $r = explode($this->sym, $mark);
     $this->mark = array_shift($r);
     if ($this->mark != '') {
         $src = Path::theme('~.marks/' . $this->prefix . $this->mark . '.json');
         if ($src) {
             $data = file_get_contents($src);
             $data = Load::json_decode($data);
         } else {
             $data = false;
         }
         //$data=infra_mem_get($this->prefix.$this->mark);
         if (!$data || !is_array($data['data'])) {
             $this->mark = '';
         } else {
             if (!$data['time']) {
                 $data['time'] = time();
             }
             $this->isold = true;
             $this->isoutdate = time() > $data['time'] + $this->warrantytime;
             $this->old = $data['data'];
         }
     }
     $this->data = $this->old;
     $add = implode($this->sym, $r);
     if ($add !== '') {
         $r = explode($this->sym, $add);
         $l = sizeof($r);
         if ($this->sym == $this->symeq) {
             if ($l % 2) {
                 $l++;
                 $r[] = '';
             }
             for ($i = 0; $i < $l; $i = $i + 2) {
                 if (!$r[$i]) {
                     continue;
                 }
                 Sequence::set($this->data, Sequence::right($r[$i]), $r[$i + 1]);
             }
         } else {
             for ($i = 0; $i < $l; $i = $i + 1) {
                 if (!$r[$i]) {
                     continue;
                 }
                 $rr = explode($this->symeq, $r[$i], 2);
                 if (!$rr[0]) {
                     continue;
                 }
                 Sequence::set($this->data, Sequence::right($rr[0]), $rr[1]);
             }
         }
     }
 }
Beispiel #3
0
        $block['row'] = array();
        if ($param['option']['nocount']) {
            $row = array('title' => 'Не указано', 'filter' => $param['nofilter']);
            $row['checked'] = !!$mymd['no'];
            if ($row['checked']) {
                $row['add'] = $add . $paramid . '.no=';
            } else {
                $row['add'] = $add . $paramid . '.no=1';
            }
            $block['row'][] = $row;
        }
        if ($block['type'] == 'string') {
            foreach ($param['option']['values'] as $value) {
                $row = array('title' => $value['title'], 'filter' => $value['filter']);
                $row['checked'] = !!$mymd[$value['id']];
                $valueid = Sequence::short(array(Catalog::urlencode($value['id'])));
                if ($row['checked']) {
                    $row['add'] = $add . $paramid . '.' . $valueid . '=';
                } else {
                    $row['add'] = $add . $paramid . '.' . $valueid . '=1';
                }
                $block['row'][] = $row;
            }
        }
        if ($conf['filteroneitem'] || sizeof($block['row']) > 1) {
            $ans['template'][] = $block;
        }
    }
    return $ans;
}, $args, isset($_GET['re']));
$ans = array_merge($ans, $res);
Beispiel #4
0
});
$fn3 = function () {
    return View::getPath();
};
Sequence::set(Template::$scope, array('infra', 'view', 'getPath'), $fn3);
$fn4 = function () {
    return View::getHost();
};
Sequence::set(Template::$scope, array('infra', 'view', 'getHost'), $fn4);
$fn5 = function ($s) {
    return Sequence::short($s);
};
Sequence::set(Template::$scope, array('infra', 'seq', 'short'), $fn5);
$fn6 = function ($s) {
    return Sequence::right($s);
};
Sequence::set(Template::$scope, array('infra', 'seq', 'right'), $fn6);
$fn7 = function () {
    return View::getRoot();
};
Sequence::set(Template::$scope, array('infra', 'view', 'getRoot'), $fn7);
$fn8 = function ($src) {
    return Load::srcInfo($src);
};
Sequence::set(Template::$scope, array('infra', 'srcinfo'), $fn8);
$host = $_SERVER['HTTP_HOST'];
$p = explode('?', $_SERVER['REQUEST_URI']);
$pathname = $p[0];
Sequence::set(Template::$scope, array('location', 'host'), $host);
Sequence::set(Template::$scope, array('location', 'pathname'), $pathname);
Beispiel #5
0
 public static function parsevar($var)
 {
     //Ищим скобки as.df[asdf[y.t]][qwer][ert]   asdf[asdf][asdf]
     if ($var == '') {
         return;
     }
     //Замен xinsert уже нет //asdf.asdf[asdf] На выходе ['asdf','asdf',['asdf']]
     $res = array();
     $start = false;
     $str = '';
     $name = '';
     $open = 0;
     //Количество вложенных открытий
     $varar = str_split($var);
     for ($i = 0, $l = sizeof($varar); $i < $l; ++$i) {
         $sym = $varar[$i];
         if ($start && $sym === ']') {
             if (!$open) {
                 $res[] = array(static::parseexp($name, true));
                 //data.name().. data[name]
                 $start = false;
                 $str = '';
                 $name = '';
                 continue;
             } else {
                 --$open;
             }
         } elseif (!$start) {
             //:[] ищем двоеточее вне скобок
             if ($sym == ':') {
                 $tpl = substr($var, $i + 1);
                 //echo $tpl;
                 $r = array();
                 $r['orig'] = $var;
                 $r['multi'] = $tpl[0] === ':';
                 if ($str) {
                     $res = array_merge($res, Sequence::right($str));
                 }
                 $r['var'] = array($res);
                 //В переменных к шаблону запятые не обрабатываются. res это массив с одним элементом в котором уже элементов много
                 if ($r['multi']) {
                     $tpl = substr($tpl, 1);
                 }
                 $r['tpl'] = static::make(array($tpl));
                 if (!isset($r['tpl']['root'])) {
                     $r['tpl']['root'] = array('');
                 }
                 return array($r);
             }
         }
         if ($start) {
             $name .= $sym;
         }
         if ($sym === '[') {
             if ($start) {
                 ++$open;
             } else {
                 $res = array_merge($res, Sequence::right($str));
                 $start = true;
             }
         }
         if (!$start) {
             $str .= $sym;
         }
     }
     $res[] = $str;
     $r = array();
     foreach ($res as $v) {
         if (is_string($v)) {
             $rrr = false;
             if ($rrr) {
                 $r[] = $rrr;
             } else {
                 $t = Sequence::right($v);
                 //a.b[b.c][c]
                 //[a,b,[b,c],[c]]
                 //b,[b,c]
                 //b,[b,c]
                 foreach ($t as $e) {
                     $r[] = $e;
                 }
             }
         } else {
             $r[] = $v;
         }
     }
     return $r;
 }
Beispiel #6
0
    return Tpl::jsoncheck($layer);
}, 'jsoncheck:is');
Run::runAddKeys('childs');
Run::runAddList('child');
Event::handler('Layer.oninit', function () {
    $root = Crumb::getInstance();
    if (!$root->is) {
        throw new \Exception('Crumb нужно инициализировать до запуска контроллера');
    }
    Sequence::set(Template::$scope, Sequence::right('infra.Crumb.query'), $root->query);
    Sequence::set(Template::$scope, Sequence::right('infra.Crumb.params'), Crumb::$params);
    Sequence::set(Template::$scope, Sequence::right('infra.Crumb.get'), Crumb::$get);
    $cl = function ($mix = null) {
        return ext\Crumb::getInstance($mix);
    };
    Sequence::set(Template::$scope, Sequence::right('infra.Crumb.getInstance'), $cl);
    External::add('child', 'layers');
    External::add('crumb', function (&$now, &$ext, &$layer, &$external, $i) {
        //проверка external в onchange
        Crumb::set($layer, 'crumb', $ext);
        return $layer[$i];
    });
}, 'crumb');
Event::handler('Layer.oninit', function (&$layer) {
    //это из-за child// всё что после child начинает плыть. по этому надо crumb каждый раз определять, брать от родителя.
    if (!isset($layer['dyn'])) {
        //Делается только один раз
        Crumb::set($layer, 'crumb', $layer['crumb']);
    }
    if (empty($layer['parent'])) {
        return;
Beispiel #7
0
            $n['name'] = Sequence::right($n['name']);
            $r = Each::exec($list, function &($item) use(&$n, &$ans) {
                //Устанавливаемое значение ищим в новости
                $r = null;
                //найдено совпадение новости с устанавливаемым значением.. новость удаляем
                $a = Sequence::contain($item['name'], $n['name']);
                if ($a || $a == array()) {
                    $r = true;
                    return $r;
                    //news Длиннее... и часть новости изменена в устанавливаемом значение
                }
                $ans['a'] = $a;
                //Новость ищим в устанавливаемом значение
                $right = Sequence::contain($n['name'], $item['name']);
                if ($right) {
                    $n['value'] = Sequence::set($n['value'], $right, $item['value']);
                    //Новость осталась но она включает устанавливаемые данные
                }
                return $r;
            });
            if ($r) {
                $del = new Fix('del');
                return $del;
            }
            $r = null;
            return $r;
        });
    }
}
if ($list) {
    if (!$session_id) {
Beispiel #8
0
 public static function addFiles($root, &$pos, $dir = false)
 {
     $props = array('producer', 'article');
     if (!isset($pos['images'])) {
         $pos['images'] = array();
     }
     if (!isset($pos['texts'])) {
         $pos['texts'] = array();
     }
     if (!isset($pos['files'])) {
         $pos['files'] = array();
     }
     if (!$dir) {
         $dir = array();
         $pth = Path::resolve($root);
         if (Each::forr($props, function &($name) use(&$dir, &$pos) {
             $rname = Sequence::right($name);
             $val = Sequence::get($pos, $rname);
             if (!$val) {
                 return true;
             }
             $dir[] = $val;
             $r = null;
             return $r;
         })) {
             return;
         }
         if ($dir) {
             $dir = implode('/', $dir) . '/';
             $dir = $pth . $dir;
         } else {
             $dir = $pth;
         }
     } else {
         $dir = $root . $dir;
     }
     $dir = Path::theme($dir);
     if (!$dir) {
         return false;
     }
     if (is_dir($dir)) {
         $paths = glob($dir . '*');
     } elseif (is_file($dir)) {
         $paths = array($dir);
         $p = Load::srcInfo($dir);
         $dir = $p['folder'];
     }
     Each::forr($paths, function &($p) use(&$pos, $dir) {
         $d = explode('/', $p);
         $name = array_pop($d);
         $n = mb_strtolower($name);
         $fd = Load::nameInfo($n);
         $ext = $fd['ext'];
         //if(!$ext)return;
         if (!is_file($dir . $name)) {
             return;
         }
         //$name=preg_replace('/\.\w{0,4}$/','',$name);
         /*$p=pathinfo($p);
         		$name=$p['basename'];
         		$ext=strtolower($p['extension']);*/
         if ($name[0] == '.') {
             return;
         }
         $dir = Path::pretty($dir);
         $name = Path::toutf($dir . $name);
         $im = array('png', 'gif', 'jpg');
         $te = array('html', 'tpl', 'mht', 'docx');
         if (in_array($ext, $im)) {
             $pos['images'][] = $name;
         } else {
             if (in_array($ext, $te)) {
                 $pos['texts'][] = $name;
             } else {
                 if ($ext != 'db') {
                     $pos['files'][] = $name;
                 }
             }
         }
         $r = null;
         return $r;
     });
     $pos['images'] = array_unique($pos['images']);
     $pos['texts'] = array_unique($pos['texts']);
     $pos['files'] = array_unique($pos['files']);
 }
Beispiel #9
0
 public static function short($right)
 {
     return Sequence::short($right, '/');
 }
Beispiel #10
0
 public static function writeNews($list, $session_id)
 {
     if (!$list) {
         return;
     }
     $db =& Db::pdo();
     global $infra_session_lasttime;
     $isphp = !!$infra_session_lasttime;
     $sql = 'insert into `ses_records`(`session_id`, `name`, `value`, `time`) VALUES(?,?,?,FROM_UNIXTIME(?))';
     $stmt = $db->prepare($sql);
     $sql = 'delete from `ses_records` where `session_id`=? and `name`=? and `time`<=FROM_UNIXTIME(?)';
     $delstmt = $db->prepare($sql);
     Each::exec($list, function &($rec) use($isphp, &$delstmt, &$stmt, $session_id) {
         $r = null;
         if (!$isphp && $rec['name'][0] == 'safe') {
             return $r;
         }
         $name = Sequence::short($rec['name']);
         $delstmt->execute(array($session_id, $name, $rec['time']));
         $stmt->execute(array($session_id, $name, Load::json_encode($rec['value']), $rec['time']));
         if (!$isphp && !$name) {
             //Сохранится safe
             Session::clear();
         }
         return $r;
     });
 }
Beispiel #11
0
 public static function filtering(&$poss, $md)
 {
     if (!sizeof($poss)) {
         return;
     }
     $params = Catalog::getParams();
     $filters = array();
     foreach ($params as $prop) {
         if ($prop['more']) {
             if (empty($md['more'])) {
                 continue;
             }
             //Filter more
             if (empty($md['more'][$prop['mdid']])) {
                 continue;
             }
             //Filter more
             $valtitles = array();
             $val = $md['more'][$prop['mdid']];
             foreach ($val as $value => $one) {
                 $valtitles[$value] = $value;
             }
             $filter = array('title' => $prop['title'], 'name' => Sequence::short(array('more', Catalog::urlencode($prop['mdid']))));
             $poss = array_filter($poss, function ($pos) use($prop, $val, &$valtitles) {
                 foreach ($val as $value => $one) {
                     $option = $pos['more'][$prop['posid']];
                     if ($value === 'yes' && Xlsx::isSpecified($option)) {
                         return true;
                     }
                     if ($value === 'no' && !Xlsx::isSpecified($option)) {
                         return true;
                     }
                     $titles = $pos['more'][$prop['posname']];
                     if ($prop['separator']) {
                         $option = explode($prop['separator'], $option);
                         $titles = explode($prop['separator'], $titles);
                     } else {
                         $option = array($option);
                         $titles = array($titles);
                     }
                     foreach ($option as $k => $opt) {
                         $id = Path::encode($opt);
                         if (strcasecmp($value, $id) == 0) {
                             $valtitles[$value] = $titles[$k];
                             return true;
                         }
                     }
                 }
                 return false;
             });
             if ($val['no']) {
                 unset($val['no']);
                 $val['Не указано'] = 1;
             }
             if ($val['yes']) {
                 unset($val['yes']);
                 $val['Указано'] = 1;
             }
             $filter['value'] = implode(', ', array_values($valtitles));
             $filters[] = $filter;
         } else {
             if (empty($md[$prop['mdid']])) {
                 continue;
             }
             $valtitles = array();
             $val = $md[$prop['mdid']];
             foreach ($val as $value => $one) {
                 $valtitles[$value] = $value;
             }
             $filter = array('title' => $prop['title'], 'name' => Sequence::short(array(Catalog::urlencode($prop['mdid']))));
             $poss = array_filter($poss, function ($pos) use($prop, $val, &$valtitles) {
                 foreach ($val as $value => $one) {
                     $option = $pos[$prop['posid']];
                     $titles = $pos[$prop['posname']];
                     if ($value === 'yes' && Xlsx::isSpecified($option)) {
                         return true;
                     }
                     if ($value === 'no' && !Xlsx::isSpecified($option)) {
                         return true;
                     }
                     if ($prop['separator']) {
                         $option = explode($prop['separator'], $option);
                         $titles = explode($prop['separator'], $titles);
                     } else {
                         $option = array($option);
                         $titles = array($titles);
                     }
                     foreach ($option as $k => $opt) {
                         $id = Path::encode($opt);
                         if (strcasecmp($value, $id) == 0) {
                             $valtitles[$value] = $titles[$k];
                             return true;
                         }
                     }
                 }
                 return false;
             });
             if ($val['no']) {
                 unset($val['no']);
                 $val['Не указано'] = 1;
             }
             if ($val['yes']) {
                 unset($val['yes']);
                 $val['Указано'] = 1;
             }
             $filter['value'] = implode(', ', array_values($valtitles));
             $filters[] = $filter;
         }
     }
     //Filter group
     $key = 'group';
     if (!empty($md[$key])) {
         $title = 'Группа';
         $val = $md[$key];
         $filter = array('title' => $title, 'name' => Sequence::short(array(Catalog::urlencode($key))));
         $poss = array_filter($poss, function ($pos) use($key, $val) {
             $prop = $pos[$key];
             foreach ($val as $value => $one) {
                 if ($value === 'yes') {
                     return true;
                 }
                 foreach ($pos['path'] as $path) {
                     if ((string) $value === $path) {
                         return true;
                     }
                 }
             }
             return false;
         });
         if ($val['no']) {
             unset($val['no']);
             $val['Не указано'] = 1;
         }
         if ($val['yes']) {
             unset($val['yes']);
             $val['Указано'] = 1;
         }
         $filter['value'] = implode(', ', array_keys($val));
         if ($md['search']) {
             $filters[] = $filter;
         }
     }
     //Filter search
     if (!empty($md['search'])) {
         $v = preg_split("/\\s+/", mb_strtolower($md['search']));
         foreach ($v as $i => $s) {
             $v[$i] = preg_replace("/ы\$/", "", $s);
         }
         $poss = array_filter($poss, function ($pos) use($v) {
             return Catalog::searchTest($pos, $v);
         });
         $filters[] = array('title' => 'Поиск', 'name' => 'search', 'value' => $md['search']);
     }
     //Extend::filtering($poss, $md, $filters);
     return $filters;
 }
Beispiel #12
0
namespace infrajs\crumb;

use infrajs\controller\Controller;
use infrajs\each\Each;
use infrajs\controller\Run;
use infrajs\controller\Layer;
use infrajs\path\Path;
use infrajs\event\Event;
use infrajs\sequence\Sequence;
use infrajs\template\Template;
use infrajs\session\Session;
use infrajs\controller\External;
Path::reqif('-controller/infra.php');
$cl = function ($name, $def = null) {
    return Session::get($name, $def);
};
Sequence::set(Template::$scope, Sequence::right('infra.session.get'), $cl);
$cl = function () {
    return Session::getLink();
};
Sequence::set(Template::$scope, Sequence::right('infra.session.getLink'), $cl);
$cl = function () {
    return Session::getTime();
};
Sequence::set(Template::$scope, Sequence::right('infra.session.getTime'), $cl);
$cl = function () {
    return Session::getId();
};
Sequence::set(Template::$scope, Sequence::right('infra.session.getId'), $cl);