Esempio n. 1
0
 public function load($src)
 {
     $item = Load::loadJSON($src);
     if (!$item) {
         $item = array();
     }
     if (!empty($item['external'])) {
         if (!is_array($item['external'])) {
             $item['external'] = explode(', ', $item['external']);
         }
         foreach ($item['external'] as $esrc) {
             if (!Path::theme($esrc)) {
                 echo '<pre>';
                 throw new \Exception('Not found seojson external ' . $esrc);
             }
             $ext = self::load($esrc);
             foreach ($ext as $k => $v) {
                 if (!isset($item[$k])) {
                     $item[$k] = $v;
                     continue;
                 }
             }
             if (!empty($ext['properties'])) {
                 foreach ($ext['properties'] as $k => $v) {
                     if (isset($item['properties'][$k])) {
                         continue;
                     }
                     $item['properties'][$k] = $v;
                 }
             }
             if (!empty($ext['names'])) {
                 foreach ($ext['names'] as $k => $v) {
                     if (isset($item['names'][$k])) {
                         continue;
                     }
                     $item['names'][$k] = $v;
                 }
             }
             if (!empty($ext['itemprops'])) {
                 foreach ($ext['itemprops'] as $k => $v) {
                     if (isset($item['itemprops'][$k])) {
                         continue;
                     }
                     $item['itemprops'][$k] = $v;
                 }
             }
         }
     }
     return $item;
 }
Esempio n. 2
0
 public static function check(&$layer)
 {
     if (!isset($layer['css'])) {
         return;
     }
     if (static::$ready[$css]) {
         return;
     }
     Each::fora($layer['css'], function ($css) use(&$layer) {
         Css::$ready[$css] = true;
         $code = Load::loadTEXT($css);
         View::html('<style>' . $code . '</style>', $layer['div']);
         $r = null;
         return $r;
     });
 }
Esempio n. 3
0
 public static function preview($src)
 {
     $param = self::parse($src);
     $data = Load::srcInfo($src);
     unset($data['query']);
     //$data = Load::nameInfo($data['file']);
     $temphtml = strip_tags($param['html'], '<p>');
     //preg_match('/^(<p.*>.{'.$previewlen.'}.*<\/p>)/U',$temphtml,$match);
     preg_match('/(<p.*>.{1}.*<\\/p>)/U', $temphtml, $match);
     if (sizeof($match) > 1) {
         $preview = $match[1];
     } else {
         $preview = $param['html'];
     }
     $preview = preg_replace('/<h1.*<\\/h1>/U', '', $preview);
     $preview = preg_replace('/<img.*>/U', '', $preview);
     $preview = preg_replace('/<p.*>\\s*<\\/p>/iU', '', $preview);
     $preview = preg_replace("/\\s+/", ' ', $preview);
     $preview = trim($preview);
     /*preg_match('/<img.*src=["\'](.*)["\'].*>/U', $param['html'], $match);
     		if ($match && $match[1]) {
     			$img = $match[1];
     		} else {
     			$img = false;
     		}*/
     $filetime = filemtime(Path::theme($src));
     $data['modified'] = $filetime;
     if (!empty($param['links'])) {
         $data['links'] = $param['links'];
     }
     if (!empty($param['heading'])) {
         $data['heading'] = $param['heading'];
     }
     //title - depricated
     if (!empty($data['name'])) {
         $data['title'] = $data['name'];
     }
     /*if ($img) {
     			$data['img'] = $img;
     		}*/
     if (!empty($param['images'])) {
         $data['images'] = $param['images'];
     }
     $data['preview'] = $preview;
     return $data;
 }
Esempio n. 4
0
 public static function checkExt(&$layer, &$external)
 {
     if (!$external) {
         return;
     }
     unset($layer['external']);
     Each::fora($external, function &(&$exter) use(&$layer) {
         if (is_string($exter)) {
             $external =& Load::loadJSON($exter);
         } else {
             $external = $exter;
         }
         if ($external) {
             foreach ($external as $i => &$v) {
                 external::merge($layer, $external, $i);
             }
         }
         $r = null;
         return $r;
     });
 }
