Example #1
0
 /**
  * Кэширумеая функция, основной разбор.
  */
 public static function parse($src)
 {
     $args = array($src);
     $param = Cache::exec(array($src), 'docx_parse', function ($src, $re) {
         $conf = Docx::$conf;
         $imgmaxwidth = $conf['imgmaxwidth'];
         $previewlen = $conf['previewlen'];
         $cachename = Path::tofs(Path::encode($src));
         $cacheFolder = Path::mkdir(Docx::$conf['cache'] . $cachename . '/');
         //В винде ингда вылетает о шибка что нет прав удалить какой-то файл в папке и как следствие саму папку
         //Обновление страницы проходит уже нормально
         //Полагаю в линукс такой ошибки не будет хз почему возникает
         Cache::fullrmdir($cacheFolder);
         $path = Path::theme($src);
         if (!$path) {
             return array('html' => false);
         }
         $xmls = docx_getTextFromZippedXML($path, 'word/document.xml', $cacheFolder, $re);
         $rIds = array();
         $param = array('folder' => $cacheFolder, 'imgmaxwidth' => $imgmaxwidth, 'previewlen' => $previewlen, 'rIds' => $rIds);
         if ($xmls[0]) {
             $xmlar = docx_dom_to_array($xmls[0]);
             $xmlar2 = docx_dom_to_array($xmls[1]);
             foreach ($xmlar2['Relationships']['Relationship'] as $v) {
                 $rIds[$v['Id']] = $v['Target'];
             }
             $param['rIds'] = $rIds;
             $html = docx_each($xmlar, '\\infrajs\\doc\\docx_analyse', $param);
         } else {
             $param['rIds'] = array();
             $html = '';
         }
         $param['html'] = $html;
         return $param;
     }, $args, isset($_GET['re']));
     unset($param['rIds']);
     unset($param['type']);
     unset($param['imgmaxwidth']);
     unset($param['previewlen']);
     unset($param['isli']);
     unset($param['isul']);
     unset($param['imgnum']);
     unset($param['folder']);
     return $param;
 }
