Example #1
0
     $ans['size'] = ceil(filesize($file) / 1000);
     $ans['time'] = filemtime($file);
     preg_match("/\\.([a-zA-Z0-9]+)\$/", $file, $match);
     $ans['ext'] = strtolower($match[1]);
 }
 $ans['corable'] = in_array(strtolower($ans['ext']), $CORABLE);
 $ans['rteable'] = (bool) Path::theme('infra/lib/wymeditor/');
 if ($ans['rteable']) {
     $ans['rteable'] = in_array(strtolower($ans['ext']), $RTEABLE);
 }
 $conf = Config::get('imager');
 $imgext = $conf['images'];
 Each::forr($imgext, function &($e) use(&$ans) {
     if ($e == $ans['ext']) {
         $ans['image'] = true;
     }
     //Значит это картинка
     $r = null;
     return $r;
 });
 if ($file) {
     //Если файл есть
     $p = explode('/', $file);
     //Имя с расширением
     $ans['file'] = array_pop($p);
 } else {
     //Если файла нет.. определяем имя из id
     $p = explode('/', $id);
     //Имя с расширением
     $ans['file'] = array_pop($p);
 }
 $ans['file'] = preg_replace("/^\\~/", '', Path::toutf($ans['file']));
Example #2
0
    if ($el == 4) {
        return new Fix('del');
    }
    //пробовал передавать не new infra_Fix, а просто infra_Fix массив удалялся полностью, ну или просто функция неправильно срабатывала.
});
if ($res !== null) {
    return Ans::err($ans, 'Странный результат');
}
if ($count3 != $len) {
    return Ans::err($ans, 'Неожиданное количество выполненией');
}
if ($ar3[3] == 4) {
    return Ans::err($ans, 'Не работает удаление');
}
//Протестировать back
$ar = array(1, 2, 3, 4, 5, 6);
$count = 0;
$res = Each::forr($ar, function ($el) use(&$count) {
    return new Fix('del', false);
}, true);
if (isset($ar[5])) {
    return Ans::err($ans, 'Не работает back');
}
$ar = array(1, 2, 3, 4, 5, 6);
$res = Each::forr($ar, function ($el) {
    return $el;
}, true);
if ($res != 6) {
    return Ans::err($ans, 'Не работает back');
}
return Ans::ret($ans, 'Всё ок');
Example #3
0
Each::forr($ar, function ($v) use(&$count) {
    ++$count;
    if ($v == 'b') {
        return new Fix('del');
    }
}, true);
if ($count == 4 && sizeof($ar) == 3 && $ar[1] == 'c') {
} else {
    $result = false;
}
//simple
$ar = array('a', 'b', 'c', 'e');
$count = 0;
Each::forr($ar, function ($v) use(&$count) {
    ++$count;
    if ($v == 'b') {
        return new Fix('del');
    }
});
if ($count == 4 && sizeof($ar) == 3 && $ar[1] == 'c') {
} else {
    $result = false;
}
//obj
$ar = array('a' => 111, 'b' => 222, 'c' => 333, 'e' => 444);
$count = 0;
Each::foro($ar, function ($v, $key) use(&$count) {
    ++$count;
    if ($key == 'b') {
        return new Fix('del');
    }
});
Example #4
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']);
 }
Example #5
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));
 }