Browse Source

Global:

- fix layout Meta

Blog:
- added Vimeo video
- fix YouTube, Vimeo preview image
- fix URL rule
master
Egorka 7 years ago
parent
commit
cfa2e73b61
  1. 71
      common/modules/blog/controllers/PostController.php
  2. 4
      common/modules/blog/controllers/manage/PostController.php
  3. 18
      common/modules/blog/entities/BlogPost.php
  4. 1
      common/modules/blog/messages/ru/blog.php
  5. 31
      common/modules/blog/services/BlogPostManageService.php
  6. 4
      common/modules/blog/urls/BlogMainUrlRule.php
  7. 10
      common/modules/blog/views/manage/post/_form.php
  8. 11
      common/modules/blog/views/manage/post/view.php
  9. 86
      core/helpers/VideoHelper.php
  10. 35
      core/widgets/VideoWidget.php
  11. 18
      frontend/web/themes/start/layouts/main.php
  12. 18
      frontend/web/themes/start/modules/blog/views/post/post.php
  13. BIN
      static/cache/posts/368_287_10.jpg
  14. BIN
      static/cache/posts/368_287_11.jpg
  15. BIN
      static/cache/posts/368_287_13.jpg
  16. BIN
      static/cache/posts/368_287_15.jpg
  17. BIN
      static/cache/posts/368_287_16.jpg
  18. BIN
      static/cache/posts/368_287_4.jpg
  19. BIN
      static/cache/posts/368_287_5.jpg
  20. BIN
      static/cache/posts/368_287_6.jpg
  21. BIN
      static/cache/posts/368_287_7.jpg
  22. BIN
      static/cache/posts/368_287_8.jpg
  23. BIN
      static/cache/posts/368_287_9.jpg
  24. BIN
      static/cache/posts/370_325_10.jpg
  25. BIN
      static/cache/posts/370_325_11.jpg
  26. BIN
      static/cache/posts/370_325_13.jpg
  27. BIN
      static/cache/posts/370_325_15.jpg
  28. BIN
      static/cache/posts/370_325_16.jpg
  29. BIN
      static/cache/posts/370_325_4.jpg
  30. BIN
      static/cache/posts/370_325_5.jpg
  31. BIN
      static/cache/posts/370_325_6.jpg
  32. BIN
      static/cache/posts/370_325_7.jpg
  33. BIN
      static/cache/posts/370_325_8.jpg
  34. BIN
      static/cache/posts/370_325_9.jpg
  35. BIN
      static/cache/posts/683_407_10.jpg
  36. BIN
      static/cache/posts/683_407_13.jpg
  37. BIN
      static/cache/posts/683_407_4.jpg
  38. BIN
      static/cache/posts/683_407_5.jpg
  39. BIN
      static/cache/posts/683_407_6.jpg
  40. BIN
      static/cache/posts/683_407_7.jpg
  41. BIN
      static/cache/posts/683_407_8.jpg
  42. BIN
      static/cache/posts/683_407_9.jpg
  43. BIN
      static/cache/posts/94_94_10.jpg
  44. BIN
      static/cache/posts/94_94_11.jpg
  45. BIN
      static/cache/posts/94_94_13.jpg
  46. BIN
      static/cache/posts/94_94_15.jpg
  47. BIN
      static/cache/posts/94_94_16.jpg
  48. BIN
      static/cache/posts/94_94_4.jpg
  49. BIN
      static/cache/posts/94_94_5.jpg
  50. BIN
      static/cache/posts/94_94_6.jpg
  51. BIN
      static/cache/posts/94_94_7.jpg
  52. BIN
      static/cache/posts/94_94_8.jpg
  53. BIN
      static/cache/posts/94_94_9.jpg
  54. BIN
      static/cache/posts/admin_10.jpg
  55. BIN
      static/cache/posts/admin_11.jpg
  56. BIN
      static/cache/posts/admin_13.jpg
  57. BIN
      static/cache/posts/admin_15.jpg
  58. BIN
      static/cache/posts/admin_16.jpg
  59. BIN
      static/cache/posts/admin_4.jpg
  60. BIN
      static/cache/posts/admin_5.jpg
  61. BIN
      static/cache/posts/admin_6.jpg
  62. BIN
      static/cache/posts/admin_7.jpg
  63. BIN
      static/cache/posts/admin_8.jpg
  64. BIN
      static/cache/posts/admin_9.jpg
  65. BIN
      static/cache/posts/home_slider_10.jpg
  66. BIN
      static/cache/posts/home_slider_11.jpg
  67. BIN
      static/cache/posts/home_slider_13.jpg
  68. BIN
      static/cache/posts/home_slider_15.jpg
  69. BIN
      static/cache/posts/home_slider_16.jpg
  70. BIN
      static/cache/posts/home_slider_4.jpg
  71. BIN
      static/cache/posts/home_slider_5.jpg
  72. BIN
      static/cache/posts/home_slider_6.jpg
  73. BIN
      static/cache/posts/home_slider_7.jpg
  74. BIN
      static/cache/posts/home_slider_8.jpg
  75. BIN
      static/cache/posts/home_slider_9.jpg
  76. BIN
      static/cache/posts/list_10.jpg
  77. BIN
      static/cache/posts/list_11.jpg
  78. BIN
      static/cache/posts/list_13.jpg
  79. BIN
      static/cache/posts/list_15.jpg
  80. BIN
      static/cache/posts/list_16.jpg
  81. BIN
      static/cache/posts/list_4.jpg
  82. BIN
      static/cache/posts/list_5.jpg
  83. BIN
      static/cache/posts/list_6.jpg
  84. BIN
      static/cache/posts/list_7.jpg
  85. BIN
      static/cache/posts/list_8.jpg
  86. BIN
      static/cache/posts/list_9.jpg
  87. BIN
      static/cache/posts/origin_10.jpg
  88. BIN
      static/cache/posts/origin_11.jpg
  89. BIN
      static/cache/posts/origin_13.jpg
  90. BIN
      static/cache/posts/origin_15.jpg
  91. BIN
      static/cache/posts/origin_16.jpg
  92. BIN
      static/cache/posts/origin_4.jpg
  93. BIN
      static/cache/posts/origin_5.jpg
  94. BIN
      static/cache/posts/origin_6.jpg
  95. BIN
      static/cache/posts/origin_7.jpg
  96. BIN
      static/cache/posts/origin_8.jpg
  97. BIN
      static/cache/posts/origin_9.jpg
  98. BIN
      static/cache/posts/thumb_10.jpg
  99. BIN
      static/cache/posts/thumb_11.jpg
  100. BIN
      static/cache/posts/thumb_13.jpg
  101. Some files were not shown because too many files have changed in this diff Show More

