123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace manager\controllers;
- use Yii;
- use manager\models\TildaAPI;
- class TildaController extends BaseController
- {
- const keylist = 'uactive';
- const project = 461598;
- public function actionIndex()
- {
- $cache = Yii::$app->cache;
- $ckey = "Tilda_ProjectsLis";
- if( !($proj = $cache->get( $ckey )) ){
- $api = $this->GetApi();
- $proj = $api->getProjectsList( self::project );
- $cache->set( $ckey, $proj, 60*10 );
- }
- return $this->render("index", ['proj'=>$proj]);
- }
- public function actionProj($id)
- {
- $cache = Yii::$app->cache;
- $ckey = "Tilda_PageLis_".$id;
- $ckey2 = "Tilda_PageInf_".$id;
- if( !($proj = $cache->get( $ckey )) ){
- $api = $this->GetApi();
- $proj = $api->getPagesList( $id );
- $cache->set( $ckey, $proj, 60*10 );
- }
- if( !($info = $cache->get( $ckey2 )) ){
- $api = isset($api)?$api:$this->GetApi();
- $info = $api->getProjectInfo($id);
- $cache->set( $ckey2, $info, 60*60 );
- }
- return $this->render("pages", ['pages'=>$proj,'info'=>$info]);
- }
- public function actionExport()
- {
- if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){
- $api = $this->GetApi();
- return $this->render("pagesconf", ['pages'=>$post['Check'],'proj'=>$post['proj'], 'api'=>$api]);
- }
- return $this->redirect('index');
- }
- public function actionExportstart()
- {
- if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){
- $api = $this->GetApi();
- return $this->render("export", ['pages'=>$post['Check'],'proj'=>$post['proj'], 'api'=>$api, 'main'=>$post['main'], 'url'=>$post['url']]);
- }
- return $this->redirect('index');
- }
- public function actionProcess()
- {
- if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){
- $api = $this->GetApi();
- // $tildapage = unserialize($post['data']);
- $pageid = $post['data'];
- /* запрашиваем все данные для экспорта страницы */
- $tildapage = $api->getPageFullExport($pageid);
- if (! $tildapage || empty($tildapage['html'])) {
- echo "Error: cannot get page [$pageid] or page not publish<br>\n";
- return;
- }
- /* временный фикс */
- $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';
- //print_r($local->arSearchFiles);
- /* так как мы копировали общие файлы в одни папки, а в HTML они указывают на другие, то произведем замену */
- $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);
- $tildapage['html'] = $html;
- }
- $tildapage = $api->local->savePage($tildapage);
- $tildapage = $api->local->saveMetaPage($tildapage);
- return json_encode( ['status'=>'ok', 'id'=>$tildapage['id']] );
- }
- return json_encode( ['status'=>'err'] );
- }
- public function actionView()
- {
- $api = $this->GetApi();
- return $this->render("view", ['api'=>$api]);
- }
- protected function GetApi()
- {
- return new TildaAPI( 'vre13190dtp27i45zo6g', 'ainf80ynghlc80dc1mdf');
- }
- }
|