?> </p> <hr> <?php $images = ContentHelper::fetchImages($model->text); if ($images['count']) { $carousel = CarouselWidget::widget(['template' => 'single', 'mode' => 'images', 'slides' => $images['images']]); echo '<div class="col-lg-12">' . $carousel . '</div>'; $this->registerMetaTag(['property' => 'og:image', 'content' => url::toRoute($images['main']['src'], true)]); } ?> <div class="col-lg-12"> <?php echo ContentHelper::cleanImages($model->text); ?> </div> </div> <div class="col-md-4"> <!-- Blog Search Well --> <!-- <div class="well">--> <!-- <h4>Search</h4>--> <!-- <div class="input-group">--> <!-- <input type="text" class="form-control">--> <!-- <span class="input-group-btn">--> <!-- <button class="btn btn-default" type="button"><i class="fa fa-search"></i></button>--> <!-- </span>--> <!-- </div>--> <!-- </div>-->
<a href="/">Додому</a> </li> <li class="active">Лента</li> </ol> </div> </div> <!-- /.row --> <?php $model = new Content(); // $items = $model->bySection(5, $perPage); $lenghtLimit = 720; $out = ''; if (!empty($models)) { foreach ($models as $item) { $images = ContentHelper::fetchImages($item['text']); $cleanContent = ContentHelper::cleanImages($item['text']); $header = '<h3><a href="/info/' . $item['slug'] . '" > ' . $item['name'] . '</a></h3>'; $buttonMore = ''; if (strlen($cleanContent) >= $lenghtLimit) { $buttonMore = '<a class="btn btn-info" href="/events/' . $item['slug'] . '" style="float:right;" ><i>Докладніше</i></a>'; $cleanContent = BaseStringHelper::truncate(strip_tags($cleanContent), $lenghtLimit, "..."); } $content = '<p>' . $cleanContent . '</p>'; if (!$images['count']) { $item = '<div class="col-md-12">' . $header . $content . $buttonMore . '</div>'; } else { $item = '<div class="col-md-5"><a href="/info/' . $item['slug'] . '"> <img class="img-responsive img-hover" src="' . $images['main']['src'] . '" alt="' . $images['main']['alt'] . '"> </a></div><div class="col-md-7">' . $header . $content . $buttonMore . '</div>'; } $out .= '<div class="row">' . $item . '</div><hr>';
<?php use ut8ia\contentmodule\helpers\ContentHelper; use yii\helpers\BaseStringHelper; $images = ContentHelper::fetchImages($item->text); $imageBlock = ''; if ($images['count']) { $imageBlock = '<a href=' . $urlHead . $item->slug . '> <img class="' . $imageClass . '" src="' . $images['main']['src'] . '" alt="' . $images['main']['alt'] . '"></a> <hr>'; } ?> <h2> <a href="<?php echo $urlHead . $item->slug; ?> "><?php echo $item->name; ?> </a> </h2> <hr> <?php echo $imageBlock; ?> <p><?php echo BaseStringHelper::truncate(strip_tags($item->text), $textTruncate, "..."); ?> </p> <a class="<?php echo $classMore;
public function imagesBySection($section_id, $limit = null, $mainOnly = null) { $ans = Content::find()->where(['=', 'section_id', $section_id])->andWhere(['=', 'published', true])->andWhere(['=', '`contentmanager_content`.`lang_id`', Lang::getCurrent()->id])->orderBy('RAND() '); $ans = (int) $limit ? $ans->limit($limit) : $ans; $items = $ans->all(); if (!empty($items)) { $collection = []; $c = 0; foreach ($items as $item) { $images = ContentHelper::fetchImages($item->text); //skip if content has no images if (!$images['count']) { continue; } // fetch image - main or random if ($mainOnly) { $collection[$c]['src'] = $images['main']['src']; $collection[$c]['slug'] = $item['slug']; } else { $imageNum = (int) rand(0, $images['count'] - 1); $collection[$c]['src'] = $images['images'][$imageNum]['src']; $collection[$c]['slug'] = $item['slug']; } $c++; if ($c == $limit) { break; } } } return $collection; }