Esempio n. 5
0
} elseif ($type == 'takefile') {
    if ($submit) {
        $take = (bool) $_GET['take'];
        $ans['take'] = $take;
        $file = autoedit_theme($id);
        $file = Path::toutf($file);
        if (!$file) {
            $ans['noaction'] = true;
            //Собственно всё осталось как было
        } else {
            $takepath = autoedit_takepath($file);
            if (!$take && is_file($takepath)) {
                $r = @unlink($takepath);
                if (!$r) {
                    return Ans::err($ans, 'Неудалось отпустить файл');
                }
            } elseif ($take && !is_file($takepath)) {
                //Повторно захватывать не будем
                $save = array('path' => $id, 'date' => time(), 'ip' => $_SERVER['REMOTE_ADDR'], 'browser' => $_SERVER['HTTP_USER_AGENT']);
                $r = file_put_contents($takepath, Load::json_encode($save));
                if (!$r) {
                    return Ans::err('Неудалось захватить файл');
                }
            } else {
                $ans['noaction'] = true;
                //Собственно всё осталось как было
            }
        }
    }
}
return Ans::ret($ans);
Esempio n. 6
0
        }
    }
    $br = infra_imager_browser();
    $name = preg_replace("/(.*\\/)*/", '', $isrc);
    if (!$name) {
        $name = Path::encode($isrc);
    }
    $name = Imager::toutf($name);
    if (!preg_match('/ff/', $br)) {
        $name = rawurlencode($name);
    }
    if (preg_match('/ie6/', $br)) {
        $name = preg_replace("/\\s/", '%20', $name);
    }
    if (!$type) {
        $type = 'image/jpeg';
    }
    $ans = array('name' => $name, 'type' => $type);
    //return $data;
    //}, $args, isset($_GET['re']));
    //)
    file_put_contents($cachesrc . '.data', $data);
    file_put_contents($cachesrc, Load::json_encode($ans));
    $ans['data'] = $data;
} else {
    $ans = Load::loadJSON($cachesrc);
    $ans['data'] = Load::loadTEXT($cachesrc . '.data');
}
header('Content-Disposition: filename="' . $ans['name'] . '";');
header('content-type: image/' . $ans['type']);
echo $ans['data'];
Esempio n. 7
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);
Esempio n. 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']);
 }
namespace infrajs\controller;

use infrajs\config\Config;
use infrajs\path\Path;
use infrajs\view\View;
use infrajs\load\Load;
use infrajs\ans\Ans;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../../');
    require_once 'vendor/autoload.php';
}
$ans = array();
$ans['title'] = 'check4';
$query = Crumb::$query;
Config::get('controller');
View::html('<div id="main1"></div><div id="main2"></div>', true);
$layers = Load::loadJSON('-test-akiyatkin/resources/check4.json');
Crumb::change('test');
Controller::check($layers);
$html = View::html();
preg_match_all('/x/', $html, $matches);
$count = sizeof($matches[0]);
$countneed = 2;
Crumb::change($query);
Layer::$start_id = 1;
Layer::$ids = array();
View::html('', true);
if ($count != $countneed) {
    return Ans::err($ans);
}
return Ans::ret($ans);
Esempio n. 10
0
<?php

namespace infrajs\controller;

use infrajs\ans\Ans;
use infrajs\path\Path;
use infrajs\view\View;
use infrajs\load\Load;
use infrajs\router\Router;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../../');
    require_once 'vendor/autoload.php';
    Router::init();
}
$query = Crumb::$href;
$ans = array('title' => 'Проверки контроллера');
$composer = Load::loadJSON('-infrajs/composer.json');
$require = $composer['require'];
foreach ($require as $path => $ver) {
    $p = explode('/', $path);
    $r = Path::reqif('-' . $p[1] . '/infra.php');
}
$layer = array('data' => 1, 'tpl' => array('qewr{data}'));
Crumb::change('');
$html = Controller::check($layer);
if ($html != 'qewr1') {
    return Ans::err($ans, 'Результат неожиданный ' . $html);
}
Crumb::change($query);
View::html('', true);
return Ans::ret($ans);
Esempio n. 11
0
    Router::init();
}
$ans = array();
$osrc = Ans::GET('src');
if (!$osrc) {
    return Ans::err($ans, 'Для работы необходимо передать параметр ?src= до папки с иллюстрациями: ' . $osrc);
}
$src = Path::theme($osrc);
if (!$src) {
    return Ans::err($ans, 'Неправильный путь до папки с иллюстрациями: ' . $osrc);
}
$list = Access::cache(__FILE__, function ($src) {
    $list = array();
    array_map(function ($file) use(&$list, $src) {
        if ($file[0] == '.') {
            return;
        }
        $fdata = Load::nameInfo($file);
        if (!in_array($fdata['ext'], array('jpg', 'jpeg', 'png'))) {
            return;
        }
        $list[] = $src . Path::toutf($file);
    }, scandir($src));
    return $list;
}, array($src));
$conf = Config::get('teremok');
$count = $conf['count'];
$count = Ans::GET('count', 'int', $count);
$list = array_slice($list, 0, $count);
$ans['list'] = $list;
return Ans::ret($ans);
Esempio n. 12
0
 function err($ans, $msg)
 {
     $ans['msg'] = $msg;
     echo Load::json_encode($ans);
 }