Example #2
0
    session_start();
    if (empty($_SESSION['submit_time'])) {
        $_SESSION['submit_time'] = 0;
    }
    if (time() - $_SESSION['submit_time'] < 60) {
        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'])) {
Example #3
0
            $file = autoedit_createPath($origfile);
            $ans['msg'] .= 'Файл был создан<br>';
            if (!$file) {
                return Ans::err($ans, 'Не удалось создать путь до файла ' . Path::toutf($file));
            }
        }
        $r = file_put_contents($file, $_REQUEST['content']);
        if (!$r) {
            return Ans::err($ans, 'Неудалось сохранить файл');
        }
        $ans['msg'] .= 'Cохранено';
        return Ans::ret($ans);
    }
} elseif ($type === 'seo') {
    $dir = Path::resolve('~seo/');
    $src = Path::tofs($id);
    $src = str_replace('/', '-', $src);
    $src = str_replace('..', '-', $src);
    if (strlen($src) > 100) {
        $src = md5($src);
    }
    $src = $dir . 'seo-' . $src . '.json';
    if (!$submit) {
        $seo = Load::loadJSON($src);
        $ans['seo'] = $seo;
    } else {
        $dir = autoedit_createPath($dir);
        $seo = $_POST['seo'];
        $def = $_POST['def'];
        $keys = array();
        Each::foro($seo, function ($val, $key) use(&$seo, &$def, &$keys) {
Example #4
0
function autoedit_takepath($file = false)
{
    $takepath = Path::resolve('!admin_takefiles/');
    if ($file === false) {
        return $takepath;
    }
    $file = autoedit_theme($file);
    $path = $takepath . preg_replace('/[\\/\\\\\\*]/', '_', Path::tofs($file)) . '.js';
    return $path;
}
Example #5
0
 public static function theme($src)
 {
     $p = explode('?', $src, 2);
     $query = sizeof($p) == 2 ? '?' . $p[1] : '';
     $args = array($p[0]);
     $src = Once::exec('Path::theme', function ($str) {
         //Повторно для адреса не работает Путь только отностельно корня сайта или со звёздочкой
         //Скрытые файлы доступны
         $str = Path::toutf($str);
         $conf = Path::$conf;
         if (!$str) {
             return false;
         }
         $is_fn = mb_substr($str, mb_strlen($str) - 1, 1) == '/' || in_array($str, array('-', '~', '!')) ? 'is_dir' : 'is_file';
         $ch = mb_substr($str, 0, 1);
         if ($ch == '~') {
             $str = mb_substr($str, 1);
             $str = Path::tofs($str);
             if ($is_fn($conf['data'] . $str)) {
                 return $conf['data'] . $str;
             }
         } else {
             if ($ch == '-') {
                 $str = mb_substr($str, 1);
                 $str = Path::tofs($str);
                 $p = explode('/', $str);
                 //file.ext folder/ folder/file.ext folder/dir/file.ext
                 if (sizeof($p) > 1) {
                     if (!empty($conf['clutch'][$p[0]])) {
                         foreach ($conf['clutch'][$p[0]] as $dir) {
                             if ($is_fn($dir . $str)) {
                                 return $dir . $str;
                             }
                         }
                     }
                 }
                 if ($is_fn($str)) {
                     return $str;
                 }
                 //Корень важней search, clutch важней корня
                 if ($p[0] == 'index') {
                     array_shift($p);
                     $s = implode('/', $p);
                     if ($is_fn($s)) {
                         return $s;
                     }
                 } else {
                     $s = 'index/' . $str;
                     if ($is_fn($s)) {
                         return $s;
                     }
                 }
                 foreach ($conf['search'] as $dir) {
                     if ($is_fn($dir . $str)) {
                         return $dir . $str;
                     }
                 }
             } else {
                 if ($ch == '!') {
                     $str = mb_substr($str, 1);
                     $str = Path::tofs($str);
                     if ($is_fn($conf['cache'] . $str)) {
                         return $conf['cache'] . $str;
                     }
                 } else {
                     //Проверка что путь уже правильный... происходит когда нет звёздочки... Неопределённость может возникнуть только с явными путями
                     //if($is_fn($str))return $str;//Относительный путь в первую очередь, если повторный вызов для пути попадём сюда
                     $str = Path::tofs($str);
                     if ($is_fn($str)) {
                         return $str;
                     }
                 }
             }
         }
         return false;
     }, $args);
     if (!$src) {
         return false;
     }
     return $src . $query;
 }
Example #6
0
function &xls_parseAll($path)
{
    $data = Cache::exec(array($path), 'xls_parseAll', function &($path) {
        $file = Path::theme($path);
        $data = array();
        if (!$file) {
            return $data;
        }
        $in = Load::srcInfo($path);
        if ($in['ext'] == 'xls') {
            require_once __DIR__ . '/excel_parser/oleread.php';
            require_once __DIR__ . '/excel_parser/reader.php';
            if (!$file) {
                return $data;
            }
            $d = new \Spreadsheet_Excel_Reader();
            $d->setOutputEncoding('utf-8');
            $d->read($file);
            Each::forr($d->boundsheets, function &($v, $k) use(&$d, &$data) {
                $data[$v['name']] =& $d->sheets[$k]['cells'];
                $r = null;
                return $r;
            });
        } elseif ($in['ext'] == 'csv') {
            $handle = fopen('php://memory', 'w+');
            fwrite($handle, Path::toutf(file_get_contents($file)));
            rewind($handle);
            $data = array();
            //Массив будет хранить данные из csv
            while (($line = fgetcsv($handle, 0, ";")) !== false) {
                //Проходим весь csv-файл, и читаем построчно. 3-ий параметр разделитель поля
                $data[] = $line;
                //Записываем строчки в массив
            }
            fclose($handle);
            foreach ($data as $k => $v) {
                foreach ($data[$k] as $kk => $vv) {
                    $vv = trim($vv);
                    if ($vv === '') {
                        unset($data[$k][$kk]);
                    } else {
                        $data[$k][$kk] = $vv;
                    }
                }
                if (!$data[$k]) {
                    unset($data[$k]);
                }
            }
            $data = array('list' => $data);
        } elseif ($in['ext'] == 'xlsx') {
            $cacheFolder = Path::resolve(Xlsx::$conf['cache']);
            //$cacheFolder .= Path::encode($path).'/';//кэш
            $cacheFolder .= md5($path) . '/';
            //кэш
            Cache::fullrmdir($cacheFolder, true);
            //удалить старый кэш
            $r = mkdir($cacheFolder);
            if (!$r) {
                echo '<pre>';
                throw new \Exception('Не удалось создать папку для кэша ' . $cacheFolder);
            }
            //разархивировать
            $zip = new \ZipArchive();
            $pathfs = Path::theme($path);
            if ((int) phpversion() > 6) {
                $zipcacheFolder = Path::tofs($cacheFolder);
                $zippathfs = Path::toutf($pathfs);
            } else {
                $zipcacheFolder = Path::tofs($cacheFolder);
                //Без кирилицы
                $zippathfs = Path::tofs($pathfs);
            }
            $r = $zip->open($zippathfs);
            if ($r === true) {
                $zip->extractTo($zipcacheFolder);
                $zip->close();
                $contents = simplexml_load_file($cacheFolder . 'xl/sharedStrings.xml');
                $contents = $contents->si;
                $workbook = simplexml_load_file($cacheFolder . 'xl/workbook.xml');
                $sheets = $workbook->sheets->sheet;
                $handle = opendir($cacheFolder . 'xl/worksheets/');
                $i = 0;
                $syms = array();
                while ($file = readdir($handle)) {
                    if ($file[0] == '.') {
                        continue;
                    }
                    $src = $cacheFolder . 'xl/worksheets/' . $file;
                    if (!is_file($src)) {
                        continue;
                    }
                    $files[] = $file;
                }
                closedir($handle);
                natsort($files);
                foreach ($files as $file) {
                    $src = $cacheFolder . 'xl/worksheets/' . $file;
                    $list = $sheets[$i];
                    ++$i;
                    $list = $list->attributes();
                    $list = (string) $list['name'];
                    $data[$list] = array();
                    $sheet = simplexml_load_file($cacheFolder . 'xl/worksheets/' . $file);
                    $rows = $sheet->sheetData->row;
                    foreach ($rows as $row) {
                        $attr = $row->attributes();
                        $r = (string) $attr['r'];
                        $data[$list][$r] = array();
                        $cells = $row->c;
                        foreach ($cells as $cell) {
                            if (!$cell->v) {
                                continue;
                            }
                            $attr = $cell->attributes();
                            if ($attr['t'] == 's') {
                                $place = (int) $cell->v;
                                if (isset($contents[$place]->r)) {
                                    $value = '';
                                    foreach ($contents[$place]->r as $con) {
                                        $value .= $con->t;
                                    }
                                } else {
                                    $value = $contents[$place]->t;
                                }
                            } else {
                                $value = $cell->v;
                                $value = (double) $value;
                            }
                            $attr = $cell->attributes();
                            $c = (string) $attr['r'];
                            //FA232
                            preg_match("/\\D+/", $c, $c);
                            $c = $c[0];
                            $syms[$c] = true;
                            $data[$list][$r][$c] = (string) $value;
                        }
                    }
                }
                $syms = array_keys($syms);
                natsort($syms);
                /*usort($syms,function($a,$b){
                			$la=strlen($a);
                			$lb=strlen($b);
                			if($la>$lb)return 1;
                			if($la<$lb)return -1;
                			if($a>$b)return 1;
                			if($a<$b)return -1;
                			return 0;
                		});*/
                $symbols = array();
                foreach ($syms as $i => $s) {
                    $symbols[$s] = $i + 1;
                }
                foreach ($data as $list => $listdata) {
                    foreach ($listdata as $row => $rowdata) {
                        $data[$list][$row] = array();
                        foreach ($rowdata as $cell => $celldata) {
                            $data[$list][$row][$symbols[$cell]] = $celldata;
                        }
                        if (!$data[$list][$row]) {
                            unset($data[$list][$row]);
                        }
                        //Пустые строки нам не нужны
                    }
                }
            }
            // Если что-то пошло не так, возвращаем пустую строку
            //return "";
            //собрать данные
        }
        return $data;
    }, array($path));
    return $data;
}
Example #7
0
 public static function getType($src)
 {
     return Once::exec(__FILE__ . 'getTpype', function ($src) {
         $src = Path::tofs($src);
         $handle = fopen($src, 'r');
         $line = fgets($handle, 50);
         $line2 = fgets($handle, 50);
         fclose($handle);
         if (preg_match('/JFIF/', $line)) {
             return 'jpeg';
         }
         if (preg_match('/PNG/', $line)) {
             return 'png';
         }
         if (preg_match('/GIF/', $line)) {
             return 'gif';
         }
         if (preg_match('/Exif/', $line)) {
             return 'jpeg';
         }
         if (preg_match('/Exif/', $line2)) {
             return 'jpeg';
         }
         if (preg_match('/BM/', $line)) {
             return 'wbmp';
         }
         return false;
     }, array($src));
 }
Example #8
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);
 }
Example #9
0
    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'];
            $text = Rubrics::article($src);
            echo $text;
            return;
        }