convert() public static method

Convert the CMS-Tags into HTML-Tags.
public static convert ( string $text ) : string
$text string The content where the CMS-Tags should be found and convert into Html-Tags.
return string The converted output of $text.
Ejemplo n.º 1
0
 public function testInvalidContent()
 {
     $this->assertSame(false, TagParser::convert(false));
     $this->assertSame(true, TagParser::convert(true));
     $this->assertSame(1, TagParser::convert(1));
     $this->assertSame(0, TagParser::convert(0));
     $this->assertSame('string', TagParser::convert('string'));
     $this->assertSame([], TagParser::convert([]));
     $this->assertSame('', TagParser::convert(''));
 }
Ejemplo n.º 2
0
 /**
  * Render the NavItem content and set several view specific data.
  *
  * @param integer $navItemId
  * @param string $appendix
  * @param boolean|integer $setNavItemTypeId To get the content of a version this parameter will change the database value from the nav item Model
  * to this provided value
  *
  * @throws NotFoundHttpException
  * @throws MethodNotAllowedHttpException
  */
 public function renderItem($navItemId, $appendix = null, $setNavItemTypeId = false)
 {
     $model = NavItem::find()->where(['id' => $navItemId])->with('nav')->one();
     if (!$model) {
         throw new NotFoundHttpException('The requested nav item could not found.');
     }
     Yii::$app->urlManager->contextNavItemId = $navItemId;
     Yii::$app->set('page', ['class' => 'luya\\cms\\frontend\\components\\Page', 'model' => $model]);
     $currentMenu = Yii::$app->menu->current;
     $event = new BeforeRenderEvent();
     $event->menu = $currentMenu;
     foreach ($model->nav->getProperties() as $property) {
         $object = $property->getObject();
         $object->trigger($object::EVENT_BEFORE_RENDER, $event);
         if (!$event->isValid) {
             throw new MethodNotAllowedHttpException('Your are not allowed to see this page.');
             return Yii::$app->end();
         }
     }
     if ($setNavItemTypeId !== false && !empty($setNavItemTypeId)) {
         $model->nav_item_type_id = $setNavItemTypeId;
     }
     $typeModel = $model->getType();
     if (!$typeModel) {
         throw new NotFoundHttpException("The requestd nav item could not be found with the paired type, maybe this version does not exists for this Type.");
     }
     $typeModel->setOptions(['navItemId' => $navItemId, 'restString' => $appendix]);
     $content = $typeModel->getContent();
     if ($content instanceof Response) {
         return Yii::$app->end(0, $content);
     }
     // it seems to be a json response as it is an array
     if (is_array($content)) {
         return $content;
     }
     // https://github.com/luyadev/luya/issues/863 - if context controller is not false and the layout variable is not empty, the layout file will be displayed
     // as its already renderd by the module controller itself.
     if ($typeModel->controller !== false && !empty($typeModel->controller->layout)) {
         $this->layout = false;
     }
     if ($this->view->title === null) {
         if (empty($model->title_tag)) {
             $this->view->title = $model->title;
         } else {
             $this->view->title = $model->title_tag;
         }
     }
     $this->view->registerMetaTag(['name' => 'og:title', 'content' => $this->view->title], 'fbTitle');
     $this->view->registerMetaTag(['name' => 'og:type', 'content' => 'website'], 'ogType');
     if (!empty($model->description)) {
         $this->view->registerMetaTag(['name' => 'description', 'content' => $model->description], 'metaDescription');
         $this->view->registerMetaTag(['name' => 'og:description', 'content' => $model->description], 'fbDescription');
     }
     if (!empty($model->keywords)) {
         $this->view->registerMetaTag(['name' => 'keywords', 'content' => implode(", ", $currentMenu->keywords)], 'metyKeywords');
     }
     if ($this->module->enableTagParsing) {
         $content = TagParser::convert($content);
     }
     if (Yii::$app->has('adminuser') && !Yii::$app->adminuser->isGuest && $this->module->overlayToolbar === true) {
         $this->view->registerCssFile('https://fonts.googleapis.com/icon?family=Material+Icons');
         $this->getView()->on(View::EVENT_BEGIN_BODY, [$this, 'renderToolbar'], ['content' => $content]);
     }
     return $content;
 }