Esempio n. 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;
}
Esempio n. 2
0
 function file_download($filename, $mimetype = 'application/octet-stream')
 {
     //thanks http://shaman.asiadata.ru/node/217
     if (file_exists($filename)) {
         $br = infra_download_browser();
         $name = preg_replace("/(.*\\/)*/", '', $filename);
         //$name=Path::tofs($name);
         $name = Path::toutf($name);
         if (!preg_match('/ff/', $br)) {
             $name = rawurlencode($name);
         }
         //$name=preg_replace("/ё/",'e',$name);
         if (preg_match('/chrome/', $br)) {
             $name = preg_replace('/%40/', '@', $name);
         }
         if (preg_match('/ie6/', $br)) {
             $name = preg_replace("/\\s/", '%20', $name);
         }
         header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
         header('Content-Type: ' . $mimetype);
         header('Last-Modified: ' . gmdate('r', filemtime($filename)));
         header('ETag: ' . sprintf('%x-%x-%x', fileinode($filename), filesize($filename), filemtime($filename)));
         header('Content-Length: ' . filesize($filename));
         header('Connection: close');
         header('Content-Disposition: attachment; filename="' . $name . '";');
         // Открываем искомый файл
         $f = fopen($filename, 'r');
         while (!feof($f)) {
             // Читаем килобайтный блок, отдаем его в вывод и сбрасываем в буфер
             echo fread($f, 1024);
             flush();
         }
         // Закрываем файл
         fclose($f);
     } else {
         header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
         header('Status: 404 Not Found');
     }
 }
Esempio n. 3
0
 public static function tofs($str)
 {
     if (isset($_SERVER['WINDIR'])) {
         $str = Path::toutf($str);
         $str = iconv('UTF-8', 'CP1251', $str);
     }
     return $str;
 }
