Ejemplo n.º 1
1
 public function actionIndex($url)
 {
     $model = Page::findOne(['url' => $url]);
     if (!$model) {
         Alert::add('Strona nie została znaleziona', Alert::TYPE_ERROR);
         return $this->goHome();
     }
     return $this->render('index', ['model' => $model]);
 }
Ejemplo n.º 2
0
 /**
  * Finds the Page model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Page::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 3
0
 public function actionView($slug)
 {
     $model = new Page();
     $node = $model->findOne(['slug' => $slug]);
     if (empty($node)) {
         throw new NotFoundHttpException('Không tim thấy nội dung theo yêu cầu.');
     }
     return $this->render('view', ['node' => $node]);
 }
Ejemplo n.º 4
0
 /**
  * page view
  * @param $id
  * @return string
  * @throws NotFoundHttpException
  * @internal param $name
  */
 public function actionPage($id)
 {
     $model = Page::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
     /* found */
     if ($model->content->language !== Yii::$app->language) {
         Yii::$app->session->setFlash('info', Yii::t('app', 'This page has no {CUR_LANG} version. You are currently viewing the {LANGUAGE} version.', ['CUR_LANG' => Message::getLocaleList()[Yii::$app->language], 'LANGUAGE' => Message::getLocaleList()[$model->content->language]]));
     }
     /* seo */
     /* metaData */
     $title = $model->content->title;
     $keywords = $model->content->keywords;
     $description = $model->content->description;
     $metaTags[] = ['name' => 'keywords', 'content' => $keywords];
     $metaTags[] = ['name' => 'description', 'content' => $description];
     /* Facebook */
     $metaTags[] = ['property' => 'og:title', 'content' => $title];
     $metaTags[] = ['property' => 'og:description', 'content' => $description];
     $metaTags[] = ['property' => 'og:type', 'content' => 'article'];
     // article, product, profile etc
     $metaTags[] = ['property' => 'og:image', 'content' => $model->content->thumbnail];
     //best 1200 x 630
     $metaTags[] = ['property' => 'og:url', 'content' => $model->content->getViewUrl(true)];
     if ($appId = Setting::getValue('fbAppId')) {
         $metaTags[] = ['property' => 'fb:app_id', 'content' => $appId];
     }
     //$metaTags[]=['property' => 'fb:app_id', 'content' => ''];
     //$metaTags[]=['property' => 'fb:admins', 'content' => ''];
     /* Twitter */
     $metaTags[] = ['name' => 'twitter:card', 'content' => 'summary_large_image'];
     $metaTags[] = ['name' => 'twitter:site', 'content' => Setting::getValue('twitterSite')];
     //        $metaTags[]=['name'=>'twitter:title', 'content'=>$title];
     //        $metaTags[]=['name'=>'twitter:description', 'content'=>$description];
     //        $metaTags[]=['name'=>'twitter:image', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:data1', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:label1', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:data2', 'content'=>''];
     //        $metaTags[]=['name'=>'twitter:label2', 'content'=>''];
     /* jsonld */
     $imageObject = $model->content->getImageObject();
     $jsonLd = (object) ['@type' => 'Article', 'http://schema.org/name' => $title, 'http://schema.org/headline' => $description, 'http://schema.org/articleBody' => $model->content->content, 'http://schema.org/dateCreated' => Yii::$app->formatter->asDate($model->content->created_at, 'php:c'), 'http://schema.org/dateModified' => Yii::$app->formatter->asDate($model->content->updated_at, 'php:c'), 'http://schema.org/datePublished' => Yii::$app->formatter->asDate($model->content->created_at, 'php:c'), 'http://schema.org/url' => Yii::$app->request->absoluteUrl, 'http://schema.org/image' => (object) ['@type' => 'ImageObject', 'http://schema.org/url' => !empty($imageObject['url']) ? $imageObject['url'] : '', 'http://schema.org/width' => !empty($imageObject['width']) ? $imageObject['width'] : '', 'http://schema.org/height' => !empty($imageObject['height']) ? $imageObject['height'] : ''], 'http://schema.org/author' => (object) ['@type' => 'Organization', 'http://schema.org/name' => Yii::$app->name], 'http://schema.org/publisher' => (object) ['@type' => 'Organization', 'http://schema.org/name' => Yii::$app->name, 'http://schema.org/logo' => (object) ['@type' => 'ImageObject', 'http://schema.org/url' => Yii::$app->urlManager->createAbsoluteUrl(Yii::$app->homeUrl . '/images/logo.png')]], 'http://schema.org/mainEntityOfPage' => (object) ['@type' => 'WebPage', '@id' => Yii::$app->request->absoluteUrl]];
     /* OK */
     $data['title'] = $title;
     $data['metaTags'] = $metaTags;
     $data['jsonLd'] = $jsonLd;
     $this->registerMetaTagJsonLD($data);
     return $this->render('page', ['model' => $model]);
 }
Ejemplo n.º 5
0
 public function actionUpdate($id)
 {
     if ($id) {
         $model = Page::findOne($id);
         if (!$model) {
             throw new NotFoundHttpException();
         }
     } else {
         $model = new Page();
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->addFlash('success', 'Страница сохранена');
         return $this->redirect(['index']);
     }
     return $this->render('update', ['model' => $model]);
 }
Ejemplo n.º 6
0
 /**
  * get page title base on language
  * @param $id
  * @return mixed|null
  */
 public static function getTitle($id)
 {
     $page = Page::findOne($id);
     if ($page) {
         return $page->getPageTitle();
     }
     return null;
 }
Ejemplo n.º 7
0
 public function actionView($slug)
 {
     $pageModel = new Page();
     $pageData = $pageModel->findOne(['slug' => $slug]);
     return $this->render($pageData->views, ['node' => $pageData]);
 }
Ejemplo n.º 8
0
 public function actionAbout()
 {
     $this->title = '关于 - ' . Yii::$app->name;
     $this->description = '';
     if (($model = Page::findOne(['route' => 'about'])) !== null) {
         return $this->render('page', ['model' => $model]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 9
0
 /**
  * Deletes Page
  * @throws \Exception
  */
 public function deletePage()
 {
     /** @var $page Page */
     if ($page = Page::findOne($this->item_id)) {
         $page->removeAllTagValues();
         $page->delete();
     }
 }
Ejemplo n.º 10
0
 /**
  * Creates menu item from existing content
  * @param $content_type integer
  * @param $content_id integer
  *
  * @return string|Response
  */
 public function actionCreateFromContent($content_type, $content_id)
 {
     $model = new MenuItemForm();
     $model->scenario = 'createFromContent';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->saveMenuItem();
         $session = Yii::$app->session;
         $session->setFlash('info', Yii::t('back', 'New menu item successfully added!'));
         $controllerId = $content_type == MenuItemRecord::CONTENT_PAGE ? 'page' : 'category';
         $redirectUrl = [$controllerId . '/index'];
         return $this->redirect($redirectUrl);
     } else {
         $model->content_type = $content_type;
         $model->content_id = $content_id;
         /** @var Page|Category $content */
         $content = $content_type == MenuItemRecord::CONTENT_PAGE ? Page::findOne($content_id) : Category::findOne($content_id);
         $model->title = $content->title;
         $boxes = [];
         if ($content->active) {
             $boxes[] = MenuItemForm::PROPERTY_ACTIVE;
         }
         if ($content->public) {
             $boxes[] = MenuItemForm::PROPERTY_PUBLIC;
         }
         $model->boxes = $boxes;
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('_formFromContent', compact('model'));
         } else {
             return $this->render('_formFromContent', compact('model'));
         }
     }
 }