_archive_item.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @var $model \app\models\News
  4. * @var $key
  5. * @var $index
  6. * @var $widget
  7. */
  8. use app\models\base\Image;
  9. $preview = $model->image;
  10. $retina = $preview->getUrl(Image::SIZE_680x383,"webp");
  11. $normal = $preview->getUrl(Image::SIZE_320x180,"webp");
  12. $bad = $preview->getUrl(Image::SIZE_320x180,'jpg');
  13. $bad = $bad?$bad:'/images/default.jpg';
  14. if( $retina === false || $normal == false ){
  15. $normal = $bad;
  16. $retina = $bad;
  17. }
  18. $normal .= "?v=".$model->rev;
  19. $retina .= "?v=".$model->rev;
  20. $bad .= "?v=".$model->rev;
  21. $count=$model->getCommentsAll()->count();
  22. /*
  23. После этой даты не выводить фото
  24. if( isset( $model->dt_pub ) && strtotime( $model->dt_pub ) < strtotime('2015-01-01 00:00:00') ){
  25. $bad = '/images/default.jpg';
  26. $normal = $bad;
  27. $retina = $bad;
  28. };
  29. */
  30. if( isset($index) ){
  31. $index = $index+1;
  32. }else{
  33. static $index = 0;
  34. }
  35. ?>
  36. <div class="">
  37. <div class="archive-news-item" data-key="<?=$key?>">
  38. <div class="illustration">
  39. <?php if($preview instanceof \app\models\base\Image):?>
  40. <div class="picture-cont-16x9">
  41. <a href="<?=$model->url?>">
  42. <picture class="w-100">
  43. <source srcset="<?=$normal?>, <?=$retina?> 2x" media="(min-width: 600px)">
  44. <img src="<?=$bad?>" alt="<?=htmlentities($model->photo_title,ENT_QUOTES)?>" srcset="<?=$normal?>, <?=$retina?> 2x" class="w-100" <?=($index > 2)?'loading="lazy"':''?>>
  45. </picture>
  46. </a>
  47. </div>
  48. <?php else:?>
  49. <div class="picture-cont-16x9">
  50. <a href="<?=$model->url?>">
  51. </a>
  52. </div>
  53. <?php endif;?>
  54. </div>
  55. <div class="meta">
  56. <h2 class="title"><a href="<?=$model->url?>"><?=$model->title?></a></h2>
  57. <div class="published_at">
  58. <?=$model->publishedAt?>
  59. <?php if($count>0):?>
  60. <span class="commnets">&nbsp;<svg class="icon icon-comments"><use xlink:href="/svg/symbol/sprite-clear.svg#comments"></use></svg><?=$count?></span>
  61. <?php endif;?>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <?php if($index == 4) echo $this->render("@app/views/_etc/banners/archiveAfterFive")?>