Esempio n. 13
0
    });
}
$data = array('list' => array());
$errors = array();
foreach ($list as $name => $files) {
    foreach ($files as $file) {
        $ext = Path::getExt($file);
        if ($ext != 'php') {
            continue;
        }
        $finfo = Load::srcInfo($file);
        $text = Load::loadTEXT($file . '?type=auto');
        if (strlen($text) > 1000) {
            $res = array('title' => $name . ' ' . $finfo['name'], 'result' => 0, 'msg' => 'Слишком длинный текст', 'class' => 'bg-warning');
        } else {
            $res = Load::json_decode($text, true);
            if (!is_array($res)) {
                $res = array('result' => 0, 'msg' => 'Некорректный json ' . print_r($res, true));
            }
        }
        $res['src'] = $finfo['src'];
        $res['name'] = $finfo['file'];
        //имя тестируемого файла
        if (!$res['result']) {
            $errors[] = $name . ' ' . $res['name'] . ' ' . $res['msg'];
        }
        if ($type == 'errors') {
            if (!$res['result']) {
                $data['list'][$name][] = $res;
            }
        } else {
Esempio n. 14
0
 public static function load($src, $name = null)
 {
     $src = Path::theme($src);
     if (!$src) {
         return;
     }
     Once::exec('Config::load::' . $src, function () use($src, $name) {
         $d = file_get_contents($src);
         try {
             $d = Load::json_decode($d);
         } catch (\Exception $e) {
         }
         if (!is_array($d)) {
             echo '<pre>';
             throw new \Exception('Wrong config ' . $src);
         }
         if ($name) {
             Config::accept($name, $d);
         } else {
             foreach ($d as $k => &$v) {
                 Config::accept($k, $v);
             }
         }
     });
 }
Esempio n. 15
0
}
$p = explode(',', $lim);
if (sizeof($p) != 2) {
    return Ans::err($ans, 'Is wrong paramter lim');
}
$start = (int) $p[0];
$count = (int) $p[1];
$args = array($start, $count);
$list = Catalog::cache('producers.php', function ($start, $count) {
    $ans = array();
    $data = Catalog::init();
    $prods = array();
    Xlsx::runPoss($data, function &(&$pos) use(&$prods) {
        if (empty($prods[$pos['producer']])) {
            $prods[$pos['producer']] = 0;
        }
        $prods[$pos['producer']]++;
        $r = null;
        return $r;
    });
    arsort($prods, SORT_NUMERIC);
    $prods = array_slice($prods, $start, $count);
    return $prods;
}, $args, isset($_GET['re']));
$ans['menu'] = Load::loadJSON('-catalog/menu.json');
$ans['list'] = $list;
$conf = Catalog::$conf;
$ans['breadcrumbs'][] = array('main' => true, 'href' => '', 'title' => 'Главная', 'add' => 'group');
$ans['breadcrumbs'][] = array('href' => '', 'title' => $conf['title'], 'add' => 'group');
$ans['breadcrumbs'][] = array('active' => true, 'href' => 'producers', 'title' => 'Производители');
return Ans::ret($ans);
Esempio n. 16
0
                }
                if (!is_file($dir . $file)) {
                    return;
                }
                $ext = Path::getExt($file);
                if ($ext != 'md') {
                    return;
                }
                $res = array('src' => $dir . $file, 'vendor' => $vendor, 'name' => $name, 'file' => $file);
                $map['vendors'][$vendor][$name]['list'][] = $res;
                $map['names'][$dir] =& $map['vendors'][$vendor][$name];
            }, scandir($dir));
        }, scandir($dir));
    }, scandir($dir));
    return $map;
});
$fd = Load::srcInfo($src);
if (isset($map['names'][$fd['folder']])) {
    $namedata = $map['names'][$fd['folder']];
} else {
    $namedata = array();
}
$text = file_get_contents(Path::theme($src));
$body = Markdown::defaultTransform($text);
//$data['files']=$files;
$data['map'] = $map;
$data['src'] = $src;
$data['namedata'] = $namedata;
$data['body'] = $body;
$html = Template::parse(Path::theme('-mdreader/index.tpl'), $data);
echo $html;
Esempio n. 17
0
 public static function article($src)
 {
     return Cache::exec(array($src), __FILE__, function ($src) {
         $html = Load::loadTEXT('-doc/get.php?src=' . $src);
         $info = Load::srcInfo($src);
         if (!in_array($info['ext'], array('html', 'tpl', 'php'))) {
             $soft = true;
         } else {
             $soft = false;
         }
         return Rubrics::parse($html, $soft);
     }, array($src), isset($_GET['re']));
 }
