} $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'); }
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; }
namespace infrajs\doc; use infrajs\access\Access; use infrajs\ans\Ans; use infrajs\path\Path; if (!is_file('vendor/autoload.php')) { chdir('../../../../'); require_once 'vendor/autoload.php'; } $ans = array(); Access::test(true); $text = Docx::get('-test-akiyatkin/resources/test.docx'); if (!$text || mb_strlen($text) != 1048) { return Ans::err($ans, 'Cant read file .docx mb_strlen ' . mb_strlen($text)); } $preview = Docx::preview('-test-akiyatkin/resources/test.docx'); if (sizeof($preview) != 12) { return Ans::err($ans, 'Cant read preview test.docx ' . sizeof($preview)); } if (sizeof($preview['links']) != 4) { return Ans::err($ans, 'Cant read links test.docx'); } if (sizeof($preview['images']) != 1) { return Ans::err($ans, 'Cant read images test.docx'); } if (mb_strlen($preview['preview']) != 119) { return Ans::err($ans, 'Cant read test.docx preview ' . mb_strlen($preview['preview'])); } $name = 'test.tpl'; $preview = Mht::preview('-test-akiyatkin/resources/' . $name); if (sizeof($preview) != 12) {
function docx_get($src, $type = 'norm', $re = false) { return Docx::get($src, $type, $re); }
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; }