'\models\News', ]; /** * @var int cache lifetime, `0` - for not use cache */ public $cacheExpire = 180; /** * @var array default channel options */ public $channelOptions = []; /** * @var string default route to render Turbo-pages feed (use "/" - for root) */ public $turboRoute = "/rss/turbo"; /** * @var string the module version */ private $version = "1.0.4"; /** * @var integer, priority of initialization */ private $priority = 5; /** * {@inheritdoc} */ public function init() { parent::init(); // Set version of current module $this->setVersion($this->version); // Set priority of current module $this->setPriority($this->priority); // Process and normalize route for frontend $this->turboRoute = self::normalizeRoute($this->turboRoute); // $this->bootstrap(Yii::$app); } /** * {@inheritdoc} */ public function dashboardNavItems($createLink = false) { $items = [ 'label' => $this->name, 'icon' => 'fa fa-fw fa-rocket', 'url' => [$this->routePrefix . '/'. $this->id], 'active' => (in_array(\Yii::$app->controller->module->id, [$this->id]) && Yii::$app->controller->id == 'list'), ]; return $items; } /** * {@inheritdoc} */ public function bootstrap($app) { parent::bootstrap($app); if (isset(Yii::$app->params["turbo.supportModels"])) $this->supportModels = Yii::$app->params["turbo.supportModels"]; if (isset(Yii::$app->params["turbo.cacheExpire"])) $this->cacheExpire = Yii::$app->params["turbo.cacheExpire"]; if (isset(Yii::$app->params["turbo.channelOptions"])) $this->channelOptions = Yii::$app->params["turbo.channelOptions"]; if (isset(Yii::$app->params["turbo.turboRoute"])) $this->turboRoute = Yii::$app->params["turbo.turboRoute"]; if (!isset($this->supportModels)) throw new InvalidConfigException("Required module property `supportModels` isn't set."); if (!isset($this->cacheExpire)) throw new InvalidConfigException("Required module property `cacheExpire` isn't set."); if (!isset($this->channelOptions)) throw new InvalidConfigException("Required module property `channelOptions` isn't set."); if (!isset($this->turboRoute)) throw new InvalidConfigException("Required module property `turboRoute` isn't set."); if (!is_array($this->supportModels)) throw new InvalidConfigException("Module property `supportModels` must be array."); if (!is_array($this->channelOptions)) throw new InvalidConfigException("Module property `channelOptions` must be array."); if (!is_integer($this->cacheExpire)) throw new InvalidConfigException("Module property `cacheExpire` must be integer."); if (!is_string($this->turboRoute)) throw new InvalidConfigException("Module property `turboRoute` must be a string."); // Add route to pass turbo-pages in frontend $turboRoute = $this->turboRoute; if (empty($turboRoute) || $turboRoute == "/") { $app->getUrlManager()->addRules([ [ 'pattern' => '/rss', 'route' => '/rss/default', 'suffix' => '.xml' ], '/turbo.xml' => '/rss/default' ], true); } else if (is_string($turboRoute)) { $app->getUrlManager()->addRules([ [ 'pattern' => $turboRoute . '/feed', 'route' => 'rss/default', 'suffix' => '.xml' ], $turboRoute . '/feed.xml' => 'rss/default' ], true); $app->getUrlManager()->addRules([ [ 'pattern' => $turboRoute . '/turbo', 'route' => 'rss/default/turbo', 'suffix' => '.xml' ], $turboRoute . '/feed.xml' => 'rss/default' ], true); $app->getUrlManager()->addRules([ [ 'pattern' => $turboRoute . '/dzen', 'route' => 'rss/default/dzen', 'suffix' => '.xml' ], $turboRoute . '/dzen.xml' => 'rss/default' ], true); $app->getUrlManager()->addRules([ [ 'pattern' => $turboRoute . '/ria', 'route' => 'rss/default/ria', 'suffix' => '.xml' ], $turboRoute . '/ria.xml' => 'rss/default' ], true); } // echo $turboRoute; // Attach to events of create/change/remove of models for the subsequent clearing cache of feeds if (!($app instanceof \yii\console\Application)) { if ($cache = $app->getCache()) { if (is_array($models = $this->supportModels)) { foreach ($models as $name => $class) { if (class_exists($class)) { $model = new $class(); \yii\base\Event::on($class, $model::EVENT_AFTER_INSERT, function ($event) use ($cache) { $cache->delete(md5('yandex-turbo')); }); \yii\base\Event::on($class, $model::EVENT_AFTER_UPDATE, function ($event) use ($cache) { $cache->delete(md5('yandex-dzen')); }); \yii\base\Event::on($class, $model::EVENT_AFTER_DELETE, function ($event) use ($cache) { $cache->delete(md5('yandex-ria')); }); } } } } } } /** * Generate current RSS-feed URL * * @return null|string */ public function getFeedURL() { $url = null; $turboRoute = $this->turboRoute; if (empty($turboRoute) || $turboRoute == "/") { $url = Url::to('/turbo.xml', true); } else { $url = Url::to($turboRoute . '/feed.xml', true); } return $url; } /** * Get items for building a Yandex.Turbo pages * * @return array */ public function getTurboItems() { $items = []; if (is_array($models = $this->supportModels)) { foreach ($models as $name => $class) { // If class of model exist if (class_exists($class)) { $model = new $class(); $newsDataProvider = new \yii\data\ActiveDataProvider( [ "query"=>\app\models\News::find()->andwhere(['active'=>'Y'])->andWhere(['between', 'news.dt_pub', date("Y-m-d H:i:00",time()-2678400*1 ) , date("Y-m-d H:i:00")])->orderBy(["dt_pub"=>SORT_DESC])->limit(200), "pagination" =>[ "pageSize"=>200 ], ] ); // If module is loaded if (1) { $append = []; foreach ($newsDataProvider->getModels() as $item) { $turbo = true; if( stripos( $item->text, '#is', '', $text); //$text = News::processInjects($text); // var_dump($f); //$text = $f->renderBody(); // $f->renderBody(); // $text = CutLastInject( $text, $a['id'] ); // $text = ShowInject( $text ); // $text = str_replace( 'id="inject"', '', $text ); // $text = ShowGalleryWidgetm( $text ); $text = strip_tags( $text,'
',' ',$text); $text = preg_replace('##is', '', $text); //$text = News::processInjects($text); // var_dump($f); //$text = $f->renderBody(); // $f->renderBody(); // $text = CutLastInject( $text, $a['id'] ); // $text = ShowInject( $text ); // $text = str_replace( 'id="inject"', '', $text ); // $text = ShowGalleryWidgetm( $text ); $re = '|