Пример #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;
     });
 }
Пример #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]);
             }
         }
     }
 }
Пример #3
0
    Template::$scope['~conf'] = Config::get();
});
$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);
Пример #4
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;
 }
Пример #5
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;
Пример #6
0
$ans['auth'] = !!$session_id;
//Здесь session_id проверенный
if ($session_id && $timelast <= $time) {
    $sql = 'select name, value, unix_timestamp(time) as time from ses_records where session_id=? and time>=from_unixtime(?) order by time, rec_id';
    $stmt = $db->prepare($sql);
    $stmt->execute(array($session_id, $timelast));
    $news = $stmt->fetchAll();
    if ($list) {
        $ans['list'] = $list;
    }
    //$ans['orignews']=$news;
    if ($news) {
        $ans['news'] = $news;
        Each::fora($ans['news'], function &(&$n) use($list, &$ans) {
            $n['value'] = Load::json_decode($n['value'], true);
            $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']);
Пример #7
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']);
 }
Пример #8
0
 public static function right($short)
 {
     return Sequence::right($short, '/');
 }
Пример #9
0
 /**
  * Записывает в сессию session_id или email имя и значение.
  *
  * @param string|int	  $email Может быть $session_id
  * @param string|string[] $short Может быть $right путь до значения в объекте
  * @param mixed		   $value Значение для записи. Любое значение записывается даже null, которое по факту приводит к удалению значения
  *
  * @return void|string Строка-ошибка
  */
 public static function user_set($email, $short = array(), $value = null)
 {
     $user = Session::getUser($email);
     if (!$user) {
         return 'Email Not Found';
     }
     $obj =& Session::user_init($email);
     $right = Sequence::right($short);
     Sequence::set($obj, $right, $value);
     $list = array();
     $list['name'] = $right;
     $list['value'] = $value;
     $list['time'] = time();
     Session::writeNews($list, $user['session_id']);
 }
Пример #10
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);