Esempio n. 18
0
<?php

use infrajs\load\Load;
use infrajs\router\Router;
use infrajs\ans\Ans;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../');
    require_once 'vendor/autoload.php';
    Router::init();
}
$ans = array();
$data = Load::loadJSON('-teremok/teremok.php?src=-teremok/images/');
if (!$data || !$data['result']) {
    return Ans::err($ans, 'Ошибка нет данных');
}
return Ans::ret($ans, 'Данные есть, теремок должен работать');
Esempio n. 19
0
    if (empty($conf['reCAPTCHA_secret'])) {
        return Ans::err($ans, 'Ошибка на сервере некорректно настроена <a href="https://www.google.com/recaptcha">reCAPTCHA</a>');
    }
    if (empty($_POST['g-recaptcha-response'])) {
        return Ans::err($ans, 'Ошибка, не пройдена проверка антибот.');
    }
    $ip = $_SERVER['REMOTE_ADDR'];
    $paramsArray = array('secret' => $conf['reCAPTCHA_secret'], 'response' => $_POST['g-recaptcha-response'], 'remoteip' => $ip);
    $vars = http_build_query($paramsArray);
    // преобразуем массив в URL-кодированную строку
    $options = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $vars));
    $context = stream_context_create($options);
    // создаём контекст потока
    $result = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context);
    //отправляем запрос
    $result = Load::json_decode($result, true);
    $ans['reCAPTCHA'] = $result;
    if (!$result || !$result['success']) {
        return Ans::err($ans, 'Ошибка, не пройдена спам проверка.');
    }
    if (empty($_POST['antispam'])) {
        $antispam = '';
    } else {
        $antispam = $_POST['antispam'];
    }
    if (!$antispam) {
        return Ans::err($ans, 'Не пройдена проверка антиспам.');
    }
}
if (in_array('name', $conf['required'])) {
    if (strlen($persona) < 2) {
Esempio n. 20
0
            if (!$group['path']) {
                $ans['breadcrumbs'][] = array('href' => 'producers', 'title' => 'Производители');
            }
        }
    }
    Catalog::sort($ans['list'], $md);
    //Numbers
    $pages = ceil(sizeof($ans['list']) / $md['count']);
    if ($pages < $page) {
        $page = $pages;
    }
    $ans['numbers'] = Catalog::numbers($page, $pages, 11);
    $ans['list'] = array_slice($ans['list'], ($page - 1) * $md['count'], $md['count']);
    //Text
    $src = Rubrics::find($conf['dir'] . 'articles/', $ans['title']);
    if ($src) {
        $ans['textinfo'] = Rubrics::info($src);
        $ans['text'] = Load::loadTEXT('-doc/get.php?src=' . $src);
        //Изменение текста не отражается как изменение каталога, должно быть вне кэша
    }
    foreach ($ans['list'] as $k => $pos) {
        $pos = Catalog::getPos($pos);
        $group = Catalog::getGroup($pos['group']);
        $pos['descr'] = $group['descr'];
        unset($pos['texts']);
        unset($pos['files']);
        $ans['list'][$k] = $pos;
    }
    return $ans;
}, $args, $re);
return Ans::ret($ans);
Esempio n. 21
0
<?php

namespace infrajs\load;

