123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?
- use yii\helpers\Html;
- use yii\widgets\ActiveForm;
- use yii\web\View;
- use yii;
- $this->title = 'Tilda';
- $this->params['breadcrumbs'][] = ['label' => 'Tilda', 'url' => ['index'] ];
- $this->params['breadcrumbs'][] = 'Экспорт';
- $arExportPages = array();
- $mainPage = '';
- $cat = $api->local->getProjectDir();
- $url = trim($url);
- if( $url ){
- $api->local->setProjectDir($cat.$url.DIRECTORY_SEPARATOR);
- if ($api->local->createBaseFolders() === false) {
- ?>
- <div class="row">
- <div class="col-md-12">
- <div class="callout callout-danger">
- <h5>Ошибка создания папок <?=$local->lastError?></h5>
- </div>
- </div>
- </div>
- <?
- }
- }
- ?>
- <div class="row">
- <div class="col-md-12">
- <div class="callout callout-danger">
- <h5>Экспорт</h5>
- URL:
- <a class="uppercase" href="https://www.amic.ru/<?=$cat.$url.DIRECTORY_SEPARATOR?>">https://www.amic.ru/<?=$cat.$url.DIRECTORY_SEPARATOR?></a>
- </div>
- </div>
- </div>
- <div class="row">
- <input type="hidden" value="<?=$proj?>" name="proj">
- <?
- foreach($pages as $k=>$i){
- $item = $api->getpageexport($i);
- $arExportPages[] = $item['id'];
- $api->local->setProject($item);
- ?>
- <div class="col-md-6">
- <div class="card card-widget widget-user-2">
- <div class="card-header">
- <h3 class="card-title">
- <input type="hidden" value="<?=$item['id']?>" name="Check[]">
- <?
- if( $item['id'] == $main ){
- $mainPage = $item['filename'];
- ?>
- <label class="form-check-label">Главная страница</label>
- <?
- }
- ?>
- </h3>
- </div>
- <div class="attachment-block clearfix">
- <?
- if( isset( $item['img'] ) && $item['img'] != '' ){
- $img = $item['img'];
- $img = str_replace( basename($img), '-/resize/160x/'.basename($img), $img );
- ?>
- <img src="<?=$img?>" class="attachment-img m-2">
- <?
- }
- ?>
- <h3 class="widget-user-username"><?=$item['title']?></h3>
- <p class="mx-2"><?=$item['date']?></p>
- <div class="card-footer p-0">
- <div class="card-body">
- <p><?=$item['filename']?></p>
- <?=$item['descr']?>
- </div>
- <div class="card-footer text-center">
- <div class="progress progress-sm">
- <div class="progress-bar bg-success progress-bar-striped" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
- <span class="sr-only">100% Complete (warning)</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <?
- }
- ?>
- <div class="col-12">
- <div class="card card-default">
- <div class="card-header">
- <h3 class="card-title">
- <i class="fas fa-exclamation-triangle"></i>
- Alerts <i class="fa fa-sync fa-spin"></i>
- </h3>
- </div>
- <div class="card-body">
- <div class="alert alert-warning alert-dismissible">
- <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
- <h5><i class="icon fas fa-ban"></i> Alert!</h5>
- <?
- // Загрузка глобальная
- /* копируем общие CSS файлы */
- $arFiles = $api->local->copyCssFiles('css');
- if (! $arFiles) {
- die('Error in copy CSS files [' . $api->lastError . ']');
- }
-
- $arFiles = $api->local->copyJsFiles('js');
- if (! $arFiles) {
- die('Error in copy JS files [' . $api->lastError . ']');
- }
-
- $arFiles = $api->local->copyImagesFiles('img');
- if (! $arFiles) {
- die('Error in copy IMG files [' . $api->lastError . ']');
- }
-
- $countexport = 1;
- foreach ($arExportPages as $pageid) {
- if( !in_array( $pageid, $pages ) ) continue;
-
-
- $tildapage = $api->getPageFullExport($pageid);
- if (! $tildapage || empty($tildapage['html'])) {
- echo "Error: cannot get page [$pageid] or page not publish<br>\n";
- continue;
- }
-
- $html = preg_replace(array('|//static.tildacdn.com/js/|','|//static.tildacdn.com/css/|'),array('',''), $tildapage['html']);
- if ($html > '') {
- $tildapage['html'] = $html;
- }
- $tildapage['export_imgpath'] = $api->local->arProject['export_imgpath'];
- $tildapage['needsync'] = '0';
-
- $html = preg_replace($api->local->arSearchFiles, $api->local->arReplaceFiles, $tildapage['html']);
- if ($html > '') {
- $html = str_replace( $api->local->getProjectDir() ,'',$html);
- $html = str_replace('href="/','href="',$html);
- $html = str_replace('src="/','src="',$html);
- $html = str_replace('src="/','src="//',$html);
- $html = str_replace('src="/yastatic.net','src="//yastatic.net',$html);
- $html = str_replace('rentafont_webfonts.js','../.js/rentafont_webfonts.js',$html);
- $html = str_replace('http://amic.ru/page'.$tildapage['id'],$api->local->getProjectDir().'/page'.$tildapage['id'],$html);
- $html = str_replace('https://amic.ru/page'.$tildapage['id'],$api->local->getProjectDir().'/page'.$tildapage['id'],$html);
- $html = str_replace('><',">\n<",$html);
- $matches = array();
- preg_match_all('|\<link(.*)|i', $html, $matches);
- foreach( $matches[1] as $item ){
- if( stristr( $item, '"canonical"') ){
- preg_match('|href="(.*)"|', $item, $m2);
- $html = str_replace( $m2[1], 'https://www.amic.ru/'.$api->local->getProjectDir(),$html);
- }
- }
- $tildapage['html'] = $html;
- }
-
- $tildapage = $api->local->savePage($tildapage);
- echo "<br>Save page $pageid - success<br>\n";
- $tildapage = $api->local->saveMetaPage($tildapage);
- $countexport++;
- }
- ?>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col">
- <?
- $dir = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . $api->local->getProjectDir();
- if( file_exists($dir.'index.html') ) unlink($dir.'index.html');
- if( @symlink( $dir.$mainPage, $dir.'index.html' ) ){
- echo '<h2><span class="badge badge-primary">Всё хорошо: index.html</span></h2>';
- }else{
- echo '<h2><span class="badge danger-primary">Ошибка создания index.html</span></h2>';
- }
- ?>
- </div>
- </div>
|