public function genMicrotronData()
 {
     $url = "http://www.microtron.ua/price/mt1.zip";
     $path = Yii::$app->basePath . "/web/uploads/microtron/";
     $filename = $path . "mt1.zip";
     /* Download zip*/
     file_put_contents($filename, file_get_contents($url));
     /* Extract zip*/
     $res = UnifiedArchive::open($filename);
     $res->extractNode($path);
     /* Work with xls*/
     $xls = $path . $res->getFileNames()[0];
     $objReader = \PHPExcel_IOFactory::createReader(\PHPExcel_IOFactory::identify($xls));
     $objReader->setReadDataOnly(true);
     $objPHPExcelReader = $objReader->load($xls);
     $data = [];
     $sheet = $objPHPExcelReader->getSheet(0);
     $highestRow = $sheet->getHighestRow();
     $highestColumn = $sheet->getHighestColumn();
     for ($row = 1; $row <= $highestRow; $row++) {
         $data[] = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
     }
     foreach ($data as &$item) {
         foreach ($item as &$sub) {
             $sub = array_filter($sub);
         }
         $item = array_filter($item);
     }
     $data = array_filter(array_slice($data, 8, count($data), true));
     foreach ($data as &$sub) {
         if (isset($sub[0])) {
             $sub = $sub[0];
             if (is_string($sub[0])) {
                 $sub = '';
             }
         } else {
             $sub = null;
         }
     }
     $data = array_filter($data);
     $response = [];
     foreach ($data as $item) {
         $response[] = array("product" => $item[1], "price" => isset($item[7]) ? $item[7] : "", "url" => $item[10], "store" => "microtron");
     }
     return $response;
 }
Esempio n. 2
0
#!/usr/bin/php
<?php 
use wapmorgan\UnifiedArchive\UnifiedArchive;
require dirname(dirname(__FILE__)) . '/vendor/autoload.php';
$opts = getopt("lthdeuia:o:n:");
echo "Usage: " . $argv[0] . " -l/-t/-h/-d/-e/-u/-i {-a archive} " . "[-n nodeForDetails|nodeForExtract|nodeForUnpack] " . "[-o outputDirForExtract]" . PHP_EOL;
echo "nodes actions: list / table / hierarchy; " . "node actions: details / extract / unpack; " . "stat actions: information;" . PHP_EOL;
if (!isset($opts['a'])) {
    exit;
}
$archive = \wapmorgan\UnifiedArchive\UnifiedArchive::open($opts['a']);
$files = $archive->getFileNames();
sort($files);
if (isset($opts['l'])) {
    var_export($files);
} else {
    if (isset($opts['t'])) {
        echo sprintf("%8s | %8s | %31s | %10s | %s", "Unpacked", "Packed", "Mtime", "Compressed", "Node name") . PHP_EOL;
        foreach ($files as $file) {
            $fdata = $archive->getFileData($file);
            echo sprintf("%8s | %8s | %31s | %10s | %s", $fdata->uncompressed_size, $fdata->compressed_size, date('r', $fdata->mtime), (int) $fdata->is_compressed, $fdata->filename) . PHP_EOL;
        }
    } elseif (isset($opts['h'])) {
        var_export($archive->getHierarchy());
    } else {
        if (isset($opts['e']) && isset($opts['n']) && isset($opts['o'])) {
            $result = $archive->extractNode($opts['o'], $opts['n']);
            if ($result === false) {
                echo "fail" . PHP_EOL;
            } else {
                echo "Extracted " . $result . " file(s)" . PHP_EOL;
Esempio n. 3
0
#!/usr/bin/php
<?php 
use wapmorgan\UnifiedArchive\UnifiedArchive;
require dirname(dirname(__FILE__)) . '/vendor/autoload.php';
echo "Usage: " . $argv[0] . " [directory]" . PHP_EOL;
function formatBytes($bytes, $precision = 2)
{
    $units = array('B', 'KB', 'MB', 'GB', 'TB');
    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);
    $bytes /= pow(1024, $pow);
    // $bytes /= (1 << (10 * $pow));
    return round($bytes, $precision) . $units[$pow];
}
echo sprintf("%28s | %4s | %8s | %8s | %8s | %8s | %8s | %8s | %8s | %8s", "Name", "Type", "Size", "Unpacked", "Packed", "Files", "Ratio", "Size", "Unpacked", "Packed") . PHP_EOL;
foreach (glob(isset($argv[1]) ? rtrim($argv[1], '/*') . '/*' : './*') as $file) {
    if (is_file($file)) {
        if (($archive = UnifiedArchive::open($file)) === null) {
            continue;
        }
        echo sprintf("%-28s | %4s | %8d | %8d | %8d | %8d | %7dx | %8s |" . " %8s | %8s", basename($file), $archive->getArchiveType(), $archive->getArchiveSize(), $archive->countUncompressedFilesSize(), $archive->countCompressedFilesSize(), $archive->countFiles(), $archive->countCompressedFilesSize() > 0 ? ceil($archive->countUncompressedFilesSize() / $archive->countCompressedFilesSize()) : 0, formatBytes($archive->getArchiveSize()), formatBytes($archive->countUncompressedFilesSize()), formatBytes($archive->countCompressedFilesSize())) . PHP_EOL;
    }
}
Esempio n. 4
0
/** @var $ctrl \bbn\mvc\controller */
if (isset($ctrl->files['file'], $ctrl->arguments[0]) && \bbn\str::is_integer($ctrl->arguments[0])) {
    $f =& $ctrl->files['file'];
    $path = BBN_USER_PATH . 'tmp/' . $ctrl->arguments[0];
    $new = \bbn\str::encode_filename($f['name'], \bbn\str::file_ext($f['name']));
    $file = $path . '/' . $new;
    if (\bbn\file\dir::create_path($path) && move_uploaded_file($f['tmp_name'], $file)) {
        $tmp = \bbn\str::file_ext($new, 1);
        $fname = $tmp[0];
        $ext = $tmp[1];
        $ctrl->obj->success = 1;
        $archives = ['zip', 'rar', 'tar', 'gzip', 'iso'];
        $images = ['jpg', 'gif', 'jpeg', 'png', 'svg'];
        $files = [basename($file)];
        if (in_array($ext, $archives)) {
            $archive = \wapmorgan\UnifiedArchive\UnifiedArchive::open($file);
            \bbn\file\dir::create_path($path . '/' . $fname);
            if ($num = $archive->extractNode($path . '/' . $fname, '/')) {
                $tmp = getcwd();
                chdir($path);
                $all = \bbn\file\dir::scan($fname, 'file');
                foreach ($all as $a) {
                    array_push($files, $a);
                }
                chdir($tmp);
            }
        }
        $ctrl->obj->files = [];
        foreach ($files as $f) {
            $tmp = \bbn\str::file_ext($f, 1);
            $fname = $tmp[0];