Esempio n. 1
0
 public function renderItem($navItemId, $appendix = null)
 {
     $model = NavItem::findOne($navItemId);
     if (!$model) {
         throw new NotFoundHttpException('The requested nav item could not found.');
     }
     Yii::$app->urlManager->contextNavItemId = $navItemId;
     Yii::$app->set('page', ['class' => 'cms\\components\\Page', 'model' => $model]);
     $event = new \cms\events\BeforeRenderEvent();
     foreach ($model->getNav()->getProperties() as $property) {
         $object = $model->getNav()->getProperty($property['var_name']);
         $object->trigger($object::EVENT_BEFORE_RENDER, $event);
         if (!$event->isValid) {
             Yii::$app->end();
         }
     }
     $typeModel = $model->getType();
     $typeModel->setOptions(['cmsControllerObject' => $this, 'navItemId' => $navItemId, 'restString' => $appendix]);
     $content = $typeModel->getContent();
     if ($this->view->title === null) {
         $this->view->title = $model->title;
     }
     $this->view->registerMetaTag(['name' => 'og:title', 'content' => $this->view->title], 'fbTitle');
     if (!empty($model->description)) {
         $this->view->registerMetaTag(['name' => 'description', 'content' => $model->description], 'metaDescription');
         $this->view->registerMetaTag(['name' => 'og:description', 'content' => $model->description], 'fbDescription');
     }
     if ($this->module->enableTagParsing) {
         $content = Parser::encode($content);
     }
     return $content;
 }
Esempio n. 2
0
 public function testStaticLinksParser()
 {
     $this->assertEquals('<a href="http://luya.io">luya.io</a>', Parser::encode('link[http://luya.io](luya.io)'));
     $this->assertEquals('<a href="http://luya.io">Hello Whitespace</a>', Parser::encode('link[http://luya.io](Hello Whitespace)'));
     $this->assertEquals('<a href="http://luya.io">http://luya.io</a>', Parser::encode('link[http://luya.io]'));
     $this->assertEquals('<a href="http://luya.io">luya.io</a>', Parser::encode('link[luya.io]'));
     $this->assertEquals('<a href="http://luya.io">Hello Whitespace</a>', Parser::encode('link[luya.io](Hello Whitespace)'));
     $this->assertEquals('<a href="http://luya.io">Hello /\\#~[] Chars</a>', Parser::encode('link[luya.io](Hello /\\#~[] Chars)'));
 }