Exemple #1
0
function autoedit_theme($isrc)
{
    $src = Access::cache('autoedit_theme', function ($isrc) {
        $src = Path::theme($isrc);
        if ($src) {
            return $src;
        }
        $fdata = Load::srcInfo($isrc);
        $folder = Path::theme($fdata['folder']);
        if (!Path::theme($folder)) {
            return false;
        }
        array_map(function ($file) use(&$result, $fdata) {
            if ($file[0] == '.') {
                return;
            }
            $file = Path::toutf($file);
            $fd = Load::nameInfo($file);
            if ($fdata['id'] && $fdata['id'] != $fd['id']) {
                return;
            }
            if ($fdata['name'] && $fdata['name'] != $fd['name']) {
                return;
            }
            if ($fdata['ext'] && $fdata['ext'] != $fd['ext']) {
                return;
            } elseif ($result) {
                //Расширение не указано и уже есть результат
                //Исключение.. расширение tpl самое авторитетное
                if ($fd['ext'] != 'tpl') {
                    return;
                }
            }
            $result = $file;
        }, scandir(Path::theme($folder)));
        if (!$result) {
            return false;
        }
        return Path::theme($folder . $result);
    }, array($isrc), isset($_GET['re']));
    return $src;
}
Exemple #2
0
$src = Access::cache('files_get_php', function ($isrc) {
    $src = Path::theme($isrc);
    if ($src) {
        return $src;
    }
    $fdata = Load::srcInfo($isrc);
    $folder = Path::theme($fdata['folder']);
    if (!Path::theme($folder)) {
        return false;
    }
    array_map(function ($file) use(&$result, $fdata) {
        if ($file[0] == '.') {
            return;
        }
        $file = Path::toutf($file);
        $fd = Load::nameInfo($file);
        if ($fdata['id'] && $fdata['id'] != $fd['id']) {
            return;
        }
        if ($fdata['name'] && $fdata['name'] != $fd['name']) {
            return;
        }
        if ($fdata['ext'] && $fdata['ext'] != $fd['ext']) {
            return;
        } elseif ($result) {
            //Расширение не указано и уже есть результат
            //Исключение.. расширение tpl самое авторитетное
            if ($fd['ext'] != 'tpl') {
                return;
            }
        }
Exemple #3
0
 public static function srcInfo($src)
 {
     $p = explode('?', $src);
     $file = array_shift($p);
     if ($p) {
         $query = '?' . implode('?', $p);
     } else {
         $query = '';
     }
     $p = explode('/', $file);
     $file = array_pop($p);
     if (sizeof($p) == 0) {
         if (preg_match("/^\\~/", $file)) {
             $file = preg_replace("/^\\~/", '', $file);
             $p[] = '~';
         } else {
             if (preg_match("/^\\*/", $file)) {
                 $file = preg_replace("/^\\-/", '', $file);
                 $p[] = '-';
             } else {
                 if (preg_match("/^\\|/", $file)) {
                     $file = preg_replace("/^\\!/", '', $file);
                     $p[] = '!';
                 }
             }
         }
     }
     $folder = implode('/', $p);
     if ($folder) {
         $folder .= '/';
     }
     $fdata = Load::nameInfo($file);
     $fdata['query'] = $query;
     $fdata['src'] = $src;
     $fdata['path'] = $folder . $file;
     $fdata['folder'] = $folder;
     return $fdata;
 }
Exemple #4
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);
Exemple #5
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']);
 }
Exemple #6
0
<?php

use infrajs\access\Access;
use infrajs\event\Event;
use infrajs\ans\Ans;
use infrajs\load\Load;
use infrajs\each\Each;
use infrajs\config\Config;
if (!is_file('vendor/autoload.php')) {
    chdir('../../../../');
    require_once 'vendor/autoload.php';
}
$ans = array('title' => 'Тест на совпадение названия указанного файла и его путь');
$file = Load::nameInfo('*1 file@23.txt');
$src = Load::srcInfo('*1 file@23.txt');
if ($file['id'] != 23 && $src['src'] != '*1 file@23.txt') {
    return Ans::err($ans, 'Такого файла не существует или не правидьно указан путь');
}
return Ans::ret($ans, 'Путь указан правильно, файл найден');
Exemple #7
0
function _rub_list($dir, $start, $count, $exts)
{
    if (!$dir) {
        return array();
    }
    $dir = Path::toutf($dir);
    $dir = Path::theme($dir);
    $res = array();
    if (!$dir || !is_dir($dir)) {
        return $res;
    }
    if (is_dir($dir) && ($dh = opendir($dir))) {
        $files = array();
        while (($file = readdir($dh)) !== false) {
            if ($file[0] == '.') {
                continue;
            }
            if ($file[0] == '~') {
                continue;
            }
            if ($file == 'Thumbs.db') {
                continue;
            }
            //depricated -> Rubrics::info();
            $rr = Load::nameInfo(Path::toutf($file));
            $ext = $rr['ext'];
            if ($exts && !in_array($ext, $exts)) {
                continue;
            }
            $size = filesize($dir . $file);
            $file = Path::toutf($file);
            if (in_array($ext, array('mht', 'tpl', 'html', 'txt', 'php'))) {
                $rr = Mht::preview(Path::toutf($dir) . $file);
            } elseif (in_array($ext, array('docx'))) {
                $rr = Docx::preview(Path::toutf($dir) . $file);
            }
            $rr['size'] = round($size / 1000000, 2);
            $links = @$rr['links'];
            if ($links) {
                unset($rr['links']);
                $ptube = rub_ptube();
                $ptube2 = rub_ptube();
                foreach ($links as $v) {
                    $r = preg_match('/' . $ptube . '/', $v['href'], $match);
                    $r2 = preg_match('/' . $ptube2 . '/', $v['href'], $match);
                    if ($r) {
                        if (!@$rr['video']) {
                            $rr['video'] = array();
                        }
                        $v['id'] = $match[1];
                        $rr['video'][] = $v;
                    } elseif ($r2) {
                        if (!@$rr['video']) {
                            $rr['video'] = array();
                        }
                        $v['id'] = $match[1];
                        $rr['video'][] = $v;
                    } else {
                        if (!@$rr['links']) {
                            $rr['links'] = array();
                        }
                        $rr['links'][] = $v;
                    }
                }
            }
            $files[] = $rr;
        }
        usort($files, function ($b, $a) {
            $a = @$a['date'];
            $b = @$b['date'];
            return $a < $b ? +1 : -1;
        });
        $maxid = 0;
        foreach ($files as $fdata) {
            if (!$fdata['id']) {
                continue;
            }
            if ($fdata['id'] > $maxid) {
                $maxid = $fdata['id'];
            }
        }
        foreach ($files as &$fdata) {
            if ($fdata['id'] && $fdata['date']) {
                continue;
            }
            if (!$fdata['id']) {
                $fdata['id'] = ++$maxid;
            }
        }
        $files = array_reverse($files);
        if ($count || $start) {
            $files = array_splice($files, $start, $count);
        }
        foreach ($files as $fdata) {
            $res[$fdata['id']] = $fdata;
        }
    }
    return $res;
}