71
common/modules/blog/controllers/PostController.php

@ -2,14 +2,21 @@
namespace common\modules\blog\controllers; namespace common\modules\blog\controllers;
use common\modules\blog\entities\BlogPost;
use common\modules\blog\forms\BlogCommentForm; use common\modules\blog\forms\BlogCommentForm;
use common\modules\blog\forms\BlogPostForm;
use common\modules\blog\helpers\BlogPostHelper;
use common\modules\blog\repositories\read\BlogCategoryReadRepository; use common\modules\blog\repositories\read\BlogCategoryReadRepository;
use common\modules\blog\repositories\read\BlogPostReadRepository; use common\modules\blog\repositories\read\BlogPostReadRepository;
use common\modules\blog\repositories\read\BlogTagReadRepository; use common\modules\blog\repositories\read\BlogTagReadRepository;
use common\modules\blog\services\BlogCommentService; use common\modules\blog\services\BlogCommentService;
use core\entities\Meta;
use frontend\components\FrontendController; use frontend\components\FrontendController;
use Yii; use Yii;
use yii\base\Security;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\helpers\FileHelper;
use yii\helpers\Json;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\AccessControl; use yii\filters\AccessControl;
@ -43,10 +50,10 @@ class PostController extends FrontendController
{ {
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::className(), 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'actions' => ['index', 'category', 'tag', 'post'], 'actions' => ['index', 'category', 'tag', 'post', 'preview'],
'allow' => true, 'allow' => true,
//'roles' => ['Blog'], //'roles' => ['Blog'],
], ],
@ -159,4 +166,64 @@ class PostController extends FrontendController
'model' => $form, 'model' => $form,
]); ]);
} }
public function beforeAction($action)
{
// ...set `$this->enableCsrfValidation` here based on some conditions...
// call parent method that will check CSRF if such property is true.
if ($action->id === 'preview') {
# code...
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}
public function actionPreview()
{
Yii::$app->controller->enableCsrfValidation = false;
$form = new BlogPostForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
$post = new BlogPost();
$post->id = -1;
$post->title = $form->title;
$post->description = $form->description;
$post->content = $form->content;
$post->category_id = $form->category_id;
$post->created_at = time();
$post->updated_at = time();
$post->published_at = time();
$meta = new Meta($form->meta->title, $form->meta->description, $form->meta->keywords);
$post->meta = $meta;
$post->meta_json = Json::encode([
'title' => $form->meta->title,
'description' => $form->meta->description,
'keywords' => $form->meta->keywords,
]);
$post->video = $form->video;
$post->slug = $form->slug;
if ($form->image) {
$post->setImage($form->image);
}
else if ($form->video) {
$src = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg';
$filename = (new Security())->generateRandomString(15) . '.jpg';
copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg'));
//copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $filename));
$post->image = $filename;
}
$path = $post->getUploadedFilePath('image');
FileHelper::createDirectory(pathinfo($path, PATHINFO_DIRNAME), 0775, true);
$post->image->saveAs($path);
$post->image = $post->getImageFileUrl('image');
return $this->render('post', [
'post' => $post,
]);
}
return '';
}
} }

