view.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. /**
  3. * @var $this \yii\web\View
  4. * @var $model \app\models\front\News
  5. */
  6. use yii\helpers\ArrayHelper;
  7. use app\modules\ldjson\jsonLD;
  8. use yii\web\UrlManager;
  9. use app\models\Authors;
  10. use app\models\base\Image;
  11. use \app\models\news;
  12. use yii\helpers\Url;
  13. /*
  14. $this->registerJsFile('https://platform-api.sharethis.com/js/sharethis.js#property=63ecb32f4a4876001374e328&product=inline-reaction-buttons', [
  15. 'position' => $this::POS_END,
  16. 'async' => 'async',
  17. 'defer' => 'defer'
  18. ]);
  19. */
  20. $preview = $model->image;
  21. $retina = $preview->getUrl(Image::SIZE_HD,"jpg");
  22. $normal = $preview->getUrl(Image::SIZE_1040x586,"webp");
  23. $bad = $preview->getUrl(Image::SIZE_680x383,'jpg');
  24. $bad = $bad?$bad:'/images/default.jpg';
  25. if( $retina === false || $normal === false ){
  26. $normal = $bad;
  27. $retina = $bad;
  28. }
  29. $normal .= "?v=".$model->rev;
  30. $retina .= "?v=".$model->rev;
  31. $bad .= "?v=".$model->rev;
  32. /*
  33. После этой даты не выводить фото до подтверждения юриста
  34. if( isset( $model->dt_pub ) && strtotime( $model->dt_pub ) < strtotime('2015-01-01 00:00:00') ){
  35. $bad = '/images/default.jpg';
  36. $normal = $bad;
  37. $retina = $bad;
  38. };
  39. */
  40. Yii::$app->og->title =($model->meta_title)?$model->meta_title:$model->title;
  41. Yii::$app->og->description = ($model->lid && trim($model->lid) <> '')?str_replace( '"', "&quot;", strip_tags($model->lid) ):trim(str_replace( '"',"'",substr(strip_tags( $model->text ),0,150)))."...";
  42. if( $model->active == 'N' || $model->dt_pub > date("Y-m-d H:i:s") || $model->noindex == 'Y' ){
  43. Yii::$app->og->noindex = 'Y';
  44. }else{
  45. \Yii::$app->og->canonical = $model->getUrl(true);
  46. \Yii::$app->og->amp = Url::base('https').'/amp/news/'.$model->id;
  47. \Yii::$app->og->og_url = $model->getUrl(true);
  48. \Yii::$app->og->og_image = $model->image->url;
  49. \Yii::$app->og->og_type = "article";
  50. \Yii::$app->og->og_title = htmlspecialchars(($model->meta_title)?strip_tags(str_replace( '"',"&quot;",$model->meta_title)):strip_tags(str_replace( '"',"&quot;",$model->title)));
  51. \Yii::$app->og->og_description = ($model->lid && trim($model->lid) <> '')?str_replace( '"',"&quot;",strip_tags($model->lid)):trim(str_replace( '"',"&quot;",substr(strip_tags( $model->text ),0,150)))."...";
  52. \Yii::$app->og->dtpub = date( "r", strtotime( $model->dt_pub ) );
  53. }
  54. jsonLD::addAmicORG();
  55. jsonLD::news( $model->title, preg_replace('/\s+/', ' ', str_replace( ["\n","\r"],' ',Yii::$app->og->description)), $model->image->url, $model->dt_pub, $model->getUrl(), $model->uid, $model->text, $model->meta_title);
  56. jsonLD::addfaq($model->text, $model->title);
  57. $story = new \app\models\base\Story();
  58. $this->params['breadcrumbs'] = [
  59. [
  60. "text"=>"НОВОСТИ",
  61. "url"=>"/news"
  62. ]
  63. ];
  64. $this->params['context'] = "post-view";
  65. //$topic = ArrayHelper::getValue($model->topics,0);
  66. $topic = Yii::$app->cache->getOrSet('topic-news-'.$model->id, function () use($model){
  67. return $model->getTopics()->andWhere(['show'=>"Y","active"=>1])->one();
  68. }, News::$keysCache['topic-news-##']);
  69. if($topic instanceof \app\models\base\NewsTopic){
  70. $this->params['breadcrumbs'][] =
  71. [
  72. "text"=>$topic->title,
  73. "url"=>"/news/".mb_strtolower($topic->url)
  74. ];
  75. }
  76. $i = 1;
  77. foreach($this->params['breadcrumbs'] as $el){
  78. jsonLD::addBreadcrumb($i, $el['url'], $el['text']);
  79. $i++;
  80. }
  81. if( $model->show_author == 'Y' )
  82. {
  83. $author = Authors::getAuthor( $model->author );
  84. $authorName = $author->name;
  85. \Yii::$app->og->author =$authorName;
  86. jsonLD::author( $authorName );
  87. }else{
  88. $authorName = 'ИА Амител';
  89. jsonLD::author( $authorName, false );
  90. }
  91. if( strstr( $model->text, 'id="widgetseting"' ) && strstr( $model->text, 'windows="100"' ) ) $model->type = 2; //старый стиль широкой страницы
  92. $GLOBALS['type_long'] = ($model->type == 6); //лонгрид
  93. ?>
  94. <?php if(!is_null($model->embed_url) && $model->embed_url!=''):?>
  95. <div class="row">
  96. <div class="col-md-12 mb-5">
  97. <div class="picture-cont-16x9">
  98. <picture class="w-100 youtube-iframe-placeholder" data-link="<?=$model->getYoutubeEmbedLink()?>">
  99. <source srcset="<?=$preview->getUrl(Image::SIZE_680x383,"jpg")?>" media="(min-width: 600px)">
  100. <source srcset="<?=$preview->getUrl(Image::SIZE_680x383,"webp")?>" media="(min-width: 600px)">
  101. <img src="<?=$preview->getUrl(Image::SIZE_680x383)?>" alt="<?=$model->photo_title?>" class="w-100" loading="lazy">
  102. </picture>
  103. </div>
  104. </div>
  105. </div>
  106. <?php endif;?>
  107. <div class="row">
  108. <div class="<?=($model->type == 2 || $model->type == 6)?'col-md-12':'col-md-8'?>">
  109. <div id="post" class="post">
  110. <?
  111. if( Yii::$app->user->can('editor') ){
  112. ?>
  113. <span style="position: absolute;background-color: #a9a9a924;right: 30px;top: 10px; box-shadow: 2px 5px 5px 3px #888;"><img onclick="location='/manager/news/update?id=<?=$model['id']?>'" src="/img/edit.svg" width="25px" height="25px" style="padding:3px;cursor:pointer;"><img onclick="navigator.clipboard.writeText('https://www.amic.ru/news/<?=$model['id']?>');elementPopup(this,'Ссылка скопирована в буфер обмена');" src="/img/share-boxed.svg" width="25px" height="25px" style="padding:3px;margin-top: 2px;cursor:pointer;" ></span>
  114. <?
  115. }
  116. ?>
  117. <?=$this->render("/layouts/breadcrumbs")?>
  118. <h1><?=$model->title?></h1>
  119. <p class="lead"><?=$model->lid?></p>
  120. <p class="published_at"><?=$model->getPublishedNorm()?>, <?=$authorName?> <?= ($model->mark!="" && !is_null($model->mark)) ? \yii\helpers\Html::tag('span', $model->mark,['class'=>'float-right']) : ""?></p>
  121. <p class="share_and_comment">
  122. <a href="#comments" class="comments_btn">Комментировать</a>
  123. <a onclick="Share.vkontakte('<?=Yii::$app->og->og_url?>','<?=addslashes(Yii::$app->og->og_title)?>','<?=Yii::$app->og->og_image?>','<?=str_replace( '"',"&quot; ",Yii::$app->og->og_description)?>')" href="#">
  124. <svg class="icon icon-vk"><use xlink:href="/svg/symbol/sprite-clear.svg#vk"></use></svg>
  125. </a>
  126. <a onclick="Share.odnoklassniki('<?=Yii::$app->og->og_url?>','<?=addslashes(Yii::$app->og->og_title)?>','<?=Yii::$app->og->og_image?>','<?=str_replace( '"',"&quot; ",Yii::$app->og->og_description)?>')" href="#">
  127. <svg class="icon icon-ok"><use xlink:href="/svg/symbol/sprite-clear.svg#ok"></use></svg>
  128. </a>
  129. <a onclick="navigator.clipboard.writeText('<?=Yii::$app->og->og_url?>'); elementPopup(this,'Ссылка скопирована в буфер обмена')" class="copy-link" href="#">
  130. <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 8 8">
  131. <use href="/img/share-boxed.svg#share"></use>
  132. </svg>
  133. </a>
  134. </p>
  135. <p>
  136. <?php if($model->photo_include == 'Y' && $model->image instanceof \app\models\base\Image):?>
  137. <div class="picture-cont-16x9">
  138. <picture class="w-100">
  139. <source srcset="<?=$normal?>, <?=$retina?> 2x" media="(min-width: 600px)">
  140. <img src="<?=$bad?>" alt="<?=htmlentities($model->photo_title,ENT_QUOTES)?>" title="<?=htmlentities($model->photo_title,ENT_QUOTES)?>" class="w-100">
  141. </picture>
  142. </div>
  143. <div class="image-title"><?=$model->photo_title?></div>
  144. <?php endif;?>
  145. </p>
  146. <section class="text">
  147. <?=$model->renderBody()?>
  148. <?=($model->inscription == 2)?'<span class="advertisement">Реклама</span>':''?>
  149. <?=($model->inscription == 1)?'<span class="advertisement">Реклама</span><br><span class="med_advertisement">Имеются противопоказания, необходима консультация специалиста</span>':''?>
  150. <?=($model->inscription == 3)?'<span class="advertisement">Партнёр amic.ru</span>':''?>
  151. </section>
  152. <?php
  153. echo $this->render("@app/views/news/view/tags",["model"=>$model]);
  154. ?>
  155. <section class="share-this">
  156. <!-- ShareThis BEGIN -->
  157. <div class="sharethis-inline-reaction-buttons"></div>
  158. <!-- ShareThis END -->
  159. <div style="clear: both;"></div>
  160. </section>
  161. <?
  162. $stn = $story->getForNews($model->id);
  163. if( count($stn) > 0 ){
  164. echo $this->render("@app/views/news/view/story",["model"=>$stn, "id"=>$model->id]);
  165. foreach( $stn as $a ){
  166. jsonLD::story( trim( stripslashes( $a['title'] ) ) );
  167. }
  168. }
  169. ?>
  170. <?php if(Yii::$app->deviceDetect->isMobile()): ?>
  171. <section style="height: 300px;">
  172. <?=$this->render('@app/views/_etc/banners/bannerMobile3')?>
  173. </section>
  174. <?php else:?>
  175. <section style="height: 100px;">
  176. <?=$this->render('@app/views/_etc/banners/transparant5')?>
  177. </section>
  178. <?php endif;?>
  179. <section class="comments" id="comments">
  180. <?=$this->render("view/comments/list",["model"=>$model])?>
  181. </section>
  182. </div>
  183. </div>
  184. <script>
  185. (function (){
  186. let main_view_cont = document.getElementById('post');
  187. let height = main_view_cont.offsetHeight;
  188. console.log(height)
  189. let style = document.createElement("style");
  190. style.innerHTML = "#lenta-container{ max-height:"+height+"px;}";
  191. main_view_cont.parentNode.append(style);
  192. })()
  193. </script>
  194. <div class="<?=($model->type == 2 || $model->type == 6)?'hidden':'col-md-4'?>" id="lenta-container">
  195. <?=$this->render("/layouts/lenta/lenta")?>
  196. </div>
  197. <div class="col-md-12">
  198. <h3 class="mt-3" style="font-family: Helvetica,Arial,sans-serif;
  199. font-size: 20px;
  200. font-weight: 700;
  201. line-height: 24px;
  202. color: #373e44;
  203. padding-bottom: 12px;
  204. padding-top: 12px;">Новости партнеров</h3>
  205. <?//=$this->render('@app/views/_etc/banners/partnermetrics')?>
  206. <div id="ferst_partner_block"></div>
  207. <?/*
  208. <?=$this->render('@app/views/_etc/banners/partner3D')?>
  209. <?=$this->render('@app/views/_etc/banners/partner2D')?>
  210. <?=$this->render('@app/views/_etc/banners/partner1D')?>
  211. */?>
  212. <?php
  213. if(Yii::$app->deviceDetect->isMobile()){
  214. echo $this->render('@app/views/_etc/banners/moevideo');
  215. }
  216. ?>
  217. </div>
  218. <div class="col-md-12" id="infinity_newsfeed">
  219. <?=$this->render("view/infinity_newsfeed",['model'=>$model])?>
  220. </div>
  221. <div id="main-carousel" class="splide"></div>
  222. </div>
  223. <?php
  224. if( strpos( $model->text, 'class="InviewElement' ) !== false ){
  225. echo $this->render('view/inview');
  226. }
  227. ?>
  228. <?php
  229. $this->registerJsFile("/js/splide/dist/js/splide.min.js");
  230. $this->registerCssFile("/js/splide/dist/css/splide.min.css")
  231. ?>
  232. <script>
  233. var intersectionObserver = new IntersectionObserver(function(entries) {
  234. if (entries[0].intersectionRatio <= 0 || $(entries[0].target).html().length > 10 ) return;
  235. <?$code = $this->render('@app/views/_etc/banners/mytarget')?>
  236. <?$code .= $this->render('@app/views/_etc/banners/partner3D')?>
  237. <?$code .= $this->render('@app/views/_etc/banners/partner2D')?>
  238. <?$code .= $this->render('@app/views/_etc/banners/partner1D')?>
  239. <?$code .= $this->render('@app/views/_etc/banners/partner4D')?>
  240. var code = <?=json_encode($code)?>;
  241. $(entries[0].target).html(code);
  242. console.log('загрузить партнёрский блок');
  243. });
  244. (function (){
  245. intersectionObserver.observe(document.querySelector('#ferst_partner_block'));
  246. var gallery = document.getElementById("gallery-0");
  247. if(gallery!==null) {
  248. var wrapper = document.createElement("div");
  249. wrapper.classList.add('gallery-wrapper')
  250. gallery.parentNode.insertBefore(wrapper, gallery)
  251. wrapper.append(gallery)
  252. var gallery_items = gallery.getElementsByTagName("img");
  253. var track = document.createElement("div");
  254. var list = document.createElement('ul');
  255. gallery.classList.add("splide")
  256. list.classList.add("splide__list")
  257. track.classList.add("splide__track")
  258. gallery.prepend(track)
  259. track.prepend(list)
  260. for (var i = 0; i < gallery_items.length; i++) {
  261. var img = gallery_items[i];
  262. var img_cont = document.createElement('li')
  263. img_cont.classList.add("splide__slide")
  264. img_cont.append(img)
  265. list.append(img_cont)
  266. }
  267. var main_view = document.createElement("div")
  268. main_view.classList.add("splide", "gallery-view");
  269. main_view.innerHTML = gallery.innerHTML;
  270. gallery.style.paddingBottom = "18px";
  271. gallery.style.marginBottom = 0;
  272. wrapper.prepend(main_view)
  273. }
  274. document.addEventListener( 'DOMContentLoaded', function () {
  275. //return true;
  276. const galleries = document.querySelectorAll('.gallery-view');
  277. if(galleries.length>0){
  278. for (let i=0; i < galleries.length; i++){
  279. let element = galleries[i];
  280. if(element !== null){
  281. var main = new Splide(element, {
  282. type : 'fade',
  283. rewind : true,
  284. pagination: false,
  285. arrows : true,
  286. speed: 1000
  287. } );
  288. var thumbnails =new Splide( element.parentNode.querySelector('.gallery'), {
  289. fixedWidth: 100,
  290. fixedHeight: 60,
  291. gap : 10,
  292. rewind : true,
  293. pagination: false,
  294. isNavigation: true,
  295. arrows : false,
  296. } );
  297. main.sync( thumbnails );
  298. main.mount();
  299. thumbnails.mount();
  300. }
  301. }
  302. }
  303. if(document.querySelector('.gallery-view') !== null){
  304. // var main = new Splide( '.gallery-view', {
  305. // type : 'fade',
  306. // rewind : true,
  307. // pagination: false,
  308. // arrows : true,
  309. // speed: 1000
  310. // } );
  311. // var thumbnails =new Splide( '.gallery', {
  312. // fixedWidth: 100,
  313. // fixedHeight: 60,
  314. // gap : 10,
  315. // rewind : true,
  316. // pagination: false,
  317. // isNavigation: true,
  318. // arrows : false,
  319. // } );
  320. //
  321. // main.sync( thumbnails );
  322. // main.mount();
  323. // thumbnails.mount();
  324. }
  325. let fullscreenBtn = null;
  326. let gallery_wrappers = document.querySelectorAll('.gallery-wrapper');
  327. for (let i = 0; i < gallery_wrappers.length; i++) {
  328. fullscreenBtn = document.createElement('div');
  329. fullscreenBtn.classList.add('fullscreenButton');
  330. gallery_wrappers[i].append(fullscreenBtn)
  331. fullscreenBtn.onclick = function (){
  332. gallery_wrappers[i].classList.toggle('fullscreen')
  333. gallery_wrappers[i].querySelectorAll('.gallery-view img').forEach(function (elem) {
  334. elem.setAttribute('src', elem.dataset.original);
  335. })
  336. }
  337. }
  338. } );
  339. })()
  340. </script>
  341. <script>
  342. Share = {
  343. vkontakte: function(purl, ptitle, pimg, text) {
  344. url = 'https://vkontakte.ru/share.php?';
  345. url += 'url=' + encodeURIComponent(purl);
  346. url += '&title=' + encodeURIComponent(ptitle);
  347. url += '&description=' + encodeURIComponent(text);
  348. url += '&image=' + encodeURIComponent(pimg);
  349. url += '&noparse=true';
  350. Share.popup(url);
  351. },
  352. odnoklassniki: function(purl, text) {
  353. //url = 'https://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1';
  354. url = 'https://connect.ok.ru/offer?';
  355. url += '&st.comments=' + encodeURIComponent(text);
  356. url += '&url=' + encodeURIComponent(purl);
  357. Share.popup(url);
  358. },
  359. facebook: function(purl, ptitle, pimg, text) {
  360. url = 'http://www.facebook.com/sharer.php?s=100';
  361. url += '&p[title]=' + encodeURIComponent(ptitle);
  362. url += '&p[summary]=' + encodeURIComponent(text);
  363. url += '&p[url]=' + encodeURIComponent(purl);
  364. url += '&p[images][0]=' + encodeURIComponent(pimg);
  365. Share.popup(url);
  366. },
  367. twitter: function(purl, ptitle) {
  368. url = 'https://twitter.com/share?';
  369. url += 'text=' + encodeURIComponent(ptitle);
  370. url += '&url=' + encodeURIComponent(purl);
  371. url += '&counturl=' + encodeURIComponent(purl);
  372. Share.popup(url);
  373. },
  374. mailru: function(purl, ptitle, pimg, text) {
  375. url = 'http://connect.mail.ru/share?';
  376. url += 'url=' + encodeURIComponent(purl);
  377. url += '&title=' + encodeURIComponent(ptitle);
  378. url += '&description=' + encodeURIComponent(text);
  379. url += '&imageurl=' + encodeURIComponent(pimg);
  380. Share.popup(url)
  381. },
  382. popup: function(url) {
  383. window.open(url,'','toolbar=0,status=0,width=626,height=436');
  384. }
  385. };
  386. const elementPopup = function (element, text)
  387. {
  388. console.log(element)
  389. const positionY = element.offsetTop;
  390. const positionX = element.offsetLeft;
  391. let popup = document.createElement("div")
  392. popup.style.position = 'absolute';
  393. popup.style.top = (positionY - 35) + 'px';
  394. popup.style.left = positionX + "px";
  395. popup.style.color = "white";
  396. popup.style.background = "#00000052";
  397. popup.style.borderRadius = "5px";
  398. popup.style.padding = "1px 20px";
  399. popup.style.opacity = "1";
  400. popup.style.transition = "0.3s";
  401. popup.innerHTML = text
  402. popup.classList.add('element-popup')
  403. element.parentNode.append(popup)
  404. setTimeout(function (){
  405. popup.style.opacity=0
  406. console.log(popup.style.transition)
  407. },3000)
  408. }
  409. </script>
  410. <?php if($model->mark!="" && !is_null($model->mark) && is_null(\Yii::$app->request->get('erid'))):?>
  411. <script>
  412. (function (){
  413. const url = new URL(location.href);
  414. url.searchParams.append('erid','<?=$model->mark?>')
  415. window.history.pushState({},'',url);
  416. })()
  417. </script>
  418. <?php endif;?>
  419. <script>
  420. (function (){
  421. const placeholders = document.getElementsByClassName('youtube-iframe-placeholder');
  422. if(placeholders.length>0){
  423. for(let i =0;i<placeholders.length;i++){
  424. placeholders[i].onclick = function (){
  425. const waiting = document.createElement("div");
  426. waiting.style.position = "absolute";
  427. waiting.style.width = "100%";
  428. waiting.style.height = "100%";
  429. waiting.style.background = "url('/img/loading.gif')";
  430. waiting.style.backgroundPosition = "center";
  431. waiting.style.backgroundRepeat = "no-repeat";
  432. waiting.style.backgroundSize = "contain";
  433. waiting.style.zIndex = 1;
  434. this.replaceWith(waiting);
  435. const iframe = document.createElement("iframe");
  436. iframe.src = this.dataset.link+"?autoplay=1";
  437. iframe.style.position = "absolute";
  438. iframe.style.zIndex = 2;
  439. iframe.width = "100%";
  440. iframe.height = "100%";
  441. iframe.title = "YouTube video player";
  442. iframe.frameBorder = "0";
  443. iframe.allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
  444. iframe.allowFullscreen = true;
  445. waiting.parentNode.append(iframe);
  446. }
  447. }
  448. }
  449. })()
  450. </script>
  451. <?
  452. if( Yii::$app->deviceDetect->isMobile() ){
  453. $this->registerJs(
  454. <<<JS
  455. $(function () {
  456. loadScript( 'https://platform-api.sharethis.com/js/sharethis.js#property=63ecb32f4a4876001374e328&product=inline-reaction-buttons', 8000 );
  457. });
  458. JS
  459. ,
  460. $this::POS_READY,
  461. 'sharethis'
  462. );
  463. }else{
  464. $this->registerJs(
  465. <<<JS
  466. $(function () {
  467. loadScript( 'https://platform-api.sharethis.com/js/sharethis.js#property=63ecb32f4a4876001374e328&product=inline-reaction-buttons', 100 );
  468. });
  469. JS
  470. ,
  471. $this::POS_READY,
  472. 'sharethis'
  473. );
  474. }