use infrajs\ans\Ans;
Ans::$conf['isReturn'] = function () {
    return Load::isphp();
};
Esempio n. 22
0
        }
        $result = $file;
    }, scandir(Path::theme($folder)));
    if (!$result) {
        return false;
    }
    return Path::theme($folder . $result);
}, array($fdata['path']), isset($_GET['re']));
$ans = array('src' => $isrc);
if (!$src) {
    if (!Load::isphp()) {
        header('HTTP/1.0 404 Not Found');
    }
    return;
}
$fdata = Load::srcInfo($src);
if (in_array($fdata['ext'], array('docx'))) {
    $txt = Docx::get($src);
    return Ans::txt($txt);
}
if (in_array($fdata['ext'], array('mht'))) {
    $txt = Mht::get($src);
    return Ans::txt($txt);
}
if (in_array($fdata['ext'], array('tpl', 'html', 'htm', 'php'))) {
    $txt = Load::loadTEXT($src);
    return Ans::txt($txt);
}
if (!Load::isphp()) {
    header('HTTP/1.0 400 Bad Request');
}
Esempio n. 23
0
 private static function load($path)
 {
     $args = array($path);
     $res = Once::exec('Load::load', function ($path) {
         //php файлы эмитация веб запроса
         //всё остальное file_get_content
         $_r_e_s_ = array();
         $_r_e_s_['cache'] = !Nostore::check(function () use($path, &$_r_e_s_) {
             if (Path::isDir($path)) {
                 $p = explode('?', $path, 2);
                 $p[0] .= 'index.php';
                 $path = implode('?', $p);
             }
             $load_path = Path::theme($path);
             $fdata = Load::srcinfo($load_path);
             if ($load_path && $fdata['file']) {
                 $plug = Path::theme($fdata['path']);
                 if ($fdata['ext'] == 'php') {
                     $getstr = Path::toutf($fdata['query']);
                     //get параметры в utf8, с вопросом
                     $getstr = preg_replace("/^\\?/", '', $getstr);
                     parse_str($getstr, $get);
                     if (!$get) {
                         $get = array();
                     }
                     $GET = $_GET;
                     $_GET = $get;
                     $REQUEST = $_REQUEST;
                     $_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
                     $SERVER_QUERY_STRING = $_SERVER['QUERY_STRING'];
                     $_SERVER['QUERY_STRING'] = $getstr;
                     $from_php_old = Load::isphp();
                     Load::isphp(true);
                     ob_start();
                     //headers надо ловить
                     $ans = array();
                     $rrr = (include $plug);
                     $result = ob_get_contents();
                     $resecho = $result;
                     ob_end_clean();
                     Load::isphp($from_php_old);
                     if ($rrr !== 1 && !is_null($rrr)) {
                         //Есть возвращённый результат
                         $result = $rrr;
                         if ($resecho) {
                             //Сообщение об ошибке... далее всё ломаем
                             $result = $resecho . Load::json_encode($result);
                             //Есть вывод в браузер и return
                         }
                     }
                     $_SERVER['QUERY_STRING'] = $SERVER_QUERY_STRING;
                     $_REQUEST =& $REQUEST;
                     $_GET =& $GET;
                     $data = $result;
                     //$data='php file';
                 } else {
                     $data = file_get_contents($plug);
                 }
                 $_r_e_s_ = array();
                 //Если в include это имя использовалось. Главное чтобы оно небыло ссылкой &
                 $_r_e_s_['status'] = 200;
                 $_r_e_s_['value'] = $data;
             } else {
                 $_r_e_s_['status'] = 404;
                 $_r_e_s_['value'] = '';
             }
         });
         return $_r_e_s_;
     }, $args);
     if (!$res['cache']) {
         Nostore::on();
     }
     return $res['value'];
 }
Esempio n. 24
0
 public static function getTpl(&$layer)
 {
     $tpl = $layer['tpl'];
     if (is_string($tpl)) {
         $tpl = Load::loadTEXT($tpl);
         //M доп параметры после :
     } elseif (is_array($tpl)) {
         $tpl = $tpl[0];
     } else {
         $tpl = '';
     }
     if (!$tpl) {
         $tpl = '';
     }
     return $tpl;
 }
Esempio n. 25
0
<?php

use infrajs\update\Update;
use infrajs\config\Config;
use infrajs\load\Load;
use infrajs\path\Path;
$conf = Config::get();
$sys = array();
foreach ($conf as $name => $c) {
    if ($c['clutch']) {
        $sys[$name] = array();
        $sys[$name]['clutch'] = $c['clutch'];
    }
}
$json = Load::json_encode($sys);
file_put_contents(Path::$conf['cache'] . '/.infra.json', $json);
Esempio n. 26
0
 private function makeMark($data)
 {
     if (!$data) {
         return '';
     }
     self::rksort($data);
     $key = md5(serialize($data));
     $that = $this;
     $mark = Once::exec($this->prefix . $key, function () use($data, $that, $key) {
         $isoutdate = true;
         $raise = $this->raise;
         //На сколько символов разрешено увеличивать хэш
         $note = $this->note;
         //При увеличении на сколько записывается сообщение в лог
         $len = $this->len - 1;
         while ($isoutdate && $len < $this->len + $raise) {
             $len++;
             $mark = substr($key, 0, $len);
             $src = Path::theme('~.marks/' . $that->prefix . $mark . '.json');
             if ($src) {
                 $otherdata = file_get_contents($src);
                 $otherdata = Load::json_decode($otherdata, true);
             } else {
                 $otherdata = false;
             }
             //$otherdata=infra_mem_get($that->prefix.$mark);
             if ($otherdata && is_array($otherdata['data']) && $otherdata['time']) {
                 if ($otherdata['data'] == $data) {
                     $isoutdate = false;
                     //Такая метка уже есть и она правильная
                 } else {
                     //Решается судьба старой метки
                     $isoutdate = time() > $data['time'] + $this->warrantytime;
                 }
             } else {
                 $isoutdate = false;
             }
         }
         if ($len >= $this->len + $note) {
             $that->notice = 'Mark adding to hash ' . ($len - $this->len) . ' symbol(s) for save time warranty ' . print_r($data, true);
             error_log($that->notice);
         }
         if ($isoutdate) {
             //Все метки актуальны... перезаписываем первую
             $that->error = 'Mark rewrite actual hashmark';
             error_log($that->error);
             $mark = substr($key, 0, $this->len);
         }
         $src = Path::theme('~.marks/');
         if (!$src) {
             die('Fatal error no marks dir');
         }
         $src = $src . $this->prefix . $mark . '.json';
         $data = Load::json_encode(array('time' => time(), 'data' => $data));
         $data = file_put_contents($src, $data);
         //infra_mem_set($that->prefix.$mark, array(
         //	'time'=>time(),
         //	'data'=>$data
         //));
         return $mark;
     });
     return $mark;
 }
