Exemple #1
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;
 }
Exemple #2
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) {
Exemple #3
0
 public static function &loadJSON($path)
 {
     $args = array($path);
     $res = Once::exec('Load::loadJSON', function ($path) {
         $res = array();
         $res['cache'] = !Nostore::check(function () use($path, &$text) {
             $text = Load::load($path);
         });
         if (is_string($text)) {
             $res['value'] = Load::json_decode($text);
         } else {
             $res['value'] = $text;
         }
         return $res;
     }, $args);
     if (!$res['cache']) {
         Nostore::on();
     }
     return $res['value'];
     return $res['value'];
 }
Exemple #4
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) {
Exemple #5
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 {
Exemple #6
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);
             }
         }
     });
 }
Exemple #7
0
 public static function &user_init($email)
 {
     $user = Session::getUser($email);
     $session_id = $user['session_id'];
     $nowsession_id = Session::getId();
     if ($session_id == $nowsession_id) {
         return Session::get();
     }
     return Once::exec(__FILE__ . 'user_init', function ($session_id) {
         $sql = 'select name, value, unix_timestamp(time) as time from ses_records where session_id=? order by time,rec_id';
         $db = Db::pdo();
         $stmt = $db->prepare($sql);
         $stmt->execute(array($session_id));
         $news = $stmt->fetchAll();
         if (!$news) {
             $news = array();
         }
         $obj = array();
         Each::forr($news, function &(&$v) use(&$obj) {
             $r = null;
             if ($v['value'] == 'null') {
                 $value = null;
             } else {
                 $value = Load::json_decode($v['value']);
             }
             $right = Sequence::right($v['name']);
             $obj = Sequence::set($obj, $right, $value);
             return $r;
         });
         return $obj;
     }, array($session_id));
 }
Exemple #8
0
<?php

namespace infrajs\infra;

use infrajs\access\Access;
use infrajs\event\Event;
use infrajs\ans\Ans;
use infrajs\load\Load;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../../');
    require_once 'vendor/autoload.php';
}
$ans = array();
$ans['title'] = 'Тест на декодирование JSON';
$source = '""';
$data = Load::json_decode($source);
if ($data !== '') {
    return Ans::err($ans, 'Не может декодировать');
}
return Ans::ret($ans, 'Декодировано');