Example #1
0
}
$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) {
    return Ans::err($ans, 'Cant read preview ' . $name . ' ' . sizeof($preview));
}
if (sizeof($preview['links']) != 1) {
    return Ans::err($ans, 'Cant read links ' . $name . ' ' . sizeof($preview['links']));
}
if (sizeof($preview['images']) != 2) {
    return Ans::err($ans, 'Cant read images ' . $name . ' ' . sizeof($preview['images']));
}
if (mb_strlen($preview['preview']) != 521) {
    return Ans::err($ans, 'Cant read ' . $name . ' preview ' . strlen($preview['preview']));
}
$name = 'test.tpl';
$text = Mht::get('-test-akiyatkin/resources/' . $name);
if (mb_strlen($text) != 1935) {
Example #2
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;
 }
Example #3
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;
}