Esempio n. 27
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) {
Esempio n. 28
0
<?php

namespace infrajs\controller;

use infrajs\router\Router;
use infrajs\load\Load;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../../');
    require_once 'vendor/autoload.php';
    Router::init();
}
$data = Controller::$conf['index'];
Run::exec($data, function &(&$layer) {
    while (@$layer['external'] && !Layer::pop($layer, 'onlyclient')) {
        $ext =& $layer['external'];
        External::checkExt($layer, $ext);
    }
    $r = null;
    return $r;
});
$data = Load::json_encode($data);
?>
infrajs.checkAdd(<?php 
echo $data;
?>
);
Event.handler('Crumb.onchange', function () {
	infrajs.check();
}, 'infrajs');<?php 
Esempio n. 29
0
 public static function parse($src)
 {
     $src = Path::theme($src);
     if (!$src) {
         return;
     }
     $args = array($src);
     return Cache::exec(array($src), 'mhtparse', function ($src) {
         $conf = Docx::$conf;
         $imgmaxwidth = $conf['imgmaxwidth'];
         $previewlen = $conf['previewlen'];
         $filename = Path::theme($src);
         $fdata = Load::srcInfo($src);
         if ($fdata['ext'] == 'php') {
             $data = Load::loadTEXT($filename);
         } else {
             $data = file_get_contents($filename);
         }
         $ans = array();
         if ($fdata['ext'] == 'mht') {
             $p = explode('/', $filename);
             $fname = array_pop($p);
             $fnameext = $fname;
             //$fname=basename($filename);
             preg_match("/^(\\d*)/", $fname, $match);
             $date = $match[0];
             $fname = Path::toutf(preg_replace('/^\\d*\\s+/', '', $fname));
             $fname = preg_replace('/\\.\\w{0,4}$/', '', $fname);
             $ar = preg_split('/------=_NextPart_.*/', $data);
             if (sizeof($ar) > 1) {
                 //На первом месте идёт информация о ворде...
                 unset($ar[0]);
                 unset($ar[sizeof($ar) - 1]);
             }
             $ar = array_values($ar);
             $folder = Path::mkdir(Docx::$conf['cache'] . md5($src) . '/');
             $html = '';
             for ($i = 0, $l = sizeof($ar); $i < $l; ++$i) {
                 if (!$ar[$i]) {
                     continue;
                 }
                 $d = preg_split("/\n/", $ar[$i], 6);
                 $j = -1;
                 do {
                     ++$j;
                 } while (@$d[$j][0] !== 'C' && $j <= 5);
                 if ($j >= 5) {
                     /*
                     	не нашли
                     	Content-Location: file:///C:/0FCF1655/file9909.files/header.htm
                     	Content-Transfer-Encoding: quoted-printable
                     	Content-Type: text/html; charset="us-ascii"
                     */
                     continue;
                 }
                 $location = preg_replace('/Content-Location: /', '', $d[$j]);
                 $location = trim($location);
                 $encoding = preg_replace('/Content-Transfer-Encoding: /', '', $d[$j + 1]);
                 $type = preg_replace('/Content-Type: /', '', $d[$j + 2]);
                 $content = $d[5];
                 $name = basename($location);
                 if (preg_match("/text\\/html/", $type) || preg_match('/Subject:/', $type)) {
                     $html .= $content;
                 } else {
                     @file_put_contents($folder . $name, base64_decode($content));
                     //Сохраняем картинку или тп...
                 }
             }
             if (!$html) {
                 $html = '';
             }
             $html = preg_replace("/=\r\n/", '', $html);
             $html = preg_replace("/\\s+/", ' ', $html);
             $html = preg_replace("/^.*<body .*>\\s*/U", '', $html, 1);
             $html = preg_replace("/\\s*<\\/body>.*/", '', $html, 1);
             $images = array();
             preg_match_all('/src=3D".*\\.files\\/(image.+)"/U', $html, $match, PREG_PATTERN_ORDER);
             for ($i = 0, $l = sizeof($match[1]); $i < $l; $i = $i + 2) {
                 $min = $match[1][$i + 1];
                 if (!$min) {
                     $min = $match[1][$i];
                 }
                 $images[$min] = $match[1][$i];
                 //Каждая следующая картинка есть уменьшенная копия предыдущей оригинального размера
             }
             $html = preg_replace("/<\\!--.*-->/U", '', $html);
             $html = preg_replace("/<!\\[if !vml\\]>/", '', $html);
             $html = preg_replace("/<!\\[endif\\]>/", '', $html);
             $html = preg_replace('/=3D/', '=', $html);
             $html = preg_replace('/align="right"/', 'align="right" class="right"', $html);
             $html = preg_replace('/align="left"/', 'align="left" class="left"', $html);
             $html = preg_replace('/align=right/', 'align="right" class="right"', $html);
             $html = preg_replace('/align=left/', 'align="left" class="left"', $html);
             $html = Path::toutf($html);
             //Виндовые файлы хранятся в cp1251
             $folder = Path::toutf($folder);
             $html = preg_replace('/ src=".*\\/(.*)"/U', ' src="' . $folder . '${1}"', $html);
             $html = preg_replace('/<span class=SpellE>(.*)<\\/span>/U', '${1}', $html);
             $html = preg_replace('/<span lang=.*>(.*)<\\/span>/U', '${1}', $html);
             $html = preg_replace('/<span class=GramE>(.*)<\\/span>/U', '${1}', $html);
             $html = preg_replace("/<span style='mso.*>(.*)<\\/span>/U", '${1}', $html);
             $html = preg_replace("/<span style='mso.*>(.*)<\\/span>/U", '${1}', $html);
             $html = preg_replace("/<span style='mso.*>(.*)<\\/span>/U", '${1}', $html);
             $html = preg_replace("/<span style='mso.*>(.*)<\\/span>/U", '${1}', $html);
             $html = preg_replace('/ class=MsoNormal/U', '', $html);
             $html = preg_replace('/<a name="_.*>(.*)<\\/a>/U', '${1}', $html);
             //Приводим к единому виду маркерные списки
             $patern = '/<p class=MsoListParagraphCxSp(\\w+) .*>(.*)<\\/p>/U';
             $count = 3;
             do {
                 preg_match($patern, $html, $match);
                 if (sizeof($match) == $count) {
                     $pos = strtolower($match[1]);
                     $text = $match[2];
                     $text = preg_replace('/^.*(<\\/span>)+/U', '', $text, 1);
                     $text = '<li>' . $text . '</li>';
                     if ($pos == 'first') {
                         $text = '<ul>' . $text;
                     }
                     if ($pos == 'last') {
                         $text = $text . '</ul>';
                     }
                     $html = preg_replace($patern, $text, $html, 1);
                 } else {
                     break;
                 }
             } while (sizeof($match) == $count);
             $title = $fname;
             $patern = '/<img(.*)>/U';
             $count = 2;
             do {
                 preg_match($patern, $html, $match);
                 if (sizeof($match) == $count) {
                     $sfind = $match[1];
                     //$sfind='<img src="/image.asdf">';
                     preg_match("/width=(\\d*)/", $sfind, $match2);
                     $w = trim($match2[1]);
                     preg_match("/height=(\\d*)/", $sfind, $match2);
                     $h = trim($match2[1]);
                     if (!$w || $w > $imgmaxwidth) {
                         $w = $imgmaxwidth;
                     }
                     preg_match('/src="(.*\\/)(image.*)"/U', $sfind, $match2);
                     $path = trim($match2[1]);
                     $small = $match2[2];
                     preg_match('/alt="(.*)".*/U', $sfind, $match2);
                     $alt = trim(@$match2[1]);
                     $alt = html_entity_decode($alt, ENT_QUOTES, 'utf-8');
                     preg_match('/align="(.*)".*/U', $sfind, $match2);
                     $align = trim($match2[1]);
                     $align = html_entity_decode($align, ENT_QUOTES, 'utf-8');
                     $big = $images[$small];
                     if (!$big) {
                         $big = $small;
                     }
                     $isbig = preg_match('/#/', $alt);
                     if ($isbig) {
                         $alt = preg_replace('/#/', '', $alt);
                     }
                     //$i="<IMG title='$alt' src='/-imager/?w=$w&h=$h&src=".($path.$big)."' align='$align' class='$align' alt='$alt'>";
                     $i = "<IMG src='/-imager/?w={$w}&h={$h}&src=" . ($path . $big) . "' align='{$align}' class='{$align}'>";
                     //urlencode решает проблему с ie7 когда иллюстрации с адресом содержащим пробел не показываются
                     if ($isbig) {
                         $i = "<a target='about:blank' href='/-imager/?src=" . urlencode($path . $big) . "'>{$i}</a>";
                     }
                     //$i.='<textarea style="width:500px; height:300px">'.$i.'</textarea>';
                     $html = preg_replace($patern, $i, $html, 1);
                 } else {
                     break;
                 }
             } while (sizeof($match) == $count);
             $patern = "/###\\{(.*)\\}###/U";
             //js код
             do {
                 preg_match($patern, $html, $match);
                 if (sizeof($match) > 0) {
                     $param = $match[1];
                     $param = strip_tags($param);
                     $param = html_entity_decode($param, ENT_QUOTES, 'utf-8');
                     $param = preg_replace('/(‘|’)/', "'", $param);
                     $param = preg_replace('/(“|«|»|”)/', '"', $param);
                     $html = preg_replace($patern, $param, $html, 1);
                 } else {
                     break;
                 }
             } while (sizeof($match) > 1);
             $patern = "/####.*<table.*>(.*)<\\/table>.*####/U";
             do {
                 preg_match($patern, $html, $match);
                 if (sizeof($match) > 0) {
                     $param = $match[1];
                     $param = preg_replace('/style=".*"/U', '', $param);
                     $param = preg_replace("/style='.*'/U", '', $param);
                     $html = preg_replace($patern, '<table class="table table-striped">' . $param . '</table>', $html, 1);
                 } else {
                     break;
                 }
             } while (sizeof($match) > 1);
             $ans['images'] = array();
             foreach ($images as $img) {
                 $ans['images'][] = array('src' => $folder . $img);
             }
         } else {
             $html = $data;
             $images = array();
             preg_match_all('/<img.*src="(.*)".*>/U', $html, $match, PREG_PATTERN_ORDER);
             for ($i = 0, $l = sizeof($match[1]); $i < $l; $i++) {
                 $images[] = array('src' => $match[1][$i]);
                 //Каждая следующая картинка есть уменьшенная копия предыдущей оригинального размера
             }
             $ans['images'] = $images;
         }
         $r = preg_match('/<h.*>(.*)<\\/h.>/U', $html, $match);
         if ($r) {
             $heading = strip_tags($match[1]);
         } else {
             $heading = false;
         }
         $ans['heading'] = $heading;
         preg_match_all('/<a.*href="(.*)".*>(.*)<\\/a>/U', $html, $match);
         $links = array();
         foreach ($match[1] as $k => $v) {
             $title = strip_tags($match[2][$k]);
             if (!$title) {
                 continue;
             }
             $links[] = array('title' => $title, 'href' => $match[1][$k]);
         }
         $ans['links'] = $links;
         $html = trim($html);
         $html = html_entity_decode($html, ENT_COMPAT, 'UTF-8');
         $html = preg_replace('/
/U', '', $html);
         //bugfix списки в mht порождаются адский символ. в eval-е скрипта недопустим.
         $ans['html'] = $html;
         foreach ($ans['images'] as &$item) {
             $item['src'] = preg_replace('/^\\//', '', $item['src']);
         }
         return $ans;
     }, $args);
 }
Esempio n. 30
0
    if (!isset($layer['is']) || is_null($layer['is'])) {
        $is = true;
    } else {
        $is = $layer['is'];
    }
    if ($is == '0') {
        $is = false;
    }
    //В шаблоне false не удаётся вернуть
    return $is;
}, 'is:div');
Event::handler('Layer.isshow', function (&$layer) {
    //tpl depricated
    if (is_string(@$layer['tpl']) && @$layer['tplcheck']) {
        //Мы не можем делать проверку пока другой плагин не подменит tpl
        $res = Load::loadTEXT($layer['tpl']);
        if (!$res) {
            return false;
        }
    }
}, 'tplcheck:is');
Event::handler('Layer.isshow', function (&$layer) {
    //tpl depricated
    if (Layer::pop($layer, 'onlyclient')) {
        return;
    }
    return Tpl::jsoncheck($layer);
}, 'jsoncheck:is');
Run::runAddKeys('childs');
Run::runAddList('child');
Event::handler('Layer.oninit', function () {