Esempio n. 4
0
     }
     $sysdir = $dir . $file . '/';
     if ($sysdir == './' . Path::$conf['data']) {
         return;
     }
     if ($sysdir == './' . Path::$conf['cache']) {
         return;
     }
     if ($sysdir == './vendor/') {
         return;
     }
 } else {
     if ($file[0] == '.') {
         return;
     }
     $name = Path::toutf($file);
 }
 $dir = $dir . $file . '/';
 if (empty($map['vendors'][$vendor][$name])) {
     $map['vendors'][$vendor][$name] = array('src' => $dir . 'README.md', 'vendor' => $vendor, 'name' => $name, 'is' => is_file($dir . 'README.md'), 'list' => array());
 }
 array_map(function ($file) use(&$map, $dir, $vendor, $name) {
     if ($file[0] == '.') {
         return;
     }
     if (!is_file($dir . $file)) {
         return;
     }
     $ext = Path::getExt($file);
     if ($ext != 'md') {
         return;
Esempio n. 5
0
 public static function info($src)
 {
     if (!Path::theme($src)) {
         return array();
     }
     $rr = Load::srcInfo($src);
     $ext = $rr['ext'];
     $size = filesize(Path::theme($src));
     if (in_array($ext, array('mht', 'tpl', 'html', 'txt', 'php'))) {
         $rr = Mht::preview($src);
     } elseif (in_array($ext, array('docx'))) {
         $rr = Docx::preview($src);
     }
     $rr['size'] = round($size / 1000000, 2);
     //Mb
     if (!empty($rr['links'])) {
         $links = $rr['links'];
         unset($rr['links']);
         foreach ($links as $v) {
             $r = preg_match('/http.*youtube\\.com.*watch.*=([\\w\\-]+).*/', $v['href'], $match);
             $r2 = preg_match('/http.{0,1}:\\/\\/youtu\\.be\\/([\\w\\-]+)/', $v['href'], $match);
             if ($r) {
                 if (empty($rr['video'])) {
                     $rr['video'] = array();
                 }
                 $v['id'] = $match[1];
                 $rr['video'][] = $v;
             } elseif ($r2) {
                 if (empty($rr['video'])) {
                     $rr['video'] = array();
                 }
                 $v['id'] = $match[1];
                 $rr['video'][] = $v;
             } else {
                 if (empty($rr['links'])) {
                     $rr['links'] = array();
                 }
                 $rr['links'][] = $v;
             }
         }
     }
     if (!empty($rr['name'])) {
         $dir = Path::theme($rr['folder'] . $rr['name'] . '/');
         if ($dir) {
             $list = array();
             array_map(function ($file) use(&$list, $src) {
                 if ($file[0] == '.') {
                     return;
                 }
                 //if (!is_file($dir.$file)) return;
                 $fd = Load::nameinfo($file);
                 if (!in_array($fd['ext'], ['jpeg', 'jpg', 'png'])) {
                     return;
                 }
                 $list[] = Path::toutf($fd);
             }, scandir($dir));
             Load::sort($list, 'ascending');
             foreach ($list as $k => $fd) {
                 $list[$k] = Path::toutf($fd['file']);
             }
             $rr['gallerydir'] = $rr['folder'] . $rr['name'] . '/';
             $rr['gallery'] = $list;
         }
     }
     return $rr;
 }
Esempio n. 6
0
/*
	type два смысла.. type blog - имя рубрики и type list то как отображается всё
*/
if (empty($conf['list'][$type])) {
    return Ans::err($ans, 'Undefined type ' . $type);
}
$dir = '~' . $type . '/';
$ans['type'] = $conf['list'][$type];
if (in_array($conf['list'][$type]['type'], array('list', 'info'))) {
    $exts = array('docx', 'tpl', 'mht', 'html', 'php');
} else {
    $exts = array();
}
if (!empty($_GET['id'])) {
    //Загрузка файла
    $id = Path::toutf($_GET['id']);
    $res = rub_search($dir, $id, $exts);
    if (isset($_GET['image'])) {
        if ($res['images']) {
            $data = file_get_contents(Path::tofs($res['images'][0]['src']));
            echo $data;
        } else {
            //@header('HTTP/1.1 404 Not Found');
        }
        return;
    } elseif (isset($_GET['show'])) {
        if (!$res) {
            header("HTTP/1.0 404 Not Found");
            return;
        } else {
            $src = $dir . $res['file'];
Esempio n. 7
0
$fdata = Load::srcInfo($isrc);
$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;
            }
Esempio n. 8
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. 9
0
function docx_analyse($el, $key, &$param, $keyparent)
{
    $tag = array('', '');
    $isli = false;
    $isheading = false;
    $h = '';
    $t = '';
    //Таблицы
    if (is_array($el) && @$el['tbl'] == '1') {
        $param['istable'] = true;
        $tag = array("<table class='table table-striped'>\n", '</table>');
    } elseif ($key === 'w:tr' && $param['istable']) {
        $tag = array("<tr>\n", '</tr>');
        //}else if($key==='w:p'&&$param['istable']){
    } elseif ($key === 'w:tc' && $param['istable']) {
        $tag = array('<td>', '</td>');
    } elseif ($key == 'w:pict' && $el['v:shape']) {
        $rid = $el['v:shape']['v:imagedata']['id'];
        $src = $param['folder'] . 'word/' . $param['rIds'][$rid];
        $style = $el['v:shape']['style'];
        if (preg_match('/:right/', $style)) {
            $align = 'right';
        } else {
            $align = 'left';
        }
        if (!$param['images']) {
            $param['images'] = array();
        }
        $param['images'][] = array('src' => Path::toutf($src));
        //$tag=array('<img align="'.$align.'" src="'.$src.'">','');
        $tag = array('<div style="background-color:gray; color:white; font-weight:normal; padding:5px; font-size:14px; float:' . $align . '">Некорректно<br>добавленная<br>картинка</div>', '');
        //Картинки
    } elseif ($keyparent === 'w:drawing') {
        if (!@$param['imgnum']) {
            $param['imgnum'] = 0;
        }
        $imgnum = ++$param['imgnum'];
        //$origsrc=$el['wp:docPr']['descr'];
        $inline = $key == 'wp:inline';
        $align = @$el['wp:positionH']['wp:align'];
        if ($align !== 'left') {
            $align = 'right';
        }
        $width = ceil($el['wp:extent']['cx'] / 8000);
        $height = ceil($el['wp:extent']['cy'] / 8000);
        if ($width > $param['imgmaxwidth']) {
            $width = $param['imgmaxwidth'];
            $height = '';
        }
        $src = $param['folder'] . 'word/media/image' . $imgnum;
        if (is_file($src . '.jpeg')) {
            $src .= '.jpeg';
        } elseif (is_file($src . '.jpg')) {
            $src .= '.jpg';
        } elseif (is_file($src . '.png')) {
            $src .= '.png';
        } elseif (is_file($src . '.gif')) {
            $src .= '.gif';
        } else {
            $src .= '.wtf';
        }
        $alt = @$el['wp:docPr']['title'];
        if (!@$param['images']) {
            $param['images'] = array();
        }
        $param['images'][] = array('src' => Path::toutf($src));
        $src = '/-imager/?src=' . Path::toutf($src);
        if ($height) {
            $src .= '&h=' . $height;
        }
        if ($width) {
            $src .= '&w=' . $width;
        }
        $tag = '<img src="' . $src . '"';
        //if($height)$tag.=' height="'.$height.'px"';
        //if($width)$tag.=' width="'.$width.'px"';
        if ($alt) {
            $tag .= ' alt="' . $alt . '"';
        } else {
            $tag .= ' alt=""';
        }
        if (!$inline && $align) {
            $tag .= ' class="img-thumbnail ' . $align . '"';
        } else {
            $tag .= ' class="img-thumbnail"';
        }
        $tag .= '>';
        $tag = array($tag, '');
        if (isset($el['wp:docPr']) && isset($el['wp:docPr']['a:hlinkClick'])) {
            //Ссылка на самой картинке
            $r = $el['wp:docPr']['a:hlinkClick']['id'];
            $link = $param['rIds'][$r];
            $tag[0] = '<a href="' . $link . '">' . $tag[0];
            $tag[1] = '</a>';
        }
        //Список
    } elseif ($key === 'w:p' && @$el['w:pPr'] && @$el['w:pPr']['w:numPr']) {
        $isli = true;
        $param['isli'] = true;
        $v = @$el['w:pPr']['w:numPr']['w:numId'];
        if (@$param['isul'] !== $v) {
            if (@$param['isul']) {
                $h .= "</ul>\n";
            }
            $param['isul'] = $v;
            $h .= "<ul>\n";
            $tag = array('<li>', '</li>');
        } else {
            $tag = array('<li>', '</li>');
        }
        //h1 h2 h3 h4
    } elseif ($key === 'w:p' && @$el['rsidR'] && @$el['w:pPr'] && @$el['w:pPr']['w:pStyle'] && in_array(@$el['w:pPr']['w:pStyle']['val'], array(1, 2, 3, 4, 5, 6))) {
        $isheading = true;
        $v = $el['w:pPr']['w:pStyle']['val'];
        $tag = array('<h' . $v . '>', '</h' . $v . ">\n");
        //Абзац
    } elseif ($key === 'w:p' && @$el['rsidR']) {
        $tag = array('<p>', "</p>\n");
        //a
    } elseif ($key === 'w:r' && @$el['history']) {
        $href = $param['rIds'][$el['id']];
        $tag = array('<a href="' . $href . '">', '</a>');
        //b i u
    } elseif ($key === 'w:r' && @$el['w:rPr'] && (isset($el['w:rPr']['w:i']) || isset($el['w:rPr']['w:b']) || isset($el['w:rPr']['w:u']))) {
        if (isset($el['w:rPr']['w:i'])) {
            $tag[0] .= '<i>';
        }
        if (isset($el['w:rPr']['w:b'])) {
            $tag[0] .= '<b>';
        }
        if (isset($el['w:rPr']['w:u'])) {
            $tag[0] .= '<u>';
        }
        if (isset($el['w:rPr']['w:u'])) {
            $tag[1] .= '</u>';
        }
        if (isset($el['w:rPr']['w:b'])) {
            $tag[1] .= '</b>';
        }
        if (isset($el['w:rPr']['w:i'])) {
            $tag[1] .= '</i>';
        }
        //<i>
    } elseif ($key === 'w:r' && @$el['w:rPr'] && isset($el['w:rPr']['w:i'])) {
        $tag = array('<i>', '</i>');
        //<b>
    } elseif ($key === 'w:r' && @$el['w:rPr'] && isset($el['w:rPr']['w:b'])) {
        $tag = array('<b>', '</b>');
        //<br>
    } elseif ($key === 'w:br') {
        $tag = array('<br>', '');
    }
    //Список
    if (@$param['isul'] && !@$param['isli']) {
        //Есть метка что мы в ul и нет что в li
        $param['isul'] = false;
        $h .= '</ul>';
    }
    //=====================
    if ($key === 'w:t') {
        //Текст
        if (is_string($el)) {
            $t .= $el;
        } else {
            $t .= $el['_value'];
        }
        $h .= $tag[0] . $t;
    } else {
        //Вложенность
        $hr = docx_each($el, '\\infrajs\\doc\\docx_analyse', $param, $key);
        if ($tag[0] == '<p>' && preg_match("/\\{.*\\}/", $hr)) {
            $t = strip_tags($hr);
            if ($t[0] == '{' && $t[strlen($t) - 1] == '}') {
                $t = substr($t, 1, strlen($t) - 2);
                $t = explode(':', $t);
                if (sizeof($t) == 2) {
                    $name = $t[0];
                    $val = $t[1];
                    if ($name == 'div') {
                        //envdiv {div:tadam}
                        //чтобы обработать env нужно уже загрузить этот слой к этому времени env обработаны
                        //$hr='<script>if(window.infra)infra.when(infrajs,"onshow",function(){ infrajs.envSet("'.$t[1].'",true)});</script>';
                        $tag[0] = '<div id="' . $val . '">';
                        $tag[1] = '</div>';
                        $hr = '';
                    }
                }
            }
        }
        $h .= $tag[0];
        //Открывающий тэг
        //<a>
        if ($isheading && !@$param['heading']) {
            $param['heading'] = strip_tags($hr);
        }
        if ($key === 'w:r' && @$el['history']) {
            if (!@$param['links']) {
                $param['links'] = array();
            }
            $href = $param['rIds'][$el['id']];
            $param['links'][] = array('href' => $href, 'title' => strip_tags($hr));
        }
        $h .= $hr;
    }
    //=====================
    //Таблицы
    if (is_array($el) && @$el['tbl'] == '1') {
        $param['istable'] = false;
        //Список
    } elseif ($isli) {
        //Вышли из какого-то li
        $param['isli'] = false;
    } elseif ($isheading) {
        //Вышли из какого-то li
        $isheading = false;
    }
    $h .= $tag[1];
    //Закрывающий тэг
    return $h;
}
Esempio n. 10
0
function &imager_makeInfo($src)
{
    $info = imager_readInfo($src);
    if ($info) {
        return $info;
    }
    $dir = '~imager/';
    Path::mkdir($dir);
    $dir .= '.notwater/';
    Path::mkdir($dir);
    $i = '';
    $orig = $dir . Path::encode($src);
    while (is_file($orig)) {
        $orig = $orig . $i;
        $i .= 'i';
    }
    $r = copy($src, $orig);
    //по адресу orig не существует файла было проверено
    if (!$r) {
        die('Не удалось сохранить оригинал');
    }
    $info = array();
    $info['host'] = $_SERVER['HTTP_HOST'];
    $info['size'] = filesize(Path::tofs($orig));
    $info['date'] = date('j.m.Y');
    $info['orig'] = Path::toutf($orig);
    return $info;
}
Esempio n. 11
0
<?php

namespace infrajs\catalog;

use infrajs\nostore\Nostore;
use infrajs\excel\Xlsx;
use infrajs\view\View;
use infrajs\path\Path;
use infrajs\ans\Ans;
use infrajs\config\Config;
//Nostoer::on();
$orig_val = Path::toutf(strip_tags($_GET['val']));
$orig_art = Path::toutf(strip_tags($_GET['art']));
$val = mb_strtolower($orig_val);
$art = mb_strtolower($orig_art);
$args = array($val, $art);
$ans = array();
$pos = Catalog::cache('position', function ($val, $art) {
    $data = Catalog::init();
    // список всей продукции
    return Xlsx::runPoss($data, function &(&$pos, $i, &$group) use(&$val, &$art) {
        $r = null;
        if (mb_strtolower($pos['producer']) !== $val) {
            return $r;
        }
        if (mb_strtolower($pos['article']) !== $art) {
            return $r;
        }
        return $pos;
    });
}, $args, isset($_GET['re']));
Esempio n. 12
0
 public static function getPos(&$pos)
 {
     $args = array($pos['producer'], $pos['article']);
     return Access::cache('Catalog::getPos', function () use($pos) {
         Xlsx::addFiles(Catalog::$conf['dir'], $pos);
         $files = explode(',', @$pos['Файлы']);
         foreach ($files as $f) {
             if (!$f) {
                 continue;
             }
             $f = trim($f);
             Xlsx::addFiles(Catalog::$conf['dir'], $pos, $f);
         }
         $files = array();
         foreach ($pos['files'] as $f) {
             if (is_string($f)) {
                 $f = Path::theme($f);
                 //убрали звездочку
                 $d = Load::srcInfo(Path::toutf($f));
             } else {
                 $d = $f;
                 $f = $d['src'];
             }
             $d['size'] = round(filesize(Path::tofs($f)) / 1000000, 2);
             if (!$d['size']) {
                 $d['size'] = '0.01';
             }
             $d['src'] = Path::pretty($d['src']);
             $files[] = $d;
         }
         $pos['files'] = $files;
         if ($pos['texts']) {
             foreach ($pos['texts'] as $k => $t) {
                 $pos['texts'][$k] = Load::loadTEXT('-doc/get.php?src=' . $t);
             }
         }
         return $pos;
     }, $args);
 }
Esempio n. 13
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;
}
Esempio n. 14
0
namespace infrajs\infra;

use infrajs\access\Access;
use infrajs\event\Event;
use infrajs\ans\Ans;
use infrajs\path\Path;
use infrajs\session\Session;
if (!is_file('vendor/autoload.php')) {
    chdir(explode('vendor/', __DIR__)[0]);
    require_once 'vendor/autoload.php';
}
Access::admin(true);
$ans = array();
if (isset($_GET['get'])) {
    $name = Ans::REQ('name');
    $ans['id'] = Session::getId();
    $ans['data'] = Session::get($name);
} else {
    if (isset($_GET['clear'])) {
        Session::clear();
    } else {
        if (isset($_GET['set'])) {
            $ans = array();
            $name = Path::toutf($_REQUEST['name']);
            $val = Path::toutf($_REQUEST['val']);
            Session::set($name, $val);
        }
    }
}
return Ans::ret($ans);
Esempio n. 15
0
         unset($_SESSION['imager']['files'][$k]);
         //Чтобы при обнолении страницы, не бегать снова
     }
     //Теперь у нас есть только массив origs
     foreach ($_SESSION['imager']['origs'] as $orig => $srcs) {
         $origf = Path::theme($orig);
         if (!$origf) {
             //if(preg_match("/^core\/data\//",$orig))continue;//старая версия сайта ничего с этим не поделать
             //die('Не найден оригинал '.Path::toutf($orig)." для картинки ".Path::toutf(print_r($srcs,true)).'<br>\n');
             echo 'Не найден оригинал ' . Path::toutf($orig) . ' для картинки ' . Path::toutf(print_r($srcs, true)) . '<br>\\n';
             continue;
         }
         foreach ($srcs as $src) {
             $r = copy($origf, $src);
             if (!$r) {
                 die('Не удалось скопировать на место оригинал ' . Path::toutf($src));
             }
         }
         $r = unlink($origf);
         if (!$r) {
             die('Не удалось удалить востановленный оригинал');
         }
         unset($_SESSION['imager']['origs'][$orig]);
         //Пометили что этот оригинал уже востановили
     }
     $files = Iadmin::runfolder($dirorig, 1, 0);
     unset($_SESSION['imager']);
 } elseif ($act == 'delcache') {
     infra_mem_flush();
 }
 header('location: /-imager/admin.php');
Esempio n. 16
0
        return Ans::err($ans, 'Письмо уже отправлено! Новое сообщение можно будет отправить через 1 минуту!');
    }
    $_SESSION['submit_time'] = time();
}
$ans['testmail'] = $mdata['testmail'];
if ($maildir) {
    $folder = Path::theme($maildir);
    $name = Path::tofs(Path::encode($data['name']));
    $fname = date('Y F j H-i') . ' ' . $name . ' ' . time();
    if ($conf['file'] && $file) {
        $src = $folder . $fname . '.' . Path::tofs($file['name']);
        $r = move_uploaded_file($file['tmp_name'], $src);
        if (!$r) {
            return Ans::err($ans, 'Неудалось загрузить файл');
        }
        $data['file'] = Path::toutf(Path::pretty($src));
    }
}
$body = Template::parse('-contacts/mail.tpl', $data);
if (!$body) {
    $body = 'Ошибка. Не найден шаблон письма!';
}
if ($maildir) {
    file_put_contents($folder . $fname . '.txt', print_r($body, true) . "\n\n\n\n\n" . print_r($mdata, true));
}
if (!isset($mdata['email_from'])) {
    return Ans::err($ans, 'Ошибка с адресом получателя!');
}
$r = Mail::toAdmin($mdata['subject'], $mdata['email_from'], $body, $mdata['testmail']);
if (!$r) {
    return Ans::err($ans, "Неудалось отправить письмо из-за ошибки на сервере!");
Esempio n. 17
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']);
 }
