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; }); }
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); }
} $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'); }
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);
return Ans::ret($ans, 'SEO-данные сохранены'); } return Ans::err($ans, 'Ошибка. SEO-данные не сохранены'); } } elseif ($type === 'corfile') { if (!$submit) { $folder = Path::resolve($id); $path = explode('/', $folder); $name = array_pop($path); //Так как папка заканчивается на / последний элемент в массиве буедт всегда пустым $parent = implode('/', $path) . '/'; $parent = Path::pretty($parent); $ans['oldfolder'] = $parent; //Папка в которой можно увидеть обрабатываемую папку $ans['oldname'] = $name; $ans['content'] = Load::loadTEXT($id); return Ans::ret($ans); } else { $file = $id; //$isdir=Path::theme($file,'sdn'); //if($isdir) return infra_echo($ans,'Существует папка с именем как у файла '.$id); $isfile = Path::theme($file); if (!$isfile) { if (!autoedit_ext($file)) { $file .= '.tpl'; } $ans['msg'] .= 'Файл был создан<br>'; $file = autoedit_createPath($file); if (!$file) { return Ans::err($ans, 'Не удалось создать путь до файла' . $id); }
<?php namespace infrajs\template; use infrajs\load\Load; use infrajs\event\Event; use infrajs\config\Config; use infrajs\sequence\Sequence; use infrajs\path\Path; use infrajs\path\URN; use infrajs\view\view; //Template::$conf['root']=URN::getAbsRoot(); //Sequence::set(Template::$scope, array('~root'), Template::$conf['root']); Template::$fs['load'] = function ($src) { return Load::loadTEXT($src); }; $fn2 = function ($name = null) { return $conf = Config::pub($name); }; Sequence::set(Template::$scope, array('infra', 'config'), $fn2); Sequence::set(Template::$scope, array('Config', 'get'), $fn2); Event::one('Controller.oninit', function () { Template::$scope['~conf'] = Config::get(); }); $fn3 = function () { return View::getPath(); }; Sequence::set(Template::$scope, array('infra', 'view', 'getPath'), $fn3); $fn4 = function () { return View::getHost(); };
} } $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'];
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 () {
} else { $list[$name][] = Path::pretty($tsrc); } return $r; }); } $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') {
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'])); }
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; }
public static function loadCSS(&$js, $name) { $c = Config::get($name); if (empty($c['css'])) { return; } if (!empty($c['off'])) { return; } if (!empty($c['dependencies'])) { Each::exec($c['dependencies'], function &($name) use(&$js) { Collect::loadCSS($js, $name); $r = null; return $r; }); } if (!empty(Collect::$cssed[$name])) { return; } Collect::$cssed[$name] = true; $root = !empty($c['-collect']) && $c['-collect'] == 'root'; Each::exec($c['css'], function &($path) use($name, &$js, $root) { $r = null; if ($root) { $src = $path; } else { $src = '-' . $name . '/' . $path; } $js .= "\n\n" . '/*load css ' . $src . "*/\r\n"; if (!Path::theme($src)) { echo '<pre>'; throw new \Exception('Не найден файл ' . $src); } $js .= Load::loadTEXT('-csspath/?src=' . $src); return $r; }); }
} if (empty($conf[$name]['testerjs'])) { continue; } $list[$name] = []; $tsrc = $conf[$name]['testerjs']; $tsrc = Path::theme('-' . $name . '/' . $tsrc); if (!$tsrc) { echo '<pre>'; print_r($c); throw new \Exception('Tester. Некорректно указан путь до теста.'); } $list[$name] = Path::pretty($tsrc); } $ans['list'] = $list; return Ans::ret($ans); } $plugin = Ans::GET('plugin'); if ($plugin) { $conf = Config::get(); if (empty($conf[$plugin])) { return Ans::err($ans, 'Плагин не найден'); } if (empty($conf[$plugin]['testerjs'])) { return Ans::err($ans, 'Тесты у плагина не указаны testerjs'); } $code = Load::loadTEXT('-' . $plugin . '/' . $conf[$plugin]['testerjs']); echo $code; } else { return Ans::err($ans, 'Wrong parameters. Required list or plugin.'); }
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); }
public static function load($src) { if (!Path::theme($src)) { echo '<pre>'; echo $src; throw new \Exception('Не найден файл ' . $src); } return Load::loadTEXT($src); }