4
common/modules/blog/controllers/manage/PostController.php

@ -28,7 +28,7 @@ class PostController extends Controller
{ {
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::className(), 'class' => AccessControl::class,
'rules' => [ 'rules' => [
[ [
'allow' => true, 'allow' => true,
@ -41,7 +41,7 @@ class PostController extends Controller
], ],
], ],
'verbs' => [ 'verbs' => [
'class' => VerbFilter::className(), 'class' => VerbFilter::class,
'actions' => [ 'actions' => [
'delete' => ['POST'], 'delete' => ['POST'],
'activate' => ['POST'], 'activate' => ['POST'],

18
common/modules/blog/entities/BlogPost.php

@ -273,22 +273,22 @@ class BlogPost extends ActiveRecord
public function getBlogComments(): ActiveQuery public function getBlogComments(): ActiveQuery
{ {
return $this->hasMany(BlogComment::className(), ['post_id' => 'id']); return $this->hasMany(BlogComment::class, ['post_id' => 'id']);
} }
public function getBlogTagAssignments(): ActiveQuery public function getBlogTagAssignments(): ActiveQuery
{ {
return $this->hasMany(BlogTagAssignment::className(), ['post_id' => 'id']); return $this->hasMany(BlogTagAssignment::class, ['post_id' => 'id']);
} }
public function getTags(): ActiveQuery public function getTags(): ActiveQuery
{ {
return $this->hasMany(BlogTag::className(), ['id' => 'tag_id'])->viaTable('blog_tag_assignments', ['post_id' => 'id']); return $this->hasMany(BlogTag::class, ['id' => 'tag_id'])->viaTable('blog_tag_assignments', ['post_id' => 'id']);
} }
public function getCategory(): ActiveQuery public function getCategory(): ActiveQuery
{ {
return $this->hasOne(BlogCategory::className(), ['id' => 'category_id']); return $this->hasOne(BlogCategory::class, ['id' => 'category_id']);
} }
###################################### ######################################
@ -296,15 +296,15 @@ class BlogPost extends ActiveRecord
public function behaviors(): array public function behaviors(): array
{ {
return [ return [
TimestampBehavior::className(), TimestampBehavior::class,
MetaBehavior::className(), MetaBehavior::class,
[ [
'class' => SaveRelationsBehavior::className(), 'class' => SaveRelationsBehavior::class,
'relations' => ['blogTagAssignments', 'blogComments'], 'relations' => ['blogTagAssignments', 'blogComments'],
], ],
[ [
// todo Image Sizes to settings or theme settings // todo Image Sizes to settings or theme settings
'class' => ImageUploadBehavior::className(), 'class' => ImageUploadBehavior::class,
'attribute' => 'image', 'attribute' => 'image',
'createThumbsOnRequest' => true, 'createThumbsOnRequest' => true,
//'filePath' => $this::FILE_ORIGINAL_PATH . '/[[id]].[[extension]]', //'filePath' => $this::FILE_ORIGINAL_PATH . '/[[id]].[[extension]]',
@ -313,7 +313,7 @@ class BlogPost extends ActiveRecord
'thumbPath' => '@staticRoot/cache/posts/[[profile]]_[[id]].[[extension]]', 'thumbPath' => '@staticRoot/cache/posts/[[profile]]_[[id]].[[extension]]',
'thumbUrl' => '@static/cache/posts/[[profile]]_[[id]].[[extension]]', 'thumbUrl' => '@static/cache/posts/[[profile]]_[[id]].[[extension]]',
'thumbs' => [ 'thumbs' => [
'blog_list' => ['width' => 750, 'height' => 300], 'blog_list' => ['width' => 750, 'height' => 300, 'resizeUp' => true],
'blog_post' => ['width' => 900, 'height' => 300], 'blog_post' => ['width' => 900, 'height' => 300],
'admin' => ['width' => 60, 'height' => 60], 'admin' => ['width' => 60, 'height' => 60],

1
common/modules/blog/messages/ru/blog.php

@ -54,6 +54,7 @@ return [
'User' => 'Пользователь', 'User' => 'Пользователь',
'Post' => 'Статья', 'Post' => 'Статья',
'YouTube URL' => 'Ссылка YouTube', 'YouTube URL' => 'Ссылка YouTube',
'Video URL' => 'Ссылка на видео (YouTube, Vimeo)',
'Add Image' => 'Новое изображение', 'Add Image' => 'Новое изображение',
'Video' => 'Видео', 'Video' => 'Видео',
'If a video link is specified, the image will be used as a preview image' => 'Если указана ссылка на видео, то изображение будет рассматриваться как картинка для предварительного просмотра', 'If a video link is specified, the image will be used as a preview image' => 'Если указана ссылка на видео, то изображение будет рассматриваться как картинка для предварительного просмотра',

31
common/modules/blog/services/BlogPostManageService.php

@ -10,6 +10,7 @@ use common\modules\blog\repositories\BlogCategoryRepository;
use common\modules\blog\repositories\BlogRepository; use common\modules\blog\repositories\BlogRepository;
use common\modules\blog\repositories\BlogTagRepository; use common\modules\blog\repositories\BlogTagRepository;
use core\entities\Meta; use core\entities\Meta;
use core\helpers\VideoHelper;
use core\services\TransactionManager; use core\services\TransactionManager;
use yii\base\Security; use yii\base\Security;
use yii\helpers\Inflector; use yii\helpers\Inflector;
@ -53,16 +54,6 @@ class BlogPostManageService
) )
); );
if ($form->image) {
$post->setImage($form->image);
}
else if ($form->video) {
$src = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg';
$filename = (new Security())->generateRandomString(15) . '.jpg';
copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg'));
$post->image = $filename;
}
$this->transaction->wrap(function () use ($post, $form) { $this->transaction->wrap(function () use ($post, $form) {
if (is_array($form->tags->new_tags) && !empty($form->tags->new_tags)) { if (is_array($form->tags->new_tags) && !empty($form->tags->new_tags)) {
@ -75,6 +66,23 @@ class BlogPostManageService
} }
} }
$this->posts->save($post); $this->posts->save($post);
if ($form->image) {
$post->setImage($form->image);
}
else if ($form->video) {
$src = VideoHelper::getThumb($form->video);
//$src = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg';
$filename = (new Security())->generateRandomString(15) . '.jpg';
copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg'));
$post->image = $filename;
}
if ($form->status == BlogPost::STATUS_ACTIVE) {
$post->activate();
}
$this->posts->save($post);
}); });
return $post; return $post;
@ -106,7 +114,8 @@ class BlogPostManageService
} }
elseif ($form->video && (!$post->image || $form->reset_image)) { elseif ($form->video && (!$post->image || $form->reset_image)) {
$post->cleanFiles(); $post->cleanFiles();
$src = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg'; $src = VideoHelper::getThumb($form->video);
//$src = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg';
$filename = (new Security())->generateRandomString(15) . '.jpg'; $filename = (new Security())->generateRandomString(15) . '.jpg';
copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg')); copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg'));
$post->image = $filename; $post->image = $filename;

4
common/modules/blog/urls/BlogMainUrlRule.php

@ -4,7 +4,6 @@ namespace common\modules\blog\urls;
use common\modules\blog\repositories\read\BlogPostReadRepository; use common\modules\blog\repositories\read\BlogPostReadRepository;
use yii\base\BaseObject; use yii\base\BaseObject;
use yii\base\InvalidParamException;
use yii\caching\Cache; use yii\caching\Cache;
use yii\caching\TagDependency; use yii\caching\TagDependency;
use yii\web\UrlNormalizerRedirectException; use yii\web\UrlNormalizerRedirectException;
@ -66,7 +65,8 @@ class BlogMainUrlRule extends BaseObject implements UrlRuleInterface
}, null, new TagDependency(['tags' => ['blog']])); }, null, new TagDependency(['tags' => ['blog']]));
if (!$url) { if (!$url) {
throw new InvalidParamException('Undefined id.'); return '#';
//throw new InvalidArgumentException('Undefined id.');
} }
$url = $this->prefix . '/' . $url; $url = $this->prefix . '/' . $url;

10
common/modules/blog/views/manage/post/_form.php

@ -132,7 +132,7 @@ $this->registerJs($js2);
<?php endif; ?> <?php endif; ?>
</div> </div>
<div id="field_video" class="tab-pane fade" style="padding-top: 20px;"> <div id="field_video" class="tab-pane fade" style="padding-top: 20px;">
<?= $form->field($model, 'video')->textInput()->label(Yii::t('blog', 'YouTube URL'))->hint(Yii::t('blog', 'If a video link is specified, the image will be used as a preview image')) ?> <?= $form->field($model, 'video')->textInput()->label(Yii::t('blog', 'Video URL'))->hint(Yii::t('blog', 'If a video link is specified, the image will be used as a preview image')) ?>
</div> </div>
</div> </div>
@ -158,7 +158,13 @@ $this->registerJs($js2);
<div class="box box-default"> <div class="box box-default">
<div class="box-header with-border"><?= Yii::t('blog', 'Publish') ?></div> <div class="box-header with-border"><?= Yii::t('blog', 'Publish') ?></div>
<div class="box-body"> <div class="box-body">
<?= Html::button(Yii::t('blog', 'Preview on site')) ?> <?= Html::submitButton(Yii::t('blog', 'Preview on site'), [
'class' => 'btn btn-info',
'value'=>'preview',
'name'=>'submit_preview',
'formaction' => Url::to(Yii::$app->params['frontendHostInfo'] . '/blog/post/preview'),
'formtarget' => '_blank',
]) ?>
<hr> <hr>
<?= $form->field($model, 'status')->radioList(BlogPostHelper::statusList()) ?> <?= $form->field($model, 'status')->radioList(BlogPostHelper::statusList()) ?>
<hr> <hr>

11
common/modules/blog/views/manage/post/view.php

@ -76,7 +76,11 @@ $this->params['breadcrumbs'][] = $title;
<div class="box"> <div class="box">
<div class="box-header with-border"><?= Yii::t('blog', 'Image') ?></div> <div class="box-header with-border"><?= Yii::t('blog', 'Image') ?></div>
<div class="box-body"> <div class="box-body">
<?= Html::img('https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg', [ <!-- < ?= Html::img('https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg', [
'width' => 300,
'class' => 'thumbnail',
]) ?> -->
<?= Html::img(\core\helpers\VideoHelper::getThumb($post->video), [
'width' => 300, 'width' => 300,
'class' => 'thumbnail', 'class' => 'thumbnail',
]) ?> ]) ?>
@ -88,7 +92,10 @@ $this->params['breadcrumbs'][] = $title;
<div class="box"> <div class="box">
<div class="box-header with-border"><?= Yii::t('blog', 'Video') ?></div> <div class="box-header with-border"><?= Yii::t('blog', 'Video') ?></div>
<div class="box-body"> <div class="box-body">
<iframe class="embed-responsive-item" src="https://www.youtube.com/embed/<?= BlogPostHelper::parseYoutubeUrl($post->video) ?>?rel=0" frameborder="0" allowfullscreen></iframe> <?= \core\widgets\VideoWidget::widget([
'src' => $post->video,
'style' => '',
]) ?>
</div> </div>
</div> </div>
<?php endif; ?> <?php endif; ?>

86
core/helpers/VideoHelper.php

@ -0,0 +1,86 @@
<?php
/**
* Created by Error202
* Date: 06.07.2018
*/
namespace core\helpers;
class VideoHelper
{
public static function identityProvider($url)
{
if (preg_match('%youtube|youtu\.be%i', $url)) {
return 'youtube';
}
elseif (preg_match('%vimeo%i', $url)) {
return 'vimeo';
}
return null;
}
public static function getThumb($url)
{
$src = '';
switch (self::identityProvider($url)) {
case 'youtube':
$id = VideoHelper::parseYoutubeUrl($url);
$src = 'https://i.ytimg.com/vi/' . $id . '/maxresdefault.jpg';
break;
case 'vimeo':
$id = VideoHelper::parseVimeoUrl($url);
$data = file_get_contents("http://vimeo.com/api/v2/video/$id.json");
$data = json_decode($data);
$src = $data[0]->thumbnail_large;
break;
}
return $src;
}
public static function parseVimeoUrl($url)
{
$urls = parse_url($url);
// https://vimeo.com/274720181
if($urls['host'] == 'vimeo.com'){
$id = ltrim($urls['path'],'/');
}
// https://player.vimeo.com/video/274720181
else {
$parts = explode('/',$urls['path']);
$id = end($parts);
}
return $id;
}
public static function parseYoutubeUrl($url)
{
$urls = parse_url($url);
//url is http://youtu.be/xxxx
if($urls['host'] == 'youtu.be'){
$id = ltrim($urls['path'],'/');
}
//url is http://www.youtube.com/embed/xxxx
else if(strpos($urls['path'],'embed') == 1){
$parts = explode('/',$urls['path']);
$id = end($parts);
}
//url is xxxx only
else if(strpos($url,'/')===false){
$id = $url;
}
//http://www.youtube.com/watch?feature=player_embedded&v=m-t4pcO99gI
//url is http://www.youtube.com/watch?v=xxxx
else{
parse_str($urls['query']);
/* @var $v */
$id = $v;
if(!empty($feature)){
$id = end(explode('v=',$urls['query']));
}
}
return $id;
}
}

35
core/widgets/VideoWidget.php

@ -0,0 +1,35 @@
<?php
/**
* Created by Error202
* Date: 06.07.2018
*/
namespace core\widgets;
use yii\base\Widget;
use core\helpers\VideoHelper;
class VideoWidget extends Widget
{
public $src;
public $width = 640;
public $height = 360;
public $style = "width: 100%";
public function run() {
$player = '';
switch (VideoHelper::identityProvider($this->src)) {
case 'youtube':
$id = VideoHelper::parseYoutubeUrl($this->src);
$player = '<iframe style="'.$this->style.'" width="'.$this->width.'" height="'.$this->height.'" src="https://www.youtube.com/embed/'.$id.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
break;
case 'vimeo':
$id = VideoHelper::parseVimeoUrl($this->src);
$player = '<iframe style="'.$this->style.'" src="https://player.vimeo.com/video/'.$id.'" width="'.$this->width.'" height="'.$this->height.'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
break;
}
return $player;
}
}

18
frontend/web/themes/start/layouts/main.php

@ -3,6 +3,8 @@
* @var $this \yii\web\View * @var $this \yii\web\View
*/ */
use yii\helpers\Html;
\frontend\web\themes\start\layouts\code\assets\AppAsset::register($this); \frontend\web\themes\start\layouts\code\assets\AppAsset::register($this);
rmrevin\yii\fontawesome\cdn\AssetBundle::register($this); rmrevin\yii\fontawesome\cdn\AssetBundle::register($this);
?> ?>
@ -12,13 +14,12 @@ rmrevin\yii\fontawesome\cdn\AssetBundle::register($this);
<head> <head>
<meta charset="utf-8"> <meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content=""> <meta name="author" content="Egor Oldenburger">
<meta name="author" content="">
<title>Modern Business - Start Bootstrap Template</title>
<title><?= Html::encode($this->title) ?></title>
<?= Html::csrfMetaTags() ?>
<?php $this->head() ?> <?php $this->head() ?>
</head> </head>
@ -27,12 +28,17 @@ rmrevin\yii\fontawesome\cdn\AssetBundle::register($this);
<!-- Navigation --> <!-- Navigation -->
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark fixed-top"> <nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container"> <div class="container">
<a class="navbar-brand" href="index.html">Start Bootstrap</a> <?= Html::a('Start Bootstrap', ['/site/index'], ['class' => 'navbar-brand']) ?>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="collapse navbar-collapse" id="navbarResponsive"> <div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto">
<li class="nav-item">
<?= Html::a(Yii::t('blog_public', 'Blog'), ['/blog/post/index'], ['class' => 'nav-link']) ?>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="about.html">About</a> <a class="nav-link" href="about.html">About</a>
</li> </li>

18
frontend/web/themes/start/modules/blog/views/post/post.php

@ -40,14 +40,28 @@ $url_full = Yii::$app->params['frontendHostInfo'] . Url::to(['/blog/post/post',
<hr> <hr>
<!-- Preview Image --> <!-- Preview Image -->
<?php if ($post->video): ?>
<!-- <iframe style="width: 100%" width="560" height="315" src="https://www.youtube.com/embed/< ?= \core\helpers\PostHelper::parseYoutubeUrl($post->video) ?>" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> -->
<?= \core\widgets\VideoWidget::widget([
'src' => $post->video,
]) ?>
<?php else: ?>
<img class="img-fluid rounded" src="<?= Html::encode($post->getThumbFileUrl('image', 'blog_post')) ?>" alt=""> <img class="img-fluid rounded" src="<?= Html::encode($post->getThumbFileUrl('image', 'blog_post')) ?>" alt="">
<?php endif; ?>
<hr> <hr>
<!-- Post Content --> <!-- Post Content -->
<p class="lead"><?= Html::encode($post->description) ?></p> <p class="lead"><?= Html::encode($post->description) ?></p>
<?= $post->content ?> <!-- < ?= $post->content ?> -->
<?= Yii::$app->formatter->asHtml($post->content, [
'Attr.AllowedRel' => array('nofollow'),
'HTML.SafeObject' => true,
'Output.FlashCompat' => true,
'HTML.SafeIframe' => true,
'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%',
]) ?>
<?= \common\modules\blog\widgets\TagWidget::widget([ <?= \common\modules\blog\widgets\TagWidget::widget([
'post_id' => $post->id 'post_id' => $post->id

BIN
static/cache/posts/368_287_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 KiB

BIN
static/cache/posts/368_287_11.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 29 KiB

BIN
static/cache/posts/368_287_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 98 KiB

BIN
static/cache/posts/368_287_15.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

BIN
static/cache/posts/368_287_16.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

BIN
static/cache/posts/368_287_4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 KiB

BIN
static/cache/posts/368_287_5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 166 KiB

BIN
static/cache/posts/368_287_6.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 KiB

BIN
static/cache/posts/368_287_7.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

BIN
static/cache/posts/368_287_8.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 KiB

BIN
static/cache/posts/368_287_9.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

BIN
static/cache/posts/370_325_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 KiB

BIN
static/cache/posts/370_325_11.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

After

Width:  |  Height:  |  Size: 29 KiB

BIN
static/cache/posts/370_325_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 110 KiB

BIN
static/cache/posts/370_325_15.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 KiB

BIN
static/cache/posts/370_325_16.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 KiB

BIN
static/cache/posts/370_325_4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

BIN
static/cache/posts/370_325_5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 KiB

BIN
static/cache/posts/370_325_6.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

BIN
static/cache/posts/370_325_7.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

BIN
static/cache/posts/370_325_8.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

BIN
static/cache/posts/370_325_9.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 KiB

BIN
static/cache/posts/683_407_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 KiB

BIN
static/cache/posts/683_407_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 187 KiB

After

Width:  |  Height:  |  Size: 213 KiB

BIN
static/cache/posts/683_407_4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 KiB

BIN
static/cache/posts/683_407_5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 389 KiB

BIN
static/cache/posts/683_407_6.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 KiB

BIN
static/cache/posts/683_407_7.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 KiB

BIN
static/cache/posts/683_407_8.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

BIN
static/cache/posts/683_407_9.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 386 KiB

BIN
static/cache/posts/94_94_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

BIN
static/cache/posts/94_94_11.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 13 KiB

BIN
static/cache/posts/94_94_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

BIN
static/cache/posts/94_94_15.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

BIN
static/cache/posts/94_94_16.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

BIN
static/cache/posts/94_94_4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

BIN
static/cache/posts/94_94_5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

BIN
static/cache/posts/94_94_6.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

BIN
static/cache/posts/94_94_7.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

BIN
static/cache/posts/94_94_8.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

BIN
static/cache/posts/94_94_9.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

BIN
static/cache/posts/admin_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

BIN
static/cache/posts/admin_11.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
static/cache/posts/admin_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
static/cache/posts/admin_15.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

BIN
static/cache/posts/admin_16.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

BIN
static/cache/posts/admin_4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

BIN
static/cache/posts/admin_5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

BIN
static/cache/posts/admin_6.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

BIN
static/cache/posts/admin_7.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

BIN
static/cache/posts/admin_8.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

BIN
static/cache/posts/admin_9.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

BIN
static/cache/posts/home_slider_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 KiB

BIN
static/cache/posts/home_slider_11.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 KiB

After

Width:  |  Height:  |  Size: 29 KiB

BIN
static/cache/posts/home_slider_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 114 KiB

BIN
static/cache/posts/home_slider_15.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

BIN
static/cache/posts/home_slider_16.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

BIN
static/cache/posts/home_slider_4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

BIN
static/cache/posts/home_slider_5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 KiB

BIN
static/cache/posts/home_slider_6.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

BIN
static/cache/posts/home_slider_7.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

BIN
static/cache/posts/home_slider_8.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 138 KiB

BIN
static/cache/posts/home_slider_9.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 KiB

BIN
static/cache/posts/list_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

BIN
static/cache/posts/list_11.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 29 KiB

BIN
static/cache/posts/list_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 43 KiB

BIN
static/cache/posts/list_15.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

BIN
static/cache/posts/list_16.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

BIN
static/cache/posts/list_4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

BIN
static/cache/posts/list_5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

BIN
static/cache/posts/list_6.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

BIN
static/cache/posts/list_7.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

BIN
static/cache/posts/list_8.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

BIN
static/cache/posts/list_9.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

BIN
static/cache/posts/origin_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 KiB

BIN
static/cache/posts/origin_11.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 556 KiB

After

Width:  |  Height:  |  Size: 29 KiB

BIN
static/cache/posts/origin_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 267 KiB

After

Width:  |  Height:  |  Size: 192 KiB

BIN
static/cache/posts/origin_15.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

BIN
static/cache/posts/origin_16.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 630 KiB

BIN
static/cache/posts/origin_4.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 364 KiB

BIN
static/cache/posts/origin_5.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 849 KiB

BIN
static/cache/posts/origin_6.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 695 KiB

BIN
static/cache/posts/origin_7.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 350 KiB

BIN
static/cache/posts/origin_8.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 364 KiB

BIN
static/cache/posts/origin_9.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 560 KiB

BIN
static/cache/posts/thumb_10.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

BIN
static/cache/posts/thumb_11.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 24 KiB

BIN
static/cache/posts/thumb_13.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save