Esempio n. 18
0
<?php

namespace infrajs\catalog;

use infrajs\excel\Xlsx;
use infrajs\path\Path;
use infrajs\ans\Ans;
use infrajs\load\Load;
use infrajs\view\View;
use infrajs\nostore\Nostore;
use infrajs\config\Config;
use infrajs\rubrics\Rubrics;
$ans = array();
$md = Catalog::initMark($ans);
$val = Ans::GET('val');
$val = Path::toutf(strip_tags($val));
if ($val) {
    $md['search'] = $val;
}
//Временное значение
if (isset($_GET['seo'])) {
    $link = $_GET['seo'];
    if ($md['group']) {
        foreach ($md['group'] as $val => $one) {
            break;
        }
        $link = $link . '?m=:group.' . $val . '=1';
    } else {
        if ($md['producer']) {
            foreach ($md['producer'] as $val => $one) {
                break;
Esempio n. 19
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. 20
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. 21
0
        array_map(function ($file) use(&$list, $dir) {
            if ($file[0] == '.') {
                return;
            }
            if ($file[0] == '~') {
                return;
            }
            //Скрытый файл Word
            if (!is_file(Path::theme($dir) . $file)) {
                return;
            }
            $fd = Load::nameinfo($file);
            if (!in_array($fd['ext'], array('docx', 'html', 'tpl'))) {
                return;
            }
            $list[] = Rubrics::info(Path::toutf($dir . $file));
        }, scandir(Path::theme($dir)));
        Load::sort($list);
        return $list;
    }, array($dir));
    $list = array_slice($list, $start, $count);
    $ans['list'] = $list;
} else {
    if ($type == 'page') {
        if ($type == 'page') {
            $id = Ans::GET('id');
        }
        if (!$id) {
            return Ans::err($ans, 'Для type=page необходимо указать id страницы');
        }
        $src = Rubrics::find($dir, $id);